A timer is a software facility that allows functions to be invoked at some future moment, after a given time interval has elapsed; a time-out denotes a moment at which the time interval associated with a timer has elapsed.
Timers are widely used both by the kernel and by processes. Most device drivers use timers to detect anomalous conditions — floppy disk drivers, for instance, use timers to switch off the device motor after the floppy has not been accessed for a while, and parallel printer drivers use them to detect erroneous printer conditions.
Timers are also used quite often by programmers to force the execution of specific functions at some future time (see the later section Section 6.7.3).
Implementing a timer is relatively easy. Each timer contains a field
that indicates how far in the future the timer should expire. This
field is initially calculated by adding the right number of ticks to
the current value of
. The field does not
change. Every time the kernel checks a timer, it compares the
expiration field to the value of
jiffies at the
current moment, and the timer expires when
is greater or equal to the stored value. This comparison is made via
time_before_eq macros, which take care of possible
Linux considers two types of timers called dynamic timers and interval timers. The first type is used by the kernel, while interval timers may be created by processes in User ...