Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 15: Time Management


When the handler has finished, theHRTIMER_STATE_CALLBACKflag can be removed again. If the timer
requested to be put back into the queue, thenenqueue_hrtimerfulfills this request.

15.4.4 Periodic Tick Emulation


The clock event handler in high-resolution mode ishrtimer_interrupt. This implies that
tick_handle_periodicdoes not provide the periodic tick anymore. An equivalent functionality thus
needs be made available based on high-resolution timers. The implementation is (nearly) identical
between the situations with and without dynamic ticks. The generic framework for dynamic ticks is
discussed in Section 15.5; the required components are covered here only cursorily.

Essentially,tick_schedis a special data structure to manage all relevant information about periodic
ticks, and one instance per CPU is provided by the global variabletick_cpu_sched.

tick_setup_sched_timeris called to activate the tick emulation layer when the kernel switches to
high-resolution mode. One high-resolution timer is installed per CPU. The required instance ofstruct
hrtimeris kept in the per-CPU variabletick_sched:

<tick.h>
struct tick_sched {
struct hrtimer sched_timer;
...
}

The functiontick_sched_timeris used as the callback handler. To avoid a situation in which all CPUs
are engaged in running the periodic tick handlers at the same time, the kernel distributes the acceleration
time as shown in Figure 15-16. Recall that the length of a tick period (in nanoseconds) istick_period.
The ticks are spread across the first half of this period. Assume that the first tick starts at time 0. If the
system containsNCPUs, the remaining periodic ticks are started at times,2,3,...The offsetis
given bytick_period/(2N).

CPU 0
CPU 1
CPU 2
CPU 3

CPU N

periodic
tick occurs

0 tick_period/2 tick_period time
Figure 15-16: Distributing periodic tick handlers in high-resolution mode.

The tick timer is registered like every other regular high-resolution timer. The function displays some
similarities totick_periodic, but is slightly more complicated. The code flow diagram is shown in
Figure 15-17.

If the CPU that is currently executing the timer is responsible to provide the global tick (recall that this
duty has already been distributed in low-resolution mode at boot time), thentick_do_update_jiffies64
computes the number of jiffies that have passed since the last update — in our case, this will always be
Free download pdf