Changeset View
Changeset View
Standalone View
Standalone View
sys/net/altq/altq_fairq.c
Show First 20 Lines • Show All 313 Lines • ▼ Show 20 Lines | |||||
#ifndef ALTQ_RED | #ifndef ALTQ_RED | ||||
if (flags & FARF_RED) { | if (flags & FARF_RED) { | ||||
#ifdef ALTQ_DEBUG | #ifdef ALTQ_DEBUG | ||||
printf("fairq_class_create: RED not configured for FAIRQ!\n"); | printf("fairq_class_create: RED not configured for FAIRQ!\n"); | ||||
#endif | #endif | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
#endif | #endif | ||||
#ifndef ALTQ_CODEL | |||||
if (flags & FARF_CODEL) { | |||||
#ifdef ALTQ_DEBUG | |||||
printf("fairq_class_create: CODEL not configured for FAIRQ!\n"); | |||||
#endif | |||||
return (NULL); | |||||
} | |||||
#endif | |||||
if (nbuckets == 0) | if (nbuckets == 0) | ||||
nbuckets = 256; | nbuckets = 256; | ||||
if (nbuckets > FAIRQ_MAX_BUCKETS) | if (nbuckets > FAIRQ_MAX_BUCKETS) | ||||
nbuckets = FAIRQ_MAX_BUCKETS; | nbuckets = FAIRQ_MAX_BUCKETS; | ||||
/* enforce power-of-2 size */ | /* enforce power-of-2 size */ | ||||
while ((nbuckets ^ (nbuckets - 1)) != ((nbuckets << 1) - 1)) | while ((nbuckets ^ (nbuckets - 1)) != ((nbuckets << 1) - 1)) | ||||
++nbuckets; | ++nbuckets; | ||||
if ((cl = pif->pif_classes[pri]) != NULL) { | if ((cl = pif->pif_classes[pri]) != NULL) { | ||||
/* modify the class instead of creating a new one */ | /* modify the class instead of creating a new one */ | ||||
IFQ_LOCK(cl->cl_pif->pif_ifq); | IFQ_LOCK(cl->cl_pif->pif_ifq); | ||||
if (cl->cl_head) | if (cl->cl_head) | ||||
fairq_purgeq(cl); | fairq_purgeq(cl); | ||||
IFQ_UNLOCK(cl->cl_pif->pif_ifq); | IFQ_UNLOCK(cl->cl_pif->pif_ifq); | ||||
#ifdef ALTQ_RIO | #ifdef ALTQ_RIO | ||||
if (cl->cl_qtype == Q_RIO) | if (cl->cl_qtype == Q_RIO) | ||||
rio_destroy((rio_t *)cl->cl_red); | rio_destroy((rio_t *)cl->cl_red); | ||||
#endif | #endif | ||||
#ifdef ALTQ_RED | #ifdef ALTQ_RED | ||||
if (cl->cl_qtype == Q_RED) | if (cl->cl_qtype == Q_RED) | ||||
red_destroy(cl->cl_red); | red_destroy(cl->cl_red); | ||||
#endif | #endif | ||||
#ifdef ALTQ_CODEL | |||||
if (cl->cl_qtype == Q_CODEL) | |||||
codel_destroy(cl->cl_codel); | |||||
#endif | |||||
} else { | } else { | ||||
cl = malloc(sizeof(struct fairq_class), | cl = malloc(sizeof(struct fairq_class), | ||||
M_DEVBUF, M_WAITOK | M_ZERO); | M_DEVBUF, M_WAITOK | M_ZERO); | ||||
cl->cl_nbuckets = nbuckets; | cl->cl_nbuckets = nbuckets; | ||||
cl->cl_nbucket_mask = nbuckets - 1; | cl->cl_nbucket_mask = nbuckets - 1; | ||||
cl->cl_buckets = malloc( | cl->cl_buckets = malloc( | ||||
sizeof(struct fairq_bucket) * cl->cl_nbuckets, | sizeof(struct fairq_bucket) * cl->cl_nbuckets, | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | if (flags & FARF_RED) { | ||||
cl->cl_qlimit * 10/100, | cl->cl_qlimit * 10/100, | ||||
cl->cl_qlimit * 30/100, | cl->cl_qlimit * 30/100, | ||||
red_flags, red_pkttime); | red_flags, red_pkttime); | ||||
if (cl->cl_red != NULL) | if (cl->cl_red != NULL) | ||||
cl->cl_qtype = Q_RED; | cl->cl_qtype = Q_RED; | ||||
} | } | ||||
} | } | ||||
#endif /* ALTQ_RED */ | #endif /* ALTQ_RED */ | ||||
#ifdef ALTQ_CODEL | |||||
if (flags & FARF_CODEL) { | |||||
cl->cl_codel = codel_alloc(5, 100, 0); | |||||
if (cl->cl_codel != NULL) | |||||
cl->cl_qtype = Q_CODEL; | |||||
} | |||||
#endif | |||||
return (cl); | return (cl); | ||||
} | } | ||||
static int | static int | ||||
fairq_class_destroy(struct fairq_class *cl) | fairq_class_destroy(struct fairq_class *cl) | ||||
{ | { | ||||
struct fairq_if *pif; | struct fairq_if *pif; | ||||
Show All 23 Lines | |||||
#ifdef ALTQ_RIO | #ifdef ALTQ_RIO | ||||
if (cl->cl_qtype == Q_RIO) | if (cl->cl_qtype == Q_RIO) | ||||
rio_destroy((rio_t *)cl->cl_red); | rio_destroy((rio_t *)cl->cl_red); | ||||
#endif | #endif | ||||
#ifdef ALTQ_RED | #ifdef ALTQ_RED | ||||
if (cl->cl_qtype == Q_RED) | if (cl->cl_qtype == Q_RED) | ||||
red_destroy(cl->cl_red); | red_destroy(cl->cl_red); | ||||
#endif | #endif | ||||
#ifdef ALTQ_CODEL | |||||
if (cl->cl_qtype == Q_CODEL) | |||||
codel_destroy(cl->cl_codel); | |||||
#endif | |||||
} | } | ||||
free(cl->cl_buckets, M_DEVBUF); | free(cl->cl_buckets, M_DEVBUF); | ||||
free(cl, M_DEVBUF); | free(cl, M_DEVBUF); | ||||
return (0); | return (0); | ||||
} | } | ||||
/* | /* | ||||
▲ Show 20 Lines • Show All 178 Lines • ▼ Show 20 Lines | |||||
#ifdef ALTQ_RIO | #ifdef ALTQ_RIO | ||||
if (cl->cl_qtype == Q_RIO) | if (cl->cl_qtype == Q_RIO) | ||||
return rio_addq((rio_t *)cl->cl_red, &b->queue, m, cl->cl_pktattr); | return rio_addq((rio_t *)cl->cl_red, &b->queue, m, cl->cl_pktattr); | ||||
#endif | #endif | ||||
#ifdef ALTQ_RED | #ifdef ALTQ_RED | ||||
if (cl->cl_qtype == Q_RED) | if (cl->cl_qtype == Q_RED) | ||||
return red_addq(cl->cl_red, &b->queue, m, cl->cl_pktattr); | return red_addq(cl->cl_red, &b->queue, m, cl->cl_pktattr); | ||||
#endif | #endif | ||||
#ifdef ALTQ_CODEL | |||||
if (cl->cl_qtype == Q_CODEL) | |||||
return codel_addq(cl->cl_codel, &b->queue, m); | |||||
#endif | |||||
if (qlen(&b->queue) >= qlimit(&b->queue)) { | if (qlen(&b->queue) >= qlimit(&b->queue)) { | ||||
m_freem(m); | m_freem(m); | ||||
return (-1); | return (-1); | ||||
} | } | ||||
if (cl->cl_flags & FARF_CLEARDSCP) | if (cl->cl_flags & FARF_CLEARDSCP) | ||||
write_dsfield(m, cl->cl_pktattr, 0); | write_dsfield(m, cl->cl_pktattr, 0); | ||||
Show All 14 Lines | |||||
#ifdef ALTQ_RIO | #ifdef ALTQ_RIO | ||||
else if (cl->cl_qtype == Q_RIO) | else if (cl->cl_qtype == Q_RIO) | ||||
m = rio_getq((rio_t *)cl->cl_red, &b->queue); | m = rio_getq((rio_t *)cl->cl_red, &b->queue); | ||||
#endif | #endif | ||||
#ifdef ALTQ_RED | #ifdef ALTQ_RED | ||||
else if (cl->cl_qtype == Q_RED) | else if (cl->cl_qtype == Q_RED) | ||||
m = red_getq(cl->cl_red, &b->queue); | m = red_getq(cl->cl_red, &b->queue); | ||||
#endif | #endif | ||||
#ifdef ALTQ_CODEL | |||||
else if (cl->cl_qtype == Q_CODEL) | |||||
m = codel_getq(cl->cl_codel, &b->queue); | |||||
#endif | |||||
else | else | ||||
m = _getq(&b->queue); | m = _getq(&b->queue); | ||||
/* | /* | ||||
* Calculate the BW change | * Calculate the BW change | ||||
*/ | */ | ||||
if (m != NULL) { | if (m != NULL) { | ||||
uint64_t delta; | uint64_t delta; | ||||
▲ Show 20 Lines • Show All 164 Lines • ▼ Show 20 Lines | |||||
#ifdef ALTQ_RED | #ifdef ALTQ_RED | ||||
if (cl->cl_qtype == Q_RED) | if (cl->cl_qtype == Q_RED) | ||||
red_getstats(cl->cl_red, &sp->red[0]); | red_getstats(cl->cl_red, &sp->red[0]); | ||||
#endif | #endif | ||||
#ifdef ALTQ_RIO | #ifdef ALTQ_RIO | ||||
if (cl->cl_qtype == Q_RIO) | if (cl->cl_qtype == Q_RIO) | ||||
rio_getstats((rio_t *)cl->cl_red, &sp->red[0]); | rio_getstats((rio_t *)cl->cl_red, &sp->red[0]); | ||||
#endif | |||||
#ifdef ALTQ_CODEL | |||||
if (cl->cl_qtype == Q_CODEL) | |||||
codel_getstats(cl->cl_codel, &sp->codel); | |||||
#endif | #endif | ||||
} | } | ||||
/* convert a class handle to the corresponding class pointer */ | /* convert a class handle to the corresponding class pointer */ | ||||
static struct fairq_class * | static struct fairq_class * | ||||
clh_to_clp(struct fairq_if *pif, uint32_t chandle) | clh_to_clp(struct fairq_if *pif, uint32_t chandle) | ||||
{ | { | ||||
struct fairq_class *cl; | struct fairq_class *cl; | ||||
Show All 14 Lines |