Introduction to jiffies in the Linux kernel and their effects

  

The hardware provides a system timer for the kernel to calculate and manage time. The kernel presets the frequency of the system timer, ie the tick rate, and each cycle is called a tick. The Linux kernel starts with the 2.5 kernel and increases the frequency from 100 to 1000 (of course, it brings a lot of advantages and some disadvantages).

jiffies is a global variable in the kernel that is used to record the system startup. The number of beats produced. For example, if the computing system is running for a long time, it can be calculated using jiffies/tick rate. Jiffies are defined in the file:

extern unsigned long volatile jiffies;

You can use jiffies to set timeouts, such as:

unsigned long timeout = jiffies + tick_rate * 2; //Timeout after 2 seconds

if(time_before(jiffies, timeout){

//There is no timeout

}

else{

//Timed out

}

The kernel provides four macros to compare the beat counts. These macros are defined in the file:

time_before(unknown, known)

time_after(unknown, known)

time_before_eq(unknown, known)

time_after_eq(unknown, known)

Use these macros to avoid comparisons Jiffies have a wraparound problem due to excessive size.

In addition to the system timer, there is a time-related clock: Real Time Clock (RTC), which is a hardware clock used to store system time permanently. Turn off the micro battery on the motherboard to keep timing. When the system starts, the kernel starts by reading the RTC. Initialize Wall Time and store it in the xtime variable, which is the main role of RTC.

Copyright © Windows knowledge All Rights Reserved