Example #1
0
/* TODO FIXME YOLO
   tutaj niewykorzystywane sa wartosci zuzytego czasu itd.
   ZMIENIC
*/
int do_noquantum(message *m_ptr)
// *   do_noquantum:        Called on behalf of process' that run out of quantum
{
	register struct schedproc *rmp;
	int rv, proc_nr_n;

	if (sched_isokendpt(m_ptr->m_source, &proc_nr_n) != OK) {
		printf("SCHED: WARNING: got an invalid endpoint in OOQ msg %u.\n",
		m_ptr->m_source);
		return EBADEPT;
	}

	rmp = &schedproc[proc_nr_n]; // tu dostaję schedproc procesu, którym się bawię
	// wyciągam to z jakiegoś message *m_ptr, nie wiem co to, ale w sumie co za różnica - ważne
	// że jest dostęp do procesu
	// od tego momentu mogę z procesem zrobić wszystko
	if (rmp->priority < MIN_USER_Q) { //a to jest też liczba kolejek
		rmp->priority += 1; /* lower priority */
	}

	//Sprawdzenie zużytego czasu systemowego
	clock_t newTime;
	sys_times(rmp->endpoint, NULL, &newTime, NULL, NULL);
	//ZRÓB OBLICZENIA SRUTUTUTUTU
	rmp->YOLO = newTime;

	if ((rv = schedule_process_local(rmp)) != OK) {
		return rv;
	}
	return OK;
}
Example #2
0
int do_noquantum(message *m_ptr)
{
	register struct schedproc *rmp;
	int rv, proc_nr_n;

	if (sched_isokendpt(m_ptr->m_source, &proc_nr_n) != OK) {
		printf("SCHED: WARNING: got an invalid endpoint in OOQ msg %u.\n",
		m_ptr->m_source);
		return EBADEPT;
	}

	rmp = &schedproc[proc_nr_n];
	
	if (PROCESS_IN_USER_Q(rmp)) {
		rmp->priority = USER_Q;
 	} else if (rmp->priority < MAX_USER_Q - 1){
 		rmp->priority += 1;
 	}
 	/* printf("do_noquantum, %d in %d\n", rmp->endpoint, rmp->priority); */

	if ((rv = schedule_process_local(rmp)) != OK) {
		return rv;
	}
	
	if ((rv = do_lottery()) != OK) {
 		return rv;
	}
	return OK;
}
Example #3
0
/* CHANGE END */
int do_noquantum(message *m_ptr)
{
    /* CHANGE START */
    struct schedproc *rmp, *rmp_temp;
    /* CHANGE END */
    int rv, proc_nr_n;

    if (sched_isokendpt(m_ptr->m_source, &proc_nr_n) != OK) {
        printf("SCHED: WARNING: got an invalid endpoint in OOQ msg %u.\n",
               m_ptr->m_source);
        return EBADEPT;
    }

    rmp = &schedproc[proc_nr_n];

    /* CHANGE START */
    rmp->time_slice = DEFAULT_USER_TIME_SLICE;
    rmp->priority = HOLDING_Q;

    if ((rv = schedule_process_local(rmp)) != OK) /* move out of quantum process */
        return rv;

    if ((rv = do_lottery()) != OK) /* schedule a new winner */
        return rv;
    /* CHANGE END */

    return OK;
}
int do_noquantum(message *m_ptr)
{
	register struct schedproc *rmp;
	int rv, proc_nr_n;

	if (sched_isokendpt(m_ptr->m_source, &proc_nr_n) != OK) {
		printf("SCHED: WARNING: got an invalid endpoint in OOQ msg %u.\n",
		m_ptr->m_source);
		return EBADEPT;
	}

	rmp = &schedproc[proc_nr_n];
	if(rmp->priority>=MAX_USER_Q && rmp->priority<=MIN_USER_Q)
	{
		rmp->priority=USER_Q;
		
	}
	else if (rmp->priority < MAX_USER_Q-1) {
		rmp->priority += 1; /* lower priority */
	}
	if ((rv = schedule_process_local(rmp)) != OK) {
		return rv;
	}
	return pick_lottery();
}
/*==================================================================*
 *				pick_lottery			    *
 *==================================================================*/
