Expanding out ideas on Simulator 2... trying to get everything working
This commit is contained in:
parent
93904cb2f3
commit
62418ec35a
5 changed files with 138 additions and 12 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
CC = gcc -Wall -std=c99 -pedantic -g
|
CC = gcc -Wall -std=c99 -pedantic -g
|
||||||
SOURCES = StringUtils.c simulator.c metadataops.c configops.c OS_SimDriver.c
|
SOURCES = StringUtils.c simulator.c metadataops.c configops.c OS_SimDriver.c simtimer.c
|
||||||
OBJECTS = OS_SimDriver.o simulator.o metadataops.o configops.o StringUtils.o
|
OBJECTS = OS_SimDriver.o simulator.o metadataops.o configops.o StringUtils.o simtimer.o
|
||||||
|
|
||||||
all: Simulator
|
all: Simulator
|
||||||
|
|
||||||
|
|
@ -22,6 +22,9 @@ configops.o: configops.c
|
||||||
OS_SimDriver.o: OS_SimDriver.c
|
OS_SimDriver.o: OS_SimDriver.c
|
||||||
$(CC) -c OS_SimDriver.c -o OS_SimDriver.o
|
$(CC) -c OS_SimDriver.c -o OS_SimDriver.o
|
||||||
|
|
||||||
|
simtimer.o: simtimer.c
|
||||||
|
$(CC) -c simtimer.c -o simtimer.o
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(OBJECTS) sim02 sim02.out
|
rm -f $(OBJECTS) sim02 sim02.out
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,9 @@
|
||||||
// Constants /////////////////////////////////////////////////////////////////
|
// Constants /////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
const char RADIX_POINT = '.';
|
const char RADIX_POINT = '.';
|
||||||
|
const char SPACED = ' ';
|
||||||
|
|
||||||
void runTimer( int milliSeconds )
|
void *runTimer( int milliSeconds )
|
||||||
{
|
{
|
||||||
struct timeval startTime, endTime;
|
struct timeval startTime, endTime;
|
||||||
int startSec, startUSec, endSec, endUSec;
|
int startSec, startUSec, endSec, endUSec;
|
||||||
|
|
@ -61,11 +62,12 @@ void runTimer( int milliSeconds )
|
||||||
secDiff = ( endSec - startSec ) * 1000;
|
secDiff = ( endSec - startSec ) * 1000;
|
||||||
timeDiff = secDiff + mSecDiff;
|
timeDiff = secDiff + mSecDiff;
|
||||||
}
|
}
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
double accessTimer( int controlCode, char *timeStr )
|
double accessTimer( int controlCode, char *timeStr )
|
||||||
{
|
{
|
||||||
static Boolean running = False;
|
static bool running = false;
|
||||||
static int startSec = 0, endSec = 0, startUSec = 0, endUSec = 0;
|
static int startSec = 0, endSec = 0, startUSec = 0, endUSec = 0;
|
||||||
static int lapSec = 0, lapUSec = 0;
|
static int lapSec = 0, lapUSec = 0;
|
||||||
struct timeval startData, lapData, endData;
|
struct timeval startData, lapData, endData;
|
||||||
|
|
@ -75,7 +77,7 @@ double accessTimer( int controlCode, char *timeStr )
|
||||||
{
|
{
|
||||||
case ZERO_TIMER:
|
case ZERO_TIMER:
|
||||||
gettimeofday( &startData, NULL );
|
gettimeofday( &startData, NULL );
|
||||||
running = True;
|
running = true;
|
||||||
|
|
||||||
startSec = startData.tv_sec;
|
startSec = startData.tv_sec;
|
||||||
startUSec = startData.tv_usec;
|
startUSec = startData.tv_usec;
|
||||||
|
|
@ -88,7 +90,7 @@ double accessTimer( int controlCode, char *timeStr )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LAP_TIMER:
|
case LAP_TIMER:
|
||||||
if( running == True )
|
if( running == true )
|
||||||
{
|
{
|
||||||
gettimeofday( &lapData, NULL );
|
gettimeofday( &lapData, NULL );
|
||||||
|
|
||||||
|
|
@ -106,10 +108,10 @@ double accessTimer( int controlCode, char *timeStr )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STOP_TIMER:
|
case STOP_TIMER:
|
||||||
if( running == True )
|
if( running == true )
|
||||||
{
|
{
|
||||||
gettimeofday( &endData, NULL );
|
gettimeofday( &endData, NULL );
|
||||||
running = False;
|
running = false;
|
||||||
|
|
||||||
endSec = endData.tv_sec;
|
endSec = endData.tv_sec;
|
||||||
endUSec = endData.tv_usec;
|
endUSec = endData.tv_usec;
|
||||||
|
|
|
||||||
|
|
@ -31,12 +31,16 @@
|
||||||
enum TIMER_CTRL_CODES { ZERO_TIMER, LAP_TIMER, STOP_TIMER };
|
enum TIMER_CTRL_CODES { ZERO_TIMER, LAP_TIMER, STOP_TIMER };
|
||||||
|
|
||||||
extern const char RADIX_POINT;
|
extern const char RADIX_POINT;
|
||||||
extern const char SPACE;
|
extern const char SPACED;
|
||||||
|
|
||||||
// Function Prototyp /////////////////////////////////////////////////////////
|
// Function Prototyp /////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void runTimer( int milliSeconds );
|
void *runTimer( int milliSeconds );
|
||||||
|
// will run a timer for the amount of ms specified
|
||||||
double accessTimer( int controlCode, char *timeStr );
|
double accessTimer( int controlCode, char *timeStr );
|
||||||
|
// returns the actual time as a double AND as a time string
|
||||||
|
|
||||||
|
// no more access needed beyond this point (supporting functions)
|
||||||
double processTime( double startSec, double endSec,
|
double processTime( double startSec, double endSec,
|
||||||
double startUSec, double endUSec, char *timeStr );
|
double startUSec, double endUSec, char *timeStr );
|
||||||
void timeToString( int secTime, int uSecTime, char *timeStr );
|
void timeToString( int secTime, int uSecTime, char *timeStr );
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,72 @@
|
||||||
#include "configops.h"
|
#include "configops.h"
|
||||||
#include "metadataops.h"
|
#include "metadataops.h"
|
||||||
#include "StandardConstants.h"
|
#include "StandardConstants.h"
|
||||||
|
#include "simulator.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
Name: createProcessList
|
||||||
|
Process: reads through the opcode struct to fill out the linked list of PCBs
|
||||||
|
Function Input/Parameters: metadata (OpCodeType *)
|
||||||
|
Function Output/Parameters: none
|
||||||
|
Function Output/Returned: head pointer to the PCBs
|
||||||
|
Device Input/Device: none
|
||||||
|
Device Output/Device: none
|
||||||
|
Dependencies: malloc, sizeof, ???
|
||||||
|
*/
|
||||||
|
ProcessControlBlockLL *createProcessList(OpCodeType *metadataPtr)
|
||||||
|
{
|
||||||
|
// allocate and create the ProcessControlBlockLL using malloc and size of
|
||||||
|
ProcessControlBlockLL *headBlock;
|
||||||
|
headBlock = malloc(sizeof(ProcessControlBlockLL));
|
||||||
|
// set the head pointer to NULL
|
||||||
|
headBlock->headPtr = NULL;
|
||||||
|
// return headBlock
|
||||||
|
return headBlock;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Name: destroyProcessList
|
||||||
|
Process: deallocates memory used for the linked list struct
|
||||||
|
Function Input/Parameters: head pointer to linked list (ProcessControlBlockLL *)
|
||||||
|
Function Output/Parameters: none
|
||||||
|
Function Output/Returned: NULL
|
||||||
|
Device Input/Device: none
|
||||||
|
Device Output/Device: none
|
||||||
|
Dependencies: free, destroyProcessListHelper, ???
|
||||||
|
*/
|
||||||
|
ProcessControlBlockLL *destroyProcessList(ProcessControlBlockLL *linkedListPtr)
|
||||||
|
{
|
||||||
|
// call the first destroyProcessListHelper
|
||||||
|
destroyProcessListHelper(linkedListPtr->headPtr);
|
||||||
|
// free the rest of the struct
|
||||||
|
free(linkedListPtr);
|
||||||
|
// return null
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Name: destroyProcessListHelper
|
||||||
|
Process: recursively clears the PCB linked list struct, freeing the struct
|
||||||
|
Function Input/Parameters: head pointer to linked list (ProcessControlBlockLL *)
|
||||||
|
Function Output/Parameters: none
|
||||||
|
Function Output/Returned: NULL
|
||||||
|
Device Input/Device: none
|
||||||
|
Device Output/Device: none
|
||||||
|
Dependencies: free, destroyProcessListHelper(recursively), ???
|
||||||
|
*/
|
||||||
|
ProcessControlBlock *destroyProcessListHelper(ProcessControlBlock *nodePtr)
|
||||||
|
{
|
||||||
|
// check to see if the next pointer is NOT null
|
||||||
|
if(nodePtr->nextPtr != NULL)
|
||||||
|
{
|
||||||
|
// if not null, move to the next pointer (recurse)
|
||||||
|
nodePtr->nextPtr = destroyProcessListHelper(nodePtr->nextPtr);
|
||||||
|
}
|
||||||
|
// free the 'parent' node
|
||||||
|
free(nodePtr);
|
||||||
|
// return null
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Name: runSim
|
Name: runSim
|
||||||
|
|
|
||||||
|
|
@ -24,15 +24,28 @@ typedef struct ProcessControlBlockStruct
|
||||||
// this will be a mini loop within the master loop that goes until it
|
// this will be a mini loop within the master loop that goes until it
|
||||||
// hits the app end command.
|
// hits the app end command.
|
||||||
// it may hold the next opcode, since you don't need to traverse backward
|
// it may hold the next opcode, since you don't need to traverse backward
|
||||||
|
char *nextOpCode;
|
||||||
// have an IO cycle count here
|
// have an IO cycle count here
|
||||||
|
int ioCycles;
|
||||||
// have a CPU cycle count here
|
// have a CPU cycle count here
|
||||||
|
int cpuCycles;
|
||||||
// maybe have a total cycle count here
|
// maybe have a total cycle count here
|
||||||
|
int totalCycles;
|
||||||
// time left could be calculated from these.
|
// time left could be calculated from these.
|
||||||
// potentially could change the cycles or have a 'left' variable to
|
// potentially could change the cycles or have a 'left' variable to
|
||||||
// see how many are left.
|
// see how many are left.
|
||||||
// also need a time left state here?
|
// also need a time left state here?
|
||||||
|
double timeLeft;
|
||||||
|
// connect to the next process control block here
|
||||||
|
struct ProcessControlBlockStruct *nextPtr;
|
||||||
} ProcessControlBlock;
|
} ProcessControlBlock;
|
||||||
|
|
||||||
|
typedef struct ProcessControlBlockLLStruct
|
||||||
|
{
|
||||||
|
// holds the head ptr for PCBs
|
||||||
|
ProcessControlBlock *headPtr;
|
||||||
|
} ProcessControlBlockLL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Name: ???
|
Name: ???
|
||||||
Process: ???
|
Process: ???
|
||||||
|
|
@ -51,7 +64,7 @@ Dependencies: ???
|
||||||
/*
|
/*
|
||||||
Name: ???
|
Name: ???
|
||||||
Process: ???
|
Process: ???
|
||||||
// Function Input/Parameters: ???
|
Function Input/Parameters: ???
|
||||||
Function Output/Parameters: none
|
Function Output/Parameters: none
|
||||||
Function Output/Returned: none
|
Function Output/Returned: none
|
||||||
Device Input/Device: none
|
Device Input/Device: none
|
||||||
|
|
@ -71,7 +84,45 @@ Dependencies: ???
|
||||||
// need a function called destroyProcessList
|
// need a function called destroyProcessList
|
||||||
// deallocated the ll of PCBs recursively, frees the rest of the struct.
|
// deallocated the ll of PCBs recursively, frees the rest of the struct.
|
||||||
|
|
||||||
//
|
// have a function to change the state of the process?
|
||||||
|
// have it take in the process struct, switch it's state and report that it
|
||||||
|
// has switched FROM a state TO a different state.
|
||||||
|
|
||||||
|
/*
|
||||||
|
Name: createProcessList
|
||||||
|
Process: reads through the opcode struct to fill out the linked list of PCBs
|
||||||
|
Function Input/Parameters: metadata (OpCodeType *)
|
||||||
|
Function Output/Parameters: none
|
||||||
|
Function Output/Returned: head pointer to the PCBs
|
||||||
|
Device Input/Device: none
|
||||||
|
Device Output/Device: none
|
||||||
|
Dependencies: malloc, sizeof, ???
|
||||||
|
*/
|
||||||
|
ProcessControlBlockLL *createProcessList(OpCodeType *metadataPtr);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Name: destroyProcessList
|
||||||
|
Process: deallocates memory used for the linked list struct
|
||||||
|
Function Input/Parameters: head pointer to linked list (ProcessControlBlockLL *)
|
||||||
|
Function Output/Parameters: none
|
||||||
|
Function Output/Returned: NULL
|
||||||
|
Device Input/Device: none
|
||||||
|
Device Output/Device: none
|
||||||
|
Dependencies: free, destroyProcessListHelper, ???
|
||||||
|
*/
|
||||||
|
ProcessControlBlockLL *destroyProcessList(ProcessControlBlockLL *linkedListPtr);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Name: destroyProcessListHelper
|
||||||
|
Process: recursively clears the PCB linked list struct, freeing the struct
|
||||||
|
Function Input/Parameters: head pointer to linked list (ProcessControlBlockLL *)
|
||||||
|
Function Output/Parameters: none
|
||||||
|
Function Output/Returned: NULL
|
||||||
|
Device Input/Device: none
|
||||||
|
Device Output/Device: none
|
||||||
|
Dependencies: free, destroyProcessListHelper(recursively), ???
|
||||||
|
*/
|
||||||
|
ProcessControlBlock *destroyProcessListHelper(ProcessControlBlock *nodePtr);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Name: runSim
|
Name: runSim
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue