Chapter 15: Time Management
Finally, the tick device is reprogrammed to provide the next event at the proper point in time. While the
method to set the timer differs between high- and low-resolution mode, the code jumps to the labelout
if programming is successful in both cases:
kernel/time/tick-sched.c
expires = ktime_add_ns(last_update, tick_period.tv64 *
delta_jiffies);
ts->idle_expires = expires;
if (ts->nohz_mode == NOHZ_MODE_HIGHRES) {
hrtimer_start(&ts->sched_timer, expires,
HRTIMER_MODE_ABS);
/* Check, if the timer was already in the past */
if (hrtimer_active(&ts->sched_timer))
goto out;
} else if(!tick_program_event(expires, 0))
goto out;
tick_do_update_jiffies64(ktime_get());
}
raise_softirq_irqoff(TIMER_SOFTIRQ);
out:
ts->next_jiffies = next_jiffies;
ts->last_jiffies = last_jiffies;
ts->sleep_length = ktime_sub(dev->next_event, now);
}
If reprogramming failed, then too much time was spent in processing, and the expiration date already
liesinthepast.Inthiscase,tick_do_update_jiffies_64updates jiffies to the correct value, and the
timer softIRQTIMER_SOFTIRQis raised to process any pending timer-wheel timers. Note that the softIRQ
is also raised if some events are due in the current jiffy period.
Restarting Ticks
tick_nohz_restart_sched_tickis used to restart ticks. The code flow diagram is given by Figure 15-20.
Account idle time
Set tick_sched->tick_stopped = 0
Program next tick event
tick_nohz_restart_sched_tick
tick_do_update_jiffies64
Figure 15-20: Code flow diagram for
tick_nohz_restart_sched_tick.
Again, the implementation is complicated by various technical details, but the general principle is rather
simple. Our old acquaintancetick_do_updates_jiffies64is called first. After correctly accounting the