Introduction to timer subsystem in linux subsystem set (1)
Generally, to run the entire linux system, a linux clock is required, that is, the time Subsystem. This is exactly what we need, so we will study the time Subsystem in linux.
The Linux kernel must complete two major timing measurements. One is timing, saving the current time and date, so that it can be called by time (), gettimeofday () and other systems and returned to the user program, and the other is timing, this mechanism mainly tells the kernel or application that a certain time interval has passed, triggers the callback function, and then does something.
The hardware mainly includes real-time clock RTC and CPU local Timer. Among them, RTC is another chip outside the cpu or an internal module. However, it is necessary to provide a button-like battery separately. In Linux, only RTC is used to obtain the time and date. For more information about RTC, see the rtc subsystem. The CPU local Timer is actually the Internal Timer module of the CPU, which is generally counted by the CPU Timer module. Of course, this is done by adding a multiplier to the main chip through the crystal oscillator, then, the main chip can count based on different clock frequencies. This count can only increase or decrease, and then there will be interruptions after overflow. Generally, this overflow value can be set. To run an embedded system, the clock is required. The specific porting code is mainly under arch and cannot be transplanted according to different systems.
Linux has Dynamic Ticks and High Resolution Timer. For more information, see kernel/time/Kconfig.
config TICK_ONESHOTboolconfig NO_HZbool "Tickless System (Dynamic Ticks)"depends on !ARCH_USES_GETTIMEOFFSET && GENERIC_CLOCKEVENTSselect TICK_ONESHOThelp This option enables a tickless system: timer interrupts will only trigger on an as-needed basis both when the system is busy and when the system is idle.config HIGH_RES_TIMERSbool "High Resolution Timer Support"depends on !ARCH_USES_GETTIMEOFFSET && GENERIC_CLOCKEVENTSselect TICK_ONESHOThelp This option enables high resolution timer support. If your hardware is not capable then this option only increases the size of the kernel image.
CONFIG_NO_HZ is used to control Dynamic Ticks, and CONFIG_HIGH_REST_TIMERS controls High Resolution Timer.
If the above-mentioned high-precision timer and dynamic tick are not selected, we will use the linux system's low-precision timer and briefly introduce the basic knowledge. Let's continue to study!