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:
parent
7035f119a8
commit
0b6d2d0b0c
3 changed files with 52 additions and 17 deletions
|
|
@ -429,6 +429,8 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr)
|
|||
// string variable for the timer stuff
|
||||
char simulatorOutput[MAX_STR_LEN];
|
||||
char timeStringy[MAX_STR_LEN];
|
||||
int processCount = 0;
|
||||
int processIterator;
|
||||
|
||||
accessTimer(ZERO_TIMER, timeStringy);
|
||||
// Operating System start timer goes here, log it.
|
||||
|
|
@ -443,12 +445,13 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr)
|
|||
pcbList = fillProcessList(configPtr, metaDataMstrPtr, pcbList);
|
||||
pcbPtr = pcbList->headPtr;
|
||||
|
||||
// calculate pcb total time
|
||||
// calculate pcb total time, number of processes
|
||||
int totalPCBTime = 0;
|
||||
while(pcbPtr != NULL)
|
||||
{
|
||||
totalPCBTime = totalPCBTime + pcbPtr->timeLeft;
|
||||
pcbPtr = pcbPtr->nextPtr;
|
||||
processCount = processCount + 1;
|
||||
}
|
||||
pcbPtr = pcbList->headPtr;
|
||||
|
||||
|
|
@ -461,26 +464,57 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr)
|
|||
// set the current process id to the first scheduled process
|
||||
currentPid = scheduleProcess(pcbList, configPtr);
|
||||
// loop until current process is hit
|
||||
while(pcbPtr != NULL)
|
||||
// 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++)
|
||||
{
|
||||
if(pcbPtr->uniquePid == currentPid)
|
||||
while (pcbPtr != NULL)
|
||||
{
|
||||
// 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;
|
||||
pthread_join(runThread, NULL);
|
||||
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;
|
||||
pthread_join(runThread, NULL);
|
||||
}
|
||||
processTimeLeft = pcbPtr->timeLeft;
|
||||
pcbPtr = pcbPtr->nextPtr;
|
||||
}
|
||||
processTimeLeft = pcbPtr->timeLeft;
|
||||
pcbPtr = pcbPtr->nextPtr;
|
||||
currentPid = scheduleProcess(pcbList, configPtr);
|
||||
pcbPtr = pcbList->headPtr;
|
||||
}
|
||||
pthread_join(cpuThread, NULL);
|
||||
sprintf(simulatorOutput, "%f, OS: System Stop\n", accessTimer(LAP_TIMER, timeStringy));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue