Transcript
Page 1: Cpr E 308 Spring 2005 Process Scheduling Basic Question: Which process goes next? Personal Computers –Few processes, interactive, low response time Batch

Cpr E 308 Spring 2005

Process Scheduling

Basic Question: Which process goes next?

• Personal Computers– Few processes, interactive, low response time

• Batch Systems (Compute Servers)– Many processes, not interactive, throughput is

important

• Real Time Systems– Guaranteed response times, must meet deadlines

Page 2: Cpr E 308 Spring 2005 Process Scheduling Basic Question: Which process goes next? Personal Computers –Few processes, interactive, low response time Batch

Cpr E 308 Spring 2005

Context Switch

• One process stops and another one starts

• Process Contexts stored in the Kernel Process Table

• Significant Overhead for each Context Switch

Page 3: Cpr E 308 Spring 2005 Process Scheduling Basic Question: Which process goes next? Personal Computers –Few processes, interactive, low response time Batch

Cpr E 308 Spring 2005

Non Preemptive Scheduling

• Context Switch happens only when the process gives up the CPU (wait for I/O, process completes, etc)– Example: DOS

• Bad: A user process can cause the system to hang

• Good: Fewer context switches

Page 4: Cpr E 308 Spring 2005 Process Scheduling Basic Question: Which process goes next? Personal Computers –Few processes, interactive, low response time Batch

Cpr E 308 Spring 2005

Preemptive Scheduling

• CPU forcibly taken away from process and given to a new process

• Preemptive Scheduling used on current PC operating systems (Windows, Linux)

• Enabled by interrupts

Page 5: Cpr E 308 Spring 2005 Process Scheduling Basic Question: Which process goes next? Personal Computers –Few processes, interactive, low response time Batch

Cpr E 308 Spring 2005

Goals of Batch Scheduling

• Maximize Throughput (jobs per minute)

• Fast Response Times

• Fairness to Processes

• Often the goals conflict with each other…

Page 6: Cpr E 308 Spring 2005 Process Scheduling Basic Question: Which process goes next? Personal Computers –Few processes, interactive, low response time Batch

Cpr E 308 Spring 2005

First Come First Serve (FCFS) (non preemptive)

• Rule: Service processes (jobs) according to order of arrival

• Implementation1. Maintain queue of current processes 2. Schedule first in queue; Scheduled job executes until it finishes or blocks

for I/O3. A new job is added to the end of the queue

• Advantages: Simple, easy to implement

• Problems– Example: a short job arriving soon after a long one– What about simultaneous, or near simultaneous arrivals?– Doesn’t optimize throughput or the response time

Page 7: Cpr E 308 Spring 2005 Process Scheduling Basic Question: Which process goes next? Personal Computers –Few processes, interactive, low response time Batch

Cpr E 308 Spring 2005

Shortest Job First (non-preemptive)

• Suppose 3 jobsarrive

• Shortest Job First:

• Scheduler X:

8 2

1 113

1

8 10 11

Sum of response times = 15

Sum of response times = 29

Page 8: Cpr E 308 Spring 2005 Process Scheduling Basic Question: Which process goes next? Personal Computers –Few processes, interactive, low response time Batch

Cpr E 308 Spring 2005

Shortest Remaining Time Next (preemptive)

• Shortest job First is fine if all jobs arrive simultaneously

• If not, use shortest remaining time next– Strategy: Next schedule the job with the

shortest time to completion

• Starvation: A long job might be continually pre-empted by many short jobs

Page 9: Cpr E 308 Spring 2005 Process Scheduling Basic Question: Which process goes next? Personal Computers –Few processes, interactive, low response time Batch

Cpr E 308 Spring 2005

Realistically . . .

• Don’t know the length of jobs

• Jobs don’t run to completion– run till they block for user input

• How long is that?

– predict using past behavior

– Guess next job’s running time = average running time of all jobs so far from the user

Copyright © 2002 Thomas W.Doeppner. All rights reserved

Page 10: Cpr E 308 Spring 2005 Process Scheduling Basic Question: Which process goes next? Personal Computers –Few processes, interactive, low response time Batch

Cpr E 308 Spring 2005

Mean Guessing

i

Ti guess(i)

Copyright © 2002 Thomas W.Doeppner. All rights reserved

Page 11: Cpr E 308 Spring 2005 Process Scheduling Basic Question: Which process goes next? Personal Computers –Few processes, interactive, low response time Batch

Cpr E 308 Spring 2005

Exponential Averaging

• guessi = a(new_data) + (1-a)(guessi-1)– a: weight given to new data– (1-a): weight given to previous guess

Copyright © 2002 Thomas W.Doeppner. All rights reserved

