mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [RFC PATCH 0/2] riscv: Use the vector registers for large memcpy()
@ 2026-12-02  4:03 Cong Wang
  2026-12-02  4:03 ` [RFC PATCH 1/2] riscv: lib: Give the scalar memcpy() body a symbol of its own Cong Wang
  2026-12-02  4:03 ` [RFC PATCH 2/2] riscv: lib: Use the vector registers for large memcpy() Cong Wang
  0 siblings, 2 replies; 3+ messages in thread
From: Cong Wang @ 2026-12-02  4:03 UTC (permalink / raw)
  To: linux-kernel, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti
  Cc: Andy Chiu, daichengrong, Troy Mitchell, linux-riscv, Cong Wang

From: Cong Wang <cwang@multikernel.io>

Vectorized mem* routines were part of the kernel-mode vector series in
2023 and were dropped in v9 [1], because kernel_vector_begin() changes
state in the task struct and a memcpy() of that task struct (fork) then
copied the changed state. This series brings memcpy() back with a check
for that case: a copy that overlaps what a vector section writes to
stays scalar. memmove() and memset() are not touched.

Patch 1 gives the scalar memcpy() body its own symbol. Patch 2 adds the
entry sequence, the helper that decides, and the vector loop.

On a SpacemiT A100 core (1024-bit vectors) the vector copy is 1.3 times
faster at 8 KB and 3 times faster from 64 KB up. On a SpacemiT X100 core
(256-bit vectors) it gains much less: nothing below 16 KB, 1.3 times at
256 KB and above. Both tables are in patch 2.

Dependencies: the series applies on top of the first three patches of
"riscv: optimize mode switch latency for Vector" v7 [2]. The second
threshold in patch 2, for user vector state that is live in the
registers, relies on a system call leaving that state discarded, which
is what patch 3 of that series provides.

Testing: on a SpacemiT K3 board, with a backport of this series and of
its dependencies to 7.0, on both core types. The A100 cores are not
brought up by mainline and ran a kernel of their own, started with
out-of-tree patches. The kernel's riscv vector and sigreturn self tests
show no change. A test module, not part of this series, checks the data
of copies of 0 to 600 bytes and of larger sizes at all alignments,
that a copy at the threshold takes the vector path, and that a copy
stays scalar in each case where it has to.

[1] https://lore.kernel.org/linux-riscv/20231229143627.22898-1-andy.chiu@sifive.com/
[2] https://lore.kernel.org/linux-riscv/20261111184359.1239821-1-tchiu@tenstorrent.com/

---
Cong Wang (2):
  riscv: lib: Give the scalar memcpy() body a symbol of its own
  riscv: lib: Use the vector registers for large memcpy()

 arch/riscv/Kconfig                      |  10 +++
 arch/riscv/include/asm/asm-prototypes.h |   4 +
 arch/riscv/lib/Makefile                 |   1 +
 arch/riscv/lib/memcpy.S                 |  19 ++++-
 arch/riscv/lib/memcpy_vector.S          |  17 ++++
 arch/riscv/lib/riscv_v_helpers.c        | 102 ++++++++++++++++++++++--
 arch/riscv/purgatory/Makefile           |   2 +
 7 files changed, 147 insertions(+), 8 deletions(-)
 create mode 100644 arch/riscv/lib/memcpy_vector.S

-- 
2.43.0


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

end of thread, other threads:[~2026-12-02  4:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-02  4:03 [RFC PATCH 0/2] riscv: Use the vector registers for large memcpy() Cong Wang
2026-12-02  4:03 ` [RFC PATCH 1/2] riscv: lib: Give the scalar memcpy() body a symbol of its own Cong Wang
2026-12-02  4:03 ` [RFC PATCH 2/2] riscv: lib: Use the vector registers for large memcpy() Cong Wang

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®