From patchwork Tue Oct 18 03:18:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos O'Donell X-Patchwork-Id: 16608 X-Patchwork-Delegate: triegel@redhat.com Received: (qmail 38066 invoked by alias); 18 Oct 2016 03:19:06 -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 38000 invoked by uid 89); 18 Oct 2016 03:19:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.2 spammy=sk:glibc-2, sk:glibc2, __typeof, upcoming X-HELO: mail-qt0-f175.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:to:from:subject:organization:message-id:date :user-agent:mime-version:content-transfer-encoding; bh=vmCB+cJfZ0qWxpiwhSUjli7I5TiRQPVZABo4PrN7x6Y=; b=lDWJFXetdI9oj6q7Cp6OUysHNrS8nEQg0FQPPTgGCdyBXTEA9jwKBHrSWrW4UnD62T Etp3E+Ofh/Thek9i/5iVrXpcRJYs5A8Wb97esxK6zgKbwzxZdfSselEcwjMmr0EPOJXO /Ko1pjzQObiqn/EdAu/g4M8dFuoIGKubGaSuBd3taLLC2f3t2wl3i17xufWlC15ZraQs bpG8jDm5E/tsSk5sgQVcLgQ1Ipv40wz844/b+uTvndfHCHwgAkpNHznN05WIuC0NGHBo uaGWCcLtnD5Y38KtQNPQN9FdL2p7UsnMUetkG8J/tO7OJksY8BQD3I9qexvPIolnBluv nWpw== X-Gm-Message-State: AA6/9RkkG6of3REa9QxFgIgg4QAGs5afPT3QjW5feLWuxnF+nW4btjyMG5PUNu32+o3BwYvo X-Received: by 10.200.36.125 with SMTP id d58mr574618qtd.147.1476760736841; Mon, 17 Oct 2016 20:18:56 -0700 (PDT) To: GNU C Library , Torvald Riegel From: Carlos O'Donell Subject: [PATCH] Fix x86 atomic_fetch_xor_release. Message-ID: <1eeffe37-c4ec-fef7-537b-9ad17129b6c0@redhat.com> Date: Mon, 17 Oct 2016 23:18:54 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 Torvald, No code uses atomic_fetch_xor_release except for the upcoming conditional variable rewrite. Therefore there is no user visible bug here. The use of atomic_compare_and_exchange_bool_rel is removed (since it doesn't exist anymore), and is replaced by atomic_compare_exchange_weak_release. We use weak_release because it provides better performance in the loop (the weak semantic) and because the xor is release MO (the release semantic). We don't reload expected in the loop because atomic_compare_and_exchange_weak_release does this for us as part of the CAS failure. It is otherwise a fairly plain conversion that fixes building the new condvar for 32-bit x86. I have pushed the new condvar into Fedora Rawhide for testing. OK to checkin? Cheers, Carlos. 2016-10-17 Carlos O'Donell * include/atomic.h [USE_COMPILER_ATOMIC_BUILTINS && !atomic_fetch_xor_release] (atomic_fetch_xor_release): Use atomic_compare_exchange_weak_release. Index: glibc-2.24-256-g5140d03/include/atomic.h =================================================================== --- glibc-2.24-256-g5140d03.orig/include/atomic.h +++ glibc-2.24-256-g5140d03/include/atomic.h @@ -777,18 +777,22 @@ void __atomic_link_error (void); # endif # ifndef atomic_fetch_xor_release +/* Failing the atomic_compare_exchange_weak_release reloads the value in + __atg104_expected, so we need only do the XOR again and retry. */ # define atomic_fetch_xor_release(mem, operand) \ - ({ __typeof (*(mem)) __atg104_old; \ - __typeof (mem) __atg104_memp = (mem); \ + ({ __typeof (mem) __atg104_memp = (mem); \ + __typeof (*(mem)) __atg104_expected = (*__atg104_memp); \ + __typeof (*(mem)) __atg104_desired; \ __typeof (*(mem)) __atg104_op = (operand); \ \ do \ - __atg104_old = (*__atg104_memp); \ - while (__builtin_expect \ - (atomic_compare_and_exchange_bool_rel ( \ - __atg104_memp, __atg104_old ^ __atg104_op, __atg104_old), 0));\ + __atg104_desired = __atg104_expected ^ __atg104_op; \ + while (__glibc_unlikely \ + (atomic_compare_exchange_weak_release ( \ + __atg104_memp, &__atg104_expected, __atg104_desired) \ + == 0)); \ \ - __atg104_old; }) + __atg104_expected; }) #endif #endif /* !USE_ATOMIC_COMPILER_BUILTINS */