Top Banner
2.5 Scheduling 2.5 Scheduling
45

2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

Jan 21, 2016

Download

Documents

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: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

2.5 Scheduling2.5 Scheduling

Page 2: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

2.5 Scheduling2.5 Scheduling

Given a multiprogramming system, Given a multiprogramming system, there are many times when more than there are many times when more than 1 process is waiting for the CPU (in the 1 process is waiting for the CPU (in the ready queue).ready queue).

The The schedulerscheduler (using a (using a scheduling scheduling algorithmalgorithm) decides which process will ) decides which process will run next.run next.

User satisfaction is important.User satisfaction is important.

Page 3: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

Context switchContext switch

When the CPU changes from one process When the CPU changes from one process to another.to another.

Expensive operation.Expensive operation.1.1. User mode to kernel modeUser mode to kernel mode

2.2. Save state of current processSave state of current process Registers, invalidate cache, MMU (Note: Pipeline Registers, invalidate cache, MMU (Note: Pipeline

becomes useless.)becomes useless.)

3.3. Run schedulerRun scheduler Pick next process to runPick next process to run Load state of next processLoad state of next process

4.4. Run next processRun next process

Page 4: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

Process Process behaviobehavio

rr

Types:Types:1.1. I/O bound – spend most time I/O bound – spend most time

performing I/Operforming I/O

2.2. Compute bound – spend most time Compute bound – spend most time performing computationperforming computation

3.3. MixtureMixture

Page 5: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

When do we need to When do we need to schedule?schedule?

creation (before/after parent?)creation (before/after parent?)exitexitblock (I/O, semaphore, sleep, wait, block (I/O, semaphore, sleep, wait,

etc.)etc.) I/O interrupt/completionI/O interrupt/completionclock interruptclock interrupt

non preemptive (run until you block or non preemptive (run until you block or “cooperate”)“cooperate”)

preemptivepreemptive

Page 6: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

Scheduling environmentsScheduling environments

1.1. BatchBatch

2.2. InteractiveInteractive

3.3. Real timeReal time

Page 7: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

Scheduling algorithm goalsScheduling algorithm goals(for all systems)(for all systems)

Page 8: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

Scheduling algorithm goalsScheduling algorithm goals(for batch systems)(for batch systems)

Page 9: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

Scheduling algorithm goalsScheduling algorithm goals(for interactive systems)(for interactive systems)

Page 10: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

Scheduling algorithm goalsScheduling algorithm goals(for real-time systems)(for real-time systems)

Page 11: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

Concepts & definitionsConcepts & definitions

Throughput = # of jobs completed per Throughput = # of jobs completed per hourhour

Page 12: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

Concepts & definitionsConcepts & definitions

Turnaround time = avg of “start (submit) Turnaround time = avg of “start (submit) to completion” times; avg wait timeto completion” times; avg wait time

Page 13: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

Concepts & definitionsConcepts & definitions

CPU utilization = avg of CPU busynessCPU utilization = avg of CPU busyness

Page 14: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

Concepts & definitionsConcepts & definitions

Response time = time between issuing a Response time = time between issuing a command and getting the resultcommand and getting the result

Page 15: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

Concepts & definitionsConcepts & definitions

Proportionality = user perception that Proportionality = user perception that “complex” things take a long time and “complex” things take a long time and that is fine, but “simple” things must be that is fine, but “simple” things must be quickquick

Page 16: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

Concepts & definitionsConcepts & definitions

Predictability = regularity, especially Predictability = regularity, especially important for audio and video streamingimportant for audio and video streaming

Page 17: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

BATCH SCHEDULINGBATCH SCHEDULING

Page 18: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

Batch schedulingBatch scheduling

1.1. First-come first-servedFirst-come first-served

2.2. Shortest job firstShortest job first

3.3. Shortest remaining time nextShortest remaining time next

4.4. Three-level schedulingThree-level scheduling

Page 19: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

Batch schedulingBatch scheduling

1. First-come first-served1. First-come first-servedSimpleSimple

Non preemptiveNon preemptive

Process runs until it either blocks on I/O Process runs until it either blocks on I/O or finishesor finishes

Page 20: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

Batch schedulingBatch scheduling

2. Shortest job first2. Shortest job firstOptimal turnaround time (when all start Optimal turnaround time (when all start

together)together)

Requires that we know run times Requires that we know run times a prioria priori

Page 21: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

Batch schedulingBatch scheduling

3. Shortest remaining time next3. Shortest remaining time nextPreemptive version of shortest job firstPreemptive version of shortest job firstRequires Requires a prioria priori information informationWhen a new job arrives, its total time is When a new job arrives, its total time is

