commit c4097c29512269f4547ebefb8abdc57a2892b479 from: rsc date: Tue May 11 17:51:27 2004 UTC Fix small bugs. commit - 2f2df5e02ef22c9727ae2b8269d5c76a061d296f commit + c4097c29512269f4547ebefb8abdc57a2892b479 blob - 356d7b6289e32ec7a4c47d690a5d271da7b2ca51 blob + 2721fb4ed78e1be446314fac74f7f2129496356b --- include/thread.h +++ include/thread.h @@ -121,7 +121,7 @@ Channel* threadwaitchan(void); int tprivalloc(void); void tprivfree(int); void **tprivaddr(int); -void yield(void); +int yield(void); long threadstack(void); blob - de2bee946b997fe3a8dbc0865570e897095f4d96 blob + 8bdeab6100de4caca09026317fff766e7ab8a33a --- src/cmd/ls.C +++ src/cmd/ls.C @@ -101,6 +101,8 @@ ls(char *s, int multi) return 1; } if(db->qid.type&QTDIR && dflag==0){ + free(db); + db = nil; output(); fd = open(s, OREAD); if(fd == -1) blob - 2b9011ccc6311fddb3d8d4094c41646e3e75939c blob + 6644778c434c7e7f11b7303c83d63261bd1526bc --- src/cmd/rc/plan9ish.c +++ src/cmd/rc/plan9ish.c @@ -71,7 +71,7 @@ void Vinit(void){ for(s=*env;*s && *s!='(' && *s!='=';s++); switch(*s){ case '\0': - pfmt(err, "rc: odd environment %q?\n", *env); + // pfmt(err, "rc: odd environment %q?\n", *env); break; case '=': *s='\0'; blob - d82eaa941589c507a2d86a3c8f42f7d48d49b751 blob + 3b52216b96def02205504b58ef635704f226f9c2 --- src/cmd/time.c +++ src/cmd/time.c @@ -11,6 +11,7 @@ main(int argc, char *argv[]) { int i; Waitmsg *w; + vlong t0, t1; long l; char *p; char err[ERRMAX]; @@ -20,6 +21,7 @@ main(int argc, char *argv[]) exits("usage"); } + t0 = nsec(); switch(fork()){ case -1: error("fork"); @@ -37,8 +39,9 @@ main(int argc, char *argv[]) loop: w = wait(); + t1 = nsec(); if(w == nil){ - errstr(err, sizeof err); + rerrstr(err, sizeof err); if(strcmp(err, "interrupted") == 0) goto loop; error("wait"); @@ -47,7 +50,7 @@ main(int argc, char *argv[]) add("%ld.%.2ldu", l/1000, (l%1000)/10); l = w->time[1]; add("%ld.%.2lds", l/1000, (l%1000)/10); - l = w->time[2]; + l = (t1-t0)/1000000; add("%ld.%.2ldr", l/1000, (l%1000)/10); add("\t"); for(i=1; ithread; - _threadstacklimit(t->stk); + _threadstacklimit(t->stk, t->stk+t->stksize); (*f)(arg); threadexits(nil); @@ -39,18 +39,19 @@ _threadinswitch(int enter) USED(enter); #ifdef USEVALGRIND if(enter) - VALGRIND_SET_STACK_LIMIT(0, 0, 1); - else VALGRIND_SET_STACK_LIMIT(0, 0, 0); + else + VALGRIND_SET_STACK_LIMIT(0, 0, 1); #endif } void -_threadstacklimit(void *addr) +_threadstacklimit(void *bottom, void *top) { - USED(addr); + USED(bottom); + USED(top); #ifdef USEVALGRIND - VALGRIND_SET_STACK_LIMIT(1, addr, 0); + VALGRIND_SET_STACK_LIMIT(1, bottom, top); #endif } blob - 21f6041d9ab7fb2c911a5a0fa21df98292a29255 blob + 94d4db9abea7f3a8609f56e777f5ec240d367fb4 --- src/libthread/PowerMacintosh.c +++ src/libthread/PowerMacintosh.c @@ -32,7 +32,7 @@ _threadinswitch(int enter) } void -_threadstacklimit(void *addr) +_threadstacklimit(void *addr, void *addr2) { USED(addr); } blob - b63fee44416722030a85ba93d03527fa9a2c25c7 blob + f5f0d6c06f3a678159437c3868a8f6489620153c --- src/libthread/create.c +++ src/libthread/create.c @@ -24,6 +24,7 @@ newthread(Proc *p, void (*f)(void *arg), void *arg, ui if(stacksize < 32) sysfatal("bad stacksize %d", stacksize); t = _threadmalloc(sizeof(Thread), 1); + t->lastfd = -1; s = _threadmalloc(stacksize, 0); t->stk = (uchar*)s; t->stksize = stacksize; blob - 927fc64f8f740dab6de72194b4abec25ead0aae6 blob + a6890332e0ef859bb1d1be557c406f89c2ff0b84 --- src/libthread/fdwait.c +++ src/libthread/fdwait.c @@ -2,12 +2,13 @@ #include #include #include - +#include "threadimpl.h" #include #include #include #define debugpoll 0 +static int noblocked[4096/32]; #ifdef __APPLE__ #include @@ -174,11 +175,15 @@ _threadfdwait(int fd, int rw, ulong pc) struct { Channel c; + Alt *qentry[2]; ulong x; } s; threadfdwaitsetup(); chaninit(&s.c, sizeof(ulong), 1); + s.c.qentry = (volatile Alt**)s.qentry; + s.c.nentry = 2; + memset(s.qentry, 0, sizeof s.qentry); for(i=0; ithread; + if(t && t->lastfd == fd) + return; fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0)|O_NONBLOCK); + if(t) + t->lastfd = fd; + + /* We could lock this but we're probably single-threaded + * and the worst that will happen is we'll run fcntl + * a few more times. + */ + noblocked[fd/(8*sizeof(int))] |= 1<<(fd%(8*sizeof(int))); } long blob - 04e6cd9f5f9fa84b7c82299a2272409d2975fcaa blob + bc7ad0f8671cda102a97075b6057278db01549af --- src/libthread/main.c +++ src/libthread/main.c @@ -32,24 +32,12 @@ _threaddie(int x) exit(_threadexitsallstatus[0] ? 1 : 0); } -static void -_nop(int x) -{ - USED(x); -} - int main(int argc, char **argv) { Mainarg *a; Proc *p; - signal(SIGTERM, _threaddie); - signal(SIGCHLD, _nop); - signal(SIGALRM, _nop); -// signal(SIGINFO, _threadstatus); -// rfork(RFREND); - //_threaddebuglevel = (DBGSCHED|DBGCHAN|DBGREND)^~0; _systhreadinit(); _qlockinit(_threadrendezvous); blob - 1ced9021221b8fd2e69e5c4542b69f2e4ab5af86 blob + f8ec8e806b520a40b82927f2688ae802a872983f --- src/libthread/mkfile +++ src/libthread/mkfile @@ -59,6 +59,7 @@ asm-OpenBSD-386.$O: asm-FreeBSD-386.s # sorry VG=`test -d /home/rsc/pub/valgrind-debian && echo -DUSEVALGRIND` +# VG= CFLAGS=$CFLAGS $VG blob - 9ad7298b251835df505807d2d65656f66f718690 blob + bdb9ad6b21c9c2957eecf76af1679905c83fe9f5 --- src/libthread/sched.c +++ src/libthread/sched.c @@ -171,7 +171,7 @@ needstack(int howmuch) } } -void +int _sched(void) { Proc *p; @@ -186,8 +186,8 @@ Resched: // psstate(t->state), &t->sched, &p->sched); if(_setlabel(&t->sched)==0) _gotolabel(&p->sched); - _threadstacklimit(t->stk); - return; + _threadstacklimit(t->stk, t->stk+t->stksize); + return p->nsched++; }else{ t = runthread(p); if(t == nil){ @@ -277,10 +277,15 @@ _threadidle(void) unlock(&p->readylock); } -void +int yield(void) { - _sched(); + Proc *p; + int nsched; + + p = _threadgetproc(); + nsched = p->nsched; + return _sched() - nsched; } void blob - 6312dac9b80f478cd83b9e68aeb9b15a035d238f blob + 0d2d8d249457bc6fc296f9916c6d7eac69162c27 --- src/libthread/sun4u.c +++ src/libthread/sun4u.c @@ -46,7 +46,7 @@ _threadinswitch(int enter) } void -_threadstacklimit(void *addr) +_threadstacklimit(void *addr, void *addr2) { USED(addr); } blob - 373164adbeb1a1836544dd31c83fc1bcc3e44a96 blob + 7e44e6464d813607c79c7d364e925ce02729a7d0 --- src/libthread/threadimpl.h +++ src/libthread/threadimpl.h @@ -99,6 +99,7 @@ struct Thread ulong userpc; void* udata[NPRIV]; /* User per-thread data pointer */ + int lastfd; }; struct Execargs @@ -143,6 +144,7 @@ struct Proc Waitmsg *waitmsg; void* udata; /* User per-proc data pointer */ + int nsched; }; struct Pqueue { /* Proc queue */ @@ -169,7 +171,7 @@ void _freeproc(Proc*); Proc* _newproc(void(*)(void*), void*, uint, char*, int, int); int _procsplhi(void); void _procsplx(int); -void _sched(void); +int _sched(void); int _schedexec(Execargs*); void _schedexecwait(void); void _schedexit(Proc*); @@ -219,4 +221,4 @@ extern int _threadgetpid(void); extern void _threadmemset(void*, int, int); extern void _threaddebugmemset(void*, int, int); extern int _threadprocs; -extern void _threadstacklimit(void*); +extern void _threadstacklimit(void*, void*);