sched()

sched()

概要

引数

  • なし

実装

  109: /*
  110:  *  If changing this routine, look also at sleep().  It
  111:  *  contains a copy of the guts of sched().
  112:  */
  113: void
  114: sched(void)
  115: {
  116:         Proc *p;
  117: 
  118:         if(m->ilockdepth)
  119:                 panic("ilockdepth %d, last lock 0x%p at 0x%lux, sched called from 0x%lux",
  120:                         m->ilockdepth, up?up->lastilock:nil,
  121:                         (up && up->lastilock)?up->lastilock->pc:0,
  122:                         getcallerpc(&p+2));
  123: 
  124:         if(up){
  125:                 /*
  126:                  * Delay the sched until the process gives up the locks
  127:                  * it is holding.  This avoids dumb lock loops.
  128:                  * Don't delay if the process is Moribund.
  129:                  * It called sched to die.
  130:                  * But do sched eventually.  This avoids a missing unlock
  131:                  * from hanging the entire kernel. 
  132:                  * But don't reschedule procs holding palloc or procalloc.
  133:                  * Those are far too important to be holding while asleep.
  134:                  *
  135:                  * This test is not exact.  There can still be a few instructions
  136:                  * in the middle of taslock when a process holds a lock
  137:                  * but Lock.p has not yet been initialized.
  138:                  */
  139:                 if(up->nlocks.ref)
  140:                 if(up->state != Moribund)
  141:                 if(up->delaysched < 20
  142:                 || palloc.Lock.p == up
  143:                 || procalloc.Lock.p == up){
  144:                         up->delaysched++;
  145:                         delayedscheds++;
  146:                         return;
  147:                 }
  148:                 up->delaysched = 0;
  149: 
  150:                 splhi();
  151: 
  152:                 /* statistics */
  153:                 m->cs++;
  154: 
  155:                 procsave(up);
  156:                 if(setlabel(&up->sched)){
  • 詳細はsetlabel()?を参照
  157:                         procrestore(up);
  158:                         spllo();
  159:                         return;
  160:                 }
  161:                 gotolabel(&m->sched);
  • 詳細はgotolabel()?を参照
  162:         }
  163:         p = runproc();
  164:         if(!p->edf){
  165:                 updatecpu(p);
  166:                 p->priority = reprioritize(p);
  167:         }
  168:         if(p != m->readied)
  169:                 m->schedticks = m->ticks + HZ/10;
  170:         m->readied = 0;
  171:         up = p;
  172:         up->state = Running;
  173:         up->mach = MACHP(m->machno);
  174:         m->proc = up;
  175:         mmuswitch(up);
  176:         gotolabel(&up->sched);
  177: }