Confusing LINUX clock xtime and jiffies

Source: Internet
Author: User
Xtime and jiffies, which are easy to confuse with LINUX clock, are common Linux technologies-Linux programming and kernel information. The following is a detailed description. In LINUX, the clock interruption involves two global variables: xtime, timeval, and jiffies. First, check the timeval structure.

Struct timeval
{
Time_t TV _sec;/*** second ***/
Susecond_t TV _usec;/*** microsecond ***/
}

Many people have been confused in this place. In the end, the microsecond is millisecond or microsecond. I also often make this mistake and have been confused for a long time. Let's clarify it, 1 second = 1000 milliseconds (3 zero), 1 second = 1000 000 microseconds (6 zero), 1 second = 1000 000 000 nanoseconds (9 zero ), 1 second = 1000 000 000 000 second (12 zeros ). The second is represented by s, the millisecond is represented by ms, And the microsecond is represented by μs. The second is represented by ns, and the second is represented by ps. Their unit of classification is thousands, that is, three zeros each time. The reason for obfuscation is found. Because ms is used for representation, I always think that microsecond is millisecond, So I understood TV _usec wrong. The expression of the unit confuses me and most people. It is very important to remember this.

Therefore, xtime is the time obtained from the cmos circuit, generally from a historical time point to the present time, that is, to obtain the date displayed on the operating system. This is the so-called "Real-Time Clock", and its accuracy is microseconds.

Jiffies records the total number of clock interruptions from the computer to the present. In the Linux kernel, jiffies is much more important than xtime. It depends on the system frequency, in Hz. Here we have to explain the unit of frequency, 1 MHz = 1000,000Hz (6 zeros ), 1 KHz = 1000Hz (3 zeros ). the frequency is the reciprocal of the cycle, generally the number of interruptions in one second. Therefore, if we need to know the precise time unit of the system, we need to calculate it, if the frequency of our system is 200 Mhz, the interval between one interruption is 1 second/200,000,000Hz = 0.000 000 005 seconds. Let's take a look at our time unit above, in contrast, the decimal point is followed by nine zeros. Therefore, in theory, the accuracy of our system is 5 nanoseconds. The clock frequency in LINUX is determined by a constant HZ. Generally, HZ = 100, so the accuracy is 10 ms (milliseconds ). That is to say, an interruption occurs every 10 ms. Therefore, Linux is generally accurate to 10 ms.
Related Article

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.