Scheduling

1,326 views

Published on

Published in: Education, Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,326
On SlideShare
0
From Embeds
0
Number of Embeds
78
Actions
Shares
0
Downloads
121
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Scheduling

  1. 1. Scheduling
  2. 2. Basic concept In a single-processor system only one process can run at a time. Other active processes wait their turn until the CPU is free. ● The main purpose of the multiprogramming is to have process running at all times, in order to maximize CPU utilization. ● Maximization is achieved by reducing the idle time of a process while waits for the completion of some I/O request ● Operating System 2011/2012
  3. 3. CPU – I/O Burst Cycle ● ● ● The process execution process execution consists of a cycle of CPU execution and I/O wait. The duration of the CPU execution and the I/O wait depend on the process type. Processes are divided in ● CPU bounded ● I/O bounded Operating System 2011/2012
  4. 4. CPU Scheduler A new process is scheduled by the CPU when the previous one: 1. switches from the running state to the waiting state, 2. switches from the running state to the ready state 3. switches from the waiting state to the ready state 4. terminates ● ● ● When scheduling takes place only under circumstances 1 and 4, we say that the scheduling scheme is nonpreemptive or cooperative, otherwise, it is preemptive. At the nonpreemptive scheduling is the process that autonomously releases the resource. At the preemptive scheduling is the scheduler that forces the process to interrupt and release the resource. Operating System 2011/2012
  5. 5. Dispatcher The dispatcher is the module that gives the control of the CPU to the process selected by the short-term scheduler. This module is responsible of the process switch: ● collects the information of one process to stop ● store the process stack ● load the next process stack ● give control to the CPU The time the dispatcher takes to stop one process and start another process of the queue is called dispatch latency. Operating System 2011/2012
  6. 6. Scheduling Criteria The criteria used by the algorithms to evaluate the efficiency are: ● ● ● ● ● CPU utilization: % of time where the CPU is busy. Throughput: number of processes that are completed per time unit (from mm to h). 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. Waiting time: is the sum of the periods spent waiting in the ready queue. Response time: is the time from the submission of a request until the first response is produced. Operating System 2011/2012
  7. 7. Scheduling Algorithms ● First-Come, First-Served (FCFS) ● Shortest-Job-First (SJF) ● Priority Scheduling ● Round-Robin Scheduling ● Multilevel Queue Scheduling ● Multilevel Feedback Queue Scheduling Operating System 2011/2012
  8. 8. First-Come, First-Served (FCFS) ● Simplest CPU-scheduling algorithm. ● The process that requests the CPU first is allocated the CPU first (managed by the FIFO queue) . ● ( + ) The code for FCFS scheduling is simple to write and understand. ● ( - ) The average waiting time under the FCFS policy is often quite long. Operating System 2011/2012
  9. 9. First-Come, First-Served (FCFS) Suppose that the processes arrive in the order: P1 , P2 , P3, with the respective computation time: 24, 3, 3. Waiting time for: ● P1 = 0 – no process to wait; ● P2 = 24 – starts after P1; ● P3 = 27 – starts after P1 and P2; Average waiting time: (0 + 24 + 27)/3 = 17 Operating System 2011/2012
  10. 10. First-Come, First-Served (FCFS) Suppose that the processes arrive in the order P2 , P3 , P1 with the respective computation time: 3, 3, 24. Waiting time for: ● P2 = 0 – no process to wait; ● P3 = 3 – starts after P2; ● P1 = 6 – starts after P2 and P3; Average waiting time: (0 + 3 + 6) / 3 = 3 Operating System 2011/2012
  11. 11. First-Come, First-Served (FCFS) FCFS is non-preemptive ● Not good for time sharing systems where where each user needs to get a share of the CPU at regular intervals. ● Convoy effect short process(I/O bound) wait for one long CPU-bound process to complete a CPU burst before they get a turn ● ➢ ➢ ➢ ➢ ➢ lowers CPU and device utilization I/O bound processes complete their burst and enter ready queue – I/O devices idle and I/O bound processes waiting CPU bound process completes CPU burst and moves to I/O device I/O bound processes all quickly complete their CPU bursts and enter I/O queue – now CPU is idle CPU bound completes I/O and executes on CPU; back to step 1 Operating System 2011/2012
  12. 12. Shortest-Job-First (SJF) Shortest-Next-CPU-Burst algorithm. ● This algorithm associates with each process the length of the process’s next CPU burst. ● If the next CPU bursts of two processes are the same, FCFS scheduling is used. ● Two schemes: ● ● ● ● nonpreemptive – once CPU given to the process it cannot be preempted until completes its CPU burst. preemptive – if a new process arrives with CPU burst length less than remaining time of current executing process, preempt. This scheme is know as the Shortest-RemainingTime-First (SRTF). SJF is optimal – gives minimum average waiting time for a given set of processes. Operating System 2011/2012
  13. 13. Shortest-Job-First (SJF) Suppose that the processes arrive in the order: P1 , P2 , P3, P4 with the respective computation time: 6, 8, 7, 3. Waiting time for: ● P4 = 0 – no process to wait; ● P1 = 3 – starts after P4; ● P3 = 9 – starts after P4 and P1; ● P2 = 16 – starts after P4, P1 and P3; Average waiting time: (3 + 16 + 9 + 0)/4 = 7 Operating System 2011/2012
  14. 14. Shortest-Job-First (SJF) Suppose that the processes arrive in the order: P1 , P2 , P3, P4 with the respective computation time: 8, 4, 9, 3. Waiting time for: ● P4 = 0 – no process to wait; ● P2 = 3 – starts after P4; ● P3 = 9 – starts after P4 and P1; ● P2 = 16 – starts after P4, P1 and P3; Average waiting time: (3 + 16 + 9 + 0)/4 = 7 Operating System 2011/2012
  15. 15. Priority Scheduling A priority number (integer) is associated with each process ● The CPU is allocated to the process with the highest priority (smallest integer – highest priority). ● Can be preemptive (compares priority of process that has arrived at the ready queue with priority of currently running process) or nonpreemptive (put at the head of the ready queue). ● SJF is a priority scheduling where priority is the predicted next CPU burst time. ● Problem Starvation – low priority processes may never execute. ● Solution Aging – as time progresses increase the priority of the process. ● Operating System 2011/2012
  16. 16. Priority Scheduling Process Burst Time Priority P1 10 3 P2 1 1 P3 2 4 P4 1 5 P5 5 2 Operating System 2011/2012
  17. 17. Round-Robin Scheduling Each process gets a small unit of CPU time (time quantum), usually 10-100 milliseconds. After this time has elapsed, the process is preempted and added to the end of the ready queue. ● If there are n processes in the ready queue and the time quantum is q, then each process gets 1/n of the CPU time in chunks of at most q time units at once. No process waits more than (n-1)q time units. ● Performance ● q large -> FIFO ● q small -> q must be large with respect to context switch, otherwise overhead is too high. ● Operating System 2011/2012
  18. 18. Multilevel Queue Scheduling Ready queue is partitioned into separate queues: ➢ foreground (interactive) ➢ background (batch) ● Each queue has its own scheduling algorithm, ➢ foreground – RR ➢ background – FCFS ● Scheduling must be done between the queues. ➢ Fixed priority scheduling; (i.e., serve all from foreground then from background). Possibility of starvation. ➢ Time slice – each queue gets a certain amount of CPU time which it can schedule amongst its processes; i.e., 80% to foreground in RR, 20% to background in FCFS ● Operating System 2011/2012
  19. 19. Multilevel Feedback Queue A process can move between the various queues; aging can be implemented this way. Multilevel-feedback-queue scheduler defined by the following parameters: ● number of queues ● scheduling algorithms for each queue ● method used to determine when to upgrade a process ● method used to determine when to demote a process ● method used to determine which queue a process will enter when that process needs service Operating System 2011/2012
  20. 20. Multilevel Feedback Queue Three queues: ● Q0 – time quantum 8 milliseconds ● Q1 – time quantum 16 milliseconds ● Q2 – FCFS Scheduling ● A new job enters queue Q0 which is served FCFS. When it gains CPU, job receives 8 milliseconds. If it does not finish in 8 milliseconds, job is moved to queue Q1. ● At Q1 job is again served FCFS and receives 16 additional milliseconds. If it still does not complete, it is preempted and moved to queue Q2. Operating System 2011/2012
  21. 21. Multiple-Processor Scheduling ● Multiprocessing ● ● ● Processor affinity ● ● ● Soft Hard Load Balancing ● ● ● Asymmetric (AMP) Symmetric (SMP) push migration: task pull migration: process Multi-core Operating System 2011/2012
  22. 22. Symmetric vs Asymmetric Asymmetric: processors are dedicated to specific tasks. Symmetric: processors can execute the same tasks and exchange them during execution. Operating System 2011/2012
  23. 23. Processor Affinity Processor Affinity: the ability of a processor to exchange process executing on run-time. Soft affinity: a process can move from one CPU to another. Hard affinity: a process can not move from one CPU to another. Operating System 2011/2012
  24. 24. Load Balancing Push migration occurs when a specific task periodically checks the load on each processor and move a process from a busy CPU to an idle one. Pull migration occurs when an idle processor pulls a waiting task from a busy processor. Operating System 2011/2012

×