FreeBSD/sys/netpfil/ipfw/dn_sched_fq_pie.c
/*
 * Initialize fq_pie scheduler instance.
 * also, allocate memory for flows array.
 */
Initialize fq_pie scheduler instance.
also, allocate memory for flows array.
Initialize fq_pie scheduler instance . also allocate memory for flows array .
static int
fq_pie_new_sched(struct dn_sch_inst *_si)
{
	struct fq_pie_si *si;
	struct dn_queue *q;
	struct fq_pie_schk *schk;
	struct fq_pie_flow *flows;
	int i;
	si = (struct fq_pie_si *)_si;
	schk = (struct fq_pie_schk *)(_si->sched+1);
	if(si->si_extra) {
		D("si already configured!");
		return 0;
	}
	q = &si->main_q;
	set_oid(&q->ni.oid, DN_QUEUE, sizeof(*q));
	q->_si = _si;
	q->fs = _si->sched->fs;
	si->si_extra = malloc(sizeof(struct fq_pie_si_extra),
		 M_DUMMYNET, M_NOWAIT | M_ZERO);
	if (si->si_extra == NULL) {
		D("cannot allocate memory for fq_pie si extra vars");
		return ENOMEM ; 
	}
	si->si_extra->flows = malloc(schk->cfg.flows_cnt * sizeof(struct fq_pie_flow),
		 M_DUMMYNET, M_NOWAIT | M_ZERO);
	flows = si->si_extra->flows;
	if (flows == NULL) {
		free(si->si_extra, M_DUMMYNET);
		si->si_extra = NULL;
		D("cannot allocate memory for fq_pie flows");
		return ENOMEM ; 
	}
	si->perturbation = random();
	si->si_extra->nr_active_q = 0;
	STAILQ_INIT(&si->newflows);
	STAILQ_INIT(&si->oldflows);
	for (i = 0; i < schk->cfg.flows_cnt; i++) {
		flows[i].pst.parms = &schk->cfg.pcfg;
		flows[i].psi_extra = si->si_extra;
		pie_init(&flows[i], schk);
	}
	fq_pie_desc.ref_count++;
	return 0;
}
static int fq_pie_new_sched ( struct dn_sch_inst * _si ) { struct fq_pie_si * si ; struct dn_queue * q ; struct fq_pie_schk * schk ; struct fq_pie_flow * flows ; int i ; si = ( struct fq_pie_si * ) _si ; schk = ( struct fq_pie_schk * ) ( _si -> sched + 1 ) ; if ( si -> si_extra ) { D ( " " ) ; return 0 ; } q = & si -> main_q ; set_oid ( & q -> ni . oid , DN_QUEUE , sizeof ( * q ) ) ; q -> _si = _si ; q -> fs = _si -> sched -> fs ; si -> si_extra = malloc ( sizeof ( struct fq_pie_si_extra ) , M_DUMMYNET , M_NOWAIT | M_ZERO ) ; if ( si -> si_extra == NULL ) { D ( " " ) ; return ENOMEM ; } si -> si_extra -> flows = malloc ( schk -> cfg . flows_cnt * sizeof ( struct fq_pie_flow ) , M_DUMMYNET , M_NOWAIT | M_ZERO ) ; flows = si -> si_extra -> flows ; if ( flows == NULL ) { free ( si -> si_extra , M_DUMMYNET ) ; si -> si_extra = NULL ; D ( " " ) ; return ENOMEM ; } si -> perturbation = random ( ) ; si -> si_extra -> nr_active_q = 0 ; STAILQ_INIT ( & si -> newflows ) ; STAILQ_INIT ( & si -> oldflows ) ; for ( i = 0 ; i < schk -> cfg . flows_cnt ; i ++ ) { flows [ i ] . pst . parms = & schk -> cfg . pcfg ; flows [ i ] . psi_extra = si -> si_extra ; pie_init ( & flows [ i ] , schk ) ; } fq_pie_desc . ref_count ++ ; return 0 ; }
Initialize fq_pie scheduler instance.
Initialize fq_pie scheduler instance .
/* init the main queue */ /* allocate memory for scheduler instance extra vars */ /* allocate memory for flows array */ /* init perturbation for this si */ /* init the old and new flows lists */ /* init the flows (sub-queues) */