Project #3 ::
Memory Management (Paging)
Subroutine Structure
CIS343
Top
Level Subroutines
Note: The subroutines marked Sub
are procedures;
functions are marked Function.
Names of subroutines called are shown
by indentation.
Sub cmdExit_Click( ) :: the Exit
Button
Sub Form_Load() :: does a
bit of initialization
Sub cmdInit_Click( ) ::
initializes the program
ReadTraces
InitGlobals
Sub cmdRunSim_Click() :: the main simulation loop
doOneEvent
executeInstruction
closeUpShop
Secondary
& Tertiary Level Subroutines
Sub ReadTraces() :: reads
trace files into parallel 2-d arrays
Sub InitGlobals() ::
initializes global data structures & variables
SetSubmissionTimes
InitMTK
InitQs
Sub SetSubmissionTimes() :: initializes information about job
submission times
Sub InitMTK() :: initializes the master time keeper array (MTK)
Sub InitQs() :: initializes the global queues: readyQ, newQ, and availQ.
Public Function QuittingTime() As Boolean :: determines whether it is
time to halt
simulation
Public Sub executeInstruction() :: simulates execution of
one instruction
onePageRef(.
. . )
ihOnePageFault(.
. . )
twoPageRefs(page1(.
. . )
ihTwoPageFaults(
. . . )
ihSysCall_1_2
ihSysCall_3(
. . . )
ihJobFinish
Sub doOneEvent() :: performs OS operations for a scheduled event
ReWordEvent(currentEvent)
Remove1stEvent
ihJobEnters(sysClock,
currentJob)
ihQuantumExpires(sysClock,
currentJob)
ihUnblock(sysClock,
currentJob)
Public Sub closeUpShop() :: closes files, etc.
Interrupt
Handlers
Sub ihJobEnters(ByVal curTime As Long, ByVal pid As
Integer) ::
Invoked when
job is submitted to the system
addItemNewQ(pid)
addItemRQ(pid)
makeCPUJob(pid)
Sub ihUnblock(ByVal curTime As Long, ByVal pid As Integer) :: Handles
removing job from Blocked Queue.
addItemRQ
(pid)
makeCPUJob(pid)
Sub ihQuantumExpires(ByVal curTime As Long, ByVal pid As
Integer) ::
Invoked when cpu job’s quantum expires (not used in FIFO)
addItemRQ(pid)
giveCPU
Sub ihOnePageFault(ByVal pageNumber As Integer) :: processes a single page
fault
getPageFrame
blockCPUJob(pageFaultBlockTime)
Sub ihTwoPageFaults(ByVal page1 As Integer, ByVal page2 As
Integer) ::
processes a double page fault
getPageFrame
blockCPUJob(pageFaultBlockTime)
Sub ihSysCall_1_2() :: processes syscalls #1 & #2
blockCPUJob(syscallBlockTime)
Sub ihSysCall_3(ByVal pageLo As Integer, ByVal pageHi As
Integer) ::
processes syscall #3
onePageRef(page,
"read")
simpPageFault(page)
Call
blockCPUJob( . . . )
Sub ihJobFinish() :: processes job completion
isEmptyNewQ()
addItemRQ(removeNewQ())
giveCPU
Helper
Subroutines
sortMTK(ByVal numItemsIn As Integer) :: Sorts events of MTK by
time
Public Sub makeCPUJob(ByVal pid As Integer) :: Gives CPU to job #pid
Public Sub RegisterEvent(ByVal eTime As Long, ByVal pid As
Integer, ByVal regEvent As String) :: places
an event onto the MTK list
sortMTK(numberOfEvents)
Public Sub giveCPU() :: chooses
next job to get CPU
isEmptyRQ()
makeCPUJob(removeRQ())
Sub Remove1stEvent() :: removes
event about to be handled by OS
Function onePageRef(ByVal pageNum As Integer, ByVal
refType As String) As Boolean :: processes a single page reference returning True
if the page
referenced is resident; False otherwise
Function twoPageRefs(ByVal page1 As Integer, ByVal
refType1 As String, ByVal page2 As Integer, ByVal refType2 As String, ByRef
refCode As Integer) As Boolean :: processes a double page reference returning True
if the page
referenced is resident; False otherwise; also returns via parameter a reference
code to indicate which pages were non-resident
Sub blockCPUJob(ByVal amtBlock As Integer) :: blocks the current CPU
job
RegisterEvent(sysClock
+ amtBlock, cpuJob, "junblock")
giveCPU
Function getPageFrame() As Integer :: returns a frame number,
invoking page replacement, if necessary
isEmptyAvQ
removeAvQ
modClock
Function modClock() As Integer :: implements the modClock
page replacement strategy; returns the frame number replaced
doStepOne(frameNum)
doStepTwo(frameNum)
Function doStepOne(ByRef frameNum As Integer) As Boolean :: carries out the first
step of modClock; returns True if step succeeded; False otherwise; also, if
succeeded, returns the frame number found
Function doStepTwo(ByRef frameNum As Integer) As Boolean :: carries out the second
step of modClock; returns True if step succeeded; False otherwise; also, if
succeeded, returns the frame number found
Sub simpPageFault(ByVal pageNumber As Integer) :: processes a single page
fault, but does not block the faulting job (used by Syscall #3)
Queue
Manipulation Subroutines
Ready Queue:
Function removeRQ() As Integer :: removes item at head of
queue and returns it
Sub addItemRQ(ByVal addItem As Integer) :: adds item to tail of
queue
Function isEmptyRQ() As Boolean :: returns True
if ReadyQ is
empty;
False otherwise
Function nextSlotRQ(ByVal index As Integer) As Integer :: calculates value of
next queue pointer
Avail Queue: keeps a list of available
page frames
Function removeAvQ() As Integer
Sub addItemAvQ(ByVal addItem As Integer)
Function isEmptyAvQ() As Boolean
Function nextSlotAvQ(ByVal index As Integer) As Integer
New Queue: keeps a list of jobs in the New state
Function removeNewQ() As Integer
Sub addItemNewQ(ByVal addItem As Integer)
Function isEmptyNewQ() As Boolean
Function nextSlotNewQ(ByVal index As Integer) As Integer
Subroutines
for Display & Debugging
Sub showMTK() :: prints
contents of MTK array into designated file
Public Function ReWordEvent(ByVal cEvent As String) As
String :: used
to
produce output strings
Public Function IdentifyJob(ByVal pid As Integer) As String :: more output strings