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