Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp503226rdb; Thu, 21 Dec 2023 16:33:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IFqvzRt9XtPXzyV/Ke7Fa6VZnD1QhqyfczB34ib9I9xp4e2aI4gwCKsIxoELC2LusaB2gc+ X-Received: by 2002:a2e:8ed8:0:b0:2cc:6acf:dd9 with SMTP id e24-20020a2e8ed8000000b002cc6acf0dd9mr195626ljl.89.1703205221289; Thu, 21 Dec 2023 16:33:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703205221; cv=none; d=google.com; s=arc-20160816; b=B8pEeUWNHdJdWr/6pJWFCF22xw3ydeHH1aMugHAY86QaCx0pfWPBrILZUpvIARY0RH 0OO8/yw2z7PJUozvjJNaVrj0vhcJuxOTGR7pBJRRzoJ/Vp+EUy03vX9ksBwZFxlZUuny QF3VnAsBucVLi7UBdFu8OXiZRGG51DDd9s1LxPnlttyYUqeHwcVGPvHq5qlUIFTWJOaC WSiCPPd06yZJYVLSkrvC7tJQuyZVnp4KXf/JDj4GdUtYlSiWtdXmamkCu+sP9wdjHLmZ iWeekgElNl2mDw3bWnzxv6h2W9AZhfhVIGUDGpeYjRIsd8mTCFFTlK8n9T6/gQsx4AvO w4SQ== 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=gT2S+IFWfDyvEzGcQ+UPG2TyLdjAdmz8TijtgL9n5Xs=; fh=mZpzoj7DuFKDTL0pme+XpUIk6D9/XM2SLlhUWu3EnaA=; b=fhvK4Rp4qgg5Ln7CDlvc7oBNNTY4f+Kte4HH+Ykj6qXlz/D+rVjbvrzcTYEFDomMd+ aOhpBrcVF5tsb+4lmy2FNSACLM2+WehhDjMfFw/QVl2oDPDydCC+belAFKHLmEjnQPwU wgB4JPAueWjkASlgHEVpeH/UABuJH/gKD1+5AGu7Olb6pdGr4UziwV2lm1wqfWjYpNa5 j91ziDfYYlDRPlkrNtWArTtK9Os6WIjaunEpm3SsYtWU3a9aVrECJmMTppqoiUeEQSkq uCqxyNDM6RFGTq440kWzw5XkJ9TOyqr+WD4y1or44c9Jb6z22v5R/Cd+VqlwsLnrSv6E aXWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VwT61Jw1; spf=pass (google.com: domain of linux-kernel+bounces-9208-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9208-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id w2-20020a056402268200b0054c4523f740si1329181edd.491.2023.12.21.16.33.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 16:33:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9208-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VwT61Jw1; spf=pass (google.com: domain of linux-kernel+bounces-9208-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9208-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 0D5901F23BDA for ; Fri, 22 Dec 2023 00:33:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 887671873; Fri, 22 Dec 2023 00:33:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VwT61Jw1" 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 B7E1D17C3; Fri, 22 Dec 2023 00:33:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2B9CBC433CC; Fri, 22 Dec 2023 00:33:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703205212; bh=DCqhY8G5czXPSCGceoCrCYsQxI4lJLYKd7y7x4FihOc=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=VwT61Jw1XQYHEa2vgWAYs1YoHWRO0S7hE7Htv1Ic0gxCEFWc0JYnVBTnXfvqX6avS jUJ6S9/rLOx0USXJDoa7SDnefPcILSXcFE6wDKsN4NNO9OoMi7KwoGlxnovMqMPgj2 oDypB3jIbd+6LeJvPKF3jO1e7YE9fz07sAExO7UXzLDJ+TILLAqsKhafsszWX2XvyZ os4QPe1VQCru8CxOejXi7ZSHZ3owJ8Y7CBT5EQeSXQroPYTMOu5t0LFcvYgqN2FI+H u9o2HpMzk8wQac4LTIziwTZAyl7uYmpZccVo56FfHumBTqhfMmFQNZy0DkrOqDOEjB SRmizus1ojIhQ== Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-5545139bed4so167681a12.2; Thu, 21 Dec 2023 16:33:32 -0800 (PST) X-Gm-Message-State: AOJu0YzMOkDmV2p8Wlu95LJJ/e+M9wFK1T9EhlDSgq8mrZf0jmPI2pbc 4IbLsHn+v/11yLaf/E6s7miSSW4ISQFT4fnMR+U= X-Received: by 2002:a50:cd16:0:b0:554:1171:4495 with SMTP id z22-20020a50cd16000000b0055411714495mr61774edi.23.1703205210523; Thu, 21 Dec 2023 16:33:30 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231220-optimize_checksum-v13-0-a73547e1cad8@rivosinc.com> <20231220-optimize_checksum-v13-2-a73547e1cad8@rivosinc.com> In-Reply-To: <20231220-optimize_checksum-v13-2-a73547e1cad8@rivosinc.com> From: Guo Ren Date: Fri, 22 Dec 2023 08:33:18 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v13 2/5] riscv: Add static key for misaligned accesses To: Charlie Jenkins 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Dec 21, 2023 at 7:38=E2=80=AFAM 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_u= nlikely(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/cpufeatur= e.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 t= he > + * result of unaligned access speed for all cpus will be availabl= e. > + */ > + > + int cpu; > + bool fast_misaligned_access_speed =3D true; > + > + for_each_online_cpu(cpu) { Each online_cpu? Is there any offline_cpu that is no fast_misaligned_access_speed? Move into your riscv_online_cpu for each CPU, and use stop_machine for synchronization. > + int this_perf =3D per_cpu(misaligned_access_speed, cpu); > + > + if (this_perf !=3D RISCV_HWPROBE_MISALIGNED_FAST) { > + fast_misaligned_access_speed =3D 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 pat= ch > > -- > 2.43.0 > > --=20 Best Regards Guo Ren