Linux Kernel: Introduce Hz, tick and jiffies

Source: Internet
Author: User
Linux core is an important time-related domain name or change. The following describes Hz, tick, and jiffies.

Hz
In Linux, the kernel sends the timer interrupt (IRQ 0) Every fixed period. Hz is used to determine that there are two times of timer interrupts every second. In the example, Hz is 1000, indicating that there are 1000 timer interrupts requests per second. Hz can be set when the core is updated, as shown in the following example (the core version is 2.6.20-15 ):

Adrian @ Adrian-desktop :~ $ CD/usr/src/Linux
Adrian @ Adrian-desktop:/usr/src/Linux $ make menuconfig
Processor type and features ---> timer frequency (250Hz) --->


Hz can be set to 100, 250, 300, or 1000. Set the core version of the younger brother to 250.

Small entity
Check the number of times in the timer of/proc/interrupt, and check its value again in one second. In theory, the difference between the two should be about 250.

Adrian @ Adrian-desktop :~ $ CAT/proc/interrupts | grep timer & sleep 1 & CAT/proc/interrupts | grep Timer
0: 9309306 io-APIC-edge Timer
0: 9309562 io-APIC-edge Timer

The preceding four bit values indicate the number of CPU connections, the number of CPU connections, and the value of PIC and memory.


Question: What Will timer interrupt do? The answer is as follows:

Update the time, date, and system time from the start to the current time.
Updates the system resource usage statistics
Check whether the program that is running the row has exceeded the allocated row time. If yes, the program invades (preempt) to facilitate other programs waiting for the same row.
Check whether the delay time between the software timer, such as the alarm system call, and the time delay function has exceeded.
Tick
Tick Is the inverted Number of Hz, that is, the time when timer interrupt generates a middle interval. For example, when Hz is 250, tick is 4 ms (millisecond ).

Jiffies
Jiffies is the Linux core variable (32-bit variable, unsigned long). It is used to compile the system's self-opening and how many Tick has elapsed. Every time timer interrupt is generated, the jiffies changes will be incremented. It is worth noting that jiffies is set to-300 * Hz (ARCH/i386/kernel/time. c), that is, after the system is enabled for five minutes, jiffies will overflow. How can I handle the overflow? In fact, the Linux core defines a macro (timer_after, time_after_eq, time_before, and time_before_eq). Even if it is an overflow, it can use this macro to obtain the content of jiffies.

In addition, the 80x86 architecture defines a jiffies_64 variable that is related to jiffies. This variable is 64-bit, and it may take several hundred years to wait for this change to overflow. Therefore, it is necessary to wait until the overflow occurs. Then how does one obtain the jiffies information from jiffies_64? In fact, jiffies is applied to the lowest 32-bit jiffies_64. Therefore, jiffies_64 can obtain jiffies without the problem of overflow.

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.