Savepoint, started the allocate memory management stuff.
+- simulator.c
This commit is contained in:
parent
bb6d8ac0af
commit
d7bb439a2a
3 changed files with 57 additions and 19 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
0.000001, OS: Simulator start
|
0.000000, OS: Simulator start
|
||||||
READY state from NEW state
|
READY state from NEW state
|
||||||
ate
|
ate
|
||||||
|
|
||||||
|
|
|
||||||
BIN
Sim03/sim03
BIN
Sim03/sim03
Binary file not shown.
|
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Name: accessMemory
|
Name: accessMemory
|
||||||
Process: checks offset from the PCB
|
Process: checks that the memory is between the offset and the size.
|
||||||
|
checks that the memory is ???
|
||||||
Function Input/Parameters: source PCB (ProcessControlBlock *), offset (int), size (int)
|
Function Input/Parameters: source PCB (ProcessControlBlock *), offset (int), size (int)
|
||||||
Function Output/Parameters: none
|
Function Output/Parameters: none
|
||||||
Function Output/Returned: boolean to indicate success or failure of accessed memory
|
Function Output/Returned: boolean to indicate success or failure of accessed memory
|
||||||
|
|
@ -90,15 +91,15 @@ ProcessControlBlockLL *createProcessList()
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Name: deallocMemory
|
Name: deallocMemory
|
||||||
Process: 'deallocates' memory within the PCB, removes offset and size within it's PCB
|
Process: 'deallocates' memory within the PCB, removes every offset and size within it's PCB
|
||||||
Function Input/Parameters: source PCB (ProcessControlBlock *), offset (int), size (int)
|
Function Input/Parameters: source PCB (ProcessControlBlock *)
|
||||||
Function Output/Parameters: none
|
Function Output/Parameters: none
|
||||||
Function Output/Returned: boolean to indicate success or failure of allocated memory
|
Function Output/Returned: boolean to indicate success or failure of allocated memory
|
||||||
Device Input/Device: none
|
Device Input/Device: none
|
||||||
Device Output/Device: none
|
Device Output/Device: none
|
||||||
Dependencies: ???
|
Dependencies: ???
|
||||||
*/
|
*/
|
||||||
bool deallocMemory(ProcessControlBlock *singlePCB, int offset, int size)
|
bool deallocMemory(ProcessControlBlock *singlePCB)
|
||||||
{
|
{
|
||||||
// return true (temp)
|
// return true (temp)
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -377,12 +378,12 @@ Process: checks to make sure an allocate will be successful,
|
||||||
Function Input/Parameters: PCBList (ProcessControlBlockLL *), memory code (MEMORY_SIGNALS),
|
Function Input/Parameters: PCBList (ProcessControlBlockLL *), memory code (MEMORY_SIGNALS),
|
||||||
offset (int), size (int), configuration data (ConfigDataType *)
|
offset (int), size (int), configuration data (ConfigDataType *)
|
||||||
Function Output/Parameters: none
|
Function Output/Parameters: none
|
||||||
Function Output/Returned: none?
|
Function Output/Returned: boolean for success or failure of memory management
|
||||||
Device Input/Device: none
|
Device Input/Device: none
|
||||||
Device Output/Device: none
|
Device Output/Device: none
|
||||||
Dependencies: ???
|
Dependencies: ???
|
||||||
*/
|
*/
|
||||||
void 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;
|
bool memDisplay = configPtr->memDisplay;
|
||||||
ProcessControlBlock *wkgPtr;
|
ProcessControlBlock *wkgPtr;
|
||||||
|
|
@ -401,9 +402,12 @@ void memManager(ProcessControlBlockLL *pcbList, MEMORY_SIGNALS memCode, int offs
|
||||||
{
|
{
|
||||||
// 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)
|
||||||
{
|
{
|
||||||
// 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
|
||||||
|
|
@ -456,9 +460,19 @@ void memManager(ProcessControlBlockLL *pcbList, MEMORY_SIGNALS memCode, int offs
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MEMORY_ALLOCATE:
|
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.
|
// grab the offset and size, store it, using the allocate memory function.
|
||||||
// if the function returns true, then it successfully did the operation, display as such.
|
|
||||||
subFunctionSuccess = allocMemory(singlePCB, offset, size);
|
subFunctionSuccess = allocMemory(singlePCB, offset, size);
|
||||||
|
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 (memDisplay)
|
||||||
{
|
{
|
||||||
if(subFunctionSuccess)
|
if(subFunctionSuccess)
|
||||||
|
|
@ -507,7 +521,7 @@ void memManager(ProcessControlBlockLL *pcbList, MEMORY_SIGNALS memCode, int offs
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MEMORY_DEALLOCATE:
|
case MEMORY_DEALLOCATE:
|
||||||
subFunctionSuccess = deallocMemory(singlePCB, offset, size);
|
subFunctionSuccess = deallocMemory(singlePCB);
|
||||||
if (memDisplay)
|
if (memDisplay)
|
||||||
{
|
{
|
||||||
if (subFunctionSuccess)
|
if (subFunctionSuccess)
|
||||||
|
|
@ -545,7 +559,8 @@ void memManager(ProcessControlBlockLL *pcbList, MEMORY_SIGNALS memCode, int offs
|
||||||
}
|
}
|
||||||
// clear out the dynamic array
|
// clear out the dynamic array
|
||||||
free(memorySizeArray);
|
free(memorySizeArray);
|
||||||
// no return, void (temp)
|
// return if the subfunction succeeded, if applicable
|
||||||
|
return subFunctionSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -625,13 +640,14 @@ void runProcess(ProcessControlBlock *singlePCB, ConfigDataType *configPtr, Proce
|
||||||
char *argument;
|
char *argument;
|
||||||
int intArg;
|
int intArg;
|
||||||
int intArgTwo;
|
int intArgTwo;
|
||||||
|
bool memManagerSuccess = true;
|
||||||
// char *inOutArg;
|
// char *inOutArg;
|
||||||
command = workingMeta->command;
|
command = workingMeta->command;
|
||||||
argument = workingMeta->strArg1;
|
argument = workingMeta->strArg1;
|
||||||
intArg = workingMeta->intArg2;
|
intArg = workingMeta->intArg2;
|
||||||
intArgTwo = workingMeta->intArg3;
|
intArgTwo = workingMeta->intArg3;
|
||||||
// inOutArg = workingMeta->inOutArg;
|
// inOutArg = workingMeta->inOutArg;
|
||||||
while (!(compareString(command, "app") == EQUIV && compareString(argument, "end") == EQUIV) && !(compareString(command, "sys") == EQUIV && compareString(argument, "end") == EQUIV))
|
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
|
// check to see what operation will be performed
|
||||||
if (compareString(command, "cpu") == EQUIV && compareString(argument, "process") == EQUIV)
|
if (compareString(command, "cpu") == EQUIV && compareString(argument, "process") == EQUIV)
|
||||||
|
|
@ -652,14 +668,26 @@ void runProcess(ProcessControlBlock *singlePCB, ConfigDataType *configPtr, Proce
|
||||||
sprintf(processOutput, "%f, Process: %d, %s %s request (%d, %d)\n", accessTimer(LAP_TIMER, timeStringy), singlePCB->uniquePid, command, argument, intArg, intArgTwo);
|
sprintf(processOutput, "%f, Process: %d, %s %s request (%d, %d)\n", accessTimer(LAP_TIMER, timeStringy), singlePCB->uniquePid, command, argument, intArg, intArgTwo);
|
||||||
logOutput(configPtr, processOutput, false);
|
logOutput(configPtr, processOutput, false);
|
||||||
// run the memory manager in allocate mode
|
// run the memory manager in allocate mode
|
||||||
memManager(pcbList, MEMORY_ALLOCATE, intArg, intArgTwo, configPtr, singlePCB);
|
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);
|
||||||
|
logOutput(configPtr, processOutput, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if(compareString(argument, "access") == EQUIV)
|
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);
|
sprintf(processOutput, "%f, Process: %d, %s %s request (%d, %d)\n", accessTimer(LAP_TIMER, timeStringy), singlePCB->uniquePid, command, argument, intArg, intArgTwo);
|
||||||
logOutput(configPtr, processOutput, false);
|
logOutput(configPtr, processOutput, false);
|
||||||
// run the memory manager in access mode
|
// run the memory manager in access mode
|
||||||
memManager(pcbList, MEMORY_ACCESS, intArg, intArgTwo, configPtr, singlePCB);
|
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);
|
||||||
|
logOutput(configPtr, processOutput, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
workingMeta = workingMeta->nextNode;
|
workingMeta = workingMeta->nextNode;
|
||||||
|
|
@ -668,9 +696,19 @@ void runProcess(ProcessControlBlock *singlePCB, ConfigDataType *configPtr, Proce
|
||||||
intArg = workingMeta->intArg2;
|
intArg = workingMeta->intArg2;
|
||||||
intArgTwo = workingMeta->intArg3;
|
intArgTwo = workingMeta->intArg3;
|
||||||
}
|
}
|
||||||
// display the process exited
|
// display the process exited, if not segfaulted.
|
||||||
|
if(memManagerSuccess)
|
||||||
|
{
|
||||||
|
//
|
||||||
sprintf(processOutput, "\n%f, OS: Process %d ended\n", accessTimer(LAP_TIMER, timeStringy), singlePCB->uniquePid);
|
sprintf(processOutput, "\n%f, OS: Process %d ended\n", accessTimer(LAP_TIMER, timeStringy), singlePCB->uniquePid);
|
||||||
logOutput(configPtr, processOutput, false);
|
logOutput(configPtr, processOutput, false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//
|
||||||
|
sprintf(processOutput, "\n%f, OS: Segmentation Fault, Process %d ended\n", accessTimer(LAP_TIMER, timeStringy), singlePCB->uniquePid);
|
||||||
|
logOutput(configPtr, processOutput, false);
|
||||||
|
}
|
||||||
// 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);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue