Upload
duncan-day
View
17
Download
0
Embed Size (px)
DESCRIPTION
Traditional Unix Scheduling. “Traditional” means No consideration on realtime processes. Typically 4.3BSD and SVR3 MFQ-based Preemptive (time quantum based) Round robin in the same priority queue Same time quantum to different priority queues Dynamic priority assignment Priority - PowerPoint PPT Presentation
Citation preview
1
Traditional Unix SchedulingTraditional Unix Scheduling• “Traditional” means
– No consideration on realtime processes.– Typically 4.3BSD and SVR3
• MFQ-based– Preemptive (time quantum based)– Round robin in the same priority queue– Same time quantum to different priority queues– Dynamic priority assignment
• Priority – Integer value between 0 and 127
• Numerically lower values correspond to higher priorities.• Priorities between 0 and 49 are reserved for the kernel• Priorities between 50 and 127 are for user-level programs
2
• PCB: the most important data structure in an OS – Process identification
• PID
– CPU state information• The contents of CPU registers• Program counter
– Indicates the address of the next instruction to be executed.
– Process control information• Event that a process is waiting on. • I/O status (e.g., open files)• Scheduling info
Process Control
Block
User Program
User Data/Stack
Kernel Stack
Process Image
3
• PCB contains, as process scheduling info,– Current scheduling priority (pri) – User mode priority (usrpri)– Measure of recent CPU
utilization (cpu)– Nice value (user-controllable
adjustment factor; nice)
• Current scheduling priority (pri)– Used to decide which process
to schedule. – Same as user mode priority
(usrpri), when a process is in user mode.
– Goes down to place higher priority to kernel mode processing upon I/O completion.
• Down to a predefined priority (0 =< sleep priority =< 49).
– 10 for file access– 20 for disk I/O
• This enables a prompt I/O completion (a prompt completion of system call).
– Replaced with the current user mode priority (usrpri) when it is back in use mode.
4
7-State Process Behavior Model7-State Process Behavior Model
• Ready: The process is in main memory and available for execution.
• Blocked: The process is in main memory and blocked on an event.
• Blocked, suspended: The process is in virtual memory and blocked on an event.
• Ready, suspended: The process is in virtual memory but is available for execution as soon as it is loaded to main memory.
Ready,Suspended
Ready Running Terminated
Blocked
activatedDispatched to a CPU
interrupted
I/O or event waitEvent completion
exit
Blocked,Blocked,SuspendedSuspended
Suspended
Suspended
New
admitted
activated
5
• User mode priority (usrpri)– Depends two factors:
• Recent CPU utilization (cpu)
• Nice value (nice)
• CPU utilization– Initialized to 0 when a
process is created. – Incremented (for the
currently-running process) at every clock interrupt.
• 10 msec
• Nice value– An integer value between
0 and 39• The default value is 20.
– Increasing this value decreases the priority.
• Only OS administrators can decrease it.
– The nice command is used to change the nice value for each process.
• Accepts -20 to 19 as an increment to the current value.
6
• cpuj(i)– CPU utilization by process j through interval i. – Unit time for i: 10 msec.
• DR: decay rate– cpuj is reduced by a decay rate.– 1/2 in SVR3.
• PUSER (baseline priority): 50– used to divide processes into fixed bands of priority levels.
€
cpu j (i) = DR*cpu j (i −1)
usrpri j (i) = PUSER +cpu j (i)
2+ nice j
• Every second, user mode priority (usrpri) is updated as follows:
7
An ExampleAn Example
€
cpu j (i) =cpu j (i −1)
2
usrpri j (i) = 50 +cpu j (i)
2+ 0
DR: 1/2PUSER: 50nice: 0
3 processes in thesame priority band
Time quantum/process:1 sec
Process 1usrpri cpu
Process 2usrpri cpu
Process 3usrpri cpuTime
0
1 sec
2 sec
3 sec
4 sec
50 01
2
100
50 0
50 0
75 50
50 01
2
100
50 0
62 25
75 50
50 01
2
100
75 50
56 1213
112
62 25
78 56 62 25
56 1213
112
10 ms20 ms
8
4.3BSD Scheduler4.3BSD Scheduler
• 32 run (ready) queue– A queue for 4 adjacent priorities
• RQ0 for priorities 0 to 3• RQ1 for priorities 4 to 7
• RR in each RQ– RR time quantum: 100 msec– The highest-priority process is
always scheduled first in each RQ.
• MFQ across RQs– If all other ready processes are
on lower RQs, the current process continues to run even if its quantum has expired.
• Priority update– Once every second– Process promotion and
demotion across RQs
• Timing of context switches– The current process blocks on
a resource or exits.• Voluntary context switch
– RR-based preemption– Priority-based preemption– I/O (event) completion
CPU
Run Queue 0admitteddispatched
Run Queue 1
Run Queue 31
9
HWHW• The decay factor used in 4.3BSD is:
• LoadAverage– The average number of ready processes over the
last second.
• Discuss how this decay factor impacts process scheduling.
• Compare the scheduling algorithms in SVR3 and 4.3BSD.
€
DR =2∗LoadAverage2∗LoadAverage +1
10
Considering Process GroupsConsidering Process Groups
• In traditional Unix scheduling,– A priority is assigned per process. – Processes compete for CPU time.
• What about a group of processes? – Processes created by each application– Processes created by each user– Processes in the same session (or job)
• ps -j• ps -Aj
11
Fair Share Scheduling (FSS)Fair Share Scheduling (FSS)• Group-aware priority
assignment– Group: application, user or
session
• Assigns the same/similar priority (share of the CPU) to the processes in the same group – Give fewer CPU time to
processes that have had more than their fair share
– Give more CPU time to processes that have had less than their fair share.
• Considers the CPU utilization history of a group of processes– along with the CPU utilization
history of individual processes.• e.g., 25% share of the total
CPU time, when there are 4 groups.
• Can assign different priorities to different groups– Foreground and background
processes– OS administrators, normal
users and guests
• An extension to the traditional Unix scheduler.
12
• cpuj(i)– CPU utilization by process j through interval i. – Unit time for i: 10 msec.
• gcpuj(i)– CPU utilization by group k through interval i.
• DRp DRg: decay rate– cpuj and cpuk are reduced by DRp and DRg, respectively.
• PUSER (baseline priority):– The default value: 50
• Wk: weight assigned to group k.– 0 < Wk < 1 and
€
cpu j (i) = DRp *cpu j (i −1)
gcpuk = DRg * gcpuk (i −1)
usrpri j (i) = PUSER +cpu j (i)
2+gcpuk (i)
4 *Wk
• Every second, user mode priority (usrpri) is updated as follows:
€
Wk
k
∑ =1
13
An ExampleAn Example
€
cpu j (i) =cpu j (i −1)
2
gcpuk (i) =gcpuk (i −1)
2usrpri j (i) =
50 +cpu j (i)
2+gcpuk (i)
2
DRp, DRg: 1/2PUSER: 50W1 and W2: 1/2
3 processes in thesame priority band
P1 is in Group 1P2 and P3 in Group 2
Time quantum/process:1 sec
Time0
1 sec
2 sec
3 sec
4 sec
10 ms20 ms
5 sec
Process 1usrpri cpu gcpu
50 0 0 1 1 2 2
100 100
50 0 0 1 1 2 2
100 100
106 50 62
Process 2usrpri cpu gcpu
Process 3usrpri cpu gcpu
50 0 0
50 0 0
100 50 50
Group 1 Group 2
50 0 0 1 2
100
74 25 25
125 125
100 50 50
75 0 50
112 62 62
74 25 25
125
62 0 25
100 125
87 12 62
80 31 31
131 131
14
Process 1Usrpri cpu
Process 2usrpri cpu
Process 3usrpri cpuTime
0
1 sec
2 sec
3 sec
4 sec
50 01
2
100
50 0
50 0
75 50
50 0 1
100
50 0
62 25
75 50
50 01
100
75 50
56 1213
112
62 25
78 56 62 25
56 1213
112
10 ms20 ms
Process 1usrpri cpu gcpu
50 0 0 1 1 2 2
100 100
50 0 0 1 1 2 2
100 100
106 50 62
Process 2usrpri cpu gcpu
Process 3usrpri cpu gcpu
50 0 0
50 0 0
100 50 50
Group 1 Group 2
50 0 0 1 2
100
74 25 25
125 125
100 50 50
75 0 50
112 62 62
74 25 25
125
62 0 25
100 125
87 12 62
80 31 31
131 131
Traditional Unix Scheduling Fair Share Scheduling