From eb058d07bcc8d8de42eb0e1531f231917694927f Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Tue, 26 Mar 2002 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 2002-03-26 --- alphapc/mem.h | 1 - bitsy/mem.h | 1 - mtx/mem.h | 1 - pc/mem.h | 1 - port/alarm.c | 2 +- port/devsdp.c | 18 +++++++++--------- port/portfns.h | 1 + port/proc.c | 16 ++++++++++------ 8 files changed, 21 insertions(+), 20 deletions(-) diff --git a/alphapc/mem.h b/alphapc/mem.h index 0f738ff1640f6a038837254e6419cdde0ae26f7e..90d406fc121d877b28f1336071e88f6354753aa5 100644 --- a/alphapc/mem.h +++ b/alphapc/mem.h @@ -29,7 +29,6 @@ #define HZ 100 /* clock frequency */ #define MS2HZ (1000/HZ) #define TK2SEC(t) ((t)/HZ) /* ticks to seconds */ -#define MS2TK(t) (((t)*HZ+500)/1000) /* milliseconds to closest tick */ /* * Magic registers diff --git a/bitsy/mem.h b/bitsy/mem.h index 45a7e0267191a40b8cf2606c1a72161c1d18c4ee..c54d0aa33492427b5f448d638eaa3162304e4973 100644 --- a/bitsy/mem.h +++ b/bitsy/mem.h @@ -24,7 +24,6 @@ #define HZ (20) /* clock frequency */ #define MS2HZ (1000/HZ) /* millisec per clock tick */ #define TK2SEC(t) ((t)/HZ) /* ticks to seconds */ -#define MS2TK(t) ((((ulong)(t))*HZ)/1000) /* milliseconds to ticks */ /* * Virtual addresses: diff --git a/mtx/mem.h b/mtx/mem.h index a4f5307bc613faf24c79c74b0ad61e116e88ebd1..f774bd10d2a5dfbf2c4a8590d60408921c5f8006 100644 --- a/mtx/mem.h +++ b/mtx/mem.h @@ -35,7 +35,6 @@ #define MS2HZ (1000/HZ) #define TK2SEC(t) ((t)/HZ) /* ticks to seconds */ #define TK2MS(t) ((t)*MS2HZ) /* ticks to milliseconds */ -#define MS2TK(t) (((t)*HZ+500)/1000) /* milliseconds to closest tick */ /* * Standard PPC Special Purpose Registers (OEA and VEA) diff --git a/pc/mem.h b/pc/mem.h index df270c9ae55075154c10b10b38843ab14c71b401..99d97a72f4105dbd81353402fec089df6685824a 100644 --- a/pc/mem.h +++ b/pc/mem.h @@ -25,7 +25,6 @@ #define HZ (100) /* clock frequency */ #define MS2HZ (1000/HZ) /* millisec per clock tick */ #define TK2SEC(t) ((t)/HZ) /* ticks to seconds */ -#define MS2TK(t) (((t)*HZ+500)/1000) /* milliseconds to closest tick */ /* * Fundamental addresses diff --git a/port/alarm.c b/port/alarm.c index ed5a82e1134c0e8e1fb71334dbc199b3b3b073ec..f8a140375eac4cf5c73539bbe00688515e62bf4f 100644 --- a/port/alarm.c +++ b/port/alarm.c @@ -89,7 +89,7 @@ procalarm(ulong time) up->alarm = 0; return old; } - when = MS2TK(time)+MACHP(0)->ticks; + when = ms2tk(time)+MACHP(0)->ticks; qlock(&alarms); l = &alarms.head; diff --git a/port/devsdp.c b/port/devsdp.c index c1a9ca242529247647c7c5c293442f5a2bd93191..aa499eeb768be27e239873c6f685145baa2380a5 100644 --- a/port/devsdp.c +++ b/port/devsdp.c @@ -955,7 +955,7 @@ static void convsetstate(Conv *c, int state) { -if(1)print("convsetstate %d: %s -> %s\n", c->id, convstatename[c->state], convstatename[state]); +if(0)print("convsetstate %d: %s -> %s\n", c->id, convstatename[c->state], convstatename[state]); switch(state) { default: @@ -1224,14 +1224,14 @@ conviput(Conv *c, Block *b, int control) if(seqdiff <= 0) { if(seqdiff <= -SeqWindow) { -print("old sequence number: %ld (%ld %ld)\n", seq, c->in.seqwrap, seqdiff); +if(0)print("old sequence number: %ld (%ld %ld)\n", seq, c->in.seqwrap, seqdiff); c->lstats.inBadSeq++; freeb(b); return nil; } if(c->in.window & (1<<-seqdiff)) { -print("dup sequence number: %ld (%ld %ld)\n", seq, c->in.seqwrap, seqdiff); +if(0)print("dup sequence number: %ld (%ld %ld)\n", seq, c->in.seqwrap, seqdiff); c->lstats.inDup++; freeb(b); return nil; @@ -1244,7 +1244,7 @@ print("dup sequence number: %ld (%ld %ld)\n", seq, c->in.seqwrap, seqdiff); if(0) print("coniput seq=%ulx\n", seq); if(c->in.auth != 0) { if(!(*c->in.auth)(&c->in, b->rp-4, BLEN(b)+4)) { -print("bad auth %ld\n", BLEN(b)+4); +if(0)print("bad auth %ld\n", BLEN(b)+4); c->lstats.inBadAuth++; freeb(b); return nil; @@ -1254,7 +1254,7 @@ print("bad auth %ld\n", BLEN(b)+4); if(c->in.cipher != 0) { if(!(*c->in.cipher)(&c->in, b->rp, BLEN(b))) { -print("bad cipher\n"); +if(0)print("bad cipher\n"); c->lstats.inBadOther++; freeb(b); return nil; @@ -1263,7 +1263,7 @@ print("bad cipher\n"); if(c->in.cipherblklen > 1) { pad = b->wp[-1]; if(pad > BLEN(b)) { -print("pad too big\n"); +if(0)print("pad too big\n"); c->lstats.inBadOther++; freeb(b); return nil; @@ -1314,7 +1314,7 @@ print("pad too big\n"); break; return b; } -print("dropping packet id=%d: type=%d n=%ld control=%d\n", c->id, type, BLEN(b), control); +if(0)print("dropping packet id=%d: type=%d n=%ld control=%d\n", c->id, type, BLEN(b), control); c->lstats.inBadOther++; freeb(b); return nil; @@ -1441,7 +1441,7 @@ convicontrol(Conv *c, int subtype, Block *b) switch(subtype){ case ControlMesg: if(cseq == c->in.controlseq) { -print("duplicate control packet: %ulx\n", cseq); +if(0)print("duplicate control packet: %ulx\n", cseq); // duplicate control packet freeb(b); if(c->in.controlpkt == nil) @@ -2285,7 +2285,7 @@ thwackuncomp(Conv *c, int subtype, ulong seq, Block **bp) n = unthwack(c->in.compstate, b->wp, ThwMaxBlock, bb->rp, BLEN(bb), seq); freeb(bb); if(n < 0) { -print("unthwack failed: %d\n", n); +if(0)print("unthwack failed: %d\n", n); freeb(b); return 0; } diff --git a/port/portfns.h b/port/portfns.h index 828f7b4489e0c017da4fd2c4d3f2275812ba8fb6..c7ecaea37d959bd04dbb3bfe53d27cff25f43412 100644 --- a/port/portfns.h +++ b/port/portfns.h @@ -171,6 +171,7 @@ Chan* mntauth(Chan*, char*); void mntdump(void); long mntversion(Chan*, char*, int, int); void mountfree(Mount*); +ulong ms2tk(ulong); ulong msize(void*); void muxclose(Mnt*); Chan* namec(char*, int, int, ulong); diff --git a/port/proc.c b/port/proc.c index aed0e92732f87791d18f2e0290c58cb0359c4d98..a1d82d3c9225d5912034d69e4c009be9bd7aac1c 100644 --- a/port/proc.c +++ b/port/proc.c @@ -507,18 +507,22 @@ tfn(void *arg) return MACHP(0)->ticks >= up->twhen || up->tfn(arg); } +ulong +ms2tk(ulong ms) +{ + /* avoid overflows at the cost of precision */ + if(ms >= 1000000000/HZ) + return (ms/1000)*HZ; + return (ms+500)*HZ/1000; +} + void tsleep(Rendez *r, int (*fn)(void*), void *arg, int ms) { ulong when; Proc *f, **l; - /* avoid overflows at the cost of precision */ - if(ms >= 1000000) - when = ms/(1000/HZ); - else - when = MS2TK(ms); - when += MACHP(0)->ticks; + when = ms2tk(ms) + MACHP(0)->ticks; lock(&talarm); /* take out of list if checkalarm didn't */