Compare commits

..

No commits in common. "cff600c0cd20c37fa53b2585e15d93e6a90d7e86" and "638e55e77fbbcb947b97d596d4d6039c242cb724" have entirely different histories.

5 changed files with 202 additions and 214 deletions

View file

@ -1,7 +1,7 @@
Start Simulator Configuration File: Start Simulator Configuration File:
Version/Phase : 1.05 Version/Phase : 1.05
File Path : metadata5.mdf File Path : metadata5.mdf
CPU Scheduling Code : FCFS-P CPU Scheduling Code : SJF-N
Quantum Time (cycles) : 3 Quantum Time (cycles) : 3
Memory Available (KB) : 11100 Memory Available (KB) : 11100
Memory Display (On/Off) : On Memory Display (On/Off) : On

View file

@ -1 +1 @@
0.000001, OS: Simulator start 0.000000, OS: Simulator start

Binary file not shown.

View file

@ -89,8 +89,6 @@ Dependencies: ???
*/ */
bool allocMemory(ProcessControlBlock *singlePCB, int offset, int size, int arraySize) 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; int allocateIterator = 0;
// while until a '-1' is hit, then store the value. // while until a '-1' is hit, then store the value.
while(singlePCB->allocatedMemSizes[allocateIterator] != -1 && allocateIterator < arraySize) while(singlePCB->allocatedMemSizes[allocateIterator] != -1 && allocateIterator < arraySize)
@ -399,13 +397,6 @@ ProcessControlBlockLL *fillProcessList(ConfigDataType *configPtr, OpCodeType *me
inOutArg = wkgMetaPtr->inOutArg; 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
return headPointer; return headPointer;
} }
@ -464,6 +455,7 @@ bool interruptManager(ConfigDataType *configPtr, ProcessControlBlock *singlePCB,
// /* code */ // /* code */
// break; // break;
case CLEAR_INTERRUPT: case CLEAR_INTERRUPT:
// COMMENT HERE
return false; return false;
break; break;
} }
@ -486,7 +478,7 @@ Dependencies: fprintf, ???
logFileLL *logOutput(ConfigDataType *configPtr, char *logStr, bool isEnd, logFileLL *logPtr) logFileLL *logOutput(ConfigDataType *configPtr, char *logStr, bool isEnd, logFileLL *logPtr)
{ {
logFile toLog; logFile toLog;
// logFile *logStrPtr; logFile *logStrPtr;
logFile *wkgLogPtr; logFile *wkgLogPtr;
logFile *prevWkgLogPtr; logFile *prevWkgLogPtr;
wkgLogPtr = logPtr->headPtr; wkgLogPtr = logPtr->headPtr;
@ -529,8 +521,8 @@ logFileLL *logOutput(ConfigDataType *configPtr, char *logStr, bool isEnd, logFil
} }
if (wkgLogPtr == NULL) if (wkgLogPtr == NULL)
{ {
// logStrPtr = addLog(toLog); logStrPtr = addLog(toLog);
// prevWkgLogPtr->nextPtr = addLog(toLog); // THIS SHOULD BE THE WORKING LINE, but it doesn't. // prevWkgLogPtr->nextPtr = addLog(toLog);
// prevWkgLogPtr = addLog(toLog); // prevWkgLogPtr = addLog(toLog);
// prevWkgLogPtr->nextPtr = logStrPtr; // prevWkgLogPtr->nextPtr = logStrPtr;
// prevWkgLogPtr->nextPtr = logStrPtr; // prevWkgLogPtr->nextPtr = logStrPtr;
@ -560,192 +552,190 @@ Device Input/Device: none
Device Output/Device: none Device Output/Device: none
Dependencies: ??? Dependencies: ???
*/ */
// bool memManager(ProcessControlBlockLL *pcbList, MEMORY_SIGNALS memCode, int offset, int size, ConfigDataType *configPtr, bool memManager(ProcessControlBlockLL *pcbList, MEMORY_SIGNALS memCode, int offset, int size, ConfigDataType *configPtr,
// ProcessControlBlock *singlePCB) ProcessControlBlock *singlePCB)
// { {
// // printf("Memory Offset: %d\n", offset); bool memDisplay = configPtr->memDisplay;
// // printf("Memory Size: %d\n", size); ProcessControlBlock *wkgPtr;
// bool memDisplay = configPtr->memDisplay; int availableMem = configPtr->memAvailable;
// ProcessControlBlock *wkgPtr; int usedMem = 0;
// int availableMem = configPtr->memAvailable; int currentOffset = 0;
// int usedMem = 0; int currentSize = 0;
// int currentOffset = 0; int memIterator;
// int currentSize = 0; int *memorySizeArray;
// int memIterator; int totalArraySize = 0;
// int *memorySizeArray; bool subFunctionSuccess = true;
// int totalArraySize = 0; wkgPtr = pcbList->headPtr;
// bool subFunctionSuccess = true;
// wkgPtr = pcbList->headPtr;
// // grab how much memory is being used total, then count how big the total memory array should be // grab how much memory is being used total, then count how big the total memory array should be
// while(wkgPtr != NULL) while(wkgPtr != NULL)
// { {
// // count up the total used memory within each process control block. // count up the total used memory within each process control block.
// for(memIterator = 0; memIterator < wkgPtr->memArraySize; memIterator++) for(memIterator = 0; memIterator < wkgPtr->memArraySize; memIterator++)
// { {
// if(wkgPtr->allocatedMemSizes[memIterator] != -1) if(wkgPtr->allocatedMemSizes[memIterator] != -1)
// { {
// // grab how much memory is used by that process // grab how much memory is used by that process
// usedMem = usedMem + wkgPtr->allocatedMemSizes[memIterator]; usedMem = usedMem + wkgPtr->allocatedMemSizes[memIterator];
// } }
// totalArraySize = totalArraySize + 1; totalArraySize = totalArraySize + 1;
// } }
// // move to the next pointer // move to the next pointer
// wkgPtr = wkgPtr->nextPtr; wkgPtr = wkgPtr->nextPtr;
// } }
// // reset the working pointer // reset the working pointer
// wkgPtr = pcbList->headPtr; wkgPtr = pcbList->headPtr;
// // declare the array for the memory // declare the array for the memory
// memorySizeArray = malloc(sizeof(int) * totalArraySize); memorySizeArray = malloc(sizeof(int) * totalArraySize);
// // grab the entire memory structure, so that the memory can be contiguous // grab the entire memory structure, so that the memory can be contiguous
// while (wkgPtr != NULL) while (wkgPtr != NULL)
// { {
// // count up the total used memory within each process control block. // count up the total used memory within each process control block.
// for (memIterator = 0; memIterator < totalArraySize; memIterator++) for (memIterator = 0; memIterator < totalArraySize; memIterator++)
// { {
// // grab how much memory is used by that process // grab how much memory is used by that process
// memorySizeArray[memIterator] = wkgPtr->allocatedMemSizes[memIterator]; memorySizeArray[memIterator] = wkgPtr->allocatedMemSizes[memIterator];
// } }
// // move to the next pointer // move to the next pointer
// wkgPtr = wkgPtr->nextPtr; wkgPtr = wkgPtr->nextPtr;
// } }
// // grab the size of the // grab the size of the
// // while() // while()
// // { // {
// // // // //
// // } // }
// // switch case for each memory code // switch case for each memory code
// switch (memCode) switch (memCode)
// { {
// case MEMORY_INITIALIZE: case MEMORY_INITIALIZE:
// for(memIterator = 0; memIterator < singlePCB->memArraySize; memIterator++) for(memIterator = 0; memIterator < singlePCB->memArraySize; memIterator++)
// { {
// // initialize the arrays with all '-1' to 'nullify' the memory, make it easier to iterate through later // initialize the arrays with all '-1' to 'nullify' the memory, make it easier to iterate through later
// singlePCB->allocatedMemOffsets[memIterator] = -1; singlePCB->allocatedMemOffsets[memIterator] = -1;
// singlePCB->allocatedMemSizes[memIterator] = -1; singlePCB->allocatedMemSizes[memIterator] = -1;
// } }
// if(memDisplay) if(memDisplay)
// { {
// // //
// printf("--------------------------------------------------\n"); printf("--------------------------------------------------\n");
// printf("After memory initialization\n"); printf("After memory initialization\n");
// printf("%d [ Open, P#: x, %d-%d ] %d\n", usedMem, currentOffset, currentSize, availableMem - 1); printf("%d [ Open, P#: x, %d-%d ] %d\n", usedMem, currentOffset, currentSize, availableMem - 1);
// printf("--------------------------------------------------\n"); printf("--------------------------------------------------\n");
// } }
// break; break;
// case MEMORY_ALLOCATE: case MEMORY_ALLOCATE:
// // check if the memory allocation can happen before storing it. // check if the memory allocation can happen before storing it.
// if(size <= availableMem - usedMem + 1) if(size <= availableMem - usedMem + 1)
// { {
// // grab the offset and size, store it, using the allocate memory function. // grab the offset and size, store it, using the allocate memory function.
// subFunctionSuccess = allocMemory(singlePCB, offset, size, singlePCB->memArraySize); subFunctionSuccess = allocMemory(singlePCB, offset, size, singlePCB->memArraySize);
// usedMem = usedMem + size; usedMem = usedMem + size;
// } }
// else else
// { {
// // set the subfunction success to false. // set the subfunction success to false.
// subFunctionSuccess = false; subFunctionSuccess = false;
// } }
// // if the function returns true, then it successfully did the operation, display as such. // if the function returns true, then it successfully did the operation, display as such.
// if (memDisplay) if (memDisplay)
// { {
// if(subFunctionSuccess) if(subFunctionSuccess)
// { {
// // //
// printf("--------------------------------------------------\n"); printf("--------------------------------------------------\n");
// printf("After memory allocation\n"); printf("After memory allocation\n");
// printf("%d [ Used, P#: %d, %d-%d ] %d\n", offset - offset, singlePCB->uniquePid, offset, printf("%d [ Used, P#: %d, %d-%d ] %d\n", offset - offset, singlePCB->uniquePid, offset,
// offset + size - 1, size - 1); offset + size - 1, size - 1);
// printf("%d [ Open, P#: x, %d-%d ] %d\n", usedMem, currentOffset, currentSize, availableMem - 1); printf("%d [ Open, P#: x, %d-%d ] %d\n", usedMem, currentOffset, currentSize, availableMem - 1);
// printf("--------------------------------------------------\n"); printf("--------------------------------------------------\n");
// } }
// else else
// { {
// // //
// printf("--------------------------------------------------\n"); printf("--------------------------------------------------\n");
// printf("After memory allocation failure\n"); printf("After memory allocation failure\n");
// printf("%d [ Open, P#: x, %d-%d ] %d\n", usedMem, currentOffset, currentSize, availableMem - 1); printf("%d [ Open, P#: x, %d-%d ] %d\n", usedMem, currentOffset, currentSize, availableMem - 1);
// printf("--------------------------------------------------\n"); printf("--------------------------------------------------\n");
// } }
// } }
// break; break;
// case MEMORY_ACCESS: case MEMORY_ACCESS:
// // printf("Used memory at current: %d\n", usedMem); // printf("Used memory at current: %d\n", usedMem);
// subFunctionSuccess = accessMemory(singlePCB, offset, size); subFunctionSuccess = accessMemory(singlePCB, offset, size);
// if (memDisplay) if (memDisplay)
// { {
// if (subFunctionSuccess) if (subFunctionSuccess)
// { {
// // //
// printf("--------------------------------------------------\n"); printf("--------------------------------------------------\n");
// printf("After access success\n"); printf("After access success\n");
// printf("%d [ Used, P#: %d, %d-%d ] %d\n", offset - offset, singlePCB->uniquePid, offset, printf("%d [ Used, P#: %d, %d-%d ] %d\n", offset - offset, singlePCB->uniquePid, offset,
// offset + size - 1, size - 1); offset + size - 1, size - 1);
// printf("%d [ Open, P#: x, %d-%d ] %d\n", usedMem, currentOffset, currentSize, availableMem - 1); printf("%d [ Open, P#: x, %d-%d ] %d\n", usedMem, currentOffset, currentSize, availableMem - 1);
// printf("--------------------------------------------------\n"); printf("--------------------------------------------------\n");
// } }
// else else
// { {
// // //
// printf("--------------------------------------------------\n"); printf("--------------------------------------------------\n");
// printf("After access failure\n"); printf("After access failure\n");
// printf("%d [ Used, P#: %d, %d-%d ] %d\n", offset - offset, singlePCB->uniquePid, offset, printf("%d [ Used, P#: %d, %d-%d ] %d\n", offset - offset, singlePCB->uniquePid, offset,
// offset + size - 1, size - 1); offset + size - 1, size - 1);
// printf("%d [ Open, P#: x, %d-%d ] %d\n", usedMem, currentOffset, currentSize, availableMem - 1); printf("%d [ Open, P#: x, %d-%d ] %d\n", usedMem, currentOffset, currentSize, availableMem - 1);
// printf("--------------------------------------------------\n"); printf("--------------------------------------------------\n");
// } }
// } }
// break; break;
// case MEMORY_DEALLOCATE: case MEMORY_DEALLOCATE:
// subFunctionSuccess = deallocMemory(singlePCB, singlePCB->memArraySize); subFunctionSuccess = deallocMemory(singlePCB, singlePCB->memArraySize);
// if (memDisplay) if (memDisplay)
// { {
// if (subFunctionSuccess) if (subFunctionSuccess)
// { {
// // THIS SHOULD ALWAYS HAPPEN. // THIS SHOULD ALWAYS HAPPEN.
// printf("--------------------------------------------------\n"); printf("--------------------------------------------------\n");
// printf("After clear process %d success\n", singlePCB->uniquePid); 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("%d [ Open, P#: x, %d-%d ] %d\n", usedMem - usedMem, currentOffset, currentSize, availableMem - 1);
// printf("--------------------------------------------------\n"); printf("--------------------------------------------------\n");
// } }
// else else
// { {
// // THIS SHOULD NEVER HAPPEN. // THIS SHOULD NEVER HAPPEN.
// printf("--------------------------------------------------\n"); printf("--------------------------------------------------\n");
// printf("After clear process %d failure\n", singlePCB->uniquePid); 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("%d [ Open, P#: x, %d-%d ] %d\n", usedMem - usedMem, currentOffset, currentSize, availableMem - 1);
// printf("--------------------------------------------------\n"); printf("--------------------------------------------------\n");
// } }
// } }
// break; break;
// case MEMORY_CLEAR: case MEMORY_CLEAR:
// if (memDisplay) if (memDisplay)
// { {
// // this will happen regardless. Will always be cleaning up memory with dealloc. // this will happen regardless. Will always be cleaning up memory with dealloc.
// printf("--------------------------------------------------\n"); printf("--------------------------------------------------\n");
// printf("After memory clear\n"); printf("After memory clear\n");
// printf("No memory configured\n"); printf("No memory configured\n");
// printf("--------------------------------------------------\n"); printf("--------------------------------------------------\n");
// } }
// break; break;
// default: default:
// break; break;
// } }
// // clear out the dynamic array // clear out the dynamic array
// free(memorySizeArray); free(memorySizeArray);
// // return if the subfunction succeeded, if applicable // return if the subfunction succeeded, if applicable
// return subFunctionSuccess; return subFunctionSuccess;
// } }
/* /*
Name: runCPU Name: runCPU
@ -920,17 +910,15 @@ void runProcess(ProcessControlBlock *singlePCB, ConfigDataType *configPtr, Proce
singlePCB->uniquePid, command, argument, intArg, intArgTwo); singlePCB->uniquePid, command, argument, intArg, intArgTwo);
logOutput(configPtr, processOutput, false, logList); logOutput(configPtr, processOutput, false, logList);
// run the memory manager in allocate mode // run the memory manager in allocate mode
// printf("Memory Offset: %d\n", intArg); memManagerSuccess = memManager(pcbList, MEMORY_ALLOCATE, intArg, intArgTwo, configPtr, singlePCB);
// printf("Memory Size: %d\n", intArgTwo); if(!memManagerSuccess)
// 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,
// timeDigits = accessTimer(LAP_TIMER, timeStringy); singlePCB->uniquePid, command, argument, intArg, intArgTwo);
// sprintf(processOutput, "%f, Process: %d, failed %s %s request (%d, %d)\n", timeDigits, logOutput(configPtr, processOutput, false, logList);
// singlePCB->uniquePid, command, argument, intArg, intArgTwo); }
// logOutput(configPtr, processOutput, false, logList);
// }
} }
else if(compareString(argument, "access") == EQUIV) else if(compareString(argument, "access") == EQUIV)
{ {
@ -939,15 +927,15 @@ void runProcess(ProcessControlBlock *singlePCB, ConfigDataType *configPtr, Proce
singlePCB->uniquePid, command, argument, intArg, intArgTwo); singlePCB->uniquePid, command, argument, intArg, intArgTwo);
logOutput(configPtr, processOutput, false, logList); logOutput(configPtr, processOutput, false, logList);
// run the memory manager in access mode // run the memory manager in access mode
// memManagerSuccess = memManager(pcbList, MEMORY_ACCESS, intArg, intArgTwo, configPtr, singlePCB); memManagerSuccess = memManager(pcbList, MEMORY_ACCESS, intArg, intArgTwo, configPtr, singlePCB);
// if (!memManagerSuccess) if (!memManagerSuccess)
// { {
// // //
// timeDigits = accessTimer(LAP_TIMER, timeStringy); timeDigits = accessTimer(LAP_TIMER, timeStringy);
// sprintf(processOutput, "%f, Process: %d, failed %s %s request (%d, %d)\n", timeDigits, sprintf(processOutput, "%f, Process: %d, failed %s %s request (%d, %d)\n", timeDigits,
// singlePCB->uniquePid, command, argument, intArg, intArgTwo); singlePCB->uniquePid, command, argument, intArg, intArgTwo);
// logOutput(configPtr, processOutput, false, logList); logOutput(configPtr, processOutput, false, logList);
// } }
} }
} }
workingMeta = workingMeta->nextNode; workingMeta = workingMeta->nextNode;
@ -983,7 +971,7 @@ void runProcess(ProcessControlBlock *singlePCB, ConfigDataType *configPtr, Proce
logOutput(configPtr, processOutput, false, logList); logOutput(configPtr, processOutput, false, logList);
} }
// deallocate the memory for the process // deallocate the memory for the process
// memManager(pcbList, MEMORY_DEALLOCATE, intArg, intArgTwo, configPtr, singlePCB); memManager(pcbList, MEMORY_DEALLOCATE, intArg, intArgTwo, configPtr, singlePCB);
} }
/* /*
@ -1078,7 +1066,7 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr)
currentPid = scheduleProcess(pcbList, configPtr, loggingList); currentPid = scheduleProcess(pcbList, configPtr, loggingList);
// initialize memory with the memManager // 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 // loop until current process is hit
for(processIterator = 0; processIterator < processCount; processIterator++) for(processIterator = 0; processIterator < processCount; processIterator++)
@ -1126,7 +1114,7 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr)
} }
pthread_join(cpuThread, NULL); pthread_join(cpuThread, NULL);
// deallocate all the memory for each process. // 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); timeDigits = accessTimer(LAP_TIMER, timeStringy);
sprintf(simulatorOutput, "%f, OS: System Stop\n", timeDigits); sprintf(simulatorOutput, "%f, OS: System Stop\n", timeDigits);
logOutput(configPtr, simulatorOutput, false, loggingList); logOutput(configPtr, simulatorOutput, false, loggingList);

View file

@ -301,8 +301,8 @@ Device Input/Device: none
Device Output/Device: none Device Output/Device: none
Dependencies: ??? Dependencies: ???
*/ */
// bool memManager(ProcessControlBlockLL *pcbList, MEMORY_SIGNALS memCode, int offset, int size, ConfigDataType *configPtr, bool memManager(ProcessControlBlockLL *pcbList, MEMORY_SIGNALS memCode, int offset, int size, ConfigDataType *configPtr,
// ProcessControlBlock *singlePCB); ProcessControlBlock *singlePCB);
/* /*
Name: runCPU Name: runCPU