您的位置:首页 > 其它

shedule()调用时机

2011-09-08 17:15 120 查看
schedule()的调用意味着一个进程从cpu上拉下来,另一个进程即将获得时间片

7.4.4. The schedule( ) Function
The schedule( ) function implements the scheduler. Its objective is to find a process in the runqueue list and then assign the CPU to it. It is invoked, directly or in a lazy (deferred)
way, by several kernel routines.

可以是直接调用,也可以是被几个内核路径延迟调用

7.4.4.1.Direct invocation
The scheduler is invoked directly when the current process must be blocked right away because the resource it needs is not available. In this case, the kernel routine that wants to block it proceeds as follows:

Inserts current in the proper wait queue.

Changes the state of current either to TASK_INTERRUPTIBLE or to TASK_UNINTERRUPTIBLE.

Invokes schedule( ).

Checks whether the resource is available; if not, goes to step 2.

Once the resource is available, removes current from the wait queue.

The kernel routine checks repeatedly whether the resource needed by the process is available; if not, it yields the CPU to some other process by invoking schedule( ). Later, when the scheduler once again grants
the CPU to the process, the availability of the resource is rechecked. These steps are similar to those performed by wait_event( ) and similar functions described in the section "How
Processes Are Organized" in
Chapter 3.
The scheduler is also directly invoked by many device drivers that execute long iterative tasks. At each iteration cycle, the driver checks the value of the TIF_NEED_RESCHED flag and, if necessary, invokes
schedule( ) to voluntarily relinquish the CPU.
7.4.4.2.Lazy invocation
The scheduler can also be invoked in a lazy way by setting the TIF_NEED_RESCHED flag of current to 1. Because a check on the value of this flag is always made before resuming the execution of a User Mode process
(see the section "Returning from Interrupts and Exceptions" inChapter 4), schedule( ) will definitely
be invoked at some time in the near future.
Typical examples of lazy invocation of the scheduler are:

When current has used up its quantum of CPU time; this is done by the scheduler_tick( ) function.

When a process is woken up and its priority is higher than that of the current process; this task is performed by the try_to_wake_up( ) function.

When a sched_setscheduler( ) system call is issued (see the section "System Calls Related to Scheduling" later in this
chapter).

.....

"一个进程时间片用完时,插入到活动队列或过期队列

一个进程主动放弃时间片,插入到过期队列

一个进程得不到资源,插入到等待队列

一个进程主动插入到等待队列"

上面是一个猜测,先放在这里
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息