Reputation: 349
I am working on a new linux scheduler, and I need hrtimers. I read how to implement them, in: http://lwn.net/Articles/167897/
I made a small program, to test these timers before using them, and I have some problems.
That small program is something like this:
#include "linux/ktime.h"
#include "linux/hrtimer.h"
#include "linux/timer.h"
#include "linux/tick.h"
static void funcion_timers(unsigned long data) {
printk(" HOLA HA SALTADO EL TIMER y el dato es %lu \n", data);
}
int main () {
ktime_t kt;
int i;
struct hrtimer my_timer;
clockid_t reloj;
enum hrtimer_mode mode;
kt = ktime_set(0, 5000000);
reloj=CLOCK_MONOTONIC;
mode=HRTIMER_REL;
printk("EMPIEZA EL PROGRAMA");
hrtimer_init(&my_timer, reloj);
my_timer.function=&funcion_timers;
my_timer.data=3;
hrtimer_start(&my_timer, kt, mode);
for (i=0; i<10000; i++) { } //A kind of waste of time cause I had problem with sleep into the kernel
}
And when I compile I am told (I'm not copying from the shell because it is in Spanish xD):
HRTIMER_REL
was not been declaredhrtimer_init
needs more argumentsmy_timer.function=&funcion_timers;
I have an incompatible pointer type :Sstruct hrtimer
doesn't have a member called data
Why does hrtimer_init need arguments? I thought it was defined as:
*void hrtimer_init(struct hrtimer *timer, clockid_t which_clock);*
In conclusion, I think I may have not understand how clockid_t
works; how does it work?
I cannot find too much information about it on the Internet.
Thanks a lot, :D Alberto
Upvotes: 3
Views: 1706
Reputation: 6102
As noted by Banthar, the API for hrtimers has changed, and thus made quite a few of the examples in existence on the internet outdated. You can have a look at the current functions at https://github.com/torvalds/linux/blob/master/include/linux/hrtimer.h, and the commit messages usually (cross your fingers first though) give an idea of what has changed, why, and what you should do to make your code work.
From the above link:
HRTIMER_REL
has been renamed to HRTIMER_MODE_REL
hrtimer_init()
needs a mode parameter (in your case probably HRTIMER_MODE_REL
)
The callback function needs to be of type: enum hrtimer_restart (*function)(struct hrtimer *)
The data
member has been removed from struct hrtimer
, as the timer itself is now passed to the callback function.
Upvotes: 1