From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D73AFC2D0E7 for ; Thu, 26 Mar 2020 02:41:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A18DA2073E for ; Thu, 26 Mar 2020 02:41:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="G+XtDpPY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727822AbgCZCkx (ORCPT ); Wed, 25 Mar 2020 22:40:53 -0400 Received: from mail-qt1-f193.google.com ([209.85.160.193]:36034 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727805AbgCZCkw (ORCPT ); Wed, 25 Mar 2020 22:40:52 -0400 Received: by mail-qt1-f193.google.com with SMTP id m33so4147815qtb.3; Wed, 25 Mar 2020 19:40:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=b3wMLtwJjVx+cW6i5BwYTXEhVTKTsG2r4lo8N4p/ptY=; b=G+XtDpPYFDSyRzm0QXWKZwQ1v4BUaj6m0HrOPZTJHDU3pfomu98YgSKwFfgzg6spNT MA/Im34q5ZDnMIVDB04KS2MZ6ywaKwGuzN5sxLdAkkKzrzv/xALvRWvBLm67Jg8GmqcD SDvcbfJSJPkLPYIEtwwQ3HIO7SB+UZa2Ef2ghVJshGBcGjJTJRcnJb/vg5+Lq4qiU3oA vdBKRD1F9pBN9MB4xTVS7Eb7+NXh7FQmfPPvAmCZs76yu8PUFLYQlzk6EcglAeT3iq9G NXH1XN2z1N78uOO5wCL/szfhsHW/bQUbR62QUD2MvRgWj1vuu7ac5itB89CuebQUegGO S6sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=b3wMLtwJjVx+cW6i5BwYTXEhVTKTsG2r4lo8N4p/ptY=; b=lO9U8w6+OCI7bBn8ie+i28oIdNMmtjgs9nffZCCEDIAO43pePl23M5oDTQCEd0oIpD pEwz85sKVZabPcTqi6BTYOvRHKCyXnXX8lSWTtAkio27o8l9rdw0hHUmZtpCmEUSxDQO r9uV8EZWeRaI8LFYiyci+4HFoRKDdZtmOW528bm29VzlHcahHkXC50ikhsw8YPe6BJCA BFEEUJeLuVlNIA1WtpNpr1Yx7APUGE/h3ZhWWQQeeuuqw5/IFLGPwGR2GHzIho6caMlu /Xg0ZKWM84W6LWUqS5k+5QO5du/TD2es4xwjHocAiMKY6tWK/DX0n7CebUCmenbc3aLA ECXg== X-Gm-Message-State: ANhLgQ1ZJkDCSLwWBi0xYRyPADWJU40ouutSkSfC9clm/n6XDOlvValb ZJY7ylBXnwRTDei3j1/pN6g= X-Google-Smtp-Source: ADFU+vuBYJphO1kTx7mC+IwOjpOMaxnxWuorjwSu3zdstMRXUhAMpjk5Wd3f7oSj7xg9X7A6HUovpA== X-Received: by 2002:ac8:5458:: with SMTP id d24mr6099798qtq.255.1585190450781; Wed, 25 Mar 2020 19:40:50 -0700 (PDT) Received: from auth1-smtp.messagingengine.com (auth1-smtp.messagingengine.com. [66.111.4.227]) by smtp.gmail.com with ESMTPSA id u15sm671282qte.91.2020.03.25.19.40.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Mar 2020 19:40:50 -0700 (PDT) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailauth.nyi.internal (Postfix) with ESMTP id A946227C0054; Wed, 25 Mar 2020 22:40:49 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Wed, 25 Mar 2020 22:40:49 -0400 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrudehhedggeejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeeuohhquhhn ucfhvghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtghomheqnecukfhppeehvd drudehhedrudduuddrjedunecuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehm rghilhhfrhhomhepsghoqhhunhdomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthi dqieelvdeghedtieegqddujeejkeehheehvddqsghoqhhunhdrfhgvnhhgpeepghhmrghi lhdrtghomhesfhhigihmvgdrnhgrmhgv X-ME-Proxy: Received: from localhost (unknown [52.155.111.71]) by mail.messagingengine.com (Postfix) with ESMTPA id 27FAE3067F32; Wed, 25 Mar 2020 22:40:49 -0400 (EDT) From: Boqun Feng To: linux-kernel@vger.kernel.org Cc: Alan Stern , Andrea Parri , Will Deacon , Peter Zijlstra , Boqun Feng , 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 , linux-arch@vger.kernel.org, linux-doc@vger.kernel.org Subject: [PATCH v4 3/4] Documentation/litmus-tests/atomic: Add a test for atomic_set() Date: Thu, 26 Mar 2020 10:40:21 +0800 Message-Id: <20200326024022.7566-4-boqun.feng@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200326024022.7566-1-boqun.feng@gmail.com> References: <20200326024022.7566-1-boqun.feng@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-doc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-doc@vger.kernel.org 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 --- 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. -- 2.25.1