commit d61eacede41f7e23b141c6f882f2efe63847a4c0 Author: Ryota Ozaki Date: Tue Jul 25 13:48:58 2017 +0900 localcount debug diff --git a/sys/kern/subr_localcount.c b/sys/kern/subr_localcount.c index 064d5407f07..a132e6c7566 100644 --- a/sys/kern/subr_localcount.c +++ b/sys/kern/subr_localcount.c @@ -253,5 +253,36 @@ localcount_release(struct localcount *lc, kcondvar_t *cv, kmutex_t *interlock) } localcount_adjust(lc, -1); + KDASSERT(localcount_debug_refcnt(lc) >= 0); out: kpreempt_enable(); } + +static void +localcount_debug_refcnt_cb(void *p, void *arg, struct cpu_info *ci __unused) +{ + int64_t *localp = p; + int64_t *total = arg; + + *total += *localp; +} + +/* + * localcount_debug_refcnt(lc) + * + * Return a total reference count of lc. It should be used only + * for debugging purposes because the result isn't guaranteed to + * be accurate and stable. + * + * Can sleep. + */ +int64_t +localcount_debug_refcnt(struct localcount *lc) +{ + int64_t total = 0; + + ASSERT_SLEEPABLE(); + + percpu_foreach(lc->lc_percpu, localcount_debug_refcnt_cb, &total); + + return total; +} diff --git a/sys/sys/localcount.h b/sys/sys/localcount.h index 6a301197e95..a15eb4a315d 100644 --- a/sys/sys/localcount.h +++ b/sys/sys/localcount.h @@ -55,4 +55,6 @@ void localcount_acquire(struct localcount *); void localcount_release(struct localcount *, struct kcondvar *, struct kmutex *); +int64_t localcount_debug_refcnt(struct localcount *); + #endif /* _SYS_LOCALCOUNT_H */