From c054d30736657f9a69f65d320ab94b47344ec036 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Wed, 17 Aug 1994 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1994-08-17 --- carrera/clock.c | 2 +- carrera/trap.c | 5 +++++ pc/fns.h | 2 ++ pc/main.c | 19 ++----------------- pc/mem.h | 5 ----- pc/trap.c | 33 --------------------------------- port/cache.c | 2 ++ port/devproc.c | 20 ++++++++++---------- port/page.c | 8 +++----- port/portdat.h | 5 ++++- port/portfns.h | 2 +- port/proc.c | 11 +++++++++-- port/segment.c | 4 ++-- port/swap.c | 2 ++ port/sysproc.c | 4 ++-- 15 files changed, 45 insertions(+), 79 deletions(-) diff --git a/carrera/clock.c b/carrera/clock.c index 3949a0b154954a142029f8d86679ee6a3d947db2..4c2db468d23f867127cdada3646369e35a49d035 100644 --- a/carrera/clock.c +++ b/carrera/clock.c @@ -93,7 +93,7 @@ clock(Ureg *ur) checkalarms(); mouseclock(); - if(up == 0 || (ur->status&IE) == 0 || up->state != Running) + if(up == 0 || up->state != Running) return; if(anyready()) diff --git a/carrera/trap.c b/carrera/trap.c index f1ad5c21af155c6c2ecf8cf4e382f1cc05a2bfa7..a3890a8d61e561114a68ae88023b4de90f96195f 100644 --- a/carrera/trap.c +++ b/carrera/trap.c @@ -361,12 +361,17 @@ intr(Ureg *ur) if(cause & INTR7) { clock(ur); cause &= ~INTR7; + return; } if(cause) { iprint("cause %lux\n", cause); exit(1); } + + /* preemptive scheduling */ + if(up && up->state == Running && anyhigher()) + sched(); } char* diff --git a/pc/fns.h b/pc/fns.h index c73bbadca4f881fe97bd17e16d5eac11790fea57..a4403daedbff864917f7b44c95c741a8c9cab25d 100644 --- a/pc/fns.h +++ b/pc/fns.h @@ -87,6 +87,8 @@ int tas(void*); void uartclock(void); void uartpoll(void); void vgainit(void); +void vgasavecrash(uchar*, int); +void vgarestorecrash(uchar*, int); int x86(void); #define waserror() (up->nerrlab++, setlabel(&up->errlab[up->nerrlab-1])) diff --git a/pc/main.c b/pc/main.c index 33c8e7b2e84d80af2c339029c66e6b1bf4abef1b..e6031e1902cef0c7c50b01b2c1463380342125a9 100644 --- a/pc/main.c +++ b/pc/main.c @@ -390,20 +390,13 @@ confinit(void) } /* - * zero and clear all except first 2 meg and crash area. - * put crash area at high end of memory. + * zero and clear all except first 2 meg. */ x = 0x12345678; for(i = MAXMEG; i > 1; i--){ if(mmap[i] != 'x') continue; - j = MB; - if(crasharea == 0){ - crasharea = (i+1)*MB - PGROUND(CRASHSIZE); - crashend = crasharea + CRASHSIZE; - j = MB - PGROUND(CRASHSIZE); - } - if(memclrtest(i, j, x) < 0) + if(memclrtest(i, MB, x) < 0) mmap[i] = ' '; x += 0x3141526; } @@ -418,8 +411,6 @@ confinit(void) ; conf.npage0 = (i*MB - ktop)/BY2PG; conf.topofmem = i*MB; - if(crasharea < conf.base0 + BY2PG*conf.npage0) - conf.npage0 -= PGROUND(CRASHSIZE)/BY2PG; /* * bank1 usually goes from the end of BOOTARGS to 640k @@ -441,15 +432,9 @@ confinit(void) ; conf.npage1 = (j - i)*MB/BY2PG; conf.topofmem = j*MB; - if(crasharea < conf.base1 + BY2PG*conf.npage1) - conf.npage1 -= PGROUND(CRASHSIZE)/BY2PG; break; } - /* make crasharea a virtual address */ - crasharea |= KZERO; - crashend |= KZERO; - conf.npage = conf.npage0 + conf.npage1; conf.ldepth = 0; if(pcnt < 10) diff --git a/pc/mem.h b/pc/mem.h index 4e9680c2bc343390eb60768641c71c4ab2422ad8..6db6f9fbfe38502cd8d8bf88600bd8f6d4e733df 100644 --- a/pc/mem.h +++ b/pc/mem.h @@ -55,11 +55,6 @@ #define MACHSIZE 4096 -/* - * an area for storing crash info to be picked up later - */ -#define CRASHSIZE (KSTACK+BY2PG) - /* * known 80386 segments (in GDT) and their selectors */ diff --git a/pc/trap.c b/pc/trap.c index 5a1cc7a0bb51acf880c50848fee75bd932e52b7a..d1d2338e6d459aefba3ea5933e900c6b300248de 100644 --- a/pc/trap.c +++ b/pc/trap.c @@ -61,19 +61,6 @@ struct int free; } halloc; -/* - * somewhere to drop crash info - */ -typedef struct -{ - ulong magic; - void *kbot; - void *ksp; - char text[NAMELEN]; - Ureg ureg; - uchar kstack[KSTACK]; -} Crashstate; - void sethvec(int v, void (*r)(void), int type, int pri) { @@ -353,7 +340,6 @@ dumpregs2(Ureg *ur) void dumpregs(Ureg *ur) { - Crashstate *cs; extern ulong etext; ulong *x; @@ -362,13 +348,6 @@ dumpregs(Ureg *ur) dumpregs2(ur); print(" magic %lux %lux %lux\n", x[0], x[1], x[2]); print(" ur %lux up %lux\n", ur, up); - - /* save crash info */ - if(crasharea == 0) - return; - print("crasharea 0x%lux\n", crasharea); - cs = (Crashstate*)crasharea; - memmove(&cs->ureg, ur, sizeof(Ureg)); } void @@ -376,7 +355,6 @@ dumpstack(void) { ulong l, v, i; extern ulong etext; - Crashstate *cs; if(up == 0) return; @@ -393,17 +371,6 @@ dumpstack(void) print("\n"); } } - - /* save crash info */ - if(crasharea == 0) - return; - print("crasharea 0x%lux\n", crasharea); - cs = (Crashstate*)crasharea; - memmove(cs->kstack, up->kstack, KSTACK); - cs->kbot = up->kstack; - memmove(cs->text, up->text, NAMELEN); - cs->magic = 0xdeaddead; - cs->ksp = &l; } /* diff --git a/port/cache.c b/port/cache.c index 5f61f76ec8c53aefba0cc2b6e2c1ad8478201780..91760b18672400b58399002d6e21e37c21a570b2 100644 --- a/port/cache.c +++ b/port/cache.c @@ -67,6 +67,8 @@ cinit(void) cache.tail = m; cache.tail->next = 0; cache.head->prev = 0; + + fscache.notext = 1; } void diff --git a/port/devproc.c b/port/devproc.c index 42fa5b5159ca55399b41bace2639547a7cc98383..478d0fba8946af54a0a8b7387ccd210c53b0bafc 100644 --- a/port/devproc.c +++ b/port/devproc.c @@ -49,10 +49,6 @@ Dirtab procdir[] = /* Segment type from portdat.h */ char *sname[]={ "Text", "Data", "Bss", "Stack", "Shared", "Phys", "Shdata" }; -/* where to put crash information when memory isn't wiped */ -ulong crasharea; -ulong crashend; - /* * Qids are, in path: * 4 bits of file type (qids above) @@ -318,12 +314,6 @@ procread(Chan *c, void *va, long n, ulong offset) memmove(a, (char*)offset, n); return n; } - if(offset >= crasharea && offset < crashend){ - if(offset+n > crashend) - n = crashend - offset; - memmove(a, (char*)offset, n); - return n; - } error(Ebadarg); case Qnote: @@ -697,6 +687,7 @@ void procctlreq(Proc *p, char *va, int n) { char buf[NAMELEN]; + int i; if(n > NAMELEN) n = NAMELEN; @@ -743,6 +734,15 @@ procctlreq(Proc *p, char *va, int n) error(Ebadctl); ready(p); } + else + if(strncmp(buf, "pri", 3) == 0){ + if(n < 4) + error(Ebadarg); + i = atoi(buf+4); + if(i < 0 || i >= Nrq) + error(Ebadarg); + p->basepri = i; + } else error(Ebadctl); } diff --git a/port/page.c b/port/page.c index 736576a1ffbc6ad41649ce10c6207287adf95066..df12d3568a5bbbc02482fd5519cfd345f9275110 100644 --- a/port/page.c +++ b/port/page.c @@ -250,11 +250,9 @@ duppage(Page *p) /* Always call with p locked */ Page *np; int color; - /* No dup for swap pages */ - if(p->image == &swapimage) { - uncachepage(p); + /* No dup for swap/cache pages */ + if(p->image->notext) return; - } lock(&palloc); /* No freelist cache when memory is very low */ @@ -333,7 +331,7 @@ uncachepage(Page *p) /* Always called with a locked page */ { Page **l, *f; - if(p->image == 0) + if(p->image == 0 || p->image->notext) return; lock(&palloc.hashlock); diff --git a/port/portdat.h b/port/portdat.h index a5569f7485d4c2d1c671852339dbddcb431170c0..17212e3a4e759d3d106609ffe92d83c74b0a2dad 100644 --- a/port/portdat.h +++ b/port/portdat.h @@ -315,6 +315,7 @@ struct Image Segment *s; /* TEXT segment for image if running */ Image *hash; /* Qid hash chains */ Image *next; /* Free list */ + int notext; /* no file associated */ }; struct Pte @@ -500,7 +501,9 @@ enum NERR = 15, NNOTE = 5, - Nrq = 5, + Nrq = 20, + PriNormal = 10, + PriRoot = 5, }; struct Proc diff --git a/port/portfns.h b/port/portfns.h index 707ac655ffb6fe4b1eeb978c03504b81058b59a2..67eba9326721f1d425c5ea6c26b45364eefa710f 100644 --- a/port/portfns.h +++ b/port/portfns.h @@ -1,8 +1,8 @@ void addrootfile(char*, uchar*, ulong); void alarmkproc(void*); Block* allocb(int); +int anyhigher(void); int anyready(void); -int anyready0(void); Image* attachimage(int, Chan*, ulong, ulong); long authcheck(Chan*, char*, int); void authclose(Chan*); diff --git a/port/proc.c b/port/proc.c index e20447d5a0df5eb867c94519ea7310f839268de7..94d0c0791f3971dec33ccfb4213237832a9d6b35 100644 --- a/port/proc.c +++ b/port/proc.c @@ -23,6 +23,7 @@ struct int nrdy; +int lastreadied; Schedq runq[Nrq]; char *statename[] = @@ -107,9 +108,13 @@ anyready(void) } int -anyready0(void) +anyhigher(void) { - return runq->head != 0; + int x; + + x = lastreadied; + lastreadied = Nrq; + return nrdy && x <= up->priority; } void @@ -138,6 +143,8 @@ ready(Proc *p) nrdy++; p->readyticks = m->ticks; p->state = Ready; + if(lastreadied > p->priority) + lastreadied = p->priority; unlock(runq); splx(s); } diff --git a/port/segment.c b/port/segment.c index 84d47e91ef2506b06be1a7fd1b6a5b663b6c1708..df3c8ccf08f0e6db39233a3a0735fe9b0626d0e3 100644 --- a/port/segment.c +++ b/port/segment.c @@ -274,7 +274,7 @@ imagereclaim(void) lock(&palloc); for(p = palloc.head; p; p = p->next) { if(p->ref == 0 && p->image && canlock(p)) { - if(p->ref == 0 && p->image != &swapimage) + if(p->ref == 0) uncachepage(p); unlock(p); } @@ -289,7 +289,7 @@ putimage(Image *i) Chan *c; Image *f, **l; - if(i == &swapimage) + if(i->notext) return; lock(i); diff --git a/port/swap.c b/port/swap.c index cd8b3c004b38fe273b449f1a6c09aeb219442980..f3e798ea40f6e178e769420e678c12e6109c66fd 100644 --- a/port/swap.c +++ b/port/swap.c @@ -33,6 +33,8 @@ swapinit(void) iolist = xalloc(Maxpages*sizeof(Page*)); if(swapalloc.swmap == 0 || iolist == 0) panic("swapinit: not enough memory"); + + swapimage.notext = 1; } ulong diff --git a/port/sysproc.c b/port/sysproc.c index 5efec57f7e46080f376a078d232ad737168cd62f..cd824976af0d02d3329f5b20cf2f87317560e724 100644 --- a/port/sysproc.c +++ b/port/sysproc.c @@ -397,9 +397,9 @@ sysexec(ulong *arg) * '/' processes are high priority (hack to make /ip more responsive) */ if(devchar[tc->type] == L'/') - up->basepri = 0; + up->basepri = PriRoot; else - up->basepri = 1; + up->basepri = PriNormal; up->priority = up->basepri; poperror(); close(tc);