Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/subr_counter.c
Show First 20 Lines • Show All 121 Lines • ▼ Show 20 Lines | |||||
* | * | ||||
* Returns non-negative if we are in the rate, negative otherwise. | * Returns non-negative if we are in the rate, negative otherwise. | ||||
* 0 - rate limit not reached. | * 0 - rate limit not reached. | ||||
* -1 - rate limit reached. | * -1 - rate limit reached. | ||||
* >0 - rate limit was reached before, and was just reset. The return value | * >0 - rate limit was reached before, and was just reset. The return value | ||||
* is number of events since last reset. | * is number of events since last reset. | ||||
*/ | */ | ||||
int64_t | int64_t | ||||
counter_ratecheck(struct counter_rate *cr, int64_t limit) | counter_ratecheck(struct counter_rate *cr, int64_t limit, int64_t jitter) | ||||
cperciva: I would call this `inc` rather than `jitter`, since it's the increment being added. | |||||
Done Inline ActionsSee here (counter_ratecheck() in sys/kern/subr_counter.c). cem: See here (counter_ratecheck() in sys/kern/subr_counter.c). | |||||
{ | { | ||||
int64_t val; | int64_t val; | ||||
int now; | int now; | ||||
val = cr->cr_over; | val = cr->cr_over; | ||||
now = ticks; | now = ticks; | ||||
if ((u_int)(now - cr->cr_ticks) >= hz) { | if ((u_int)(now - cr->cr_ticks) >= hz) { | ||||
Show All 20 Lines | if ((cr->cr_lock == 0) && | ||||
/* | /* | ||||
* We failed to lock, in this case other thread may | * We failed to lock, in this case other thread may | ||||
* be running counter_u64_zero(), so it is not safe | * be running counter_u64_zero(), so it is not safe | ||||
* to do an update, we skip it. | * to do an update, we skip it. | ||||
*/ | */ | ||||
return (val); | return (val); | ||||
} | } | ||||
counter_u64_add(cr->cr_rate, 1); | counter_u64_add(cr->cr_rate, jitter); | ||||
if (cr->cr_over != 0) | if (cr->cr_over != 0) | ||||
return (-1); | return (-1); | ||||
if (counter_u64_fetch(cr->cr_rate) > limit) | if (counter_u64_fetch(cr->cr_rate) > limit) | ||||
val = cr->cr_over = -1; | val = cr->cr_over = -1; | ||||
return (val); | return (val); | ||||
} | } | ||||
Show All 17 Lines |
I would call this inc rather than jitter, since it's the increment being added.