Documente Academic
Documente Profesional
Documente Cultură
1. Basic Concepts
1.1 Motivations
Process execution consists of CPU execution (CPU Burst) and I/O wait (I/O Burst)1 Process execution is an alternating sequence of CPU Burst and I/O Burst. (Begin) CPU Burst I/O Burst CPU Burst I/O Burst CPU Burst (Terminated) Generally, a process has a large number of short CPU bursts and a small # of long CPU burst (see Figure 5.1)
# of CPU Bursts
Duration of CPU Burst Figure 5.1 Histogram of CPU Burst times CPU Scheduler select a process from the ready queue when the current process releases the CPU Since the scheduler executes very frequently, it must be o Very fast to avoid wasting CPU time o Very efficient (i.e., the problem of selecting a CPU algorithm for a particular system)
While the CPU bound process has a larger number of longer CPU bursts, the I/O bound process has a larger number of I/O bursts. Because there is a CPU burst between two I/O burst, the I/O bound process has a larger number of short CPU bursts.
Note that all the PCBs (Process Control Blocks) in the ready queue represent the processes in CPU burst state2.
Dispatcher switches the context so as to start the execution of the next process, which is selected by the CPU scheduler.
o Cons: Additional overheads (e.g., more frequent context switching, HW timer, coordinated access to data, etc.)
Assumptions: The durations of the CPU bursts of P1, P2, and P3 are 19, 10, and 7 respectively. P1, P2, and P3 have only one CPU burst. Processes arrival time: P1 (0), P2 (2), P3 (4): P1 P2 P3
0 7 17 36 Waiting times: P1=17-4=13; P2=7-2=5; P3=0 Avg. Waiting time = (13+5+0)/3=6 Figure 5.2 Examples of FCFS algorithm Convey effect: several processes that have very short CPU bursts follow one big CPU bound process. Lets assume that all processes have similar I/O bursts. Pros: o Simple to understand and implement o Very fast selection of the next process Cons: o Avg. Waiting time is long and may vary substantially, depending on the process input order o Not suitable for time-sharing OS
Assumptions: The durations of the CPU bursts of P1, P2, and P3 are 19, 10, and 7 respectively. P1, P2, and P3 have only one CPU burst. Processes arrival time: P1 (0), P2 (2), P3 (4). Non-Preemptive: P1 0 P2 P1 Preemptive: P3 024 P2 11 P1 19 36 P3 19 P2 26 36
Waiting times: P1=0+(19-2)=17; P2=0+(11-4)=7; P3=0 Avg. Waiting time = (17+7+0)/3=8 Figure 5.3 Examples of SJF & SRTF
Pros: o Yields minimum avg. waiting time for a given set of processes. Cons: o Difficult to estimate CPU burst time. o Starvation (indefinite blocking) Predicting the next burst time based on the previous bursts (exponential avg. of the lengths of previous CPU bursts).
o o o o
tn: length of the nth CPU burst n+1: predicted length of the next CPU burst 01 n+1 = tn + (1-)n (Note, + (1-) = 1) is the weight of the most recent CPU burst length tn (1-) is the weight of the past history of CPU burst lengths n The weight of tn-x is (1- )x. Since (1-) < 1, as x increases, the weight of tn-x is decreased.
Waiting times: P1=0+(19-2)=17; P2=0+(11-4)=7; P3=0 Avg. Waiting time = (17+7+0)/3=8 Figure 5.4 Examples of NP & P Priority Scheduling Algorithms A priority is associated with each process, and the CPU is allocated to the process with the highest priority. Equal-priority processes are scheduled in FCFS. o Non-preemptive: once the CPU has been given to a process, it cannot be preempted until the process completes the CPU burst. o Preemptive: when a process with the priority that is higher than the priority of the current process is inserted into the ready queue, the current process relinquishes the CPU involuntarily and the CPU is allocated to Pi. Priority values are defined either internally or externally (relative to the system) 5
SJF and SRTF are the variants of Priority Scheduling (e.g., p=) Pros: o More reactive o Can be used for soft real-time systems Cons: o Can cause indefinite blocking or starvation Solution: gradually increase priority of Pi as time progresses (also known as aging).