Minix3 Priority Scheduler

2,854 views
Skip to first unread message

ms.cut...@yahoo.com

unread,
Apr 1, 2011, 12:08:13 PM4/1/11
to minix3
Dear all,
I'm working on a project to change the Minix3 Scheduler. The goal is
to implement a multi-level priority scheduler for user-level
processes.
The multi-level priority scheduler used in this project will have
three queues that operate in a round-robin fashion. Processes in a
higher priority queue run more often than processes in a low priority
queue, but all processes do get to run. I started to think of a way to
modify the code in the sched() function however am stuck in how to
implement a round robin queue. Please help me!!
Regards,

Erik van der Kouwe

unread,
Apr 1, 2011, 5:38:31 PM4/1/11
to minix3
Hi,
This looks like a homework assignment.

The policy in this newsgroup is not to help with homework assignments
unless there is a very specific question that is clearly related to
MINIX. This question is too generic for us to answer, the idea of the
assignment is probably to make you think about this. For questions
like these you should ask your professor.

If, on the other hand, you have a specific question we would be happy
to help you.

With kind regards,
Erik

ms.cut...@yahoo.com

unread,
Apr 1, 2011, 5:43:00 PM4/1/11
to minix3
Hi,

Thanks for the quick reply. It is a project am working on now and I
just need a start point on how to implement the round robin queue then
I will come up with my own algorithm for the scheduling. Your help is
really appreciated.
I've started with defining two global variables in the proc.h as head
an tail
now am think of using the enqueue and dequeue methods to write the
queue in the sched( ) function in proc.c
Any suggestions or am on the right track?

Regards

ms.cut...@yahoo.com

unread,
Apr 3, 2011, 1:56:42 PM4/3/11
to minix3
I've trued many things and I've changed the code in proc.c and do_nice
and when I try to reboot the system it is giving me this error:
kernel pm vfs rs memory log tty ds mfs vm pfs init (4190k)"
Any ideas??

On Apr 2, 12:38 am, Erik van der Kouwe <erik...@gmail.com> wrote:

srivatsa bhat

unread,
Apr 3, 2011, 2:15:48 PM4/3/11
to min...@googlegroups.com
On Sun, Apr 3, 2011 at 11:26 PM, ms.cut...@yahoo.com <ms.cut...@yahoo.com> wrote:
I've trued many things and I've changed the code in proc.c and do_nice
and when I try to reboot the system it is giving me this error:
kernel pm vfs rs memory log tty ds mfs vm pfs init (4190k)"
Any ideas??


I don't think that is an error. It just prints that line while booting.. Just wait for some time and see if you get the login prompt.
However, if it is truly an error, can you attach a screen-shot of the same?

Regards,
Srivatsa S. Bhat

Erik van der Kouwe

unread,
Apr 3, 2011, 2:41:30 PM4/3/11
to minix3
Hi,

> I've trued many things and I've changed the code in proc.c and do_nice
> and when I try to reboot the system it is giving me this error:
> kernel pm vfs rs memory log tty ds mfs vm pfs init (4190k)"
> Any ideas??

As correctly pointed out by Srivatsa, this is not an error message. I
expect the modified scheduler doesn't schedule any processes or fails
in some other way. You can probably still boot into your old (working)
system by selecting 1 on the boot prompt.

To get more info on these kinds of errors, you'll probably need to do
serial debugging as printing to the console probably doesn't work yet
in this phase of the boot. This is easiest if you're running MINIX
inside a hypervisor. In this case, first tell it to redirect the
serial somewhere. With QEMU/KVM for example you can set "-serial
stdio" on the command line to achieve this. When booting the machine,
press escape when the boot menu appears. Now type "ctty 0" to enable
serial debugging and "verbose=1" to get more info during boot (higher
numbers can be used to further increase debug output). Then type
"boot" to boot into the default (=newest) boot image.

