From d8a84f08e87c0afe0e630de063e2a1198d02a8fd Mon Sep 17 00:00:00 2001 From: Mateusz Guzik Date: Sun, 16 Feb 2020 18:20:09 +0000 Subject: [PATCH] refcount: update comments about fencing when releasing counts after r357989 Requested by: kib Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D23719 --- sys/kern/kern_synch.c | 4 ++-- sys/sys/refcount.h | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c index 1a19e67bc21..435f1a63a52 100644 --- a/sys/kern/kern_synch.c +++ b/sys/kern/kern_synch.c @@ -368,8 +368,8 @@ refcount_release_last(volatile u_int *count, u_int n, u_int old) /* * Last reference. Signal the user to call the destructor. * - * Ensure that the destructor sees all updates. The fence_rel - * at the start of refcount_releasen synchronizes with this fence. + * Ensure that the destructor sees all updates. This synchronizes + * with release fences from all routines which drop the count. */ atomic_thread_fence_acq(); return (true); diff --git a/sys/sys/refcount.h b/sys/sys/refcount.h index 9173793c328..a3becb5558a 100644 --- a/sys/sys/refcount.h +++ b/sys/sys/refcount.h @@ -119,6 +119,9 @@ refcount_releasen(volatile u_int *count, u_int n) KASSERT(n < REFCOUNT_SATURATION_VALUE / 2, ("refcount_releasen: n=%u too large", n)); + /* + * Paired with acquire fence in refcount_release_last. + */ atomic_thread_fence_rel(); old = atomic_fetchadd_int(count, -n); if (__predict_false(n >= REFCOUNT_COUNT(old) || @@ -198,6 +201,9 @@ refcount_release_if_gt(volatile u_int *count, u_int n) return (false); if (__predict_false(REFCOUNT_SATURATED(old))) return (true); + /* + * Paired with acquire fence in refcount_release_last. + */ if (atomic_fcmpset_rel_int(count, &old, old - 1)) return (true); }