Esempio n. 1
0
/*===========================================================================*
 *				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;

	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;
}
Esempio n. 2
0
/*===========================================================================*
 *				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;
}
Esempio n. 3
0
/*===========================================================================*
 *                                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;
}