If you've done this, printf output appears where you redirected the
serial to. This allows you to add printf statements to your scheduler
code to see where it's going wrong.

With kind regards,
Erik

ms.cut...@yahoo.com

unread,
Apr 3, 2011, 2:46:56 PM4/3/11
to minix3
Hi,
Thank you for your reply. Actually it worked and minix started but I
will ask if you can help me in this project please. Please let me know
so that I can send you the details.
Thanks anyway

On Apr 3, 9:15 pm, srivatsa bhat <bhat.sriva...@gmail.com> wrote:
> On Sun, Apr 3, 2011 at 11:26 PM, ms.cute_ah...@yahoo.com <

Erik van der Kouwe

unread,
Apr 3, 2011, 3:06:05 PM4/3/11
to minix3
Hi,

> Thank you for your reply. Actually it worked and minix started but I
> will ask if you can help me in this project please. Please let me know
> so that I can send you the details.

As I mentioned before, this group is not intended for help with
homework assignments. Such help should be provided by your professor
or teaching assistant.

If you have specific problems, feel free to post them here. To
increase the chance of getting useful help, always include the full
error message, sufficient detail of what you have changed and an
overview of the things you've already tried to debug your problem and
the results from that.

With kind regards,
Erik

ms.cut...@yahoo.com

unread,
Apr 23, 2011, 5:41:01 AM4/23/11
to minix3
I've finished the project but it didn't compile. Can someone help me
plz?
I've done the following things:
in the Proc.h file:
1. Three counters are defined (count1, count2 and count3) to track the
number of processes in each user processes queue.
2. The total number of processes is changed to 19 to fit the 3 extra
user queues.

In the Proc.c file:
2.1 enqueue( ) & dequeue( ) functions
In these function, the counters for the user processes are incremented
and decremneted repectively.
2.2 sched( )
In this function, we diffrenciated between the system processes and
the user ones.

PRIVATE void sched(rp, queue, front)
register struct proc *rp; /* process to be scheduled */
int *queue; /* return: queue to use */
int *front; /* return: front or back */
{
/* This function determines the scheduling policy. It is called
whenever a
* process must be added to one of the scheduling queues to decide
where to
* insert it. As a side-effect the process' priority may be
updated.
*/
int time_left = (rp->p_ticks_left > 0); /* quantum fully consumed */

/* Check whether the process has time left. Otherwise give a new
quantum
* and lower the process' priority, unless the process already is in
the
* lowest queue.
*/
if (! time_left) { /* quantum consumed ? */
rp->p_ticks_left = rp->p_quantum_size; /* give new quantum */
if (rp->p_priority < (NR_SCHED_QUEUES-1)) {
if(priv(rp)->s_flags & SYS_PROC){
rp->p_priority += 1; /* lower priority */
}
}

}
/* If there is time left, the process is added to the front of its
queue,
* so that it can immediately run. The queue to use simply is always
the
* process' current priority.
*/

if(priv(rp)->s_flags & SYS_PROC)
{
*front = time_left;
}
else
{
if(rp->p_priority<16)
{
rp->p_priority=16;
}
*front=0;
}
*queue = rp->p_priority;
}


