Post on 04-Nov-2018
1
5. Planificación de Procesos 1
Pontificia Universidad Católica del Perú. Ingeniería Informática. INF231 - Sistemas Operativos
Copyright © 2001, Viktor Khlebnikov v 0.1
Capítulo 5:
Planificaciónde Procesos(Scheduling)
5. Planificación de Procesos 2
Pontificia Universidad Católica del Perú. Ingeniería Informática. INF231 - Sistemas Operativos
Copyright © 2001, Viktor Khlebnikov v 0.1
The scheduler The scheduling algorithm
Process behavior:
AST, MOS2E, Fig. 2-37
Scheduler, Scheduling Algorithm and Process Behavior
A CPU-bound process
An I/O-bound process
2
5. Planificación de Procesos 3
Pontificia Universidad Católica del Perú. Ingeniería Informática. INF231 - Sistemas Operativos
Copyright © 2001, Viktor Khlebnikov v 0.1
1. when a new process is created: the parent process orthe child process
2. when a process exits
3. when a process blocks on I/O, on a semaphore, ...
4. when an I/O interrupt occurs
5. when a hardware clock occurs:nonpreemptive scheduling algorithm
preemptive scheduling algorithm
AST, MOS2E, p. 135
When to Schedule
5. Planificación de Procesos 4
Pontificia Universidad Católica del Perú. Ingeniería Informática. INF231 - Sistemas Operativos
Copyright © 2001, Viktor Khlebnikov v 0.1
Three environments worth distinguishing are
1. Batch.
2. Interactive.
3. Real time.
AST, MOS2E, p. 136
Categories of Scheduling Algorithms
3
5. Planificación de Procesos 5
Pontificia Universidad Católica del Perú. Ingeniería Informática. INF231 - Sistemas Operativos
Copyright © 2001, Viktor Khlebnikov v 0.1
All systemsFairness - giving each process a fair share of the CPUPolicy enforcement - seeing that stated policy is carried outBalance - keeping all parts of the system busy
Batch systemsThroughput - maximize jobs per hourTurnaround time - minimize time between submission and
terminationCPU utilization - keep the CPU busy all the time
AST, MOS2E, p. 137
Scheduling Algorithm Goals (1/2)
5. Planificación de Procesos 6
Pontificia Universidad Católica del Perú. Ingeniería Informática. INF231 - Sistemas Operativos
Copyright © 2001, Viktor Khlebnikov v 0.1
Interactive systemsResponse time - respond to requests quicklyProportionality - meet user’s expectations
Real-time systemsMeeting deadlines - avoid losing dataPredictability - avoid quality degradation in multimedia
systems
AST, MOS2E, p. 137
Scheduling Algorithm Goals (2/2)
4
5. Planificación de Procesos 7
Pontificia Universidad Católica del Perú. Ingeniería Informática. INF231 - Sistemas Operativos
Copyright © 2001, Viktor Khlebnikov v 0.1
Proceso Duración de la ráfagaP1 24P2 3P3 3
Scheduling in Batch Systems: First-Come First-Served (FCFS)
P1 P2 P3
0
P2P1
24 27 30
tpr.espera = (0+24+27)/3 = 51/3 = 17
Efecto de convoy: one CPU-bound process runs for 1 sec, then it reads a disk block.Many I/O-bound processes have to perform 1000 disk reads to complete.Result: each I/O-bound process gets to read 1 block per second and will take 1000 secto finish. But in case of 10 msec preemption, the I/O-bound process would finish in10 sec and without slowing down the CPU-bound process very much.
nonpreemptiveP3
Gráfica de Gantt
5. Planificación de Procesos 8
Pontificia Universidad Católica del Perú. Ingeniería Informática. INF231 - Sistemas Operativos
Copyright © 2001, Viktor Khlebnikov v 0.1
Proceso Duración de la ráfagaP1 8P2 4P3 4P4 4
Scheduling in Batch Systems: Shortest Job First (SJF) (1/2)
P1 P2 P30
P2P1
8 12 16
tpr.respuesta =(8+12+16+20)/4 =56/4 = 14
nonpreemptive
P4P3
P420
P1P2 P30 4 8 12
tpr.respuesta =(4+8+12+20)/4 =44/4 = 11
P420
5
5. Planificación de Procesos 9
Pontificia Universidad Católica del Perú. Ingeniería Informática. INF231 - Sistemas Operativos
Copyright © 2001, Viktor Khlebnikov v 0.1
Consider the case of 4 jobs, with run times of a, b, c, and d, respectively. Thefirst job finishes at time a, the second finishes at time a + b, and so on. Themean turnaround time is (4a + 3b + 2c + d)/4. ...
Proceso Duración de la ráfaga Tiempo de llegadaP1 2 0P2 4 0P3 1 3P4 1 3P5 1 3
Scheduling in Batch Systems: Shortest Job First (SJF) (2/2)
P1 P2 P30
P2P1
2 7 8
tmean turnaround =(2+6+4+5+6)/5 = 23/5 = 4.6versus 4.4for P2, P3, P4, P5, P1.
nonpreemptive
P4P3
P49
P5
P5
6
5. Planificación de Procesos 10
Pontificia Universidad Católica del Perú. Ingeniería Informática. INF231 - Sistemas Operativos
Copyright © 2001, Viktor Khlebnikov v 0.1
Proceso Duración de la ráfaga Tiempo de llegadaP1 2 0P2 4 0P3 1 3P4 1 3P5 1 3
Scheduling in Batch Systems: Shortest Remaining Time First
P1 P2 P30
P2P1
2 6
tmean turnaround =(2+9+1+2+3)/5 =17/5 = 3.2
preemptive
P4P3
P49
P5
P5
5
P23 4
6
5. Planificación de Procesos 11
Pontificia Universidad Católica del Perú. Ingeniería Informática. INF231 - Sistemas Operativos
Copyright © 2001, Viktor Khlebnikov v 0.1
Scheduling in Batch Systems: Three-Level Scheduling
AST, MOS2E, Fig. 2-40
5. Planificación de Procesos 12
Pontificia Universidad Católica del Perú. Ingeniería Informática. INF231 - Sistemas Operativos
Copyright © 2001, Viktor Khlebnikov v 0.1
Scheduling and Process State Transitions
WS, OSIDP, 3E, Fig. 9-1
7
5. Planificación de Procesos 13
Pontificia Universidad Católica del Perú. Ingeniería Informática. INF231 - Sistemas Operativos
Copyright © 2001, Viktor Khlebnikov v 0.1
Queuing Diagram for Scheduling
WS, OSIDP, 3E, Fig. 9-3
5. Planificación de Procesos 14
Pontificia Universidad Católica del Perú. Ingeniería Informática. INF231 - Sistemas Operativos
Copyright © 2001, Viktor Khlebnikov v 0.1
Round-Robin Scheduling (1/4)
One of the oldest, simplest, fairest, and most widely usedalgorithms is round robin (time slicing).
Quantum, quanta. Process (context) switch.
AST, MOS2E, Fig. 2-41
The list of runnable processes. The list of runnable processesafter B uses its quantum.
8
5. Planificación de Procesos 15
Pontificia Universidad Católica del Perú. Ingeniería Informática. INF231 - Sistemas Operativos
Copyright © 2001, Viktor Khlebnikov v 0.1
Round-Robin Scheduling (2/4)
WS, OSIDP, 3E, Fig. 9-6
5. Planificación de Procesos 16
Pontificia Universidad Católica del Perú. Ingeniería Informática. INF231 - Sistemas Operativos
Copyright © 2001, Viktor Khlebnikov v 0.1
Round-Robin Scheduling (3/4)
WS, OSIDP, 3E, Fig. 9-6
9
5. Planificación de Procesos 17
Pontificia Universidad Católica del Perú. Ingeniería Informática. INF231 - Sistemas Operativos
Copyright © 2001, Viktor Khlebnikov v 0.1
Queuing Diagram for Virtual Round-Robin Scheduling (4/4)
WS, OSIDP, 3E, Fig. 9-7
5. Planificación de Procesos 18
Pontificia Universidad Católica del Perú. Ingeniería Informática. INF231 - Sistemas Operativos
Copyright © 2001, Viktor Khlebnikov v 0.1
Priority Scheduling (1/7)
AST, MOS2E, Fig. 2-42
10
5. Planificación de Procesos 19
Pontificia Universidad Católica del Perú. Ingeniería Informática. INF231 - Sistemas Operativos
Copyright © 2001, Viktor Khlebnikov v 0.1
Priority Scheduling (2/7)
WS, OSIDP, 3E, Fig. 9-4
5. Planificación de Procesos 20
Pontificia Universidad Católica del Perú. Ingeniería Informática. INF231 - Sistemas Operativos
Copyright © 2001, Viktor Khlebnikov v 0.1
MINIX Structure (3/7)
AST & ASW, OSDI2E, Fig. 2-26
Layer
4
3
2
1 Process management
Disktask
Ttytask
Clocktask
Memorymanager
Ethernettask . . . I/O tasks
Filesystem
Systemtask
Networkserver
. . . Server processes
. . .Userprocess
Userprocess
UserprocessInit User processes
11
5. Planificación de Procesos 21
Pontificia Universidad Católica del Perú. Ingeniería Informática. INF231 - Sistemas Operativos
Copyright © 2001, Viktor Khlebnikov v 0.1
MINIX Scheduling (4/7)
AST & ASW, OSDI2E, Fig. 2-36
5. Planificación de Procesos 22
Pontificia Universidad Católica del Perú. Ingeniería Informática. INF231 - Sistemas Operativos
Copyright © 2001, Viktor Khlebnikov v 0.1
UNIX Scheduling (5/7)
AST, MOS2E, Fig. 10-11
12
5. Planificación de Procesos 23
Pontificia Universidad Católica del Perú. Ingeniería Informática. INF231 - Sistemas Operativos
Copyright © 2001, Viktor Khlebnikov v 0.1
Mapping of Win32 priorities to Windows 2000 priorities (6/7)
AST, MOS2E, Fig. 11-18
5. Planificación de Procesos 24
Pontificia Universidad Católica del Perú. Ingeniería Informática. INF231 - Sistemas Operativos
Copyright © 2001, Viktor Khlebnikov v 0.1
Windows 2000 support 32 priorities for threads (7/7)
AST, MOS2E, Fig. 11-19
13
5. Planificación de Procesos 25
Pontificia Universidad Católica del Perú. Ingeniería Informática. INF231 - Sistemas Operativos
Copyright © 2001, Viktor Khlebnikov v 0.1
Aging
AST, MOS2E, p. 146
Se predice como un promedio exponencial de las longitudesmedidas de las ráfagas de CPU anteriores.
Sea tn la longitud de la n-ésima ráfaga de CPU, y ττττn+1 el valorprevisto para la siguiente ráfaga. Entonces, para αααα, 0 ≤≤≤≤ αααα ≤≤≤≤ 1,se define
ττττn+1 = αααα tn + (1 - αααα) ττττn
Esta fórmula define un promedio esponencial.
Maduración o envejecimiento (aging).
αααα = 0.5
5. Planificación de Procesos 26
Pontificia Universidad Católica del Perú. Ingeniería Informática. INF231 - Sistemas Operativos
Copyright © 2001, Viktor Khlebnikov v 0.1
Other Scheduling Algorithms
AST, MOS2E, pp. 146-148
Guaranteed Scheduling: if there are n users logged in whileyou are working, you will receive about 1/n of the CPU power.
Lottery Scheduling: the system might hold a lottery 50 times asecond, with each winner getting 20 msec of CPU time as a prize.
Fair-Share Scheduling:
user 1 has four processes, A, B, C, and D, and user 2 has only1 process, E. If two users have each been promised 50% of theCPU:
A E B E C E D E A E B E C E D E
14
5. Planificación de Procesos 27
Pontificia Universidad Católica del Perú. Ingeniería Informática. INF231 - Sistemas Operativos
Copyright © 2001, Viktor Khlebnikov v 0.1
Feedback Scheduling
WS, OSIDP, 3E, Fig. 9-10
5. Planificación de Procesos 28
Pontificia Universidad Católica del Perú. Ingeniería Informática. INF231 - Sistemas Operativos
Copyright © 2001, Viktor Khlebnikov v 0.1
A Comparison of Scheduling Policies (1/3)
Process Arrival Time Service Time
1 0 32 2 63 4 44 6 55 8 2
WS, OSIDP, 3E, Fig. 9-5
15
5. Planificación de Procesos 29
Pontificia Universidad Católica del Perú. Ingeniería Informática. INF231 - Sistemas Operativos
Copyright © 2001, Viktor Khlebnikov v 0.1
A Comparison of Scheduling Policies (2/3)
WS, OSIDP, 3E, Fig. 9-5
5. Planificación de Procesos 30
Pontificia Universidad Católica del Perú. Ingeniería Informática. INF231 - Sistemas Operativos
Copyright © 2001, Viktor Khlebnikov v 0.1
A Comparison of Scheduling Policies (3/3)
WS, OSIDP, 3E, Fig. 9-5