Cleaned up Sim02's mess. Can look at previous commits to figure out what is going on.

+- simulator.c/h
This commit is contained in:
Charles Descamps 2024-02-22 05:31:32 -07:00
parent e76f2971de
commit 5a747ab1dd
2 changed files with 14 additions and 84 deletions

View file

@ -159,18 +159,7 @@ ProcessControlBlockLL *fillProcessList(ConfigDataType *configPtr, OpCodeType *me
// set the nextOpCode as a pointer to the first place metadataPtr started
currentPCB.nextOpCode = wkgMetaPtr->nextNode;
}
//
// count number of io cycles
// if ((compareString(command, "dev") == 0 && compareString(inOutArg, "in") == 0))
// {
// integerArgumentOne = wkgMetaPtr->intArg2;
// ioCycleCount = ioCycleCount + integerArgumentOne;
// }
// if ((compareString(command, "dev") == 0 && compareString(inOutArg, "out") == 0))
// {
// integerArgumentOne = wkgMetaPtr->intArg2;
// ioCycleCount = ioCycleCount + integerArgumentOne;
// }
if(compareString(command, "dev") == 0)
{
integerArgumentOne = wkgMetaPtr->intArg2;
@ -214,17 +203,14 @@ ProcessControlBlockLL *fillProcessList(ConfigDataType *configPtr, OpCodeType *me
// do both the metadata and PCBs
if(headPointer->headPtr == NULL)
{
//
headPointer->headPtr = addProcess(currentPCB);
wkgPCBPtr = headPointer->headPtr;
}
else
{
//
wkgPCBPtr->nextPtr = addProcess(currentPCB);
wkgPCBPtr = wkgPCBPtr->nextPtr;
}
}
// move to the next bit of data
wkgMetaPtr = wkgMetaPtr->nextNode;
@ -258,16 +244,13 @@ void logOutput(ConfigDataType *configPtr, char *logStr, bool isEnd)
fileWritePtr = fopen(configPtr->logToFileName, "w");
if (fileWritePtr != NULL)
{
//
fprintf(fileWritePtr, "%s", logStr);
// fputs(fileWritePtr, logStr);
fprintf(stdout, "%s", logStr);
}
// no return, void
// close the file, if at the end.
if (isEnd)
{
//
fclose(fileWritePtr);
}
// fclose(fileWritePtr);
@ -280,22 +263,18 @@ void logOutput(ConfigDataType *configPtr, char *logStr, bool isEnd)
fileWritePtr = fopen(configPtr->logToFileName, "w");
if (fileWritePtr != NULL)
{
//
fprintf(fileWritePtr, "%s", logStr);
// fputs(fileWritePtr, logStr);
}
// no return, void
// close the file, if at the end.
if (isEnd)
{
//
fclose(fileWritePtr);
}
// fclose(fileWritePtr);
}
else
{
//
fprintf(stdout, "%s", logStr);
}
}
@ -318,14 +297,6 @@ void runCPU(char *command, char *argument, int intArg, ConfigDataType *configPtr
// int intArg = workingMeta->intArg2;
char cpuOutput[MAX_STR_LEN];
int cpuTime = 0;
// pthread_t cpuThread;
// pthread_create(&cpuThread, NULL, (void *)&simThread, (void *)cpuTime);
// pthread_join(cpuThread, NULL);
//
// printf("%f is the time for runCPU\n", accessTimer(LAP_TIMER, timeStringy));
//
//
//
cpuTime = intArg * configPtr->procCycleRate;
sprintf(cpuOutput, "%f, Process: %d, %s %s operation start\n", accessTimer(LAP_TIMER, timeStringy), processId, command, argument);
logOutput(configPtr, cpuOutput, false);
@ -333,7 +304,6 @@ void runCPU(char *command, char *argument, int intArg, ConfigDataType *configPtr
pthread_t cpuThread;
pthread_create(&cpuThread, NULL, (void *)&simThread, (void *)cpuTime);
pthread_join(cpuThread, NULL);
//
sprintf(cpuOutput, "%f, Process: %d, %s %s operation end\n", accessTimer(LAP_TIMER, timeStringy), processId, command, argument);
logOutput(configPtr, cpuOutput, false);
// pthread_exit(NULL);
@ -352,19 +322,14 @@ Dependencies: ???
void runIO(char *command, char *argument, int intArg, ConfigDataType *configPtr, int processId)
{
char timeStringy[MAX_STR_LEN];
// char *command = workingMeta->command;
// char *argument = workingMeta->strArg1;
// int intArg = workingMeta->intArg2;
char ioOutput[MAX_STR_LEN];
int ioTime = 0;
ioTime = intArg * configPtr->ioCycleRate;
sprintf(ioOutput, "%f, Process: %d, %s %s operation start\n", accessTimer(LAP_TIMER, timeStringy), processId, command, argument);
logOutput(configPtr, ioOutput, false);
// run timer for intArg * procCycleRate
pthread_t ioThread;
pthread_create(&ioThread, NULL, (void *)&simThread, (void *)ioTime);
pthread_join(ioThread, NULL);
//
sprintf(ioOutput, "%f, Process: %d, %s %s operation end\n", accessTimer(LAP_TIMER, timeStringy), processId, command, argument);
logOutput(configPtr, ioOutput, false);
}
@ -393,7 +358,7 @@ void runProcess(ProcessControlBlock *singlePCB, ConfigDataType *configPtr)
argument = workingMeta->strArg1;
intArg = workingMeta->intArg2;
inOutArg = workingMeta->inOutArg;
while (!(compareString(command, "app") == 0 && compareString(argument, "end") == 0)) // compareString(command, "cpu") == 0 && compareString(argument, "process") == 0
while (!(compareString(command, "app") == 0 && compareString(argument, "end") == 0))
{
//
if (compareString(command, "cpu") == 0 && compareString(argument, "process") == 0)
@ -458,7 +423,6 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr)
int totalPCBTime = 0;
while(pcbPtr != NULL)
{
//
totalPCBTime = totalPCBTime + pcbPtr->timeLeft;
pcbPtr = pcbPtr->nextPtr;
}
@ -476,11 +440,8 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr)
// loop until current process is hit
while(pcbPtr != NULL)
{
//
if(pcbPtr->uniquePid == currentPid)
{
//
// printf("Process %d running\n", currentPid);
// needs to set from READY to RUNNING
pcbPtr->process_state = PROCESS_STATE_READY;
sprintf(simulatorOutput, "%f, OS: Process %d set to RUNNING state from READY state\n", accessTimer(LAP_TIMER, timeStringy), pcbPtr->uniquePid);
@ -500,8 +461,6 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr)
pcbPtr = pcbPtr->nextPtr;
currentPid = scheduleProcess(pcbList, configPtr);
}
//
// deallocate the process list with destroyProcessList
destroyProcessList(pcbList);
// once complete, log the output to FILE if required
@ -599,22 +558,6 @@ Dependencies: ???
*/
void *simThread(int milSec)
{
//
// int *milSecPtr = (int *)milSec;
// printf("Running Timer for %d ms, %d sec\n", milSec, milSec / 1000);
runTimer(milSec);
// printf("Ran Timer\n");
pthread_exit(NULL);
}
/*
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
// getNextOpCode, not needed for Sim02 apparently, keep in mind.
// checkForIO, I think this gets passed the current process and runs the IO ops
// checkForCPU, I think this gets passed the current process and runs the CPU ops
// checkForMemory, I think this gets passed the current process
// and runs mem ops (not needed for Sim02)
// cpuIdler (not needed for Sim02)

View file

@ -56,10 +56,6 @@ Device Input/Device: none
Device Output/Device: none
Dependencies: ???
*/
// need a function (or functions) to handle FILE I/O?
// runSim function will have a FILE *
// will have a function that gets the FILE * and
// adds whatever operation occurred
/*
Name: ???
@ -71,28 +67,19 @@ Device Input/Device: none
Device Output/Device: none
Dependencies: ???
*/
// need a function for the global/local timer (given??? may need to just import)
// need a function for scheduler/dispatcher
// this could use a switch statement to tell which scheduling method to choose from.
// Sim02 only requires FCFS working atm.
// need a function called createProcessList
// this initializes the process control block ll.
// need a function called fillProcessList
// this fills the linked list of PCBs,
// loads the first instruction after app start
// and ...
// reads through the opcode struct to fill out the linked list of PCBs
// need a function called destroyProcessList
// deallocated the ll of PCBs recursively, frees the rest of the struct.
// have a function to change the state of the process?
// have it take in the process struct, switch it's state and report that it
// has switched FROM a state TO a different state.
/*
Name: addProcess
Process: allocates the memory for the pcb, grabs the data from the created PCB,
dumps the data so that the node can be linked correctly.
Function Input/Parameters: source PCB (ProcessControlBlock)
Function Output/Parameters: none
Function Output/Returned: filled PCB (ProcessControlBlock *)
Device Input/Device: none
Device Output/Device: none
Dependencies: malloc, sizeof, ???
*/
ProcessControlBlock *addProcess(const ProcessControlBlock source);
/*
Name: createProcessList