PERFORCE change 58472 for review

John Baldwin jhb at FreeBSD.org
Thu Jul 29 11:08:07 PDT 2004


http://perforce.freebsd.org/chv.cgi?CH=58472

Change 58472 by jhb at jhb_slimer on 2004/07/29 18:07:13

	Simplifiy the store_rel() optimization by just writing it in C
	like the 80386 case.  Also, adjust the comment above as far as
	PentiumPro + vs. 80386.

Affected files ...

.. //depot/projects/smpng/sys/i386/include/atomic.h#14 edit

Differences ...

==== //depot/projects/smpng/sys/i386/include/atomic.h#14 (text+ko) ====

@@ -69,7 +69,7 @@
 
 int atomic_cmpset_int(volatile u_int *dst, u_int exp, u_int src);
 
-#define	ATOMIC_STORE_LOAD(TYPE, LOP, SOP)			\
+#define	ATOMIC_STORE_LOAD(TYPE, LOP)			\
 u_##TYPE	atomic_load_acq_##TYPE(volatile u_##TYPE *p);	\
 void		atomic_store_rel_##TYPE(volatile u_##TYPE *p, u_##TYPE v)
 
@@ -175,12 +175,12 @@
 #if defined(I386_CPU)
 
 /*
- * We assume that a = b will do atomic loads and stores.
- *
- * XXX: This is _NOT_ safe on a P6 or higher because it does not guarantee
- * memory ordering.  These should only be used on a 386.
+ * We assume that a = b will do atomic loads and stores.  However, on a
+ * PentiumPro or higher reads may pass writes, so for that case we have
+ * to use a serializing instruction (i.e. with LOCK) to do the load.  For
+ * the 386 case, we can use a simple store since 386's don't support SMP.
  */
-#define ATOMIC_STORE_LOAD(TYPE, LOP, SOP, SCONS)	\
+#define ATOMIC_STORE_LOAD(TYPE, LOP)			\
 static __inline u_##TYPE				\
 atomic_load_acq_##TYPE(volatile u_##TYPE *p)		\
 {							\
@@ -197,7 +197,7 @@
 
 #else /* !defined(I386_CPU) */
 
-#define ATOMIC_STORE_LOAD(TYPE, LOP, SOP, SCONS)	\
+#define ATOMIC_STORE_LOAD(TYPE, LOP)			\
 static __inline u_##TYPE				\
 atomic_load_acq_##TYPE(volatile u_##TYPE *p)		\
 {							\
@@ -214,10 +214,8 @@
 static __inline void					\
 atomic_store_rel_##TYPE(volatile u_##TYPE *p, u_##TYPE v)\
 {							\
-	__asm __volatile(SOP				\
-	: "=m" (*p),			/* 0 */		\
-	: SCONS (v)			/* 1 */		\
-	: "memory");				 	\
+	*p = v;						\
+	__asm __volatile("" : : : "memory");		\
 }							\
 struct __hack
 
@@ -227,7 +225,7 @@
 
 extern int atomic_cmpset_int(volatile u_int *, u_int, u_int);
 
-#define ATOMIC_STORE_LOAD(TYPE, LOP, SOP, SCONS)			\
+#define ATOMIC_STORE_LOAD(TYPE, LOP)					\
 extern u_##TYPE atomic_load_acq_##TYPE(volatile u_##TYPE *p);		\
 extern void atomic_store_rel_##TYPE(volatile u_##TYPE *p, u_##TYPE v)
 
@@ -255,10 +253,10 @@
 ATOMIC_ASM(add,	     long,  "addl %1,%0",  "ir",  v);
 ATOMIC_ASM(subtract, long,  "subl %1,%0",  "ir",  v);
 
-ATOMIC_STORE_LOAD(char,	"cmpxchgb %b0,%1", "movb %b1,%0", "iq");
-ATOMIC_STORE_LOAD(short,"cmpxchgw %w0,%1", "movw %w1,%0", "ir");
-ATOMIC_STORE_LOAD(int,	"cmpxchgl %0,%1",  "movl %1,%0", "ir");
-ATOMIC_STORE_LOAD(long,	"cmpxchgl %0,%1",  "movl %1,%0", "ir");
+ATOMIC_STORE_LOAD(char,	"cmpxchgb %b0,%1");
+ATOMIC_STORE_LOAD(short,"cmpxchgw %w0,%1");
+ATOMIC_STORE_LOAD(int,	"cmpxchgl %0,%1");
+ATOMIC_STORE_LOAD(long,	"cmpxchgl %0,%1");
 
 #undef ATOMIC_ASM
 #undef ATOMIC_STORE_LOAD


More information about the p4-projects mailing list