int pick_lottery()
{
	struct schedproc *rmp;
	int total_tickets = 0;
	int lucky_ticket = 0;
	int iter = 0;

	for(iter=0;iter<NR_PROCS;iter++)
	{
		rmp=&schedproc[iter];
		if((rmp->flags && IN_USE) && (rmp->priority==USER_Q)){
			total_tickets+=rmp->num_of_tickets;
		}
	}

	if(total_tickets==0)
		return OK;
	lucky_ticket = random()%total_tickets;
	for(iter=0;iter<NR_PROCS;iter++)
	{
		rmp = &schedproc[iter];
		if((rmp->flags && IN_USE) && (rmp->priority==USER_Q))
		{
			lucky_ticket-=rmp->num_of_tickets;
			if(lucky_ticket<0)
			{
				rmp->priority = MAX_USER_Q;
				schedule_process_local(rmp);
				break;
			}
		}
	}
	return OK;
}
Example #6
0
/*===========================================================================*
 *				do_nice					     *
 *===========================================================================*/
int do_nice(message *m_ptr)
{
	struct schedproc *rmp;
	int rv;
	int proc_nr_n;
	unsigned new_q, old_q, old_max_q;
	int old_ticketsNum;

	/* check who can send you requests */
	if (!accept_message(m_ptr))
		return EPERM;

	if (sched_isokendpt(m_ptr->SCHEDULING_ENDPOINT, &proc_nr_n) != OK) {
		printf("SCHED: WARNING: got an invalid endpoint in OOQ msg "
		"%ld\n", m_ptr->SCHEDULING_ENDPOINT);
		return EBADEPT;
	}

	rmp = &schedproc[proc_nr_n];
	new_q = (unsigned) m_ptr->SCHEDULING_MAXPRIO;
	if (new_q >= NR_SCHED_QUEUES) {
		return EINVAL;
	}

	/* Store old values, in case we need to roll back the changes */
	old_q     = rmp->priority;
	old_max_q = rmp->max_priority;
	old_ticketsNum = rmp->ticketsNum;

	/* Update the proc entry and reschedule the process */
	/*rmp->max_priority = rmp->priority = new_q;*/
	rmp->priority = USER_Q;
	
	
	/**new_q = MAX_USER_Q + (nice-PRIO_MIN) * (MIN_USER_Q-MAX_USER_Q+1) / (PRIO_MAX-PRIO_MIN+1);*/
	
	rmp->ticketsNum += ((new_q - MAX_USER_Q)*(PRIO_MAX-PRIO_MIN+1)/(MIN_USER_Q-MAX_USER_Q+1) )+ PRIO_MIN;

	printf(" *** %d ***\n", rmp->ticketsNum);
	if((int)rmp->ticketsNum < 5)
		rmp->ticketsNum = 5;
	if((int)rmp->ticketsNum > 100)
		rmp->ticketsNum = 100;	
	printf("**** %d ****\n", (int) rmp->ticketsNum);
	if ((rv = schedule_process_local(rmp)) != OK) {
		/* Something went wrong when rescheduling the process, roll
		 * back the changes to proc struct */
		rmp->priority     = old_q;
		rmp->max_priority = old_max_q;
		rmp->ticketsNum = old_ticketsNum;
	}
	
	return do_lottery();
	//return rv;
}
Example #7
0
/*==========================================================================*
  *				do_lottery				     *
  *===========================================================================*/
int do_lottery()
 {
 	struct schedproc *rmp;
 	int proc_nr;
 	int lucky;
 	int old_priority;
 	int flag = -1;
 	int nTickets = 0;
 
 	for (proc_nr=0, rmp=schedproc; proc_nr < NR_PROCS; proc_nr++, rmp++) {
 		if ((rmp->flags & IN_USE) && PROCESS_IN_USER_Q(rmp)) {
 			if (USER_Q == rmp->priority) {
 				nTickets += rmp->ticketsNum;
 			}
 		}
 	}
 
 	lucky = nTickets ? random() % nTickets : 0;
 	for (proc_nr=0, rmp=schedproc; proc_nr < NR_PROCS; proc_nr++, rmp++) {
 		if ((rmp->flags & IN_USE) && PROCESS_IN_USER_Q(rmp) &&
 				USER_Q == rmp->priority) {
 			old_priority = rmp->priority;
 			/* rmp->priority = USER_Q; */
 			if (lucky >= 0) {
 				lucky -= rmp->ticketsNum;
 				/*
 				   printf("lucky - %d = %d\n", rmp->ticketsNum, lucky);
 				 */
 				if (lucky < 0) {
 					rmp->priority = MAX_USER_Q;
 					flag = OK;
 					/* printf("endpoint %d\n", rmp->endpoint); */
 				}
 			}
 			if (old_priority != rmp->priority) {
 				schedule_process_local(rmp);
				break;
 			}
 		}
 	}
 	/*
	for (proc_nr=0, rmp=schedproc; proc_nr < NR_PROCS; proc_nr++, rmp++) {
 		if ((rmp->flags & IN_USE) && PROCESS_IN_USER_Q(rmp)) {
 			if (USER_Q == rmp->priority)
 				count_17++;
 			else if (MAX_USER_Q == rmp->priority)
 				count_16++;
 		}
	}
	printf("in 16: %d; in 17: %d\n", count_16, count_17); 
 	*/
 	/* printf("do_lottery OK? %d lucky=%d\n", flag, lucky); */
 	return nTickets ? flag : OK;
}
/* This function in called every 100 ticks to rebalance the queues. The current
 * scheduler bumps processes down one priority when ever they run out of
 * quantum. This function will find all proccesses that have been bumped down,
 * and pulls them back up. This default policy will soon be changed.
 */
