mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-25 16:13:17 +00:00
Add a way to force 1:1 mode for libpthread. To do this, define
LIBPTHREAD_SYSTEM_SCOPE in the environment. You can still force libpthread to be built in strictly 1:1 by adding -DSYSTEM_SCOPE_ONLY to CFLAGS. This is kept for archs that don't yet support M:N mode. Requested by: rwatson Reviewed by: davidxu
This commit is contained in:
parent
ea39d07d2a
commit
00be1d3d12
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=133269
@ -126,9 +126,8 @@ _pthread_create(pthread_t * thread, const pthread_attr_t * attr,
|
||||
*/
|
||||
}
|
||||
}
|
||||
#ifdef SYSTEM_SCOPE_ONLY
|
||||
new_thread->attr.flags |= PTHREAD_SCOPE_SYSTEM;
|
||||
#endif
|
||||
if (_thread_scope_system != 0)
|
||||
new_thread->attr.flags |= PTHREAD_SCOPE_SYSTEM;
|
||||
if (create_stack(&new_thread->attr) != 0) {
|
||||
/* Insufficient memory to create a stack: */
|
||||
ret = EAGAIN;
|
||||
|
@ -126,11 +126,8 @@ _pthread_exit(void *status)
|
||||
KSE_LOCK_ACQUIRE(curkse, &_thread_list_lock);
|
||||
/* Use thread_list_lock */
|
||||
_thread_active_threads--;
|
||||
#ifdef SYSTEM_SCOPE_ONLY
|
||||
if (_thread_active_threads == 0) {
|
||||
#else
|
||||
if (_thread_active_threads == 1) {
|
||||
#endif
|
||||
if ((_thread_scope_system == 0 && _thread_active_threads == 1) ||
|
||||
(_thread_scope_system != 0 && _thread_active_threads == 0)) {
|
||||
KSE_LOCK_RELEASE(curkse, &_thread_list_lock);
|
||||
_kse_critical_leave(crit);
|
||||
exit(0);
|
||||
|
@ -258,11 +258,7 @@ _libpthread_init(struct pthread *curthread)
|
||||
_kse_init();
|
||||
|
||||
/* Initialize the initial kse and kseg. */
|
||||
#ifdef SYSTEM_SCOPE_ONLY
|
||||
_kse_initial = _kse_alloc(NULL, 1);
|
||||
#else
|
||||
_kse_initial = _kse_alloc(NULL, 0);
|
||||
#endif
|
||||
_kse_initial = _kse_alloc(NULL, _thread_scope_system);
|
||||
if (_kse_initial == NULL)
|
||||
PANIC("Can't allocate initial kse.");
|
||||
_kse_initial->k_kseg = _kseg_alloc(NULL);
|
||||
@ -467,6 +463,14 @@ init_private(void)
|
||||
/* Clear pending signals and get the process signal mask. */
|
||||
SIGEMPTYSET(_thr_proc_sigpending);
|
||||
|
||||
/* Are we in M:N mode (default) or 1:1 mode? */
|
||||
#ifdef SYSTEM_SCOPE_ONLY
|
||||
_thread_scope_system = 1;
|
||||
#else
|
||||
if (getenv("LIBPTHREAD_SYSTEM_SCOPE") != NULL)
|
||||
_thread_scope_system = 1;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* _thread_list_lock and _kse_count are initialized
|
||||
* by _kse_init()
|
||||
|
@ -75,13 +75,8 @@ __FBSDID("$FreeBSD$");
|
||||
* same number of KSEs and KSE groups as threads. Once these levels are
|
||||
* reached, any extra KSE and KSE groups will be free()'d.
|
||||
*/
|
||||
#ifdef SYSTEM_SCOPE_ONLY
|
||||
#define MAX_CACHED_KSES 100
|
||||
#define MAX_CACHED_KSEGS 100
|
||||
#else
|
||||
#define MAX_CACHED_KSES 50
|
||||
#define MAX_CACHED_KSEGS 50
|
||||
#endif
|
||||
#define MAX_CACHED_KSES ((_thread_scope_system == 0) ? 50 : 100)
|
||||
#define MAX_CACHED_KSEGS ((_thread_scope_system == 0) ? 50 : 100)
|
||||
|
||||
#define KSE_SET_MBOX(kse, thrd) \
|
||||
(kse)->k_kcb->kcb_kmbx.km_curthread = &(thrd)->tcb->tcb_tmbx
|
||||
@ -412,19 +407,20 @@ _kse_setthreaded(int threaded)
|
||||
*/
|
||||
_kse_initial->k_flags |= KF_STARTED;
|
||||
|
||||
#ifdef SYSTEM_SCOPE_ONLY
|
||||
/*
|
||||
* For bound thread, kernel reads mailbox pointer once,
|
||||
* we'd set it here before calling kse_create
|
||||
*/
|
||||
_tcb_set(_kse_initial->k_kcb, _thr_initial->tcb);
|
||||
KSE_SET_MBOX(_kse_initial, _thr_initial);
|
||||
_kse_initial->k_kcb->kcb_kmbx.km_flags |= KMF_BOUND;
|
||||
#else
|
||||
_thr_initial->attr.flags &= ~PTHREAD_SCOPE_SYSTEM;
|
||||
_kse_initial->k_kseg->kg_flags &= ~KGF_SINGLE_THREAD;
|
||||
_kse_initial->k_kcb->kcb_kmbx.km_curthread = NULL;
|
||||
#endif
|
||||
if (_thread_scope_system == 0) {
|
||||
_thr_initial->attr.flags &= ~PTHREAD_SCOPE_SYSTEM;
|
||||
_kse_initial->k_kseg->kg_flags &= ~KGF_SINGLE_THREAD;
|
||||
_kse_initial->k_kcb->kcb_kmbx.km_curthread = NULL;
|
||||
}
|
||||
else {
|
||||
/*
|
||||
* For bound thread, kernel reads mailbox pointer
|
||||
* once, we'd set it here before calling kse_create.
|
||||
*/
|
||||
_tcb_set(_kse_initial->k_kcb, _thr_initial->tcb);
|
||||
KSE_SET_MBOX(_kse_initial, _thr_initial);
|
||||
_kse_initial->k_kcb->kcb_kmbx.km_flags |= KMF_BOUND;
|
||||
}
|
||||
|
||||
/*
|
||||
* Locking functions in libc are required when there are
|
||||
@ -443,15 +439,17 @@ _kse_setthreaded(int threaded)
|
||||
_kse_initial->k_kcb->kcb_kmbx.km_lwp;
|
||||
_thread_activated = 1;
|
||||
|
||||
#ifndef SYSTEM_SCOPE_ONLY
|
||||
/* Set current thread to initial thread */
|
||||
_tcb_set(_kse_initial->k_kcb, _thr_initial->tcb);
|
||||
KSE_SET_MBOX(_kse_initial, _thr_initial);
|
||||
_thr_start_sig_daemon();
|
||||
_thr_setmaxconcurrency();
|
||||
#else
|
||||
__sys_sigprocmask(SIG_SETMASK, &_thr_initial->sigmask, NULL);
|
||||
#endif
|
||||
if (_thread_scope_system == 0) {
|
||||
/* Set current thread to initial thread */
|
||||
_tcb_set(_kse_initial->k_kcb, _thr_initial->tcb);
|
||||
KSE_SET_MBOX(_kse_initial, _thr_initial);
|
||||
_thr_start_sig_daemon();
|
||||
_thr_setmaxconcurrency();
|
||||
}
|
||||
else {
|
||||
__sys_sigprocmask(SIG_SETMASK, &_thr_initial->sigmask,
|
||||
NULL);
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
@ -992,6 +992,7 @@ SCLASS struct pthread *_thr_initial SCLASS_PRESET(NULL);
|
||||
/* For debugger */
|
||||
SCLASS int _libkse_debug SCLASS_PRESET(0);
|
||||
SCLASS int _thread_activated SCLASS_PRESET(0);
|
||||
SCLASS int _thread_scope_system SCLASS_PRESET(0);
|
||||
|
||||
/* List of all threads: */
|
||||
SCLASS TAILQ_HEAD(, pthread) _thread_list
|
||||
|
@ -126,9 +126,8 @@ _pthread_create(pthread_t * thread, const pthread_attr_t * attr,
|
||||
*/
|
||||
}
|
||||
}
|
||||
#ifdef SYSTEM_SCOPE_ONLY
|
||||
new_thread->attr.flags |= PTHREAD_SCOPE_SYSTEM;
|
||||
#endif
|
||||
if (_thread_scope_system != 0)
|
||||
new_thread->attr.flags |= PTHREAD_SCOPE_SYSTEM;
|
||||
if (create_stack(&new_thread->attr) != 0) {
|
||||
/* Insufficient memory to create a stack: */
|
||||
ret = EAGAIN;
|
||||
|
@ -126,11 +126,8 @@ _pthread_exit(void *status)
|
||||
KSE_LOCK_ACQUIRE(curkse, &_thread_list_lock);
|
||||
/* Use thread_list_lock */
|
||||
_thread_active_threads--;
|
||||
#ifdef SYSTEM_SCOPE_ONLY
|
||||
if (_thread_active_threads == 0) {
|
||||
#else
|
||||
if (_thread_active_threads == 1) {
|
||||
#endif
|
||||
if ((_thread_scope_system == 0 && _thread_active_threads == 1) ||
|
||||
(_thread_scope_system != 0 && _thread_active_threads == 0)) {
|
||||
KSE_LOCK_RELEASE(curkse, &_thread_list_lock);
|
||||
_kse_critical_leave(crit);
|
||||
exit(0);
|
||||
|
@ -258,11 +258,7 @@ _libpthread_init(struct pthread *curthread)
|
||||
_kse_init();
|
||||
|
||||
/* Initialize the initial kse and kseg. */
|
||||
#ifdef SYSTEM_SCOPE_ONLY
|
||||
_kse_initial = _kse_alloc(NULL, 1);
|
||||
#else
|
||||
_kse_initial = _kse_alloc(NULL, 0);
|
||||
#endif
|
||||
_kse_initial = _kse_alloc(NULL, _thread_scope_system);
|
||||
if (_kse_initial == NULL)
|
||||
PANIC("Can't allocate initial kse.");
|
||||
_kse_initial->k_kseg = _kseg_alloc(NULL);
|
||||
@ -467,6 +463,14 @@ init_private(void)
|
||||
/* Clear pending signals and get the process signal mask. */
|
||||
SIGEMPTYSET(_thr_proc_sigpending);
|
||||
|
||||
/* Are we in M:N mode (default) or 1:1 mode? */
|
||||
#ifdef SYSTEM_SCOPE_ONLY
|
||||
_thread_scope_system = 1;
|
||||
#else
|
||||
if (getenv("LIBPTHREAD_SYSTEM_SCOPE") != NULL)
|
||||
_thread_scope_system = 1;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* _thread_list_lock and _kse_count are initialized
|
||||
* by _kse_init()
|
||||
|
@ -75,13 +75,8 @@ __FBSDID("$FreeBSD$");
|
||||
* same number of KSEs and KSE groups as threads. Once these levels are
|
||||
* reached, any extra KSE and KSE groups will be free()'d.
|
||||
*/
|
||||
#ifdef SYSTEM_SCOPE_ONLY
|
||||
#define MAX_CACHED_KSES 100
|
||||
#define MAX_CACHED_KSEGS 100
|
||||
#else
|
||||
#define MAX_CACHED_KSES 50
|
||||
#define MAX_CACHED_KSEGS 50
|
||||
#endif
|
||||
#define MAX_CACHED_KSES ((_thread_scope_system == 0) ? 50 : 100)
|
||||
#define MAX_CACHED_KSEGS ((_thread_scope_system == 0) ? 50 : 100)
|
||||
|
||||
#define KSE_SET_MBOX(kse, thrd) \
|
||||
(kse)->k_kcb->kcb_kmbx.km_curthread = &(thrd)->tcb->tcb_tmbx
|
||||
@ -412,19 +407,20 @@ _kse_setthreaded(int threaded)
|
||||
*/
|
||||
_kse_initial->k_flags |= KF_STARTED;
|
||||
|
||||
#ifdef SYSTEM_SCOPE_ONLY
|
||||
/*
|
||||
* For bound thread, kernel reads mailbox pointer once,
|
||||
* we'd set it here before calling kse_create
|
||||
*/
|
||||
_tcb_set(_kse_initial->k_kcb, _thr_initial->tcb);
|
||||
KSE_SET_MBOX(_kse_initial, _thr_initial);
|
||||
_kse_initial->k_kcb->kcb_kmbx.km_flags |= KMF_BOUND;
|
||||
#else
|
||||
_thr_initial->attr.flags &= ~PTHREAD_SCOPE_SYSTEM;
|
||||
_kse_initial->k_kseg->kg_flags &= ~KGF_SINGLE_THREAD;
|
||||
_kse_initial->k_kcb->kcb_kmbx.km_curthread = NULL;
|
||||
#endif
|
||||
if (_thread_scope_system == 0) {
|
||||
_thr_initial->attr.flags &= ~PTHREAD_SCOPE_SYSTEM;
|
||||
_kse_initial->k_kseg->kg_flags &= ~KGF_SINGLE_THREAD;
|
||||
_kse_initial->k_kcb->kcb_kmbx.km_curthread = NULL;
|
||||
}
|
||||
else {
|
||||
/*
|
||||
* For bound thread, kernel reads mailbox pointer
|
||||
* once, we'd set it here before calling kse_create.
|
||||
*/
|
||||
_tcb_set(_kse_initial->k_kcb, _thr_initial->tcb);
|
||||
KSE_SET_MBOX(_kse_initial, _thr_initial);
|
||||
_kse_initial->k_kcb->kcb_kmbx.km_flags |= KMF_BOUND;
|
||||
}
|
||||
|
||||
/*
|
||||
* Locking functions in libc are required when there are
|
||||
@ -443,15 +439,17 @@ _kse_setthreaded(int threaded)
|
||||
_kse_initial->k_kcb->kcb_kmbx.km_lwp;
|
||||
_thread_activated = 1;
|
||||
|
||||
#ifndef SYSTEM_SCOPE_ONLY
|
||||
/* Set current thread to initial thread */
|
||||
_tcb_set(_kse_initial->k_kcb, _thr_initial->tcb);
|
||||
KSE_SET_MBOX(_kse_initial, _thr_initial);
|
||||
_thr_start_sig_daemon();
|
||||
_thr_setmaxconcurrency();
|
||||
#else
|
||||
__sys_sigprocmask(SIG_SETMASK, &_thr_initial->sigmask, NULL);
|
||||
#endif
|
||||
if (_thread_scope_system == 0) {
|
||||
/* Set current thread to initial thread */
|
||||
_tcb_set(_kse_initial->k_kcb, _thr_initial->tcb);
|
||||
KSE_SET_MBOX(_kse_initial, _thr_initial);
|
||||
_thr_start_sig_daemon();
|
||||
_thr_setmaxconcurrency();
|
||||
}
|
||||
else {
|
||||
__sys_sigprocmask(SIG_SETMASK, &_thr_initial->sigmask,
|
||||
NULL);
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
@ -992,6 +992,7 @@ SCLASS struct pthread *_thr_initial SCLASS_PRESET(NULL);
|
||||
/* For debugger */
|
||||
SCLASS int _libkse_debug SCLASS_PRESET(0);
|
||||
SCLASS int _thread_activated SCLASS_PRESET(0);
|
||||
SCLASS int _thread_scope_system SCLASS_PRESET(0);
|
||||
|
||||
/* List of all threads: */
|
||||
SCLASS TAILQ_HEAD(, pthread) _thread_list
|
||||
|
Loading…
Reference in New Issue
Block a user