Is it safe to call wake_up() from interrupt context?

Oct 06, 2006 5 Replies

Hi All,



Is it safe to call wake_up function from interrupt context in bottom half ? Actually I am trying to do something like this :



//This function is called from the process context fn_in_process_context () { //some code here in_use = 1; wait_event (queue, in_use==0); //some more code }


//This function is called from the interrupt context.....in bottom half



callback_fn_in_interrupt_context() { //some code here in_use = 0; wake_up (queue); //some more code }


Is this piece of code looks OK or is it possible that wake_up() will somehow call the schedule in some cases?



Yes. This is one of the main usage patterns pf wake_up().

regards

Wolfgang

I am using this in my sample driver but sometimes it gives me an error "Scheduling while atomic" . Below is the call trace that I was getting at my end:

scheduling while atomic: mymodule/0xffffff00/564

Call Trace:

[] schedule+0x74/0x980 [] __wake_up+0x34/0x64 [] schedule+0x0/0x980 [] prepare_to_wait+0x0/0x7c [] fn_in_process_context+0x32c/0x578 [mymodule] [] irq_exit+0x40/0x4c [] __do_softirq+0x68/0xec [] autoremove_wake_function+0x0/0x44 [] __copy_user+0x0/0x1c [] autoremove_wake_function+0x0/0x44 [] autoremove_wake_function+0x0/0x44

I am running my driver on 2.6.14 kernel on MIPS architecture. Then what is the possible reason of this error if wake_up() is not the culprit here?

"Linux Device drivers" says "wait_event_interruptible() is preferred over wait_event()".

-Michael

But I don't think that this is creating the problem here as this is called from the process context. I used the wait_event() function so that spurious signals will not wake up my process.

Hi,

You got the message "schedule while atomic". That means you may use some functions to involve the schedule call in your interrupt context. For example, sleep_on, etc. Copy_to_user, etc. You need check your code again and make no such functions existing in the interrupt contxt. You know, the schedule function will be called after the end of interrupt.

Take care

Gaurav wrote:

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required