![Page 1: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/1.jpg)
![Page 2: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/2.jpg)
2
ProgramProgram ProcessProcess
Abstract Computing Environment
FileManager
MemoryManager
DeviceManager
ProtectionProtection
DeadlockDeadlockSynchronizationSynchronization
ProcessDescription
ProcessDescription
CPUCPU Other H/WOther H/W
SchedulerScheduler ResourceManager
ResourceManagerResource
Manager
ResourceManagerResource
Manager
ResourceManager
MemoryMemoryDevicesDevices
Process Mgr
![Page 3: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/3.jpg)
Scheduling mechanism is the part of the process manager that handles the removal of the running process of CPU and the selection of another process on the basis of a particular strategy Scheduler chooses one from the ready threads
to use the CPU when it is available Scheduling policy determines when it is time
for a thread to be removed from the CPU and which ready thread should be allocated the CPU next
3
![Page 4: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/4.jpg)
4
ReadyList
ReadyList SchedulerScheduler CPUCPU
ResourceManager
ResourceManager
ResourcesResources
Preemption or voluntary yield
Allocate Request
DoneNewThread job
jobjob
jobjob
“Ready”“Running”
“Blocked”
![Page 5: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/5.jpg)
New threads put into ready state and added to ready list
Running thread may cease using CPU for any of four reasons Thread has completed its execution Thread requests a resource, but can’t get it Thread voluntarily releases CPU Thread is preempted by scheduler and
involuntarily releases CPU Scheduling policy determines which
thread gets the CPU and when a thread is preempted
5
![Page 6: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/6.jpg)
6
Ready Process
EnqueuerEnqueuer ReadyList
ReadyList
DispatcherDispatcher ContextSwitcher
ContextSwitcher
ProcessDescriptor
ProcessDescriptor
CPUCPU
From OtherStates
Running Process
![Page 7: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/7.jpg)
Adds processes which are ready to run to the ready list
May compute the priority for the waiting process (could also be determined by the dispatcher)
7
![Page 8: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/8.jpg)
Saves contents of processor registers for a process being taken off the CPU If hardware has more than one set of
processor registers, OS may just switch between sets
Typically, one set is used for supervisor mode, others for applications
Depending on OS, process could be switched out voluntarily or involuntarily
8
![Page 9: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/9.jpg)
Dispatcher module gives control of the CPU to the process selected by the short-term scheduler; this involves: switching context
From process, to dispatcher, to new process switching to user mode jumping to the proper location in the user
program to restart that program
9
![Page 10: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/10.jpg)
10
R1R2
Rn
. . .
StatusRegisters
Functional Unit
Left Operand
Right Operand
Result ALU
PC
IRCtl Unit
![Page 11: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/11.jpg)
11
CPU
New Thread Descriptor
Old ThreadDescriptor
![Page 12: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/12.jpg)
Context switching is a time-consuming process Assuming n general registers and m status registers,
each requiring b store operations, and K time units to perform a store, the time required is
(n + m) b × K time units Then a processor requiring 50 ns to store 1 unit of
information, and assuming that n = 32 and m = 8, the time required is 2000 ns = 2 μs
A complete context switch involves removing process, loading dispatcher, removing dispatcher, loader new process at least 8 μs required
Note that a 1 Ghz processor could have executed about 4,000 instructions in this time
Some processors use several sets of registers to reduce this switching time (one set for supervisor mode, the other for user)
12
![Page 13: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/13.jpg)
Need a mechanism to call the scheduler Voluntary call
Process blocks itself Calls the scheduler Non-preemptive scheduling
Involuntary call External force (interrupt) blocks the process Calls the scheduler Preemptive scheduling
13
![Page 14: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/14.jpg)
Each process will voluntarily share the CPU By calling the scheduler periodically The simplest approach Requires a yield instruction to allow the
running process to release CPU
14
yield(pi.pc, pj.pc) { memory[pi.pc] = PC; PC = memory[pj.pc];}
![Page 15: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/15.jpg)
pi can be “automatically” determined from the processor status registers So function can be written as
15
yield(*, pj.pc) { memory[pi.pc] = PC; PC = memory[pj.pc];}
![Page 16: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/16.jpg)
16
yield(*, pj.pc);. . .yield(*, pi.pc);. . .yield(*, pj.pc);. . .
• pi and pj can resume one another’s execution
• Suppose pj is the scheduler:// p_i yields to scheduleryield(*, pj.pc);// scheduler chooses pk
yield(*, pk.pc);// pk yields to scheduleryield(*, pj.pc);// scheduler chooses ...
![Page 17: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/17.jpg)
Every process periodically yields to the scheduler
Relies on correct process behavior Malicious Accidental
Need a mechanism to override running process
17
![Page 18: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/18.jpg)
18
![Page 19: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/19.jpg)
Periodic involuntary interruption Through an interrupt from an interval timer
device Which generates an interrupt whenever the
timer expires The scheduler will be called in the interrupt
handler A scheduler that uses involuntary CPU sharing
is called a preemptive scheduler
19
![Page 20: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/20.jpg)
20
IntervalTimer() { InterruptCount--; if (InterruptCount <= 0) { InterruptRequest = TRUE; InterruptCount = K }}
SetInterval( <programmableValue>) { K = <programmableValue>; InterruptCount = K;}
Interrupt occurs every K clock ticks
![Page 21: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/21.jpg)
Interval timer device handler Keeps an in-memory clock up-to-date Invokes the scheduler
21
IntervalTimerHandler() { Time++; // update the clock TimeToSchedule--; if(TimeToSchedule <= 0) { <invoke scheduler>; TimeToSchedule = TimeSlice; }}
![Page 22: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/22.jpg)
Involuntary CPU sharing – timer interrupts Time quantum determined by interval timer –
usually fixed size for every process using the system
Sometimes called the time slice length
22
![Page 23: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/23.jpg)
Mechanism never changes Strategy = policy the dispatcher uses to
select a process from the ready list Different policies for different
requirements
23
![Page 24: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/24.jpg)
Policy can control/influence: CPU utilization Average time a process waits for service Average amount of time to complete a job
Could strive for any of: Equitability Favor very short or long jobs Meet priority requirements Meet deadlines
24
![Page 25: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/25.jpg)
Suppose the scheduler knows each process pi’s service time, pi -- or it can estimate each pi :
Policy can optimize on any criteria, e.g., CPU utilization Waiting time Deadline
To find an optimal schedule: Have a finite, fixed # of pi
Know pi for each pi
Enumerate all schedules, then choose the best25
![Page 26: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/26.jpg)
The (pi) are almost certainly just estimates
General algorithm to choose optimal schedule is O(n2)
Other processes may arrive while these processes are being serviced
Usually, optimal schedule is only a theoretical benchmark – scheduling policies try to approximate an optimal schedule
26
![Page 27: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/27.jpg)
The scheduling criteria will depend in part on the goals of the OS and on priorities of processes, fairness, overall resource utilization, throughput, turnaround time, response time, and deadlines
27
![Page 28: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/28.jpg)
P will be a set of processes, p0, p1, ..., pn-1 S(pi) is the state of pi {running, ready,
blocked} τ(pi), the service time
The amount of time pi needs to be in the running state before it is completed
W (pi), the waiting time The time pi spends in the ready state before its
first transition to the running state TTRnd(pi), turnaround time
The amount of time between the moment pi first enters the ready state and the moment the process exits the running state for the last time
28
![Page 29: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/29.jpg)
Simplified, but still provides analysis results Easy to analyze performance No issue of voluntary/involuntary sharing
29
ReadyList
ReadyList SchedulerScheduler CPUCPU
ResourceManager
ResourceManager
ResourcesResources
Allocate Request
DoneNewProcess job
jobjob
jobjob
“Ready”“Running”
“Blocked”
Preemption or voluntary yield
![Page 30: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/30.jpg)
30
ReadyList
ReadyList SchedulerScheduler CPUCPU DoneNew
Process
System pi per second
Each pi uses 1/ μ units ofthe CPU
Let = the average rate at which processes are placed in the Ready List, arrival rate
Let μ = the average service rate 1/ μ = the average (pi)
![Page 31: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/31.jpg)
31
ReadyList
ReadyList SchedulerScheduler CPUCPU DoneNew
Process
Let = the average rate at which processes are placed in the Ready List, arrival rate
Let μ = the average service rate 1/ μ = the average (pi)
Let = the fraction of the time that the CPU is expected to be busy = # pi that arrive per unit time * avg time each spends on CPU = * 1/ μ = / μ • Note: must have < (i.e., < 1)
• What if approaches 1?
![Page 32: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/32.jpg)
Max CPU utilization Max throughput Min turnaround time Min waiting time Min response time Which one to use depends on the
system’s design goal
32
![Page 33: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/33.jpg)
33
ReadyList
ReadyList SchedulerScheduler CPUCPU DoneNew
Process
• Try to use the simplified scheduling model
• Only consider running and ready states
• Ignores time in blocked state:– New process created when it enters ready state– Process is destroyed when it enters blocked state– Really just looking at “small phases” of a process
Blocked or preempted processes
![Page 34: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/34.jpg)
First-come, first served (FCFS) Shorter jobs first (SJF)
or Shortest job next (SJN) Higher priority jobs first Job with the closest deadline first
34
![Page 35: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/35.jpg)
35
![Page 36: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/36.jpg)
36
![Page 37: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/37.jpg)
Used to illustrate deterministic schedules Dependencies of a process on other processes
Plots processor(s) against time Shows which processes on executing on which
processors at which times Also shows idle time, so illustrates the
utilization of each processor In following, will only assume one
processor
37
![Page 38: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/38.jpg)
First-Come-First-Served Assigns priority to processes in the order in
which they request the processor
i τ(pi)
0 350
1 125
2 475
3 250
4 7538
![Page 39: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/39.jpg)
39
i (pi)0 3501 1252 4753 2504 75
p0
TTRnd(p0) = (p0) = 350 W(p0) = 0
0 350
![Page 40: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/40.jpg)
40
i (pi)0 3501 1252 4753 2504 75
p0 p1
TTRnd(p0) = (p0) = 350TTRnd(p1) = ((p1) +TTRnd(p0)) = 125+350 = 475
W(p0) = 0W(p1) = TTRnd(p0) = 350
475350
![Page 41: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/41.jpg)
41
i (pi)0 3501 1252 4753 2504 75
p0 p1 p2
TTRnd(p0) = (p0) = 350TTRnd(p1) = ((p1) +TTRnd(p0)) = 125+350 = 475TTRnd(p2) = ((p2) +TTRnd(p1)) = 475+475 = 950
W(p0) = 0W(p1) = TTRnd(p0) = 350W(p2) = TTRnd(p1) = 475
475 950
![Page 42: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/42.jpg)
42
i (pi)0 3501 1252 4753 2504 75
p0 p1 p2 p3
TTRnd(p0) = (p0) = 350TTRnd(p1) = ((p1) +TTRnd(p0)) = 125+350 = 475TTRnd(p2) = ((p2) +TTRnd(p1)) = 475+475 = 950TTRnd(p3) = ((p3) +TTRnd(p2)) = 250+950 = 1200
W(p0) = 0W(p1) = TTRnd(p0) = 350W(p2) = TTRnd(p1) = 475W(p3) = TTRnd(p2) = 950
1200950
![Page 43: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/43.jpg)
43
i (pi)0 3501 1252 4753 2504 75
p0 p1 p2 p3 p4
TTRnd(p0) = (p0) = 350TTRnd(p1) = ((p1) +TTRnd(p0)) = 125+350 = 475TTRnd(p2) = ((p2) +TTRnd(p1)) = 475+475 = 950TTRnd(p3) = ((p3) +TTRnd(p2)) = 250+950 = 1200TTRnd(p4) = ((p4) +TTRnd(p3)) = 75+1200 = 1275
W(p0) = 0W(p1) = TTRnd(p0) = 350W(p2) = TTRnd(p1) = 475W(p3) = TTRnd(p2) = 950W(p4) = TTRnd(p3) = 1200
1200 1275
![Page 44: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/44.jpg)
44
i (pi)0 3501 1252 4753 2504 75
p0 p1 p2 p3 p4
TTRnd(p0) = (p0) = 350TTRnd(p1) = ((p1) +TTRnd(p0)) = 125+350 = 475TTRnd(p2) = ((p2) +TTRnd(p1)) = 475+475 = 950TTRnd(p3) = ((p3) +TTRnd(p2)) = 250+950 = 1200TTRnd(p4) = ((p4) +TTRnd(p3)) = 75+1200 = 1275
W(p0) = 0W(p1) = TTRnd(p0) = 350W(p2) = TTRnd(p1) = 475W(p3) = TTRnd(p2) = 950W(p4) = TTRnd(p3) = 1200
Wavg = (0+350+475+950+1200)/5 = 2974/5 = 595
127512009504753500
•Easy to implement•Ignores service time, etc•Not a great performer
![Page 45: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/45.jpg)
In FCFS, when a process arrives, all in ready list will be processed before this job
Let μ be the service rate Let L be the ready list length Wavg(p) = L*1/μ + 0.5* 1/ μ = L/ μ +1/(2 μ)
(in queue) (active process) Compare predicted wait with actual in
earlier examples
45
![Page 46: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/46.jpg)
Example: Process Burst Time P1 24 P2 3 P3 3
Suppose that the processes arrive in the order: P1, P2 , P3 The Gantt Chart for the schedule is:
Waiting time for P1 = 0; P2 = 24; P3 = 27
Average waiting time: (0 + 24 + 27)/3 = 17
46
P1 P2 P3
24 27 300
![Page 47: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/47.jpg)
Suppose that the processes arrive in the order P2 , P3 , P1
The Gantt chart for the schedule is:
Waiting time for P1 = 6; P2 = 0; P3 = 3 Average waiting time: (6 + 0 + 3)/3 = 3 Much better than previous case.
47
P1P3P2
63 300
![Page 48: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/48.jpg)
Associate with each process the length of its next CPU burst. Use these lengths to schedule the process
with the shortest time. SJN is optimal
gives minimum average waiting time for a given set of processes.
48
![Page 49: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/49.jpg)
Two schemes: non-preemptive – once CPU given to the
process it cannot be preempted until completes its CPU burst.
Preemptive – if a new process arrives with CPU burst length less than remaining time of current executing process, preempt. This scheme is know as the Shortest-Remaining-Time-Next (SRTN).
49
![Page 50: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/50.jpg)
50
i (pi)0 3501 1252 4753 2504 75
p4
TTRnd(p4) = (p4) = 75 W(p4) = 0
750
![Page 51: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/51.jpg)
51
i (pi)0 3501 1252 4753 2504 75
p1p4
TTRnd(p1) = (p1)+(p4) = 125+75 = 200
TTRnd(p4) = (p4) = 75
W(p1) = 75
W(p4) = 0
200750
![Page 52: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/52.jpg)
52
i (pi)0 3501 1252 4753 2504 75
p1 p3p4
TTRnd(p1) = (p1)+(p4) = 125+75 = 200
TTRnd(p3) = (p3)+(p1)+(p4) = 250+125+75 = 450TTRnd(p4) = (p4) = 75
W(p1) = 75
W(p3) = 200W(p4) = 0
450200750
![Page 53: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/53.jpg)
53
i (pi)0 3501 1252 4753 2504 75
p0p1 p3p4
TTRnd(p0) = (p0)+(p3)+(p1)+(p4) = 350+250+125+75 = 800TTRnd(p1) = (p1)+(p4) = 125+75 = 200
TTRnd(p3) = (p3)+(p1)+(p4) = 250+125+75 = 450TTRnd(p4) = (p4) = 75
W(p0) = 450W(p1) = 75
W(p3) = 200W(p4) = 0
800450200750
![Page 54: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/54.jpg)
54
i (pi)0 3501 1252 4753 2504 75
p0p1 p2p3p4
TTRnd(p0) = (p0)+(p3)+(p1)+(p4) = 350+250+125+75 = 800TTRnd(p1) = (p1)+(p4) = 125+75 = 200TTRnd(p2) = (p2)+(p0)+(p3)+(p1)+(p4) = 475+350+250+125+75 = 1275TTRnd(p3) = (p3)+(p1)+(p4) = 250+125+75 = 450TTRnd(p4) = (p4) = 75
W(p0) = 450W(p1) = 75W(p2) = 800
W(p3) = 200W(p4) = 0
1275800450200750
![Page 55: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/55.jpg)
55
i (pi)0 3501 1252 4753 2504 75 p0p1 p2p3p4
TTRnd(p0) = (p0)+(p3)+(p1)+(p4) = 350+250+125+75 = 800TTRnd(p1) = (p1)+(p4) = 125+75 = 200TTRnd(p2) = (p2)+(p0)+(p3)+(p1)+(p4) = 475+350+250+125+75 = 1275TTRnd(p3) = (p3)+(p1)+(p4) = 250+125+75 = 450TTRnd(p4) = (p4) = 75
W(p0) = 450W(p1) = 75W(p2) = 800
W(p3) = 200W(p4) = 0
Wavg = (450+75+800+200+0)/5 = 1525/5 = 305
1275800450200750
•Minimizes wait time•May starve large jobs•Must know service times
![Page 56: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/56.jpg)
Can only estimate the length. Can be done by using the length of
previous CPU bursts, using exponential averaging.
56
:Define 4.
10 , 3.
burst CPUnext for the valuepredicted 2.
burst CPU oflength actual 1.
1
n
thn nt
nnn t 1 1
![Page 57: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/57.jpg)
=0 n+1 = n
Recent history does not count. =1
n+1 = tn
Only the actual last CPU burst counts. If we expand the formula, we get:
n+1 = tn+(1 - ) tn-1 + …+(1 - )j tn-j + …+(1 - )n+1 0
Since both and (1 - ) are less than or equal to 1, each successive term has less weight than its predecessor.
57
![Page 58: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/58.jpg)
In priority scheduling, processes/threads are allocated to the CPU based on the basis of an externally assigned priority A commonly used convention is that lower
numbers have higher priority Static priorities vs. dynamic priorities
Static priorities are computed once at the beginning and are not changed
Dynamic priorities allow the threads to become more or less important depending on how much service it has recently received
58
![Page 59: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/59.jpg)
There are non-preemptive and preemptive priority scheduling algorithms Preemptive nonpreemptive
SJN is a priority scheduling where priority is the predicted next CPU burst time.
FCFS is a priority scheduling where priority is the arrival time
59
![Page 60: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/60.jpg)
60
Non-preemptive Priority Scheduling
i (pi) Pri0 350 51 125 22 475 33 250 14 75 4 p0p1 p2p3 p4
TTRnd(p0) = (p0)+(p4)+(p2)+(p1) )+(p3) = 350+75+475+125+250 = 1275TTRnd(p1) = (p1)+(p3) = 125+250 = 375TTRnd(p2) = (p2)+(p1)+(p3) = 475+125+250 = 850TTRnd(p3) = (p3) = 250TTRnd(p4) = (p4)+ (p2)+ (p1)+(p3) = 75+475+125+250 = 925 TTRnd = (1275+375+850+250+925)/5 = 735
W(p0) = 925W(p1) = 250W(p2) = 375
W(p3) = 0W(p4) = 850
Wavg = (925+250+375+0+850)/5 = 2400/5 = 480
12759258503752500
•Reflects importance of external use•May cause starvation•Can address starvation with aging
![Page 61: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/61.jpg)
61
i (pi) Deadline0 350 5751 125 5502 475 10503 250 (none)4 75 200
p0p1 p2 p3p4
12751050550200
0
•Allocates service by deadline•May not be feasible
p0p1 p2 p3p4
p0 p1 p2 p3p4
575
![Page 62: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/62.jpg)
Hard real-time systems – required to complete a critical task within a guaranteed amount of time.
Soft real-time computing – requires that critical processes receive priority over less fortunate ones.
62
![Page 63: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/63.jpg)
63
ReadyList
ReadyList SchedulerScheduler CPUCPU
Preemption or voluntary yield
DoneNewProcess
• Highest priority process is guaranteed to be running at all times– Or at least at the beginning of a time slice
• Dominant form of contemporary scheduling
• But complex to build & analyze
![Page 64: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/64.jpg)
Also called the shortest remaining job next
When a new process arrives, its next CPU burst is compared to the remaining time of the running process If the new arriver’s time is shorter, it will
preempt the CPU from the current running process
64
![Page 65: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/65.jpg)
ProcessArrival TimeBurst TimeP1 0.0 7
P2 2.0 4
P3 4.0 1
P4 5.0 4
Average time spent in ready queue = (9 + 1 + 0 +2)/4 = 3
65
P1 P3P2
42 110
P4
5 7
P2 P1
16
![Page 66: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/66.jpg)
ProcessArrival TimeBurst TimeP1 0.0 7
P2 2.0 4
P3 4.0 1
P4 5.0 4 SJN (non-preemptive)
Average time spent in ready queue (0 + 6 + 3 + 7)/4 = 4
66
P1 P3 P2
73 160
P4
8 12
![Page 67: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/67.jpg)
Each process gets a small unit of CPU time (time quantum), usually 10-100 milliseconds. After this time has elapsed, the process is preempted and added to the end of the ready queue.
If there are n processes in the ready queue and the time quantum is q, then each process gets 1/n of the CPU time in chunks of at most q time units at once. No process waits more than (n-1)q time units.
67
![Page 68: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/68.jpg)
68
Good way to upset customers!
![Page 69: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/69.jpg)
69
i (pi)0 3501 1252 4753 2504 75
p0
W(p0) = 0
0 50
![Page 70: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/70.jpg)
70
i (pi)0 3501 1252 4753 2504 75
p0
W(p0) = 0W(p1) = 50
1000p1
![Page 71: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/71.jpg)
71
i (pi)0 3501 1252 4753 2504 75
p0
W(p0) = 0W(p1) = 50W(p2) = 100
1000p2p1
![Page 72: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/72.jpg)
72
i (pi)0 3501 1252 4753 2504 75
p0
W(p0) = 0W(p1) = 50W(p2) = 100W(p3) = 150
2001000p3p2p1
![Page 73: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/73.jpg)
73
i (pi)0 3501 1252 4753 2504 75
p0
W(p0) = 0W(p1) = 50W(p2) = 100W(p3) = 150W(p4) = 200
2001000p4p3p2p1
![Page 74: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/74.jpg)
74
i (pi)0 3501 1252 4753 2504 75
p0
W(p0) = 0W(p1) = 50W(p2) = 100W(p3) = 150W(p4) = 200
3002001000p0p4p3p2p1
![Page 75: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/75.jpg)
75
i (pi)0 3501 1252 4753 2504 75
p0
TTRnd(p4) =
W(p0) = 0W(p1) = 50W(p2) = 100W(p3) = 150W(p4) = 200
4754003002001000p4p0p4p3p2p1 p1 p2 p3
![Page 76: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/76.jpg)
76
i (pi)0 3501 1252 4753 2504 75
p0
TTRnd(p1) =
TTRnd(p4) =
W(p0) = 0W(p1) = 50W(p2) = 100W(p3) = 150W(p4) = 200
4754003002001000p4 p1p0p4p3p2p1 p1 p2 p3 p0
550
![Page 77: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/77.jpg)
77
i (pi)0 3501 1252 4753 2504 75
p0
TTRnd(p1) =
TTRnd(p3) = TTRnd(p4) =
W(p0) = 0W(p1) = 50W(p2) = 100W(p3) = 150W(p4) = 200
4754003002001000p4 p1p0p4p3p2p1 p1 p2 p3 p0 p3p2
p0 p3p2 p0 p3p2
550 650
650 750 850 950
![Page 78: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/78.jpg)
78
i (pi)0 3501 1252 4753 2504 75
p0
TTRnd(p0) = TTRnd(p1) =
TTRnd(p3) = TTRnd(p4) =
W(p0) = 0W(p1) = 50W(p2) = 100W(p3) = 150W(p4) = 200
4754003002001000p4 p1p0p4p3p2p1 p1 p2 p3 p0 p3p2
p0 p3p2 p0 p3p2 p0 p2 p0
550 650
650 750 850 950 1050
![Page 79: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/79.jpg)
79
i (pi)0 3501 1252 4753 2504 75
p0
TTRnd(p0) = TTRnd(p1) = TTRnd(p2) = TTRnd(p3) = TTRnd(p4) =
W(p0) = 0W(p1) = 50W(p2) = 100W(p3) = 150W(p4) = 200
4754003002001000p4 p1p0p4p3p2p1 p1 p2 p3 p0 p3p2
p0 p3p2 p0 p3p2 p0 p2 p0 p2 p2 p2 p2
550 650
650 750 850 950 1050 1150 1250 1275
![Page 80: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/80.jpg)
80
i (pi)0 3501 1252 4753 2504 75
p0
TTRnd(p0) = TTRnd(p1) = TTRnd(p2) = TTRnd(p3) = TTRnd(p4) =
W(p0) = 0W(p1) = 50W(p2) = 100W(p3) = 150W(p4) = 200
Wavg = (0+50+100+150+200)/5 = 500/5 = 100
4754003002001000
•Equitable•Most widely-used•Fits naturally with interval timer
p4 p1p0p4p3p2p1 p1 p2 p3 p0 p3p2
p0 p3p2 p0 p3p2 p0 p2 p0 p2 p2 p2 p2
550 650
650 750 850 950 1050 1150 1250 1275
TTRnd_avg = (1100+550+1275+950+475)/5 = 4350/5 = 870
![Page 81: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/81.jpg)
Performance q large FIFO q small q must be large with respect to
context switch, otherwise overhead is too high.
81
![Page 82: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/82.jpg)
82
![Page 83: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/83.jpg)
83
![Page 84: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/84.jpg)
84
i (pi)0 3501 1252 4753 2504 75
•Overhead must be considered
p0
TTRnd(p0) = TTRnd(p1) = TTRnd(p2) = TTRnd(p3) = TTRnd(p4) =
W(p0) = 0W(p1) = 60W(p2) = 120W(p3) = 180W(p4) = 240
Wavg = (0+60+120+180+240)/5 = 600/5 = 120
5404803602401200p4 p1p0p4p3p2p1 p1 p2 p3 p0 p3p2
p0 p3p2 p0 p3p2 p0 p2 p0 p2 p2 p2 p2
575 790
910 1030 1150 1270 1390 1510 1535
TTRnd_avg = (1320+660+1535+1140+565)/5 = 5220/5 = 1044
635 670
790
![Page 85: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/85.jpg)
85
Ready List0Ready List0
Ready List1Ready List1
Ready List2Ready List2
Ready ListnReady Listn
SchedulerScheduler CPUCPU
Preemption or voluntary yield
DoneNewProcess
•Each list may use a different policy•FCFS•SJN•RR
![Page 86: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/86.jpg)
Ready queue is partitioned into separate queues foreground (interactive) background (batch)
Each queue has its own scheduling algorithm foreground – RR background – FCFS
86
![Page 87: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/87.jpg)
Scheduling must be done between the queues. Fixed priority scheduling; i.e., serve all from
foreground then from background. Possibility of starvation.
Time slice – each queue gets a certain amount of CPU time which it can schedule amongst its processes; i.e., 80% to foreground in RR 20% to background in FCFS
87
![Page 88: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/88.jpg)
88
![Page 89: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/89.jpg)
A process can move between the various queues; aging can be implemented this way.
Multilevel-feedback-queue scheduler defined by the following parameters: number of queues scheduling algorithms for each queue method used to determine when to upgrade a
process method used to determine when to demote a
process method used to determine which queue a process
will enter when that process needs service89
![Page 90: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/90.jpg)
90
![Page 91: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/91.jpg)
Three queues: Q0 – time quantum 8 milliseconds
Q1 – time quantum 16 milliseconds
Q2 – FCFS
Scheduling A new job enters queue Q0 which is served FCFS.
When it gains CPU, job receives 8 milliseconds. If it does not finish in 8 milliseconds, job is moved to queue Q1.
At Q1 job is again served FCFS and receives 16 additional milliseconds. If it still does not complete, it is preempted and moved to queue Q2.
91
![Page 92: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/92.jpg)
92
![Page 93: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/93.jpg)
93
![Page 94: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/94.jpg)
CPU scheduling more complex when multiple CPUs are available.
Homogeneous processors within a multiprocessor.
Load sharing Asymmetric multiprocessing – only one
processor accesses the system data structures, alleviating the need for data sharing.
94
![Page 95: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/95.jpg)
Deterministic modeling – takes a particular predetermined workload and defines the performance of each algorithm for that workload.
Queuing models Implementation
95
![Page 96: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/96.jpg)
96
![Page 97: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/97.jpg)
Involuntary CPU sharing -- timer interrupts Time quantum determined by interval timer --
usually fixed for every process using the system
Sometimes called the time slice length Priority-based process (job) selection
Select the highest priority process Priority reflects policy
With preemption Usually a variant of Multi-Level Queues
97
![Page 98: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/98.jpg)
All use a multiple-queue system UNIX SVR4: 160 levels, three classes
time-sharing, system, real-time Solaris: 170 levels, four classes
time-sharing, system, real-time, interrupt OS/2 2.0: 128 level, four classes
background, normal, server, real-time Windows NT 3.51: 32 levels, two classes
regular and real-time Mach uses “hand-off scheduling”
98
![Page 99: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/99.jpg)
Involuntary CPU Sharing Preemptive algorithms 32 Multi-Level Queues
Queues 0-7 are reserved for system functions Queues 8-31 are for user space functions nice influences (but does not dictate) queue
level
99
![Page 100: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/100.jpg)
Involuntary CPU Sharing across threads Preemptive algorithms 32 Multi-Level Queues
Highest 16 levels are “real-time” Next lower 15 are for system/user threads
Range determined by process base priority Lowest level is for the idle thread
100
![Page 101: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/101.jpg)
In file kernel/sched.c The policy is a variant of RR scheduling
101
![Page 102: 2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process](https://reader034.vdocuments.net/reader034/viewer/2022051517/56649ed55503460f94be600a/html5/thumbnails/102.jpg)
The scheduler is responsible for multiplexing the CPU among a set of ready processes / threads It is invoked periodically by a timer interrupt,
by a system call, other device interrupts, any time that the running process terminates
It selects from the ready list according to its scheduling policy Which includes non-preemptive and preemptive
algorithms
102