diff --git a/Sim02/simulator.c b/Sim02/simulator.c index f0ad96d..db9281f 100644 --- a/Sim02/simulator.c +++ b/Sim02/simulator.c @@ -159,7 +159,18 @@ ProcessControlBlockLL *fillProcessList(ConfigDataType *configPtr, OpCodeType *me // set the nextOpCode as a pointer to the first place metadataPtr started currentPCB.nextOpCode = wkgMetaPtr->nextNode; } + // // count number of io cycles + // if ((compareString(command, "dev") == 0 && compareString(inOutArg, "in") == 0)) + // { + // integerArgumentOne = wkgMetaPtr->intArg2; + // ioCycleCount = ioCycleCount + integerArgumentOne; + // } + // if ((compareString(command, "dev") == 0 && compareString(inOutArg, "out") == 0)) + // { + // integerArgumentOne = wkgMetaPtr->intArg2; + // ioCycleCount = ioCycleCount + integerArgumentOne; + // } if(compareString(command, "dev") == 0) { integerArgumentOne = wkgMetaPtr->intArg2; @@ -203,14 +214,17 @@ ProcessControlBlockLL *fillProcessList(ConfigDataType *configPtr, OpCodeType *me // do both the metadata and PCBs if(headPointer->headPtr == NULL) { + // headPointer->headPtr = addProcess(currentPCB); wkgPCBPtr = headPointer->headPtr; } else { + // wkgPCBPtr->nextPtr = addProcess(currentPCB); wkgPCBPtr = wkgPCBPtr->nextPtr; } + } // move to the next bit of data wkgMetaPtr = wkgMetaPtr->nextNode; @@ -244,13 +258,16 @@ void logOutput(ConfigDataType *configPtr, char *logStr, bool isEnd) fileWritePtr = fopen(configPtr->logToFileName, "w"); if (fileWritePtr != NULL) { + // fprintf(fileWritePtr, "%s", logStr); + // fputs(fileWritePtr, logStr); fprintf(stdout, "%s", logStr); } // no return, void // close the file, if at the end. if (isEnd) { + // fclose(fileWritePtr); } // fclose(fileWritePtr); @@ -263,18 +280,22 @@ void logOutput(ConfigDataType *configPtr, char *logStr, bool isEnd) fileWritePtr = fopen(configPtr->logToFileName, "w"); if (fileWritePtr != NULL) { + // fprintf(fileWritePtr, "%s", logStr); + // fputs(fileWritePtr, logStr); } // no return, void // close the file, if at the end. if (isEnd) { + // fclose(fileWritePtr); } // fclose(fileWritePtr); } else { + // fprintf(stdout, "%s", logStr); } } @@ -297,6 +318,14 @@ void runCPU(char *command, char *argument, int intArg, ConfigDataType *configPtr // 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); @@ -304,6 +333,7 @@ void runCPU(char *command, char *argument, int intArg, ConfigDataType *configPtr 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); @@ -322,14 +352,19 @@ Dependencies: ??? 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); } @@ -358,7 +393,7 @@ void runProcess(ProcessControlBlock *singlePCB, ConfigDataType *configPtr) argument = workingMeta->strArg1; intArg = workingMeta->intArg2; inOutArg = workingMeta->inOutArg; - while (!(compareString(command, "app") == 0 && compareString(argument, "end") == 0)) + 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) @@ -423,6 +458,7 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr) int totalPCBTime = 0; while(pcbPtr != NULL) { + // totalPCBTime = totalPCBTime + pcbPtr->timeLeft; pcbPtr = pcbPtr->nextPtr; } @@ -440,8 +476,11 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr) // loop until current process is hit while(pcbPtr != NULL) { + // if(pcbPtr->uniquePid == currentPid) { + // + // 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); @@ -461,6 +500,8 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr) pcbPtr = pcbPtr->nextPtr; currentPid = scheduleProcess(pcbList, configPtr); } + + // // deallocate the process list with destroyProcessList destroyProcessList(pcbList); // once complete, log the output to FILE if required @@ -558,6 +599,22 @@ Dependencies: ??? */ void *simThread(int milSec) { + // + // int *milSecPtr = (int *)milSec; + // printf("Running Timer for %d ms, %d sec\n", milSec, milSec / 1000); runTimer(milSec); + // printf("Ran Timer\n"); pthread_exit(NULL); -} \ No newline at end of file +} +/* +Current Note to programmer: do the scheduler, the runIO and runCPU functions, and then the FILE IO functions +this is all that is left so far, hopefully not too bad. +*/ + +// getNextProcess/scheduler/dispatcher run here, loads/"runs" the process +// getNextOpCode, not needed for Sim02 apparently, keep in mind. +// checkForIO, I think this gets passed the current process and runs the IO ops +// checkForCPU, I think this gets passed the current process and runs the CPU ops +// checkForMemory, I think this gets passed the current process +// and runs mem ops (not needed for Sim02) +// cpuIdler (not needed for Sim02) \ No newline at end of file diff --git a/Sim02/simulator.h b/Sim02/simulator.h index 02be3a6..167145b 100644 --- a/Sim02/simulator.h +++ b/Sim02/simulator.h @@ -56,6 +56,10 @@ Device Input/Device: none Device Output/Device: none Dependencies: ??? */ +// need a function (or functions) to handle FILE I/O? +// runSim function will have a FILE * + // will have a function that gets the FILE * and + // adds whatever operation occurred /* Name: ??? @@ -67,19 +71,28 @@ Device Input/Device: none Device Output/Device: none Dependencies: ??? */ +// need a function for the global/local timer (given??? may need to just import) -/* -Name: addProcess -Process: allocates the memory for the pcb, grabs the data from the created PCB, - dumps the data so that the node can be linked correctly. -Function Input/Parameters: source PCB (ProcessControlBlock) -Function Output/Parameters: none -Function Output/Returned: filled PCB (ProcessControlBlock *) -Device Input/Device: none -Device Output/Device: none -Dependencies: malloc, sizeof, ??? -*/ -ProcessControlBlock *addProcess(const ProcessControlBlock source); +// need a function for scheduler/dispatcher + // this could use a switch statement to tell which scheduling method to choose from. + // Sim02 only requires FCFS working atm. + +// need a function called createProcessList +// this initializes the process control block ll. + +// need a function called fillProcessList +// this fills the linked list of PCBs, +// loads the first instruction after app start +// and ... + +// reads through the opcode struct to fill out the linked list of PCBs + +// need a function called destroyProcessList +// 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 @@ -154,7 +167,7 @@ Device Input/Device: none Device Output/Device: none Dependencies: ??? */ -void runCPU(char *command, char *argument, int intArg, ConfigDataType *configPtr, int processId); +void runCPU(); /* Name: runIO @@ -166,7 +179,8 @@ Device Input/Device: none Device Output/Device: none Dependencies: ??? */ -void runIO(char *command, char *argument, int intArg, ConfigDataType *configPtr, int processId); +void runIO(); + /* Name: runSim Process: primary simulation driver