csci 4 6 730 operating systems
play

CSCI [4|6] 730 Operating Systems CPU Scheduling Maria Hybinette, - PDF document

CSCI [4|6] 730 Operating Systems CPU Scheduling Maria Hybinette, UGA Maria Hybinette, UGA Scheduling Plans Introductory Concepts Embellish on the introductory concepts Case studies Look at real time scheduling. Practical


  1. CSCI [4|6] 730 Operating Systems CPU Scheduling Maria Hybinette, UGA Maria Hybinette, UGA Scheduling Plans • Introductory Concepts • Embellish on the introductory concepts • Case studies • Look at real time scheduling. – Practical system have some theory, and lots of tweaking (hacking). Maria Hybinette, UGA Maria Hybinette, UGA

  2. Why Schedule? Management of Resources • Resource: Anything that can be used by only a single [set] process(es) at any instant in time – Not just the CPU, what else? • Hardware device or a piece of information – Examples: • CPU (time, time slice) • Tape drive, Disk space, Memory (spatial) • Locked record in a database (information, synchronization) • Focus today managing the CPU, short term scheduling. Maria Hybinette, UGA Maria Hybinette, UGA Multilevel Feedback Queue • Give new processes high priority and small time slice (preference to smaller jobs) • If process doesn‘t finish job bump it to the next lower level priority queue (with a larger time-slice). • Common in interactive system Maria Hybinette, UGA Maria Hybinette, UGA

  3. Case Studies: Early Scheduling Implementations • Windows and Early MS-DOS – Non-Multitasking (so no scheduler needed) • Mac OS 9 – Kernel schedule processes: • A Round Robin Preemptive (fair, each process gets a fair share of CPU – Processes • schedules multiple (MACH) threads that use a cooperative thread schedule manager – each process has its own copy of the scheduler. Maria Hybinette, UGA Maria Hybinette, UGA Case Studies: Modern Scheduling Implementations • Multilevel Feedback Queue w/ Preemption: – FreeBSD, NetBSD Solaris, Linux pre 2.5 – Example Linux: 0-99 real time tasks (200ms quanta), 100-140 nice tasks (10 ms quanta -> expired queue) • Cooperative Scheduling (no preemption) – Windows 3.1x, Mac OS pre3 (thread level) • O(1) Scheduling – time to schedule independent of number of tasks in system – Linux 2.5-2.6.24 ((v2.6.0 first version ~2003/2004) • Completely Fair Scheduler (link read) – Maximizes CPU utilization while maximizing interactive performance / Red/Black Tree instead of Queue – Linux 2.6.23+ Maria Hybinette, UGA Maria Hybinette, UGA

  4. Review: Real World Scheduling: • Characteristics of the processes – Are they I/O bound or CPU bound? – Do we have statistics about the processes, e.g., deadlines? – Is their behavior predictable? • Characteristics of the machine – How many CPUs or cores? – Can we preempt processes? – How is memory shared by the CPUs? • Characteristics of the user – Are the processes interactive (e.g. desktop apps)? • Drove the the development of Linux Scheduling protocols. – Or are the processes background jobs? Maria Hybinette, UGA Maria Hybinette, UGA http://pages.cs.wisc.edu/~remzi/OSTEP/

  5. Basic Scheduler Architecture • Scheduler selects from the ready processes, and assigns them to a CPU – System may have >1 CPU – Various different approaches for selecting processes • Scheduling decisions are made when a process: 1. Switches from running to waiting No preemption 2. Terminates 3. Switches from running to ready Preemption 4. Switches from waiting to ready • Scheduler may have access to additional information – Process deadlines, data in shared memory, etc. Maria Hybinette, UGA Maria Hybinette, UGA Beware: Dispatch Latency • The dispatcher gives control of the CPU to the process selected by the scheduler – Switches context – Switching to/from kernel mode/user mode – Saving the old EIP, loading the new EIP • Warning: dispatching incurs a cost – Context switching and mode switch are expensive – Adds latency to processing times • It is advantageous to minimize process switching Maria Hybinette, UGA Maria Hybinette, UGA

  6. Review: Scheduling Optimization Criteria • Max CPU utilization – keep the CPU as busy as possible • Max throughput – # of processes that finish over time – Min turnaround time – amount of time to finish a process • No scheduler can meet all these criteria – Min waiting time – amount of time a ready process has been waiting to • Which criteria are most important depend on types of execute processes and expectations of the system • Min response time – amount time between submitting • E.g. response time is key on the desktop a request and receiving a response • Throughput is more important for MapReduce – E.g. time between clicking a button and seeing a response • Fairness – all processes receive min/max fair CPU resources 11 Maria Hybinette, UGA Maria Hybinette, UGA Interactive Systems & Tension • Imagine you are typing/clicking in a desktop app – You don’t care about turnaround time – What you care about is responsiveness • E.g. if you start typing but the app doesn’t show the text for 10 seconds, you’ll become frustrated • Response time = first run time – arrival time – Round Robin • Turn around time : – SJCF 12 Maria Hybinette, UGA Maria Hybinette, UGA

  7. Proce Burst Arriva RR vs. STCF ss Time l Time P1 6 0 P2 8 0 P3 10 0 P1 P2 P3 6 14 24 Time: 0 STCF • Avg. turnaround time: (6 + 14 + 24) / 3 = 14.7 • Avg. response time: (0 + 6 + 14) / 3 = 6.7 P1 P2 P3 P1 P2 P3 P1 P2 P3 P2 P3 Time: 0 2 4 6 8 10 12 14 16 18 20 24 RR • 2 second time slices • Avg. turnaround time: (14 + 20 + 24) / 3 = 19.3 • Avg. response time: (0 + 2 + 4) / 3 = 2 Maria Hybinette, UGA Maria Hybinette, UGA Tradeoffs RR STCF + + Achieves optimal, low Excellent response times turnaround times + With N process and time slice of Q … - Bad response times + No process waits more than - Inherently unfair ( N -1)/ Q time slices + - Short jobs finish first Achieves fairness + Each process receives 1/ N CPU time - Worst possible turnaround times - If Q is large ! FIFO behavior • Optimizing for turnaround or response time is a trade-off • Achieving both requires more sophisticated algorithms Maria Hybinette, UGA Maria Hybinette, UGA

  8. Earliest Deadline First (EDF) • Each process has a deadline it must finish by • Priorities are assigned according to deadlines – Tighter deadlines are given higher priority Process Burst Arrival Dead Time Time line P1 15 0 40 P2 3 4 10 P1 P2 P1 P3 P4 P3 P1 P3 6 10 20 0 4 7 10 13 17 20 28 P4 4 13 18 • EDF is optimal (assuming preemption) [uniprocessors] • But, it’s only useful if processes have known deadlines – Typically used in real-time OS’s Maria Hybinette, UGA Maria Hybinette, UGA https://en.wikipedia.org/wiki/Earliest_deadline_first_scheduling Rules of MFLQ • Rule 1 : If Priority(A) > Priority(B), A runs, B doesn’t • Rule 2 : If Priority(A) = Priority(B), A & B run in RR • Rule 3 : Processes start at the highest priority • Rule 4 : – Rule 4a : If a process uses an entire time slice while running, its priority is reduced – Rule 4b : If a process gives up the CPU before its time slice is up, it remains at the same priority level 16 Maria Hybinette, UGA Maria Hybinette, UGA

  9. Problems With MLFQ So Far… High priority Q0 processes always take Q1 • Starvation precedence Q2 sleep(1ms) just before over low time slice expires priority Time: 0 2 4 6 8 10 12 14 Unscrupulous Q0 process never gets Q1 • Cheating demoted, monopolizes Q2 CPU time Time: 0 2 4 6 8 10 12 14 17 Maria Hybinette, UGA Maria Hybinette, UGA MLFQ Rule 5: Priority Boost • Rule 5 : After some time period S , move all processes to the highest priority queue • Solves two problems: – Starvation: low priority processes will eventually become high priority, acquire CPU time – Dynamic behavior: a CPU bound process that has become interactive will now be high priority 18 Maria Hybinette, UGA Maria Hybinette, UGA

  10. Priority Boost Example Priority Starvation :( Boost Without Priority Boost With Priority Boost Q0 Q0 Q1 Q1 Q2 Q2 Time: 0 2 4 6 8 10 12 14 Time: 0 2 4 6 8 10 12 14 16 18 19 Maria Hybinette, UGA Maria Hybinette, UGA Revised Rule 4: Cheat Prevention • Rule 4a and 4b let a process game the scheduler – Repeatedly yield just before the time limit expires • Solution: better accounting – Rule 4 : Once a process uses up its time allotment at a given priority (regardless of whether it gave up the CPU), demote its priority – Basically, keep track of total CPU time used by each process during each time interval S • Instead of just looking at continuous CPU time 20 Maria Hybinette, UGA Maria Hybinette, UGA

  11. Preventing Cheating Time Time sleep(1ms) just before allotment allotment time slice expires exhausted exhausted Without Cheat Prevention With Cheat Prevention Q0 Q0 Q1 Q1 Q2 Q2 Time: 0 2 4 6 8 10 12 14 16 Time: 0 2 4 6 8 10 12 14 Round robin 21 Maria Hybinette, UGA Maria Hybinette, UGA MLFQ Rule Review • Rule 1 : If Priority(A) > Priority(B), A runs, B doesn’t • Rule 2 : If Priority(A) = Priority(B), A & B run in RR • Rule 3 : Processes start at the highest priority • Rule 4 : Once a process uses up its time allotment at a given priority, demote it • Rule 5 : After some time period S , move all processes to the highest priority queue 22 Maria Hybinette, UGA Maria Hybinette, UGA

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend