Class Sim

java.lang.Object
   |
   +----Sim

class Sim
extends 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().


Variable Index

 o arrivalCount
The number of job arrivals
 o ARRIVALS_SLOT
Slot number for the JobArrivals device.
 o BLOCKSIZE
The size of a disk block, in bytes
 o CLOCK_SLOT
Slot number for the Clock device.
 o completed
Information about completed Jobs.
 o CPU_SLOT
Slot number for the CPU device.
 o cpuScheduler
Scheduler for the cpu
 o currentTime
The current simulated time (in ms since start)
 o dev_name
For debugging: slot names
 o device
An array of devices, index by one of the following slot numbers
 o DEVICES
Number of devices "installed"
 o DISK_SLOT
Slot number for the Disk device.
 o DISK_TIME
The amount of time it takes for a disk operation
 o diskScheduler
Scheduler for the disk
 o ODD_BURST_PROB
Probability of an "unusual" CPU burst.
 o QUANTUM
The quantum for round-robin scheduling
 o SWAP_OVERHEAD
Penalty for starting and stopping a process.
 o traceFlag
Trace flag.
 o verbosity
Flag to control the verbosity of debugging output.

Constructor Index

 o Sim()

Method Index

 o assert(boolean)
Crude assertion checking.
 o db(int, Object, Object)
Overloaded version of the debug method.
 o db(int, Object, Object, Object)
Overloaded version of the debug method.
 o db(int, Object, Object, Object, Object)
Overloaded version of the debug method.
 o db(int, Object, Object, Object, Object, Object)
Overloaded version of the debug method.
 o db(int, Object, Object, Object, Object, Object, int)
Overloaded version of the debug method.
 o db(int, String)
Print a message if verbosity >= level.
 o db(String)
Print a message unconditionally.
 o firstInterrupt()
Query the devices to see which one will be the first to interrupt.
 o mainLoop(String)
This is the main program that runs the simulation.
 o moreVerbose()
Increase the verbosity.
 o now()
Get the current time.
 o pr(String)
Print a message unconditionally without a header.
 o schedule(Job, Device)
Utility routine to send a Job to the Disk, CPU, or completion as appropriate.
 o tod(int)
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.

Variables

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

 o QUANTUM
 public static int QUANTUM
The quantum for round-robin scheduling

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

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

 o ODD_BURST_PROB
 public static final double ODD_BURST_PROB
Probability of an "unusual" CPU burst.

See Also:
newBurst
 o currentTime
 private static int currentTime
The current simulated time (in ms since start)

 o DEVICES
 private static final int DEVICES
Number of devices "installed"

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

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

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

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

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

 o dev_name
 private static final String dev_name[]
For debugging: slot names

 o diskScheduler
 private static Scheduler diskScheduler
Scheduler for the disk

 o cpuScheduler
 private static Scheduler cpuScheduler
Scheduler for the cpu

 o arrivalCount
 private static int arrivalCount
The number of job arrivals

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

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

 o traceFlag
 public static boolean traceFlag
Trace flag.

Constructors

 o Sim
 Sim()

Methods

 o now
 public static int now()
Get the current time.

Returns:
the current time.
 o mainLoop
 static void mainLoop(String fname)
This is the main program that runs the simulation.

Parameters:
fname - the name of the trace file describing the jobs.
 o 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.
 o 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.
 o moreVerbose
 public static void moreVerbose()
Increase the verbosity.

 o db
 public static void db(int level,
                       String msg)
Print a message if verbosity >= level.

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

Parameters:
level - the verbosity level of this message.
o1 - a parameter.
o2 - a parameter.
 o db
 public static void db(int level,
                       Object o1,
                       Object o2,
                       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.
 o db
 public static void db(int level,
                       Object o1,
                       Object o2,
                       Object o3,
                       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.
 o db
 public static void db(int level,
                       Object o1,
                       Object o2,
                       Object o3,
                       Object o4,
                       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.
 o db
 public static void db(int level,
                       Object o1,
                       Object o2,
                       Object o3,
                       Object o4,
                       Object o5,
                       int o6)
Overloaded version of the debug method.

Parameters:
level - the verbosity level of this message.
o1 - a parameter.
 o db
 public static void db(String msg)
Print a message unconditionally.

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

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

Parameters:
the - assertion.
 o tod
 public static 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.