Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 15: Time Management


All the kernel needs to do is calltick_periodic. If the clock event device operates in one-shot mode, the
next tick event needs to be programmed:

kernel/tick/tick-common.c
...
/*
* Setup the next period for devices, which do not have
* periodic mode:
*/
next = ktime_add(dev->next_event, tick_period);
for (;;) {
if (!clockevents_program_event(dev, next, ktime_get()))
return;
tick_periodic(cpu);
next = ktime_add(next, tick_period);
}
}

Sincetick_device->next_eventcontains the time of thecurrenttick event, the time for the
next event can easily be computed by incrementing the value with the length of the interval
as specified intick_period. Programming this event is then usually just a matter of calling
clockevents_program_event. Should this fail^14 because the time for the next clock event lies already in
the past, then the kernel callstick_periodicmanually and tries again to reprogram the event until it
succeeds.

15.4 High-Resolution Timers


After having discussed the generic time framework, we are now ready to take the next step and dive
into the implementation of high-resolution timers. Two fundamental differences distinguish these timers
from low-resolution timers:


  1. High-resolution (high-res) timers are time-ordered on a red-black tree.

  2. They are independent of periodic ticks. They do not use a time specification based on jiffies,
    but employ nanosecond time stamps.


Merging the high-resolution timer mechanism into the kernel was an interesting process in itself. After
the usual development and testing phase, kernel 2.6.16 contained the basic framework that provided
most of the implementation except one thing: support for high-resolution timers.... The classical imple-
mentation of low-resolution timers had, however, been replaced with a new foundation in this release. It
was based on the high-resolution timer framework, although the supported resolution was not any better
than before. Following kernel releases then added support for another class of timers that did actually
provide high-resolution capabilities.

This merge strategy is not only of historical interest: Since low-resolution timers are implemented on top
of the high-resolution mechanism, (partial) support for high-resolution timers will also be built into the
kernel even if support for them is not explicitly enabled! Nevertheless, the system will only be able to
provide timers with low-resolution capabilities.

(^14) Note that 0 is returned on success, so!clockevents_program_event(...)checks for failure.

Free download pdf