C语言 如何解决“BUG: schedule while atomic: swapper /0x00000103/0, CPU#0”?在 TSC2007 驱动程序中?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3537252/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to solve "BUG: scheduling while atomic: swapper /0x00000103/0, CPU#0"? in TSC2007 Driver?
提问by Ali Bing?l
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
我找到了tsc2007驱动,并根据我们的需要进行了修改。我们公司正在生产自己的 TI DM365 板。在这块板上,我们使用了 TSC2007 并将 PENIRQ 引脚连接到 DM365 的 GPIO0。在驱动程序上显示正常。当我触摸触摸屏光标正在移动但同时我得到
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.zipone is with timer the other is not. it is giving this error in any case.
警告和嵌入式 Linux 正在崩溃。我修改了 2 个文件并上传到http://www.muhendislikhizmeti.com/touchscreen.zip一个是带计时器的,另一个不是。它在任何情况下都会出现此错误。
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.
我在网上找到了一个解决方案,我需要使用工作队列并使用 schedule_work() API 进行调用。但他们现在对我来说很模糊。有没有人知道如何解决这个问题,并且可以给我一些建议,从哪里开始使用工作队列。
回答by caf
"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().
的东西,可以睡常见的例子是mutex_lock(),kmalloc(..., GFP_KERNEL),get_user()和put_user()。
回答by ag lotfi
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.
正如在第一个答案中所说的那样,当调度程序感到困惑并因此无法正常工作时,会发生原子性调度,这是因为调度程序试图在包含不可调度代码的部分中执行“schedule()” .
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
例如,在受自旋锁保护的部分内使用 sleeps。尝试在受自旋锁保护的代码中使用另一个锁(信号量、互斥锁...)也可能会干扰调度程序。此外,在用户空间中使用自旋锁可以驱动调度程序这样做。希望这可以帮助
回答by Luke Wren
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_NOWAITor GFP_ATOMIC.
对于其他有类似错误的人 - 我遇到了这个问题,因为我有一个从原子上下文调用的函数,该函数kzalloc(..., GFP_KERN)在应该使用GFP_NOWAITor时使用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!
希望这对其他人有用!
回答by Zeb
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();

