From: Conor Dooley <conor.dooley@microchip.com>
To: Charlie Jenkins <charlie@rivosinc.com>
Cc: "Paul Walmsley" <paul.walmsley@sifive.com>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
"Albert Ou" <aou@eecs.berkeley.edu>,
"Jisheng Zhang" <jszhang@kernel.org>,
"Evan Green" <evan@rivosinc.com>,
"Clément Léger" <cleger@rivosinc.com>,
"Eric Biggers" <ebiggers@kernel.org>,
"Elliot Berman" <quic_eberman@quicinc.com>,
"Charles Lohr" <lohr85@gmail.com>,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v7 1/4] riscv: lib: Introduce has_fast_unaligned_access function
Date: Thu, 7 Mar 2024 07:49:17 +0000 [thread overview]
Message-ID: <20240307-coronary-snagged-cf3409df8f7a@wendy> (raw)
In-Reply-To: <20240306-disable_misaligned_probe_config-v7-1-6c90419e7a96@rivosinc.com>
[-- Attachment #1: Type: text/plain, Size: 3868 bytes --]
On Wed, Mar 06, 2024 at 12:00:01PM -0800, Charlie Jenkins wrote:
$subject: riscv: lib: Introduce has_fast_unaligned_access function
nit - s/ function/()/ & put the () after function names in commit
messages please.
> Create has_fast_unaligned_access to avoid needing to explicitly check
> the fast_misaligned_access_speed_key static key.
>
> Signed-off-by: Charlie Jenkins <charlie@rivosinc.com>
> Reviewed-by: Evan Green <evan@rivosinc.com>
Reviewed-by: Conor Dooley <conor.dooley@microchip.com>
Cheers,
Conor.
> ---
> arch/riscv/include/asm/cpufeature.h | 11 ++++++++---
> arch/riscv/kernel/cpufeature.c | 6 +++---
> arch/riscv/lib/csum.c | 7 ++-----
> 3 files changed, 13 insertions(+), 11 deletions(-)
>
> diff --git a/arch/riscv/include/asm/cpufeature.h b/arch/riscv/include/asm/cpufeature.h
> index 5a626ed2c47a..466e1f591919 100644
> --- a/arch/riscv/include/asm/cpufeature.h
> +++ b/arch/riscv/include/asm/cpufeature.h
> @@ -1,6 +1,6 @@
> /* SPDX-License-Identifier: GPL-2.0-only */
> /*
> - * Copyright 2022-2023 Rivos, Inc
> + * Copyright 2022-2024 Rivos, Inc
> */
>
> #ifndef _ASM_CPUFEATURE_H
> @@ -53,6 +53,13 @@ static inline bool check_unaligned_access_emulated(int cpu)
> static inline void unaligned_emulation_finish(void) {}
> #endif
>
> +DECLARE_STATIC_KEY_FALSE(fast_unaligned_access_speed_key);
> +
> +static __always_inline bool has_fast_unaligned_accesses(void)
> +{
> + return static_branch_likely(&fast_unaligned_access_speed_key);
> +}
> +
> unsigned long riscv_get_elf_hwcap(void);
>
> struct riscv_isa_ext_data {
> @@ -135,6 +142,4 @@ 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 89920f84d0a3..7878cddccc0d 100644
> --- a/arch/riscv/kernel/cpufeature.c
> +++ b/arch/riscv/kernel/cpufeature.c
> @@ -810,14 +810,14 @@ static void check_unaligned_access_nonboot_cpu(void *param)
> check_unaligned_access(pages[cpu]);
> }
>
> -DEFINE_STATIC_KEY_FALSE(fast_misaligned_access_speed_key);
> +DEFINE_STATIC_KEY_FALSE(fast_unaligned_access_speed_key);
>
> static void modify_unaligned_access_branches(cpumask_t *mask, int weight)
> {
> if (cpumask_weight(mask) == weight)
> - static_branch_enable_cpuslocked(&fast_misaligned_access_speed_key);
> + static_branch_enable_cpuslocked(&fast_unaligned_access_speed_key);
> else
> - static_branch_disable_cpuslocked(&fast_misaligned_access_speed_key);
> + static_branch_disable_cpuslocked(&fast_unaligned_access_speed_key);
> }
>
> static void set_unaligned_access_static_branches_except_cpu(int cpu)
> diff --git a/arch/riscv/lib/csum.c b/arch/riscv/lib/csum.c
> index af3df5274ccb..7178e0acfa22 100644
> --- a/arch/riscv/lib/csum.c
> +++ b/arch/riscv/lib/csum.c
> @@ -3,7 +3,7 @@
> * Checksum library
> *
> * Influenced by arch/arm64/lib/csum.c
> - * Copyright (C) 2023 Rivos Inc.
> + * Copyright (C) 2023-2024 Rivos Inc.
> */
> #include <linux/bitops.h>
> #include <linux/compiler.h>
> @@ -318,10 +318,7 @@ unsigned int do_csum(const unsigned char *buff, int len)
> * branches. The largest chunk of overlap was delegated into the
> * do_csum_common function.
> */
> - if (static_branch_likely(&fast_misaligned_access_speed_key))
> - return do_csum_no_alignment(buff, len);
> -
> - if (((unsigned long)buff & OFFSET_MASK) == 0)
> + if (has_fast_unaligned_accesses() || (((unsigned long)buff & OFFSET_MASK) == 0))
> return do_csum_no_alignment(buff, len);
>
> return do_csum_with_alignment(buff, len);
>
> --
> 2.43.2
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2024-03-07 7:50 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-06 20:00 [PATCH v7 0/4] riscv: Use Kconfig to set unaligned access speed Charlie Jenkins
2024-03-06 20:00 ` [PATCH v7 1/4] riscv: lib: Introduce has_fast_unaligned_access function Charlie Jenkins
2024-03-07 7:49 ` Conor Dooley [this message]
2024-03-06 20:00 ` [PATCH v7 2/4] riscv: Only check online cpus for emulated accesses Charlie Jenkins
2024-03-06 20:00 ` [PATCH v7 3/4] riscv: Decouple emulated unaligned accesses from access speed Charlie Jenkins
2024-03-07 7:54 ` Conor Dooley
2024-03-06 20:00 ` [PATCH v7 4/4] riscv: Set unaligned access speed at compile time Charlie Jenkins
2024-03-07 8:24 ` Conor Dooley
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240307-coronary-snagged-cf3409df8f7a@wendy \
--to=conor.dooley@microchip.com \
--cc=aou@eecs.berkeley.edu \
--cc=charlie@rivosinc.com \
--cc=cleger@rivosinc.com \
--cc=ebiggers@kernel.org \
--cc=evan@rivosinc.com \
--cc=jszhang@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=lohr85@gmail.com \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=quic_eberman@quicinc.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®