From f82a40df0ac2adde7d333a809dbb4d22f58547e6 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Sun, 12 Dec 1993 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1993-12-12 --- carrera/devether.c | 40 +++++++++++++++++++--------------------- carrera/l.s | 25 ------------------------- carrera/mmu.c | 14 ++++++++++---- carrera/trap.c | 10 +--------- port/devproc.c | 9 +-------- port/fault.c | 27 +++++++++++++-------------- port/page.c | 4 ++-- port/portdat.h | 4 +++- port/proc.c | 25 +++++++++++-------------- port/sysproc.c | 1 - 10 files changed, 60 insertions(+), 99 deletions(-) diff --git a/carrera/devether.c b/carrera/devether.c index a3e03b49b94436489ea44872e648c2555d907872..500d76292bee6bdf56f16e593d23c4aaa7936f5f 100644 --- a/carrera/devether.c +++ b/carrera/devether.c @@ -75,7 +75,7 @@ typedef struct enum { Nrb = 16, /* receive buffers */ - Ntb = 8, /* transmit buffers */ + Ntb = 16, /* transmit buffers */ }; enum @@ -425,6 +425,14 @@ sonicpkt(Ether *ctlr, RXpkt *r, Pbuf *p) } } +static int +isoutbuf(void *arg) +{ + Ether *ctlr = arg; + + return ctlr->tda[ctlr->th].status == Host; +} + void etherintr(void) { @@ -462,7 +470,8 @@ etherintr(void) txpkt = &c->tda[c->ti]; } status &= ~(Txdn|Txer); - wakeup(&c->tr); + if(isoutbuf(c)) + wakeup(&c->tr); } if((status & (Pktrx|Rde)) == 0) @@ -514,7 +523,7 @@ etherintr(void) status &= ~Lcd; /* - * Warnings that something is afoot. + * Warnings that something is atoe. */ if(status & Hbl){ print("sonic: cd heartbeat lost\n"); @@ -674,14 +683,6 @@ etherread(Chan *c, void *buf, long n, ulong offset) return netifread(ether[0], c, buf, n, offset); } -static int -isoutbuf(void *arg) -{ - Ether *ctlr = arg; - - return ctlr->tda[ctlr->th].status == Host; -} - static int etherloop(Etherpkt *p, long n) { @@ -722,13 +723,13 @@ etherwrite(Chan *c, void *buf, long n, ulong offset) USED(offset); - if(n > ETHERMAXTU) - error(Ebadarg); - /* etherif.c handles structure */ if(NETTYPE(c->qid.path) != Ndataqid) return netifwrite(ether[0], c, buf, n); + if(n > ETHERMAXTU) + error(Ebadarg); + /* we handle data */ if(etherloop(buf, n)) return n; @@ -739,15 +740,12 @@ etherwrite(Chan *c, void *buf, long n, ulong offset) nexterror(); } - tsleep(&ctlr->tr, isoutbuf, ctlr, 1000); + tsleep(&ctlr->tr, isoutbuf, ctlr, 10000); - if(!isoutbuf(ctlr)) { - print("ether transmitter jammed\n"); - reset(ctlr); - WR(cr, Rxen); - } + if(!isoutbuf(ctlr)) + print("ether transmitter jammed cr #%lux\n", RD(cr)); else { - p =(Pbuf*)ctlr->tb[ctlr->th]; + p = (Pbuf*)ctlr->tb[ctlr->th]; memmove(p->d, buf, n); if(n < 60) { memset(p->d+n, 0, 60-n); diff --git a/carrera/l.s b/carrera/l.s index 9718fd5477b44fe19bf123de7e7d9b5b425a07a0..eec3b94c7db726e75e256270d4fcb53488d30623 100644 --- a/carrera/l.s +++ b/carrera/l.s @@ -432,31 +432,6 @@ wasuser: BNE R26, notsys JAL syscall(SB) - MOVW R0, R2 - MOVW R0, R3 - MOVW R0, R4 - MOVW R0, R5 - MOVW R0, R6 - MOVW R0, R7 - MOVW R0, R8 - MOVW R0, R9 - MOVW R0, R10 - MOVW R0, R11 - MOVW R0, R12 - MOVW R0, R13 - MOVW R0, R14 - MOVW R0, R15 - MOVW R0, R16 - MOVW R0, R17 - MOVW R0, R18 - MOVW R0, R19 - MOVW R0, R20 - MOVW R0, R21 - MOVW R0, R22 - MOVW R0, R23 - MOVW R0, R24 - MOVW R0, R25 - MOVW R0, R27 sysrestore: MOVW 0x28(SP), R31 diff --git a/carrera/mmu.c b/carrera/mmu.c index 405a40ec41c6a6fa1a0973e1689c03f8ef7200b8..7a0989afbbfe3f55b37ab451eb83e06a6014750c 100644 --- a/carrera/mmu.c +++ b/carrera/mmu.c @@ -287,13 +287,19 @@ putmmu(ulong tlbvirt, ulong tlbphys, Page *pg) puttlb(entry->virt, entry->phys0, entry->phys1); ctl = &pg->cachectl[m->machno]; - if(*ctl == PG_DATFLUSH) { + switch(*ctl) { + case PG_TXTFLUSH: + icflush((void*)pg->va, BY2PG); + *ctl = PG_NOFLUSH; + break; + case PG_DATFLUSH: dcflush((void*)pg->va, BY2PG); *ctl = PG_NOFLUSH; - }else - if(*ctl == PG_TXTFLUSH) { - icflush((void*)pg->va, BY2PG); + break; + case PG_NEWCOL: + cleancache(); /* Too expensive */ *ctl = PG_NOFLUSH; + break; } splx(s); } diff --git a/carrera/trap.c b/carrera/trap.c index 4f780ae4cc2b5bbc30b2e1bb2912967ad13c1fd9..e20e330b90c956ab559ec942c9400bfae765775c 100644 --- a/carrera/trap.c +++ b/carrera/trap.c @@ -201,13 +201,6 @@ trap(Ureg *ur) case CTLBM: case CTLBL: case CTLBS: -{ -((ulong*)0xA0090000)[0] = ur->pc; -((ulong*)0xA0090000)[1] = ur->badvaddr; -((ulong*)0xA0090000)[2] = ur->cause; -((ulong*)0xA0090000)[3] = 0x12345678; -((ulong*)0xA0090000)[4] = 0x87654321; -} if(up == 0) kernfault(ur, ecode); @@ -299,7 +292,6 @@ intr(Ureg *ur) switch(devint) { default: panic("unknown devint=#%lux", devint); - case 0x28: /* Serial 1 */ NS16552intr(0); break; @@ -329,7 +321,7 @@ intr(Ureg *ur) } if(cause & INTR4) { devint = IO(uchar, I386ack); - iprint("i386ack=#%lux\n", devint); + iprint("i386ACK #%lux\n", devint); cause &= ~INTR4; } diff --git a/port/devproc.c b/port/devproc.c index 18a0989ff9c7381a403952f00b652f3b6a2d3d93..ff6e6ff17f716714a102db9cc19e21bf824fd8d4 100644 --- a/port/devproc.c +++ b/port/devproc.c @@ -697,8 +697,8 @@ procstopwait(Proc *p, int ctl) void procctlreq(Proc *p, char *va, int n) { - int i; char buf[NAMELEN]; + extern int pfthreshold; if(n > NAMELEN) n = NAMELEN; @@ -745,13 +745,6 @@ procctlreq(Proc *p, char *va, int n) error(Ebadctl); ready(p); } - else - if(strncmp(buf, "cpu ", 4) == 0) { - i = strtoul(buf+4, 0, 0); - if(i < 0 || i >= conf.nmach) - error(Ebadctl); - p->mp = MACHP(i); - } else error(Ebadctl); } diff --git a/port/fault.c b/port/fault.c index 1051d039f4baa9a67c90c4473a786ab839ecbd06..4a58a4fc159360ec555b5141902975fe58c096d0 100644 --- a/port/fault.c +++ b/port/fault.c @@ -43,7 +43,7 @@ fault(ulong addr, int read) int fixfault(Segment *s, ulong addr, int read, int doputmmu) { - int i, type; + int type; Pte **p, *etp; ulong mmuphys=0, soff; Page **pg, *lkp, *new; @@ -69,15 +69,15 @@ fixfault(Segment *s, ulong addr, int read, int doputmmu) panic("fault"); break; - case SG_TEXT: - if(pagedout(*pg)) /* Demand load */ + case SG_TEXT: /* Demand load */ + if(pagedout(*pg)) pio(s, addr, soff, pg); mmuphys = PPN((*pg)->pa) | PTERONLY|PTEVALID; (*pg)->modref = PG_REF; break; - case SG_SHDATA: /* Shared data */ + case SG_SHDATA: /* Shared data */ if(pagedout(*pg)) pio(s, addr, soff, pg); @@ -89,7 +89,7 @@ fixfault(Segment *s, ulong addr, int read, int doputmmu) goto done; case SG_BSS: - case SG_SHARED: /* Zero fill on demand */ + case SG_SHARED: /* Zero fill on demand */ case SG_STACK: if(*pg == 0) { new = newpage(1, &s, addr); @@ -100,7 +100,7 @@ fixfault(Segment *s, ulong addr, int read, int doputmmu) } /* NO break */ - case SG_DATA: /* Demand load/pagein/copy on write */ + case SG_DATA: /* Demand load/pagein/copy on write */ if(pagedout(*pg)) pio(s, addr, soff, pg); @@ -108,7 +108,7 @@ fixfault(Segment *s, ulong addr, int read, int doputmmu) goto done; if(read && conf.copymode == 0) { - mmuphys = PPN((*pg)->pa) | /*PTERONLY|*/PTEVALID; + mmuphys = PPN((*pg)->pa)|PTERONLY|PTEVALID; (*pg)->modref |= PG_REF; break; } @@ -125,7 +125,9 @@ fixfault(Segment *s, ulong addr, int read, int doputmmu) putpage(lkp); } else { - /* put a duplicate of a text page back onto the free list */ + /* put a duplicate of a text page back onto + * the free list + */ if(lkp->image) duppage(lkp); @@ -152,15 +154,9 @@ fixfault(Segment *s, ulong addr, int read, int doputmmu) mmuphys = PPN((*pg)->pa) |PTEWRITE|PTEUNCACHED|PTEVALID; (*pg)->modref = PG_MOD|PG_REF; -/* print("v %lux p %lux\n", addr, mmuphys); /**/ break; } - if(s->flushme) { - for(i = 0; i < MAXMACH; i++) - (*pg)->cachectl[i] = PG_TXTFLUSH; - } - qunlock(&s->lk); if(doputmmu) @@ -262,6 +258,9 @@ pio(Segment *s, ulong addr, ulong soff, Page **p) else putpage(new); } + + if(s->flushme) + memset((*p)->cachectl, PG_TXTFLUSH, sizeof((*p)->cachectl)); } void diff --git a/port/page.c b/port/page.c index fc9933458825489c6409432d84e2bb8601d60ed4..b2ec448931bd352f2a535bce86ec8694c4d6473b 100644 --- a/port/page.c +++ b/port/page.c @@ -112,7 +112,7 @@ retry: lock(&palloc); } - /* First try for out colour */ + /* First try for our colour */ for(p = palloc.head; p; p = p->next) if(p->color == color) break; @@ -120,7 +120,7 @@ retry: if(p == 0) { print("! "); p = palloc.head; - memset(p->cachectl, PG_DATFLUSH, sizeof(p->cachectl)); + memset(p->cachectl, PG_NEWCOL, sizeof(p->cachectl)); p->color = color; } diff --git a/port/portdat.h b/port/portdat.h index 17a7e3fadc76cf8668e99660da456d0e53a81b24..9296263c85f04752f22f28c415190002ed11a389 100644 --- a/port/portdat.h +++ b/port/portdat.h @@ -247,6 +247,7 @@ enum PG_NOFLUSH = 0, PG_TXTFLUSH = 1, /* flush icache */ PG_DATFLUSH = 2, /* flush both i & d caches */ + PG_NEWCOL = 3, /* page has been recolored */ PG_MOD = 0x01, /* software modified bit */ PG_REF = 0x02, /* software referenced bit */ @@ -554,7 +555,8 @@ struct Proc Note lastnote; int (*notify)(void*, char*); - Mach *mp; /* machine this process is tied to */ + Mach *mp; /* machine this process last ran on */ + ulong mpfault; /* page faults on that mach at sched time */ void *ureg; /* User registers for notes */ void *dbgreg; /* User registers for devproc */ diff --git a/port/proc.c b/port/proc.c index 01d6c674d284692e1f11b3426d9de5d3d3cb4d56..54a20c419af1019f129c792778be7884d0d3c609 100644 --- a/port/proc.c +++ b/port/proc.c @@ -79,10 +79,13 @@ sched(void) { if(up) { splhi(); + + /* statistics */ m->cs++; up->counter[CSCNTR]++; -up->counter[TLBCNTR] += m->tlbfault - m->otlbfault; -m->otlbfault = m->tlbfault; + up->counter[TLBCNTR] += m->tlbfault - m->otlbfault; + m->otlbfault = m->tlbfault; + procsave(up); if(setlabel(&up->sched)) { procrestore(up); @@ -102,7 +105,7 @@ m->otlbfault = m->tlbfault; int anyready(void) { - return runloq.head != 0 || runhiq.head != 0 || m->runq.head != 0; + return runhiq.head != 0 || runloq.head != 0; } void @@ -113,12 +116,10 @@ ready(Proc *p) s = splhi(); - rq = &runhiq; - if(p->mp) - rq = &p->mp->runq; - else if(p->state == Running) rq = &runloq; + else + rq = &runhiq; lock(&runhiq); p->rnext = 0; @@ -142,21 +143,16 @@ runproc(void) loop: spllo(); - while(runhiq.head == 0 && runloq.head == 0 && m->runq.head == 0) + while(runhiq.head == 0 && runloq.head == 0) ; - splhi(); - lock(&runhiq); - - if(m->runq.head) - rq = &m->runq; - else if(runhiq.head) rq = &runhiq; else rq = &runloq; + lock(&runhiq); p = rq->head; /* p->mach==0 only when process state is saved */ if(p == 0 || p->mach){ @@ -170,6 +166,7 @@ loop: if(p->state != Ready) print("runproc %s %d %s\n", p->text, p->pid, statename[p->state]); unlock(&runhiq); + p->state = Scheding; return p; } diff --git a/port/sysproc.c b/port/sysproc.c index e4975b0cd36381ff1b513fc0c2dd655a5c66a183..07ff2582fd36e9fc723865422ee13c2cd1d0945e 100644 --- a/port/sysproc.c +++ b/port/sysproc.c @@ -160,7 +160,6 @@ sysrfork(ulong *arg) p->time[TReal] = MACHP(0)->ticks; memmove(p->text, up->text, NAMELEN); memmove(p->user, up->user, NAMELEN); - p->mp = up->mp; /* * since the bss/data segments are now shareable, * any mmu info about this process is now stale