komikat
komikat

Reputation: 79

xv6 scheduling: Kernel panic

I'm trying to implement a FCFS scheduler in RISC V XV6 but I keep getting the following error:

scause 0x000000000000000d
sepc=0x0000000080000b58 stval=0x0000000000000001
panic: kerneltrap

I'm not sure how to interpret this, I guessed that there was an issue with the trap code but I already have modified it to not yield if the program is scheduled using FCFS.

Relevant code:

proc.c

void scheduler(void)
{
  struct proc *p;
  struct cpu *c = mycpu();
  c->proc = 0;
  for (;;)
  {
    // Avoid deadlock by ensuring that devices can interrupt.
    intr_on();
    #ifdef FCFS
    struct proc* min_start = 0; // process with the minimum creation time
    for (p = proc; p < &proc[NPROC]; p++)
    {
      acquire(&p->lock);
      if (p->state == RUNNABLE) {
        if (min_start == 0)
          min_start = p;
        else if (p->creation_time > min_start->creation_time)
          min_start = p;
      }
      release(&p->lock);
    }

    if (min_start != 0) {
      acquire(&min_start->lock);
      min_start->state = RUNNING;
      c->proc = min_start;
      swtch(&c->context, &min_start->context);

    // done running
      c->proc = 0;
      release(&min_start->lock);
    }
    #endif

    ...
  }
}

proc.h

struct proc
{ ...
  int creation_time;            // Global process start timestamp
  ...
};

Upvotes: 1

Views: 1370

Answers (1)

amin_tay
amin_tay

Reputation: 62

The line sepc=0x0000000080000b58 is telling you what line in assembly code responsible for the error.

you should copy 80000b58, and go to kernel/kernel.asm file.

Now search for the copied number, this will show you the line that caused the error.

Upvotes: 1

Related Questions