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).
.....
"一个进程时间片用完时,插入到活动队列或过期队列
一个进程主动放弃时间片,插入到过期队列
一个进程得不到资源,插入到等待队列
一个进程主动插入到等待队列"
上面是一个猜测,先放在这里
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).
.....
"一个进程时间片用完时,插入到活动队列或过期队列
一个进程主动放弃时间片,插入到过期队列
一个进程得不到资源,插入到等待队列
一个进程主动插入到等待队列"
上面是一个猜测,先放在这里
相关文章推荐
- AppDelegate中几个常用的回调调用时机
- C++中构造函数和析构函数调用的时机
- struts的reset调用时机
- android 系统回调onSizeChange, onMeasure, onLayout调用时机
- iOS scrollViewDidScroll:调用时机
- static方法与非static方法之间区别和调用的时机
- 拷贝构造函数3.调用时机
- Activity的onSaveInstanceState和onRestoreInstanceState调用的时机
- onActivityResult()和setResult()的调用时机
- onSaveInstanceState(Bundle outState)的调用时机
- 拷贝构造函数调用时机3
- Linux的进程调度时机(Schedule函数何时调用)
- iOS UIView layoutSubviews调用时机
- 拷贝构造函数调用时机
- Spring中事务管理的不同时机切入调用
- 构造代码块与静态代码块的调用时机
- schedule()函数的调用时机(周期性调度)
- activity ondestory()的调用时机
- Appdelegate 调用时机
- UIView的drawRect调用时机和条件