Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 15: Time Management


Actually, the task is quite simple if the clock event device supports periodic events. In this
case,tick_set_periodic_handlerinstallstick_handle_periodicas handler function, and
clockevents_set_modeensures that the clock event device runs in periodic mode.


If the event device does not support periodic events, then the kernel must make do with one-shot events.
clockevents_set_modesets the event device to this mode, but additionally, the next event needs to be
programmed in manually usingclockevents_program_event.


In both cases, the handler functiontick_handle_periodicis called on the next event of the tick device.
(Recall that we focus on the low-res case without dynamic ticks here; other settings will use different
handler functions!) Before discussing the handler function, I need to introduce the auxiliary function
tick_periodic. It is responsible for handling the periodic tick on a given CPU required as an argument:


kernel/time/tick_common.c
static void tick_periodic(int cpu);

Figure 15-11 shows what is going on inside the function.


CPU responsible for global tick?

profile_tick

tick_periodic

do_timer

update_process_times

Figure 15-11: Code flow diagram fortick_periodic.

If the current tick device is responsible for the global tick, thendo_timeris called. Recall that this function
is discussed in Section 15.2.1. Nevertheless, remember thatdo_timerisresponsibletoupdatetheglobal
jiffiesvalue that is used as the coarse-grained time base in many parts of the kernel.


update_process_timesis called by every tick handler, as well asprofile_tick. The first function is
discussed in Section 15.2.1.profile_tickis responsible for profiling, but the details are not discussed
here.


Let’s go back to the handler function. Things are again easier here if periodic events are in use:


kernel/tick/tick-common.c
void tick_handle_periodic(struct clock_event_device *dev)
{
int cpu = smp_processor_id();
ktime_t next;
tick_periodic(cpu);
if (dev->mode != CLOCK_EVT_MODE_ONESHOT)
return;
...
Free download pdf