static void balance_queues(struct timer *tp)
{
	struct schedproc *rmp;
	int proc_nr;

	for (proc_nr=0, rmp=schedproc; proc_nr < NR_PROCS; proc_nr++, rmp++) {
		if (rmp->flags & IN_USE) {
			if (rmp->priority > rmp->max_priority && !PROCESS_IN_USER_Q(rmp)) {
				rmp->priority -= 1; /* increase priority */
				schedule_process_local(rmp);
			}
		}
	}

	set_timer(&sched_timer, balance_timeout, balance_queues, 0);
}
int do_noquantum(message *m_ptr)
{
    register struct schedproc *rmp;
    int rv, proc_nr_n;

    if (sched_isokendpt(m_ptr->m_source, &proc_nr_n) != OK) {
        printf("SCHED: WARNING: got an invalid endpoint in OOQ msg %u.\n",
               m_ptr->m_source);
        return EBADEPT;
    }
    /*int filept = open ( "log_MLFQ . t x t " ,O_WRONLY|O_APPEND|O_CREAT, 0666) ;
    char charbuf[2048];*/
    rmp = &schedproc[proc_nr_n];
    int priority =rmp->priority;
    int rm_endpt=(int)rmp->endpoint;
    if(priority==MAX_USER_Q)
    {
        printf("Process [%d] has  priority %d and consumed quantum  :%d\n",rm_endpt,MAX_USER_Q+1,DEFAULT_USER_TIME_SLICE );
        rmp->priority=MAX_USER_Q+1;/*INCREASING the priority and placing in 17th */

        rmp->time_slice=2*DEFAULT_USER_TIME_SLICE;
    }
    else if(priority==MAX_USER_Q+1)
    {
        printf("Process [%d] has priority %d and consumed quantum  :%d\n",rm_endpt,MAX_USER_Q+2,2*DEFAULT_USER_TIME_SLICE);
        rmp->priority=MAX_USER_Q+1;
        rmp->time_slice=4*DEFAULT_USER_TIME_SLICE;
    }
    else if(priority==MAX_USER_Q+2)
    {
        printf("Process [%d] has priority %d and consumed quantum  :%d\n",rm_endpt,MAX_USER_Q+2,4*DEFAULT_USER_TIME_SLICE);
        rmp->priority=MAX_USER_Q;
        rmp->time_slice=DEFAULT_USER_TIME_SLICE;
    }
    else
    {
        printf("Setting the process [%d]'s priorit y to%d",rm_endpt,MAX_USER_Q);
        rmp->priority=MAX_USER_Q;
        rmp->time_slice=DEFAULT_USER_TIME_SLICE;
    }

    rv=schedule_process_local(rmp);
    close(filept);
    if(rv!=OK)
        return rv;
    return OK;
}
/* This function in called every N ticks to rebalance the queues. The current
 * scheduler bumps processes down one priority when ever they run out of
 * quantum. This function will find all proccesses that have been bumped down,
 * and pulls them back up. This default policy will soon be changed.
 */
