summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authordavidxu <davidxu@FreeBSD.org>2006-08-08 04:42:41 +0000
committerdavidxu <davidxu@FreeBSD.org>2006-08-08 04:42:41 +0000
commitcfa46376c709e58e6cdbe41e2d8674dc0ee29184 (patch)
treeb35cd73f8796696f70ac2128fab255ddaa5c9969 /lib
parentae9a521b0529c447bd5d6355a0690c7b2af3ad5c (diff)
downloadFreeBSD-src-cfa46376c709e58e6cdbe41e2d8674dc0ee29184.zip
FreeBSD-src-cfa46376c709e58e6cdbe41e2d8674dc0ee29184.tar.gz
Get number of CPUs and ignore spin count on single processor machine.
Diffstat (limited to 'lib')
-rw-r--r--lib/libthr/thread/thr_init.c3
-rw-r--r--lib/libthr/thread/thr_private.h2
-rw-r--r--lib/libthr/thread/thr_pspinlock.c16
3 files changed, 15 insertions, 6 deletions
diff --git a/lib/libthr/thread/thr_init.c b/lib/libthr/thread/thr_init.c
index 1150985..5d1aae5 100644
--- a/lib/libthr/thread/thr_init.c
+++ b/lib/libthr/thread/thr_init.c
@@ -99,6 +99,7 @@ struct pthread_cond_attr _pthread_condattr_default = {
};
pid_t _thr_pid;
+int _thr_smp_cpus = 1;
size_t _thr_guard_default;
size_t _thr_stack_default = THR_STACK_DEFAULT;
size_t _thr_stack_initial = THR_STACK_INITIAL;
@@ -443,6 +444,8 @@ 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);
_thr_page_size = getpagesize();
_thr_guard_default = _thr_page_size;
_pthread_attr_default.guardsize_attr = _thr_guard_default;
diff --git a/lib/libthr/thread/thr_private.h b/lib/libthr/thread/thr_private.h
index 29993ec..bb6c999 100644
--- a/lib/libthr/thread/thr_private.h
+++ b/lib/libthr/thread/thr_private.h
@@ -588,6 +588,8 @@ 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 size_t _thr_guard_default __hidden;
extern size_t _thr_stack_default __hidden;
extern size_t _thr_stack_initial __hidden;
diff --git a/lib/libthr/thread/thr_pspinlock.c b/lib/libthr/thread/thr_pspinlock.c
index ec3d68b..561ac26 100644
--- a/lib/libthr/thread/thr_pspinlock.c
+++ b/lib/libthr/thread/thr_pspinlock.c
@@ -104,13 +104,17 @@ _pthread_spin_lock(pthread_spinlock_t *lock)
count = SPIN_COUNT;
while ((ret = THR_UMTX_TRYLOCK(curthread, &lck->s_lock)) != 0) {
while (lck->s_lock) {
-#ifdef __i386__
- /* tell cpu we are spinning */
- __asm __volatile("pause");
-#endif
- if (--count <= 0) {
- count = SPIN_COUNT;
+ if (_thr_smp_cpus <= 1) {
_pthread_yield();
+ } else {
+#if defined(__i386__) || defined(__x86_64__)
+ /* tell cpu we are spinning */
+ __asm __volatile("pause");
+#endif
+ if (--count <= 0) {
+ count = SPIN_COUNT;
+ _pthread_yield();
+ }
}
}
}
OpenPOWER on IntegriCloud