Skip to content
Snippets Groups Projects
Commit 65e89a87 authored by Elizabeth Baker's avatar Elizabeth Baker
Browse files

"RUNNING" time fiddles

parent 3dd0834f
Branches
No related tags found
No related merge requests found
...@@ -20,7 +20,7 @@ typedef struct { ...@@ -20,7 +20,7 @@ typedef struct {
int timeRemaining; int timeRemaining;
int subProcsRunning; int subProcsRunning;
int justStarted; int justStarted;
int deltaTime; int startTime;
} process; } process;
typedef struct { typedef struct {
...@@ -111,11 +111,7 @@ int main(int argc, char *argv[]) { ...@@ -111,11 +111,7 @@ int main(int argc, char *argv[]) {
//while (fgets(line, sizeof line, f) != NULL) { //while (fgets(line, sizeof line, f) != NULL) {
while (newProcess = getNextProcessB(f, arrivalLounge, readAhead)) { while (newProcess = getNextProcessB(f, arrivalLounge, readAhead)) {
//printf("process id:%s process arrival time: %d\n", newProcess->processID, newProcess->timeArrived);
deltaTime = newProcess->timeArrived - currentTime; deltaTime = newProcess->timeArrived - currentTime;
//update currentTime //update currentTime
currentTime += deltaTime; currentTime += deltaTime;
...@@ -167,9 +163,6 @@ int main(int argc, char *argv[]) { ...@@ -167,9 +163,6 @@ int main(int argc, char *argv[]) {
} }
numProcessesLeft += 1; numProcessesLeft += 1;
llist_push(paralellizedProcesses, newProcess); llist_push(paralellizedProcesses, newProcess);
} else {
printf("Error in test file ");
exit(1);
} }
// Log started processes. // Log started processes.
for (int j = 0; j < numCPU; j++) { for (int j = 0; j < numCPU; j++) {
...@@ -177,9 +170,9 @@ int main(int argc, char *argv[]) { ...@@ -177,9 +170,9 @@ int main(int argc, char *argv[]) {
//next process in queue started //next process in queue started
if (headProcess != NULL && headProcess->justStarted) { if (headProcess != NULL && headProcess->justStarted) {
// printf("current time: %d\n", currentTime); // printf("current time: %d\n", currentTime);
printf("%d,RUNNING,pid=%s,remaining_time=%d,cpu=%d - AAAA line 181\n",
headProcess->startTime, headProcess->processID, headProcess->timeRemaining, j);
headProcess->justStarted = 0; headProcess->justStarted = 0;
printf("%d,RUNNING,pid=%s,remaining_time=%d,cpu=%d - AAAA line 184\n",
currentTime + headProcess->deltaTime, headProcess->processID, headProcess->timeRemaining, j);
} }
} }
...@@ -223,13 +216,13 @@ int main(int argc, char *argv[]) { ...@@ -223,13 +216,13 @@ int main(int argc, char *argv[]) {
//next process in queue started //next process in queue started
if (headProcess != NULL && headProcess->justStarted) { if (headProcess != NULL && headProcess->justStarted) {
// printf("current time: %d\n", currentTime); // printf("current time: %d\n", currentTime);
headProcess->justStarted = 0;
printf("%d,RUNNING,pid=%s,remaining_time=%d,cpu=%d\n", printf("%d,RUNNING,pid=%s,remaining_time=%d,cpu=%d\n",
currentTime, headProcess->processID, headProcess->timeRemaining, j); headProcess->startTime, headProcess->processID, headProcess->timeRemaining, j);
headProcess->justStarted = 0;
} }
} }
// currentTime += deltaTime; // currentTime += startTime;
} }
// printf("Completed Queue:"); // printf("Completed Queue:");
// llist_print(completedProcesses, (void (*)(void *)) &printQEntry); // llist_print(completedProcesses, (void (*)(void *)) &printQEntry);
...@@ -293,9 +286,10 @@ void initializeProcess(char data[], process *newProcess) { ...@@ -293,9 +286,10 @@ void initializeProcess(char data[], process *newProcess) {
if (token != NULL) { if (token != NULL) {
newProcess->parallelisable = token[0]; newProcess->parallelisable = token[0];
} }
newProcess->deltaTime =0; newProcess->startTime = 0;
newProcess->timeCompleted = -1; newProcess->timeCompleted = -1;
newProcess->timeRemaining = newProcess->executionTime; newProcess->timeRemaining = newProcess->executionTime;
newProcess->justStarted = 0;
} }
process *headData(llist *q) { process *headData(llist *q) {
...@@ -333,12 +327,11 @@ void advanceProcessQueue(llist *processQueue, int currentTime, int deltaTime, ll ...@@ -333,12 +327,11 @@ void advanceProcessQueue(llist *processQueue, int currentTime, int deltaTime, ll
while (headProcess != NULL && deltaTime != 0) { while (headProcess != NULL && deltaTime != 0) {
if (deltaTime >= headProcess->timeRemaining) { // Process has finished if (deltaTime >= headProcess->timeRemaining) { // Process has finished
deltaTime -= headProcess->timeRemaining; deltaTime -= headProcess->timeRemaining;
headProcess->timeCompleted = currentTime - deltaTime; //+ headProcess->timeRemaining; headProcess->timeCompleted = currentTime - deltaTime;
// int t = headProcess->timeRemaining;
headProcess->timeRemaining = 0; headProcess->timeRemaining = 0;
if (headProcess->parallelisable == 'p') { if (headProcess->parallelisable == 'p') {
//printf("process had finished, and was a paralized subprocess\n"); //printf("process had finished, and was a paralized subprocess\n");
parentPid[0] = strtok(headProcess->processID, ".");//todo to get rid of warning strncopy parentPid[0] = strtok(headProcess->processID, ".");
paralizedProcess = parallelParent(paralellProcesses, parentPid); paralizedProcess = parallelParent(paralellProcesses, parentPid);
paralizedProcess->subProcsRunning -= 1; paralizedProcess->subProcsRunning -= 1;
if (paralizedProcess->subProcsRunning == 0) { if (paralizedProcess->subProcsRunning == 0) {
...@@ -346,10 +339,10 @@ void advanceProcessQueue(llist *processQueue, int currentTime, int deltaTime, ll ...@@ -346,10 +339,10 @@ void advanceProcessQueue(llist *processQueue, int currentTime, int deltaTime, ll
// parallelized process has completed. // parallelized process has completed.
*numProcessesLeft -= 1; *numProcessesLeft -= 1;
*numProcessComplete += 1; *numProcessComplete += 1;
paralizedProcess->timeCompleted = currentTime - deltaTime;//todo error on calculation here paralizedProcess->timeCompleted = currentTime - deltaTime;
paralizedProcess->timeRemaining = 0; paralizedProcess->timeRemaining = 0;
headProcess->timeRemaining = 0; headProcess->timeRemaining = 0;
//printf("process had finished: Current time: %d, deltaTime: %d\n", currentTime, deltaTime); //printf("process had finished: Current time: %d, startTime: %d\n", currentTime, startTime);
printf("%d,FINISHED,pid=%s,proc_remaining=%d\n", printf("%d,FINISHED,pid=%s,proc_remaining=%d\n",
paralizedProcess->timeCompleted, paralizedProcess->processID, *numProcessesLeft); paralizedProcess->timeCompleted, paralizedProcess->processID, *numProcessesLeft);
// Could accumulate statistics here instead of keeping list of completed processes // Could accumulate statistics here instead of keeping list of completed processes
...@@ -359,7 +352,7 @@ void advanceProcessQueue(llist *processQueue, int currentTime, int deltaTime, ll ...@@ -359,7 +352,7 @@ void advanceProcessQueue(llist *processQueue, int currentTime, int deltaTime, ll
headProcess = headData(processQueue); headProcess = headData(processQueue);
if (headProcess){ if (headProcess){
headProcess->justStarted = -1; headProcess->justStarted = -1;
headProcess->deltaTime = deltaTime; headProcess->startTime = currentTime - deltaTime;
} }
} else { // finishedprocess is not parallelisable } else { // finishedprocess is not parallelisable
...@@ -373,13 +366,12 @@ void advanceProcessQueue(llist *processQueue, int currentTime, int deltaTime, ll ...@@ -373,13 +366,12 @@ void advanceProcessQueue(llist *processQueue, int currentTime, int deltaTime, ll
headProcess = headData(processQueue); headProcess = headData(processQueue);
if (headProcess){ if (headProcess){
headProcess->justStarted = -1; headProcess->justStarted = -1;
headProcess->deltaTime = deltaTime; headProcess->startTime = currentTime - deltaTime;
} }
} }
} else { // head process not finished } else { // head process not finished
headProcess->timeRemaining -= deltaTime; headProcess->timeRemaining -= deltaTime;
headProcess->deltaTime = deltaTime;
deltaTime = 0; deltaTime = 0;
// llist_print( processQueue, (void (*)(void *)) &printQEntry ); // llist_print( processQueue, (void (*)(void *)) &printQEntry );
} }
...@@ -420,8 +412,11 @@ void addProcessToQueue(llist *processQueue, process *newProcess, int currentTime ...@@ -420,8 +412,11 @@ void addProcessToQueue(llist *processQueue, process *newProcess, int currentTime
process *headProcess; process *headProcess;
llist_add_inorder(newProcess, processQueue, (int (*)(void *, void *)) &leastTimeRemaining); llist_add_inorder(newProcess, processQueue, (int (*)(void *, void *)) &leastTimeRemaining);
headProcess = headData(processQueue); headProcess = headData(processQueue);
if (strncmp(headProcess->processID, newProcess->processID, sizeof (newProcess->processID))) // llist_print(processQueue, (void (*)(void *)) &printQEntry);
if (strncmp(headProcess->processID, newProcess->processID, sizeof (newProcess->processID))) {
headProcess->justStarted = -1; headProcess->justStarted = -1;
headProcess->startTime = currentTime;
}
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment