>
UNIVERSITY OF WISCONSIN-MADISON
Computer Sciences Department | ||
CS 537
Spring 2001 | A. Arpaci-Dusseau | |
Quiz #2: Feb 14th, 2001 -- CPU Scheduling |
Name: Solutions | Student ID #: Solutions |
Job | Arrival Time | CPU time |
A | 0 | 5 |
B | 2 | 4 |
C | 4 | 5 |
D | 6 | 2 |
For each of the following scheduling algorithms, compute the waiting time of each job. You should use the definition of waiting time given in Lecture (that is, the total time the job is waiting in the ready queue). Note that drawing the Gantt charts may be helpful for you and may allow us to give you partial credit if you make a mistake, but is not required for full credit.
FCFS:
Gantt chart:
0 5 9 14 16
|--------------|----------|--------------|----|
A B C D
General formula for waiting time with non-preemptive policies:
T_firstscheduled - T_arrival
Waiting time of each job:
A: 0 - 0 = 0
B: 5 - 2 = 3
C: 9 - 4 = 5
D: 14 - 6 = 8
Note that you did not need to calculate the average waiting time of
the workload.
SJF:
0 5 9 11 16
|--------------|----------|----|--------------|
A B D C
A: 0 - 0 = 0
B: 5 - 2 = 3
C: 11 - 4 = 7
D: 9 - 6 = 3
STCF:
0 5 6 8 11 16 |--------------|--|----|--------|--------------| A B D B C More general formula for waiting time with preemptive policies (of course, also works with non-preemptive policies): T_finished - T_cpu - T_arrival A: 0 B: 11 - 4 - 2 = 5 C: 7 D: 0
1. Both scheduling algorithms assume that one can predict the CPU burst of each job in the workload, which is not possible in practice. (However, the OS can often use the past behavior of the job to predict how it will behave in the future, which is what is done with multi-level feedback queues). 2. Both scheduling algorithms can starve jobs with long CPU bursts, if shorter jobs keep arriving. (Therefore, multi-level feedback queue schedulers usually watch to ensure that each job is getting scheduled periodically and raises the priority of any jobs that aren't.)
What is the mean system load given this workload? (Big Hint: This question is straight out of the textbook, but is still solvable if you didn't read this part carefully. For "mean system load" report the average percentage of time that the CPU is busy, or utilized. Note that the scheduling algorithm used is irrelevant!)
On average, a job is arriving every 4 seconds and uses 1 second of CPU time. Regardless of how the jobs are scheduled, on average, the CPU will be busy 1sec/4sec or 25% of the time.
Imagine that instead of 1 second of processing time, each job requires 10 seconds of processing time. Will this system ever be idle? What implications does this workload have in the design of the OS?
Given that the processing time of each job (i.e., 10 secs) is longer than the time between job arrivals (i.e., 4 secs), there will always be jobs that need to be processed and the system will never be idle. In fact, the number of jobs in the system will keep increasing over time since jobs are arriving more rapidly than they can be serviced. Remember that the OS must have a PCB in the ready queue for every job in the system; any finite-length ready queue will eventually overflow. The implication is that the OS must limit, or control, the number of jobs that can be in the ready list at any time, thereby rejecting jobs when the ready queue is full. This is known as admission control.