From: Eric Biggers <ebiggers@kernel.org>
To: Feng Jiang <jiangfeng@kylinos.cn>
Cc: pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu,
alex@ghiti.fr, kees@kernel.org, andy@kernel.org,
akpm@linux-foundation.org, martin.petersen@oracle.com,
ardb@kernel.org, ajones@ventanamicro.com,
conor.dooley@microchip.com, samuel.holland@sifive.com,
linus.walleij@linaro.org, nathan@kernel.org,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
linux-hardening@vger.kernel.org
Subject: Re: [PATCH v2 01/14] lib/string: extract generic strlen() into __generic_strlen()
Date: Tue, 13 Jan 2026 16:01:51 -0800 [thread overview]
Message-ID: <20260114000151.GB2178@quark> (raw)
In-Reply-To: <20260113082748.250916-2-jiangfeng@kylinos.cn>
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@kernel.org>
> Signed-off-by: Feng Jiang <jiangfeng@kylinos.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
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2026-01-14 0:02 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-13 8:27 [PATCH v2 00/14] riscv: optimize string functions and add kunit tests Feng Jiang
2026-01-13 8:27 ` [PATCH v2 01/14] lib/string: extract generic strlen() into __generic_strlen() Feng Jiang
2026-01-13 8:33 ` Andy Shevchenko
2026-01-14 0:01 ` Eric Biggers [this message]
2026-01-14 1:41 ` Feng Jiang
2026-01-14 7:07 ` Andy Shevchenko
2026-01-14 10:10 ` David Laight
2026-01-15 6:50 ` Feng Jiang
2026-01-15 6:55 ` Andy Shevchenko
2026-01-13 8:27 ` [PATCH v2 02/14] lib/string: extract generic strnlen() into __generic_strnlen() Feng Jiang
2026-01-13 8:27 ` [PATCH v2 03/14] lib/string: extract generic strchr() into __generic_strchr() Feng Jiang
2026-01-13 8:27 ` [PATCH v2 04/14] lib/string: extract generic strrchr() into __generic_strrchr() Feng Jiang
2026-01-13 8:27 ` [PATCH v2 05/14] lib/string_kunit: add correctness test for strlen Feng Jiang
2026-01-13 8:27 ` [PATCH v2 06/14] lib/string_kunit: add correctness test for strnlen Feng Jiang
2026-01-13 8:41 ` Andy Shevchenko
2026-01-13 8:27 ` [PATCH v2 07/14] lib/string_kunit: add correctness test for strrchr() Feng Jiang
2026-01-13 8:27 ` [PATCH v2 08/14] lib/string_kunit: add performance benchmark for strlen() Feng Jiang
2026-01-13 8:46 ` Andy Shevchenko
2026-01-14 6:14 ` Feng Jiang
2026-01-14 7:04 ` Feng Jiang
2026-01-14 7:21 ` Andy Shevchenko
2026-01-14 8:05 ` Feng Jiang
2026-01-14 10:21 ` David Laight
2026-01-15 6:24 ` Feng Jiang
2026-01-15 10:40 ` David Laight
2026-01-18 11:11 ` kernel test robot
2026-01-13 8:27 ` [PATCH v2 09/14] lib/string_kunit: add performance benchmark for strnlen() Feng Jiang
2026-01-13 8:27 ` [PATCH v2 10/14] lib/string_kunit: add performance benchmark for strchr() Feng Jiang
2026-01-13 8:27 ` [PATCH v2 11/14] lib/string_kunit: add performance benchmark for strrchr() Feng Jiang
2026-01-13 8:27 ` [PATCH v2 12/14] riscv: lib: add strnlen implementation Feng Jiang
2026-01-13 8:48 ` Andy Shevchenko
2026-01-13 8:27 ` [PATCH v2 13/14] riscv: lib: add strchr implementation Feng Jiang
2026-01-13 8:27 ` [PATCH v2 14/14] riscv: lib: add strrchr implementation Feng Jiang
2026-01-13 8:52 ` [PATCH v2 00/14] riscv: optimize string functions and add kunit tests Andy Shevchenko
2026-01-15 4:43 ` Joel Stanley
2026-01-19 9:24 ` Feng Jiang
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=20260114000151.GB2178@quark \
--to=ebiggers@kernel.org \
--cc=ajones@ventanamicro.com \
--cc=akpm@linux-foundation.org \
--cc=alex@ghiti.fr \
--cc=andy@kernel.org \
--cc=aou@eecs.berkeley.edu \
--cc=ardb@kernel.org \
--cc=conor.dooley@microchip.com \
--cc=jiangfeng@kylinos.cn \
--cc=kees@kernel.org \
--cc=linus.walleij@linaro.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=martin.petersen@oracle.com \
--cc=nathan@kernel.org \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
--cc=samuel.holland@sifive.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