Presentation is loading. Please wait.

Presentation is loading. Please wait.

Slide 6-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Threads and Scheduling 6.

Similar presentations


Presentation on theme: "Slide 6-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Threads and Scheduling 6."— Presentation transcript:

1 Slide 6-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Threads and Scheduling 6

2 Slide 6-2 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Announcements Program Assignment #1 due Tuesday Feb. 15 at 11 am –TA will explain parts b-d in recitation Read chapters 6 and 7

3 Slide 6-3 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Scheduling A process can be switched out due to: –blocking on I/O –voluntarily yielding the CPU –being preemptive time sliced, i.e interrupted –termination The OS’s scheduler implements a scheduling policy that selects the next process to run from the ready queue, based on several criteria –CPU utilization - 40% to 90% –Throughput - # processes completed/second –Turnaround Time - how long it takes to execute that process –Waiting Time - sum of time waiting in the ready queue –Response Time - time until first response

4 Slide 6-4 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Scheduling The dispatcher gives control of the CPU to the process selected by the scheduler, which involves –switching context –switching to user mode –jumping to the proper location in the user program to restart that program

5 Slide 6-5 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 FCFS Scheduling First Come First Serve: order of arrival dictates order of scheduling If processes arrive in order P1, P2, P3, then Gantt chart of CPU service time is: ProcessCPU Service Time P124 P23 P33 P1P2P3 0 242730

6 Slide 6-6 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 FCFS Scheduling If processes arrive in reverse order P3, P2, P1, then Gantt chart of CPU service time is: ProcessCPU Service Time P124 P23 P33 P1P2P3 03630

7 Slide 6-7 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 FCFS Scheduling average wait time is (0+24+27)/3 = 17 seconds in top scenario average wait time is (0+3+6)/3 = 3 seconds in 2 nd scenario FCFS wait times are generally not minimal, and vary if process service times vary a lot P1P2P3 03630 P1P2P3 0 242730

8 Slide 6-8 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 FCFS Scheduling If there is one CPU-bound process, and many I/O bound processes, then –convoy effect: I/O bound processes finish their I/O and wait for one large process to complete, then execute quickly, block on I/O, while CPU- bound process dominates again

9 Slide 6-9 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Shortest Job First Scheduling Choose the process/thread with the lowest service time –gives priority to shortest processes –minimizes the average wait time can prove this - out of 24 possibilities, this has the lowest average wait time intuition: moving a short process before a long one decreases the wait time of short processes more than it increases the wait time of long processes ProcessCPU Service Time P16 P28 P37 P43 03916 P1P3P2 24 av wait time = (0+3+9+16)/4 = 7 seconds

10 Slide 6-10 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Shortest Job First Scheduling It is difficult to know the length of each job a priori –difficult to know the length of each CPU burst of a job So predict the burst length of each job/process/thread –for each thread, track its pattern of CPU usage, and keep a running average could be a sliding window instead, this is often an exponentially weighted average –Ave(n) = (1-  *CPU_usage(n) +  *Ave(n-1), where 0<  <1 –This can be rewritten Ave(n) =  (1-  )*  n-i-1 * CPU_usage(i) summed from i=0 to n-1 Can be preemptive, i.e. when a new job arrives in ready queue, if its service time is less than currently executing job’s service time, then it preempts current job

11 Slide 6-11 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Priority Scheduling SJF is a special case of priority scheduling, where priority is given to short jobs Any criteria can be used to decide on a priority –measurable characteristics of the process –external criteria Can be preemptive, i.e. higher priority process arrives in the ready queue and preempts a lower priority process ProcessCPU Service Time Priority P1103 P211 P324 P415 P552 P2 01616 P5P1P3 19 P4 18

12 Slide 6-12 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Priority Scheduling Can starve low priority processes A solution is aging: as low priority processes age, their priority is increased –if priorities range from 1-128, can increase (decrement) the priority by 1 every T seconds

13 Slide 6-13 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Deadline Scheduling Hard real time systems require that certain processes must complete execution within a certain time, or the system crashes –robots Admission control policy –No notion of not being able to admit a process in FCFS, SJF, and priority –Here, can’t admit a process if its deadline can’t be met –This is typical of many Quality-of-Service scheduling policies in networking - can’t admit a new stream/flow of packets if its QOS deadlines/guarantees cannot be met ProcessCPU Service Time Deadline from now P0350575 P1125550 P24751050 P3250none P475200

14 Slide 6-14 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Deadline Scheduling i  (p i ) Deadline 0 350 575 1 125 550 2 475 1050 3 250 (none) 4 75 200 p0p0 p1p1 p2p2 p3p3 p4p4 1275 1050550200 0 Allocates service by deadline May not be feasible p0p0 p1p1 p2p2 p3p3 p4p4 p0p0 p1p1 p2p2 p3p3 p4p4 575

15 Slide 6-15 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Round Robin Scheduling The ready queue is treated as a circular queue, and the CPU scheduler rotates among the processes in the ready queue, giving each a time slice, after which it is preempted by a timer interrupt and another process is started –useful for time sharing multitasking systems - most widely used scheduling algorithm –combines FCFS and preemption –simple and fair, though wait times can be long Fair: If there are n processes, each process gets 1/n of CPU Simple: Don’t need to know service times a priori A process can finish before its time slice is up. The scheduler just selects the next process in the queue

16 Slide 6-16 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Round Robin Scheduling Suppose we use a time slice of 4 ms, and ignoring context switch overhead Now P1 is time sliced out, and P2 and P3 are allowed to run sooner than FCFS average wait time is 5.66 ms ProcessCPU Service Time (ms) P124 P23 P33 P1 04710 P2 P1 1422182630 P1

17 Slide 6-17 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Round Robin Scheduling Context switch overhead affects the choice of time slice –context switches can take 10 microseconds to copy register state to/from memory on a 1 GHz CPU, that’s 10000 wasted cycles per context switch! –if the time slice is on the order of a context switch, then CPU spends most of its time context switching –Typically choose time slice to be large enough so that only 10% of CPU time is spent context switching –Most modern systems choose time slices of 10-100 ms

18 Slide 6-18 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Round Robin Scheduling Weighted Round Robin - each process is given some number of time slices, not just one per round this is a way to implement priorities with preemptive time slicing

19 Slide 6-19 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Multi-level Queue Scheduling Partitions ready queue into several queues –different processes have different needs, e.g. foreground and background –so don’t apply the same scheduling policy to every process, e.g. foreground gets RR, background gets FCFS Queues can be organized by priority, or each given a percentage of CPU, or hybrid

20 Slide 6-20 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Multi-level Feedback Queues Allows processes to move between queues Criteria for movement depends –could be aging –could be CPU-bound processes move down the hierarchy of queues, allowing interactive and I/O-bound processes to move up give a time slice to each queue, with smaller time slices higher up if a process doesn’t finish by its time slice, it is moved down to the next lowest queue


Download ppt "Slide 6-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Threads and Scheduling 6."

Similar presentations


Ads by Google