Compare commits
No commits in common. "5a747ab1dd1e6797a762ac0d727d2a80820acee9" and "b306a179d8679a958f96dc7f094988ddb655500a" have entirely different histories.
5a747ab1dd
...
b306a179d8
2 changed files with 87 additions and 16 deletions
|
|
@ -159,7 +159,18 @@ 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;
|
||||||
|
|
@ -203,14 +214,17 @@ 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;
|
||||||
|
|
@ -244,13 +258,16 @@ 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);
|
||||||
|
|
@ -263,18 +280,22 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -297,6 +318,14 @@ 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);
|
||||||
|
|
@ -304,6 +333,7 @@ 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);
|
||||||
|
|
@ -322,14 +352,19 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
@ -358,7 +393,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))
|
while (!(compareString(command, "app") == 0 && compareString(argument, "end") == 0)) // compareString(command, "cpu") == 0 && compareString(argument, "process") == 0
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
if (compareString(command, "cpu") == 0 && compareString(argument, "process") == 0)
|
if (compareString(command, "cpu") == 0 && compareString(argument, "process") == 0)
|
||||||
|
|
@ -423,6 +458,7 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
@ -440,8 +476,11 @@ 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);
|
||||||
|
|
@ -461,6 +500,8 @@ 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
|
||||||
|
|
@ -558,6 +599,22 @@ 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,6 +56,10 @@ 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: ???
|
||||||
|
|
@ -67,19 +71,28 @@ 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
|
||||||
Name: addProcess
|
// this could use a switch statement to tell which scheduling method to choose from.
|
||||||
Process: allocates the memory for the pcb, grabs the data from the created PCB,
|
// Sim02 only requires FCFS working atm.
|
||||||
dumps the data so that the node can be linked correctly.
|
|
||||||
Function Input/Parameters: source PCB (ProcessControlBlock)
|
// need a function called createProcessList
|
||||||
Function Output/Parameters: none
|
// this initializes the process control block ll.
|
||||||
Function Output/Returned: filled PCB (ProcessControlBlock *)
|
|
||||||
Device Input/Device: none
|
// need a function called fillProcessList
|
||||||
Device Output/Device: none
|
// this fills the linked list of PCBs,
|
||||||
Dependencies: malloc, sizeof, ???
|
// loads the first instruction after app start
|
||||||
*/
|
// 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
|
||||||
|
|
@ -154,7 +167,7 @@ Device Input/Device: none
|
||||||
Device Output/Device: none
|
Device Output/Device: none
|
||||||
Dependencies: ???
|
Dependencies: ???
|
||||||
*/
|
*/
|
||||||
void runCPU(char *command, char *argument, int intArg, ConfigDataType *configPtr, int processId);
|
void runCPU();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Name: runIO
|
Name: runIO
|
||||||
|
|
@ -166,7 +179,8 @@ Device Input/Device: none
|
||||||
Device Output/Device: none
|
Device Output/Device: none
|
||||||
Dependencies: ???
|
Dependencies: ???
|
||||||
*/
|
*/
|
||||||
void runIO(char *command, char *argument, int intArg, ConfigDataType *configPtr, int processId);
|
void runIO();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Name: runSim
|
Name: runSim
|
||||||
Process: primary simulation driver
|
Process: primary simulation driver
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue