From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9030 invoked by alias); 13 Jul 2009 16:11:01 -0000 Received: (qmail 9012 invoked by uid 22791); 13 Jul 2009 16:10:58 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from sunsite.ms.mff.cuni.cz (HELO sunsite.mff.cuni.cz) (195.113.15.26) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 13 Jul 2009 16:10:51 +0000 Received: from sunsite.mff.cuni.cz (localhost [127.0.0.1]) by sunsite.mff.cuni.cz (8.14.3/8.14.3) with ESMTP id n6DGAWtL027871; Mon, 13 Jul 2009 18:10:32 +0200 Received: (from jakub@localhost) by sunsite.mff.cuni.cz (8.14.3/8.14.3/Submit) id n6DGAV3b027870; Mon, 13 Jul 2009 18:10:31 +0200 Date: Mon, 13 Jul 2009 16:11:00 -0000 From: Jakub Jelinek To: Ulrich Drepper , Steve Munroe , Ryan Arnold Cc: Glibc hackers Subject: [PATCH] Use rel semantics of cas instead of acq semantics with full barrier before it in _int_free Message-ID: <20090713161031.GF3101@sunsite.ms.mff.cuni.cz> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.19 (2009-01-05) 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/msg00000.txt.bz2 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 -#ifndef catomic_compare_and_exchange_val_rel -# define catomic_compare_and_exchange_val_rel(mem, newval, oldval) \ +#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) #endif @@ -155,15 +160,20 @@ #endif -#ifndef atomic_compare_and_exchange_bool_rel -# define atomic_compare_and_exchange_bool_rel(mem, newval, oldval) \ - atomic_compare_and_exchange_bool_acq (mem, newval, oldval) +#ifndef catomic_compare_and_exchange_bool_rel +# ifndef atomic_compare_and_exchange_bool_rel +# define catomic_compare_and_exchange_bool_rel(mem, newval, oldval) \ + catomic_compare_and_exchange_bool_acq (mem, newval, oldval) +# else +# define catomic_compare_and_exchange_bool_rel(mem, newval, oldval) \ + atomic_compare_and_exchange_bool_rel (mem, newval, oldval) +# endif #endif -#ifndef catomic_compare_and_exchange_bool_rel -# define catomic_compare_and_exchange_bool_rel(mem, newval, oldval) \ - catomic_compare_and_exchange_bool_acq (mem, newval, oldval) +#ifndef atomic_compare_and_exchange_bool_rel +# define atomic_compare_and_exchange_bool_rel(mem, newval, oldval) \ + atomic_compare_and_exchange_bool_acq (mem, newval, oldval) #endif --- 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