Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 15: Time Management


❑ expires_nextcontains the absolute time of the next event that is due for expiration.
❑ hres_activeis used as a Boolean variable to signal if high-resolution mode is active, or if only
low-resolution is available.
❑ When a timer expires, it is moved from the red-black tree to a list headed bycb_pending.^15 Note
that the timers on this list still need to be processed. This will take place in the softIRQ handler.
❑ nr_eventskeeps track of the total number of timer interrupts.

he global per-CPU variablehrtimer_cpu_basecontains an instance ofstruct hrtimer_base_cpufor
each processor in the system. Initially it is equipped with the following contents:


kernel/hrtimer.c
DEFINE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases) =
{

.clock_base =
{
{
.index = CLOCK_REALTIME,
.get_time = &ktime_get_real,
.resolution = KTIME_LOW_RES,
},
{
.index = CLOCK_MONOTONIC,
.get_time = &ktime_get,
.resolution = KTIME_LOW_RES,
},
}
};

Since the system is initialized in low-resolution mode, the achievable resolution is onlyKTIME_LOW_RES.
The pre-processor constant denotes the timer interval between periodic ticks with frequencyHZin
nanoseconds.ktime_getandktime_get_realboth obtain the current time by usinggetnstimeofday,
discussed in Section 15.3.


A very important component is still missing. How is a timer itself specified? The kernel provides the
following data structure for this purpose:


<hrtimer.h>
struct hrtimer {
struct rb_node node;
ktime_t expires;
int (*function)(struct hrtimer *);
struct hrtimer_base *base;
unsigned long state;
#ifdef CONFIG_HIGH_RES_TIMERS
enum hrtimer_cb_mode cb_mode;
struct list_head cb_entry;
#endif
};

(^15) This requires that the timer is allowed to be executed in softIRQ context. Alternatively, timers are expired directly in the clock
hardware IRQ without involving the detour via the expiration list.

Free download pdf