This lab has four basic goals:
Many elements of this laboratory exercise are based on Lab Exercise 7.1 in Nutt's text. In particular, students should read that material carefully for an explanation of the approach of event-driven simulation.
Program ~walker/213/c-examples/simulation-sched.c and include-file
~walker/213/c-examples/fcfs_scheduler.c provides a basic
framework for an event-driven simulation for the first-come, first-served
(FCFS) non-preemptive scheduling algorithm.
Looking at the above code in more detail,
~walker/213/c-examples/fcfs_scheduler.c includes the
structures, variables, and functions specific to job scheduling.
int jobQueueIsEmpty (void) returns true or false, according to
whether any jobs are waiting in a ready state for scheduling and execution,
void initializeJobQueue (void) sets up the job queue with no jobs
currently pending,
void insertJob (struct Event * job) adds the specified job to
the job queue, and
struct Event * selectJob (void) selects the next job to run
from the job queue, removes the job from the queue, and returns it.
The current details of these functions implement the FCFS scheduling algorithms. To change the FCFS scheduler to Shortest Job Next (SJN) or Priority scheduling, only the internals of these functions need be altered.
simulation-sched.c incorporates the fcfs_scheduler.c into an
event-based simulation.
registerJob event
that enters the job into the system's data structure for ready processes.
scheduler. If jobs are
pending, the scheduler event retrieves the next job using the
select operation and runs the job. If no jobs are pending,
time is advanced until the next event will occur.
processEvent event is
triggered. This adds any required administrative overhead to the clock.
If processes run without preemption, then the process is run to
completion. If preemption is allowed, then the process runs for its time
slice. When the process stops, a new scheduler event is triggered.
registerJob events, the program reads a sequence
of jobs (arrival time, required processing time, priority) from a file for
use in the simulation. (As given, the file is
/home/walker/213/c-examples/simulation-sched-data.txt.)
Each job arrival generates an event, placed on an eventList.
preemptiveAlg is 0 for nonpreemptive scheduling or
the basic time quantum for a time slice for preemptive scheduling.
schedulerOverhead specifies the amount of
administrative overhead required by the scheduler each time it is called.
This program contains three debugging flags that can provide on-going information as the simulation runs:
input prints the input cases as they are read from the
file
eventlist prints the event list each time through the
main simulation loop
timemonitor prints the waiting and processing times of
completed jobs each time through the main simulation loop.
Any combination of these flags can be invoked at compile time. For
example, the following line invokes the input and
timemonitor flags:
gcc -o simulation-sched -Dinput -Dtimemonitor simulation-sched.c && simulation-sched
Steps for this Lab:
schedulerOverhead as 0.0, 0.01, 0.02, 0.03, and 0.04
seconds.
simulation-sched.data.txt) or
you may expand this file to include further processes.
fcfs_scheduler.c to another that
implements the SJN scheduling algorithm.
processJob event
handler. In this case, if the time quantum preemptiveAlg is
positive, then a job is allowed to run continuously only for that time
slice. If the job finishes in a time slice, then statistics for the job
are compiled. Otherwise, the time remaining for the job is reduced by the
time slice, and the scheduler is invoked again.
fcfs_scheduler.c to another than
implements a multi-queue, priority system. Assume priorities are between 1
(most pressing importance) through 10 (not very important). In this
variation, vary the time allocated to a job according to its priority:
time interval = preemptiveAlg / 2^(priority-1)
Work to be turned in:
This document is available on the World Wide Web as
http://www.cs.grinnell.edu/~walker/courses/213.fa04/lab-scheduling.shtml
|
created September 26, 2004 last revised September 27, 2004 |
|
| For more information, please contact Henry M. Walker at (walker@cs.grinnell.edu) |