Started scheduleProcess function, will pick up later.

+- simulator.c
This commit is contained in:
Charles Descamps 2024-02-21 01:07:16 -07:00
parent a946ea2c1c
commit fa99b171f9
3 changed files with 74 additions and 15 deletions

Binary file not shown.

View file

@ -87,10 +87,10 @@ ProcessControlBlock *destroyProcessListHelper(ProcessControlBlock *nodePtr)
/* /*
Name: fillProcessList Name: fillProcessList
Process: iterates through the metadata LL, fills out each process as needed. Process: iterates through the metadata LL, fills out each process as needed.
(Linking is left to the calling function, returns a pointer to the filled struct) Function Input/Parameters: metadata (OpCodeType *),
Function Input/Parameters: metadata (OpCodeType *) headPointer (ProcessControlBlockLL *)
Function Output/Parameters: none Function Output/Parameters: none
Function Output/Returned: pointer to filled PCB (ProcessControlBlock *) Function Output/Returned: pointer to filled PCB (ProcessControlBlockLL *)
Device Input/Device: none Device Input/Device: none
Device Output/Device: none Device Output/Device: none
Dependencies: ??? Dependencies: ???
@ -224,8 +224,8 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr)
// currentTime variable that stores the time. [now unsure if needed] // currentTime variable that stores the time. [now unsure if needed]
// need a variable for headPointer to point // need a variable for headPointer to point
ProcessControlBlockLL *pcbList; ProcessControlBlockLL *pcbList;
// string variable for nextCode // string variable for nextCode, temp unused
char *nextCode; // char *nextCode;
// create the process list with createProcessList, store the pointed to address // create the process list with createProcessList, store the pointed to address
pcbList = createProcessList(); pcbList = createProcessList();
// fill the process list given the metadata // fill the process list given the metadata
@ -263,6 +263,52 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr)
// void function, no return. // void function, no return.
} }
/*
Name: scheduleProcess
Process: takes in the scheduling data, and then returns which process is to be ran
Function Input/Parameters: head pointer of PCB List (ProcessControlBlockLL *),
configuration data (ConfigDataType *)
Function Output/Parameters: none
Function Output/Returned: none
Device Input/Device: none
Device Output/Device: none
Dependencies: ???
*/
int scheduleProcess(ProcessControlBlockLL *headPointer, ConfigDataType *configPtr)
{
int returnPid = -1;
// switch case for each scheduling algorithm
switch (configPtr->cpuSchedCode)
{
case CPU_SCHED_FCFS_N_CODE:
// 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.
// 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
break;
case CPU_SCHED_FCFS_P_CODE:
// TODO: First Come, First Served, Preemptive Scheduling
break;
case CPU_SCHED_RR_P_CODE:
// TODO: Round Robin Scheduling
break;
case CPU_SCHED_SJF_N_CODE:
// TODO: Shortest Job First Scheduling
break;
case CPU_SCHED_SRTF_P_CODE:
// TODO: Shortest Run-time First Scheduling
break;
}
// return returnPid
return returnPid;
}
/*
Current Note to programmer: do the scheduler, the runIO and runCPU functions, and then the FILE IO functions
this is all that is left so far, hopefully not too bad.
*/
// getNextProcess/scheduler/dispatcher run here, loads/"runs" the process // getNextProcess/scheduler/dispatcher run here, loads/"runs" the process
// getNextOpCode, not needed for Sim02 apparently, keep in mind. // getNextOpCode, not needed for Sim02 apparently, keep in mind.
// checkForIO, I think this gets passed the current process and runs the IO ops // checkForIO, I think this gets passed the current process and runs the IO ops

View file

@ -133,9 +133,10 @@ ProcessControlBlock *destroyProcessListHelper(ProcessControlBlock *nodePtr);
/* /*
Name: fillProcessList Name: fillProcessList
Process: iterates through the metadata LL, fills out each process as needed. Process: iterates through the metadata LL, fills out each process as needed.
Function Input/Parameters: metadata (OpCodeType *) Function Input/Parameters: metadata (OpCodeType *),
headPointer (ProcessControlBlockLL *)
Function Output/Parameters: none Function Output/Parameters: none
Function Output/Returned: none Function Output/Returned: pointer to filled PCB (ProcessControlBlockLL *)
Device Input/Device: none Device Input/Device: none
Device Output/Device: none Device Output/Device: none
Dependencies: ??? Dependencies: ???
@ -155,4 +156,16 @@ Dependencies: ???
*/ */
void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr); void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr);
/*
Name: scheduleProcess
Process: takes in the scheduling data, and then returns which process is to be ran
Function Input/Parameters: head pointer of PCB List (ProcessControlBlockLL *)
Function Output/Parameters: none
Function Output/Returned: none
Device Input/Device: none
Device Output/Device: none
Dependencies: ???
*/
int scheduleProcess(ProcessControlBlockLL *headPointer, ConfigDataType *configPtr);
#endif // SIMULATORX #endif // SIMULATORX