From owner-svn-src-all@freebsd.org Sun Jan 19 18:18:18 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 20AE9221548; Sun, 19 Jan 2020 18:18:18 +0000 (UTC) (envelope-from jeff@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 48132K5nFCz4XRt; Sun, 19 Jan 2020 18:18:17 +0000 (UTC) (envelope-from jeff@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id BD2F4EE79; Sun, 19 Jan 2020 18:18:17 +0000 (UTC) (envelope-from jeff@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 00JIIHtj049445; Sun, 19 Jan 2020 18:18:17 GMT (envelope-from jeff@FreeBSD.org) Received: (from jeff@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 00JIIHOv049443; Sun, 19 Jan 2020 18:18:17 GMT (envelope-from jeff@FreeBSD.org) Message-Id: <202001191818.00JIIHOv049443@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jeff set sender to jeff@FreeBSD.org using -f From: Jeff Roberson Date: Sun, 19 Jan 2020 18:18:17 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r356885 - in head/sys: kern sys X-SVN-Group: head X-SVN-Commit-Author: jeff X-SVN-Commit-Paths: in head/sys: kern sys X-SVN-Commit-Revision: 356885 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 19 Jan 2020 18:18:18 -0000 Author: jeff Date: Sun Jan 19 18:18:17 2020 New Revision: 356885 URL: https://svnweb.freebsd.org/changeset/base/356885 Log: Provide an API for interlocked refcount sleeps. Reviewed by: kib, markj Differential Revision: https://reviews.freebsd.org/D22908 Modified: head/sys/kern/kern_synch.c head/sys/sys/refcount.h Modified: head/sys/kern/kern_synch.c ============================================================================== --- head/sys/kern/kern_synch.c Sun Jan 19 17:47:04 2020 (r356884) +++ head/sys/kern/kern_synch.c Sun Jan 19 18:18:17 2020 (r356885) @@ -381,15 +381,21 @@ refcount_release_last(volatile u_int *count, u_int n, * a precise answer should use refcount_wait(). */ void -refcount_sleep(volatile u_int *count, const char *wmesg, int pri) +_refcount_sleep(volatile u_int *count, struct lock_object *lock, + const char *wmesg, int pri) { void *wchan; u_int old; - if (REFCOUNT_COUNT(*count) == 0) + if (REFCOUNT_COUNT(*count) == 0) { + if (lock != NULL) + LOCK_CLASS(lock)->lc_unlock(lock); return; + } wchan = __DEVOLATILE(void *, count); sleepq_lock(wchan); + if (lock != NULL) + LOCK_CLASS(lock)->lc_unlock(lock); old = *count; for (;;) { if (REFCOUNT_COUNT(old) == 0) { Modified: head/sys/sys/refcount.h ============================================================================== --- head/sys/sys/refcount.h Sun Jan 19 17:47:04 2020 (r356884) +++ head/sys/sys/refcount.h Sun Jan 19 18:18:17 2020 (r356885) @@ -46,7 +46,6 @@ #define REFCOUNT_COUNT(x) ((x) & ~REFCOUNT_WAITER) bool refcount_release_last(volatile u_int *count, u_int n, u_int old); -void refcount_sleep(volatile u_int *count, const char *wmesg, int prio); /* * Attempt to handle reference count overflow and underflow. Force the counter @@ -135,13 +134,29 @@ refcount_release(volatile u_int *count) return (refcount_releasen(count, 1)); } +#ifdef _KERNEL +struct lock_object; +void _refcount_sleep(volatile u_int *count, struct lock_object *, + const char *wmesg, int prio); + static __inline void +refcount_sleep(volatile u_int *count, const char *wmesg, int prio) +{ + + _refcount_sleep(count, NULL, wmesg, prio); +} + +#define refcount_sleep_interlock(count, lock, wmesg, prio) \ + _refcount_sleep((count), (struct lock_object *)(lock), (wmesg), (prio)) + +static __inline void refcount_wait(volatile u_int *count, const char *wmesg, int prio) { while (*count != 0) refcount_sleep(count, wmesg, prio); } +#endif /* * This functions returns non-zero if the refcount was