DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
	Thomas Monjalon <thomas@monjalon.net>,
	Ferruh Yigit <ferruh.yigit@amd.com>,
	Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>,
	Ori Kam <orika@nvidia.com>
Subject: [PATCH v4 03/30] ethdev: replace uses of rte_memcpy
Date: Fri,  5 Apr 2024 09:53:14 -0700	[thread overview]
Message-ID: <20240405165518.367503-4-stephen@networkplumber.org> (raw)
In-Reply-To: <20240405165518.367503-1-stephen@networkplumber.org>

Replace use of rte_memcpy in ethdev. Most of these were
fixed size, and the others were not in the fast path.
Where possible replace memcpy() with structure assignment
which has same effect is type safe.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>

ethdev: struct assign
---
 lib/ethdev/rte_ethdev.c |  12 ++---
 lib/ethdev/rte_flow.c   | 101 +++++++++++++++++++---------------------
 2 files changed, 53 insertions(+), 60 deletions(-)

diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c
index f1c658f49e..27d2416466 100644
--- a/lib/ethdev/rte_ethdev.c
+++ b/lib/ethdev/rte_ethdev.c
@@ -15,7 +15,6 @@
 #include <rte_log.h>
 #include <rte_interrupts.h>
 #include <rte_kvargs.h>
-#include <rte_memcpy.h>
 #include <rte_common.h>
 #include <rte_mempool.h>
 #include <rte_malloc.h>
@@ -618,7 +617,7 @@ rte_eth_dev_owner_get(const uint16_t port_id, struct rte_eth_dev_owner *owner)
 	rte_spinlock_lock(rte_mcfg_ethdev_get_lock());
 
 	if (eth_dev_shared_data_prepare() != NULL) {
-		rte_memcpy(owner, &ethdev->data->owner, sizeof(*owner));
+		*owner = ethdev->data->owner;
 		ret = 0;
 	} else {
 		ret = -ENOMEM;
@@ -1316,15 +1315,14 @@ rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
 	dev->data->dev_configured = 0;
 
 	 /* Store original config, as rollback required on failure */
-	memcpy(&orig_conf, &dev->data->dev_conf, sizeof(dev->data->dev_conf));
+	orig_conf = dev->data->dev_conf;
 
 	/*
 	 * Copy the dev_conf parameter into the dev structure.
 	 * rte_eth_dev_info_get() requires dev_conf, copy it before dev_info get
 	 */
 	if (dev_conf != &dev->data->dev_conf)
-		memcpy(&dev->data->dev_conf, dev_conf,
-		       sizeof(dev->data->dev_conf));
+		dev->data->dev_conf = *dev_conf;
 
 	/* Backup mtu for rollback */
 	old_mtu = dev->data->mtu;
@@ -1601,7 +1599,7 @@ rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
 	eth_dev_rx_queue_config(dev, 0);
 	eth_dev_tx_queue_config(dev, 0);
 rollback:
-	memcpy(&dev->data->dev_conf, &orig_conf, sizeof(dev->data->dev_conf));
+	dev->data->dev_conf = orig_conf;
 	if (old_mtu != dev->data->mtu)
 		dev->data->mtu = old_mtu;
 
@@ -3843,7 +3841,7 @@ rte_eth_dev_conf_get(uint16_t port_id, struct rte_eth_conf *dev_conf)
 		return -EINVAL;
 	}
 
-	memcpy(dev_conf, &dev->data->dev_conf, sizeof(struct rte_eth_conf));
+	*dev_conf = dev->data->dev_conf;
 
 	rte_ethdev_trace_conf_get(port_id, dev_conf);
 
