大虾留步,“BUG: scheduling while atomic:” 是怎么回事啊?

olla168 2009-08-12 07:20:07
程序中起了一个线程,有调用wait_event_interruptible(),估计应该是调用schedule时,在schedule打印出来的。

只是这里想不明白if (unlikely(in_atomic() && !current->exit_state)) 这个条件一般什么时候满足?可能是什么原因呢?

从程序上看,那个线程不会在原子上下文运行呢~~ 想不明白啊~~ 大虾指点下啊~~

#define __wait_event_interruptible(wq, condition, ret)			\
do { \
DEFINE_WAIT(__wait); \
\
for (;;) { \
prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE); \
if (condition) \
break; \
if (!signal_pending(current)) { \
schedule(); \
continue; \
} \
ret = -ERESTARTSYS; \
break; \
} \
finish_wait(&wq, &__wait); \
} while (0)

#define wait_event_interruptible(wq, condition) \
({ \
int __ret = 0; \
if (!(condition)) \
__wait_event_interruptible(wq, condition, __ret); \
__ret; \
})

asmlinkage void __sched schedule(void)
{
struct task_struct *prev, *next;
struct prio_array *array;
struct list_head *queue;
unsigned long long now;
unsigned long run_time;
int cpu, idx, new_prio;
long *switch_count;
struct rq *rq;

/*
* 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() && !current->exit_state)) {
printk(KERN_ERR "BUG: scheduling while atomic: "
"%s/0x%08x/%d\n",
current->comm, preempt_count(), current->pid);
debug_show_held_locks(current);
if (irqs_disabled())
print_irqtrace_events(current);
dump_stack();
}
profile_hit(SCHED_PROFILING, __builtin_return_address(0));

need_resched:
//...
}


呵呵,本来帖子问题点数想给100分的,可惜只能给60~~ 呵呵,大虾别介意啊~~ 继续指点继续指点~~
...全文
5127 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
eddiezhou 2010-12-31
  • 打赏
  • 举报
回复
遇到同样问题了
hefuhua 2009-08-12
  • 打赏
  • 举报
回复
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


为0表示TASK_RUNNING状态,也就是说原子状态,而且当前进程在运行,那么就不能切换给其它的进程
olla168 2009-08-12
  • 打赏
  • 举报
回复
“当前进程的退出状态为0”是什么意思?
hefuhua 2009-08-12
  • 打赏
  • 举报
回复
不是大侠,是老兵

if (unlikely(in_atomic() && !current->exit_state))
我理解是在原子操作中,且当前进程的退出状态为0,那么schedule()是切换进程的,我们知道在原子状态是不能切换进程的,所以这个条件为bug

4,467

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 内核源代码研究区
社区管理员
  • 内核源代码研究区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