Lecture 8: CPU Scheduling

Slides:



Advertisements
Similar presentations
CPU Scheduling.
Advertisements

Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 5: CPU Scheduling.
Chap 5 Process Scheduling. Basic Concepts Maximum CPU utilization obtained with multiprogramming CPU–I/O Burst Cycle – Process execution consists of a.
Chapter 5 CPU Scheduling. CPU Scheduling Topics: Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling.
CPU Scheduling CS 3100 CPU Scheduling1. Objectives To introduce CPU scheduling, which is the basis for multiprogrammed operating systems To describe various.
Chapter 5: CPU Scheduling Joe McCarthy CSS 430: Operating Systems - CPU Scheduling1.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 5: CPU Scheduling.
CS 311 – Lecture 23 Outline Kernel – Process subsystem Process scheduling Scheduling algorithms User mode and kernel mode Lecture 231CS Operating.
Chapter 6: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Chapter 6: CPU Scheduling Basic.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
Chapter 5-CPU Scheduling
02/11/2004CSCI 315 Operating Systems Design1 CPU Scheduling Algorithms Notice: The slides for this lecture have been largely based on those accompanying.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
Chapter 5: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Basic Concepts Maximum CPU utilization.
Silberschatz, Galvin, and Gagne  Applied Operating System Concepts Module 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
CS212: OPERATING SYSTEM Lecture 3: Process Scheduling 1.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
Silberschatz and Galvin  Operating System Concepts Module 5: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 5: CPU Scheduling.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
Chapter 5: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 5: CPU Scheduling Basic Concepts Scheduling Criteria.
Chapter 5: Process Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Basic Concepts Maximum CPU utilization can be obtained.
1 11/29/2015 Chapter 6: CPU Scheduling l Basic Concepts l Scheduling Criteria l Scheduling Algorithms l Multiple-Processor Scheduling l Real-Time Scheduling.
Chapter 5: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Chapter 5: CPU Scheduling Basic.
Silberschatz and Galvin  Operating System Concepts Module 5: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 5 CPU Scheduling Slide 1 Chapter 5 CPU Scheduling.
6.1 CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling Algorithm Evaluation.
Chapter 4 CPU Scheduling. 2 Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling Algorithm Evaluation.
Lecture 4 CPU scheduling. Basic Concepts Single Process  one process at a time Maximum CPU utilization obtained with multiprogramming CPU idle :waiting.
CPU scheduling.  Single Process  one process at a time  Maximum CPU utilization obtained with multiprogramming  CPU idle :waiting time is wasted 2.
1 Module 5: Scheduling CPU Scheduling Scheduling Algorithms Reading: Chapter
Basic Concepts Maximum CPU utilization obtained with multiprogramming
1 Chapter 5: CPU Scheduling. 2 Basic Concepts Scheduling Criteria Scheduling Algorithms.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
lecture 5: CPU Scheduling
Chapter 6: CPU Scheduling
Dan C. Marinescu Office: HEC 439 B. Office hours: M, Wd 3 – 4:30 PM.
Chapter 5a: CPU Scheduling
Chapter 5: CPU Scheduling
Operating Systems Processes Scheduling.
CPU Scheduling.
Chapter 6: CPU Scheduling
Chapter 6: CPU Scheduling
Chapter 5: CPU Scheduling
CPU Scheduling G.Anuradha
Chapter 6: CPU Scheduling
Module 5: CPU Scheduling
Chapter 5: CPU Scheduling
Operating System Concepts
Chapter 5: CPU Scheduling
Chapter 5: CPU Scheduling
3: CPU Scheduling Basic Concepts Scheduling Criteria
Chapter5: CPU Scheduling
Chapter 5: CPU Scheduling
Chapter 6: CPU Scheduling
Outline Scheduling algorithms Multi-processor scheduling
Operating System Concepts
Chapter 6: CPU Scheduling
Chapter 5: CPU Scheduling
Lecture 2 Part 3 CPU Scheduling
Operating System , Fall 2000 EA101 W 9:00-10:00 F 9:00-11:00
Shortest-Job-First (SJR) Scheduling
Chapter 6: CPU Scheduling
Module 5: CPU Scheduling
Chapter 5: CPU Scheduling
Chapter 6: CPU Scheduling
Chapter 6: CPU Scheduling
CPU Scheduling: Basic Concepts
Module 5: CPU Scheduling
Chapter 5: CPU Scheduling
Presentation transcript:

