Starting work on Simulator 3, SJF works-ish...
+- config0.cnf (SJF mode) +- simulator.c/h +- sim03
This commit is contained in:
parent
90c3f8cc3f
commit
7035f119a8
5 changed files with 87 additions and 8 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
Start Simulator Configuration File:
|
Start Simulator Configuration File:
|
||||||
Version/Phase : 1.05
|
Version/Phase : 1.05
|
||||||
File Path : metadata5.mdf
|
File Path : metadata5.mdf
|
||||||
CPU Scheduling Code : FCFS-N
|
CPU Scheduling Code : SJF-N
|
||||||
Quantum Time (cycles) : 3
|
Quantum Time (cycles) : 3
|
||||||
Memory Available (KB) : 11100
|
Memory Available (KB) : 11100
|
||||||
Memory Display (On/Off) : On
|
Memory Display (On/Off) : On
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
0.000000, OS: Simulator start
|
0.000001, OS: Simulator start
|
||||||
READY state from NEW state
|
READY state from NEW state
|
||||||
ate
|
ate
|
||||||
|
|
||||||
ate
|
ate
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
BIN
Sim03/sim03
Executable file
BIN
Sim03/sim03
Executable file
Binary file not shown.
|
|
@ -227,6 +227,27 @@ ProcessControlBlockLL *fillProcessList(ConfigDataType *configPtr, OpCodeType *me
|
||||||
return headPointer;
|
return headPointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Name: findMin
|
||||||
|
Process: compares two values, returns the smaller of the two.
|
||||||
|
Function Input/Parameters: two integer values (int)
|
||||||
|
Function Output/Parameters: none
|
||||||
|
Function Output/Returned: minimum of the two input integer values (int)
|
||||||
|
Device Input/Device: none
|
||||||
|
Device Output/Device: none
|
||||||
|
Dependencies: none
|
||||||
|
*/
|
||||||
|
int findMin(int one, int another)
|
||||||
|
{
|
||||||
|
int minimumVal = one;
|
||||||
|
if(another < minimumVal)
|
||||||
|
{
|
||||||
|
minimumVal = another;
|
||||||
|
}
|
||||||
|
// return zero(temp)
|
||||||
|
return minimumVal;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Name: logOutput
|
Name: logOutput
|
||||||
Process: Takes in a string, and then outputs it to monitor AND/OR file
|
Process: Takes in a string, and then outputs it to monitor AND/OR file
|
||||||
|
|
@ -445,7 +466,7 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr)
|
||||||
if(pcbPtr->uniquePid == currentPid)
|
if(pcbPtr->uniquePid == currentPid)
|
||||||
{
|
{
|
||||||
// needs to set from READY to RUNNING
|
// needs to set from READY to RUNNING
|
||||||
pcbPtr->process_state = PROCESS_STATE_READY;
|
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);
|
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);
|
logOutput(configPtr, simulatorOutput, false);
|
||||||
pthread_t runThread;
|
pthread_t runThread;
|
||||||
|
|
@ -497,7 +518,6 @@ int scheduleProcess(ProcessControlBlockLL *headPointer, ConfigDataType *configPt
|
||||||
{
|
{
|
||||||
case CPU_SCHED_FCFS_N_CODE:
|
case CPU_SCHED_FCFS_N_CODE:
|
||||||
// First Come, First Served, Non-preemptive Scheduling
|
// First Come, First Served, Non-preemptive Scheduling
|
||||||
// only one implemented for now. returns first process without fail.
|
|
||||||
// need to find whichever process is first, AND the state is NEW.
|
// need to find whichever process is first, AND the state is NEW.
|
||||||
// will set the state to READY, return the pid of the process which
|
// will set the state to READY, return the pid of the process which
|
||||||
// was set to ready.
|
// was set to ready.
|
||||||
|
|
@ -506,7 +526,7 @@ int scheduleProcess(ProcessControlBlockLL *headPointer, ConfigDataType *configPt
|
||||||
while(wkgPtr != NULL)
|
while(wkgPtr != NULL)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
if(wkgPtr->process_state != PROCESS_STATE_READY && wkgPtr->process_state != PROCESS_STATE_TERMINATED)
|
if(wkgPtr->process_state == PROCESS_STATE_NEW)
|
||||||
{
|
{
|
||||||
// set the process within the PCB to the ready state, report in ready state.
|
// set the process within the PCB to the ready state, report in ready state.
|
||||||
wkgPtr->process_state = PROCESS_STATE_READY;
|
wkgPtr->process_state = PROCESS_STATE_READY;
|
||||||
|
|
@ -523,7 +543,7 @@ int scheduleProcess(ProcessControlBlockLL *headPointer, ConfigDataType *configPt
|
||||||
while(wkgPtr != NULL && (returnPid == -1))
|
while(wkgPtr != NULL && (returnPid == -1))
|
||||||
{
|
{
|
||||||
// check if the process is NOT terminated
|
// check if the process is NOT terminated
|
||||||
if (wkgPtr->process_state == PROCESS_STATE_READY)
|
if (wkgPtr->process_state != PROCESS_STATE_RUNNING && wkgPtr->process_state != PROCESS_STATE_TERMINATED)
|
||||||
{
|
{
|
||||||
//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), wkgPtr->uniquePid, wkgPtr->timeLeft);
|
sprintf(loggingStr, "%f, OS: Process %d selected with %.0f ms remaining\n", accessTimer(LAP_TIMER, timeStringy), wkgPtr->uniquePid, wkgPtr->timeLeft);
|
||||||
|
|
@ -541,7 +561,55 @@ int scheduleProcess(ProcessControlBlockLL *headPointer, ConfigDataType *configPt
|
||||||
// TODO: Round Robin Scheduling
|
// TODO: Round Robin Scheduling
|
||||||
break;
|
break;
|
||||||
case CPU_SCHED_SJF_N_CODE:
|
case CPU_SCHED_SJF_N_CODE:
|
||||||
// TODO: Shortest Job First Scheduling
|
// Shortest Job First Scheduling
|
||||||
|
// need to find shortest job, maybe using a find min function?
|
||||||
|
// reuse the previous code to set each process to READY from NEW
|
||||||
|
// will select the process that is in the READY state, with the shortest time.
|
||||||
|
int shortestJob = 0;
|
||||||
|
int shortestJobProcNum = 0;
|
||||||
|
while (wkgPtr != NULL)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
if (wkgPtr->process_state == PROCESS_STATE_NEW)
|
||||||
|
{
|
||||||
|
// set the process within the PCB to the ready state, report in ready state.
|
||||||
|
wkgPtr->process_state = PROCESS_STATE_READY;
|
||||||
|
// printf("Process %d set to READY from NEW\n", wkgPtr->uniquePid);
|
||||||
|
sprintf(loggingStr, "%f, OS: Process %d set to READY state from NEW state\n", accessTimer(LAP_TIMER, timeStringy), wkgPtr->uniquePid);
|
||||||
|
logOutput(configPtr, loggingStr, false);
|
||||||
|
}
|
||||||
|
// move to the next pointer
|
||||||
|
wkgPtr = wkgPtr->nextPtr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// reset the pointer to get ready for selection of process
|
||||||
|
wkgPtr = headPointer->headPtr;
|
||||||
|
// load in the first process time
|
||||||
|
shortestJob = wkgPtr->timeLeft;
|
||||||
|
// move to the next pointer.
|
||||||
|
wkgPtr = wkgPtr->nextPtr;
|
||||||
|
while (wkgPtr != NULL && (returnPid == -1))
|
||||||
|
{
|
||||||
|
// check if the process is NOT terminated
|
||||||
|
// now, ALSO needs to check which process takes the least time.
|
||||||
|
if (wkgPtr->process_state != PROCESS_STATE_RUNNING && wkgPtr->process_state != PROCESS_STATE_TERMINATED)
|
||||||
|
{
|
||||||
|
// check to see if the working pointer job is shorter than the current shortest job
|
||||||
|
shortestJob = findMin(shortestJob, wkgPtr->timeLeft);
|
||||||
|
// check to see if the shortest job time changed, if it did, change the process number
|
||||||
|
if(shortestJob == wkgPtr->timeLeft)
|
||||||
|
{
|
||||||
|
// change process number, or leave it unchanged.
|
||||||
|
shortestJobProcNum = wkgPtr->uniquePid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// move to next pointer
|
||||||
|
wkgPtr = wkgPtr->nextPtr;
|
||||||
|
}
|
||||||
|
// 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);
|
||||||
|
logOutput(configPtr, loggingStr, false);
|
||||||
|
returnPid = shortestJobProcNum;
|
||||||
break;
|
break;
|
||||||
case CPU_SCHED_SRTF_P_CODE:
|
case CPU_SCHED_SRTF_P_CODE:
|
||||||
// TODO: Shortest Run-time First Scheduling
|
// TODO: Shortest Run-time First Scheduling
|
||||||
|
|
|
||||||
|
|
@ -131,6 +131,18 @@ Dependencies: ???
|
||||||
*/
|
*/
|
||||||
ProcessControlBlockLL *fillProcessList(ConfigDataType *configPtr, OpCodeType *metadataPtr, ProcessControlBlockLL *headPointer);
|
ProcessControlBlockLL *fillProcessList(ConfigDataType *configPtr, OpCodeType *metadataPtr, ProcessControlBlockLL *headPointer);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Name: findMin
|
||||||
|
Process: compares two values, returns the smaller of the two.
|
||||||
|
Function Input/Parameters: two integer values (int)
|
||||||
|
Function Output/Parameters: none
|
||||||
|
Function Output/Returned: minimum of the two input integer values (int)
|
||||||
|
Device Input/Device: none
|
||||||
|
Device Output/Device: none
|
||||||
|
Dependencies: none
|
||||||
|
*/
|
||||||
|
int findMin(int one, int another);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Name: logOutput
|
Name: logOutput
|
||||||
Process: Takes in a string, and then outputs it to monitor AND/OR file
|
Process: Takes in a string, and then outputs it to monitor AND/OR file
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue