Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 15: Time Management


until the next timer will expire. The tick is re-enabled again after this time span, or when an interrupt
occurs. In the meantime, the CPU can enjoy a well-deserved sleep. Note that only classical timers need to
be considered for this purpose. High-resolution timers are not bound by the tick frequency, and are also
not implemented on top of periodic ticks.

Before discussing the dynamic tick implementation, let us note that one-shot clocks are a prerequisite for
them. Since a key feature of dynamic ticks is that the tick mechanism can be stopped and restarted as
necessary, purely periodic timers will fundamentally not suit the mechanism.

In the following,periodic ticksmean a tick implementation that doesnotuse dynamic ticks. This must not
be confused with clock event devices that work in periodic mode.

15.5.1 Data Structures


Dynamic ticks need to be implemented differently depending on whether high- or low-resolution timers
are used. In both cases, the implementation is centered around the following data structure:

<tick.h>
struct tick_sched {
struct hrtimer sched_timer;
enum tick_nohz_mode nohz_mode;
ktime_t idle_tick;
int tick_stopped;
unsigned long idle_jiffies;
unsigned long idle_calls;
unsigned long idle_sleeps;
ktime_t idle_entrytime;
ktime_t idle_sleeptime;
ktime_t sleep_length;
unsigned long last_jiffies;
unsigned long next_jiffies;
ktime_t idle_expires;
};

The individual elements are used as follows:

❑ sched_timerrepresents the timer used to implement the ticks.
❑ The current mode of operation is stored innohz_mode. There are three possibilities:
<tick.h>
enum tick_nohz_mode {
NOHZ_MODE_INACTIVE,
NOHZ_MODE_LOWRES,
NOHZ_MODE_HIGHRES,
};

NOHZ_MOD_INACTIVEis used if periodic ticks are active, while the other two constants indicate
that dynamic ticks are used based on low- and high-resolution timers, respectively.
❑ idle_tickstores the expiration time of the last tick before ticks are disabled. This is important
to know when ticks are enabled again because the next tick must appear at exactly the same
time as if ticks had never been disabled. The proper point in time can be computed by using the
Free download pdf