Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp525398rdb; Thu, 21 Dec 2023 17:38:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IESy1jJZF78U97g2TPB1owfLGxNTt+Or0EzmiHycBzEawHLp9Ezso25gNOMKsisyxFmvwmG X-Received: by 2002:ad4:4ee6:0:b0:67a:38f3:10d9 with SMTP id dv6-20020ad44ee6000000b0067a38f310d9mr902161qvb.7.1703209085222; Thu, 21 Dec 2023 17:38:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703209085; cv=none; d=google.com; s=arc-20160816; b=QN8I+UXJ80CGZlXuAzn1HvIsqa1WSg5b+8FlXIi9wEQTLMhJW2F/lwNdEnEu1u02u7 xDMvgJ0Q4CASl0bGjWuY+kYohNnLSrJunbHPB+KMdy8jZj44xViIBjb3ZHoutG6A0UA6 UwutQRvxkLaxBnbaKZJ1b/0kU0VX7Fm2VfOfS+EU2+GwXdyLHDdEdQihHcdpiTILyzv8 hyCDlmjPAkcacqmj6HhVB6lVigceIF1bkNC6Ri7YQvlzr6Epktrz+Fh/fYhd4t57pi2O vNRxU8ugQB3JEw5dkyL0Rn6wjfCARNBCIosGQllRcP+69enN2U1bjTkh8BUU46tqLnot C23w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=/pHml5C4iB2UVOdNccbY5NzIin1Pbsu1DFBGnQ9mBxA=; fh=jmBDxm6hKlLYUQCfKgtnHR8t+9PkTlaty4Qcil1N8yU=; b=icT2s6eVyZrme0OIUin37Yis6EJANQ/nbBdW9a9/j1lx3kUWyKDvbRX170doH4R3ph kGU0gOSY0y5Yukk5mKtES1FbPHRHnDky8hr19syOaDTkgDzab3k75zg3JURpPYHj7wUg puF+LjDaE3VPqKuD6mcDVjcxt8jnq1tzSwILl+HqiBV2rg9gJimnWoJvvhXhZgftw5/r 6vbOw3gypN/DDqYUrSJA3Q1gXtI12+vJ688R+YrXgP9LiW81JlKBSyzuRppv9FpRkCk+ 8o2JKoZkIHLHbf2KmI5hy19HRQfi0WBP3YXlQsWKKzMGNiiuo7//QmX8Y7WAqGbIEGNd 5png== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=AYuKH2Pl; spf=pass (google.com: domain of linux-kernel+bounces-9247-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9247-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id bz7-20020ad44c07000000b0067f82185c5csi2598179qvb.606.2023.12.21.17.38.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 17:38:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9247-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=AYuKH2Pl; spf=pass (google.com: domain of linux-kernel+bounces-9247-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9247-linux.lists.archive=gmail.com@vger.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 E4F861C21AFE for ; Fri, 22 Dec 2023 01:38:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EFA0B2907; Fri, 22 Dec 2023 01:37:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="AYuKH2Pl" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 797FF23D5 for ; Fri, 22 Dec 2023 01:37:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-28bd734aab4so1142838a91.3 for ; Thu, 21 Dec 2023 17:37:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1703209074; x=1703813874; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=/pHml5C4iB2UVOdNccbY5NzIin1Pbsu1DFBGnQ9mBxA=; b=AYuKH2PlMSZpPlBghtdLi8cYjGAVnyVZYL8FmKRgRe6hdpEZrmiRFzLdHBX71SzWtx LNDjjt8JqX+KLduuugyHlnOuIKRjvS5PPLfZ2Zs5bKw+Ez8vdEC6fKxki5EbuPmaKngd 7YZAUSJK+m1eWSvSL2zN0XOXcJIm0fuuMXrFtjIehCslPXMXSqkNA0ONTGnEBtkbOWuK 0H3UKud96Mx8U4dBUBqWfbTgaTfGRAnOK6dg1DN9dWUHyZa7/1hlxgd0lZDNXuHq+QYC R4OfmBnDrqeXURs8I3eY2MJ6ZR75PY4S0GePVrRQkmKrLp0imBk5rWhGfkz3AGBp8nxg q9pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703209074; x=1703813874; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/pHml5C4iB2UVOdNccbY5NzIin1Pbsu1DFBGnQ9mBxA=; b=mXVLFL3uH+6NE3QNY/f7eqfcR6ihxBcmn4b/zoANEZxX2G67DkbO6X/gEb/su5fXur ScY1sW7LkEv/DzMhJWH14vpJySc7CY3rXqnPhyTeKzntv3p8DbiwLO/5yg1Ul0S6h7yu 4EEnx7Q6j36KkkzMSK/YIOroBAJ9tVGjIa51uSrfN4JDMsd/VvPz5EoXTasoFaFkIKzn W78iCIGAPDsf87kNyvgxMs9ytN3X9pN+C3Yx3VKEhV8Ev2Kdsb1ot2S+q1zP4mCaIF5r b9zh70u+gsKEAXyXlLmFR9zRuuxhtcREf6J0FedqFK894UHq8RmBb4WWb8dqIenVOMJs 6F/w== X-Gm-Message-State: AOJu0YxGeDAtI4gfPAjcjrf/jBeHCZhZ9GeNzsS3ftLWaZ5DOgI00OdW qy2QNZUR9Z47BTwXR1ECrwngdKcChkkl0A== X-Received: by 2002:a17:90a:6f43:b0:28b:9f7c:177 with SMTP id d61-20020a17090a6f4300b0028b9f7c0177mr513590pjk.18.1703209073698; Thu, 21 Dec 2023 17:37:53 -0800 (PST) Received: from ghost ([12.44.203.122]) by smtp.gmail.com with ESMTPSA id si6-20020a17090b528600b0028b5812c477sm6343572pjb.35.2023.12.21.17.37.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 17:37:53 -0800 (PST) Date: Thu, 21 Dec 2023 17:37:51 -0800 From: Charlie Jenkins To: Guo Ren Cc: Palmer Dabbelt , Conor Dooley , Samuel Holland , David Laight , Xiao Wang , Evan Green , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, Paul Walmsley , Albert Ou , Arnd Bergmann Subject: Re: [PATCH v13 2/5] riscv: Add static key for misaligned accesses Message-ID: References: <20231220-optimize_checksum-v13-0-a73547e1cad8@rivosinc.com> <20231220-optimize_checksum-v13-2-a73547e1cad8@rivosinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Fri, Dec 22, 2023 at 08:33:18AM +0800, Guo Ren wrote: > On Thu, Dec 21, 2023 at 7:38 AM Charlie Jenkins wrote: > > > > Support static branches depending on the value of misaligned accesses. > > This will be used by a later patch in the series. All cpus must be > > considered "fast" for this static branch to be flipped. > > > > Signed-off-by: Charlie Jenkins > > --- > > arch/riscv/include/asm/cpufeature.h | 2 ++ > > arch/riscv/kernel/cpufeature.c | 30 ++++++++++++++++++++++++++++++ > > 2 files changed, 32 insertions(+) > > > > diff --git a/arch/riscv/include/asm/cpufeature.h b/arch/riscv/include/asm/cpufeature.h > > index a418c3112cd6..7b129e5e2f07 100644 > > --- a/arch/riscv/include/asm/cpufeature.h > > +++ b/arch/riscv/include/asm/cpufeature.h > > @@ -133,4 +133,6 @@ static __always_inline bool riscv_cpu_has_extension_unlikely(int cpu, const unsi > > return __riscv_isa_extension_available(hart_isa[cpu].isa, ext); > > } > > > > +DECLARE_STATIC_KEY_FALSE(fast_misaligned_access_speed_key); > > + > > #endif > > diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c > > index b3785ffc1570..095eb6ebdcaa 100644 > > --- a/arch/riscv/kernel/cpufeature.c > > +++ b/arch/riscv/kernel/cpufeature.c > > @@ -10,6 +10,7 @@ > > #include > > #include > > #include > > +#include > > #include > > #include > > #include > > @@ -728,6 +729,35 @@ void riscv_user_isa_enable(void) > > csr_set(CSR_SENVCFG, ENVCFG_CBZE); > > } > > > > +DEFINE_STATIC_KEY_FALSE(fast_misaligned_access_speed_key); > > + > > +static int set_unaligned_access_static_branches(void) > > +{ > > + /* > > + * This will be called after check_unaligned_access_all_cpus so the > > + * result of unaligned access speed for all cpus will be available. > > + */ > > + > > + int cpu; > > + bool fast_misaligned_access_speed = true; > > + > > + for_each_online_cpu(cpu) { > Each online_cpu? Is there any offline_cpu that is no > fast_misaligned_access_speed? I think instead of checking offline cpus, it would make more sense to adjust the static branch when offline cpus come online. Since riscv_online_cpu is called when a new CPU comes online, I can update the static branch inside of that function. > > Move into your riscv_online_cpu for each CPU, and use stop_machine for > synchronization. > I do not understand what you mean by "Move into your riscv_online_cpu for each CPU", but I am assuming you are referring to updating the static branch inside of riscv_online_cpu. I believe any race condition that could be solved by stop_machine will become irrelevent by ensuring that the static branch is updated when a new cpu comes online. - Charlie > > + int this_perf = per_cpu(misaligned_access_speed, cpu); > > + > > + if (this_perf != RISCV_HWPROBE_MISALIGNED_FAST) { > > + fast_misaligned_access_speed = false; > > + break; > > + } > > + } > > + > > + if (fast_misaligned_access_speed) > > + static_branch_enable(&fast_misaligned_access_speed_key); > > + > > + return 0; > > +} > > + > > +arch_initcall_sync(set_unaligned_access_static_branches); > > + > > #ifdef CONFIG_RISCV_ALTERNATIVE > > /* > > * Alternative patch sites consider 48 bits when determining when to patch > > > > -- > > 2.43.0 > > > > > > > -- > Best Regards > Guo Ren