From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2758 invoked by alias); 14 Jul 2009 14:44:10 -0000 Received: (qmail 2741 invoked by uid 22791); 14 Jul 2009 14:44:09 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL,BAYES_00,SPF_PASS X-Spam-Check-By: sourceware.org Received: from e2.ny.us.ibm.com (HELO e2.ny.us.ibm.com) (32.97.182.142) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 14 Jul 2009 14:43:58 +0000 Received: from d01relay01.pok.ibm.com (d01relay01.pok.ibm.com [9.56.227.233]) by e2.ny.us.ibm.com (8.13.1/8.13.1) with ESMTP id n6EEcgk2018406 for ; Tue, 14 Jul 2009 10:38:42 -0400 Received: from d01av05.pok.ibm.com (d01av05.pok.ibm.com [9.56.224.195]) by d01relay01.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id n6EEhtOl165606 for ; Tue, 14 Jul 2009 10:43:55 -0400 Received: from d01av05.pok.ibm.com (loopback [127.0.0.1]) by d01av05.pok.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id n6EEhsPI006773 for ; Tue, 14 Jul 2009 10:43:54 -0400 Received: from D27MC103.RCHLAND.IBM.COM (d27mc103.rchland.ibm.com [9.10.229.52]) by d01av05.pok.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id n6EEhsLN006759; Tue, 14 Jul 2009 10:43:54 -0400 In-Reply-To: <20090713161031.GF3101@sunsite.ms.mff.cuni.cz> Subject: Re: [PATCH] Use rel semantics of cas instead of acq semantics with full barrier before it in _int_free To: Jakub Jelinek Cc: Ulrich Drepper , Glibc hackers , rsa@linux.vnet.ibm.com Message-ID: From: Steve Munroe Date: Tue, 14 Jul 2009 14:44:00 -0000 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII Mailing-List: contact libc-hacker-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sourceware.org X-SW-Source: 2009-07/txt/msg00001.txt.bz2 Jakub Jelinek wrote on 07/13/2009 11:10:31 AM: > Hi! > > The following patch fixes catomic_compare_and_exchange_*_rel definitions > (which were never used and weren't correct) and uses > catomic_compare_and_exchange_val_rel in _int_free. Comparing to the > pre-2009-07-02 --enable-experimental-malloc state the generated code should > be identical on all arches other than ppc/ppc64 and on ppc/ppc64 should use > lwsync instead of isync barrier. > > 2009-07-13 Jakub Jelinek > > * include/atomic.h (catomic_compare_and_exchange_val_rel): If arch > overrides atomic_compare_and_exchange_val_rel, define to > atomic_compare_and_exchange_val_rel by default, otherwise default > to catomic_compare_and_exchange_val_acq. > (catomic_compare_and_exchange_bool_rel): If arch overrides > atomic_compare_and_exchange_bool_rel, define to > atomic_compare_and_exchange_bool_rel by default. > * malloc/malloc.c (_int_free): Revert 2009-07-02 change. > Use catomic_compare_and_exchange_val_rel instead of > catomic_compare_and_exchange_val_acq. > > --- libc/include/atomic.h.jj 2009-05-16 19:23:35.000000000 +0200 > +++ libc/include/atomic.h 2009-07-13 17:47:02.000000000 +0200 > @@ -107,14 +107,19 @@ > #endif > > > -#ifndef atomic_compare_and_exchange_val_rel > -# define atomic_compare_and_exchange_val_rel(mem, newval, oldval) \ > - atomic_compare_and_exchange_val_acq (mem, newval, oldval) > +#ifndef catomic_compare_and_exchange_val_rel > +# ifndef atomic_compare_and_exchange_val_rel > +# define catomic_compare_and_exchange_val_rel(mem, newval, oldval) \ > + catomic_compare_and_exchange_val_acq (mem, newval, oldval) > +# else > +# define catomic_compare_and_exchange_val_rel(mem, newval, oldval) \ > + atomic_compare_and_exchange_val_rel (mem, newval, oldval) > +# endif > #endif > I assume that defining catomic_compare_and_exchange_val_rel in terms of catomic_compare_and_exchange_val_acq is only for platforms where there is no distinction (between _acq/_rel) and the platforms sysdeps atomic.h did not define separate *_rel macros. Otherwise this is a bit confusing... > snip ... > --- libc/malloc/malloc.c.jj 2009-07-07 19:10:19.000000000 +0200 > +++ libc/malloc/malloc.c 2009-07-13 17:47:52.000000000 +0200 > @@ -4822,9 +4822,8 @@ _int_free(mstate av, mchunkptr p) > goto errout; > } > p->fd = fd = old; > - atomic_full_barrier (); > } > - while ((old = catomic_compare_and_exchange_val_acq (fb, p, fd)) != fd); > + while ((old = catomic_compare_and_exchange_val_rel (fb, p, fd)) != fd); > #else > /* Another simple check: make sure the top of the bin is not the > record we are going to add (i.e., double free). */ > > Jakub This is a better solution as the use case matches release semantics. In this case we are exporting the "p->fd = fd = old" and needs the export/read barrier that the *_rel macro naturally provides. A import/write barrier is not required as the do/while iterates only for retry. For PPC the selection of raw *_acq vs *_rel macros depends on the context. Thanks Steven J. Munroe Linux on Power Toolchain Architect IBM Corporation, Linux Technology Center