Class Sim

java.lang.Object
  |
  +--Sim

class Sim
extends java.lang.Object

Class Sim is the main driver for the whole simulation. It contains the mainLoop processing loop, as well as various various methods for gathering and printing statistics and generating debugging output. All members are static. The only public members are the methods now(), moreVerbose(), db(), and tod().


Field Summary
private static int arrivalCount
          The number of job arrivals
private static int ARRIVALS_SLOT
          Slot number for the JobArrivals device.
static int BLOCKSIZE
          The size of a disk block, in bytes
private static int CLOCK_SLOT
          Slot number for the Clock device.
private static java.util.Vector completed
          Information about completed Jobs.
private static int CPU_SLOT
          Slot number for the CPU device.
private static Scheduler cpuScheduler
          Scheduler for the cpu
private static int currentTime
          The current simulated time (in ms since start)
private static java.lang.String[] dev_name
          For debugging: slot names
private static Device[] device
          An array of devices, index by one of the following slot numbers
private static int DEVICES
          Number of devices "installed"
private static int DISK_SLOT
          Slot number for the Disk device.
static int DISK_TIME
          The amount of time it takes for a disk operation
private static Scheduler diskScheduler
          Scheduler for the disk
static double ODD_BURST_PROB
          Probability of an "unusual" CPU burst.
static int QUANTUM
          The quantum for round-robin scheduling
static int SWAP_OVERHEAD
          Penalty for starting and stopping a process.
static boolean traceFlag
          Trace flag.
static int verbosity
          Flag to control the verbosity of debugging output.
 
Constructor Summary
(package private) Sim()
           
 
Method Summary
static void assert(boolean condition)
          Crude assertion checking.
static void db(int level, java.lang.Object o1, java.lang.Object o2)
          Overloaded version of the debug method.
static void db(int level, java.lang.Object o1, java.lang.Object o2, java.lang.Object o3)
          Overloaded version of the debug method.
static void db(int level, java.lang.Object o1, java.lang.Object o2, java.lang.Object o3, java.lang.Object o4)
          Overloaded version of the debug method.
static void db(int level, java.lang.Object o1, java.lang.Object o2, java.lang.Object o3, java.lang.Object o4, java.lang.Object o5)
          Overloaded version of the debug method.
static void db(int level, java.lang.Object o1, java.lang.Object o2, java.lang.Object o3, java.lang.Object o4, java.lang.Object o5, int o6)
          Overloaded version of the debug method.
static void db(int level, java.lang.String msg)
          Print a message if verbosity >= level.
static void db(java.lang.String msg)
          Print a message unconditionally.
private static int firstInterrupt()
          Query the devices to see which one will be the first to interrupt.
(package private) static void mainLoop(java.lang.String fname)
          This is the main program that runs the simulation.
static void moreVerbose()
          Increase the verbosity.
static int now()
          Get the current time.
static void pr(java.lang.String msg)
          Print a message unconditionally without a header.
private static void schedule(Job j, Device cpu)
          Utility routine to send a Job to the Disk, CPU, or completion as appropriate.
static java.lang.String tod(int time)
          Convert a time-stamp from ms to time of day in the format h:mm:ss.mmm This used to be written more "cleanly", but it turned out to consume a huge fraction of the entire time taken by the program, so it was re-written to avoid allocating and concatenating Strings until the very end.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

DISK_TIME

public static final int DISK_TIME
The amount of time it takes for a disk operation

QUANTUM

public static int QUANTUM
The quantum for round-robin scheduling

BLOCKSIZE

public static final int BLOCKSIZE
The size of a disk block, in bytes

SWAP_OVERHEAD

public static final int SWAP_OVERHEAD
Penalty for starting and stopping a process.

ODD_BURST_PROB

public static final double ODD_BURST_PROB
Probability of an "unusual" CPU burst.
See Also:
Job.newBurst()

currentTime

private static int currentTime
The current simulated time (in ms since start)

DEVICES

private static final int DEVICES
Number of devices "installed"

device

private static Device[] device
An array of devices, index by one of the following slot numbers

ARRIVALS_SLOT

private static final int ARRIVALS_SLOT
Slot number for the JobArrivals device.

DISK_SLOT

