[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260114000151.GB2178@quark>
Date: Tue, 13 Jan 2026 16:01:51 -0800
From: Eric Biggers <ebiggers@...nel.org>
To: Feng Jiang <jiangfeng@...inos.cn>
Cc: pjw@...nel.org, palmer@...belt.com, aou@...s.berkeley.edu,
alex@...ti.fr, kees@...nel.org, andy@...nel.org,
akpm@...ux-foundation.org, martin.petersen@...cle.com,
ardb@...nel.org, ajones@...tanamicro.com,
conor.dooley@...rochip.com, samuel.holland@...ive.com,
linus.walleij@...aro.org, nathan@...nel.org,
linux-riscv@...ts.infradead.org, linux-kernel@...r.kernel.org,
linux-hardening@...r.kernel.org
Subject: Re: [PATCH v2 01/14] lib/string: extract generic strlen() into
__generic_strlen()
On Tue, Jan 13, 2026 at 04:27:35PM +0800, Feng Jiang wrote:
> To support performance benchmarking in KUnit tests, extract the
> generic C implementation of strlen() into a standalone function
> __generic_strlen(). This allows tests to compare architecture-optimized
> versions against the generic baseline without duplicating code.
>
> Suggested-by: Andy Shevchenko <andy@...nel.org>
> Signed-off-by: Feng Jiang <jiangfeng@...inos.cn>
> ---
> include/linux/string.h | 1 +
> lib/string.c | 10 ++++++++--
> 2 files changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/string.h b/include/linux/string.h
> index 1b564c36d721..961645633b4d 100644
> --- a/include/linux/string.h
> +++ b/include/linux/string.h
> @@ -197,6 +197,7 @@ extern char * strstr(const char *, const char *);
> #ifndef __HAVE_ARCH_STRNSTR
> extern char * strnstr(const char *, const char *, size_t);
> #endif
> +extern __kernel_size_t __generic_strlen(const char *);
> #ifndef __HAVE_ARCH_STRLEN
> extern __kernel_size_t strlen(const char *);
> #endif
> diff --git a/lib/string.c b/lib/string.c
> index b632c71df1a5..047ecb38e09b 100644
> --- a/lib/string.c
> +++ b/lib/string.c
> @@ -412,8 +412,7 @@ char *strnchr(const char *s, size_t count, int c)
> EXPORT_SYMBOL(strnchr);
> #endif
>
> -#ifndef __HAVE_ARCH_STRLEN
> -size_t strlen(const char *s)
> +size_t __generic_strlen(const char *s)
> {
> const char *sc;
>
> @@ -421,6 +420,13 @@ size_t strlen(const char *s)
> /* nothing */;
> return sc - s;
> }
> +EXPORT_SYMBOL(__generic_strlen);
> +
> +#ifndef __HAVE_ARCH_STRLEN
> +size_t strlen(const char *s)
> +{
> + return __generic_strlen(s);
> +}
> EXPORT_SYMBOL(strlen);
A similar problem exists with the architecture-optimized CRC and crypto
functions. Historically, these subsystems exported both generic and
architecture-optimized functions.
We've actually been moving away from that design to simplify things.
For example, for CRC-32C there's now just the crc32c() function which
delegates to the "best" CRC-32C implementation, with no direct access to
the generic implementation of CRC-32C.
crc_kunit then just tests and benchmarks crc32c(). To check how the
performance of crc32c() changes when its implementation changes (whether
the change is the addition of an arch-optimized implementation or a
change in an existing arch-optimized implementation), the developer just
needs to run crc_kunit with two kernels, before and after.
I suggest just doing that. In that case there would be no need to
export the generic implementations of these functions.
(Also note that *if* the generic functions are exported, they probably
should be exported only when the KUnit test is enabled. There's no need
to include them in the kernel image when the test isn't enabled.)
- Eric
Powered by blists - more mailing lists