I want to sleep while holding a mutex

I need to write to and read from a Ethernet chip's FIFO and for that I want to use DMA controller. So I modified an existing driver and made the process to sleep using wait_event_interruptible after triggering DMA transfer and made it woken up by ISR using wake_up_interruptible. My problem is that the original driver was using spinlock to protect the FIFO access. But as all know, while holding spinlock, I should not sleep. So I tried replacing spinlock with mutex. (Because, I might sleep while acquiring the mutex, and after getting the mutex, I'll sleep again after DMA trigger. I get woken up by the ISR, and I'll release the mutex. No problem! I thought. ) But I still get this 'scheduling while atomic BUG'. The question is : I need to go to sleep until DMA completion while holding a lock (for FIFO read and write). Isn't it ok to sleep while holding a mutex?
ADD : In my case, the receive function reading the receive FIFO was NAPI poll function which is a one of softirq (interrupt mask is reset, but still it's interrupt context. tasklet is also interrupt context). To read FIFO I use DMA and goto sleep, so this was the problem : sleeping during softirq.


It is OK to sleep while holding a mutex.

scheduling while atomic BUG refers to sleeping in atomic context. Probably, you forget to unlock some lock, or you try to sleep in interrupt handler.

链接地址: http://www.djcxy.com/p/84886.html

上一篇: 从()内核的函数实际工作?

下一篇: 我想睡一边拿着一个互斥体