Activating Timers

When new timers are installed, a distinction must be made as to whether they are required by the kernel itself or by applications in userspace. First, let's discuss the mechanism for kernel timers because user timers also build on this mechanism.

add_timer is used to insert a fully supplied instance of timer_list into the structures just described above:

static inline void add_timer(struct timer_list *timer);

After checking several safety conditions (e.g., the same timer may not be added twice), work is delegated to the internal_add_timer function whose task is to place the new timer at the right position in the data structures.

The kernel must first compute the number of ticks after which time-out of the new timer will occur because an absolute time-out value is specified in the data structure of new drivers. To compensate for any missed timer handling calls, expires - base->timer_jiffies is used to compute the offset.

The group and the position within the group can be determined on the basis of this value. All that now need be done is to add the new timer to the linked list. Because it is placed at the end of the list and because the run_timer_list is processed from the beginning, a first-in, first-out mechanism is implemented.

Continue reading here: Generic Time Subsystem

Was this article helpful?

0 0