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().
-
arrivalCount
- The number of job arrivals
-
ARRIVALS_SLOT
- Slot number for the JobArrivals device.
-
BLOCKSIZE
- The size of a disk block, in bytes
-
CLOCK_SLOT
- Slot number for the Clock device.
-
completed
- Information about completed Jobs.
-
CPU_SLOT
- Slot number for the CPU device.
-
cpuScheduler
- Scheduler for the cpu
-
currentTime
- The current simulated time (in ms since start)
-
dev_name
- For debugging: slot names
-
device
- An array of devices, index by one of the following slot numbers
-
DEVICES
- Number of devices "installed"
-
DISK_SLOT
- Slot number for the Disk device.
-
DISK_TIME
- The amount of time it takes for a disk operation
-
diskScheduler
- Scheduler for the disk
-
ODD_BURST_PROB
- Probability of an "unusual" CPU burst.
-
QUANTUM
- The quantum for round-robin scheduling
-
SWAP_OVERHEAD
- Penalty for starting and stopping a process.
-
traceFlag
- Trace flag.
-
verbosity
- Flag to control the verbosity of debugging output.
-
Sim()
-
-
assert(boolean)
- Crude assertion checking.
-
db(int, Object, Object)
- Overloaded version of the debug method.
-
db(int, Object, Object, Object)
- Overloaded version of the debug method.
-
db(int, Object, Object, Object, Object)
- Overloaded version of the debug method.
-
db(int, Object, Object, Object, Object, Object)
- Overloaded version of the debug method.
-
db(int, Object, Object, Object, Object, Object, int)
- Overloaded version of the debug method.
-
db(int, String)
- Print a message if verbosity >= level.
-
db(String)
- Print a message unconditionally.
-
firstInterrupt()
- Query the devices to see which one will be the first to interrupt.
-
mainLoop(String)
- This is the main program that runs the simulation.
-
moreVerbose()
- Increase the verbosity.
-
now()
- Get the current time.
-
pr(String)
- Print a message unconditionally without a header.
-
schedule(Job, Device)
- Utility routine to send a Job to the Disk, CPU, or completion as
appropriate.
-
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.
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:
- 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 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 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.
Sim
Sim()
now
public static int now()
- Get the current time.
- Returns:
- the current time.
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.
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,
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,
Object o1,
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,
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.
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.
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.
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.
db
public static void db(String msg)
- Print a message unconditionally.
- Parameters:
- msg - the message to print.
pr
public static void pr(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 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.