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
This commit is contained in:
ShengYi Hung committed 2026-10-10 09:13:31 +11:00
1 parent 5b1f1fd624
commit 305c3044e0
3 files changed
+8 -9

No files matched your search

+1 -1
View File
@@ -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;
+1 -8
View File
@@ -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;
}
}
+6
View File
@@ -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.
*/