summaryrefslogtreecommitdiff
path: root/lib/libpthread/arch
diff options
context:
space:
mode:
authorad <ad@NetBSD.org>2007-11-13 17:20:08 +0000
committerad <ad@NetBSD.org>2007-11-13 17:20:08 +0000
commit66ac2ffaf293a1766211e270fcce0ba856f8f80e (patch)
tree14c1c20985051c159c5d7b74ce133f33a8efdd64 /lib/libpthread/arch
parent3c776c8aa6570d9365bd4dc5468590e6c51103bb (diff)
Mutexes:
- Play scrooge again and chop more cycles off acquire/release. - Spin while the lock holder is running on another CPU (adaptive mutexes). - Do non-atomic release. Threadreg: - Add the necessary hooks to use a thread register. - Add the code for i386, using %gs. - Leave i386 code disabled until xen and COMPAT_NETBSD32 have the changes.
Diffstat (limited to 'lib/libpthread/arch')
-rw-r--r--lib/libpthread/arch/i386/_context_u.S23
-rw-r--r--lib/libpthread/arch/i386/pthread_md.c16
-rw-r--r--lib/libpthread/arch/i386/pthread_md.h43
-rw-r--r--lib/libpthread/arch/x86_64/_context_u.S20
-rw-r--r--lib/libpthread/arch/x86_64/pthread_md.h28
5 files changed, 96 insertions, 34 deletions
diff --git a/lib/libpthread/arch/i386/_context_u.S b/lib/libpthread/arch/i386/_context_u.S
index 3dac247c3bd..6720bd67402 100644
--- a/lib/libpthread/arch/i386/_context_u.S
+++ b/lib/libpthread/arch/i386/_context_u.S
@@ -1,4 +1,4 @@
-/* $NetBSD: _context_u.S,v 1.6 2007/11/13 15:57:14 ad Exp $ */
+/* $NetBSD: _context_u.S,v 1.7 2007/11/13 17:20:09 ad Exp $ */
/*-
* Copyright (c) 2001, 2007 The NetBSD Foundation, Inc.
@@ -101,26 +101,17 @@ STUB(_swapcontext_u_xmm)
movl 8(%esp), %ecx
SETC
-STUB(pthread__atomic_cas_ptr)
+STUB(pthread__atomic_swap_ptr)
movl 4(%esp), %ecx
movl 8(%esp), %eax
- movl 12(%esp), %edx
- movl (%eax), %eax
- lock
- cmpxchgl %edx, (%ecx)
- jnz 1f
- mov $1, %eax
- ret
-1:
- mov 8(%esp), %edx
- mov %eax, (%edx)
- mov $0, %eax
+ xchgl %eax, (%ecx)
ret
-STUB(pthread__atomic_swap_ptr)
+STUB(pthread__atomic_or_ulong)
movl 4(%esp), %ecx
movl 8(%esp), %eax
- xchgl %eax, (%ecx)
+ lock
+ orl %eax, (%ecx)
ret
STUB(pthread__membar_full)
@@ -130,7 +121,7 @@ STUB(pthread__membar_full)
STUB(pthread__membar_producer)
/* A store is enough */
- movl $0, -4(%esp)
+ addl $0, -4(%esp)
ret
STUB(pthread__membar_consumer)
diff --git a/lib/libpthread/arch/i386/pthread_md.c b/lib/libpthread/arch/i386/pthread_md.c
index 0584a3b9b24..7dfabf2e0de 100644
--- a/lib/libpthread/arch/i386/pthread_md.c
+++ b/lib/libpthread/arch/i386/pthread_md.c
@@ -1,4 +1,4 @@
-/* $NetBSD: pthread_md.c,v 1.3 2003/03/08 08:03:37 lukem Exp $ */
+/* $NetBSD: pthread_md.c,v 1.4 2007/11/13 17:20:09 ad Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -37,10 +37,12 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: pthread_md.c,v 1.3 2003/03/08 08:03:37 lukem Exp $");
+__RCSID("$NetBSD: pthread_md.c,v 1.4 2007/11/13 17:20:09 ad Exp $");
#include <sys/param.h>
#include <sys/sysctl.h>
+
+#include <machine/sysarch.h>
#include <machine/cpu.h>
#include "pthread.h"
@@ -54,7 +56,8 @@ int (*_md_swapcontext_u)(ucontext_t *, const ucontext_t *);
* Initialize the function pointers for get/setcontext to the
* old-fp-save (s87) or new-fxsave (xmm) FP routines.
*/
-void pthread__i386_init(void)
+void
+pthread__i386_init(void)
{
int mib[2];
size_t len;
@@ -77,3 +80,10 @@ void pthread__i386_init(void)
}
}
+
+void
+pthread__threadreg_set(pthread_t self)
+{
+
+ sysarch(I386_SET_GSBASE, &self);
+}
diff --git a/lib/libpthread/arch/i386/pthread_md.h b/lib/libpthread/arch/i386/pthread_md.h
index e22fdc0c3de..c99ae7f412e 100644
--- a/lib/libpthread/arch/i386/pthread_md.h
+++ b/lib/libpthread/arch/i386/pthread_md.h
@@ -1,4 +1,4 @@
-/* $NetBSD: pthread_md.h,v 1.10 2007/09/24 12:19:40 skrll Exp $ */
+/* $NetBSD: pthread_md.h,v 1.11 2007/11/13 17:20:10 ad Exp $ */
/*-
* Copyright (c) 2001, 2007 The NetBSD Foundation, Inc.
@@ -183,5 +183,46 @@ pthread__sp(void)
#define pthread__smt_pause() __asm __volatile("rep; nop" ::: "memory")
#define PTHREAD__HAVE_ATOMIC
+/* #define PTHREAD__HAVE_THREADREG */
+
+void pthread__threadreg_set(pthread_t);
+
+static inline pthread_t
+pthread__threadreg_get(void)
+{
+ pthread_t self;
+
+ __asm volatile("movl %%gs:0, %0"
+ : "=r" (self)
+ :);
+
+ return self;
+}
+
+static inline void *
+pthread__atomic_cas_ptr(volatile void *ptr, const void *old, const void *new)
+{
+ volatile uintptr_t *cast = ptr;
+ void *ret;
+
+ __asm __volatile ("lock; cmpxchgl %2, %1"
+ : "=a" (ret), "=m" (*cast)
+ : "r" (new), "m" (*cast), "0" (old));
+
+ return ret;
+}
+
+static inline void *
+pthread__atomic_cas_ptr_ni(volatile void *ptr, const void *old, const void *new)
+{
+ volatile uintptr_t *cast = ptr;
+ void *ret;
+
+ __asm __volatile ("cmpxchgl %2, %1"
+ : "=a" (ret), "=m" (*cast)
+ : "r" (new), "m" (*cast), "0" (old));
+
+ return ret;
+}
#endif /* _LIB_PTHREAD_I386_MD_H */
diff --git a/lib/libpthread/arch/x86_64/_context_u.S b/lib/libpthread/arch/x86_64/_context_u.S
index cdb5c4a502c..8719b4fff5e 100644
--- a/lib/libpthread/arch/x86_64/_context_u.S
+++ b/lib/libpthread/arch/x86_64/_context_u.S
@@ -1,4 +1,4 @@
-/* $NetBSD: _context_u.S,v 1.8 2007/11/13 15:57:14 ad Exp $ */
+/* $NetBSD: _context_u.S,v 1.9 2007/11/13 17:20:10 ad Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -138,23 +138,17 @@ STUB(_swapcontext_u)
movq %rsi, %rdi
SETC
-STUB(pthread__atomic_cas_ptr)
- movq (%rsi), %rax
- lock
- cmpxchgq %rdx, (%rdi)
- jnz 1f
- movq $1, %rax
- ret
-1:
- movq %rax, (%rsi)
- movq $0, %rax
- ret
-
STUB(pthread__atomic_swap_ptr)
movq %rsi, %rax
+ lock
xchgq %rax, (%rdi)
ret
+STUB(pthread__atomic_or_ulong)
+ lock
+ orq %rsi, (%rdi)
+ ret
+
STUB(pthread__membar_full)
lock
addq $0, -8(%rsp)
diff --git a/lib/libpthread/arch/x86_64/pthread_md.h b/lib/libpthread/arch/x86_64/pthread_md.h
index a3a79b847d4..7f04edfd85a 100644
--- a/lib/libpthread/arch/x86_64/pthread_md.h
+++ b/lib/libpthread/arch/x86_64/pthread_md.h
@@ -1,4 +1,4 @@
-/* $NetBSD: pthread_md.h,v 1.6 2007/09/24 12:19:40 skrll Exp $ */
+/* $NetBSD: pthread_md.h,v 1.7 2007/11/13 17:20:10 ad Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -106,4 +106,30 @@ pthread__sp(void)
#define pthread__smt_pause() __asm __volatile("rep; nop" ::: "memory")
#define PTHREAD__HAVE_ATOMIC
+static inline void *
+pthread__atomic_cas_ptr(volatile void *ptr, const void *old, const void *new)
+{
+ volatile uintptr_t *cast = ptr;
+ void *ret;
+
+ __asm __volatile ("lock; cmpxchgq %2, %1"
+ : "=a" (ret), "=m" (*cast)
+ : "r" (new), "m" (*cast), "0" (old));
+
+ return ret;
+}
+
+static inline void *
+pthread__atomic_cas_ptr_ni(volatile void *ptr, const void *old, const void *new)
+{
+ volatile uintptr_t *cast = ptr;
+ void *ret;
+
+ __asm __volatile ("cmpxchgq %2, %1"
+ : "=a" (ret), "=m" (*cast)
+ : "r" (new), "m" (*cast), "0" (old));
+
+ return ret;
+}
+
#endif /* _LIB_PTHREAD_X86_64_MD_H */