Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 15: Time Management


❑ irqspecifies the number of the IRQ that is used by the event device. Note that this is only
required for global devices. Per-CPU local devices use different hardware mechanisms to emit
signals and setirqto−1.
❑ cpumaskspecifies for which CPUs the event device works. A simple bitmask is employed for this
purpose. Local devices are usually only responsible for a single CPU.
❑ broadcastis required for the broadcasting implementation that provides a workaround for non-
functional local APICs on IA-32 and AMD64 in power-saving mode. See Section 15.6 for more
details.
❑ ratingallows — in analogy to the mechanism described for clock devices — comparison of
clock event devices by explicitly rating their accuracy.
❑ All instances ofstruct clock_event_deviceare kept on the global listclockevent_devices,
andlistis the list head required for this purpose.
The auxiliary functionclockevents_register_deviceis used to register a new clock event
device. This places the device on the global list.
❑ ktime_tstorestheabsolutetimeofthenextevent.

Each event device is characterized by several features stored as a bit string infeatures.Anumberof
constants in<clockchips.h>define possible features. For our purposes, two are of interest^12 :


❑ Clock event devices that support periodic events (i.e., events that are repeated over and over
again without the need to explicitly activate them by reprogramming the device) are identified
byCLOCK_EVT_FEAT_PERIODIC.
❑ CLOCK_EVT_FEAT_ONESHOTmarks a clock capable of issuing one-shot events that happen exactly
once. Basically, this is the opposite of periodic events.

set_modepoints to a function that allows for toggling the desired mode of operation between periodic
and one-shot mode.modedesignates the current mode of operation. A clock can only be ineitherperiodic
orone-shot mode at a time, but it can nevertheless provide the ability to work in both modes — actually,
most clocks allow both possibilities.


Generic code does not need to callset_next_eventdirectly because the kernel provides the following
auxiliary function for this task:


kernel/time/clockevents.c
int clockevents_program_event(struct clock_event_device *dev, ktime_t expires,
ktime_t now)

The (absolute) expiration time for the devicedevis given inexpires, whilenowdenotes the current time.
Usually the caller will directly pass the result ofktime_get()for this parameter.


On IA-32 and AMD64 systems, the role of the global clock event device is initially assumed by the
PIT. The HPET takes over this duty once it has been initialized. To keep track of which device is used


(^12) Recall that local APICs on IA-32 and AMD64 systems expose a problem: They stop working at certain power save levels. This prob-
lem is reported to the kernel by setting the ‘‘feature’’CLOCK_EVT_FEAT_C3STOP, which should rather be named amis-feature.

Free download pdf