Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp2489650pxb; Mon, 18 Apr 2022 01:05:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3WGyrY4cPuPF6bWcLi5JXsGZMn5oHu9IDStlKqic+1+pk9kJkjAIen5A/H+ZX41SqOniP X-Received: by 2002:a05:6402:1104:b0:41d:5f4a:7f5a with SMTP id u4-20020a056402110400b0041d5f4a7f5amr11293150edv.207.1650269157768; Mon, 18 Apr 2022 01:05:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650269157; cv=none; d=google.com; s=arc-20160816; b=xAJBOwPD06nbJH+rK8OO1nHT8LEcpfRPEz2zRFOdPldGXWFkomDqGqbK4QYKDDzyTl OX5Jxgp3DsYy/2Oh5gxeQbN5C19hVIcCpuZmGbJCMelg8udqgQl9/g8S8StvdLkyaNsM Ckxz3d1tOUnLYLGqAq0eGZ1H0jxenb8ARFAP1OfDCZCuG7yh4Wu/mMqiLRnFjQ2CqzUg MtkiDGf8zBky3luLMgxHnKfSs0AOvJQSd3a5Hs+uRzjoGKw2df+9989FhC4IPT4tsIdM rzRnTK6DVcdSFhyDlz9fsvyJnx3vecserp0cmRt8YOT98Bhr3ijOx6wBImEQVe0CxjL5 IZ7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=w8FEMTX/xuVcdhSUM8I8EwNIenSORDwi1yF5x5D0CQk=; b=xLWn5yEhSufrLdBDvBJdTv+dkU63p3o+euhxr+gL9rci56cOgXArboE2n/YP/j1PbA q1ROJhjN8xOXQIP150V/2DSvrPrXb4Ca2JhsZecEqbrLPXKlbZ9wlhNm1DyqYQr5U4/Y iPzaJ9xbViwsurzJV25Kz8HfCM8ypK9Oqs1G6zOs6D1k3FCpB0tc3xzQBAhbuXL81qA5 4dksulb49lNSRNsC9wscGnmc9FqwAUztJc+BLdX41p9BBXg7VROkQE2febLUuEXfDxm0 tNBMPDPmTk+X8Log6Pd+u2s6wO+uXiWZSrMweeTU1K+v2LwtR4aAd5j6JX1nDlSXPRH6 8ZEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ZBy2A4iE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t21-20020a05640203d500b00419101e3899si5550575edw.485.2022.04.18.01.05.33; Mon, 18 Apr 2022 01:05:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ZBy2A4iE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S233222AbiDQC3J (ORCPT + 99 others); Sat, 16 Apr 2022 22:29:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230493AbiDQC3H (ORCPT ); Sat, 16 Apr 2022 22:29:07 -0400 Received: from mail-qt1-x836.google.com (mail-qt1-x836.google.com [IPv6:2607:f8b0:4864:20::836]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CB7D2ED41; Sat, 16 Apr 2022 19:26:33 -0700 (PDT) Received: by mail-qt1-x836.google.com with SMTP id z15so8159131qtj.13; Sat, 16 Apr 2022 19:26:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=w8FEMTX/xuVcdhSUM8I8EwNIenSORDwi1yF5x5D0CQk=; b=ZBy2A4iECzemte2fKwK6r8t070Gm4ptN3hs9giRZhZcCNYPTt2iL3fOgu2FEN64Fgq SxftzRQMyDbl7IrsOK84dpF4S4Eah2v4o1wgwjJtg3i6/6fUt/a17xYAT3UAVssVn+6X nJkPc4e/ZdrvhmxQk7JwAe3g4cWqinDy6hTFIhl3I+GFQr4VAX6Qud2mC3INc/YM1tuX oOrBl0yOzvWMWDRMmTB8Jn9Pr2tCgJZxPJ134nit4KZJvv/k1IQ1oKidczYT4RkYBAbs rVzbn3AoJxyDwn0ix0HRPwMF9LNVtC8ssmRcGNvZQGFEHE1xtVSnhZX8LR6BKROYKMcb D1tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=w8FEMTX/xuVcdhSUM8I8EwNIenSORDwi1yF5x5D0CQk=; b=uvfCxyUI84tx8TeuJ0ssjzQWUxj82A6+mT5ZewP++ChjmaM1a+iHgOU13xwxntx/Hd MUqpZdFBRLbVJD2HQWFytmBaX0ElyJzkukzp7wd2gsG3lSFOZHwQn2cck5EBuDaKH7uP VfAg/DEAM+I6VE93LxqKcoMSV1g4b0uqqZ3yeEKgSxgWN8OWGgrhUVJPrMmPcZW3qm8s VcOvXzmKUU0mYw02Gb82mmp8fIuNMTUh/onIutWgnOr/8edc0X/N+pCSPPLNo9z50loW BS+ComIgFc9xwaj5k/mWm7+Be5oVR4MYyy07ZTjDFB1TSjn3khE7HSrKp6FqmivG0RlP vQJQ== X-Gm-Message-State: AOAM530xH+I+EJq4kHyKt1Vk/nTI3rl4rucaHhmpYWXWHcDPpsCsKWht Em7GGkY0UDBB2YBJCgIuLs8= X-Received: by 2002:a05:622a:1a11:b0:2f1:f173:b7cc with SMTP id f17-20020a05622a1a1100b002f1f173b7ccmr3511640qtb.318.1650162392472; Sat, 16 Apr 2022 19:26:32 -0700 (PDT) Received: from auth2-smtp.messagingengine.com (auth2-smtp.messagingengine.com. [66.111.4.228]) by smtp.gmail.com with ESMTPSA id m9-20020a05622a118900b002f1fc51135dsm91489qtk.57.2022.04.16.19.26.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Apr 2022 19:26:31 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailauth.nyi.internal (Postfix) with ESMTP id 8750127C0054; Sat, 16 Apr 2022 22:26:30 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Sat, 16 Apr 2022 22:26:30 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudelkedgiedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpeeuohhquhhn ucfhvghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtghomheqnecuggftrfgrth htvghrnhepheefudejueffjeelkedtgeelleelgfffhffhvdehtdekveehjeeivdejgedu udegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepsg hoqhhunhdomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqieelvdeghedtieeg qddujeejkeehheehvddqsghoqhhunhdrfhgvnhhgpeepghhmrghilhdrtghomhesfhhigi hmvgdrnhgrmhgv X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 16 Apr 2022 22:26:28 -0400 (EDT) Date: Sun, 17 Apr 2022 10:26:22 +0800 From: Boqun Feng To: Guo Ren Cc: Andrea Parri , Daniel Lustig , "Paul E. McKenney" , Arnd Bergmann , Palmer Dabbelt , Mark Rutland , Will Deacon , Peter Zijlstra , linux-arch , Linux Kernel Mailing List , linux-riscv , Guo Ren Subject: Re: [PATCH V2 0/3] riscv: atomic: Optimize AMO instructions usage Message-ID: References: <20220412034957.1481088-1-guoren@kernel.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="gsEGlVkScL5MXyzb" Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --gsEGlVkScL5MXyzb Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Apr 17, 2022 at 12:49:44AM +0800, Guo Ren wrote: [...] >=20 > If both the aq and rl bits are set, the atomic memory operation is > sequentially consistent and cannot be observed to happen before any > earlier memory operations or after any later memory operations in the > same RISC-V hart and to the same address domain. > "0: lr.w %[p], %[c]\n" > " sub %[rc], %[p], %[o]\n" > " bltz %[rc], 1f\n". > - " sc.w.rl %[rc], %[rc], %[c]\n" > + " sc.w.aqrl %[rc], %[rc], %[c]\n" > " bnez %[rc], 0b\n" > - " fence rw, rw\n" > "1:\n" > So .rl + fence rw, rw is over constraints, only using sc.w.aqrl is more p= roper. >=20 Can .aqrl order memory accesses before and after it (not against itself, against each other), i.e. act as a full memory barrier? For example, can we end up with u =3D=3D 1, v =3D=3D 1, r1 on P0 is 0 and r1 on P1 is 0, for= the following litmus test? C lr-sc-aqrl-pair-vs-full-barrier =20 {} =20 P0(int *x, int *y, atomic_t *u) { int r0; int r1; =20 WRITE_ONCE(*x, 1); r0 =3D atomic_cmpxchg(u, 0, 1); r1 =3D READ_ONCE(*y); } =20 P1(int *x, int *y, atomic_t *v) { int r0; int r1; =20 WRITE_ONCE(*y, 1); r0 =3D atomic_cmpxchg(v, 0, 1); r1 =3D READ_ONCE(*x); } =20 exists (u=3D1 /\ v=3D1 /\ 0:r1=3D0 /\ 1:r1=3D0) Regards, Boqun --gsEGlVkScL5MXyzb Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCAAdFiEEj5IosQTPz8XU1wRHSXnow7UH+rgFAmJbesoACgkQSXnow7UH +rie9Af/UTwzwnSrsPDa9Dt5IvnF9QCWblr10PoMYKlA7wHaAC7xRVicoRsmLAXF zIlFIQEcZdxH3/o7cVOtaFDRaNoY6q667AxcTP+vzwcTBoWIAvSo7kip2ZtTAtbE 8sj/bm+AiMfAet+sJ/I0gQNm3wPC3Q0MH5XcuGTpDZQlGny+/mB5s42Ii8vpt+UJ fgHdn8TqJ4m+PURvx8Rzumv9Uz6y6X8C4/VgZTNOVA3de1tcGw6kinIvOAML8F+v mAyg5MBo3DJ2Egh4aE1bzNvcfH97MbUJIAECztxhTKcgd77I16hBhhdtZoHRkZYR 6vmBhnqkQm8683s2qqt2HOUZlmrfJQ== =Fcy2 -----END PGP SIGNATURE----- --gsEGlVkScL5MXyzb--