BUG: scheduling while atomic 分析【转】
本文转载自:https://blog.csdn.net/cfy_phonex/article/details/12090943
遇到一个典型的schedule问题。
- <3>[26578.636839] C1 [ swapper/1] BUG: scheduling while atomic: swapper/1/0/0x00000002
- <6>[26578.636869] C0 [ kworker/u:1] CPU1 is up
- <4>[26578.636900] C1 [ swapper/1] Modules linked in: bcm15500_i2c_ts
- <4>[26578.636961] C1 [ swapper/1] [<c00146d0>] (unwind_backtrace+0x0/0x11c) from [<c0602684>] (__schedule+0x70/0x6e0)
- <4>[26578.636991] C1 [ swapper/1] [<c0602684>] (__schedule+0x70/0x6e0) from [<c06030ec>] (schedule_preempt_disabled+0x14/0x20)
- <4>[26578.637052] C1 [ swapper/1] [<c06030ec>] (schedule_preempt_disabled+0x14/0x20) from [<c000f05c>] (cpu_idle+0xf0/0x104)
- <4>[26578.637083] C1 [ swapper/1] [<c000f05c>] (cpu_idle+0xf0/0x104) from [<c05e98e0>] (cpu_die+0x2c/0x5c)
- <3>[26578.637510] C1 [ swapper/1] BUG: scheduling while atomic: swapper/1/0/0x00000002
- <4>[26578.637510] C1 [ swapper/1] Modules linked in: bcm15500_i2c_ts
- <4>[26578.637602] C1 [ swapper/1] [<c00146d0>] (unwind_backtrace+0x0/0x11c) from [<c0602684>] (__schedule+0x70/0x6e0)
- <4>[26578.637663] C1 [ swapper/1] [<c0602684>] (__schedule+0x70/0x6e0) from [<c06030ec>] (schedule_preempt_disabled+0x14/0x20)
- <4>[26578.637724] C1 [ swapper/1] [<c06030ec>] (schedule_preempt_disabled+0x14/0x20) from [<c000f05c>] (cpu_idle+0xf0/0x104)
- <4>[26578.637754] C1 [ swapper/1] [<c000f05c>] (cpu_idle+0xf0/0x104) from [<c05e98e0>] (cpu_die+0x2c/0x5c)
- <3>[26578.648069] C1 [ swapper/1] BUG: scheduling while atomic: swapper/1/0/0x00000002
查看源代码
- /*
- * __schedule() is the main scheduler function.
- */
- static void __sched __schedule(void)
- {
- struct task_struct *prev, *next;
- unsigned long *switch_count;
- struct rq *rq;
- int cpu;
- need_resched:
- preempt_disable();
- cpu = smp_processor_id();
- rq = cpu_rq(cpu);
- rcu_note_context_switch(cpu);
- prev = rq->curr;
- schedule_debug(prev);
- ....
- }
- /*
- * Print scheduling while atomic bug:
- */
- static noinline void __schedule_bug(struct task_struct *prev)
- {
- if (oops_in_progress)
- return;
- printk(KERN_ERR "BUG: scheduling while atomic: %s/%d/0x%08x\n",
- prev->comm, prev->pid, preempt_count());
- debug_show_held_locks(prev);
- print_modules();
- if (irqs_disabled())
- print_irqtrace_events(prev);
- dump_stack();
- }
- /*
- * Various schedule()-time debugging checks and statistics:
- */
- static inline void schedule_debug(struct task_struct *prev)
- {
- /*
- * Test if we are atomic. Since do_exit() needs to call into
- * schedule() atomically, we ignore that path for now.
- * Otherwise, whine if we are scheduling when we should not be.
- */
- if (unlikely(in_atomic_preempt_off() && !prev->exit_state))
- __schedule_bug(prev);
- rcu_sleep_check();
- profile_hit(SCHED_PROFILING, __builtin_return_address(0));
- schedstat_inc(this_rq(), sched_count);
- }
可以看出, 满足如下条件将会打印该出错信息
unlikely(in_atomic_preempt_off() && !prev->exit_state
为0表示TASK_RUNNING状态,当前进程在运行; 并且处于原子状态,,那么就不能切换给其它的进程
Linux/include/linux/sched.h
- /*
- * Task state bitmask. NOTE! These bits are also
- * encoded in fs/proc/array.c: get_task_state().
- *
- * We have two separate sets of flags: task->state
- * is about runnability, while task->exit_state are
- * about the task exiting. Confusing, but this way
- * modifying one set can't modify the other one by
- * mistake.
- */
- #define TASK_RUNNING 0
- #define TASK_INTERRUPTIBLE 1
- #define TASK_UNINTERRUPTIBLE 2
- #define __TASK_STOPPED 4
- #define __TASK_TRACED 8
- /* in tsk->exit_state */
- #define EXIT_ZOMBIE 16
- #define EXIT_DEAD 32
- /* in tsk->state again */
- #define TASK_DEAD 64
- #define TASK_WAKEKILL 128
- #define TASK_WAKING 256
- #define TASK_STATE_MAX 512
- kernel/include/linux/hardirq.h
- #if defined(CONFIG_PREEMPT_COUNT)
- # define PREEMPT_CHECK_OFFSET 1
- #else
- # define PREEMPT_CHECK_OFFSET 0
- #endif
- /*
- * Are we running in atomic context? WARNING: this macro cannot
- * always detect atomic context; in particular, it cannot know about
- * held spinlocks in non-preemptible kernels. Thus it should not be
- * used in the general case to determine whether sleeping is possible.
- * Do not use in_atomic() in driver code.
- */
- #define in_atomic() ((preempt_count() & ~PREEMPT_ACTIVE) != 0)
- /*
- * Check whether we were atomic before we did preempt_disable():
- * (used by the scheduler, *after* releasing the kernel lock)
- */
- #define in_atomic_preempt_off() \
- ((preempt_count() & ~PREEMPT_ACTIVE) != PREEMPT_CHECK_OFFSET)
结论整理
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"这样的错误!
禁止内核抢占是指内核不会主动的抢占你的process,但是现在是你在自己的程序中主动call schedule(),
kernel并不能阻止你这么作。
Scheduling while atomic" means that a thread has called schedule() during an operation which is supposed to be atomic (ie uninterrupted).
- 190 NOTE: ***** WARNING *****
- 191 NEVER SLEEP IN A COMPLETION HANDLER. These are normally called
- 192 during hardware interrupt processing. If you can, defer substantial
- 193 work to a tasklet (bottom half) to keep system latencies low. You'll
- 194 probably need to use spinlocks to protect data structures you manipulate
- 195 in completion handlers.
- GFP_ATOMIC is used when
- (a) you are inside a completion handler, an interrupt, bottom half, tasklet or timer, or
- (b) you are holding a spinlock or rwlock (does not apply to semaphores), or
- (c) current->state != TASK_RUNNING, this is the case only after you've changed it.
BUG: scheduling while atomic 分析【转】的更多相关文章
- linux内核打印"BUG: scheduling while atomic
linux内核打印"BUG: scheduling while atomic"和"bad: scheduling from the idle thread"错误 ...
- BUG: scheduling while atomic: events/0/4/总结
对于Linux内核来说,Oops就意外着内核出了异常,此时会将产生异常时CPU的状态,出错的指令地址.数据地址及其他寄存器,函数调用的顺序甚至是栈里面的内容都打印出来,然后根据异常的严重程度来决定下一 ...
- Android BroadcastAnyWhere(Google Bug 17356824)漏洞具体分析
Android BroadcastAnyWhere(Google Bug 17356824)漏洞具体分析 作者:简行(又名 低端码农) 继上次Android的LaunchAnyWhere组件安全漏洞后 ...
- 线上BUG:MySQL死锁分析实战
原文链接:线上BUG:MySQL死锁分析实战 1 线上告警 我们不需要关注截图中得其他信息,只要能看到打印得org.springframework.dao.DeadlockLoserDataAcces ...
- [技术讨论]关于前几天公布的京东bug上的问题分析
1. 起因 前两天我公布了一个京东微信端截取到的三张图.并简单阐述了这三张图中的bug发现过程: 有朋友的评价是图中这种,可实际上.他应该是没有看出来这个bug代表的内容有多少.今天心血来潮决定具体 ...
- 一个友盟BUG的思考和分析:Invalid update
1.友盟错误信息 Invalid update: invalid number of rows . The number of rows contained ) must be equal to th ...
- BUG的定位与分析思路
一般来说bug大多数存在于3个模块: 1.前台界面,包括界面的显示,兼容性,数据提交的判断,页面的跳转等等,这些bug基本都是一眼可见的,不太需要定位,当然也不排除一些特殊情况,本身数据传过来的时候就 ...
- scheduling while atomic 出现的错误
产生这种情况的原因: 1.当中断发生时,出现了调度做法, 2.另一个是spin_lock 里调用sleep, 让出调度, 另外线程又进行spin_lock, 导致死锁. 相关问题的链接 1.为 ...
- scheduling while atomic和bad: scheduling from the idle thread(转)
https://blog.csdn.net/shanzhizi/article/details/22949121 https://blog.csdn.net/wwwtovvv/article/deta ...
随机推荐
- django数据库读写分离,分库
读写分离 在settings中配置不同名称的数据库连接参数,并配置一条数据库选择路由 DATABASES = { 'default': { 'ENGINE': 'django.db.backends. ...
- Linux下搜索文件find、which、whereis、locate
Linux下搜索文件find.which.whereis.locate: - which 寻找“执行文件” - -a 将所有可找到的命令均列出,而不仅仅列出第一个找到的命令名称 - whereis 寻 ...
- Servlet监听器与Timer定时器配合实现JAVA WEB应用简单自动作业
在web应用中,有时候客户需要一些定时程序,不需要客户自己去操作,而是由应用程序自行触发执行某些操作.这个时候监听与定时器的配合使用就基本可以实现这个需求了. 1.创建一个监听的SERVELET,这个 ...
- 6号css学习小记
一.overfloat属性:(四个值) visible :默认值.内容不会被修剪,会呈现在元素匡之外. hidden:内容会被修剪,并且其余内容是不可见的. scroll :内容会被修剪,但是浏览器会 ...
- 关于redux应用
redux 有点类似flux.但是我觉得远比flux要复杂.因为他非常的绕.一般搭配使用是redux 和react-redux 使用. 主要的思路就是: 写action:动作类型 写reducer:动 ...
- Java——BeanUtils基本用法
为了操作JavaBean的属性,sun公司自己写了一套内省的api(在Java.beans.*)中,但是我们发现操作起来还是比较复杂的,所以apache公司就自己写了一套api替代了它,大大方便了开发 ...
- ZooKeeper 基本介绍
Zookeeper 作为一个分布式的服务框架,主要用来解决分布式集群中应用系统的一致性问题,它能提供基于类似于文件系统的目录节点树方式的数据存储, Zookeeper 作用主要是用来维护和监控存储的数 ...
- window下使用mysql,报未定义标识符"SOCKET"
解决方法一: 这个错误是在VC中使用MySQL数据库时出现在mysql_com.h文件中的 my_socket fd; 说明未my_socket未定义,这时只需要在引用mysql.h头文件之前引用# ...
- 如何cancel掉慢查询
百度Elasticsearch-产品描述-介绍-百度云 https://cloud.baidu.com/doc/BES/FAQ.html#.E5.A6.82.E4.BD.95cancel.E6.8E. ...
- Open System Interconnection
https://zh.wikipedia.org/wiki/Secure_Shell Secure Shell(缩写为SSH),由IETF的网络工作小组(Network Working Group)所 ...