From nobody Thu Apr 30 11:40:25 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4g5sfx4vp1z6bhtN for ; Thu, 30 Apr 2026 11:40:25 +0000 (UTC) (envelope-from git@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R13" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4g5sfx38Zbz3T4Z for ; Thu, 30 Apr 2026 11:40:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1777549225; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=rUhzGRYRn6oXSzf9U/Cx7xdwIrk07VF4gm7G5sWXhiQ=; b=gJ+4hNM521Sxp0LSj7Ajgr65y9j3T6Ac0r4Ue4sNGY4Kdwep0Ep19hyA00H3GXnLm6hbIl 5RoO85ESyZK7jv2e5W4Nm9oXJ24UBl55jqSV07xBG1MTUWuRjZt1cF8WpZDNbkq+qndO+9 k1HzuyVeK9KbBD7x5sBLPT7wvFevHFNPi/IyZX/ovJ3fUH5qvo/17XwOzrkTRu3LdQISPs hD6CR9e0QpjFjoe+e3l7Zn5r/IbYedtLo2nWuZhGbNsP7KWKANPkNnpTrxwfRhxWoBdsIr emVK2Yvli3+H6lB2dyUGMXBYbd/V6Xa3Kv4PN+iLeADJXmldUOsS07nBIGwLyQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1777549225; a=rsa-sha256; cv=none; b=YLcQfLyHpOwLk9q4rovEUcd6aFhK/xFL6SE/G121wHIbX6/GC9W5+GmBs8s9HNGtTyCr2t 8MFVHZJ+5w2lvSj9TCcHsG9h+7RdFcPCJtD+vwUL55wZ3SH38CJxsQleYSAHfcoik73rvg RIJEOqh4m3qEJxSVB3dBfszGOaanxVnjDnP9xA4wk4rZJuB+hUXR5kPiPAZX7I4n6/Pmpe JbBEIDlsv6pNsSyTWvYiKotuCSjjXDSH9Yiu2c7opaR+KaOzmWgdZERm2P7AOyq+hus6jT SU1qXSiIhBCSUaOwKHsCgQpUQTa+flP4R61VW+nI2LKFGwF74G9AruTOCUqt0w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1777549225; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=rUhzGRYRn6oXSzf9U/Cx7xdwIrk07VF4gm7G5sWXhiQ=; b=NcMlSCx/WU+SwL6y1r75E1+F2G77pE+fTL9jRDBw0oPEzwd4p95ltU6KcnKlRsv2UjoPWQ 4PWRYboRfI5xOAeREFqgGdM0TbzW84Sr18S0w6UIPmkxxidG/T0gs4x8j0+WOe3zJ8WNuX YUzQdw2X7Osh92x9ldtcBo2oYc7GNz+ryuR8Cc7TCO414A1A1Q90V/wyW7SNpmQsxz/X+e 38jlvConhFE/tP7tzG1uW1RWMjzwB8LbfnEgmCO4jABJ+vRgJtT0ktJ8G9bDCDTqKI2t0V vCP/89mmBxNNd2ZgQjRdgxOtEO1rPuzcBcQUm6L0FEmLaKRnb53QFKJO24CwLw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4g5sfx1y6bz1PBH for ; Thu, 30 Apr 2026 11:40:25 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 21e5b by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 30 Apr 2026 11:40:25 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Jean-=?utf-8?Q?S=C3=A9bast?==?utf-8?Q?ien P=C3=A9?=dron Subject: git: eebb643bb379 - main - sx: Add `sx_has_waiters()` macro List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dumbbell X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: eebb643bb3799ae90dd248f0b5047ec481b26f68 Auto-Submitted: auto-generated Date: Thu, 30 Apr 2026 11:40:25 +0000 Message-Id: <69f33fa9.21e5b.687c9b6@gitrepo.freebsd.org> The branch main has been updated by dumbbell: URL: https://cgit.FreeBSD.org/src/commit/?id=eebb643bb3799ae90dd248f0b5047ec481b26f68 commit eebb643bb3799ae90dd248f0b5047ec481b26f68 Author: Jean-Sébastien Pédron AuthorDate: 2026-04-12 17:20:25 +0000 Commit: Jean-Sébastien Pédron CommitDate: 2026-04-30 11:40:05 +0000 sx: Add `sx_has_waiters()` macro This macro will return non-zero if there are threads waiting for this lock; otherwise, it will return zero. The function assumes (but does not assert) that the caller already holds the lock and that it is interested in other threads waiting for it to release the lock. The motivation to add this is the implementation of `rwsem_is_contended()` in linuxkpi. This Linux function indicates the same thing to the caller: if other threads are waiting for this semaphore. The amdgpu DRM driver started to use `rwsem_is_contended()` in Linux 6.12. Reviewed by: bz, olce Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D56443 --- share/man/man9/sx.9 | 12 +++++++++++- sys/compat/linuxkpi/common/include/linux/rwsem.h | 1 + sys/sys/sx.h | 4 ++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/share/man/man9/sx.9 b/share/man/man9/sx.9 index 473a47c27cf4..f96ee4ffccf7 100644 --- a/share/man/man9/sx.9 +++ b/share/man/man9/sx.9 @@ -24,7 +24,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH .\" DAMAGE. .\" -.Dd November 11, 2017 +.Dd Apri 30, 2026 .Dt SX 9 .Os .Sh NAME @@ -46,6 +46,7 @@ .Nm sx_sleep , .Nm sx_xholder , .Nm sx_xlocked , +.Nm sx_has_waiters , .Nm sx_assert , .Nm SX_SYSINIT , .Nm SX_SYSINIT_FLAGS @@ -88,6 +89,8 @@ .Fn sx_xholder "struct sx *sx" .Ft int .Fn sx_xlocked "const struct sx *sx" +.Ft int +.Fn sx_has_waiters "const struct sx *sx" .Pp .Cd "options INVARIANTS" .Cd "options INVARIANT_SUPPORT" @@ -268,6 +271,13 @@ is returned instead. will return non-zero if the current thread holds the exclusive lock; otherwise, it will return zero. .Pp +.Fn sx_has_waiters +will return non-zero if there are threads waiting for this lock; +otherwise, it will return zero. +The function assumes (but does not assert) that the caller already holds the +lock and that it is interested in other threads waiting for it to release the +lock. +.Pp For ease of programming, .Fn sx_unlock is provided as a macro frontend to the respective functions, diff --git a/sys/compat/linuxkpi/common/include/linux/rwsem.h b/sys/compat/linuxkpi/common/include/linux/rwsem.h index b7a800b12e18..43688ab93796 100644 --- a/sys/compat/linuxkpi/common/include/linux/rwsem.h +++ b/sys/compat/linuxkpi/common/include/linux/rwsem.h @@ -51,6 +51,7 @@ struct rw_semaphore { #define down_read_nested(_rw, _sc) down_read(_rw) #define init_rwsem(_rw) linux_init_rwsem(_rw, rwsem_name("lnxrwsem")) #define down_write_nest_lock(sem, _rw) down_write(_rw) +#define rwsem_is_contended(_rw) sx_has_waiters(&(_rw)->sx); #ifdef WITNESS_ALL /* NOTE: the maximum WITNESS name is 64 chars */ diff --git a/sys/sys/sx.h b/sys/sys/sx.h index d28cae9d01e5..dab4fffb6f15 100644 --- a/sys/sys/sx.h +++ b/sys/sys/sx.h @@ -259,6 +259,10 @@ __sx_xunlock(struct sx *sx, struct thread *td, const char *file, int line) (void)0; /* ensure void type for expression */ \ }) +/* Return true if there are threads waiting to acquire this sx lock. */ +#define sx_has_waiters(sx) \ + ((SX_READ_VALUE(sx) & SX_LOCK_WAITERS) != 0) + #define sx_unlock(sx) sx_unlock_((sx), LOCK_FILE, LOCK_LINE) #define sx_sleep(chan, sx, pri, wmesg, timo) \