Timer and clock
The kernel uses the timer callouts to work with the hardware timer (i.e., the timer/counter chip).
In many cases, a board can have several hardware timers. You choose one of these timers to use for timer_*() functions in the startup code and timer_*() kernel callouts. In general, hardware timers either count up or count down and may or may not be auto-reset (also called periodic).
The kernel uses a hardware timer to generate a periodic interrupt (i.e., the clock tick). The kernel uses this interrupt for:
- Updating the system time and other software clocks
- Firing software timers
- Thread scheduling
Kernel callouts
The kernel interacts with the specified hardware timer through a set of timer kernel callouts.
- timer_load()
- The kernel assumes that the hardware timer starts at 0, counts up to a number (the divisor value), and then generates an interrupt. The kernel uses the following method to specify a divisor value for the hardware timer:
- timer_reload()
- The kernel assumes that the hardware timer auto-resets (i.e., it's periodic). If the timer does not auto-reset, you must implement the timer_reload() callout. The kernel calls timer_reload() at the beginning of the interrupt.
- timer_value()
- If the kernel wants to know when to expect the next interrupt, it calls the
timer_value() callout and uses the following formula:
where a jiffy is how long it takes for the timer count to increment by one.jiffies_until_interrupt = divisor_value - timer_value()
Page updated:
