Almost fixed Simulator 2. Minor changes help get the output closer. File IO still don't work, but I can't do anything about that.
+- simulator.c +- sim02
This commit is contained in:
parent
60cc817296
commit
ae2e2ad885
3 changed files with 12 additions and 22 deletions
|
|
@ -1,5 +1,7 @@
|
||||||
0.000000, OS: Simulator start
|
0.000000, OS: Simulator start
|
||||||
READY state from NEW state
|
READY state from NEW state
|
||||||
ate
|
ate
|
||||||
tate
|
|
||||||
|
ate
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
BIN
Sim02/sim02
BIN
Sim02/sim02
Binary file not shown.
|
|
@ -134,7 +134,6 @@ ProcessControlBlockLL *fillProcessList(ConfigDataType *configPtr, OpCodeType *me
|
||||||
// set the working pointer to the first part of the metadata pointer
|
// set the working pointer to the first part of the metadata pointer
|
||||||
wkgMetaPtr = metadataPtr;
|
wkgMetaPtr = metadataPtr;
|
||||||
wkgInsPtr = metadataPtr;
|
wkgInsPtr = metadataPtr;
|
||||||
// currentPCB.nextOpCode = wkgMetaPtr;
|
|
||||||
// set another working pointer to the first part of the PCB list
|
// set another working pointer to the first part of the PCB list
|
||||||
wkgPCBPtr = headPointer->headPtr;
|
wkgPCBPtr = headPointer->headPtr;
|
||||||
|
|
||||||
|
|
@ -151,7 +150,6 @@ ProcessControlBlockLL *fillProcessList(ConfigDataType *configPtr, OpCodeType *me
|
||||||
{
|
{
|
||||||
currentPCB.nextOpCode = wkgInsPtr->nextNode;
|
currentPCB.nextOpCode = wkgInsPtr->nextNode;
|
||||||
integerArgumentOne = wkgMetaPtr->intArg2;
|
integerArgumentOne = wkgMetaPtr->intArg2;
|
||||||
printf("%s command, %s argument, %d\n", command, argument, integerArgumentOne);
|
|
||||||
// if app start,
|
// if app start,
|
||||||
if (compareString(command, "app") && compareString(argument, "start"))
|
if (compareString(command, "app") && compareString(argument, "start"))
|
||||||
{
|
{
|
||||||
|
|
@ -160,8 +158,6 @@ ProcessControlBlockLL *fillProcessList(ConfigDataType *configPtr, OpCodeType *me
|
||||||
currentPCB.uniquePid = processId;
|
currentPCB.uniquePid = processId;
|
||||||
// set the process state to PROCESS_STATE_NEW
|
// set the process state to PROCESS_STATE_NEW
|
||||||
currentPCB.process_state = PROCESS_STATE_NEW;
|
currentPCB.process_state = PROCESS_STATE_NEW;
|
||||||
// set the nextOpCode as a pointer to the first place metadataPtr started
|
|
||||||
// currentPCB.nextOpCode = wkgMetaPtr->nextNode; // broken?
|
|
||||||
}
|
}
|
||||||
// count number of io cycles
|
// count number of io cycles
|
||||||
if(compareString(command, "dev") == EQUIV)
|
if(compareString(command, "dev") == EQUIV)
|
||||||
|
|
@ -169,12 +165,12 @@ ProcessControlBlockLL *fillProcessList(ConfigDataType *configPtr, OpCodeType *me
|
||||||
integerArgumentOne = wkgMetaPtr->intArg2;
|
integerArgumentOne = wkgMetaPtr->intArg2;
|
||||||
if(compareString(inOutArg, "in") == EQUIV)
|
if(compareString(inOutArg, "in") == EQUIV)
|
||||||
{
|
{
|
||||||
//
|
// add up the IO cycle
|
||||||
ioCycleCount = ioCycleCount + integerArgumentOne;
|
ioCycleCount = ioCycleCount + integerArgumentOne;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//
|
// add up the IO cycle
|
||||||
ioCycleCount = ioCycleCount + integerArgumentOne;
|
ioCycleCount = ioCycleCount + integerArgumentOne;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -195,7 +191,6 @@ ProcessControlBlockLL *fillProcessList(ConfigDataType *configPtr, OpCodeType *me
|
||||||
currentPCB.totalCycles = ioCycleCount + cpuCycleCount;
|
currentPCB.totalCycles = ioCycleCount + cpuCycleCount;
|
||||||
|
|
||||||
// currentPCB must have the starting instruction from wkgInsPtr
|
// currentPCB must have the starting instruction from wkgInsPtr
|
||||||
// currentPCB.nextOpCode = wkgInsPtr->nextNode;
|
|
||||||
wkgInsPtr = wkgMetaPtr;
|
wkgInsPtr = wkgMetaPtr;
|
||||||
|
|
||||||
// set the time left from (ioCycles * ioCycleRate) + (cpuCycles * procCyclesRate)
|
// set the time left from (ioCycles * ioCycleRate) + (cpuCycles * procCyclesRate)
|
||||||
|
|
@ -358,6 +353,7 @@ void runProcess(ProcessControlBlock *singlePCB, ConfigDataType *configPtr)
|
||||||
// run over the entire process, running the CPU when a CPU cycle comes up
|
// run over the entire process, running the CPU when a CPU cycle comes up
|
||||||
// or a run IO when an IO cycle comes up
|
// or a run IO when an IO cycle comes up
|
||||||
char timeStringy[MAX_STR_LEN];
|
char timeStringy[MAX_STR_LEN];
|
||||||
|
// grab the next operation code for the
|
||||||
OpCodeType *workingMeta = singlePCB->nextOpCode;
|
OpCodeType *workingMeta = singlePCB->nextOpCode;
|
||||||
char *command;
|
char *command;
|
||||||
char *argument;
|
char *argument;
|
||||||
|
|
@ -367,30 +363,24 @@ void runProcess(ProcessControlBlock *singlePCB, ConfigDataType *configPtr)
|
||||||
argument = workingMeta->strArg1;
|
argument = workingMeta->strArg1;
|
||||||
intArg = workingMeta->intArg2;
|
intArg = workingMeta->intArg2;
|
||||||
inOutArg = workingMeta->inOutArg;
|
inOutArg = workingMeta->inOutArg;
|
||||||
printf("\n%s is the current command in this process.\n", command);
|
|
||||||
printf("\n%s is the current argument in this process.\n", argument);
|
|
||||||
while (!(compareString(command, "app") == EQUIV && compareString(argument, "end") == EQUIV) && !(compareString(command, "sys") == EQUIV && compareString(argument, "end") == EQUIV))
|
while (!(compareString(command, "app") == EQUIV && compareString(argument, "end") == EQUIV) && !(compareString(command, "sys") == EQUIV && compareString(argument, "end") == EQUIV))
|
||||||
{
|
{
|
||||||
//
|
// check to see what operation will be performed
|
||||||
if (compareString(command, "cpu") == EQUIV && compareString(argument, "process") == EQUIV)
|
if (compareString(command, "cpu") == EQUIV && compareString(argument, "process") == EQUIV)
|
||||||
{
|
{
|
||||||
//
|
// run the CPU for the required amount of time.
|
||||||
// printf("CPU RUNS\n");
|
|
||||||
runCPU(workingMeta->command, workingMeta->strArg1, workingMeta->intArg2, configPtr, singlePCB->uniquePid);
|
runCPU(workingMeta->command, workingMeta->strArg1, workingMeta->intArg2, configPtr, singlePCB->uniquePid);
|
||||||
}
|
}
|
||||||
if(compareString(command, "dev") == EQUIV)
|
if(compareString(command, "dev") == EQUIV)
|
||||||
{
|
{
|
||||||
//
|
// run IO operations for the required amount of time.
|
||||||
// printf("IO RUNS\n");
|
|
||||||
runIO(workingMeta->command, workingMeta->strArg1, workingMeta->intArg2, configPtr, singlePCB->uniquePid);
|
runIO(workingMeta->command, workingMeta->strArg1, workingMeta->intArg2, configPtr, singlePCB->uniquePid);
|
||||||
}
|
}
|
||||||
|
workingMeta = workingMeta->nextNode;
|
||||||
command = workingMeta->command;
|
command = workingMeta->command;
|
||||||
argument = workingMeta->strArg1;
|
argument = workingMeta->strArg1;
|
||||||
intArg = workingMeta->intArg2;
|
intArg = workingMeta->intArg2;
|
||||||
workingMeta = workingMeta->nextNode;
|
|
||||||
}
|
}
|
||||||
// workingMeta = workingMeta->nextNode;
|
|
||||||
// pthread_exit(NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -460,24 +450,22 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr)
|
||||||
logOutput(configPtr, simulatorOutput, false);
|
logOutput(configPtr, simulatorOutput, false);
|
||||||
pthread_t runThread;
|
pthread_t runThread;
|
||||||
pthread_create(&runThread, NULL, (void *)&simThread, (void *)processTimeLeft);
|
pthread_create(&runThread, NULL, (void *)&simThread, (void *)processTimeLeft);
|
||||||
pthread_join(runThread, NULL);
|
|
||||||
// runCPU(pcbPtr, configPtr);
|
|
||||||
runProcess(pcbPtr, configPtr);
|
runProcess(pcbPtr, configPtr);
|
||||||
// when finished, set to terminated
|
// when finished, set to terminated
|
||||||
sprintf(simulatorOutput, "%f, OS: Process %d set to TERMINATED state from RUNNING state\n\n", accessTimer(LAP_TIMER, timeStringy), pcbPtr->uniquePid);
|
sprintf(simulatorOutput, "%f, OS: Process %d set to TERMINATED state from RUNNING state\n\n", accessTimer(LAP_TIMER, timeStringy), pcbPtr->uniquePid);
|
||||||
logOutput(configPtr, simulatorOutput, false);
|
logOutput(configPtr, simulatorOutput, false);
|
||||||
pcbPtr->process_state = PROCESS_STATE_TERMINATED;
|
pcbPtr->process_state = PROCESS_STATE_TERMINATED;
|
||||||
|
pthread_join(runThread, NULL);
|
||||||
}
|
}
|
||||||
processTimeLeft = pcbPtr->timeLeft;
|
processTimeLeft = pcbPtr->timeLeft;
|
||||||
pcbPtr = pcbPtr->nextPtr;
|
pcbPtr = pcbPtr->nextPtr;
|
||||||
currentPid = scheduleProcess(pcbList, configPtr);
|
currentPid = scheduleProcess(pcbList, configPtr);
|
||||||
}
|
}
|
||||||
|
pthread_join(cpuThread, NULL);
|
||||||
sprintf(simulatorOutput, "%f, OS: System Stop\n", accessTimer(LAP_TIMER, timeStringy));
|
sprintf(simulatorOutput, "%f, OS: System Stop\n", accessTimer(LAP_TIMER, timeStringy));
|
||||||
logOutput(configPtr, simulatorOutput, false);
|
logOutput(configPtr, simulatorOutput, false);
|
||||||
sprintf(simulatorOutput, "%f, OS: Simulation End\n", accessTimer(LAP_TIMER, timeStringy));
|
sprintf(simulatorOutput, "%f, OS: Simulation End\n", accessTimer(LAP_TIMER, timeStringy));
|
||||||
logOutput(configPtr, simulatorOutput, true);
|
logOutput(configPtr, simulatorOutput, true);
|
||||||
pthread_join(cpuThread, NULL);
|
|
||||||
// deallocate the process list with destroyProcessList
|
// deallocate the process list with destroyProcessList
|
||||||
destroyProcessList(pcbList);
|
destroyProcessList(pcbList);
|
||||||
// once complete, log the output to FILE if required
|
// once complete, log the output to FILE if required
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue