Subject: Small usability tweak to ras
To: NetBSD Userlevel Technical Discussion List <tech-userlevel@netbsd.org>
From: Jason Thorpe <thorpej@wasabisystems.com>
List: tech-userlevel
Date: 03/02/2004 21:58:17
--Apple-Mail-12--945433922
Content-Type: multipart/mixed; boundary=Apple-Mail-11--945433930
--Apple-Mail-11--945433930
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
format=flowed
Hm, looks like I've had this sitting around in my tree for a couple of
months.
pthread and ras regression tests pass. Look OK? Anyone have any
objections?
-- Jason R. Thorpe <thorpej@wasabisystems.com>
--Apple-Mail-11--945433930
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
x-unix-mode=0644;
name="ras-patch.txt"
Content-Disposition: attachment;
filename=ras-patch.txt
Index: sys/sys/ras.h
===================================================================
RCS file: /cvsroot/src/sys/sys/ras.h,v
retrieving revision 1.2
diff -u -r1.2 ras.h
--- sys/sys/ras.h 28 Jun 2003 14:52:10 -0000 1.2
+++ sys/sys/ras.h 3 Mar 2004 05:55:14 -0000
@@ -1,7 +1,7 @@
/* $NetBSD: ras.h,v 1.2 2003/06/28 14:52:10 simonb Exp $ */
/*-
- * Copyright (c) 2002 The NetBSD Foundation, Inc.
+ * Copyright (c) 2002, 2004 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -67,6 +67,27 @@
#else
+#define RAS_DECL(name) \
+extern void __CONCAT(name,_ras_start(void)), __CONCAT(name,_ras_end(void))
+
+/*
+ * RAS_START and RAS_END contain implicit instruction reordering
+ * barriers. See __insn_barrier() in <sys/cdefs.h>.
+ */
+#define RAS_START(name) \
+ __asm __volatile(".globl " ___STRING(name) "_ras_start\n" \
+ ___STRING(name) "_ras_start:" \
+ ::: "memory")
+
+#define RAS_END(name) \
+ __asm __volatile(".globl " ___STRING(name) "_ras_end\n" \
+ ___STRING(name) "_ras_end:" \
+ ::: "memory")
+
+#define RAS_ADDR(name) (void *) __CONCAT(name,_ras_start)
+#define RAS_SIZE(name) ((size_t)((uintptr_t) __CONCAT(name,_ras_end) - \
+ (uintptr_t) __CONCAT(name,_ras_start)))
+
__BEGIN_DECLS
int rasctl(caddr_t, size_t, int);
__END_DECLS
Index: lib/libpthread/pthread_lock.c
===================================================================
RCS file: /cvsroot/src/lib/libpthread/pthread_lock.c,v
retrieving revision 1.9
diff -u -r1.9 pthread_lock.c
--- lib/libpthread/pthread_lock.c 13 Feb 2004 11:36:08 -0000 1.9
+++ lib/libpthread/pthread_lock.c 3 Mar 2004 05:55:14 -0000
@@ -60,7 +60,7 @@
static int nspins = NSPINS;
-extern void pthread__lock_ras_start(void), pthread__lock_ras_end(void);
+RAS_DECL(pthread__lock);
static void
pthread__ras_simple_lock_init(__cpu_simple_lock_t *alp)
@@ -74,13 +74,10 @@
{
__cpu_simple_lock_t old;
- /* This is the atomic sequence. */
- __asm __volatile(".globl pthread__lock_ras_start \n"
- "pthread__lock_ras_start:");
+ RAS_START(pthread__lock);
old = *alp;
*alp = __SIMPLELOCK_LOCKED;
- __asm __volatile(".globl pthread__lock_ras_end \n"
- "pthread__lock_ras_end:");
+ RAS_END(pthread__lock);
return (old == __SIMPLELOCK_UNLOCKED);
}
@@ -151,10 +148,8 @@
len = sizeof(ncpu);
sysctl(mib, 2, &ncpu, &len, NULL, 0);
- if (ncpu == 1 && rasctl((void *)pthread__lock_ras_start,
- (size_t)((uintptr_t)pthread__lock_ras_end -
- (uintptr_t)pthread__lock_ras_start),
- RAS_INSTALL) == 0) {
+ if (ncpu == 1 && rasctl(RAS_ADDR(pthread__lock),
+ RAS_SIZE(pthread__lock), RAS_INSTALL) == 0) {
pthread__lock_ops = &pthread__lock_ops_ras;
return;
}
Index: regress/sys/kern/ras/ras1/ras1.c
===================================================================
RCS file: /cvsroot/src/regress/sys/kern/ras/ras1/ras1.c,v
retrieving revision 1.5
diff -u -r1.5 ras1.c
--- regress/sys/kern/ras/ras1/ras1.c 18 Jan 2004 16:47:06 -0000 1.5
+++ regress/sys/kern/ras/ras1/ras1.c 3 Mar 2004 05:55:14 -0000
@@ -34,6 +34,7 @@
*/
#include <errno.h>
+#include <inttypes.h>
#include <stdio.h>
#include <signal.h>
#include <sys/ras.h>
@@ -54,6 +55,8 @@
handled++;
}
+RAS_DECL(main);
+
int
main(void)
{
@@ -66,8 +69,7 @@
itv.it_value.tv_usec = 0;
setitimer(ITIMER_VIRTUAL, &itv, NULL);
- if (rasctl((caddr_t)&&start, (caddr_t)&&end - (caddr_t)&&start,
- RAS_INSTALL) < 0) {
+ if (rasctl(RAS_ADDR(main), RAS_SIZE(main), RAS_INSTALL) < 0) {
if (errno == EOPNOTSUPP) {
printf("RAS is not supported on this architecture\n");
return 0;
@@ -75,8 +77,7 @@
return (1);
}
- __insn_barrier();
-start:
+ RAS_START(main);
count++;
if (count > COUNT)
goto end;
@@ -84,8 +85,8 @@
while (!handled) {
continue;
}
-end:
- __insn_barrier();
+ end:
+ RAS_END(main);
return (handled != 0);
}
Index: regress/sys/kern/ras/ras2/ras2.c
===================================================================
RCS file: /cvsroot/src/regress/sys/kern/ras/ras2/ras2.c,v
retrieving revision 1.5
diff -u -r1.5 ras2.c
--- regress/sys/kern/ras/ras2/ras2.c 18 Jan 2004 16:47:06 -0000 1.5
+++ regress/sys/kern/ras/ras2/ras2.c 3 Mar 2004 05:55:14 -0000
@@ -34,6 +34,7 @@
*/
#include <errno.h>
+#include <inttypes.h>
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
@@ -56,6 +57,8 @@
handled++;
}
+RAS_DECL(main);
+
int
main(void)
{
@@ -69,8 +72,7 @@
itv.it_value.tv_usec = 0;
setitimer(ITIMER_VIRTUAL, &itv, NULL);
- if (rasctl((caddr_t)&&start, (caddr_t)&&end - (caddr_t)&&start,
- RAS_INSTALL) < 0) {
+ if (rasctl(RAS_ADDR(main), RAS_SIZE(main), RAS_INSTALL) < 0) {
if (errno == EOPNOTSUPP) {
printf("RAS is not supported on this architecture\n");
return 0;
@@ -83,8 +85,7 @@
return (rv);
}
- __insn_barrier();
-start:
+ RAS_START(main);
count++;
if (count > COUNT)
goto end;
@@ -93,7 +94,7 @@
continue;
}
end:
- __insn_barrier();
+ RAS_END(main);
return (handled != 0);
}
Index: regress/sys/kern/ras/ras3/ras3.c
===================================================================
RCS file: /cvsroot/src/regress/sys/kern/ras/ras3/ras3.c,v
retrieving revision 1.5
diff -u -r1.5 ras3.c
--- regress/sys/kern/ras/ras3/ras3.c 18 Jan 2004 16:47:06 -0000 1.5
+++ regress/sys/kern/ras/ras3/ras3.c 3 Mar 2004 05:55:14 -0000
@@ -34,6 +34,7 @@
*/
#include <errno.h>
+#include <inttypes.h>
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
@@ -56,6 +57,8 @@
handled++;
}
+RAS_DECL(main);
+
int
main(int argc, char *argv[])
{
@@ -71,8 +74,7 @@
setitimer(ITIMER_VIRTUAL, &itv, NULL);
if (argc != 2) {
- if (rasctl((caddr_t)&&start, (caddr_t)&&end - (caddr_t)&&start,
- RAS_INSTALL) < 0) {
+ if (rasctl(RAS_ADDR(main), RAS_SIZE(main), RAS_INSTALL) < 0) {
if (errno == EOPNOTSUPP) {
printf("RAS is not supported on this "
"architecture\n");
@@ -90,8 +92,7 @@
}
}
- __insn_barrier();
-start:
+ RAS_START(main);
count++;
if (count > COUNT)
goto end;
@@ -100,7 +101,7 @@
continue;
}
end:
- __insn_barrier();
+ RAS_END(main);
return (handled != 0);
}
--Apple-Mail-11--945433930--
--Apple-Mail-12--945433922
content-type: application/pgp-signature; x-mac-type=70674453;
name=PGP.sig
content-description: This is a digitally signed message part
content-disposition: inline; filename=PGP.sig
content-transfer-encoding: 7bit
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (Darwin)
iD8DBQFARXP6OpVKkaBm8XkRAsj9AJ4hWs5Fp7EmEr2XjY/TBxeCRQiLUwCeMYIw
7Zx11rosPNhSetESwJyW450=
=u/5r
-----END PGP SIGNATURE-----
--Apple-Mail-12--945433922--