Skip to content
Advertisement

How to run hrtimer handler in softirq context?

I have found this tutorial about hrtimer: http://www.ibm.com/developerworks/linux/library/l-timers-list/

I believe the way it uses will run the callback handler in hardirq context,right? But it also said “One interesting aspect is the ability to define the execution context of the callback function (such as in softirq or hardiirq context)

I have checked the hrtimer.h file but it’s really not that intuitive. Does anyone know how to run it in softirq context? Is it similiar to run it in hardirq?

Thanks,

Advertisement

Answer

This information is regarding an old kernel – in recent releases this feature have been removed to reduce the code complexity and avoid bugs. Now hrtimer always runs in hardirq context with disabled IRQs.

One possible approach is to use a tasklet_hrtimer

#include <linux/interrupt.h>

struct tasklet_hrtimer mytimer;

enum hrtimer_restart callback(struct hrtimer *t) {
   struct tasklet_hrtimer *mytime=container_of(t,struct tasklet_hrtimer,timer);

   ...
}

...
tasklet_hrtimer_init(&mytimer,callback,clock,mode);
tasklet_hrtimer_start(&mytimer,time,mode);
...

In the example above you should replace clock, mode and time with appropriate values.

If you want to pass data to your callback, then you have to embed the tasklet_hrtimer variable in some struct of yours and use the container_of trick to get to your data.

Not quite apparently, your struct will contain a tasklet_hrtimer, which will contain a hrtimer struct. When you get a pointer to the inner most element and you know that it have a fixed offset from the parent element, you can get to the parent.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement