public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 0/5] riscv: Add fine-tuned checksum functions
@ 2023-09-11 22:57 Charlie Jenkins
  2023-09-11 22:57 ` [PATCH v4 1/5] riscv: Checksum header Charlie Jenkins
                   ` (4 more replies)
  0 siblings, 5 replies; 24+ messages in thread
From: Charlie Jenkins @ 2023-09-11 22:57 UTC (permalink / raw)
  To: Charlie Jenkins, Palmer Dabbelt, Conor Dooley, Samuel Holland,
	David Laight, linux-riscv, linux-kernel
  Cc: Paul Walmsley, Albert Ou

Each architecture generally implements fine-tuned checksum functions to
leverage the instruction set. This patch adds the main checksum
functions that are used in networking.

Vector support is included in this patch to start a discussion on that,
it can probably be optimized more. The vector patches still need some
work as they rely on GCC vector intrinsics types which cannot work in
the kernel since it requires C vector support rather than just assembler
support. I have tested the vector patches as standalone algorithms in QEMU.

This patch takes heavy use of the Zbb extension using alternatives
patching.

To test this patch, enable the configs for KUNIT, then CHECKSUM_KUNIT
and RISCV_CHECKSUM_KUNIT.

I have attempted to make these functions as optimal as possible, but I
have not ran anything on actual riscv hardware. My performance testing
has been limited to inspecting the assembly, running the algorithms on
x86 hardware, and running in QEMU.

ip_fast_csum is a relatively small function so even though it is
possible to read 64 bits at a time on compatible hardware, the
bottleneck becomes the clean up and setup code so loading 32 bits at a
time is actually faster.

Signed-off-by: Charlie Jenkins <charlie@rivosinc.com>
---
Changes in v4:
- Suggestion by David Laight to use an improved checksum used in
  arch/arc.
- Eliminates zero-extension on rv32, but not on rv64.
- Reduces data dependency which should improve execution speed on
  rv32 and rv64
- Still passes CHECKSUM_KUNIT and RISCV_CHECKSUM_KUNIT on rv32 and
  rv64 with and without zbb.
- Link to v3: https://lore.kernel.org/r/20230907-optimize_checksum-v3-0-c502d34d9d73@rivosinc.com

Changes in v3:
- Use riscv_has_extension_likely and has_vector where possible (Conor)
- Reduce ifdefs by using IS_ENABLED where possible (Conor)
- Use kernel_vector_begin in the vector code (Samuel)
- Link to v2: https://lore.kernel.org/r/20230905-optimize_checksum-v2-0-ccd658db743b@rivosinc.com

Changes in v2:
- After more benchmarking, rework functions to improve performance.
- Remove tests that overlapped with the already existing checksum
  tests and make tests more extensive.
- Use alternatives to activate code with Zbb and vector extensions
- Link to v1: https://lore.kernel.org/r/20230826-optimize_checksum-v1-0-937501b4522a@rivosinc.com

---
Charlie Jenkins (5):
      riscv: Checksum header
      riscv: Add checksum library
      riscv: Vector checksum header
      riscv: Vector checksum library
      riscv: Test checksum functions

 arch/riscv/Kconfig.debug              |   1 +
 arch/riscv/include/asm/checksum.h     | 181 +++++++++++++++++++
 arch/riscv/lib/Kconfig.debug          |  31 ++++
 arch/riscv/lib/Makefile               |   3 +
 arch/riscv/lib/csum.c                 | 302 +++++++++++++++++++++++++++++++
 arch/riscv/lib/riscv_checksum_kunit.c | 330 ++++++++++++++++++++++++++++++++++
 6 files changed, 848 insertions(+)
---
base-commit: af3c30d33476bc2694b0d699173544b07f7ae7de
change-id: 20230804-optimize_checksum-db145288ac21
-- 
- Charlie


^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2023-09-14 23:31 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-11 22:57 [PATCH v4 0/5] riscv: Add fine-tuned checksum functions Charlie Jenkins
2023-09-11 22:57 ` [PATCH v4 1/5] riscv: Checksum header Charlie Jenkins
2023-09-12 10:24   ` Emil Renner Berthing
2023-09-13  2:38     ` Charlie Jenkins
2023-09-13  9:19       ` Emil Renner Berthing
2023-09-11 22:57 ` [PATCH v4 2/5] riscv: Add checksum library Charlie Jenkins
2023-09-12  8:45   ` David Laight
2023-09-13  3:09     ` Charlie Jenkins
2023-09-13  8:47       ` David Laight
2023-09-13 23:18         ` Charlie Jenkins
2023-09-14  0:41           ` Charlie Jenkins
2023-09-14 12:25   ` Conor Dooley
2023-09-14 17:58     ` Charlie Jenkins
2023-09-14 18:02       ` Conor Dooley
2023-09-14 23:30         ` Charlie Jenkins
2023-09-11 22:57 ` [PATCH v4 3/5] riscv: Vector checksum header Charlie Jenkins
2023-09-11 22:57 ` [PATCH v4 4/5] riscv: Vector checksum library Charlie Jenkins
2023-09-14 12:46   ` Conor Dooley
2023-09-14 16:14     ` Charlie Jenkins
2023-09-14 16:29       ` Conor Dooley
2023-09-14 17:29         ` Charlie Jenkins
2023-09-14 17:36           ` Conor Dooley
2023-09-14 20:59             ` Charlie Jenkins
2023-09-11 22:57 ` [PATCH v4 5/5] riscv: Test checksum functions Charlie Jenkins

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox