CS 446/646 Principles of Computer Operating Systems

Spring 2009

Lab 3

Due on Tuesday, April 28 at 12:00 pm


In this assignment, you will write a program that simulates a dispatcher that schedules the CPU time for a stream of arriving processes. Details and required characteristics of the dispatcher are described below.

Multi-Level Priority Dispatcher

The dispatcher operates at four priority levels:

Multi-level queue

The dispatcher needs to maintain two submission queues - Real-Time and User priority - fed from the job dispatch list. The dispatch list is examined at every dispatcher tick and jobs that "have arrived" are transferred to the appropriate submission queue. The submission queues are then examined; any Real-Time jobs are run to completion, preempting any other jobs currently running.

The Real-Time priority job queue must be empty before the lower priority feedback dispatcher is reactivated. Any User priority jobs in the User job queue that are ready to run are transferred to the appropriate priority queue. Normal operation of a feedback queue will accept all jobs at the highest priority after each completed time quantum. However, this dispatcher has the ability to accept jobs at a lower priority, inserting them in the appropriate queue. This enables the dispatcher to emulate a simple Round Robin dispatcher if all jobs are accepted at the lowest priority.

When all "ready" higher priority jobs have been completed, the feedback dispatcher resumes by starting or resuming the process at the head of the highest priority non-empty queue. At the next tick, the current job is suspended (or terminated) if there are any other jobs "ready" of an equal or higher priority.

Always assume that an arriving process(es) joins the queue right before the process that is coming from the processor. For example, this happens when process A finishes its time quantum at time 5, and another process B arrives right at the time 5. According to our policy, process B must stand before process A in the queue at time 5.

The logical flow of processes should be as shown in the figure below.


Bonus (25 points)

You should realize that the logical flow described in the figure above allows User processes to starve. In addition to the dispatcher logical flow described in the figure above, also implement other logical flows as shown in Figure below so that User processes are guaranteed to reach the CPU eventually.

Specifically, if a User process has been in the three-level feedback scheduling system for 100 time quantums (i.e., 100 seconds), move that User process to the Real Time Queue for one time quantum amount, i.e. 1 second. If that 1 second is still not enough to complete the User process, then move it back down to the three-level feedback scheduling system by making it enter at the highest priority level. In this manner, very long processes might traverse the Real Time Queue and the three-level feedback queues several times. Notice that a User process can stay be in the highest priority level of the feedback scheduling system, but be moved to the Real Time Queue if it has not been able to reach the CPU for 100 time quantums. These additional flows in the logic are shown in the Figure below with solid lines.

New Dispatcher

This advanced version of the dispatcher should be submitted as a separate source file(s) and the executable's name should be fairdispatcher. Note that this executable and the source file(s) must be in addition to the ones for the earlier version.

Dispatch List

The Dispatch List is the list of processes to be processed by the dispatcher. The list is contained in a text file that is specified on the command line, i.e.

~> dispatcher dispatchlist.txt

Note that we should be able to give the same Dispatch List file to the advanced executable fairdispatcher as well.

Except the last line, each line of the list describes one process with the following data as a "comma-space" delimited list:

	< arrival time >, < priority >, < processor time > 

The last line of the list will be empty. Thus,

	1, 0, 3
	2, 1, 2
	3, 3, 6
	< empty line >

would indicate:

After handling all the process events, your dispatcher program (i.e. dispatcher) should finally print the global average turnaround time, and global average waiting time. Use this printout format with two decimals:

Average turnaround time = 5.33
Average waiting time = 1.67

The submission text file (i.e. dispatchlist.txt) can be of any length, containing up to 1000 jobs. The jobs in the file will be in time order. It will be terminated with an end-of-line followed by an end-of-file marker. Obviously, your submitted dispatcher will be tested with complex combinations of processes and their arrivals.


You might test your project using
test1.txt (Average turnaround = 5.33 and Average wait = 1.67), test2.txt (Average turnaround = 57.25 and Average wait = 41.75), and test3.txt (Average turnaround = 295.11 and Average wait = 268.18) and compare your result against dispatcher (should run in Linux systems if you set it to executable).

Design Document

Design your dispatcher (second dispatchers for bonus) that satisfies the criteria outlined above. In a formal design document: