Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 15: Time Management


Set resolution in clock base

retrigger_next_event

hrtimer_switch_to_highres

tick_init_highres

tick_switch_to_oneshot(hrtimer_interrupt)

tick_setup_sched_timer

Figure 15-18: Code flow diagram forhrtimer_switch_to_hires.

tick_init_switch_to_highresis a wrapper function usingtick_switch_to_oneshotto set the clock
event device to one-shot mode. Additionally,hrtimer_interruptis installed as event handler. After-
ward the periodic tick emulation is activated withtick_init_highresas discussed above. Since the
resolution is now improved, this also needs to be reflected in the data structures:

kernel/hrtimer.c
static int hrtimer_switch_to_hres(void)
{
...
base->hres_active = 1;
base->clock_base[CLOCK_REALTIME].resolution = KTIME_HIGH_RES;
base->clock_base[CLOCK_MONOTONIC].resolution = KTIME_HIGH_RES;
...
}

Finally,retrigger_next_eventreprograms the clock event device to set the ball rolling. High-resolution
support is now active!

15.5 Dynamic Ticks


Periodic ticks have provided a notion of time to the Linux kernel for many of years. The approach is
simple and effective, but shows one particular deficiency on systems where power consumption does
matter: The periodic tick requires that the system is in an active state at a certain frequency. Longer
periods of rest are impossible because of this.

Dynamic ticks mend this problem. The periodic tick is only activated when some tasks actually do need
to be performed. Otherwise, it is temporarily disabled. Support for this technique can be selected at
compile time, and the resulting system is also referred to as atickless system.However,thisnameisnot
entirely accurate because the fundamental frequencyHZat which the periodic tick operates when it is
functional still provides a raster for time flow. Since the tick can be activated and deactivated according
to the current needs, the termdynamic ticksfits very well.

How can the kernel decide if the system has nothingto do? Recall from Chapter 2 that if no active tasks
are on the run queue, the kernel picks a special task — the idle task — to run. At this point, the dynamic
tick mechanism enters the game. Whenever the idle task is selected to run, the periodic tick is disabled
Free download pdf