Hello everyone,
I have written a kernel module that uses kernel timers.
it works fine but if don't make mytimer static then the system hangs.
Moreover if try calling set_timer from init module many times the syatem hangs.I am unable to locat the fault.
Any help would be greatly appreciated.the code goes like this:
#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/init.h>
#include<linux/sched.h>
#include<linux/timer.h>
void timer_timeout(int c)
{
struct timeval timecount;
do_gettimeofday(&timecount);
printk(KERN_INFO "\ntimer%d expired at :%ld seconds %ld microseconds",c,timecount.tv_sec,timecount.tv_usec);
}
void set_timer(void)
{
static struct timer_list mytimer;
static int i=1;
struct timeval timecount;
init_timer(&mytimer);
mytimer.expires=jiffies+2*HZ;
mytimer.data="">
mytimer.function=(void*)timer_timeout;
add_timer(&mytimer);
do_gettimeofday(&timecount);
printk(KERN_INFO "\ntimer%d started at :%ld seconds %ld microseconds",i++,timecount.tv_sec,timecount.tv_usec);
return;
}
int time_init(void)
{
set_timer();
return 0;
}
void time_cleanup(void)
{
printk(KERN_INFO "\ntimer unloaded\n");
}
module_init(time_init);
module_exit(time_cleanup);
MODULE_LICENSE("GPL");