Top Banner
EEL 358 1 Scheduling Reading: Silberschatz chapter 6 Additional Reading: Stallings chapter 9
28

Scheduling - Hong Kong Polytechnic Universitycsajaykr/myhome/file/Scheduling.pdf · Load Balancing Symmetric Multithreading Algorithm Evaluation Real Time Scheduling Scheduling Examples

Oct 19, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Scheduling - Hong Kong Polytechnic Universitycsajaykr/myhome/file/Scheduling.pdf · Load Balancing Symmetric Multithreading Algorithm Evaluation Real Time Scheduling Scheduling Examples

EEL 358 1

Scheduling

Reading:Silberschatzchapter 6

Additional Reading:Stallingschapter 9

Page 2: Scheduling - Hong Kong Polytechnic Universitycsajaykr/myhome/file/Scheduling.pdf · Load Balancing Symmetric Multithreading Algorithm Evaluation Real Time Scheduling Scheduling Examples

EEL 358 2

OutlineIntroductionTypes of SchedulingScheduling CriteriaFCFS SchedulingShortest-Job-First SchedulingPriority SchedulingRound Robin SchedulingMultilevel Queue SchedulingMultiprocessor Scheduling

Load BalancingSymmetric Multithreading

Algorithm EvaluationReal Time SchedulingScheduling Examples

Windows XP, 2000Linux

Page 3: Scheduling - Hong Kong Polytechnic Universitycsajaykr/myhome/file/Scheduling.pdf · Load Balancing Symmetric Multithreading Algorithm Evaluation Real Time Scheduling Scheduling Examples

EEL 358 3

Basic PointsProcess Scheduling, Thread Scheduling

Max CPU Utilization → Multiprogramming

CPU Burst ↔ I/O Burst

CPU Burst Distribution

Introduction

Page 4: Scheduling - Hong Kong Polytechnic Universitycsajaykr/myhome/file/Scheduling.pdf · Load Balancing Symmetric Multithreading Algorithm Evaluation Real Time Scheduling Scheduling Examples

EEL 358 4

Histogram – CPU Burst Duration

Page 5: Scheduling - Hong Kong Polytechnic Universitycsajaykr/myhome/file/Scheduling.pdf · Load Balancing Symmetric Multithreading Algorithm Evaluation Real Time Scheduling Scheduling Examples

EEL 358 5

CPU Scheduling DecisionsRunning → Waiting state

e.g. I/O Request, wait by ParentRunning → Ready state

e.g. InterruptWaiting → Ready state

e.g. Completion of I/OProcess Termination

Nonpreemptive SchedulingPreemptive Scheduling

Associated CostDesign of OS Kernel

Process → Kernel, wait for sys call or I/O completion beforecontext switch

Scheduling Types

Page 6: Scheduling - Hong Kong Polytechnic Universitycsajaykr/myhome/file/Scheduling.pdf · Load Balancing Symmetric Multithreading Algorithm Evaluation Real Time Scheduling Scheduling Examples

EEL 358 6

Scheduling CriteriaCPU Utilization – How busy is the CPU?

Throughput – Number of processes that are completed per unit time

Turnaround Time – How long to execute a process? Submission ↔ Completion

Waiting Time – Sum of periods spent in ready queue

Response Time – Process Request → First response

Page 7: Scheduling - Hong Kong Polytechnic Universitycsajaykr/myhome/file/Scheduling.pdf · Load Balancing Symmetric Multithreading Algorithm Evaluation Real Time Scheduling Scheduling Examples

EEL 358 7

Optimization CriteriaMax CPU utilization

Max throughput

Min turnaround time

Min waiting time

Min response time

Conflicting goals! Requires careful balanceAverage, Min/Max, Variance

Page 8: Scheduling - Hong Kong Polytechnic Universitycsajaykr/myhome/file/Scheduling.pdf · Load Balancing Symmetric Multithreading Algorithm Evaluation Real Time Scheduling Scheduling Examples

EEL 358 8

Process Burst TimeP1 24P2 3P3 3

Arrivals in the order: P1 , P2 , P3 The Gantt Chart for the schedule:

Waiting time → P1 = 0; P2 = 24; P3 = 27Average waiting time → (0 + 24 + 27)/3 = 17

P1 P2 P3

24 27 300

FCFS Scheduling

Page 9: Scheduling - Hong Kong Polytechnic Universitycsajaykr/myhome/file/Scheduling.pdf · Load Balancing Symmetric Multithreading Algorithm Evaluation Real Time Scheduling Scheduling Examples

EEL 358 9

FCFS SchedulingSay, if the processes arrive in the order

P2 , P3 , P1

The Gantt chart for the schedule:

Waiting time → P1 = 6; P2 = 0; P3 = 3Average waiting time → (6 + 0 + 3)/3 = 3, Previously 17 ↑Convoy effect → Short process behind long processNonpreemptive → Problem for time sharing systems

