Compare commits
2 commits
b306a179d8
...
5a747ab1dd
| Author | SHA1 | Date | |
|---|---|---|---|
| 5a747ab1dd | |||
| e76f2971de |
2 changed files with 16 additions and 87 deletions
|
|
@ -159,18 +159,7 @@ ProcessControlBlockLL *fillProcessList(ConfigDataType *configPtr, OpCodeType *me
|
||||||
// set the nextOpCode as a pointer to the first place metadataPtr started
|
// set the nextOpCode as a pointer to the first place metadataPtr started
|
||||||
currentPCB.nextOpCode = wkgMetaPtr->nextNode;
|
currentPCB.nextOpCode = wkgMetaPtr->nextNode;
|
||||||
}
|
}
|
||||||
//
|
|
||||||
// count number of io cycles
|
// 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)
|
if(compareString(command, "dev") == 0)
|
||||||
{
|
{
|
||||||
integerArgumentOne = wkgMetaPtr->intArg2;
|
integerArgumentOne = wkgMetaPtr->intArg2;
|
||||||
|
|
@ -214,17 +203,14 @@ ProcessControlBlockLL *fillProcessList(ConfigDataType *configPtr, OpCodeType *me
|
||||||
// do both the metadata and PCBs
|
// do both the metadata and PCBs
|
||||||
if(headPointer->headPtr == NULL)
|
if(headPointer->headPtr == NULL)
|
||||||
{
|
{
|
||||||
//
|
|
||||||
headPointer->headPtr = addProcess(currentPCB);
|
headPointer->headPtr = addProcess(currentPCB);
|
||||||
wkgPCBPtr = headPointer->headPtr;
|
wkgPCBPtr = headPointer->headPtr;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//
|
|
||||||
wkgPCBPtr->nextPtr = addProcess(currentPCB);
|
wkgPCBPtr->nextPtr = addProcess(currentPCB);
|
||||||
wkgPCBPtr = wkgPCBPtr->nextPtr;
|
wkgPCBPtr = wkgPCBPtr->nextPtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// move to the next bit of data
|
// move to the next bit of data
|
||||||
wkgMetaPtr = wkgMetaPtr->nextNode;
|
wkgMetaPtr = wkgMetaPtr->nextNode;
|
||||||
|
|
@ -258,16 +244,13 @@ void logOutput(ConfigDataType *configPtr, char *logStr, bool isEnd)
|
||||||
fileWritePtr = fopen(configPtr->logToFileName, "w");
|
fileWritePtr = fopen(configPtr->logToFileName, "w");
|
||||||
if (fileWritePtr != NULL)
|
if (fileWritePtr != NULL)
|
||||||
{
|
{
|
||||||
//
|
|
||||||
fprintf(fileWritePtr, "%s", logStr);
|
fprintf(fileWritePtr, "%s", logStr);
|
||||||
// fputs(fileWritePtr, logStr);
|
|
||||||
fprintf(stdout, "%s", logStr);
|
fprintf(stdout, "%s", logStr);
|
||||||
}
|
}
|
||||||
// no return, void
|
// no return, void
|
||||||
// close the file, if at the end.
|
// close the file, if at the end.
|
||||||
if (isEnd)
|
if (isEnd)
|
||||||
{
|
{
|
||||||
//
|
|
||||||
fclose(fileWritePtr);
|
fclose(fileWritePtr);
|
||||||
}
|
}
|
||||||
// fclose(fileWritePtr);
|
// fclose(fileWritePtr);
|
||||||
|
|
@ -280,22 +263,18 @@ void logOutput(ConfigDataType *configPtr, char *logStr, bool isEnd)
|
||||||
fileWritePtr = fopen(configPtr->logToFileName, "w");
|
fileWritePtr = fopen(configPtr->logToFileName, "w");
|
||||||
if (fileWritePtr != NULL)
|
if (fileWritePtr != NULL)
|
||||||
{
|
{
|
||||||
//
|
|
||||||
fprintf(fileWritePtr, "%s", logStr);
|
fprintf(fileWritePtr, "%s", logStr);
|
||||||
// fputs(fileWritePtr, logStr);
|
|
||||||
}
|
}
|
||||||
// no return, void
|
// no return, void
|
||||||
// close the file, if at the end.
|
// close the file, if at the end.
|
||||||
if (isEnd)
|
if (isEnd)
|
||||||
{
|
{
|
||||||
//
|
|
||||||
fclose(fileWritePtr);
|
fclose(fileWritePtr);
|
||||||
}
|
}
|
||||||
// fclose(fileWritePtr);
|
// fclose(fileWritePtr);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//
|
|
||||||
fprintf(stdout, "%s", logStr);
|
fprintf(stdout, "%s", logStr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -318,14 +297,6 @@ void runCPU(char *command, char *argument, int intArg, ConfigDataType *configPtr
|
||||||
// int intArg = workingMeta->intArg2;
|
// int intArg = workingMeta->intArg2;
|
||||||
char cpuOutput[MAX_STR_LEN];
|
char cpuOutput[MAX_STR_LEN];
|
||||||
int cpuTime = 0;
|
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;
|
cpuTime = intArg * configPtr->procCycleRate;
|
||||||
sprintf(cpuOutput, "%f, Process: %d, %s %s operation start\n", accessTimer(LAP_TIMER, timeStringy), processId, command, argument);
|
sprintf(cpuOutput, "%f, Process: %d, %s %s operation start\n", accessTimer(LAP_TIMER, timeStringy), processId, command, argument);
|
||||||
logOutput(configPtr, cpuOutput, false);
|
logOutput(configPtr, cpuOutput, false);
|
||||||
|
|
@ -333,7 +304,6 @@ void runCPU(char *command, char *argument, int intArg, ConfigDataType *configPtr
|
||||||
pthread_t cpuThread;
|
pthread_t cpuThread;
|
||||||
pthread_create(&cpuThread, NULL, (void *)&simThread, (void *)cpuTime);
|
pthread_create(&cpuThread, NULL, (void *)&simThread, (void *)cpuTime);
|
||||||
pthread_join(cpuThread, NULL);
|
pthread_join(cpuThread, NULL);
|
||||||
//
|
|
||||||
sprintf(cpuOutput, "%f, Process: %d, %s %s operation end\n", accessTimer(LAP_TIMER, timeStringy), processId, command, argument);
|
sprintf(cpuOutput, "%f, Process: %d, %s %s operation end\n", accessTimer(LAP_TIMER, timeStringy), processId, command, argument);
|
||||||
logOutput(configPtr, cpuOutput, false);
|
logOutput(configPtr, cpuOutput, false);
|
||||||
// pthread_exit(NULL);
|
// pthread_exit(NULL);
|
||||||
|
|
@ -352,19 +322,14 @@ Dependencies: ???
|
||||||
void runIO(char *command, char *argument, int intArg, ConfigDataType *configPtr, int processId)
|
void runIO(char *command, char *argument, int intArg, ConfigDataType *configPtr, int processId)
|
||||||
{
|
{
|
||||||
char timeStringy[MAX_STR_LEN];
|
char timeStringy[MAX_STR_LEN];
|
||||||
// char *command = workingMeta->command;
|
|
||||||
// char *argument = workingMeta->strArg1;
|
|
||||||
// int intArg = workingMeta->intArg2;
|
|
||||||
char ioOutput[MAX_STR_LEN];
|
char ioOutput[MAX_STR_LEN];
|
||||||
int ioTime = 0;
|
int ioTime = 0;
|
||||||
ioTime = intArg * configPtr->ioCycleRate;
|
ioTime = intArg * configPtr->ioCycleRate;
|
||||||
sprintf(ioOutput, "%f, Process: %d, %s %s operation start\n", accessTimer(LAP_TIMER, timeStringy), processId, command, argument);
|
sprintf(ioOutput, "%f, Process: %d, %s %s operation start\n", accessTimer(LAP_TIMER, timeStringy), processId, command, argument);
|
||||||
logOutput(configPtr, ioOutput, false);
|
logOutput(configPtr, ioOutput, false);
|
||||||
// run timer for intArg * procCycleRate
|
|
||||||
pthread_t ioThread;
|
pthread_t ioThread;
|
||||||
pthread_create(&ioThread, NULL, (void *)&simThread, (void *)ioTime);
|
pthread_create(&ioThread, NULL, (void *)&simThread, (void *)ioTime);
|
||||||
pthread_join(ioThread, NULL);
|
pthread_join(ioThread, NULL);
|
||||||
//
|
|
||||||
sprintf(ioOutput, "%f, Process: %d, %s %s operation end\n", accessTimer(LAP_TIMER, timeStringy), processId, command, argument);
|
sprintf(ioOutput, "%f, Process: %d, %s %s operation end\n", accessTimer(LAP_TIMER, timeStringy), processId, command, argument);
|
||||||
logOutput(configPtr, ioOutput, false);
|
logOutput(configPtr, ioOutput, false);
|
||||||
}
|
}
|
||||||
|
|
@ -393,7 +358,7 @@ void runProcess(ProcessControlBlock *singlePCB, ConfigDataType *configPtr)
|
||||||
argument = workingMeta->strArg1;
|
argument = workingMeta->strArg1;
|
||||||
intArg = workingMeta->intArg2;
|
intArg = workingMeta->intArg2;
|
||||||
inOutArg = workingMeta->inOutArg;
|
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)
|
if (compareString(command, "cpu") == 0 && compareString(argument, "process") == 0)
|
||||||
|
|
@ -458,7 +423,6 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr)
|
||||||
int totalPCBTime = 0;
|
int totalPCBTime = 0;
|
||||||
while(pcbPtr != NULL)
|
while(pcbPtr != NULL)
|
||||||
{
|
{
|
||||||
//
|
|
||||||
totalPCBTime = totalPCBTime + pcbPtr->timeLeft;
|
totalPCBTime = totalPCBTime + pcbPtr->timeLeft;
|
||||||
pcbPtr = pcbPtr->nextPtr;
|
pcbPtr = pcbPtr->nextPtr;
|
||||||
}
|
}
|
||||||
|
|
@ -476,11 +440,8 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr)
|
||||||
// loop until current process is hit
|
// loop until current process is hit
|
||||||
while(pcbPtr != NULL)
|
while(pcbPtr != NULL)
|
||||||
{
|
{
|
||||||
//
|
|
||||||
if(pcbPtr->uniquePid == currentPid)
|
if(pcbPtr->uniquePid == currentPid)
|
||||||
{
|
{
|
||||||
//
|
|
||||||
// printf("Process %d running\n", 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_READY;
|
||||||
sprintf(simulatorOutput, "%f, OS: Process %d set to RUNNING state from READY state\n", accessTimer(LAP_TIMER, timeStringy), pcbPtr->uniquePid);
|
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;
|
pcbPtr = pcbPtr->nextPtr;
|
||||||
currentPid = scheduleProcess(pcbList, configPtr);
|
currentPid = scheduleProcess(pcbList, configPtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// deallocate the process list with destroyProcessList
|
// deallocate the process list with destroyProcessList
|
||||||
destroyProcessList(pcbList);
|
destroyProcessList(pcbList);
|
||||||
// once complete, log the output to FILE if required
|
// once complete, log the output to FILE if required
|
||||||
|
|
@ -599,22 +558,6 @@ Dependencies: ???
|
||||||
*/
|
*/
|
||||||
void *simThread(int milSec)
|
void *simThread(int milSec)
|
||||||
{
|
{
|
||||||
//
|
|
||||||
// int *milSecPtr = (int *)milSec;
|
|
||||||
// printf("Running Timer for %d ms, %d sec\n", milSec, milSec / 1000);
|
|
||||||
runTimer(milSec);
|
runTimer(milSec);
|
||||||
// printf("Ran Timer\n");
|
|
||||||
pthread_exit(NULL);
|
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)
|
|
||||||
|
|
@ -56,10 +56,6 @@ Device Input/Device: none
|
||||||
Device Output/Device: none
|
Device Output/Device: none
|
||||||
Dependencies: ???
|
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: ???
|
Name: ???
|
||||||
|
|
@ -71,28 +67,19 @@ Device Input/Device: none
|
||||||
Device Output/Device: none
|
Device Output/Device: none
|
||||||
Dependencies: ???
|
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.
|
Name: addProcess
|
||||||
// Sim02 only requires FCFS working atm.
|
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.
|
||||||
// need a function called createProcessList
|
Function Input/Parameters: source PCB (ProcessControlBlock)
|
||||||
// this initializes the process control block ll.
|
Function Output/Parameters: none
|
||||||
|
Function Output/Returned: filled PCB (ProcessControlBlock *)
|
||||||
// need a function called fillProcessList
|
Device Input/Device: none
|
||||||
// this fills the linked list of PCBs,
|
Device Output/Device: none
|
||||||
// loads the first instruction after app start
|
Dependencies: malloc, sizeof, ???
|
||||||
// and ...
|
*/
|
||||||
|
ProcessControlBlock *addProcess(const ProcessControlBlock source);
|
||||||
// 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: createProcessList
|
Name: createProcessList
|
||||||
|
|
@ -167,7 +154,7 @@ Device Input/Device: none
|
||||||
Device Output/Device: none
|
Device Output/Device: none
|
||||||
Dependencies: ???
|
Dependencies: ???
|
||||||
*/
|
*/
|
||||||
void runCPU();
|
void runCPU(char *command, char *argument, int intArg, ConfigDataType *configPtr, int processId);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Name: runIO
|
Name: runIO
|
||||||
|
|
@ -179,8 +166,7 @@ Device Input/Device: none
|
||||||
Device Output/Device: none
|
Device Output/Device: none
|
||||||
Dependencies: ???
|
Dependencies: ???
|
||||||
*/
|
*/
|
||||||
void runIO();
|
void runIO(char *command, char *argument, int intArg, ConfigDataType *configPtr, int processId);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Name: runSim
|
Name: runSim
|
||||||
Process: primary simulation driver
|
Process: primary simulation driver
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue