Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 29 Apr 2002 19:29:35 -0700 (PDT)
From:      Jake Burkholder <jake@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 10498 for review
Message-ID:  <200204300229.g3U2TZJ70152@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://people.freebsd.org/~peter/p4db/chv.cgi?CH=10498

Change 10498 by jake@jake_sparc64 on 2002/04/29 19:29:16

	I'm tired of seeing these changes.

Affected files ...

... //depot/projects/sparc64/libexec/rtld-elf/alpha/lockdflt.c#5 edit
... //depot/projects/sparc64/libexec/rtld-elf/alpha/rtld_machdep.h#4 edit
... //depot/projects/sparc64/libexec/rtld-elf/alpha/rtld_start.S#4 edit
... //depot/projects/sparc64/libexec/rtld-elf/i386/lockdflt.c#5 edit
... //depot/projects/sparc64/libexec/rtld-elf/i386/rtld_machdep.h#3 edit
... //depot/projects/sparc64/libexec/rtld-elf/ia64/lockdflt.c#5 edit
... //depot/projects/sparc64/libexec/rtld-elf/ia64/rtld_machdep.h#3 edit
... //depot/projects/sparc64/libexec/rtld-elf/ia64/rtld_start.S#3 edit

Differences ...

==== //depot/projects/sparc64/libexec/rtld-elf/alpha/lockdflt.c#5 (text+ko) ====

@@ -50,8 +50,6 @@
 #include <stdlib.h>
 #include <time.h>
 
-#include <machine/atomic.h>
-
 #include "debug.h"
 #include "rtld.h"
 
@@ -118,7 +116,7 @@
 {
     Lock *l = (Lock *)lock;
 
-    atomic_add_acq_int(&l->lock, RC_INCR);
+    atomic_add_int(&l->lock, RC_INCR);
     while (l->lock & WAFLAG)
 	    nanosleep(&usec, NULL);
 }