P1P3P2

63 300

Page 10: Scheduling - Hong Kong Polytechnic Universitycsajaykr/myhome/file/Scheduling.pdf · Load Balancing Symmetric Multithreading Algorithm Evaluation Real Time Scheduling Scheduling Examples

EEL 358 10

SJF SchedulingCPU assigned to process with smallest next CPU burst, Tie → FCFS

Shortest-next-CPU-burst algorithm

Major difficultyEstimating the processing time of each job, Predicting the Next!Long running jobs may starve, steady supply of short jobs to CPU

SJF is optimal – minimum average waiting time

Page 11: Scheduling - Hong Kong Polytechnic Universitycsajaykr/myhome/file/Scheduling.pdf · Load Balancing Symmetric Multithreading Algorithm Evaluation Real Time Scheduling Scheduling Examples

EEL 358 11

Process Arrival Time Burst TimeP1 0.0 7P2 2.0 4P3 4.0 1P4 5.0 4

SJF (non-preemptive)

Average waiting time → (0 + 6 + 3 + 7)/4 = 4

SJF Scheduling

P1 P3 P2

73 160

P4

8 12

Page 12: Scheduling - Hong Kong Polytechnic Universitycsajaykr/myhome/file/Scheduling.pdf · Load Balancing Symmetric Multithreading Algorithm Evaluation Real Time Scheduling Scheduling Examples

EEL 358 12

SJF SchedulingProcess Arrival Time Burst Time

P1 0.0 7P2 2.0 4P3 4.0 1P4 5.0 4

SJF (preemptive)

Average waiting time = (9 + 1 + 0 +2)/4 = 3

P1 P3P2

42 110

P4

5 7

P2 P1

16

Page 13: Scheduling - Hong Kong Polytechnic Universitycsajaykr/myhome/file/Scheduling.pdf · Load Balancing Symmetric Multithreading Algorithm Evaluation Real Time Scheduling Scheduling Examples

EEL 358 13

Priority SchedulingA priority number (integer) associated with each process

SJF – A Priority schedulingEqual Priority - FCFS

CPU → Process with the highest priority, High ↔ LowPreemptiveNonpreemptive

Defining PrioritiesInternally, Measurable Quantities

Memory required, time limits, # open files, ratio of avg I/O to CPU burst, etc.

Externally, Outside OSImportance of Process, type/amount of funds, etc.

StarvationLow priority processes may never execute

Solution?Aging

Page 14: Scheduling - Hong Kong Polytechnic Universitycsajaykr/myhome/file/Scheduling.pdf · Load Balancing Symmetric Multithreading Algorithm Evaluation Real Time Scheduling Scheduling Examples

EEL 358 14

Round Robin (RR)Each process gets a small unit of CPU time

Time Quantum (time-slice)usually 10-100 milliseconds

Time elapsed → PreemptedIf not completed → end of the ready queue

RR reduces penalty for short jobs in FCFS

Critical Issue → Length of quantum, qq large → FIFO or FCFSq small → Context switch overhead

Page 15: Scheduling - Hong Kong Polytechnic Universitycsajaykr/myhome/file/Scheduling.pdf · Load Balancing Symmetric Multithreading Algorithm Evaluation Real Time Scheduling Scheduling Examples

EEL 358 15

Process Burst TimeP1 53P2 17P3 68P4 24

The Gantt chart is:

Typically, higher average turnaround than SJF, but better response.

P1 P2 P3 P4 P1 P3 P4 P1 P3 P3

0 20 37 57 77 97 117 121 134 154 162

Round Robin (RR)

Page 16: Scheduling - Hong Kong Polytechnic Universitycsajaykr/myhome/file/Scheduling.pdf · Load Balancing Symmetric Multithreading Algorithm Evaluation Real Time Scheduling Scheduling Examples

EEL 358 16

Round Robin (RR)

Page 17: Scheduling - Hong Kong Polytechnic Universitycsajaykr/myhome/file/Scheduling.pdf · Load Balancing Symmetric Multithreading Algorithm Evaluation Real Time Scheduling Scheduling Examples

EEL 358 17

Round Robin (RR)

Page 18: Scheduling - Hong Kong Polytechnic Universitycsajaykr/myhome/file/Scheduling.pdf · Load Balancing Symmetric Multithreading Algorithm Evaluation Real Time Scheduling Scheduling Examples

EEL 358 18

Multilevel QueueReady queue → separate queues

foreground (interactive)background (batch)

Each queue → own scheduling algorithm, e.g.foreground – RRbackground – FCFS

Scheduling must be done between the queuesFixed priority scheduling; (i.e., serve all from foreground then from background), StarvationTime slice – each queue gets a certain amount of CPU time which it can schedule amongst its processes; i.e., 80% to foreground in RR20% to background in FCFS

