runproc()

runproc()

概要

引数

  • なし

実装

  492: /*
  493:  *  pick a process to run
  494:  */
  495: Proc*
  496: runproc(void)
  497: {
  498:         Schedq *rq;
  499:         Proc *p;
  500:         ulong start, now;
  501:         int i;
  502:         void (*pt)(Proc*, int, vlong);
  503: 
  504:         start = perfticks();
  • 詳細はperfticks()?を参照
  505: 
  506:         /* cooperative scheduling until the clock ticks */
  507:         if(coopsched && (p=m->readied) && p->mach==0 && p->state==Ready
  508:         && runq[Nrq-1].head == nil && runq[Nrq-2].head == nil){
  509:                 skipscheds++;
  510:                 rq = &runq[p->priority];
  511:                 goto found;
  512:         }
  513: 
  514:         preempts++;
  515: 
  516: loop:
  517:         /*
  518:          *  find a process that last ran on this processor (affinity),
  519:          *  or one that hasn't moved in a while (load balancing).  Every
  520:          *  time around the loop affinity goes down.
  521:          */
  522:         spllo();
  523:         for(i = 0;; i++){
  524:                 /*
  525:                  *  find the highest priority target process that this
  526:                  *  processor can run given affinity constraints.
  527:                  *
  528:                  */
  529:                 for(rq = &runq[Nrq-1]; rq >= runq; rq--){
  530:                         for(p = rq->head; p; p = p->rnext){
  531:                                 if(p->mp == nil || p->mp == MACHP(m->machno)
  532:                                 || (!p->wired && i > 0))
  533:                                         goto found;
  534:                         }
  535:                 }
  536: 
  537:                 /* waste time or halt the CPU */
  538:                 idlehands();
  • 詳細はidlehands()?を参照
  539: 
  540:                 /* remember how much time we're here */
  541:                 now = perfticks();
  542:                 m->perf.inidle += now-start;
  543:                 start = now;
  544:         }
  545: 
  546: found:
  547:         splhi();
  548:         p = dequeueproc(rq, p);
  549:         if(p == nil)
  550:                 goto loop;
  551: 
  552:         p->state = Scheding;
  553:         p->mp = MACHP(m->machno);
  554: 
  555:         if(edflock(p)){
  • 詳細はedflock()?を参照
  556:                 edfrun(p, rq == &runq[PriEdf]);       /* start deadline timer and do admin */
  • 詳細はedfrun()?を参照
  557:                 edfunlock();
  • 詳細はedfunlock()?を参照
  558:         }
  559:         pt = proctrace;
  • 詳細はproctrace()?を参照
  560:         if(pt)
  561:                 pt(p, SRun, 0);
  562:         return p;
  563: }