diff options
author | davidxu <davidxu@FreeBSD.org> | 2006-12-15 11:52:01 +0000 |
---|---|---|
committer | davidxu <davidxu@FreeBSD.org> | 2006-12-15 11:52:01 +0000 |
commit | ca278718335da1ed4af28e199e5459b0a6fadd2a (patch) | |
tree | ea09b321c6b33b576a254a34f061222ae4c103b0 | |
parent | 8ec27d6b35247153cee3394ff6c7e8ef85e63ff3 (diff) | |
download | FreeBSD-src-ca278718335da1ed4af28e199e5459b0a6fadd2a.zip FreeBSD-src-ca278718335da1ed4af28e199e5459b0a6fadd2a.tar.gz |
- Remove variable _thr_scope_system, all threads are system scope.
- Rename _thr_smp_cpus to boolean variable _thr_is_smp.
- Define CPU_SPINWAIT macro for each arch, only X86 supports it.
-rw-r--r-- | lib/libthr/arch/amd64/include/pthread_md.h | 3 | ||||
-rw-r--r-- | lib/libthr/arch/arm/include/pthread_md.h | 1 | ||||
-rw-r--r-- | lib/libthr/arch/i386/include/pthread_md.h | 2 | ||||
-rw-r--r-- | lib/libthr/arch/ia64/include/pthread_md.h | 2 | ||||
-rw-r--r-- | lib/libthr/arch/powerpc/include/pthread_md.h | 2 | ||||
-rw-r--r-- | lib/libthr/arch/sparc64/include/pthread_md.h | 2 | ||||
-rw-r--r-- | lib/libthr/thread/thr_create.c | 5 | ||||
-rw-r--r-- | lib/libthr/thread/thr_init.c | 16 | ||||
-rw-r--r-- | lib/libthr/thread/thr_private.h | 3 | ||||
-rw-r--r-- | lib/libthr/thread/thr_pspinlock.c | 8 |
10 files changed, 19 insertions, 25 deletions
diff --git a/lib/libthr/arch/amd64/include/pthread_md.h b/lib/libthr/arch/amd64/include/pthread_md.h index 30f63ca..6814cac 100644 --- a/lib/libthr/arch/amd64/include/pthread_md.h +++ b/lib/libthr/arch/amd64/include/pthread_md.h @@ -36,7 +36,8 @@ #include <stddef.h> #include <sys/types.h> #include <machine/sysarch.h> -#include <ucontext.h> + +#define CPU_SPINWAIT __asm __volatile("pause") #define DTV_OFFSET offsetof(struct tcb, tcb_dtv) diff --git a/lib/libthr/arch/arm/include/pthread_md.h b/lib/libthr/arch/arm/include/pthread_md.h index 30f9f86..0164da6 100644 --- a/lib/libthr/arch/arm/include/pthread_md.h +++ b/lib/libthr/arch/arm/include/pthread_md.h @@ -36,6 +36,7 @@ #include <machine/sysarch.h> #include <stddef.h> +#define CPU_SPINWAIT #define DTV_OFFSET offsetof(struct tcb, tcb_dtv) /* diff --git a/lib/libthr/arch/i386/include/pthread_md.h b/lib/libthr/arch/i386/include/pthread_md.h index 4140b9c..1f629e1 100644 --- a/lib/libthr/arch/i386/include/pthread_md.h +++ b/lib/libthr/arch/i386/include/pthread_md.h @@ -37,6 +37,8 @@ #include <sys/types.h> #include <machine/sysarch.h> +#define CPU_SPINWAIT __asm __volatile("pause") + #define DTV_OFFSET offsetof(struct tcb, tcb_dtv) /* diff --git a/lib/libthr/arch/ia64/include/pthread_md.h b/lib/libthr/arch/ia64/include/pthread_md.h index eff38bb..0cff7c9 100644 --- a/lib/libthr/arch/ia64/include/pthread_md.h +++ b/lib/libthr/arch/ia64/include/pthread_md.h @@ -31,6 +31,8 @@ #include <stddef.h> +#define CPU_SPINWAIT + #define DTV_OFFSET offsetof(struct tcb, tcb_dtv) /* diff --git a/lib/libthr/arch/powerpc/include/pthread_md.h b/lib/libthr/arch/powerpc/include/pthread_md.h index e8ca8b3..2abbbdc 100644 --- a/lib/libthr/arch/powerpc/include/pthread_md.h +++ b/lib/libthr/arch/powerpc/include/pthread_md.h @@ -36,6 +36,8 @@ #include <stddef.h> #include <sys/types.h> +#define CPU_SPINWAIT + #define DTV_OFFSET offsetof(struct tcb, tcb_dtv) #define TP_OFFSET 0x7008 diff --git a/lib/libthr/arch/sparc64/include/pthread_md.h b/lib/libthr/arch/sparc64/include/pthread_md.h index 054c2be..8bfa5f4 100644 --- a/lib/libthr/arch/sparc64/include/pthread_md.h +++ b/lib/libthr/arch/sparc64/include/pthread_md.h @@ -35,6 +35,8 @@ #include <stddef.h> +#define CPU_SPINWAIT + #define DTV_OFFSET offsetof(struct tcb, tcb_dtv) /* diff --git a/lib/libthr/thread/thr_create.c b/lib/libthr/thread/thr_create.c index 276e550..abab212 100644 --- a/lib/libthr/thread/thr_create.c +++ b/lib/libthr/thread/thr_create.c @@ -86,11 +86,6 @@ _pthread_create(pthread_t * thread, const pthread_attr_t * attr, new_thread->attr.sched_policy = curthread->attr.sched_policy; } - if (_thr_scope_system > 0) - new_thread->attr.flags |= PTHREAD_SCOPE_SYSTEM; - else if (_thr_scope_system < 0) - new_thread->attr.flags &= ~PTHREAD_SCOPE_SYSTEM; - new_thread->tid = TID_TERMINATED; if (create_stack(&new_thread->attr) != 0) { diff --git a/lib/libthr/thread/thr_init.c b/lib/libthr/thread/thr_init.c index ae4ea33..981941b 100644 --- a/lib/libthr/thread/thr_init.c +++ b/lib/libthr/thread/thr_init.c @@ -58,7 +58,6 @@ char *_usrstack; struct pthread *_thr_initial; -int _thr_scope_system; int _libthr_debug; int _thread_event_mask; struct pthread *_thread_last_event; @@ -99,7 +98,7 @@ struct pthread_cond_attr _pthread_condattr_default = { }; pid_t _thr_pid; -int _thr_smp_cpus = 1; +int _thr_is_smp = 0; size_t _thr_guard_default; size_t _thr_stack_default = THR_STACK_DEFAULT; size_t _thr_stack_initial = THR_STACK_INITIAL; @@ -446,22 +445,15 @@ init_private(void) len = sizeof (_usrstack); if (sysctl(mib, 2, &_usrstack, &len, NULL, 0) == -1) PANIC("Cannot get kern.usrstack from sysctl"); - len = sizeof(_thr_smp_cpus); - sysctlbyname("kern.smp.cpus", &_thr_smp_cpus, &len, NULL, 0); + len = sizeof(_thr_is_smp); + sysctlbyname("kern.smp.cpus", &_thr_is_smp, &len, NULL, 0); + _thr_is_smp = (_thr_is_smp > 1); _thr_page_size = getpagesize(); _thr_guard_default = _thr_page_size; _pthread_attr_default.guardsize_attr = _thr_guard_default; _pthread_attr_default.stacksize_attr = _thr_stack_default; TAILQ_INIT(&_thr_atfork_list); -#ifdef SYSTEM_SCOPE_ONLY - _thr_scope_system = 1; -#else - if (getenv("LIBPTHREAD_SYSTEM_SCOPE") != NULL) - _thr_scope_system = 1; - else if (getenv("LIBPTHREAD_PROCESS_SCOPE") != NULL) - _thr_scope_system = -1; -#endif } init_once = 1; } diff --git a/lib/libthr/thread/thr_private.h b/lib/libthr/thread/thr_private.h index 04492ea..d3a179c 100644 --- a/lib/libthr/thread/thr_private.h +++ b/lib/libthr/thread/thr_private.h @@ -549,7 +549,6 @@ extern int __isthreaded; extern char *_usrstack __hidden; extern struct pthread *_thr_initial __hidden; -extern int _thr_scope_system __hidden; /* For debugger */ extern int _libthr_debug; @@ -578,7 +577,7 @@ extern struct pthread_cond_attr _pthread_condattr_default __hidden; extern struct pthread_prio _thr_priorities[] __hidden; extern pid_t _thr_pid __hidden; -extern int _thr_smp_cpus __hidden; +extern int _thr_is_smp __hidden; extern size_t _thr_guard_default __hidden; extern size_t _thr_stack_default __hidden; diff --git a/lib/libthr/thread/thr_pspinlock.c b/lib/libthr/thread/thr_pspinlock.c index 05dc981..d5684fc 100644 --- a/lib/libthr/thread/thr_pspinlock.c +++ b/lib/libthr/thread/thr_pspinlock.c @@ -104,13 +104,11 @@ _pthread_spin_lock(pthread_spinlock_t *lock) count = SPIN_COUNT; while ((ret = THR_UMUTEX_TRYLOCK(curthread, &lck->s_lock)) != 0) { while (lck->s_lock.m_owner) { - if (_thr_smp_cpus <= 1) { + if (_thr_is_smp) { _pthread_yield(); } else { -#if defined(__i386__) || defined(__x86_64__) - /* tell cpu we are spinning */ - __asm __volatile("pause"); -#endif + CPU_SPINWAIT; + if (--count <= 0) { count = SPIN_COUNT; _pthread_yield(); |