Operating System Process Scheduling (Ch 4.2, 5.1 - 5.3)
-
date post
22-Dec-2015 -
Category
Documents
-
view
222 -
download
3
Transcript of Operating System Process Scheduling (Ch 4.2, 5.1 - 5.3)
![Page 1: Operating System Process Scheduling (Ch 4.2, 5.1 - 5.3)](https://reader034.fdocuments.in/reader034/viewer/2022052603/56649d7e5503460f94a60cd3/html5/thumbnails/1.jpg)
Operating System
Process Scheduling
(Ch 4.2, 5.1 - 5.3)
![Page 2: Operating System Process Scheduling (Ch 4.2, 5.1 - 5.3)](https://reader034.fdocuments.in/reader034/viewer/2022052603/56649d7e5503460f94a60cd3/html5/thumbnails/2.jpg)
Schedulers
Short-Term– “Which process gets the CPU?”– Fast, since once per 100 ms
Long-Term (batch)– “Which process gets the Ready Queue?”
Medium-Term (Unix)– “Which Ready Queue process to memory?”– Swapping
![Page 3: Operating System Process Scheduling (Ch 4.2, 5.1 - 5.3)](https://reader034.fdocuments.in/reader034/viewer/2022052603/56649d7e5503460f94a60cd3/html5/thumbnails/3.jpg)
CPU-IO Burst Cycle
add
read
(I/O Wait)
store
increment
write
(I/O Wait)Burst Duration
Fre
quen
cy
![Page 4: Operating System Process Scheduling (Ch 4.2, 5.1 - 5.3)](https://reader034.fdocuments.in/reader034/viewer/2022052603/56649d7e5503460f94a60cd3/html5/thumbnails/4.jpg)
Preemptive Scheduling
Four times to re-schedule1 Running to Waiting (I/O wait)2 Running to Ready (time slice)3 Waiting to Ready (I/O completion)4 Termination
#2 optional ==> “Preemptive” Timing may cause unexpected results
– updating shared variable– kernel saving state
![Page 5: Operating System Process Scheduling (Ch 4.2, 5.1 - 5.3)](https://reader034.fdocuments.in/reader034/viewer/2022052603/56649d7e5503460f94a60cd3/html5/thumbnails/5.jpg)
Question
What Performance Criteria Should the Scheduler Seek to Optimize?– Ex: CPU minimize time spent in queue– Others?
![Page 6: Operating System Process Scheduling (Ch 4.2, 5.1 - 5.3)](https://reader034.fdocuments.in/reader034/viewer/2022052603/56649d7e5503460f94a60cd3/html5/thumbnails/6.jpg)
Scheduling Criteria1 CPU utilization (40 to 90)2 Throughput (processes / hour)3 Turn-around time4 Waiting time (in queue) Maximize #1, #2 Minimize #3, #4 Response time
– Self-regulated by users (go home)– Bounded ==> Variance!
![Page 7: Operating System Process Scheduling (Ch 4.2, 5.1 - 5.3)](https://reader034.fdocuments.in/reader034/viewer/2022052603/56649d7e5503460f94a60cd3/html5/thumbnails/7.jpg)
First-Come, First-ServedProcess
A
B
C
Burst Time
8
1
1
0 8 9 10
A B C
Avg Wait Time (0 + 8 + 9) / 3 = 5.7
GanttChart
![Page 8: Operating System Process Scheduling (Ch 4.2, 5.1 - 5.3)](https://reader034.fdocuments.in/reader034/viewer/2022052603/56649d7e5503460f94a60cd3/html5/thumbnails/8.jpg)
Shortest Job First
0 1 2 10
AB C
Avg Wait Time (0 + 1 + 2) / 3 = 1 Optimal Avg Wait Prediction tough … Ideas?
Process
A
B
C
Burst Time
8
1
1
![Page 9: Operating System Process Scheduling (Ch 4.2, 5.1 - 5.3)](https://reader034.fdocuments.in/reader034/viewer/2022052603/56649d7e5503460f94a60cd3/html5/thumbnails/9.jpg)
Priority Scheduling SJF is a special case
Process
A
B
C
Burst Time
8
1
1
Priority
2
1
3
0 1 9 10
AB C
Avg Wait Time (0 + 1 + 9) / 3 = 3.3
![Page 10: Operating System Process Scheduling (Ch 4.2, 5.1 - 5.3)](https://reader034.fdocuments.in/reader034/viewer/2022052603/56649d7e5503460f94a60cd3/html5/thumbnails/10.jpg)
Priority Scheduling Criteria? Internal
– open files– memory requirements– CPU time used - time slice expired (RR)– process age - I/O wait completed
External– $– department sponsoring work– process importance– super-user (root) - nice
![Page 11: Operating System Process Scheduling (Ch 4.2, 5.1 - 5.3)](https://reader034.fdocuments.in/reader034/viewer/2022052603/56649d7e5503460f94a60cd3/html5/thumbnails/11.jpg)
Round Robin Fixed time-slice and Preemption
Process
A
B
C
Burst Time
5
3
3
B CA B C A B CA A
Avg = (8 + 9 + 11) / 3 = 9.3 FCFS? SJF?
8 9 11
![Page 12: Operating System Process Scheduling (Ch 4.2, 5.1 - 5.3)](https://reader034.fdocuments.in/reader034/viewer/2022052603/56649d7e5503460f94a60cd3/html5/thumbnails/12.jpg)
Round Robin Fun
Process
A
B
C
Burst Time
10
10
10
Turn-around time?– q = 10– q = 1– q --> 0
![Page 13: Operating System Process Scheduling (Ch 4.2, 5.1 - 5.3)](https://reader034.fdocuments.in/reader034/viewer/2022052603/56649d7e5503460f94a60cd3/html5/thumbnails/13.jpg)
More Round Robin FunProcess
A
B
C
D
Burst Time
6
3
1
7
1 2 3 4 5 6 7Time Quantum
Avg
. Tur
n-ar
ound
Tim
e
Rule:80% withinone quantum
![Page 14: Operating System Process Scheduling (Ch 4.2, 5.1 - 5.3)](https://reader034.fdocuments.in/reader034/viewer/2022052603/56649d7e5503460f94a60cd3/html5/thumbnails/14.jpg)
Fun with SchedulingProcess
A
B
C
Burst Time
10
1
2
Priority
2
1
3
Gantt Charts: – FCFS– SJF– Priority– RR (q=1)
Performance: – Throughput– Waiting time– Turnaround time
![Page 15: Operating System Process Scheduling (Ch 4.2, 5.1 - 5.3)](https://reader034.fdocuments.in/reader034/viewer/2022052603/56649d7e5503460f94a60cd3/html5/thumbnails/15.jpg)
More Fun with SchedulingProcess
A
B
C
Arrival Time
0.0
0.4
1.0
Burst Time
8
4
1
Turn around time: – FCFS– SJF– q=1 CPU idle– q=0.5 CPU idle
![Page 16: Operating System Process Scheduling (Ch 4.2, 5.1 - 5.3)](https://reader034.fdocuments.in/reader034/viewer/2022052603/56649d7e5503460f94a60cd3/html5/thumbnails/16.jpg)
Multi-Level Queues
SystemPriority 1
Priority 2
Priority 3
Interactive
Batch
Categories of processes
Run all in 1 first, then 2 … Starvation! Divide between queues: 70% 1, 15% 2 …
... ...
![Page 17: Operating System Process Scheduling (Ch 4.2, 5.1 - 5.3)](https://reader034.fdocuments.in/reader034/viewer/2022052603/56649d7e5503460f94a60cd3/html5/thumbnails/17.jpg)
Multi-Level Feedback Queues
QueuePriority 1
Priority 2
Priority 3
Queue
Queue
1 Quantum
2 Quanta
4 Quanta
Time slice expensive but want interactive
Consider process needing 100 quanta– 1, 4, 8, 16, 32, 64 = 7 swaps!
Favor interactive users
... ... ...
![Page 18: Operating System Process Scheduling (Ch 4.2, 5.1 - 5.3)](https://reader034.fdocuments.in/reader034/viewer/2022052603/56649d7e5503460f94a60cd3/html5/thumbnails/18.jpg)
Evaluating Scheduling Algorithms
With all these possible scheduling algorithms, how to choose one?– Ease of implementation– Efficiency of implementation / low overhead– Performance evaluation (next slide)
![Page 19: Operating System Process Scheduling (Ch 4.2, 5.1 - 5.3)](https://reader034.fdocuments.in/reader034/viewer/2022052603/56649d7e5503460f94a60cd3/html5/thumbnails/19.jpg)
Performance Evaluation Methods
Deterministic methods / Gantt charts– Use more realistic workloads
Queueing theory – Mathematical techniques– Uses probablistic models of jobs / CPU
utilization Simulation
– Probabilistic or trace-driven
![Page 20: Operating System Process Scheduling (Ch 4.2, 5.1 - 5.3)](https://reader034.fdocuments.in/reader034/viewer/2022052603/56649d7e5503460f94a60cd3/html5/thumbnails/20.jpg)
Linux Process Scheduling
Two classes of processes:– Real-Time– Normal
Real-Time:– Always run Real-Time above Normal– Round-Robin or FIFO– “Soft” not “Hard”
![Page 21: Operating System Process Scheduling (Ch 4.2, 5.1 - 5.3)](https://reader034.fdocuments.in/reader034/viewer/2022052603/56649d7e5503460f94a60cd3/html5/thumbnails/21.jpg)
Linux Process Scheduling
Normal: Credit-Based– process with most credits is selected– time-slice then lose a credit (0, then suspend)– no runnable process (all suspended), add to
every process:credits = credits/2 + priority
Automatically favors I/O bound processes
![Page 22: Operating System Process Scheduling (Ch 4.2, 5.1 - 5.3)](https://reader034.fdocuments.in/reader034/viewer/2022052603/56649d7e5503460f94a60cd3/html5/thumbnails/22.jpg)
Questions
What is a PCB? List steps that occur during interrupt Explain how SJF works True or False:
– FCFS is optimal in terms of avg waiting time– Most processes are CPU bound– The shorter the time quantum, the better
micro-shell.c?
![Page 23: Operating System Process Scheduling (Ch 4.2, 5.1 - 5.3)](https://reader034.fdocuments.in/reader034/viewer/2022052603/56649d7e5503460f94a60cd3/html5/thumbnails/23.jpg)
Interrupt Handling Stores program counter (hardware) Loads new program counter (hardware)
– jump to interrupt service procedure Save PCB information (assembly) Set up new stack (assembly) Set “waiting” process to “ready” (C) Re-schedule (probably awakened process) (C)
– “dispatcher” in SOS, “schedule” in Linux If new process, called a context-switch
![Page 24: Operating System Process Scheduling (Ch 4.2, 5.1 - 5.3)](https://reader034.fdocuments.in/reader034/viewer/2022052603/56649d7e5503460f94a60cd3/html5/thumbnails/24.jpg)
Outline
Processes – PCB – Interrupt Handlers
Scheduling– Algorithms – Linux
– WinNT
![Page 25: Operating System Process Scheduling (Ch 4.2, 5.1 - 5.3)](https://reader034.fdocuments.in/reader034/viewer/2022052603/56649d7e5503460f94a60cd3/html5/thumbnails/25.jpg)
Windows NT Scheduling
Basic scheduling unit is a thread Priority based scheduling per thread Preemptive operating system No shortest job first, no quotas
![Page 26: Operating System Process Scheduling (Ch 4.2, 5.1 - 5.3)](https://reader034.fdocuments.in/reader034/viewer/2022052603/56649d7e5503460f94a60cd3/html5/thumbnails/26.jpg)
Priority Assignment NT kernel uses 31 priority levels
– 31 is the highest; 0 is system idle thread– Realtime priorities: 16 - 31– Dynamic priorities: 1 - 15
Users specify a priority class: realtime (24) , high (13), normal (8) and idle (4)
– and a relative priority: highest (+2), above normal (+1), normal (0), below
normal (-1), and lowest (-2)
– to establish the starting priority Threads also have a current priority
![Page 27: Operating System Process Scheduling (Ch 4.2, 5.1 - 5.3)](https://reader034.fdocuments.in/reader034/viewer/2022052603/56649d7e5503460f94a60cd3/html5/thumbnails/27.jpg)
Quantum
Determines how long a Thread runs once selected
Varies based on:– NT Workstation or NT Server– Intel or Alpha hardware– Foreground/Background application threads
How do you think it varies with each?
![Page 28: Operating System Process Scheduling (Ch 4.2, 5.1 - 5.3)](https://reader034.fdocuments.in/reader034/viewer/2022052603/56649d7e5503460f94a60cd3/html5/thumbnails/28.jpg)
Dispatcher Ready List
Keeps track of all Ready-to-execute threads
Queue of threads assigned to each level
DispatcherReady List
11
10
9
8
7
Ready Threads
![Page 29: Operating System Process Scheduling (Ch 4.2, 5.1 - 5.3)](https://reader034.fdocuments.in/reader034/viewer/2022052603/56649d7e5503460f94a60cd3/html5/thumbnails/29.jpg)
FindReadyThread
Locates the highest priority thread that is ready to execute
Scans dispatcher ready list Picks front thread in highest priority
nonempty queue
When is this like round robin?
![Page 30: Operating System Process Scheduling (Ch 4.2, 5.1 - 5.3)](https://reader034.fdocuments.in/reader034/viewer/2022052603/56649d7e5503460f94a60cd3/html5/thumbnails/30.jpg)
Boosting and Decay
Boost priority – Event that “wakes” blocked thread– Boosts never exceed priority 15 for dynamic– Realtime priorities are not boosted
Decay priority– by one for each quantum– decays only to starting priority (no lower)
![Page 31: Operating System Process Scheduling (Ch 4.2, 5.1 - 5.3)](https://reader034.fdocuments.in/reader034/viewer/2022052603/56649d7e5503460f94a60cd3/html5/thumbnails/31.jpg)
Starvation Prevention
Low priority threads may never execute “Anti-CPU starvation policy”
– thread that has not executed for 3 seconds– boost priority to 15– double quantum
Decay is swift not gradual after this boost