Chapter 15: Time Management
1 because I do not consider dynamic tick mode for now. The previously discussed functiondo_timer
is used to handle all duties of the global timer. Recall that this includes updating the globaljiffies64
variable.
CPU responsible for global tick?
Set next tick after tick_period
return HRTIMER_RESTART
tick_sched_timer
tick_do_update_jiffies64
update_process_times
profile_tick
Figure 15-17: Code flow diagram fortick_sched_timer.
When the per-CPU periodic tick tasks have been performed inupdate_process_times(see Section 15.8)
andprofile_tick, the time for the next event is computed, andhrtimer_forwardprograms the timer
accordingly. By returningHRTIMER_RESTART, the timer is automatically re-queued and activated when
the next tick is due.
15.4.5 Switching to High-Resolution Timers
High-resolution timers are not enabled from the very beginning, but can only be activated when suitable
high-resolution clock sources have been initialized and added to the generic clock framework. Low-
resolution ticks, however, are provided (nearly) from the very beginning. In the following, I discuss how
the kernel switches from low- to high-resolution mode.
The high-resolution queue is processed byhrtimer_run_queuewhen low-resolution timers are active.
Before the queues are run, the function provides checks if a clock event device suitable for high resolution
timers is present in the system. In this case, the switch to high resolution mode is performed:
kernel/hrtimer.c
void hrtimer_run_queues(void)
{
...
if (tick_check_oneshot_change(!hrtimer_is_hres_enabled()))
if (hrtimer_switch_to_hres())
return;
...
}
tick_check_oneshot_changesignalizes that high-resolution timers can be used if a clock that
supports one-shot mode and fulfills the resolution requirements for high-res timers, that is, if the flag
CLOCK_SOURCE_VALID_FOR_HRESis set.hrtimer_switch_to_hresperforms the actual switch. The
required steps are summarized in Figure 15-18.