Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 15: Time Management


/* Check, if the jiffies need an update */
if (tick_do_timer_cpu == cpu)
tick_do_update_jiffies64(now);

update_process_times(user_mode(regs));
profile_tick(CPU_PROFILING);

If the CPU is responsible to provide the global tick, it is sufficient to calltick_do_update_jiffies64,
which takes care of everything required — details will follow in a moment.update_process_timesand
profile_ticktake over the duties of the local tick as you have seen several times before.

The crucial part is to reprogram the tick device. If the tick mechanism is stopped on the current CPU,
this is not necessary, and the CPU will go into a complete sleep. (Note that settingnext_event.tv64
= KTIME_MAXensures that the event device will not expire anytime soon, or never for practical
purposes.)

If ticks are active, thentick_nohz_reprogramsets the tick timer to expire at the next jiffy. Thewhileloop
ensures that reprogramming is repeated until it succeeds if the processing should have taken too long
and the next tick lies already in the past:

kernel/time/tick-sched.c
/* Do not restart, when we are in the idle loop */
if (ts->tick_stopped)
return;

while (tick_nohz_reprogram(ts, now)) {
now = ktime_get();
tick_do_update_jiffies64(now);
}
}

Updating Jiffies


The global tick device callstick_do_update_jiffies64to update the globaljiffies_64variable, the
basis of low-resolution timer handling. When periodic ticks are in use, this is comparatively simple
because the function is called whenever a jiffy has passed. When dynamic ticks are enabled, the situation
can arise in which all CPUs of the system are idle and none provides global ticks. This needs to be taken
into account bytick_do_update_jiffies64. Let’s go directly to the code to see how:

kernel/time/tick-sched.c
static void tick_do_update_jiffies64(ktime_t now)
{
unsigned long ticks = 0;
ktime_t delta;

delta = ktime_sub(now, last_jiffies_update);

Since the function needs to decide if more than a single jiffy has passed since the last update, the differ-
ence between the current time andlast_jiffies_updatemust be computed.
Free download pdf