> -----Original Message----- > From: pradeep singh [mailto:2500.pradeep@xxxxxxxxx] > Sent: Wednesday, March 22, 2006 12:52 PM > To: Bennett, Robert P > Cc: kernel-issues > Subject: Re: spinlocks and kernel timer !!! > > > On 3/22/06, Bennett, Robert P <Robert.Bennett@xxxxxx> wrote: > > > > > -----Original Message----- > > > From: kernelnewbies-bounce@xxxxxxxxxxxx > > > [mailto:kernelnewbies-bounce@xxxxxxxxxxxx] On Behalf Of pradeep > > > singh > > > Sent: Wednesday, March 22, 2006 9:59 AM > > > To: kernel-issues > > > Subject: spinlocks and kernel timer !!! > > > > > > > > > Hi > > > > > > static void some_method() > > > { > > > unsigned long expires; > > > static struct timer_list *timer; > > > expires = jiffes + 20; > > > data = 5; > > > timer->expires = expires; > > > timer->function = my_function; > > > timer->data = data; > > > init_timer(timer); /*initalise timer*/ > > > spin_lock_irqsave(&spinlock, iflags); > > > spin_unlock_irqrestore(&spinlock, iflags); > > > > > > return 0; > > > } > > > > > > static int __init mod_init( void ) > > > { > > > printk(KERN_DEBUG "in init..\n"); > > > some_method(); > > > printk(KERN_DEBUG "after some method in init..\n"); > > > > > > return 0; > > > }; > > > > > > static void __exit mod_exit( void ) > > > { > > > printk(KERN_DEBUG "bye world...\n"); > > > > > > } > > > > > > My question is between spin_lock_irqsave() and > > > spin_unlock_irqrestore() code is supposed to be atomic > right? Now as > > > i have initialised a timer structure in the function.If > the jiffies > > > gets equal to expires in between > > > spinlock() and spinunlock() will my_function() execute? > > > > > > What will happen and why? > > > > You will OOPS as soon as you dereference "timer", since you > > did not initialize it. > > does this means init_timer( timer ) will not initialise the timer ? > > I think LDD3 says about init_timer(timer) to initialise the > timer :), where am i getting this all wrong ? Can you please explain ? What I meant to say was you did not allocate a timer_list struct and assign the pointer to 'timer'. When you simply declare 'static struct timer_list *timer' timer will be set to NULL. You should use 'static struct timer_list *timer = kzalloc(sizeof(*timer))' and check timer for NULL before you dereference it. Anyway, nothing will happen in this case, because you did not do anything with timer after you initialized it. If you don't call add_timer(timer), nothing will happen. Also, why do you have timer defined as a static variable that is local to some_method()? You have leaked the timer_list as soon as you return. You should define the variable as global, and in the __exit function, do del_timer(timer); kfree(timer); > > thank you > > > As for the behavior of the timer, I would expect > that nothing > > is going to happen until after the > > spin_unlock_irqrestore() has been executed, since local > > interrupts are disabled. > > > > -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/