Esempio n. 1
0
/*------------------------------------------------------------------------
 * insert.c  --  insert an process into a q list in key order
 *------------------------------------------------------------------------
 */
int insert(int proc, int head, int key)
{
	int	next;			/* runs through list		*/
	int	prev;

	if(getschedclass()==0 || getschedclass() == 2){
	next = q[head].qnext;
	
	while (q[next].qkey < key){	/* tail has maxint as key	*/
		next = q[next].qnext;
		
		}
	q[proc].qnext = next;
	q[proc].qprev = prev = q[next].qprev;
	q[proc].qkey  = key;
	q[prev].qnext = proc;
	q[next].qprev = proc;
	return(OK);
	}
	else if(getschedclass()==1){

	//now we are in the other function so here we will insert the process using enqueue so we can use it like a FiFo]
		
		enqueue(proc,tname(queuedecider(proc)));
		return(OK);		
	}
}
Esempio n. 2
0
/*------------------------------------------------------------------------
 * chprio  --  change the scheduling priority of a process
 *------------------------------------------------------------------------
 */
SYSCALL chprio(int pid, int newprio)
{
	STATWORD ps;    
	struct	pentry	*pptr;

	disable(ps);
	if (isbadpid(pid) || newprio<=0 ||
	    (pptr = &proctab[pid])->pstate == PRFREE) {
		restore(ps);
		return(SYSERR);
	}
	pptr->pprio = newprio;
	// If we are currently using the aging scheduler...
	if (getschedclass() == AGINGSCHED) {
		// We want to updated the queue priority now
		// (the linux-like scheduler will do that itself)
		q[pid].qkey = newprio;
		// If this priority is in the ready queue...
		if (isinqueue(pid, rdyhead)) {
			// Then we need to remove it from the queue
			dequeue(pid);
			// And put it back in so that the queue
			// will remain sorted
			insert(pid, rdyhead, newprio);
		}
	}
	restore(ps);
	return(newprio);
}
/*-----------------------------------------------------------------------
 * resched  --  reschedule processor to highest priority ready process
 *
 * Notes:	Upon entry, currpid gives current process id.
 *		Proctab[currpid].pstate gives correct NEXT state for
 *			current process if other than PRREADY.
 *------------------------------------------------------------------------
 */
int resched() {
	switch (getschedclass()) {
	case LINUXSCHED:
		return Linux_22_Scheduling();
	case MULTIQSCHED:
		return Multiqueue_Scheduling();
	default:
		return Xinu_Default_Scheduling();
	}
	return OK;

}
Esempio n. 4
0
/*------------------------------------------------------------------------
 * ready  --  make a process eligible for CPU service
 *------------------------------------------------------------------------
 */
int ready(int pid, int resch)
{
	register struct	pentry	*pptr;

	if (isbadpid(pid))
		return(SYSERR);
	pptr = &proctab[pid];
	pptr->pstate = PRREADY;
	//change the insert here.
	if(getschedclass()==2){
		insert(pid,rdyhead,pptr->goodness);
		//what if I enqueue this from tail, but max is also in tail..
	
	}else{
	insert(pid,rdyhead,pptr->pprio);
	}
	if (resch)
		resched();
	return(OK);
}
Esempio n. 5
0
/*------------------------------------------------------------------------
 * chprio  --  change the scheduling priority of a process
 *------------------------------------------------------------------------
 */
