Module Name: src
Committed By: matt
Date: Thu Aug 16 04:49:48 UTC 2012
Modified Files:
src/lib/libpthread: pthread_int.h pthread_mutex.c pthread_spin.c
src/lib/libpthread/arch/arm: pthread_md.h
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 src/lib/libpthread/pthread_int.h
cvs rdiff -u -r1.53 -r1.54 src/lib/libpthread/pthread_mutex.c
cvs rdiff -u -r1.5 -r1.6 src/lib/libpthread/pthread_spin.c
cvs rdiff -u -r1.6 -r1.7 src/lib/libpthread/arch/arm/pthread_md.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/libpthread/pthread_int.h
diff -u src/lib/libpthread/pthread_int.h:1.85 src/lib/libpthread/pthread_int.h:1.86
--- src/lib/libpthread/pthread_int.h:1.85 Fri May 4 12:26:33 2012
+++ src/lib/libpthread/pthread_int.h Thu Aug 16 04:49:47 2012
@@ -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
Index: src/lib/libpthread/pthread_mutex.c
diff -u src/lib/libpthread/pthread_mutex.c:1.53 src/lib/libpthread/pthread_mutex.c:1.54
--- src/lib/libpthread/pthread_mutex.c:1.53 Tue Mar 13 01:05:55 2012
+++ src/lib/libpthread/pthread_mutex.c Thu Aug 16 04:49:47 2012
@@ -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 *pt
#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, pt
* are dependent upon 'thread'.
*/
thread = atomic_swap_ptr(&ptm->ptm_waiters, NULL);
+ pthread__smt_wake();
for (;;) {
/*
Index: src/lib/libpthread/pthread_spin.c
diff -u src/lib/libpthread/pthread_spin.c:1.5 src/lib/libpthread/pthread_spin.c:1.6
--- src/lib/libpthread/pthread_spin.c:1.5 Mon Apr 28 20:23:01 2008
+++ src/lib/libpthread/pthread_spin.c Thu Aug 16 04:49:47 2012
@@ -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 *
self = pthread__self();
pthread__spinunlock(self, &lock->pts_spin);
+ pthread__smt_wake();
return 0;
}
Index: src/lib/libpthread/arch/arm/pthread_md.h
diff -u src/lib/libpthread/arch/arm/pthread_md.h:1.6 src/lib/libpthread/arch/arm/pthread_md.h:1.7
--- src/lib/libpthread/arch/arm/pthread_md.h:1.6 Tue Jan 25 19:12:04 2011
+++ src/lib/libpthread/arch/arm/pthread_md.h Thu Aug 16 04:49:48 2012
@@ -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])
/*