Finished with SJF Scheduling, minus one tiny bug. Otherwise, memory operations can be started on.
This commit is contained in:
parent
0b6d2d0b0c
commit
eb87c7f9b9
3 changed files with 34 additions and 2 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.
|
|
@ -495,7 +495,10 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr)
|
||||||
{
|
{
|
||||||
while (pcbPtr != NULL)
|
while (pcbPtr != NULL)
|
||||||
{
|
{
|
||||||
if (pcbPtr->uniquePid == currentPid)
|
// printf("Current Process Number is: %d\n", pcbPtr->uniquePid);
|
||||||
|
// printf("Process Status is: %d\n", pcbPtr->process_state);
|
||||||
|
// printf("Scheduled Process is: %d\n", currentPid);
|
||||||
|
if (pcbPtr->process_state != PROCESS_STATE_TERMINATED && pcbPtr->uniquePid == currentPid)
|
||||||
{
|
{
|
||||||
// needs to set from READY to RUNNING
|
// needs to set from READY to RUNNING
|
||||||
pcbPtr->process_state = PROCESS_STATE_RUNNING;
|
pcbPtr->process_state = PROCESS_STATE_RUNNING;
|
||||||
|
|
@ -547,6 +550,19 @@ int scheduleProcess(ProcessControlBlockLL *headPointer, ConfigDataType *configPt
|
||||||
wkgPtr = headPointer->headPtr;
|
wkgPtr = headPointer->headPtr;
|
||||||
char loggingStr[MAX_STR_LEN];
|
char loggingStr[MAX_STR_LEN];
|
||||||
char timeStringy[MAX_STR_LEN];
|
char timeStringy[MAX_STR_LEN];
|
||||||
|
int processCount = 0;
|
||||||
|
|
||||||
|
while (wkgPtr != NULL)
|
||||||
|
{
|
||||||
|
if(wkgPtr->process_state != PROCESS_STATE_TERMINATED)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
processCount = processCount + 1;
|
||||||
|
}
|
||||||
|
wkgPtr = wkgPtr->nextPtr;
|
||||||
|
}
|
||||||
|
wkgPtr = headPointer->headPtr;
|
||||||
|
|
||||||
// switch case for each scheduling algorithm
|
// switch case for each scheduling algorithm
|
||||||
switch (configPtr->cpuSchedCode)
|
switch (configPtr->cpuSchedCode)
|
||||||
{
|
{
|
||||||
|
|
@ -640,6 +656,22 @@ int scheduleProcess(ProcessControlBlockLL *headPointer, ConfigDataType *configPt
|
||||||
// move to next pointer
|
// move to next pointer
|
||||||
wkgPtr = wkgPtr->nextPtr;
|
wkgPtr = wkgPtr->nextPtr;
|
||||||
}
|
}
|
||||||
|
// check the number of processes, if there is one left, then
|
||||||
|
wkgPtr = headPointer->headPtr;
|
||||||
|
if(processCount == 1)
|
||||||
|
{
|
||||||
|
// find the last process that is READY but not TERMINATED, set it's PID as the return.
|
||||||
|
while(wkgPtr != NULL)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
if (wkgPtr->process_state != PROCESS_STATE_TERMINATED)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
shortestJobProcNum = wkgPtr->uniquePid;
|
||||||
|
}
|
||||||
|
wkgPtr = wkgPtr->nextPtr;
|
||||||
|
}
|
||||||
|
}
|
||||||
// printf("Process %d Selected with %.0f ms remaining\n", wkgPtr->uniquePid, wkgPtr->timeLeft);
|
// printf("Process %d Selected with %.0f ms remaining\n", wkgPtr->uniquePid, wkgPtr->timeLeft);
|
||||||
sprintf(loggingStr, "%f, OS: Process %d selected with %.0f ms remaining\n", accessTimer(LAP_TIMER, timeStringy), shortestJobProcNum, (double)shortestJob);
|
sprintf(loggingStr, "%f, OS: Process %d selected with %.0f ms remaining\n", accessTimer(LAP_TIMER, timeStringy), shortestJobProcNum, (double)shortestJob);
|
||||||
logOutput(configPtr, loggingStr, false);
|
logOutput(configPtr, loggingStr, false);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue