0

I'm supposed to implement a scheduling algorithm for Minix. It should be round robin (which is actually already implemented in Minix 2), but with a little trick: every process should be given a "priority" or "category" 0, 1 or 2 and:

  • processes with priority 2 should be able to run for 3 consecutive time quanta
  • processes with priority 1 ... for 2 consec. ...
  • processes with priority 0 after the time quantum ends should land at the end of the queue.

I THINK I did it, but it's probably wrong, but I'm honestly not sure how to test it. I made a program to test it, it's simple loop

/** ... **/
for(i = 0; i < 16; i++)
{
    for(j = 0; j < 65535 * 256; j++) {}
    printf("== Loop with priority %d ends rotation: %d\n", myPriority, i + 1);
}
printf("== Ending: %d\n", myPriority);

I then use this script:

#!/bin/sh

time ./test 0 &
time ./test 1 &
time ./test 2 &

to test the results. I think that naturally the process with priority 2 should have the shortest execution time but it's quite the opposite and sometimes the process with pr. 0 has longer time than the one with pr. 1, which is extremely weird to me. Is it how it should be or is my implemention of the scheduling wrong (I assume the test program is fine)? What's the expected result?

Here's also the implementation of this scheduling, it's very simple and therefore probably wrong. It's the part (rather ending) of ready(rp) function in kernel/proc.c.

  if (rp->p_cat == 0) {
    rp->p_nextready = rdy_head[USER_Q];
    rdy_head[USER_Q] = rp;
  }
  if (rp->p_cat == 1) {
    rp->p_nextready = rp;
    rp->p_nextready->p_nextready = rdy_head[USER_Q];
    rdy_head[USER_Q] = rp;
  }
  if (rp->p_cat == 2) {
    rp->p_nextready = rp;
    rp->p_nextready->p_nextready = rp;
    rp->p_nextready->p_nextready->p_nextready = rdy_head[USER_Q];
    rdy_head[USER_Q] = rp;
  }
paolostyle
  • 1,849
  • 14
  • 17
  • 2
    For category 1, you set `rp->next = rp` and then `rp->next->next = head`. That's exactly the same as `rp->next = head`. In other words, all three categories do exactly the same thing. – user3386109 Nov 18 '15 at 02:44
  • Thanks, I looked up everything and decided to do it differently. Now my results are that the shortest exec time has process with the highest priority, as I thought it would work before I even started coding. So I guess problem is solved, unless it shouldn't work that way (execution times are 2=>14, 1=>18, 0=>20). – paolostyle Nov 18 '15 at 03:23

0 Answers0