From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by sourceware.org (Postfix) with ESMTPS id 78A243895FDA for ; Tue, 15 Nov 2022 13:28:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 78A243895FDA Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=ispras.ru Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=ispras.ru Received: from [10.10.3.121] (unknown [10.10.3.121]) by mail.ispras.ru (Postfix) with ESMTPS id DE5FB419E9DE; Tue, 15 Nov 2022 13:28:16 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru DE5FB419E9DE Date: Tue, 15 Nov 2022 16:28:16 +0300 (MSK) From: Alexander Monakov To: Jonathan Wakely cc: Hongyu Wang , gcc-patches@gcc.gnu.org, hongtao.liu@intel.com, ubizjak@gmail.com Subject: Re: [PATCH] doc: Reword the description of -mrelax-cmpxchg-loop [PR 107676] In-Reply-To: Message-ID: <9289c261-6aeb-2fdf-6599-4e8d77c30f8@ispras.ru> References: <20221115033559.66827-1-hongyu.wang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,KAM_DMARC_STATUS,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Tue, 15 Nov 2022, Jonathan Wakely via Gcc-patches wrote: > > @item -mrelax-cmpxchg-loop > > @opindex mrelax-cmpxchg-loop > >-Relax cmpxchg loop by emitting an early load and compare before cmpxchg, > >-execute pause if load value is not expected. This reduces excessive > >-cachline bouncing when and works for all atomic logic fetch builtins > >-that generates compare and swap loop. > >+For compare and swap loops that emitted by some __atomic_* builtins > > s/that emitted/that are emitted/ > > >+(e.g. __atomic_fetch_(or|and|xor|nand) and their __atomic_*_fetch > >+counterparts), emit an atomic load before cmpxchg instruction. If the > > s/before cmpxchg/before the cmpxchg/ > > >+loaded value is not equal to expected, execute a pause instead of > > s/not equal to expected/not equal to the expected/ > > >+directly run the cmpxchg instruction. This might reduce excessive > > s/directly run/directly running/ This results in "... execute a pause instead of directly running the cmpxchg instruction", which needs further TLC because: * 'a pause' should be 'the PAUSE instruction'; * 'directly running [an instruction]' does not seem correct in context. The option also applies to __sync builtins, not just __atomic. How about the following: When emitting a compare-and-swap loop for @ref{__sync Builtins} and @ref{__atomic Builtins} lacking a native instruction, optimize for the highly contended case by issuing an atomic load before the @code{CMPXCHG} instruction, and invoke the @code{PAUSE} instruction when restarting the loop. Alexander