CS372: Solutions for Homework 9

Problem 1:

Most round-robin schedulers use a fixed size quantum. Give an argument in favor of and against a small quantum.

Solution:
An argument against a small time quantum:  Efficiency. A small time quantum requires the timer to generate interrupts with short
intervals. Each interrupt causes a context switch, so overhead increases with a larger number of interrupts.
An argument for a small time quantum:  Response time. A large time quantum will reduce the overhead of context switching since
interrupts will be generated with relatively long intervals, hence there will be fewer interrupts. However, a short job will have to wait
longer time on the ready queue before it can get to execute on the processor. With a short time quantum, such a short job will finish
quicker and produces the result to the end user faster than with a longer time quantum.

Problem 2:

As a system administrator you have noticed that usage peaks between 10:00AM to 5:00PM and between 7:00PM to 10:00PM. The company's CEO decided to call on you to design a system where during these peak hours there will be three levels of users. Users in level 1 are to enjoy better response time than users in level 2, who in turn will enjoy better response time than users in level 3. You are to design such a system so that all users will still get some progress, but with the indicated preferences in place.
  1. Will a fixed priority scheme with pre-emption and 3 fixed priorities work? Why, or why not?
  2. Will a UNIX-style multi-feedback queue work? Why, or why not?
  3. If none of the above works, could you design a scheduling scheme that meets the requirements?

Solution:
1. No, it will not work. A fixed priority scheme can cause starvation. The required solution should enable all users to
make progress. Fixed priority does not guarantee progress for processes with low priorities.

2. No, it will not work. The multi-feedback queuing system will cause processes in level 1 to get less time on the CPU if
they stay in the system for very long. So, even though a level-1 process may start at the highest level in the feedback
queue, its priority will degrade over time. So this solution does not satisfy the requirements.

3. A process of level-1 will have 3 entries in the ready queue, distributed evenly over the queue. A process of level-2 will
have 2 entries, while a process of level 3 will have one entry. In a run, a process at level 1 will get 3 times as much as a
process at level 3 on the CPU. Care should be taken such that when a process requests an I/O operation, that all its
entries would be removed from the ready queue simultaneously. Also, when a process is added to the ready queue, it has
to be entered with all its entries even distributed over the entire queue. Other solutions such as a lottery scheduler are possible.

Problem 3

A periodic task is one that is characterized with a period T, and a CPU time C, such that for every period T of real time, the task executes C time on the CPU. Periodic tasks occur in real-time applications such as multimedia. For example, a video display process needs to draw a picture every 40 msec (outside the US, Japan and Canada). To do so, such a process will have a period of 40 msec, and within each, it will require some time to do the data copying and drawing the picture after getting it from the video stream.

Admission control is a policy implemented by the process manager in which the manager decides whether it will be able to run a task with given parameters and with the existing load. Of course, if the process manager over commits itself, a periodic task will not be able to meet its processing requirement every period. For the video display process example, the picture flow will slow down and a viewer will notice and get irritated.
Assume that a system has 5 processes, an editor, a mail checking program, a video display process, a network browser and a clock display. The requirements are such that the mail checking program has to execute for 10 msec every 1sec, the video display must execute 25 msec every 40 msec, and the clock display must execute for 10 msec every 1 sec.

  1. What scheduling policy would you use for such a system?
  2. Two process schedulers are available for you. The first would consume about 5 msec of overhead in context switching every 40 msec, while the second consumes 0.5 msec of overhead in context switching every 40 msec. The first ensures that the periodic processes will get time on the CPU every 40 msec if they are ready, while the second uses simple round-robin scheduling. Which one is better suited for this application batch? Which one is more efficient?
  3. Assume that the clock display program actually underestimated the time it wanted to run, and instead has now to run for 20 msec every 40 msec. What should the system do? How could it do it? Explain your answers.
    If an audio unit is to be installed with an audio playback processing requiring 15 msec every 40 msec, would you be able to admit the process into the system? If yes explain why, and if not, explain why and suggest what the system could do.

Solution:
1. A fixed priority scheme in which the video display would have the highest priority, followed by the clock, then followed by the rest.

2. While the second scheduling algorithm is more efficient than the first, it is practically useless for such a batch of applications because simple round-robin does not give the necessary guarantees that the video display program will run every 40- msec.