compared to the current process’ compared to the current process’ remaining time. If the new job needs remaining time. If the new job needs less time to finish, the new job is less time to finish, the new job is started.started.

New, short jobs get good service New, short jobs get good service

Page 22: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

Batch schedulingBatch scheduling

4. Three-level scheduling4. Three-level scheduling1.1. Admission scheduler – chooses next job Admission scheduler – chooses next job

beginbegin2.2. Memory scheduler – which jobs are kept in Memory scheduler – which jobs are kept in

memory and which jobs are swapped to memory and which jobs are swapped to diskdiskHow long swapped in or out?How long swapped in or out?How much CPU time recently?How much CPU time recently?How big is the process?How big is the process?How important is the process?How important is the process?

3.3. CPU scheduler – picks which runs nextCPU scheduler – picks which runs next Degree of multiprogramming – number of Degree of multiprogramming – number of

processes in memoryprocesses in memory

Page 23: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

INTERACTIVE INTERACTIVE SCHEDULINGSCHEDULING

Page 24: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

Interactive schedulingInteractive scheduling

1.1. Round-robin schedulingRound-robin scheduling

2.2. Priority schedulingPriority scheduling

3.3. Multiple queuesMultiple queues

4.4. Shortest process nextShortest process next

5.5. Guaranteed schedulingGuaranteed scheduling

6.6. Lottery schedulingLottery scheduling

7.7. Fair-share schedulingFair-share scheduling

Page 25: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

Interactive schedulingInteractive scheduling

1. Round-robin scheduling1. Round-robin schedulingSimple, fair, widely used, preemptiveSimple, fair, widely used, preemptiveQuantum = time intervalQuantum = time interval

Process/context switch is expensiveProcess/context switch is expensiveToo small and we waste timeToo small and we waste timeToo large and interactive system will appear Too large and interactive system will appear

sluggishsluggish~20-50 msec is good~20-50 msec is good

Every process has equal priorityEvery process has equal priority

Page 26: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

Interactive schedulingInteractive scheduling

2. Priority scheduling2. Priority schedulingEach process is assigned a priority; Each process is assigned a priority;

process with highest priority is next to process with highest priority is next to run.run.

Types:Types:1.1. staticstatic

2.2. dynamic (ex. I/O bound jobs get a boost)dynamic (ex. I/O bound jobs get a boost)

Unix/Linux Unix/Linux nicenice command command

Page 27: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

Interactive schedulingInteractive scheduling

Ex. 4 priorities & RR w/in a priorityEx. 4 priorities & RR w/in a priority

Page 28: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

Interactive schedulingInteractive scheduling

3. Multiple queues3. Multiple queuesdifferent Q’s for different types of jobsdifferent Q’s for different types of jobs

Ex. 4 queues for:Ex. 4 queues for:Terminal, I/O, short quantum, and long Terminal, I/O, short quantum, and long

quantumquantum

Page 29: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

Interactive schedulingInteractive scheduling

4. Shortest process next4. Shortest process nextShortest job first always produces min Shortest job first always produces min

avg response time (for batch systems)avg response time (for batch systems)How do we estimate this (for interactive How do we estimate this (for interactive

jobs)?jobs)?

Page 30: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

Interactive schedulingInteractive scheduling

4. Shortest process next4. Shortest process nextShortest job first always produces min avg Shortest job first always produces min avg

response time (for batch systems)response time (for batch systems)How do we estimate this (for interactive How do we estimate this (for interactive

jobs)?jobs)?From recent behavior (of interactive commands, TFrom recent behavior (of interactive commands, T ii))Example of aging (or IIR filter)Example of aging (or IIR filter)

alpha near 1 implies little memoryalpha near 1 implies little memory alpha near 0 implies much memoryalpha near 0 implies much memory

