From patchwork Thu Jun 20 13:20:13 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Kleen X-Patchwork-Id: 252929 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 813262C023D for ; Thu, 20 Jun 2013 23:20:43 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; q=dns; s= default; b=njFsolrBpA0FWLR07YNSSgpR5iVr9MuE15EvVFJBfy8zoNjtpxrhb R6GmI2NxBktk5KGPm4JSw4gLnwalHhqZgoWrWzIUk0zmCcqtyioPnIF4JJJtVSj8 +h4S2FzDcJKDWom2W2BqfuQBC4EtcTU+7UxPED0rZahd+lIqh2wwUw= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; s= default; bh=NI8/oYT5VPpQDZbRtxyKxyPCnuM=; b=NDSdtXL3WTI5goeZEkAe k0dsX1F0v2Cka6WntHOWzJm1tEMex32z7RGrPf/zPbbVlniK07GSRMc/jEaewYQO yZcetHGfCzoyXnwEAo66UCo8D9pRCjN8ZaO8torF1XIHbOpwI0aywYeYl5OGwigZ CfV9Vawewcc9UAzI9XEc9Ik= Received: (qmail 20005 invoked by alias); 20 Jun 2013 13:20:26 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 19949 invoked by uid 89); 20 Jun 2013 13:20:26 -0000 X-Spam-SWARE-Status: No, score=-3.9 required=5.0 tests=AWL, BAYES_00, KHOP_THREADED, RP_MATCHES_RCVD autolearn=ham version=3.3.1 Received: from one.firstfloor.org (HELO one.firstfloor.org) (193.170.194.197) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Thu, 20 Jun 2013 13:20:25 +0000 Received: from basil.firstfloor.org (71-32-246-34.ptld.qwest.net [71.32.246.34]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by one.firstfloor.org (Postfix) with ESMTPSA id 422B3866A7; Thu, 20 Jun 2013 15:20:23 +0200 (CEST) Received: by basil.firstfloor.org (Postfix, from userid 1000) id 4E262A2581; Thu, 20 Jun 2013 06:20:21 -0700 (PDT) From: Andi Kleen To: gcc-patches@gcc.gnu.org Cc: Andi Kleen Subject: [PATCH 2/2] Fix HLE example in manual Date: Thu, 20 Jun 2013 06:20:13 -0700 Message-Id: <1371734413-12372-2-git-send-email-andi@firstfloor.org> In-Reply-To: <1371734413-12372-1-git-send-email-andi@firstfloor.org> References: <1371734413-12372-1-git-send-email-andi@firstfloor.org> From: Andi Kleen The HLE example in the manual only commits when using bool for the flag, because __atomic_clear only writes bool, and HLE requires the acquire and release to match. So when the example is copied with e.g. an int variable it does not commit and causes slower than expected performance. Some people are running into problems because of this. Switch it over to use __atomic_store. Also fix a minor typo nearby. gcc/: 2013-06-13 Andi Kleen * doc/extend.texi: Dont use __atomic_clear in HLE example. Fix typo. --- gcc/doc/extend.texi | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index aa3abef..b6f786d 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -7524,18 +7524,20 @@ End lock elision on a lock variable. Memory model must be @code{__ATOMIC_RELEASE} or stronger. @end table -When a lock acquire fails it's required for good performance to abort +When a lock acquire fails it is required for good performance to abort the transaction quickly. This can be done with a @code{_mm_pause} @smallexample #include // For _mm_pause +int lockvar; + /* Acquire lock with lock elision */ while (__atomic_exchange_n(&lockvar, 1, __ATOMIC_ACQUIRE|__ATOMIC_HLE_ACQUIRE)) _mm_pause(); /* Abort failed transaction */ ... /* Free lock with lock elision */ -__atomic_clear(&lockvar, __ATOMIC_RELEASE|__ATOMIC_HLE_RELEASE); +__atomic_store(&lockvar, 0, __ATOMIC_RELEASE|__ATOMIC_HLE_RELEASE); @end smallexample @node Object Size Checking