diff --git a/code/scheduler.c b/code/scheduler.c index 0c87195..c615e69 100644 --- a/code/scheduler.c +++ b/code/scheduler.c @@ -17,6 +17,9 @@ process_t *currentProcess = NULL; perfStats stats; int semid; + +bool started; +bool terminated; /** * main - The main function of the scheduler. * @@ -98,6 +101,10 @@ void schedule(scheduler_type schType, int quantem, int gen_msgQID) { quantemClk = getClk(); int lastClk = quantemClk; + started = 0; + terminated = 0; + bool WasRunning = 0; + while (1) { currentClk = getClk(); @@ -110,7 +117,15 @@ void schedule(scheduler_type schType, int quantem, int gen_msgQID) { printf(ANSI_GREY "========================================\n" ANSI_RESET); printf(ANSI_BLUE "==>SCH: Current Clk = %i\n" ANSI_RESET, currentClk); + if(started || WasRunning){ + stats.totalWorkingTime++; + } + + started =0; + terminated =0; + if (currentProcess) { + WasRunning = 1; int remTime = getRemTime(currentProcess); if(remTime > 0){ printf(ANSI_BLUE "==>SCH:" ANSI_GREEN " Process %d " ANSI_BOLD @@ -118,6 +133,9 @@ void schedule(scheduler_type schType, int quantem, int gen_msgQID) { currentProcess->id, remTime); } } + else{ + WasRunning = 0; + } } newProcess = NULL; @@ -138,6 +156,10 @@ void schedule(scheduler_type schType, int quantem, int gen_msgQID) { rQuantem = quantem; } + if(currentClk!=lastClk){ + + } + lastClk = currentClk; } @@ -420,6 +442,7 @@ void startProcess(process_t *process) { process->WT = getClk() - process->AT; + started =1; // log this logger("started", process); kill(process->pid, SIGCONT); @@ -460,6 +483,8 @@ void resumeProcess(process_t *process) { kill(process->pid, SIGCONT); process->state = RUNNING; + started =1; + // log this logger("resumed", process); } @@ -492,6 +517,8 @@ void sigUsr1Handler(int signum) { int status; killedProcess = wait(&status); + terminated = 1; + currentProcess->TA = getClk() - currentProcess->AT; logger("finished", currentProcess); @@ -533,7 +560,6 @@ void logger(char *msg, process_t *p) { fprintf(logFileptr, " TA %i WTA %.2f", p->TA, WTA); stats.WTAs[stats.numFinished] = WTA; stats.numFinished += 1; - stats.totalWorkingTime += p->BT; stats.totalWaitingTime += p->WT; stats.totalWTA += WTA; } diff --git a/code/scheduler.log b/code/scheduler.log index 041ec96..b13f3fa 100644 --- a/code/scheduler.log +++ b/code/scheduler.log @@ -1,6 +1,20 @@ -At time 3 process 3 started arr 3 total 3 remain 3 wait 0 -At time 6 process 3 finished arr 3 total 3 remain 0 wait 0 TA 3 WTA 1.00 -At time 6 process 2 started arr 3 total 2 remain 2 wait 3 -At time 8 process 2 finished arr 3 total 2 remain 0 wait 3 TA 5 WTA 2.50 -At time 8 process 1 started arr 3 total 1 remain 1 wait 5 -At time 9 process 1 finished arr 3 total 1 remain 0 wait 5 TA 6 WTA 6.00 +At time 6 process 1 started arr 6 total 1 remain 1 wait 0 +At time 7 process 1 finished arr 6 total 1 remain 0 wait 0 TA 1 WTA 1.00 +At time 16 process 2 started arr 16 total 2 remain 2 wait 0 +At time 18 process 2 finished arr 16 total 2 remain 0 wait 0 TA 2 WTA 1.00 +At time 18 process 3 started arr 17 total 11 remain 11 wait 1 +At time 29 process 3 finished arr 17 total 11 remain 0 wait 1 TA 12 WTA 1.09 +At time 29 process 4 started arr 28 total 1 remain 1 wait 1 +At time 30 process 4 finished arr 28 total 1 remain 0 wait 1 TA 2 WTA 2.00 +At time 30 process 5 started arr 29 total 23 remain 23 wait 1 +At time 53 process 5 finished arr 29 total 23 remain 0 wait 1 TA 24 WTA 1.04 +At time 53 process 8 started arr 51 total 4 remain 4 wait 2 +At time 57 process 8 finished arr 51 total 4 remain 0 wait 2 TA 6 WTA 1.50 +At time 57 process 6 started arr 34 total 4 remain 4 wait 23 +At time 61 process 6 finished arr 34 total 4 remain 0 wait 23 TA 27 WTA 6.75 +At time 61 process 10 started arr 56 total 17 remain 17 wait 5 +At time 78 process 10 finished arr 56 total 17 remain 0 wait 5 TA 22 WTA 1.29 +At time 78 process 9 started arr 52 total 21 remain 21 wait 26 +At time 99 process 9 finished arr 52 total 21 remain 0 wait 26 TA 47 WTA 2.24 +At time 99 process 7 started arr 44 total 24 remain 24 wait 55 +At time 123 process 7 finished arr 44 total 24 remain 0 wait 55 TA 79 WTA 3.29 diff --git a/code/scheduler.perf b/code/scheduler.perf index 8f2cdd6..f046bce 100644 --- a/code/scheduler.perf +++ b/code/scheduler.perf @@ -1,4 +1,4 @@ -CPU utilization = 66.67% -Avg WTA = 3.17 -Avg Waiting = 2.67 -Std WTA = 4.39 +CPU utilization = 87.80% +Avg WTA = 2.12 +Avg Waiting = 11.40 +Std WTA = 2.86