Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 15: Time Management


unsigned long seq, last_jiffies, next_jiffies, delta_jiffies, flags;
struct tick_sched *ts;
ktime_t last_update, expires, now, delta;
struct clock_event_device *dev = __get_cpu_var(tick_cpu_device).evtdev;
int cpu;

cpu = smp_processor_id();
ts = &per_cpu(tick_cpu_sched, cpu);

Some statistical information is updated. Recall that the meaning of these fields has already been described
in Section 15.5.1. The last jiffy update and the current jiffy value are stored in local variables:


kernel/time/tick-sched.c
now = ktime_get();

ts->idle_entrytime = now;
ts->idle_calls++;

last_update = last_jiffies_update;
last_jiffies = jiffies;

It only makes sense to deactivate ticks if the next periodic event is more than one tick away. The auxiliary
functionget_next_timer_interruptanalyzes the timer wheel and discovers the jiffy value at which the
next event is due.delta_wheelthen denotes how many jiffies away the next event is:


kernel/time/tick_sched.c
/* Get the next timer wheel timer */
next_jiffies = get_next_timer_interrupt(last_jiffies);
delta_jiffies = next_jiffies - last_jiffies;

If the next tick is at least one jiffy away (note that it can also be possible that some event is due in the
current jiffy), the tick device needs to be reprogrammed accordingly:


kernel/timer/tick-sched.c
/* Schedule the tick, if we are at least one jiffie off */
if ((long)delta_jiffies >= 1) {

ts->idle_tick = ts->sched_timer.expires;
ts->tick_stopped = 1;
ts->idle_jiffies = last_jiffies;

The meaning of the modifiedtick_schedfields has been discussed before.


If the current CPU had to provide the global tick, the task must be handed to another CPU. This is simply
achieved by settingtick_do_timer_cputo−1. The next tick handler that will be activated on another
CPU then automatically takes the duties of the global tick source:


kernel/time/tick-sched.c
if (cpu == tick_do_timer_cpu)
tick_do_timer_cpu = -1;

ts->idle_sleeps++;
Free download pdf