commit f9838f091f891ccdb51a1bb0c0e6f899f04affda 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..30d51a8cbbf 100644 --- a/sys/kern/subr_localcount.c +++ b/sys/kern/subr_localcount.c @@ -209,6 +209,9 @@ localcount_acquire(struct localcount *lc) KASSERT(lc->lc_totalp == NULL); localcount_adjust(lc, +1); +#ifdef LOCKDEBUG + atomic_inc_32(&lc->lc_refcnt); +#endif } /* @@ -253,5 +256,26 @@ localcount_release(struct localcount *lc, kcondvar_t *cv, kmutex_t *interlock) } localcount_adjust(lc, -1); +#ifdef LOCKDEBUG + if ((int32_t)atomic_dec_32_nv(&lc->lc_refcnt) < 0) + panic("counter underflow"); +#endif out: kpreempt_enable(); } + +/* + * localcount_debug_refcnt(lc) + * + * Return a total reference count of lc. It returns a correct value + * only if LOCKDEBUG enabled. Otherwise always return 0. + */ +int32_t +localcount_debug_refcnt(const struct localcount *lc) +{ + +#ifdef LOCKDEBUG + return (int32_t)lc->lc_refcnt; +#else + return 0; +#endif +} diff --git a/sys/sys/localcount.h b/sys/sys/localcount.h index 6a301197e95..5de28bf516b 100644 --- a/sys/sys/localcount.h +++ b/sys/sys/localcount.h @@ -37,6 +37,9 @@ #endif #include +#ifdef LOCKDEBUG +#include +#endif struct kcondvar; struct kmutex; @@ -45,6 +48,9 @@ struct percpu; struct localcount { int64_t *lc_totalp; struct percpu *lc_percpu; /* int64_t */ +#ifdef LOCKDEBUG + uint32_t lc_refcnt; +#endif }; void localcount_init(struct localcount *); @@ -55,4 +61,6 @@ void localcount_acquire(struct localcount *); void localcount_release(struct localcount *, struct kcondvar *, struct kmutex *); +int32_t localcount_debug_refcnt(const struct localcount *); + #endif /* _SYS_LOCALCOUNT_H */