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

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?

Reply to
grv.aggarwal
Loading thread data ...

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

regards

Wolfgang

Reply to
Wolfgang Mües

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?

Reply to
grv.aggarwal

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

-Michael

Reply to
Michael Schnell

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.

Reply to
Gaurav

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:

Reply to
tony

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.