plan 9 kernel history: overview | file list | diff list

1990/08272/port/stream.c (diff list | history)

1990/08272/sys/src/9/port/stream.c:24,421990/0905/sys/src/9/port/stream.c:24,29 (short | long | prev | next)
1990/0312    
 */ 
1990/0321    
static Qinfo *lds[Nlds+1]; 
1990/0227    
 
1990/0321    
void 
newqinfo(Qinfo *qi) 
{ 
	int i; 
1990/0227    
                 
1990/0321    
	for(i=0; i<Nlds && lds[i]; i++) 
		if(lds[i] == qi) 
			return; 
	if(i == Nlds) 
		panic("pushable"); 
	lds[i] = qi; 
} 
                 
1990/0227    
/* 
 *  All stream structures are ialloc'd at boot time 
 */ 
1990/08272/sys/src/9/port/stream.c:68,731990/0905/sys/src/9/port/stream.c:55,68
1990/0227    
}; 
 
/* 
1990/0905    
 *  the per stream directory structure 
 */ 
Dirtab streamdir[]={ 
	"data",		Sdataqid,	0,			0600, 
	"ctl",		Sctlqid,	0,			0600, 
}; 
 
/* 
1990/0331    
 *  Dump all block information of how many blocks are in which queues 
 */ 
void 
1990/08272/sys/src/9/port/stream.c:120,1321990/0905/sys/src/9/port/stream.c:115,133
1990/0227    
 *  Allocate streams, queues, and blocks.  Allocate n block classes with 
 *	1/2(m+1) to class m < n-1 
 *	1/2(n-1) to class n-1 
1990/0905    
 * 
 *  All data areas are alligned to their size. 
 * 
 *  No data area crosses a 4k boundary.  This allows us to use the 
 *  VME/SCSI/LANCE to MP bus maps on the SGI power series machines. 
1990/0227    
 */ 
void 
streaminit(void) 
{ 
	int class, i, n; 
1990/0905    
	int class, i, n, left; 
1990/0227    
	Block *bp; 
	Bclass *bcp; 
1990/0905    
	uchar *ptr; 
1990/0227    
 
	slist = (Stream *)ialloc(conf.nstream * sizeof(Stream), 0); 
	qlist = (Queue *)ialloc(conf.nqueue * sizeof(Queue), 0); 
1990/08272/sys/src/9/port/stream.c:133,1381990/0905/sys/src/9/port/stream.c:134,140
1990/0227    
	blist = (Block *)ialloc(conf.nblock * sizeof(Block), 0); 
	bp = blist; 
	n = conf.nblock; 
1990/0905    
	left = 0; 
1990/0227    
	for(class = 0; class < Nclass; class++){ 
		if(class < Nclass-1) 
			n = n/2; 
1990/08272/sys/src/9/port/stream.c:143,1501990/0905/sys/src/9/port/stream.c:145,159
1990/08272    
			 *  starts on a page boundary.  This makes sure 
			 *  no block crosses a page boundary. 
			 */ 
1990/0227    
			if(bcp->size) 
1990/08272    
				bp->base = (uchar *)ialloc(bcp->size, i == 0); 
1990/0905    
			if(bcp->size){ 
				if(bcp->size > left){ 
					left = bcp->size>4096 ? bcp->size : 4096; 
					ptr = (uchar *)ialloc(left, 1); 
				} 
				bp->base = ptr; 
				ptr += bcp->size; 
				left -= bcp->size; 
			} 
1990/0227    
			bp->lim = bp->base + bcp->size; 
			bp->flags = class; 
			freeb(bp); 
1990/08272/sys/src/9/port/stream.c:479,5321990/0905/sys/src/9/port/stream.c:488,493
1990/0227    
} 
 
/* 
1990/0312    
 *  make sure the first block has n bytes 
 */ 
Block * 
pullup(Block *bp, int n) 
{ 
	Block *nbp; 
	int i; 
                 
	/* 
	 *  this should almost always be true, the rest it 
	 *  just for to avoid every caller checking. 
	 */ 
	if(BLEN(bp) >= n) 
		return bp; 
                 
	/* 
	 *  if not enough room in the first block, 
	 *  add another to the front of the list. 
	if(bp->lim - bp->rptr < n){ 
		nbp = allocb(n); 
		nbp->next = bp; 
		bp = nbp; 
	} 
                 
	/* 
	 *  copy bytes from the trailing blocks into the first 
	 */ 
	n -= BLEN(bp); 
	while(nbp = bp->next){ 
		i = BLEN(nbp); 
		if(i > n) { 
			memcpy(bp->wptr, nbp->rptr, n); 
			bp->wptr += n; 
			nbp->rptr += n; 
			return bp; 
		} else { 
			memcpy(bp->wptr, nbp->rptr, i); 
			bp->wptr += i; 
			bp->next = nbp->next; 
			nbp->next = 0; 
			freeb(nbp); 
		} 
	} 
	freeb(bp); 
	return 0; 
} 
                 
/* 
 *  grow the front of a list of blocks by n bytes 
 */ 
Block * 
1990/08272/sys/src/9/port/stream.c:626,6391990/0905/sys/src/9/port/stream.c:587,592
1990/0227    
} 
 
/* 
 *  the per stream directory structure 
 */ 
Dirtab streamdir[]={ 
	"data",		Sdataqid,	0,			0600, 
	"ctl",		Sctlqid,	0,			0600, 
}; 
                 
/* 
 *  A stream device consists of the contents of streamdir plus 
 *  any directory supplied by the actual device. 
 * 
1990/08272/sys/src/9/port/stream.c:1197,11991990/0905/sys/src/9/port/stream.c:1150,1169
1990/0801    
	devdir(c, c->qid, name, n, 0, &dir); 
	convD2M(&dir, db); 
1990/0227    
} 
1990/0905    
 
/* 
 *  announce a line discipline that can be pushed 
 */ 
void 
newqinfo(Qinfo *qi) 
{ 
	int i; 
 
	for(i=0; i<Nlds && lds[i]; i++) 
		if(lds[i] == qi) 
			return; 
	if(i == Nlds) 
		panic("pushable"); 
	lds[i] = qi; 
} 
 


source code copyright © 1990-2005 Lucent Technologies; see license
Plan 9 distribution
comments to russ cox (rsc@swtch.com)