aboutsummaryrefslogtreecommitdiff
path: root/sys/sys/counter.h
diff options
context:
space:
mode:
authorGleb Smirnoff <glebius@FreeBSD.org>2016-12-09 17:58:34 +0000
committerGleb Smirnoff <glebius@FreeBSD.org>2016-12-09 17:58:34 +0000
commit169170209c38774c8755f21b2f40a1dd86945a71 (patch)
treed7250c2acb3b4158b1f49c6accb98c0e59e1b559 /sys/sys/counter.h
parentebecdad811cd77b49725d13ea6734296d7e79238 (diff)
downloadsrc-169170209c38774c8755f21b2f40a1dd86945a71.tar.gz
src-169170209c38774c8755f21b2f40a1dd86945a71.zip
Provide counter_ratecheck(), a MP-friendly substitution to ppsratecheck().
When rated event happens at a very quick rate, the ppsratecheck() is not only racy, but also becomes a performance bottleneck. Together with: rrs, jtl
Notes
Notes: svn path=/head/; revision=309745
Diffstat (limited to 'sys/sys/counter.h')
-rw-r--r--sys/sys/counter.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/sys/sys/counter.h b/sys/sys/counter.h
index 2ce7134176f2..5046d41d5f3a 100644
--- a/sys/sys/counter.h
+++ b/sys/sys/counter.h
@@ -59,5 +59,18 @@ uint64_t counter_u64_fetch(counter_u64_t);
for (int i = 0; i < (n); i++) \
counter_u64_zero((a)[i]); \
} while (0)
+
+/*
+ * counter(9) based rate checking.
+ */
+struct counter_rate {
+ counter_u64_t cr_rate; /* Events since last second */
+ volatile int cr_lock; /* Lock to clean the struct */
+ int cr_ticks; /* Ticks on last clean */
+ int cr_over; /* Over limit since cr_ticks? */
+};
+
+int64_t counter_ratecheck(struct counter_rate *, int64_t);
+
#endif /* _KERNEL */
#endif /* ! __SYS_COUNTER_H__ */