Concurrency and Threading: CPU Scheduling Execution State of a Thread or Process Schedulers in the OS Structure of CPU Schedulers Criteria for Scheduling Scheduling Algorithms: FIFO, SJF, FP, MLFQ Multiprocessor Scheduling Concurrency and Threading: Scheduling
State of a Thread/Process CSCE 410/611 : Operating Systems State of a Thread/Process starting starting suspended ready suspended ready ready ready running running terminated suspended blocked suspended blocked blocked blocked Concurrency and Threading: Scheduling
CSCE 410/611 : Operating Systems Schedulers starting long-term (admission) scheduler short-term (CPU) scheduler suspended ready ready running terminated suspended blocked blocked medium-term (memory) scheduler Concurrency and Threading: Scheduling
CSCE 410/611 : Operating Systems Multiprogramming starting starting starting starting ready ready ready ready running running running blocked blocked Concurrency and Threading: Scheduling
CPU Bursts vs. I/O Bursts CSCE 410/611 : Operating Systems CPU Bursts vs. I/O Bursts starting short-term (CPU) scheduler CPU Burst ready ready running running I/O “Burst” blocked blocked Concurrency and Threading: Scheduling
CSCE 410/611 : Operating Systems CPU Bursts and Jobs thread starts thread terminates blocked blocked CPU burst CPU burst CPU burst Concurrency and Threading: Scheduling
CSCE 410/611 : Operating Systems CPU Bursts and Jobs thread starts thread terminates blocked blocked CPU burst CPU burst CPU burst Concurrency and Threading: Scheduling
CSCE 410/611 : Operating Systems CPU Bursts and Jobs job “starts” job “terminates” “Job” thread starts thread terminates blocked blocked CPU burst CPU burst CPU burst Concurrency and Threading: Scheduling
Scheduling Decisions Decision: “Who is going to use the CPU next?!” 4 2 ready running 3 1 non-preemptive blocked preemptive Scheduling decision points: 1. The running thread changes from running to blocked (current CPU burst of that thread is over). 2. The running thread terminates. 3. A blocked thread becomes ready (new CPU burst of that thread begins). 4. The current thread changes from running to ready . Concurrency and Threading: Scheduling
Structure of a Scheduling Subsystem CSCE 410/611 : Operating Systems Structure of a Scheduling Subsystem ready threads TCB ready queue scheduling subsystem CPU Scheduler Dispatcher select thread start new thread ? Concurrency and Threading: Scheduling
What Is a Good Scheduler? Criteria CSCE 410/611 : Operating Systems What Is a Good Scheduler? Criteria User oriented: Response time : time interval from start of job to first response Normalized response time: ratio of response time to execution time Waiting time : sum of periods spent waiting in ready queue System oriented: CPU utilization : percentage of time CPU is busy Throughput : number of jobs completed per time unit Concurrency and Threading: Scheduling
What Is a Good Scheduler? Criteria CSCE 410/611 : Operating Systems What Is a Good Scheduler? Criteria Any good scheduler should: maximize CPU utilization and throughput minimize waiting time, response time Huh? maximum/minimum values? average values? variance? Concurrency and Threading: Scheduling
Scheduling Algorithms CSCE 410/611 : Operating Systems Scheduling Algorithms FCFS : First-come-first-served SPN: Shortest Process Next Priority scheduling RR : Round-Robin MLFQ: Multilevel Feedback Queue Scheduling Multiprocessor scheduling Concurrency and Threading: Scheduling
Common Structure of a Scheduler CSCE 410/611 : Operating Systems Common Structure of a Scheduler ready queue “priority list” new jobs CPU Concurrency and Threading: Scheduling
First-Come-First-Served (FCFS/FIFO) CSCE 410/611 : Operating Systems First-Come-First-Served (FCFS/FIFO) ready queue TCB head tail new jobs CPU CPU Cons: long average and worst-case waiting times poor dynamic behavior (convoy effect) Pros: very simple Concurrency and Threading: Scheduling
CSCE 410/611 : Operating Systems Shortest-Job-First ready queue new jobs longest jobs shortest jobs CPU CPU TCB Whenever CPU is idle, pick thread with shortest next CPU burst. Pros: minimizes average waiting times Cons: Starvation of threads with long CPU bursts. How to determine length of next CPU burst?! Concurrency and Threading: Scheduling
SJF Minimizes Average Waiting Time CSCE 410/611 : Operating Systems SJF Minimizes Average Waiting Time Provably optimal! Proof: swapping of jobs Plong Plong Pshort Pshort Pshort dW = tshort - tlong < 0 Plong Example: 6 8 12 4 W = 6+18+26 = 50 12 8 6 8 12 4 12 4 W = 6+14+26 = 46 6 8 12 4 8 4 W = 6+14+18 = 38 6 8 12 4 6 4 W = 6+10+18 = 34 6 8 12 4 W = 4+10+18 = 32 Concurrency and Threading: Scheduling
Fixed-Priority Scheduler CSCE 410/611 : Operating Systems Fixed-Priority Scheduler ready queue new jobs low priority high priority CPU CPU TCB Whenever CPU is idle, pick thread with highest priority. Cons: Starvation of low-priority threads Priority: thread/process class urgency Concurrency and Threading: Scheduling
Fixed-Priority Scheduler CSCE 410/611 : Operating Systems Fixed-Priority Scheduler ready queue new jobs low priority high priority CPU CPU TCB Whenever CPU is idle, pick thread with highest priority. Cons: Starvation of low-priority threads Priority: thread/process class urgency Solution: Aging: increase priority over time Concurrency and Threading: Scheduling
Fixed Priority Scheduling (implementation) CSCE 410/611 : Operating Systems Fixed Priority Scheduling (implementation) Conceptually Priority Queues q=f(p) priority queue priority low priority CPU low priority high priority CPU (compare priorities) Selector (compare priorities) Selector Array of FIFO queues! high priority Concurrency and Threading: Scheduling
CSCE 410/611 : Operating Systems Round-Robin go back to end of queue! FIFO with preemption after time quantum Popular method for time sharing Choice of time quantum: large: FCFS small: “Processor sharing” Time quantum also defines context-switching overhead FIFO queue time quantum CPU CPU terminate Concurrency and Threading: Scheduling
Multilevel Feedback Queue Scheduling CSCE 410/611 : Operating Systems (conceptually!) low priority RR (quantum=2ms) RR (quantum=4ms) RR (quantum=8ms) FIFO (RR with quantum infinity) FIFO FIFO aging demotion (compare priorities) Selector FIFO FIFO high priority CPU Concurrency and Threading: Scheduling
Multilevel Feedback Queue Scheduling CSCE 410/611 : Operating Systems (conceptually!) low priority RR (quantum=2ms) RR (quantum=4ms) RR (quantum=8ms) FIFO (RR with quantum infinity) FIFO FIFO aging (compare priorities) Selector FIFO FIFO high priority CPU CPU demotion! Concurrency and Threading: Scheduling
Dynamic Multiprocessor Scheduling CSCE 410/611 : Operating Systems Dynamic Multiprocessor Scheduling global scheduler CPU ready queue CPU new jobs CPU CPU CPU Concurrency and Threading: Scheduling
Static Multiprocessor Scheduling CSCE 410/611 : Operating Systems Static Multiprocessor Scheduling local scheduler Partition ready queue CPU ready queue thread partitioning CPU new threads ready queue CPU ready queue CPU Concurrency and Threading: Scheduling
CPU Scheduling: Summary Execution State of a Thread or Process Schedulers in the OS Structure of Schedulers Criteria for Scheduling Scheduling Algorithms: FIFO, SJF, FP, MLFQ Multiprocessor Scheduling Concurrency and Threading: Scheduling