Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 15: Time Management


Clock Event Devices


Clock event devices are defined by the following data structure:

<clockchips.h>
struct clock_event_device {
const char *name;
unsigned int features;
unsigned long max_delta_ns;
unsigned long min_delta_ns;
unsigned long mult;
int shift;
int rating;
int irq;
cpumask_t cpumask;
int (*set_next_event)(unsigned long evt,
struct clock_event_device *);
void (*set_mode)(enum clock_event_mode mode,
struct clock_event_device *);
void (*event_handler)(struct clock_event_device *);
void (*broadcast)(cpumask_t mask);
struct list_head list;
enum clock_event_mode mode;
ktime_t next_event;
};

Recall that clock event devices allow for registering aneventthat is going to happen at a defined point
of time in the future. In comparison to a full-blown timer implementation, however, only a single event
can be stored. The key elements of everyclock_event_deviceareset_next_eventbecause it allows for
setting the time at which the event is going to take place, andevent_handler, which is called when the
event actually happens.

Besides, the elements ofclock_event_devicehave the following purpose:

❑ nameis a human-readable representation for the event device. It shows up in/proc/timerlist.
❑ max_delta_nsandmin_delta_nsspecify the maximum or minimum, respectively, difference
between the current time and the time for the next event. Clocks work with individual frequen-
cies at which device cycles occur, but the generic time subsystem expects a nanosecond value
when the event shall take place. The auxiliary functionclockevent_delta2nshelps to convert
one representation into the other.
Consider, for instance, that the current time is 20,min_delta_nsis 2, andmax_delta_nsis 40 (of
course, the exemplary values do not represent any situation possible in reality). Then the next
event can take place during the time interval [22, 60] where the boundaries are included.
❑ multandshiftare a multiplier and a divider, respectively, used to convert between clock cycles
and nanosecond values.
❑ The function pointed to byevent_handleris called by the hardware interface code (which usu-
ally is architecture-specific) to pass clock events on to the generic layers.
Free download pdf