Page 12: Cpr E 308 Spring 2005 Process Scheduling Basic Question: Which process goes next? Personal Computers –Few processes, interactive, low response time Batch

Cpr E 308 Spring 2005

Better Guessing

i

Ti

guess(i)

Copyright © 2002 Thomas W.Doeppner. All rights reserved

Page 13: Cpr E 308 Spring 2005 Process Scheduling Basic Question: Which process goes next? Personal Computers –Few processes, interactive, low response time Batch

Cpr E 308 Spring 2005

Round Robin (Preemptive)

• Give CPU time to each process by turn

• Circular queue of ready processes

• Quantum = CPU time allotted every turn

• How to choose the value of the quantum?o Too small might mean high context switch overhead

o Too large might mean bad response times

o Typically a few 10s of milliseconds

o If quantum is very high, then similar to FCFS

Page 14: Cpr E 308 Spring 2005 Process Scheduling Basic Question: Which process goes next? Personal Computers –Few processes, interactive, low response time Batch

Cpr E 308 Spring 2005

Round Robin Example

• Three processes– P1 = 24ms– P2 = 6ms– P3 = 3ms

• Quantum = 4ms

• What is the schedule?

Page 15: Cpr E 308 Spring 2005 Process Scheduling Basic Question: Which process goes next? Personal Computers –Few processes, interactive, low response time Batch

Cpr E 308 Spring 2005

Round Robin

• Better than shortest remaining time next– Long job will not be overwhelmed by short

jobs

• Better than first come first serve– Long job arriving early will not overwhelm

future short jobs

Page 16: Cpr E 308 Spring 2005 Process Scheduling Basic Question: Which process goes next? Personal Computers –Few processes, interactive, low response time Batch

Cpr E 308 Spring 2005

Priority Scheduling

• Different Priorities– Background process sending mail versus– Shell process accepting input

• “nice” command in UNIX – allows user to reduce the priority of a process

Page 17: Cpr E 308 Spring 2005 Process Scheduling Basic Question: Which process goes next? Personal Computers –Few processes, interactive, low response time Batch

Cpr E 308 Spring 2005

Priority Scheduling Goals

• Schedule jobs with highest priority first

• High priority jobs should not overwhelm the others– Might decrease priority with time

Page 18: Cpr E 308 Spring 2005 Process Scheduling Basic Question: Which process goes next? Personal Computers –Few processes, interactive, low response time Batch

Cpr E 308 Spring 2005

Multiple Queues – Static Version

System level processes

Interactive processes

Batch processes

• Lower priority queues don’t run if higher priority queues non-empty• Could time slice between queues

High

Low

Page 19: Cpr E 308 Spring 2005 Process Scheduling Basic Question: Which process goes next? Personal Computers –Few processes, interactive, low response time Batch

Cpr E 308 Spring 2005

Multiple Queues – Dynamic Version

Quantum = 1

Quantum = 2

Quantum = 4

• Process enters high priority level

• If takes more than 1 quantum, moved to second highest priority, …..

High

Low

Page 20: Cpr E 308 Spring 2005 Process Scheduling Basic Question: Which process goes next? Personal Computers –Few processes, interactive, low response time Batch

Cpr E 308 Spring 2005

Multiple Queues – Dynamic Version

• Higher priority = faster service, but short service times

• Reduce number of context switches for long processes

• What about a process which became interactive after a long bout of computation?– Increase priority?

Page 21: Cpr E 308 Spring 2005 Process Scheduling Basic Question: Which process goes next? Personal Computers –Few processes, interactive, low response time Batch

Cpr E 308 Spring 2005

Real-Time Scheduling

• Provide time guarantees

• Upper bound on response times– Programmer’s job!

– Every level of the system

• Soft versus hard real-time– Streaming mp3 player versus air-traffic controller

Page 22: Cpr E 308 Spring 2005 Process Scheduling Basic Question: Which process goes next? Personal Computers –Few processes, interactive, low response time Batch

Cpr E 308 Spring 2005

Real-Time Scheduling

• Is this set of processes schedulable?– A: once every 100ms, 20ms CPU time– B: once every 200ms, 80ms CPU time– C: once every 100ms, 50ms CPU time

• If schedulable, still have to draw up a schedule for the processes

Page 23: Cpr E 308 Spring 2005 Process Scheduling Basic Question: Which process goes next? Personal Computers –Few processes, interactive, low response time Batch

Cpr E 308 Spring 2005

CPU Scheduling: Summary

• FCFS

• Shortest job first, shortest remaining job next

• Round robin – context switch overhead

• Priority scheduling – Multi-level queues

• Real-time Scheduling – Schedulability


Top Related