unsigned long hrtimer_forward(struct hrtimer *timer, ktime_t now, ktime_t interval);

This resets the timer so that it expires after now [usually now is set to the value returned by hrtimer_clock_base->get_time() ]. The exact expiration time is determined by taking the old expiration time of the timer and adding interval so often that the new expiration time lies past now. The function returns the number of times that interval had to be added to the expiration time to exceed now.

Let us illustrate the behavior by an example. If the old expiration time is 5, now is 12, and interval is 2, then the new expiration time will be 13. The return value is 4 because 13 = 5 + 4 x 2.

A common application for high-resolution timers is to put a task to sleep for a specified, short amount of time. The kernel provides another data structure for this purpose:

<hltiratr.h^timer_sleeper {

struct hrtimer timer; struct task_struct *task;

An hrtimer instance is bundled with a pointer to the task in question. The kernel uses hrtimer_wakeup as the expiration function for sleepers. When the timer expires, the hrtimer_sleeper can be derived from the hrtimer using the container_of mechanism (note that the timer is embedded in struct hrtimer_sleeper), and the associated task can be woken up.

Continue reading here: Setting Timers

Was this article helpful?

0 0