"Finished" Sim02
+- simulator.c/h
This commit is contained in:
parent
79db35ade5
commit
b306a179d8
3 changed files with 107 additions and 14 deletions
|
|
@ -157,7 +157,7 @@ ProcessControlBlockLL *fillProcessList(ConfigDataType *configPtr, OpCodeType *me
|
|||
// set the process state to PROCESS_STATE_NEW
|
||||
currentPCB.process_state = PROCESS_STATE_NEW;
|
||||
// set the nextOpCode as a pointer to the first place metadataPtr started
|
||||
currentPCB.nextOpCode = wkgMetaPtr;
|
||||
currentPCB.nextOpCode = wkgMetaPtr->nextNode;
|
||||
}
|
||||
//
|
||||
// count number of io cycles
|
||||
|
|
@ -310,7 +310,34 @@ Device Input/Device: none
|
|||
Device Output/Device: none
|
||||
Dependencies: ???
|
||||
*/
|
||||
void runCPU();
|
||||
void runCPU(char *command, char *argument, int intArg, ConfigDataType *configPtr, int processId)
|
||||
{
|
||||
char timeStringy[MAX_STR_LEN];
|
||||
// char *command = workingMeta->command;
|
||||
// char *argument = workingMeta->strArg1;
|
||||
// int intArg = workingMeta->intArg2;
|
||||
char cpuOutput[MAX_STR_LEN];
|
||||
int cpuTime = 0;
|
||||
// pthread_t cpuThread;
|
||||
// pthread_create(&cpuThread, NULL, (void *)&simThread, (void *)cpuTime);
|
||||
// pthread_join(cpuThread, NULL);
|
||||
//
|
||||
// printf("%f is the time for runCPU\n", accessTimer(LAP_TIMER, timeStringy));
|
||||
//
|
||||
//
|
||||
//
|
||||
cpuTime = intArg * configPtr->procCycleRate;
|
||||
sprintf(cpuOutput, "%f, Process: %d, %s %s operation start\n", accessTimer(LAP_TIMER, timeStringy), processId, command, argument);
|
||||
logOutput(configPtr, cpuOutput, false);
|
||||
// run timer for intArg * procCycleRate
|
||||
pthread_t cpuThread;
|
||||
pthread_create(&cpuThread, NULL, (void *)&simThread, (void *)cpuTime);
|
||||
pthread_join(cpuThread, NULL);
|
||||
//
|
||||
sprintf(cpuOutput, "%f, Process: %d, %s %s operation end\n", accessTimer(LAP_TIMER, timeStringy), processId, command, argument);
|
||||
logOutput(configPtr, cpuOutput, false);
|
||||
// pthread_exit(NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
Name: runIO
|
||||
|
|
@ -322,7 +349,25 @@ Device Input/Device: none
|
|||
Device Output/Device: none
|
||||
Dependencies: ???
|
||||
*/
|
||||
void runIO();
|
||||
void runIO(char *command, char *argument, int intArg, ConfigDataType *configPtr, int processId)
|
||||
{
|
||||
char timeStringy[MAX_STR_LEN];
|
||||
// char *command = workingMeta->command;
|
||||
// char *argument = workingMeta->strArg1;
|
||||
// int intArg = workingMeta->intArg2;
|
||||
char ioOutput[MAX_STR_LEN];
|
||||
int ioTime = 0;
|
||||
ioTime = intArg * configPtr->ioCycleRate;
|
||||
sprintf(ioOutput, "%f, Process: %d, %s %s operation start\n", accessTimer(LAP_TIMER, timeStringy), processId, command, argument);
|
||||
logOutput(configPtr, ioOutput, false);
|
||||
// run timer for intArg * procCycleRate
|
||||
pthread_t ioThread;
|
||||
pthread_create(&ioThread, NULL, (void *)&simThread, (void *)ioTime);
|
||||
pthread_join(ioThread, NULL);
|
||||
//
|
||||
sprintf(ioOutput, "%f, Process: %d, %s %s operation end\n", accessTimer(LAP_TIMER, timeStringy), processId, command, argument);
|
||||
logOutput(configPtr, ioOutput, false);
|
||||
}
|
||||
|
||||
/*
|
||||
Name: runProcess
|
||||
|
|
@ -334,7 +379,41 @@ Device Input/Device: none
|
|||
Device Output/Device: none
|
||||
Dependencies: ???
|
||||
*/
|
||||
void runProcess();
|
||||
void runProcess(ProcessControlBlock *singlePCB, ConfigDataType *configPtr)
|
||||
{
|
||||
// run over the entire process, running the CPU when a CPU cycle comes up
|
||||
// or a run IO when an IO cycle comes up
|
||||
char timeStringy[MAX_STR_LEN];
|
||||
OpCodeType *workingMeta = singlePCB->nextOpCode;
|
||||
char *command;
|
||||
char *argument;
|
||||
int intArg;
|
||||
char *inOutArg;
|
||||
command = workingMeta->command;
|
||||
argument = workingMeta->strArg1;
|
||||
intArg = workingMeta->intArg2;
|
||||
inOutArg = workingMeta->inOutArg;
|
||||
while (!(compareString(command, "app") == 0 && compareString(argument, "end") == 0)) // compareString(command, "cpu") == 0 && compareString(argument, "process") == 0
|
||||
{
|
||||
//
|
||||
if (compareString(command, "cpu") == 0 && compareString(argument, "process") == 0)
|
||||
{
|
||||
//
|
||||
runCPU(workingMeta->command, workingMeta->strArg1, workingMeta->intArg2, configPtr, singlePCB->uniquePid);
|
||||
}
|
||||
if(compareString(command, "dev") == 0)
|
||||
{
|
||||
//
|
||||
runIO(workingMeta->command, workingMeta->strArg1, workingMeta->intArg2, configPtr, singlePCB->uniquePid);
|
||||
}
|
||||
command = workingMeta->command;
|
||||
argument = workingMeta->strArg1;
|
||||
intArg = workingMeta->intArg2;
|
||||
workingMeta = workingMeta->nextNode;
|
||||
}
|
||||
// workingMeta = workingMeta->nextNode;
|
||||
// pthread_exit(NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
Name: runSim
|
||||
|
|
@ -360,10 +439,11 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr)
|
|||
// char *nextCode;
|
||||
// string variable for the timer stuff
|
||||
char simulatorOutput[MAX_STR_LEN];
|
||||
char timeStringy[MAX_STR_LEN];
|
||||
|
||||
// accessTimer(ZERO_TIMER, NULL);
|
||||
accessTimer(ZERO_TIMER, timeStringy);
|
||||
// Operating System start timer goes here, log it.
|
||||
sprintf(simulatorOutput, "%f, OS: Simulator start\n", accessTimer(LAP_TIMER, NULL));
|
||||
sprintf(simulatorOutput, "%f, OS: Simulator start\n", accessTimer(LAP_TIMER, timeStringy));
|
||||
logOutput(configPtr, simulatorOutput, false);
|
||||
|
||||
// int variable for process to run
|
||||
|
|
@ -373,11 +453,6 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr)
|
|||
// fill the process list given the metadata
|
||||
pcbList = fillProcessList(configPtr, metaDataMstrPtr, pcbList);
|
||||
pcbPtr = pcbList->headPtr;
|
||||
// create temp strings
|
||||
char *command;
|
||||
char *argument;
|
||||
// int iterator
|
||||
int pcbIterator;
|
||||
|
||||
// calculate pcb total time
|
||||
int totalPCBTime = 0;
|
||||
|
|
@ -392,7 +467,9 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr)
|
|||
pthread_t cpuThread;
|
||||
pthread_create(&cpuThread, NULL, (void *)&simThread, (void *)totalPCBTime);
|
||||
pthread_join(cpuThread, NULL);
|
||||
|
||||
|
||||
//
|
||||
int processTimeLeft = pcbPtr->timeLeft;
|
||||
|
||||
// set the current process id to the first scheduled process
|
||||
currentPid = scheduleProcess(pcbList, configPtr);
|
||||
|
|
@ -405,10 +482,21 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr)
|
|||
//
|
||||
// printf("Process %d running\n", currentPid);
|
||||
// needs to set from READY to RUNNING
|
||||
pcbPtr->process_state = PROCESS_STATE_READY;
|
||||
sprintf(simulatorOutput, "%f, OS: Process %d set to RUNNING state from READY state\n", accessTimer(LAP_TIMER, timeStringy), pcbPtr->uniquePid);
|
||||
logOutput(configPtr, simulatorOutput, false);
|
||||
pthread_t runThread;
|
||||
pthread_create(&runThread, NULL, (void *)&simThread, (void *)processTimeLeft);
|
||||
pthread_join(runThread, NULL);
|
||||
// runCPU(pcbPtr, configPtr);
|
||||
runProcess(pcbPtr, configPtr);
|
||||
// when finished, set to terminated
|
||||
sprintf(simulatorOutput, "%f, OS: Process %d set to TERMINATED state from RUNNING state\n", accessTimer(LAP_TIMER, timeStringy), pcbPtr->uniquePid);
|
||||
logOutput(configPtr, simulatorOutput, false);
|
||||
pcbPtr->process_state = PROCESS_STATE_TERMINATED;
|
||||
|
||||
}
|
||||
processTimeLeft = pcbPtr->timeLeft;
|
||||
pcbPtr = pcbPtr->nextPtr;
|
||||
currentPid = scheduleProcess(pcbList, configPtr);
|
||||
}
|
||||
|
|
@ -439,6 +527,7 @@ int scheduleProcess(ProcessControlBlockLL *headPointer, ConfigDataType *configPt
|
|||
int returnPid = -1;
|
||||
wkgPtr = headPointer->headPtr;
|
||||
char loggingStr[MAX_STR_LEN];
|
||||
char timeStringy[MAX_STR_LEN];
|
||||
// switch case for each scheduling algorithm
|
||||
switch (configPtr->cpuSchedCode)
|
||||
{
|
||||
|
|
@ -458,7 +547,7 @@ int scheduleProcess(ProcessControlBlockLL *headPointer, ConfigDataType *configPt
|
|||
//
|
||||
wkgPtr->process_state = PROCESS_STATE_READY;
|
||||
// printf("Process %d set to READY from NEW\n", wkgPtr->uniquePid);
|
||||
sprintf(loggingStr, "%f, OS: Process %d set to READY state from NEW state\n", accessTimer(LAP_TIMER, NULL), wkgPtr->uniquePid);
|
||||
sprintf(loggingStr, "%f, OS: Process %d set to READY state from NEW state\n", accessTimer(LAP_TIMER, timeStringy), wkgPtr->uniquePid);
|
||||
logOutput(configPtr, loggingStr, false);
|
||||
}
|
||||
|
||||
|
|
@ -473,7 +562,7 @@ int scheduleProcess(ProcessControlBlockLL *headPointer, ConfigDataType *configPt
|
|||
if (wkgPtr->process_state == PROCESS_STATE_READY)
|
||||
{
|
||||
//printf("Process %d Selected with %.0f ms remaining\n", wkgPtr->uniquePid, wkgPtr->timeLeft);
|
||||
sprintf(loggingStr, "%f, OS: Process %d selected with %.0f ms remaining\n", accessTimer(LAP_TIMER, NULL), wkgPtr->uniquePid, wkgPtr->timeLeft);
|
||||
sprintf(loggingStr, "%f, OS: Process %d selected with %.0f ms remaining\n", accessTimer(LAP_TIMER, timeStringy), wkgPtr->uniquePid, wkgPtr->timeLeft);
|
||||
logOutput(configPtr, loggingStr, false);
|
||||
returnPid = wkgPtr->uniquePid;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue