net: optimize raw checksum computation
PATCH v2 1/1 net: optimize raw checksum computation
From: Scott Mitchell <[email protected]>
Optimize __rte_raw_cksum() by processing data in larger unrolled loops instead of iterating word-by-word. The new implementation processes 64-byte blocks (32 x uint16_t) in the hot path, followed by smaller 32/16/8/4/2-byte chunks.
Uses uint64_t accumulator to reduce carry propagation overhead and leverages unaligned_uint16_t for safe unaligned access on all platforms.
Performance results from cksum_perf_autotest (TSC cycles/byte):
Block size Before After Improvement
100 0.40-0.64 0.13-0.14 ~3-4x
1500 0.49-0.51 0.10-0.11 ~4-5x
9000 0.48-0.51 0.11-0.12 ~4x---
Changes in v2:
- Fixed UndefinedBehaviorSanitizer errors by adding uint32_t casts to prevent signed integer overflow in addition chains
- Restored uint32_t sum accumulator instead of uint64_t
- Added 64k length to test_cksum_perf.c
app/test/meson.build | 1 + app/test/test_cksum_fuzz.c | 241 +++++++++++++++++++++++++++++++++++++ app/test/test_cksum_perf.c | 2 +- lib/net/rte_cksum.h | 59 +++++++-- 4 files changed, 292 insertions(+), 11 deletions(-) create mode 100644 app/test/test_cksum_fuzz.c
app/test/meson.build +1 -0
@@ -38,6 +38,7 @@ source_file_deps = { 'test_byteorder.c': [], 'test_cfgfile.c': ['cfgfile'], 'test_cksum.c': ['net'], + 'test_cksum_fuzz.c': ['net'], 'test_cksum_perf.c': ['net'], 'test_cmdline.c': [], 'test_cmdline_cirbuf.c': [],
app/test/test_cksum_fuzz.c new file +241 -0
241 lines not on this page · raw message
app/test/test_cksum_perf.c +1 -1
@@ -15,7 +15,7 @@#define NUM_BLOCKS 10#define ITERATIONS 1000000 -static const size_t data_sizes[] = {20 ,21 ,100 ,101 ,1500 ,1501 }; +static const size_t data_sizes[] = {20 ,21 ,100 ,101 ,1500 ,1501 ,9000 ,9001 ,65536 ,65537 }; static __rte_noinline uint16_tdo_rte_raw_cksum (const void *buf,size_t len)
lib/net/rte_cksum.h +49 -10
70 lines not on this page · raw message
Signature · 1 line
2.39.5 (Apple Git-154)