From nobody Mon Oct 06 02:22:10 2025 X-Original-To: dev-commits-src-main@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 4cg31t4Zddz69LGg; Mon, 06 Oct 2025 02:22:10 +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 "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4cg31t3zBSz3sSS; Mon, 06 Oct 2025 02:22:10 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1759717330; 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=KfVi6Wk1HWlDHWevmS4ytJjzTNfO4Mk1qh32fnYNZgc=; b=M0l6fhibk6bOMKw/ZOn3lyeurf17kgULgfN74hujbvwIvk3vMMvQqGfuCFmEdxrcuAFe/c 4s1Iw6R6WR2hPqnyc4xRqui5t6qvLuaO5ptyeYq0CY1yCODoa/3PSjptc2sIvM9VUR1Qc4 5NL2wz3gWPhEscfnZ/glcB9LjRSAgGM0VTVvzJNwHVfJknk+F5ivaMUN5UF5uATo05EtWA rWYBERrBOt5wmUblRMNT2jZOLm/zuMnY4EmaEhNENDmnUg2uP4bpUq+bprtoKw7yOFDVZJ qf4JnA/5dNQyPWCec0+Ivj+zuQpE3mKfL2Vp3zhG8Q4CdOdrFfTSwtXKQIX3yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1759717330; 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=KfVi6Wk1HWlDHWevmS4ytJjzTNfO4Mk1qh32fnYNZgc=; b=PdParP6oycOGC2NkjKhy4OVhvZDiB466WXvBLzqR7VQhtYwvUM9pytfkxyILqqKuIDBMiE tjkm0f568dbzikUW0Ph4sJALr5enN1mzmizmYGkGae/6iPaoOpaSUPS+adFd+R/m6Ue8x9 noKKYluZqLA1GgsrEW5HBZd3c148d6J2n6DP00I139zwfCcVnXTGNxOqa2eFvR8kDPESQv olnNXf9RcqRpYsulahjdY5kW1tlAv5UDwfNdjxg46m/aGEUcMirYT7MXuMxbOXHAQMOsGK zuS4AvVyuQHX1g4JH18MW42CU+Ppo3uhyUzBWPrhVpwz25gQv+5srGTJX6DcqQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1759717330; a=rsa-sha256; cv=none; b=LWTi1tkaYVFr3DnVowU9RcNxpRxmVdTIC7ATMrUHdkMlJvMkpZ5uFYhQlFuarp1APmz5DY RcBCwzsKDXYViBAdJckfUefeK1jl+F8KVPXAaS+8IKhrb6d6mddo6yvB6zEkyEEassiB2r zWxCm8JMXjTv63qtmrPoS8Q4UO2Neg2wRnIvrlvLgm/jI7T+/i9NvY+McVnZv84Da4Ynu7 fRxFKuDCajPdJSJVrS/Gr0LzaxdAkJKUPbH+2Px3fvgW3HvL858UZ0e12zIMFY8PvMx6xe R/UwP+n9s2BnJ6fabyH82DLE8dlw+1LpVPva/ELESG0p++hMX/nBZHxf4rMUNA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4cg31t3MH7zgHS; Mon, 06 Oct 2025 02:22:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 5962MAd7061879; Mon, 6 Oct 2025 02:22:10 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 5962MAwu061876; Mon, 6 Oct 2025 02:22:10 GMT (envelope-from git) Date: Mon, 6 Oct 2025 02:22:10 GMT Message-Id: <202510060222.5962MAwu061876@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mateusz Guzik Subject: git: e0b571d77364 - main - mtx: rename MTX_CONTESTED to MTX_WAITERS List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mjg X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: e0b571d77364d0dcae5492d9f3b901d01d3e13ca Auto-Submitted: auto-generated The branch main has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=e0b571d77364d0dcae5492d9f3b901d01d3e13ca commit e0b571d77364d0dcae5492d9f3b901d01d3e13ca Author: Mateusz Guzik AuthorDate: 2025-10-06 02:00:50 +0000 Commit: Mateusz Guzik CommitDate: 2025-10-06 02:19:38 +0000 mtx: rename MTX_CONTESTED to MTX_WAITERS Using the word "contested" for the case where there are threads blocked on the lock is misleading at best (the lock is already contested if it is being held by one thread and wanted by another). It also diverges from naming used in other primitives (which refer to them as "waiters"). Rename it for some consistency. There were uses of the flag outside of mutex code itself. This is an abuse of the interface. The netgraph thing looks suspicious at best, the sctp thing is fundamentally wrong. Fixing those up is left as an exercise for the reader. While here touch up stale commentary. Sponsored by: Rubicon Communications, LLC ("Netgate") --- sys/kern/kern_mutex.c | 23 +++++++++-------------- sys/netgraph/netflow/netflow.c | 6 +++--- sys/netinet/sctp_lock_bsd.h | 6 +++--- sys/sys/mutex.h | 6 +++--- 4 files changed, 18 insertions(+), 23 deletions(-) diff --git a/sys/kern/kern_mutex.c b/sys/kern/kern_mutex.c index b7316ea5f387..d67c70984528 100644 --- a/sys/kern/kern_mutex.c +++ b/sys/kern/kern_mutex.c @@ -503,8 +503,8 @@ _mtx_trylock_flags_(volatile uintptr_t *c, int opts, const char *file, int line) /* * __mtx_lock_sleep: the tougher part of acquiring an MTX_DEF lock. * - * We call this if the lock is either contested (i.e. we need to go to - * sleep waiting for it), or if we need to recurse on it. + * We get here if lock profiling is enabled, the lock is already held by + * someone else or we are recursing on it. */ #if LOCK_DEBUG > 0 void @@ -660,13 +660,8 @@ retry_turnstile: } #endif - /* - * If the mutex isn't already contested and a failure occurs - * setting the contested bit, the mutex was either released - * or the state of the MTX_RECURSED bit changed. - */ - if ((v & MTX_CONTESTED) == 0 && - !atomic_fcmpset_ptr(&m->mtx_lock, &v, v | MTX_CONTESTED)) { + if ((v & MTX_WAITERS) == 0 && + !atomic_fcmpset_ptr(&m->mtx_lock, &v, v | MTX_WAITERS)) { goto retry_turnstile; } @@ -1029,8 +1024,8 @@ thread_lock_set(struct thread *td, struct mtx *new) /* * __mtx_unlock_sleep: the tougher part of releasing an MTX_DEF lock. * - * We are only called here if the lock is recursed, contested (i.e. we - * need to wake up a blocked thread) or lockstat probe is active. + * We get here if lock profiling is enabled, the lock is already held by + * someone else or we are recursing on it. */ #if LOCK_DEBUG > 0 void @@ -1207,7 +1202,7 @@ _mtx_destroy(volatile uintptr_t *c) if (!mtx_owned(m)) MPASS(mtx_unowned(m)); else { - MPASS((m->mtx_lock & (MTX_RECURSED|MTX_CONTESTED)) == 0); + MPASS((m->mtx_lock & (MTX_RECURSED|MTX_WAITERS)) == 0); /* Perform the non-mtx related part of mtx_unlock_spin(). */ if (LOCK_CLASS(&m->lock_object) == &lock_class_mtx_spin) { @@ -1359,8 +1354,8 @@ db_show_mtx(const struct lock_object *lock) db_printf("DESTROYED"); else { db_printf("OWNED"); - if (m->mtx_lock & MTX_CONTESTED) - db_printf(", CONTESTED"); + if (m->mtx_lock & MTX_WAITERS) + db_printf(", WAITERS"); if (m->mtx_lock & MTX_RECURSED) db_printf(", RECURSED"); } diff --git a/sys/netgraph/netflow/netflow.c b/sys/netgraph/netflow/netflow.c index 978d6fd0b54d..05c6062463be 100644 --- a/sys/netgraph/netflow/netflow.c +++ b/sys/netgraph/netflow/netflow.c @@ -960,7 +960,7 @@ struct ngnf_show_header *resp) list_id = 0; TAILQ_FOREACH(fle, &hsh->head, fle_hash) { - if (hsh->mtx.mtx_lock & MTX_CONTESTED) { + if (hsh->mtx.mtx_lock & MTX_WAITERS) { resp->hash_id = i; resp->list_id = list_id; mtx_unlock(&hsh->mtx); @@ -1111,7 +1111,7 @@ ng_netflow_expire(void *arg) * Interrupt thread wants this entry! * Quick! Quick! Bail out! */ - if (hsh->mtx.mtx_lock & MTX_CONTESTED) + if (hsh->mtx.mtx_lock & MTX_WAITERS) break; /* @@ -1150,7 +1150,7 @@ ng_netflow_expire(void *arg) * Interrupt thread wants this entry! * Quick! Quick! Bail out! */ - if (hsh->mtx.mtx_lock & MTX_CONTESTED) + if (hsh->mtx.mtx_lock & MTX_WAITERS) break; /* diff --git a/sys/netinet/sctp_lock_bsd.h b/sys/netinet/sctp_lock_bsd.h index ec66be0cf371..a60983cb30e3 100644 --- a/sys/netinet/sctp_lock_bsd.h +++ b/sys/netinet/sctp_lock_bsd.h @@ -263,10 +263,10 @@ } while (0) #define SCTP_INP_LOCK_CONTENDED(_inp) \ - ((_inp)->inp_mtx.mtx_lock & MTX_CONTESTED) + ((_inp)->inp_mtx.mtx_lock & MTX_WAITERS) #define SCTP_INP_READ_CONTENDED(_inp) \ - ((_inp)->inp_rdata_mtx.mtx_lock & MTX_CONTESTED) + ((_inp)->inp_rdata_mtx.mtx_lock & MTX_WAITERS) #ifdef SCTP_LOCK_LOGGING #define SCTP_INP_RLOCK(_inp) do { \ @@ -337,7 +337,7 @@ } while (0) #define SCTP_ASOC_CREATE_LOCK_CONTENDED(_inp) \ - ((_inp)->inp_create_mtx.mtx_lock & MTX_CONTESTED) + ((_inp)->inp_create_mtx.mtx_lock & MTX_WAITERS) /* * For the majority of things (once we have found the association) we will diff --git a/sys/sys/mutex.h b/sys/sys/mutex.h index 83300d4eb593..4f6b45d78a88 100644 --- a/sys/sys/mutex.h +++ b/sys/sys/mutex.h @@ -68,9 +68,9 @@ */ #define MTX_UNOWNED 0x00000000 /* Cookie for free mutex */ #define MTX_RECURSED 0x00000001 /* lock recursed (for MTX_DEF only) */ -#define MTX_CONTESTED 0x00000002 /* lock contested (for MTX_DEF only) */ +#define MTX_WAITERS 0x00000002 /* lock has waiters (for MTX_DEF only) */ #define MTX_DESTROYED 0x00000004 /* lock destroyed */ -#define MTX_FLAGMASK (MTX_RECURSED | MTX_CONTESTED | MTX_DESTROYED) +#define MTX_FLAGMASK (MTX_RECURSED | MTX_WAITERS | MTX_DESTROYED) /* * Prototypes @@ -217,7 +217,7 @@ void _thread_lock(struct thread *); #define _mtx_obtain_lock_fetch(mp, vp, tid) \ atomic_fcmpset_acq_ptr(&(mp)->mtx_lock, vp, (tid)) -/* Try to release mtx_lock if it is unrecursed and uncontested. */ +/* Try to release mtx_lock if it is unrecursed and without waiters. */ #define _mtx_release_lock(mp, tid) \ atomic_cmpset_rel_ptr(&(mp)->mtx_lock, (tid), MTX_UNOWNED)