Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1790671ybb; Thu, 26 Mar 2020 07:25:08 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsJRn6Yd290b+Ns2DM/wA3ZeJumUH0IuebokMnjph42kOSg9OzX2mnNBWX60FW2wzLB5IOE X-Received: by 2002:aca:5210:: with SMTP id g16mr199735oib.174.1585232708271; Thu, 26 Mar 2020 07:25:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585232708; cv=none; d=google.com; s=arc-20160816; b=aO5Ztv6HDZeocNrU1XQTMGlbRiIyCVN7NZhYORRbP74a8BwpAmsp2A7yDQ+GYSmuIn CbnRTE0V+2kfCWUXdTx2/40Jb3ti4BLeenzdSCJvvhoYHE+5IQChEBPpzfQEwcAUFRa0 NiyWpcr9kBGdr1t4DFpFkDsZJcG4hu+ix9M+5waDuFC0zqgAWrgvLRCJ2yrnOaAG2bRM IRcnHzfVuvOYynQUa6jBBigofqH/+RfA+LgbPx7oCv3vxyc5TpMKNMuWXQD0cBeWLCb0 JkImudq/+AprsQrD3pH+a17reJoGAF+HbZIyUc+qqFE2axgK0NPeSnzPDHVJ0vWsT4y6 tHkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:in-reply-to :subject:cc:to:from:date; bh=WcNW37EsYjdgCYhUUO55opECADMC8+BP3TIVKrRkQYc=; b=ZjzEVR6o6fwrh2dLGPa/L/KJhIh+G/9sWSp3sOgkBXg3b97bymrwR/fQKgUalbHQW3 YbSbnG31s1WfQavVfXSVUhMZ5w26AVDVAwkgA0EFta0dUbqFMxFAWRX/0S+c5UnkqDda jZysqUmCrEulvZ35rUkvoPw8S3qXp2ri9/1lbvD2+BrZuvTLM9VFrsNzBHlg8ieqwzJm Y4xt9JjKn1vtixhqfcyiIbSxBtWiuhB/wnWHqoWrFMsoQPS1Kcw8jHhe+8Kahw3uUI6H tmf754sqEK4TO6jsmDKDo7VgFJl25uHlBDmTQGl3l6F6Mhd7VOCxSyOeti06ksE/p7tX CWRQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k185si1120962oif.13.2020.03.26.07.24.55; Thu, 26 Mar 2020 07:25:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728002AbgCZOXW (ORCPT + 99 others); Thu, 26 Mar 2020 10:23:22 -0400 Received: from netrider.rowland.org ([192.131.102.5]:45575 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1727989AbgCZOXW (ORCPT ); Thu, 26 Mar 2020 10:23:22 -0400 Received: (qmail 6696 invoked by uid 500); 26 Mar 2020 10:23:21 -0400 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 26 Mar 2020 10:23:21 -0400 Date: Thu, 26 Mar 2020 10:23:21 -0400 (EDT) From: Alan Stern X-X-Sender: stern@netrider.rowland.org To: Boqun Feng cc: linux-kernel@vger.kernel.org, Andrea Parri , Will Deacon , Peter Zijlstra , Nicholas Piggin , David Howells , Jade Alglave , Luc Maranget , "Paul E. McKenney" , Akira Yokosawa , Daniel Lustig , Jonathan Corbet , Mauro Carvalho Chehab , "David S. Miller" , Rob Herring , Greg Kroah-Hartman , Jonathan Cameron , Joel Fernandes , , Subject: Re: [PATCH v4 3/4] Documentation/litmus-tests/atomic: Add a test for atomic_set() In-Reply-To: <20200326024022.7566-4-boqun.feng@gmail.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 26 Mar 2020, Boqun Feng wrote: > We already use a litmus test in atomic_t.txt to describe the behavior of > an atomic_set() with the an atomic RMW, so add it into atomic-tests > directory to make it easily accessible for anyone who cares about the > semantics of our atomic APIs. > > Besides currently the litmus test "atomic-set" in atomic_t.txt has a few > things to be improved: > > 1) The CPU/Processor numbers "P1,P2" are not only inconsistent with > the rest of the document, which uses "CPU0" and "CPU1", but also > unacceptable by the herd tool, which requires processors start > at "P0". > > 2) The initialization block uses a "atomic_set()", which is OK, but > it's better to use ATOMIC_INIT() to make clear this is an > initialization. > > 3) The return value of atomic_add_unless() is discarded > inexplicitly, which is OK for C language, but it will be helpful > to the herd tool if we use a void cast to make the discard > explicit. > > 4) The name and the paragraph describing the test need to be more > accurate and aligned with our wording in LKMM. > > Therefore fix these in both atomic_t.txt and the new added litmus test. > > Signed-off-by: Boqun Feng > Acked-by: Andrea Parri > --- Acked-by: Alan Stern > Documentation/atomic_t.txt | 14 +++++------ > ...c-RMW-ops-are-atomic-WRT-atomic_set.litmus | 24 +++++++++++++++++++ > Documentation/litmus-tests/atomic/README | 7 ++++++ > 3 files changed, 38 insertions(+), 7 deletions(-) > create mode 100644 Documentation/litmus-tests/atomic/Atomic-RMW-ops-are-atomic-WRT-atomic_set.litmus > > diff --git a/Documentation/atomic_t.txt b/Documentation/atomic_t.txt > index 0ab747e0d5ac..67d1d99f8589 100644 > --- a/Documentation/atomic_t.txt > +++ b/Documentation/atomic_t.txt > @@ -85,21 +85,21 @@ smp_store_release() respectively. Therefore, if you find yourself only using > the Non-RMW operations of atomic_t, you do not in fact need atomic_t at all > and are doing it wrong. > > -A subtle detail of atomic_set{}() is that it should be observable to the RMW > -ops. That is: > +A note for the implementation of atomic_set{}() is that it must not break the > +atomicity of the RMW ops. That is: > > - C atomic-set > + C Atomic-RMW-ops-are-atomic-WRT-atomic_set > > { > - atomic_set(v, 1); > + atomic_t v = ATOMIC_INIT(1); > } > > - P1(atomic_t *v) > + P0(atomic_t *v) > { > - atomic_add_unless(v, 1, 0); > + (void)atomic_add_unless(v, 1, 0); > } > > - P2(atomic_t *v) > + P1(atomic_t *v) > { > atomic_set(v, 0); > } > diff --git a/Documentation/litmus-tests/atomic/Atomic-RMW-ops-are-atomic-WRT-atomic_set.litmus b/Documentation/litmus-tests/atomic/Atomic-RMW-ops-are-atomic-WRT-atomic_set.litmus > new file mode 100644 > index 000000000000..49385314d911 > --- /dev/null > +++ b/Documentation/litmus-tests/atomic/Atomic-RMW-ops-are-atomic-WRT-atomic_set.litmus > @@ -0,0 +1,24 @@ > +C Atomic-RMW-ops-are-atomic-WRT-atomic_set > + > +(* > + * Result: Never > + * > + * Test that atomic_set() cannot break the atomicity of atomic RMWs. > + *) > + > +{ > + atomic_t v = ATOMIC_INIT(1); > +} > + > +P0(atomic_t *v) > +{ > + (void)atomic_add_unless(v, 1, 0); > +} > + > +P1(atomic_t *v) > +{ > + atomic_set(v, 0); > +} > + > +exists > +(v=2) > diff --git a/Documentation/litmus-tests/atomic/README b/Documentation/litmus-tests/atomic/README > index ae61201a4271..a1b72410b539 100644 > --- a/Documentation/litmus-tests/atomic/README > +++ b/Documentation/litmus-tests/atomic/README > @@ -2,3 +2,10 @@ This directory contains litmus tests that are typical to describe the semantics > of our atomic APIs. For more information about how to "run" a litmus test or > how to generate a kernel test module based on a litmus test, please see > tools/memory-model/README. > + > +============ > +LITMUS TESTS > +============ > + > +Atomic-RMW-ops-are-atomic-WRT-atomic_set.litmus > + Test that atomic_set() cannot break the atomicity of atomic RMWs. >