Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 15: Time Management


goto retry;
}

/* Raise softirq? */
if (raise)
raise_softirq(HRTIMER_SOFTIRQ);
}

Note that reprogramming fails if the next expiration date is already in the past — this can happen if timer
processing took too long. In this case, the whole processing sequence is restarted by jumping to theretry
label at the beginning of the function.

One more final step is necessary to complete one round of high-resolution timer handling: Run the
softIRQ to execute the pending callbacks. The softIRQ handler isrun_hrtimer_softirq, and Figure 15-14
shows the code flow diagram.^17

HRTIMER_RESTART
returned?

run_hrtimer_softirq

timer->function

enqueue_hrtimer
Iterate overall pending timers
Figure 15-14: Code flow diagram forrun_hrtimer_softirq.

Essentially, the function iterates over the list of all pending timers. For each timer, the callback handler is
executed. If the timer requests to be restarted, thenenqueue_hrtimerdoes the required mechanics.

High-ResolutionTimers in Low-ResolutionMode


What if no high-resolution clocks are available? In this case, expiring high resolution timers is initiated
from thehrtimer_run_queues, which is called by the high-resolution timer softIRQHRTIMER_SOFTIRQ
(since softIRQ processing is based on low-resolution timers in this case, the mechanism does not provide
any high-resolution capabilities naturally). The code flow diagram is depicted in Figure 15-15. Note that
this is a simplified version. In reality, the function is more involved because switching from low- to high-
resolution mode is started from this place. However, these problems will not bother us now; the required
extensions are discussed in Section 15.4.5.

Iterate over all bases

run_hrtimer_queue

hrtimer_run_queues

hrtimer_get_softirq_time

Figure 15-15: Code flow diagram for
hrtimer_run_queues.

(^17) The corner case that a timer is rearmed on another CPU after thecallback has been executed is omitted. This possibly requires
reprogramming the clock event device to the new expiration time if the timer is the first on the tree to expire.

Free download pdf