CPU Scheduling进程调度算法
1.Preemptive scheduling
CPU scheduling decisons may take place under the following four conditions:
1.when a process switches from running state to the waiting state(for example, I/O Request , or invocation of waif wait for the termination of one of the child processes)
2. when a process switches from the running state to the ready state ,for example ,when an interupt occurs
3. when a process switches from the waiting state to the ready state,for example, completion of I/O。
4. when a process terminates.
when scheduling takes place only under circumstances 1 and 4, we say the scheduling cheme is nonpreepmtive; otherwise, the schedulign is preemptive.
2.Dispatcher
The dispatcher is the module that gives control of the CPU to the process selected by the short-term scheduler. This function involves:
Switching context;
switching to user mode;
jumping to the proper location in the user program to the restart that program.
The dispatcher should be as fast as possible, given that it is invoked during every process switch. The time it takes for the dispatcher to stop one process and start anohter running is known as the dispatch latency.
3 Scheduling Criteria
1.CPU utilization:
we want to keep the cpu as busy as possible. CPU Utilization may range from 0 to 100 percent. in a real system, it should range from 40 percent to 90 percen.
2.Throughput:
If the CPU is busy executing processes, then work is being done. One measure of work is the number of processes completed per time unit, called throughput.
3.Turnaround time:
from the point of view of a particular process, the important criterion is how long it takes to execute that process. The inverval from the time of submission of a process to the time of completion is the turnaround time. TurnAround time is the sum of the periods spent waiting to get into memory, waiting in the ready queue,executing on the CPU, and doing I/O.
4.Waiting Time &Response Time.
4. Scheduling Algorithms
CPU scheduling deals with the problem of deciding which of the processes in the ready queue is to be allocated the CPU.
1.FCFS(First Come Fist Served Scheduling)
with this schema, the process that requests the cpu first is allocated the cpu first. The implemention of the FCFS policy is easily managed with a FIFO queue. When the CPU is free, it is allocated to the process at the head of the queue. The running process is then removed form the queue.
2. Shortest-Job-First scheduling(SJF scheduling)
The algorithm associates with each process the length of the latter's next cpu burst. When the cpu is available, it is assigned to the process that has the smallest next CPU burst. If two processes have the same length next CPU burst, FSCS schedulign is used to break the tie.
The SJF schedulig algorithm is probably opitmal. The real difficulty with the SJF algorithm is knowning the length of the next CPU burst. There is no way to know to know the length of the next CPU burst.
3. Priority Scheduling
The SJF algorithm is a special case of the general priority-scheduling algotithm. A priority is assolcaited with each process, and the CPU is allocated to the process with the highest priority. Equal-priority processes are schuduled in FCFS order.
An SJF algorithm is simply a priority algorhm where the priority is the inverse of the (predicted) next CPU burst. the larger the CPU burst, the lower the priority.
A major problem with priority-scheduling algorithms is indefinte blockhing(or starvation). In a heavlly loaded computer system, a steady stream of higher-priority processes can prevent a low-priority process from ever getting the CPU.
A solution to the problem of indefinite blockage of low-priority processes is aging. Aging is a technique of gradually increasing the priority of the processes taht wait in the system for a long time. For example, if priorities range from 127(low) to 0(high), we could decremet the priority of a waiting process by 1 every 15 minites. Eventually, even a process with an initial priority of 127 would have the highest priority in the sytem and would be executed.
4.Round-Robin Scheduling
The round-robin(RR) scheduling is designed especially for time-sharing system. It is similiar to FCFS scheduling, but preemption is added to switch between process. A small unit a time, called a time quantum( or time slice), is defined. A time quantum is generally from 10 to 100 miliseconds. The read queue is treated as a curcular queue. The CPU schedule goes around the ready queue, allocating the CPU to each process for a time interval of up to 1 time quantum.
5.Multi-level Queue Scheduling
A multi-level queue-scheduling algorithm partitions the ready queue into several separate queues. The processes are permanently assisgned to one queue, generally based on some property of the process, such as memory size, process priority, or process type. Each Queue has its own scheduling algorithm.
6.Multi-level Feedback Queue scheduling
Normally, in a multi-level queue-scheduling algorithm, processes are permanently assigned to a queue on entry to the system. Processes do not move between queues.
Multi-level FeedBack queue-scheduling algorithm, however, allows a process to move between queues. The idea is to separate processes with different cpu-burst characteristics. If a process uses too much cpu time, ti will be moved to a lower-priority queue.
CPU scheduling decisons may take place under the following four conditions:
1.when a process switches from running state to the waiting state(for example, I/O Request , or invocation of waif wait for the termination of one of the child processes)
2. when a process switches from the running state to the ready state ,for example ,when an interupt occurs
3. when a process switches from the waiting state to the ready state,for example, completion of I/O。
4. when a process terminates.
when scheduling takes place only under circumstances 1 and 4, we say the scheduling cheme is nonpreepmtive; otherwise, the schedulign is preemptive.
2.Dispatcher
The dispatcher is the module that gives control of the CPU to the process selected by the short-term scheduler. This function involves:
Switching context;
switching to user mode;
jumping to the proper location in the user program to the restart that program.
The dispatcher should be as fast as possible, given that it is invoked during every process switch. The time it takes for the dispatcher to stop one process and start anohter running is known as the dispatch latency.
3 Scheduling Criteria
1.CPU utilization:
we want to keep the cpu as busy as possible. CPU Utilization may range from 0 to 100 percent. in a real system, it should range from 40 percent to 90 percen.
2.Throughput:
If the CPU is busy executing processes, then work is being done. One measure of work is the number of processes completed per time unit, called throughput.
3.Turnaround time:
from the point of view of a particular process, the important criterion is how long it takes to execute that process. The inverval from the time of submission of a process to the time of completion is the turnaround time. TurnAround time is the sum of the periods spent waiting to get into memory, waiting in the ready queue,executing on the CPU, and doing I/O.
4.Waiting Time &Response Time.
4. Scheduling Algorithms
CPU scheduling deals with the problem of deciding which of the processes in the ready queue is to be allocated the CPU.
1.FCFS(First Come Fist Served Scheduling)
with this schema, the process that requests the cpu first is allocated the cpu first. The implemention of the FCFS policy is easily managed with a FIFO queue. When the CPU is free, it is allocated to the process at the head of the queue. The running process is then removed form the queue.
2. Shortest-Job-First scheduling(SJF scheduling)
The algorithm associates with each process the length of the latter's next cpu burst. When the cpu is available, it is assigned to the process that has the smallest next CPU burst. If two processes have the same length next CPU burst, FSCS schedulign is used to break the tie.
The SJF schedulig algorithm is probably opitmal. The real difficulty with the SJF algorithm is knowning the length of the next CPU burst. There is no way to know to know the length of the next CPU burst.
3. Priority Scheduling
The SJF algorithm is a special case of the general priority-scheduling algotithm. A priority is assolcaited with each process, and the CPU is allocated to the process with the highest priority. Equal-priority processes are schuduled in FCFS order.
An SJF algorithm is simply a priority algorhm where the priority is the inverse of the (predicted) next CPU burst. the larger the CPU burst, the lower the priority.
A major problem with priority-scheduling algorithms is indefinte blockhing(or starvation). In a heavlly loaded computer system, a steady stream of higher-priority processes can prevent a low-priority process from ever getting the CPU.
A solution to the problem of indefinite blockage of low-priority processes is aging. Aging is a technique of gradually increasing the priority of the processes taht wait in the system for a long time. For example, if priorities range from 127(low) to 0(high), we could decremet the priority of a waiting process by 1 every 15 minites. Eventually, even a process with an initial priority of 127 would have the highest priority in the sytem and would be executed.
4.Round-Robin Scheduling
The round-robin(RR) scheduling is designed especially for time-sharing system. It is similiar to FCFS scheduling, but preemption is added to switch between process. A small unit a time, called a time quantum( or time slice), is defined. A time quantum is generally from 10 to 100 miliseconds. The read queue is treated as a curcular queue. The CPU schedule goes around the ready queue, allocating the CPU to each process for a time interval of up to 1 time quantum.
5.Multi-level Queue Scheduling
A multi-level queue-scheduling algorithm partitions the ready queue into several separate queues. The processes are permanently assisgned to one queue, generally based on some property of the process, such as memory size, process priority, or process type. Each Queue has its own scheduling algorithm.
6.Multi-level Feedback Queue scheduling
Normally, in a multi-level queue-scheduling algorithm, processes are permanently assigned to a queue on entry to the system. Processes do not move between queues.
Multi-level FeedBack queue-scheduling algorithm, however, allows a process to move between queues. The idea is to separate processes with different cpu-burst characteristics. If a process uses too much cpu time, ti will be moved to a lower-priority queue.