From owner-p4-projects@FreeBSD.ORG Thu Jul 29 18:08:06 2004 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 7F6DC16A4D0; Thu, 29 Jul 2004 18:08:06 +0000 (GMT) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4F4E416A4CF for ; Thu, 29 Jul 2004 18:08:06 +0000 (GMT) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2C92A43D49 for ; Thu, 29 Jul 2004 18:08:06 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.12.11/8.12.11) with ESMTP id i6TI82Ea049594 for ; Thu, 29 Jul 2004 18:08:02 GMT (envelope-from jhb@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.12.11/8.12.11/Submit) id i6TI82sM049591 for perforce@freebsd.org; Thu, 29 Jul 2004 18:08:02 GMT (envelope-from jhb@freebsd.org) Date: Thu, 29 Jul 2004 18:08:02 GMT Message-Id: <200407291808.i6TI82sM049591@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to jhb@freebsd.org using -f From: John Baldwin To: Perforce Change Reviews Subject: PERFORCE change 58472 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Jul 2004 18:08:07 -0000 http://perforce.freebsd.org/chv.cgi?CH=58472 Change 58472 by jhb@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