M port/fault.c => port/fault.c +1 -1
@@ 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)
M port/proc.c => port/proc.c +1 -0
@@ 118,6 118,7 @@ ready(Proc *p)
int s;
s = splhi();
+
if(p->state == Running)
rq = &runloq;
else
M port/stream.c => port/stream.c +1 -1
@@ 1149,7 1149,7 @@ streamread(Chan *c, void *vbuf, long n)
putbq(q, bp);
left = 0;
}
- };
+ }
qunlock(&s->rdlock);
poperror();
M port/sysfile.c => port/sysfile.c +2 -0
@@ 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();
M power/devbit3.c => power/devbit3.c +5 -4
@@ 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);
}
M power/mem.h => power/mem.h +1 -1
@@ 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<<STLBLOG)
#define NTLBPID 64 /* number of pids */
M power/mmu.c => power/mmu.c +40 -37
@@ 40,25 40,26 @@ newtlbpid(Proc *p)
if(s >= 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; i<NTLBPID; i++){
+ sp = pidproc[i];
+ if(!sp || sp->pidonmach[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<NTLB; i++)
- if(!p[TLBPID(gettlbvirt(i))])
+ if(!pidhere[TLBPID(gettlbvirt(i))])
puttlbx(i, KZERO | PTEPID(i), 0);
}