11 )1(ˆ iii TTT

Page 31: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

Interactive schedulingInteractive scheduling

Example of aging (or IIR filter)Example of aging (or IIR filter)alpha near 1 implies little memoryalpha near 1 implies little memoryalpha near 0 implies much memoryalpha near 0 implies much memory

How can we “increase” the “memory?”How can we “increase” the “memory?”

11 )1(ˆ iii TTT

Page 32: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

Interactive schedulingInteractive scheduling

5. Guaranteed scheduling5. Guaranteed schedulingGiven n processes, each process should Given n processes, each process should

get 1/n of the CPU timeget 1/n of the CPU timeSay we keep track of the actual CPU Say we keep track of the actual CPU

used vs. what we should receive used vs. what we should receive (entitled to/deserved).(entitled to/deserved).

K = actual / entitledK = actual / entitledK = 1 K = 1 we got what we deserved we got what we deservedK < 1 K < 1 we got less than deserved we got less than deservedK > 1 K > 1 we got more than deserved we got more than deserved

Pick process w/ min K to run nextPick process w/ min K to run next

Page 33: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

Interactive schedulingInteractive scheduling

6. Lottery scheduling6. Lottery schedulingEach process gets tickets; # of tickets Each process gets tickets; # of tickets

can vary from process to process.can vary from process to process.If your ticket is chosen, you run next.If your ticket is chosen, you run next.

Highly responsive (new process might Highly responsive (new process might run right away)run right away)

Processes can cooperate (give each Processes can cooperate (give each other their tickets)other their tickets)

Page 34: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

Interactive schedulingInteractive scheduling

7. Fair-share scheduling7. Fair-share schedulingConsider who (user) owns the processConsider who (user) owns the processEx.Ex.

User A has 1 processUser A has 1 processUser B has 9 processesUser B has 9 processes

Should user A get 10% and user B get 90%?Should user A get 10% and user B get 90%?Or should A get 50% and B get 50% (5.6% Or should A get 50% and B get 50% (5.6%

for each of the 9 processes)?for each of the 9 processes)?Latter is fair-share.Latter is fair-share.

Page 35: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

REAL TIME SCHEDULINGREAL TIME SCHEDULING

Page 36: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

Real time schedulingReal time scheduling

Time plays an essential role.Time plays an essential role.

System must react w/in a fixed amount of System must react w/in a fixed amount of time.time.

Page 37: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

Real time schedulingReal time scheduling

Categories:Categories:1.1. Hard – absolute deadlines must be metHard – absolute deadlines must be met

2.2. Soft – missing an occasional deadline is Soft – missing an occasional deadline is tolerabletolerable

Page 38: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

Real time schedulingReal time scheduling

Event types:Event types:1.1. Periodic = occurring at regular intervalsPeriodic = occurring at regular intervals

2.2. Aperiodic = occurring unpredictablyAperiodic = occurring unpredictably

Page 39: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

Real time schedulingReal time scheduling

Algorithm types:Algorithm types:1.1. Static (before the system starts running)Static (before the system starts running)

2.2. Dynamic (scheduling decisions at run time)Dynamic (scheduling decisions at run time)

Page 40: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

Real time schedulingReal time scheduling

Given m Given m periodicperiodic events. events.

Event i occurs w/ period PEvent i occurs w/ period Pii, and requires C, and requires Cii seconds of CPU time.seconds of CPU time.

SchedulableSchedulable iff: iff:

11

m

i i

i

P

CWe’re basically normalizing C (event length) by P (event frequency).

Page 41: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

11

m

i i

i

P

CSchedulable exampleSchedulable example

Given periods PGiven periods Pii = = 100, 200, and 500 100, 200, and 500 msec and CPU msec and CPU time requirements time requirements of Cof Cii = 50, 30, 100 = 50, 30, 100 msecmsec

Can we handle Can we handle another event w/ another event w/ PP44=1 sec?=1 sec? Yes, as long as Yes, as long as

CC44<=150 msec<=150 msec

185.02.015.05.0500

100

200

30

100

50

11000

?

500

100

200

30

100

50

11000

150

500

100

200

30

100

50

Page 42: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

THREADS & THREAD THREADS & THREAD SCHEDULINGSCHEDULING

Page 43: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

Thread scheduling types:Thread scheduling types:

1.1. User levelUser level

2.2. Kernel levelKernel level

Page 44: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

Thread schedulingThread scheduling

1. User level threads1. User level threads No clock interrupts (per thread)No clock interrupts (per thread) A compute bound thread will dominate its A compute bound thread will dominate its

process but not the CPUprocess but not the CPU A thread can yield to other threads within the A thread can yield to other threads within the

same processsame process Typically round robin or priorityTypically round robin or priority

Tradeoffs:Tradeoffs:

+ Context switch from thread to thread is simpler+ Context switch from thread to thread is simpler

+ App specific thread scheduler can be used+ App specific thread scheduler can be used

- If a thread blocks on I/O, the entire process (all - If a thread blocks on I/O, the entire process (all threads) blockthreads) block

Page 45: 2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

Thread schedulingThread scheduling

2. Kernel level threads2. Kernel level threadsThreads scheduled like processes.Threads scheduled like processes.

Tradeoffs:Tradeoffs:

- Context switch from thread to thread is - Context switch from thread to thread is expensive (but scheduler can make expensive (but scheduler can make more informed choices).more informed choices).

+ A thread, blocking on I/O, doesn’t + A thread, blocking on I/O, doesn’t block all other threads in process.block all other threads in process.