cpu scheduling
play

CPU Scheduling Schedulers Structure of a CPU scheduler Criteria - PDF document

CPU Scheduling Schedulers Structure of a CPU scheduler Criteria for scheduling Scheduling Algorithms FCFS SPN SRT MLFQ CPU scheduling in Unix Schedulers start long-term scheduler short-term scheduler


  1. CPU Scheduling • Schedulers • Structure of a CPU scheduler • Criteria for scheduling • Scheduling Algorithms – FCFS – SPN – SRT – MLFQ • CPU scheduling in Unix Schedulers start long-term scheduler short-term scheduler suspended ready running ready suspended blocked blocked medium-term scheduler

  2. Short-Term Scheduling • Motivation for multiprogramming: Have multiple processes in memory to keep CPU busy. • Typical execution profile of a process: start terminate wait for I/O wait for I/O wait for I/O CPU burst CPU burst CPU burst CPU burst • CPU scheduler is managing the execution of CPU bursts, represented by processes in ready or running state. Scheduling Decisions • Who is going to use the CPU next? 4 2 ready running ready running 3 1 waiting waiting non-preemptive • Scheduling decision points: – 1 . The running process changes from running to waiting (current CPU burst of that process is over). preemptive – 2 . The running process terminates. – 3 . A waiting process becomes ready (new CPU burst of that process begins). – 4 . The current process switches from running to ready .

  3. Structure of a Scheduler (I) ready queue ready queue PCB scheduler dispatcher CPU PCB scheduler dispatcher CPU select process start new process ? ? What Is a Good Scheduler? Criteria • User oriented: – Turnaround time : time interval from submission of job until its completion – Waiting time : sum of periods spent waiting in ready queue – Response time : time interval from submission of job to first response – Normalized turnaround time : ratio of turnaround time to service time • System oriented: – CPU utilization : percentage of time CPU is busy – Throughput : number of jobs completed per time unit • Any good scheduler should: – maximize CPU utilization and throughput – minimize turnaround time, waiting time, response time • Huh? – maximum/minimum values vs. average values vs. variance

  4. Scheduling Algorithms • FCFS : First-come-first-served • SPN: Shortest Process Next • SRT : Shortest Remaining Time • priority scheduling • RR : Round-robin • Multilevel feedback queue scheduling • Multiprocessor scheduling Structure of a Scheduler (II) (conceptual structure) determine location in queue determine location in queue head head tail tail CPU CPU PCB PCB • Incoming process is put into right location in ready queue. • Dispatcher always picks first element in ready queue.

  5. First-Come-First-Served (FCFS) append at the end of queue append at the end of queue head head tail tail CPU CPU PCB PCB • Advantages: – very simple • Disadvantages: – long average and worst-case waiting times – poor dynamic behavior (convoy effect) Waiting Times for FCFS • Example: P 1 = 24, P 2 = 6, P 3 = 6 W awg = (24+30)/3 = 18 P 1 P 2 P 3 W wc = 30 Different arrival order: W awg = (6+12)/3 = 6 P 2 P 3 P 1 W wc = 12 • Average waiting times is not minimal. • Waiting times may substantially vary over time. • Worst-case waiting times can be very long.

  6. Convoy Effects CPU I/O empty! empty! CPU-bound I/O-bound CPU empty! empty! I/O Convoy Effects CPU I/O idle! idle! CPU-bound I/O-bound

  7. Convoy Effects CPU I/O empty! empty! CPU-bound I/O-bound CPU empty! empty! I/O Shortest Process Next determine location in queue determine location in queue (compare next CPU burst lengths) (compare next CPU burst lengths) CPU CPU long jobs short jobs • Whenever CPU is idle, picks process with shortest next CPU burst . • Advantages: minimizes average waiting times. • Problem: How to determine length of next CPU burst? • Problem: starvation of jobs with long CPU bursts.

  8. SJF Minimizes Average Waiting Time • Provably optimal: Proof: swapping of jobs P long P short P long P short P short P long dW = t short - t long < 0 P short P long • Example: 6 12 8 4 W = 6+18+26 = 50 6 8 12 4 W = 6+14+26 = 46 6 8 4 12 W = 6+14+18 = 38 6 4 8 12 W = 6+10+18 = 34 4 6 8 12 W = 4+10+18 = 32 • Question: How to determine execution time of next CPU burst ?! – wild guess? – code inspection? • Forecasting (i.e. estimation) S n+1 = F(T n , T n-1 , T n-2 , T n-3 , T n-4 , ...) • Simple forecasting function: exponential average: S n+1 = a T n + (1-a) S n • Example: a = 0.8 S n+1 = 0.8T n + 0.16T n-1 + 0.032T n-2 + 0.0064T n-3 + ...

  9. Exponential Averaging: Example 16 14 a = 0.2 12 a = 0.5 10 a = 0.8 8 6 4 2 1 Preemptive SPN: Shortest- Remaining-Time -First • SPN: P 1 and P 3 arrive here P 2 arrives here P 1 P 2 P 3 nil P 3 P 2 P 3 ready queue P 3 • SRT: P 1 and P 3 arrive here P 2 arrives here P 1 P 2 P 1 P 3 nil P 3 P 1 P 3 P 3 P 1 resumes execution P 1 is preempted

  10. Priority Scheduling Selector Selector (compare priorities) (compare priorities) CPU CPU low priority high priority • Whenever CPU is idle, picks process with highest priority . • Priority: – process class, burst length, urgency, pocket depth. • Unbounded blocking: Starvation – Increase priority over time: aging • Conceptually • Priority Queues : priority queue low priority priority low priority q=f(p) (compare priorities) (compare priorities) (compare priorities) (compare priorities) Selector Selector Selector Selector high priority high priority CPU CPU CPU CPU

  11. Round-Robin • FIFO with preemption after time quantum • Method for time sharing • Choice of time quantum: – large: FCFS – small: Processor sharing • Time quantum also defines context-switching FIFO queue overhead end of • Response time smaller time quantum with large time quantums CPU CPU terminate Multilevel Queue Scheduling low priority batch processes (compare priorities) (compare priorities) user processes Selector Selector high-priority user processes kernel processes high priority separate queues, perhaps with different scheduling policies CPU CPU

  12. Multilevel Feedback Queue Scheduling (conceptually) low priority FCFS (quantum = infinity) (compare priorities) (compare priorities) quantum = 16 ms Selector Selector aging quantum = 4ms quantum = 2 ms high priority demotion MFBS: Implementation (Unix System V) • Clock handler generates 60 clock ticks per second. • Each PCB contains a field CPU (“recent CPU usage”), which is incremented on every clock tick while process is running. • Every 60 ticks scheduler is awakened and – ajusts recent CPU usage according to a decay function: decay( CPU ) = CPU /2 – recalculates priorities according to following formula (higher priorities have lower priority values!): priority = CPU /2 + base_priority • Decay rate controls aging. • Priority recalculation controls demotion • Note : This is a simplified view! (For a more detailed description refer to M.J.Bach, The Design of the UNIX Operating System. )

  13. MFBS on UNIX System V: Example • 3 processes, each with base priority 60: Process A Process B Process C time priority CPU count priority CPU count priority CPU count 60 0 60 0 60 0 1 ... 60 1 75 30 60 0 60 0 1 ... 2 67 15 75 30 60 0 1 ... 3 63 7 67 15 75 30 8 ... 67 4 76 33 63 7 67 15 8 ... 67 5 68 16 76 33 63 7

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend