DPDK patches and discussions
 help / color / mirror / Atom feed
From: Pavan Nikhilesh <pbhagavatula@caviumnetworks.com>
To: jerin.jacob@caviumnetworks.com, jingjing.wu@intel.com,
	bruce.richardson@intel.com, hemant.agrawal@nxp.com,
	ferruh.yigit@intel.com, thomas@monjalon.net,
	olivier.matz@6wind.com
Cc: dev@dpdk.org, Pavan Nikhilesh <pbhagavatula@caviumnetworks.com>
Subject: [dpdk-dev] [PATCH 2/3] ethdev: add API to get preferred mempool ops name
Date: Thu, 14 Dec 2017 01:25:37 +0530	[thread overview]
Message-ID: <20171213195538.14290-3-pbhagavatula@caviumnetworks.com> (raw)
In-Reply-To: <20171213195538.14290-1-pbhagavatula@caviumnetworks.com>

Add API to scan through the ethernet devices and return the best mbuf
mempool ops name.
If no such mempool is found it returns the default mempool configured.

Signed-off-by: Pavan Nikhilesh <pbhagavatula@caviumnetworks.com>
---
 lib/librte_ether/rte_ethdev.c           | 41 +++++++++++++++++++++++++++++++++
 lib/librte_ether/rte_ethdev.h           | 12 ++++++++++
 lib/librte_ether/rte_ethdev_version.map |  7 ++++++
 lib/librte_mempool/rte_mempool.h        | 12 ++++++++++
 4 files changed, 72 insertions(+)

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 318af2869..514037ec2 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -3591,3 +3591,44 @@ rte_eth_dev_pool_ops_supported(uint16_t port_id, const char *pool)
 
 	return (*dev->dev_ops->pool_ops_supported)(dev, pool);
 }
+
+const char *
+rte_eth_dev_get_preferred_pool_name(uint8_t set_default)
+{
+	int i, j;
+	int ret;
+	int best_weight = 0;
+	int default_pool_weight = 0;
+	const char *default_pool_name = rte_eal_mbuf_default_mempool_ops();
+	const char *preferred_pool_name = NULL;
+
+	for (i = 0; i < rte_mempool_ops_count(); i++) {
+		int weight = 0;
+		const char *name = rte_mempool_get_ops(i)->name;
+
+		for (j = 0; j < rte_eth_dev_count(); j++) {
+			ret = rte_eth_dev_pool_ops_supported(j, name);
+			if (ret < 0) {
+				weight = -1;
+				break;
+			}
+			weight += ret ? 1 : 2;
+		}
+
+		if (weight > best_weight) {
+			best_weight = weight;
+			preferred_pool_name = name;
+		}
+
+		if (!strcmp(name, default_pool_name))
+			default_pool_weight = weight;
+	}
+
+	if (!best_weight || best_weight == default_pool_weight)
+		preferred_pool_name = default_pool_name;
+
+	if (set_default)
+		rte_eal_set_mbuf_default_mempool_ops(preferred_pool_name);
+
+	return preferred_pool_name;
+}
diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h
index 341c2d624..3f4b234a0 100644
--- a/lib/librte_ether/rte_ethdev.h
+++ b/lib/librte_ether/rte_ethdev.h
@@ -4606,6 +4606,18 @@ int rte_eth_dev_adjust_nb_rx_tx_desc(uint16_t port_id,
 int
 rte_eth_dev_pool_ops_supported(uint16_t port_id, const char *pool);
 
+/**
+ * Scan through the ethernet devices and select the best mempool ops supported
+ * across them.
+ *
+ * @param set_default
+ *   Set the selected mempool ops as default.
+ * @return
+ *   The name of the selected mempool ops.
+ */
+const char *
+rte_eth_dev_get_preferred_pool_name(uint8_t set_default);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/librte_ether/rte_ethdev_version.map b/lib/librte_ether/rte_ethdev_version.map
index e9681ac8e..674a59c92 100644
--- a/lib/librte_ether/rte_ethdev_version.map
+++ b/lib/librte_ether/rte_ethdev_version.map
@@ -198,6 +198,13 @@ DPDK_17.11 {
 
 } DPDK_17.08;
 
+DPDK_18.02 {
+	global:
+
+	rte_eth_dev_get_preferred_pool_name;
+
+} DPDK_17.11;
+
 EXPERIMENTAL {
 	global:
 
diff --git a/lib/librte_mempool/rte_mempool.h b/lib/librte_mempool/rte_mempool.h
index 721227f6d..27033102d 100644
--- a/lib/librte_mempool/rte_mempool.h
+++ b/lib/librte_mempool/rte_mempool.h
@@ -485,6 +485,18 @@ rte_mempool_get_ops(int ops_index)
 	return &rte_mempool_ops_table.ops[ops_index];
 }
 
+/**
+ * @internal Get the total number of mempool ops.
+ *
+ * @return
+ *   The number of mempool ops in the ops table.
+ */
+static inline int
+rte_mempool_ops_count(void)
+{
+	return rte_mempool_ops_table.num_ops;
+}
+
 /**
  * @internal Wrapper for mempool_ops alloc callback.
  *
-- 
2.14.1

  parent reply	other threads:[~2017-12-13 19:56 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-13 19:55 [dpdk-dev] [PATCH 0/3] ethdev: add API to get preferred mbuf pool ops Pavan Nikhilesh
2017-12-13 19:55 ` [dpdk-dev] [PATCH 1/3] eal: add API to set default mbuf mempool ops Pavan Nikhilesh
2017-12-13 19:55 ` Pavan Nikhilesh [this message]
2017-12-13 19:55 ` [dpdk-dev] [PATCH 3/3] app/testpmd: set preferred mempool as default pktpool Pavan Nikhilesh
2018-01-16  6:06   ` Lu, Wenzhuo
2018-01-16  8:20     ` Pavan Nikhilesh
2017-12-13 21:22 ` [dpdk-dev] [PATCH 0/3] ethdev: add API to get preferred mbuf pool ops Thomas Monjalon

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=20171213195538.14290-3-pbhagavatula@caviumnetworks.com \
    --to=pbhagavatula@caviumnetworks.com \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=hemant.agrawal@nxp.com \
    --cc=jerin.jacob@caviumnetworks.com \
    --cc=jingjing.wu@intel.com \
    --cc=olivier.matz@6wind.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).