diff --git a/Sim03/logfile_1.lgf b/Sim03/logfile_1.lgf index fea283a..c3d5bca 100644 --- a/Sim03/logfile_1.lgf +++ b/Sim03/logfile_1.lgf @@ -1 +1 @@ -0.000001, OS: Simulator start +0.000988, OS: Simulator start diff --git a/Sim03/sim03 b/Sim03/sim03 index 9e0361f..5bbd904 100755 Binary files a/Sim03/sim03 and b/Sim03/sim03 differ diff --git a/Sim04/logfile_1.lgf b/Sim04/logfile_1.lgf index e69de29..52b0e91 100644 --- a/Sim04/logfile_1.lgf +++ b/Sim04/logfile_1.lgf @@ -0,0 +1,7 @@ +0.000000, OS: Simulator start + READY state from NEW state +ate + +ate + + diff --git a/Sim04/sim03 b/Sim04/sim03 deleted file mode 100755 index 8d57268..0000000 Binary files a/Sim04/sim03 and /dev/null differ diff --git a/Sim04/sim04 b/Sim04/sim04 new file mode 100755 index 0000000..0b1c3b8 Binary files /dev/null and b/Sim04/sim04 differ diff --git a/Sim04/sim03_mf b/Sim04/sim04_mf similarity index 90% rename from Sim04/sim03_mf rename to Sim04/sim04_mf index d6d51fb..ce4d173 100644 --- a/Sim04/sim03_mf +++ b/Sim04/sim04_mf @@ -5,7 +5,7 @@ OBJECTS = OS_SimDriver.o simulator.o metadataops.o configops.o StringUtils.o sim all: Simulator Simulator: $(OBJECTS) - $(CC) $(OBJECTS) -o sim03 + $(CC) $(OBJECTS) -lpthread -o sim04 StringUtils.o: StringUtils.c $(CC) -c StringUtils.c -o StringUtils.o @@ -26,7 +26,7 @@ simtimer.o: simtimer.c $(CC) -c simtimer.c -o simtimer.o clean: - rm -f $(OBJECTS) sim03 sim03.out + rm -f $(OBJECTS) sim04 sim04.out clean_objects: rm -f $(OBJECTS) diff --git a/Sim04/simulator.c b/Sim04/simulator.c index db2ba8f..ba5a2d8 100644 --- a/Sim04/simulator.c +++ b/Sim04/simulator.c @@ -71,7 +71,7 @@ bool allocMemory(ProcessControlBlock *singlePCB, int offset, int size, int array singlePCB->allocatedMemOffsets[allocateIterator] = offset; singlePCB->allocatedMemSizes[allocateIterator] = size; allocateIterator = allocateIterator + 1; - printf("Alloc Iter: %d\n", allocateIterator); + // printf("Alloc Iter: %d\n", allocateIterator); } // return true (temp) return true; @@ -331,6 +331,21 @@ int findMin(int one, int another) return minimumVal; } +/* +Name: interruptManager +Process: does the managing of interrupts for the program +Function Input/Parameters: ??? +Function Output/Parameters: none +Function Output/Returned: ??? +Device Input/Device: none +Device Output/Device: none +Dependencies: none +*/ +void interruptManager() +{ + // +} + /* Name: logOutput Process: Takes in a string, and then outputs it to monitor AND/OR file @@ -400,7 +415,8 @@ Device Input/Device: none Device Output/Device: none Dependencies: ??? */ -bool memManager(ProcessControlBlockLL *pcbList, MEMORY_SIGNALS memCode, int offset, int size, ConfigDataType *configPtr, ProcessControlBlock *singlePCB) +bool memManager(ProcessControlBlockLL *pcbList, MEMORY_SIGNALS memCode, int offset, int size, ConfigDataType *configPtr, + ProcessControlBlock *singlePCB) { bool memDisplay = configPtr->memDisplay; ProcessControlBlock *wkgPtr; @@ -497,7 +513,8 @@ bool memManager(ProcessControlBlockLL *pcbList, MEMORY_SIGNALS memCode, int offs // printf("--------------------------------------------------\n"); printf("After memory allocation\n"); - printf("%d [ Used, P#: %d, %d-%d ] %d\n", offset - offset, singlePCB->uniquePid, offset, offset + size - 1, size - 1); + printf("%d [ Used, P#: %d, %d-%d ] %d\n", offset - offset, singlePCB->uniquePid, offset, + offset + size - 1, size - 1); printf("%d [ Open, P#: x, %d-%d ] %d\n", usedMem, currentOffset, currentSize, availableMem - 1); printf("--------------------------------------------------\n"); } @@ -522,7 +539,8 @@ bool memManager(ProcessControlBlockLL *pcbList, MEMORY_SIGNALS memCode, int offs // printf("--------------------------------------------------\n"); printf("After access success\n"); - printf("%d [ Used, P#: %d, %d-%d ] %d\n", offset - offset, singlePCB->uniquePid, offset, offset + size - 1, size - 1); + printf("%d [ Used, P#: %d, %d-%d ] %d\n", offset - offset, singlePCB->uniquePid, offset, + offset + size - 1, size - 1); printf("%d [ Open, P#: x, %d-%d ] %d\n", usedMem, currentOffset, currentSize, availableMem - 1); printf("--------------------------------------------------\n"); } @@ -531,7 +549,8 @@ bool memManager(ProcessControlBlockLL *pcbList, MEMORY_SIGNALS memCode, int offs // printf("--------------------------------------------------\n"); printf("After access failure\n"); - printf("%d [ Used, P#: %d, %d-%d ] %d\n", offset - offset, singlePCB->uniquePid, offset, offset + size - 1, size - 1); + printf("%d [ Used, P#: %d, %d-%d ] %d\n", offset - offset, singlePCB->uniquePid, offset, + offset + size - 1, size - 1); printf("%d [ Open, P#: x, %d-%d ] %d\n", usedMem, currentOffset, currentSize, availableMem - 1); printf("--------------------------------------------------\n"); } @@ -593,6 +612,7 @@ Dependencies: pthreads, sprintf, logOutput, ??? */ void runCPU(char *command, char *argument, int intArg, ConfigDataType *configPtr, int processId) { + double timeDigits; char timeStringy[MAX_STR_LEN]; // char *command = workingMeta->command; // char *argument = workingMeta->strArg1; @@ -601,13 +621,15 @@ void runCPU(char *command, char *argument, int intArg, ConfigDataType *configPtr int cpuTime = 0; int *cpuTimePtr = &cpuTime; cpuTime = intArg * configPtr->procCycleRate; - sprintf(cpuOutput, "%f, Process: %d, %s %s operation start\n", accessTimer(LAP_TIMER, timeStringy), processId, command, argument); + timeDigits = accessTimer(LAP_TIMER, timeStringy); + sprintf(cpuOutput, "%f, Process: %d, %s %s operation start\n", timeDigits, processId, command, argument); logOutput(configPtr, cpuOutput, false); // run timer for intArg * procCycleRate pthread_t cpuThread; pthread_create(&cpuThread, NULL, runTimer, (void *)cpuTimePtr); pthread_join(cpuThread, NULL); - sprintf(cpuOutput, "%f, Process: %d, %s %s operation end\n", accessTimer(LAP_TIMER, timeStringy), processId, command, argument); + timeDigits = accessTimer(LAP_TIMER, timeStringy); + sprintf(cpuOutput, "%f, Process: %d, %s %s operation end\n", timeDigits, processId, command, argument); logOutput(configPtr, cpuOutput, false); // pthread_exit(NULL); } @@ -624,17 +646,20 @@ Dependencies: pthreads, sprintf, logOutput, ??? */ void runIO(char *command, char *argument, int intArg, ConfigDataType *configPtr, int processId) { + double timeDigits; char timeStringy[MAX_STR_LEN]; char ioOutput[MAX_STR_LEN]; int ioTime = 0; int *ioTimePtr = &ioTime; ioTime = intArg * configPtr->ioCycleRate; - sprintf(ioOutput, "%f, Process: %d, %s %s operation start\n", accessTimer(LAP_TIMER, timeStringy), processId, command, argument); + timeDigits = accessTimer(LAP_TIMER, timeStringy); + sprintf(ioOutput, "%f, Process: %d, %s %s operation start\n", timeDigits, processId, command, argument); logOutput(configPtr, ioOutput, false); pthread_t ioThread; pthread_create(&ioThread, NULL, runTimer, (void *)ioTimePtr); pthread_join(ioThread, NULL); - sprintf(ioOutput, "%f, Process: %d, %s %s operation end\n", accessTimer(LAP_TIMER, timeStringy), processId, command, argument); + timeDigits = accessTimer(LAP_TIMER, timeStringy); + sprintf(ioOutput, "%f, Process: %d, %s %s operation end\n", timeDigits, processId, command, argument); logOutput(configPtr, ioOutput, false); } @@ -650,6 +675,7 @@ Dependencies: accessTimer, compareString, runCPU, runIO, ??? */ void runProcess(ProcessControlBlock *singlePCB, ConfigDataType *configPtr, ProcessControlBlockLL *pcbList) { + double timeDigits; // 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]; @@ -667,7 +693,9 @@ void runProcess(ProcessControlBlock *singlePCB, ConfigDataType *configPtr, Proce intArg = workingMeta->intArg2; intArgTwo = workingMeta->intArg3; // inOutArg = workingMeta->inOutArg; - while (!(compareString(command, "app") == EQUIV && compareString(argument, "end") == EQUIV) && !(compareString(command, "sys") == EQUIV && compareString(argument, "end") == EQUIV) && memManagerSuccess) + while (!(compareString(command, "app") == EQUIV && compareString(argument, "end") == EQUIV) && + !(compareString(command, "sys") == EQUIV && compareString(argument, "end") == EQUIV) && + memManagerSuccess) { // check to see what operation will be performed if (compareString(command, "cpu") == EQUIV && compareString(argument, "process") == EQUIV) @@ -685,27 +713,35 @@ void runProcess(ProcessControlBlock *singlePCB, ConfigDataType *configPtr, Proce // run memory operations with the memory manager if(compareString(argument, "allocate") == EQUIV) { - sprintf(processOutput, "%f, Process: %d, %s %s request (%d, %d)\n", accessTimer(LAP_TIMER, timeStringy), singlePCB->uniquePid, command, argument, intArg, intArgTwo); + timeDigits = accessTimer(LAP_TIMER, timeStringy); + sprintf(processOutput, "%f, Process: %d, %s %s request (%d, %d)\n", timeDigits, + singlePCB->uniquePid, command, argument, intArg, intArgTwo); logOutput(configPtr, processOutput, false); // run the memory manager in allocate mode memManagerSuccess = memManager(pcbList, MEMORY_ALLOCATE, intArg, intArgTwo, configPtr, singlePCB); if(!memManagerSuccess) { // - sprintf(processOutput, "%f, Process: %d, failed %s %s request (%d, %d)\n", accessTimer(LAP_TIMER, timeStringy), singlePCB->uniquePid, command, argument, intArg, intArgTwo); + timeDigits = accessTimer(LAP_TIMER, timeStringy); + sprintf(processOutput, "%f, Process: %d, failed %s %s request (%d, %d)\n", timeDigits, + singlePCB->uniquePid, command, argument, intArg, intArgTwo); logOutput(configPtr, processOutput, false); } } else if(compareString(argument, "access") == EQUIV) { - sprintf(processOutput, "%f, Process: %d, %s %s request (%d, %d)\n", accessTimer(LAP_TIMER, timeStringy), singlePCB->uniquePid, command, argument, intArg, intArgTwo); + timeDigits = accessTimer(LAP_TIMER, timeStringy); + sprintf(processOutput, "%f, Process: %d, %s %s request (%d, %d)\n", timeDigits, + singlePCB->uniquePid, command, argument, intArg, intArgTwo); logOutput(configPtr, processOutput, false); // run the memory manager in access mode memManagerSuccess = memManager(pcbList, MEMORY_ACCESS, intArg, intArgTwo, configPtr, singlePCB); if (!memManagerSuccess) { // - sprintf(processOutput, "%f, Process: %d, failed %s %s request (%d, %d)\n", accessTimer(LAP_TIMER, timeStringy), singlePCB->uniquePid, command, argument, intArg, intArgTwo); + timeDigits = accessTimer(LAP_TIMER, timeStringy); + sprintf(processOutput, "%f, Process: %d, failed %s %s request (%d, %d)\n", timeDigits, + singlePCB->uniquePid, command, argument, intArg, intArgTwo); logOutput(configPtr, processOutput, false); } } @@ -720,13 +756,15 @@ void runProcess(ProcessControlBlock *singlePCB, ConfigDataType *configPtr, Proce if(memManagerSuccess) { // - sprintf(processOutput, "\n%f, OS: Process %d ended\n", accessTimer(LAP_TIMER, timeStringy), singlePCB->uniquePid); + timeDigits = accessTimer(LAP_TIMER, timeStringy); + sprintf(processOutput, "\n%f, OS: Process %d ended\n", timeDigits, singlePCB->uniquePid); logOutput(configPtr, processOutput, false); } else { // - sprintf(processOutput, "\n%f, OS: Segmentation Fault, Process %d ended\n", accessTimer(LAP_TIMER, timeStringy), singlePCB->uniquePid); + timeDigits = accessTimer(LAP_TIMER, timeStringy); + sprintf(processOutput, "\n%f, OS: Segmentation Fault, Process %d ended\n", timeDigits, singlePCB->uniquePid); logOutput(configPtr, processOutput, false); } // deallocate the memory for the process @@ -757,6 +795,7 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr) // char *nextCode; // string variable for the timer stuff char simulatorOutput[MAX_STR_LEN]; + double timeDigits; char timeStringy[MAX_STR_LEN]; int processCount = 0; int processIterator; @@ -765,7 +804,8 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr) accessTimer(ZERO_TIMER, timeStringy); // Operating System start timer goes here, log it. - sprintf(simulatorOutput, "%f, OS: Simulator start\n", accessTimer(LAP_TIMER, timeStringy)); + timeDigits = accessTimer(LAP_TIMER, timeStringy); + sprintf(simulatorOutput, "%f, OS: Simulator start\n", timeDigits); logOutput(configPtr, simulatorOutput, false); // int variable for process to run int currentPid; @@ -812,13 +852,17 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr) { // needs to set from READY to RUNNING pcbPtr->process_state = PROCESS_STATE_RUNNING; - sprintf(simulatorOutput, "%f, OS: Process %d set to RUNNING state from READY state\n\n", accessTimer(LAP_TIMER, timeStringy), pcbPtr->uniquePid); + timeDigits = accessTimer(LAP_TIMER, timeStringy); + sprintf(simulatorOutput, "%f, OS: Process %d set to RUNNING state from READY state\n\n", timeDigits, + pcbPtr->uniquePid); logOutput(configPtr, simulatorOutput, false); pthread_t runThread; pthread_create(&runThread, NULL, runTimer, (void *)processTimeLeftPtr); runProcess(pcbPtr, configPtr, pcbList); // 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); + timeDigits = accessTimer(LAP_TIMER, timeStringy); + sprintf(simulatorOutput, "%f, OS: Process %d set to TERMINATED state from RUNNING state\n\n", timeDigits, + pcbPtr->uniquePid); logOutput(configPtr, simulatorOutput, false); pcbPtr->process_state = PROCESS_STATE_TERMINATED; pthread_join(runThread, NULL); @@ -833,9 +877,11 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr) pthread_join(cpuThread, NULL); // deallocate all the memory for each process. memManager(pcbList, MEMORY_CLEAR, memoryOffset, memorySize, configPtr, pcbList->headPtr); - sprintf(simulatorOutput, "%f, OS: System Stop\n", accessTimer(LAP_TIMER, timeStringy)); + timeDigits = accessTimer(LAP_TIMER, timeStringy); + sprintf(simulatorOutput, "%f, OS: System Stop\n", timeDigits); logOutput(configPtr, simulatorOutput, false); - sprintf(simulatorOutput, "%f, OS: Simulation End\n", accessTimer(LAP_TIMER, timeStringy)); + timeDigits = accessTimer(LAP_TIMER, timeStringy); + sprintf(simulatorOutput, "%f, OS: Simulation End\n", timeDigits); logOutput(configPtr, simulatorOutput, true); // deallocate the process list with destroyProcessList destroyProcessList(pcbList); @@ -858,6 +904,7 @@ Dependencies: sprintf, logOutput, ??? */ int scheduleProcess(ProcessControlBlockLL *headPointer, ConfigDataType *configPtr) { + double timeDigits; ProcessControlBlock *wkgPtr; int returnPid = -1; wkgPtr = headPointer->headPtr; @@ -897,7 +944,9 @@ int scheduleProcess(ProcessControlBlockLL *headPointer, ConfigDataType *configPt // set the process within the PCB to the ready state, report in ready state. 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, timeStringy), wkgPtr->uniquePid); + timeDigits = accessTimer(LAP_TIMER, timeStringy); + sprintf(loggingStr, "%f, OS: Process %d set to READY state from NEW state\n", timeDigits, + wkgPtr->uniquePid); logOutput(configPtr, loggingStr, false); } // move to the next pointer @@ -912,7 +961,9 @@ int scheduleProcess(ProcessControlBlockLL *headPointer, ConfigDataType *configPt if (wkgPtr->process_state != PROCESS_STATE_RUNNING && wkgPtr->process_state != PROCESS_STATE_TERMINATED) { //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, timeStringy), wkgPtr->uniquePid, wkgPtr->timeLeft); + timeDigits = accessTimer(LAP_TIMER, timeStringy); + sprintf(loggingStr, "%f, OS: Process %d selected with %.0f ms remaining\n", timeDigits, + wkgPtr->uniquePid, wkgPtr->timeLeft); logOutput(configPtr, loggingStr, false); returnPid = wkgPtr->uniquePid; } @@ -940,7 +991,9 @@ int scheduleProcess(ProcessControlBlockLL *headPointer, ConfigDataType *configPt // set the process within the PCB to the ready state, report in ready state. 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, timeStringy), wkgPtr->uniquePid); + timeDigits = accessTimer(LAP_TIMER, timeStringy); + sprintf(loggingStr, "%f, OS: Process %d set to READY state from NEW state\n", timeDigits, + wkgPtr->uniquePid); logOutput(configPtr, loggingStr, false); } // move to the next pointer @@ -991,7 +1044,9 @@ int scheduleProcess(ProcessControlBlockLL *headPointer, ConfigDataType *configPt if(processCount != 0) { // 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, timeStringy), shortestJobProcNum, (double)shortestJob); + timeDigits = accessTimer(LAP_TIMER, timeStringy); + sprintf(loggingStr, "%f, OS: Process %d selected with %.0f ms remaining\n", timeDigits, + shortestJobProcNum, (double)shortestJob); logOutput(configPtr, loggingStr, false); } returnPid = shortestJobProcNum; @@ -1002,20 +1057,4 @@ int scheduleProcess(ProcessControlBlockLL *headPointer, ConfigDataType *configPt } // return returnPid return returnPid; -} - -/* -Name: simThread -Process: wrapper functions for threading in the simulator -Function Input/Parameters: milliseconds (int) -Function Output/Parameters: none -Function Output/Returned: none -Device Input/Device: none -Device Output/Device: none -Dependencies: pthreads, runTimer -*/ -// void *simThread(int milSec) -// { -// runTimer(milSec); -// pthread_exit(NULL); -// } \ No newline at end of file +} \ No newline at end of file diff --git a/Sim04/simulator.h b/Sim04/simulator.h index 9e9e59f..f55b9de 100644 --- a/Sim04/simulator.h +++ b/Sim04/simulator.h @@ -219,16 +219,4 @@ Dependencies: ??? */ int scheduleProcess(ProcessControlBlockLL *headPointer, ConfigDataType *configPtr); -/* -Name: simThread -Process: wrapper functions for threading in the simulator -Function Input/Parameters: milliseconds (int) -Function Output/Parameters: none -Function Output/Returned: none -Device Input/Device: none -Device Output/Device: none -Dependencies: ??? -*/ -// void *simThread(int milSec); - #endif // SIMULATORX \ No newline at end of file