From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.51 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796184228; b=s4EC69boavMMGJUgeq/V5FNd618AC3MTdqxtlMgHJLcjH9eG1xTNXFhuNW7AWmhuKS0S tCynqYGQa6uh2dKrd49b0pAQ5HFSWzjEntWKJ2UgL5AHfiUarasfcq8GX2BvAfnefZsEC 1j0sMxOOE1/Ce47Wnqy9kXVNmRzORbJtT1VM8sJgwciW+Gb/DqmKckS/z8ZldiLa1rATT 60JHGQngMx5RY+j3vh1yaNn8DbuLU1JFtBi9L72kADEnV9I+r8EcyGAlclsvhqz8Tx1Jy PnOVAgjIhUFqSDqwgaCbnNshnUT+Hzn1Lcw1wdJv8Gvrd2NAL77fwAVz9IaTm4hVHWw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796184228; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=+NZS89a1fhawTTZCO0zoA0QNNxAXGNW0sPDYKGr7USg=; b=vqumyfVQopVGXc13YKB43hMwxP0+9J3eKCDYav086y6/162FvXytJFl8EcxU4JEzZgBI XJBCLaGFLdbHkWRRDmS//U3jJWBYN4HGQACLv6nThT82t2S7MlQo6RHJqcxHnSy0mCaEV qJ6iwOl6oblj4MqvxPkd563qa5a3L/a1GZm6YibaVH3z/vUGajudrA3J2YUrleH2QVNTg +dv+Gwo5OKbGXqrA4EQmv/2hjJA6ZoB9kNFAfVJ64tXmwEb52zMklAJVvMzYiBvHaYLaX 1e76e7Pt6z1UgKD0RqHksk93Cvy/jjmiFsWnZfPMlIMdF958pOQcRkLCSMRRbX9AHWw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=nAiKCXaA; arc=none smtp.remote-ip=74.125.82.51 Received: from mail-dl1-f51.google.com (mail-dl1-f51.google.com [74.125.82.51]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 509C2606A325 for ; Wed, 2 Dec 2026 04:03:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 509C2606A325 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=nAiKCXaA Received: by mail-dl1-f51.google.com with SMTP id a92af1059eb24-170135e43c7so6137546c88.0 for ; Tue, 01 Dec 2026 20:03:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796184227; x=1796789027; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=+NZS89a1fhawTTZCO0zoA0QNNxAXGNW0sPDYKGr7USg=; b=nAiKCXaAalyEQUOr4niiOgXP6ma2PJTLwRotBEV1JMLkHgc7sCkfjUMavtVN7EqVIV uC3LgSuGAojBrsULMmlpq45N2OrTqnWieiqjSNnVnX9VCNHXCJAxqyG9FdYogwiMbbad +Txu/SZK5REjl7EDERlGEpw8UR4FSr9alw36Ns6V/sfN4Wy5zXJEId0MMeivRtj20HEa aEfr9kzDQSH3REE8116QdsMxf/amXBsh16MVpXV/HyTwjgYkEgGdo5avWts2V9aQXp+h AYFkAbtAG23w3I/mlbS0pgNS5G+zwQf3LKW3JG/8viwz+5ld6dvs49AIH7QOYwHtHer8 K13A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796184227; x=1796789027; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=+NZS89a1fhawTTZCO0zoA0QNNxAXGNW0sPDYKGr7USg=; b=y0VX5PvdcCP91DuKaIiyDLGIiNWhD6sdhKnoyPfukpyPxhnGnK4u0rPRU7QngDZxzW aEvQVBYFZ8LzjH4XobB+23RdGAKlTLFW4xLsqGI5eIbtzem/ZbLziG8g5r+3LuV9bc3w rMNn7/1byb+qXq9PH1hwzG9WJZFwx2NIzrIWaFbayHCI/dtqG42TPB6dkE9oeAt/X5z6 lv04xdK29Kbjr05A+fRrznAkypdhezSBgYQSn6tNqaiLjH+5sXVVOpIhCJk7EEf+gpQg 7wUHxWGXNymJOO+mWjjjtCH5IadvOKj9c5+CqT/EWJEWHpiu6U5aafjbru3TWlX48wk3 GwPQ== X-Gm-Message-State: APuU4Z/QPI3wS+YhQRG1ue7LB+WGWXWFJsUVTDFpNOetkZwvbdFAIg3M /exMUlBVnRIHga8figdi+luQolldENbWDqOih/L55WVWwoXNkvdO0YTkmWvx9m9e X-Gm-Gg: AZFdTZcjcOk50hGu9HLIrHvSF4ZcRZPUE3Zkh3GsARck/h0Ww2OpwY9FwAM51LBQsTO c5B34sGYdupmI85Oxcy4C/dNj/mT87151qocT2X/mxIhBkETjHIvLDId8my3vQ8mywK124BYevI Mt49lfmTrKC3EezSu1aRtX4Gncokdxg1mluR4dBUyQ2xwJM2HWcK1OrkipHDB7ZKzEJHCKVSk1D LgTyjXAIwuWOGDbMeaTQOTO3Der8ezSGyNgXKzoJXxf/9F2FGVh32rR/tIj13BPisL9Rape7iFI zEWbWLTw6IH3YNJFstN3VQGuriumMLt+kR1h0+2gJqhZ6H20L4gQUJeHhKyalH3IlQIXpk+4e2r 28mrOn1LtpnWS8/Yyj6cEzy0lE8Hs8OUPDIsGWkWGy6Weo/IPPCb3wCkvg4Yp1EmUtiVB1VtTWD obHvNRVpW3mpHW2hnKoDgR/xy3vyrp5FZdZ+7uaJZyNitPHXimuupkVf6Iia2LA62qTQvS/0Lpc 1TLGAZ3xLOzjND/AxId6TJEKORCS9KXTJ4io3yNAFavBEy3oRDxtVZmyJPclxNktt3QicfPYVli Y9wo8gvKDg/kNB8J1EDy5GjkoMOQdcEwFLPXi6ikD1Bgnw2E8VI8MwMU03A9uKy4yeG1u9VlXvE M5AEss/rs27+S X-Received: by 2002:a05:7022:f907:b0:1b3:a8a3:c6de with SMTP id a92af1059eb24-1b5567f6835mr36369709c88.5.1796184227077; Tue, 01 Dec 2026 20:03:47 -0800 (PST) Received: from pop-os.tail4adac7.ts.net ([2601:647:4080:d44b:ad52:d54f:afd9:833a]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b55684c85fsm140420321c88.14.2026.12.01.20.03.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 20:03:46 -0800 (PST) From: Cong Wang To: linux-kernel@vger.kernel.org, Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti Cc: Andy Chiu , daichengrong , Troy Mitchell , linux-riscv@lists.infradead.org, Cong Wang Subject: [RFC PATCH 0/2] riscv: Use the vector registers for large memcpy() Date: Tue, 1 Dec 2026 20:03:42 -0800 Message-ID: <20261202040344.1259264-1-xiyou.wangcong@gmail.com> X-Mailer: git-send-email 2.43.0 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Cong Wang 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