Lecture 8: CPU Scheduling Joe McCarthy CSS 430: Operating Systems - CPU Scheduling

Chapter 5: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Thread Scheduling Multiple-Processor Scheduling Operating Systems Examples Algorithm Evaluation Material derived, in part, from Operating Systems Concepts with Java, 8th Ed. © 2009 Silberschatz, Galvin & Gagne CSS 430: Operating Systems - CPU Scheduling

[from Chapter 1: Introduction] CPU [from Chapter 1: Introduction] CSS 430: Operating Systems - CPU Scheduling

[from Chapter 1: Introduction] CPU Scheduling [from Chapter 1: Introduction] CSS 430: Operating Systems - CPU Scheduling

[from Chapter 1: Introduction] CPU Scheduling [from Chapter 1: Introduction] CSS 430: Operating Systems - CPU Scheduling

[from Chapter 1: Introduction] CPU Scheduling Multiprogramming [from Chapter 1: Introduction] CSS 430: Operating Systems - CPU Scheduling

[from Chapter 3: Processes] CPU Scheduling [from Chapter 3: Processes] CSS 430: Operating Systems - CPU Scheduling

[from Chapter 3: Processes] CPU Scheduling Process Control Blocks [from Chapter 3: Processes] CSS 430: Operating Systems - CPU Scheduling

[from Chapter 3: Processes] CPU Scheduling Can all PCBs have access to CPU simultaneously? [from Chapter 3: Processes] CSS 430: Operating Systems - CPU Scheduling

[from Chapter 3: Processes] CPU Scheduling [from Chapter 3: Processes] CSS 430: Operating Systems - CPU Scheduling

[from Chapter 3: Processes] CPU Queues [from Chapter 3: Processes] CSS 430: Operating Systems - CPU Scheduling

[from Chapter 3: Processes] Process States [from Chapter 3: Processes] CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling Basic Concepts Goal: Maximize CPU utilization via optimized multiprogramming CPU–I/O Burst Cycle: Process execution consists of a cycle of CPU execution I/O wait CPU burst durations vary Within a process, across different processes CSS 430: Operating Systems - CPU Scheduling

Histogram of CPU-burst Durations CSS 430: Operating Systems - CPU Scheduling

Alternating Sequence of CPU & I/O Bursts CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling CPU Scheduler Selects next process to run (i.e., to get CPU time) Dispatches that process (allocates the CPU to it) CPU scheduler called when a process … CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling CPU Scheduler Selects next process to run (i.e., to get CPU time) Dispatches that process (allocates the CPU to it) CPU scheduler called when a process: Running  terminated Running  waiting Running  ready Waiting  ready Preemptive vs. non-preemptive CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling Dispatcher Activates a process (gives control of the CPU to the process) selected by the short-term scheduler Three steps: CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling Dispatcher Activates a process (gives control of the CPU to the process) selected by the short-term scheduler Three steps: CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling Dispatcher Activates a process (gives control of the CPU to the process) selected by the short-term scheduler Three steps: Switch context Switch to user mode Jump to the proper location in user program to start/resume CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling Dispatcher Activates a process (gives control of the CPU to the process) selected by the short-term scheduler Three steps: Switch context Switch to user mode Jump to the proper location in user program to start/resume Dispatch latency? CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling Dispatcher Activates a process (gives control of the CPU to the process) selected by the short-term scheduler Three steps: Switch context Switch to user mode Jump to the proper location in user program to start/resume Dispatch latency: time it takes for the dispatcher to stop one user process and start another one CSS 430: Operating Systems - CPU Scheduling

Scheduling Milestones Submission Time Time when job is submitted E.g., when command is entered in shell Admission Time Time when job is admitted to Ready queue PCB creation & other housekeeping has to take place Activation Time Time when job is first activated (Ready  Running) E.g., when first output starts appearing on console NB: may have several CPU-I/O burst cycles Completion Time Time when job finishes executing CSS 430: Operating Systems - CPU Scheduling

Job (Process/Thread) Times Response Time Time before job is first activated Activation Time – Submission Time E.g., time between entering command & first response Wait Time Total amount of time job spends in Ready queue Execution Time Total amount of time job spends Running NB: may have several CPU-I/O burst cycles Turnaround Time Time a job takes to complete after it is submitted Completion Time – Submission Time CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling Scheduling Criteria CPU utilization % of time CPU is executing user processes Throughput # of processes that complete their execution per time unit Average response time average amount of between when a process is submitted & first response (for time-sharing environment) Average waiting time average amount of time a process waits in Ready queue Average turnaround time average amount of time to execute a process CSS 430: Operating Systems - CPU Scheduling

