From patchwork Wed Oct 29 18:18:56 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Torvald Riegel X-Patchwork-Id: 3481 Received: (qmail 25205 invoked by alias); 29 Oct 2014 18:19:04 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 25192 invoked by uid 89); 29 Oct 2014 18:19:02 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.4 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Subject: [PATCH] Fix atomic_full_barrier on x86 and x86_64. From: Torvald Riegel To: GLIBC Devel Date: Wed, 29 Oct 2014 19:18:56 +0100 Message-ID: <1414606736.10085.1.camel@triegel.csb> Mime-Version: 1.0 Currently, x86 and x86_64 do not define any of the barriers. The generic default for the barriers is that full barriers are just compiler barriers and read and write barriers default to using the full barrier definition. On x86 and x86_64, however, only read/write barriers (ie, acquire and release fences in how glibc uses them) are just compiler barriers -- a full barrier needs an mfence instruction. This patch defines atomic_full_barrier accordingly without making read/write barriers stronger than compiler barriers. The only use of atomic_full_barrier on x86/x86_64 is in sysdeps/nptl/fork.c, but there, ISTM that this actually only needs an acquire barrier. So, this patch doesn't fix existing bugs in *current* code, and only makes fork a tiny tiny bit slower. Nonetheless, there are other uses of full barriers in generic code (e.g., semaphores). Those don't apply for x86/x86_64 because we currently have arch-specific code for those, but would if we start using the generic code on x86 too (and we couldn't do until we fix the x86 full barrier). * sysdeps/x86_64/bits/atomic.h: (atomic_full_barrier, atomic_read_barrier, atomic_write_barrier): Define. * sysdeps/i386/i486/bits/atomic.h (atomic_full_barrier, atomic_read_barrier, atomic_write_barrier): Define. commit be14e33b607609462130a0264c7a9460596da3f8 Author: Torvald Riegel Date: Wed Oct 29 10:34:36 2014 +0100 Fix atomic_full_barrier on x86 and x86_64. * sysdeps/x86_64/bits/atomic.h: (atomic_full_barrier, atomic_read_barrier, atomic_write_barrier): Define. * sysdeps/i386/i486/bits/atomic.h (atomic_full_barrier, atomic_read_barrier, atomic_write_barrier): Define. diff --git a/sysdeps/i386/i486/bits/atomic.h b/sysdeps/i386/i486/bits/atomic.h index 76e0e8e..7c432f9 100644 --- a/sysdeps/i386/i486/bits/atomic.h +++ b/sysdeps/i386/i486/bits/atomic.h @@ -532,3 +532,7 @@ typedef uintmax_t uatomic_max_t; #define atomic_or(mem, mask) __arch_or_body (LOCK_PREFIX, mem, mask) #define catomic_or(mem, mask) __arch_or_body (__arch_cprefix, mem, mask) + +#define atomic_full_barrier() __asm ("mfence" ::: "memory") +#define atomic_read_barrier() __asm ("" ::: "memory") +#define atomic_write_barrier() __asm ("" ::: "memory") diff --git a/sysdeps/x86_64/bits/atomic.h b/sysdeps/x86_64/bits/atomic.h index 4d19ef0..25f73aa 100644 --- a/sysdeps/x86_64/bits/atomic.h +++ b/sysdeps/x86_64/bits/atomic.h @@ -466,3 +466,7 @@ typedef uintmax_t uatomic_max_t; #define atomic_or(mem, mask) __arch_or_body (LOCK_PREFIX, mem, mask) #define catomic_or(mem, mask) __arch_or_body (__arch_cprefix, mem, mask) + +#define atomic_full_barrier() __asm ("mfence" ::: "memory") +#define atomic_read_barrier() __asm ("" ::: "memory") +#define atomic_write_barrier() __asm ("" ::: "memory")