SJF Scheduling is incomplete, and does not work past a certain point.

Trying to figure out how not to break FCFS while working on SJF.
+- simulator.c
This commit is contained in:
Charles Descamps 2024-03-13 16:28:20 -07:00
parent 7035f119a8
commit 0b6d2d0b0c
3 changed files with 52 additions and 17 deletions

View file

@ -4,3 +4,4 @@ ate
ate ate

Binary file not shown.

View file

@ -429,6 +429,8 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr)
// string variable for the timer stuff // string variable for the timer stuff
char simulatorOutput[MAX_STR_LEN]; char simulatorOutput[MAX_STR_LEN];
char timeStringy[MAX_STR_LEN]; char timeStringy[MAX_STR_LEN];
int processCount = 0;
int processIterator;
accessTimer(ZERO_TIMER, timeStringy); accessTimer(ZERO_TIMER, timeStringy);
// Operating System start timer goes here, log it. // Operating System start timer goes here, log it.
@ -443,12 +445,13 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr)
pcbList = fillProcessList(configPtr, metaDataMstrPtr, pcbList); pcbList = fillProcessList(configPtr, metaDataMstrPtr, pcbList);
pcbPtr = pcbList->headPtr; pcbPtr = pcbList->headPtr;
// calculate pcb total time // calculate pcb total time, number of processes
int totalPCBTime = 0; int totalPCBTime = 0;
while(pcbPtr != NULL) while(pcbPtr != NULL)
{ {
totalPCBTime = totalPCBTime + pcbPtr->timeLeft; totalPCBTime = totalPCBTime + pcbPtr->timeLeft;
pcbPtr = pcbPtr->nextPtr; pcbPtr = pcbPtr->nextPtr;
processCount = processCount + 1;
} }
pcbPtr = pcbList->headPtr; pcbPtr = pcbList->headPtr;
@ -461,6 +464,35 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr)
// set the current process id to the first scheduled process // set the current process id to the first scheduled process
currentPid = scheduleProcess(pcbList, configPtr); currentPid = scheduleProcess(pcbList, configPtr);
// loop until current process is hit // loop until current process is hit
// while(pcbPtr->process_state != PROCESS_STATE_TERMINATED && pcbPtr != NULL && processCount != 0)
// {
// if(pcbPtr->uniquePid == currentPid)
// {
// // 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);
// logOutput(configPtr, simulatorOutput, false);
// pthread_t runThread;
// pthread_create(&runThread, NULL, (void *)&simThread, (void *)processTimeLeft);
// runProcess(pcbPtr, configPtr);
// // 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);
// logOutput(configPtr, simulatorOutput, false);
// pcbPtr->process_state = PROCESS_STATE_TERMINATED;
// processCount = processCount - 1;
// pthread_join(runThread, NULL);
// }
// processTimeLeft = pcbPtr->timeLeft;
// pcbPtr = pcbPtr->nextPtr;
// currentPid = scheduleProcess(pcbList, configPtr);
// if(configPtr->cpuSchedCode == CPU_SCHED_SJF_N_CODE && pcbPtr == NULL)
// {
// //
// pcbPtr = pcbList->headPtr;
// }
// }
for(processIterator = 0; processIterator < processCount; processIterator++)
{
while (pcbPtr != NULL) while (pcbPtr != NULL)
{ {
if (pcbPtr->uniquePid == currentPid) if (pcbPtr->uniquePid == currentPid)
@ -480,7 +512,9 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr)
} }
processTimeLeft = pcbPtr->timeLeft; processTimeLeft = pcbPtr->timeLeft;
pcbPtr = pcbPtr->nextPtr; pcbPtr = pcbPtr->nextPtr;
}
currentPid = scheduleProcess(pcbList, configPtr); currentPid = scheduleProcess(pcbList, configPtr);
pcbPtr = pcbList->headPtr;
} }
pthread_join(cpuThread, NULL); pthread_join(cpuThread, NULL);
sprintf(simulatorOutput, "%f, OS: System Stop\n", accessTimer(LAP_TIMER, timeStringy)); sprintf(simulatorOutput, "%f, OS: System Stop\n", accessTimer(LAP_TIMER, timeStringy));