3. The system has to be able to stop the offending process. To do so, the system must set timers that would generate interrupts at the time limit by which a task has to finish. So, if the task has not finished after its allotted time has expired, then it is simply switched out and another application is run. This requires a very complex implementation to ensure that the timers are being handled properly.

4. The system cannot admit such a process, because it does not have the capacity to handle the workload and guarantee the time limits required for the other processes. In situations like this, the system may simply tell the user "sorry", or it may give her the ability to stop some of the existing applications so that the freed capacity be used to run the new application. Or, it may simply tell the user "we will not run this as it should, do you want to continue anyway?".

Problem 4

Comparison of FIFO, RR and SRTF Algorithms. Given the following mix of job, job lengths, and arrival times, assume a time slice of 10 and compute the completion for each job and average response time for the FIFO, RR, and SRTF algorithms.

Solution:

  Scheduling Algorithms
Job Length
(secs)
Arrival
time
FIFO RR SRTF
    Completion
time
Response
time
Completion
time
Response
time
Completion
time
Response
time
0850 85 85 220 220 220220
13010 115 105 80 70 4030
23510 150 140 125 115 7565
32080 170 90 145 65 10020
45085 220 135 215 130 15065
Average Response Time 111 120 80
Note:
RR's scheduling is:

    0:    0
  10:    1        * if scheduling 0, the result is listed below.
  20:    2
  30:    0
  40:    1
  50:    2
  60:    0
  70:    1
  80:    2        -------->Job1 completes
  90:    0
100:    3
110:    4
120:    2
125:    0        --------->Job2 completes
135:    3
145:    4        --------->Job3 completes
155:    0
165:    4
175:    0
185:    4
195:    0
205:    4
215:    0         --------->Job4 completes
220:               --------->Job0 completes

RR can also be:

  Scheduling Algorithms
Job Length
(secs)
Arrival
time
FIFO RR SRTF
    Completion
time
Response
time
Completion
time
Response
time
Completion
time
Response
time
0850 85 85 220 220 220220
13010 115 105 90 80 4030
23510 150 140 135 125 7565
32080 170 90 155 75 10020
45085 220 135 220 135 15065
Average Response Time 111 125 80

Problem 5

Consider the following preemptive priority-scheduling algorithm based on dynamically changing priorities. Larger priority numbers imply higher priority. When a process is waiting for CPU (in the ready queue, but not running), its priority changes at a rate of a (i.e., P(t) = P0 +a * (t - t0) where t0 is the time at which the process joins the ready queue) . Similarly, when it is running, its priority changes at a rate b. All processes are given a priority 0 when they enter the ready queue. The parameters a and b can be set to obtain many different scheduling algorithms.
  1. What is the algorithm that results from b > a > 0 ?
  2. What is the algorithm that results from a < b < 0 ?

