CSCI [4|6] 730 Operating Systems Scheduling Plans

CSCI [4|6] 730 Operating Systems Scheduling Plans

CSCI [4|6] 730 Operating Systems CPU Scheduling 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 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 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 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 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 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 http://pages.cs.wisc.edu/~remzi/OSTEP/ 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 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 Review: Scheduling Optimization Criteria • Max CPU utilization – keep the CPU as busy as possible • Max throughput – # of processes that finish over time – Min turnaround• No scheduler time – amount can of meet time to all finish these a process criteria – • Min Which waiting criteria time – amountare most of time important a ready processdepend has on been types waiting of to execute processes and expectations of the system • Min response• E.g. time response – amount time is timekey on between the desktop submitting a request• Throughput and receiving is more a response 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 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 Proce Burst Arriva ss Time l Time RR vs. STCF P1 6 0 P2 8 0 P3 10 0 P1 P2 P3 STCF Time: 0 6 14 24 • 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 Tradeoffs RR STCF + Excellent response times + Achieves optimal, low + With N process and time slice of turnaround times Q… - Bad response times + No process waits more than (N-1)/Q time slices - Inherently unfair + Achieves fairness - Short jobs finish first + 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 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 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 Problems With MLFQ So Far… Q0 High priority processes Q1 always take • Starvation precedence Q2sleep(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, Q2 monopolizes CPU time Time: 0 2 4 6 8 10 12 14 17 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 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 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 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 Time: 0 2 4 6 8 10 12 14 16 Round robin 21 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 Parameterizing MLFQ • MLFQ meets our goals – Balances response time and turnaround time – Does not require prior knowledge about processes • But, it has many knobs to tune – Number of queues? – How to divide CPU time between the queues? – For each queue: • Which scheduling regime to use? • Time slice/quantum? – Method for demoting priorities? – Method for boosting priorities? 23 Maria Hybinette, UGA MLFQ In Practice • Many OSs use MLFQ-like schedulers – Example: Windows NT/2000/XP/Vista, Solaris, FreeBSD • OSs ship with “reasonable” MLFQ parameters – Variable length time slices • High priority queues – short time slices • Low priority queues – long time slices – Priority 0 sometimes reserved for OS processes 24 Maria Hybinette, UGA Giving Hints/Advice • Some OSes allow users/processes to give the scheduler “hints” about priorities • Example: nice command on Linux $ nice <options> <command [args …]> – Run the command at the specified priority – Priorities range from -20 (high) to 19 (low) 25 Maria Hybinette, UGA Recap • So-far schedulers discussed are designed to optimize performance: – Minimum response times – Minimum turnaround times • MLFQ achieves these goals, but it’s complicated

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    23 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us