1

I am trying to implement mixture of MLFQ and lottery scheduler in xv6. The problem I am encountering is I am making a function which calculates the total number of processes with high priority in a queue and the sum of their tickets. When I print the no_of_tickets within the loop it prints correct value. But when I am printing it before return value. It prints zero and go into forever loop. Here is my code

int no_of_processes = 0;
int count(int q_rank)
{
struct proc *p; int no_of_tickets = 0;
for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){
         if(p->queue_rank==q_rank)
    {
    if(p->state != RUNNABLE)
            continue;
            no_of_tickets = (no_of_tickets + (p->tickets));
            no_of_processes++;
    }
}
return no_of_tickets;
}

struct pstat pstat;


void
    scheduler(void)
    {
     struct proc *p;
     struct proc *p1;
     int f;
     for(f=0; f<NPROC; f++)
     {
     pstat.hticks[f]=0;
     pstat.lticks[f]=0;
     pstat.inuse[f]=0;
     }
     for(;;){
    int h_index=-1;
    int l_index=-1;
    sti();
    acquire(&ptable.lock);
    for(p1 = ptable.proc; p1 < &ptable.proc[NPROC]; p1++){
     int no_of_tickets = count(1);
     cprintf("%d", no_of_tickets);
     for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){
     if(p->queue_rank == 1)
    {
      h_index++;
      if(p->state != RUNNABLE)

      continue;
      p->queue_rank=0;
       (p->hticks)++;
       pstat.inuse[h_index]=1;
       pstat.pid[h_index]=p->pid;
       pstat.hticks[h_index]=p->hticks;
   run(p);
}
}
    l_index++;  
  if((p1->state != RUNNABLE) || (p1->queue_rank != 0))
    continue;
    (p1->lticks)++;
    pstat.lticks[l_index]=p1->lticks;
    run(p1);
    if(p1->state != ZOMBIE)
{
    run(p1);
}
}
   release(&ptable.lock);
  }
  }
Anmol Yousaf
  • 65
  • 1
  • 13

0 Answers0