Changeset View
Changeset View
Standalone View
Standalone View
head/sys/net/altq/altq_subr.c
Show First 20 Lines • Show All 286 Lines • ▼ Show 20 Lines | (void)printf("altq assertion \"%s\" failed: file \"%s\", line %d\n", | ||||
failedexpr, file, line); | failedexpr, file, line); | ||||
panic("altq assertion"); | panic("altq assertion"); | ||||
/* NOTREACHED */ | /* NOTREACHED */ | ||||
} | } | ||||
#endif | #endif | ||||
/* | /* | ||||
* internal representation of token bucket parameters | * internal representation of token bucket parameters | ||||
* rate: byte_per_unittime << 32 | * rate: (byte_per_unittime << TBR_SHIFT) / machclk_freq | ||||
* (((bits_per_sec) / 8) << 32) / machclk_freq | * (((bits_per_sec) / 8) << TBR_SHIFT) / machclk_freq | ||||
* depth: byte << 32 | * depth: byte << TBR_SHIFT | ||||
* | * | ||||
*/ | */ | ||||
#define TBR_SHIFT 32 | #define TBR_SHIFT 29 | ||||
#define TBR_SCALE(x) ((int64_t)(x) << TBR_SHIFT) | #define TBR_SCALE(x) ((int64_t)(x) << TBR_SHIFT) | ||||
#define TBR_UNSCALE(x) ((x) >> TBR_SHIFT) | #define TBR_UNSCALE(x) ((x) >> TBR_SHIFT) | ||||
static struct mbuf * | static struct mbuf * | ||||
tbr_dequeue(ifq, op) | tbr_dequeue(ifq, op) | ||||
struct ifaltq *ifq; | struct ifaltq *ifq; | ||||
int op; | int op; | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | if (tbr == NULL) { | ||||
return (ENOMEM); | return (ENOMEM); | ||||
} | } | ||||
tbr->tbr_rate = TBR_SCALE(profile->rate / 8) / machclk_freq; | tbr->tbr_rate = TBR_SCALE(profile->rate / 8) / machclk_freq; | ||||
tbr->tbr_depth = TBR_SCALE(profile->depth); | tbr->tbr_depth = TBR_SCALE(profile->depth); | ||||
if (tbr->tbr_rate > 0) | if (tbr->tbr_rate > 0) | ||||
tbr->tbr_filluptime = tbr->tbr_depth / tbr->tbr_rate; | tbr->tbr_filluptime = tbr->tbr_depth / tbr->tbr_rate; | ||||
else | else | ||||
tbr->tbr_filluptime = 0xffffffffffffffffLL; | tbr->tbr_filluptime = LLONG_MAX; | ||||
/* | |||||
* The longest time between tbr_dequeue() calls will be about 1 | |||||
* system tick, as the callout that drives it is scheduled once per | |||||
* tick. The refill-time detection logic in tbr_dequeue() can only | |||||
* properly detect the passage of up to LLONG_MAX machclk ticks. | |||||
* Therefore, in order for this logic to function properly in the | |||||
* extreme case, the maximum value of tbr_filluptime should be | |||||
* LLONG_MAX less one system tick's worth of machclk ticks less | |||||
* some additional slop factor (here one more system tick's worth | |||||
* of machclk ticks). | |||||
*/ | |||||
if (tbr->tbr_filluptime > (LLONG_MAX - 2 * machclk_per_tick)) | |||||
tbr->tbr_filluptime = LLONG_MAX - 2 * machclk_per_tick; | |||||
tbr->tbr_token = tbr->tbr_depth; | tbr->tbr_token = tbr->tbr_depth; | ||||
tbr->tbr_last = read_machclk(); | tbr->tbr_last = read_machclk(); | ||||
tbr->tbr_lastop = ALTDQ_REMOVE; | tbr->tbr_lastop = ALTDQ_REMOVE; | ||||
otbr = ifq->altq_tbr; | otbr = ifq->altq_tbr; | ||||
ifq->altq_tbr = tbr; /* set the new tbr */ | ifq->altq_tbr = tbr; /* set the new tbr */ | ||||
if (otbr != NULL) | if (otbr != NULL) | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | tbr_timeout(arg) | ||||
splx(s); | splx(s); | ||||
if (active > 0) | if (active > 0) | ||||
CALLOUT_RESET(&tbr_callout, 1, tbr_timeout, (void *)0); | CALLOUT_RESET(&tbr_callout, 1, tbr_timeout, (void *)0); | ||||
else | else | ||||
tbr_timer = 0; /* don't need tbr_timer anymore */ | tbr_timer = 0; /* don't need tbr_timer anymore */ | ||||
} | } | ||||
/* | /* | ||||
* get token bucket regulator profile | |||||
*/ | |||||
int | |||||
tbr_get(ifq, profile) | |||||
struct ifaltq *ifq; | |||||
struct tb_profile *profile; | |||||
{ | |||||
struct tb_regulator *tbr; | |||||
IFQ_LOCK(ifq); | |||||
if ((tbr = ifq->altq_tbr) == NULL) { | |||||
profile->rate = 0; | |||||
profile->depth = 0; | |||||
} else { | |||||
profile->rate = | |||||
(u_int)TBR_UNSCALE(tbr->tbr_rate * 8 * machclk_freq); | |||||
profile->depth = (u_int)TBR_UNSCALE(tbr->tbr_depth); | |||||
} | |||||
IFQ_UNLOCK(ifq); | |||||
return (0); | |||||
} | |||||
/* | |||||
* attach a discipline to the interface. if one already exists, it is | * attach a discipline to the interface. if one already exists, it is | ||||
* overridden. | * overridden. | ||||
* Locking is done in the discipline specific attach functions. Basically | * Locking is done in the discipline specific attach functions. Basically | ||||
* they call back to altq_attach which takes care of the attach and locking. | * they call back to altq_attach which takes care of the attach and locking. | ||||
*/ | */ | ||||
int | int | ||||
altq_pfattach(struct pf_altq *a) | altq_pfattach(struct pf_altq *a) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 238 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
/* | /* | ||||
* get queue statistics | * get queue statistics | ||||
* Locking is done in the discipline specific functions with regards to | * Locking is done in the discipline specific functions with regards to | ||||
* copyout operations, also it is not yet clear which lock to use. | * copyout operations, also it is not yet clear which lock to use. | ||||
*/ | */ | ||||
int | int | ||||
altq_getqstats(struct pf_altq *a, void *ubuf, int *nbytes) | altq_getqstats(struct pf_altq *a, void *ubuf, int *nbytes, int version) | ||||
{ | { | ||||
int error = 0; | int error = 0; | ||||
switch (a->scheduler) { | switch (a->scheduler) { | ||||
#ifdef ALTQ_CBQ | #ifdef ALTQ_CBQ | ||||
case ALTQT_CBQ: | case ALTQT_CBQ: | ||||
error = cbq_getqstats(a, ubuf, nbytes); | error = cbq_getqstats(a, ubuf, nbytes, version); | ||||
break; | break; | ||||
#endif | #endif | ||||
#ifdef ALTQ_PRIQ | #ifdef ALTQ_PRIQ | ||||
case ALTQT_PRIQ: | case ALTQT_PRIQ: | ||||
error = priq_getqstats(a, ubuf, nbytes); | error = priq_getqstats(a, ubuf, nbytes, version); | ||||
break; | break; | ||||
#endif | #endif | ||||
#ifdef ALTQ_HFSC | #ifdef ALTQ_HFSC | ||||
case ALTQT_HFSC: | case ALTQT_HFSC: | ||||
error = hfsc_getqstats(a, ubuf, nbytes); | error = hfsc_getqstats(a, ubuf, nbytes, version); | ||||
break; | break; | ||||
#endif | #endif | ||||
#ifdef ALTQ_FAIRQ | #ifdef ALTQ_FAIRQ | ||||
case ALTQT_FAIRQ: | case ALTQT_FAIRQ: | ||||
error = fairq_getqstats(a, ubuf, nbytes); | error = fairq_getqstats(a, ubuf, nbytes, version); | ||||
break; | break; | ||||
#endif | #endif | ||||
#ifdef ALTQ_CODEL | #ifdef ALTQ_CODEL | ||||
case ALTQT_CODEL: | case ALTQT_CODEL: | ||||
error = codel_getqstats(a, ubuf, nbytes); | error = codel_getqstats(a, ubuf, nbytes, version); | ||||
break; | break; | ||||
#endif | #endif | ||||
default: | default: | ||||
error = ENXIO; | error = ENXIO; | ||||
} | } | ||||
return (error); | return (error); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,205 Lines • Show Last 20 Lines |