mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Cong Wang <xiyou.wangcong@gmail.com>
To: linux-kernel@vger.kernel.org, Paul Walmsley <pjw@kernel.org>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Albert Ou <aou@eecs.berkeley.edu>,
	Alexandre Ghiti <alex@ghiti.fr>
Cc: Andy Chiu <tchiu@tenstorrent.com>,
	daichengrong <daichengrong@iscas.ac.cn>,
	Troy Mitchell <troy@kernel.org>,
	linux-riscv@lists.infradead.org, Cong Wang <cwang@multikernel.io>
Subject: [RFC PATCH 0/2] riscv: Use the vector registers for large memcpy()
Date: Tue,  1 Dec 2026 20:03:42 -0800	[thread overview]
Message-ID: <20261202040344.1259264-1-xiyou.wangcong@gmail.com> (raw)

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


             reply	other threads:[~2026-12-02  4:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  4:03 Cong Wang [this message]
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

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=20261202040344.1259264-1-xiyou.wangcong@gmail.com \
    --to=xiyou.wangcong@gmail.com \
    --cc=alex@ghiti.fr \
    --cc=aou@eecs.berkeley.edu \
    --cc=cwang@multikernel.io \
    --cc=daichengrong@iscas.ac.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=palmer@dabbelt.com \
    --cc=pjw@kernel.org \
    --cc=tchiu@tenstorrent.com \
    --cc=troy@kernel.org \
    /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®