Cyclictest implementation principle

Source: Internet
Author: User

During the embedded virtualization experiment, the real-time performance test has always been performed using javasictest. In fact, the code is only several hundred lines, and the basic principle is also very simple, however, you must pay attention to the APIS it uses.

Here we assume that the parameter used for policictest is: cyclictest-T1-n-m-P 80-I 10000-l 10000. The clock-related settings are as follows:-N specifies clock_nanosleep ();-clock is not specified, so clock_monotonic is used by default instead of clock_realtime;-R is not specified, use the default absolute
Time, not relative. The key process of javasictest code is: 1. use clock_gettime (clock_monotonic, & now) to obtain the current time T1; 2. then it is determined that the par-> mode is mode_clock_nanosleep, par-> timermode = timer_abstime, and therefore clock_nanosleep (clock_monotonic, timer_abstime, & next, null); 3. then use clock_gettime (clock_monotonic, & now) to obtain the current time t2, and calculate t2-(t1 + interval) to obtain latency. In the code, t1 + interval is assigned to next, so you only need to calculate the second now (T2)
-Next. Therefore, clock_gettime and clock_nanosleep are two key APIs to port javasictest to other operating systems. It depends on whether the corresponding APIs can be called in other operating systems. Let's take a look at the implementation of clock_gettime in the Linux kernel. For details, refer to clock_gettime.c: If clock_realtime is used, it puts the gettimeofday call time into the struct timeval variable and converts it to struct.
Timespec type (the timeval precision is subtle, And the timespec precision is nanoseconds ). For clock_monotonic, call hp_timing_gettime. The hp_timing_gettime process is as follows: 1. call _ get_clockfreq to obtain the CPU clock frequency freq, that is, the clock speed. 2. call hp_timing_now (TSC) to obtain the current time. The variable name should be the read TSC; 3. TSC minus the tsc4. TSC/freq read when the current process starts, the number of seconds passed can be calculated; (TSC % freq) * 10 ^ 9/freq can calculate the number of nanoseconds that have passed through the query. In x86, gettimeofday is generally implemented using TSC, but the accuracy is only subtle. Therefore, clock_gettime is gettime by reading TSC, which is irrelevant to the value of Hz. In addition, I think the implementation of gettimeofday should be to convert Real-Time to TSC value when reading RTC, then, gettimeofday returns this value plus the current TSC (because TSC starts counting from 0 at CPU startup) and converts it to a subtle format. Finally, in the timerthread of javasictest, you can determine whether the par-> mode is mode_cyclic. this parameter is irrelevant to the setting of this parameter, the function of iteration is not to start the next iteration immediately after each test, but to specify the next iteration starting from a certain cycle after this iteration. This is similar to the period Test Method of ltp_latency.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.