From be3a5a6dc372870c9c6cb3b039228fab89db07b5 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sun, 8 Jun 2014 00:19:33 +0200 Subject: [PATCH] kernel: remove Block refcounting (thanks erik) --- sys/src/9/ip/gre.c | 44 +++++++------------------------------ sys/src/9/kw/ether1116.c | 3 --- sys/src/9/pc/ether82543gc.c | 1 - sys/src/9/pc/etherdp83820.c | 1 - sys/src/9/pc/etheriwl.c | 2 +- sys/src/9/pc/etherm10g.c | 1 - sys/src/9/pc/ethervt6105m.c | 1 - sys/src/9/port/allocb.c | 10 +-------- sys/src/9/port/portdat.h | 1 - sys/src/9/port/qio.c | 3 +-- sys/src/9/port/ucallocb.c | 10 +-------- sys/src/9/teg2/ether8169.c | 1 - 12 files changed, 12 insertions(+), 66 deletions(-) diff --git a/sys/src/9/ip/gre.c b/sys/src/9/ip/gre.c index b7982dc33..dd7ce5b96 100644 --- a/sys/src/9/ip/gre.c +++ b/sys/src/9/ip/gre.c @@ -65,7 +65,7 @@ struct GREhdr{ typedef struct GREpriv GREpriv; struct GREpriv{ /* non-MIB stats */ - ulong lenerr; /* short packet */ + uvlong lenerr; /* short packet */ }; typedef struct Bring Bring; @@ -135,8 +135,8 @@ static char *sessend = "session end"; static void grekick(void *x, Block *bp); static char *gresetup(Conv *, char *, char *, char *); -ulong grepdin, grepdout, grebdin, grebdout; -ulong grepuin, grepuout, grebuin, grebuout; +uvlong grepdin, grepdout, grebdin, grebdout; +uvlong grepuin, grepuout, grebuin, grebuout; static Block * getring(Bring *r) @@ -437,13 +437,7 @@ restart: memmove(gre->src, grec->coa, sizeof gre->dst); memmove(gre->dst, grec->south, sizeof gre->dst); - /* - * Make sure the packet does not go away. - */ - _xinc(&bp->ref); - assert(bp->ref == 2); - - ipoput4(c->p->f, bp, 0, gre->ttl - 1, gre->tos, nil); + ipoput4(c->p->f, copyblock(bp, BLEN(bp)), 0, gre->ttl - 1, gre->tos, nil); grepdout++; grebdout += BLEN(bp); @@ -673,7 +667,7 @@ grestats(Proto *gre, char *buf, int len) gpriv = gre->priv; return snprint(buf, len, - "gre: %lud %lud %lud %lud %lud %lud %lud %lud, lenerrs %lud\n", + "gre: %llud %llud %llud %llud %llud %llud %llud %llud, lenerrs %llud\n", grepdin, grepdout, grepuin, grepuout, grebdin, grebdout, grebuin, grebuout, gpriv->lenerr); } @@ -800,13 +794,7 @@ grectldlresume(Conv *c, int, char **) gre = (GREhdr *)bp->rp; qunlock(&grec->lock); - /* - * Make sure the packet does not go away. - */ - _xinc(&bp->ref); - assert(bp->ref == 2); - - ipoput4(c->p->f, bp, 0, gre->ttl - 1, gre->tos, nil); + ipoput4(c->p->f, copyblock(bp, BLEN(bp)), 0, gre->ttl - 1, gre->tos, nil); qlock(&grec->lock); addring(&grec->dlpending, bp); @@ -841,8 +829,7 @@ grectlulresume(Conv *c, int, char **) static char * grectlforward(Conv *c, int, char **argv) { - int len; - Block *bp, *nbp; + Block *bp; GREconv *grec; GREhdr *gre; Metablock *m; @@ -866,22 +853,7 @@ grectlforward(Conv *c, int, char **argv) m = (Metablock *)bp->base; assert(m->rp >= bp->base && m->rp < bp->lim); - /* - * If the packet is still held inside the IP transmit - * system, make a copy of the packet first. - */ - if(bp->ref > 1){ - len = bp->wp - m->rp; - nbp = allocb(len); - memmove(nbp->wp, m->rp, len); - nbp->wp += len; - freeb(bp); - bp = nbp; - } - else{ - /* Patch up rp */ - bp->rp = m->rp; - } + bp->rp = m->rp; gre = (GREhdr *)bp->rp; memmove(gre->src, grec->coa, sizeof gre->dst); diff --git a/sys/src/9/kw/ether1116.c b/sys/src/9/kw/ether1116.c index c119f2aa2..9e54ef173 100644 --- a/sys/src/9/kw/ether1116.c +++ b/sys/src/9/kw/ether1116.c @@ -484,8 +484,6 @@ static void getmibstats(Ctlr *); static void rxfreeb(Block *b) { - /* freeb(b) will have previously decremented b->ref to 0; raise to 1 */ - _xinc(&b->ref); b->wp = b->rp = (uchar*)((uintptr)(b->lim - Rxblklen) & ~(Bufalign - 1)); assert(((uintptr)b->rp & (Bufalign - 1)) == 0); @@ -1413,7 +1411,6 @@ ctlralloc(Ctlr *ctlr) iprint("ether1116: no memory for rx buffers\n"); break; } - assert(b->ref == 1); b->wp = b->rp = (uchar*) ((uintptr)(b->lim - Rxblklen) & ~(Bufalign - 1)); assert(((uintptr)b->rp & (Bufalign - 1)) == 0); diff --git a/sys/src/9/pc/ether82543gc.c b/sys/src/9/pc/ether82543gc.c index db9aaa6e0..a17075de1 100644 --- a/sys/src/9/pc/ether82543gc.c +++ b/sys/src/9/pc/ether82543gc.c @@ -758,7 +758,6 @@ gc82543allocb(Ctlr* ctlr) if((bp = *(ctlr->freehead)) != nil){ *(ctlr->freehead) = bp->next; bp->next = nil; - _xinc(&bp->ref); /* prevent bp from being freed */ } iunlock(&freelistlock); return bp; diff --git a/sys/src/9/pc/etherdp83820.c b/sys/src/9/pc/etherdp83820.c index a9d655ee0..a9bed75e9 100644 --- a/sys/src/9/pc/etherdp83820.c +++ b/sys/src/9/pc/etherdp83820.c @@ -511,7 +511,6 @@ dp83820rballoc(Desc* desc) } dp83820rbpool = bp->next; bp->next = nil; - _xinc(&bp->ref); /* prevent bp from being freed */ iunlock(&dp83820rblock); desc->bufptr = PCIWADDR(bp->rp); diff --git a/sys/src/9/pc/etheriwl.c b/sys/src/9/pc/etheriwl.c index b82536084..56868b331 100644 --- a/sys/src/9/pc/etheriwl.c +++ b/sys/src/9/pc/etheriwl.c @@ -1346,7 +1346,7 @@ postboot(Ctlr *ctlr) continue; if((b = ctlr->calib.cmd[i]) == nil) continue; - b->ref++; /* dont free on command completion */ + b = copyblock(b, BLEN(b)); if((err = qcmd(ctlr, 4, 176, nil, 0, b)) != nil){ freeb(b); return err; diff --git a/sys/src/9/pc/etherm10g.c b/sys/src/9/pc/etherm10g.c index a27768ab0..bceb971f8 100644 --- a/sys/src/9/pc/etherm10g.c +++ b/sys/src/9/pc/etherm10g.c @@ -864,7 +864,6 @@ balloc(Rx* rx) if((bp = rx->pool->head) != nil){ rx->pool->head = bp->next; bp->next = nil; - _xinc(&bp->ref); /* prevent bp from being freed */ rx->pool->n--; } iunlock(rx->pool); diff --git a/sys/src/9/pc/ethervt6105m.c b/sys/src/9/pc/ethervt6105m.c index 888edcc2a..357dc72ed 100644 --- a/sys/src/9/pc/ethervt6105m.c +++ b/sys/src/9/pc/ethervt6105m.c @@ -597,7 +597,6 @@ vt6105Mrballoc(void) if((bp = vt6105Mrbpool) != nil){ vt6105Mrbpool = bp->next; bp->next = nil; - _xinc(&bp->ref); /* prevent bp from being freed */ } iunlock(&vt6105Mrblock); diff --git a/sys/src/9/port/allocb.c b/sys/src/9/port/allocb.c index 3466840f2..816dab837 100644 --- a/sys/src/9/port/allocb.c +++ b/sys/src/9/port/allocb.c @@ -30,8 +30,6 @@ _allocb(int size) b->list = nil; b->free = 0; b->flag = 0; - b->ref = 0; - _xinc(&b->ref); /* align start of data portion by rounding up */ addr = (uintptr)b; @@ -123,16 +121,10 @@ void freeb(Block *b) { void *dead = (void*)Bdead; - long ref; - if(b == nil || (ref = _xdec(&b->ref)) > 0) + if(b == nil) return; - if(ref < 0){ - dumpstack(); - panic("freeb: ref %ld; caller pc %#p", ref, getcallerpc(&b)); - } - /* * drivers which perform non cache coherent DMA manage their own buffer * pool of uncached buffers and provide their own free routine. diff --git a/sys/src/9/port/portdat.h b/sys/src/9/port/portdat.h index a3eecabc3..1d427cfc6 100644 --- a/sys/src/9/port/portdat.h +++ b/sys/src/9/port/portdat.h @@ -135,7 +135,6 @@ enum struct Block { - long ref; Block* next; Block* list; uchar* rp; /* first unconsumed byte */ diff --git a/sys/src/9/port/qio.c b/sys/src/9/port/qio.c index 8076b04b8..3f663ab93 100644 --- a/sys/src/9/port/qio.c +++ b/sys/src/9/port/qio.c @@ -77,8 +77,7 @@ freeblist(Block *b) for(; b != 0; b = next){ next = b->next; - if(b->ref == 1) - b->next = nil; + b->next = nil; freeb(b); } } diff --git a/sys/src/9/port/ucallocb.c b/sys/src/9/port/ucallocb.c index 954c5d96a..93a07d336 100644 --- a/sys/src/9/port/ucallocb.c +++ b/sys/src/9/port/ucallocb.c @@ -33,8 +33,6 @@ _ucallocb(int size) b->list = nil; b->free = 0; b->flag = 0; - b->ref = 0; - _xinc(&b->ref); /* align start of data portion by rounding up */ addr = (ulong)b; @@ -117,16 +115,10 @@ void ucfreeb(Block *b) { void *dead = (void*)Bdead; - long ref; - if(b == nil || (ref = _xdec(&b->ref)) > 0) + if(b == nil) return; - if(ref < 0){ - dumpstack(); - panic("ucfreeb: ref %ld; caller pc %#p", ref, getcallerpc(&b)); - } - /* * drivers which perform non cache coherent DMA manage their own buffer * pool of uncached buffers and provide their own free routine. diff --git a/sys/src/9/teg2/ether8169.c b/sys/src/9/teg2/ether8169.c index 67f3bdc90..e9aa021cb 100644 --- a/sys/src/9/teg2/ether8169.c +++ b/sys/src/9/teg2/ether8169.c @@ -462,7 +462,6 @@ rballoc(void) if((bp = rbpool) != nil){ rbpool = bp->next; bp->next = nil; - _xinc(&bp->ref); /* prevent bp from being freed */ } iunlock(&rblock); return bp;