Jiffies in Linux Kernel

Source: Internet
Author: User
Jiffies in Linux kernel-general Linux technology-Linux programming and kernel information. For details, refer to the following section. The hardware provides a system timer for the kernel to calculate and manage time. The kernel program the preset system timer frequency, that is, the tick rate. Each cycle is called a tick ). The Linux kernel starts to increase the frequency from 2.5 to 100 (of course, it brings many advantages and some disadvantages ).

Jiffies is a global variable in the kernel. It is used to record the number of beats generated from system startup. For example, if the computing system runs for a long time, you can use jiffies/tick rate for calculation. Jiffies is defined in the file Medium:

Extern unsigned long volatile jiffies;

Jiffies can be used to set timeout, for example:
Unsigned long timeout = jiffies + tick_rate * 2; // timeout after 2 seconds


If (time_before (jiffies, timeout ){
// No timeout

}
Else {
// Timeout

}

The kernel provides four macros to compare the cycle count, which are defined in the file Medium:

Time_before (unknown, known)
Time_after (unknown, known)
Time_before_eq (unknown, known)
Time_after_eq (unknown, known)

When comparing these macros, you can avoid the redirection problem caused by the large size of jiffies.

In addition to the system timer, there is also a time-related clock: Real-time clock (RTC), which is a hardware clock used to persistently store the system time, the system shuts down and depends on the micro-battery on the motherboard to maintain timing. When the system starts, the kernel initializes the Wall Time by reading RTC and stores it in the xtime variable. This is the main function of RTC.

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.