git: 305c3044e024 - main - libthr: Support disable spinloop
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 09 Oct 2026 22:13:48 UTC
The branch main has been updated by aokblast:
URL: https://cgit.FreeBSD.org/src/commit/?id=305c3044e0249ea24a9b4571dfa6ae319a5bcdec
commit 305c3044e0249ea24a9b4571dfa6ae319a5bcdec
Author: ShengYi Hung <aokblast@FreeBSD.org>
AuthorDate: 2026-10-08 18:38:06 +0000
Commit: ShengYi Hung <aokblast@FreeBSD.org>
CommitDate: 2026-10-09 22:13:31 +0000
libthr: Support disable spinloop
Like yieldloops, we shoulde be able to set _thr_spinloops to zero.
Originally, it makes us to enformce default spin time even if we try to
disable it. Make MUTEX_ADAPTIVE_SPINS a one time initialization now.
Reviewed by: kib
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D60486
---
lib/libthr/thread/thr_init.c | 2 +-
lib/libthr/thread/thr_mutex.c | 9 +--------
lib/libthr/thread/thr_private.h | 6 ++++++
3 files changed, 8 insertions(+), 9 deletions(-)
diff --git a/lib/libthr/thread/thr_init.c b/lib/libthr/thread/thr_init.c
index 162ef7dfe7a9..c019c8f27b36 100644
--- a/lib/libthr/thread/thr_init.c
+++ b/lib/libthr/thread/thr_init.c
@@ -118,7 +118,7 @@ size_t _thr_guard_default;
size_t _thr_stack_default = THR_STACK_DEFAULT;
size_t _thr_stack_initial = THR_STACK_INITIAL;
int _thr_page_size;
-int _thr_spinloops;
+int _thr_spinloops = MUTEX_ADAPTIVE_SPINS;
int _thr_yieldloops;
int _thr_queuefifo = 4;
int _gc_count;
diff --git a/lib/libthr/thread/thr_mutex.c b/lib/libthr/thread/thr_mutex.c
index 139dc768b7ba..9c0939aa6080 100644
--- a/lib/libthr/thread/thr_mutex.c
+++ b/lib/libthr/thread/thr_mutex.c
@@ -62,12 +62,6 @@ _Static_assert(offsetof(struct pthread_mutex, m_qe) >= CACHE_LINE_SIZE,
"m_qe must not share a cache line with m_lock.m_owner");
#endif
-/*
- * For adaptive mutexes, how many times to spin doing trylock2
- * before entering the kernel to block
- */
-#define MUTEX_ADAPTIVE_SPINS 2000
-
/*
* Prototypes
*/
@@ -274,8 +268,7 @@ mutex_init_body(struct pthread_mutex *pmutex,
pmutex->m_lock.m_flags |= UMUTEX_ROBUST;
}
if (PMUTEX_TYPE(pmutex->m_flags) == PTHREAD_MUTEX_ADAPTIVE_NP) {
- pmutex->m_spinloops =
- _thr_spinloops ? _thr_spinloops: MUTEX_ADAPTIVE_SPINS;
+ pmutex->m_spinloops = _thr_spinloops;
pmutex->m_yieldloops = _thr_yieldloops;
}
}
diff --git a/lib/libthr/thread/thr_private.h b/lib/libthr/thread/thr_private.h
index cf90ac5bd4ef..ffc4ff7233db 100644
--- a/lib/libthr/thread/thr_private.h
+++ b/lib/libthr/thread/thr_private.h
@@ -154,6 +154,12 @@ TAILQ_HEAD(mutex_queue, pthread_mutex);
#define MAX_DEFER_WAITERS 50
+/*
+ * For adaptive mutexes, how many times to spin doing trylock2
+ * before entering the kernel to block
+ */
+#define MUTEX_ADAPTIVE_SPINS 2000
+
/*
* Values for pthread_mutex m_ps indicator.
*/