Re: Kernel Timers

Matthias Welwarsky (matze@stud.fbi.fh-darmstadt.de)
Wed, 13 Jan 1999 12:51:58 +0100


Ravi Wijayaratne wrote:
> struct timer_list period_timer;
>
> void function1(void)
> {
> printk(" period Expired \n");
> period_timer.expires=jiffies + 60*HZ; /* sixty seconds */
> period_timer.function = &function1;
> add_timer(&period_timer);
> }
>
> I expected that every 60 seconds function1 will get invoked and print
> the string given in printk.
>
> However when I compile the kernel and boot from this kernel
> function1 goes to a infinite loop and prints the string at very fast
> rate. Definitely not once per minute.
>
> What is wrong with this ?
>

Hi Ravi.
The function itself looks correct, I've done it this way in several
cases, too. However, you MUST make sure that your function1 is not
called while the timer is still running (or protect it by a if
(timer_pending(&period_timer)) return; ). Else the add_timer()
completely messes up the timer list. So, for debugging I'd add the
following:

...
if (timer_pending(&period_timer)) {
printk(KERN_DEBUG "oops, timer still running\n");
return;
}
...

Gruss
Matthias

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/