diff --git a/Sim02/logfile_1.lgf b/Sim02/logfile_1.lgf index ba01ba2..52b0e91 100644 --- a/Sim02/logfile_1.lgf +++ b/Sim02/logfile_1.lgf @@ -1,5 +1,7 @@ 0.000000, OS: Simulator start READY state from NEW state ate -tate + +ate + diff --git a/Sim02/sim02 b/Sim02/sim02 index 13fb927..a59a9ea 100755 Binary files a/Sim02/sim02 and b/Sim02/sim02 differ diff --git a/Sim02/simulator.c b/Sim02/simulator.c index 3e87544..ea7e6e0 100644 --- a/Sim02/simulator.c +++ b/Sim02/simulator.c @@ -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