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;
}
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;
}
相关文章推荐
- Code view is missing in SharePoint Designer Beta 2 when you try to edit a WSS v3 site.
- Unable to find the report in the manifest resources. Please build the project, and try again.
- [转] Try to use one var statement per scope in JavaScript
- Error 0x80070020 when you try to start a Web site in IIS 7.0
- How to pass a input parameter in Script task of SSIS
- 为什么实际内存使用量已经超过了memory.soft_limit_in_bytes,但是并没有立即触发try_to_free_pages in try_charge
- A bug in PackageInstaller app. Relate to activity task affinity.
- Try to find out the wrong in the test
- In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.
- [导入]How to keep a local variable in scope across a try and catch block?
- Idling along, (or what to do in the idle task)
- On a new installed FreeBSD server, when you try to SSH to the server as root, you will end up in the
- JZOJ 5521 Try to find out the wrong in the test
- Try to use "twisted.enterprise.adbapi" accessing database nonblockingly in Twisted (failed)
- Task Scheduler faild to launch action "C:\Windows\SYSTEM32\cmd.exe" in instance "{xxx}" of task "\ca
- Problems in mapping parameters of type Int64 to the Execute SQL Task
- do not try to modified the value in const region
- The project was not built due to "Could not delete ...".Fix the problem, then try refreshing this project and building it since it may be inconsistent.
- Using TRY/CATCH to Resolve a Deadlock in SQL Server 2005
- How to attach multiple files in the Send Mail Task in SSIS