static int rtentry_ctor(void *mem, int size, void *arg, int how) { struct rtentry *rt = mem; bzero(rt, offsetof(struct rtentry, rt_endzero)); counter_u64_zero(rt->rt_pksent); return (0); }
counter_u64_t counter_u64_alloc(int flags) { counter_u64_t r; r = uma_zalloc(pcpu_zone_64, flags); if (r != NULL) counter_u64_zero(r); return (r); }
void mp_ring_reset_stats(struct mp_ring *r) { counter_u64_zero(r->enqueues); counter_u64_zero(r->drops); counter_u64_zero(r->starts); counter_u64_zero(r->stalls); counter_u64_zero(r->restarts); counter_u64_zero(r->abdications); }
/* * MP-friendly version of ppsratecheck(). * * Returns non-negative if we are in the rate, negative otherwise. * 0 - rate limit not reached. * -1 - rate limit reached. * >0 - rate limit was reached before, and was just reset. The return value * is number of events since last reset. */ int64_t counter_ratecheck(struct counter_rate *cr, int64_t limit) { int64_t val; int now; val = cr->cr_over; now = ticks; if (now - cr->cr_ticks >= hz) { /* * Time to clear the structure, we are in the next second. * First try unlocked read, and then proceed with atomic. */ if ((cr->cr_lock == 0) && atomic_cmpset_acq_int(&cr->cr_lock, 0, 1)) { /* * Check if other thread has just went through the * reset sequence before us. */ if (now - cr->cr_ticks >= hz) { val = counter_u64_fetch(cr->cr_rate); counter_u64_zero(cr->cr_rate); cr->cr_over = 0; cr->cr_ticks = now; if (val <= limit) val = 0; } atomic_store_rel_int(&cr->cr_lock, 0); } else /* * We failed to lock, in this case other thread may * be running counter_u64_zero(), so it is not safe * to do an update, we skip it. */ return (val); } counter_u64_add(cr->cr_rate, 1); if (cr->cr_over != 0) return (-1); if (counter_u64_fetch(cr->cr_rate) > limit) val = cr->cr_over = -1; return (val); }
int sysctl_handle_counter_u64(SYSCTL_HANDLER_ARGS) { uint64_t out; int error; out = counter_u64_fetch(*(counter_u64_t *)arg1); error = SYSCTL_OUT(req, &out, sizeof(uint64_t)); if (error || !req->newptr) return (error); /* * Any write attempt to a counter zeroes it. */ counter_u64_zero(*(counter_u64_t *)arg1); return (0); }
int sysctl_handle_counter_u64_array(SYSCTL_HANDLER_ARGS) { uint64_t *out; int error; out = malloc(arg2 * sizeof(uint64_t), M_TEMP, M_WAITOK); for (int i = 0; i < arg2; i++) out[i] = counter_u64_fetch(((counter_u64_t *)arg1)[i]); error = SYSCTL_OUT(req, out, arg2 * sizeof(uint64_t)); free(out, M_TEMP); if (error || !req->newptr) return (error); /* * Any write attempt to a counter zeroes it. */ for (int i = 0; i < arg2; i++) counter_u64_zero(((counter_u64_t *)arg1)[i]); return (0); }