summaryrefslogtreecommitdiff
path: root/lib/libpthread
diff options
context:
space:
mode:
authormatt <matt@NetBSD.org>2012-08-16 04:49:47 +0000
committermatt <matt@NetBSD.org>2012-08-16 04:49:47 +0000
commit6a3069e1c50fa610f804db3be271aa4ae210b024 (patch)
tree4fa288126e23a6b3717c3badfef8f9e5d11c61c4 /lib/libpthread
parentf54a3f5e69cc66993e101f08febc3fd40e22324d (diff)
Add a pthread__smt_wake and add support for it on arm along with
pthread__smt_pause. These are implemented using the ARM instructions SEV (wake) and WFE (pause). These are treated as NOPs on ARM CPUs that don't support them.
Diffstat (limited to 'lib/libpthread')
-rw-r--r--lib/libpthread/arch/arm/pthread_md.h5
-rw-r--r--lib/libpthread/pthread_int.h5
-rw-r--r--lib/libpthread/pthread_mutex.c9
-rw-r--r--lib/libpthread/pthread_spin.c5
4 files changed, 17 insertions, 7 deletions
diff --git a/lib/libpthread/arch/arm/pthread_md.h b/lib/libpthread/arch/arm/pthread_md.h
index 58f757cfa72..e6082e5e8c0 100644
--- a/lib/libpthread/arch/arm/pthread_md.h
+++ b/lib/libpthread/arch/arm/pthread_md.h
@@ -1,4 +1,4 @@
-/* $NetBSD: pthread_md.h,v 1.6 2011/01/25 19:12:04 christos Exp $ */
+/* $NetBSD: pthread_md.h,v 1.7 2012/08/16 04:49:48 matt Exp $ */
/*
* Copyright (c) 2001 Wasabi Systems, Inc.
@@ -49,6 +49,9 @@ pthread__sp(void)
return (ret);
}
+#define pthread__smt_pause() __asm __volatile("wfe")
+#define pthread__smt_wake() __asm __volatile("sev")
+
#define pthread__uc_sp(ucp) ((ucp)->uc_mcontext.__gregs[_REG_SP])
/*
diff --git a/lib/libpthread/pthread_int.h b/lib/libpthread/pthread_int.h
index 1158b90dc42..4e6364a2418 100644
--- a/lib/libpthread/pthread_int.h
+++ b/lib/libpthread/pthread_int.h
@@ -1,4 +1,4 @@
-/* $NetBSD: pthread_int.h,v 1.85 2012/05/04 12:26:33 joerg Exp $ */
+/* $NetBSD: pthread_int.h,v 1.86 2012/08/16 04:49:47 matt Exp $ */
/*-
* Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -299,6 +299,9 @@ int pthread__checkpri(int) PTHREAD_HIDE;
#ifndef pthread__smt_pause
#define pthread__smt_pause() /* nothing */
#endif
+#ifndef pthread__smt_wake
+#define pthread__smt_wake() /* nothing */
+#endif
/*
* Bits in the owner field of the lock that indicate lock state. If the
diff --git a/lib/libpthread/pthread_mutex.c b/lib/libpthread/pthread_mutex.c
index 110e98fa496..6b2c8d83873 100644
--- a/lib/libpthread/pthread_mutex.c
+++ b/lib/libpthread/pthread_mutex.c
@@ -1,4 +1,4 @@
-/* $NetBSD: pthread_mutex.c,v 1.53 2012/03/13 01:05:55 joerg Exp $ */
+/* $NetBSD: pthread_mutex.c,v 1.54 2012/08/16 04:49:47 matt Exp $ */
/*-
* Copyright (c) 2001, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -47,7 +47,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: pthread_mutex.c,v 1.53 2012/03/13 01:05:55 joerg Exp $");
+__RCSID("$NetBSD: pthread_mutex.c,v 1.54 2012/08/16 04:49:47 matt Exp $");
#include <sys/types.h>
#include <sys/lwpctl.h>
@@ -379,8 +379,10 @@ pthread_mutex_unlock(pthread_mutex_t *ptm)
#endif
self = pthread__self();
value = atomic_cas_ptr_ni(&ptm->ptm_owner, self, NULL);
- if (__predict_true(value == self))
+ if (__predict_true(value == self)) {
+ pthread__smt_wake();
return 0;
+ }
return pthread__mutex_unlock_slow(ptm);
}
@@ -475,6 +477,7 @@ pthread__mutex_wakeup(pthread_t self, pthread_mutex_t *ptm)
* are dependent upon 'thread'.
*/
thread = atomic_swap_ptr(&ptm->ptm_waiters, NULL);
+ pthread__smt_wake();
for (;;) {
/*
diff --git a/lib/libpthread/pthread_spin.c b/lib/libpthread/pthread_spin.c
index 910a94548b4..01738d73c5b 100644
--- a/lib/libpthread/pthread_spin.c
+++ b/lib/libpthread/pthread_spin.c
@@ -1,4 +1,4 @@
-/* $NetBSD: pthread_spin.c,v 1.5 2008/04/28 20:23:01 martin Exp $ */
+/* $NetBSD: pthread_spin.c,v 1.6 2012/08/16 04:49:47 matt Exp $ */
/*-
* Copyright (c) 2001, 2006, 2007 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: pthread_spin.c,v 1.5 2008/04/28 20:23:01 martin Exp $");
+__RCSID("$NetBSD: pthread_spin.c,v 1.6 2012/08/16 04:49:47 matt Exp $");
#include <sys/types.h>
#include <sys/ras.h>
@@ -133,6 +133,7 @@ pthread_spin_unlock(pthread_spinlock_t *lock)
self = pthread__self();
pthread__spinunlock(self, &lock->pts_spin);
+ pthread__smt_wake();
return 0;
}