Scheduling Optimization Criteria CPU utilization: maximize % of time CPU is executing user processes Throughput: maximize # of processes that complete their execution per time unit Average response time: minimize average amount of between when a process is submitted & first response (for time-sharing environment) Average waiting time: minimize average amount of time a process waits in Ready queue Average turnaround time: minimize average amount of time to execute a process CSS 430: Operating Systems - CPU Scheduling

First-Come, First-Served (FCFS) FCFS policy often implemented with FIFO queue Example: 3 processes with the following burst times: P1 = 24; P2 = 3; P3 = 3 Suppose that the processes arrive at t0 in the order: P1, P2, P3 The Gantt Chart for the schedule is: Waiting times Average waiting time: P1 P2 P3 24 27 30 CSS 430: Operating Systems - CPU Scheduling

First-Come, First-Served (FCFS) FCFS policy often implemented with FIFO queue Example: 3 processes with the following burst times: P1 = 24; P2 = 3; P3 = 3 Suppose that the processes arrive at t0 in the order: P1, P2, P3 The Gantt Chart for the schedule is: Waiting times: P1 = 0; P2 = 24; P3 = 27 Average waiting time: (0 + 24 + 27) / 3 = 17.0 P1 P2 P3 24 27 30 CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling FCFS Scheduling Suppose that the processes arrive in the order: P2 , P3 , P1 The Gantt chart for the schedule is: Waiting times: Average waiting time: P1 P3 P2 6 3 30 CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling FCFS Scheduling Suppose that the processes arrive in the order: P2 , P3 , P1 The Gantt chart for the schedule is: Waiting times: P1 = 6; P2 = 0;; P3 = 3 Average waiting time: (6 + 0 + 3) / 3 = 3.0 P1 P3 P2 6 3 30 CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling FCFS Scheduling P1 P2 P3 24 27 30 P1 P3 P2 6 3 30 Order: P1, P2, P3 Average wait: 17.0 Order: P2, P3, P1 Average wait: 3.0 Convoy effect: short process[es] stuck behind long process How could we achieve minimal average waiting time? CSS 430: Operating Systems - CPU Scheduling

Shortest-Job-First (SJF) Scheduling Always schedule the shortest job first Select process with shortest next CPU burst. Optimal average waiting time For any set of processes P1 P3 P2 6 3 30 CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling Example of SJF Process Arrival Time Burst Time P1 0.0 6 P2 2.0 8 P3 4.0 7 P4 5.0 3 SJF scheduling chart CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling Example of SJF Process Arrival Time Burst Time P1 0.0 6 P2 2.0 8 P3 4.0 7 P4 5.0 3 SJF scheduling chart Average waiting time: P4 P3 P1 3 16 9 P2 24 CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling Example of SJF Process Arrival Time Burst Time P1 0.0 6 P2 2.0 8 P3 4.0 7 P4 5.0 3 SJF scheduling chart Average waiting time: (3 + 16 + 9 + 0) / 4 = 7.0 P4 P3 P1 3 16 9 P2 24 CSS 430: Operating Systems - CPU Scheduling

Shortest-Job-First (SJF) Scheduling Always schedule the shortest job first Select process with shortest next CPU burst. Optimal average waiting time For any set of processes Only one problem P1 P3 P2 6 3 30 CSS 430: Operating Systems - CPU Scheduling

Shortest-Job-First (SJF) Scheduling Always schedule the shortest job first Select process with shortest next CPU burst. Optimal average waiting time For any set of processes Only one problem P1 P3 P2 6 3 30 http://www.hedgeworld.com/blog/?p=3570 CSS 430: Operating Systems - CPU Scheduling

Shortest-Job-First (SJF) Scheduling Always schedule the shortest job first Select process with shortest next CPU burst. Optimal average waiting time For any set of processes Only one problem How to know the length of the next CPU burst? P1 P3 P2 6 3 30 http://www.hedgeworld.com/blog/?p=3570 CSS 430: Operating Systems - CPU Scheduling

Determining Length of Next CPU Burst Can only estimate length of future bursts Use exponential averaging of previous bursts CSS 430: Operating Systems - CPU Scheduling

