kernel: remove Block refcounting (thanks erik)

This commit is contained in:
cinap_lenrek 2014-06-08 00:19:33 +02:00
parent 9ee3095553
commit be3a5a6dc3
12 changed files with 12 additions and 66 deletions

View file

@ -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;
}
gre = (GREhdr *)bp->rp;
memmove(gre->src, grec->coa, sizeof gre->dst);

View file

@ -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);

View file

@ -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;

View file

@ -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);

View file

@ -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;

View file

@ -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);

View file

@ -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);

View file

@ -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.

View file

@ -135,7 +135,6 @@ enum
struct Block
{
long ref;
Block* next;
Block* list;
uchar* rp; /* first unconsumed byte */

View file

@ -77,7 +77,6 @@ freeblist(Block *b)
for(; b != 0; b = next){
next = b->next;
if(b->ref == 1)
b->next = nil;
freeb(b);
}

View file

@ -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.

View file

@ -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;