* add_timer crashes the kernel,Why?
@ 2010-12-20 8:27 lijin liu
2010-12-20 8:43 ` Raz
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: lijin liu @ 2010-12-20 8:27 UTC (permalink / raw)
To: kernelnewbies
Hello everyone!
I want to use the timer in my kernel module. I read the book _Linux
kernel development 3rd version_ and LDD 3rd version.
Both the two books tell me write the code like this:
struct timer_list my_timer;
init_timer(&my_timer);
my_timer.expires = jiffies + wait;
my_timer.data = 0;
my_timer.function=my_function;
//active the timer:
add_timer(&timer);
When I insmod the module, the kernel crashed, and when I change my
code to *mod_timer* rather than add_timer.
It just works!
But why the add_timer crash the kernel?
^ permalink raw reply [flat|nested] 7+ messages in thread
* add_timer crashes the kernel,Why?
2010-12-20 8:27 add_timer crashes the kernel,Why? lijin liu
@ 2010-12-20 8:43 ` Raz
2010-12-20 9:06 ` Wick
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Raz @ 2010-12-20 8:43 UTC (permalink / raw)
To: kernelnewbies
try to remove mytimer from stack
On Mon, Dec 20, 2010 at 10:27 AM, lijin liu <llj098@gmail.com> wrote:
> Hello everyone!
>
> I want to use the timer in my kernel module. I read the book _Linux
> kernel development 3rd version_ and LDD 3rd version.
>
> Both the two books tell me write the code like this:
>
> struct timer_list my_timer;
> init_timer(&my_timer);
>
> my_timer.expires = jiffies + wait;
> my_timer.data = 0;
> my_timer.function=my_function;
>
> //active the timer:
> add_timer(&timer);
>
>
> When I insmod the module, the kernel crashed, and when I change my
> code to *mod_timer* rather than add_timer.
>
> It just works!
>
> But why the add_timer crash the kernel?
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20101220/379fbea7/attachment.html
^ permalink raw reply [flat|nested] 7+ messages in thread
* add_timer crashes the kernel,Why?
2010-12-20 8:27 add_timer crashes the kernel,Why? lijin liu
2010-12-20 8:43 ` Raz
@ 2010-12-20 9:06 ` Wick
[not found] ` <AANLkTikY4+BqhjrNYiwR+1WrN53+_6JGiCkJ-kCTGL-B@mail.gmail.com>
2010-12-20 9:08 ` Mulyadi Santosa
3 siblings, 0 replies; 7+ messages in thread
From: Wick @ 2010-12-20 9:06 UTC (permalink / raw)
To: kernelnewbies
Hi Lijin:
On Mon, Dec 20, 2010 at 4:27 PM, lijin liu <llj098@gmail.com> wrote:
> Hello everyone!
>
> I want to use the timer in my kernel module. I read the book ?_Linux
> kernel development 3rd version_ ?and LDD 3rd version.
>
> Both the two books tell me write the code like this:
>
> struct timer_list my_timer;
> init_timer(&my_timer);
>
> my_timer.expires = jiffies + wait;
> my_timer.data = 0;
> my_timer.function=my_function;
You just constructed my_timer.
>
> //active the timer:
> add_timer(&timer);
and add timer (not my_timer )to the timer list ...
If the problem still exists, suggest you copy all codes and crash log here.
>
>
> When I insmod the module, the kernel crashed, and when I change my
> code to *mod_timer* rather than add_timer.
^ permalink raw reply [flat|nested] 7+ messages in thread
* add_timer crashes the kernel,Why?
[not found] ` <AANLkTikY4+BqhjrNYiwR+1WrN53+_6JGiCkJ-kCTGL-B@mail.gmail.com>
@ 2010-12-20 9:06 ` lijin liu
2010-12-20 9:33 ` Mulyadi Santosa
0 siblings, 1 reply; 7+ messages in thread
From: lijin liu @ 2010-12-20 9:06 UTC (permalink / raw)
To: kernelnewbies
On Mon, Dec 20, 2010 at 4:42 PM, Raz <raziebe@gmail.com> wrote:
> try to remove mytimer from stack
Yes, I made a stupid mistake, It works now.
^ permalink raw reply [flat|nested] 7+ messages in thread
* add_timer crashes the kernel,Why?
2010-12-20 8:27 add_timer crashes the kernel,Why? lijin liu
` (2 preceding siblings ...)
[not found] ` <AANLkTikY4+BqhjrNYiwR+1WrN53+_6JGiCkJ-kCTGL-B@mail.gmail.com>
@ 2010-12-20 9:08 ` Mulyadi Santosa
2010-12-20 14:15 ` Dexter Haslem
3 siblings, 1 reply; 7+ messages in thread
From: Mulyadi Santosa @ 2010-12-20 9:08 UTC (permalink / raw)
To: kernelnewbies
Hi :)
On Mon, Dec 20, 2010 at 15:27, lijin liu <llj098@gmail.com> wrote:
> Hello everyone!
>
> I want to use the timer in my kernel module. I read the book ?_Linux
> kernel development 3rd version_ ?and LDD 3rd version.
>
> Both the two books tell me write the code like this:
>
> struct timer_list my_timer;
> init_timer(&my_timer);
>
> my_timer.expires = jiffies + wait;
> my_timer.data = 0;
> my_timer.function=my_function;
>
> //active the timer:
> add_timer(&timer);
>
>
> When I insmod the module, the kernel crashed, and when I change my
> code to *mod_timer* rather than add_timer.
Hmmm, from http://lxr.linux.no/linux+v2.6.36/kernel/timer.c#L864, it reads:
void add_timer(struct timer_list *timer)
{
BUG_ON(timer_pending(timer));
mod_timer(timer, timer->expires);
}
thus, IMHO the error happened because there is other timer pending...
somehow it is forbidden to add timer when other are still in queue in
latest kernel
--
regards,
Mulyadi Santosa
Freelance Linux trainer and consultant
blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* add_timer crashes the kernel,Why?
2010-12-20 9:06 ` lijin liu
@ 2010-12-20 9:33 ` Mulyadi Santosa
0 siblings, 0 replies; 7+ messages in thread
From: Mulyadi Santosa @ 2010-12-20 9:33 UTC (permalink / raw)
To: kernelnewbies
On Mon, Dec 20, 2010 at 16:06, lijin liu <llj098@gmail.com> wrote:
> On Mon, Dec 20, 2010 at 4:42 PM, Raz <raziebe@gmail.com> wrote:
>> try to remove mytimer from stack
>
> Yes, I made a stupid mistake, It works now.
ah so you put all of the mentioned code in module_init? no wonder
then....init finishes...code and stack cleaned up....timer refers to
NULL...boom.
next time, please paste the exact code...so people didn't mis conclude
the statement....
--
regards,
Mulyadi Santosa
Freelance Linux trainer and consultant
blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* add_timer crashes the kernel,Why?
2010-12-20 9:08 ` Mulyadi Santosa
@ 2010-12-20 14:15 ` Dexter Haslem
0 siblings, 0 replies; 7+ messages in thread
From: Dexter Haslem @ 2010-12-20 14:15 UTC (permalink / raw)
To: kernelnewbies
On 12/20/2010 2:08 AM, Mulyadi Santosa wrote:
> Hi :)
>
> On Mon, Dec 20, 2010 at 15:27, lijin liu<llj098@gmail.com> wrote:
>> Hello everyone!
>>
>> I want to use the timer in my kernel module. I read the book _Linux
>> kernel development 3rd version_ and LDD 3rd version.
>>
>> Both the two books tell me write the code like this:
>>
>> struct timer_list my_timer;
>> init_timer(&my_timer);
>>
>> my_timer.expires = jiffies + wait;
>> my_timer.data = 0;
>> my_timer.function=my_function;
>>
>> //active the timer:
>> add_timer(&timer);
>>
>>
>> When I insmod the module, the kernel crashed, and when I change my
>> code to *mod_timer* rather than add_timer.
>
> Hmmm, from http://lxr.linux.no/linux+v2.6.36/kernel/timer.c#L864, it reads:
> void add_timer(struct timer_list *timer)
> {
> BUG_ON(timer_pending(timer));
> mod_timer(timer, timer->expires);
> }
>
> thus, IMHO the error happened because there is other timer pending...
> somehow it is forbidden to add timer when other are still in queue in
> latest kernel
>
I believe add_timer just prevents creating duplicate timers from the
same struct. I was actually thinking I had the same problem with timer
code (following essential linux device drivers). But the issue was
removing a module with an active timer will cause a crash.
Here is what I ended up with, a silly sample timer that chains itself 3
times. It might be useful to OP: http://pastebin.com/v4rr3t50
--
-Dexter Haslem
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2010-12-20 14:15 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-20 8:27 add_timer crashes the kernel,Why? lijin liu
2010-12-20 8:43 ` Raz
2010-12-20 9:06 ` Wick
[not found] ` <AANLkTikY4+BqhjrNYiwR+1WrN53+_6JGiCkJ-kCTGL-B@mail.gmail.com>
2010-12-20 9:06 ` lijin liu
2010-12-20 9:33 ` Mulyadi Santosa
2010-12-20 9:08 ` Mulyadi Santosa
2010-12-20 14:15 ` Dexter Haslem
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).