Predicting Length of Next CPU Burst CSS 430: Operating Systems - CPU Scheduling

Examples of Exponential Averaging  = 0 n+1 = n Recent history does not count  = 1 n+1 = tn Only the most recent CPU burst counts  = 0.5 (typically) If we expand the formula, we get: n+1 =  tn+(1 - ) tn -1 + … +(1 -  )j  tn -j + … +(1 -  )n +1 0 Since both  and (1 - ) are less than or equal to 1, each successive term has less weight than its predecessor CSS 430: Operating Systems - CPU Scheduling

Shortest Remaining Time First Pre-emptive version of SJF CSS 430: Operating Systems - CPU Scheduling

Shortest Remaining Time First Pre-emptive version of SJF Average wait time? CSS 430: Operating Systems - CPU Scheduling

Shortest Remaining Time First Pre-emptive version of SJF Average wait time: [(10 – 1) + (1 – 1) + (17 – 2) + (5 – 3)] / 4 = 6.5 CSS 430: Operating Systems - CPU Scheduling

Shortest Remaining Time First Pre-emptive version of SJF Average wait time: [(10 – 1) + (1 – 1) + (17 – 2) + (5 – 3)] / 4 = 6.5 Non pre-emptive SJF? CSS 430: Operating Systems - CPU Scheduling

Shortest Remaining Time First Pre-emptive version of SJF Average wait time: [(10 – 1) + (1 – 1) + (17 – 2) + (5 – 3)] / 4 = 6.5 Non pre-emptive SJF: [0 + (8 – 1) + (17 – 2) + (12 – 3)] / 4 = 7.75 CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling Priority Scheduling A priority number (integer) is associated with each process Based on internal and/or external factors The CPU is allocated to the process with the highest priority Preemptive: new, higher priority processes take precedence Nonpreemptive: new processes wait for current process Textbook: low #  high priority [opposite of ThreadOS] SJF priority: FCFS priority: CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling Priority Scheduling A priority number (integer) is associated with each process Based on internal and/or external factors The CPU is allocated to the process with the highest priority Preemptive: new, higher priority processes take precedence Nonpreemptive: new processes wait for current process Textbook: low #  high priority (opposite of ThreadOS) SJF priority: predicted next CPU burst time FCFS priority: arrival time CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling Priority Scheduling A priority number (integer) is associated with each process Based on internal and/or external factors The CPU is allocated to the process with the highest priority Preemptive: new, higher priority processes take precedence Nonpreemptive: new processes wait for current process Textbook: low #  high priority (opposite of ThreadOS) SJF priority: predicted next CPU burst time FCFS priority: arrival time Problem? CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling Priority Scheduling A priority number (integer) is associated with each process Based on internal and/or external factors The CPU is allocated to the process with the highest priority Preemptive: new, higher priority processes take precedence Nonpreemptive: new processes wait for current process Textbook: low #  high priority (opposite of ThreadOS) SJF priority: predicted next CPU burst time FCFS priority: arrival time Problem  Starvation – low priority processes may never execute CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling Priority Scheduling A priority number (integer) is associated with each process Based on internal and/or external factors The CPU is allocated to the process with the highest priority Preemptive: new, higher priority processes take precedence Nonpreemptive: new processes wait for current process Textbook: low #  high priority (opposite of ThreadOS) SJF priority: predicted next CPU burst time FCFS priority: arrival time Problem  Starvation – low priority processes may never execute Solution  Aging – as time progresses increase the priority of the process CSS 430: Operating Systems - CPU Scheduling

Priority Scheduling Example Average wait time: (6 + 0 + 16 + 18 + 1) / 5 = 8.2 CSS 430: Operating Systems - CPU Scheduling

Priority Scheduling Example Average wait time: (6 + 0 + 16 + 18 + 1) / 5 = 8.2 If pre-emptive & process arrival times are 0, 1, 2, 3, 4? Average wait time: CSS 430: Operating Systems - CPU Scheduling

Priority Scheduling Example Average wait time: (6 + 0 + 16 + 18 + 1) / 5 = 8.2 If pre-emptive & process arrival times are 0, 1, 2, 3, 4? Average wait time: [((2 – 1) + (9 – 4)) + 0 + (16 – 2) + (18 – 3) + 0] / 5 = 7.0 CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling Round Robin (RR) Each process gets time quantum (q) of CPU time (typically 10-100 ms) Selected from head of Ready queue If process does not block (I/O) within q ms: preempted Added to the tail of the Ready queue (as are new processes) General observations: n processes in the Ready queue each process gets 1/n of the CPU time (in slices of size q) maximum waiting time: (n-1)q time units CSS 430: Operating Systems - CPU Scheduling

