Capítulo 5: Planificación de Procesos (Scheduling) 5. Planificación de Procesos 1 Scheduler, Scheduling Algorithm and Process Behavior The scheduler The scheduling algorithm Process behavior: A CPU-bound process An I/O-bound process AST, MOS2E, Fig. 2-37 5. Planificación de Procesos 2 1
When to Schedule 1. when a new process is created: the parent process or the 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 5. Planificación de Procesos 3 Categories of Scheduling Algorithms Three environments worth distinguishing are 1. Batch. 2. Interactive. 3. Real time. AST, MOS2E, p. 136 5. Planificación de Procesos 4 2
Scheduling Algorithm Goals (1/2) All systems Fairness - giving each process a fair share of the CPU Policy enforcement - seeing that stated policy is carried out Balance - keeping all parts of the system busy Batch systems Throughput - maximize jobs per hour Turnaround time - minimize time between submission and termination CPU utilization - keep the CPU busy all the time AST, MOS2E, p. 137 5. Planificación de Procesos 5 Scheduling Algorithm Goals (2/2) Interactive systems Response time - respond to requests quickly Proportionality - meet user s expectations Real-time systems Meeting deadlines - avoid losing data Predictability - avoid quality degradation in multimedia systems AST, MOS2E, p. 137 5. Planificación de Procesos 6 3
Scheduling in Batch Systems: First-Come First-Served (FCFS) P1 P2 P3 Proceso Duración de la ráfaga P1 24 P2 3 P3 3 nonpreemptive Gráfica de Gantt P1 P2 P3 0 24 27 30 t pr.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 sec to finish. But in case of 10 msec preemption, the I/O-bound process would finish in 10 sec and without slowing down the CPU-bound process very much. 5. Planificación de Procesos 7 Scheduling in Batch Systems: Shortest Job First (SJF) (1/2) P2 P4 P1 P3 0 Proceso Duración de la ráfaga P1 8 P2 4 P3 4 P4 4 nonpreemptive P1 P2 P3 8 12 16 P4 20 t pr.respuesta = (8+12+16+20)/4 = 56/4 = 14 P2 P3 P4 0 4 8 12 P1 20 t pr.respuesta = (4+8+12+20)/4 = 44/4 = 11 5. Planificación de Procesos 8 4
Scheduling in Batch Systems: Shortest Job First (SJF) (2/2) Consider the case of 4 jobs, with run times of a, b, c, and d, respectively. The first job finishes at time a, the second finishes at time a + b, and so on. The mean turnaround time is (4a + 3b + 2c + d)/4.... Proceso Duración de la ráfaga Tiempo de llegada P1 2 0 P2 4 0 P3 1 3 P4 1 3 P5 1 3 P2 P1 0 P4 P3 P5 P1 P2 P3 2 6 7 8 nonpreemptive P4 P5 9 t mean turnaround = (2+6+4+5+6)/5 = 23/5 = 4.6 versus 4.4 for P2, P3, P4, P5, P1. 5. Planificación de Procesos 9 Scheduling in Batch Systems: Shortest Remaining Time First Proceso Duración de la ráfaga Tiempo de llegada P1 2 0 P2 4 0 P3 1 3 P4 1 3 P5 1 3 P2 P1 0 P1 P4 P3 P5 preemptive P2 P3 P4 P5 P2 2 3 4 5 6 9 t mean turnaround = (2+9+1+2+3)/5 = 17/5 = 3.2 5. Planificación de Procesos 10 5
Scheduling in Batch Systems: Three-Level Scheduling AST, MOS2E, Fig. 2-40 5. Planificación de Procesos 11 Scheduling and Process State Transitions WS, OSIDP, 3E, Fig. 9-1 5. Planificación de Procesos 12 6
Queuing Diagram for Scheduling WS, OSIDP, 3E, Fig. 9-3 5. Planificación de Procesos 13 Round-Robin Scheduling (1/4) One of the oldest, simplest, fairest, and most widely used algorithms is round robin (time slicing). Quantum, quanta. Process (context) switch. The list of runnable processes. The list of runnable processes after B uses its quantum. AST, MOS2E, Fig. 2-41 5. Planificación de Procesos 14 7
Round-Robin Scheduling (2/4) WS, OSIDP, 3E, Fig. 9-6 5. Planificación de Procesos 15 Round-Robin Scheduling (3/4) WS, OSIDP, 3E, Fig. 9-6 5. Planificación de Procesos 16 8
Queuing Diagram for Virtual Round-Robin Scheduling (4/4) WS, OSIDP, 3E, Fig. 9-7 5. Planificación de Procesos 17 Priority Scheduling (1/7) AST, MOS2E, Fig. 2-42 5. Planificación de Procesos 18 9
Priority Scheduling (2/7) WS, OSIDP, 3E, Fig. 9-4 5. Planificación de Procesos 19 MINIX Structure (3/7) Layer 4 Init User process User process User process... User processes 3 Memory manager File system Network server... Server processes 2 Disk task Tty task Clock task System task Ethernet task... I/O tasks 1 Process management AST & ASW, OSDI2E, Fig. 2-26 5. Planificación de Procesos 20 10
MINIX Scheduling (4/7) AST & ASW, OSDI2E, Fig. 2-36 5. Planificación de Procesos 21 UNIX Scheduling (5/7) AST, MOS2E, Fig. 10-11 5. Planificación de Procesos 22 11
Mapping of Win32 priorities to Windows 2000 priorities (6/7) AST, MOS2E, Fig. 11-18 5. Planificación de Procesos 23 Windows 2000 support 32 priorities for threads (7/7) AST, MOS2E, Fig. 11-19 5. Planificación de Procesos 24 12
Aging Se predice como un promedio exponencial de las longitudes medidas de las ráfagas de CPU anteriores. Sea t n la longitud de la n-ésima ráfaga de CPU, y τ n+1 el valor previsto para la siguiente ráfaga. Entonces, para α, 0 α 1, se define τ n+1 = α t n + (1 - α) τ n Esta fórmula define un promedio esponencial. Maduración o envejecimiento (aging). α = 0.5 AST, MOS2E, p. 146 5. Planificación de Procesos 25 Other Scheduling Algorithms Guaranteed Scheduling: if there are n users logged in while you are working, you will receive about 1/n of the CPU power. Lottery Scheduling: the system might hold a lottery 50 times a second, 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 only 1 process, E. If two users have each been promised 50% of the CPU: A E B E C E D E A E B E C E D E AST, MOS2E, pp. 146-148 5. Planificación de Procesos 26 13
Feedback Scheduling WS, OSIDP, 3E, Fig. 9-10 5. Planificación de Procesos 27 A Comparison of Scheduling Policies (1/3) Process Arrival Time Service Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2 WS, OSIDP, 3E, Fig. 9-5 5. Planificación de Procesos 28 14
A Comparison of Scheduling Policies (2/3) WS, OSIDP, 3E, Fig. 9-5 5. Planificación de Procesos 29 A Comparison of Scheduling Policies (3/3) WS, OSIDP, 3E, Fig. 9-5 5. Planificación de Procesos 30 15