SYSCALL chprio(int pid, int newprio)
{
    STATWORD ps;    
    struct  pentry  *pptr;

    disable(ps);
    if (isbadpid(pid) || newprio<=0 ||
        (pptr = &proctab[pid])->pstate == PRFREE) {
        restore(ps);
        return(SYSERR);
    }
    pptr->pprio = newprio;

    // If we are doing exponential scheduling then
    // we need to change the processes order in the 
    // ready queue. 
    if ((getschedclass() == EXPDISTSCHED) && (pid != currpid)) {
        dequeue(pid);
        insert(pid, rdyhead, newprio);
    }
    restore(ps);
    return(newprio);
}
Esempio n. 6
0
int main() {
	srand(1);
	int i;
	int count = 0;
	char buf[8];
	double total_cnt;
	double a_percent, b_percent, c_percent, d_percent;

	kprintf(
			"\n\n########## Test Case1, linux-like scheduling basic(2 processes):\n");
	setschedclass(LINUXSCHED);
	resume(prC = create(proc, 2000, 90, "proc C", 1, 'C'));
	while (count++ < LOOP) {
		kprintf("M");

		for (i = 0; i < 10000000; i++)
			;
	}
	kill(prC);

	kprintf(
			"\n\n########## Test Case2, linux-like scheduling basic(4 processes):\n");
	count = 0;
	resume(prA = create(proc, 2000, 5, "proc A", 1, 'A'));
	resume(prB = create(proc, 2000, 50, "proc B", 1, 'B'));
	resume(prC = create(proc, 2000, 100, "proc C", 1, 'C'));
	while (count++ < LOOP) {
		kprintf("M");
		for (i = 0; i < 10000000; i++)
			;
	}
	kill(prA);
	kill(prB);
	kill(prC);

	kprintf(
			"\n\n########## Test Case3, linux-like scheduling with priority 15 and 25 (3 processes):\n");
	count = 0;
	setschedclass(LINUXSCHED);
	resume(prA = create(proc, 2000, 15, "proc A", 1, 'A'));
	resume(prB = create(proc, 2000, 25, "proc B", 1, 'B'));
	while (count++ < LOOP) {
		kprintf("M");
		for (i = 0; i < 10000000; i++)
			;
	}
	kill(prA);
	kill(prB);

	kprintf(
			"\n\n########## Test Case4, linux-like scheduling with quantum 8 (3 processes):\n");
	count = 0;
	setschedclass(LINUXSCHED);
	resume(prA = create(proc, 2000, 8, "proc A", 1, 'A'));
	resume(prB = create(proc, 2000, 8, "proc B", 1, 'B'));
	while (count++ < LOOP) {
		kprintf("M");

		for (i = 0; i < 10000000; i++)
			;
	}
	kill(prA);
	kill(prB);

	kprintf(
			"\n\n########## Test Case5, linux-like scheduling with quantum 100 (3 processes):\n");
	count = 0;
	setschedclass(LINUXSCHED);
	resume(prA = create(proc, 2000, 100, "proc A", 1, 'A'));
	resume(prB = create(proc, 2000, 100, "proc B", 1, 'B'));
	while (count++ < LOOP) {
		kprintf("M");

		for (i = 0; i < 10000000; i++)
			;
	}
	kill(prA);
	kill(prB);

	kprintf(
			"\n\n########## Test Case6, linux-like scheduling with quantum 1000 (3 processes):\n");
	count = 0;
	setschedclass(LINUXSCHED);
	resume(prA = create(proc, 2000, 1000, "proc A", 1, 'A'));
	resume(prB = create(proc, 2000, 1000, "proc B", 1, 'B'));
	while (count++ < LOOP) {
		kprintf("M");

		for (i = 0; i < 10000000; i++)
			;
	}
	kill(prA);
	kill(prB);

	count = 0;
	kprintf(
			"\n\n########## Test Case7, linux-like scheduling with big quantum(3 processes):\n");
	setschedclass(LINUXSCHED);
	resume(prA = create(proc, 2000, 1000000000, "proc A", 1, 'A'));
	resume(prB = create(procsleep, 2000, 1000000000, "proc B", 1, 'B'));
	while (count++ < LOOP) {
		kprintf("M");

		for (i = 0; i < 10000000; i++)
			;
	}
	kill(prA);
	kill(prB);

	count = 0;
	kprintf(
			"\n\n########## Test Case8, linux-like scheduling with chprio(3 processes):\n");
	setschedclass(LINUXSCHED);
	resume(prA = create(proc, 2000, 100, "proc A", 1, 'A'));
	resume(prB = create(procchprio, 2000, 100, "proc B", 1, 'B'));
	while (count++ < LOOP) {
		kprintf("M");

		for (i = 0; i < 10000000; i++)
			;
	}
	kill(prA);
	kill(prB);

	count = 0;
	kprintf(
			"\n\n########## Test Case9, linux-like scheduling with create(3 processes):\n");
	setschedclass(LINUXSCHED);
	resume(prA = create(proc, 2000, 200, "proc A", 1, 'A'));
	resume(prB = create(proccreate, 2000, 200, "proc B", 1, 'B'));
	while (count++ < LOOP) {
		kprintf("M");

		for (i = 0; i < 10000000; i++)
			;
	}
	sleep(5);
	kill(prA);
	kill(prB);

	count = 0;
	kprintf(
			"\n\n########## Test Case10, linux-like scheduling with sleep across epoch(3 processes):\n");
	setschedclass(LINUXSCHED);
	resume(prA = create(proclong, 2000, 200, "proc A", 1, 'A'));
	resume(prB = create(procsleepmore, 2000, 200, "proc B", 1, 'B'));
	while (count++ < LOOP * 2) {
		kprintf("M");

		for (i = 0; i < 10000000; i++)
			;
	}
	sleep(5);
	kill(prA);
	kill(prB);

	kprintf("\n\n########## Test Case11, multi-q scheduling(3 processes):\n");
	setschedclass(MULTIQSCHED);
	printf("Scheduler = %d\n", getschedclass());
	total_cnt = 0;
	a_percent = 0;
	b_percent = 0;
	prA = create(proc_a, 2000, 100, "proc A", 1, 'A');
	prB = createReal(proc_b, 2000, 10, "proc B", 1, 'B');
	resume(prA);
	resume(prB);
	sleep(5);
	kill(prA);
	kill(prB);
	total_cnt = a_cnt + b_cnt;
	a_percent = (double) a_cnt / total_cnt * 100;
	b_percent = (double) b_cnt / total_cnt * 100;
	kprintf("Test RESULT: A = %d, B = %d (%d : %d)\n", a_cnt, b_cnt,
			(int) a_percent, (int) b_percent);

	kprintf("\n\n########## Test Case12, multi-q scheduling(4 processes):\n");
	total_cnt = 0;
	a_percent = 0;
	b_percent = 0;
	c_percent = 0;
	a_cnt = b_cnt = c_cnt = 0;
	prA = create(proc_a, 2000, 100, "proc A", 1, 'A');
	prB = createReal(proc_b, 2000, 10, "proc B", 1, 'B');
	prC = createReal(proc_c, 2000, 10, "proc C", 1, 'C');
	resume(prA);
	resume(prB);
	resume(prC);
	sleep(10);
	kill(prA);
	kill(prB);
	kill(prC);
	total_cnt = a_cnt + b_cnt + c_cnt;
	a_percent = (double) a_cnt / total_cnt * 100;
	b_percent = (double) b_cnt / total_cnt * 100;
	c_percent = (double) c_cnt / total_cnt * 100;
	kprintf("Test RESULT: A = %d, B = %d, C = %d (%d : %d : %d)\n", a_cnt,
			b_cnt, c_cnt, (int) a_percent, (int) b_percent, (int) c_percent);

	kprintf(
			"\n\n########## Test Case13, multi-q scheduling without real proc(3 processes):\n");
	setschedclass(MULTIQSCHED);
	total_cnt = 0;
	a_percent = 0;
	b_percent = 0;
	a_cnt = 0;
	b_cnt = 0;
	prA = create(proc_a, 2000, 100, "proc A", 1, 'A');
	prB = create(proc_b, 2000, 100, "proc B", 1, 'B');
	resume(prA);
	resume(prB);
	sleep(5);
	kill(prA);
	kill(prB);
	total_cnt = a_cnt + b_cnt;
	a_percent = (double) a_cnt / total_cnt * 100;
	b_percent = (double) b_cnt / total_cnt * 100;
	kprintf("Test RESULT: A = %d, B = %d (%d : %d)\n", a_cnt, b_cnt,
			(int) a_percent, (int) b_percent);

}