Example of RR with Time Quantum = 4 Process Burst Time P1 24 P2 3 P3 3 The Gantt chart is: Compare to SJF: P1 P2 P3 4 7 10 14 18 22 26 30 P1 P3 P2 6 3 30 CSS 430: Operating Systems - CPU Scheduling

Time Quantum & Context Switch Time Performance issues: q large  q small  CSS 430: Operating Systems - CPU Scheduling

Time Quantum & Context Switch Time Performance issues: q large  FCFS q small  context switch overhead too high CSS 430: Operating Systems - CPU Scheduling

Time Quantum  Turnaround Time CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling Multilevel Queue Ready queue can be partitioned into separate queues E.g., foreground (interactive) & background (batch) Each queue can have its own scheduling algorithm Scheduling must be done between the queues Simplest: Fixed priority scheduling One possibility: 100% priority to foreground Serve foreground if any; serve background only if no foreground Problem? CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling Multilevel Queue Ready queue can be partitioned into separate queues E.g., foreground (interactive) & background (batch) Each queue can have its own scheduling algorithm Scheduling must be done between the queues Simplest: Fixed priority scheduling One possibility: 100% priority to foreground Serve foreground if any; serve background only if no foreground Problem: possibility of starvation Another possibility? CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling Multilevel Queue Ready queue can be partitioned into separate queues E.g., foreground (interactive) & background (batch) Each queue can have its own scheduling algorithm Scheduling must be done between the queues Simplest: Fixed priority scheduling One possibility: 100% priority to foreground Serve foreground if any; serve background only if no foreground Problem: possibility of starvation. Another possibility: 80/20 priority using time slices 80% to foreground using RR 20% to background using FCFS CSS 430: Operating Systems - CPU Scheduling

Multilevel Queue Scheduling CSS 430: Operating Systems - CPU Scheduling

Multilevel Feedback Queue Process can migrate among queues Queue placement based on past behavior (feedback) Parameters: number of queues scheduling algorithms for each queue when to upgrade a process when to demote a process when to select a queue for service CSS 430: Operating Systems - CPU Scheduling

Multilevel Feedback Queue CSS 430: Operating Systems - CPU Scheduling

Example of Multilevel Feedback Queue Three queues: Q0, Q1, Q2; all use FCFS If blocked for I/O, job returned to Q0 when I/O done New jobs enter queue Q0 When activated (given CPU), job receives 8 milliseconds If not done, job is preempted, demoted to queue Q1 Jobs in Q1 When activated, job receives 16 additional milliseconds If not done, job is preempted, demoted to Q2 Jobs in Q2 When activated, job runs until terminated or interrupted If not done, job is preempted, returned to Q2 CSS 430: Operating Systems - CPU Scheduling

Multiple-Processor Scheduling CPU scheduling more complex when multiple CPUs are available Homogeneous processors within a multiprocessor Asymmetric multiprocessing: only one processor accesses the system data structures, alleviating the need for data sharing (master & slave processors) Symmetric multiprocessing (SMP): each processor is self-scheduling, all processes in common ready queue, or each has its own private queue of ready processes CSS 430: Operating Systems - CPU Scheduling

Multiple-Processor Scheduling CPU scheduling more complex when multiple CPUs are available Homogeneous processors within a multiprocessor Asymmetric multiprocessing: only one processor accesses the system data structures, alleviating the need for data sharing (master & slave processors) Symmetric multiprocessing (SMP): each processor is self-scheduling, all processes in common ready queue, or each has its own private queue of ready processes Processor affinity? CSS 430: Operating Systems - CPU Scheduling

Multiple-Processor Scheduling CPU scheduling more complex when multiple CPUs are available Homogeneous processors within a multiprocessor Asymmetric multiprocessing: only one processor accesses the system data structures, alleviating the need for data sharing (master & slave processors) Symmetric multiprocessing (SMP): each processor is self-scheduling, all processes in common ready queue, or each has its own private queue of ready processes Processor affinity? CSS 430: Operating Systems - CPU Scheduling

