[dpdk-dev] [PATCH 1/2] mempool: check the support for the given mempool

Hemant Agrawal hemant.agrawal at nxp.com
Tue Jul 4 14:22:47 CEST 2017


External offloaded mempool may not be available always or compatible.
This check enables run time verification of the presence of external
mempool before the mempool ops are installed.

This patch introduces new optional "supported" mempool ops function
to check if a given mempool instance is available and compatible.

If this is not defined, the default will be that mempool is supported.

Signed-off-by: Hemant Agrawal <hemant.agrawal at nxp.com>
---
 lib/librte_mempool/rte_mempool.h     | 24 ++++++++++++++++++++++++
 lib/librte_mempool/rte_mempool_ops.c | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+)

diff --git a/lib/librte_mempool/rte_mempool.h b/lib/librte_mempool/rte_mempool.h
index 76b5b3b..1ae2e70 100644
--- a/lib/librte_mempool/rte_mempool.h
+++ b/lib/librte_mempool/rte_mempool.h
@@ -389,6 +389,12 @@ typedef int (*rte_mempool_dequeue_t)(struct rte_mempool *mp,
  */
 typedef unsigned (*rte_mempool_get_count)(const struct rte_mempool *mp);
 
+/**
+ * Return if the given mempool is supported and compatible for this instance.
+ * it is optional to implement for mempools
+ */
+typedef int (*rte_mempool_supported)(const struct rte_mempool *mp);
+
 /** Structure defining mempool operations structure */
 struct rte_mempool_ops {
 	char name[RTE_MEMPOOL_OPS_NAMESIZE]; /**< Name of mempool ops struct. */
@@ -397,6 +403,8 @@ struct rte_mempool_ops {
 	rte_mempool_enqueue_t enqueue;   /**< Enqueue an object. */
 	rte_mempool_dequeue_t dequeue;   /**< Dequeue an object. */
 	rte_mempool_get_count get_count; /**< Get qty of available objs. */
+	rte_mempool_supported supported;
+	/**< Verify if mempool is supported for usages*/
 } __rte_cache_aligned;
 
 #define RTE_MEMPOOL_MAX_OPS_IDX 16  /**< Max registered ops structs */
@@ -518,6 +526,21 @@ void
 rte_mempool_ops_free(struct rte_mempool *mp);
 
 /**
+ * Check the given mempool availability and compatibility.
+ *
+ * @param mp
+ *   Pointer to the memory pool.
+ * @param name
+ *   Name of the ops structure to use for this mempool.
+ * @return
+ *   0: Success;  mempool instance is supported and compatible.
+ * - <0: Error; mempool instance is not supported or not compatible.
+ */
+int
+rte_mempool_ops_check_support(const struct rte_mempool *mp,
+				      const char *name);
+
+/**
  * Set the ops of a mempool.
  *
  * This can only be done on a mempool that is not populated, i.e. just after
@@ -533,6 +556,7 @@ rte_mempool_ops_free(struct rte_mempool *mp);
  *   - 0: Success; the mempool is now using the requested ops functions.
  *   - -EINVAL - Invalid ops struct name provided.
  *   - -EEXIST - mempool already has an ops struct assigned.
+ *   - -ENOTSUP  - mempool instance not supported.
  */
 int
 rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name,
diff --git a/lib/librte_mempool/rte_mempool_ops.c b/lib/librte_mempool/rte_mempool_ops.c
index 5f24de2..c426a9a 100644
--- a/lib/librte_mempool/rte_mempool_ops.c
+++ b/lib/librte_mempool/rte_mempool_ops.c
@@ -85,6 +85,7 @@ rte_mempool_register_ops(const struct rte_mempool_ops *h)
 	ops->enqueue = h->enqueue;
 	ops->dequeue = h->dequeue;
 	ops->get_count = h->get_count;
+	ops->supported = h->supported;
 
 	rte_spinlock_unlock(&rte_mempool_ops_table.sl);
 
@@ -123,6 +124,31 @@ rte_mempool_ops_get_count(const struct rte_mempool *mp)
 	return ops->get_count(mp);
 }
 
+/* check if given mempool is supported  and compatible for this instance. */
+int
+rte_mempool_ops_check_support(const struct rte_mempool *mp, const char *name)
+{
+	unsigned i;
+	struct rte_mempool_ops *ops = NULL;
+
+	for (i = 0; i < rte_mempool_ops_table.num_ops; i++) {
+		if (!strcmp(name, rte_mempool_ops_table.ops[i].name)) {
+			ops = &rte_mempool_ops_table.ops[i];
+			break;
+		}
+	}
+
+	if (ops == NULL)
+		return -EINVAL;
+
+	if (ops->supported) {
+		if (ops->supported(mp))
+			return -ENOTSUP;
+	}
+
+	return 0;
+}
+
 /* sets mempool ops previously registered by rte_mempool_register_ops. */
 int
 rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name,
@@ -146,6 +172,12 @@ rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name,
 	if (ops == NULL)
 		return -EINVAL;
 
+	/* verify if the given mempool is supported for this instance  */
+	if (ops->supported) {
+		if (ops->supported(mp))
+			return -ENOTSUP;
+	}
+
 	mp->ops_index = i;
 	mp->pool_config = pool_config;
 	return 0;
-- 
2.7.4



More information about the dev mailing list