diff --git a/Sim04/config0.cnf b/Sim04/config0.cnf index 9404729..4654fe8 100644 --- a/Sim04/config0.cnf +++ b/Sim04/config0.cnf @@ -1,7 +1,7 @@ Start Simulator Configuration File: Version/Phase : 1.05 File Path : metadata5.mdf -CPU Scheduling Code : SJF-N +CPU Scheduling Code : FCFS-P Quantum Time (cycles) : 3 Memory Available (KB) : 11100 Memory Display (On/Off) : On diff --git a/Sim04/sim04 b/Sim04/sim04 index 085f484..30f062f 100755 Binary files a/Sim04/sim04 and b/Sim04/sim04 differ diff --git a/Sim04/simulator.c b/Sim04/simulator.c index ba49b0b..3fd445b 100644 --- a/Sim04/simulator.c +++ b/Sim04/simulator.c @@ -89,6 +89,8 @@ Dependencies: ??? */ bool allocMemory(ProcessControlBlock *singlePCB, int offset, int size, int arraySize) { + // printf("Memory Offset: %d\n", offset); + // printf("Memory Size: %d\n", size); int allocateIterator = 0; // while until a '-1' is hit, then store the value. while(singlePCB->allocatedMemSizes[allocateIterator] != -1 && allocateIterator < arraySize) @@ -397,6 +399,13 @@ ProcessControlBlockLL *fillProcessList(ConfigDataType *configPtr, OpCodeType *me inOutArg = wkgMetaPtr->inOutArg; } + if (configPtr->cpuSchedCode == CPU_SCHED_RR_P_CODE) + { + // if in round robin preemptive scheduling, then make the linked list + // into a circularly linked list, with the head pointer pointed to the + // first node, and the last node linked to the first. + wkgPCBPtr->nextPtr = headPointer->headPtr; + } // return headPointer return headPointer; } @@ -455,7 +464,6 @@ bool interruptManager(ConfigDataType *configPtr, ProcessControlBlock *singlePCB, // /* code */ // break; case CLEAR_INTERRUPT: - // COMMENT HERE return false; break; } @@ -478,7 +486,7 @@ Dependencies: fprintf, ??? logFileLL *logOutput(ConfigDataType *configPtr, char *logStr, bool isEnd, logFileLL *logPtr) { logFile toLog; - logFile *logStrPtr; + // logFile *logStrPtr; logFile *wkgLogPtr; logFile *prevWkgLogPtr; wkgLogPtr = logPtr->headPtr; @@ -521,8 +529,8 @@ logFileLL *logOutput(ConfigDataType *configPtr, char *logStr, bool isEnd, logFil } if (wkgLogPtr == NULL) { - logStrPtr = addLog(toLog); - // prevWkgLogPtr->nextPtr = addLog(toLog); + // logStrPtr = addLog(toLog); + // prevWkgLogPtr->nextPtr = addLog(toLog); // THIS SHOULD BE THE WORKING LINE, but it doesn't. // prevWkgLogPtr = addLog(toLog); // prevWkgLogPtr->nextPtr = logStrPtr; // prevWkgLogPtr->nextPtr = logStrPtr; @@ -552,190 +560,192 @@ 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 memDisplay = configPtr->memDisplay; - ProcessControlBlock *wkgPtr; - int availableMem = configPtr->memAvailable; - int usedMem = 0; - int currentOffset = 0; - int currentSize = 0; - int memIterator; - int *memorySizeArray; - int totalArraySize = 0; - bool subFunctionSuccess = true; - wkgPtr = pcbList->headPtr; +// bool memManager(ProcessControlBlockLL *pcbList, MEMORY_SIGNALS memCode, int offset, int size, ConfigDataType *configPtr, +// ProcessControlBlock *singlePCB) +// { +// // printf("Memory Offset: %d\n", offset); +// // printf("Memory Size: %d\n", size); +// bool memDisplay = configPtr->memDisplay; +// ProcessControlBlock *wkgPtr; +// int availableMem = configPtr->memAvailable; +// int usedMem = 0; +// int currentOffset = 0; +// int currentSize = 0; +// int memIterator; +// int *memorySizeArray; +// int totalArraySize = 0; +// bool subFunctionSuccess = true; +// wkgPtr = pcbList->headPtr; - // grab how much memory is being used total, then count how big the total memory array should be - while(wkgPtr != NULL) - { - // count up the total used memory within each process control block. - for(memIterator = 0; memIterator < wkgPtr->memArraySize; memIterator++) - { - if(wkgPtr->allocatedMemSizes[memIterator] != -1) - { - // grab how much memory is used by that process - usedMem = usedMem + wkgPtr->allocatedMemSizes[memIterator]; - } - totalArraySize = totalArraySize + 1; - } - // move to the next pointer - wkgPtr = wkgPtr->nextPtr; - } +// // grab how much memory is being used total, then count how big the total memory array should be +// while(wkgPtr != NULL) +// { +// // count up the total used memory within each process control block. +// for(memIterator = 0; memIterator < wkgPtr->memArraySize; memIterator++) +// { +// if(wkgPtr->allocatedMemSizes[memIterator] != -1) +// { +// // grab how much memory is used by that process +// usedMem = usedMem + wkgPtr->allocatedMemSizes[memIterator]; +// } +// totalArraySize = totalArraySize + 1; +// } +// // move to the next pointer +// wkgPtr = wkgPtr->nextPtr; +// } - // reset the working pointer - wkgPtr = pcbList->headPtr; +// // reset the working pointer +// wkgPtr = pcbList->headPtr; - // declare the array for the memory - memorySizeArray = malloc(sizeof(int) * totalArraySize); +// // declare the array for the memory +// memorySizeArray = malloc(sizeof(int) * totalArraySize); - // grab the entire memory structure, so that the memory can be contiguous - while (wkgPtr != NULL) - { - // count up the total used memory within each process control block. - for (memIterator = 0; memIterator < totalArraySize; memIterator++) - { - // grab how much memory is used by that process - memorySizeArray[memIterator] = wkgPtr->allocatedMemSizes[memIterator]; - } - // move to the next pointer - wkgPtr = wkgPtr->nextPtr; - } +// // grab the entire memory structure, so that the memory can be contiguous +// while (wkgPtr != NULL) +// { +// // count up the total used memory within each process control block. +// for (memIterator = 0; memIterator < totalArraySize; memIterator++) +// { +// // grab how much memory is used by that process +// memorySizeArray[memIterator] = wkgPtr->allocatedMemSizes[memIterator]; +// } +// // move to the next pointer +// wkgPtr = wkgPtr->nextPtr; +// } - // grab the size of the - // while() - // { - // // - // } +// // grab the size of the +// // while() +// // { +// // // +// // } - // switch case for each memory code - switch (memCode) - { - case MEMORY_INITIALIZE: - for(memIterator = 0; memIterator < singlePCB->memArraySize; memIterator++) - { - // initialize the arrays with all '-1' to 'nullify' the memory, make it easier to iterate through later - singlePCB->allocatedMemOffsets[memIterator] = -1; - singlePCB->allocatedMemSizes[memIterator] = -1; - } - if(memDisplay) - { - // - printf("--------------------------------------------------\n"); - printf("After memory initialization\n"); - printf("%d [ Open, P#: x, %d-%d ] %d\n", usedMem, currentOffset, currentSize, availableMem - 1); - printf("--------------------------------------------------\n"); - } - break; +// // switch case for each memory code +// switch (memCode) +// { +// case MEMORY_INITIALIZE: +// for(memIterator = 0; memIterator < singlePCB->memArraySize; memIterator++) +// { +// // initialize the arrays with all '-1' to 'nullify' the memory, make it easier to iterate through later +// singlePCB->allocatedMemOffsets[memIterator] = -1; +// singlePCB->allocatedMemSizes[memIterator] = -1; +// } +// if(memDisplay) +// { +// // +// printf("--------------------------------------------------\n"); +// printf("After memory initialization\n"); +// printf("%d [ Open, P#: x, %d-%d ] %d\n", usedMem, currentOffset, currentSize, availableMem - 1); +// printf("--------------------------------------------------\n"); +// } +// break; - case MEMORY_ALLOCATE: - // check if the memory allocation can happen before storing it. - if(size <= availableMem - usedMem + 1) - { - // grab the offset and size, store it, using the allocate memory function. - subFunctionSuccess = allocMemory(singlePCB, offset, size, singlePCB->memArraySize); - usedMem = usedMem + size; - } - else - { - // set the subfunction success to false. - subFunctionSuccess = false; - } - // if the function returns true, then it successfully did the operation, display as such. - if (memDisplay) - { - if(subFunctionSuccess) - { - // - 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 [ Open, P#: x, %d-%d ] %d\n", usedMem, currentOffset, currentSize, availableMem - 1); - printf("--------------------------------------------------\n"); - } - else - { - // - printf("--------------------------------------------------\n"); - printf("After memory allocation failure\n"); - printf("%d [ Open, P#: x, %d-%d ] %d\n", usedMem, currentOffset, currentSize, availableMem - 1); - printf("--------------------------------------------------\n"); - } - } - break; +// case MEMORY_ALLOCATE: +// // check if the memory allocation can happen before storing it. +// if(size <= availableMem - usedMem + 1) +// { +// // grab the offset and size, store it, using the allocate memory function. +// subFunctionSuccess = allocMemory(singlePCB, offset, size, singlePCB->memArraySize); +// usedMem = usedMem + size; +// } +// else +// { +// // set the subfunction success to false. +// subFunctionSuccess = false; +// } +// // if the function returns true, then it successfully did the operation, display as such. +// if (memDisplay) +// { +// if(subFunctionSuccess) +// { +// // +// 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 [ Open, P#: x, %d-%d ] %d\n", usedMem, currentOffset, currentSize, availableMem - 1); +// printf("--------------------------------------------------\n"); +// } +// else +// { +// // +// printf("--------------------------------------------------\n"); +// printf("After memory allocation failure\n"); +// printf("%d [ Open, P#: x, %d-%d ] %d\n", usedMem, currentOffset, currentSize, availableMem - 1); +// printf("--------------------------------------------------\n"); +// } +// } +// break; - case MEMORY_ACCESS: - // printf("Used memory at current: %d\n", usedMem); - subFunctionSuccess = accessMemory(singlePCB, offset, size); - if (memDisplay) - { - if (subFunctionSuccess) - { - // - 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 [ Open, P#: x, %d-%d ] %d\n", usedMem, currentOffset, currentSize, availableMem - 1); - printf("--------------------------------------------------\n"); - } - else - { - // - 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 [ Open, P#: x, %d-%d ] %d\n", usedMem, currentOffset, currentSize, availableMem - 1); - printf("--------------------------------------------------\n"); - } - } - break; +// case MEMORY_ACCESS: +// // printf("Used memory at current: %d\n", usedMem); +// subFunctionSuccess = accessMemory(singlePCB, offset, size); +// if (memDisplay) +// { +// if (subFunctionSuccess) +// { +// // +// 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 [ Open, P#: x, %d-%d ] %d\n", usedMem, currentOffset, currentSize, availableMem - 1); +// printf("--------------------------------------------------\n"); +// } +// else +// { +// // +// 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 [ Open, P#: x, %d-%d ] %d\n", usedMem, currentOffset, currentSize, availableMem - 1); +// printf("--------------------------------------------------\n"); +// } +// } +// break; - case MEMORY_DEALLOCATE: - subFunctionSuccess = deallocMemory(singlePCB, singlePCB->memArraySize); - if (memDisplay) - { - if (subFunctionSuccess) - { - // THIS SHOULD ALWAYS HAPPEN. - printf("--------------------------------------------------\n"); - printf("After clear process %d success\n", singlePCB->uniquePid); - printf("%d [ Open, P#: x, %d-%d ] %d\n", usedMem - usedMem, currentOffset, currentSize, availableMem - 1); - printf("--------------------------------------------------\n"); - } - else - { - // THIS SHOULD NEVER HAPPEN. - printf("--------------------------------------------------\n"); - printf("After clear process %d failure\n", singlePCB->uniquePid); - printf("%d [ Open, P#: x, %d-%d ] %d\n", usedMem - usedMem, currentOffset, currentSize, availableMem - 1); - printf("--------------------------------------------------\n"); - } - } - break; +// case MEMORY_DEALLOCATE: +// subFunctionSuccess = deallocMemory(singlePCB, singlePCB->memArraySize); +// if (memDisplay) +// { +// if (subFunctionSuccess) +// { +// // THIS SHOULD ALWAYS HAPPEN. +// printf("--------------------------------------------------\n"); +// printf("After clear process %d success\n", singlePCB->uniquePid); +// printf("%d [ Open, P#: x, %d-%d ] %d\n", usedMem - usedMem, currentOffset, currentSize, availableMem - 1); +// printf("--------------------------------------------------\n"); +// } +// else +// { +// // THIS SHOULD NEVER HAPPEN. +// printf("--------------------------------------------------\n"); +// printf("After clear process %d failure\n", singlePCB->uniquePid); +// printf("%d [ Open, P#: x, %d-%d ] %d\n", usedMem - usedMem, currentOffset, currentSize, availableMem - 1); +// printf("--------------------------------------------------\n"); +// } +// } +// break; - case MEMORY_CLEAR: - if (memDisplay) - { - // this will happen regardless. Will always be cleaning up memory with dealloc. - printf("--------------------------------------------------\n"); - printf("After memory clear\n"); - printf("No memory configured\n"); - printf("--------------------------------------------------\n"); - } - break; +// case MEMORY_CLEAR: +// if (memDisplay) +// { +// // this will happen regardless. Will always be cleaning up memory with dealloc. +// printf("--------------------------------------------------\n"); +// printf("After memory clear\n"); +// printf("No memory configured\n"); +// printf("--------------------------------------------------\n"); +// } +// break; - default: - break; - } - // clear out the dynamic array - free(memorySizeArray); - // return if the subfunction succeeded, if applicable - return subFunctionSuccess; -} +// default: +// break; +// } +// // clear out the dynamic array +// free(memorySizeArray); +// // return if the subfunction succeeded, if applicable +// return subFunctionSuccess; +// } /* Name: runCPU @@ -910,15 +920,17 @@ void runProcess(ProcessControlBlock *singlePCB, ConfigDataType *configPtr, Proce singlePCB->uniquePid, command, argument, intArg, intArgTwo); logOutput(configPtr, processOutput, false, logList); // run the memory manager in allocate mode - memManagerSuccess = memManager(pcbList, MEMORY_ALLOCATE, intArg, intArgTwo, configPtr, singlePCB); - if(!memManagerSuccess) - { - // - 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, logList); - } + // printf("Memory Offset: %d\n", intArg); + // printf("Memory Size: %d\n", intArgTwo); + // memManagerSuccess = memManager(pcbList, MEMORY_ALLOCATE, intArg, intArgTwo, configPtr, singlePCB); + // if(!memManagerSuccess) + // { + // // + // 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, logList); + // } } else if(compareString(argument, "access") == EQUIV) { @@ -927,15 +939,15 @@ void runProcess(ProcessControlBlock *singlePCB, ConfigDataType *configPtr, Proce singlePCB->uniquePid, command, argument, intArg, intArgTwo); logOutput(configPtr, processOutput, false, logList); // run the memory manager in access mode - memManagerSuccess = memManager(pcbList, MEMORY_ACCESS, intArg, intArgTwo, configPtr, singlePCB); - if (!memManagerSuccess) - { - // - 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, logList); - } + // memManagerSuccess = memManager(pcbList, MEMORY_ACCESS, intArg, intArgTwo, configPtr, singlePCB); + // if (!memManagerSuccess) + // { + // // + // 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, logList); + // } } } workingMeta = workingMeta->nextNode; @@ -971,7 +983,7 @@ void runProcess(ProcessControlBlock *singlePCB, ConfigDataType *configPtr, Proce logOutput(configPtr, processOutput, false, logList); } // deallocate the memory for the process - memManager(pcbList, MEMORY_DEALLOCATE, intArg, intArgTwo, configPtr, singlePCB); + // memManager(pcbList, MEMORY_DEALLOCATE, intArg, intArgTwo, configPtr, singlePCB); } /* @@ -1066,7 +1078,7 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr) currentPid = scheduleProcess(pcbList, configPtr, loggingList); // initialize memory with the memManager - memManager(pcbList, MEMORY_INITIALIZE, memoryOffset, memorySize, configPtr, pcbList->headPtr); + // memManager(pcbList, MEMORY_INITIALIZE, memoryOffset, memorySize, configPtr, pcbList->headPtr); // loop until current process is hit for(processIterator = 0; processIterator < processCount; processIterator++) @@ -1114,7 +1126,7 @@ 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); + // memManager(pcbList, MEMORY_CLEAR, memoryOffset, memorySize, configPtr, pcbList->headPtr); timeDigits = accessTimer(LAP_TIMER, timeStringy); sprintf(simulatorOutput, "%f, OS: System Stop\n", timeDigits); logOutput(configPtr, simulatorOutput, false, loggingList); diff --git a/Sim04/simulator.h b/Sim04/simulator.h index df03988..07e724a 100644 --- a/Sim04/simulator.h +++ b/Sim04/simulator.h @@ -301,8 +301,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); /* Name: runCPU