Operating Systems CSE 411
description
Transcript of Operating Systems CSE 411
![Page 1: Operating Systems CSE 411](https://reader033.fdocuments.in/reader033/viewer/2022052703/56813dfd550346895da7d6fb/html5/thumbnails/1.jpg)
Operating SystemsOperating SystemsCSE 411CSE 411
CPU ManagementCPU ManagementSept. 20 2006 - Lecture 7Sept. 20 2006 - Lecture 7
Instructor: Bhuvan UrgaonkarInstructor: Bhuvan Urgaonkar
![Page 2: Operating Systems CSE 411](https://reader033.fdocuments.in/reader033/viewer/2022052703/56813dfd550346895da7d6fb/html5/thumbnails/2.jpg)
• Last class– Dispatcher– Context switch, FCFS, SJF, SRPT, RR, Priority,
Quantum size– Read on your own: Multi-level (feedback) queue
based scheduling• Today
– More on CPU scheduling
![Page 3: Operating Systems CSE 411](https://reader033.fdocuments.in/reader033/viewer/2022052703/56813dfd550346895da7d6fb/html5/thumbnails/3.jpg)
Proportional-Share Schedulers
• A general class of scheduling algorithms• Process Pi given a CPU weight wi > 0• The scheduler needs to ensure the following
– forall i, j, |Ti(t1, t2)/Tj(t1,t2) - wi/wj| ≤ e– Given Pi and Pj were backlogged during [t1,t2]
• Who chooses the weights and how?• Application modeling problem: non-trivial
– Approaches: analytical, empirical• A part of my Ph.D. thesis
• Many PS schedulers developed in the 90s– E.g., Start-time Fair Queueing (Qlinux UT-Austin/Umass-
Amherst)
![Page 4: Operating Systems CSE 411](https://reader033.fdocuments.in/reader033/viewer/2022052703/56813dfd550346895da7d6fb/html5/thumbnails/4.jpg)
Lottery Scheduling[Carl Waldspurger, MIT,
~1995]• Perhaps the simplest proportional-share scheduler• Create lottery tickets equal to the sum of the weights
of all processes– What if the weights are non-integral?
• Draw a lottery ticket and schedule the process that owns that ticket– What if the process is not ready?
• Draw tickets only for ready processes– Homework 1: Calculate the time/space complexity of the
operations Lottery scheduling will involve– Likely question on Exam 1 !!!
![Page 5: Operating Systems CSE 411](https://reader033.fdocuments.in/reader033/viewer/2022052703/56813dfd550346895da7d6fb/html5/thumbnails/5.jpg)
Lottery Scheduling Example
1 4
2 5
3 6
7 10
8 11
9 12
13
14
15
9
P1=6 P2=9
Schedule P2
![Page 6: Operating Systems CSE 411](https://reader033.fdocuments.in/reader033/viewer/2022052703/56813dfd550346895da7d6fb/html5/thumbnails/6.jpg)
Lottery Scheduling Example
1 4
2 5
3 6
7 10
8 11
9 12
13
14
15
3
P1=6 P2=9
Schedule P1
![Page 7: Operating Systems CSE 411](https://reader033.fdocuments.in/reader033/viewer/2022052703/56813dfd550346895da7d6fb/html5/thumbnails/7.jpg)
Lottery Scheduling Example
1 4
2 5 11
6
7 10
8
3 9 12
13
14
15
11• As t ∞, processes will get their share (unless they were blocked a lot)• Problem with Lottery scheduling: Only probabilistic guarantee• What does the scheduler have to do
– When a new process arrives?– When a process terminates?
P1=6 P2=9
Schedule P2
![Page 8: Operating Systems CSE 411](https://reader033.fdocuments.in/reader033/viewer/2022052703/56813dfd550346895da7d6fb/html5/thumbnails/8.jpg)
Work Conservation• Examples of work-conserving schedulers:
All schedulers we have studied so far• Examples of non-work-conserving
schedulers: – DFS, a PS scheduler for multi-processors (Abhishek
Chandra, Umass, 2000, now at Univ. of Minnesota)• Experiments showed the scheduler had become NWC!• Fair Airport to convert into a WC scheme
NWCScheduler
WCScheduler
![Page 9: Operating Systems CSE 411](https://reader033.fdocuments.in/reader033/viewer/2022052703/56813dfd550346895da7d6fb/html5/thumbnails/9.jpg)
Reservation-based Schedulers
• Each process has a pair (x, y) – Divide time into periods of length y
each– Guaranteed to get x time units every
period• Can be Non-work-conserving
![Page 10: Operating Systems CSE 411](https://reader033.fdocuments.in/reader033/viewer/2022052703/56813dfd550346895da7d6fb/html5/thumbnails/10.jpg)
Rate Regulation: Leaky Bucket
• A type of reservation-based scheduling• Leaky bucket policing
– Rate ri for process Pi
– CPU cycles over period t ri * t
ri
bi
CPU requirement
CPU the process gets
Max. rate at which the process may progress
burst
![Page 11: Operating Systems CSE 411](https://reader033.fdocuments.in/reader033/viewer/2022052703/56813dfd550346895da7d6fb/html5/thumbnails/11.jpg)
Rate Regulation: Token Bucket
• A type of reservation-based scheduling• Token bucket policing
– Rate ri and burst bi for process Pi
– CPU cycles over period t ri * t + bi
ri
bi tokensCPU requirementburst
![Page 12: Operating Systems CSE 411](https://reader033.fdocuments.in/reader033/viewer/2022052703/56813dfd550346895da7d6fb/html5/thumbnails/12.jpg)
Deadline-based Scheduling
• Can be NWC• Several variants NP-hard• Real-time systems• “Soft” real-time systems
– E.g., media servers: 30 MPEG-1 frames/sec
– A few violations may be tolerable
![Page 13: Operating Systems CSE 411](https://reader033.fdocuments.in/reader033/viewer/2022052703/56813dfd550346895da7d6fb/html5/thumbnails/13.jpg)
An Interesting Problem: An Invitation to do Research on
CPU Scheduling
• Can we achieve the effect of a scheduler that can provide resource guarantees using a priority-based scheduler?
• You are welcome to talk to me during office hours if you find this interesting or if you have any thoughts on this
![Page 14: Operating Systems CSE 411](https://reader033.fdocuments.in/reader033/viewer/2022052703/56813dfd550346895da7d6fb/html5/thumbnails/14.jpg)
Hierarchical Schedulers
• Variety of schedulers• Subsets of processes with
different scheduling needs
Reservation-based(4, 10) (6, 10)
LotteryRound-robinw=1 w=2
UNIXUNIXProcesses
![Page 15: Operating Systems CSE 411](https://reader033.fdocuments.in/reader033/viewer/2022052703/56813dfd550346895da7d6fb/html5/thumbnails/15.jpg)
Scheduler Considerations: Context-Switch
Overhead• Switching context
– User mode to Kernel mode– Save PCB– Process interrupt (e.g, TCP/IP processing) if needed– Run scheduling algorithm– Load registers (e.g., PC) from PCB of chosen process – Flush TLB (will discuss this under memory management)
• Switching to user mode• Jumping to the proper location in the user program to restart
that program• Context switch time for Pentium/Linux: tens of microsec• So how often should the scheduler be invoked?
![Page 16: Operating Systems CSE 411](https://reader033.fdocuments.in/reader033/viewer/2022052703/56813dfd550346895da7d6fb/html5/thumbnails/16.jpg)
Scheduler Considerations:
Quantum Length• The duration for which a CPU-intensive process will
run before being scheduled out in favor of another process
• Different processes may have different quantum lengths– E.g., UNIX: Higher priority => Larger quantum
• Typically tens of msec in modern systems• Small => Context switch overhead high• Large => Bad responsiveness => Interactive
processes suffer
![Page 17: Operating Systems CSE 411](https://reader033.fdocuments.in/reader033/viewer/2022052703/56813dfd550346895da7d6fb/html5/thumbnails/17.jpg)
Scheduler Considerations:CPU Accounting
• Scheduler maintains CPU usage, last scheduling instant etc. in each PCB
• Who should be charged for the CPU usage during interrupt processing?– Optional reading: Resource containers (Rice
University, OSDI 1999, Gaurav Banga et al.)
![Page 18: Operating Systems CSE 411](https://reader033.fdocuments.in/reader033/viewer/2022052703/56813dfd550346895da7d6fb/html5/thumbnails/18.jpg)
Scheduler Considerations:Time and Space Requirements
• Run time (n processes)– FCFS: O(1)– RR: O(1)– Deadline-based algos: NP-hard variants, poly-time
heuristics• Update time: Operations done when set of
processes changes (new, terminate, block, become ready)
• Space requirements– Space to store various data structs
![Page 19: Operating Systems CSE 411](https://reader033.fdocuments.in/reader033/viewer/2022052703/56813dfd550346895da7d6fb/html5/thumbnails/19.jpg)
Scheduler Evaluation• Optimize one or more of response time,
waiting time, throughput, fairness, utilization, ..
• Overheads– Run time (time to pick the next process to schedule)– Update time– Space requirements
![Page 20: Operating Systems CSE 411](https://reader033.fdocuments.in/reader033/viewer/2022052703/56813dfd550346895da7d6fb/html5/thumbnails/20.jpg)
Analytical Approaches to Scheduler Evaluation
• Example 1: Our evaluation of FCFS and SJF• Example 2: Queueing Theory
– Little’s Law: applies to any scheduling discipline– avg_num_processes_in_system = tput *
avg_time_spent_in_system
– Queuing theory provides expressions for mean response time for certain scheduling policies (FCFS, PS, LCFS)
– Other statistical properties of response time only under restrictive assumptions on arrival process and service time
runningwaiting
yet to arrive serviced
![Page 21: Operating Systems CSE 411](https://reader033.fdocuments.in/reader033/viewer/2022052703/56813dfd550346895da7d6fb/html5/thumbnails/21.jpg)
Discussion: Analytical Approaches
• Pros:– Intellectually satisfying!– Quick, no code to be written– May provide generally applicable results
• Cons:– Often over-simplified
• Hard to model complex scheduling algorithms• Lack of info about workloads
![Page 22: Operating Systems CSE 411](https://reader033.fdocuments.in/reader033/viewer/2022052703/56813dfd550346895da7d6fb/html5/thumbnails/22.jpg)
Simulation-based Evaluation
• Write software that mimics the behavior of the scheduler
• Subject it to realistic workload• Observe output and make inferences about
performance of scheduler• Only need to know the algorithms, no need to
do complex math• Easier to implement than the actual system
![Page 23: Operating Systems CSE 411](https://reader033.fdocuments.in/reader033/viewer/2022052703/56813dfd550346895da7d6fb/html5/thumbnails/23.jpg)
Prototyping• Build it!
![Page 24: Operating Systems CSE 411](https://reader033.fdocuments.in/reader033/viewer/2022052703/56813dfd550346895da7d6fb/html5/thumbnails/24.jpg)
Analysis, Simulation, and Prototyping
Compared
Analysis
Simulation
Prototyping
accuracy,programming skills
effort, time investment,mathematical skills, generality
![Page 25: Operating Systems CSE 411](https://reader033.fdocuments.in/reader033/viewer/2022052703/56813dfd550346895da7d6fb/html5/thumbnails/25.jpg)
Hybrid ApproachesAnalysis
Simulation Prototyping
![Page 26: Operating Systems CSE 411](https://reader033.fdocuments.in/reader033/viewer/2022052703/56813dfd550346895da7d6fb/html5/thumbnails/26.jpg)
Threads
![Page 27: Operating Systems CSE 411](https://reader033.fdocuments.in/reader033/viewer/2022052703/56813dfd550346895da7d6fb/html5/thumbnails/27.jpg)
What is a Thread?
• A basic unit of CPU utilization like a process (not necessarily known to the OS though)
• “Smaller” than a process– Part of a process– Shares code + data + some other OS resources with
other threads that belong to the same process
![Page 28: Operating Systems CSE 411](https://reader033.fdocuments.in/reader033/viewer/2022052703/56813dfd550346895da7d6fb/html5/thumbnails/28.jpg)
User Threads• Thread management done by user-level
threads library• OS doesn’t know about the existence of these
threads• Three primary thread libraries:
– POSIX Pthreads– Win32 threads– Java threads
![Page 29: Operating Systems CSE 411](https://reader033.fdocuments.in/reader033/viewer/2022052703/56813dfd550346895da7d6fb/html5/thumbnails/29.jpg)
Kernel Threads• OS sees and manages these threads• OS provides system calls to create, terminate,
etc. (just like the system calls it provides for processes)
• Examples– Windows XP/2000– Solaris– Linux– Tru64 UNIX– Mac OS X
![Page 30: Operating Systems CSE 411](https://reader033.fdocuments.in/reader033/viewer/2022052703/56813dfd550346895da7d6fb/html5/thumbnails/30.jpg)
Benefits• Responsiveness• Resource Sharing• Economy• Utilization of MP Architectures