vx32

Local 9vx git repository for patches.
git clone git://r-36.net/vx32
Log | Files | Refs

commit a3985efe6946ed22480d95497c21a5fce3d8c678
parent 2c77246844ef513be4f03fd34c2dc656aed31b1c
Author: yiyus <yiyu.jgl@gmail.com>
Date:   Tue, 20 Jul 2010 16:39:08 +0200

a/*.ed updates: almost done

Diffstat:
src/9vx/a/page.c | 6+++---
src/9vx/a/pgrp.c | 2+-
src/9vx/a/portclock.ed | 6------
src/9vx/a/portdat.ed | 8+++++++-
src/9vx/a/portdat.h | 7+++----
src/9vx/a/portfns.ed | 17++++++++++++++++-
src/9vx/a/portfns.h | 1+
src/9vx/a/proc.c | 35++++++++++++++++++-----------------
src/9vx/a/proc.ed | 26+++++++++++++++++++++++---
src/9vx/a/qio.c | 11++++++-----
10 files changed, 78 insertions(+), 41 deletions(-)

diff --git a/src/9vx/a/page.c b/src/9vx/a/page.c @@ -129,7 +129,7 @@ newpage(int clear, Segment **s, ulong va) color = getpgcolor(va); hw = swapalloc.highwater; for(;;) { - if(palloc.freecount >= hw) + if(palloc.freecount > hw) break; if(up->kp && palloc.freecount > 0) break; @@ -182,7 +182,7 @@ newpage(int clear, Segment **s, ulong va) lock(&p->lk); if(p->ref != 0) - panic("newpage"); + panic("newpage: p->ref %d != 0", p->ref); uncachepage(p); p->ref++; @@ -641,7 +641,7 @@ portcountpagerefs(ulong *ref, int print) if(s == nil) continue; if(s->ref.ref != s->mark){ - iprint("segment %#.8lux (used by proc %lud pid %lud) has bad ref count %lud actual %lud\n", + iprint("segment %#p (used by proc %lud pid %lud) has bad ref count %lud actual %lud\n", s, i, p->pid, s->ref, s->mark); } } diff --git a/src/9vx/a/pgrp.c b/src/9vx/a/pgrp.c @@ -180,7 +180,7 @@ dupfgrp(Fgrp *f) lock(&f->ref.lk); /* Make new fd list shorter if possible, preserving quantization */ new->nfd = f->maxfd+1; - i = (uint)new->nfd%DELTAFD; + i = new->nfd%DELTAFD; if(i != 0) new->nfd += DELTAFD - i; new->fd = malloc(new->nfd*sizeof(Chan*)); diff --git a/src/9vx/a/portclock.ed b/src/9vx/a/portclock.ed @@ -1,6 +0,0 @@ -,s/lock(tt)/lock(\&tt->lk)/ -,s/Lock;/Lock lk;/ -,s/lock(nt)/lock(\&nt->lk)/ -,s/lock(dt)/lock(\&dt->lk)/ -/^timerintr/ s/Tval/Tval v/ -,s/lock(\&timers\[0\])/lock(\&timers[0].lk)/ diff --git a/src/9vx/a/portdat.ed b/src/9vx/a/portdat.ed @@ -10,7 +10,9 @@ g/CCREATE/d v/typedef/ s!Ref;!Ref ref;!g v/typedef/ s/Rendez;/Rendez rendez;/g v/typedef/ s/RWlock;/RWlock lk;/g - +/ulong args/s/ulong/uint32/ +/notify/s/i.*;/ulong notify;/ +/ureg/s/void \*/ulong / /^ RFNAMEG/-3i // Plan 9 VX added for help with FreeBSD #undef RFNAMEG @@ -30,6 +32,10 @@ v/typedef/ s/RWlock;/RWlock lk;/g v/typedef/ s/Timer;/Timer timer;/g /Notsave;/ s/Notsave;/Notsave notsave;/ ,s/PMMU;/PMMU pmmu;/g +/PMMU/a + /* syscall trace */ + char *syscalltrace; +. $a void printmap(void); // Plan 9 VX diff --git a/src/9vx/a/portdat.h b/src/9vx/a/portdat.h @@ -744,7 +744,7 @@ struct Proc int setargs; - ulong ureg; /* User registers for notes */ + ulong ureg; /* User registers for notes */ void *dbgreg; /* User registers for devproc */ Notsave notsave; @@ -762,7 +762,8 @@ enum MAXCRYPT = 127, NUMSIZE = 12, /* size of formatted number */ MB = (1024*1024), - READSTR = 1000, /* temporary buffer size for device reads */ + /* READSTR was 1000, which is way too small for usb's ctl file */ + READSTR = 4000, /* temporary buffer size for device reads */ }; extern Conf conf; @@ -958,9 +959,7 @@ enum Qkick = (1<<5), /* always call the kick routine after qwrite */ }; - #define DEVDOTDOT -1 - void printmap(void); // Plan 9 VX diff --git a/src/9vx/a/portfns.ed b/src/9vx/a/portfns.ed @@ -8,8 +8,21 @@ #define reboot _kreboot #undef _assert #define _assert __kassert +#define rand _krand +#define memrchr _kmemrchr . +/ canqlock/s/canqlock/__&/ +/ canrlock/s/canrlock/__&/ +/ lock/s/lock/__&/ +/ qlock/s/qlock/__&/ +/ rlock/s/rlock/__&/ +/okaddr/s/int/void*/ +/ qunlock/s/qunlock/__&/ +/ runlock/s/runlock/__&/ +/ unlock/s/unlock/__&/ +/ wlock/s/wlock/__&/ +/ wunlock/s/wunlock/__&/ g/gotolabel/d g/setlabel/d $a @@ -25,6 +38,8 @@ Proc* _runproc(void); void uartecho(char*, int); void vx32sysr1(void); void vxnewproc(Proc*); - +void mmusize(int); +void plimitproc(void*); +void ploadproc(void*); . g/ยต/d diff --git a/src/9vx/a/portfns.h b/src/9vx/a/portfns.h @@ -366,6 +366,7 @@ uvlong us2fastticks(uvlong); void userinit(void); ulong userpc(void); long userwrite(char*, int); +void validaddr(ulong, ulong, int); void validname(char*, int); char* validnamedup(char*, int); void validstat(uchar*, int); diff --git a/src/9vx/a/proc.c b/src/9vx/a/proc.c @@ -1,11 +1,11 @@ #define WANT_M -#include "u.h" +#include "u.h" #include "lib.h" #include "mem.h" #include "dat.h" #include "fns.h" #include "error.h" -#include "trace.h" +#include "trace.h" int schedgain = 30; /* units in seconds */ int nrdy; @@ -112,11 +112,12 @@ sched(void) if(traceprocs) // Plan 9 VX print("sched %p %p [%s]\n", m, up, up ? up->text : ""); if(m->ilockdepth) - panic("ilockdepth %d, last lock 0x%p at 0x%lux, sched called from 0x%lux", - m->ilockdepth, up?up->lastilock:nil, - (up && up->lastilock)?up->lastilock->pc:0, + panic("cpu%d: ilockdepth %d, last lock %#p at %#p, sched called from %#p", + m->machno, + m->ilockdepth, + up? up->lastilock: nil, + (up && up->lastilock)? up->lastilock->pc: 0, getcallerpc(&p+2)); - if(up){ /* * Delay the sched until the process gives up the locks @@ -743,12 +744,12 @@ sleep(Rendez *r, int (*f)(void*), void *arg) s = splhi(); if(up->nlocks.ref) - print("process %lud sleeps with %lud locks held, last lock 0x%p locked at pc 0x%lux, sleep called from 0x%lux\n", + print("process %lud sleeps with %lud locks held, last lock %#p locked at pc %#lux, sleep called from %#p\n", up->pid, up->nlocks.ref, up->lastlock, up->lastlock->pc, getcallerpc(&r)); lock(&r->lk); lock(&up->rlock); if(r->p){ - print("double sleep called from 0x%lux, %lud %lud\n", getcallerpc(&r), r->p->pid, up->pid); + print("double sleep called from %#p, %lud %lud\n", getcallerpc(&r), r->p->pid, up->pid); dumpstack(); } @@ -766,7 +767,7 @@ sleep(Rendez *r, int (*f)(void*), void *arg) * never mind */ if(traceprocs) - print("cpu%d: %ld sleep: already happened\n", m->machno, up->pid); + print("sleep %p %p: already happened\n", m, up); r->p = nil; unlock(&up->rlock); unlock(&r->lk); @@ -787,7 +788,7 @@ sleep(Rendez *r, int (*f)(void*), void *arg) procsave(up); if(setlabel(&up->sched)) { if(traceprocs) - print("cpu%d: %ld sleep: awake\n", m->machno, up->pid); + print("sleep %p %p: awake\n", m, up); /* * here when the process is awakened */ @@ -795,7 +796,7 @@ sleep(Rendez *r, int (*f)(void*), void *arg) spllo(); } else { if(traceprocs) - print("cpu%d: %ld sleep: sleeping\n", m->machno, up->pid); + print("sleep %p %p: sleeping\n", m, up); /* * here to go to sleep (i.e. stop Running) */ @@ -838,8 +839,8 @@ twakeup(Ureg *ureg, Timer *t) void tsleep(Rendez *r, int (*fn)(void*), void *arg, ulong ms) { - if(up->timer.tt){ - print("tsleep: timer active: mode %d, tf 0x%lux\n", up->timer.tmode, up->timer.tf); + if (up->timer.tt){ + print("tsleep: timer active: mode %d, tf %#p\n", up->timer.tmode, up->timer.tf); timerdel(&up->timer); } up->timer.tns = MS2NS(ms); @@ -855,7 +856,7 @@ tsleep(Rendez *r, int (*fn)(void*), void *arg, ulong ms) nexterror(); } sleep(r, tfn, arg); - if(up->timer.tt) + if (up->timer.tt) timerdel(&up->timer); up->timer.twhen = 0; poperror(); @@ -1054,7 +1055,7 @@ pexit(char *exitstr, int freemem) if(up->syscalltrace) free(up->syscalltrace); up->alarm = 0; - if(up->timer.tt) + if (up->timer.tt) timerdel(&up->timer); pt = proctrace; if(pt) @@ -1316,9 +1317,9 @@ procflushseg(Segment *s) * wait for all processors to take a clock interrupt * and flush their mmu's */ - for(nm = 0; nm < conf.nmach && nm < 1; nm++) + for(nm = 0; nm < conf.nmach; nm++) if(MACHP(nm) != m) - while(MACHP(nm)->flushmmu && MACHP(nm)->proc != nil) + while(MACHP(nm)->flushmmu) sched(); } diff --git a/src/9vx/a/proc.ed b/src/9vx/a/proc.ed @@ -1,3 +1,6 @@ +1i +#define WANT_M +. /edf.*Admitted/,/edfrecord/d /edfstop/,/edf = nil/d ,s/(!p->edf)/(1)/ @@ -8,7 +11,7 @@ g/edfstop(up)/d ,s/lock(runq)/lock(\&runq->lk)/ ,s/lock(\&procalloc)/lock(\&procalloc.lk)/ ,s/lock(r)/lock(\&r->lk)/ -/^newproc/ +/^newproc/ s/^// /^ return p/i vxnewproc(p); . @@ -26,14 +29,13 @@ g/edfstop(up)/d ,s/Lock;/Lock lk;/g ,s/lock(\&broken)/lock(\&broken.lk)/g ,s/MACHP(0)->ticks/msec()/g -,s/lock(\&procalloc)/lock(\&procalloc.lk)/g ,s/lock(\&palloc)/lock(\&palloc.lk)/g ,s/ref(p->dot)/ref(\&p->dot->ref)/g ,s/ref(kpgrp)/ref(\&kpgrp->ref)/g g/"edf.h"/d g/Edf/d ,s;\.Lock\.;.lk.;g -/^schedinit/ +/^schedinit/ s/^// / setlabel(\&m->sched)/a if(traceprocs) // Plan 9 VX print("schedinit %p %p %s\n", m, up, up ? up->text : ""); @@ -95,3 +97,21 @@ g/Edf/d p->nerrlab = 0; . /^ ready(p)/+1,/flushmmu/d +/^newproc/ s/^// +/p->procctl = 0;/c + if(up && up->procctl == Proc_tracesyscall) + p->procctl = Proc_tracesyscall; + else + p->procctl = 0; + p->syscalltrace = 0; +. +/up->alarm = 0;/i + if(up->syscalltrace) + free(up->syscalltrace); +. +/p = newproc();/i + extern int tracekdev; + if(tracekdev) + iprint("kproc %s\n", name); + +. diff --git a/src/9vx/a/qio.c b/src/9vx/a/qio.c @@ -76,7 +76,8 @@ freeblist(Block *b) for(; b != 0; b = next){ next = b->next; - b->next = 0; + if(b->ref == 1) + b->next = nil; freeb(b); } } @@ -98,7 +99,7 @@ padblock(Block *bp, int size) } if(bp->next) - panic("padblock 0x%luX", getcallerpc(&bp)); + panic("padblock %#p", getcallerpc(&bp)); n = BLEN(bp); padblockcnt++; nbp = allocb(size+n); @@ -112,7 +113,7 @@ padblock(Block *bp, int size) size = -size; if(bp->next) - panic("padblock 0x%luX", getcallerpc(&bp)); + panic("padblock %#p", getcallerpc(&bp)); if(bp->lim - bp->wp >= size) return bp; @@ -227,7 +228,7 @@ pullupblock(Block *bp, int n) } else { /* shouldn't happen but why crash if it does */ if(i < 0){ - print("pullup negative length packet, called from 0x%p\n", + print("pullup negative length packet, called from %#p\n", getcallerpc(&bp)); i = 0; } @@ -1271,7 +1272,7 @@ qwrite(Queue *q, void *vp, int len) uchar *p = vp; QDEBUG if(!islo()) - print("qwrite hi %lux\n", getcallerpc(&q)); + print("qwrite hi %#p\n", getcallerpc(&q)); sofar = 0; do {