Page 19: Scheduling - Hong Kong Polytechnic Universitycsajaykr/myhome/file/Scheduling.pdf · Load Balancing Symmetric Multithreading Algorithm Evaluation Real Time Scheduling Scheduling Examples

EEL 358 19

Multilevel Queue Scheduling

Page 20: Scheduling - Hong Kong Polytechnic Universitycsajaykr/myhome/file/Scheduling.pdf · Load Balancing Symmetric Multithreading Algorithm Evaluation Real Time Scheduling Scheduling Examples

EEL 358 20

Multilevel Feedback QueueSeparate processes → CPU burst characteristicsProcess moves up ↔ down in queues

Too much time ↓Aging ↑

Key pointsnumber of queuesscheduling algorithms for each queuemethod used to determine when to upgrade a processmethod used to determine when to demote a processmethod used to determine which queue a process will enter when that process needs service

Page 21: Scheduling - Hong Kong Polytechnic Universitycsajaykr/myhome/file/Scheduling.pdf · Load Balancing Symmetric Multithreading Algorithm Evaluation Real Time Scheduling Scheduling Examples

EEL 358 21

Example of Multilevel Feedback Queue

CPUPrimary CPUScheduling

Page 22: Scheduling - Hong Kong Polytechnic Universitycsajaykr/myhome/file/Scheduling.pdf · Load Balancing Symmetric Multithreading Algorithm Evaluation Real Time Scheduling Scheduling Examples

EEL 358 22

Multiple-Processor SchedulingMultiple CPUs → High scheduling complexityHomogeneous Processors

Asymmetric MultiprocessingNo data sharing, System data structures → one processor

Symmetric MultiprocessingSelf Scheduling, Ready queue

Processor AffinitySoft Vs Hard affinity

Load BalancingPush MigrationPull Migration

Page 23: Scheduling - Hong Kong Polytechnic Universitycsajaykr/myhome/file/Scheduling.pdf · Load Balancing Symmetric Multithreading Algorithm Evaluation Real Time Scheduling Scheduling Examples

EEL 358 23

Algorithm EvaluationDeterministic modeling

Takes a particular predetermined workload and defines the performance of each algorithm for that workload

Queueing modelsQueue of network serversLittle’s formula, l = λ × w

λ - Avg arrival rate, w - Avg waiting time, l - Avg queue length

SimulationModel, clockSimulation → modifies system with clock ↑Distribution driven simulationOnly # instances of an event, order?

Page 24: Scheduling - Hong Kong Polytechnic Universitycsajaykr/myhome/file/Scheduling.pdf · Load Balancing Symmetric Multithreading Algorithm Evaluation Real Time Scheduling Scheduling Examples

EEL 358 24

Evaluation of CPU Schedulers by Simulation

Page 25: Scheduling - Hong Kong Polytechnic Universitycsajaykr/myhome/file/Scheduling.pdf · Load Balancing Symmetric Multithreading Algorithm Evaluation Real Time Scheduling Scheduling Examples

EEL 358 25

Real-Time SchedulingHard real-time systems

Complete a critical task within a guaranteed timeAdmit or RejectImpossible with SS, VMResource Reservation

Soft real-time computingCritical processes receive priority over less fortunate onesGeneral-purpose systems → Multimedia, GraphicsPriority InversionPriority-inheritance protocol

Page 26: Scheduling - Hong Kong Polytechnic Universitycsajaykr/myhome/file/Scheduling.pdf · Load Balancing Symmetric Multithreading Algorithm Evaluation Real Time Scheduling Scheduling Examples

EEL 358 26

SchedulingPriority-based, preemptive schedulingThread runs → preempted by higher priority thread, terminates, QuDoes not guarantee execution of a real-time thread within time-limit

Thread Priorities32 level priority schemeReal time class → 16-32Variable class → 1-15Memory Management → Thread at 0 priority

Six Classes (Win32 API) – 1 + 5Within each 6 classes – 7 relative prioritiesCurrently selected foreground process → Scheduling Quantum ↑ 3

Example: Windows XP, 2000

Page 27: Scheduling - Hong Kong Polytechnic Universitycsajaykr/myhome/file/Scheduling.pdf · Load Balancing Symmetric Multithreading Algorithm Evaluation Real Time Scheduling Scheduling Examples

EEL 358 27

Windows XP, 2000 Priorities

Relative Priority ↓

Priority Classes →

← Base Priority

Page 28: Scheduling - Hong Kong Polytechnic Universitycsajaykr/myhome/file/Scheduling.pdf · Load Balancing Symmetric Multithreading Algorithm Evaluation Real Time Scheduling Scheduling Examples

EEL 358 28

Example: LinuxScheduling

Increased support for SMP, Scaling with # tasksProcessor affinity, load balancingHigh priority tasks → longer quanta, vice-versaReal time tasks – static prioritiesRest dynamic → nice values ± 5 (interactivity)

Numeric Priorities0-140 level priority schemeReal time → 0-99Nice values → 100-140