riscv: Add fine-tuned checksum functions
v2 cover riscv: Add fine-tuned checksum functions
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.
---
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/[email protected]
---
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 | 194 ++++++++++++++++++++ arch/riscv/lib/Kconfig.debug | 31 ++++ arch/riscv/lib/Makefile | 3 + arch/riscv/lib/csum.c | 333 ++++++++++++++++++++++++++++++++++ arch/riscv/lib/riscv_checksum_kunit.c | 330 +++++++++++++++++++++++++++++++++ 6 files changed, 892 insertions(+)
---
base-commit: 65d6e954e37872fd9afb5ef3fc0481bb3c2f20f4
change-id: 20230804-optimize_checksum-db145288ac21
Signature · 1 line
- Charlie
PATCH v2 1/5 riscv: Checksum header
Provide checksum algorithms that have been designed to leverage riscv instructions such as rotate. In 64-bit, can take advantage of the larger register to avoid some overflow checking.
--- arch/riscv/include/asm/checksum.h | 96 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+)
arch/riscv/include/asm/checksum.h new file +96 -0
@@ -0,0 +1,96 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* IP checksum routines +* +* Copyright (C) 2023 Rivos Inc. +*/ +#ifndef __ASM_RISCV_CHECKSUM_H +#define __ASM_RISCV_CHECKSUM_H + +#include <linux/in6.h> +#include <linux/uaccess.h> + +#ifdef CONFIG_32BIT +typedef unsigned int csum_t ; +#else +typedef unsigned long csum_t ; +#endif + +/* +* Fold a partial checksum without adding pseudo headers +*/ +static inline __sum16 csum_fold (__wsum sum) +{ + sum += (sum >>16 ) | (sum <<16 ); +return (__force __sum16)(~(sum >>16 )); +} + +#define csum_fold csum_fold + +/* +* Quickly compute an IP checksum with the assumption that IPv4 headers will +* always be in multiples of 32-bits, and have an ihl of at least 5. +* @ihl is the number of 32 bit segments and must be greater than or equal to 5. +* @iph is assumed to be word aligned. +*/ +static inline __sum16 ip_fast_csum (const void *iph,unsigned int ihl) +{ +csum_t csum =0 ; +int pos =0 ; + +do { + csum += ((const unsigned int *)iph)[pos]; +#ifdef CONFIG_32BIT + csum += csum < ((const unsigned int *)iph)[pos]; +#endif // !CONFIG_32BIT + }while (++pos < ihl); + +#ifdef CONFIG_RISCV_ISA_ZBB +if (IS_ENABLED (CONFIG_RISCV_ALTERNATIVE )) { +csum_t fold_temp; + +asm_volatile_goto (ALTERNATIVE ("j %l[no_zbb]" ,"nop" ,0 , +RISCV_ISA_EXT_ZBB ,1 ) + : + : + : + : no_zbb); +#ifdef CONFIG_32BIT + asm(".option push \n\ +.option arch,+zbb \n\ +rori %[fold_temp],%[csum],16 \n\ +add %[csum],%[fold_temp],%[csum] \n\ +.option pop" + : [csum]"+r" (csum), [fold_temp]"=&r" (fold_temp)); +#else // !CONFIG_32BIT + asm(".option push \n\ +.option arch,+zbb \n\ +rori %[fold_temp], %[csum], 32 \n\ +add %[csum], %[fold_temp], %[csum] \n\ +srli %[csum], %[csum], 32 \n\ +roriw %[fold_temp], %[csum], 16 \n\ +addw %[csum], %[fold_temp], %[csum] \n\ +.option pop" + : [csum]"+r" (csum), [fold_temp]"=&r" (fold_temp)); +#endif // !CONFIG_32BIT +return ~(csum >>16 ); + } +/* +* ZBB only saves three instructions on 32-bit and five on 64-bit so not +* worth checking if supported without Alternatives. +*/ +no_zbb: +#endif // CONFIG_RISCV_ISA_ZBB +#ifdef CONFIG_32BIT +#else // !CONFIG_32BIT + csum += (csum >>32 ) | (csum <<32 ); + csum >>=16 ; +#endif // !CONFIG_32BIT +return csum_fold ((__force __wsum )csum); +} + +#define ip_fast_csum ip_fast_csum + +#include <asm-generic/checksum.h> + +#endif // __ASM_RISCV_CHECKSUM_H
Signature · 1 line
2.42.0
Re: [PATCH v2 1/5] riscv: Checksum header
Hey Charlie,
Just a passing thought that I can't really test since I am meant to be on holidays...
Quoted 50 lines · Charlie Jenkins
Provide checksum algorithms that have been designed to leverage riscv instructions such as rotate. In 64-bit, can take advantage of the larger register to avoid some overflow checking.
Signed-off-by Charlie Jenkins <[email protected]>--- arch/riscv/include/asm/checksum.h | 96 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+)arch/riscv/include/asm/checksum.h new file +35
-0@@ -0,0 +1,96 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* IP checksum routines +* +* Copyright (C) 2023 Rivos Inc. +*/ +#ifndef __ASM_RISCV_CHECKSUM_H +#define __ASM_RISCV_CHECKSUM_H + +#include <linux/in6.h> +#include <linux/uaccess.h> + +#ifdef CONFIG_32BIT +typedef unsigned int csum_t ; +#else +typedef unsigned long csum_t ; +#endif + +/* +* Fold a partial checksum without adding pseudo headers +*/ +static inline __sum16 csum_fold (__wsum sum) +{ + sum += (sum >>16 ) | (sum <<16 ); +return (__force __sum16)(~(sum >>16 )); +} + +#define csum_fold csum_fold + +/* +* Quickly compute an IP checksum with the assumption that IPv4 headers will +* always be in multiples of 32-bits, and have an ihl of at least 5. +* @ihl is the number of 32 bit segments and must be greater than or equal to 5. +* @iph is assumed to be word aligned. +*/
arch/riscv/include/asm/checksum.h line 45
Quoted 10 lines
arch/riscv/include/asm/checksum.h new file +10
-0+static inline __sum16 ip_fast_csum (const void *iph,unsigned int ihl) +{ +csum_t csum =0 ; +int pos =0 ; + + do { + csum += ((const unsigned int *)iph)[pos]; +#ifdef CONFIG_32BIT + csum += csum < ((const unsigned int *)iph)[pos]; +#endif // !CONFIG_32BIT
Some of this ifdeffery really should become IS_ENABLED(), there's nothing in some of them that can't just get removed by the compiler.
arch/riscv/include/asm/checksum.h line 48
Quoted 3 lines
arch/riscv/include/asm/checksum.h new file +3
-0+ }while (++pos < ihl); + +#ifdef CONFIG_RISCV_ISA_ZBB
This here I can't test since I'm supposed to be AFK, but can this also be an IS_ENABLED()? I know it is guarding code that the toolchain may not support, but does it get removed before that matters?
I mainly ask because there's a host of ifdeffery here & the code would be a lot easier to understand if we could cut it down to a minimum.
Quoted 17 lines
arch/riscv/include/asm/checksum.h new file +17
-0+if (IS_ENABLED (CONFIG_RISCV_ALTERNATIVE )) { +csum_t fold_temp; + +asm_volatile_goto (ALTERNATIVE ("j %l[no_zbb]" ,"nop" ,0 , +RISCV_ISA_EXT_ZBB ,1 ) + : + : + : + : no_zbb); +#ifdef CONFIG_32BIT + asm(".option push \n\ +.option arch,+zbb \n\ +rori %[fold_temp],%[csum],16 \n\ +add %[csum],%[fold_temp],%[csum] \n\ +.option pop" + : [csum]"+r" (csum), [fold_temp]"=&r" (fold_temp)); +#else // !CONFIG_32BIT
arch/riscv/include/asm/checksum.h line 75
Quoted 10 lines
arch/riscv/include/asm/checksum.h new file +10
-0+ asm(".option push \n\ +.option arch,+zbb \n\ +rori %[fold_temp], %[csum], 32 \n\ +add %[csum], %[fold_temp], %[csum] \n\ +srli %[csum], %[csum], 32 \n\ +roriw %[fold_temp], %[csum], 16 \n\ +addw %[csum], %[fold_temp], %[csum] \n\ +.option pop" + : [csum]"+r" (csum), [fold_temp]"=&r" (fold_temp)); +#endif // !CONFIG_32BIT
These 3 I think are pretty easy to follow immediately, but...
arch/riscv/include/asm/checksum.h line 88
Quoted 13 lines
arch/riscv/include/asm/checksum.h new file +13
-0+ return ~(csum >> 16); + } +/* +* ZBB only saves three instructions on 32-bit and five on 64-bit so not +* worth checking if supported without Alternatives. +*/ +no_zbb: +#endif // CONFIG_RISCV_ISA_ZBB +#ifdef CONFIG_32BIT +#else // !CONFIG_32BIT + csum += (csum >>32 ) | (csum <<32 ); + csum >>=16 ; +#endif // !CONFIG_32BIT
...these ones here could be converted too, afaict.
Thanks,
Conor.
Quoted 12 lines
arch/riscv/include/asm/checksum.h new file +8
-0+ return csum_fold((__force __wsum)csum); +} + +#define ip_fast_csum ip_fast_csum + +#include <asm-generic/checksum.h> + +#endif // __ASM_RISCV_CHECKSUM_H Signature · 2 lines
-- 2.42.0
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v2 1/5] riscv: Checksum header
Quoted 127 lines · Conor Dooley
Hey Charlie,
Just a passing thought that I can't really test since I am meant to be on holidays...
Quoted 50 lines · Charlie Jenkins
Provide checksum algorithms that have been designed to leverage riscv instructions such as rotate. In 64-bit, can take advantage of the larger register to avoid some overflow checking.
Signed-off-by Charlie Jenkins <[email protected]>--- arch/riscv/include/asm/checksum.h | 96 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+)arch/riscv/include/asm/checksum.h new file +35
-0@@ -0,0 +1,96 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* IP checksum routines +* +* Copyright (C) 2023 Rivos Inc. +*/ +#ifndef __ASM_RISCV_CHECKSUM_H +#define __ASM_RISCV_CHECKSUM_H + +#include <linux/in6.h> +#include <linux/uaccess.h> + +#ifdef CONFIG_32BIT +typedef unsigned int csum_t ; +#else +typedef unsigned long csum_t ; +#endif + +/* +* Fold a partial checksum without adding pseudo headers +*/ +static inline __sum16 csum_fold (__wsum sum) +{ + sum += (sum >>16 ) | (sum <<16 ); +return (__force __sum16)(~(sum >>16 )); +} + +#define csum_fold csum_fold + +/* +* Quickly compute an IP checksum with the assumption that IPv4 headers will +* always be in multiples of 32-bits, and have an ihl of at least 5. +* @ihl is the number of 32 bit segments and must be greater than or equal to 5. +* @iph is assumed to be word aligned. +*/ arch/riscv/include/asm/checksum.h line 45
Quoted 10 lines
arch/riscv/include/asm/checksum.h new file +10
-0+static inline __sum16 ip_fast_csum (const void *iph,unsigned int ihl) +{ +csum_t csum =0 ; +int pos =0 ; + + do { + csum += ((const unsigned int *)iph)[pos]; +#ifdef CONFIG_32BIT + csum += csum < ((const unsigned int *)iph)[pos]; +#endif // !CONFIG_32BITSome of this ifdeffery really should become
IS_ENABLED(), there's nothing in some of them that can't just get removed by the compiler.arch/riscv/include/asm/checksum.h line 48
Quoted 3 lines
arch/riscv/include/asm/checksum.h new file +3
-0+ }while (++pos < ihl); + +#ifdef CONFIG_RISCV_ISA_ZBB This here I can't test since I'm supposed to be AFK, but can this also be an
IS_ENABLED()? I know it is guarding code that the toolchain may not support, but does it get removed before that matters?I mainly ask because there's a host of ifdeffery here & the code would be a lot easier to understand if we could cut it down to a minimum.
Quoted 17 lines
arch/riscv/include/asm/checksum.h new file +17
-0+if (IS_ENABLED (CONFIG_RISCV_ALTERNATIVE )) { +csum_t fold_temp; + +asm_volatile_goto (ALTERNATIVE ("j %l[no_zbb]" ,"nop" ,0 , +RISCV_ISA_EXT_ZBB ,1 ) + : + : + : + : no_zbb); +#ifdef CONFIG_32BIT + asm(".option push \n\ +.option arch,+zbb \n\ +rori %[fold_temp],%[csum],16 \n\ +add %[csum],%[fold_temp],%[csum] \n\ +.option pop" + : [csum]"+r" (csum), [fold_temp]"=&r" (fold_temp)); +#else // !CONFIG_32BIT arch/riscv/include/asm/checksum.h line 75
Quoted 10 lines
arch/riscv/include/asm/checksum.h new file +10
-0+ asm(".option push \n\ +.option arch,+zbb \n\ +rori %[fold_temp], %[csum], 32 \n\ +add %[csum], %[fold_temp], %[csum] \n\ +srli %[csum], %[csum], 32 \n\ +roriw %[fold_temp], %[csum], 16 \n\ +addw %[csum], %[fold_temp], %[csum] \n\ +.option pop" + : [csum]"+r" (csum), [fold_temp]"=&r" (fold_temp)); +#endif // !CONFIG_32BIT These 3 I think are pretty easy to follow immediately, but...
arch/riscv/include/asm/checksum.h line 88
Quoted 13 lines
arch/riscv/include/asm/checksum.h new file +13
-0+ return ~(csum >> 16); + } +/* +* ZBB only saves three instructions on 32-bit and five on 64-bit so not +* worth checking if supported without Alternatives. +*/ +no_zbb: +#endif // CONFIG_RISCV_ISA_ZBB +#ifdef CONFIG_32BIT +#else // !CONFIG_32BIT + csum += (csum >>32 ) | (csum <<32 ); + csum >>=16 ; +#endif // !CONFIG_32BIT ...these ones here could be converted too, afaict.
Quoted 3 lines
Thanks,
Conor.
That should make it look much cleaner, I will switch over to IS_ENABLED.
- Charlie
Quoted 9 lines
Quoted 9 lines
arch/riscv/include/asm/checksum.h new file +8
-0+ return csum_fold((__force __wsum)csum); +} + +#define ip_fast_csum ip_fast_csum + +#include <asm-generic/checksum.h> + +#endif // __ASM_RISCV_CHECKSUM_H
Quoted 3 lines
Quoted 3 lines
Signature · 1 line
2.42.0
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
RE: [PATCH v2 1/5] riscv: Checksum header
...
Quoted 8 lines
Quoted 8 lines
arch/riscv/include/asm/checksum.h line 26
Quoted 8 lines
arch/riscv/include/asm/checksum.h new file +8
-0+/* +* Fold a partial checksum without adding pseudo headers +*/ +static inline __sum16 csum_fold (__wsum sum) +{ + sum += (sum >>16 ) | (sum <<16 ); +return (__force __sum16)(~(sum >>16 )); +}
I'm intrigued, gcc normally compiler that quite well. The very similar (from arch/arc):
return (~sum - rol32(sum, 16)) >> 16;
is slightly better on most architectures. (Especially if the ~sum and rol() can be executed together.)
The only odd archs I saw were sparc32 (carry flag bug no rotate) and arm (barrel shifter on all instructions).
It is better than the current asm for a lot of archs including x64.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
Re: [PATCH v2 1/5] riscv: Checksum header
Quoted 12 lines · David Laight
...
Quoted 8 lines
Quoted 8 lines
arch/riscv/include/asm/checksum.h line 26
Quoted 8 lines
arch/riscv/include/asm/checksum.h new file +8
-0+/* +* Fold a partial checksum without adding pseudo headers +*/ +static inline __sum16 csum_fold (__wsum sum) +{ + sum += (sum >>16 ) | (sum <<16 ); +return (__force __sum16)(~(sum >>16 )); +}I'm intrigued, gcc normally compiler that quite well. The very similar (from
arch/arc):
Quoted 3 lines
return (~sum - rol32(sum, 16)) >> 16;is slightly better on most architectures. (Especially if the ~sum and
rol()can be executed together.)
Oh wow that solves the problem of needing to zero extend the result after taking the not. Taking the shift after the not both zero-extends and places the result in the correct spot. It is a very interesting property that it is possible to change the order of the operations if the addition becomes a subtraction. I will make the change. Thank you!
- Charlie
Quoted 4 lines
The only odd archs I saw were sparc32 (carry flag bug no rotate) and arm (barrel shifter on all instructions).
Quoted 8 lines
It is better than the current asm for a lot of archs including x64.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH v2 2/5 riscv: Add checksum library
In reply to Charlie JenkinsProvide a 32 and 64 bit version of do_csum. When compiled for 32-bit will load from the buffer in groups of 32 bits, and when compiled for 64-bit will load in groups of 64 bits. Benchmarking by proxy compiling csum_ipv6_magic (64-bit version) for an x86 chip as well as running the riscv generated code in QEMU, discovered that summing in a tree-like structure is about 4% faster than doing 64-bit reads.
--- arch/riscv/include/asm/checksum.h | 11 ++ arch/riscv/lib/Makefile | 1 + arch/riscv/lib/csum.c | 227 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 239 insertions(+)
arch/riscv/include/asm/checksum.h +11 -0
@@ -16,6 +16,14 @@ typedef unsigned int csum_t;typedef unsigned long csum_t ;#endif +/* Default version is sufficient for 32 bit */ +#ifdef CONFIG_64BIT +#define _HAVE_ARCH_IPV6_CSUM +__sum16 csum_ipv6_magic (const struct in6_addr *saddr, +const struct in6_addr *daddr, +__u32 len,__u8 proto,__wsum sum); +#endif +/* * Fold a partial checksum without adding pseudo headers */
@@ -91,6 +99,9 @@ static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl)#define ip_fast_csum ip_fast_csum +extern unsigned int do_csum (const unsigned char *buff,int len); +#define do_csum do_csum +#include <asm-generic/checksum.h> #endif // __ASM_RISCV_CHECKSUM_H
arch/riscv/lib/Makefile +1 -0
@@ -6,6 +6,7 @@ lib-y += memmove.o lib-y += strcmp.o lib-y += strlen.o lib-y += strncmp.o +lib-y += csum.o lib-$(CONFIG_MMU) += uaccess.o lib-$(CONFIG_64BIT) += tishift.o lib-$(CONFIG_RISCV_ISA_ZICBOZ) += clear_page.o
arch/riscv/lib/csum.c new file +227 -0
227 lines not on this page · raw message
Signature · 1 line
2.42.0
Re: [PATCH v2 2/5] riscv: Add checksum library
Quoted 7 lines · Charlie Jenkins
arch/riscv/lib/csum.c new file +7
-0+#ifdef CONFIG_RISCV_ISA_ZBB +if (IS_ENABLED (CONFIG_RISCV_ALTERNATIVE )) { +/* +* Zbb is likely available when the kernel is compiled with Zbb +* support, so nop when Zbb is available and jump when Zbb is +* not available. +*/
arch/riscv/lib/csum.c line 174
Quoted 10 lines
arch/riscv/lib/csum.c new file +10
-0+asm_volatile_goto (ALTERNATIVE ("j %l[no_zbb]" ,"nop" ,0 , +RISCV_ISA_EXT_ZBB ,1 ) + : + : + : + : no_zbb); + }else { +if (!__riscv_isa_extension_available (NULL ,RISCV_ISA_EXT_ZBB )) + goto no_zbb; + }
Again, do these constructs have an appreciable benefit over doing if (!riscv_has_extension_likely(<ZBB>)
goto no_zbb;
?
That encaspulates the fallback to a non-alternative mechanism for you, in case you had not noticed.
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v2 2/5] riscv: Add checksum library
Quoted 22 lines · Conor Dooley
Quoted 7 lines · Charlie Jenkins
arch/riscv/lib/csum.c new file +7
-0+#ifdef CONFIG_RISCV_ISA_ZBB +if (IS_ENABLED (CONFIG_RISCV_ALTERNATIVE )) { +/* +* Zbb is likely available when the kernel is compiled with Zbb +* support, so nop when Zbb is available and jump when Zbb is +* not available. +*/ arch/riscv/lib/csum.c line 174
Quoted 10 lines
arch/riscv/lib/csum.c new file +10
-0+asm_volatile_goto (ALTERNATIVE ("j %l[no_zbb]" ,"nop" ,0 , +RISCV_ISA_EXT_ZBB ,1 ) + : + : + : + : no_zbb); + }else { +if (!__riscv_isa_extension_available (NULL ,RISCV_ISA_EXT_ZBB )) + goto no_zbb; + }Again, do these constructs have an appreciable benefit over doing if (!riscv_has_extension_likely(<ZBB>)
Quoted 6 lines
goto no_zbb;?
That encaspulates the fallback to a non-alternative mechanism for you, in case you had not noticed.
I got caught up in the other patch where I did not want to fall back, so then in this patch I forgot I could use riscv_has_extension_likely. I will make the change.
- Charlie
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH v2 3/5 riscv: Vector checksum header
In reply to Charlie JenkinsVector code is written in assembly rather than using the GCC vector instrinsics because they did not provide optimal code. Vector instrinsic types are still used so the inline assembly can appropriately select vector registers. However, this code cannot be merged yet because it is currently not possible to use vector instrinsics in the kernel because vector support needs to be directly enabled by assembly.
--- arch/riscv/include/asm/checksum.h | 87 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+)
arch/riscv/include/asm/checksum.h +87 -0
@@ -10,6 +10,10 @@#include <linux/in6.h> #include <linux/uaccess.h> +#ifdef CONFIG_RISCV_ISA_V +#include <riscv_vector.h> +#endif +#ifdef CONFIG_32BIT typedef unsigned int csum_t ;#else
@@ -43,6 +47,89 @@ static inline __sum16 csum_fold(__wsum sum)*/ static inline __sum16 ip_fast_csum (const void *iph,unsigned int ihl) { +#ifdef CONFIG_RISCV_ISA_V +if (IS_ENABLED (CONFIG_RISCV_ALTERNATIVE )) { +/* +* Vector is likely available when the kernel is compiled with +* vector support, so nop when vector is available and jump when +* vector is not available. +*/ +asm_volatile_goto (ALTERNATIVE ("j %l[no_vector]" ,"nop" ,0 , + RISCV_ISA_EXT_v,1 ) + : + : + : + : no_vector); + }else { +if (!__riscv_isa_extension_available (NULL , RISCV_ISA_EXT_v)) + goto no_vector; + } + +vuint64m1_t prev_buffer; +vuint32m1_t curr_buffer; +unsigned int vl; +#ifdef CONFIG_32_BIT +csum_t high_result, low_result; + +riscv_v_enable (); + asm(".option push \n\ +.option arch, +v \n\ +vsetivli x0, 1, e64, ta, ma \n\ +vmv.v.i %[prev_buffer], 0 \n\ +1: \n\ +vsetvli %[vl], %[ihl], e32, m1, ta, ma \n\ +vle32.v %[curr_buffer], (%[iph]) \n\ +vwredsumu.vs %[prev_buffer], %[curr_buffer], %[prev_buffer] \n\ +sub %[ihl], %[ihl], %[vl] \n\ +slli %[vl], %[vl], 2 \n\ +add %[iph], %[vl], %[iph] \n\ +# If not all of iph could fit into vector reg, do another sum \n\ +bne %[ihl], zero, 1b \n\ +vsetivli x0, 1, e64, m1, ta, ma \n\ +vmv.x.s %[low_result], %[prev_buffer] \n\ +addi %[vl], x0, 32 \n\ +vsrl.vx %[prev_buffer], %[prev_buffer], %[vl] \n\ +vmv.x.s %[high_result], %[prev_buffer] \n\ +.option pop" + : [vl]"=&r" (vl), [prev_buffer]"=&vd" (prev_buffer), + [curr_buffer]"=&vd" (curr_buffer), + [high_result]"=&r" (high_result), + [low_result]"=&r" (low_result) + : [iph]"r" (iph), [ihl]"r" (ihl)); +riscv_v_disable (); + + high_result += low_result; + high_result += high_result < low_result; +#else // !CONFIG_32_BIT +csum_t result; + +riscv_v_enable (); + asm(".option push \n\ +.option arch, +v \n\ +vsetivli x0, 1, e64, ta, ma \n\ +vmv.v.i %[prev_buffer], 0 \n\ +1: \n\ +# Setup 32-bit sum of iph \n\ +vsetvli %[vl], %[ihl], e32, m1, ta, ma \n\ +vle32.v %[curr_buffer], (%[iph]) \n\ +# Sum each 32-bit segment of iph that can fit into a vector reg \n\ +vwredsumu.vs %[prev_buffer], %[curr_buffer], %[prev_buffer] \n\ +subw %[ihl], %[ihl], %[vl] \n\ +slli %[vl], %[vl], 2 \n\ +addw %[iph], %[vl], %[iph] \n\ +# If not all of iph could fit into vector reg, do another sum \n\ +bne %[ihl], zero, 1b \n\ +vsetvli x0, x0, e64, m1, ta, ma \n\ +vmv.x.s %[result], %[prev_buffer] \n\ +.option pop" + : [vl]"=&r" (vl), [prev_buffer]"=&vd" (prev_buffer), + [curr_buffer]"=&vd" (curr_buffer), [result]"=&r" (result) + : [iph]"r" (iph), [ihl]"r" (ihl)); +riscv_v_disable (); +#endif // !CONFIG_32_BIT +no_vector: +#endif // !CONFIG_RISCV_ISA_V +csum_t csum =0 ;int pos =0 ;
Signature · 1 line
2.42.0
Re: [PATCH v2 3/5] riscv: Vector checksum header
Quoted 39 lines · Charlie Jenkins
Vector code is written in assembly rather than using the GCC vector instrinsics because they did not provide optimal code. Vector instrinsic types are still used so the inline assembly can appropriately select vector registers. However, this code cannot be merged yet because it is currently not possible to use vector instrinsics in the kernel because vector support needs to be directly enabled by assembly.
Signed-off-by Charlie Jenkins <[email protected]>--- arch/riscv/include/asm/checksum.h | 87 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+)arch/riscv/include/asm/checksum.h +11
-0@@ -10,6 +10,10 @@#include <linux/in6.h> #include <linux/uaccess.h> +#ifdef CONFIG_RISCV_ISA_V +#include <riscv_vector.h> +#endif +#ifdef CONFIG_32BIT typedef unsigned int csum_t ;#else @@ -43,6 +47,89 @@ static inline __sum16 csum_fold(__wsum sum)*/ static inline __sum16 ip_fast_csum (const void *iph,unsigned int ihl) { +#ifdef CONFIG_RISCV_ISA_V +if (IS_ENABLED (CONFIG_RISCV_ALTERNATIVE )) { +/* +* Vector is likely available when the kernel is compiled with +* vector support, so nop when vector is available and jump when +* vector is not available. +*/
arch/riscv/include/asm/checksum.h static inline __sum16 csum_fold(__wsum sum) · line 66
Quoted 10 lines
arch/riscv/include/asm/checksum.h +10
-0+asm_volatile_goto (ALTERNATIVE ("j %l[no_vector]" ,"nop" ,0 , + RISCV_ISA_EXT_v,1 ) + : + : + : + : no_vector); + }else { +if (!__riscv_isa_extension_available (NULL , RISCV_ISA_EXT_v)) + goto no_vector; + }
Silly question maybe, but is this complexity required? If you were to go and do
if (!has_vector()) goto no_vector
is there any meaningful difference difference in performance?
Quoted 8 lines
arch/riscv/include/asm/checksum.h +8
-0+ +vuint64m1_t prev_buffer; +vuint32m1_t curr_buffer; +unsigned int vl; +#ifdef CONFIG_32_BIT +csum_t high_result, low_result; + +riscv_v_enable ();
arch/riscv/include/asm/checksum.h static inline __sum16 csum_fold(__wsum sum) · line 84
Quoted 10 lines
arch/riscv/include/asm/checksum.h +10
-0+ asm(".option push \n\ + .option arch, +v \n\ + vsetivli x0, 1, e64, ta, ma \n\ + vmv.v.i %[prev_buffer], 0 \n\ + 1: \n\ + vsetvli %[vl], %[ihl], e32, m1, ta, ma \n\ + vle32.v %[curr_buffer], (%[iph]) \n\ + vwredsumu.vs %[prev_buffer], %[curr_buffer], %[prev_buffer] \n\ + sub %[ihl], %[ihl], %[vl] \n\ + slli %[vl], %[vl], 2 \n\
Also, could you please try to align the operands for asm stuff? It makes quite a difference to readability.
Thanks,
Conor.
Quoted 55 lines
arch/riscv/include/asm/checksum.h +48
-0+ add %[iph], %[vl], %[iph] \n\ +# If not all of iph could fit into vector reg, do another sum \n\ + bne %[ihl], zero, 1b \n\ + vsetivli x0, 1, e64, m1, ta, ma \n\ + vmv.x.s %[low_result], %[prev_buffer] \n\ + addi %[vl], x0, 32 \n\ + vsrl.vx %[prev_buffer], %[prev_buffer], %[vl] \n\ + vmv.x.s %[high_result], %[prev_buffer] \n\ + .option pop" + : [vl] "=&r" (vl), [prev_buffer] "=&vd" (prev_buffer), + [curr_buffer] "=&vd" (curr_buffer), + [high_result] "=&r" (high_result), + [low_result] "=&r" (low_result) + : [iph] "r" (iph), [ihl] "r" (ihl)); + riscv_v_disable(); + + high_result += low_result; + high_result += high_result < low_result; +#else // !CONFIG_32_BIT +csum_t result; + +riscv_v_enable (); + asm(".option push \n\ +.option arch, +v \n\ +vsetivli x0, 1, e64, ta, ma \n\ +vmv.v.i %[prev_buffer], 0 \n\ +1: \n\ +# Setup 32-bit sum of iph \n\ +vsetvli %[vl], %[ihl], e32, m1, ta, ma \n\ +vle32.v %[curr_buffer], (%[iph]) \n\ +# Sum each 32-bit segment of iph that can fit into a vector reg \n\ +vwredsumu.vs %[prev_buffer], %[curr_buffer], %[prev_buffer] \n\ +subw %[ihl], %[ihl], %[vl] \n\ +slli %[vl], %[vl], 2 \n\ +addw %[iph], %[vl], %[iph] \n\ +# If not all of iph could fit into vector reg, do another sum \n\ +bne %[ihl], zero, 1b \n\ +vsetvli x0, x0, e64, m1, ta, ma \n\ +vmv.x.s %[result], %[prev_buffer] \n\ +.option pop" + : [vl]"=&r" (vl), [prev_buffer]"=&vd" (prev_buffer), + [curr_buffer]"=&vd" (curr_buffer), [result]"=&r" (result) + : [iph]"r" (iph), [ihl]"r" (ihl)); +riscv_v_disable (); +#endif // !CONFIG_32_BIT +no_vector: +#endif // !CONFIG_RISCV_ISA_V +csum_t csum =0 ;int pos =0 ;Signature · 2 lines
-- 2.42.0
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v2 3/5] riscv: Vector checksum header
Quoted 53 lines · Conor Dooley
Quoted 39 lines · Charlie Jenkins
Vector code is written in assembly rather than using the GCC vector instrinsics because they did not provide optimal code. Vector instrinsic types are still used so the inline assembly can appropriately select vector registers. However, this code cannot be merged yet because it is currently not possible to use vector instrinsics in the kernel because vector support needs to be directly enabled by assembly.
Signed-off-by Charlie Jenkins <[email protected]>--- arch/riscv/include/asm/checksum.h | 87 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+)arch/riscv/include/asm/checksum.h +11
-0@@ -10,6 +10,10 @@#include <linux/in6.h> #include <linux/uaccess.h> +#ifdef CONFIG_RISCV_ISA_V +#include <riscv_vector.h> +#endif +#ifdef CONFIG_32BIT typedef unsigned int csum_t ;#else @@ -43,6 +47,89 @@ static inline __sum16 csum_fold(__wsum sum)*/ static inline __sum16 ip_fast_csum (const void *iph,unsigned int ihl) { +#ifdef CONFIG_RISCV_ISA_V +if (IS_ENABLED (CONFIG_RISCV_ALTERNATIVE )) { +/* +* Vector is likely available when the kernel is compiled with +* vector support, so nop when vector is available and jump when +* vector is not available. +*/ arch/riscv/include/asm/checksum.h static inline __sum16 csum_fold(__wsum sum) · line 66
Quoted 10 lines
arch/riscv/include/asm/checksum.h +10
-0+asm_volatile_goto (ALTERNATIVE ("j %l[no_vector]" ,"nop" ,0 , + RISCV_ISA_EXT_v,1 ) + : + : + : + : no_vector); + }else { +if (!__riscv_isa_extension_available (NULL , RISCV_ISA_EXT_v)) + goto no_vector; + }Silly question maybe, but is this complexity required? If you were to go and do
Quoted 3 lines
if (!has_vector()) goto no_vectoris there any meaningful difference difference in performance?
Yes I should use that instead.
Quoted 24 lines
Quoted 10 lines
arch/riscv/include/asm/checksum.h +8
-0+ +vuint64m1_t prev_buffer; +vuint32m1_t curr_buffer; +unsigned int vl; +#ifdef CONFIG_32_BIT +csum_t high_result, low_result; + +riscv_v_enable ();arch/riscv/include/asm/checksum.h static inline __sum16 csum_fold(__wsum sum) · line 84
Quoted 10 lines
arch/riscv/include/asm/checksum.h +10
-0+ asm(".option push \n\ + .option arch, +v \n\ + vsetivli x0, 1, e64, ta, ma \n\ + vmv.v.i %[prev_buffer], 0 \n\ + 1: \n\ + vsetvli %[vl], %[ihl], e32, m1, ta, ma \n\ + vle32.v %[curr_buffer], (%[iph]) \n\ + vwredsumu.vs %[prev_buffer], %[curr_buffer], %[prev_buffer] \n\ + sub %[ihl], %[ihl], %[vl] \n\ + slli %[vl], %[vl], 2 \n\Also, could you please try to align the operands for asm stuff? It makes quite a difference to readability.
Quoted 3 lines
Thanks,
Conor.
Will do.
- Charlie
Quoted 52 lines
Quoted 52 lines
arch/riscv/include/asm/checksum.h +48
-0+ add %[iph], %[vl], %[iph] \n\ +# If not all of iph could fit into vector reg, do another sum \n\ + bne %[ihl], zero, 1b \n\ + vsetivli x0, 1, e64, m1, ta, ma \n\ + vmv.x.s %[low_result], %[prev_buffer] \n\ + addi %[vl], x0, 32 \n\ + vsrl.vx %[prev_buffer], %[prev_buffer], %[vl] \n\ + vmv.x.s %[high_result], %[prev_buffer] \n\ + .option pop" + : [vl] "=&r" (vl), [prev_buffer] "=&vd" (prev_buffer), + [curr_buffer] "=&vd" (curr_buffer), + [high_result] "=&r" (high_result), + [low_result] "=&r" (low_result) + : [iph] "r" (iph), [ihl] "r" (ihl)); + riscv_v_disable(); + + high_result += low_result; + high_result += high_result < low_result; +#else // !CONFIG_32_BIT +csum_t result; + +riscv_v_enable (); + asm(".option push \n\ +.option arch, +v \n\ +vsetivli x0, 1, e64, ta, ma \n\ +vmv.v.i %[prev_buffer], 0 \n\ +1: \n\ +# Setup 32-bit sum of iph \n\ +vsetvli %[vl], %[ihl], e32, m1, ta, ma \n\ +vle32.v %[curr_buffer], (%[iph]) \n\ +# Sum each 32-bit segment of iph that can fit into a vector reg \n\ +vwredsumu.vs %[prev_buffer], %[curr_buffer], %[prev_buffer] \n\ +subw %[ihl], %[ihl], %[vl] \n\ +slli %[vl], %[vl], 2 \n\ +addw %[iph], %[vl], %[iph] \n\ +# If not all of iph could fit into vector reg, do another sum \n\ +bne %[ihl], zero, 1b \n\ +vsetvli x0, x0, e64, m1, ta, ma \n\ +vmv.x.s %[result], %[prev_buffer] \n\ +.option pop" + : [vl]"=&r" (vl), [prev_buffer]"=&vd" (prev_buffer), + [curr_buffer]"=&vd" (curr_buffer), [result]"=&r" (result) + : [iph]"r" (iph), [ihl]"r" (ihl)); +riscv_v_disable (); +#endif // !CONFIG_32_BIT +no_vector: +#endif // !CONFIG_RISCV_ISA_V +csum_t csum =0 ;int pos =0 ;
Quoted 3 lines
Quoted 3 lines
Signature · 1 line
2.42.0
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v2 3/5] riscv: Vector checksum header
In reply to Charlie JenkinsQuoted 50 lines · Charlie Jenkins
Vector code is written in assembly rather than using the GCC vector instrinsics because they did not provide optimal code. Vector instrinsic types are still used so the inline assembly can appropriately select vector registers. However, this code cannot be merged yet because it is currently not possible to use vector instrinsics in the kernel because vector support needs to be directly enabled by assembly.
Signed-off-by Charlie Jenkins <[email protected]>--- arch/riscv/include/asm/checksum.h | 87 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+)arch/riscv/include/asm/checksum.h +22
-0@@ -10,6 +10,10 @@#include <linux/in6.h> #include <linux/uaccess.h> +#ifdef CONFIG_RISCV_ISA_V +#include <riscv_vector.h> +#endif +#ifdef CONFIG_32BIT typedef unsigned int csum_t ;#else @@ -43,6 +47,89 @@ static inline __sum16 csum_fold(__wsum sum)*/ static inline __sum16 ip_fast_csum (const void *iph,unsigned int ihl) { +#ifdef CONFIG_RISCV_ISA_V +if (IS_ENABLED (CONFIG_RISCV_ALTERNATIVE )) { +/* +* Vector is likely available when the kernel is compiled with +* vector support, so nop when vector is available and jump when +* vector is not available. +*/ +asm_volatile_goto (ALTERNATIVE ("j %l[no_vector]" ,"nop" ,0 , + RISCV_ISA_EXT_v,1 ) + : + : + : + : no_vector); + }else { +if (!__riscv_isa_extension_available (NULL , RISCV_ISA_EXT_v)) + goto no_vector; + } +
arch/riscv/include/asm/checksum.h static inline __sum16 csum_fold(__wsum sum) · line 77
Quoted 10 lines
arch/riscv/include/asm/checksum.h +10
-0+vuint64m1_t prev_buffer; +vuint32m1_t curr_buffer; +unsigned int vl; +#ifdef CONFIG_32_BIT +csum_t high_result, low_result; + +riscv_v_enable (); + asm(".option push \n\ + .option arch, +v \n\ + vsetivli x0, 1, e64, ta, ma \n\
Also, I don't see that you have addressed previous review comments from Samuel:
https://lore.kernel.org/linux-riscv/[email protected]/
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v2 3/5] riscv: Vector checksum header
Quoted 57 lines · Conor Dooley
Quoted 56 lines · Charlie Jenkins
Vector code is written in assembly rather than using the GCC vector instrinsics because they did not provide optimal code. Vector instrinsic types are still used so the inline assembly can appropriately select vector registers. However, this code cannot be merged yet because it is currently not possible to use vector instrinsics in the kernel because vector support needs to be directly enabled by assembly.
Signed-off-by Charlie Jenkins <[email protected]>--- arch/riscv/include/asm/checksum.h | 87 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+)arch/riscv/include/asm/checksum.h +28
-0@@ -10,6 +10,10 @@#include <linux/in6.h> #include <linux/uaccess.h> +#ifdef CONFIG_RISCV_ISA_V +#include <riscv_vector.h> +#endif +#ifdef CONFIG_32BIT typedef unsigned int csum_t ;#else @@ -43,6 +47,89 @@ static inline __sum16 csum_fold(__wsum sum)*/ static inline __sum16 ip_fast_csum (const void *iph,unsigned int ihl) { +#ifdef CONFIG_RISCV_ISA_V +if (IS_ENABLED (CONFIG_RISCV_ALTERNATIVE )) { +/* +* Vector is likely available when the kernel is compiled with +* vector support, so nop when vector is available and jump when +* vector is not available. +*/ +asm_volatile_goto (ALTERNATIVE ("j %l[no_vector]" ,"nop" ,0 , + RISCV_ISA_EXT_v,1 ) + : + : + : + : no_vector); + }else { +if (!__riscv_isa_extension_available (NULL , RISCV_ISA_EXT_v)) + goto no_vector; + } + +vuint64m1_t prev_buffer; +vuint32m1_t curr_buffer; +unsigned int vl; +#ifdef CONFIG_32_BIT +csum_t high_result, low_result; +
Quoted 8 lines
arch/riscv/include/asm/checksum.h static inline __sum16 csum_fold(__wsum sum) · line 77
Quoted 4 lines
arch/riscv/include/asm/checksum.h +4
-0+riscv_v_enable (); + asm(".option push \n\ + .option arch, +v \n\ + vsetivli x0, 1, e64, ta, ma \n\Also, I don't see that you have addressed previous review comments from Samuel:
https://lore.kernel.org/linux-riscv/[email protected]/
I added the check for vector as Samuel suggested, but then I accidentally used riscv_v_enable() instead of kernel_vector_begin(), I will make that change.
- Charlie
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH v2 4/5 riscv: Vector checksum library
In reply to Charlie JenkinsThis patch is not ready for merge as vector support in the kernel is limited. However, the code has been tested in QEMU so the algorithms do work. When Vector support is more mature, I will do more thorough testing of this code. It is written in assembly rather than using the GCC vector instrinsics because they did not provide optimal code.
--- arch/riscv/lib/csum.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+)
arch/riscv/lib/csum.c +106 -0
@@ -12,6 +12,10 @@#include <net/checksum.h> +#ifdef CONFIG_RISCV_ISA_V +#include <riscv_vector.h> +#endif +/* Default version is sufficient for 32 bit */ #ifndef CONFIG_32BIT __sum16 csum_ipv6_magic(const struct in6_addr *saddr,
@@ -115,6 +119,108 @@ unsigned int __no_sanitize_address do_csum(const unsigned char *buff, int len) offset = (csum_t )buff &OFFSET_MASK ;kasan_check_read (buff, len); ptr = (const csum_t *)(buff - offset); +#ifdef CONFIG_RISCV_ISA_V +if (IS_ENABLED (CONFIG_RISCV_ALTERNATIVE )) { +/* +* Vector is likely available when the kernel is compiled with +* vector support, so nop when vector is available and jump when +* vector is not available. +*/ +asm_volatile_goto (ALTERNATIVE ("j %l[no_vector]" ,"nop" ,0 , + RISCV_ISA_EXT_v,1 ) + : + : + : + : no_vector); + }else { +if (!__riscv_isa_extension_available (NULL , RISCV_ISA_EXT_v)) + goto no_vector; + } + + len += offset; + +vuint64m1_t prev_buffer; +vuint32m1_t curr_buffer; +unsigned int shift, cl, tail_seg; +csum_t vl, csum; +const csum_t *ptr; + +#ifdef CONFIG_32BIT +csum_t high_result, low_result; +#else +csum_t result; +#endif + +// Read the tail segment + tail_seg = len %4 ; + csum =0 ; +if (tail_seg) { + shift = (4 - tail_seg) *8 ; + csum = *(unsigned int *)((const unsigned char *)ptr + len - tail_seg); + csum = ((unsigned int )csum << shift) >> shift; + len -= tail_seg; + } + +unsigned int start_mask = (unsigned int )(~(~0U << offset)); + +riscv_v_enable (); + asm(".option push \n\ +.option arch, +v \n\ +vsetvli %[vl], %[len], e8, m1, ta, ma \n\ +# clear out mask and vector registers since we switch up sizes \n\ +vmclr.m v0 \n\ +vmclr.m %[prev_buffer] \n\ +vmclr.m %[curr_buffer] \n\ +# Mask out the leading bits of a misaligned address \n\ +vsetivli x0, 1, e64, m1, ta, ma \n\ +vmv.s.x %[prev_buffer], %[csum] \n\ +vmv.s.x v0, %[start_mask] \n\ +vsetvli %[vl], %[len], e8, m1, ta, ma \n\ +vmnot.m v0, v0 \n\ +vle8.v %[curr_buffer], (%[buff]), v0.t \n\ +j 2f \n\ +# Iterate through the buff and sum all words \n\ +1: \n\ +vsetvli %[vl], %[len], e8, m1, ta, ma \n\ +vle8.v %[curr_buffer], (%[buff]) \n\ +2: \n\ +vsetvli x0, x0, e32, m1, ta, ma \n\ +vwredsumu.vs %[prev_buffer], %[curr_buffer], %[prev_buffer] \n\t" +#ifdef CONFIG_32BIT +"sub %[len], %[len], %[vl] \n\ +slli %[vl], %[vl], 2 \n\ +add %[buff], %[vl], %[buff] \n\ +bnez %[len], 1b \n\ +vsetvli x0, x0, e64, m1, ta, ma \n\ +vmv.x.s %[result], %[prev_buffer] \n\ +addi %[vl], x0, 32 \n\ +vsrl.vx %[prev_buffer], %[prev_buffer], %[vl] \n\ +vmv.x.s %[high_result], %[prev_buffer] \n\ +.option pop" + : [vl]"=&r" (vl), [prev_buffer]"=&vd" (prev_buffer), + [curr_buffer]"=&vd" (curr_buffer), + [high_result]"=&r" (high_result), [low_result]"=&r" (low_result) + : [buff]"r" (ptr), [len]"r" (len), [start_mask]"r" (start_mask), + [csum]"r" (csum)); + + high_result += low_result; + high_result += high_result < low_result; +#else // !CONFIG_32BIT +"subw %[len], %[len], %[vl] \n\ +slli %[vl], %[vl], 2 \n\ +addw %[buff], %[vl], %[buff] \n\ +bnez %[len], 1b \n\ +vsetvli x0, x0, e64, m1, ta, ma \n\ +vmv.x.s %[result], %[prev_buffer] \n\ +.option pop" + : [vl] "=&r"(vl), [prev_buffer] "=&vd"(prev_buffer), + [curr_buffer] "=&vd"(curr_buffer), [result] "=&r"(result) + : [buff] "r"(ptr), [len] "r"(len), [start_mask] "r"(start_mask), + [csum] "r"(csum)); +#endif // !CONFIG_32BIT +riscv_v_disable (); +no_vector: +#endif // CONFIG_RISCV_ISA_V len = len + offset -sizeof (csum_t);/*
Signature · 1 line
2.42.0
PATCH v2 5/5 riscv: Test checksum functions
In reply to Charlie JenkinsAdd Kconfig support for riscv specific testing modules. This was created to supplement lib/checksum_kunit.c, and add tests for ip_fast_csum and csum_ipv6_magic.
--- arch/riscv/Kconfig.debug | 1 + arch/riscv/lib/Kconfig.debug | 31 ++++ arch/riscv/lib/Makefile | 2 + arch/riscv/lib/riscv_checksum_kunit.c | 330 ++++++++++++++++++++++++++++++++++ 4 files changed, 364 insertions(+)
arch/riscv/Kconfig.debug +1 -0
@@ -0,0 +1 @@ +source "arch/riscv/lib/Kconfig.debug"
arch/riscv/lib/Kconfig.debug new file +31 -0
@@ -0,0 +1,31 @@ +# SPDX-License-Identifier: GPL-2.0-only +menu "riscv Testing and Coverage" + +menuconfig RUNTIME_TESTING_MENU + bool "Runtime Testing" + def_bool y + help + Enable riscv runtime testing. + +if RUNTIME_TESTING_MENU + +config RISCV_CHECKSUM_KUNIT + tristate "KUnit test riscv checksum functions at runtime" if !KUNIT_ALL_TESTS + depends on KUNIT + default KUNIT_ALL_TESTS + help + Enable this option to test the checksum functions at boot. + + KUnit tests run during boot and output the results to the debug log + in TAP format (http://testanything.org/). Only useful for kernel devs + running the KUnit test harness, and not intended for inclusion into a + production build. + + For more information on KUnit and unit tests in general please refer + to the KUnit documentation in Documentation/dev-tools/kunit/. + + If unsure, say N. + +endif # RUNTIME_TESTING_MENU + +endmenu # "riscv Testing and Coverage"
arch/riscv/lib/Makefile +2 -0
@@ -12,3 +12,5 @@ lib-$(CONFIG_64BIT) += tishift.o lib-$(CONFIG_RISCV_ISA_ZICBOZ) += clear_page.o obj-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o + +obj-$(CONFIG_RISCV_CHECKSUM_KUNIT) += riscv_checksum_kunit.o
arch/riscv/lib/riscv_checksum_kunit.c new file +330 -0
330 lines not on this page · raw message
Signature · 1 line
2.42.0