~kris/9p

9hist

9d8e6c11ac0d589a60d4ff42badd6ba38e1e99f1 — David du Colombier 36 years ago 916bb53
Plan 9 from Bell Labs 1990-04-06
6 files changed, 44 insertions(+), 38 deletions(-)

M gnot/dat.h
M gnot/stream.c
M gnot/sturp.c
M port/stream.c
M port/sturp.c
M power/dat.h
M gnot/dat.h => gnot/dat.h +2 -2
@@ 383,6 383,7 @@ struct Blist {
	Block	*first;		/* first data block */
	Block	*last;		/* last data block */
	long	len;		/* length of list in bytes */
	int	nb;		/* number of blocks in list */
};

/*


@@ 390,7 391,6 @@ struct Blist {
 */
struct Queue {
	Blist;
	int	nb;		/* number of blocks in queue */
	int	flag;
	Qinfo	*info;		/* line discipline definition */
	Queue	*other;		/* opposite direction, same line discipline */


@@ 428,7 428,7 @@ struct Stream {
#define PUTNEXT(q,b)	(*(q)->next->put)((q)->next, b)
#define BLEN(b)		((b)->wptr - (b)->rptr)
#define QFULL(q)	((q)->flag & QHIWAT)
#define FLOWCTL(q)	{ if(QFULL(q)) flowctl(q); }
#define FLOWCTL(q)	{ if(QFULL(q->next)) flowctl(q); }

/*
 *  stream file qid's & high water mark

M gnot/stream.c => gnot/stream.c +3 -5
@@ 372,6 372,7 @@ putbq(Blist *q, Block *bp)
		q->last = bp;
	q->first = bp;
	q->len += BLEN(bp);
	q->nb++;
	unlock(q);
}



@@ 391,7 392,7 @@ getq(Queue *q)
			q->last = 0;
		q->len -= BLEN(bp);
		q->nb--;
		if((q->flag&QHIWAT) && q->len < Streamhi/2 && q->nb < Streambhi){
		if((q->flag&QHIWAT) && q->len<Streamhi/2 && q->nb<Streambhi/2){
			wakeup(&q->other->next->other->r);
			q->flag &= ~QHIWAT;
		}


@@ 941,10 942,7 @@ streamctlwrite(Stream *s, void *a, long n)
static int
notfull(void *arg)
{
	Queue *q;

	q = (Queue *)arg;
	return !QFULL(q->next);
	return !QFULL((Queue *)arg);
}
void
flowctl(Queue *q)

M gnot/sturp.c => gnot/sturp.c +22 -11
@@ 207,6 207,9 @@ urpclose(Queue *q)
	 *  kill off the kernel process
	 */
	wakeup(&up->rq->r);

	if(up->kstarted == 0)
		up->state = 0;
}

/*


@@ 572,18 575,20 @@ output(Urp *up)
	 *  fill the transmit buffers
	 */
	q = up->wq;
	for(bp = getq(q); bp && up->xb[up->nxb]==0; up->nxb = NEXT(up->nxb)){
		if(BLEN(bp) > up->maxblock){
			nbp = up->xb[up->nxb] = allocb(0);
			nbp->rptr = bp->rptr;
			nbp->wptr = bp->rptr = bp->rptr + up->maxblock;
		} else {
			up->xb[up->nxb] = bp;
			bp = getq(q);
	if(up->xb[up->nxb]==0) {
		for(bp=getq(q); bp && up->xb[up->nxb]==0; up->nxb=NEXT(up->nxb)){
			if(BLEN(bp) > up->maxblock){
				nbp = up->xb[up->nxb] = allocb(0);
				nbp->rptr = bp->rptr;
				nbp->wptr = bp->rptr = bp->rptr + up->maxblock;
			} else {
				up->xb[up->nxb] = bp;
				bp = getq(q);
			}
		}
		if(bp)
			putbq(q, bp);
	}
	if(bp)
		putbq(q, bp);
/*	print("output w(%d) up->xb[%d](%ux) up->nxb(%d) up->state(%ux)\n",
		WINDOW(up), up->next, up->xb[up->next], up->nxb, up->state);
/**/


@@ 868,6 873,12 @@ urpkproc(void *arg)

	up = (Urp *)arg;

	if(waserror()){
		up->state = 0;
		up->kstarted = 0;
		wakeup(&up->r);
		return;
	}
	for(;;){
		if(up->state & (HUNGUP|CLOSING)){
			if(isflushed(up))


@@ 879,6 890,6 @@ urpkproc(void *arg)
		output(up);
		tsleep(&up->rq->r, todo, up, MSrexmit/2);
	}
	up->kstarted = 0;
	up->state = 0;
	up->kstarted = 0;
}

M port/stream.c => port/stream.c +2 -5
@@ 392,7 392,7 @@ getq(Queue *q)
			q->last = 0;
		q->len -= BLEN(bp);
		q->nb--;
		if((q->flag&QHIWAT) && q->len < Streamhi/2 && q->nb < Streambhi){
		if((q->flag&QHIWAT) && q->len<Streamhi/2 && q->nb<Streambhi/2){
			wakeup(&q->other->next->other->r);
			q->flag &= ~QHIWAT;
		}


@@ 942,10 942,7 @@ streamctlwrite(Stream *s, void *a, long n)
static int
notfull(void *arg)
{
	Queue *q;

	q = (Queue *)arg;
	return !QFULL(q->next);
	return !QFULL((Queue *)arg);
}
void
flowctl(Queue *q)

M port/sturp.c => port/sturp.c +12 -12
@@ 575,20 575,20 @@ output(Urp *up)
	 *  fill the transmit buffers
	 */
	q = up->wq;
	for(bp = getq(q); q->first && up->xb[up->nxb]==0; up->nxb = NEXT(up->nxb)){
		if(bp == 0)
			bp = getq(q);
		if(BLEN(bp) > up->maxblock){
			nbp = up->xb[up->nxb] = allocb(0);
			nbp->rptr = bp->rptr;
			nbp->wptr = bp->rptr = bp->rptr + up->maxblock;
		} else {
			up->xb[up->nxb] = bp;
			bp = 0;
	if(up->xb[up->nxb]==0) {
		for(bp=getq(q); bp && up->xb[up->nxb]==0; up->nxb=NEXT(up->nxb)){
			if(BLEN(bp) > up->maxblock){
				nbp = up->xb[up->nxb] = allocb(0);
				nbp->rptr = bp->rptr;
				nbp->wptr = bp->rptr = bp->rptr + up->maxblock;
			} else {
				up->xb[up->nxb] = bp;
				bp = getq(q);
			}
		}
		if(bp)
			putbq(q, bp);
	}
	if(bp)
		putbq(q, bp);
/*	print("output w(%d) up->xb[%d](%ux) up->nxb(%d) up->state(%ux)\n",
		WINDOW(up), up->next, up->xb[up->next], up->nxb, up->state);
/**/

M power/dat.h => power/dat.h +3 -3
@@ 400,6 400,7 @@ struct Blist {
	Block	*first;		/* first data block */
	Block	*last;		/* last data block */
	long	len;		/* length of list in bytes */
	int	nb;		/* number of blocks in list */
};

/*


@@ 407,7 408,6 @@ struct Blist {
 */
struct Queue {
	Blist;
	int	nb;		/* number of blocks in queue */
	int	flag;
	Qinfo	*info;		/* line discipline definition */
	Queue	*other;		/* opposite direction, same line discipline */


@@ 445,7 445,7 @@ struct Stream {
#define PUTNEXT(q,b)	(*(q)->next->put)((q)->next, b)
#define BLEN(b)		((b)->wptr - (b)->rptr)
#define QFULL(q)	((q)->flag & QHIWAT)
#define FLOWCTL(q)	{ if(QFULL(q)) flowctl(q); }
#define FLOWCTL(q)	{ if(QFULL(q->next)) flowctl(q); }

/*
 *  stream file qid's & high water mark


@@ 455,7 455,7 @@ enum {
	Sdataqid = Shighqid,
	Sctlqid = Sdataqid-1,
	Slowqid = Sctlqid,
	Streamhi= (9*1024),	/* byte count high water mark */
	Streamhi= (17*1024),	/* byte count high water mark */
	Streambhi= 16,		/* block count high water mark */
};