Solution:

  1. FCFS (First-come, first-served).

    All the processes in the ready queue has the same inital priorty 0 (P0 =0) . Their priority increases at the same rate a(a>0).  Thus, the earlier the process enters the ready quese(t0) , the higher its priority will be (P(t) = a * (t - t0) ) .

    Once the process with the highest priority (first-come compared to other process in the ready queue) is running, its priority increases at a higher rate (b>a>0) than the priorities of those processes in the ready queue. So no other process will preempt it and it will run to its completion.

  2. LCFS (Last-come, first-served).

    All the processes in the ready queue has the same initial priority 0 (P0 =0) . Their priority decreases at the same rate a(a<0).  Thus, the earlier the process enters the ready quese(t0) , the lower its priority will be (P(t) = a * (t - t0) ) .

    Once the process with the highest priority(last-come compared to other process in the ready queue) is running, no other process in the ready queue will preempt it since its priority decreases at a lower rate (a<b<0) than the priorities of those processes in the ready queue. But it will be preempted by any new coming process because the new process's priority is 0 which is the highest possible priority.

    Problem 6

    Many scheduling algorithms are parameterized. For instance, the round-robin algorithm requires a parameter to indicate the time quantum. The multi-level feedback (MLF) scheduling algorithm requires parameters to define the number of queues, the scheduling algorithm for each queue, and the criteria to move processes between queues (and perhaps others. . .).

    Hence, each of these algorithms represents a set of algorithms (e.g., the set of round-robin algorithms with different quantum sizes). Further, one set of algorithms may simulate another (e.g., round-robin with infinite quantum duration is the same as first-come, first-served (FCFS)). For each of the following pairs of algorithms, answer the following questions:

    1. Priority scheduling and shortest job first (SJF)
      1. State the parameters and behavior of priority scheduling
        Solution
        Parameter: Each job has a priority P
        Behavior: Choose the job with the lowest numerical priority

      2. State the parameters and behavior of SJF
        Solution
        Parameter: Each job has a remaining time T
        Behavior: Choose the job with the lowest remaining T

      3. Can SJF simulate priority scheduling for all possible parameters of priority scheduling? (How or why not: State how to set SJF scheduling parameters as a function of priority scheduling parameters or explain why this cannot be done.)
        Solution
        2 possible answers: (1) No - although both schedulers are priority queues, SJF is more restrictive than a general priority scheduler since a job's time may not correspond to its priority. (2) Yes - "spoof" the scheduler by passing priority in place of time.

      4. Can priority scheduling simulate SJF for all possible parameters of SJF? (How or why not.)
        Solution
        Yes - set the priority P to the remaining time T

    2. Multilevel feedback queues and first come first served (FCFS)
      1. State the parameters and behavior of multi-level feedback queues
        Solution
        Parameters: N (# queues), scheduling algorithm for each queue, function that selects in which queue to place a job, criteria to interrupt a running job
        Behavior: Always schedule the job from the head of the lowest #'d non-empty queue according to that queue's scheduling algorithm; interrupt a running job when told to by the interrupt criteria; place newly arrived jobs or interrupted jobs in a queue based on the selection function

      2. State the parameters and behavior of FCFS
        Solution
        No parameters
        Behavior: Place arriving jobs at the back of a FIFO queue; when scheduling a new job, choose the one from the front of the FIFO queue; never interrupt a running job

      3. Can FCFS simulate multi-level feedback for all possible parameters of multi-level feedback? (How or why not?)
        Solution
        No. Counterexample: make the top queue of MLF run RR with a short time quantum. If two jobs arrive and each is longer than the quantum, the MLF scheduler will allow both jobs to run for at least one quantum before either completes, but FCFS can never interrupt a running job, so one of the two will complete before the other has a chance to run.

      4. Can multi-level feedback scheduling simulate FCFS for all possible parameters of FCFS? (How or why not?)
        Solution
        Yes. Make MLF have 1 queue and have that one queue run FCFS. Function to select which queue - always choose that queue. Policy to interrupt - Never.

    3. Priority scheduling and first come first served (FCFS)
      1. Can FCFS simulate priority scheduling for all possible parameters of priority scheduling? (How or why not?)
        Solution
        No. Counterexample: Suppose job 1 arrives at time 1 with priority 10 and length 1,000,000 and job 2 arrives at time 2 with priority 1 and length 1,000,000. FCFS will run job 1 to completion, then job 2 to completion. Priority will run job 1 for 1 unit, then job 2 to completion, then job 1 to completion.

      2. Can priority scheduling simulate FCFS for all possible parameters of FCFS? (How or why not?)
        Solution
        Yes. Set all jobs to equal priority (we assume that the priority queue breaks ties with FCFS and infinite time quantum)

    4. Round-robin and shortest job first (SJF)
      1. State the parameters and behavior of round robin
        Solution
        Parameter: Quantum Q
        Behavior: Run FIFO queue, but interrupt a running job Q units after it begins running and move it to the end of the FIFO queue

      2. Can round robin simulate SJF for all possible parameters of SJF? (How or why not?)
        Solution
        No. Counterexample. 3 jobs arrive: job 1 at time 0 is 10 seconds long, job 2 arrives at time 1 and is 100 seconds long, job 3 at time 2 is 10 seconds long. SJF must run 1 to completion, then 3 to completion, and then 2 to completion. Claim: RR must run at least one quantum of job 2 before running any job 3.

      3. Can SJF simulate round robin for all possible parameters of round robin? (How or why not?)
        Solution
        No. Same counterexample.

    Problem 7

    True/False Shortest positioning time first (SPTF), in which a disk scheduler selectes as the next block to fetch the block for which the (rotational time + seek time) is minimal is the optimal disk scheduling algorithm with respect to response time.

    Solution:
    False.