From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id F33833895FE1 for ; Tue, 15 Nov 2022 13:44:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F33833895FE1 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668519872; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=rmPk6/oaxH6oKEoWLqQoNrcthdCTQj+rSBqD+ywz6kE=; b=e0fbUTjtt8VbPYtFGxO5nJ9UYUR8Lx/lk7KrUYSsmCEGlXIjLo7pilqj9JglB7Mb/i49Ne M6uxLmMvLPcqKC00BdVdt/DCRbOl6Bi4WzHNgPUyqZ5jv/hoYk7jle2ZyOuMhNegKVZTPc nyWA+bShALibmikjF+JiRR8e8ZOPzeI= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-435-MrWEeDrMMCSg4z7gTQB3nw-1; Tue, 15 Nov 2022 08:44:31 -0500 X-MC-Unique: MrWEeDrMMCSg4z7gTQB3nw-1 Received: by mail-ej1-f69.google.com with SMTP id xj11-20020a170906db0b00b0077b6ecb23fcso7327097ejb.5 for ; Tue, 15 Nov 2022 05:44:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=rmPk6/oaxH6oKEoWLqQoNrcthdCTQj+rSBqD+ywz6kE=; b=bitayqztsaj8w/zurGVz4TAjp2S1s4pXCAfUPaz3nnb1X5thjIf41JTU02vsKxcrs6 5N0VWj1Cj9G1cF+oajTu7YTadazZAz0ygprQ0onQtDOjjCuQ+7vTWnIaH5WYmngq8cEP /iYO0TbG67c4FVDakq7kAS55hu0eyGjftpXd4RMOrIIsPnMpj9Q3hinQLlD34uRLu9V2 4jFxhJdoSBhv18wnHKjePC2pIMvpiDp83NXVMFONiGgYTPED0ddYFwyCPBr/MUKv51bS 1uMsYhUJF9oJreRqfDt4pFC3ZRjM68/u7BoY96Etes2jH4xctbQuigqYy13iaa2UoQ3W 8hjg== X-Gm-Message-State: ANoB5plnlaBUFC+qbju9xy1f+3ZrIROaYblt4J4+J3tJBv//IJHn/R/S +3CLSKoNtDVqqXsKj4enTHy5xDVEMYDMbm/1mi1bAai5BcQeU4n1jNiIHbruoouK9NXWv40wDIc 6g/nD1J6JOJwle9hLi67UuDF6pXh9HSC8xg== X-Received: by 2002:a17:906:1ed0:b0:78d:9e77:1f8c with SMTP id m16-20020a1709061ed000b0078d9e771f8cmr13816758ejj.236.1668519870170; Tue, 15 Nov 2022 05:44:30 -0800 (PST) X-Google-Smtp-Source: AA0mqf5gHpRIWhjTP9elyHnlb+mR/vwZLA7iVri/WdayPHhm2rSD/9GNgYx+Q1dOzbwN3NKujpRur2kM45BVwk7E8sQ= X-Received: by 2002:a17:906:1ed0:b0:78d:9e77:1f8c with SMTP id m16-20020a1709061ed000b0078d9e771f8cmr13816742ejj.236.1668519869968; Tue, 15 Nov 2022 05:44:29 -0800 (PST) MIME-Version: 1.0 References: <20221115033559.66827-1-hongyu.wang@intel.com> <9289c261-6aeb-2fdf-6599-4e8d77c30f8@ispras.ru> In-Reply-To: <9289c261-6aeb-2fdf-6599-4e8d77c30f8@ispras.ru> From: Jonathan Wakely Date: Tue, 15 Nov 2022 13:44:19 +0000 Message-ID: Subject: Re: [PATCH] doc: Reword the description of -mrelax-cmpxchg-loop [PR 107676] To: Alexander Monakov Cc: Hongyu Wang , gcc-patches@gcc.gnu.org, hongtao.liu@intel.com, ubizjak@gmail.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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 at 13:34, Alexander Monakov wrote: > > 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. That's much better, thanks. My only remaining quibble would be that "invoking" an instruction seems only marginally better than running one. Emitting? Issuing? Using? Adding?