Debugging fillProcessBlock functions, trying to figure out where memleaks are.

+- simulator.c
This commit is contained in:
Charles Descamps 2024-02-21 13:36:15 -07:00
parent fa99b171f9
commit 672c26a5c7
3 changed files with 62 additions and 12 deletions

Binary file not shown.

View file

@ -5,19 +5,36 @@
/*
Name: addProcess
Process: adds a process to the
Function Input/Parameters: none
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: head pointer to the PCBs
Function Output/Returned: filled PCB (ProcessControlBlock *)
Device Input/Device: none
Device Output/Device: none
Dependencies: malloc, sizeof, fillProcessList
Dependencies: malloc, sizeof, ???
*/
// ProcessControlBlock *addProcess()
// {
// // return NULL (temp)
// return NULL;
// }
ProcessControlBlock *addProcess(const ProcessControlBlock source)
{
ProcessControlBlock *workingNode;
workingNode = malloc(sizeof(ProcessControlBlock));
workingNode->uniquePid = source.uniquePid;
workingNode->cpuCycles = source.cpuCycles;
workingNode->ioCycles = source.ioCycles;
workingNode->nextOpCode = source.nextOpCode;
workingNode->process_state = source.process_state;
workingNode->timeLeft = source.timeLeft;
workingNode->totalCycles = source.totalCycles;
workingNode->nextPtr = NULL;
printf("uniquePID: %d\n", workingNode->uniquePid);
printf("process state: %d\n", workingNode->process_state);
printf("io cycles: %d\n", workingNode->ioCycles);
printf("cpu cycles: %d\n", workingNode->cpuCycles);
printf("total cycles: %d\n", workingNode->totalCycles);
printf("time left in ms: %f\n\n", workingNode->timeLeft);
// return workingNode
return workingNode;
}
/*
Name: createProcessList
@ -188,6 +205,10 @@ ProcessControlBlockLL *fillProcessList(OpCodeType *metadataPtr, ProcessControlBl
currentPCB.timeLeft = timeLeftCount;
// increment the PID counter
processId = processId + 1;
ioCycleCount = 0;
cpuCycleCount = 0;
timeLeftCount = 0.0;
}
// move to the next bit of data
wkgMetaPtr = wkgMetaPtr->nextNode;
@ -196,8 +217,8 @@ ProcessControlBlockLL *fillProcessList(OpCodeType *metadataPtr, ProcessControlBl
// needs to add nodes to the end and all data once parsed
// do both the metadata and PCBs
wkgPCBPtr = &currentPCB;
wkgPCBPtr->nextPtr = NULL;
wkgPCBPtr = addProcess(currentPCB);
wkgPCBPtr = wkgPCBPtr->nextPtr;
}
// return null (temp) (should return the headpointer)
return headPointer;
@ -226,6 +247,8 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr)
ProcessControlBlockLL *pcbList;
// string variable for nextCode, temp unused
// char *nextCode;
// int variable for process to run
int currentPid;
// create the process list with createProcessList, store the pointed to address
pcbList = createProcessList();
// fill the process list given the metadata
@ -243,6 +266,7 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr)
// function holds master loop, loops until sys end opcode found OR wkgPtrMaster nextNode != NULL
while(wkgPtrMaster->nextNode != NULL || (compareString(argument, "end") && compareString(command, "sys")))
{
currentPid = scheduleProcess(pcbList, configPtr);
// will have a loop that goes from app start to app end for a PCB
// (checks to see if the next instruction is NOT app end), using getNextProcess?
// this will getNextOpCode
@ -259,7 +283,7 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr)
//
// deallocate the process list with destroyProcessList
destroyProcessList(pcbList);
//printf("runSim called here");
// once complete, log the output to FILE if required
// void function, no return.
}
@ -276,7 +300,9 @@ Dependencies: ???
*/
int scheduleProcess(ProcessControlBlockLL *headPointer, ConfigDataType *configPtr)
{
ProcessControlBlock *wkgPtr;
int returnPid = -1;
wkgPtr = headPointer->headPtr;
// switch case for each scheduling algorithm
switch (configPtr->cpuSchedCode)
{
@ -287,6 +313,19 @@ int scheduleProcess(ProcessControlBlockLL *headPointer, ConfigDataType *configPt
// will set the state to READY, return the pid of the process which
// was set to ready.
// ignores any process which has a state of TERMINATED
// printf("uniquePID: %d\n", wkgPtr->uniquePid);
// printf("process state: %d\n", wkgPtr->process_state);
// printf("io cycles: %d\n", wkgPtr->ioCycles);
// printf("cpu cycles: %d\n", wkgPtr->cpuCycles);
// printf("total cycles: %d\n", wkgPtr->totalCycles);
// printf("time left in ms: %f\n", wkgPtr->timeLeft);
// while(wkgPtr->nextPtr != NULL || wkgPtr->process_state == PROCESS_STATE_NEW)
// {
// //
// returnPid = wkgPtr->uniquePid;
// printf("%d was selected.\n", returnPid);
// wkgPtr = wkgPtr->nextPtr;
// }
break;
case CPU_SCHED_FCFS_P_CODE:
// TODO: First Come, First Served, Preemptive Scheduling

View file

@ -143,6 +143,17 @@ Dependencies: ???
*/
ProcessControlBlockLL *fillProcessList(OpCodeType *metadataPtr, ProcessControlBlockLL *headPointer);
/*
Name: logOutput
Process: Takes in a string, and then outputs it to monitor AND/OR file
Function Input/Parameters: string (char *), file pointer (FILE *)
Function Output/Parameters: none
Function Output/Returned: none
Device Input/Device: none
Device Output/Device: none
Dependencies: sprintf, ???
*/
/*
Name: runSim
Process: primary simulation driver