Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 15: Time Management


To set up a tick device, the kernel provides the functiontick_setup_device. The prototype is as follows,
and the code flow diagram is depicted in Figure 15-8^13 :


kernel/time/tick-common.c
static void tick_setup_device(struct tick_device *td,
struct clock_event_device *newdev, int cpu,
cpumask_t cpumask);

Initial setup? Assume global tick duties

Yes

No

No

Yes Periodic mode?

Device requires broadcast? return

tick_setup_device

tick_setup_periodic

tick_setup_oneshot

tick_device_uses_broadcast

Figure 15-8: Code flow diagram fortick_setup_device.

The parametertdspecifies thetick_deviceinstance that is going to be set up. It is about to be equipped
with the clock event devicenewdev.cpudenotes the processor to which the device is associated, and
cpumaskis a bitmask that allows for restricting the tick device to specific CPUs.


When the device is set up for the first time (i.e., if no clock event device is associated with the tick device),
the kernel performs two actions:



  1. If no tick device has been chosen to assume the role as global tick device yet, then the cur-
    rent device is selected, andtick_do_timer_cpuis set to the processor number to which the
    current device belongs.tick_period, that is, the interval between ticks in nanoseconds, is
    computed based on the value ofHZ.

  2. The tick device is set to work in periodic mode.


After assigning the event device to the tick device, the function is finished if broadcasting mode is active
(recall that this is used if the system is in a power-saving state where the local clocks don’t work; see
Section 15.6 for more details). Otherwise, the kernel needs to establish a periodic tick. How this is done
depends on whether the tick device runs in periodic or oneshot mode, and the work is correspondingly
delegated either totick_setup_periodicortick_setup_oneshot.


The fact that the tick device is in one-shot mode does not automatically mean that
dynamic ticks are enabled! Ticks in high-resolution mode are, for instance, always
implemented on top of one-shot timers.

(^13) The function is automatically called if a new clock event device is registered that allows for creating a better tick device than the
previously available ones. Devices with a higher quality are favored, but not if the new and more accurate device does not support
one-shot mode, while the old device does provide this support.

Free download pdf