Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Cpr E 308 Spring 2005 Process Scheduling Basic Question: Which process goes next? Personal Computers –Few processes, interactive, low response time Batch."— Presentation transcript:

1 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

2 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

3 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

4 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

5 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…

6 Cpr E 308 Spring 2005 First Come First Serve (FCFS) (non preemptive) Rule: Service processes (jobs) according to order of arrival Implementation 1.Maintain queue of current processes 2.Schedule first in queue; Scheduled job executes until it finishes or blocks for I/O 3.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

7 Cpr E 308 Spring 2005 Shortest Job First (non-preemptive) Suppose 3 jobs arrive Shortest Job First: Scheduler X: 8 2 1113 1 81011 Sum of response times = 15 Sum of response times = 29

8 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

9 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

10 Cpr E 308 Spring 2005 Mean Guessing i TiTi guess(i) Copyright © 2002 Thomas W.Doeppner. All rights reserved

11 Cpr E 308 Spring 2005 Exponential Averaging guess i = a(new_data) + (1-a)(guess i-1 ) –a: weight given to new data –(1-a): weight given to previous guess Copyright © 2002 Thomas W.Doeppner. All rights reserved

12 Cpr E 308 Spring 2005 Better Guessing i TiTi guess(i) Copyright © 2002 Thomas W.Doeppner. All rights reserved

13 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? oToo small might mean high context switch overhead oToo large might mean bad response times oTypically a few 10s of milliseconds oIf quantum is very high, then similar to FCFS

14 Cpr E 308 Spring 2005 Round Robin Example Three processes –P1 = 24ms –P2 = 6ms –P3 = 3ms Quantum = 4ms What is the schedule?

15 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

16 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

17 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

18 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

19 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

20 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?

21 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

22 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

23 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


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

Similar presentations


Ads by Google