riscv: Add fine-tuned checksum functions
Subsystems (2)
v9 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.
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.
Relies on https://lore.kernel.org/lkml/[email protected]/
---
The algorithm proposed to replace the default csum_fold can be seen to compute the same result by running all 2^32 possible inputs.
static inline unsigned int ror32(unsigned int word, unsigned int shift)
{
return (word >> (shift & 31)) | (word << ((-shift) & 31));
}unsigned short csum_fold(unsigned int csum)
{
unsigned int sum = csum;
sum = (sum & 0xffff) + (sum >> 16);
sum = (sum & 0xffff) + (sum >> 16);
return ~sum;
}unsigned short csum_fold_arc(unsigned int csum)
{
return ((~csum - ror32(csum, 16)) >> 16);
}int main()
{
unsigned int start = 0x0;
do {
if (csum_fold(start) != csum_fold_arc(start)) {
printf("Not the same %u\n", start);
return -1;
}
start += 1;
} while(start != 0x0);
printf("The same\n");
return 0;
}Cc: Paul Walmsley <[email protected]>
Cc: Albert Ou <[email protected]>
Cc: Arnd Bergmann <[email protected]>
To: Charlie Jenkins <[email protected]>
To: Palmer Dabbelt <[email protected]>
To: Conor Dooley <[email protected]>
To: Samuel Holland <[email protected]>
To: David Laight <[email protected]>
To: Xiao Wang <[email protected]>
To: Evan Green <[email protected]>
To: [email protected]
To: [email protected]
To: [email protected]
---
Changes in v9:
- Use ror64 (Xiao)
- Move do_csum and csum_ipv6_magic headers to patch 4 (Xiao)
- Remove word "IP" from checksum headers (Xiao)
- Swap to using ifndef CONFIG_32BIT instead of ifdef CONFIG_64BIT (Xiao)
- Run no alignment code when buff is aligned (Xiao)
- Consolidate two do_csum implementations overlap into do_csum_common
- Link to v8: https://lore.kernel.org/r/[email protected]
Changes in v8:
- Speedups of 12% without Zbb and 21% with Zbb when cpu supports fast
misaligned accesses for do_csum
- Various formatting updates
- Patch now relies on https://lore.kernel.org/lkml/[email protected]/
- Link to v7: https://lore.kernel.org/r/[email protected]
Changes in v7:
- Included linux/bitops.h in asm-generic/checksum.h to use ror (Conor)
- Optimized loop in do_csum (David)
- Used ror instead of shifting (David)
- Unfortunately had to reintroduce ifdefs because gcc is not smart
enough to not throw warnings on code that will never execute
- Use ifdef instead of IS_ENABLED on __LITTLE_ENDIAN because IS_ENABLED
does not work on that
- Only optimize for zbb when alternatives is enabled in do_csum
- Link to v6: https://lore.kernel.org/r/[email protected]
Changes in v6:
- Fix accuracy of commit message for csum_fold
- Fix indentation
- Link to v5: https://lore.kernel.org/r/[email protected]
Changes in v5:
- Drop vector patches
- Check ZBB enabled before doing any ZBB code (Conor)
- Check endianness in IS_ENABLED
- Revert to the simpler non-tree based version of ipv6_csum_magic since
David pointed out that the tree based version is not better.
- Link to v4: https://lore.kernel.org/r/[email protected]
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/[email protected]
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/[email protected]
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):
asm-generic: Improve csum_fold
riscv: Add static key for misaligned accesses
riscv: Checksum header
riscv: Add checksum library
riscv: Test checksum functions
arch/riscv/Kconfig.debug | 1 + arch/riscv/include/asm/checksum.h | 92 ++++++++++ arch/riscv/include/asm/cpufeature.h | 3 + arch/riscv/kernel/cpufeature.c | 30 ++++ arch/riscv/lib/Kconfig.debug | 31 ++++ arch/riscv/lib/Makefile | 3 + arch/riscv/lib/csum.c | 326 +++++++++++++++++++++++++++++++++ arch/riscv/lib/riscv_checksum_kunit.c | 330 ++++++++++++++++++++++++++++++++++ include/asm-generic/checksum.h | 6 +- 9 files changed, 819 insertions(+), 3 deletions(-)
---
base-commit: 8d68c506cd34a142331623fd23eb1c4e680e1955
change-id: 20230804-optimize_checksum-db145288ac21
Signature · 1 line
- Charlie
PATCH v9 1/5 asm-generic: Improve csum_fold
This csum_fold implementation introduced into arch/arc by Vineet Gupta is better than the default implementation on at least arc, x86, and riscv. Using GCC trunk and compiling non-inlined version, this implementation has 41.6667%, 25% fewer instructions on riscv64, x86-64 respectively with -O3 optimization. Most implmentations override this default in asm, but this should be more performant than all of those other implementations except for arm which has barrel shifting and sparc32 which has a carry flag.
--- include/asm-generic/checksum.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
include/asm-generic/checksum.h +3 -3
@@ -2,6 +2,8 @@#ifndef __ASM_GENERIC_CHECKSUM_H#define __ASM_GENERIC_CHECKSUM_H +#include <linux/bitops.h> +/* * computes the checksum of a memory block at buff, length len, * and adds in "sum" (32-bit)
@@ -31,9 +33,7 @@ extern __sum16 ip_fast_csum(const void *iph, unsigned int ihl);static inline __sum16 csum_fold (__wsum csum) {u32 sum = (__force u32 )csum; - sum = (sum &0xffff ) + (sum >>16 ); - sum = (sum &0xffff ) + (sum >>16 ); -return (__force __sum16 )~sum; +return (__force __sum16)((~sum -ror32 (sum,16 )) >>16 ); }#endif
Signature · 1 line
2.34.1
PATCH v9 2/5 riscv: Add static key for misaligned accesses
In reply to Charlie JenkinsSupport static branches depending on the value of misaligned accesses. This will be used by a later patch in the series. All cpus must be considered "fast" for this static branch to be flipped.
--- arch/riscv/include/asm/cpufeature.h | 3 +++ arch/riscv/kernel/cpufeature.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+)
arch/riscv/include/asm/cpufeature.h +3 -0
@@ -7,6 +7,7 @@#define _ASM_CPUFEATURE_H#include <linux/bitmap.h> +#include <linux/jump_label.h> #include <asm/hwcap.h> /*
@@ -32,4 +33,6 @@ extern struct riscv_isainfo hart_isa[NR_CPUS];int check_unaligned_access (void *unused); +DECLARE_STATIC_KEY_FALSE (fast_misaligned_access_speed_key); +#endif
arch/riscv/kernel/cpufeature.c +30 -0
@@ -9,6 +9,7 @@#include <linux/acpi.h> #include <linux/bitmap.h> #include <linux/ctype.h> +#include <linux/jump_label.h> #include <linux/log2.h> #include <linux/memory.h> #include <linux/module.h>
@@ -665,6 +666,35 @@ static int check_unaligned_access_all_cpus(void)arch_initcall (check_unaligned_access_all_cpus); +DEFINE_STATIC_KEY_FALSE (fast_misaligned_access_speed_key); + +static int set_unaligned_access_static_branches (void ) +{ +/* +* This will be called after check_unaligned_access_all_cpus so the +* result of unaligned access speed for all cpus will be available. +*/ + +int cpu; +bool fast_misaligned_access_speed = true; + +for_each_online_cpu (cpu) { +int this_perf =per_cpu (misaligned_access_speed, cpu); + +if (this_perf !=RISCV_HWPROBE_MISALIGNED_FAST ) { + fast_misaligned_access_speed = false; +break ; + } + } + +if (fast_misaligned_access_speed) +static_branch_enable (&fast_misaligned_access_speed_key); + +return 0 ; +} + +arch_initcall_sync (set_unaligned_access_static_branches); +#ifdef CONFIG_RISCV_ALTERNATIVE /* * Alternative patch sites consider 48 bits when determining when to patch
Signature · 7 lines
2.34.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH v9 3/5 riscv: Checksum header
In reply to Charlie JenkinsProvide 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 | 81 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+)
arch/riscv/include/asm/checksum.h new file +81 -0
@@ -0,0 +1,81 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* 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> + +#define ip_fast_csum ip_fast_csum + +/* Define riscv versions of functions before importing asm-generic/checksum.h */ +#include <asm-generic/checksum.h> + +/* +* 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 given that NET_IP_ALIGN is set to 2 on +* riscv, defining IP headers to be aligned. +*/ +static inline __sum16 ip_fast_csum (const void *iph,unsigned int ihl) +{ +unsigned long csum =0 ; +int pos =0 ; + +do { + csum += ((const unsigned int *)iph)[pos]; +if (IS_ENABLED (CONFIG_32BIT )) + csum += csum < ((const unsigned int *)iph)[pos]; + }while (++pos < ihl); + +/* +* ZBB only saves three instructions on 32-bit and five on 64-bit so not +* worth checking if supported without Alternatives. +*/ +if (IS_ENABLED (CONFIG_RISCV_ISA_ZBB ) && +IS_ENABLED (CONFIG_RISCV_ALTERNATIVE )) { +unsigned long fold_temp; + +asm_volatile_goto (ALTERNATIVE ("j %l[no_zbb]" ,"nop" ,0 , +RISCV_ISA_EXT_ZBB ,1 ) + : + : + : + : no_zbb); + +if (IS_ENABLED (CONFIG_32BIT )) { + asm(".option push \n\ +.option arch,+zbb \n\ +not %[fold_temp], %[csum] \n\ +rori %[csum], %[csum], 16 \n\ +sub %[csum], %[fold_temp], %[csum] \n\ +.option pop" + : [csum]"+r" (csum), [fold_temp]"=&r" (fold_temp)); + }else { + 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\ +not %[fold_temp], %[csum] \n\ +roriw %[csum], %[csum], 16 \n\ +subw %[csum], %[fold_temp], %[csum] \n\ +.option pop" + : [csum]"+r" (csum), [fold_temp]"=&r" (fold_temp)); + } +return csum >>16 ; + } +no_zbb: +#ifndef CONFIG_32BIT + csum +=ror64 (csum,32 ); + csum >>=32 ; +#endif +return csum_fold ((__force __wsum )csum); +} + +#endif /* __ASM_RISCV_CHECKSUM_H */
Signature · 7 lines
2.34.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v9 3/5] riscv: Checksum header
Quoted 51 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]>Acked-by Conor Dooley <[email protected]>--- arch/riscv/include/asm/checksum.h | 81 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+)arch/riscv/include/asm/checksum.h new file +35
-0@@ -0,0 +1,81 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* 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> + +#define ip_fast_csum ip_fast_csum + +/* Define riscv versions of functions before importing asm-generic/checksum.h */ +#include <asm-generic/checksum.h> + +/* +* 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 given that NET_IP_ALIGN is set to 2 on +* riscv, defining IP headers to be aligned. +*/ +static inline __sum16 ip_fast_csum (const void *iph,unsigned int ihl) +{ +unsigned long csum =0 ; +int pos =0 ; + +do { + csum += ((const unsigned int *)iph)[pos]; +if (IS_ENABLED (CONFIG_32BIT )) + csum += csum < ((const unsigned int *)iph)[pos]; + }while (++pos < ihl); +
arch/riscv/include/asm/checksum.h line 45
Quoted 10 lines
arch/riscv/include/asm/checksum.h new file +10
-0+/* +* ZBB only saves three instructions on 32-bit and five on 64-bit so not +* worth checking if supported without Alternatives. +*/ +if (IS_ENABLED (CONFIG_RISCV_ISA_ZBB ) && +IS_ENABLED (CONFIG_RISCV_ALTERNATIVE )) { +unsigned long fold_temp; + +asm_volatile_goto (ALTERNATIVE ("j %l[no_zbb]" ,"nop" ,0 , + RISCV_ISA_EXT_ZBB, 1)
This looks like a open coding of riscv_has_extension_*, so if we use the it, the code could be rewritten as:
if (riscv_has_extension_likely(RISCV_ISA_EXT_ZBB)) {
if (32bit) {
asm(...)
} else {
asm(...)
}
return csum >> 16;
}
#ifndef CONFIG_32BIT
csum += ror64(csum, 32);
csum >>= 32;
#endif
return csum_fold((__force __wsum)csum);The code readability is improved and make it a bit easier to refactor the asm(...) code in the future.
And IMHO, the generated code should be the same.
Thanks
Quoted 47 lines
arch/riscv/include/asm/checksum.h new file +36
-0+ : + : + : + : no_zbb); + +if (IS_ENABLED (CONFIG_32BIT )) { + asm(".option push \n\ +.option arch,+zbb \n\ +not %[fold_temp], %[csum] \n\ +rori %[csum], %[csum], 16 \n\ +sub %[csum], %[fold_temp], %[csum] \n\ +.option pop" + : [csum]"+r" (csum), [fold_temp]"=&r" (fold_temp)); + }else { + 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\ +not %[fold_temp], %[csum] \n\ +roriw %[csum], %[csum], 16 \n\ +subw %[csum], %[fold_temp], %[csum] \n\ +.option pop" + : [csum]"+r" (csum), [fold_temp]"=&r" (fold_temp)); + } +return csum >>16 ; + } +no_zbb: +#ifndef CONFIG_32BIT + csum +=ror64 (csum,32 ); + csum >>=32 ; +#endif +return csum_fold ((__force __wsum )csum); +} + +#endif /* __ASM_RISCV_CHECKSUM_H */ Signature · 8 lines
-- 2.34.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v9 3/5] riscv: Checksum header
Quoted 81 lines · Jisheng Zhang
Quoted 51 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]>Acked-by Conor Dooley <[email protected]>--- arch/riscv/include/asm/checksum.h | 81 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+)arch/riscv/include/asm/checksum.h new file +35
-0@@ -0,0 +1,81 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* 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> + +#define ip_fast_csum ip_fast_csum + +/* Define riscv versions of functions before importing asm-generic/checksum.h */ +#include <asm-generic/checksum.h> + +/* +* 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 given that NET_IP_ALIGN is set to 2 on +* riscv, defining IP headers to be aligned. +*/ +static inline __sum16 ip_fast_csum (const void *iph,unsigned int ihl) +{ +unsigned long csum =0 ; +int pos =0 ; + +do { + csum += ((const unsigned int *)iph)[pos]; +if (IS_ENABLED (CONFIG_32BIT )) + csum += csum < ((const unsigned int *)iph)[pos]; + }while (++pos < ihl); +arch/riscv/include/asm/checksum.h line 45
Quoted 10 lines
arch/riscv/include/asm/checksum.h new file +10
-0+/* +* ZBB only saves three instructions on 32-bit and five on 64-bit so not +* worth checking if supported without Alternatives. +*/ +if (IS_ENABLED (CONFIG_RISCV_ISA_ZBB ) && +IS_ENABLED (CONFIG_RISCV_ALTERNATIVE )) { +unsigned long fold_temp; + +asm_volatile_goto (ALTERNATIVE ("j %l[no_zbb]" ,"nop" ,0 , + RISCV_ISA_EXT_ZBB, 1)This looks like a open coding of riscv_has_extension_*, so if we use the it, the code could be rewritten as:
if (riscv_has_extension_likely(RISCV_ISA_EXT_ZBB)) { if (32bit) { asm(...) } else { asm(...) } return csum >> 16; } #ifndef CONFIG_32BIT csum += ror64(csum, 32); csum >>= 32; #endif return csum_fold((__force __wsum)csum);
Quoted 6 lines
The code readability is improved and make it a bit easier to refactor the asm(...) code in the future.
And IMHO, the generated code should be the same.
Thanks
It is unfortunately not the same. riscv_has_extension_likely checks at runtime for ZBB if alternatives is not supported. That is why the comment is there. I can reference riscv_has_extension_likely to avoid confusion.
- Charlie
Quoted 48 lines
Quoted 48 lines
arch/riscv/include/asm/checksum.h new file +36
-0+ : + : + : + : no_zbb); + +if (IS_ENABLED (CONFIG_32BIT )) { + asm(".option push \n\ +.option arch,+zbb \n\ +not %[fold_temp], %[csum] \n\ +rori %[csum], %[csum], 16 \n\ +sub %[csum], %[fold_temp], %[csum] \n\ +.option pop" + : [csum]"+r" (csum), [fold_temp]"=&r" (fold_temp)); + }else { + 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\ +not %[fold_temp], %[csum] \n\ +roriw %[csum], %[csum], 16 \n\ +subw %[csum], %[fold_temp], %[csum] \n\ +.option pop" + : [csum]"+r" (csum), [fold_temp]"=&r" (fold_temp)); + } +return csum >>16 ; + } +no_zbb: +#ifndef CONFIG_32BIT + csum +=ror64 (csum,32 ); + csum >>=32 ; +#endif +return csum_fold ((__force __wsum )csum); +} + +#endif /* __ASM_RISCV_CHECKSUM_H */ Signature · 8 lines
-- 2.34.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH v9 4/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.
--- arch/riscv/include/asm/checksum.h | 11 ++ arch/riscv/lib/Makefile | 1 + arch/riscv/lib/csum.c | 326 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 338 insertions(+)
arch/riscv/include/asm/checksum.h +11 -0
@@ -12,6 +12,17 @@#define ip_fast_csum ip_fast_csum +extern unsigned int do_csum (const unsigned char *buff,int len); +#define do_csum do_csum + +/* Default version is sufficient for 32 bit */ +#ifndef CONFIG_32BIT +#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 +/* Define riscv versions of functions before importing asm-generic/checksum.h */ #include <asm-generic/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 +326 -0
326 lines not on this page · raw message
Signature · 7 lines
2.34.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH v9 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 lib Testing and Coverage" + +menuconfig RUNTIME_LIB_TESTING_MENU + bool "Runtime Lib Testing" + def_bool y + help + Enable riscv runtime lib testing. + +if RUNTIME_LIB_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_LIB_TESTING_MENU + +endmenu # "riscv lib 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.34.1
Arnd Bergmann
maintainerRe: [PATCH v9 5/5] riscv: Test checksum functions
Quoted 10 lines · Charlie Jenkins
Add
Kconfigsupport for riscv specific testing modules. This was created to supplementlib/checksum_kunit.c, and add tests forip_fast_csumandcsum_ipv6_magic.Signed-off-by Charlie Jenkins <[email protected]>--- arch/riscv/Kconfig.debug | 1 + arch/riscv/lib/Kconfig.debug | 31 ++++ arch/riscv/lib/Makefile | 2 + arch/riscv/lib/riscv_checksum_kunit.c | 330 ++++++++++++++++++++++++++++++++++
I don't understand this bit, what is special about riscv here that prevents you from adding it to the common lib/checksum_kunit.c?
Arnd
Re: [PATCH v9 5/5] riscv: Test checksum functions
Quoted 12 lines · Arnd Bergmann
Quoted 10 lines · Charlie Jenkins
Add
Kconfigsupport for riscv specific testing modules. This was created to supplementlib/checksum_kunit.c, and add tests forip_fast_csumandcsum_ipv6_magic.Signed-off-by Charlie Jenkins <[email protected]>--- arch/riscv/Kconfig.debug | 1 + arch/riscv/lib/Kconfig.debug | 31 ++++ arch/riscv/lib/Makefile | 2 + arch/riscv/lib/riscv_checksum_kunit.c | 330 ++++++++++++++++++++++++++++++++++
Quoted 4 lines
I don't understand this bit, what is special about riscv here that prevents you from adding it to the common
lib/checksum_kunit.c?Arnd
Oh, I can add it to the common one. I was hesitant to do that just because it would affect all archs.
- Charlie
Quoted 15 lines · Charlie Jenkins
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.
This patch takes heavy use of the Zbb extension using alternatives patching.
To test this patch, enable the configs for KUNIT, then
CHECKSUM_KUNITandRISCV_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.
Quoted 6 lines
ip_fast_csumis 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.
I coulda sworn I reported build issues against the v8 of this series that are still present in this v9. For example:
https://patchwork.kernel.org/project/linux-riscv/patch/[email protected]/
Cheers,
Conor.
Quoted 21 lines · Conor Dooley
Quoted 20 lines · Charlie Jenkins
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.
This patch takes heavy use of the Zbb extension using alternatives patching.
To test this patch, enable the configs for KUNIT, then
CHECKSUM_KUNITandRISCV_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_csumis 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.
Quoted 8 lines
Quoted 1 line
I coulda sworn I reported build issues against the v8 of this series that are still present in this v9. For example:
https://patchwork.kernel.org/project/linux-riscv/patch/[email protected]/Cheers,
Conor.
You did, and I fixed the build issues. This is another instance of how Patchwork reports the results of the previous build before the new build completes. Patchwork was very far behind so it took around 15 hours for the result to be ready. There are some miscellaneous warnings in random drivers that I don't think can be attributed to this patch.
- Charlie
Quoted 24 lines · Charlie Jenkins
Quoted 23 lines · Conor Dooley
Quoted 21 lines · Charlie Jenkins
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.
This patch takes heavy use of the Zbb extension using alternatives patching.
To test this patch, enable the configs for KUNIT, then
CHECKSUM_KUNITandRISCV_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_csumis 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.
Quoted 8 lines
Quoted 3 lines
I coulda sworn I reported build issues against the v8 of this series that are still present in this v9. For example:
https://patchwork.kernel.org/project/linux-riscv/patch/[email protected]/You did, and I fixed the build issues. This is another instance of how Patchwork reports the results of the previous build before the new build completes. Patchwork was very far behind so it took around 15 hours for the result to be ready.
:clown_face:
Quoted 2 lines
There are some miscellaneous warnings in random drivers that I don't think can be attributed to this patch.
Yeah, there sometimes are warnings that seem spurious when you touch a bunch of header files. I'm not really sure how to improve on that, since it was newly introduced. My theory is that how we do a build of commit A, then commit A~1 and then commit A again & take the difference between the 2nd and 3rd builds (which should both be partial rebuilds) is not as symmetrical as I might've thought and is the source of those seemingly unrelated issues that come up from time to time.