diff --git a/lib/ethdev/rte_flow.c b/lib/ethdev/rte_flow.c
index 7ab1100ea0..776352b984 100644
--- a/lib/ethdev/rte_flow.c
+++ b/lib/ethdev/rte_flow.c
@@ -62,7 +62,8 @@ rte_flow_conv_copy(void *buf, const void *data, const size_t size,
 	size_t sz = rte_type ? desc[type].size : sizeof(void *);
 	if (buf == NULL || data == NULL)
 		return 0;
-	rte_memcpy(buf, data, (size > sz ? sz : size));
+
+	memcpy(buf, data, (size > sz ? sz : size));
 	if (rte_type && desc[type].desc_fn)
 		sz += desc[type].desc_fn(size > 0 ? buf : NULL, data);
 	return sz;
@@ -73,11 +74,10 @@ rte_flow_item_flex_conv(void *buf, const void *data)
 {
 	struct rte_flow_item_flex *dst = buf;
 	const struct rte_flow_item_flex *src = data;
-	if (buf) {
-		dst->pattern = rte_memcpy
-			((void *)((uintptr_t)(dst + 1)), src->pattern,
-			 src->length);
-	}
+
+	if (buf)
+		dst->pattern = memcpy((void *)((uintptr_t)(dst + 1)),
+				      src->pattern, src->length);
 	return src->length;
 }
 
@@ -643,16 +643,18 @@ rte_flow_conv_item_spec(void *buf, const size_t size,
 		mask.raw = item->mask ? item->mask : &rte_flow_item_raw_mask;
 		src.raw = data;
 		dst.raw = buf;
-		rte_memcpy(dst.raw,
-			   (&(struct rte_flow_item_raw){
-				.relative = src.raw->relative,
-				.search = src.raw->search,
-				.reserved = src.raw->reserved,
-				.offset = src.raw->offset,
-				.limit = src.raw->limit,
-				.length = src.raw->length,
-			   }),
-			   size > sizeof(*dst.raw) ? sizeof(*dst.raw) : size);
+
+		memcpy(dst.raw,
+		       (&(struct rte_flow_item_raw){
+			       .relative = src.raw->relative,
+			       .search = src.raw->search,
+			       .reserved = src.raw->reserved,
+			       .offset = src.raw->offset,
+			       .limit = src.raw->limit,
+			       .length = src.raw->length,
+		       }),
+		       size > sizeof(*dst.raw) ? sizeof(*dst.raw) : size);
+
 		off = sizeof(*dst.raw);
 		if (type == RTE_FLOW_CONV_ITEM_SPEC ||
 		    (type == RTE_FLOW_CONV_ITEM_MASK &&
@@ -664,9 +666,8 @@ rte_flow_conv_item_spec(void *buf, const size_t size,
 		if (tmp) {
 			off = RTE_ALIGN_CEIL(off, sizeof(*dst.raw->pattern));
 			if (size >= off + tmp)
-				dst.raw->pattern = rte_memcpy
-					((void *)((uintptr_t)dst.raw + off),
-					 src.raw->pattern, tmp);
+				dst.raw->pattern = memcpy((void *)((uintptr_t)dst.raw + off),
+							  src.raw->pattern, tmp);
 			off += tmp;
 		}
 		break;
@@ -716,32 +717,31 @@ rte_flow_conv_action_conf(void *buf, const size_t size,
 	case RTE_FLOW_ACTION_TYPE_RSS:
 		src.rss = action->conf;
 		dst.rss = buf;
-		rte_memcpy(dst.rss,
-			   (&(struct rte_flow_action_rss){
-				.func = src.rss->func,
-				.level = src.rss->level,
-				.types = src.rss->types,
-				.key_len = src.rss->key_len,
-				.queue_num = src.rss->queue_num,
-			   }),
-			   size > sizeof(*dst.rss) ? sizeof(*dst.rss) : size);
+		memcpy(dst.rss,
+		       (&(struct rte_flow_action_rss){
+			       .func = src.rss->func,
+			       .level = src.rss->level,
+			       .types = src.rss->types,
+			       .key_len = src.rss->key_len,
+			       .queue_num = src.rss->queue_num,
+		       }),
+		       size > sizeof(*dst.rss) ? sizeof(*dst.rss) : size);
+
 		off = sizeof(*dst.rss);
 		if (src.rss->key_len && src.rss->key) {
 			off = RTE_ALIGN_CEIL(off, sizeof(*dst.rss->key));
 			tmp = sizeof(*src.rss->key) * src.rss->key_len;
 			if (size >= (uint64_t)off + (uint64_t)tmp)
-				dst.rss->key = rte_memcpy
-					((void *)((uintptr_t)dst.rss + off),
-					 src.rss->key, tmp);
+				dst.rss->key = memcpy((void *)((uintptr_t)dst.rss + off),
+						      src.rss->key, tmp);
 			off += tmp;
 		}
 		if (src.rss->queue_num) {
 			off = RTE_ALIGN_CEIL(off, sizeof(*dst.rss->queue));
 			tmp = sizeof(*src.rss->queue) * src.rss->queue_num;
 			if (size >= (uint64_t)off + (uint64_t)tmp)
-				dst.rss->queue = rte_memcpy
-					((void *)((uintptr_t)dst.rss + off),
-					 src.rss->queue, tmp);
+				dst.rss->queue = memcpy((void *)((uintptr_t)dst.rss + off),
+							src.rss->queue, tmp);
 			off += tmp;
 		}
 		break;
@@ -983,20 +983,15 @@ rte_flow_conv_rule(struct rte_flow_conv_rule *dst,
 	size_t off;
 	int ret;
 
-	rte_memcpy(dst,
-		   (&(struct rte_flow_conv_rule){
-			.attr = NULL,
-			.pattern = NULL,
-			.actions = NULL,
-		   }),
-		   size > sizeof(*dst) ? sizeof(*dst) : size);
+	memcpy(dst, &(struct rte_flow_conv_rule) { },
+	       size > sizeof(*dst) ? sizeof(*dst) : size);
+
 	off = sizeof(*dst);
 	if (src->attr_ro) {
 		off = RTE_ALIGN_CEIL(off, sizeof(double));
 		if (size && size >= off + sizeof(*dst->attr))
-			dst->attr = rte_memcpy
-				((void *)((uintptr_t)dst + off),
-				 src->attr_ro, sizeof(*dst->attr));
+			dst->attr = memcpy((void *)((uintptr_t)dst + off),
+					   src->attr_ro, sizeof(*dst->attr));
 		off += sizeof(*dst->attr);
 	}
 	if (src->pattern_ro) {
@@ -1098,7 +1093,7 @@ rte_flow_conv(enum rte_flow_conv_op op,
 		attr = src;
 		if (size > sizeof(*attr))
 			size = sizeof(*attr);
-		rte_memcpy(dst, attr, size);
+		memcpy(dst, attr, size);
 		ret = sizeof(*attr);
 		break;
 	case RTE_FLOW_CONV_OP_ITEM:
@@ -1180,14 +1175,14 @@ rte_flow_copy(struct rte_flow_desc *desc, size_t len,
 	if (ret < 0)
 		return 0;
 	ret += sizeof(*desc) - sizeof(*dst);
-	rte_memcpy(desc,
-		   (&(struct rte_flow_desc){
-			.size = ret,
-			.attr = *attr,
-			.items = dst_size ? dst->pattern : NULL,
-			.actions = dst_size ? dst->actions : NULL,
-		   }),
-		   len > sizeof(*desc) ? sizeof(*desc) : len);
+	memcpy(desc,
+	       (&(struct rte_flow_desc){
+		       .size = ret,
+		       .attr = *attr,
+		       .items = dst_size ? dst->pattern : NULL,
+		       .actions = dst_size ? dst->actions : NULL,
+	       }),
+	       len > sizeof(*desc) ? sizeof(*desc) : len);
 
 	rte_flow_trace_copy(desc, len, attr, items, actions, ret);
 
-- 
2.43.0


  parent reply	other threads:[~2024-04-05 16:56 UTC|newest]

Thread overview: 88+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-03 16:32 [PATCH 0/2] uuid: enhancements and tests Stephen Hemminger
2024-04-03 16:32 ` [PATCH 1/2] eal: add functions to generate uuid values Stephen Hemminger
2024-04-04 16:11   ` Tyler Retzlaff
2024-04-03 16:32 ` [PATCH 2/2] test: add functional test for uuid Stephen Hemminger
2024-04-03 22:11 ` [PATCH v2 0/2] uuid: add generate functions and tests Stephen Hemminger
2024-04-03 22:11   ` [PATCH v2 1/2] eal: add functions to generate uuid values Stephen Hemminger
2024-04-04 16:16     ` Tyler Retzlaff
2024-04-03 22:11   ` [PATCH v2 2/2] test: add functional test for uuid Stephen Hemminger
2024-04-04 16:18     ` Tyler Retzlaff
2024-04-04 16:22 ` [PATCH v3 0/2] uuid: add generate functions and tests Stephen Hemminger
2024-04-04 16:22   ` [PATCH v3 1/2] eal: add functions to generate uuid values Stephen Hemminger
2024-04-04 16:22   ` [PATCH v3 2/2] test: add functional test for uuid Stephen Hemminger
2024-04-05 16:53 ` [PATCH v4 00/30] replace use of rte_memcpy with fixed sizes Stephen Hemminger
2024-04-05 16:53   ` [PATCH v4 01/30] cocci/rte_memcpy: add script to eliminate fixed size rte_memcpy Stephen Hemminger
2024-04-06  9:01     ` Morten Brørup
2024-04-05 16:53   ` [PATCH v4 02/30] eal: replace use of " Stephen Hemminger
2024-04-05 16:53   ` Stephen Hemminger [this message]
2024-04-05 16:53   ` [PATCH v4 04/30] eventdev: " Stephen Hemminger
2024-04-05 16:53   ` [PATCH v4 05/30] cryptodev: " Stephen Hemminger
2024-04-10 15:40     ` [EXTERNAL] " Akhil Goyal
2024-04-05 16:53   ` [PATCH v4 06/30] ip_frag: " Stephen Hemminger
2024-04-05 16:53   ` [PATCH v4 07/30] net: " Stephen Hemminger
2024-04-05 16:53   ` [PATCH v4 08/30] lpm: " Stephen Hemminger
2024-04-05 16:53   ` [PATCH v4 09/30] node: " Stephen Hemminger
2024-04-05 16:53   ` [PATCH v4 10/30] pdcp: " Stephen Hemminger
2024-04-05 16:53   ` [PATCH v4 11/30] pipeline: " Stephen Hemminger
2024-04-05 16:53   ` [PATCH v4 12/30] rib: " Stephen Hemminger
2024-04-05 16:53   ` [PATCH v4 13/30] security: " Stephen Hemminger
2024-04-10 15:40     ` [EXTERNAL] " Akhil Goyal
2024-04-05 16:53   ` [PATCH v4 14/30] bus: remove unneeded rte_memcpy.h include Stephen Hemminger
2024-04-05 16:53   ` [PATCH v4 15/30] net: replace use of fixed size rte_memcpy Stephen Hemminger
2024-04-05 16:53   ` [PATCH v4 16/30] raw: " Stephen Hemminger
2024-04-05 16:53   ` [PATCH v4 17/30] baseband: " Stephen Hemminger
2024-04-05 16:53   ` [PATCH v4 18/30] common: " Stephen Hemminger
2024-04-05 16:53   ` [PATCH v4 19/30] crypto: " Stephen Hemminger
2024-04-05 16:53   ` [PATCH v4 20/30] " Stephen Hemminger
2024-04-05 16:53   ` [PATCH v4 21/30] event: " Stephen Hemminger
2024-04-05 16:53   ` [PATCH v4 22/30] mempool: " Stephen Hemminger
2024-04-05 16:53   ` [PATCH v4 23/30] ml/cnxk: " Stephen Hemminger
2024-04-05 16:53   ` [PATCH v4 24/30] app/test-pmd: " Stephen Hemminger
2024-04-05 16:53   ` [PATCH v4 25/30] app/graph: " Stephen Hemminger
2024-04-05 16:53   ` [PATCH v4 26/30] app/test-eventdev: " Stephen Hemminger
2024-04-05 16:53   ` [PATCH v4 27/30] app/test: " Stephen Hemminger
2024-04-10 18:28     ` [EXTERNAL] " Akhil Goyal
2024-04-05 16:53   ` [PATCH v4 28/30] app/test-pipeline: remove unused rte_memcpy.h include Stephen Hemminger
2024-04-05 16:53   ` [PATCH v4 29/30] app/test-bbdev: remove unnecessary include of rte_memcpy.h Stephen Hemminger
2024-04-05 16:53   ` [PATCH v4 30/30] examples: replace use of fixed size rte_memcpy Stephen Hemminger
2024-04-09 17:05 ` [PATCH v4 0/2] uuid: generator functions and unit test Stephen Hemminger
2024-04-09 17:05   ` [PATCH v4 1/2] eal: add functions to generate uuid values Stephen Hemminger
2024-04-09 17:05   ` [PATCH v4 2/2] test: add functional test for uuid Stephen Hemminger
2024-05-22  3:27 ` [PATCH v5 00/32] replace use of rte_memcpy() with fixed size Stephen Hemminger
2024-05-22  3:27   ` [PATCH v5 01/32] cocci/rte_memcpy: add script to eliminate fixed size rte_memcpy Stephen Hemminger
2024-05-22  3:27   ` [PATCH v5 02/32] eal: replace use of " Stephen Hemminger
2024-05-22  3:27   ` [PATCH v5 03/32] ethdev: replace uses of rte_memcpy Stephen Hemminger
2024-05-22  3:27   ` [PATCH v5 04/32] eventdev: replace use of fixed size rte_memcpy Stephen Hemminger
2024-05-22  3:27   ` [PATCH v5 05/32] cryptodev: " Stephen Hemminger
2024-05-22  3:27   ` [PATCH v5 06/32] ip_frag: " Stephen Hemminger
2024-05-22  3:27   ` [PATCH v5 07/32] net: " Stephen Hemminger
2024-05-22  3:27   ` [PATCH v5 08/32] lpm: " Stephen Hemminger
2024-05-22  3:27   ` [PATCH v5 09/32] node: " Stephen Hemminger
2024-05-22  3:27   ` [PATCH v5 10/32] pdcp: " Stephen Hemminger
2024-05-22  3:27   ` [PATCH v5 11/32] pipeline: " Stephen Hemminger
2024-05-22  3:27   ` [PATCH v5 12/32] rib: " Stephen Hemminger
2024-05-22  3:27   ` [PATCH v5 13/32] security: " Stephen Hemminger
2024-05-22  3:27   ` [PATCH v5 14/32] bus: remove unneeded rte_memcpy.h include Stephen Hemminger
2024-05-22  3:27   ` [PATCH v5 15/32] raw: replace use of fixed size rte_memcpy Stephen Hemminger
2024-05-22  3:27   ` [PATCH v5 16/32] baseband: " Stephen Hemminger
2024-05-23 18:28     ` Chautru, Nicolas
2024-05-22  3:27   ` [PATCH v5 17/32] common: " Stephen Hemminger
2024-05-22  3:27   ` [PATCH v5 18/32] crypto: " Stephen Hemminger
2024-05-22  3:27   ` [PATCH v5 19/32] event: " Stephen Hemminger
2024-05-22  3:27   ` [PATCH v5 20/32] mempool: " Stephen Hemminger
2024-05-22  3:27   ` [PATCH v5 21/32] ml/cnxk: " Stephen Hemminger
2024-05-22  3:27   ` [PATCH v5 22/32] app/test-pmd: " Stephen Hemminger
2024-05-22  3:27   ` [PATCH v5 23/32] app/graph: " Stephen Hemminger
2024-05-22  3:27   ` [PATCH v5 24/32] app/test-eventdev: " Stephen Hemminger
2024-05-22  3:27   ` [PATCH v5 25/32] app/test: " Stephen Hemminger
2024-05-22  3:27   ` [PATCH v5 26/32] app/test-pipeline: remove unused rte_memcpy.h include Stephen Hemminger
2024-05-22  3:27   ` [PATCH v5 27/32] app/test-bbdev: remove unnecessary include of rte_memcpy.h Stephen Hemminger
2024-05-22  3:27   ` [PATCH v5 28/32] examples: replace use of fixed size rte_memcpy Stephen Hemminger
2024-05-22  3:27   ` [PATCH v5 29/32] net/null: replace use of fixed size memcpy Stephen Hemminger
2024-05-22  3:27   ` [PATCH v5 30/32] net/tap: replace use of fixed size rte_memcpy Stephen Hemminger
2024-05-22  3:27   ` [PATCH v5 31/32] net/pcap: " Stephen Hemminger
2024-05-22  3:27   ` [PATCH v5 32/32] net/af_xdp:: " Stephen Hemminger
2024-05-26 14:51   ` [PATCH v5 00/32] replace use of rte_memcpy() with fixed size Mattias Rönnblom
2024-05-26 23:32     ` Stephen Hemminger
2024-05-27  6:06       ` Mattias Rönnblom
2024-05-27  6:38       ` Morten Brørup

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240405165518.367503-4-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=andrew.rybchenko@oktetlabs.ru \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@amd.com \
    --cc=orika@nvidia.com \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).