In the Linux operating system, many activities are related to time, such as process scheduling and network processing, and so on. Therefore, understanding the clock processing mechanism in the Linux operating system helps to better understand how the Linux operating system works. This paper analyzes the clock processing mechanism of Linux 2.6.25 kernel, first introduces some hardware timers in computer system, then focuses on the hardware clock and software clock processing in Linux operating system and the application of software clock. Finally, the full text is summarized.
1 timers in a computer system
There are many hardware timers in the computer system, such as real timer Clock (RTC), Time Stamp Counter (TSC), and programmable Interval timer (PIT), and so on.
This section is not the midpoint of this article, just a few, and more, see references:
Real Timer Clock (RTC):
Independent of the entire computer system (e.g., CPU and other chip)
The kernel uses it to get the system current time and date
Time Stamp Counter (TSC):
From Pentium, a register TSC is provided to accumulate the clock signal generated by each external oscillator
Access this register via instruction RDTSC
can provide more accurate time measurements than PIT,TSC
Programmable Interval Timer (PIT):
Time Measuring Equipment
The kernel uses the device that produces clock interrupts, resulting in clock interrupts that depend on the hardware architecture, slow for Ms once, and fast for 1 ms at a time
High Precision Event Timer (hpet):
PIT and RTC replacements, compared to previous timers, Hpet provides a higher clock frequency (at least ten MHz) and a wider counter width (64-bit)
A hpet includes a fixed-frequency numeric increment counter and 3 to 32 independent timers, each of which has a comparator and a register (holding a value indicating when the interrupt is triggered). Each comparer compares the values in the counter with the values in the registers, and when the two values are equal, an interrupt is generated
2 Hardware clock processing
The hardware clock in this case refers to the processing of the hardware timer clock interruption.