From owner-freebsd-alpha Fri Dec 15 14:22:15 2000 From owner-freebsd-alpha@FreeBSD.ORG Fri Dec 15 14:22:13 2000 Return-Path: Delivered-To: freebsd-alpha@freebsd.org Received: from front4m.grolier.fr (front4m.grolier.fr [195.36.216.54]) by hub.freebsd.org (Postfix) with ESMTP id 0376637B400; Fri, 15 Dec 2000 14:22:12 -0800 (PST) Received: from nas1-109.cgy.club-internet.fr (nas1-109.cgy.club-internet.fr [195.36.197.109]) by front4m.grolier.fr (8.9.3/No_Relay+No_Spam_MGC990224) with ESMTP id XAA00177; Fri, 15 Dec 2000 23:19:49 +0100 (MET) Date: Fri, 15 Dec 2000 22:22:00 +0100 (CET) From: =?ISO-8859-1?Q?G=E9rard_Roudier?= X-Sender: groudier@linux.local To: John Baldwin Cc: Bernd Walter , freebsd-alpha@FreeBSD.ORG Subject: RE: mb and wmb in atomic_ In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=ISO-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE Sender: owner-freebsd-alpha@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org On Fri, 15 Dec 2000, John Baldwin wrote: >=20 > On 15-Dec-00 Bernd Walter wrote: > > Why are the mb and wmb operations needed in the atomic_ functions? > > If I understood it correctly the locked operations are in synced > > with others CPUs and there is no memory operation beside the variable > > itself. >=20 > They should probably only be used with the 'acq' and 'rel' variants. Hmm= , btw, > it looks like I have the order of the barriers in the 'acq' and 'rel' var= iants > wrong. The barriers should be on the inside, not the outside. Anyone di= sagree? The mb() inside the atomic_ operations are obviously seriously miscommented: For example: static __inline void atomic_set_32(volatile u_int32_t *p, u_int32_t v) { =09u_int32_t temp; =09__asm __volatile ( =09=09"1:\tldl_l %0, %2\n\t"=09=09/* load old value */ =09=09"bis %0, %3, %0\n\t"=09=09/* calculate new value */ =09=09"stl_c %0, %1\n\t"=09=09/* attempt to store */ =09=09"beq %0, 2f\n\t"=09=09/* spin if failed */ =09=09"mb\n\t"=09=09=09/* drain to memory */ =09=09".section .text3,\"ax\"\n"=09/* improve branch prediction */ =09=09"2:\tbr 1b\n"=09=09=09/* try again */ =09=09".previous\n" =09=09: "=3D&r" (temp), "=3Dm" (*p) =09=09: "m" (*p), "r" (v) =09=09: "memory"); } There is obviously no relevance here in trying to drain something to memory. Note that thinking about a mb() as something that drains to memory is a serious mistake in my opinion. We want to order there, not to drain anything anywhere. However, the mb() above does have the effect of throwing away any read=20 that may have been prefetched by the CPU. If we need that here, we must not remove the mb(), otherwise the mb() can be removed. G=E9rard. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-alpha" in the body of the message