How to solve "BUG: scheduling while atomic: swapper /0x00000103/0, CPU#0"? in TSC2007 Driver?

22

I found tsc2007 driver and modified according to our needs. Our firm is producing its own TI DM365 board. In this board we used TSC2007 and connected PENIRQ pin to GPIO0 of DM365. It is being seen OK on driver. when i touch to touchscreen cursor is moving but at the same time i am getting

BUG: scheduling while atomic: swapper /0x00000103/0, CPU#0

warning and embedded Linux is being crashed. there are 2 files that i modified and uploaded to http://www.muhendislikhizmeti.com/touchscreen.zip one is with timer the other is not. it is giving this error in any case.

I found a solution on web that i need to use work queue and call with using schedule_work() API. but they are blur for me now. Is anybody have any idea how to solve this problem and can give me some advice where to start to use work queue.

c
linux-kernel
asked on Stack Overflow Aug 21, 2010 by Ali Bing√∂l • edited Aug 22, 2010 by John Saunders

4 Answers

33

"Scheduling while atomic" indicates that you've tried to sleep somewhere that you shouldn't - like within a spinlock-protected critical section or an interrupt handler.

Common examples of things that can sleep are mutex_lock(), kmalloc(..., GFP_KERNEL), get_user() and put_user().

answered on Stack Overflow Aug 23, 2010 by caf • edited Oct 9, 2015 by caf
14

Exactly as said in 1st answer, scheduling while atomic happens when the scheduler gets confused and therefore unable to work properly and this because the scheduler tried to perform a "schedule()" in a section that contains a schedulable code inside of a non schedulable one.

For example using sleeps inside of a section protected by a spinlock. Trying to use another lock(semaphores,mutexes..) inside of a spinlock-proteced code may also disturb the scheduler. In addition using spinlocks in user space can drive the scheduler to behave as such. Hope this helps

answered on Stack Overflow Dec 2, 2011 by ag lotfi • edited Feb 8, 2016 by √Čtienne
5

For anyone else with a similar error - I had this problem because I had a function, called from an atomic context, that used kzalloc(..., GFP_KERN) when it should have used GFP_NOWAIT or GFP_ATOMIC.

This is just one example of a function sleeping when you don't want to, which is something you have to be careful of in kernel programming.

Hope this is useful to somebody else!

answered on Stack Overflow Aug 15, 2015 by Luke Wren
2

Thanks for the former two answers, in my case it was enough to disable the preemption:

preempt_disable();

// Your code with locks and schedule()

preempt_enable();
answered on Stack Overflow Feb 14, 2014 by Zeb

User contributions licensed under CC BY-SA 3.0