2.3 pick_proc
This function contains the algorithm for the scheduling of the
processes.
PRIVATE struct proc * pick_proc(void)
{
/* Decide who to run now. A new process is selected an returned.
* When a billable process is selected, record it in 'bill_ptr', so
that the
* clock task can tell who to bill for system time.
*/
register struct proc *rp; /* process to run */
int q; /* iterate over queues */

/* Check each of the scheduling queues for ready processes. The
number of
* queues is defined in proc.h, and priorities are set in the task
table.
* The lowest queue contains IDLE, which is always ready.
*/
for (q=0; q < NR_SCHED_QUEUES; q++) {
if(!(rp = rdy_head[q])) {
TRACE(VF_PICKPROC, printf("queue %d empty\n", q););
continue;
}

if(q==16 && count1>0){

rp=rdy_head[q];

}

else if(q==17 && count2>0 && count1==0)
{
rp=rdy_head[q];
}
else if(if(q==18 && count3>0 && count1==0 && count2==0)
{
rp=rdy_head[q];
}

TRACE(VF_PICKPROC, printf("found %s / %d on queue %d\n",
rp->p_name, rp->p_endpoint, q););
vmassert(!proc_is_runnable(rp));
if (priv(rp)->s_flags & BILLABLE)
bill_ptr = rp; /* bill for system time */
return rp;
}
return NULL;
}



In the do_nice
We have added some conditions to put the user processes's priorities
to be from 0 to 2
if (pri < PRIO_MIN || pri > PRIO_MAX) return(EINVAL);
if(priv(rp)->s_flags & SYS_PROC){
new_q = MAX_USER_Q + (pri-PRIO_MIN) * (MIN_USER_Q-MAX_USER_Q+1) /
(PRIO_MAX-PRIO_MIN+1);
if (new_q < MAX_USER_Q) new_q = MAX_USER_Q; /* shouldn't happen */
if (new_q > MIN_USER_Q) new_q = MIN_USER_Q; /* shouldn't happen */
}
else
{
if(pri>2){
pri=2;}
if(pri<0){
pri=0;}
new_q = NR_SCHED_QUEUES+pri;
}
/* Make sure the process is not running while changing its
priority.
* Put the process back in its new queue if it is runnable.
*/
RTS_LOCK_SET(rp, RTS_SYS_LOCK);
rp->p_max_priority = rp->p_priority = new_q;
RTS_LOCK_UNSET(rp, RTS_SYS_LOCK);

return(OK);
}


Any suggestions??

On Apr 3, 10:06 pm, Erik van der Kouwe <erik...@gmail.com> wrote:
> Hi,
>
> > Thank you for your reply. Actually it worked andminixstarted but I

Erik van der Kouwe

unread,
Apr 23, 2011, 5:48:53 AM4/23/11
to minix3
Hi,

> I've finished the project but it didn't compile.

So, what compiler error(s) do you get then? There is no way anyone can
help you without knowing what went wrong.

With kind regards,
Erik

ms.cut...@yahoo.com

unread,
Apr 23, 2011, 12:12:36 PM4/23/11
to minix3
When I try to test the system with this command lines it hangs:
./a.out 5 0 100 5000&
./a.out 6 0 100 5000&

Erik van der Kouwe

unread,
Apr 23, 2011, 12:18:36 PM4/23/11
to minix3
> When I try to test the system with this command lines it hangs:
> ./a.out 5 0 100 5000&
> ./a.out 6 0 100 5000&

???

You just mentioned that the project didn't even compile.

ms.cut...@yahoo.com

unread,
Apr 23, 2011, 12:22:01 PM4/23/11
to minix3
Sorry it is my mistake. What I meant is the minix started but when I
try these line of code it just hangs.

Erik van der Kouwe

unread,
Apr 23, 2011, 12:45:02 PM4/23/11
to minix3
Hi,

> Sorry it is my mistake. What I meant is the minix started but when I
> try these line of code it just hangs.

In that case it is unlikely anyone will find your bug just by looking
at the source code. I recommend you debug it to find out what is
happening.

One good way to do that would be to add printfs to the relevant code
to find out what is happening. If you connect a serial cable and type
"ctty 0" in the boot monitor before MINIX start, you can capture this
output on another computer to make it easier. The simplest way is to
run in QEMU or KVM and use the "-serial stdio" command line switch to
connect the virtual serial cable to stdin/stdout.

With kind regards,
Erik

ms.cut...@yahoo.com

unread,
Apr 23, 2011, 3:01:09 PM4/23/11
to minix3
I will try to put the printf statement and see what will happen.
Thank you very much for the reply..
Regards,
Reply all
Reply to author
Forward
0 new messages