Top Banner
CS 3013 & CS 502 S ummer 2006 Scheduling 1 Scheduling The art and science of allocating the CPU and other resources to processes
22

CS 3013 & CS 502 Summer 2006 Scheduling1 The art and science of allocating the CPU and other resources to processes.

Dec 20, 2015

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: CS 3013 & CS 502 Summer 2006 Scheduling1 The art and science of allocating the CPU and other resources to processes.

CS 3013 & CS 502 Summer 2006

Scheduling 1

Scheduling

The art and science of allocating the CPU and other

resources to processes

Page 2: CS 3013 & CS 502 Summer 2006 Scheduling1 The art and science of allocating the CPU and other resources to processes.

CS 3013 & CS 502 Summer 2006

Scheduling 2

• Bursts of CPU usage alternate with periods of I/O wait– a CPU-bound process– an I/O bound process

• Which process should have higher CPU priority?• Which process should have higher I/O or disk priority?

Page 3: CS 3013 & CS 502 Summer 2006 Scheduling1 The art and science of allocating the CPU and other resources to processes.

CS 3013 & CS 502 Summer 2006

Scheduling 3

Process Scheduling

• When to run scheduler1. Process create2. Process exit3. Process blocks4. System interrupt

• Non-preemptive – process runs until it blocks or gives up CPU (1,2,3)

• Preemptive – process runs for some time or until some asynchronous action interrupts, then scheduler selects a process to run (1-4)

Page 4: CS 3013 & CS 502 Summer 2006 Scheduling1 The art and science of allocating the CPU and other resources to processes.

CS 3013 & CS 502 Summer 2006

Scheduling 4

Scheduling – Policies

• Issues– Fairness – don’t starve process– Priorities – most important first– Deadlines – task X must be done by time t– Optimization – e.g. throughput, response time

• Reality - No universal scheduling policy– Many models– Determine what to optimize - metrics– Select an appropriate one and adjust based on

experience

Page 5: CS 3013 & CS 502 Summer 2006 Scheduling1 The art and science of allocating the CPU and other resources to processes.

CS 3013 & CS 502 Summer 2006

Scheduling 5

Process Scheduling – System Needs

Page 6: CS 3013 & CS 502 Summer 2006 Scheduling1 The art and science of allocating the CPU and other resources to processes.

CS 3013 & CS 502 Summer 2006

Scheduling 6

Scheduling – Metrics

• Simplicity – easy to implement• Job latency – time from start to completion• Interactive latency – time from action start

to expected system response• Throughput – number of jobs completed• Utilization – keep processor and/or subset

of I/O devices busy• Determinism – insure that jobs get done

before some time or event• Fairness – every job makes progress

Page 7: CS 3013 & CS 502 Summer 2006 Scheduling1 The art and science of allocating the CPU and other resources to processes.

CS 3013 & CS 502 Summer 2006

Scheduling 7

Batch System Scheduling

Note: Number of Processes in Memory determines the degree of multiprogramming

Page 8: CS 3013 & CS 502 Summer 2006 Scheduling1 The art and science of allocating the CPU and other resources to processes.

CS 3013 & CS 502 Summer 2006

Scheduling 8

Interactive System Scheduling

• First-Come, First-Served (FCFS)• Round Robin (RR)• Shortest Completion Time First

(SCTF)• Priority

Page 9: CS 3013 & CS 502 Summer 2006 Scheduling1 The art and science of allocating the CPU and other resources to processes.

CS 3013 & CS 502 Summer 2006

Scheduling 9

Scheduling Policies – FCFS

• First Come, First Served (FCFS)– Easy to implement– Non-preemptive– Minimizes context switch overhead– Favors compute bound jobs– Short jobs penalized

• I.e., once a longer job gets the CPU, it gets in the way of a bunch of shorter jobs

Page 10: CS 3013 & CS 502 Summer 2006 Scheduling1 The art and science of allocating the CPU and other resources to processes.

CS 3013 & CS 502 Summer 2006

Scheduling 10

Scheduling Policies – Round Robin

• Round Robin (RR)– Preemptive– Ready processes given a quantum of

time when scheduled– Process runs until quantum expires or

until it blocks (whichever comes first)

– Suitable for interactive (timesharing) systems

– Setting quantum is critical for efficiency

Page 11: CS 3013 & CS 502 Summer 2006 Scheduling1 The art and science of allocating the CPU and other resources to processes.

CS 3013 & CS 502 Summer 2006

Scheduling 11

Scheduling Policies – Comparison

10 jobs each take 100 seconds – look at when jobs complete

• FCFS – job 1: 100s, job 2: 200s … job 10:1000s

• RR– 1 sec quantum– Job 1: 991s, job 2 : 992s …

• RR good for short jobs – worse for long jobs

Page 12: CS 3013 & CS 502 Summer 2006 Scheduling1 The art and science of allocating the CPU and other resources to processes.

CS 3013 & CS 502 Summer 2006

Scheduling 12

Scheduling Policies – RR example

• Utilization– A and B compute bound jobs:– 100 ms @ 100%

