Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 15: Time Management


to handle global clock events on x86 systems, the global variableglobal_clock_eventas defined in
arch/x86/kernel/i8253.cis employed. It points to theclock_event_deviceinstance for the global
clock device that is currently in use.

Clock devices and clock event device are formally unconnected at the data structure level. However,
one particular hardware chip in the system provides capabilities that allow fulfillment of the require-
ments for both interfaces, so the kernel usually registers a clock device and a clock event device per
time hardware chip. Consider, for instance, the HPET device on IA-32 and AMD64 systems. The capa-
bilities as clock source are collected inclocksource_hpet, whilehpet_clockeventis an instance of
clock_event_device.Botharedefinedinarch/x86/kernel/hpet.c.hpet_initfirst registers the clock
source and then the clock event device. This adds two time-management objects to the kernel, but only a
single piece of hardware is required.

Tick Devices


One particular important use of clock event devices is to provide periodic ticks — recall from Section 15.2
that ticks are, for instance, required to operate the classical timer wheel. A tick device is an extension of a
clock event device:

<tick.h>
struct tick_device {
struct clock_event_device *evtdev;
enum tick_device_mode mode;
}

enum tick_device_mode {
TICKDEV_MODE_PERIODIC,
TICKDEV_MODE_ONESHOT,
};

Atick_deviceis just a wrapper aroundstruct clock_event_devicewith an additional field that
specifies which mode the device is in. This can either be periodic or one-shot. The distinction will be
important when tickless systems are considered; this is discussed further in Section 15.5. For now, it
suffices to see a tick device as mechanism to provides a continuous stream of tick events. These form the
basis for the scheduler, the classical timer wheel, and related components of the kernel.

Again, the kernel distinguishes global and local (per-CPU) tick devices. The local devices are collected
intick_cpu_device(defined inkernel/time/tick-internal.h). Note that the kernel automatically
creates a tick device when a new clock event device is registered.

Several global variables are additionally defined ininclude/time/tick-internal.h:

❑ tick_cpu_deviceis a per-CPU list containing one instance ofstruct tick_devicefor each CPU
in the system.
❑ tick_next_periodspecifies the time (in nanoseconds) when the next global tick event will
happen.
❑ tick_do_timer_cpucontains the CPU number whose tick device assumes the role of the global
tick device.
❑ tick_periodstores the interval between ticks in nanoseconds. It is the counterpart toHZthat
denotes the frequency at which ticks occur.
Free download pdf