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:
Charles Descamps 2024-03-13 13:42:21 -07:00
parent 60cc817296
commit ae2e2ad885
3 changed files with 12 additions and 22 deletions

View file

@ -1,5 +1,7 @@
0.000000, OS: Simulator start
READY state from NEW state
ate
tate
ate

Binary file not shown.

View file

@ -134,7 +134,6 @@ ProcessControlBlockLL *fillProcessList(ConfigDataType *configPtr, OpCodeType *me
// set the working pointer to the first part of the metadata pointer
wkgMetaPtr = metadataPtr;
wkgInsPtr = metadataPtr;
// currentPCB.nextOpCode = wkgMetaPtr;
// set another working pointer to the first part of the PCB list
wkgPCBPtr = headPointer->headPtr;
@ -151,7 +150,6 @@ ProcessControlBlockLL *fillProcessList(ConfigDataType *configPtr, OpCodeType *me
{
currentPCB.nextOpCode = wkgInsPtr->nextNode;
integerArgumentOne = wkgMetaPtr->intArg2;
printf("%s command, %s argument, %d\n", command, argument, integerArgumentOne);
// if app start,
if (compareString(command, "app") && compareString(argument, "start"))
{
@ -160,8 +158,6 @@ ProcessControlBlockLL *fillProcessList(ConfigDataType *configPtr, OpCodeType *me
currentPCB.uniquePid = processId;
// 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->nextNode; // broken?
}
// count number of io cycles
if(compareString(command, "dev") == EQUIV)
@ -169,12 +165,12 @@ ProcessControlBlockLL *fillProcessList(ConfigDataType *configPtr, OpCodeType *me
integerArgumentOne = wkgMetaPtr->intArg2;
if(compareString(inOutArg, "in") == EQUIV)
{
//
// add up the IO cycle
ioCycleCount = ioCycleCount + integerArgumentOne;
}
else
{
//
// add up the IO cycle
ioCycleCount = ioCycleCount + integerArgumentOne;
}
}
@ -195,7 +191,6 @@ ProcessControlBlockLL *fillProcessList(ConfigDataType *configPtr, OpCodeType *me
currentPCB.totalCycles = ioCycleCount + cpuCycleCount;
// currentPCB must have the starting instruction from wkgInsPtr
// currentPCB.nextOpCode = wkgInsPtr->nextNode;
wkgInsPtr = wkgMetaPtr;
// 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
// or a run IO when an IO cycle comes up
char timeStringy[MAX_STR_LEN];
// grab the next operation code for the
OpCodeType *workingMeta = singlePCB->nextOpCode;
char *command;
char *argument;
@ -367,30 +363,24 @@ void runProcess(ProcessControlBlock *singlePCB, ConfigDataType *configPtr)
argument = workingMeta->strArg1;
intArg = workingMeta->intArg2;
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))
{
//
// check to see what operation will be performed
if (compareString(command, "cpu") == EQUIV && compareString(argument, "process") == EQUIV)
{
//
// printf("CPU RUNS\n");
// run the CPU for the required amount of time.
runCPU(workingMeta->command, workingMeta->strArg1, workingMeta->intArg2, configPtr, singlePCB->uniquePid);
}
if(compareString(command, "dev") == EQUIV)
{
//
// printf("IO RUNS\n");
// run IO operations for the required amount of time.
runIO(workingMeta->command, workingMeta->strArg1, workingMeta->intArg2, configPtr, singlePCB->uniquePid);
}
workingMeta = workingMeta->nextNode;
command = workingMeta->command;
argument = workingMeta->strArg1;
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);
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\n", accessTimer(LAP_TIMER, timeStringy), pcbPtr->uniquePid);
logOutput(configPtr, simulatorOutput, false);
pcbPtr->process_state = PROCESS_STATE_TERMINATED;
pthread_join(runThread, NULL);
}
processTimeLeft = pcbPtr->timeLeft;
pcbPtr = pcbPtr->nextPtr;
currentPid = scheduleProcess(pcbList, configPtr);
}
pthread_join(cpuThread, NULL);
sprintf(simulatorOutput, "%f, OS: System Stop\n", accessTimer(LAP_TIMER, timeStringy));
logOutput(configPtr, simulatorOutput, false);
sprintf(simulatorOutput, "%f, OS: Simulation End\n", accessTimer(LAP_TIMER, timeStringy));
logOutput(configPtr, simulatorOutput, true);
pthread_join(cpuThread, NULL);
// deallocate the process list with destroyProcessList
destroyProcessList(pcbList);
// once complete, log the output to FILE if required