Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp7451859rdb; Wed, 3 Jan 2024 17:25:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IEG/7EPk6Xn5kB9gVKB0PV23FR+4DBNe/DF/PdzyQ5ALnt5EPfkfP/118Nc429G5QvOESXC X-Received: by 2002:ac8:4e8d:0:b0:428:882f:5dac with SMTP id 13-20020ac84e8d000000b00428882f5dacmr192804qtp.33.1704331513401; Wed, 03 Jan 2024 17:25:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704331513; cv=none; d=google.com; s=arc-20160816; b=usGhctCwVOAmIQlFS5eSBNn2reyL/HZu3LG7ztNgoSkRAS89BnEUPOE3JqvM6ONnZP zq67lxOWfEEs2pJO1J5gb9/QHyPZsuHpcBudz383vym6ybLIiimGU5b2WZagLCD0J95m 9zWlco5PqVWdi4k7oNZkClKFhbIUoFxtsHPuRIgM39VpSxAIBkKXzrzJouVqZsohG3vH NOg9aiVjUE0D3RLmLKcAJJIJrErbP3USyk9dBQMwyGMO/1kW3Os9Hu3/4sNokgWbwEyP 5LVvS5Bx+qsdCTF6x2h9hc7kmunC+hHIpdcLIHI3r5L2Y8IDEiGjHxqRCBtC/n8YFvLM jkGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=kupo0d1GmqGtIMyERdL6lzAQOcPZfpGjR0z3lozbbzU=; fh=J5CYSLzAv55qI1WdAKTU31RF+nLU5kJwyDhOKXfokNs=; b=ZYLUZf6WAnlyZkjyCwpHcS/7VY6ozan+tHPkTclWIir4QTQDFT6n9pwDPwDW3PLCX4 eMAyywgl5hZlIqcwOctLYHlFzN/pWW1CgZKnn8DTw/AImsrS+ptFHtBT7/JkUm6cRzcB aDATE/LuMoKm86jS8NZrgvuDGYMFCjQGk8q4Oh0iI9Bkkr9fWcS25bp9pKWA3wN3rosy dvomBn+aoWGK96ruGE0BCT55WBg7OUw3hKHoHKBFKasvEx6lUmSEz4ZQcUAQLZXoSTj1 Qx34AOL5oWQvcMYvI93bfoEo4PDLjc+6qvJttgZA+we6OtjoCenzcnsskTPuq8ffr5Nb 4L9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tMrNfGBO; spf=pass (google.com: domain of linux-kernel+bounces-16177-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16177-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id j15-20020ac85f8f000000b004254e18956asi31078465qta.98.2024.01.03.17.25.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 17:25:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-16177-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tMrNfGBO; spf=pass (google.com: domain of linux-kernel+bounces-16177-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16177-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id E733B1C248F8 for ; Thu, 4 Jan 2024 01:25:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0CC40187A; Thu, 4 Jan 2024 01:24:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="tMrNfGBO" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 40A531852 for ; Thu, 4 Jan 2024 01:24:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AE0ECC4339A for ; Thu, 4 Jan 2024 01:24:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704331493; bh=kdiz8o8d/7k1J0F+igL00Zui4dSZF0XFj1b7FGHQtiE=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=tMrNfGBO3wHy4+Rjoro8wYszWNnfUkoML2TYONWJrvc2yNhclGP3TPSW4V5yCuzlb SeCem0UKZN0Uz20PKrQ2Ch1YKSqr8vnCl1pxgGtGqiaXc4ha6p/ZAipQu4IauJcbhf fgamOMFCveEszky6qY8IHTPUrTdT32SuV21n0UjCkrDazY5Dbkf6b2C96B8q2b/qSK bbPMuw5C29OYTYedG7S3d5l2aIgepAiqbpHlXRf3y8IDEwc15YPITq4vvuE3N8+d8X W7M04j3qjxhtpkyb0ggJEwU8T6HfgyWc23AiOrdr+hyb4St4v5VO5EHFMTAc7Ks6DZ b5y4L+IXauqPw== Received: by mail-ed1-f50.google.com with SMTP id 4fb4d7f45d1cf-556aa7fe765so41595a12.2 for ; Wed, 03 Jan 2024 17:24:53 -0800 (PST) X-Gm-Message-State: AOJu0YxIcNJ9xjDVdyJF2eukWjdafIkYMg8w+cgWzXUqzHMTvS/qdvjC 23nOH4LerdPnJo2HSD49eu8xnSux4Rkekz13wjw= X-Received: by 2002:a50:c182:0:b0:556:db12:af4b with SMTP id m2-20020a50c182000000b00556db12af4bmr803567edf.54.1704331491922; Wed, 03 Jan 2024 17:24:51 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231231082955.16516-1-guoren@kernel.org> <20231231082955.16516-4-guoren@kernel.org> <20240102-81391283df04c430d76c0eb0@orel> In-Reply-To: From: Guo Ren Date: Thu, 4 Jan 2024 09:24:40 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH V2 3/3] riscv: xchg: Prefetch the destination word for sc.w To: Leonardo Bras Cc: Andrew Jones , paul.walmsley@sifive.com, palmer@dabbelt.com, panqinglin2020@iscas.ac.cn, bjorn@rivosinc.com, conor.dooley@microchip.com, peterz@infradead.org, keescook@chromium.org, wuwei2016@iscas.ac.cn, xiaoguang.xing@sophgo.com, chao.wei@sophgo.com, unicorn_wang@outlook.com, uwu@icenowy.me, jszhang@kernel.org, wefu@redhat.com, atishp@atishpatra.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Guo Ren Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Jan 4, 2024 at 3:45=E2=80=AFAM Leonardo Bras w= rote: > > On Wed, Jan 03, 2024 at 02:15:45PM +0800, Guo Ren wrote: > > On Tue, Jan 2, 2024 at 7:19=E2=80=AFPM Andrew Jones wrote: > > > > > > On Sun, Dec 31, 2023 at 03:29:53AM -0500, guoren@kernel.org wrote: > > > > From: Guo Ren > > > > > > > > The cost of changing a cacheline from shared to exclusive state can= be > > > > significant, especially when this is triggered by an exclusive stor= e, > > > > since it may result in having to retry the transaction. > > > > > > > > This patch makes use of prefetch.w to prefetch cachelines for write > > > > prior to lr/sc loops when using the xchg_small atomic routine. > > > > > > > > This patch is inspired by commit: 0ea366f5e1b6 ("arm64: atomics: > > > > prefetch the destination word for write prior to stxr"). > > > > > > > > Signed-off-by: Guo Ren > > > > Signed-off-by: Guo Ren > > > > --- > > > > arch/riscv/include/asm/cmpxchg.h | 4 +++- > > > > 1 file changed, 3 insertions(+), 1 deletion(-) > > > > > > > > diff --git a/arch/riscv/include/asm/cmpxchg.h b/arch/riscv/include/= asm/cmpxchg.h > > > > index 26cea2395aae..d7b9d7951f08 100644 > > > > --- a/arch/riscv/include/asm/cmpxchg.h > > > > +++ b/arch/riscv/include/asm/cmpxchg.h > > > > @@ -10,6 +10,7 @@ > > > > > > > > #include > > > > #include > > > > +#include > > > > > > > > #define __arch_xchg_masked(prepend, append, r, p, n) = \ > > > > > > Are you sure this is based on v6.7-rc7? Because I don't see this macr= o. > > Oh, it is based on Leobras' patches. I would remove it in the next of v= ersion. > > I would say this next :) Thx for the grammar correction. > > > > > > > > > > ({ = \ > > > > @@ -23,6 +24,7 @@ > > > > = \ > > > > __asm__ __volatile__ ( = \ > > > > prepend = \ > > > > + PREFETCHW_ASM(%5) = \ > > > > "0: lr.w %0, %2\n" = \ > > > > " and %1, %0, %z4\n" = \ > > > > " or %1, %1, %z3\n" = \ > > > > @@ -30,7 +32,7 @@ > > > > " bnez %1, 0b\n" = \ > > > > append = \ > > > > : "=3D&r" (__retx), "=3D&r" (__rc), "+A" (*(__ptr32b))= \ > > > > - : "rJ" (__newx), "rJ" (~__mask) = \ > > > > + : "rJ" (__newx), "rJ" (~__mask), "rJ" (__ptr32b) = \ > > > > > > I'm pretty sure we don't want to allow the J constraint for __ptr32b. > > > > > > > : "memory"); = \ > > > > = \ > > > > r =3D (__typeof__(*(p)))((__retx & __mask) >> __s); = \ > > > > -- > > > > 2.40.1 > > > > > > > > > > Thanks, > > > drew > > > > > > > > -- > > Best Regards > > Guo Ren > > > > Nice patch :) > Any reason it's not needed in __arch_cmpxchg_masked(), and __arch_cmpxchg= () ? CAS is a conditional AMO, unlike xchg (Stand AMO). Arm64 is wrong, or they have a problem with the hardware. > > Thanks! > Leo > --=20 Best Regards Guo Ren