Multiple-Processor Scheduling CPU scheduling more complex when multiple CPUs are available Homogeneous processors within a multiprocessor Asymmetric multiprocessing: only one processor accesses the system data structures, alleviating the need for data sharing (master & slave processors) Symmetric multiprocessing (SMP): each processor is self-scheduling, all processes in common ready queue, or each has its own private queue of ready processes Processor affinity: process has affinity for processor on which it is currently running soft affinity: policy hard affinity: mechanism CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling http://hadoop.apache.org/common/docs/current/hdfs_design.html CSS 430: Operating Systems - CPU Scheduling

NUMA and CPU Scheduling NUMA = non-uniform memory access CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling Multicore Processors Multiple threads per core Memory stall: CPU awaits instruction/data fetch Multiple hardware threads: logical processors Each logical processor can run a software thread Enables progress to made on one thread while memory is updated Two approaches Coarse-grained multithreading (latency event) Fine-grained multithreading (per instruction) CSS 430: Operating Systems - CPU Scheduling

Multithreaded Multicore System CSS 430: Operating Systems - CPU Scheduling

Operating System Examples Solaris scheduling Windows XP scheduling Linux scheduling CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling Solaris Scheduling Dispatch Table (for TS, IA) CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling Windows XP Scheduling Priority classes Relative priorities Processes within a variable class (not real-time): Expired time quantum  reduce priority Released from wait  increase priority Foreground process gets extra boost CSS 430: Operating Systems - CPU Scheduling

Linux priorities & time quanta CSS 430: Operating Systems - CPU Scheduling

runqueue: active & expired When all task lists in active array are empty, exchange active array & expired array CSS 430: Operating Systems - CPU Scheduling

Java Thread Scheduling Priority-based FCFS within same priority level May be preemptive or non-preemptive A runnable thread executes until: Time quantum expires Blocks for I/O Exits its run() method Yields to another thread via yield() “cooperative multitasking” CSS 430: Operating Systems - CPU Scheduling

Java Thread Priorities Values: 1 .. 10 Thread.MAX_PRIORITY = 10 Thread.NORM_PRIORITY = 5 Thread.MIN_PRIORITY = 1 Methods: int Thread.getPriority() Thread.setPriority( int newPriority ) CSS 430: Operating Systems - CPU Scheduling

Mapping Java Thread Priorities JVM runs on host Java Thread priorities (user)  host kernel priorities Example: Win32 CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling Algorithm Evaluation How can we compare scheduling algorithms? CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling Algorithm Evaluation How can we compare scheduling algorithms? FCFS, SJF & RR average wait times? CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling FCFS, SJF & RR: average wait times? CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling FCFS, SJF & RR: average wait times? CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling FCFS, SJF & RR: average wait times? FCFS: (0 + 10 + 39 + 42 + 49) / 5 = 28 CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling FCFS, SJF & RR: average wait times? FCFS: (0 + 10 + 39 + 42 + 49) / 5 = 28 CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling FCFS, SJF & RR: average wait times? FCFS: (0 + 10 + 39 + 42 + 49) / 5 = 28 SJF: (10 + 32 + 0 + 3 + 20) / 5 = 13 CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling FCFS, SJF & RR: average wait times? FCFS: (0 + 10 + 39 + 42 + 49) / 5 = 28 SJF: (10 + 32 + 0 + 3 + 20) / 5 = 13 CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling FCFS, SJF & RR: average wait times? FCFS: (0 + 10 + 39 + 42 + 49) / 5 = 28 SJF: (10 + 32 + 0 + 3 + 20) / 5 = 13 RR: (0 + 32 + 20 + 23 + 40) / 5 = 23 CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling Algorithm Evaluation How can we compare scheduling algorithms? Analysis Deterministic models: predetermined workload CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling Algorithm Evaluation How can we compare scheduling algorithms? Analysis Deterministic models: predetermined workload Queueing models: use probability distribution Arrival rate Service rate CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling Algorithm Evaluation How can we compare scheduling algorithms? Analysis Deterministic models: predetermined workload Queueing models: use probability distribution Arrival rate Service rate Simulation ThreadOS CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling Algorithm Evaluation How can we compare scheduling algorithms? Analysis Deterministic models: predetermined workload Queueing models: use probability distribution Arrival rate Service rate Simulation ThreadOS Implementation CSS 430: Operating Systems - CPU Scheduling

CSS 430: Operating Systems - CPU Scheduling For next time Readings Chapter 4: Threads Chapter 6: Process Synchronization CSS 430: Operating Systems - CPU Scheduling