proc.c
//PAGEBREAK: 42
// Per-CPU process scheduler.
// Each CPU calls scheduler() after setting itself up.
// Scheduler never returns.  It loops, doing:
//  - choose a process to run
//  - swtch to start running that process
//  - eventually that process transfers control
//      via swtch back to the scheduler.
42
Per-CPU process scheduler.
Each CPU calls scheduler() after setting itself up.
Scheduler never returns.  It loops, doing:
choose a process to run
swtch to start running that process
eventually that process transfers control
via swtch back to the scheduler.
42 Per - CPU process scheduler . Each CPU calls scheduler () after setting itself up . Scheduler never returns . It loops doing : choose a process to run swtch to start running that process eventually that process transfers control via swtch back to the scheduler .
void
scheduler(void)
{
  struct proc *p;
  for(;;){
    sti();
    acquire(&ptable.lock);
while(ptable.pReadyList[0] || ptable.pReadyList[1] || ptable.pReadyList[2]){
if(ptable.TimeToReset==0)
{
ResetPriority();
ptable.TimeToReset=MaxTimeToReset;
}
else
{
ptable.TimeToReset=ptable.TimeToReset-1;
}
	p=GetReady();
      proc = p;
      switchuvm(p);
      p->state = RUNNING;
    RemoveReadyList(p);
      swtch(&cpu->scheduler, proc->context);
      switchkvm();
      proc = 0;
    }
    release(&ptable.lock);
  }
}
void scheduler ( void ) { struct proc * p ; for ( ; ; ) { sti ( ) ; acquire ( & ptable . lock ) ; while ( ptable . pReadyList [ 0 ] || ptable . pReadyList [ 1 ] || ptable . pReadyList [ 2 ] ) { if ( ptable . TimeToReset == 0 ) { ResetPriority ( ) ; ptable . TimeToReset = MaxTimeToReset ; } else { ptable . TimeToReset = ptable . TimeToReset - 1 ; } p = GetReady ( ) ; proc = p ; switchuvm ( p ) ; p -> state = RUNNING ; RemoveReadyList ( p ) ; swtch ( & cpu -> scheduler , proc -> context ) ; switchkvm ( ) ; proc = 0 ; } release ( & ptable . lock ) ; } }
PAGEBREAK: 42
Per-CPU process scheduler.
PAGEBREAK : 42 Per - CPU process scheduler .
// Enable interrupts on this processor. // Loop over process table looking for process to run. //reset priority //for (p = GetReady(); p != 0; p = GetReady()){ // Switch to chosen process.  It is the process's job // to release ptable.lock and then reacquire it // before jumping back to us. // Process is done running for now. // It should have changed its p->state before coming back. //RemoveReadyList(p);