Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp252894ybv; Tue, 18 Feb 2020 22:27:17 -0800 (PST) X-Google-Smtp-Source: APXvYqyzfXrWncxttCNRKi0MGX65MvXlEOaaSkb51/Fmd6Jnalq7d0GRX0/HRecmxcQmOdlzq9jL X-Received: by 2002:aca:2207:: with SMTP id b7mr3779510oic.109.1582093637245; Tue, 18 Feb 2020 22:27:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582093637; cv=none; d=google.com; s=arc-20160816; b=hN/YTJDJPn1ypBrIvtGTTOMKiA5AZwdNKTtj0SqnuHJaJGY3zFG0JIgx9PRITWSkkK kZtFeN96iiAkQku8NIt9rNDfJvlqofVhIM6pOQRCcQ3T/2TzhovFUFwVcWwoMN6vLo71 Rrwl2QoI2RInuXOYB6cg10KOOXOgwyvVpS2kcfp/K6CxohZAInjwlcTcp559TXHwOtLS OM8ECt2DrZfyr4weh30U3bzCmtmTh3OBYvCq3s8xdNrVeFJMhryMgP1hkanKkqI+e7Xc BODNc/YKnxp+F71UkSHOYs9Afy2JHO68AquZ4rxlHj1DQSCeJj52OEaHUWIbHFP0Y/ta a7wQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xSVXe85di4uctFtWBVBwJQVGLp4RQYE6apzrP4URRsk=; b=ue0j3vCg9oveohh8gk3R0q2D4pRvgtsbgN83dkKbYxUVd+HFZwgyOStzUgr0u86Tm9 X4t3nMLAcuakuS+/JX592oB5ufDKqbcmpWncbHZMfFEz2naoWV7Pw+c4Ewi9KzOv9l6j TfuVx0qvW7a6q2rrx3eSPk+aM/vfzMngTe92EtrMsXXtf93quUmbp1gZOhXetWStjY7o ljBY+xUk0P1AHpsQNBCi7ki7ZNE3z+uE3qLR+7mItBnOcqKI/xttVQMk0ryR6BoDtXIW 9H57K+UpxeIgosydoqt8gGbVBbt+qpM/+4aJ1oon5mPJlZLYLt2/T2/Hhq6cwZ04H7SJ EmcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IiJLW7y5; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r6si653430otn.216.2020.02.18.22.26.54; Tue, 18 Feb 2020 22:27:17 -0800 (PST) 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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IiJLW7y5; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726604AbgBSG0r (ORCPT + 99 others); Wed, 19 Feb 2020 01:26:47 -0500 Received: from mail-qk1-f194.google.com ([209.85.222.194]:46149 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726106AbgBSG0o (ORCPT ); Wed, 19 Feb 2020 01:26:44 -0500 Received: by mail-qk1-f194.google.com with SMTP id u124so21530749qkh.13; Tue, 18 Feb 2020 22:26:43 -0800 (PST) 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=xSVXe85di4uctFtWBVBwJQVGLp4RQYE6apzrP4URRsk=; b=IiJLW7y5wNw7wkLqB6I5LL/YXpwfrvt6lwt3pgz5RzFlK2FZSO8IvJI7uF/6rc+Wlv zKaK+JmjAg0U/Gx+H3k2BCCgtNzRomEc7LS8zTdTdVCmk8x3mtH8pHxc8FU4Ilv69XKd d+OLiVHTHx5xGV5ffMjYD4SJQbMjz7AAl8M44IMq9BUk0di9lT3oNYdIhBSThPTbPQ2V 2uZy5Gi1E5acdskS/8DYh49DwOLw4WMgeIRBHwfkT56PDaCSaRkSQi8UHTf7I8KvNrPd fSLxozJ40K0/kBoz3mjmY4EZX0KtseL8HEcgmxRIJoYmcLr9yZIYcpUWh8DBqSCwEbqJ tHtg== 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=xSVXe85di4uctFtWBVBwJQVGLp4RQYE6apzrP4URRsk=; b=TZMEzBgjkd3rsAtNSJ7ktoZ5dZpEOKWbiQ9EzbJ2bIz9cVaz8ckn0dlI8D5X5jL1pe FLUJKzPuPljrH3xl5Nh16w3CAjR+XV0qq0XDngwW+fv0q+kiRstuB/dSpJAmrquURVrI +DpqIgPeqS2FiTv1uPBDR6fXR0Al0j13V5MtJ/tZTEVu/F/dVhuW73Mz+TqvBJHgFzdF cOoEc53QawwhHvwNL8D9bbKNxiquDbuIQCjRwV6CqLMd7boGpErGKxjCJ6RbLs4JnQYU 7yaILhM9tcW35K8XGDgoB/3QWN3OMLjvG71WnL8zHeqOGllfdnAfKsc/1ffcYvAb1+ZF DupA== X-Gm-Message-State: APjAAAUxQ4bGnTE5ANV5SvbJwNxz2vCQvvweJx8XTbX05Bo0guJojwse P1Rrd80DVPFQkVgVUZrzxMI= X-Received: by 2002:a37:a8f:: with SMTP id 137mr665848qkk.435.1582093602787; Tue, 18 Feb 2020 22:26:42 -0800 (PST) Received: from auth1-smtp.messagingengine.com (auth1-smtp.messagingengine.com. [66.111.4.227]) by smtp.gmail.com with ESMTPSA id j4sm525607qkk.84.2020.02.18.22.26.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Feb 2020 22:26:41 -0800 (PST) Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailauth.nyi.internal (Postfix) with ESMTP id 4F2DB22200; Wed, 19 Feb 2020 01:26:40 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Wed, 19 Feb 2020 01:26:40 -0500 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrjeelgdelgecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepuehoqhhunhcu hfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucfkphephedvrd duheehrdduuddurdejudenucevlhhushhtvghrufhiiigvpedvnecurfgrrhgrmhepmhgr ihhlfhhrohhmpegsohhquhhnodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqd eiledvgeehtdeigedqudejjeekheehhedvqdgsohhquhhnrdhfvghngheppehgmhgrihhl rdgtohhmsehfihigmhgvrdhnrghmvg X-ME-Proxy: Received: from localhost (unknown [52.155.111.71]) by mail.messagingengine.com (Postfix) with ESMTPA id C1DC83060F09; Wed, 19 Feb 2020 01:26:39 -0500 (EST) 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 , linux-arch@vger.kernel.org, linux-doc@vger.kernel.org Subject: [RFC v2 4/4] Documentation/locking/atomic: Add a litmus test smp_mb__after_atomic() Date: Wed, 19 Feb 2020 14:26:27 +0800 Message-Id: <20200219062627.104736-5-boqun.feng@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200219062627.104736-1-boqun.feng@gmail.com> References: <20200219062627.104736-1-boqun.feng@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We already use a litmus test in atomic_t.txt to describe atomic RMW + smp_mb__after_atomic() is stronger than acquire (both the read and the write parts are ordered). So make it a litmus test in atomic-tests directory, so that people can access the litmus easily. Additionally, change the processor numbers "P1, P2" to "P0, P1" in atomic_t.txt for the consistency with the processor numbers in the litmus test, which herd can handle. Signed-off-by: Boqun Feng --- ...ter_atomic-is-stronger-than-acquire.litmus | 32 +++++++++++++++++++ Documentation/atomic-tests/README | 5 +++ Documentation/atomic_t.txt | 10 +++--- 3 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 Documentation/atomic-tests/Atomic-RMW+mb__after_atomic-is-stronger-than-acquire.litmus diff --git a/Documentation/atomic-tests/Atomic-RMW+mb__after_atomic-is-stronger-than-acquire.litmus b/Documentation/atomic-tests/Atomic-RMW+mb__after_atomic-is-stronger-than-acquire.litmus new file mode 100644 index 000000000000..9a8e31a44b28 --- /dev/null +++ b/Documentation/atomic-tests/Atomic-RMW+mb__after_atomic-is-stronger-than-acquire.litmus @@ -0,0 +1,32 @@ +C Atomic-RMW+mb__after_atomic-is-stronger-than-acquire + +(* + * Result: Never + * + * Test that an atomic RMW followed by a smp_mb__after_atomic() is + * stronger than a normal acquire: both the read and write parts of + * the RMW are ordered before the subsequential memory accesses. + *) + +{ +} + +P0(int *x, atomic_t *y) +{ + int r0; + int r1; + + r0 = READ_ONCE(*x); + smp_rmb(); + r1 = atomic_read(y); +} + +P1(int *x, atomic_t *y) +{ + atomic_inc(y); + smp_mb__after_atomic(); + WRITE_ONCE(*x, 1); +} + +exists +(0:r0=1 /\ 0:r1=0) diff --git a/Documentation/atomic-tests/README b/Documentation/atomic-tests/README index a1b72410b539..714cf93816ea 100644 --- a/Documentation/atomic-tests/README +++ b/Documentation/atomic-tests/README @@ -7,5 +7,10 @@ tools/memory-model/README. LITMUS TESTS ============ +Atomic-RMW+mb__after_atomic-is-stronger-than-acquire + Test that an atomic RMW followed by a smp_mb__after_atomic() is + stronger than a normal acquire: both the read and write parts of + the RMW are ordered before the subsequential memory accesses. + Atomic-RMW-ops-are-atomic-WRT-atomic_set.litmus Test that atomic_set() cannot break the atomicity of atomic RMWs. diff --git a/Documentation/atomic_t.txt b/Documentation/atomic_t.txt index d30cb3d87375..a455328443eb 100644 --- a/Documentation/atomic_t.txt +++ b/Documentation/atomic_t.txt @@ -233,19 +233,19 @@ as well. Similarly, something like: is an ACQUIRE pattern (though very much not typical), but again the barrier is strictly stronger than ACQUIRE. As illustrated: - C strong-acquire + C Atomic-RMW+mb__after_atomic-is-stronger-than-acquire { } - P1(int *x, atomic_t *y) + P0(int *x, atomic_t *y) { r0 = READ_ONCE(*x); smp_rmb(); r1 = atomic_read(y); } - P2(int *x, atomic_t *y) + P1(int *x, atomic_t *y) { atomic_inc(y); smp_mb__after_atomic(); @@ -253,14 +253,14 @@ strictly stronger than ACQUIRE. As illustrated: } exists - (r0=1 /\ r1=0) + (0:r0=1 /\ 0:r1=0) This should not happen; but a hypothetical atomic_inc_acquire() -- (void)atomic_fetch_inc_acquire() for instance -- would allow the outcome, because it would not order the W part of the RMW against the following WRITE_ONCE. Thus: - P1 P2 + P0 P1 t = LL.acq *y (0) t++; -- 2.25.0