eal/x86: optimize memcpy of small 64-byte blocks
Subsystems (3)
PATCH 1/1 eal/x86: optimize memcpy of small 64-byte blocks
The implementation for copying 64-byte blocks up to 512 (or 256) bytes does not depend on address alignment with the size of the CPU's vector registers, but is implemented in both unaligned and aligned copy functions.
The main rte_memcpy() function was updated, so
if the copy size is known at compile time and the other criteria match, the copy is performed without checking alignment requirements. This provides two benefits when the optimization comes into play:
1. A performance gain, because the address alignment check is avoided.
3. Reduced instruction memory footprint, because the compiler only generates one instance of the function for copying, instead of two instances (one in the unaligned copy function, and one in the aligned copy function).
Furthermore, the temporary alignment mask definition (ALIGNMENT_MASK) was prefixed by RTE_MEMCPY_ to prevent potential namespace collision.
And finally, the superfluous function declaration at the top of the file was removed, and its description was moved to the function definition.
This improves search results with source code browsers.
--- lib/eal/x86/include/rte_memcpy.h | 64 ++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 20 deletions(-)
lib/eal/x86/include/rte_memcpy.h +44 -20
@@ -32,21 +32,6 @@ extern "C" {#define RTE_MEMCPY_AVX #endif -/** -* Copy bytes from one location to another. The locations must not overlap. -* -* @param dst -* Pointer to the destination of the data. -* @param src -* Pointer to the source data. -* @param n -* Number of bytes to copy. -* @return -* Pointer to the destination data. -*/ -static __rte_always_inline void * -rte_memcpy(void *__rte_restrict dst, const void *__rte_restrict src, size_t n); -/** * Copy bytes from one location to another, * locations must not overlap.
@@ -187,7 +172,8 @@ rte_mov256(uint8_t *__rte_restrict dst, const uint8_t *__rte_restrict src)* AVX512 implementation below */ -#define ALIGNMENT_MASK 0x3F +#define RTE_MEMCPY_ALIGNMENT_MASK 0x3F +#define RTE_MEMCPY_BLOCK_64_MAX 512/** * Copy 128-byte blocks from one location to another,
@@ -333,7 +319,8 @@ rte_memcpy_generic_more_than_64(void *__rte_restrict dst, const void *__rte_rest* AVX implementation below */ -#define ALIGNMENT_MASK 0x1F +#define RTE_MEMCPY_ALIGNMENT_MASK 0x1F +#define RTE_MEMCPY_BLOCK_64_MAX 256/** * Copy 128-byte blocks from one location to another,
@@ -444,7 +431,8 @@ rte_memcpy_generic_more_than_64(void *__rte_restrict dst, const void *__rte_rest* SSE implementation below */ -#define ALIGNMENT_MASK 0x0F +#define RTE_MEMCPY_ALIGNMENT_MASK 0x0F +#define RTE_MEMCPY_BLOCK_64_MAX 512/** * Macro for copying unaligned block from one location to another with constant load offset,
@@ -673,6 +661,18 @@ rte_memcpy_aligned_more_than_64(void *__rte_restrict dst, const void *__rte_restreturn ret; } +/** +* Copy bytes from one location to another. The locations must not overlap. +* +* @param dst +* Pointer to the destination of the data. +* @param src +* Pointer to the source data. +* @param n +* Number of bytes to copy. +* @return +* Pointer to the destination data. +*/ static __rte_always_inline void * rte_memcpy(void *__rte_restrict dst, const void *__rte_restrict src, size_t n) {
@@ -707,15 +707,39 @@ rte_memcpy(void *__rte_restrict dst, const void *__rte_restrict src, size_t n)#endif return dst; } +/* Common way for small copy size of 64-byte blocks. Unlikely, so constant size only */ +if (__rte_constant (n) && (n &63 ) ==0 && n <=RTE_MEMCPY_BLOCK_64_MAX ) { +void *ret = dst; + +if (n &512 ) { +rte_mov256 ((uint8_t *)dst +0 *256 , (const uint8_t *)src +0 *256 ); +rte_mov256 ((uint8_t *)dst +1 *256 , (const uint8_t *)src +1 *256 ); + } +if (n &256 ) { +rte_mov256 ((uint8_t *)dst, (const uint8_t *)src); + src = (const uint8_t *)src +256 ; + dst = (uint8_t *)dst +256 ; + } +if (n &128 ) { +rte_mov128 ((uint8_t *)dst, (const uint8_t *)src); + src = (const uint8_t *)src +128 ; + dst = (uint8_t *)dst +128 ; + } +if (n &64 ) +rte_mov64 ((uint8_t *)dst, (const uint8_t *)src); + +return ret; + }/* Implementation for size > 64 bytes depends on alignment with vector register size. */ -if (!(((uintptr_t )dst | (uintptr_t )src) &ALIGNMENT_MASK )) +if (!(((uintptr_t )dst | (uintptr_t )src) &RTE_MEMCPY_ALIGNMENT_MASK ))return rte_memcpy_aligned_more_than_64 (dst, src, n);else return rte_memcpy_generic_more_than_64 (dst, src, n); } -#undef ALIGNMENT_MASK +#undef RTE_MEMCPY_ALIGNMENT_MASK +#undef RTE_MEMCPY_BLOCK_64_MAX #ifdef __cplusplus }
Signature · 1 line
2.43.0
RFC PATCH 1/1 pile stack and mempool driver (resend)
Early submission of:
- some mempool optimizations,
- a new mempool "pile" driver, and
- its underlying "pile" stack implementation.
For community feedback and CI test.
Needless to say, this must be separated into a series of patches. For now, I'm submitting a snapshot of work in progress.
Some performance numbers from mempool_perf_autotest_2cores, all with cache=1024 cores=2 n_keep=32768:
start performance test (using ring_mp_mc, with cache) n_get_bulk= 64 n_put_bulk= 64 constant_n=0 rate_persec= 753985338 n_get_bulk=256 n_put_bulk=256 constant_n=0 rate_persec= 755805913
start performance test for lf_stack (with cache) n_get_bulk= 64 n_put_bulk= 64 constant_n=0 rate_persec= 29132352 n_get_bulk=256 n_put_bulk=256 constant_n=0 rate_persec= 29276708
start performance test for pile (with cache) n_get_bulk= 64 n_put_bulk= 64 constant_n=0 rate_persec= 560159479 n_get_bulk=256 n_put_bulk=256 constant_n=0 rate_persec= 557910933
Hat tip to Bruce for bringing attention to the ring not being the optimal mempool driver.
--- app/test/test_mempool.c | 3 +- app/test/test_stack.c | 70 ++++- app/test/test_stack_perf.c | 15 +- config/rte_config.h | 5 +- doc/guides/prog_guide/stack_lib.rst | 67 ++++- drivers/mempool/stack/rte_mempool_stack.c | 40 +++ drivers/net/bonding/rte_eth_bond_pmd.c | 2 +- drivers/net/intel/cpfl/cpfl_rxtx.h | 2 +- drivers/net/sxe2/sxe2_txrx_vec_avx512.c | 3 +- drivers/net/tap/rte_eth_tap.c | 2 +- lib/eal/include/rte_common.h | 12 + lib/eal/x86/include/rte_memcpy.h | 29 ++ lib/mempool/mempool_trace.h | 1 - lib/mempool/rte_mempool.c | 51 ++-- lib/mempool/rte_mempool.h | 74 +++-- lib/stack/meson.build | 3 +- lib/stack/rte_stack.c | 18 +- lib/stack/rte_stack.h | 77 +++++- lib/stack/rte_stack_lf.h | 6 +- lib/stack/rte_stack_lf_c11.h | 2 +- lib/stack/rte_stack_lf_generic.h | 2 +- lib/stack/rte_stack_lf_stubs.h | 2 +- lib/stack/rte_stack_pile.c | 33 +++ lib/stack/rte_stack_pile.h | 316 ++++++++++++++++++++++ lib/stack/rte_stack_std.h | 41 ++- 25 files changed, 756 insertions(+), 120 deletions(-) create mode 100644 lib/stack/rte_stack_pile.c create mode 100644 lib/stack/rte_stack_pile.h
app/test/test_mempool.c +1 -2
@@ -112,8 +112,7 @@ test_mempool_basic(struct rte_mempool *mp, int use_external_cache)GOTO_ERR (ret, out);printf ("get private data\n" ); -if (rte_mempool_get_priv (mp) != (char *)mp + -RTE_MEMPOOL_HEADER_SIZE (mp, mp->cache_size)) +if (rte_mempool_get_priv (mp) != (char *)mp +sizeof (struct rte_mempool ))GOTO_ERR (ret, out);#ifndef RTE_EXEC_ENV_FREEBSD /* rte_mem_virt2iova() not supported on bsd */
app/test/test_stack.c +56 -14
106 lines not on this page · raw message
app/test/test_stack_perf.c +13 -2
@@ -14,14 +14,14 @@#include "test.h" #define STACK_NAME "STACK_PERF" -#define MAX_BURST 32 +#define MAX_BURST RTE_MEMPOOL_CACHE_MAX_SIZE / 2#define STACK_SIZE (RTE_MAX_LCORE * MAX_BURST)/* * Push/pop bulk sizes, marked volatile so they aren't treated as compile-time * constants. */ -static volatile unsigned int bulk_sizes[] = {8 ,MAX_BURST }; +static volatile unsigned int bulk_sizes[] = {1 ,8 ,32 ,MAX_BURST };static RTE_ATOMIC (uint32_t ) lcore_barrier;
@@ -354,5 +354,16 @@ test_lf_stack_perf(void)#endif } +static int +test_pile_perf (void ) +{ +#if defined(RTE_STACK_PILE_SUPPORTED ) +return __test_stack_perf (RTE_STACK_F_PILE ); +#else +return TEST_SKIPPED ; +#endif +} +REGISTER_PERF_TEST (stack_perf_autotest, test_stack_perf);REGISTER_PERF_TEST (stack_lf_perf_autotest, test_lf_stack_perf); +REGISTER_PERF_TEST (stack_pile_perf_autotest, test_pile_perf);
config/rte_config.h +4 -1
@@ -56,7 +56,7 @@#define RTE_CONTIGMEM_DEFAULT_BUF_SIZE (512*1024*1024)/* mempool defines */ -#define RTE_MEMPOOL_CACHE_MAX_SIZE 512 +#define RTE_MEMPOOL_CACHE_MAX_SIZE 1024/* RTE_LIBRTE_MEMPOOL_STATS is not set */ /* RTE_LIBRTE_MEMPOOL_DEBUG is not set */
@@ -64,6 +64,9 @@#define RTE_MBUF_DEFAULT_MEMPOOL_OPS "ring_mp_mc"/* RTE_MBUF_HISTORY_DEBUG is not set */ +/* stack defines */ +#define RTE_STACK_PILE_BULK_SIZE 32 +/* ether defines */ #define RTE_MAX_QUEUES_PER_PORT 1024#define RTE_ETHDEV_RXTX_CALLBACKS 1
doc/guides/prog_guide/stack_lib.rst +63 -4
95 lines not on this page · raw message
drivers/mempool/stack/rte_mempool_stack.c +40 -0
@@ -41,6 +41,36 @@ lf_stack_alloc(struct rte_mempool *mp)return __stack_alloc (mp,RTE_STACK_F_LF ); } +static int +pile_alloc (struct rte_mempool *mp) +{ +return __stack_alloc (mp,RTE_STACK_F_PILE ); +} + +static int +pile_enqueue (struct rte_mempool *mp,void *const *obj_table, +unsigned int n) +{ +struct rte_stack *s = mp->pool_data; + +RTE_ASSERT (s !=NULL ); +RTE_ASSERT (obj_table !=NULL ); + +return __rte_stack_pile_push (s, obj_table, n) ==0 ? -ENOBUFS :0 ; +} + +static int +pile_dequeue (struct rte_mempool *mp,void **obj_table, +unsigned int n) +{ +struct rte_stack *s = mp->pool_data; + +RTE_ASSERT (s !=NULL ); +RTE_ASSERT (obj_table !=NULL ); + +return __rte_stack_pile_pop (s, obj_table, n) ==0 ? -ENOBUFS :0 ; +} +static int stack_enqueue (struct rte_mempool *mp,void *const *obj_table,unsigned int n)
@@ -93,5 +123,15 @@ static struct rte_mempool_ops ops_lf_stack = { .get_count = stack_get_count }; +static struct rte_mempool_ops ops_pile = { + .name ="pile" , + .alloc = pile_alloc, + .free = stack_free, + .enqueue = pile_enqueue, + .dequeue = pile_dequeue, + .get_count = stack_get_count +}; +RTE_MEMPOOL_REGISTER_OPS (ops_stack);RTE_MEMPOOL_REGISTER_OPS (ops_lf_stack); +RTE_MEMPOOL_REGISTER_OPS (ops_pile);
drivers/net/bonding/rte_eth_bond_pmd.c +1 -1
@@ -1702,7 +1702,7 @@ member_configure_slow_queue(struct rte_eth_dev *bonding_eth_dev,snprintf (mem_name,RTE_DIM (mem_name),"member_port%u_slow_pool" , member_id); port->slow_pool =rte_pktmbuf_pool_create (mem_name,8191 , -250 ,0 ,RTE_MBUF_DEFAULT_BUF_SIZE , +256 ,0 ,RTE_MBUF_DEFAULT_BUF_SIZE , member_eth_dev->data->numa_node);/* Any memory allocation failure in initialization is critical because
drivers/net/intel/cpfl/cpfl_rxtx.h +1 -1
@@ -25,7 +25,7 @@#define CPFL_P2P_QUEUE_GRP_ID 1#define CPFL_P2P_DESC_LEN 16#define CPFL_P2P_NB_MBUF 4096 -#define CPFL_P2P_CACHE_SIZE 250 +#define CPFL_P2P_CACHE_SIZE 256#define CPFL_P2P_MBUF_SIZE 2048#define CPFL_P2P_RING_BUF 128
drivers/net/sxe2/sxe2_txrx_vec_avx512.c +2 -1
@@ -67,11 +67,12 @@ static __rte_always_inline int32_t sxe2_tx_bufs_free_vec_avx512(struct sxe2_tx_q } cache->len += rs_thresh; -if (cache->len >= cache->flushthresh) { +if (cache->len >= cache->size) { (void )rte_mempool_ops_enqueue_bulk (mp, &cache->objs[cache->size], cache->len - cache->size); cache->len = cache->size; } + goto done; }
drivers/net/tap/rte_eth_tap.c +1 -1
@@ -61,7 +61,7 @@#define TAP_MAX_MAC_ADDRS 16#define TAP_GSO_MBUFS_PER_CORE 128#define TAP_GSO_MBUF_SEG_SIZE 128 -#define TAP_GSO_MBUF_CACHE_SIZE 4 +#define TAP_GSO_MBUF_CACHE_SIZE 32#define TAP_GSO_MBUFS_NUM \ (TAP_GSO_MBUFS_PER_CORE * TAP_GSO_MBUF_CACHE_SIZE)
lib/eal/include/rte_common.h +12 -0
@@ -567,6 +567,15 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void)#define __rte_assume (condition) __assume(condition)#endif +/** +* Alignment hint precondition +*/ +#ifdef RTE_TOOLCHAIN_MSVC +#define __rte_assume_aligned (ptr, alignment) (ptr) +#else +#define __rte_assume_aligned (ptr, alignment) __builtin_assume_aligned(ptr, alignment) +#endif +/** * Disable AddressSanitizer on some code */
@@ -775,6 +784,9 @@ rte_is_aligned(const void * const __rte_restrict ptr, const unsigned int align)/** Force minimum cache line alignment. */ #define __rte_cache_min_aligned __rte_aligned(RTE_CACHE_LINE_MIN_SIZE) +/** Cache alignment hint precondition */ +#define __rte_assume_cache_aligned (ptr) __rte_assume_aligned(ptr, RTE_CACHE_LINE_SIZE) +#define _RTE_CACHE_GUARD_HELPER2 (unique) \ alignas(RTE_CACHE_LINE_SIZE) \ char cache_guard_ ## unique[RTE_CACHE_LINE_SIZE * RTE_CACHE_GUARD_LINES]
lib/eal/x86/include/rte_memcpy.h +29 -0
@@ -707,6 +707,35 @@ rte_memcpy(void *__rte_restrict dst, const void *__rte_restrict src, size_t n)#endif return dst; } +/* Common way for small copy size of 64-byte blocks */ +#if defined __AVX512F__ && definedRTE_MEMCPY_AVX512 +if (__rte_constant (n) && (n &63 ) ==0 && n <=512 ) { +#elif defined RTE_MEMCPY_AVX +if (__rte_constant (n) && (n &63 ) ==0 && n <=256 ) { +#else /* SSE implementation */ +if (__rte_constant (n) && (n &63 ) ==0 && n <=512 ) { +#endif +void *ret = dst; + +if (n &512 ) { +rte_mov256 ((uint8_t *)dst +0 *256 , (const uint8_t *)src +0 *256 ); +rte_mov256 ((uint8_t *)dst +1 *256 , (const uint8_t *)src +1 *256 ); + } +if (n &256 ) { +rte_mov256 ((uint8_t *)dst, (const uint8_t *)src); + src = (const uint8_t *)src +256 ; + dst = (uint8_t *)dst +256 ; + } +if (n &128 ) { +rte_mov128 ((uint8_t *)dst, (const uint8_t *)src); + src = (const uint8_t *)src +128 ; + dst = (uint8_t *)dst +128 ; + } +if (n &64 ) +rte_mov64 ((uint8_t *)dst, (const uint8_t *)src); + +return ret; + }/* Implementation for size > 64 bytes depends on alignment with vector register size. */ if (!(((uintptr_t )dst | (uintptr_t )src) &ALIGNMENT_MASK ))
lib/mempool/mempool_trace.h +0 -1
@@ -119,7 +119,6 @@ RTE_TRACE_POINT(rte_trace_point_emit_i32 (socket_id);rte_trace_point_emit_ptr (cache);rte_trace_point_emit_u32 (cache->len); -rte_trace_point_emit_u32 (cache->flushthresh); ) RTE_TRACE_POINT(
lib/mempool/rte_mempool.c +29 -22
117 lines not on this page · raw message
lib/mempool/rte_mempool.h +35 -39
155 lines not on this page · raw message
lib/stack/meson.build +2 -1
@@ -1,7 +1,7 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2019 Intel Corporation -sources = files('rte_stack.c', 'rte_stack_std.c', 'rte_stack_lf.c') +sources = files('rte_stack.c', 'rte_stack_std.c', 'rte_stack_lf.c', 'rte_stack_pile.c') headers = files('rte_stack.h') # subheaders, not for direct inclusion by apps indirect_headers += files(
@@ -10,4 +10,5 @@ indirect_headers += files( 'rte_stack_lf_generic.h', 'rte_stack_lf_c11.h', 'rte_stack_lf_stubs.h', + 'rte_stack_pile.h', )
lib/stack/rte_stack.c +17 -1
@@ -1,5 +1,6 @@/* SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2019 Intel Corporation +* Copyright(c) 2026 SmartShare Systems */ #include <stdalign.h>
@@ -32,6 +33,8 @@ rte_stack_init(struct rte_stack *s, unsigned int count, uint32_t flags)if (flags &RTE_STACK_F_LF )rte_stack_lf_init (s, count); +else if (flags &RTE_STACK_F_PILE ) +rte_stack_pile_init (s, count);else rte_stack_std_init (s); }
@@ -41,6 +44,8 @@ rte_stack_get_memsize(unsigned int count, uint32_t flags) {if (flags &RTE_STACK_F_LF )return rte_stack_lf_get_memsize (count); +else if (flags &RTE_STACK_F_PILE ) +return rte_stack_pile_get_memsize (count);else return rte_stack_std_get_memsize (count); }
@@ -58,7 +63,11 @@ rte_stack_create(const char *name, unsigned int count, int socket_id,unsigned int sz;int ret; -if (flags & ~(RTE_STACK_F_LF )) { +if (flags & ~(RTE_STACK_F_LF |RTE_STACK_F_PILE )) { +STACK_LOG_ERR ("Unsupported stack flags %#x" , flags); +return NULL ; + } +if ((flags &RTE_STACK_F_LF ) && (flags &RTE_STACK_F_PILE )) {STACK_LOG_ERR ("Unsupported stack flags %#x" , flags);return NULL ; }
@@ -73,6 +82,13 @@ rte_stack_create(const char *name, unsigned int count, int socket_id, return NULL; }#endif +#if !defined(RTE_STACK_PILE_SUPPORTED ) +if (flags &RTE_STACK_F_PILE ) { +STACK_LOG_ERR ("Pile is not supported on your platform" ); + rte_errno =ENOTSUP ; +return NULL ; + } +#endif sz =rte_stack_get_memsize (count, flags);
lib/stack/rte_stack.h +75 -2
149 lines not on this page · raw message
lib/stack/rte_stack_lf.h +4 -2
@@ -34,7 +34,7 @@*/ static __rte_always_inline unsigned int__rte_stack_lf_push (struct rte_stack *s, -void *const *obj_table, + void * const * __rte_restrict obj_table,unsigned int n) {struct rte_stack_lf_elem *tmp, *first, *last =NULL ;
@@ -71,7 +71,8 @@ __rte_stack_lf_push(struct rte_stack *s,* - Actual number of objects popped. */ static __rte_always_inline unsigned int -__rte_stack_lf_pop (struct rte_stack *s,void **obj_table,unsigned int n) +__rte_stack_lf_pop(struct rte_stack *s, void ** __rte_restrict obj_table, +unsigned int n) {struct rte_stack_lf_elem *first, *last =NULL ;
@@ -79,6 +80,7 @@ __rte_stack_lf_pop(struct rte_stack *s, void **obj_table, unsigned int n)return 0 ;/* Pop n used elements */ +__rte_assume (obj_table !=NULL ); first =__rte_stack_lf_pop_elems (&s->stack_lf.used, n, obj_table, &last);if (unlikely (first ==NULL ))
lib/stack/rte_stack_lf_c11.h +1 -1
@@ -99,7 +99,7 @@ __rte_stack_lf_push_elems(struct rte_stack_lf_list *list, static __rte_always_inline struct rte_stack_lf_elem *__rte_stack_lf_pop_elems (struct rte_stack_lf_list *list,unsigned int num, -void **obj_table, + void ** __rte_restrict obj_table,struct rte_stack_lf_elem **last) {struct rte_stack_lf_head old_head;
lib/stack/rte_stack_lf_generic.h +1 -1
@@ -74,7 +74,7 @@ __rte_stack_lf_push_elems(struct rte_stack_lf_list *list, static __rte_always_inline struct rte_stack_lf_elem *__rte_stack_lf_pop_elems (struct rte_stack_lf_list *list,unsigned int num, -void **obj_table, + void ** __rte_restrict obj_table,struct rte_stack_lf_elem **last) {struct rte_stack_lf_head old_head;
lib/stack/rte_stack_lf_stubs.h +1 -1
@@ -30,7 +30,7 @@ __rte_stack_lf_push_elems(struct rte_stack_lf_list *list, static __rte_always_inline struct rte_stack_lf_elem *__rte_stack_lf_pop_elems (struct rte_stack_lf_list *list,unsigned int num, -void **obj_table, + void ** __rte_restrict obj_table,struct rte_stack_lf_elem **last) {RTE_SET_USED (obj_table);
lib/stack/rte_stack_pile.c new file +33 -0
@@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2026 SmartShare Systems +*/ + +#include "rte_stack.h" + +void +rte_stack_pile_init (struct rte_stack *s,unsigned int count) +{ +unsigned int bulk = (count +RTE_STACK_PILE_BULK_SIZE -1 ) /RTE_STACK_PILE_BULK_SIZE ; +struct rte_stack_pile_bulk_elem * bulk_elems = (struct rte_stack_pile_bulk_elem *)(&s->stack_pile +1 ); +struct rte_stack_lf_elem * solo_elems = (struct rte_stack_lf_elem *)&bulk_elems[bulk]; +unsigned int i; + +for (i =0 ; i < bulk; i++) +__rte_stack_pile_bulk_push_elems (&s->stack_pile.free_bulk, + &bulk_elems[i], &bulk_elems[i],1 ); +for (i =0 ; i < count; i++) +__rte_stack_lf_push_elems (&s->stack_pile.free_solo, + &solo_elems[i], &solo_elems[i],1 ); +} + +ssize_t +rte_stack_pile_get_memsize (unsigned int count) +{ +unsigned int bulk = (count +RTE_STACK_PILE_BULK_SIZE -1 ) /RTE_STACK_PILE_BULK_SIZE ; +ssize_t sz =sizeof (struct rte_stack );/* Already cache line aligned. */ + sz += bulk *sizeof (struct rte_stack_pile_bulk_elem );/* Already cache line aligned. */ + sz +=RTE_CACHE_LINE_ROUNDUP (count *sizeof (struct rte_stack_lf_elem )); + sz +=RTE_CACHE_GUARD_LINES *RTE_CACHE_LINE_SIZE ; + +return sz; +}
lib/stack/rte_stack_pile.h new file +316 -0
316 lines not on this page · raw message
lib/stack/rte_stack_std.h +19 -22
80 lines not on this page · raw message
Signature · 1 line
2.43.0
RE: [RFC PATCH] pile stack and mempool driver (resend)
PLEASE IGNORE THIS EMAIL.
Using wildcard for git send-email, and blindly hitting enter when it asks for confirmation.
Venlig hilsen / Kind regards,
-Morten Brørup
Quoted 1,826 lines
-----Original Message-----
From: Morten Brørup [mailto:[email protected]]
Sent: Tuesday, 4 August 2026 16.33
To: [email protected]; Bruce Richardson
Cc: Morten Brørup
Subject: [RFC PATCH] pile stack and mempool driver (resend)Early submission of:
- some mempool optimizations,
- a new mempool "pile" driver, and
- its underlying "pile" stack implementation.For community feedback and CI test.
Needless to say, this must be separated into a series of patches. For now, I'm submitting a snapshot of work in progress.
Some performance numbers from
mempool_perf_autotest_2cores, all with cache=1024 cores=2 n_keep=32768:start performance test (using
ring_mp_mc, with cache) n_get_bulk= 64 n_put_bulk= 64 constant_n=0 rate_persec= 753985338 n_get_bulk=256 n_put_bulk=256 constant_n=0 rate_persec= 755805913start performance test for
lf_stack(with cache) n_get_bulk= 64 n_put_bulk= 64 constant_n=0 rate_persec= 29132352 n_get_bulk=256 n_put_bulk=256 constant_n=0 rate_persec= 29276708start performance test for pile (with cache) n_get_bulk= 64 n_put_bulk= 64 constant_n=0 rate_persec= 560159479 n_get_bulk=256 n_put_bulk=256 constant_n=0 rate_persec= 557910933
Hat tip to Bruce for bringing attention to the ring not being the optimal mempool driver.
Signed-off-by Morten Brørup <[email protected]>--- app/test/test_mempool.c | 3 +- app/test/test_stack.c | 70 ++++- app/test/test_stack_perf.c | 15 +- config/rte_config.h | 5 +- doc/guides/prog_guide/stack_lib.rst | 67 ++++- drivers/mempool/stack/rte_mempool_stack.c | 40 +++ drivers/net/bonding/rte_eth_bond_pmd.c | 2 +- drivers/net/intel/cpfl/cpfl_rxtx.h | 2 +- drivers/net/sxe2/sxe2_txrx_vec_avx512.c | 3 +- drivers/net/tap/rte_eth_tap.c | 2 +- lib/eal/include/rte_common.h | 12 + lib/eal/x86/include/rte_memcpy.h | 29 ++ lib/mempool/mempool_trace.h | 1 - lib/mempool/rte_mempool.c | 51 ++-- lib/mempool/rte_mempool.h | 74 +++-- lib/stack/meson.build | 3 +- lib/stack/rte_stack.c | 18 +- lib/stack/rte_stack.h | 77 +++++- lib/stack/rte_stack_lf.h | 6 +- lib/stack/rte_stack_lf_c11.h | 2 +- lib/stack/rte_stack_lf_generic.h | 2 +- lib/stack/rte_stack_lf_stubs.h | 2 +- lib/stack/rte_stack_pile.c | 33 +++ lib/stack/rte_stack_pile.h | 316 ++++++++++++++++++++++ lib/stack/rte_stack_std.h | 41 ++- 25 files changed, 756 insertions(+), 120 deletions(-) create mode 100644 lib/stack/rte_stack_pile.c create mode 100644 lib/stack/rte_stack_pile.happ/test/test_mempool.c +1
-2@@ -112,8 +112,7 @@ test_mempool_basic(struct rte_mempool *mp, int use_external_cache)GOTO_ERR (ret ,out );printf ("get private data\n" ); -if (rte_mempool_get_priv (mp) != (char *)mp + -RTE_MEMPOOL_HEADER_SIZE (mp, mp->cache_size)) +if (rte_mempool_get_priv (mp) != (char *)mp +sizeof (struct rte_mempool ))GOTO_ERR (ret, out);#ifndef
RTE_EXEC_ENV_FREEBSD/*rte_mem_virt2iova()not supported on
bsd */app/test/test_stack.c +4
-7@@ -81,13 +81,29 @@ test_stack_push_pop(struct rte_stack *s, void **obj_table, unsigned int bulk_sz) } } -for (i =0 ; i <STACK_SIZE ; i++) { -if (obj_table[i] != popped_objs[STACK_SIZE - i -1 ]) { - printf("[%s():%u] Incorrect value %p at index 0x%x\n", - __func__, __LINE__, - popped_objs[STACK_SIZE - i -1 ], i); -rte_free (popped_objs); -return -1 ; + if (!(s->flags & RTE_STACK_F_PILE)) { +for (i =0 ; i <STACK_SIZE ; i++) { +if (obj_table[i] != popped_objs[STACK_SIZE - i -1 ]) { + printf("[%s():%u] Incorrect value %p at index0x%x\n",
app/test/test_stack.c +9
-0+ __func__, __LINE__, + popped_objs[STACK_SIZE - i - 1], i); +rte_free (popped_objs); +return -1 ; + } + } + } + + if ((s->flags & RTE_STACK_F_PILE) && (bulk_sz &(
RTE_STACK_PILE_BULK_SIZE- 1)) == 0) {app/test/test_stack.c +1
-0+for (i =0 ; i <STACK_SIZE ; i +=RTE_STACK_PILE_BULK_SIZE ){
app/test/test_stack.c +2
-0+ if (memcmp(&obj_table[i], + &popped_objs[STACK_SIZE -
RTE_STACK_PILE_BULK_SIZE- i],app/test/test_stack.c +2
-0+ RTE_STACK_PILE_BULK_SIZE) != 0) { + printf("[%s():%u] Incorrect values %p at index0x%x with bulk size %u\n",
app/test/test_stack.c +2
-0+ __func__, __LINE__, + popped_objs[STACK_SIZE -
RTE_STACK_PILE_BULK_SIZE- i], i,bulk_sz);app/test/test_stack.c +22
-5+rte_free (popped_objs); +return -1 ; + } } }@@ -152,12 +168,26 @@ test_stack_basic(uint32_t flags) goto fail_test; } - ret =rte_stack_push (s, obj_table,2 *STACK_SIZE ); -if (ret !=0 ) { -printf ("[%s():%u] Excess objects push succeeded\n" , - __func__, __LINE__); - goto fail_test; +__rte_diagnostic_push +#pragma GCC diagnostic ignored "-Warray-bounds" +#pragma GCC diagnostic ignored "-Wstringop-overread" +if (!(s->flags &RTE_STACK_F_PILE )) { + ret =rte_stack_push (s, obj_table,2 *STACK_SIZE ); +if (ret !=0 ) { +printf ("[%s():%u] Excess objects push succeeded\n" , + __func__, __LINE__); + goto fail_test; + } } +if (s->flags &RTE_STACK_F_PILE ) { + ret =rte_stack_push (s, obj_table,STACK_SIZE *RTE_STACK_PILE_BULK_SIZE +1 ); +if (ret !=0 ) { +printf ("[%s():%u] Excess objects push succeeded\n" , + __func__, __LINE__); + goto fail_test; + } + } +__rte_diagnostic_pop ret =rte_stack_pop (s, obj_table,1 );app/test/test_stack.c +2
-2if (ret !=0 ) {@@ -181,14 +211,14 @@ test_stack_name_reuse(uint32_t flags) {struct rte_stack *s[2 ]; - s[0 ] =rte_stack_create ("test" ,STACK_SIZE ,rte_socket_id (), flags); + s[0 ] =rte_stack_create (__func__,STACK_SIZE ,rte_socket_id (), flags);if (s[0 ] ==NULL ) {printf ("[%s():%u] Failed to create a stack\n" , __func__, __LINE__);return -1 ; } - s[1 ] =rte_stack_create ("test" ,STACK_SIZE ,rte_socket_id (), flags); + s[1] = rte_stack_create(__func__, STACK_SIZE, rte_socket_id(),flags);
app/test/test_stack.c +11
-0if (s[1 ] !=NULL ) {printf ("[%s():%u] Failed to detect re-used name\n" , __func__, __LINE__);@@ -300,6 +330,7 @@ stack_thread_push_pop(__rte_unused void *args) __func__, __LINE__, num);return -1 ; } +rte_compiler_barrier (); }return 0 ;@@ -384,5 +415,16 @@ test_lf_stack(void)#endif } +static int +test_pile (void ) +{ +#if defined(RTE_STACK_PILE_SUPPORTED ) +return __test_stack (RTE_STACK_F_PILE ); +#else +return TEST_SKIPPED ; +#endif +} +REGISTER_FAST_TEST (stack_autotest,NOHUGE_SKIP ,ASAN_OK , test_stack); REGISTER_FAST_TEST(stack_lf_autotest, NOHUGE_SKIP, ASAN_OK,
test_lf_stack); +REGISTER_FAST_TEST(stack_pile_autotest,NOHUGE_SKIP,ASAN_OK,test_pile);app/test/test_stack_perf.c +1
-1@@ -14,14 +14,14 @@#include "test.h" #define STACK_NAME "STACK_PERF" -#define MAX_BURST 32 +#define MAX_BURST RTE_MEMPOOL_CACHE_MAX_SIZE / 2#define STACK_SIZE (RTE_MAX_LCORE * MAX_BURST)/* * Push/pop bulk sizes, marked volatile so they aren't treated as compile-time
* constants.
*/app/test/test_stack_perf.c +12
-1-static volatile unsigned int bulk_sizes[] = {8 ,MAX_BURST }; +static volatile unsigned int bulk_sizes[] = {1 ,8 ,32 ,MAX_BURST };static RTE_ATOMIC (uint32_t ) lcore_barrier;@@ -354,5 +354,16 @@ test_lf_stack_perf(void)#endif } +static int +test_pile_perf (void ) +{ +#if defined(RTE_STACK_PILE_SUPPORTED ) +return __test_stack_perf (RTE_STACK_F_PILE ); +#else +return TEST_SKIPPED ; +#endif +} +REGISTER_PERF_TEST (stack_perf_autotest, test_stack_perf);REGISTER_PERF_TEST (stack_lf_perf_autotest, test_lf_stack_perf); +REGISTER_PERF_TEST (stack_pile_perf_autotest, test_pile_perf);config/rte_config.h +4
-1@@ -56,7 +56,7 @@#define RTE_CONTIGMEM_DEFAULT_BUF_SIZE (512*1024*1024)/* mempool defines */ -#define RTE_MEMPOOL_CACHE_MAX_SIZE 512 +#define RTE_MEMPOOL_CACHE_MAX_SIZE 1024/* RTE_LIBRTE_MEMPOOL_STATS is not set */ /* RTE_LIBRTE_MEMPOOL_DEBUG is not set */ @@ -64,6 +64,9 @@#define RTE_MBUF_DEFAULT_MEMPOOL_OPS "ring_mp_mc"/* RTE_MBUF_HISTORY_DEBUG is not set */ +/* stack defines */ +#define RTE_STACK_PILE_BULK_SIZE 32 +/* ether defines */ #define RTE_MAX_QUEUES_PER_PORT 1024#define RTE_ETHDEV_RXTX_CALLBACKS 1doc/guides/prog_guide/stack_lib.rst +2
-1@@ -1,5 +1,6 @@ .. SPDX-License-Identifier: BSD-3-Clause Copyright(c) 2019 Intel Corporation. + Copyright(c) 2026 SmartShare Systems. Stack Library =============@@ -9,9 +10,10 @@ stack of pointers. The stack library provides the following basic operations: -* Create a uniquely named stack of a user-specified size and using a +* Create a uniquely named stack (or pile) of a user-specified sizeand using a
user-specified socket, with either standard (lock-based) or lock-
free
behavior.doc/guides/prog_guide/stack_lib.rst +1
-0+ The pile resembles a lock-free stack, but is not strictly LIFO. * Push and pop a burst of one or more stack objects (pointers). These functions are multi-thread safe.@@ -25,8 +27,9 @@ The stack library provides the following basicoperations:
Implementation
---------------The library supports two types of stacks: standard (lock-based) and lock-free.
-Both types use the same set of interfaces, but their implementations differ.
+The library supports three types of stacks: standard (lock-based), lock-free,
+and pile (lock-free, not strictly LIFO, optimized for bulk operations).
+All types use the same set of interfaces, but their implementations differ...
_Stack_Library_Std_Stack:doc/guides/prog_guide/stack_lib.rst +0
-0@@ -64,7 +67,7 @@ The linked list elements themselves are maintained ina lock-free LIFO, and are
allocated before stack pushes and freed after stack pops. Since the
stack has a
fixed maximum depth, these elements do not need to be dynamically
created.-The lock-free behavior is selected by passing the *RTE_STACK_F_LF* flag to
+The lock-free behavior is selected by passing the ``RTE_STACK_F_LF`` flag to
``rte_stack_create()``.Preventing the ABA problem
doc/guides/prog_guide/stack_lib.rst +0
-0@@ -86,3 +89,59 @@ both pop stale data and incorrectly change the headpointer. By adding a
modification counter that is updated on every push and pop as part of
the
compare-and-swap, the algorithm can detect when the list changes even
if the
head pointer remains the same.doc/guides/prog_guide/stack_lib.rst +7
-0+ +.. _Stack_Library_Pile: + +Pile +~~~~ + +The pile is a stack-like implementation, optimized for bulkoperations.
+It is only LIFO on bulk level, not on object level; i.e. arrays of bulks are
+pushed and popped in LIFO manner, but objects within each bulk are not ordereddoc/guides/prog_guide/stack_lib.rst +3
-0+as expected by a stack. + +The pile implementation generally resembles that of the lock-freestack.
+In addition to the lock-free stack's linked list of solo (single- object) elements,doc/guides/prog_guide/stack_lib.rst +2
-0+it also contains a linked list of bulk (multi-object) elements. +And similar to the linked list of free elements, it contains twolinked lists of
doc/guides/prog_guide/stack_lib.rst +2
-0+free elements, one for each element type (bulk and solo). +The lock-free property means that multiple threads can push and popsimultaneously.
doc/guides/prog_guide/stack_lib.rst +4
-0+One thread being preempted/delayed in a push or pop operation will not +impede the forward progress of any other thread. + +Push operations are performed by splitting the burst in two: objectsfitting into
+bulk elements, and any remaining objects (after filling bulk elements) intodoc/guides/prog_guide/stack_lib.rst +4
-0+solo elements, and then performaing two lock-free push operations, +one for each element type (solo and bulk). + +Pop operations are performed by splitting the burst in two: objectsfitting into
+bulk elements, and any remaining objects (not filling a bulk element) intodoc/guides/prog_guide/stack_lib.rst +3
-0+solo elements. Two lock-free pop operations are performed, +first for bulk elements, and then for solo elements. +If the pop operation for bulk elements fails, it keeps retrying,requesting one
+less bulk element. The number of solo elements in the following request isdoc/guides/prog_guide/stack_lib.rst +3
-0+correspondingly increased. + +The pile's lock-free list push and pop operations use the lock-freestack's
+implementations (and uses type casting to mimick C++ class inheritance).doc/guides/prog_guide/stack_lib.rst +2
-0+ +The linked list elements themselves are maintained in two lock-freeLIFOs,
doc/guides/prog_guide/stack_lib.rst +3
-0+one for bulk elements and one for solo elements, and are +allocated before pushes and freed after pops. Since the pile has a +fixed maximum depth, these elements do not need to be dynamicallycreated.
doc/guides/prog_guide/stack_lib.rst +2
-0+ +The pile behavior is selected by passing the ``RTE_STACK_F_PILE`` flagto
+``rte_stack_create()``.doc/guides/prog_guide/stack_lib.rst +2
-0+ +The pile bulk size can be changed by modifying``RTE_STACK_PILE_BULK_SIZE`` in
+``config/rte_config.h``.doc/guides/prog_guide/stack_lib.rst +6
-0+For optimal performance when using the pile mempool driver, the +mempool cache size / 2 should be divisible by the pile bulk size. + +Note: +The pile is designed and optimized for use with bulks of objects. +Bursts not a multiple of the bulk size are still handled in a lock-free,
+forward-progress-guaranteed manner. However, pop operations may exhibit
+significantly lower performance in instances where the optimal number ofdoc/guides/prog_guide/stack_lib.rst +2
-0+bulk elements is unavailable, and it is necessary to retry (fetching +increasingly fewer bulk elements and correspondingly more soloelements).
drivers/mempool/stack/rte_mempool_stack.c +30
-0@@ -41,6 +41,36 @@ lf_stack_alloc(struct rte_mempool *mp)return __stack_alloc (mp,RTE_STACK_F_LF ); } +static int +pile_alloc (struct rte_mempool *mp) +{ +return __stack_alloc (mp,RTE_STACK_F_PILE ); +} + +static int +pile_enqueue (struct rte_mempool *mp,void *const *obj_table, +unsigned int n) +{ +struct rte_stack *s = mp->pool_data; + +RTE_ASSERT (s !=NULL ); +RTE_ASSERT (obj_table !=NULL ); + +return __rte_stack_pile_push (s, obj_table, n) ==0 ? -ENOBUFS :0 ; +} + +static int +pile_dequeue (struct rte_mempool *mp,void **obj_table, +unsigned int n) +{ +struct rte_stack *s = mp->pool_data; + +RTE_ASSERT (s !=NULL ); +RTE_ASSERT (obj_table !=NULL ); + +return __rte_stack_pile_pop (s, obj_table, n) ==0 ? -ENOBUFS :0 ; +} + static int stack_enqueue(struct rte_mempool *mp, void * const *obj_table,drivers/mempool/stack/rte_mempool_stack.c +10
-0unsigned int n)@@ -93,5 +123,15 @@ static struct rte_mempool_ops ops_lf_stack = { .get_count = stack_get_count }; +static struct rte_mempool_ops ops_pile = { + .name ="pile" , + .alloc = pile_alloc, + .free = stack_free, + .enqueue = pile_enqueue, + .dequeue = pile_dequeue, + .get_count = stack_get_count +}; +RTE_MEMPOOL_REGISTER_OPS (ops_stack);RTE_MEMPOOL_REGISTER_OPS (ops_lf_stack); +RTE_MEMPOOL_REGISTER_OPS (ops_pile);drivers/net/bonding/rte_eth_bond_pmd.c +1
-1@@ -1702,7 +1702,7 @@ member_configure_slow_queue(struct rte_eth_dev *bonding_eth_dev,snprintf (mem_name,RTE_DIM (mem_name),"member_port%u_slow_pool" , member_id); port->slow_pool =rte_pktmbuf_pool_create (mem_name,8191 , -250 ,0 ,RTE_MBUF_DEFAULT_BUF_SIZE , +256 ,0 ,RTE_MBUF_DEFAULT_BUF_SIZE , member_eth_dev->data->numa_node);/* Any memory allocation failure in initialization is
critical becausedrivers/net/intel/cpfl/cpfl_rxtx.h +1
-1@@ -25,7 +25,7 @@#define CPFL_P2P_QUEUE_GRP_ID 1#define CPFL_P2P_DESC_LEN 16#define CPFL_P2P_NB_MBUF 4096 -#define CPFL_P2P_CACHE_SIZE 250 +#define CPFL_P2P_CACHE_SIZE 256#define CPFL_P2P_MBUF_SIZE 2048#define CPFL_P2P_RING_BUF 128drivers/net/sxe2/sxe2_txrx_vec_avx512.c +0
-0@@ -67,11 +67,12 @@ static __rte_always_inline int32_tsxe2_tx_bufs_free_vec_avx512(struct
sxe2_tx_qdrivers/net/sxe2/sxe2_txrx_vec_avx512.c +1
-1} cache->len += rs_thresh; -if (cache->len >= cache->flushthresh) { +if (cache->len >= cache->size) { (void)rte_mempool_ops_enqueue_bulk(mp, &cache->objs[cache->size], cache->len -
cache->size);drivers/net/sxe2/sxe2_txrx_vec_avx512.c +1
-0cache->len = cache->size; } + goto done; }drivers/net/tap/rte_eth_tap.c +1
-1@@ -61,7 +61,7 @@#define TAP_MAX_MAC_ADDRS 16#define TAP_GSO_MBUFS_PER_CORE 128#define TAP_GSO_MBUF_SEG_SIZE 128 -#define TAP_GSO_MBUF_CACHE_SIZE 4 +#define TAP_GSO_MBUF_CACHE_SIZE 32#define TAP_GSO_MBUFS_NUM \ (TAP_GSO_MBUFS_PER_CORE * TAP_GSO_MBUF_CACHE_SIZE)lib/eal/include/rte_common.h +9
-0@@ -567,6 +567,15 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void) #define __rte_assume(condition) __assume(condition)#endif +/** +* Alignment hint precondition +*/ +#ifdef RTE_TOOLCHAIN_MSVC +#define __rte_assume_aligned (ptr, alignment) (ptr) +#else +#define __rte_assume_aligned (ptr, alignment) __builtin_assume_aligned(ptr, alignment) +#endif +/** * Disable AddressSanitizer on some code
*/lib/eal/include/rte_common.h +3
-0@@ -775,6 +784,9 @@ rte_is_aligned(const void * const __rte_restrict ptr, const unsigned int align)/** Force minimum cache line alignment. */ #define __rte_cache_min_aligned __rte_aligned(RTE_CACHE_LINE_MIN_SIZE) +/** Cache alignment hint precondition */ +#define __rte_assume_cache_aligned (ptr) __rte_assume_aligned(ptr, RTE_CACHE_LINE_SIZE) +#define _RTE_CACHE_GUARD_HELPER2 (unique) \lib/eal/include/rte_common.h +0
-0alignas(RTE_CACHE_LINE_SIZE) \ char cache_guard_ ## unique[RTE_CACHE_LINE_SIZE *
RTE_CACHE_GUARD_LINES]lib/eal/x86/include/rte_memcpy.h +29
-0@@ -707,6 +707,35 @@ rte_memcpy(void *__rte_restrict dst, const void *__rte_restrict src, size_t n)#endif return dst; } +/* Common way for small copy size of 64-byte blocks */ +#if defined __AVX512F__ && definedRTE_MEMCPY_AVX512 +if (__rte_constant (n) && (n &63 ) ==0 && n <=512 ) { +#elif defined RTE_MEMCPY_AVX +if (__rte_constant (n) && (n &63 ) ==0 && n <=256 ) { +#else /* SSE implementation */ +if (__rte_constant (n) && (n &63 ) ==0 && n <=512 ) { +#endif +void *ret = dst; + +if (n &512 ) { +rte_mov256 ((uint8_t *)dst +0 *256 , (const uint8_t *)src +0 *256 ); +rte_mov256 ((uint8_t *)dst +1 *256 , (const uint8_t *)src +1 *256 ); + } +if (n &256 ) { +rte_mov256 ((uint8_t *)dst, (const uint8_t *)src); + src = (const uint8_t *)src +256 ; + dst = (uint8_t *)dst +256 ; + } +if (n &128 ) { +rte_mov128 ((uint8_t *)dst, (const uint8_t *)src); + src = (const uint8_t *)src +128 ; + dst = (uint8_t *)dst +128 ; + } +if (n &64 ) +rte_mov64 ((uint8_t *)dst, (const uint8_t *)src); + +return ret; + }/* Implementation for size > 64 bytes depends on alignment with
vector register size. */lib/eal/x86/include/rte_memcpy.h +0
-0if (!(((uintptr_t )dst | (uintptr_t )src) &ALIGNMENT_MASK ))lib/mempool/mempool_trace.h +0
-1@@ -119,7 +119,6 @@ RTE_TRACE_POINT(rte_trace_point_emit_i32 (socket_id);rte_trace_point_emit_ptr (cache);rte_trace_point_emit_u32 (cache->len); -rte_trace_point_emit_u32 (cache->flushthresh); ) RTE_TRACE_POINT(lib/mempool/rte_mempool.c +0
-1@@ -753,14 +753,13 @@ static void mempool_cache_init(struct rte_mempool_cache *cache, uint32_t size) { cache->size = size; - cache->flushthresh = size;/* Obsolete; for API/ABI compatibility purposes only */
cache->len= 0;
}/*
* Create and initialize a cache for objects that are retrieved from
and
* returned to an underlying mempool. This structure is identical to
the
- * local_cache[lcore_id] pointed to by the mempool structure.
+ * local_cache[lcore_id] entry in the mempool structure. */
RTE_EXPORT_SYMBOL(rte_mempool_cache_create)
structrte_mempool_cache*lib/mempool/rte_mempool.c +2
-0@@ -838,9 +837,21 @@ rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size, return NULL; } +/* +* Alignment requirement for performance optimized move within the mempool cache.
lib/mempool/rte_mempool.c +5
-0+* @ref rte_mempool_do_generic_put() implementation. +*/ +if (cache_size &31 ) { +unsigned int rounded =RTE_ALIGN_MUL_CEIL (cache_size,32 ); + RTE_MEMPOOL_LOG(WARNING, "%s cache size %u not divisible by32, using %u instead.",
lib/mempool/rte_mempool.c +7
-2+ name, cache_size, rounded); + cache_size = rounded; + } +/* asked cache too big */ if (cache_size >RTE_MEMPOOL_CACHE_MAX_SIZE || cache_size > n) { +RTE_MEMPOOL_LOG (ERR ,"Cache size too big." ); rte_errno =EINVAL ;return NULL ; }@@ -884,7 +895,7 @@ rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size, goto exit_unlock; } - mempool_size =RTE_MEMPOOL_HEADER_SIZE (mp, cache_size); + mempool_size =sizeof (struct rte_mempool ); mempool_size += private_data_size; mempool_size =RTE_ALIGN_CEIL (mempool_size,RTE_MEMPOOL_ALIGN );@@ -900,7 +911,7 @@ rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,/* init the mempool structure */ mp = mz->addr; -memset (mp,0 ,RTE_MEMPOOL_HEADER_SIZE (mp, cache_size)); +memset (mp,0 , mempool_size); ret =strlcpy (mp->name, name,sizeof (mp->name));if (ret <0 || ret >= (int )sizeof (mp->name)) {lib/mempool/rte_mempool.c +0
-7rte_errno =ENAMETOOLONG ;@@ -937,13 +948,6 @@ rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size, goto exit_unlock; } -/* -* local_cache pointer is set even if cache_size is zero. -* The local_cache points to just past the elt_pa[] array. -*/ - mp->local_cache = (struct rte_mempool_cache *) -RTE_PTR_ADD (mp,RTE_MEMPOOL_HEADER_SIZE (mp,0 )); -/* Init all default caches. */ if (cache_size !=0 ) {lib/mempool/rte_mempool.c +1
-0for (lcore_id =0 ; lcore_id <RTE_MAX_LCORE ; lcore_id++)@@ -1197,6 +1201,7 @@ mempool_obj_audit(struct rte_mempool *mp, __rte_unused void *opaque,RTE_MEMPOOL_CHECK_COOKIES (mp, &obj,1 ,2 ); } +/* check cookies before and after objects */ static void mempool_audit_cookies (struct rte_mempool *mp){
lib/mempool/rte_mempool.c +13
-8@@ -1213,23 +1218,28 @@ mempool_audit_cookies(struct rte_mempool *mp)#define mempool_audit_cookies (mp) do {} while(0)#endif -/* check cookies before and after objects */ +/* check cache size consistency */ static void mempool_audit_cache (const struct rte_mempool *mp) { -/* check cache size consistency */ unsigned lcore_id; +const uint32_t cache_size = mp->cache_size; -if (mp->cache_size ==0 ) -return ; +if (cache_size >RTE_MEMPOOL_CACHE_MAX_SIZE ) { +RTE_MEMPOOL_LOG (CRIT ,"badness on cache size" ); +rte_panic ("MEMPOOL: invalid cache size\n" ); + }for (lcore_id =0 ; lcore_id <RTE_MAX_LCORE ; lcore_id++) {const struct rte_mempool_cache *cache; cache = &mp->local_cache[lcore_id]; -if (cache->len >RTE_DIM (cache->objs)) { -RTE_MEMPOOL_LOG (CRIT ,"badness on cache[%u]" , - lcore_id); -rte_panic ("MEMPOOL: invalid cache len\n" ); +if (cache->size != cache_size) { +RTE_MEMPOOL_LOG (CRIT ,"badness on cache[%u] size" , lcore_id); +rte_panic ("MEMPOOL: invalid cache[%u] size\n" , lcore_id); + } +if (cache->len > cache_size) { +RTE_MEMPOOL_LOG (CRIT ,"badness on cache[%u] len" , lcore_id); + rte_panic("MEMPOOL: invalid cache[%u] len\n",
lcore_id);lib/mempool/rte_mempool.c +0
-3} } }@@ -1241,9 +1251,6 @@ rte_mempool_audit(struct rte_mempool *mp){ mempool_audit_cache(mp); mempool_audit_cookies(mp); - -/* For case where mempool DEBUG is not set, and cache size is 0 */ -RTE_SET_USED (mp); }/* dump the status of the mempool on the console */
lib/mempool/rte_mempool.h +0
-1@@ -89,14 +89,14 @@ struct __rte_cache_aligned rte_mempool_debug_stats{ */ struct __rte_cache_aligned rte_mempool_cache {uint32_t size;/**< Size of the cache */ -uint32_t flushthresh;/**< Obsolete; for API/ABI compatibility purposes only */
lib/mempool/rte_mempool.h +0
-1uint32_t len;/**< Current cache count */ #ifdef RTE_LIBRTE_MEMPOOL_STATS -uint32_t unused;/* * Alternative location for the most frequently updated mempool statistics (per-lcore),
lib/mempool/rte_mempool.h +1
-0* providing faster update access when using a mempool cache. +* Note: 16-byte aligned for optimal SIMD access, when updating pairs of counters.
lib/mempool/rte_mempool.h +1
-0*/ + alignas(16) struct { uint64_t put_bulk; /**< Number of puts. */ uint64_t put_objs; /**< Number of objectssuccessfully put. */
lib/mempool/rte_mempool.h +0
-0@@ -104,15 +104,9 @@ struct __rte_cache_aligned rte_mempool_cache {uint64_t get_success_objs;/**< Objects successfully allocated. */
lib/mempool/rte_mempool.h +0
-5} stats; /**< Statistics */#endif -/** -* Cache objects -* -* Note: -* Cache is allocated at double size for API/ABI compatibility purposes only.
lib/mempool/rte_mempool.h +0
-4-* When reducing its size at an API/ABI breaking release, -* remember to add a cache guard after it. -*/ - alignas(RTE_CACHE_LINE_SIZE) void*objs[RTE_MEMPOOL_CACHE_MAX_SIZE * 2];
lib/mempool/rte_mempool.h +2
-0+/** Cache objects */ + alignas(RTE_CACHE_LINE_SIZE) void*objs[RTE_MEMPOOL_CACHE_MAX_SIZE];
lib/mempool/rte_mempool.h +2
-2+RTE_CACHE_GUARD ; };/** @@ -240,8 +234,7 @@ struct __rte_cache_aligned rte_mempool {unsigned int flags;/**< Flags of the mempool. */ int socket_id;/**< Socket id passed at create. */ uint32_t size;/**< Max size of the mempool. */ -uint32_t cache_size; -/**< Size of per-lcore default local cache. */ +uint32_t cache_size;/**< Size of per-lcore default local cache. */
lib/mempool/rte_mempool.h +0
-0uint32_t elt_size;/**< Size of an element. */ uint32_t header_size;/**< Size of header (before elt). */
lib/mempool/rte_mempool.h +0
-2@@ -257,13 +250,13 @@ struct __rte_cache_aligned rte_mempool {*/ int32_t ops_index; -struct rte_mempool_cache *local_cache;/**< Per-lcore local cache */ -uint32_t populated_size;/**< Number of populated objects. */
structrte_mempool_objhdr_listelt_list; /**< List of objects in
pool */lib/mempool/rte_mempool.h +0
-0uint32_t nb_mem_chunks;/**< Number of memory chunks */ struct rte_mempool_memhdr_list mem_list;/**< List of memory chunks */
lib/mempool/rte_mempool.h +1
-0+struct rte_mempool_cache local_cache[RTE_MAX_LCORE ];/**< Per- lcore local cache */
lib/mempool/rte_mempool.h +3
-0+#ifdef RTE_LIBRTE_MEMPOOL_STATS /** Per-lcore statistics. * @@ -271,6 +264,8 @@ struct __rte_cache_aligned rte_mempool {*/ struct rte_mempool_debug_stats stats[RTE_MAX_LCORE +1 ];#endif + +/* Private data are located immediately after the mempool structure. */
};/** Spreading among memory channels not required. */
lib/mempool/rte_mempool.h +1
-13@@ -362,18 +357,6 @@ struct __rte_cache_aligned rte_mempool {#define RTE_MEMPOOL_CACHE_STAT_ADD (cache, name, n) do {} while (0)#endif -/** -* @internal Calculate the size of the mempool header. -* -* @param mp -* Pointer to the memory pool. -* @param cs -* Size of the per-lcore cache. -*/ -#define RTE_MEMPOOL_HEADER_SIZE (mp, cs) \ - (sizeof(*(mp)) + (((cs) == 0) ? 0 : \ - (sizeof(struct rte_mempool_cache) * RTE_MAX_LCORE))) -/* return the header of a mempool object (internal) */ static inline struct rte_mempool_objhdr *rte_mempool_get_header (void *obj)@@ -718,7 +701,7 @@ struct __rte_cache_aligned rte_mempool_ops {rte_mempool_dequeue_contig_blocks_t dequeue_contig_blocks; }; -#define RTE_MEMPOOL_MAX_OPS_IDX 16/**< Max registered ops structs */ +#define RTE_MEMPOOL_MAX_OPS_IDX 32/**< Max registered ops structs */ /** * Structure storing the table of registered ops structs, each of which contain
lib/mempool/rte_mempool.h +1
-1@@ -1049,7 +1032,7 @@ rte_mempool_free(struct rte_mempool *mp);* If cache_size is non-zero, the rte_mempool library will try to * limit the accesses to the common lockless pool, by maintaining a * per-lcore object cache. This argument must be lower or equal to -* RTE_MEMPOOL_CACHE_MAX_SIZE and n. +* RTE_MEMPOOL_CACHE_MAX_SIZE and n, and it must be divisible by 32. * The access to the per-lcore table is of course * faster than the multi-producer/consumer pool. The cache can be * disabled if the cache_size argument is set to 0; it can be useful to
lib/mempool/rte_mempool.h +6
-5@@ -1368,15 +1351,16 @@ rte_mempool_cache_free(struct rte_mempool_cache *cache); static __rte_always_inline struct rte_mempool_cache *rte_mempool_default_cache (struct rte_mempool *mp,unsigned lcore_id) { -if (unlikely (mp->cache_size ==0 )) +if (unlikely (lcore_id ==LCORE_ID_ANY ))return NULL ; -if (unlikely (lcore_id ==LCORE_ID_ANY )) +struct rte_mempool_cache *cache = &mp->local_cache[lcore_id]; + +if (unlikely (cache->size ==0 ))return NULL ; -rte_mempool_trace_default_cache (mp, lcore_id, - &mp->local_cache[lcore_id]); -return &mp->local_cache[lcore_id]; +rte_mempool_trace_default_cache (mp, lcore_id, cache); +return cache; }/**
lib/mempool/rte_mempool.h +1
-3@@ -1445,9 +1429,22 @@ rte_mempool_do_generic_put(struct rte_mempool*mp, void * const *obj_table, * are more hot, from the upper half of the cache. */ __rte_assume (cache->len > cache->size /2 ); -rte_mempool_ops_enqueue_bulk (mp, &cache->objs[0 ], cache- >size / 2); -rte_memcpy (&cache->objs[0 ], &cache->objs[cache->size /2 ], -sizeof (void *) * (cache->len - cache->size / 2)); + rte_mempool_ops_enqueue_bulk(mp, cache->objs, cache->size /2);
lib/mempool/rte_mempool.h +3
-0+/* +* For improved rte_memcpy() performance, move down objects +* from CPU cache line aligned address in chunks of 32 bytes.
lib/mempool/rte_mempool.h +1
-0+* Note: For cache->objs[cache->size / 2] to be cache line aligned,
cache->sizelib/mempool/rte_mempool.h +1
-0+* must be divisible by 32 on 32-bit architecture with 64- byte cache line,
lib/mempool/rte_mempool.h +1
-0+* divisible by 32 on 64-bit architecture with 128-byte cache line, and
lib/mempool/rte_mempool.h +1
-0+* be divisible by 16 on 64-bit architecture with 64-byte cache line.
lib/mempool/rte_mempool.h +1
-0+* For API consistency, require mempool cache size is divisible by 32.
lib/mempool/rte_mempool.h +3
-0+*/ + const size_t move = RTE_ALIGN_MUL_CEIL( + sizeof(void *) * (cache->len - cache->size /2), 32);
lib/mempool/rte_mempool.h +3
-0+__rte_assume (move >=32 ); +__rte_assume ((move &31 ) ==0 ); + rte_memcpy(cache->objs, __rte_assume_cache_aligned(&cache-Quoted 1 line
objs[cache->size / 2]),
lib/mempool/rte_mempool.h +2
-2+ move); cache_objs = &cache->objs[cache->len - cache->size /2 ]; cache->len = cache->len - cache->size /2 + n; }else {@@ -1892,8 +1889,7 @@ void rte_mempool_audit(struct rte_mempool *mp);*/ static inline void *rte_mempool_get_priv (struct rte_mempool *mp) { -return (char *)mp + -RTE_MEMPOOL_HEADER_SIZE (mp, mp->cache_size); +return (char *)mp +sizeof (struct rte_mempool ); }/** lib/stack/meson.build +1
-1@@ -1,7 +1,7 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2019 Intel Corporation -sources = files('rte_stack.c', 'rte_stack_std.c', 'rte_stack_lf.c') +sources = files('rte_stack.c', 'rte_stack_std.c', 'rte_stack_lf.c', 'rte_stack_pile.c') headers = files('rte_stack.h') # subheaders, not for direct inclusion by apps
indirect_headers+= files(lib/stack/meson.build +1
-0@@ -10,4 +10,5 @@ indirect_headers += files( 'rte_stack_lf_generic.h', 'rte_stack_lf_c11.h', 'rte_stack_lf_stubs.h', + 'rte_stack_pile.h', )lib/stack/rte_stack.c +3
-0@@ -1,5 +1,6 @@/* SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2019 Intel Corporation +* Copyright(c) 2026 SmartShare Systems */ #include <stdalign.h> @@ -32,6 +33,8 @@ rte_stack_init(struct rte_stack *s, unsigned int count, uint32_t flags)if (flags &RTE_STACK_F_LF )rte_stack_lf_init (s, count); +else if (flags &RTE_STACK_F_PILE ) +rte_stack_pile_init (s, count);else rte_stack_std_init (s);}
lib/stack/rte_stack.c +2
-0@@ -41,6 +44,8 @@ rte_stack_get_memsize(unsigned int count, uint32_t flags) {if (flags &RTE_STACK_F_LF )return rte_stack_lf_get_memsize (count); +else if (flags &RTE_STACK_F_PILE ) +return rte_stack_pile_get_memsize (count);else return rte_stack_std_get_memsize (count);}
lib/stack/rte_stack.c +5
-1@@ -58,7 +63,11 @@ rte_stack_create(const char *name, unsigned int count, int socket_id, unsigned int sz;int ret; -if (flags & ~(RTE_STACK_F_LF )) { +if (flags & ~(RTE_STACK_F_LF |RTE_STACK_F_PILE )) { +STACK_LOG_ERR ("Unsupported stack flags %#x" , flags); +return NULL ; + } +if ((flags &RTE_STACK_F_LF ) && (flags &RTE_STACK_F_PILE )) {STACK_LOG_ERR ("Unsupported stack flags %#x" , flags);return NULL ;lib/stack/rte_stack.c +7
-0}@@ -73,6 +82,13 @@ rte_stack_create(const char *name, unsigned int count, int socket_id, return NULL; }#endif +#if !defined(RTE_STACK_PILE_SUPPORTED ) +if (flags &RTE_STACK_F_PILE ) { +STACK_LOG_ERR ("Pile is not supported on your platform" ); + rte_errno =ENOTSUP ; +return NULL ; + } +#endif sz =rte_stack_get_memsize (count, flags);lib/stack/rte_stack.h +12
-0@@ -1,5 +1,6 @@/* SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2019 Intel Corporation +* Copyright(c) 2026 SmartShare Systems */ /** @@ -28,11 +29,45 @@#define RTE_STACK_NAMESIZE (RTE_MEMZONE_NAMESIZE - \ sizeof(RTE_STACK_MZ_PREFIX) + 1) +static_assert (((sizeof (void *) *RTE_STACK_PILE_BULK_SIZE ) &RTE_CACHE_LINE_MASK ) ==0 , +"Pile bulk size must be divisible by CPU cache line size" ); + +/* Note: Also used as solo (single-object) pile element. */ struct rte_stack_lf_elem {void *data;/**< Data pointer */ struct rte_stack_lf_elem *next;/**< Next pointer */ }; +/* +* Bulk (multi-object) pile element. +* Inherited from the rte_stack_lf_elem (single-object) class, +* and extended with an array for holding a bulk of object pointers. +*/ +struct rte_stack_pile_bulk_elem { +/* The first part must be compatible with the rte_stack_lf_elem parent class. */
lib/stack/rte_stack.h +1
-0+void *data;/**< Data pointer (unused) */
lib/stack/rte_stack.h +4
-0+struct rte_stack_pile_bulk_elem *next;/**< Next pointer */ +/* The second part differs. */ + alignas(RTE_CACHE_LINE_SIZE ) +void *objs[RTE_STACK_PILE_BULK_SIZE ];/**< Bulk (multi- object) pointers */
lib/stack/rte_stack.h +18
-0+}; + +static_assert (sizeof (struct rte_stack_lf_elem ) == +sizeof (struct rte_stack_lf_elem *) +sizeof (void *), +"Parent type has changed" ); +static_assert(RTE_SIZEOF_FIELD(struct rte_stack_lf_elem, next) == + RTE_SIZEOF_FIELD(struct rte_stack_pile_bulk_elem, next), + "Inherited type mismatch"); +static_assert (offsetof(struct rte_stack_lf_elem , next) == + offsetof(struct rte_stack_pile_bulk_elem , next), +"Inherited type mismatch" ); +static_assert(RTE_SIZEOF_FIELD(struct rte_stack_lf_elem, data) == + RTE_SIZEOF_FIELD(struct rte_stack_pile_bulk_elem, data), + "Inherited type mismatch"); +static_assert (offsetof(struct rte_stack_lf_elem , data) == + offsetof(struct rte_stack_pile_bulk_elem , data), +"Inherited type mismatch" ); + struct __rte_aligned(16) rte_stack_lf_head {struct rte_stack_lf_elem *top;/**< Stack top */ uint64_t cnt;/**< Modification counter for avoiding ABA problem */
lib/stack/rte_stack.h +4
-0@@ -51,12 +86,35 @@ struct rte_stack_lf_list {struct rte_stack_lf {/** LIFO list of elements */ alignas(RTE_CACHE_LINE_SIZE )struct rte_stack_lf_list used; +RTE_CACHE_GUARD ;/** LIFO list of free elements */ alignas(RTE_CACHE_LINE_SIZE )struct rte_stack_lf_list free; +RTE_CACHE_GUARD ;/** LIFO elements */ alignas(RTE_CACHE_LINE_SIZE )struct rte_stack_lf_elem elems[]; }; +/* Pile structure containing three lock-free LIFO-like lists: +* - A list of elements, each element holding a bulk of pointers to objects.
+ * - A list of elements, each element holding one pointer to an object.
+ * - A list of free linked-list elements.
+ */lib/stack/rte_stack.h +16
-0+struct rte_stack_pile { +/** LIFO list of bulk (multi-object) elements */ + alignas(RTE_CACHE_LINE_SIZE )struct rte_stack_lf_list bulk; +RTE_CACHE_GUARD ; +/** LIFO list of solo (single-object) elements */ + alignas(RTE_CACHE_LINE_SIZE )struct rte_stack_lf_list solo; +RTE_CACHE_GUARD ; +/** LIFO list of free bulk elements */ + alignas(RTE_CACHE_LINE_SIZE )struct rte_stack_lf_list free_bulk; +RTE_CACHE_GUARD ; +/** LIFO list of free solo elements */ + alignas(RTE_CACHE_LINE_SIZE )struct rte_stack_lf_list free_solo; +RTE_CACHE_GUARD ; +/** LIFO elements follow, first bulk, then solo */ +}; +/* Structure containing the LIFO, its current length, and a lock for mutual
* exclusion.
*/lib/stack/rte_stack.h +0
-0@@ -78,6 +136,7 @@ struct __rte_cache_aligned rte_stack {uint32_t flags;/**< Flags supplied at creation. */ union {struct rte_stack_lf stack_lf;/**< Lock-free LIFO structure. */
lib/stack/rte_stack.h +1
-0+struct rte_stack_pile stack_pile;/**< Lock-free pile (LIFO-like) structure. */
lib/stack/rte_stack.h +4
-0struct rte_stack_std stack_std;/**< LIFO structure. */ }; };@@ -88,8 +147,16 @@ struct __rte_cache_aligned rte_stack {*/ #define RTE_STACK_F_LF 0x0001 +/** +* The stack-like pile uses lock-free push and pop functions. +* It is optimized for bulks of objects, and is not strictly LIFO. +* This flag is only supported on x86_64 or arm64 platforms, currently.
+ */lib/stack/rte_stack.h +6
-1+#define RTE_STACK_F_PILE 0x0002 +#include "rte_stack_std.h" #include "rte_stack_lf.h" +#include "rte_stack_pile.h" #ifdef __cplusplusextern "C" {@@ -108,13 +175,15 @@ extern "C" {* Actual number of objects pushed (either 0 or *n*). */ static __rte_always_inline unsigned int -rte_stack_push(struct rte_stack *s, void * const *obj_table, unsigned int n) +rte_stack_push (struct rte_stack *s,void *const * __rte_restrict obj_table, unsigned int n) {RTE_ASSERT (s !=NULL );RTE_ASSERT (obj_table !=NULL );if (s->flags &RTE_STACK_F_LF )return __rte_stack_lf_push (s, obj_table, n); +else if (s->flags &RTE_STACK_F_PILE ) +return __rte_stack_pile_push (s, obj_table, n);else lib/stack/rte_stack.h +3
-1return __rte_stack_std_push (s, obj_table, n); }@@ -132,13 +201,15 @@ rte_stack_push(struct rte_stack *s, void * const*obj_table, unsigned int n) * Actual number of objects popped (either 0 or *n*). */ static __rte_always_inline unsigned int -rte_stack_pop (struct rte_stack *s,void **obj_table,unsigned int n) +rte_stack_pop(struct rte_stack *s, void ** __rte_restrict obj_table,unsigned int n) {RTE_ASSERT (s !=NULL );RTE_ASSERT (obj_table !=NULL );if (s->flags &RTE_STACK_F_LF )return __rte_stack_lf_pop (s, obj_table, n); +else if (s->flags &RTE_STACK_F_PILE ) +return __rte_stack_pile_pop (s, obj_table, n);else lib/stack/rte_stack.h +2
-0return __rte_stack_std_pop (s, obj_table, n); }@@ -158,6 +229,8 @@ rte_stack_count(struct rte_stack *s)if (s->flags &RTE_STACK_F_LF )return __rte_stack_lf_count (s); +else if (s->flags &RTE_STACK_F_PILE ) +return __rte_stack_pile_count (s);else return __rte_stack_std_count (s); }lib/stack/rte_stack_lf.h +3
-2@@ -34,7 +34,7 @@*/ static __rte_always_inline unsigned int__rte_stack_lf_push (struct rte_stack *s, -void *const *obj_table, + void * const * __rte_restrict obj_table,unsigned int n) {struct rte_stack_lf_elem *tmp, *first, *last =NULL ;@@ -71,7 +71,8 @@ __rte_stack_lf_push(struct rte_stack *s,* - Actual number of objects popped. */ static __rte_always_inline unsigned int -__rte_stack_lf_pop (struct rte_stack *s,void **obj_table,unsigned int n) +__rte_stack_lf_pop (struct rte_stack *s,void ** __rte_restrict obj_table, +unsigned int n) {lib/stack/rte_stack_lf.h +1
-0struct rte_stack_lf_elem *first, *last =NULL ;@@ -79,6 +80,7 @@ __rte_stack_lf_pop(struct rte_stack *s, void **obj_table, unsigned int n)return 0 ;/* Pop n used elements */ +__rte_assume (obj_table !=NULL ); first =__rte_stack_lf_pop_elems (&s->stack_lf.used, n, obj_table, &last);lib/stack/rte_stack_lf.h +0
-0if (unlikely (first ==NULL ))lib/stack/rte_stack_lf_c11.h +1
-1@@ -99,7 +99,7 @@ __rte_stack_lf_push_elems(struct rte_stack_lf_list *list, static __rte_always_inline struct rte_stack_lf_elem *__rte_stack_lf_pop_elems (struct rte_stack_lf_list *list,unsigned int num, -void **obj_table, + void ** __rte_restrict obj_table,struct rte_stack_lf_elem **last) {lib/stack/rte_stack_lf_c11.h +0
-0struct rte_stack_lf_head old_head;lib/stack/rte_stack_lf_generic.h +1
-1@@ -74,7 +74,7 @@ __rte_stack_lf_push_elems(struct rte_stack_lf_list *list, static __rte_always_inline struct rte_stack_lf_elem *__rte_stack_lf_pop_elems (struct rte_stack_lf_list *list,unsigned int num, -void **obj_table, + void ** __rte_restrict obj_table,struct rte_stack_lf_elem **last) {lib/stack/rte_stack_lf_generic.h +0
-0struct rte_stack_lf_head old_head;lib/stack/rte_stack_lf_stubs.h +1
-1@@ -30,7 +30,7 @@ __rte_stack_lf_push_elems(struct rte_stack_lf_list *list, static __rte_always_inline struct rte_stack_lf_elem *__rte_stack_lf_pop_elems (struct rte_stack_lf_list *list,unsigned int num, -void **obj_table, + void ** __rte_restrict obj_table,struct rte_stack_lf_elem **last) {lib/stack/rte_stack_lf_stubs.h +0
-0RTE_SET_USED (obj_table);lib/stack/rte_stack_pile.c new file +10
-0@@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2026 SmartShare Systems +*/ + +#include "rte_stack.h" + +void +rte_stack_pile_init (struct rte_stack *s,unsigned int count) +{ + unsigned int bulk = (count + RTE_STACK_PILE_BULK_SIZE - 1) /
RTE_STACK_PILE_BULK_SIZE;lib/stack/rte_stack_pile.c new file +1
-0+ struct rte_stack_pile_bulk_elem * bulk_elems = (struct
rte_stack_pile_bulk_elem*)(&s->stack_pile + 1);lib/stack/rte_stack_pile.c new file +1
-0+ struct rte_stack_lf_elem * solo_elems = (struct rte_stack_lf_elem*)&bulk_elems[bulk];
lib/stack/rte_stack_pile.c new file +14
-0+unsigned int i; + +for (i =0 ; i < bulk; i++) +__rte_stack_pile_bulk_push_elems (&s->stack_pile.free_bulk, + &bulk_elems[i], &bulk_elems[i],1 ); +for (i =0 ; i < count; i++) +__rte_stack_lf_push_elems (&s->stack_pile.free_solo, + &solo_elems[i], &solo_elems[i],1 ); +} + +ssize_t +rte_stack_pile_get_memsize (unsigned int count) +{ + unsigned int bulk = (count + RTE_STACK_PILE_BULK_SIZE - 1) /
RTE_STACK_PILE_BULK_SIZE;lib/stack/rte_stack_pile.c new file +1
-0+ssize_t sz =sizeof (struct rte_stack );/* Already cache line aligned. */
lib/stack/rte_stack_pile.c new file +1
-0+ sz += bulk *sizeof (struct rte_stack_pile_bulk_elem );/* Already cache line aligned. */
lib/stack/rte_stack_pile.c new file +1
-0+ sz += RTE_CACHE_LINE_ROUNDUP(count * sizeof(struct
rte_stack_lf_elem));lib/stack/rte_stack_pile.c new file +4
-0+ sz +=RTE_CACHE_GUARD_LINES *RTE_CACHE_LINE_SIZE ; + +return sz; +}lib/stack/rte_stack_pile.h new file +26
-0@@ -0,0 +1,316 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2026 SmartShare Systems +*/ + +#ifndef _RTE_STACK_PILE_H_ +#define _RTE_STACK_PILE_H_ + +#if !(defined(RTE_ARCH_X86_64 ) || defined(RTE_ARCH_ARM64 )) +#include "rte_stack_lf_stubs.h" +#else +#ifdef RTE_USE_C11_MEM_MODEL +#include "rte_stack_lf_c11.h" +#else +#include "rte_stack_lf_generic.h" +#endif + +/** +* Indicates that RTE_STACK_F_PILE is supported. +*/ +#define RTE_STACK_PILE_SUPPORTED +#endif + +static __rte_always_inline unsigned int +__rte_stack_pile_count (struct rte_stack *s) +{ +/* stack_lf_push() and stack_lf_pop() do not update the list's contents
lib/stack/rte_stack_pile.h new file +1
-0+* and stack_lf->len atomically, which can cause the list to appear
lib/stack/rte_stack_pile.h new file +1
-0+* shorter than it actually is if this function is called while other
lib/stack/rte_stack_pile.h new file +3
-0+* threads are modifying the list. +* +* However, given the inherently approximate nature of the
get_countlib/stack/rte_stack_pile.h new file +1
-0+* callback -- even if the list and its size were updated atomically,
lib/stack/rte_stack_pile.h new file +1
-0+* the size could change between when get_count executes and when the
lib/stack/rte_stack_pile.h new file +3
-0+* value is returned to the caller -- this is acceptable. +* +* The stack_lf->len updates are placed such that the list may appear to
lib/stack/rte_stack_pile.h new file +1
-0+* have fewer elements than it does, but will never appear to have more
lib/stack/rte_stack_pile.h new file +1
-0+* elements. If the mempool is near-empty to the point that this is a
lib/stack/rte_stack_pile.h new file +5
-0+* concern, the user should consider increasing the mempool size. +*/ +#ifdef RTE_USE_C11_MEM_MODEL + return RTE_MIN((unsigned int)s->capacity, + (unsigned int)rte_atomic_load_explicit(&s-Quoted 1 line
stack_pile.bulk.len,
lib/stack/rte_stack_pile.h new file +3
-0+ rte_memory_order_relaxed) * RTE_STACK_PILE_BULK_SIZE + + (unsigned int)rte_atomic_load_explicit(&s-Quoted 1 line
stack_pile.solo.len,
lib/stack/rte_stack_pile.h new file +5
-0+ rte_memory_order_relaxed)); +#else + /* NOTE: review for potential ordering optimization */ + return RTE_MIN((unsigned int)s->capacity, + (unsigned int)rte_atomic_load_explicit(&s-Quoted 1 line
stack_pile.bulk.len,
lib/stack/rte_stack_pile.h new file +3
-0+ rte_memory_order_seq_cst) * RTE_STACK_PILE_BULK_SIZE + + (unsigned int)rte_atomic_load_explicit(&s-Quoted 1 line
stack_pile.solo.len,
lib/stack/rte_stack_pile.h new file +23
-0+ rte_memory_order_seq_cst)); +#endif +} + +static __rte_always_inline void +__rte_stack_pile_bulk_push_elems (struct rte_stack_lf_list *list, +struct rte_stack_pile_bulk_elem *first, +struct rte_stack_pile_bulk_elem *last, +unsigned int num) +{ +__rte_stack_lf_push_elems (list, + (struct rte_stack_lf_elem *)first, + (struct rte_stack_lf_elem *)last, + num); +} + +static __rte_always_inline struct rte_stack_pile_bulk_elem * +__rte_stack_pile_bulk_pop_elems (struct rte_stack_lf_list *list, +unsigned int num, + void ** __rte_restrict obj_table, +struct rte_stack_pile_bulk_elem **last) +{ + struct rte_stack_pile_bulk_elem *first = (struct
rte_stack_pile_bulk_elem*)__rte_stack_lf_pop_elems(list, num, NULL, (structrte_stack_lf_elem**)last);lib/stack/rte_stack_pile.h new file +8
-0+if (first ==NULL ) +return NULL ; + +if (obj_table !=NULL ) { +/* Traverse the list to copy the bulks. */ +struct rte_stack_pile_bulk_elem *tmp = first; +for (unsigned int i =0 ; i < num; i++, tmp = tmp->next) + rte_memcpy(&obj_table[i * RTE_STACK_PILE_BULK_SIZE],
tmp->objs,sizeof(void *)*RTE_STACK_PILE_BULK_SIZE);lib/stack/rte_stack_pile.h new file +27
-0+ } + +return first; +} + +/** +* Push several objects on the pile (lock-free, MT-safe). +* +* @param pile +* A pointer to the pile structure. +* @param obj_table +* A pointer to a table of void * pointers (objects). +* @param n +* The number of objects to push on the pile from the obj_table. +* @return +* Actual number of objects pushed (either 0 or *n*). +*/ +static __rte_always_inline unsigned int +__rte_stack_pile_push (struct rte_stack *s, + void * const * __rte_restrict obj_table, +unsigned int n) +{ +RTE_ASSERT (s !=NULL ); +RTE_ASSERT (obj_table !=NULL ); + +struct rte_stack_pile *pile = &s->stack_pile; + struct rte_stack_pile_bulk_elem *bulk_first = NULL, *bulk_last =NULL;
lib/stack/rte_stack_pile.h new file +14
-0+struct rte_stack_lf_elem *solo_first =NULL , *solo_last =NULL ; +unsigned int n_bulk = n /RTE_STACK_PILE_BULK_SIZE ; +unsigned int n_solo = n & (RTE_STACK_PILE_BULK_SIZE -1 ); +unsigned int i; + +if (unlikely (n_bulk ==0 )) { +if (unlikely (n_solo ==0 )) +return 0 ; +else + goto solo; + } + +/* Allocate n_bulk elements from the free list. */ + bulk_first = __rte_stack_pile_bulk_pop_elems(&pile->free_bulk,
n_bulk, NULL,&bulk_last);lib/stack/rte_stack_pile.h new file +9
-0+if (unlikely (bulk_first ==NULL )) +return 0 ;/* Failed. */ + +if (likely (n_solo ==0 )) + goto bulk; + +solo: +/* Allocate n_solo elements from the free list. */ + solo_first = __rte_stack_lf_pop_elems(&pile->free_solo, n_solo,NULL,
&solo_last);lib/stack/rte_stack_pile.h new file +4
-0+if (unlikely (solo_first ==NULL )) { +/* Failed. Roll back. */ +if (n_bulk >0 ) + __rte_stack_pile_bulk_push_elems(&pile->free_bulk,
bulk_first,bulk_last,n_bulk);lib/stack/rte_stack_pile.h new file +12
-0+return 0 ; + } + +/* +* Construct the solo elements. +* Copy the objects, but ignore the object order. +*/ +struct rte_stack_lf_elem *tmp_solo = solo_first; +__rte_assume (n_solo >0 ); +__rte_assume (n_solo <RTE_STACK_PILE_BULK_SIZE ); +for (i =0 ; i < n_solo; i++, tmp_solo = tmp_solo->next) + tmp_solo->data = obj_table[n_bulk *
RTE_STACK_PILE_BULK_SIZE+ i];lib/stack/rte_stack_pile.h new file +3
-0+ +/* Push them to the solo list. */ + __rte_stack_lf_push_elems(&pile->solo, solo_first, solo_last,
n_solo);lib/stack/rte_stack_pile.h new file +8
-0+ +if (unlikely (n_bulk ==0 )) +return n;/* Done. */ + +bulk: +/* +* Construct the bulk elements. +* Copy bulks in reverse order, but ignore the object order within each bulk.
lib/stack/rte_stack_pile.h new file +5
-0+*/ +struct rte_stack_pile_bulk_elem *tmp_bulk = bulk_first; +__rte_assume (n_bulk >0 ); +for (i =0 ; i < n_bulk; i++, tmp_bulk = tmp_bulk->next) + rte_memcpy(tmp_bulk->objs, &obj_table[(n_bulk - i - 1) *
RTE_STACK_PILE_BULK_SIZE],sizeof(void *)*RTE_STACK_PILE_BULK_SIZE);lib/stack/rte_stack_pile.h new file +3
-0+ +/* Push them to the bulk list. */ + __rte_stack_pile_bulk_push_elems(&pile->bulk, bulk_first,
bulk_last,n_bulk);lib/stack/rte_stack_pile.h new file +26
-0+ +return n; +} + +/** +* Pop several objects from the pile (lock-free, MT-safe). +* +* @param pile +* A pointer to the pile structure. +* @param obj_table +* A pointer to a table of void * pointers (objects). +* @param n +* The number of objects to pull from the pile. +* @return +* Actual number of objects popped (either 0 or *n*). +*/ +static __rte_always_inline unsigned int +__rte_stack_pile_pop (struct rte_stack *s, + void ** __rte_restrict obj_table, +unsigned int n) +{ +RTE_ASSERT (s !=NULL ); +RTE_ASSERT (obj_table !=NULL ); + +struct rte_stack_pile *pile = &s->stack_pile; + struct rte_stack_pile_bulk_elem *bulk_first = NULL, *bulk_last =NULL;
lib/stack/rte_stack_pile.h new file +14
-0+struct rte_stack_lf_elem *solo_first =NULL , *solo_last =NULL ; +unsigned int n_bulk = n /RTE_STACK_PILE_BULK_SIZE ; +unsigned int n_solo = n & (RTE_STACK_PILE_BULK_SIZE -1 ); +unsigned int i; + +if (unlikely (n_bulk ==0 )) { +if (unlikely (n_solo ==0 )) +return 0 ; +else + goto solo; + } + +bulk: +/* Fetch n_bulk * RTE_STACK_PILE_BULK_SIZE objects as bulk elements. */
lib/stack/rte_stack_pile.h new file +1
-0+ bulk_first = __rte_stack_pile_bulk_pop_elems(&pile->bulk, n_bulk,
obj_table,&bulk_last);lib/stack/rte_stack_pile.h new file +2
-0+if (unlikely (bulk_first ==NULL )) { +/* Not available. Retry with fewer bulk elements; objects to be fetched as solo elements instead. */
lib/stack/rte_stack_pile.h new file +14
-0+ n_solo +=RTE_STACK_PILE_BULK_SIZE ; + n_bulk--; +if (n_bulk >0 ) + goto bulk; +else + goto solo; + } + +if (likely (n_solo ==0 )) + goto done; + +solo: +/* Fetch n_solo objects as solo elements. */ + solo_first = __rte_stack_lf_pop_elems(&pile->solo, n_solo,&obj_table[n_bulk *
RTE_STACK_PILE_BULK_SIZE],&solo_last);lib/stack/rte_stack_pile.h new file +5
-0+if (solo_first !=NULL ) + goto done; + +/* Solo elements not available. Try fragmentation. */ + alignas(RTE_CACHE_LINE_SIZE) void *obj_frag[RTE_STACK_PILE_BULK_SIZE];
lib/stack/rte_stack_pile.h new file +4
-0+struct rte_stack_pile_bulk_elem *frag; + +/* Fetch a fragmentation element as a bulk element. */ + frag = __rte_stack_pile_bulk_pop_elems(&pile->bulk, 1, obj_frag,NULL);
lib/stack/rte_stack_pile.h new file +4
-0+if (unlikely (frag ==NULL )) { +/* Failed. Roll back. */ +if (n_bulk >0 ) + __rte_stack_pile_bulk_push_elems(&pile->bulk,
bulk_first,bulk_last,n_bulk);lib/stack/rte_stack_pile.h new file +8
-0+return 0 ; + } + +/* Get n_solo objects from the fragmentation element. */ +__rte_assume (n_solo >0 ); +__rte_assume (n_solo <RTE_STACK_PILE_BULK_SIZE ); +for (i =0 ; i < n_solo; i++) + obj_table[n_bulk * RTE_STACK_PILE_BULK_SIZE + i] =obj_frag[i];
lib/stack/rte_stack_pile.h new file +4
-0+ +/* Fetch free elements for the excess objects. */ +__rte_assume (RTE_STACK_PILE_BULK_SIZE - n_solo >0 ); + __rte_assume(RTE_STACK_PILE_BULK_SIZE - n_solo <
RTE_STACK_PILE_BULK_SIZE- 1);lib/stack/rte_stack_pile.h new file +1
-0+ solo_first = __rte_stack_lf_pop_elems(&pile->free_solo,
RTE_STACK_PILE_BULK_SIZE-n_solo, NULL,&solo_last);lib/stack/rte_stack_pile.h new file +5
-0+if (unlikely (solo_first ==NULL )) { +/* Failed. Roll back. */ +struct rte_stack_pile_bulk_elem *last; +if (n_bulk >0 ) { +/* Attach the bulk elements after the fragmentation element. */
lib/stack/rte_stack_pile.h new file +14
-0+ frag->next = bulk_first; + last = bulk_last; + } else + last = frag; + __rte_stack_pile_bulk_push_elems(&pile->bulk, frag, last, 1 + n_bulk); +return 0 ; + } + +/* Construct the solo elements from the excess objects. */ +struct rte_stack_lf_elem *tmp = solo_first; +__rte_assume (n_solo >0 ); +__rte_assume (n_solo <RTE_STACK_PILE_BULK_SIZE ); + for (i = n_solo; i < RTE_STACK_PILE_BULK_SIZE; i++, tmp = tmp-Quoted 1 line
next)
lib/stack/rte_stack_pile.h new file +4
-0+ tmp->data = obj_frag[i]; + +/* Push the excess objects as solo elements. */ + __rte_stack_lf_push_elems(&pile->solo, solo_first, solo_last,
RTE_STACK_PILE_BULK_SIZE-n_solo);lib/stack/rte_stack_pile.h new file +3
-0+ n_solo =0 ; + +/* Add the fragmentation element in front of the bulk elements, so it can be freed. */
lib/stack/rte_stack_pile.h new file +11
-0+if (n_bulk >0 ) + frag->next = bulk_first; +else + bulk_last = frag; + bulk_first = frag; + n_bulk++; + +done: +/* Success. Free the elements. */ +if (n_bulk >0 ) + __rte_stack_pile_bulk_push_elems(&pile->free_bulk,
bulk_first,bulk_last,n_bulk);lib/stack/rte_stack_pile.h new file +2
-0+if (n_solo >0 ) + __rte_stack_lf_push_elems(&pile->free_solo, solo_first,
solo_last,n_solo);lib/stack/rte_stack_pile.h new file +27
-0+ + return n; +} + +/** +* @internal Initialize a pile stack. +* +* @param s +* A pointer to the stack structure. +* @param count +* The size of the stack. +*/ +void +rte_stack_pile_init (struct rte_stack *s,unsigned int count); + +/** +* @internal Return the memory required for a pile stack. +* +* @param count +* The size of the stack. +* @return +* The bytes to allocate for a pile stack. +*/ +ssize_t +rte_stack_pile_get_memsize (unsigned int count); + +#endif /* _RTE_STACK_PILE_H_ */ lib/stack/rte_stack_std.h +9
-11@@ -6,6 +6,7 @@#define _RTE_STACK_STD_H_#include <rte_branch_prediction.h> +#include <rte_memcpy.h> /** * @internal Push several objects on the stack (MT-safe). @@ -20,27 +21,24 @@* Actual number of objects pushed (either 0 or *n*). */ static __rte_always_inline unsigned int -__rte_stack_std_push (struct rte_stack *s,void *const *obj_table, +__rte_stack_std_push (struct rte_stack *s,void *const * __rte_restrict obj_table,unsigned int n) { -struct rte_stack_std *stack = &s->stack_std; -unsigned int index; -void **cache_objs; + struct rte_stack_std * __rte_restrict stack = &s->stack_std; + void ** __rte_restrict stack_objs;rte_spinlock_lock (&stack->lock); - cache_objs = &stack->objs[stack->len]; -/* Is there sufficient space in the stack? */ -if ((stack->len + n) > s->capacity) { +if (unlikely ((stack->len + n) > s->capacity)) { +/* Insufficient room in the stack. */ rte_spinlock_unlock (&stack->lock);return 0 ; } -/* Add elements back into the cache */ -for (index =0 ; index < n; ++index, obj_table++) - cache_objs[index] = *obj_table; - +/* Push objects to the stack */ + stack_objs = &stack->objs[stack->len]; stack->len += n; +rte_memcpy (stack_objs, obj_table,sizeof (void *) * n);rte_spinlock_unlock (&stack->lock);lib/stack/rte_stack_std.h +10
-11return n;@@ -59,28 +57,27 @@ __rte_stack_std_push(struct rte_stack *s, void *const *obj_table, * Actual number of objects popped (either 0 or *n*). */ static __rte_always_inline unsigned int -__rte_stack_std_pop(struct rte_stack *s, void **obj_table, unsigned int n) +__rte_stack_std_pop (struct rte_stack *s,void ** __rte_restrict obj_table, unsigned int n) { -struct rte_stack_std *stack = &s->stack_std; -unsigned int index, len; -void **cache_objs; + struct rte_stack_std * __rte_restrict stack = &s->stack_std; +unsigned int index; + void ** __rte_restrict stack_objs;rte_spinlock_lock (&stack->lock);if (unlikely (n > stack->len)) { +/* Insufficient objects in the stack. */ rte_spinlock_unlock (&stack->lock);return 0 ; } - cache_objs = stack->objs; - -for (index =0 , len = stack->len -1 ; index < n; - ++index, len--, obj_table++) - *obj_table = cache_objs[len]; - +/* Pop objects from the stack */ + stack_objs = &stack->objs[stack->len]; stack->len -= n; -rte_spinlock_unlock (&stack->lock); +for (index =0 ; index < n; index++) + *obj_table++ = *--stack_objs; +rte_spinlock_unlock (&stack->lock);return n;
}--
2.43.0
lib/eal/x86/include/rte_memcpy.h rte_memcpy(void *__rte_restrict dst, const void *__rte_restrict src, size_t n) · line 713
Quoted 4 lines · On Tue, 4 Aug 2026 14:33:04 +0000 Morten Brørup <[email protected]>…
lib/eal/x86/include/rte_memcpy.h +4
-0+/* Common way for small copy size of 64-byte blocks. Unlikely, so constant size only */ +if (__rte_constant (n) && (n &63 ) ==0 && n <=RTE_MEMCPY_BLOCK_64_MAX ) { +void *ret = dst; +
Maybe just let compiler decide, it will generate vector instructions in most cases.
if (__rte_constant(n)) return mempcpy(dst, src, n);
Quoted 10 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Tuesday, 4 August 2026 17.52Review
Quoted 1 line · On Tue, 4 Aug 2026 14:33:04 +0000 Morten Brørup <[email protected]>…
(quoted diff) +1
-0+ /* Common way for small copy size of 64-byte blocks. Unlikely, soconstant size only */
Review
Quoted 1 line
(quoted diff) +1
-0+ if (__rte_constant(n) && (n & 63) == 0 && n <=
RTE_MEMCPY_BLOCK_64_MAX) {
Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ void *ret = dst; +Maybe just let compiler decide, it will generate vector instructions in most cases.
if (__rte_constant(n)) return mempcpy(dst, src, n);
Maybe in most, but not in all:
https://godbolt.org/z/KvdKqT5rY
Quoted 18 lines
Quoted 18 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Tuesday, 4 August 2026 17.52Review
Quoted 1 line · On Tue, 4 Aug 2026 14:33:04 +0000 Morten Brørup <[email protected]>…
(quoted diff) +1
-0+ /* Common way for small copy size of 64-byte blocks. Unlikely, soconstant size only */
Review
Quoted 1 line
(quoted diff) +1
-0+ if (__rte_constant(n) && (n & 63) == 0 && n <=
RTE_MEMCPY_BLOCK_64_MAX) {Review
Quoted 2 lines
(quoted diff) +2
-0+ void *ret = dst; +Maybe just let compiler decide, it will generate vector instructions in most cases.
Quoted 5 lines
Quoted 2 lines
if (__rte_constant(n)) return mempcpy(dst, src, n);Maybe in most, but not in all:
https://godbolt.org/z/KvdKqT5rY
With '-mavx' or '-mavx512f' it looks like it does for your sample code.
Quoted 21 lines
From: Konstantin Ananyev [mailto:[email protected]]
Sent: Wednesday, 5 August 2026 07.46Quoted 7 lines
Quoted 7 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Tuesday, 4 August 2026 17.52Review
Quoted 1 line · On Tue, 4 Aug 2026 14:33:04 +0000 Morten Brørup <[email protected]>…
(quoted diff) +1
-0+ /* Common way for small copy size of 64-byte blocks.Unlikely, so
Quoted 7 lines
Quoted 7 lines
constant size only */
Review
Quoted 1 line
(quoted diff) +1
-0+ if (__rte_constant(n) && (n & 63) == 0 && n <=
RTE_MEMCPY_BLOCK_64_MAX) {Review
Quoted 2 lines
(quoted diff) +2
-0+ void *ret = dst; +Maybe just let compiler decide, it will generate vector
instructions in
Quoted 2 lines
Quoted 2 lines
most cases.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
if (__rte_constant(n)) return mempcpy(dst, src, n);Maybe in most, but not in all:
https://godbolt.org/z/KvdKqT5rYWith '-mavx' or '-mavx512f' it looks like it does for your sample code.
It also does with -msse4.2 when SZ is reduced to 256 bytes. Clang switches to inline when SZ is reduced to 128 bytes.
It seems the compiler has a threshold for when to inline and when to call the C library's memcpy subroutine. The threshold depends on both copy size and vector register size.
And it is compiler dependent.
With rte_memcpy() it is always inline.
Quoted 39 lines
-----Original Message-----
From: Morten Brørup <[email protected]>
Sent: Wednesday, August 5, 2026 6:56 AM
To: Konstantin Ananyev <[email protected]>; Stephen Hemminger <[email protected]>
Cc: [email protected]; Bruce Richardson <[email protected]>
Subject: RE: [PATCH] eal/x86: optimize memcpy of small 64-byte blocksQuoted 21 lines
From: Konstantin Ananyev [mailto:[email protected]]
Sent: Wednesday, 5 August 2026 07.46Quoted 7 lines
Quoted 7 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Tuesday, 4 August 2026 17.52Review
Quoted 1 line · On Tue, 4 Aug 2026 14:33:04 +0000 Morten Brørup <[email protected]>…
(quoted diff) +1
-0+ /* Common way for small copy size of 64-byte blocks.Unlikely, so
Quoted 7 lines
Quoted 7 lines
constant size only */
Review
Quoted 1 line
(quoted diff) +1
-0+ if (__rte_constant(n) && (n & 63) == 0 && n <=
RTE_MEMCPY_BLOCK_64_MAX) {Review
Quoted 2 lines
(quoted diff) +2
-0+ void *ret = dst; +Maybe just let compiler decide, it will generate vector
instructions in
Quoted 2 lines
Quoted 2 lines
most cases.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
if (__rte_constant(n)) return mempcpy(dst, src, n);Maybe in most, but not in all:
https://godbolt.org/z/KvdKqT5rYWith '-mavx' or '-mavx512f' it looks like it does for your sample code.
Quoted 7 lines
It also does with -msse4.2 when SZ is reduced to 256 bytes. Clang switches to inline when SZ is reduced to 128 bytes.
It seems the compiler has a threshold for when to inline and when to call the C library's memcpy subroutine.
The threshold depends on both copy size and vector register size. And it is compiler dependent.
I think there are compiler options to specify desired threshold values. Let say for gcc there is ' -mmemcpy-strategy=strategy'.
For that example in that particular case -mmemcpy-strategy=vector_loop:512:align,loop:-1:align
generates sse loads/stores.
Might be we can exploit it somehow?
I am not really happy that our home-brewed memcpy code-block keeps growing, while we keep talking that it would be good to eliminate it completely.
Quoted 1 line
With
rte_memcpy()it is always inline.
Quoted 45 lines
From: Konstantin Ananyev [mailto:[email protected]]
Sent: Wednesday, 5 August 2026 08.50Quoted 31 lines
From: Morten Brørup <[email protected]>
Sent: Wednesday, August 5, 2026 6:56 AMQuoted 28 lines
From: Konstantin Ananyev [mailto:[email protected]]
Sent: Wednesday, 5 August 2026 07.46Quoted 7 lines
Quoted 7 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Tuesday, 4 August 2026 17.52Review
Quoted 1 line · On Tue, 4 Aug 2026 14:33:04 +0000 Morten Brørup <[email protected]>…
(quoted diff) +1
-0+ /* Common way for small copy size of 64-byte blocks.Unlikely, so
Quoted 7 lines
Quoted 7 lines
constant size only */
Review
Quoted 1 line
(quoted diff) +1
-0+ if (__rte_constant(n) && (n & 63) == 0 && n <=
RTE_MEMCPY_BLOCK_64_MAX) {Review
Quoted 2 lines
(quoted diff) +2
-0+ void *ret = dst; +Maybe just let compiler decide, it will generate vector
instructions in
Quoted 7 lines
Quoted 4 lines
most cases.
if (__rte_constant(n)) return mempcpy(dst, src, n);Maybe in most, but not in all:
https://godbolt.org/z/KvdKqT5rYWith '-mavx' or '-mavx512f' it looks like it does for your sample
code.
Quoted 5 lines
It also does with -msse4.2 when SZ is reduced to 256 bytes. Clang switches to inline when SZ is reduced to 128 bytes.
It seems the compiler has a threshold for when to inline and when to
call the C
Quoted 3 lines
library's memcpy subroutine.
The threshold depends on both copy size and vector register size. And it is compiler dependent.
Quoted 6 lines
I think there are compiler options to specify desired threshold values. Let say for gcc there is ' -mmemcpy-strategy=strategy'.
For that example in that particular case -mmemcpy-strategy=vector_loop:512:align,loop:-1:align generates sse loads/stores.
Might be we can exploit it somehow?
That could give us higher granularity/control over memcpy for individual memcpy instances; might be useful for hot code paths where we have more knowledge about the copy operation than the compiler can infer. However, pragmas are discouraged in DPDK, and this looks like a very similar path.
Quoted 3 lines
I am not really happy that our home-brewed memcpy code-block keeps growing,
while we keep talking that it would be good to eliminate it completely.
I agree in principle.
However, this rte_memcpy() optimization is for the pile/mempool optimizations I'm working on, so there is a specific use case motivating the added code.
Quoted 5 lines
Quoted 5 lines
With
rte_memcpy()it is always inline.
Quoted 39 lines
Quoted 32 lines
Quoted 14 lines
Quoted 14 lines
Quoted 3 lines
Quoted 3 lines
Review
Quoted 3 lines
(quoted diff) +1
-0+ /* Common way for small copy size of 64-byte blocks.Unlikely, so
Quoted 7 lines
Quoted 7 lines
constant size only */
Review
Quoted 1 line
(quoted diff) +1
-0+ if (__rte_constant(n) && (n & 63) == 0 && n <=
RTE_MEMCPY_BLOCK_64_MAX) {Review
Quoted 2 lines
(quoted diff) +2
-0+ void *ret = dst; +Maybe just let compiler decide, it will generate vector
instructions in
Quoted 2 lines
Quoted 2 lines
most cases.
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
if (__rte_constant(n)) return mempcpy(dst, src, n);Maybe in most, but not in all:
https://godbolt.org/z/KvdKqT5rYWith '-mavx' or '-mavx512f' it looks like it does for your sample
code.
Quoted 5 lines
It also does with -msse4.2 when SZ is reduced to 256 bytes. Clang switches to inline when SZ is reduced to 128 bytes.
It seems the compiler has a threshold for when to inline and when to
call the C
Quoted 3 lines
library's memcpy subroutine.
The threshold depends on both copy size and vector register size. And it is compiler dependent.Quoted 6 lines
I think there are compiler options to specify desired threshold values. Let say for gcc there is ' -mmemcpy-strategy=strategy'.
For that example in that particular case -mmemcpy-strategy=vector_loop:512:align,loop:-1:align generates sse loads/stores.
Might be we can exploit it somehow?
Quoted 5 lines
That could give us higher granularity/control over memcpy for individual memcpy instances; might be useful for hot code paths where we have more knowledge about the copy operation than the compiler can infer. However, pragmas are discouraged in DPDK, and this looks like a very similar path.
Well, right now rte_memcpy.h is 700+ lines and keeps growing. Considering that probably pragmas are not that bad.
Of course, pragmas have their own issues and it is hard to ensure that they will produce same code between different compilers/versions, etc.
Quoted 7 lines
Quoted 3 lines
I am not really happy that our home-brewed memcpy code-block keeps growing,
while we keep talking that it would be good to eliminate it completely.I agree in principle.
However, thisrte_memcpy()optimization is for the pile/mempool optimizations I'm working on, so there is a specific use case motivating the added code.
I understand that you probably have some specific use-case in mind. BTW for this optimization you mentioned above: what is the gain with these changes?
Quoted 64 lines
From: Konstantin Ananyev [mailto:[email protected]]
Sent: Wednesday, 5 August 2026 19.16Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 1 line
Quoted 1 line
Review
Quoted 1 line
(quoted diff) +1
-0+ /* Common way for small copy size of 64-byte blocks.Unlikely, so
Quoted 7 lines
Quoted 7 lines
constant size only */
Review
Quoted 1 line
(quoted diff) +1
-0+ if (__rte_constant(n) && (n & 63) == 0 && n <=
RTE_MEMCPY_BLOCK_64_MAX) {Review
Quoted 2 lines
(quoted diff) +2
-0+ void *ret = dst; +Maybe just let compiler decide, it will generate vector
instructions in
Quoted 2 lines
Quoted 2 lines
most cases.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
if (__rte_constant(n)) return mempcpy(dst, src, n);Maybe in most, but not in all:
https://godbolt.org/z/KvdKqT5rYWith '-mavx' or '-mavx512f' it looks like it does for your
sample
Quoted 6 lines
Quoted 6 lines
code.
Quoted 5 lines
It also does with -msse4.2 when SZ is reduced to 256 bytes. Clang switches to inline when SZ is reduced to 128 bytes.
It seems the compiler has a threshold for when to inline and when
to
Quoted 6 lines
Quoted 6 lines
call the C
Quoted 3 lines
library's memcpy subroutine.
The threshold depends on both copy size and vector register size. And it is compiler dependent.I think there are compiler options to specify desired threshold
values.
Quoted 7 lines
Quoted 5 lines
Let say for gcc there is ' -mmemcpy-strategy=strategy'. For that example in that particular case -mmemcpy-strategy=vector_loop:512:align,loop:-1:align generates sse loads/stores.
Might be we can exploit it somehow?That could give us higher granularity/control over memcpy for
individual
Quoted 1 line
memcpy instances; might be useful for hot code paths where we have
more
Quoted 2 lines
knowledge about the copy operation than the compiler can infer. However, pragmas are discouraged in DPDK, and this looks like a very
similar
Quoted 1 line
path.
Well, right now
rte_memcpy.his 700+ lines and keeps growing. Considering that probably pragmas are not that bad.
Of course, pragmas have their own issues and it is hard to ensure that they will produce same code between different compilers/versions, etc.Quoted 3 lines
Quoted 3 lines
I am not really happy that our home-brewed memcpy code-block keeps growing,
while we keep talking that it would be good to eliminate itcompletely.
Quoted 3 lines
I agree in principle.
However, thisrte_memcpy()optimization is for the pile/mempool
Quoted 7 lines
optimizations
Quoted 1 line
I'm working on, so there is a specific use case motivating the added
code.
I understand that you probably have some specific use-case in mind. BTW for this optimization you mentioned above: what is the gain with these changes?
IMO, the primary benefit is the much simpler (and smaller) assembly output due to avoiding the address alignment check (and the resulting duplicated code).
I haven't measured the performance gain.
Based on the perf gain in a previous mempool optimization patch [1], it seems avoiding the address alignment check shaves ~2 cycles off the copy operation (for cache-to-cache copy). I expect that the same gain (from avoiding the address alignment check) applies here.
[1]: https://patchwork.dpdk.org/project/dpdk/patch/[email protected]/
Quoted 65 lines
Quoted 65 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 3 lines
Quoted 3 lines
Review
Quoted 3 lines
(quoted diff) +1
-0+ /* Common way for small copy size of 64-byte blocks.Unlikely, so
Quoted 7 lines
Quoted 7 lines
constant size only */
Review
Quoted 1 line
(quoted diff) +1
-0+ if (__rte_constant(n) && (n & 63) == 0 && n <=
RTE_MEMCPY_BLOCK_64_MAX) {Review
Quoted 2 lines
(quoted diff) +2
-0+ void *ret = dst; +Maybe just let compiler decide, it will generate vector
instructions in
Quoted 2 lines
Quoted 2 lines
most cases.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
if (__rte_constant(n)) return mempcpy(dst, src, n);Maybe in most, but not in all:
https://godbolt.org/z/KvdKqT5rYWith '-mavx' or '-mavx512f' it looks like it does for your
sample
Quoted 6 lines
Quoted 6 lines
code.
Quoted 5 lines
It also does with -msse4.2 when SZ is reduced to 256 bytes. Clang switches to inline when SZ is reduced to 128 bytes.
It seems the compiler has a threshold for when to inline and when
to
Quoted 6 lines
Quoted 6 lines
call the C
Quoted 3 lines
library's memcpy subroutine.
The threshold depends on both copy size and vector register size. And it is compiler dependent.I think there are compiler options to specify desired threshold
values.
Quoted 7 lines
Quoted 5 lines
Let say for gcc there is ' -mmemcpy-strategy=strategy'. For that example in that particular case -mmemcpy-strategy=vector_loop:512:align,loop:-1:align generates sse loads/stores.
Might be we can exploit it somehow?That could give us higher granularity/control over memcpy for
individual
Quoted 1 line
memcpy instances; might be useful for hot code paths where we have
more
Quoted 2 lines
knowledge about the copy operation than the compiler can infer. However, pragmas are discouraged in DPDK, and this looks like a very
similar
Quoted 1 line
path.
Well, right now
rte_memcpy.his 700+ lines and keeps growing. Considering that probably pragmas are not that bad.
Of course, pragmas have their own issues and it is hard to ensure that they will produce same code between different compilers/versions, etc.Quoted 3 lines
Quoted 3 lines
I am not really happy that our home-brewed memcpy code-block keeps growing,
while we keep talking that it would be good to eliminate itcompletely.
Quoted 3 lines
I agree in principle.
However, thisrte_memcpy()optimization is for the pile/mempooloptimizations
Quoted 1 line
I'm working on, so there is a specific use case motivating the added
Quoted 8 lines
Quoted 5 lines
code.
I understand that you probably have some specific use-case in mind. BTW for this optimization you mentioned above: what is the gain with these changes?
IMO, the primary benefit is the much simpler (and smaller) assembly output due to avoiding the address alignment check (and the resulting duplicated code).
I think that should be measurable too: whole binary and/or hot path function size reduction, etc.
Quoted 6 lines
I haven't measured the performance gain.
Based on the perf gain in a previous mempool optimization patch [1], it seems avoiding the address alignment check shaves ~2 cycles off the copy operation (for cache-to-cache copy).
I expect that the same gain (from avoiding the address alignment check) applies here.
Ok, then I suggest we do some measurements first, before going forward with it.
Quoted 82 lines
From: Konstantin Ananyev [mailto:[email protected]]
Sent: Thursday, 6 August 2026 09.58Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Review
Quoted 1 line
(quoted diff) +1
-0+ /* Common way for small copy size of 64-byteblocks.
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Unlikely, so
Quoted 7 lines
Quoted 7 lines
constant size only */
Review
Quoted 1 line
(quoted diff) +1
-0+ if (__rte_constant(n) && (n & 63) == 0 && n <=
RTE_MEMCPY_BLOCK_64_MAX) {Review
Quoted 2 lines
(quoted diff) +2
-0+ void *ret = dst; +Maybe just let compiler decide, it will generate vector
instructions in
Quoted 7 lines
Quoted 4 lines
most cases.
if (__rte_constant(n)) return mempcpy(dst, src, n);Maybe in most, but not in all:
https://godbolt.org/z/KvdKqT5rYQuoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
With '-mavx' or '-mavx512f' it looks like it does for your
sample
Quoted 6 lines
Quoted 6 lines
code.
Quoted 5 lines
It also does with -msse4.2 when SZ is reduced to 256 bytes. Clang switches to inline when SZ is reduced to 128 bytes.
It seems the compiler has a threshold for when to inline and
when
Quoted 4 lines
Quoted 4 lines
to
Quoted 3 lines
Quoted 3 lines
call the C
Quoted 2 lines
library's memcpy subroutine.
The threshold depends on both copy size and vector registersize.
Quoted 10 lines
Quoted 10 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
And it is compiler dependent.
I think there are compiler options to specify desired threshold
values.
Quoted 6 lines
Quoted 5 lines
Let say for gcc there is ' -mmemcpy-strategy=strategy'. For that example in that particular case -mmemcpy-strategy=vector_loop:512:align,loop:-1:align generates sse loads/stores.
Might be we can exploit it somehow?Quoted 3 lines
Quoted 3 lines
Quoted 1 line
That could give us higher granularity/control over memcpy for
individual
Quoted 1 line
memcpy instances; might be useful for hot code paths where we
have
Quoted 3 lines
Quoted 3 lines
more
Quoted 2 lines
knowledge about the copy operation than the compiler can infer. However, pragmas are discouraged in DPDK, and this looks like a
very
Quoted 6 lines
Quoted 6 lines
similar
Quoted 1 line
path.
Well, right now
rte_memcpy.his 700+ lines and keeps growing. Considering that probably pragmas are not that bad.
Of course, pragmas have their own issues and it is hard to ensurethat
Quoted 1 line
Quoted 1 line
they will produce same code between different compilers/versions,
etc.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
I am not really happy that our home-brewed memcpy code-block
keeps
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
growing,
while we keep talking that it would be good to eliminate itcompletely.
Quoted 3 lines
I agree in principle.
However, thisrte_memcpy()optimization is for the pile/mempooloptimizations
Quoted 1 line
I'm working on, so there is a specific use case motivating the
added
Quoted 4 lines
Quoted 4 lines
code.
I understand that you probably have some specific use-case in mind. BTW for this optimization you mentioned above: what is the gain
with
Quoted 2 lines
Quoted 1 line
these changes?
Quoted 7 lines
Quoted 1 line
IMO, the primary benefit is the much simpler (and smaller) assembly
output due
Quoted 1 line
to avoiding the address alignment check (and the resulting duplicated
code).
I think that should be measurable too: whole binary and/or hot path function size reduction, etc.
The size of the generated code for the copy operation is reduced to slightly less than half (only one instance of the copy operation instead of two, and the address alignment comparison is omitted).
Quoted 5 lines
Quoted 3 lines
I haven't measured the performance gain.
Based on the perf gain in a previous mempool optimization patch [1],it seems
Quoted 1 line
avoiding the address alignment check shaves ~2 cycles off the copy
Quoted 8 lines
operation (for
Quoted 2 lines
cache-to-cache copy).
I expect that the same gain (from avoiding the address alignmentcheck) applies
Quoted 1 line
here.
Ok, then I suggest we do some measurements first, before going forward with it.
I tried memcpy_perf_autotest, but the branch predictor kicks in and eliminates the cost of the address alignment comparison. So the results are very similar.
BTW, that's a general issue with our perf tests: Repeated testing doesn't show the cost of branches, because they are always eliminated by the branch predictor.
======= ================= ================= ================= =================
Size Cache to cache Cache to mem Mem to cache Mem to mem
(bytes) (ticks) (ticks) (ticks) (ticks)
------- ----------------- ----------------- ----------------- ----------------- ================================= 32B aligned ================================= Before
C 64 2 - 2( 9.60%) 22 - 21( 4.48%) 33 - 31( 5.15%) 57 - 56( 0.28%) C 128 4 - 4( 5.56%) 41 - 40( 3.59%) 53 - 52( 1.49%) 101 -100( 0.71%) C 192 6 - 6( 4.06%) 64 - 60( 5.61%) 68 - 69( -1.68%) 136 -138( -1.49%) C 256 10 - 9( 5.21%) 82 - 81( 1.20%) 93 - 87( 7.47%) 172 -175( -1.46%) After C 64 2 - 2( -0.71%) 22 - 21( 7.62%) 31 - 30( 4.32%) 57 - 59( -3.03%) C 128 4 - 4( -0.34%) 40 - 40( 0.60%) 50 - 50( 0.41%) 97 - 99( -1.96%) C 192 6 - 6( 5.27%) 59 - 59( -0.27%) 69 - 72( -4.42%) 139 -138( 0.90%) C 256 9 - 9( 9.14%) 77 - 77( 0.25%) 89 - 90( -0.88%) 180 -177( 1.57%) ================================== Unaligned ================================== Before C 64 5 - 5( 0.98%) 32 - 32( 0.72%) 42 - 42( 0.44%) 82 - 82( 0.51%) C 128 8 - 9(-11.26%) 51 - 50( 0.53%) 60 - 59( 0.89%) 117 -115( 1.37%) C 192 13 - 12( 1.62%) 66 - 67( -1.12%) 83 - 80( 3.26%) 157 -165( -5.25%) C 256 21 - 22( -5.78%) 94 - 93( 1.65%) 100 - 99( 1.52%) 202 -204( -1.34%) After C 64 5 - 5( 0.05%) 31 - 31( 0.16%) 40 - 39( 1.37%) 77 - 77( -0.93%) C 128 9 - 9( -0.69%) 50 - 50( -0.02%) 61 - 60( 2.71%) 118 -122( -3.15%) C 192 12 - 11( 7.68%) 68 - 66( 3.64%) 79 - 81( -2.85%) 164 -164( -0.12%) C 256 21 - 20( 1.80%) 90 - 87( 2.70%) 96 - 97( -0.99%) 202 -201( 0.09%)
Quoted 4 lines
Quoted 2 lines
[1]:
https://patchwork.dpdk.org/project/dpdk/patch/20260521185631.116046-1-
Quoted 1 line
Quoted 100 lines
Quoted 80 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +1
-0+ /* Common way for small copy size of 64-byteblocks.
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Unlikely, so
Quoted 7 lines
Quoted 7 lines
constant size only */
Review
Quoted 1 line
(quoted diff) +1
-0+ if (__rte_constant(n) && (n & 63) == 0 && n <=
RTE_MEMCPY_BLOCK_64_MAX) {Review
Quoted 2 lines
(quoted diff) +2
-0+ void *ret = dst; +Maybe just let compiler decide, it will generate vector
instructions in
Quoted 7 lines
Quoted 4 lines
most cases.
if (__rte_constant(n)) return mempcpy(dst, src, n);Maybe in most, but not in all:
https://godbolt.org/z/KvdKqT5rYQuoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
With '-mavx' or '-mavx512f' it looks like it does for your
sample
Quoted 6 lines
Quoted 6 lines
code.
Quoted 5 lines
It also does with -msse4.2 when SZ is reduced to 256 bytes. Clang switches to inline when SZ is reduced to 128 bytes.
It seems the compiler has a threshold for when to inline and
when
Quoted 4 lines
Quoted 4 lines
to
Quoted 3 lines
Quoted 3 lines
call the C
Quoted 2 lines
library's memcpy subroutine.
The threshold depends on both copy size and vector registersize.
Quoted 10 lines
Quoted 10 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
And it is compiler dependent.
I think there are compiler options to specify desired threshold
values.
Quoted 6 lines
Quoted 5 lines
Let say for gcc there is ' -mmemcpy-strategy=strategy'. For that example in that particular case -mmemcpy-strategy=vector_loop:512:align,loop:-1:align generates sse loads/stores.
Might be we can exploit it somehow?Quoted 3 lines
Quoted 3 lines
Quoted 1 line
That could give us higher granularity/control over memcpy for
individual
Quoted 1 line
memcpy instances; might be useful for hot code paths where we
have
Quoted 3 lines
Quoted 3 lines
more
Quoted 2 lines
knowledge about the copy operation than the compiler can infer. However, pragmas are discouraged in DPDK, and this looks like a
very
Quoted 6 lines
Quoted 6 lines
similar
Quoted 1 line
path.
Well, right now
rte_memcpy.his 700+ lines and keeps growing. Considering that probably pragmas are not that bad.
Of course, pragmas have their own issues and it is hard to ensurethat
Quoted 1 line
Quoted 1 line
they will produce same code between different compilers/versions,
etc.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
I am not really happy that our home-brewed memcpy code-block
keeps
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
growing,
while we keep talking that it would be good to eliminate itcompletely.
Quoted 3 lines
I agree in principle.
However, thisrte_memcpy()optimization is for the pile/mempooloptimizations
Quoted 1 line
I'm working on, so there is a specific use case motivating the
added
Quoted 4 lines
Quoted 4 lines
code.
I understand that you probably have some specific use-case in mind. BTW for this optimization you mentioned above: what is the gain
with
Quoted 2 lines
Quoted 1 line
these changes?
Quoted 7 lines
Quoted 1 line
IMO, the primary benefit is the much simpler (and smaller) assembly
output due
Quoted 1 line
to avoiding the address alignment check (and the resulting duplicated
code).
I think that should be measurable too: whole binary and/or hot path function size reduction, etc.
The size of the generated code for the copy operation is reduced to slightly less than half (only one instance of the copy operation instead of two, and the address alignment comparison is omitted).
Quoted 8 lines
Quoted 3 lines
I haven't measured the performance gain.
Based on the perf gain in a previous mempool optimization patch [1],it seems
Quoted 1 line
avoiding the address alignment check shaves ~2 cycles off the copy
operation (for
Quoted 2 lines
cache-to-cache copy).
I expect that the same gain (from avoiding the address alignment
Quoted 8 lines
Quoted 5 lines
check) applies
Quoted 1 line
here.
Ok, then I suggest we do some measurements first, before going forward with it.
I tried
memcpy_perf_autotest, but the branch predictor kicks in and eliminates the cost of the address alignment comparison. So the results are very similar.
Indeed, they are the same.
Quoted 3 lines
BTW, that's a general issue with our perf tests: Repeated testing doesn't show the cost of branches, because they are always eliminated by the branch predictor.
Might be...
But we do need some measurable evidence that such change improve things, otherwise - why to bother?
If that perf test is not goof enough - let's try to extend it or use different one. BTW, in your mempool pile RFC, I see you also use rte_memcpy over fixed sized buffers. Do you see any improvement there (wit/without rte_memcpy optimixation)?
Quoted 34 lines
======= ================= ================= =================
=================
Size Cache to cache Cache to mem Mem to cache Mem to mem
(bytes) (ticks) (ticks) (ticks) (ticks)
------- ----------------- ----------------- ----------------- ----------------- ================================= 32B aligned
=================================
BeforeC 64 2 - 2( 9.60%) 22 - 21( 4.48%) 33 - 31( 5.15%) 57 - 56( 0.28%) C 128 4 - 4( 5.56%) 41 - 40( 3.59%) 53 - 52( 1.49%) 101 -100( 0.71%) C 192 6 - 6( 4.06%) 64 - 60( 5.61%) 68 - 69( -1.68%) 136 -138( -1.49%) C 256 10 - 9( 5.21%) 82 - 81( 1.20%) 93 - 87( 7.47%) 172 -175( -1.46%) After C 64 2 - 2( -0.71%) 22 - 21( 7.62%) 31 - 30( 4.32%) 57 - 59( -3.03%) C 128 4 - 4( -0.34%) 40 - 40( 0.60%) 50 - 50( 0.41%) 97 - 99( -1.96%) C 192 6 - 6( 5.27%) 59 - 59( -0.27%) 69 - 72( -4.42%) 139 -138( 0.90%) C 256 9 - 9( 9.14%) 77 - 77( 0.25%) 89 - 90( -0.88%) 180 -177( 1.57%) ================================== Unaligned ================================== Before C 64 5 - 5( 0.98%) 32 - 32( 0.72%) 42 - 42( 0.44%) 82 - 82( 0.51%) C 128 8 - 9(-11.26%) 51 - 50( 0.53%) 60 - 59( 0.89%) 117 -115( 1.37%) C 192 13 - 12( 1.62%) 66 - 67( -1.12%) 83 - 80( 3.26%) 157 -165( -5.25%) C 256 21 - 22( -5.78%) 94 - 93( 1.65%) 100 - 99( 1.52%) 202 -204( -1.34%) After C 64 5 - 5( 0.05%) 31 - 31( 0.16%) 40 - 39( 1.37%) 77 - 77( -0.93%) C 128 9 - 9( -0.69%) 50 - 50( -0.02%) 61 - 60( 2.71%) 118 -122( -3.15%) C 192 12 - 11( 7.68%) 68 - 66( 3.64%) 79 - 81( -2.85%) 164 -164( -0.12%) C 256 21 - 20( 1.80%) 90 - 87( 2.70%) 96 - 97( -0.99%) 202 -201( 0.09%)Quoted 4 lines
Quoted 2 lines
[1]:
https://patchwork.dpdk.org/project/dpdk/patch/20260521185631.116046-1-
Quoted 1 line
Quoted 144 lines
From: Konstantin Ananyev [mailto:[email protected]]
Sent: Tuesday, 11 August 2026 09.06Quoted 10 lines
Quoted 10 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Review
Quoted 1 line
(quoted diff) +1
-0+ /* Common way for small copy size of 64-byteblocks.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Unlikely, so
Quoted 7 lines
Quoted 7 lines
constant size only */
Review
Quoted 1 line
(quoted diff) +1
-0+ if (__rte_constant(n) && (n & 63) == 0 && n <=
RTE_MEMCPY_BLOCK_64_MAX) {Review
Quoted 2 lines
(quoted diff) +2
-0+ void *ret = dst; +Maybe just let compiler decide, it will generate
vector
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
instructions in
Quoted 7 lines
Quoted 4 lines
most cases.
if (__rte_constant(n)) return mempcpy(dst, src, n);Maybe in most, but not in all:
https://godbolt.org/z/KvdKqT5rYWith '-mavx' or '-mavx512f' it looks like it does for
your
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
sample
Quoted 3 lines
Quoted 3 lines
code.
Quoted 2 lines
It also does with -msse4.2 when SZ is reduced to 256
bytes.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Clang switches to inline when SZ is reduced to 128 bytes.
It seems the compiler has a threshold for when to inline
and
Quoted 5 lines
Quoted 5 lines
when
Quoted 4 lines
Quoted 4 lines
to
Quoted 3 lines
Quoted 3 lines
call the C
Quoted 2 lines
library's memcpy subroutine.
The threshold depends on both copy size and vectorregister
Quoted 4 lines
Quoted 4 lines
size.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
And it is compiler dependent.
I think there are compiler options to specify desired
threshold
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
values.
Quoted 6 lines
Quoted 5 lines
Let say for gcc there is ' -mmemcpy-strategy=strategy'. For that example in that particular case -mmemcpy-strategy=vector_loop:512:align,loop:-1:align generates sse loads/stores.
Might be we can exploit it somehow?Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
That could give us higher granularity/control over memcpy for
individual
Quoted 1 line
memcpy instances; might be useful for hot code paths where we
have
Quoted 2 lines
Quoted 2 lines
more
Quoted 1 line
knowledge about the copy operation than the compiler can
infer.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
However, pragmas are discouraged in DPDK, and this looks like
a
Quoted 7 lines
Quoted 7 lines
very
Quoted 6 lines
Quoted 6 lines
similar
Quoted 1 line
path.
Well, right now
rte_memcpy.his 700+ lines and keeps growing. Considering that probably pragmas are not that bad. Of course, pragmas have their own issues and it is hard toensure
Quoted 2 lines
Quoted 2 lines
that
Quoted 1 line
Quoted 1 line
they will produce same code between different
compilers/versions,
Quoted 3 lines
Quoted 3 lines
etc.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
I am not really happy that our home-brewed memcpy code-
block
Quoted 7 lines
Quoted 7 lines
keeps
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
growing,
while we keep talking that it would be good to eliminate itcompletely.
Quoted 3 lines
I agree in principle.
However, thisrte_memcpy()optimization is for thepile/mempool
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
optimizations
Quoted 1 line
I'm working on, so there is a specific use case motivating
the
Quoted 4 lines
Quoted 4 lines
added
Quoted 3 lines
Quoted 3 lines
code.
I understand that you probably have some specific use-case in
mind.
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
BTW for this optimization you mentioned above: what is the gain
with
Quoted 3 lines
Quoted 1 line
these changes?
IMO, the primary benefit is the much simpler (and smaller)
assembly
Quoted 2 lines
Quoted 2 lines
output due
Quoted 1 line
to avoiding the address alignment check (and the resulting
duplicated
Quoted 3 lines
Quoted 3 lines
code).
I think that should be measurable too: whole binary and/or hot
path
Quoted 3 lines
Quoted 1 line
function size reduction, etc.
The size of the generated code for the copy operation is reduced to
slightly less
Quoted 1 line
than half (only one instance of the copy operation instead of two,
and the
Quoted 5 lines
address alignment comparison is omitted).
Quoted 3 lines
Quoted 3 lines
I haven't measured the performance gain.
Based on the perf gain in a previous mempool optimization patch[1],
Quoted 2 lines
Quoted 2 lines
it seems
Quoted 1 line
avoiding the address alignment check shaves ~2 cycles off the
copy
Quoted 7 lines
Quoted 7 lines
operation (for
Quoted 2 lines
cache-to-cache copy).
I expect that the same gain (from avoiding the address alignmentcheck) applies
Quoted 1 line
here.
Ok, then I suggest we do some measurements first, before going
forward
Quoted 3 lines
Quoted 1 line
with it.
I tried
memcpy_perf_autotest, but the branch predictor kicks in andeliminates
Quoted 1 line
the cost of the address alignment comparison. So the results are very
similar.
Indeed, they are the same.
Quoted 1 line
BTW, that's a general issue with our perf tests: Repeated testing
doesn't show
Quoted 1 line
the cost of branches, because they are always eliminated by the
branch
Quoted 1 line
predictor.
Quoted 9 lines
Might be...
But we do need some measurable evidence that such change improve things,
otherwise - why to bother?
If that perf test is not goof enough - let's try to extend it or use different one.
BTW, in your mempool pile RFC, I see you also userte_memcpyover fixed sized buffers.
Do you see any improvement there (wit/withoutrte_memcpyoptimixation)?
Looking at the generated assembly (objdump -S build/drivers/librte_mempool_stack.so)...
This is the optimized copy loop in pile_dequeue:
1650: 89 ca mov %ecx,%edx
1652: c5 fe 6f 40 40 vmovdqu 0x40(%rax),%ymm0
1657: ff c1 inc %ecx
1659: c1 e2 05 shl $0x5,%edx
165c: 49 8d 14 d4 lea (%r12,%rdx,8),%rdx
1660: c5 fe 7f 02 vmovdqu %ymm0,(%rdx)
1664: c5 fe 6f 48 60 vmovdqu 0x60(%rax),%ymm1
1669: c5 fe 7f 4a 20 vmovdqu %ymm1,0x20(%rdx)
166e: c5 fe 6f 90 80 00 00 vmovdqu 0x80(%rax),%ymm2
1675: 00
1676: c5 fe 7f 52 40 vmovdqu %ymm2,0x40(%rdx)
167b: c5 fe 6f 98 a0 00 00 vmovdqu 0xa0(%rax),%ymm3
1682: 00
1683: c5 fe 7f 5a 60 vmovdqu %ymm3,0x60(%rdx)
1688: c5 fe 6f a0 c0 00 00 vmovdqu 0xc0(%rax),%ymm4
168f: 00
1690: c5 fe 7f a2 80 00 00 vmovdqu %ymm4,0x80(%rdx)
1697: 00
1698: c5 fe 6f a8 e0 00 00 vmovdqu 0xe0(%rax),%ymm5
169f: 00
16a0: c5 fe 7f aa a0 00 00 vmovdqu %ymm5,0xa0(%rdx)
16a7: 00
16a8: c5 fe 6f b0 00 01 00 vmovdqu 0x100(%rax),%ymm6
16af: 00
16b0: c5 fe 7f b2 c0 00 00 vmovdqu %ymm6,0xc0(%rdx)
16b7: 00
16b8: c5 fe 6f b8 20 01 00 vmovdqu 0x120(%rax),%ymm7
16bf: 00
16c0: c5 fe 7f ba e0 00 00 vmovdqu %ymm7,0xe0(%rdx)
16c7: 00
16c8: 48 8b 40 08 mov 0x8(%rax),%rax
16cc: 39 f1 cmp %esi,%ecx
16ce: 75 80 jne 1650 <pile_dequeue+0xe0>
16d0:This is without the rte_memcpy optimization:
1650: 89 ca mov %ecx,%edx
1652: c5 fe 6f 40 40 vmovdqu 0x40(%rax),%ymm0
1657: 49 89 c1 mov %rax,%r9
165a: ff c1 inc %ecx
165c: c1 e2 05 shl $0x5,%edx
165f: 49 8d 14 d4 lea (%r12,%rdx,8),%rdx
1663: c5 fe 7f 02 vmovdqu %ymm0,(%rdx)
1667: c5 fe 6f 48 60 vmovdqu 0x60(%rax),%ymm1
166c: 49 09 d1 or %rdx,%r9
166f: 41 83 e1 1f and $0x1f,%r9d
1673: c5 fe 7f 4a 20 vmovdqu %ymm1,0x20(%rdx)
1678: c5 fe 6f 90 80 00 00 vmovdqu 0x80(%rax),%ymm2
167f: 00
1680: c5 fe 7f 52 40 vmovdqu %ymm2,0x40(%rdx)
1685: c5 fe 6f 98 a0 00 00 vmovdqu 0xa0(%rax),%ymm3
168c: 00
168d: c5 fe 7f 5a 60 vmovdqu %ymm3,0x60(%rdx)
1692: c5 fe 6f a0 c0 00 00 vmovdqu 0xc0(%rax),%ymm4
1699: 00
169a: c5 fe 7f a2 80 00 00 vmovdqu %ymm4,0x80(%rdx)
16a1: 00
16a2: c5 fe 6f a8 e0 00 00 vmovdqu 0xe0(%rax),%ymm5
16a9: 00
16aa: c5 fe 7f aa a0 00 00 vmovdqu %ymm5,0xa0(%rdx)
16b1: 00
16b2: c5 fe 6f b0 00 01 00 vmovdqu 0x100(%rax),%ymm6
16b9: 00
16ba: c5 fe 7f b2 c0 00 00 vmovdqu %ymm6,0xc0(%rdx)
16c1: 00
16c2: c5 fe 6f b8 20 01 00 vmovdqu 0x120(%rax),%ymm7
16c9: 00
16ca: c5 fe 7f ba e0 00 00 vmovdqu %ymm7,0xe0(%rdx)
16d1: 00
16d2: 48 8b 40 08 mov 0x8(%rax),%rax
16d6: 0f 85 c4 00 00 00 jne 17a0 <pile_dequeue+0x230>
16dc: 39 ce cmp %ecx,%esi
16de: 0f 85 6c ff ff ff jne 1650 <pile_dequeue+0xe0>
16e4:
[...]
17a0: 39 f1 cmp %esi,%ecx
17a2: 0f 85 a8 fe ff ff jne 1650 <pile_dequeue+0xe0>
17a8: e9 37 ff ff ff jmp 16e4 <pile_dequeue+0x174>Here, the alignment comparison I have optimized away is performed using register %r9.
With the optimization, the generated assembly is less cluttered, and thus easier to review.
(It seems the compiler is clever enough to not duplicate the two instances of the code, but reuse the aligned instance for the unaligned case too. So the reduction in code size is not as great as I previously claimed.)
I agree the performance benefit in CPU cycles is probably insignificant.
But the generated assembly is cleaner.
And if pressured for CPU registers, the optimization also frees up one CPU register for other purposes.
Code size reduction:
The optimized loop is 0x80 bytes of instructions.
The non-optimized is 0x8e bytes, 14 bytes more, in the loop, plus 13 bytes outside the loop.
Quoted 55 lines
Quoted 4 lines
======= ================= ================= =================
=================
Size Cache to cache Cache to mem Mem to cacheMem to mem
Quoted 1 line
(bytes) (ticks) (ticks) (ticks)
(ticks)
Quoted 1 line
------- ----------------- ----------------- ----------------- -------
----------
Quoted 4 lines
================================= 32B aligned
=================================
Before
C 64 2 - 2( 9.60%) 22 - 21( 4.48%) 33 - 31( 5.15%) 57 -56( 0.28%)
Quoted 1 line
C 128 4 - 4( 5.56%) 41 - 40( 3.59%) 53 - 52( 1.49%) 101 -
100( 0.71%)
Quoted 1 line
C 192 6 - 6( 4.06%) 64 - 60( 5.61%) 68 - 69( -1.68%) 136 -
138( -1.49%)
Quoted 1 line
C 256 10 - 9( 5.21%) 82 - 81( 1.20%) 93 - 87( 7.47%) 172 -
175( -1.46%)
Quoted 2 lines
After
C 64 2 - 2( -0.71%) 22 - 21( 7.62%) 31 - 30( 4.32%) 57 -59( -3.03%)
Quoted 1 line
C 128 4 - 4( -0.34%) 40 - 40( 0.60%) 50 - 50( 0.41%) 97 -
99( -1.96%)
Quoted 1 line
C 192 6 - 6( 5.27%) 59 - 59( -0.27%) 69 - 72( -4.42%) 139 -
138( 0.90%) > C 256 9 - 9( 9.14%) 77 - 77( 0.25%) 89 - 90( -0.88%) 180 - 177( 1.57%)Quoted 4 lines
================================== Unaligned
==================================
Before
C 64 5 - 5( 0.98%) 32 - 32( 0.72%) 42 - 42( 0.44%) 82 -82( 0.51%)
Quoted 1 line
C 128 8 - 9(-11.26%) 51 - 50( 0.53%) 60 - 59( 0.89%) 117 -
115( 1.37%)
Quoted 1 line
C 192 13 - 12( 1.62%) 66 - 67( -1.12%) 83 - 80( 3.26%) 157 -
165( -5.25%)
Quoted 1 line
C 256 21 - 22( -5.78%) 94 - 93( 1.65%) 100 - 99( 1.52%) 202 -
204( -1.34%)
Quoted 2 lines
After
C 64 5 - 5( 0.05%) 31 - 31( 0.16%) 40 - 39( 1.37%) 77 -77( -0.93%)
Quoted 1 line
C 128 9 - 9( -0.69%) 50 - 50( -0.02%) 61 - 60( 2.71%) 118 -
122( -3.15%)
Quoted 1 line
C 192 12 - 11( 7.68%) 68 - 66( 3.64%) 79 - 81( -2.85%) 164 -
164( -0.12%)
Quoted 1 line
C 256 21 - 20( 1.80%) 90 - 87( 2.70%) 96 - 97( -0.99%) 202 -
201( 0.09%)
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
[1]:
https://patchwork.dpdk.org/project/dpdk/patch/20260521185631.116046-1-
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 251 lines
Quoted 142 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
+ /* Common way for small copy size of 64-byte
blocks.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Unlikely, so
Quoted 7 lines
Quoted 7 lines
constant size only */
Quoted 1 line
+ if (__rte_constant(n) && (n & 63) == 0 && n <=
RTE_MEMCPY_BLOCK_64_MAX) {Quoted 2 lines
+ void *ret = dst;
+Maybe just let compiler decide, it will generate
vector
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
instructions in
Quoted 7 lines
Quoted 4 lines
most cases.
if (__rte_constant(n)) return mempcpy(dst, src, n);Maybe in most, but not in all:
https://godbolt.org/z/KvdKqT5rYWith '-mavx' or '-mavx512f' it looks like it does for
your
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
sample
Quoted 3 lines
Quoted 3 lines
code.
Quoted 2 lines
It also does with -msse4.2 when SZ is reduced to 256
bytes.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Clang switches to inline when SZ is reduced to 128 bytes.
It seems the compiler has a threshold for when to inline
and
Quoted 5 lines
Quoted 5 lines
when
Quoted 4 lines
Quoted 4 lines
to
Quoted 3 lines
Quoted 3 lines
call the C
Quoted 2 lines
library's memcpy subroutine.
The threshold depends on both copy size and vectorregister
Quoted 4 lines
Quoted 4 lines
size.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
And it is compiler dependent.
I think there are compiler options to specify desired
threshold
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
values.
Quoted 6 lines
Quoted 5 lines
Let say for gcc there is ' -mmemcpy-strategy=strategy'. For that example in that particular case -mmemcpy-strategy=vector_loop:512:align,loop:-1:align generates sse loads/stores.
Might be we can exploit it somehow?Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
That could give us higher granularity/control over memcpy for
individual
Quoted 1 line
memcpy instances; might be useful for hot code paths where we
have
Quoted 2 lines
Quoted 2 lines
more
Quoted 1 line
knowledge about the copy operation than the compiler can
infer.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
However, pragmas are discouraged in DPDK, and this looks like
a
Quoted 7 lines
Quoted 7 lines
very
Quoted 6 lines
Quoted 6 lines
similar
Quoted 1 line
path.
Well, right now
rte_memcpy.his 700+ lines and keeps growing. Considering that probably pragmas are not that bad. Of course, pragmas have their own issues and it is hard toensure
Quoted 2 lines
Quoted 2 lines
that
Quoted 1 line
Quoted 1 line
they will produce same code between different
compilers/versions,
Quoted 3 lines
Quoted 3 lines
etc.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
I am not really happy that our home-brewed memcpy code-
block
Quoted 7 lines
Quoted 7 lines
keeps
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
growing,
while we keep talking that it would be good to eliminate itcompletely.
Quoted 3 lines
I agree in principle.
However, thisrte_memcpy()optimization is for thepile/mempool
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
optimizations
Quoted 1 line
I'm working on, so there is a specific use case motivating
the
Quoted 4 lines
Quoted 4 lines
added
Quoted 3 lines
Quoted 3 lines
code.
I understand that you probably have some specific use-case in
mind.
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
BTW for this optimization you mentioned above: what is the gain
with
Quoted 3 lines
Quoted 1 line
these changes?
IMO, the primary benefit is the much simpler (and smaller)
assembly
Quoted 2 lines
Quoted 2 lines
output due
Quoted 1 line
to avoiding the address alignment check (and the resulting
duplicated
Quoted 3 lines
Quoted 3 lines
code).
I think that should be measurable too: whole binary and/or hot
path
Quoted 3 lines
Quoted 1 line
function size reduction, etc.
The size of the generated code for the copy operation is reduced to
slightly less
Quoted 1 line
than half (only one instance of the copy operation instead of two,
and the
Quoted 5 lines
address alignment comparison is omitted).
Quoted 3 lines
Quoted 3 lines
I haven't measured the performance gain.
Based on the perf gain in a previous mempool optimization patch[1],
Quoted 2 lines
Quoted 2 lines
it seems
Quoted 1 line
avoiding the address alignment check shaves ~2 cycles off the
copy
Quoted 7 lines
Quoted 7 lines
operation (for
Quoted 2 lines
cache-to-cache copy).
I expect that the same gain (from avoiding the address alignmentcheck) applies
Quoted 1 line
here.
Ok, then I suggest we do some measurements first, before going
forward
Quoted 3 lines
Quoted 1 line
with it.
I tried
memcpy_perf_autotest, but the branch predictor kicks in andeliminates
Quoted 1 line
the cost of the address alignment comparison. So the results are very
similar.
Indeed, they are the same.
Quoted 1 line
BTW, that's a general issue with our perf tests: Repeated testing
doesn't show
Quoted 1 line
the cost of branches, because they are always eliminated by the
branch
Quoted 1 line
predictor.
Quoted 9 lines
Might be...
But we do need some measurable evidence that such change improve things,
otherwise - why to bother?
If that perf test is not goof enough - let's try to extend it or use different one.
BTW, in your mempool pile RFC, I see you also userte_memcpyover fixed sized buffers.
Do you see any improvement there (wit/withoutrte_memcpyoptimixation)?Looking at the generated assembly (objdump -S
build/drivers/librte_mempool_stack.so)...This is the optimized copy loop in
pile_dequeue:1650: 89 ca mov %ecx,%edx 1652: c5 fe 6f 40 40 vmovdqu 0x40(%rax),%ymm0 1657: ff c1 inc %ecx 1659: c1 e2 05 shl $0x5,%edx 165c: 49 8d 14 d4 lea (%r12,%rdx,8),%rdx 1660: c5 fe 7f 02 vmovdqu %ymm0,(%rdx) 1664: c5 fe 6f 48 60 vmovdqu 0x60(%rax),%ymm1 1669: c5 fe 7f 4a 20 vmovdqu %ymm1,0x20(%rdx) 166e: c5 fe 6f 90 80 00 00 vmovdqu 0x80(%rax),%ymm2 1675: 00 1676: c5 fe 7f 52 40 vmovdqu %ymm2,0x40(%rdx) 167b: c5 fe 6f 98 a0 00 00 vmovdqu 0xa0(%rax),%ymm3 1682: 00 1683: c5 fe 7f 5a 60 vmovdqu %ymm3,0x60(%rdx) 1688: c5 fe 6f a0 c0 00 00 vmovdqu 0xc0(%rax),%ymm4 168f: 00 1690: c5 fe 7f a2 80 00 00 vmovdqu %ymm4,0x80(%rdx) 1697: 00 1698: c5 fe 6f a8 e0 00 00 vmovdqu 0xe0(%rax),%ymm5 169f: 00 16a0: c5 fe 7f aa a0 00 00 vmovdqu %ymm5,0xa0(%rdx) 16a7: 00 16a8: c5 fe 6f b0 00 01 00 vmovdqu 0x100(%rax),%ymm6 16af: 00 16b0: c5 fe 7f b2 c0 00 00 vmovdqu %ymm6,0xc0(%rdx) 16b7: 00 16b8: c5 fe 6f b8 20 01 00 vmovdqu 0x120(%rax),%ymm7 16bf: 00 16c0: c5 fe 7f ba e0 00 00 vmovdqu %ymm7,0xe0(%rdx) 16c7: 00 16c8: 48 8b 40 08 mov 0x8(%rax),%rax 16cc: 39 f1 cmp %esi,%ecx 16ce: 75 80 jne 1650 <pile_dequeue+0xe0> 16d0:This is without the
rte_memcpyoptimization:1650: 89 ca mov %ecx,%edx 1652: c5 fe 6f 40 40 vmovdqu 0x40(%rax),%ymm0 1657: 49 89 c1 mov %rax,%r9 165a: ff c1 inc %ecx 165c: c1 e2 05 shl $0x5,%edx 165f: 49 8d 14 d4 lea (%r12,%rdx,8),%rdx 1663: c5 fe 7f 02 vmovdqu %ymm0,(%rdx) 1667: c5 fe 6f 48 60 vmovdqu 0x60(%rax),%ymm1 166c: 49 09 d1 or %rdx,%r9 166f: 41 83 e1 1f and $0x1f,%r9d 1673: c5 fe 7f 4a 20 vmovdqu %ymm1,0x20(%rdx) 1678: c5 fe 6f 90 80 00 00 vmovdqu 0x80(%rax),%ymm2 167f: 00 1680: c5 fe 7f 52 40 vmovdqu %ymm2,0x40(%rdx) 1685: c5 fe 6f 98 a0 00 00 vmovdqu 0xa0(%rax),%ymm3 168c: 00 168d: c5 fe 7f 5a 60 vmovdqu %ymm3,0x60(%rdx) 1692: c5 fe 6f a0 c0 00 00 vmovdqu 0xc0(%rax),%ymm4 1699: 00 169a: c5 fe 7f a2 80 00 00 vmovdqu %ymm4,0x80(%rdx) 16a1: 00 16a2: c5 fe 6f a8 e0 00 00 vmovdqu 0xe0(%rax),%ymm5 16a9: 00 16aa: c5 fe 7f aa a0 00 00 vmovdqu %ymm5,0xa0(%rdx) 16b1: 00 16b2: c5 fe 6f b0 00 01 00 vmovdqu 0x100(%rax),%ymm6 16b9: 00 16ba: c5 fe 7f b2 c0 00 00 vmovdqu %ymm6,0xc0(%rdx) 16c1: 00 16c2: c5 fe 6f b8 20 01 00 vmovdqu 0x120(%rax),%ymm7 16c9: 00 16ca: c5 fe 7f ba e0 00 00 vmovdqu %ymm7,0xe0(%rdx) 16d1: 00 16d2: 48 8b 40 08 mov 0x8(%rax),%rax 16d6: 0f 85 c4 00 00 00 jne 17a0 <pile_dequeue+0x230> 16dc: 39 ce cmp %ecx,%esi 16de: 0f 85 6c ff ff ff jne 1650 <pile_dequeue+0xe0> 16e4: [...] 17a0: 39 f1 cmp %esi,%ecx 17a2: 0f 85 a8 fe ff ff jne 1650 <pile_dequeue+0xe0> 17a8: e9 37 ff ff ff jmp 16e4 <pile_dequeue+0x174>Here, the alignment comparison I have optimized away is performed using register %r9.
With the optimization, the generated assembly is less cluttered, and thus easier to review.
(It seems the compiler is clever enough to not duplicate the two instances of the code, but reuse the aligned instance for the unaligned case too. So the reduction in code size is not as great as I previously claimed.)I agree the performance benefit in CPU cycles is probably insignificant. But the generated assembly is cleaner.
And if pressured for CPU registers, the optimization also frees up one CPU register for other purposes.
Quoted 4 lines
Code size reduction:
The optimized loop is0x80bytes of instructions.
The non-optimized is0x8ebytes, 14 bytes more, in the loop, plus 13 bytes outside the loop.
Honestly, with such insignificant gains, I'd either leave it alone, or look more closely at compiler pragmas option we discussed before.
Quoted 56 lines
Quoted 56 lines
Quoted 5 lines
======= ================= ================= =================
=================
Size Cache to cache Cache to mem Mem to cacheMem to mem
Quoted 1 line
(bytes) (ticks) (ticks) (ticks)
(ticks)
Quoted 1 line
------- ----------------- ----------------- ----------------- -------
----------
Quoted 4 lines
================================= 32B aligned
=================================
Before
C 64 2 - 2( 9.60%) 22 - 21( 4.48%) 33 - 31( 5.15%) 57 -56( 0.28%)
Quoted 1 line
C 128 4 - 4( 5.56%) 41 - 40( 3.59%) 53 - 52( 1.49%) 101 -
100( 0.71%)
Quoted 1 line
C 192 6 - 6( 4.06%) 64 - 60( 5.61%) 68 - 69( -1.68%) 136 -
138( -1.49%)
Quoted 1 line
C 256 10 - 9( 5.21%) 82 - 81( 1.20%) 93 - 87( 7.47%) 172 -
175( -1.46%)
Quoted 2 lines
After
C 64 2 - 2( -0.71%) 22 - 21( 7.62%) 31 - 30( 4.32%) 57 -59( -3.03%)
Quoted 1 line
C 128 4 - 4( -0.34%) 40 - 40( 0.60%) 50 - 50( 0.41%) 97 -
99( -1.96%)
Quoted 1 line
C 192 6 - 6( 5.27%) 59 - 59( -0.27%) 69 - 72( -4.42%) 139 -
138( 0.90%) > C 256 9 - 9( 9.14%) 77 - 77( 0.25%) 89 - 90( -0.88%) 180 - 177( 1.57%)Quoted 4 lines
================================== Unaligned
==================================
Before
C 64 5 - 5( 0.98%) 32 - 32( 0.72%) 42 - 42( 0.44%) 82 -82( 0.51%)
Quoted 1 line
C 128 8 - 9(-11.26%) 51 - 50( 0.53%) 60 - 59( 0.89%) 117 -
115( 1.37%)
Quoted 1 line
C 192 13 - 12( 1.62%) 66 - 67( -1.12%) 83 - 80( 3.26%) 157 -
165( -5.25%)
Quoted 1 line
C 256 21 - 22( -5.78%) 94 - 93( 1.65%) 100 - 99( 1.52%) 202 -
204( -1.34%)
Quoted 2 lines
After
C 64 5 - 5( 0.05%) 31 - 31( 0.16%) 40 - 39( 1.37%) 77 -77( -0.93%)
Quoted 1 line
C 128 9 - 9( -0.69%) 50 - 50( -0.02%) 61 - 60( 2.71%) 118 -
122( -3.15%)
Quoted 1 line
C 192 12 - 11( 7.68%) 68 - 66( 3.64%) 79 - 81( -2.85%) 164 -
164( -0.12%)
Quoted 1 line
C 256 21 - 20( 1.80%) 90 - 87( 2.70%) 96 - 97( -0.99%) 202 -
201( 0.09%)
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
[1]:
https://patchwork.dpdk.org/project/dpdk/patch/20260521185631.116046-1-
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 282 lines
From: Konstantin Ananyev [mailto:[email protected]]
Sent: Tuesday, 18 August 2026 10.15Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
+ /* Common way for small copy size of 64-
byte
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
blocks.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Unlikely, so
Quoted 2 lines
Quoted 2 lines
constant size only */
+ if (__rte_constant(n) && (n & 63) == 0 &&n <=
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
RTE_MEMCPY_BLOCK_64_MAX) {
+ void *ret = dst;
+Maybe just let compiler decide, it will
generate
Quoted 11 lines
Quoted 11 lines
vector
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
instructions in
Quoted 7 lines
Quoted 4 lines
most cases.
if (__rte_constant(n))
return mempcpy(dst, src, n);Maybe in most, but not in all:
https://godbolt.org/z/KvdKqT5rYWith '-mavx' or '-mavx512f' it looks like it does
for
Quoted 7 lines
Quoted 7 lines
your
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
sample
Quoted 3 lines
Quoted 3 lines
code.
Quoted 2 lines
It also does with -msse4.2 when SZ is reduced to 256
bytes.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Clang switches to inline when SZ is reduced to 128
bytes.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
It seems the compiler has a threshold for when to
inline
Quoted 6 lines
Quoted 6 lines
and
Quoted 5 lines
Quoted 5 lines
when
Quoted 4 lines
Quoted 4 lines
to
Quoted 3 lines
Quoted 3 lines
call the C
Quoted 2 lines
library's memcpy subroutine.
The threshold depends on both copy size and vectorQuoted 8 lines
Quoted 8 lines
register
Quoted 4 lines
Quoted 4 lines
size.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
And it is compiler dependent.
I think there are compiler options to specify desired
threshold
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
values.
Quoted 1 line
Quoted 1 line
Let say for gcc there is ' -mmemcpy-
strategy=strategy'.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
For that example in that particular case -mmemcpy-strategy=vector_loop:512:align,loop:-1:align generates sse loads/stores.
Might be we can exploit it somehow?That could give us higher granularity/control over memcpy
for
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
individual
Quoted 1 line
memcpy instances; might be useful for hot code paths
where we
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
have
Quoted 2 lines
Quoted 2 lines
more
Quoted 1 line
knowledge about the copy operation than the compiler can
infer.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
However, pragmas are discouraged in DPDK, and this looks
like
Quoted 6 lines
Quoted 6 lines
a
Quoted 5 lines
Quoted 5 lines
very
Quoted 4 lines
Quoted 4 lines
similar
Quoted 1 line
path.
Well, right now
rte_memcpy.his 700+ lines and keepsgrowing.
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Considering that probably pragmas are not that bad. Of course, pragmas have their own issues and it is hard to
ensure
Quoted 2 lines
Quoted 2 lines
that
Quoted 1 line
Quoted 1 line
they will produce same code between different
Quoted 8 lines
Quoted 8 lines
compilers/versions,
Quoted 3 lines
Quoted 3 lines
etc.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
I am not really happy that our home-brewed memcpy code-
block
Quoted 3 lines
Quoted 3 lines
keeps
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
growing,
while we keep talking that it would be good toeliminate it
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
completely.
Quoted 3 lines
I agree in principle.
However, thisrte_memcpy()optimization is for thepile/mempool
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
optimizations
Quoted 1 line
I'm working on, so there is a specific use case
motivating
Quoted 5 lines
Quoted 5 lines
the
Quoted 4 lines
Quoted 4 lines
added
Quoted 3 lines
Quoted 3 lines
code.
I understand that you probably have some specific use-case
in
Quoted 2 lines
Quoted 2 lines
mind.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
BTW for this optimization you mentioned above: what is the
gain
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
with
Quoted 3 lines
Quoted 1 line
these changes?
IMO, the primary benefit is the much simpler (and smaller)
assembly
Quoted 2 lines
Quoted 2 lines
output due
Quoted 1 line
to avoiding the address alignment check (and the resulting
Quoted 8 lines
Quoted 8 lines
duplicated
Quoted 3 lines
Quoted 3 lines
code).
I think that should be measurable too: whole binary and/or hot
path
Quoted 3 lines
Quoted 1 line
function size reduction, etc.
The size of the generated code for the copy operation is reduced
to
Quoted 2 lines
Quoted 2 lines
slightly less
Quoted 1 line
than half (only one instance of the copy operation instead of
two,
Quoted 6 lines
Quoted 6 lines
and the
Quoted 5 lines
address alignment comparison is omitted).
Quoted 3 lines
Quoted 3 lines
I haven't measured the performance gain.
Based on the perf gain in a previous mempool optimizationpatch
Quoted 7 lines
Quoted 7 lines
[1],
Quoted 2 lines
Quoted 2 lines
it seems
Quoted 1 line
avoiding the address alignment check shaves ~2 cycles off the
copy
Quoted 3 lines
Quoted 3 lines
operation (for
Quoted 2 lines
cache-to-cache copy).
I expect that the same gain (from avoiding the addressalignment
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
check) applies
Quoted 1 line
here.
Ok, then I suggest we do some measurements first, before going
forward
Quoted 3 lines
Quoted 1 line
with it.
I tried
memcpy_perf_autotest, but the branch predictor kicks inand
Quoted 2 lines
Quoted 2 lines
eliminates
Quoted 1 line
the cost of the address alignment comparison. So the results are
very
Quoted 7 lines
Quoted 7 lines
similar.
Indeed, they are the same.
Quoted 1 line
BTW, that's a general issue with our perf tests: Repeated testing
doesn't show
Quoted 1 line
the cost of branches, because they are always eliminated by the
Quoted 8 lines
Quoted 8 lines
branch
Quoted 1 line
predictor.
Might be...
But we do need some measurable evidence that such change improve things,
otherwise - why to bother?
If that perf test is not goof enough - let's try to extend it oruse
Quoted 2 lines
Quoted 2 lines
different one.
BTW, in your mempool pile RFC, I see you also userte_memcpyoverfixed
Quoted 2 lines
Quoted 2 lines
sized buffers.
Do you see any improvement there (wit/withoutrte_memcpyoptimixation)?
Quoted 86 lines
Looking at the generated assembly (objdump -S
build/drivers/librte_mempool_stack.so)...This is the optimized copy loop in
pile_dequeue:1650: 89 ca mov %ecx,%edx 1652: c5 fe 6f 40 40 vmovdqu 0x40(%rax),%ymm0 1657: ff c1 inc %ecx 1659: c1 e2 05 shl $0x5,%edx 165c: 49 8d 14 d4 lea (%r12,%rdx,8),%rdx 1660: c5 fe 7f 02 vmovdqu %ymm0,(%rdx) 1664: c5 fe 6f 48 60 vmovdqu 0x60(%rax),%ymm1 1669: c5 fe 7f 4a 20 vmovdqu %ymm1,0x20(%rdx) 166e: c5 fe 6f 90 80 00 00 vmovdqu 0x80(%rax),%ymm2 1675: 00 1676: c5 fe 7f 52 40 vmovdqu %ymm2,0x40(%rdx) 167b: c5 fe 6f 98 a0 00 00 vmovdqu 0xa0(%rax),%ymm3 1682: 00 1683: c5 fe 7f 5a 60 vmovdqu %ymm3,0x60(%rdx) 1688: c5 fe 6f a0 c0 00 00 vmovdqu 0xc0(%rax),%ymm4 168f: 00 1690: c5 fe 7f a2 80 00 00 vmovdqu %ymm4,0x80(%rdx) 1697: 00 1698: c5 fe 6f a8 e0 00 00 vmovdqu 0xe0(%rax),%ymm5 169f: 00 16a0: c5 fe 7f aa a0 00 00 vmovdqu %ymm5,0xa0(%rdx) 16a7: 00 16a8: c5 fe 6f b0 00 01 00 vmovdqu 0x100(%rax),%ymm6 16af: 00 16b0: c5 fe 7f b2 c0 00 00 vmovdqu %ymm6,0xc0(%rdx) 16b7: 00 16b8: c5 fe 6f b8 20 01 00 vmovdqu 0x120(%rax),%ymm7 16bf: 00 16c0: c5 fe 7f ba e0 00 00 vmovdqu %ymm7,0xe0(%rdx) 16c7: 00 16c8: 48 8b 40 08 mov 0x8(%rax),%rax 16cc: 39 f1 cmp %esi,%ecx 16ce: 75 80 jne 1650 <pile_dequeue+0xe0> 16d0:This is without the
rte_memcpyoptimization:1650: 89 ca mov %ecx,%edx 1652: c5 fe 6f 40 40 vmovdqu 0x40(%rax),%ymm0 1657: 49 89 c1 mov %rax,%r9 165a: ff c1 inc %ecx 165c: c1 e2 05 shl $0x5,%edx 165f: 49 8d 14 d4 lea (%r12,%rdx,8),%rdx 1663: c5 fe 7f 02 vmovdqu %ymm0,(%rdx) 1667: c5 fe 6f 48 60 vmovdqu 0x60(%rax),%ymm1 166c: 49 09 d1 or %rdx,%r9 166f: 41 83 e1 1f and $0x1f,%r9d 1673: c5 fe 7f 4a 20 vmovdqu %ymm1,0x20(%rdx) 1678: c5 fe 6f 90 80 00 00 vmovdqu 0x80(%rax),%ymm2 167f: 00 1680: c5 fe 7f 52 40 vmovdqu %ymm2,0x40(%rdx) 1685: c5 fe 6f 98 a0 00 00 vmovdqu 0xa0(%rax),%ymm3 168c: 00 168d: c5 fe 7f 5a 60 vmovdqu %ymm3,0x60(%rdx) 1692: c5 fe 6f a0 c0 00 00 vmovdqu 0xc0(%rax),%ymm4 1699: 00 169a: c5 fe 7f a2 80 00 00 vmovdqu %ymm4,0x80(%rdx) 16a1: 00 16a2: c5 fe 6f a8 e0 00 00 vmovdqu 0xe0(%rax),%ymm5 16a9: 00 16aa: c5 fe 7f aa a0 00 00 vmovdqu %ymm5,0xa0(%rdx) 16b1: 00 16b2: c5 fe 6f b0 00 01 00 vmovdqu 0x100(%rax),%ymm6 16b9: 00 16ba: c5 fe 7f b2 c0 00 00 vmovdqu %ymm6,0xc0(%rdx) 16c1: 00 16c2: c5 fe 6f b8 20 01 00 vmovdqu 0x120(%rax),%ymm7 16c9: 00 16ca: c5 fe 7f ba e0 00 00 vmovdqu %ymm7,0xe0(%rdx) 16d1: 00 16d2: 48 8b 40 08 mov 0x8(%rax),%rax 16d6: 0f 85 c4 00 00 00 jne 17a0 <pile_dequeue+0x230> 16dc: 39 ce cmp %ecx,%esi 16de: 0f 85 6c ff ff ff jne 1650 <pile_dequeue+0xe0> 16e4: [...] 17a0: 39 f1 cmp %esi,%ecx 17a2: 0f 85 a8 fe ff ff jne 1650 <pile_dequeue+0xe0> 17a8: e9 37 ff ff ff jmp 16e4 <pile_dequeue+0x174>Quoted 1 line
Here, the alignment comparison I have optimized away is performed
using
Quoted 3 lines
register %r9.
With the optimization, the generated assembly is less cluttered, and
thus easier
Quoted 2 lines
to review.
(It seems the compiler is clever enough to not duplicate the twoinstances of the
Quoted 1 line
code, but reuse the aligned instance for the unaligned case too. So
the reduction
Quoted 3 lines
in code size is not as great as I previously claimed.)
I agree the performance benefit in CPU cycles is probably
insignificant.
Quoted 2 lines
But the generated assembly is cleaner.
And if pressured for CPU registers, the optimization also frees upone CPU
Quoted 2 lines
register for other purposes.
Quoted 8 lines
Quoted 3 lines
Code size reduction:
The optimized loop is0x80bytes of instructions.
The non-optimized is0x8ebytes, 14 bytes more, in the loop, plus 13bytes
Quoted 1 line
outside the loop.
Honestly, with such insignificant gains, I'd either leave it alone, or look more closely at compiler pragmas option we discussed before.
Compiled code is slightly smaller, performance is slightly better. But source code having slightly more lines of code is more important?
If the source code added was difficult to read, complexity was increased, or had side effects or spillover to other modules, I might buy that argument. But the addition is very simple and completely isolated.
If the objection is about source code readability, I could add more inline comments to the added code, elaborating that the added code path is the same for all CPU vector sizes, regardless of address alignment. But I suspect such comments would confuse more than they would help.
And it would add even more lines to the file size.
Adding compiler pragmas should probably be done in source code calling rte_memcpy(), like __rte_assume() and the coming __rte_assume_cache_aligned() [1].
[1]: https://patchwork.dpdk.org/project/dpdk/patch/[email protected]/
If you try experimenting with compiler pragmas, I'm open for reviewing an RFC! For now, let's take this small step.
Quoted 75 lines
Quoted 10 lines
Quoted 10 lines
Quoted 6 lines
======= ================= ================= =================
=================
Size Cache to cache Cache to mem Mem to cacheMem to mem
Quoted 1 line
(bytes) (ticks) (ticks) (ticks)
(ticks)
Quoted 1 line
------- ----------------- ----------------- ----------------- ---
----
Quoted 5 lines
Quoted 5 lines
----------
Quoted 4 lines
================================= 32B aligned
=================================
Before
C 64 2 - 2( 9.60%) 22 - 21( 4.48%) 33 - 31( 5.15%) 57-
Quoted 2 lines
Quoted 2 lines
56( 0.28%)
Quoted 1 line
C 128 4 - 4( 5.56%) 41 - 40( 3.59%) 53 - 52( 1.49%) 101
-
Quoted 2 lines
Quoted 2 lines
100( 0.71%)
Quoted 1 line
C 192 6 - 6( 4.06%) 64 - 60( 5.61%) 68 - 69( -1.68%) 136
-
Quoted 2 lines
Quoted 2 lines
138( -1.49%)
Quoted 1 line
C 256 10 - 9( 5.21%) 82 - 81( 1.20%) 93 - 87( 7.47%) 172
-
Quoted 3 lines
Quoted 3 lines
175( -1.46%)
Quoted 2 lines
After
C 64 2 - 2( -0.71%) 22 - 21( 7.62%) 31 - 30( 4.32%) 57-
Quoted 2 lines
Quoted 2 lines
59( -3.03%)
Quoted 1 line
C 128 4 - 4( -0.34%) 40 - 40( 0.60%) 50 - 50( 0.41%) 97
-
Quoted 2 lines
Quoted 2 lines
99( -1.96%)
Quoted 1 line
C 192 6 - 6( 5.27%) 59 - 59( -0.27%) 69 - 72( -4.42%) 139
-
Quoted 2 lines
Quoted 2 lines
138( 0.90%)
Quoted 1 line
C 256 9 - 9( 9.14%) 77 - 77( 0.25%) 89 - 90( -0.88%) 180
-
Quoted 5 lines
Quoted 5 lines
177( 1.57%)
Quoted 4 lines
================================== Unaligned
==================================
Before
C 64 5 - 5( 0.98%) 32 - 32( 0.72%) 42 - 42( 0.44%) 82-
Quoted 2 lines
Quoted 2 lines
82( 0.51%)
Quoted 1 line
C 128 8 - 9(-11.26%) 51 - 50( 0.53%) 60 - 59( 0.89%) 117
-
Quoted 2 lines
Quoted 2 lines
115( 1.37%)
Quoted 1 line
C 192 13 - 12( 1.62%) 66 - 67( -1.12%) 83 - 80( 3.26%) 157
-
Quoted 2 lines
Quoted 2 lines
165( -5.25%)
Quoted 1 line
C 256 21 - 22( -5.78%) 94 - 93( 1.65%) 100 - 99( 1.52%) 202
-
Quoted 3 lines
Quoted 3 lines
204( -1.34%)
Quoted 2 lines
After
C 64 5 - 5( 0.05%) 31 - 31( 0.16%) 40 - 39( 1.37%) 77-
Quoted 2 lines
Quoted 2 lines
77( -0.93%)
Quoted 1 line
C 128 9 - 9( -0.69%) 50 - 50( -0.02%) 61 - 60( 2.71%) 118
-
Quoted 2 lines
Quoted 2 lines
122( -3.15%)
Quoted 1 line
C 192 12 - 11( 7.68%) 68 - 66( 3.64%) 79 - 81( -2.85%) 164
-
Quoted 2 lines
Quoted 2 lines
164( -0.12%)
Quoted 1 line
C 256 21 - 20( 1.80%) 90 - 87( 2.70%) 96 - 97( -0.99%) 202
-
Quoted 6 lines
Quoted 6 lines
201( 0.09%)
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
[1]:
https://patchwork.dpdk.org/project/dpdk/patch/20260521185631.116046-1-
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 333 lines
From: Morten Brørup
Sent: Tuesday, 18 August 2026 11.13Quoted 20 lines
From: Konstantin Ananyev [mailto:[email protected]]
Sent: Tuesday, 18 August 2026 10.15Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
+ /* Common way for small copy size of 64-
byte
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
blocks.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Unlikely, so
Quoted 2 lines
constant size only */
+ if (__rte_constant(n) && (n & 63) == 0 &&n <=
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
RTE_MEMCPY_BLOCK_64_MAX) {
+ void *ret = dst;
+Maybe just let compiler decide, it will
generate
Quoted 4 lines
Quoted 4 lines
vector
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
instructions in
Quoted 2 lines
most cases.
Quoted 13 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
if (__rte_constant(n))
return mempcpy(dst, src, n);Maybe in most, but not in all:
https://godbolt.org/z/KvdKqT5rYWith '-mavx' or '-mavx512f' it looks like it does
for
Quoted 5 lines
Quoted 5 lines
your
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
sample
Quoted 3 lines
Quoted 3 lines
code.
Quoted 2 lines
It also does with -msse4.2 when SZ is reduced to
256
Quoted 13 lines
Quoted 2 lines
Quoted 2 lines
bytes.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Clang switches to inline when SZ is reduced to 128
bytes.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
It seems the compiler has a threshold for when to
inline
Quoted 7 lines
Quoted 7 lines
and
Quoted 5 lines
Quoted 5 lines
when
Quoted 4 lines
Quoted 4 lines
to
Quoted 3 lines
Quoted 3 lines
call the C
Quoted 2 lines
library's memcpy subroutine.
The threshold depends on both copy size and vectorregister
Quoted 14 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
size.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
And it is compiler dependent.
I think there are compiler options to specify desired
threshold
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
values.
Quoted 1 line
Quoted 1 line
Let say for gcc there is ' -mmemcpy-
strategy=strategy'.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
For that example in that particular case -mmemcpy-strategy=vector_loop:512:align,loop:-1:align generates sse loads/stores.
Might be we can exploit it somehow?That could give us higher granularity/control over
memcpy
Quoted 7 lines
for
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
individual
Quoted 1 line
memcpy instances; might be useful for hot code paths
where we
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
have
Quoted 2 lines
Quoted 2 lines
more
Quoted 1 line
knowledge about the copy operation than the compiler
can
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
infer.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
However, pragmas are discouraged in DPDK, and this
looks
Quoted 10 lines
like
Quoted 6 lines
Quoted 6 lines
a
Quoted 5 lines
Quoted 5 lines
very
Quoted 4 lines
Quoted 4 lines
similar
Quoted 1 line
path.
Well, right now
rte_memcpy.his 700+ lines and keepsgrowing.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Considering that probably pragmas are not that bad. Of course, pragmas have their own issues and it is hard
to
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
ensure
Quoted 2 lines
Quoted 2 lines
that
Quoted 1 line
Quoted 1 line
they will produce same code between different
compilers/versions,
Quoted 3 lines
Quoted 3 lines
etc.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
I am not really happy that our home-brewed memcpy
code-
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
block
Quoted 3 lines
Quoted 3 lines
keeps
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
growing,
while we keep talking that it would be good toeliminate it
Quoted 13 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
completely.
Quoted 3 lines
I agree in principle.
However, thisrte_memcpy()optimization is for thepile/mempool
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
optimizations
Quoted 1 line
I'm working on, so there is a specific use case
motivating
Quoted 5 lines
Quoted 5 lines
the
Quoted 4 lines
Quoted 4 lines
added
Quoted 3 lines
Quoted 3 lines
code.
I understand that you probably have some specific use-
case
Quoted 3 lines
in
Quoted 2 lines
Quoted 2 lines
mind.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
BTW for this optimization you mentioned above: what is
the
Quoted 12 lines
gain
Quoted 11 lines
Quoted 11 lines
Quoted 4 lines
Quoted 4 lines
with
Quoted 3 lines
Quoted 1 line
these changes?
IMO, the primary benefit is the much simpler (and smaller)
assembly
Quoted 2 lines
Quoted 2 lines
output due
Quoted 1 line
to avoiding the address alignment check (and the resulting
duplicated
Quoted 3 lines
Quoted 3 lines
code).
I think that should be measurable too: whole binary and/or
hot
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
path
Quoted 3 lines
Quoted 1 line
function size reduction, etc.
The size of the generated code for the copy operation is
reduced
Quoted 14 lines
to
Quoted 2 lines
Quoted 2 lines
slightly less
Quoted 1 line
than half (only one instance of the copy operation instead of
two,
Quoted 6 lines
Quoted 6 lines
and the
Quoted 5 lines
address alignment comparison is omitted).
Quoted 3 lines
Quoted 3 lines
I haven't measured the performance gain.
Based on the perf gain in a previous mempool optimizationpatch
Quoted 3 lines
Quoted 3 lines
[1],
Quoted 2 lines
Quoted 2 lines
it seems
Quoted 1 line
avoiding the address alignment check shaves ~2 cycles off
the
Quoted 9 lines
Quoted 4 lines
Quoted 4 lines
copy
Quoted 3 lines
Quoted 3 lines
operation (for
Quoted 2 lines
cache-to-cache copy).
I expect that the same gain (from avoiding the addressalignment
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
check) applies
Quoted 1 line
here.
Ok, then I suggest we do some measurements first, before
going
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
forward
Quoted 3 lines
Quoted 1 line
with it.
I tried
memcpy_perf_autotest, but the branch predictor kicks inand
Quoted 2 lines
Quoted 2 lines
eliminates
Quoted 1 line
the cost of the address alignment comparison. So the results
are
Quoted 6 lines
very
Quoted 5 lines
Quoted 5 lines
similar.
Indeed, they are the same.
Quoted 1 line
BTW, that's a general issue with our perf tests: Repeated
testing
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
doesn't show
Quoted 1 line
the cost of branches, because they are always eliminated by the
branch
Quoted 1 line
predictor.
Might be...
But we do need some measurable evidence that such change improve things,
otherwise - why to bother?
If that perf test is not goof enough - let's try to extend it orQuoted 46 lines
use
Quoted 2 lines
Quoted 2 lines
different one.
BTW, in your mempool pile RFC, I see you also userte_memcpyoverfixed
Quoted 2 lines
Quoted 2 lines
sized buffers.
Do you see any improvement there (wit/withoutrte_memcpyoptimixation)?
Quoted 39 lines
Looking at the generated assembly (objdump -S
build/drivers/librte_mempool_stack.so)...This is the optimized copy loop in
pile_dequeue:1650: 89 ca mov %ecx,%edx 1652: c5 fe 6f 40 40 vmovdqu 0x40(%rax),%ymm0 1657: ff c1 inc %ecx 1659: c1 e2 05 shl $0x5,%edx 165c: 49 8d 14 d4 lea (%r12,%rdx,8),%rdx 1660: c5 fe 7f 02 vmovdqu %ymm0,(%rdx) 1664: c5 fe 6f 48 60 vmovdqu 0x60(%rax),%ymm1 1669: c5 fe 7f 4a 20 vmovdqu %ymm1,0x20(%rdx) 166e: c5 fe 6f 90 80 00 00 vmovdqu 0x80(%rax),%ymm2 1675: 00 1676: c5 fe 7f 52 40 vmovdqu %ymm2,0x40(%rdx) 167b: c5 fe 6f 98 a0 00 00 vmovdqu 0xa0(%rax),%ymm3 1682: 00 1683: c5 fe 7f 5a 60 vmovdqu %ymm3,0x60(%rdx) 1688: c5 fe 6f a0 c0 00 00 vmovdqu 0xc0(%rax),%ymm4 168f: 00 1690: c5 fe 7f a2 80 00 00 vmovdqu %ymm4,0x80(%rdx) 1697: 00 1698: c5 fe 6f a8 e0 00 00 vmovdqu 0xe0(%rax),%ymm5 169f: 00 16a0: c5 fe 7f aa a0 00 00 vmovdqu %ymm5,0xa0(%rdx) 16a7: 00 16a8: c5 fe 6f b0 00 01 00 vmovdqu 0x100(%rax),%ymm6 16af: 00 16b0: c5 fe 7f b2 c0 00 00 vmovdqu %ymm6,0xc0(%rdx) 16b7: 00 16b8: c5 fe 6f b8 20 01 00 vmovdqu 0x120(%rax),%ymm7 16bf: 00 16c0: c5 fe 7f ba e0 00 00 vmovdqu %ymm7,0xe0(%rdx) 16c7: 00 16c8: 48 8b 40 08 mov 0x8(%rax),%rax 16cc: 39 f1 cmp %esi,%ecx 16ce: 75 80 jne 1650<
pile_dequeue+0xe0>Quoted 31 lines
Quoted 31 lines
16d0:This is without the
rte_memcpyoptimization:1650: 89 ca mov %ecx,%edx 1652: c5 fe 6f 40 40 vmovdqu 0x40(%rax),%ymm0 1657: 49 89 c1 mov %rax,%r9 165a: ff c1 inc %ecx 165c: c1 e2 05 shl $0x5,%edx 165f: 49 8d 14 d4 lea (%r12,%rdx,8),%rdx 1663: c5 fe 7f 02 vmovdqu %ymm0,(%rdx) 1667: c5 fe 6f 48 60 vmovdqu 0x60(%rax),%ymm1 166c: 49 09 d1 or %rdx,%r9 166f: 41 83 e1 1f and $0x1f,%r9d 1673: c5 fe 7f 4a 20 vmovdqu %ymm1,0x20(%rdx) 1678: c5 fe 6f 90 80 00 00 vmovdqu 0x80(%rax),%ymm2 167f: 00 1680: c5 fe 7f 52 40 vmovdqu %ymm2,0x40(%rdx) 1685: c5 fe 6f 98 a0 00 00 vmovdqu 0xa0(%rax),%ymm3 168c: 00 168d: c5 fe 7f 5a 60 vmovdqu %ymm3,0x60(%rdx) 1692: c5 fe 6f a0 c0 00 00 vmovdqu 0xc0(%rax),%ymm4 1699: 00 169a: c5 fe 7f a2 80 00 00 vmovdqu %ymm4,0x80(%rdx) 16a1: 00 16a2: c5 fe 6f a8 e0 00 00 vmovdqu 0xe0(%rax),%ymm5 16a9: 00 16aa: c5 fe 7f aa a0 00 00 vmovdqu %ymm5,0xa0(%rdx) 16b1: 00 16b2: c5 fe 6f b0 00 01 00 vmovdqu 0x100(%rax),%ymm6 16b9: 00Quoted 8 lines
Quoted 8 lines
16ba: c5 fe 7f b2 c0 00 00 vmovdqu %ymm6,0xc0(%rdx) 16c1: 00 16c2: c5 fe 6f b8 20 01 00 vmovdqu 0x120(%rax),%ymm7 16c9: 00 16ca: c5 fe 7f ba e0 00 00 vmovdqu %ymm7,0xe0(%rdx) 16d1: 00 16d2: 48 8b 40 08 mov 0x8(%rax),%rax 16d6: 0f 85 c4 00 00 00 jne 17a0<
pile_dequeue+0x230>Quoted 2 lines
Quoted 2 lines
16dc: 39 ce cmp %ecx,%esi 16de: 0f 85 6c ff ff ff jne 1650<
pile_dequeue+0xe0>Quoted 4 lines
Quoted 4 lines
16e4: [...] 17a0: 39 f1 cmp %esi,%ecx 17a2: 0f 85 a8 fe ff ff jne 1650<
pile_dequeue+0xe0>Quoted 1 line
Quoted 1 line
17a8: e9 37 ff ff ff jmp 16e4<
pile_dequeue+0x174>Quoted 6 lines
Quoted 2 lines
Here, the alignment comparison I have optimized away is performed
using
Quoted 3 lines
register %r9.
With the optimization, the generated assembly is less cluttered,
and
Quoted 5 lines
thus easier
Quoted 2 lines
to review.
(It seems the compiler is clever enough to not duplicate the twoinstances of the
Quoted 1 line
code, but reuse the aligned instance for the unaligned case too. So
Quoted 13 lines
the reduction
Quoted 3 lines
in code size is not as great as I previously claimed.)
I agree the performance benefit in CPU cycles is probably
insignificant.
Quoted 2 lines
But the generated assembly is cleaner.
And if pressured for CPU registers, the optimization also frees upone CPU
Quoted 5 lines
register for other purposes.
Code size reduction:
The optimized loop is0x80bytes of instructions.
The non-optimized is0x8ebytes, 14 bytes more, in the loop, plus13
Quoted 5 lines
bytes
Quoted 1 line
outside the loop.
Honestly, with such insignificant gains, I'd either leave it alone, or look more closely at compiler pragmas option we discussed before.
Compiled code is slightly smaller, performance is slightly better. But source code having slightly more lines of code is more important?
If the source code added was difficult to read, complexity was increased, or had side effects or spillover to other modules, I might buy that argument.
But the addition is very simple and completely isolated.If the objection is about source code readability, I could add more inline comments to the added code, elaborating that the added code path is the same for all CPU vector sizes, regardless of address alignment. But I suspect such comments would confuse more than they would help. And it would add even more lines to the file size.
Adding compiler pragmas should probably be done in source code calling
rte_memcpy(), like__rte_assume()and the coming__rte_assume_cache_aligned()[1].
Quoted 8 lines
[1]:
https://patchwork.dpdk.org/project/dpdk/patch/20260812090723.1771628-1-
[email protected]/If you try experimenting with compiler pragmas, I'm open for reviewing an RFC!
For now, let's take this small step.
I seems nobody want more code in the rte_memcpy() implementation, so I have marked this patch as Rejected, and instead posted a separate patch with the cleanups [2].
[2]: https://patchwork.dpdk.org/project/dpdk/patch/[email protected]/
I had an improved version in the works, not requiring constant size; but I assume it will be rejected too, so I'm not pursuing it. For anyone interested, it had this criteria:
if (__rte_constant((n & 63) == 0 && n <= RTE_MEMCPY_BLOCK_64_MAX) &&
(n & 63) == 0 && n <= RTE_MEMCPY_BLOCK_64_MAX) {The full diff:
@@ -175,2 +175,3 @@ rte_mov256(uint8_t *__rte_restrict dst,
#define RTE_MEMCPY_ALIGNMENT_MASK 0x3F
+#define RTE_MEMCPY_BLOCK_64_MAX 512
@@ -321,2 +322,3 @@ COPY_BLOCK_128_BACK63:
#define RTE_MEMCPY_ALIGNMENT_MASK 0x1F
+#define RTE_MEMCPY_BLOCK_64_MAX 256
@@ -432,2 +434,3 @@ COPY_BLOCK_128_BACK31:
#define RTE_MEMCPY_ALIGNMENT_MASK 0x0F
+#define RTE_MEMCPY_BLOCK_64_MAX 512
@@ -675,2 +678,36 @@ rte_memcpy(void *__rte_restrict dst, con
{
+ /*
+ * Common way for small copy size of 64-byte blocks,
+ * independent of alignment with vector register size.
+ * Note:
+ * If known at compile time that the criteria are fulfilled,
+ * the compiler will use this, and omit everything else;
+ * otherwise, the compiler will omit this.
+ */
+ static_assert(RTE_MEMCPY_BLOCK_64_MAX <= 512,
+ "64-byte block copy max size too big for implementation below");
+ if (__rte_constant((n & 63) == 0 && n <= RTE_MEMCPY_BLOCK_64_MAX) &&
+ (n & 63) == 0 && n <= RTE_MEMCPY_BLOCK_64_MAX) {
+ void *ret = dst;
+
+ if (!(RTE_MEMCPY_BLOCK_64_MAX < 512) && n == 512) {
+ rte_mov256((uint8_t *)dst + 0 * 256, (const uint8_t *)src + 0 * 256);
+ rte_mov256((uint8_t *)dst + 1 * 256, (const uint8_t *)src + 1 * 256);
+ } else {
+ if (n & 256) {
+ rte_mov256((uint8_t *)dst, (const uint8_t *)src);
+ src = (const uint8_t *)src + 256;
+ dst = (uint8_t *)dst + 256;
+ }
+ if (n & 128) {
+ rte_mov128((uint8_t *)dst, (const uint8_t *)src);
+ src = (const uint8_t *)src + 128;
+ dst = (uint8_t *)dst + 128;
+ }
+ if (n & 64)
+ rte_mov64((uint8_t *)dst, (const uint8_t *)src);
+ }
+ return ret;
+ }
+
/* Fast way when copy size doesn't exceed 64 bytes. */
@@ -715,2 +752,3 @@ rte_memcpy(void *__rte_restrict dst, con
#undef RTE_MEMCPY_ALIGNMENT_MASK
+#undef RTE_MEMCPY_BLOCK_64_MAX
Quoted 20 lines
From: Morten Brørup [mailto:[email protected]]
Sent: Tuesday, 4 August 2026 16.33The implementation for copying 64-byte blocks up to 512 (or 256) bytes does not depend on address alignment with the size of the CPU's vector registers, but is implemented in both unaligned and aligned copy functions.
The mainrte_memcpy()function was updated, so
if the copy size is known at compile time and the other criteria match, the copy is performed without checking alignment requirements. This provides two benefits when the optimization comes into play:
1. A performance gain, because the address alignment check is avoided.
3. Reduced instruction memory footprint, because the compiler only generates one instance of the function for copying, instead of two instances (one in the unaligned copy function, and one in the aligned copy function).Furthermore, the temporary alignment mask definition (
ALIGNMENT_MASK) was prefixed byRTE_MEMCPY_to prevent potential namespace collision.
Quoted 7 lines
And finally, the superfluous function declaration at the top of the file was removed, and its description was moved to the function definition.
This improves search results with source code browsers.Signed-off-by Morten Brørup <[email protected]>---
The AI in the CI is confused, so the AI Code Review warning in Patchwork can be ignored.
Quoting and commenting AI code review:
Quoted 4 lines
### 1. Bitwise test incorrect for 512-byte blocks
**File:**
lib/eal/x86/include/rte_memcpy.h:712
Quoted 8 lines
```c if (n & 512) { ```**Issue:**
This test is wrong.n & 512is true when bit 9 is set, which occurs for n=512, n=513, ..., n=767, and many other values outside the intended range. For a size of exactly 512 bytes, you wantn == 512orn >= 512(with an upper bound already enforced by the outerif).
Rubbish. Combined with the overall criteria for entering this at all, the test matches 512 exactly as intended.
Quoted 5 lines
**Why it matters:**
Withn=128, the expression128 & 512evaluates to 0 (correct, no copy).
But withn=640(which is >RTE_MEMCPY_BLOCK_64_MAXon AVX and shouldn't reach this code on AVX512), if it did reach here,640 & 512 = 512would be true and trigger a 512-byte copy when only 640 bytes total are requested.
Irrelevant. It doesn't come here when n > 512.
Quoted 4 lines
More critically, the surrounding checks are also bitwise tests (
n & 256,n & 128,n & 64),
which means this code assumesnis a combination of these powers of two.
But the entry condition isn <= RTE_MEMCPY_BLOCK_64_MAXand(n & 63) == 0, which allows any multiple of 64 up to the max (64, 128, 192, 256, 320, 384, 448, 512).
Correct.
Quoted 1 line
For
n=192, all four bitwise tests fail and nothing is copied.
Wrong. 192 = 128 + 64, so both of those will execute.
Quoted 1 line
For
n=320,n & 256 = 256is true so it copies 256 bytes, thenn & 64 = 64is true so it copies another 64 bytes from offset 256, which is correct only by accident (320 = 256+64).
Not by accident, by design.
Quoted 1 line · On Tue, 4 Aug 2026 21:11:51 +0200 Morten Brørup <[email protected]>…
The AI in the CI is confused, so the AI Code Review warning in Patchwork can be ignored.
No problem, the lack of tooling and weak model is causing lots of rubbish
Quoted 72 lines
The implementation for copying 64-byte blocks up to 512 (or 256) bytes does not depend on address alignment with the size of the CPU's vector registers, but is implemented in both unaligned and aligned copy functions.
The mainrte_memcpy()function was updated, so
if the copy size is known at compile time and the other criteria match, the copy is performed without checking alignment requirements. This provides two benefits when the optimization comes into play:
1. A performance gain, because the address alignment check is avoided.
3. Reduced instruction memory footprint, because the compiler only generates one instance of the function for copying, instead of two instances (one in the unaligned copy function, and one in the aligned copy function).Furthermore, the temporary alignment mask definition (
ALIGNMENT_MASK) was prefixed byRTE_MEMCPY_to prevent potential namespace collision.And finally, the superfluous function declaration at the top of the file was removed, and its description was moved to the function definition.
This improves search results with source code browsers.Signed-off-by Morten Brørup <[email protected]>--- lib/eal/x86/include/rte_memcpy.h | 64 ++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 20 deletions(-)lib/eal/x86/include/rte_memcpy.h +2
-16@@ -32,21 +32,6 @@ extern "C" {#define RTE_MEMCPY_AVX #endif -/** -* Copy bytes from one location to another. The locations must not overlap. -* -* @param dst -* Pointer to the destination of the data. -* @param src -* Pointer to the source data. -* @param n -* Number of bytes to copy. -* @return -* Pointer to the destination data. -*/ -static __rte_always_inline void * -rte_memcpy(void *__rte_restrict dst, const void *__rte_restrict src, size_t n); -/** * Copy bytes from one location to another, * locations must not overlap. @@ -187,7 +172,8 @@ rte_mov256(uint8_t *__rte_restrict dst, const uint8_t*__rte_restrict src) * AVX512 implementation below */ -#define ALIGNMENT_MASK 0x3F +#define RTE_MEMCPY_ALIGNMENT_MASK 0x3F +#define RTE_MEMCPY_BLOCK_64_MAX 512/** * Copy 128-byte blocks from one location to another,
lib/eal/x86/include/rte_memcpy.h +0
-0@@ -333,7 +319,8 @@ rte_memcpy_generic_more_than_64(void *__rte_restrictdst, const void
*__rte_rest
* AVX implementation below
*/
lib/eal/x86/include/rte_memcpy.h rte_memcpy_generic_more_than_64(void *__rte_restrict dst, const void *__rte_rest · line 323
Quoted 3 lines
lib/eal/x86/include/rte_memcpy.h +2
-1-#define ALIGNMENT_MASK 0x1F +#define RTE_MEMCPY_ALIGNMENT_MASK 0x1F +#define RTE_MEMCPY_BLOCK_64_MAX 256
Wonder why BLOCK_64_MAX is 512 for SSE and AVX512, but 256 for AVX2? Some empirical data or ...?
Quoted 43 lines
/**
* Copy 128-byte blocks from one location to another,lib/eal/x86/include/rte_memcpy.h +0
-0@@ -444,7 +431,8 @@ rte_memcpy_generic_more_than_64(void *__rte_restrictdst, const void
*__rte_rest
* SSE implementation below
*/lib/eal/x86/include/rte_memcpy.h +2
-1-#define ALIGNMENT_MASK 0x0F +#define RTE_MEMCPY_ALIGNMENT_MASK 0x0F +#define RTE_MEMCPY_BLOCK_64_MAX 512/** * Macro for copying unaligned block from one location to another with constant load offset,
lib/eal/x86/include/rte_memcpy.h +12
-0@@ -673,6 +661,18 @@ rte_memcpy_aligned_more_than_64(void *__rte_restrict dst, const void *__rte_restreturn ret; } +/** +* Copy bytes from one location to another. The locations must not overlap. +* +* @param dst +* Pointer to the destination of the data. +* @param src +* Pointer to the source data. +* @param n +* Number of bytes to copy. +* @return +* Pointer to the destination data. +*/ static __rte_always_inline void * rte_memcpy(void *__rte_restrict dst, const void *__rte_restrict src, size_t n){
lib/eal/x86/include/rte_memcpy.h +1
-0@@ -707,15 +707,39 @@ rte_memcpy(void *__rte_restrict dst, const void *__rte_restrict src, size_t n)#endif return dst; } +/* Common way for small copy size of 64-byte blocks. Unlikely, so constant size only */
lib/eal/x86/include/rte_memcpy.h +1
-0+ if (__rte_constant(n) && (n & 63) == 0 && n <=
Quoted 1 line
RTE_MEMCPY_BLOCK_64_MAX) {
You probably need a check (static_assert?) that RTE_MEMCPY_BLOCK_64_MAX is Within allowed values (<= 512+256+128+64).
Otherwise code block below might not be enough to copy everything.
Quoted 41 lines
lib/eal/x86/include/rte_memcpy.h +23
-0+void *ret = dst; + +if (n &512 ) { +rte_mov256 ((uint8_t *)dst +0 *256 , (const uint8_t *)src + 0 * 256); +rte_mov256 ((uint8_t *)dst +1 *256 , (const uint8_t *)src + 1 * 256); + } +if (n &256 ) { +rte_mov256 ((uint8_t *)dst, (const uint8_t *)src); + src = (const uint8_t *)src +256 ; + dst = (uint8_t *)dst +256 ; + } +if (n &128 ) { +rte_mov128 ((uint8_t *)dst, (const uint8_t *)src); + src = (const uint8_t *)src +128 ; + dst = (uint8_t *)dst +128 ; + } +if (n &64 ) +rte_mov64 ((uint8_t *)dst, (const uint8_t *)src); + +return ret; + }/* Implementation for size > 64 bytes depends on alignment with vector register size. */
lib/eal/x86/include/rte_memcpy.h +3
-3-if (!(((uintptr_t )dst | (uintptr_t )src) &ALIGNMENT_MASK )) +if (!(((uintptr_t )dst | (uintptr_t )src) &RTE_MEMCPY_ALIGNMENT_MASK ))return rte_memcpy_aligned_more_than_64 (dst, src, n);else return rte_memcpy_generic_more_than_64 (dst, src, n); } -#undef ALIGNMENT_MASK +#undef RTE_MEMCPY_ALIGNMENT_MASK +#undef RTE_MEMCPY_BLOCK_64_MAX #ifdef __cplusplus } --2.43.0
Quoted 82 lines
From: Konstantin Ananyev [mailto:[email protected]]
Sent: Wednesday, 5 August 2026 19.10Quoted 1 line
The implementation for copying 64-byte blocks up to 512 (or 256)
bytes
Quoted 1 line
does not depend on address alignment with the size of the CPU's
vector
Quoted 4 lines
registers, but is implemented in both unaligned and aligned copy functions.
The mainrte_memcpy()function was updated, so
if the copy size is known at compile time and the other criteriamatch,
Quoted 3 lines
the copy is performed without checking alignment requirements. This provides two benefits when the optimization comes into play:
1. A performance gain, because the address alignment check isavoided.
Quoted 8 lines
3. Reduced instruction memory footprint, because the compiler only generates one instance of the function for copying, instead of two instances (one in the unaligned copy function, and one in the aligned copy function).
Furthermore, the temporary alignment mask definition (
ALIGNMENT_MASK) was prefixed byRTE_MEMCPY_to prevent potential namespace collision.Quoted 8 lines
And finally, the superfluous function declaration at the top of the file was removed, and its description was moved to the function definition.
This improves search results with source code browsers.Signed-off-by Morten Brørup <[email protected]>--- lib/eal/x86/include/rte_memcpy.h | 64 ++++++++++++++++++++++----------
lib/eal/x86/include/rte_memcpy.h extern "C" { · line 36
Quoted 13 lines
1 file changed, 44 insertions(+), 20 deletions(-)lib/eal/x86/include/rte_memcpy.h +0
-2@@ -32,21 +32,6 @@ extern "C" {#define RTE_MEMCPY_AVX #endif -/** -* Copy bytes from one location to another. The locations must not overlap.
lib/eal/x86/include/rte_memcpy.h extern "C" {
Quoted 12 lines
lib/eal/x86/include/rte_memcpy.h +0
-12-* -* @param dst -* Pointer to the destination of the data. -* @param src -* Pointer to the source data. -* @param n -* Number of bytes to copy. -* @return -* Pointer to the destination data. -*/ -static __rte_always_inline void * -rte_memcpy(void *__rte_restrict dst, const void *__rte_restrict src,
size_tn);lib/eal/x86/include/rte_memcpy.h rte_mov256(uint8_t *__rte_restrict dst, const
Quoted 5 lines
lib/eal/x86/include/rte_memcpy.h +0
-1-/** * Copy bytes from one location to another, * locations must not overlap. @@ -187,7 +172,8 @@ rte_mov256(uint8_t *__rte_restrict dst, const
uint8_tlib/eal/x86/include/rte_memcpy.h rte_memcpy_generic_more_than_64(void
Quoted 11 lines
lib/eal/x86/include/rte_memcpy.h +2
-1*__rte_restrict src) * AVX512 implementation below */ -#define ALIGNMENT_MASK 0x3F +#define RTE_MEMCPY_ALIGNMENT_MASK 0x3F +#define RTE_MEMCPY_BLOCK_64_MAX 512/** * Copy 128-byte blocks from one location to another,
lib/eal/x86/include/rte_memcpy.h +0
-0@@ -333,7 +319,8 @@ rte_memcpy_generic_more_than_64(void
*__rte_restrictQuoted 4 lines
dst, const void
*__rte_rest
* AVX implementation below
*/
Quoted 6 lines
lib/eal/x86/include/rte_memcpy.h rte_memcpy_generic_more_than_64(void *__rte_restrict dst, const void *__rte_rest · line 323
Quoted 3 lines
lib/eal/x86/include/rte_memcpy.h +2
-1-#define ALIGNMENT_MASK 0x1F +#define RTE_MEMCPY_ALIGNMENT_MASK 0x1F +#define RTE_MEMCPY_BLOCK_64_MAX 256Wonder why
BLOCK_64_MAXis 512 for SSE and AVX512, but 256 for AVX2? Some empirical data or ...?
I wonder too.
Intel wrote it that way.
I considered consolidating on 512 for simplicity.
But then I would be changing the algorithm without any data to support the change.
Now you tickled my curiosity, so I went hunting...
It was 512 until DPDK 16.04, but in 16.07 it was changed to 256 with this patch:
https://github.com/DPDK/dpdk/commit/4b42e90ef0e421dc777f2b2e377eb237cd3675fa
Quoted 39 lines
lib/eal/x86/include/rte_memcpy.h rte_memcpy_generic_more_than_64(void
Quoted 5 lines
/**
* Copy 128-byte blocks from one location to another,lib/eal/x86/include/rte_memcpy.h +0
-0@@ -444,7 +431,8 @@ rte_memcpy_generic_more_than_64(void
*__rte_restrictlib/eal/x86/include/rte_memcpy.h rte_memcpy_generic_more_than_64(void *__rte_restrict dst, const void *__rte_rest
Quoted 10 lines
dst, const void
*__rte_rest
* SSE implementation below
*/lib/eal/x86/include/rte_memcpy.h +2
-1-#define ALIGNMENT_MASK 0x0F +#define RTE_MEMCPY_ALIGNMENT_MASK 0x0F +#define RTE_MEMCPY_BLOCK_64_MAX 512/** * Macro for copying unaligned block from one location to another with
lib/eal/x86/include/rte_memcpy.h rte_memcpy_aligned_more_than_64(void · line 666
Quoted 8 lines
constant load offset,
lib/eal/x86/include/rte_memcpy.h +2
-0@@ -673,6 +661,18 @@ rte_memcpy_aligned_more_than_64(void *__rte_restrict dst, const void *__rte_restreturn ret; } +/** +* Copy bytes from one location to another. The locations must not overlap.
lib/eal/x86/include/rte_memcpy.h rte_memcpy_aligned_more_than_64(void *__rte_restrict dst, const void *__rte_rest
Quoted 12 lines
lib/eal/x86/include/rte_memcpy.h +10
-0+* +* @param dst +* Pointer to the destination of the data. +* @param src +* Pointer to the source data. +* @param n +* Number of bytes to copy. +* @return +* Pointer to the destination data. +*/ static __rte_always_inline void * rte_memcpy(void *__rte_restrict dst, const void *__rte_restrict src,
size_tn)
Quoted 15 lines
Quoted 10 lines
{
lib/eal/x86/include/rte_memcpy.h +1
-0@@ -707,15 +707,39 @@ rte_memcpy(void *__rte_restrict dst, const void *__rte_restrict src, size_t n)#endif return dst; } +/* Common way for small copy size of 64-byte blocks. Unlikely, so constant size only */
lib/eal/x86/include/rte_memcpy.h +1
-0+ if (__rte_constant(n) && (n & 63) == 0 && n <=
RTE_MEMCPY_BLOCK_64_MAX) {You probably need a check (
static_assert?) thatRTE_MEMCPY_BLOCK_64_MAXis
Within allowed values (<= 512+256+128+64).
Otherwise code block below might not be enough to copy everything.
Allowed values stop at 512. Note that src and dst are not incremented for 512.
I would hope that someone changing the RTE_MEMCPY_BLOCK_64_MAX definition (or introducing a new value if support for a new vector register length is added) doesn't do it without considering what it is used for. A static_assert seems overkill here.
Quoted 46 lines
lib/eal/x86/include/rte_memcpy.h rte_memcpy(void *__rte_restrict dst, const void *__rte_restrict src, size_t n)
Quoted 5 lines
lib/eal/x86/include/rte_memcpy.h +4
-0+void *ret = dst; + +if (n &512 ) { + rte_mov256((uint8_t *)dst + 0 * 256, (const uint8_t*)src
lib/eal/x86/include/rte_memcpy.h
Quoted 2 lines
+ 0 * 256);
lib/eal/x86/include/rte_memcpy.h +1
-0+ rte_mov256((uint8_t *)dst + 1 * 256, (const uint8_t*)src
Quoted 9 lines
+ 1 * 256);
lib/eal/x86/include/rte_memcpy.h +8
-0+ } +if (n &256 ) { +rte_mov256 ((uint8_t *)dst, (const uint8_t *)src); + src = (const uint8_t *)src +256 ; + dst = (uint8_t *)dst +256 ; + } +if (n &128 ) { +rte_mov128 ((uint8_t *)dst, (const uint8_t *)src);lib/eal/x86/include/rte_memcpy.h rte_memcpy(void *__rte_restrict dst, const void *__rte_restrict src, size_t n)
Quoted 10 lines
lib/eal/x86/include/rte_memcpy.h +8
-0+ src = (const uint8_t *)src +128 ; + dst = (uint8_t *)dst +128 ; + } +if (n &64 ) +rte_mov64 ((uint8_t *)dst, (const uint8_t *)src); + +return ret; + }/* Implementation for size > 64 bytes depends on alignment with vector
lib/eal/x86/include/rte_memcpy.h
Quoted 3 lines
register size. */
lib/eal/x86/include/rte_memcpy.h +1
-1-if (!(((uintptr_t )dst | (uintptr_t )src) &ALIGNMENT_MASK )) + if (!(((uintptr_t)dst | (uintptr_t)src) &
RTE_MEMCPY_ALIGNMENT_MASK))Quoted 13 lines
lib/eal/x86/include/rte_memcpy.h +2
-2return rte_memcpy_aligned_more_than_64 (dst, src, n); else return rte_memcpy_generic_more_than_64(dst, src, n); } -#undef ALIGNMENT_MASK +#undef RTE_MEMCPY_ALIGNMENT_MASK +#undef RTE_MEMCPY_BLOCK_64_MAX #ifdef __cplusplus } --2.43.0
Quoted 94 lines
Quoted 81 lines
Quoted 3 lines
The implementation for copying 64-byte blocks up to 512 (or 256)
bytes
Quoted 1 line
does not depend on address alignment with the size of the CPU's
vector
Quoted 4 lines
registers, but is implemented in both unaligned and aligned copy functions.
The mainrte_memcpy()function was updated, so
if the copy size is known at compile time and the other criteriamatch,
Quoted 3 lines
the copy is performed without checking alignment requirements. This provides two benefits when the optimization comes into play:
1. A performance gain, because the address alignment check isavoided.
Quoted 8 lines
3. Reduced instruction memory footprint, because the compiler only generates one instance of the function for copying, instead of two instances (one in the unaligned copy function, and one in the aligned copy function).
Furthermore, the temporary alignment mask definition (
ALIGNMENT_MASK) was prefixed byRTE_MEMCPY_to prevent potential namespace collision.Quoted 8 lines
And finally, the superfluous function declaration at the top of the file was removed, and its description was moved to the function definition.
This improves search results with source code browsers.Signed-off-by Morten Brørup <[email protected]>--- lib/eal/x86/include/rte_memcpy.h | 64 ++++++++++++++++++++++----------
lib/eal/x86/include/rte_memcpy.h extern "C" { · line 36
Quoted 13 lines
1 file changed, 44 insertions(+), 20 deletions(-)lib/eal/x86/include/rte_memcpy.h +0
-2@@ -32,21 +32,6 @@ extern "C" {#define RTE_MEMCPY_AVX #endif -/** -* Copy bytes from one location to another. The locations must not overlap.
lib/eal/x86/include/rte_memcpy.h extern "C" {
Quoted 12 lines
lib/eal/x86/include/rte_memcpy.h +0
-12-* -* @param dst -* Pointer to the destination of the data. -* @param src -* Pointer to the source data. -* @param n -* Number of bytes to copy. -* @return -* Pointer to the destination data. -*/ -static __rte_always_inline void * -rte_memcpy(void *__rte_restrict dst, const void *__rte_restrict src,
size_tn);lib/eal/x86/include/rte_memcpy.h rte_mov256(uint8_t *__rte_restrict dst, const
Quoted 5 lines
lib/eal/x86/include/rte_memcpy.h +0
-1-/** * Copy bytes from one location to another, * locations must not overlap. @@ -187,7 +172,8 @@ rte_mov256(uint8_t *__rte_restrict dst, const
uint8_tlib/eal/x86/include/rte_memcpy.h rte_memcpy_generic_more_than_64(void
Quoted 11 lines
lib/eal/x86/include/rte_memcpy.h +2
-1*__rte_restrict src) * AVX512 implementation below */ -#define ALIGNMENT_MASK 0x3F +#define RTE_MEMCPY_ALIGNMENT_MASK 0x3F +#define RTE_MEMCPY_BLOCK_64_MAX 512/** * Copy 128-byte blocks from one location to another,
lib/eal/x86/include/rte_memcpy.h +0
-0@@ -333,7 +319,8 @@ rte_memcpy_generic_more_than_64(void
*__rte_restrictQuoted 4 lines
dst, const void
*__rte_rest
* AVX implementation below
*/Quoted 6 lines
lib/eal/x86/include/rte_memcpy.h rte_memcpy_generic_more_than_64(void *__rte_restrict dst, const void *__rte_rest · line 323
Quoted 3 lines
lib/eal/x86/include/rte_memcpy.h +2
-1-#define ALIGNMENT_MASK 0x1F +#define RTE_MEMCPY_ALIGNMENT_MASK 0x1F +#define RTE_MEMCPY_BLOCK_64_MAX 256Wonder why
BLOCK_64_MAXis 512 for SSE and AVX512, but 256 for AVX2? Some empirical data or ...?I wonder too.
Intel wrote it that way.
I considered consolidating on 512 for simplicity.
But then I would be changing the algorithm without any data to support the change.
Quoted 4 lines
Now you tickled my curiosity, so I went hunting...
It was 512 until DPDK 16.04, but in 16.07 it was changed to 256 with this patch:
https://github.com/DPDK/dpdk/commit/4b42e90ef0e421dc777f2b2e377eb237cd
3675fa
Interesting, so you just followed the logic in various rte_memcpy_generic_more_than_64() Implementations, right?
Quoted 55 lines
Quoted 39 lines
lib/eal/x86/include/rte_memcpy.h rte_memcpy_generic_more_than_64(void
Quoted 5 lines
/**
* Copy 128-byte blocks from one location to another,lib/eal/x86/include/rte_memcpy.h +0
-0@@ -444,7 +431,8 @@ rte_memcpy_generic_more_than_64(void
*__rte_restrictlib/eal/x86/include/rte_memcpy.h rte_memcpy_generic_more_than_64(void *__rte_restrict dst, const void *__rte_rest
Quoted 10 lines
dst, const void
*__rte_rest
* SSE implementation below
*/lib/eal/x86/include/rte_memcpy.h +2
-1-#define ALIGNMENT_MASK 0x0F +#define RTE_MEMCPY_ALIGNMENT_MASK 0x0F +#define RTE_MEMCPY_BLOCK_64_MAX 512/** * Macro for copying unaligned block from one location to another with
lib/eal/x86/include/rte_memcpy.h rte_memcpy_aligned_more_than_64(void · line 666
Quoted 8 lines
constant load offset,
lib/eal/x86/include/rte_memcpy.h +2
-0@@ -673,6 +661,18 @@ rte_memcpy_aligned_more_than_64(void *__rte_restrict dst, const void *__rte_restreturn ret; } +/** +* Copy bytes from one location to another. The locations must not overlap.
lib/eal/x86/include/rte_memcpy.h rte_memcpy_aligned_more_than_64(void *__rte_restrict dst, const void *__rte_rest
Quoted 12 lines
lib/eal/x86/include/rte_memcpy.h +10
-0+* +* @param dst +* Pointer to the destination of the data. +* @param src +* Pointer to the source data. +* @param n +* Number of bytes to copy. +* @return +* Pointer to the destination data. +*/ static __rte_always_inline void * rte_memcpy(void *__rte_restrict dst, const void *__rte_restrict src,
size_tn)Quoted 15 lines
Quoted 10 lines
{
lib/eal/x86/include/rte_memcpy.h +1
-0@@ -707,15 +707,39 @@ rte_memcpy(void *__rte_restrict dst, const void *__rte_restrict src, size_t n)#endif return dst; } +/* Common way for small copy size of 64-byte blocks. Unlikely, so constant size only */
lib/eal/x86/include/rte_memcpy.h +1
-0+ if (__rte_constant(n) && (n & 63) == 0 && n <=
RTE_MEMCPY_BLOCK_64_MAX) {You probably need a check (
static_assert?) thatRTE_MEMCPY_BLOCK_64_MAXis
Within allowed values (<= 512+256+128+64).
Otherwise code block below might not be enough to copy everything.
Quoted 1 line
Allowed values stop at 512. Note that src and dst are not incremented for 512.
Then it should be 'return' here no?
Or 'else if ...' after it.
From other side, with current code 0x180 and 0x1c0 look like a perfectly valid values for it.
Quoted 3 lines
I would hope that someone changing the
RTE_MEMCPY_BLOCK_64_MAXdefinition (or introducing a new value if support for a new vector register length is added) doesn't do it without considering what it is used for.
That's exactly the reason why I think it needs either to be documented (add comment) or self-guarded at compilation time (static_assert, RTE_BUILD_BUG_ON, some macro, erc.). BTW, curious - what is wrong with static_assert() on it?
Quoted 48 lines
A static_assert[] seems overkill here.
Quoted 46 lines
lib/eal/x86/include/rte_memcpy.h rte_memcpy(void *__rte_restrict dst, const void *__rte_restrict src, size_t n)
Quoted 5 lines
lib/eal/x86/include/rte_memcpy.h +4
-0+void *ret = dst; + +if (n &512 ) { + rte_mov256((uint8_t *)dst + 0 * 256, (const uint8_t*)src
lib/eal/x86/include/rte_memcpy.h
Quoted 2 lines
+ 0 * 256);
lib/eal/x86/include/rte_memcpy.h +1
-0+ rte_mov256((uint8_t *)dst + 1 * 256, (const uint8_t*)src
Quoted 9 lines
+ 1 * 256);
lib/eal/x86/include/rte_memcpy.h +8
-0+ } +if (n &256 ) { +rte_mov256 ((uint8_t *)dst, (const uint8_t *)src); + src = (const uint8_t *)src +256 ; + dst = (uint8_t *)dst +256 ; + } +if (n &128 ) { +rte_mov128 ((uint8_t *)dst, (const uint8_t *)src);lib/eal/x86/include/rte_memcpy.h rte_memcpy(void *__rte_restrict dst, const void *__rte_restrict src, size_t n)
Quoted 10 lines
lib/eal/x86/include/rte_memcpy.h +8
-0+ src = (const uint8_t *)src +128 ; + dst = (uint8_t *)dst +128 ; + } +if (n &64 ) +rte_mov64 ((uint8_t *)dst, (const uint8_t *)src); + +return ret; + }/* Implementation for size > 64 bytes depends on alignment with vector
lib/eal/x86/include/rte_memcpy.h
Quoted 3 lines
register size. */
lib/eal/x86/include/rte_memcpy.h +1
-1-if (!(((uintptr_t )dst | (uintptr_t )src) &ALIGNMENT_MASK )) + if (!(((uintptr_t)dst | (uintptr_t)src) &
RTE_MEMCPY_ALIGNMENT_MASK))Quoted 13 lines
lib/eal/x86/include/rte_memcpy.h +2
-2return rte_memcpy_aligned_more_than_64 (dst, src, n); else return rte_memcpy_generic_more_than_64(dst, src, n); } -#undef ALIGNMENT_MASK +#undef RTE_MEMCPY_ALIGNMENT_MASK +#undef RTE_MEMCPY_BLOCK_64_MAX #ifdef __cplusplus } --2.43.0
Quoted 108 lines
From: Konstantin Ananyev [mailto:[email protected]]
Sent: Thursday, 6 August 2026 09.44Quoted 8 lines
Quoted 8 lines
Quoted 1 line
The implementation for copying 64-byte blocks up to 512 (or 256)
bytes
Quoted 1 line
does not depend on address alignment with the size of the CPU's
vector
Quoted 4 lines
registers, but is implemented in both unaligned and aligned copy functions.
The mainrte_memcpy()function was updated, so
if the copy size is known at compile time and the other criteriaQuoted 6 lines
Quoted 6 lines
match,
Quoted 3 lines
the copy is performed without checking alignment requirements. This provides two benefits when the optimization comes into play:
1. A performance gain, because the address alignment check isavoided.
Quoted 1 line
3. Reduced instruction memory footprint, because the compiler
only
Quoted 1 line
Quoted 1 line
Quoted 1 line
generates one instance of the function for copying, instead of
two
Quoted 1 line
Quoted 1 line
Quoted 1 line
instances (one in the unaligned copy function, and one in the
aligned
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
copy function).
Furthermore, the temporary alignment mask definition
(
ALIGNMENT_MASK)Quoted 1 line
Quoted 1 line
Quoted 1 line
was prefixed by
RTE_MEMCPY_to prevent potential namespacecollision.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
And finally, the superfluous function declaration at the top of
the
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
file was removed, and its description was moved to the function definition.
This improves search results with source code browsers.Signed-off-by Morten Brørup <[email protected]>--- lib/eal/x86/include/rte_memcpy.h | 64 ++++++++++++++++++++++--------
Quoted 12 lines
Quoted 12 lines
--
Quoted 11 lines
1 file changed, 44 insertions(+), 20 deletions(-)lib/eal/x86/include/rte_memcpy.h +0
-0@@ -32,21 +32,6 @@ extern "C" {#define RTE_MEMCPY_AVX #endif Quoted 2 lines
Quoted 2 lines
lib/eal/x86/include/rte_memcpy.h extern "C" { · line 36
Quoted 2 lines
lib/eal/x86/include/rte_memcpy.h +0
-2-/** -* Copy bytes from one location to another. The locations must not
Quoted 13 lines
Quoted 13 lines
overlap.
lib/eal/x86/include/rte_memcpy.h extern "C" {
Quoted 12 lines
lib/eal/x86/include/rte_memcpy.h +0
-12-* -* @param dst -* Pointer to the destination of the data. -* @param src -* Pointer to the source data. -* @param n -* Number of bytes to copy. -* @return -* Pointer to the destination data. -*/ -static __rte_always_inline void * -rte_memcpy(void *__rte_restrict dst, const void *__rte_restrictsrc,
Quoted 23 lines
Quoted 23 lines
size_tn);lib/eal/x86/include/rte_memcpy.h rte_mov256(uint8_t *__rte_restrict dst, const
Quoted 5 lines
lib/eal/x86/include/rte_memcpy.h +0
-1-/** * Copy bytes from one location to another, * locations must not overlap. @@ -187,7 +172,8 @@ rte_mov256(uint8_t *__rte_restrict dst, const
uint8_tlib/eal/x86/include/rte_memcpy.h rte_memcpy_generic_more_than_64(void
Quoted 11 lines
lib/eal/x86/include/rte_memcpy.h +2
-1*__rte_restrict src) * AVX512 implementation below */ -#define ALIGNMENT_MASK 0x3F +#define RTE_MEMCPY_ALIGNMENT_MASK 0x3F +#define RTE_MEMCPY_BLOCK_64_MAX 512/** * Copy 128-byte blocks from one location to another,
lib/eal/x86/include/rte_memcpy.h +0
-0@@ -333,7 +319,8 @@ rte_memcpy_generic_more_than_64(void
*__rte_restrictQuoted 4 lines
dst, const void
*__rte_rest
* AVX implementation below
*/Quoted 5 lines
Quoted 5 lines
lib/eal/x86/include/rte_memcpy.h rte_memcpy_generic_more_than_64(void *__rte_restrict dst, const void *__rte_rest · line 323
Quoted 3 lines
lib/eal/x86/include/rte_memcpy.h +2
-1-#define ALIGNMENT_MASK 0x1F +#define RTE_MEMCPY_ALIGNMENT_MASK 0x1F +#define RTE_MEMCPY_BLOCK_64_MAX 256Wonder why
BLOCK_64_MAXis 512 for SSE and AVX512, but 256 forAVX2?
Quoted 6 lines
Quoted 1 line
Some empirical data or ...?
I wonder too.
Intel wrote it that way.
I considered consolidating on 512 for simplicity. But then I would be changing the algorithm without any data tosupport the
Quoted 4 lines
change.
Now you tickled my curiosity, so I went hunting...
It was 512 until DPDK 16.04, but in 16.07 it was changed to 256 with
Quoted 8 lines
this patch:
Quoted 1 line
https://github.com/DPDK/dpdk/commit/4b42e90ef0e421dc777f2b2e377eb237cd
Quoted 1 line
3675fa
Interesting, so you just followed the logic in various
rte_memcpy_generic_more_than_64()Implementations, right?
Yes.
And rte_memcpy_aligned_more_than_64().
When copying blocks of 64 bytes up to 512 (or 256) bytes, all code paths (3 generic vector variants and the aligned variant) do exactly the same. So I consolidated that into one code path, and avoid the address alignment check.
And because I consider it unlikely that rte_memcpy() is called with a size that matches the criteria, I limited it to size known at compile time.
Quoted 62 lines
Quoted 11 lines
Quoted 11 lines
lib/eal/x86/include/rte_memcpy.h rte_memcpy_generic_more_than_64(void
Quoted 6 lines
/**
* Copy 128-byte blocks from one location to another,lib/eal/x86/include/rte_memcpy.h +0
-0@@ -444,7 +431,8 @@ rte_memcpy_generic_more_than_64(void
*__rte_restrictQuoted 4 lines
dst, const void
*__rte_rest
* SSE implementation below
*/Quoted 6 lines
Quoted 6 lines
lib/eal/x86/include/rte_memcpy.h rte_memcpy_generic_more_than_64(void *__rte_restrict dst, const void *__rte_rest
Quoted 6 lines
lib/eal/x86/include/rte_memcpy.h +2
-1-#define ALIGNMENT_MASK 0x0F +#define RTE_MEMCPY_ALIGNMENT_MASK 0x0F +#define RTE_MEMCPY_BLOCK_64_MAX 512/** * Macro for copying unaligned block from one location to another
Quoted 9 lines
Quoted 9 lines
with
lib/eal/x86/include/rte_memcpy.h rte_memcpy_aligned_more_than_64(void · line 666
Quoted 8 lines
constant load offset,
lib/eal/x86/include/rte_memcpy.h +2
-0@@ -673,6 +661,18 @@ rte_memcpy_aligned_more_than_64(void *__rte_restrict dst, const void *__rte_restreturn ret; } +/** +* Copy bytes from one location to another. The locations must not
Quoted 13 lines
Quoted 13 lines
overlap.
Quoted 12 lines
lib/eal/x86/include/rte_memcpy.h +10
-0+* +* @param dst +* Pointer to the destination of the data. +* @param src +* Pointer to the source data. +* @param n +* Number of bytes to copy. +* @return +* Pointer to the destination data. +*/ static __rte_always_inline void * rte_memcpy(void *__rte_restrict dst, const void *__rte_restrictsrc,
Quoted 3 lines
Quoted 3 lines
size_tn)lib/eal/x86/include/rte_memcpy.h rte_memcpy(void *__rte_restrict dst, const
Quoted 2 lines
{
lib/eal/x86/include/rte_memcpy.h +0
-0@@ -707,15 +707,39 @@ rte_memcpy(void *__rte_restrict dst, constvoid
Quoted 5 lines
Quoted 5 lines
lib/eal/x86/include/rte_memcpy.h rte_memcpy(void *__rte_restrict dst, const void *__rte_restrict src, size_t n)
Quoted 5 lines
lib/eal/x86/include/rte_memcpy.h +1
-0*__rte_restrict src, size_t n)#endif return dst; } +/* Common way for small copy size of 64-byte blocks. Unlikely, so
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
constant size only */
lib/eal/x86/include/rte_memcpy.h +1
-0+ if (__rte_constant(n) && (n & 63) == 0 && n <=
RTE_MEMCPY_BLOCK_64_MAX) {You probably need a check (
static_assert?) that
RTE_MEMCPY_BLOCK_64_MAXQuoted 4 lines
Quoted 3 lines
is
Within allowed values (<= 512+256+128+64).
Otherwise code block below might not be enough to copy everything.
Quoted 5 lines
Quoted 1 line
Allowed values stop at 512. Note that src and dst are not incremented
for 512.
Then it should be 'return' here no?
Or 'else if ...' after it.
Not needed.
With n=512, the compiler knows that the other conditions (n & 256, 128, 64) are false, and doesn't emit code for it.
Quoted 5 lines
From other side, with current code
0x180and0x1c0look like a perfectly valid values for it.Quoted 2 lines
I would hope that someone changing the
RTE_MEMCPY_BLOCK_64_MAXdefinition (or introducing a new value if support for a new vector
Quoted 8 lines
register length
Quoted 1 line
is added) doesn't do it without considering what it is used for.
That's exactly the reason why I think it needs either to be documented (add comment)
or self-guarded at compilation time (static_assert,RTE_BUILD_BUG_ON, some macro, erc.).
BTW, curious - what is wrong withstatic_assert()on it?
Nothing wrong with static_assert(); I just think it is superfluous.
Going back to your question about the need for "return" or "else if", you convinced me now... I'll add the return for code readability purposes and a static_assert() for safety.
Quoted 55 lines
Quoted 8 lines
A static_assert[] seems overkill here.
Quoted 5 lines
lib/eal/x86/include/rte_memcpy.h rte_memcpy(void *__rte_restrict dst, const void *__rte_restrict src, size_t n)
Quoted 5 lines
lib/eal/x86/include/rte_memcpy.h +4
-0+void *ret = dst; + +if (n &512 ) { + rte_mov256((uint8_t *)dst + 0 * 256, (const
uint8_tQuoted 3 lines
Quoted 3 lines
*)src
lib/eal/x86/include/rte_memcpy.h
Quoted 2 lines
+ 0 * 256);
lib/eal/x86/include/rte_memcpy.h +1
-0+ rte_mov256((uint8_t *)dst + 1 * 256, (const
uint8_tQuoted 5 lines
Quoted 5 lines
*)src
lib/eal/x86/include/rte_memcpy.h rte_memcpy(void *__rte_restrict dst, const void *__rte_restrict src, size_t n)
Quoted 4 lines
+ 1 * 256);
lib/eal/x86/include/rte_memcpy.h +3
-0+ } +if (n &256 ) { + rte_mov256((uint8_t *)dst, (const uint8_t*)src);
Quoted 5 lines
Quoted 5 lines
lib/eal/x86/include/rte_memcpy.h rte_memcpy(void *__rte_restrict dst, const void *__rte_restrict src, size_t n)
Quoted 5 lines
lib/eal/x86/include/rte_memcpy.h +5
-0+ src = (const uint8_t *)src +256 ; + dst = (uint8_t *)dst +256 ; + } +if (n &128 ) { + rte_mov128((uint8_t *)dst, (const uint8_t*)src);
Quoted 5 lines
Quoted 5 lines
lib/eal/x86/include/rte_memcpy.h rte_memcpy(void *__rte_restrict dst, const void *__rte_restrict src, size_t n)
Quoted 5 lines
lib/eal/x86/include/rte_memcpy.h +5
-0+ src = (const uint8_t *)src +128 ; + dst = (uint8_t *)dst +128 ; + } +if (n &64 ) + rte_mov64((uint8_t *)dst, (const uint8_t*)src);
Quoted 5 lines
Quoted 5 lines
lib/eal/x86/include/rte_memcpy.h rte_memcpy(void *__rte_restrict dst, const void *__rte_restrict src, size_t n)
Quoted 5 lines
lib/eal/x86/include/rte_memcpy.h +3
-0+ +return ret; + }/* Implementation for size > 64 bytes depends on alignment with
Quoted 18 lines
Quoted 18 lines
vector
lib/eal/x86/include/rte_memcpy.h
Quoted 3 lines
register size. */
lib/eal/x86/include/rte_memcpy.h +1
-1-if (!(((uintptr_t )dst | (uintptr_t )src) &ALIGNMENT_MASK )) + if (!(((uintptr_t)dst | (uintptr_t)src) &
RTE_MEMCPY_ALIGNMENT_MASK))Quoted 13 lines
lib/eal/x86/include/rte_memcpy.h +2
-2return rte_memcpy_aligned_more_than_64 (dst, src, n); else return rte_memcpy_generic_more_than_64(dst, src, n); } -#undef ALIGNMENT_MASK +#undef RTE_MEMCPY_ALIGNMENT_MASK +#undef RTE_MEMCPY_BLOCK_64_MAX #ifdef __cplusplus } --2.43.0
PATCH v2 1/1 eal/x86: optimize memcpy of small 64-byte blocks
In reply to Morten BrørupThe implementation for copying 64-byte blocks up to 512 (or 256) bytes does not depend on address alignment with the size of the CPU's vector registers, but is implemented in both unaligned and aligned copy functions.
The main rte_memcpy() function was updated, so
if the copy size is known at compile time and the other criteria match, the copy is performed without checking alignment requirements. This provides two benefits when the optimization comes into play:
1. A performance gain, because the address alignment check is avoided.
2. Reduced instruction memory footprint, because the compiler only generates one instance of the function for copying, instead of two instances (one in the unaligned copy function, and one in the aligned copy function).
Furthermore, the temporary alignment mask definition (ALIGNMENT_MASK) was prefixed by RTE_MEMCPY_ to prevent potential namespace collision.
And finally, the superfluous function declaration at the top of the file was removed, and its description was moved to the function definition.
This improves search results with source code browsers.
---
v2:
* Fixed numbering in patch description; after 1 comes 2, not 3. (AI)
* Improved code readability by changing (n & 512) to (n == 512), adding return dst, and using if-else. (Konstantin)
* Added static_assert() to prevent future new or increased RTE_MEMCPY_BLOCK_64_MAX not being handled correctly. (Konstantin)
--- lib/eal/x86/include/rte_memcpy.h | 68 ++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 20 deletions(-)
lib/eal/x86/include/rte_memcpy.h +48 -20
@@ -32,21 +32,6 @@ extern "C" {#define RTE_MEMCPY_AVX #endif -/** -* Copy bytes from one location to another. The locations must not overlap. -* -* @param dst -* Pointer to the destination of the data. -* @param src -* Pointer to the source data. -* @param n -* Number of bytes to copy. -* @return -* Pointer to the destination data. -*/ -static __rte_always_inline void * -rte_memcpy(void *__rte_restrict dst, const void *__rte_restrict src, size_t n); -/** * Copy bytes from one location to another, * locations must not overlap.
@@ -187,7 +172,8 @@ rte_mov256(uint8_t *__rte_restrict dst, const uint8_t *__rte_restrict src)* AVX512 implementation below */ -#define ALIGNMENT_MASK 0x3F +#define RTE_MEMCPY_ALIGNMENT_MASK 0x3F +#define RTE_MEMCPY_BLOCK_64_MAX 512/** * Copy 128-byte blocks from one location to another,
@@ -333,7 +319,8 @@ rte_memcpy_generic_more_than_64(void *__rte_restrict dst, const void *__rte_rest* AVX implementation below */ -#define ALIGNMENT_MASK 0x1F +#define RTE_MEMCPY_ALIGNMENT_MASK 0x1F +#define RTE_MEMCPY_BLOCK_64_MAX 256/** * Copy 128-byte blocks from one location to another,
@@ -444,7 +431,8 @@ rte_memcpy_generic_more_than_64(void *__rte_restrict dst, const void *__rte_rest* SSE implementation below */ -#define ALIGNMENT_MASK 0x0F +#define RTE_MEMCPY_ALIGNMENT_MASK 0x0F +#define RTE_MEMCPY_BLOCK_64_MAX 512/** * Macro for copying unaligned block from one location to another with constant load offset,
@@ -673,6 +661,18 @@ rte_memcpy_aligned_more_than_64(void *__rte_restrict dst, const void *__rte_restreturn ret; } +/** +* Copy bytes from one location to another. The locations must not overlap. +* +* @param dst +* Pointer to the destination of the data. +* @param src +* Pointer to the source data. +* @param n +* Number of bytes to copy. +* @return +* Pointer to the destination data. +*/ static __rte_always_inline void * rte_memcpy(void *__rte_restrict dst, const void *__rte_restrict src, size_t n) {
@@ -707,15 +707,43 @@ rte_memcpy(void *__rte_restrict dst, const void *__rte_restrict src, size_t n)#endif return dst; } +/* Common way for small copy size of 64-byte blocks. Unlikely, so constant size only */ +static_assert (RTE_MEMCPY_BLOCK_64_MAX <=512 , +"64-byte block copy max size too big for implementation below" ); +if (__rte_constant (n) && (n &63 ) ==0 && n <=RTE_MEMCPY_BLOCK_64_MAX ) { +if (n ==512 ) { +rte_mov256 ((uint8_t *)dst +0 *256 , (const uint8_t *)src +0 *256 ); +rte_mov256 ((uint8_t *)dst +1 *256 , (const uint8_t *)src +1 *256 ); +return dst; + }else { +void *ret = dst; + +if (n &256 ) { +rte_mov256 ((uint8_t *)dst, (const uint8_t *)src); + src = (const uint8_t *)src +256 ; + dst = (uint8_t *)dst +256 ; + } +if (n &128 ) { +rte_mov128 ((uint8_t *)dst, (const uint8_t *)src); + src = (const uint8_t *)src +128 ; + dst = (uint8_t *)dst +128 ; + } +if (n &64 ) +rte_mov64 ((uint8_t *)dst, (const uint8_t *)src); + +return ret; + } + }/* Implementation for size > 64 bytes depends on alignment with vector register size. */ -if (!(((uintptr_t )dst | (uintptr_t )src) &ALIGNMENT_MASK )) +if (!(((uintptr_t )dst | (uintptr_t )src) &RTE_MEMCPY_ALIGNMENT_MASK ))return rte_memcpy_aligned_more_than_64 (dst, src, n);else return rte_memcpy_generic_more_than_64 (dst, src, n); } -#undef ALIGNMENT_MASK +#undef RTE_MEMCPY_ALIGNMENT_MASK +#undef RTE_MEMCPY_BLOCK_64_MAX #ifdef __cplusplus }
Signature · 1 line
2.43.0