private static final int DISK_SLOT
Slot number for the Disk device.

CPU_SLOT

private static final int CPU_SLOT
Slot number for the CPU device.

CLOCK_SLOT

private static final int CLOCK_SLOT
Slot number for the Clock device.

dev_name

private static final java.lang.String[] dev_name
For debugging: slot names

diskScheduler

private static Scheduler diskScheduler
Scheduler for the disk

cpuScheduler

private static Scheduler cpuScheduler
Scheduler for the cpu

arrivalCount

private static int arrivalCount
The number of job arrivals

completed

private static java.util.Vector completed
Information about completed Jobs. This is a vector of objects of type JobStats

verbosity

public static int verbosity
Flag to control the verbosity of debugging output.

traceFlag

public static boolean traceFlag
Trace flag.
Constructor Detail

Sim

Sim()
Method Detail

now

public static int now()
Get the current time.
Returns:
the current time.

mainLoop

static void mainLoop(java.lang.String fname)
This is the main program that runs the simulation.
Parameters:
fname - the name of the trace file describing the jobs.

schedule

private static void schedule(Job j,
                             Device cpu)
Utility routine to send a Job to the Disk, CPU, or completion as appropriate.
Parameters:
j - the job to be dispatched.
cpu - the CPU device.

firstInterrupt

private static int firstInterrupt()
Query the devices to see which one will be the first to interrupt. Ties are broken in favor of the lowest-numbered device. Devices return Integer.MAX_VALUE if they are not running (and so will never interrupt) so if no device is ready, the result will be 0 (ARRIVALS_SLOT).
Returns:
the slot-number of the winner.

moreVerbose

public static void moreVerbose()
Increase the verbosity.

db

public static void db(int level,
                      java.lang.String msg)
Print a message if verbosity >= level.
Parameters:
level - the verbosity level of this message.
msg - the message.

db

public static void db(int level,
                      java.lang.Object o1,
                      java.lang.Object o2)
Overloaded version of the debug method.
Parameters:
level - the verbosity level of this message.
o1 - a parameter.
o2 - a parameter.

db

public static void db(int level,
                      java.lang.Object o1,
                      java.lang.Object o2,
                      java.lang.Object o3)
Overloaded version of the debug method.
Parameters:
level - the verbosity level of this message.
o1 - a parameter.
o2 - a parameter.
o3 - a parameter.

db

public static void db(int level,
                      java.lang.Object o1,
                      java.lang.Object o2,
                      java.lang.Object o3,
                      java.lang.Object o4)
Overloaded version of the debug method.
Parameters:
level - the verbosity level of this message.
o1 - a parameter.
o2 - a parameter.
o3 - a parameter.
o4 - a parameter.

db

public static void db(int level,
                      java.lang.Object o1,
                      java.lang.Object o2,
                      java.lang.Object o3,
                      java.lang.Object o4,
                      java.lang.Object o5)
Overloaded version of the debug method.
Parameters:
level - the verbosity level of this message.
o1 - a parameter.
o2 - a parameter.
o3 - a parameter.
o4 - a parameter.
o5 - a parameter.

db

public static void db(int level,
                      java.lang.Object o1,
                      java.lang.Object o2,
                      java.lang.Object o3,
                      java.lang.Object o4,
                      java.lang.Object o5,
                      int o6)
Overloaded version of the debug method.
Parameters:
level - the verbosity level of this message.
o1 - a parameter.

db

public static void db(java.lang.String msg)
Print a message unconditionally.
Parameters:
msg - the message to print.

pr

public static void pr(java.lang.String msg)
Print a message unconditionally without a header.
Parameters:
msg - the message to print.

assert

public static void assert(boolean condition)
Crude assertion checking. Throw a RuntimeException if the condition is not true.
Parameters:
the - assertion.

tod

public static java.lang.String tod(int time)
Convert a time-stamp from ms to time of day in the format h:mm:ss.mmm This used to be written more "cleanly", but it turned out to consume a huge fraction of the entire time taken by the program, so it was re-written to avoid allocating and concatenating Strings until the very end. Too bad Java doesn't have sprintf!
Parameters:
time - the time of day in ms past midnight
Returns:
a string version of the time.