void balance_queues(void)
{
	struct schedproc *rmp;
	int r, proc_nr;

	for (proc_nr=0, rmp=schedproc; proc_nr < NR_PROCS; proc_nr++, rmp++) {
		if (rmp->flags & IN_USE) {
			if (rmp->priority > rmp->max_priority) {
				rmp->priority -= 1; /* increase priority */
				schedule_process_local(rmp);
			}
		}
	}

	if ((r = sys_setalarm(balance_timeout, 0)) != OK)
		panic("sys_setalarm failed: %d", r);
}
Example #11
0
/* This function in called every 100 ticks to rebalance the queues. The current
 * scheduler bumps processes down one priority when ever they run out of
 * quantum. This function will find all proccesses that have been bumped down,
 * and pulls them back up. This default policy will soon be changed.
 */
static void balance_queues(struct timer *tp)
{
	struct schedproc *rmp;
	int proc_nr;

	for (proc_nr=0, rmp=schedproc; proc_nr < NR_PROCS; proc_nr++, rmp++) {
		if (rmp->flags & IN_USE) {
			if (rmp->priority > rmp->max_priority) {
				/* zmiana na labach
			    	rmp->priority -= 1; */ /* increase priority */
				rmp->priority = rmp->max_priority;
				schedule_process_local(rmp);
			}
		}
	}

	set_timer(&sched_timer, balance_timeout, balance_queues, 0);
}
int do_noquantum(message *m_ptr)
{
	register struct schedproc *rmp;
	int rv, proc_nr_n;

	if (sched_isokendpt(m_ptr->m_source, &proc_nr_n) != OK) {
		printf("SCHED: WARNING: got an invalid endpoint in OOQ msg %u.\n",
		m_ptr->m_source);
		return EBADEPT;
	}

	rmp = &schedproc[proc_nr_n];
	rmp->cputime += rmp->time_slice;
	printf("\nprocess id %u has cputime %ld\n", rmp->endpoint, rmp->cputime);

	/*Lottey Scheduling*/
	/*
        If the process is in the user queue then the priority remains unchanged and we are printing it's tickets number
        time slice and priority else if the process is not in the user queue then lower the priority by 1.
	*/
	if (PROCESS_IN_USER_Q(rmp)) {
		rmp->priority = USER_Q;
		printf("\nProcess %d is executed whose ticket no is %d with time quantum %d with priority %d\n", rmp->endpoint, rmp->ticketsNum, rmp->time_slice, rmp->priority);
	} else if (rmp->priority < MAX_USER_Q - 1) {
		rmp->priority += 1; /* lower priority */
	}

	if ((rv = schedule_process_local(rmp)) != OK) {
		return rv;
	}

	/*
        Lottey Scheduling
        After a process completed it's quantum do_lottery function is called to start another process
	*/
	if((rv = do_lottery()) != OK) {
		return rv;
	}

	return OK;
}
Example #13
0
/*===========================================================================*
*   do_lottery
*
*   This function holds a lottery of all the processes in the holding queue
*   based on the number of tickets they have
*
*   @return OK - a process was scheduled via lottery (if possible)
*           -1 - failed to schedule the winning process
*===========================================================================*/
int do_lottery()
{
    struct schedproc *rmp;
    int rv, proc_nr;
    int total_tickets = 0;
    u64_t tsc;
    int winner;

    /* count the total number of tickets in all processes */
    /* we really should have a global to keep track of this total */
    /* rather than computing it every time */
    for (proc_nr = 0, rmp = schedproc; proc_nr < NR_PROCS; ++proc_nr, ++rmp)
        if (rmp->priority == HOLDING_Q && rmp->flags == IN_USE) /* winnable? */
            total_tickets += rmp->tickets;

    if (!total_tickets) /* there were no winnable processes */
        return OK;

    /* generate a "random" winning ticket */
    /* lower bits of time stamp counter are random enough */
    /*   and much faster then random() */
    read_tsc_64(&tsc);
    winner = tsc % total_tickets + 1;

    /* now find the process with the winning ticket */
    for (proc_nr = 0, rmp = schedproc; proc_nr < NR_PROCS; ++proc_nr, ++rmp) {
        if (rmp->priority == HOLDING_Q && rmp->flags == IN_USE) /* winnable? */
            winner -= rmp->tickets;
        if (winner <= 0)
            break;
    }

    //printf("Process %d won with %d of %d tickets\n", proc_nr, rmp->tickets, total_tickets);
    /* schedule new winning process */
    rmp->priority = WINNING_Q;

    if ((rv = schedule_process_local(rmp)) != OK)
        return rv;
    return OK;
}
Example #14
0
/*===========================================================================*
 *				do_nice					     *
 *===========================================================================*/
