use nil rather than 0 for pointers (finally get all of 'em), and improve stat collection to be less painful in the common case, especially on arm. Reference: /n/atom/patch/qiostats Date: Wed Sep 23 05:06:18 CES 2015 Signed-off-by: quanstro@quanstro.net --- /sys/src/nix/port/qio.c Wed Sep 23 05:05:44 2015 +++ /sys/src/nix/port/qio.c Wed Sep 23 05:05:45 2015 @@ -30,7 +30,7 @@ [Cqbwritepricnt] "qbwritepricnt", }; -static uvlong count[Ncount]; +static uvlong count[MACHMAX][Ncount]; static int debugging; @@ -75,28 +75,31 @@ uint qiomaxatomic = Maxatomic; -extern uvlong ainc64(uvlong*); /* sic */ -extern uvlong aadd64(uvlong*, uvlong); /* sic */ - static void counter(int i) { - ainc64(count+i); + count[m->machno][i]++; } static void bytes(int i, int n) { - aadd64(count+i, n); + count[m->machno][i] += n; } char* qiostats(char *p, char *e) { - int i; + int i, j; + uvlong n; - for(i = 0; i < Ncount; i++) - p = seprint(p, e, "%s %lld\n", countname[i], count[i]); + *p = 0; + for(i = 0; i < Ncount; i++){ + n = 0; + for(j = 0; j < nelem(count[0]); j++) + n += count[j][i]; + p = seprint(p, e, "%s %lld\n", countname[i], n); + } return p; } @@ -104,12 +107,12 @@ void ixsummary(void) { - int i; + char buf[1024]; debugging ^= 1; iallocsummary(); - for(i = 0; i < Ncount; i++) - print("%s %lld\n", countname[i], count[i]); + qiostats(buf, buf+sizeof buf); + print("%s", buf); } /* @@ -120,9 +123,9 @@ { Block *next; - for(; b != 0; b = next){ + for(; b != nil; b = next){ next = b->next; - b->next = 0; + b->next = nil; freeb(b); } } @@ -281,7 +284,7 @@ counter(Cpullupblockcnt); bp->wp += i; bp->next = nbp->next; - nbp->next = 0; + nbp->next = nil; freeb(nbp); n -= i; if(n == 0){ @@ -291,7 +294,7 @@ } } freeb(bp); - return 0; + return nil; } /* @@ -342,7 +345,7 @@ bp = bp->next; } - bp->wp -= (BLEN(bp) - len); + bp->wp -= BLEN(bp) - len; if(bp->next) { freeblist(bp->next); @@ -368,7 +371,7 @@ return nil; }else nbp = allocb(count); - for(; count > 0 && bp != 0; bp = bp->next){ + for(; count > 0 && bp != nil; bp = bp->next){ l = BLEN(bp); if(l > count) l = count; @@ -467,7 +470,7 @@ return nil; } q->bfirst = b->next; - b->next = 0; + b->next = nil; q->len -= BALLOC(b); q->dlen -= BLEN(b); QDEBUG checkb(b, "qget"); @@ -505,7 +508,7 @@ n = BLEN(b); if(n <= len - sofar){ q->bfirst = b->next; - b->next = 0; + b->next = nil; q->len -= BALLOC(b); q->dlen -= BLEN(b); freeb(b); @@ -556,7 +559,7 @@ for(;;) { b = q->bfirst; - if(b == 0){ + if(b == nil){ q->state |= Qstarve; iunlock(q); return -1; @@ -584,7 +587,7 @@ /* discard the block if we're done with it */ if((q->state & Qmsg) || len == n){ q->bfirst = b->next; - b->next = 0; + b->next = nil; q->len -= BALLOC(b); q->dlen -= BLEN(b); @@ -625,8 +628,8 @@ return -1; } if(q->state & Qclosed){ - len = BALLOC(b); iunlock(q); + len = BALLOC(b); freeblist(b); return len; } @@ -674,9 +677,9 @@ ilock(q); if(q->state & Qclosed){ + iunlock(q); len = BALLOC(b); freeblist(b); - iunlock(q); return len; } @@ -758,7 +761,7 @@ /* save in buffer */ b = iallocb(len); - if(b == 0){ + if(b == nil){ iunlock(q); return 0; } @@ -770,7 +773,7 @@ else q->bfirst = b; q->blast = b; - /* b->next = 0; done by iallocb() */ + /* b->next = nil; done by iallocb() */ q->len += BALLOC(b); q->dlen += BLEN(b); QDEBUG checkb(b, "qproduce"); @@ -850,8 +853,8 @@ Queue *q; q = malloc(sizeof(Queue)); - if(q == 0) - return 0; + if(q == nil) + return nil; q->limit = q->inilim = limit; q->kick = kick; @@ -872,8 +875,8 @@ Queue *q; q = malloc(sizeof(Queue)); - if(q == 0) - return 0; + if(q == nil) + return nil; q->limit = 0; q->arg = arg; @@ -888,7 +891,7 @@ { Queue *q = a; - return (q->state & Qclosed) || q->bfirst != 0; + return (q->state & Qclosed) || q->bfirst != nil; } /* @@ -1253,7 +1256,7 @@ else q->bfirst = b; q->blast = b; - b->next = 0; + b->next = nil; q->len += BALLOC(b); q->dlen += n; QDEBUG checkb(b, "qbwrite"); @@ -1446,7 +1449,7 @@ q->state &= ~(Qflow|Qstarve); strcpy(q->err, Ehungup); bfirst = q->bfirst; - q->bfirst = 0; + q->bfirst = nil; q->len = 0; q->dlen = 0; q->noblock = 0; @@ -1470,7 +1473,7 @@ /* mark it */ ilock(q); q->state |= Qclosed; - if(msg == 0 || *msg == 0) + if(msg == nil || *msg == 0) strcpy(q->err, Ehungup); else strncpy(q->err, msg, ERRMAX-1); @@ -1533,7 +1536,7 @@ int qcanread(Queue *q) { - return q->bfirst!=0; + return q->bfirst != nil; } /* @@ -1565,7 +1568,7 @@ /* mark it */ ilock(q); bfirst = q->bfirst; - q->bfirst = 0; + q->bfirst = nil; q->len = 0; q->dlen = 0; iunlock(q);