驱动程序BUG: scheduling while atomic报错分析

问题描述
在编写SPI驱动的时候,在自旋锁保护的临界区调用了spi_sync函数,这个函数是能够引起休眠进而引起调度的。错误信息如下:

BUG: scheduling while atomic: spi_touch_threa/777/0x00000002
Modules linked in: spidev mdrv_crypto sd_mod usb_storage ehci_hcd ntfs vfat msdos fat kdrv_sdmmc mmc_block mmc_core nfsv2 nfs lockd sunrpc grace nls_utf8 cifs [last unloaded: spidev]
CPU: 1 PID: 777 Comm: spi_touch_threa Not tainted 4.9.84 #151
Hardware name: SStar Soc (Flattened Device Tree)
[<c0012465>] (unwind_backtrace) from [<c000fee3>] (show_stack+0xb/0xc)
[<c000fee3>] (show_stack) from [<c01078c3>] (dump_stack+0x57/0x70)
[<c01078c3>] (dump_stack) from [<c002efbd>] (__schedule_bug+0x3d/0x5c)
[<c002efbd>] (__schedule_bug) from [<c024c649>] (__schedule+0x39/0x2f4)
[<c024c649>] (__schedule) from [<c024c959>] (schedule+0x55/0x6c)
[<c024c959>] (schedule) from [<c024eebf>] (schedule_timeout+0x15/0x162)
[<c024eebf>] (schedule_timeout) from [<c024cff9>] (wait_for_common+0x7d/0xcc)
[<c024cff9>] (wait_for_common) from [<c016ea07>] (__spi_sync+0xf1/0x11a)
[<c016ea07>] (__spi_sync) from [<c016ea4b>] (spi_sync+0x1b/0x2c)
[<c016ea4b>] (spi_sync) from [<bf94b03f>] (spidev_sync+0x3a/0x4c [spidev])
[<bf94b03f>] (spidev_sync [spidev]) from [<bf94b453>] (spi_touch_thread+0x66/0xd8 [spidev])
[<bf94b453>] (spi_touch_thread [spidev]) from [<c002c141>] (kthread+0xa1/0xb0)
[<c002c141>] (kthread) from [<c000d581>] (ret_from_fork+0x11/0x30)

结论
linux内核打印"BUG: scheduling while atomic"和"bad: scheduling from the idle thread"错误的时候,
通常是在中断处理函数中调用了可以休眠的函数,如semaphore,mutex,sleep之类的可休眠的函数,
而linux内核要求在中断处理的时候,不允许系统调度,不允许抢占,要等到中断处理完成才能做其他事情。
因此,要充分考虑中断处理的时间,一定不能太久。
另外一个能产生此问题的是在idle进程里面,做了不该做的事情。现在Linux用于很多手持式设备,为了降低功耗,
通常的作法是在idle进程里面降低CPU或RAM的频率、关闭一些设备等等。要保证这些动作的原子性才能确保
不发生"bad: scheduling from the idle thread"这样的错误!

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值