examples: memcpy cleanups
cover examples: memcpy cleanups
Looking at examples and noticed stuff around use
of rte_memcpy. Probably mostly copy/pasted.
Stephen Hemminger (4):
examples/vhost: replace memcpy with assignment examples/vmdq: replace memcpy with structure assignment examples/vmdq_dcb: replace memcpy with assignment
examples: remove unnecessary include
examples/bond/main.c | 1 - examples/ip_fragmentation/main.c | 1 - examples/ip_reassembly/main.c | 1 - examples/ipv4_multicast/main.c | 1 - examples/l2fwd-cat/cat.c | 1 - examples/l2fwd-event/l2fwd_common.h | 1 - examples/l2fwd-jobstats/main.c | 1 - examples/l2fwd-keepalive/main.c | 1 - examples/l2fwd-macsec/main.c | 1 - examples/l2fwd/main.c | 1 - examples/l3fwd-power/main.c | 1 - examples/l3fwd/main.c | 1 - examples/link_status_interrupt/main.c | 1 - .../client_server_mp/mp_server/init.c | 1 - .../client_server_mp/mp_server/main.c | 1 - examples/multi_process/symmetric_mp/main.c | 1 - examples/qos_sched/app_thread.c | 1 - examples/qos_sched/main.c | 1 - examples/server_node_efd/efd_server/init.c | 1 - examples/server_node_efd/efd_server/main.c | 1 - examples/vhost/main.c | 5 ++--- examples/vmdq/main.c | 7 +++---- examples/vmdq_dcb/main.c | 17 +++++++---------- 23 files changed, 12 insertions(+), 37 deletions(-)
Signature · 1 line
2.51.0
PATCH 1/4 examples/vhost: replace memcpy with assignment
Better to use structure assignment to preserve type info.
--- examples/vhost/main.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
examples/vhost/main.c +2 -3
@@ -405,9 +405,8 @@ get_eth_conf(struct rte_eth_conf *eth_conf, uint32_t num_devices) conf.pool_map[i].pools = (1UL << i); } - (void )(rte_memcpy (eth_conf, &vmdq_conf_default,sizeof (*eth_conf))); - (void )(rte_memcpy (ð_conf->rx_adv_conf.vmdq_rx_conf, &conf, -sizeof (eth_conf->rx_adv_conf.vmdq_rx_conf))); + *eth_conf = vmdq_conf_default; + eth_conf->rx_adv_conf.vmdq_rx_conf = conf;return 0 ; }
Signature · 1 line
2.51.0
PATCH 2/4 examples/vmdq: replace memcpy with structure assignment
In reply to Stephen HemmingerBetter to keep type safety and use assignment rather than rte_memcpy.
--- examples/vmdq/main.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
examples/vmdq/main.c +3 -4
@@ -17,7 +17,6 @@#include <rte_common.h> #include <rte_log.h> #include <rte_memory.h> -#include <rte_memcpy.h> #include <rte_eal.h> #include <rte_launch.h> #include <rte_cycles.h>
@@ -151,9 +150,9 @@ get_eth_conf(struct rte_eth_conf *eth_conf, uint32_t num_pools) conf.pool_map[i].pools = (1UL << (i % num_pools)); } - (void )(rte_memcpy (eth_conf, &vmdq_conf_default,sizeof (*eth_conf))); - (void )(rte_memcpy (ð_conf->rx_adv_conf.vmdq_rx_conf, &conf, -sizeof (eth_conf->rx_adv_conf.vmdq_rx_conf))); + *eth_conf = vmdq_conf_default; + eth_conf->rx_adv_conf.vmdq_rx_conf = conf; +if (rss_enable) { eth_conf->rxmode.mq_mode =RTE_ETH_MQ_RX_VMDQ_RSS ; eth_conf->rx_adv_conf.rss_conf.rss_hf = RTE_ETH_RSS_IP |
Signature · 1 line
2.51.0
PATCH 3/4 examples/vmdq_dcb: replace memcpy with assignment
In reply to Stephen HemmingerBetter to use structure assignment rather than memcpy.
--- examples/vmdq_dcb/main.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-)
examples/vmdq_dcb/main.c +7 -10
@@ -17,7 +17,6 @@#include <rte_common.h> #include <rte_log.h> #include <rte_memory.h> -#include <rte_memcpy.h> #include <rte_eal.h> #include <rte_launch.h> #include <rte_cycles.h>
@@ -161,15 +160,13 @@ get_eth_conf(struct rte_eth_conf *eth_conf) tx_conf.dcb_tc[i] = i % num_tcs; } dcb_conf.nb_tcs = (enum rte_eth_nb_tcs )num_tcs; - (void )(rte_memcpy (eth_conf, &vmdq_dcb_conf_default,sizeof (*eth_conf))); - (void )(rte_memcpy (ð_conf->rx_adv_conf.vmdq_dcb_conf, &conf, -sizeof (conf))); - (void )(rte_memcpy (ð_conf->rx_adv_conf.dcb_rx_conf, &dcb_conf, -sizeof (dcb_conf))); - (void )(rte_memcpy (ð_conf->rx_adv_conf.vmdq_rx_conf, &vmdq_conf, -sizeof (vmdq_conf))); - (void )(rte_memcpy (ð_conf->tx_adv_conf.vmdq_dcb_tx_conf, &tx_conf, -sizeof (tx_conf))); + + *eth_conf = vmdq_dcb_conf_default; + eth_conf->rx_adv_conf.vmdq_dcb_conf = conf; + eth_conf->rx_adv_conf.dcb_rx_conf = dcb_conf; + eth_conf->rx_adv_conf.vmdq_rx_conf = vmdq_conf; + eth_conf->tx_adv_conf.vmdq_dcb_tx_conf = tx_conf; +if (rss_enable) { eth_conf->rxmode.mq_mode =RTE_ETH_MQ_RX_VMDQ_DCB_RSS ; eth_conf->rx_adv_conf.rss_conf.rss_hf = RTE_ETH_RSS_IP |
Signature · 1 line
2.51.0
PATCH 4/4 examples: remove unnecessary include
In reply to Stephen HemmingerAll these examples include rte_memcpy.h but do not use that function.
--- examples/bond/main.c | 1 - examples/ip_fragmentation/main.c | 1 - examples/ip_reassembly/main.c | 1 - examples/ipv4_multicast/main.c | 1 - examples/l2fwd-cat/cat.c | 1 - examples/l2fwd-event/l2fwd_common.h | 1 - examples/l2fwd-jobstats/main.c | 1 - examples/l2fwd-keepalive/main.c | 1 - examples/l2fwd-macsec/main.c | 1 - examples/l2fwd/main.c | 1 - examples/l3fwd-power/main.c | 1 - examples/l3fwd/main.c | 1 - examples/link_status_interrupt/main.c | 1 - examples/multi_process/client_server_mp/mp_server/init.c | 1 - examples/multi_process/client_server_mp/mp_server/main.c | 1 - examples/multi_process/symmetric_mp/main.c | 1 - examples/qos_sched/app_thread.c | 1 - examples/qos_sched/main.c | 1 - examples/server_node_efd/efd_server/init.c | 1 - examples/server_node_efd/efd_server/main.c | 1 - 20 files changed, 20 deletions(-)
examples/bond/main.c +0 -1
@@ -21,7 +21,6 @@#include <rte_common.h> #include <rte_log.h> #include <rte_memory.h> -#include <rte_memcpy.h> #include <rte_eal.h> #include <rte_launch.h> #include <rte_cycles.h>
examples/ip_fragmentation/main.c +0 -1
@@ -18,7 +18,6 @@#include <rte_byteorder.h> #include <rte_log.h> #include <rte_memory.h> -#include <rte_memcpy.h> #include <rte_eal.h> #include <rte_launch.h> #include <rte_cycles.h>
examples/ip_reassembly/main.c +0 -1
@@ -19,7 +19,6 @@#include <rte_byteorder.h> #include <rte_log.h> #include <rte_memory.h> -#include <rte_memcpy.h> #include <rte_eal.h> #include <rte_launch.h> #include <rte_cycles.h>
examples/ipv4_multicast/main.c +0 -1
@@ -17,7 +17,6 @@#include <rte_byteorder.h> #include <rte_log.h> #include <rte_memory.h> -#include <rte_memcpy.h> #include <rte_eal.h> #include <rte_launch.h> #include <rte_cycles.h>
examples/l2fwd-cat/cat.c +0 -1
@@ -12,7 +12,6 @@#include <stdio.h> #include <rte_common.h> -#include <rte_memcpy.h> #include <pqos.h>
examples/l2fwd-event/l2fwd_common.h +0 -1
@@ -24,7 +24,6 @@#include <rte_common.h> #include <rte_malloc.h> #include <rte_memory.h> -#include <rte_memcpy.h> #include <rte_eal.h> #include <rte_launch.h> #include <rte_cycles.h>
examples/l2fwd-jobstats/main.c +0 -1
@@ -13,7 +13,6 @@#include <rte_log.h> #include <rte_malloc.h> #include <rte_memory.h> -#include <rte_memcpy.h> #include <rte_eal.h> #include <rte_launch.h> #include <rte_cycles.h>
examples/l2fwd-keepalive/main.c +0 -1
@@ -21,7 +21,6 @@#include <rte_log.h> #include <rte_malloc.h> #include <rte_memory.h> -#include <rte_memcpy.h> #include <rte_eal.h> #include <rte_launch.h> #include <rte_cycles.h>
examples/l2fwd-macsec/main.c +0 -1
@@ -21,7 +21,6 @@#include <rte_log.h> #include <rte_malloc.h> #include <rte_memory.h> -#include <rte_memcpy.h> #include <rte_eal.h> #include <rte_launch.h> #include <rte_cycles.h>
examples/l2fwd/main.c +0 -1
@@ -21,7 +21,6 @@#include <rte_log.h> #include <rte_malloc.h> #include <rte_memory.h> -#include <rte_memcpy.h> #include <rte_eal.h> #include <rte_launch.h> #include <rte_cycles.h>
examples/l3fwd-power/main.c +0 -1
@@ -21,7 +21,6 @@#include <rte_log.h> #include <rte_malloc.h> #include <rte_memory.h> -#include <rte_memcpy.h> #include <rte_eal.h> #include <rte_launch.h> #include <rte_cycles.h>
examples/l3fwd/main.c +0 -1
@@ -22,7 +22,6 @@#include <rte_log.h> #include <rte_malloc.h> #include <rte_memory.h> -#include <rte_memcpy.h> #include <rte_eal.h> #include <rte_launch.h> #include <rte_cycles.h>
examples/link_status_interrupt/main.c +0 -1
@@ -19,7 +19,6 @@#include <rte_log.h> #include <rte_malloc.h> #include <rte_memory.h> -#include <rte_memcpy.h> #include <rte_eal.h> #include <rte_launch.h> #include <rte_cycles.h>
examples/multi_process/client_server_mp/mp_server/init.c +0 -1
@@ -24,7 +24,6 @@#include <rte_ring.h> #include <rte_log.h> #include <rte_mempool.h> -#include <rte_memcpy.h> #include <rte_mbuf.h> #include <rte_interrupts.h> #include <rte_ether.h>
examples/multi_process/client_server_mp/mp_server/main.c +0 -1
@@ -24,7 +24,6 @@#include <rte_log.h> #include <rte_debug.h> #include <rte_mempool.h> -#include <rte_memcpy.h> #include <rte_mbuf.h> #include <rte_ether.h> #include <rte_interrupts.h>
examples/multi_process/symmetric_mp/main.c +0 -1
@@ -37,7 +37,6 @@#include <rte_ether.h> #include <rte_ethdev.h> #include <rte_mempool.h> -#include <rte_memcpy.h> #include <rte_mbuf.h> #include <rte_string_fns.h> #include <rte_cycles.h>
examples/qos_sched/app_thread.c +0 -1
@@ -9,7 +9,6 @@#include <rte_malloc.h> #include <rte_cycles.h> #include <rte_ethdev.h> -#include <rte_memcpy.h> #include <rte_byteorder.h> #include <rte_branch_prediction.h> #include <rte_sched.h>
examples/qos_sched/main.c +0 -1
@@ -10,7 +10,6 @@#include <rte_malloc.h> #include <rte_cycles.h> #include <rte_ethdev.h> -#include <rte_memcpy.h> #include <rte_byteorder.h> #include <rte_branch_prediction.h>
examples/server_node_efd/efd_server/init.c +0 -1
@@ -24,7 +24,6 @@#include <rte_ring.h> #include <rte_log.h> #include <rte_mempool.h> -#include <rte_memcpy.h> #include <rte_mbuf.h> #include <rte_interrupts.h> #include <rte_ether.h>
examples/server_node_efd/efd_server/main.c +0 -1
@@ -26,7 +26,6 @@#include <rte_log.h> #include <rte_debug.h> #include <rte_mempool.h> -#include <rte_memcpy.h> #include <rte_mbuf.h> #include <rte_ether.h> #include <rte_interrupts.h>
Signature · 1 line
2.51.0
Re: [PATCH 4/4] examples: remove unnecessary include
21/01/2026 18:04, Stephen Hemminger:
examples/l2fwd-cat/cat.c line 15
Quoted 7 lines
examples/l2fwd-cat/cat.c +0
-1@@ -12,7 +12,6 @@#include <stdio.h> #include <rte_common.h> -#include <rte_memcpy.h>
It breaks the build.
I add this:
examples/l2fwd-cat/cat.c +1 -0
@@ -10,6 +10,7 @@#include <sched.h> #include <signal.h> #include <stdio.h> +#include <stdlib.h>
Quoted 12 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Wednesday, 21 January 2026 18.05Looking at examples and noticed stuff around use
ofrte_memcpy. Probably mostly copy/pasted.Stephen Hemminger (4):
examples/vhost: replace memcpy with assignment examples/vmdq: replace memcpy with structure assignment examples/vmdq_dcb: replace memcpy with assignment
examples: remove unnecessary include
Structure assignment is better than [rte_]memcpy(). And this is slow path only, so no need to discuss performance.
For the series,
Thank you for cleaning this up.
21/01/2026 19:55, Morten Brørup:
Quoted 13 lines
Quoted 12 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Wednesday, 21 January 2026 18.05Looking at examples and noticed stuff around use
ofrte_memcpy. Probably mostly copy/pasted.Stephen Hemminger (4):
examples/vhost: replace memcpy with assignment examples/vmdq: replace memcpy with structure assignment examples/vmdq_dcb: replace memcpy with assignment
examples: remove unnecessary include
Quoted 7 lines
Structure assignment is better than [rte_]memcpy(). And this is slow path only, so no need to discuss performance.
For the series,
Reviewed-by Morten Brørup <[email protected]>Thank you for cleaning this up.
Applied with a small fix as notified in this thread.