@@ -131,7 +129,7 @@
 
     for ( ; ; ) {
 	sigprocmask(SIG_BLOCK, &fullsigmask, &tmp_oldsigmask);
-	if (atomic_cmpset_acq_int(&l->lock, 0, WAFLAG))
+	if (cmp0_and_store_int(&l->lock, WAFLAG) == 0)
 	    break;
 	sigprocmask(SIG_SETMASK, &tmp_oldsigmask, NULL);
 	nanosleep(&usec, NULL);
@@ -144,7 +142,7 @@
 {
     Lock *l = (Lock *)lock;
 
-    atomic_add_rel_int(&l->lock, -RC_INCR);
+    atomic_add_int(&l->lock, -RC_INCR);
 }
 
 static void
@@ -152,7 +150,7 @@
 {
     Lock *l = (Lock *)lock;
 
-    atomic_add_rel_int(&l->lock, -WAFLAG);
+    atomic_add_int(&l->lock, -WAFLAG);
     sigprocmask(SIG_SETMASK, &oldsigmask, NULL);
 }
 

==== //depot/projects/sparc64/libexec/rtld-elf/alpha/rtld_machdep.h#4 (text+ko) ====

@@ -46,4 +46,10 @@
 /* Lazy binding entry point, called via PLT. */
 void _rtld_bind_start_old(void);
 
+/* Atomic operations. */
+int cmp0_and_store_int(volatile int *, int);
+void atomic_add_int(volatile int *, int);
+void atomic_incr_int(volatile int *);
+void atomic_decr_int(volatile int *);
+
 #endif

==== //depot/projects/sparc64/libexec/rtld-elf/alpha/rtld_start.S#4 (text+ko) ====

@@ -208,3 +208,53 @@
 	RTLD_BIND_START_EPILOGUE
 
 END(_rtld_bind_start_old)
+
+/*
+ * int cmp0_and_store_int(volatile int *p, int newval);
+ *
+ * If an int holds 0, store newval into it; else do nothing.  Returns
+ * the previous value.
+ */
+LEAF(cmp0_and_store_int, 2)
+1:	mov	a1, t0
+	ldl_l	v0, 0(a0)
+	bne	v0, 3f
+	stl_c	t0, 0(a0)
+	beq	t0, 2f
+	mb
+	RET
+2:	br	1b
+3:	RET
+END(cmp0_and_store_int)
+
+LEAF(atomic_add_int, 2)
+0:	ldl_l	t0, 0(a0)
+	addq	t0, a1, t0
+	stl_c	t0, 0(a0)
+	beq	t0, 1f
+	mb
+	RET
+1:	br	0b
+END(atomic_add_int)
+ 
+/* Atomically increment an int. */
+LEAF(atomic_incr_int, 1)
+0:	ldl_l	t0, 0(a0)
+	addq	t0, 1, t0
+	stl_c	t0, 0(a0)
+	beq	t0, 1f
+	mb
+	RET
+1:	br	0b
+END(atomic_incr_int)
+
+/* Atomically decrement an int. */
+LEAF(atomic_decr_int, 1)
+0:	ldl_l	t0, 0(a0)
+	subq	t0, 1, t0
+	stl_c	t0, 0(a0)
+	beq	t0, 1f
+	mb
+	RET
+1:	br	0b
+END(atomic_decr_int)

==== //depot/projects/sparc64/libexec/rtld-elf/i386/lockdflt.c#5 (text+ko) ====

@@ -58,8 +58,6 @@
 #include <stdlib.h>
 #include <time.h>
 
-#include <machine/atomic.h>
-
 #include "debug.h"
 #include "rtld.h"
 
@@ -77,6 +75,19 @@
 static sigset_t fullsigmask, oldsigmask;
 
 static inline int
+cmpxchgl(int old, int new, volatile int *m)
+{
+	int result;
+
+	__asm __volatile ("lock; cmpxchgl %2, %0"
+	    : "=m"(*m), "=a"(result)
+	    : "r"(new), "0"(*m), "1"(old)
+	    : "cc");
+
+	return result;
+}
+
+static inline int
 xchgl(int v, volatile int *m)
 {
 	int result;
@@ -164,7 +175,7 @@
 {
     Lock *l = (Lock *)lock;
 
-    atomic_add_acq_int(&l->lock, RC_INCR);
+    atomic_add_int(&l->lock, RC_INCR);
     while (l->lock & WAFLAG)
 	    nanosleep(&usec, NULL);
 }
@@ -177,7 +188,7 @@
 
     for ( ; ; ) {
 	sigprocmask(SIG_BLOCK, &fullsigmask, &tmp_oldsigmask);
-	if (atomic_cmpset_acq_int(&l->lock, 0, WAFLAG))
+	if (cmpxchgl(0, WAFLAG, &l->lock) == 0)
 	    break;
 	sigprocmask(SIG_SETMASK, &tmp_oldsigmask, NULL);
 	nanosleep(&usec, NULL);
@@ -190,7 +201,7 @@
 {
     Lock *l = (Lock *)lock;
 
-    atomic_add_rel_int(&l->lock, -RC_INCR);
+    atomic_add_int(&l->lock, -RC_INCR);
 }
 
 static void
@@ -198,7 +209,7 @@
 {
     Lock *l = (Lock *)lock;
 
-    atomic_add_rel_int(&l->lock, -WAFLAG);
+    atomic_add_int(&l->lock, -WAFLAG);
     sigprocmask(SIG_SETMASK, &oldsigmask, NULL);
 }
 
@@ -230,7 +241,7 @@
     sigaction(SIGILL, &act, &oact);
     if (setjmp(sigill_env) == 0) {
 	lock = 0;
-	atomic_cmpset_int(&lock, 0, 1);
+	cmpxchgl(0, 1, &lock);
 	result = 1;
     } else
 	result = 0;

==== //depot/projects/sparc64/libexec/rtld-elf/i386/rtld_machdep.h#3 (text+ko) ====

@@ -52,4 +52,25 @@
 #define call_initfini_pointer(obj, target) \
 	(((InitFunc)(target))())
 
+static inline void
+atomic_decr_int(volatile int *p)
+{
+    __asm __volatile ("lock; decl %0" : "=m"(*p) : "0"(*p) : "cc");
+}
+
+static inline void
+atomic_incr_int(volatile int *p)
+{
+    __asm __volatile ("lock; incl %0" : "=m"(*p) : "0"(*p) : "cc");
+}
+
+static inline void
+atomic_add_int(volatile int *p, int val)
+{
+    __asm __volatile ("lock; addl %1, %0"
+	: "=m"(*p)
+	: "ri"(val), "0"(*p)
+	: "cc");
+}
+
 #endif

==== //depot/projects/sparc64/libexec/rtld-elf/ia64/lockdflt.c#5 (text+ko) ====

@@ -50,8 +50,6 @@
 #include <stdlib.h>
 #include <time.h>
 
-#include <machine/atomic.h>
-
 #include "debug.h"
 #include "rtld.h"
 
@@ -118,7 +116,7 @@
 {
     Lock *l = (Lock *)lock;
 
-    atomic_add_acq_int(&l->lock, RC_INCR);
+    atomic_add_int(&l->lock, RC_INCR);
     while (l->lock & WAFLAG)
 	    nanosleep(&usec, NULL);
 }
@@ -131,7 +129,7 @@
 
     for ( ; ; ) {
 	sigprocmask(SIG_BLOCK, &fullsigmask, &tmp_oldsigmask);
-	if (atomic_cmpset_acq_int(&l->lock, 0, WAFLAG))
+	if (cmp0_and_store_int(&l->lock, WAFLAG) == 0)
 	    break;
 	sigprocmask(SIG_SETMASK, &tmp_oldsigmask, NULL);
 	nanosleep(&usec, NULL);
@@ -144,7 +142,7 @@
 {
     Lock *l = (Lock *)lock;
 
-    atomic_add_rel_int(&l->lock, -RC_INCR);
+    atomic_add_int(&l->lock, -RC_INCR);
 }
 
 static void
@@ -152,7 +150,7 @@
 {
     Lock *l = (Lock *)lock;
 
-    atomic_add_rel_int(&l->lock, -WAFLAG);
+    atomic_add_int(&l->lock, -WAFLAG);
     sigprocmask(SIG_SETMASK, &oldsigmask, NULL);
 }
 

==== //depot/projects/sparc64/libexec/rtld-elf/ia64/rtld_machdep.h#3 (text+ko) ====

@@ -49,4 +49,10 @@
 void *make_function_pointer(const Elf_Sym *, const struct Struct_Obj_Entry *);
 void call_initfini_pointer(const struct Struct_Obj_Entry *, Elf_Addr);
 
+/* Atomic operations. */
+int cmp0_and_store_int(volatile int *, int);
+void atomic_add_int(volatile int *, int);
+void atomic_incr_int(volatile int *);
+void atomic_decr_int(volatile int *);
+
 #endif

==== //depot/projects/sparc64/libexec/rtld-elf/ia64/rtld_start.S#3 (text+ko) ====

@@ -157,6 +157,60 @@
 }
 END(_rtld_bind_start)
 
+/*
+ * int cmp0_and_store_int(volatile int *p, int newval);
+ *
+ * If an int holds 0, store newval into it; else do nothing.  Returns
+ * the previous value.
+ */
+ENTRY(cmp0_and_store_int, 2)
+	mov	ar.ccv=0
+	;;
+	cmpxchg4.acq r8=[in0],in1,ar.ccv
+	br.ret.sptk.many rp
+END(cmp0_and_store_int)
+
+ENTRY(atomic_add_int, 2)
+1:	ld4	r14=[in0]
+	;;
+	mov	ar.ccv=r14
+	add	r15=in1,r14
+	;;
+	cmpxchg4.acq r16=[in0],r15,ar.ccv
+	;;
+	cmp.ne	p6,p0=r14,r16
+(p6)	br.cond.spnt.few 1b
+	br.ret.sptk.many rp
+END(atomic_add_int)
+ 
+/* Atomically increment an int. */
+ENTRY(atomic_incr_int, 1)
+1:	ld4	r14=[in0]
+	;;
+	mov	ar.ccv=r14
+	add	r15=1,r14
+	;;
+	cmpxchg4.acq r16=[in0],r15,ar.ccv
+	;;
+	cmp.ne	p6,p0=r14,r16
+(p6)	br.cond.spnt.few 1b
+	br.ret.sptk.many rp
+END(atomic_incr_int)
+
+/* Atomically decrement an int. */
+ENTRY(atomic_decr_int, 1)
+1:	ld4	r14=[in0]
+	;;
+	mov	ar.ccv=r14
+	add	r15=-1,r14
+	;;
+	cmpxchg4.acq r16=[in0],r15,ar.ccv
+	;;
+	cmp.ne	p6,p0=r14,r16
+(p6)	br.cond.spnt.few 1b
+	br.ret.sptk.many rp
+END(atomic_decr_int)
+
 #define DT_NULL		0	/* Terminating entry. */
 #define DT_RELA		7	/* Address of ElfNN_Rela relocations. */
 #define DT_RELASZ	8	/* Total size of ElfNN_Rela relocations. */

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe p4-projects" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200204300229.g3U2TZJ70152>