Skip to contentSkip to conversation

examples: memcpy cleanups

PATCH In review Stephen Hemminger 3 participants 8 messages Jan 21 – Feb 17

lore
Share & tools
lore
#0 lore raw

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
#1 lore raw

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
index 4391d88c3d..ac888348d2 100644
@@ -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(&eth_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
#2 lore raw

PATCH 2/4 examples/vmdq: replace memcpy with structure assignment

In reply to Stephen Hemminger

Better 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
index 4a3ce6884c..12ef5bffc2 100644
@@ -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(&eth_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
#3 lore raw

PATCH 3/4 examples/vmdq_dcb: replace memcpy with assignment

In reply to Stephen Hemminger

Better 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
index 4ccc2fe4b0..6eccee086d 100644
@@ -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(&eth_conf->rx_adv_conf.vmdq_dcb_conf, &conf,
-			  sizeof(conf)));
-	(void)(rte_memcpy(&eth_conf->rx_adv_conf.dcb_rx_conf, &dcb_conf,
-			  sizeof(dcb_conf)));
-	(void)(rte_memcpy(&eth_conf->rx_adv_conf.vmdq_rx_conf, &vmdq_conf,
-			  sizeof(vmdq_conf)));
-	(void)(rte_memcpy(&eth_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
#4 lore raw

PATCH 4/4 examples: remove unnecessary include

In reply to Stephen Hemminger

All 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
index 9f38b63cbb..4e8eeb7a5e 100644
@@ -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
index 1f84102844..2180682373 100644
@@ -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
index 25b904dbd4..520fbea1c2 100644
@@ -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
index 1eed645d02..bd4c3f335b 100644
@@ -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
index ac8feaec8e..5beee22159 100644
@@ -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
index 8cf91b919c..f4f1c45cd1 100644
@@ -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
index 308b8edd20..a7cd5b4840 100644
@@ -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
index bff2b99531..993e0bf9da 100644
@@ -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
index 73e32fc197..98763440bc 100644
@@ -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
index c6fafdd019..59ea3172ae 100644
@@ -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
index ec12d1cc0b..02ec17d799 100644
@@ -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
index a5626ff02d..4c64194794 100644
@@ -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
index ac9c7f6217..aa33e71d7a 100644
@@ -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
index 65713dbea8..f3b9b49380 100644
@@ -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
index ebfc2febc5..691d453d0e 100644
@@ -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
index f7d8439cd4..7314a9c6ea 100644
@@ -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
index e50cc33fde..e9db70bb3c 100644
@@ -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
index b3c2c9ef23..e756ce0da2 100644
@@ -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
index 9c89f6b60d..9a20831a0d 100644
@@ -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
index 62c3f4a16d..70a7372d4a 100644
@@ -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
#5 lore raw

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>
 
 
 
Reviewed-by on the v1 series
#6 lore raw
In reply to Stephen Hemminger
Quoted 12 lines

From: Stephen Hemminger [mailto:[email protected]]
Sent: Wednesday, 21 January 2026 18.05

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

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.

#7 lore raw

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.05

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

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,

Thank you for cleaning this up.

Applied with a small fix as notified in this thread.