kernel version 2.6.32-431
sched.h:205-207:
这里是对TASK_ALL宏的定义,注释也说明了该宏也是用于wake_up的
/* Convenience macros for the sake of wake_up */
#define TASK_NORMAL (TASK_INTERRUPTIBLE | TASK_UNINTERRUPTIBLE)
#define TASK_ALL (TASK_NORMAL | __TASK_STOPPED | __TASK_TRACED)
sched.c:
2680-2695:
对于新建task,由于尚未加入任何等待队列,所以不会被__wake_up()系列函数唤醒,好像也只可能被wake_up_process()唤醒
/**
* wake_up_process - Wake up a specific process
* @p: The process to be woken up.
*
* Attempt to wake up the nominated process and move it to the set of runnable
* processes. Returns 1 if the process was woken up, 0 if it was already
* running.
*
* It may be assumed that this function implies a write memory barrier before
* changing the task state if and only if any tasks are woken up.
*/
int wake_up_process(struct task_struct *p)
{
return try_to_wake_up(p, TASK_ALL, 0);
}
EXPORT_SYMBOL(wake_up_process);
2549-2678:
/***
* try_to_wake_up - wake up a thread
* @p: the to-be-woken-up thread
* @state: the mask of task states that can be woken
* @sync: do a synchronous wakeup?
*
* Put it on the run-queue if it's not already there. The "current"
* thread is always on the run-queue (except when the actual
* re-schedule is in progress), and as such you're allowed to do
* the simpler "current->state = TASK_RUNNING" to mark yourself
* runnable without the overhead of this.
*
* returns failure only if the task is already active.
*/
static int try_to_wake_up(struct task_struct *p, unsigned int state,
int wake_flags)
{
int cpu, orig_cpu, this_cpu, success = 0;
unsigned long flags;
unsigned long en_flags = ENQUEUE_WAKEUP;
struct rq *rq;
this_cpu = get_cpu();
smp_wmb();
rq = task_rq_lock(p, &flags);
/*此处对task的state进行判断*/
if (!(p->state & state))
goto out;
......
核心思想就是在对task结构初始化完成前,不要让task进入running queue,所以把可能导致task进入running queue的路径堵死。
欢迎指正:)
在 2016年8月30日星期二 UTC+8下午5:54:49,Gao Feng写道: