crc32 combine improvements
Subsystems (4)
cover crc32 combine improvements
So almost a month passed, and I don't want this to get lost somewhere. I have applied the feedback given at that time to this set, rebased plus tested it against latest net-next. I decided to route this via netdev as it improves performance upon library code that provides library bits for SCTP, i.e. for non-linear skb csum handling in IPVS. Thus, resending this for George before it gets lost.
Thanks!
George Spelvin (3):
lib: crc32: Greatly shrink CRC combining code
lib: crc32: Mark test data __initconst
lib: crc32: Add some additional __pure annotations
include/linux/crc32.h | 20 +++++-- lib/crc32.c | 153 ++++++++++++++++++++++++-------------------------- 2 files changed, 88 insertions(+), 85 deletions(-)
Signature · 1 line
1.7.11.7
PATCH 1/3 lib: crc32: Greatly shrink CRC combining code
From: George Spelvin <[email protected]>
There's no need for a full 32x32 matrix, when rows before the last are just shifted copies of the rows after them.
There's still room for improvement (especially on X86 processors with CRC32 and PCLMUL instructions), but this is a large step in the right direction [which is in particular useful for its current user, namely SCTP checksumming over multiple skb frags[] entries, i.e. in IPVS balancing when other CRC32 offloads are not available].
The internal primitive is now called crc32_generic_shift and takes one less argument; the XOR with crc2 is done in inline wrappers.
--- include/linux/crc32.h | 14 ++++- lib/crc32.c | 147 ++++++++++++++++++++++++-------------------------- 2 files changed, 82 insertions(+), 79 deletions(-)
include/linux/crc32.h +12 -2
@@ -29,7 +29,12 @@ extern u32 crc32_be(u32 crc, unsigned char const *p, size_t len);* with the same initializer as crc1, and crc2 seed was 0. See * also crc32_combine_test(). */ -extern u32 crc32_le_combine (u32 crc1,u32 crc2,size_t len2); +u32 __attribute_const__ crc32_le_shift(u32 crc, size_t len); + +static inline u32 crc32_le_combine (u32 crc1,u32 crc2,size_t len2) +{ +return crc32_le_shift (crc1, len2) ^ crc2; +}extern u32 __crc32c_le (u32 crc,unsigned char const *p,size_t len);
@@ -51,7 +56,12 @@ extern u32 __crc32c_le(u32 crc, unsigned char const *p, size_t len);* seeded with the same initializer as crc1, and crc2 seed * was 0. See also crc32c_combine_test(). */ -extern u32 __crc32c_le_combine (u32 crc1,u32 crc2,size_t len2); +u32 __attribute_const__ __crc32c_le_shift(u32 crc, size_t len); + +static inline u32 __crc32c_le_combine (u32 crc1,u32 crc2,size_t len2) +{ +return __crc32c_le_shift (crc1, len2) ^ crc2; +}#define crc32 (seed, data, length) crc32_le(seed, (unsigned char const *)(data), length)
lib/crc32.c +70 -77
170 lines not on this page · raw message
Signature · 1 line
1.7.11.7
PATCH 2/3 lib: crc32: Mark test data __initconst
In reply to Daniel BorkmannFrom: George Spelvin <[email protected]>
So it gets discarded after the selftest.
--- lib/crc32.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
lib/crc32.c +2 -2
@@ -344,7 +344,7 @@ EXPORT_SYMBOL(crc32_be);#ifdef CONFIG_CRC32_SELFTEST /* 4096 random bytes */ -static u8 __attribute__((__aligned__ (8 ))) test_buf[] = +static u8 const __aligned(8) test_buf[]__initconst = {0x5b ,0x85 ,0x21 ,0xcb ,0x09 ,0x68 ,0x7d ,0x30 , 0xc7, 0x69, 0xd7, 0x30, 0x92, 0xde, 0x59, 0xe4,
@@ -868,7 +868,7 @@ static struct crc_test {u32 crc_le;/* expected crc32_le result */ u32 crc_be;/* expected crc32_be result */ u32 crc32c_le;/* expected crc32c_le result */ -} test[] = +} const test[] __initconst = { {0x674bf11d ,0x00000038 ,0x00000542 ,0x0af6d466 ,0xd8b6e4c1 ,0xf6e93d6c }, {0x35c672c6 ,0x0000003a ,0x000001aa ,0xc6d3dfba ,0x28aaf3ad ,0x0fe92aca },
Signature · 1 line
1.7.11.7
PATCH 3/3 lib: crc32: Add some additional __pure annotations
In reply to Daniel BorkmannFrom: George Spelvin <[email protected]>
In case they help the compiler.
--- include/linux/crc32.h | 6 +++--- lib/crc32.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-)
include/linux/crc32.h +3 -3
@@ -8,8 +8,8 @@#include <linux/types.h> #include <linux/bitrev.h> -extern u32 crc32_le (u32 crc,unsigned char const *p,size_t len); -extern u32 crc32_be (u32 crc,unsigned char const *p,size_t len); +u32 __pure crc32_le (u32 crc,unsigned char const *p,size_t len); +u32 __pure crc32_be (u32 crc,unsigned char const *p,size_t len);/** * crc32_le_combine - Combine two crc32 check values into one. For two
@@ -36,7 +36,7 @@ static inline u32 crc32_le_combine(u32 crc1, u32 crc2, size_t len2)return crc32_le_shift (crc1, len2) ^ crc2; } -extern u32 __crc32c_le (u32 crc,unsigned char const *p,size_t len); +u32 __pure __crc32c_le (u32 crc,unsigned char const *p,size_t len);/** * __crc32c_le_combine - Combine two crc32c check values into one. For two
lib/crc32.c +1 -1
@@ -53,7 +53,7 @@ MODULE_LICENSE("GPL");#if CRC_LE_BITS >8 ||CRC_BE_BITS >8 /* implements slicing-by-4 or slicing-by-8 algorithm */ -static inline u32 +static inline u32 __pure crc32_body (u32 crc,unsigned char const *buf,size_t len,const u32 (*tab)[256 ]) {# ifdef __LITTLE_ENDIAN
Signature · 1 line
1.7.11.7
David Miller
maintainerFrom: Daniel Borkmann <[email protected]>
Date: Mon, 23 Jun 2014 15:11:53 +0200
Quoted 7 lines
So almost a month passed, and I don't want this to get lost somewhere. I have applied the feedback given at that time to this set, rebased plus tested it against latest net-next. I decided to route this via netdev as it improves performance upon library code that provides library bits for SCTP, i.e. for non-linear skb csum handling in IPVS. Thus, resending this for George before it gets lost.
Series applied, thanks Daniel.