Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 15: Time Management


ktime_t (*get_softirq_time)(void);
ktime_t softirq_time;
#ifdef CONFIG_HIGH_RES_TIMERS
ktime_t offset;
int (*reprogram)(struct hrtimer *t,
struct hrtimer_clock_base *b,
ktime_t n);
#endif
};

The meaning of the fields is as follows:

❑ hrtimer_cpu_basepoints to the per-CPU basis to which the clock base belongs.
❑ indexdistinguishes betweenCLOCK_MONOTONICandCLOCK_REALTIME.
❑ rb_rootis the root of a red-black tree on which all active timers are sorted.
❑ firstpoints to the timer that will expire first.
❑ Processing high-res timers is initiated from the high-resolution timer softIRQHRTIMER_SOFTIRQ
as described in the next section.softirq_timestores the time at which the softIRQ was issued,
andget_softirq_timeis a function to obtain this time. If high-resolution mode is not active,
then the stored time will be coarse-grained.
❑ get_timereads the fine-grained time. This is simple for the monotonic clock (the value delivered
by the current clock source can be directly used),but some straightforward arithmetic is required
to convert the value into the real system time.
❑ resolutiondenotes the resolution ofthe timer in nanoseconds.
❑ When the real-time clock is adjusted, a discrepancy between the expiration values of timers
stored on theCLOCK_REALTIMEclock base and the current real time will arise. Theoffsetfield
helps to fix the situation by denoting an offset by which the timers needs to be corrected. Since
this is only a temporary effect that happens only seldomly, the complications need not be dis-
cussed in more detail.
❑ reprogramis a function that allows for reprogramminga given timer event, that is, changing the
expiration time.

Two clock bases are established for each CPU using the following data structure:

<hrtimer.h>
struct hrtimer_cpu_base {
struct hrtimer_clock_base clock_base[HRTIMER_MAX_CLOCK_BASES];
#ifdef CONFIG_HIGH_RES_TIMERS
ktime_t expires_next;
int hres_active;
struct list_head cb_pending;
unsigned long nr_events;
#endif
};

HRTIMER_MAX_CLOCK_BASESis currently set to 2 because a monotonic and a real-time clock exist as dis-
cussed above. Note that the clock bases are directly embedded intohrtimer_cpu_baseand not referenced
via pointers! The remaining fields of the structure are used as follows:
Free download pdf