DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] net/netvsc: add device argument to configure if NUMA information on the device should be ignored
@ 2025-08-11 22:48 longli
  2025-08-13  0:35 ` Stephen Hemminger
  0 siblings, 1 reply; 3+ messages in thread
From: longli @ 2025-08-11 22:48 UTC (permalink / raw)
  To: Stephen Hemminger, Wei Hu; +Cc: dev, Long Li

From: Long Li <longli@microsoft.com>

In most cases, netvsc is used with a VF device. The application generally
runs with better performance when all the device memory is allocated on
VF's NUMA node, as the VF device carries most of the data packets.

But sometimes netvsc may run on a different NUMA node than that of the VF.
This patches adds a device argument "numa" to allow the application to
configure if netvsc should be NUMA aware. The default behavior for netvsc
is that it is NUMA aware. Setting "numa=0" tells netvsc not to be NUMA
aware.

Signed-off-by: Long Li <longli@microsoft.com>
---
 doc/guides/nics/netvsc.rst     |  8 +++++
 drivers/net/netvsc/hn_ethdev.c | 66 +++++++++++++++++++++++++++++-----
 2 files changed, 66 insertions(+), 8 deletions(-)

diff --git a/doc/guides/nics/netvsc.rst b/doc/guides/nics/netvsc.rst
index 2c0ea6ac9e..e052b31dcc 100644
--- a/doc/guides/nics/netvsc.rst
+++ b/doc/guides/nics/netvsc.rst
@@ -141,3 +141,11 @@ The user can specify below argument in devargs.
     A non-zero value tells netvsc to attach external buffers to mbuf on
     receiving packets, thus avoid copying memory. Use of external buffers
     requires the application is able to read data from external mbuf.
+
+#. ``numa``:
+   The numa is used to configure if netvsc driver should be NUMA aware. The
+   default value is 1 (meaning the netvsc driver is NUMA aware). When used
+   with a VF device, the VF device's NUMA node may not be the same as netvsc's
+   NUMA node. The application generally runs with better performance if all the
+   device queues are allocated on VF's NUMA node, as the VF carries most of the
+   data packets. Setting this value to 0 makes netvsc driver not NUMA aware.
diff --git a/drivers/net/netvsc/hn_ethdev.c b/drivers/net/netvsc/hn_ethdev.c
index 0a7ed155d3..1ad4542d64 100644
--- a/drivers/net/netvsc/hn_ethdev.c
+++ b/drivers/net/netvsc/hn_ethdev.c
@@ -56,6 +56,16 @@
 #define NETVSC_ARG_RXBREAK "rx_copybreak"
 #define NETVSC_ARG_TXBREAK "tx_copybreak"
 #define NETVSC_ARG_RX_EXTMBUF_ENABLE "rx_extmbuf_enable"
+#define NETVSC_ARG_NUMA "numa"
+
+static const char * const valid_keys[] = {
+	NETVSC_ARG_LATENCY,
+	NETVSC_ARG_RXBREAK,
+	NETVSC_ARG_TXBREAK,
+	NETVSC_ARG_RX_EXTMBUF_ENABLE,
+	NETVSC_ARG_NUMA,
+	NULL
+};
 
 /* The max number of retry when hot adding a VF device */
 #define NETVSC_MAX_HOTADD_RETRY 10
@@ -105,6 +115,48 @@ struct da_cache {
 LIST_HEAD(da_cache_list, da_cache) da_cache_list;
 static unsigned int da_cache_usage;
 
+/* Check in dev args if numa should be used.
+ * By default returning true, meaning the device is numa aware
+ */
+static bool hn_use_numa(struct rte_vmbus_device *dev)
+{
+	struct rte_devargs *devargs = dev->device.devargs;
+	struct rte_kvargs *kvlist;
+	const struct rte_kvargs_pair *pair;
+	unsigned long v;
+	unsigned int i;
+	char *endp = NULL;
+	bool ret = true;
+
+	if (!devargs)
+		return ret;
+
+	PMD_INIT_LOG(DEBUG, "device args %s %s",
+		     devargs->name, devargs->args);
+
+	kvlist = rte_kvargs_parse(devargs->args, valid_keys);
+	if (!kvlist) {
+		PMD_DRV_LOG(ERR, "invalid parameters");
+		return ret;
+	}
+
+	for (i = 0; i < kvlist->count; i++) {
+		pair = &kvlist->pairs[i];
+		if (!strcmp(pair->key, NETVSC_ARG_NUMA)) {
+			v = strtoul(pair->value, &endp, 0);
+			if (*pair->value == '\0' || *endp != '\0') {
+				PMD_DRV_LOG(ERR, "invalid parameter %s=%s",
+					    pair->key, pair->value);
+			}
+			ret = v ? true : false;
+		}
+	}
+
+	rte_kvargs_free(kvlist);
+
+	return ret;
+}
+
 static struct rte_eth_dev *
 eth_dev_vmbus_allocate(struct rte_vmbus_device *dev, size_t private_data_size)
 {
@@ -116,6 +168,11 @@ eth_dev_vmbus_allocate(struct rte_vmbus_device *dev, size_t private_data_size)
 
 	name = dev->device.name;
 
+	if (!hn_use_numa(dev)) {
+		PMD_DRV_LOG(NOTICE, "NUMA mode disabled");
+		dev->device.numa_node = SOCKET_ID_ANY;
+	}
+
 	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
 		eth_dev = rte_eth_dev_allocate(name);
 		if (!eth_dev) {
@@ -126,7 +183,7 @@ eth_dev_vmbus_allocate(struct rte_vmbus_device *dev, size_t private_data_size)
 		if (private_data_size) {
 			eth_dev->data->dev_private =
 				rte_zmalloc_socket(name, private_data_size,
-						     RTE_CACHE_LINE_SIZE, dev->device.numa_node);
+						   RTE_CACHE_LINE_SIZE, dev->device.numa_node);
 			if (!eth_dev->data->dev_private) {
 				PMD_DRV_LOG(NOTICE, "can not allocate driver data");
 				rte_eth_dev_release_port(eth_dev);
@@ -199,13 +256,6 @@ static int hn_parse_args(const struct rte_eth_dev *dev)
 {
 	struct hn_data *hv = dev->data->dev_private;
 	struct rte_devargs *devargs = dev->device->devargs;
-	static const char * const valid_keys[] = {
-		NETVSC_ARG_LATENCY,
-		NETVSC_ARG_RXBREAK,
-		NETVSC_ARG_TXBREAK,
-		NETVSC_ARG_RX_EXTMBUF_ENABLE,
-		NULL
-	};
 	struct rte_kvargs *kvlist;
 	int ret;
 
-- 
2.34.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-08-13  0:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-11 22:48 [PATCH] net/netvsc: add device argument to configure if NUMA information on the device should be ignored longli
2025-08-13  0:35 ` Stephen Hemminger
2025-08-13  0:54   ` [EXTERNAL] " Long Li

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