|
Run queue
When the Linux kernel to look for a new process to run on the CPU, you must consider only the process is runnable state (ie process TASK_RUNNING state), because the process of scanning the entire list is quite inefficient, so the introduction of the runs two-way circular linked list state of the process, also called the run queue (runqueue).
Run queue to accommodate the system can run all the processes, it is a two-way circular queue
The queue by task_struct structure pointer run_list two lists to maintain. Flag queue has two: one is "empty process" idle_task, a queue length.
There are two special processes in the run queue forever alone: the current process and empty process. Earlier we discussed before, the current process is pointed to by the pointer cureent process that is currently running process, but please note, current pointer in the scheduling process (scheduler execution) does not make sense, why do you say? Before scheduling, the current process is running, when there is a scheduling opportunity sparked process scheduling, previously running process what state is unknown, in most cases in a wait state, so current at this time makes no sense, http: //Ubuntuone.cn/ until the scheduler selected a process put into operation, current really points to the currently running process; empty process is a special process that can only run the system does not process it will be executed, Linux run it as the head of the queue when the scheduler run queue traversal, from idle_task beginning to idle_task end, the scheduler is running, allowed to join the queue of runnable processes emerging, emerging runnable processes inserted into the tail, so that the benefits will not affect the members of the scheduler queue to be traversed, visible, idle_task is a very important sign of the run queue.
Another important symbol is the queue length, that is, the system can be run in a number of state (TASK_RUNNING) process, with a global integer variable nr_running representation, /kernel/fork.c defined in the following:
int nr_running = 1;
If nr_running is 0, it means that only empty queue process. Here to explain: If nr_running 0, the system of the current process and empty process is the same process. However, Linux will make full use of CPU and try to avoid this situation. |
|
|
|