您的位置:首页 > 其它

analysis of activate_task() involed in try_to_wakeup()

2008-12-04 21:01 363 查看
唤醒操作通过函数wake_up进行,它会唤醒指定的等待队列上的所有进程。它调用函数try_to_wake_up,该函数负责将进程设置为
TASK_RUNNING状态,调用activate_task将此进程放入可执行队列,如果被唤醒的进程优先级比当前正在运行的进程的优先级高,还有设
置need_resched标志。通常哪段代码促使等待条件达成,它就负责随后调用wake_up()函数。

The try_to_wake_up( ) function awakes a sleeping or stopped process
by setting its state to TASK_RUNNING and inserting it into the runqueue
of the local CPU.

The function receives as its parameters:

1. The descriptor pointer (p) of the process to be awakened

2. A mask of the process states (state) that can be awakened(要唤醒的进程状态集)

3. A flag (sync) that forbids the awakened process to preempt the process currently running on the local CPU

(如果sync为1则表示禁止唤醒进程p抢占当前进程)

更新唤醒进程p的平均睡眠时间sleep_avg和动态优先级prio;记录该进程唤醒前的睡眠状态;将该进程插入活跃优先级数组
static void activate_task(task_t *p, runqueue_t *rq, int local)
{
unsigned long long now;
now = sched_clock();

如果目标CPU不是本地CPU,就要补偿本地时钟器中断的偏差,这是通过计算本地CPU和目标CPU上最近一次发生时钟中断的相对时间戳来达到的
|---------------------------------------------------|
|#ifdef CONFIG_SMP |
| if (!local) { |
| runqueue_t *this_rq = this_rq(); |
| now = (now - this_rq->timestamp_last_tick) |
| + rq->timestamp_last_tick; |
| } |
|#endif |
|---------------------------------------------------|

更新唤醒进程p的平均睡眠时间sleep_avg和动态优先级prio
|--------------------------------|
| recalc_task_prio(p, now); |
|--------------------------------|

记录该进程唤醒前的睡眠状态,如果是中断服务程序调用的activate_task(),也就是说进程由中断激活,则该进程最有可能是交互式的,因此,置activated=2;否则置activated=1
|-----------------------------|
| if (!p->activated) { |
| if (in_interrupt()) |
| p->activated = 2; |
| else { |
| p->activated = 1; |
| } |
| } |
|-----------------------------|

p->timestamp = now;

将进程p插入可执行队列rq的活跃优先级数组rq->active中
|----------------------------|
| __activate_task(p, rq); |
|----------------------------|
}

static inline void __activate_task(task_t *p, runqueue_t *rq)
{
enqueue_task(p, rq->active);
rq->nr_running++;
}

static void enqueue_task(struct task_struct *p, prio_array_t *array)
{
sched_info_queued(p);
list_add_tail(&p->run_list, array->queue + p->prio);
__set_bit(p->prio, array->bitmap);
array->nr_active++;
p->array = array;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