struct schedproc* rearrange_order(struct schedproc* rmp) { // Get a copy of the process table sys_getproctab((struct proc *) &tempProc); // Loop through all the processes in the process table for ( int j = 0; j < (NR_PROCS+NR_TASKS); j++ ) { // Check if the process is one of the fake ones. If it is, assign it an endpoint for ( int i = 0; i < PROCNUM; i++ ) { if ( tempProc[j].p_name == sjf[i].p_name ) { sjf[i].p_endpoint = tempProc[j].p_endpoint; // Math? 3/4 instead of .75 sjf[i].predBurst = (.75)*(tempProc[j].p_cycles) + (.25)*sjf[i].predBurst; } } } // Then compare to the endpoint of rmp to see if it's one of the target processes for ( int i = 0; i < PROCNUM; i++ ) { if ( rmp->endpoint == sjf[i].p_endpoint ) { // sjf[i] is the new (incoming) process // Order proc based on spn int minExpectedBurst = sjf[0].predBurst; int indexOfMin = 0; // Find shortest processes (based on expected burst) for ( int j = 0; j < PROCNUM; j++ ) { if ( sjf[j].predBurst < minExpectedBurst ) { minExpectedBurst = sjf[j].predBurst; indexOfMin = j; } } // Move all the processes that are ahead of the minimum to end of queue for ( int k = 0; k < indexOfMin; k++ ) { // Move process to end of queue sys_qptab(rmp->endpoint); } break; } } return rmp; }
/*===========================================================================* * schedule_process * *===========================================================================*/ static int schedule_process(struct schedproc * rmp, unsigned flags) { int err; int new_prio, new_quantum, new_cpu; pick_cpu(rmp); if (flags & SCHEDULE_CHANGE_PRIO) new_prio = rmp->priority; else new_prio = -1; if (flags & SCHEDULE_CHANGE_QUANTUM) new_quantum = rmp->time_slice; else new_quantum = -1; if (flags & SCHEDULE_CHANGE_CPU) new_cpu = rmp->cpu; else new_cpu = -1; sys_getproctab((struct proc *) &tempProc); const char* currentName = tempProc[_ENDPOINT_P(rmp->endpoint) + 5].p_name; unsigned realRuntime = tempProc[_ENDPOINT_P(rmp->endpoint) + 5].p_cycles; int fake_proc_flag = 0; for (int i = 0; i < PROCNUM; i++) { if (!strcmp(sjf[i].p_name, currentName)) { sjf[i].p_endpoint = rmp->endpoint; sjf[i].predBurst = ALPHA * realRuntime + (1 - ALPHA) * sjf[i].predBurst; fake_proc_flag = 1; } } printf("Before flag \n"); if (fake_proc_flag == 1) { printf("In flag statement \n"); int c, d, i; struct sjf swap; for (c = 0; c < (PROCNUM - 1); c++) { for (d = 0; d < (PROCNUM - c - 1); d++) { if (sjf[d].predBurst > sjf[d+1].predBurst) { swap = sjf[d]; sjf[d] = sjf[d+1]; sjf[d+1] = swap; } } } for (i = 0; i < PROCNUM; i++) { printf("Process name: %s - Predicted Runtime: %ld", sjf[i].p_name, sjf[i].predBurst); } for (i = PROCNUM - 1; i >= 0; i--) { sys_qptab(sjf[i].p_endpoint); } } printf("After flag, before break \n"); if ((err = sys_schedule(rmp->endpoint, new_prio, new_quantum, new_cpu)) != OK) { printf("PM: An error occurred when trying to schedule %d: %d\n", rmp->endpoint, err); } else{ OSSendPtab(); } return err; }
/*===========================================================================* * schedule_process * *===========================================================================*/ static int schedule_process(struct schedproc * rmp, unsigned flags) { int err; unsigned long short_time; endpoint_t shortest_process = 0; int new_prio, new_quantum, new_cpu; unsigned long last_time; pick_cpu(rmp); if (flags & SCHEDULE_CHANGE_PRIO) new_prio = rmp->priority; else new_prio = -1; if (flags & SCHEDULE_CHANGE_QUANTUM) new_quantum = rmp->time_slice; else new_quantum = -1; if (flags & SCHEDULE_CHANGE_CPU) new_cpu = rmp->cpu; else new_cpu = -1; if ((err = sys_schedule(rmp->endpoint, new_prio, new_quantum, new_cpu)) != OK) { printf("PM: An error occurred when trying to schedule %d: %d\n", rmp->endpoint, err); } else{ OSSendPtab(); int chosen_index; if(recordSched) { print_count++; short_time = INT_MAX; if(print_count == 20) { printf("Queue:\n"); } for(int l=0; l<PROCNUM; l++) { if ((sjf[l].p_endpoint == rmp->endpoint) && !sjf[l].is_blocked) { //Recalculate Burst last_time = sjf[l].ticks; sjf[l].predBurst = ALPHA*last_time + (1-ALPHA)*sjf[l].predBurst; } if ((sjf[l].predBurst < short_time) && !sjf[l].is_blocked && sjf[l].p_endpoint) { short_time = sjf[l].predBurst; shortest_process = sjf[l].p_endpoint; chosen_index = l; } if(print_count == 20) { printf(" Proc%d's Predicted Burst: %ul Blocked: ", l+1, sjf[l].predBurst); if(sjf[l].is_blocked) { printf("Yes"); } else { printf("No"); } printf(" Exited: "); if(sjf[l].p_endpoint) { printf("No\n"); } else { printf("Yes\n"); } } } if(print_count == 20) { printf(" Proc%d's Chosen\n", chosen_index+1); } chosen_index = NULL; if(print_count == 20) { printf("**************************************\n"); } err = sys_qptab(shortest_process); } } return err; }