int do_nice(message *m_ptr)
{
	struct schedproc *rmp;
	int rv;
	int proc_nr_n;
	unsigned new_q, old_q, old_max_q;

	/* check who can send you requests */
	if (!accept_message(m_ptr))
		return EPERM;

	if (sched_isokendpt(m_ptr->SCHEDULING_ENDPOINT, &proc_nr_n) != OK) {
		printf("SCHED: WARNING: got an invalid endpoint in OOQ msg "
		"%ld\n", m_ptr->SCHEDULING_ENDPOINT);
		return EBADEPT;
	}

	rmp = &schedproc[proc_nr_n];
	new_q = (unsigned) m_ptr->SCHEDULING_MAXPRIO;
	if (new_q >= NR_SCHED_QUEUES) {
		return EINVAL;
	}

	/* Store old values, in case we need to roll back the changes */
	old_q     = rmp->priority;
	old_max_q = rmp->max_priority;

	/* Update the proc entry and reschedule the process */
	rmp->max_priority = rmp->priority = new_q;

	if ((rv = schedule_process_local(rmp)) != OK) {
		/* Something went wrong when rescheduling the process, roll
		 * back the changes to proc struct */
		rmp->priority     = old_q;
		rmp->max_priority = old_max_q;
	}

	return rv;
}
Example #15
0
int do_noquantum(message *m_ptr)
{
	register struct schedproc *rmp;
	int rv, proc_nr_n;

	if (sched_isokendpt(m_ptr->m_source, &proc_nr_n) != OK) {
		printf("SCHED: WARNING: got an invalid endpoint in OOQ msg %u.\n",
		m_ptr->m_source);
		return EBADEPT;
	}

	rmp = &schedproc[proc_nr_n];

	rmp = rearrange_order(rmp);

	if (rmp->priority < MIN_USER_Q) {
		rmp->priority += 1; /* lower priority */
	}

	if ((rv = schedule_process_local(rmp)) != OK) {
		return rv;
	}
	return OK;
}
/*===========================================================================*
 *				do_nice					     *
 *===========================================================================*/
int do_nice(message *m_ptr)
{
	struct schedproc *rmp;
	int rv;
	int proc_nr_n;
	unsigned new_q, old_q, old_max_q;

	/*Lottery Scheduling*/
	int old_ticketsNum; //old ticketsNum value

	/* check who can send you requests */
	if (!accept_message(m_ptr))
		return EPERM;

	if (sched_isokendpt(m_ptr->SCHEDULING_ENDPOINT, &proc_nr_n) != OK) {
		printf("SCHED: WARNING: got an invalid endpoint in OOQ msg "
		"%ld\n", m_ptr->SCHEDULING_ENDPOINT);
		return EBADEPT;
	}

	rmp = &schedproc[proc_nr_n];

    /*
        m_ptr->SCHEDULING_MAX_PRIO is set to the value of nice in servers/pm/schedule.c
    */
	new_q = (unsigned) m_ptr->SCHEDULING_MAXPRIO;

	rmp->ticketsNum += new_q;
	if(rmp->ticketsNum < 5)
		rmp->ticketsNum = 5;

    /*
        new_q is set the same value as the old_priority i.e. 13
    */
	new_q = rmp->priority;

	if (new_q >= NR_SCHED_QUEUES) {
		return EINVAL;
	}

	/* Store old values, in case we need to roll back the changes */
	old_q     = rmp->priority;
	old_max_q = rmp->max_priority;

	/*Lottery Scheduling*/
	old_ticketsNum = rmp->ticketsNum; //saving ticketsNum value to old_ticketsNum

	/* Update the proc entry and reschedule the process */

	/*Lottery Scheduling*/
	//rmp->max_priority = rmp->priority = new_q;
	rmp->priority = USER_Q; // default priority for user processes


	if ((rv = schedule_process_local(rmp)) != OK) {
		/* Something went wrong when rescheduling the process, roll
		 * back the changes to proc struct */
		rmp->priority     = old_q;
		rmp->max_priority = old_max_q;

		/*Lottery Scheduling*/
		rmp->ticketsNum = old_ticketsNum;//reverting ticketsNum value

	}

	/*Lottery Scheduling*/
	return do_lottery();//do_lottery is called to assign cpu to another process
}