From 4e977453254647fbbbf676d9f232cb4cacd868d1 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Sun, 18 Sep 1994 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1994-09-18 --- port/portdat.h | 2 +- port/proc.c | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/port/portdat.h b/port/portdat.h index 18055d7dc223f964e64c481ed80b221ee8717162..664d9590035dbc4e66881e45577cc2862170d1dd 100644 --- a/port/portdat.h +++ b/port/portdat.h @@ -588,7 +588,7 @@ struct Proc ulong rt; /* # ticks used since last blocked */ ulong art; /* avg # ticks used since last blocked */ ulong movetime; /* last time process switched processors */ - ulong readyticks; /* time process went ready */ + ulong readytime; /* time process went ready */ void *ureg; /* User registers for notes */ void *dbgreg; /* User registers for devproc */ diff --git a/port/proc.c b/port/proc.c index c9d2f3f4e1b3ec87023c5d7fce2f224474a05d46..8d934f71c875ecaa3199ef71c67c630b53a986b1 100644 --- a/port/proc.c +++ b/port/proc.c @@ -142,6 +142,7 @@ ready(Proc *p) pri = p->basepri - (((p->art + p->rt)>>1)/Squantum); if(pri < 0) pri = 0; + p->priority = pri; rq = &runq[p->priority]; lock(runq); @@ -153,7 +154,7 @@ ready(Proc *p) rq->tail = p; rq->n++; nrdy++; - p->readyticks = m->ticks; + p->readytime = m->ticks; p->state = Ready; if(p->priority > lastreadied) lastreadied = p->priority; @@ -164,8 +165,10 @@ ready(Proc *p) Proc* runproc(void) { + int i; Schedq *rq; Proc *p, *l; + static ulong lastfair; loop: @@ -175,6 +178,32 @@ loop: */ spllo(); for(;;){ + /* + * Once a second we look for a long waiting process + * in the lowest priority queue to make sure nothing + * gets starved out by a malfunctioning high priority + * process. + */ + if(m->machno == 0 && m->ticks - lastfair > HZ){ + lastfair = m->ticks; + for(rq = runq; rq < &runq[Nrq]; rq++){ + p = rq->head; + if(p){ + i = m->ticks - p->readytime; + if(i > HZ){ + p->art = 0; + p->movetime = 0; + goto found; + } + break; + } + } + } + + /* + * get highest priority process that this + * processor can run given affinity constraints + */ for(rq = &runq[Nrq-1]; rq >= runq; rq--){ if(rq->head == 0) continue; @@ -750,7 +779,7 @@ procdump(void) continue; print("rq%d:", rq-runq); for(p = rq->head; p; p = p->rnext) - print(" %d(%d)", p->pid, m->ticks - p->readyticks); + print(" %d(%d)", p->pid, m->ticks - p->readytime); print("\n"); } print("nrdy %d\n", nrdy);