From fa9868be5fbb77ae1b8cc1427b6448221987a14a Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Wed, 1 May 1991 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1991-05-01 --- port/fault.c | 2 +- port/proc.c | 1 + port/stream.c | 2 +- port/sysfile.c | 2 ++ power/devbit3.c | 9 +++--- power/mem.h | 2 +- power/mmu.c | 77 +++++++++++++++++++++++++------------------------ 7 files changed, 51 insertions(+), 44 deletions(-) diff --git a/port/fault.c b/port/fault.c index e87d01c85a6514da962a91750b4b2e3797b8c917..e6423d7473635ce3b75a76908b59e44536fda9da 100644 --- a/port/fault.c +++ b/port/fault.c @@ -87,7 +87,7 @@ fault(ulong addr, int read) qunlock(&o->chan->rdl); pg->o = 0; pg->ref--; - pexit("load i/o error", 0); + pexit("demand load i/o error", 0); } l = (char*)VA(k); if((*devtab[o->chan->type].read)(o->chan, l, n, (addr-o->va) + o->minca) != n) diff --git a/port/proc.c b/port/proc.c index 48d0cb31a872e7f2223e5cc3fe23720b4d512060..8c7b410c5ad22919c46ddb549b3b32e22736fb17 100644 --- a/port/proc.c +++ b/port/proc.c @@ -118,6 +118,7 @@ ready(Proc *p) int s; s = splhi(); + if(p->state == Running) rq = &runloq; else diff --git a/port/stream.c b/port/stream.c index d444a046dd347654d280303fcf8b2f5877cd4573..211098ec5122ac7190489a6887e74bc02be1b7df 100644 --- a/port/stream.c +++ b/port/stream.c @@ -1149,7 +1149,7 @@ streamread(Chan *c, void *vbuf, long n) putbq(q, bp); left = 0; } - }; + } qunlock(&s->rdlock); poperror(); diff --git a/port/sysfile.c b/port/sysfile.c index bd4f3d15c93a5900c29c79705d1ddff09ba8dcac..d1edd79409d333ebfd84c2bbe52eec9c4e97e69b 100644 --- a/port/sysfile.c +++ b/port/sysfile.c @@ -227,6 +227,7 @@ sysread(ulong *arg) c = fdtochan(arg[0], OREAD); validaddr(arg[1], arg[2], 1); qlock(&c->rdl); + if(waserror()){ qunlock(&c->rdl); nexterror(); @@ -255,6 +256,7 @@ syswrite(ulong *arg) c = fdtochan(arg[0], OWRITE); validaddr(arg[1], arg[2], 0); qlock(&c->wrl); + if(waserror()){ qunlock(&c->wrl); nexterror(); diff --git a/power/devbit3.c b/power/devbit3.c index 21631fc8b3460f94085e295949d8745c5b5dc96f..1e9f68f190e5f45c1c3fb61745e6b8b80eba94c6 100644 --- a/power/devbit3.c +++ b/power/devbit3.c @@ -30,9 +30,6 @@ enum void bit3send(Bit3msg *bp, ulong cmd, void *addr, ulong count) { - int entry; - - entry = MACHP(0)->ticks; do; while(*BIT3ADDR); bp->cmd = cmd; bp->addr = (ulong)addr; @@ -40,7 +37,6 @@ bit3send(Bit3msg *bp, ulong cmd, void *addr, ulong count) *BIT3ADDR = bp; wbflush(); do; while(*BIT3HOLD); - m->spinlock += entry - MACHP(0)->ticks; *BIT3INTR = 0x20; } @@ -139,6 +135,7 @@ bit3read(Chan *c, void *buf, long n, ulong offset) { Bit3msg *bp; int docpy; + ulong t0; switch(c->qid.path){ case 1: @@ -153,9 +150,11 @@ bit3read(Chan *c, void *buf, long n, ulong offset) qlock(&bit3); bit3send(bp, READ, buf, n); qunlock(&bit3); + t0 = MACHP(0)->ticks; do n = bp->rcount; while(n == 0); + m->spinlock += MACHP(0)->ticks - t0; }else{ /* * use bit3 buffer. lock the buffer till the reply @@ -166,9 +165,11 @@ bit3read(Chan *c, void *buf, long n, ulong offset) qlock(&bit3); bit3send(bp, READ, bit3.buf, n); qunlock(&bit3); + t0 = MACHP(0)->ticks; do n = bp->rcount; while(n == 0); + m->spinlock += MACHP(0)->ticks - t0; memmove(buf, bit3.buf, n); qunlock(&bit3.buflock); } diff --git a/power/mem.h b/power/mem.h index e4a63db90d5056fcd3454c4447c012cb72a47958..7e3447d45639fd00c0ff37383eb0bca879f711b5 100644 --- a/power/mem.h +++ b/power/mem.h @@ -99,7 +99,7 @@ #define TLBPID(n) (((n)>>6)&0x3F) /* N.B. MUST CHANGE l.s utlbmiss if you want to change this */ -#define STLBLOG 13 +#define STLBLOG 11 #define STLBSIZE (1<= NTLBPID) s = 1; i = s; - for(h = m->pidhere; h[i] && i != s; i = (i == NTLBPID - 1 ? 1 : i + 1)) - ; - + h = m->pidhere; + do{ + i++; + if(i >= NTLBPID) + i = 1; + }while(h[i] && i != s); + if(i == s){ i++; if(i >= NTLBPID) i = 1; } - + if(h[i]) + purgetlb(i); sp = m->pidproc[i]; - m->lastpid = i; + if(sp && sp->pidonmach[m->machno] == i) + sp->pidonmach[m->machno] = 0; m->pidproc[i] = p; p->pidonmach[m->machno] = i; - if(sp){ - if(sp->pidonmach[m->machno] == i) - sp->pidonmach[m->machno] = 0; - if(h[i]) - purgetlb(i); - } + m->lastpid = i; return i; } @@ -85,48 +86,50 @@ putmmu(ulong tlbvirt, ulong tlbphys) spllo(); } -#ifdef POPCNT -void -stlbpopcnt(void) -{ - Softtlb *entry, *etab; - - entry = m->stb; - etab = &entry[STLBSIZE]; - for(; entry < etab; entry++) - if(entry->virt) - m->spinlock++; - - m->spinlock /= 2; -} -#endif - void purgetlb(int pid) { Softtlb *entry, *etab; - char *p; + char *pidhere; Proc *sp, **pidproc; int i, rpid, mno; + char dead[NTLBPID]; m->tlbpurge++; - p = m->pidhere; + /* + * find all pid entries that are no longer used by processes + */ + mno = m->machno; + pidproc = m->pidproc; + memset(dead, 0, sizeof dead); + for(i=1; ipidonmach[mno] != i){ + pidproc[i] = 0; + dead[i] = 1; + } + } + dead[pid] = 1; + /* + * clean out all dead pids from the stlb; + * garbage collect any pids with no entries + */ memset(m->pidhere, 0, sizeof m->pidhere); + pidhere = m->pidhere; entry = m->stb; etab = &entry[STLBSIZE]; - mno = m->machno; - pidproc = m->pidproc; for(; entry < etab; entry++){ rpid = TLBPID(entry->virt); - sp = pidproc[rpid]; - if(rpid == pid || !sp || sp->pidonmach[mno] != rpid){ - entry->phys = 0; + if(dead[rpid]) entry->virt = 0; - }else - p[rpid] = 1; + else + pidhere[rpid] = 1; } + /* + * clean up the hardware + */ for(i=TLBROFF; i