CPU– C:– 1 ms CPU and 10 ms disk I/O– Quantum:– 100 ms

• CPU utilization = (100 + 100 +1)/210 = 95.7 %

– Quantum:– 1 ms (assume 0 overhead)• ABCAB(C-I/O)ABABAB ….AB• CPU utilization = 100%

– Smaller quantum can improve utilization – but consider overhead of context switches

Page 13: CS 3013 & CS 502 Summer 2006 Scheduling1 The art and science of allocating the CPU and other resources to processes.

CS 3013 & CS 502 Summer 2006

Scheduling 13

Scheduling Policies – STCF

• STCF – shortest time to completion first

• or shortest job first

– Can be preemptive– Good for throughput– Example

• jobs A = 100, B = 1, C = 2 msec• Done B @ 1, C @ 3 , A @ 103• Ave = 35, (for RR (1) about 37)

– Reality – knowledge of job runtime??

Page 14: CS 3013 & CS 502 Summer 2006 Scheduling1 The art and science of allocating the CPU and other resources to processes.

CS 3013 & CS 502 Summer 2006

Scheduling 14

Scheduling Policies – Priority

• Priority Scheduling– Preemptive– Process are given priorities and ranked

• Maybe done with multiple queues - multilevel

– Highest priority runs next• With multilevel queues

– Select from highest queue– Round robin within queue

– Recalculate priority – many algorithms• E.g. increase priority of I/O intensive jobs• E.g. favor processes in memory • Must still meet system goals – e.g. response time

Page 15: CS 3013 & CS 502 Summer 2006 Scheduling1 The art and science of allocating the CPU and other resources to processes.

CS 3013 & CS 502 Summer 2006

Scheduling 15

Scheduling Policy Problem

• Priority inversion – A has high priority, B has medium priority, C

has lowest priority – C acquires a resource that A needs to progress– A attempts to get resource, fails and busy

waits• C never runs to release resource!

or– A attempts to get resources, fails and blocks

• B (medium priority) enters system & hogs CPU• C never runs!

• Priority scheduling can’t be naive

Page 16: CS 3013 & CS 502 Summer 2006 Scheduling1 The art and science of allocating the CPU and other resources to processes.

CS 3013 & CS 502 Summer 2006

Scheduling 16

Solution

• Some systems increase the priority of a process/task/job to

• Match level of resourceor

• Match level of waiting process

Page 17: CS 3013 & CS 502 Summer 2006 Scheduling1 The art and science of allocating the CPU and other resources to processes.

CS 3013 & CS 502 Summer 2006

Scheduling 17

Scheduling Policies – Realtime

• Real Time System – processes have deadlines– Deadlines known– (usually) preemptive

• Static algorithm – periodic process behavior– Rate Monotonic Scheduling (RMS) – priority =

1/period• Dynamic – aperiodic

– Earliest Deadline First (EDF) – select process that must complete the soonest

More about this subject later in the term

Page 18: CS 3013 & CS 502 Summer 2006 Scheduling1 The art and science of allocating the CPU and other resources to processes.

CS 3013 & CS 502 Summer 2006

Scheduling 18

Scheduling – Examples

• Unix – multilevel - many policies and many policy changes over time

• Linux – multilevel with 3 major levels– Realtime FIFO – Realtime round robin– Timesharing

• Win/NT – multilevel– Threads scheduled – fibers not visible to

scheduler– Jobs – groups of processes are given quotas

that contribute to priorities

Page 19: CS 3013 & CS 502 Summer 2006 Scheduling1 The art and science of allocating the CPU and other resources to processes.

CS 3013 & CS 502 Summer 2006

Scheduling 19

Scheduling

• Until now:– focus on processes and CPU • Going forward:– focus on system resources

• memory, storage, I/O devices, web resources, …

• Space sharing– How can resources be split up? – e.g. disk, memory

• Time sharing – What gets to use something and for how long?– Whenever there are more requests than can be

granted• Typically resource can not be divided – I/O port, device, …

Page 20: CS 3013 & CS 502 Summer 2006 Scheduling1 The art and science of allocating the CPU and other resources to processes.

CS 3013 & CS 502 Summer 2006

Scheduling 20

Scheduling

• General theme – what is the “best way” to run n processes on k resources? ( k < n)

• Conflicting Objectives – no one “best way”– Latency vs. throughput– Speed vs. fairness

• Incomplete knowledge – E.g. – does user know how long a job will take

• Real world limitations– E.g. context switching takes CPU time– Job loads are unpredictable

Page 21: CS 3013 & CS 502 Summer 2006 Scheduling1 The art and science of allocating the CPU and other resources to processes.

CS 3013 & CS 502 Summer 2006

Scheduling 21

Scheduling (continued)

• Bottom line – scheduling is hard!– Know the models– Adjust based upon experience

Page 22: CS 3013 & CS 502 Summer 2006 Scheduling1 The art and science of allocating the CPU and other resources to processes.

CS 3013 & CS 502 Summer 2006

Scheduling 22

Break

(next topic)