[dpdk-dev,v5,5/8] mempool: get the mempool capability
Checks
Commit Message
Allow mempool driver to advertise his pool capability.
For that pupose, an api(rte_mempool_ops_get_capabilities)
and ->get_capability() handler has been introduced.
- Upon ->get_capabilities() call, mempool driver will advertise
his capability by oring to mempool 'flags'.
Signed-off-by: Santosh Shukla <santosh.shukla@caviumnetworks.com>
Signed-off-by: Jerin Jacob <jerin.jacob@caviumnetworks.com>
---
v4 --> v5:
- Added flags as second param in get_capability api (suggested by Olivier)
- Removed 80 char warning. (suggested by Olivier)
- Upadted API description, now explicitly mentioning that update as a
Or'ed operation by mempool handle. (suggested by Olivier)
refer [1].
[1] http://dpdk.org/dev/patchwork/patch/27598/
lib/librte_mempool/rte_mempool.c | 6 ++++++
lib/librte_mempool/rte_mempool.h | 26 ++++++++++++++++++++++++++
lib/librte_mempool/rte_mempool_ops.c | 15 +++++++++++++++
lib/librte_mempool/rte_mempool_version.map | 7 +++++++
4 files changed, 54 insertions(+)
Comments
On Wed, Sep 06, 2017 at 04:58:31PM +0530, Santosh Shukla wrote:
> Allow mempool driver to advertise his pool capability.
> For that pupose, an api(rte_mempool_ops_get_capabilities)
typo: pupose -> purpose
> ...
> --- a/lib/librte_mempool/rte_mempool.c
> +++ b/lib/librte_mempool/rte_mempool.c
> @@ -528,6 +528,12 @@ rte_mempool_populate_default(struct rte_mempool *mp)
> if (mp->nb_mem_chunks != 0)
> return -EEXIST;
>
> + /* Get mempool capability */
capability -> capabilities
> + ret = rte_mempool_ops_get_capabilities(mp, &mp->flags);
> + if (ret < 0)
> + RTE_LOG(DEBUG, MEMPOOL, "get_capability not supported for %s\n",
> + mp->name);
> +
I think the error can be ignored only if it's -ENOTSUP.
Else, the error should be propagated.
> --- 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);
>
> +/**
> + * Get the mempool capability.
> + */
capability -> capabilities
> +typedef int (*rte_mempool_get_capabilities_t)(const struct rte_mempool *mp,
> + unsigned int *flags);
> +
> /** Structure defining mempool operations structure */
> struct rte_mempool_ops {
> char name[RTE_MEMPOOL_OPS_NAMESIZE]; /**< Name of mempool ops struct. */
> @@ -397,6 +403,10 @@ 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. */
> + /**
> + * Get the pool capability
> + */
> + rte_mempool_get_capabilities_t get_capabilities;
capability -> capabilities
> } __rte_cache_aligned;
>
> #define RTE_MEMPOOL_MAX_OPS_IDX 16 /**< Max registered ops structs */
> @@ -509,6 +519,22 @@ unsigned
> rte_mempool_ops_get_count(const struct rte_mempool *mp);
>
> /**
> + * @internal wrapper for mempool_ops get_capabilities callback.
> + *
> + * @param mp [in]
> + * Pointer to the memory pool.
> + * @param flags [out]
> + * Pointer to the mempool flag.
> + * @return
> + * - 0: Success; mempool driver has advetised his pool capability by Oring to
> + * flags param.
> + * - <0: Error; code of capability function.
> + */
> +int
> +rte_mempool_ops_get_capabilities(const struct rte_mempool *mp,
> + unsigned int *flags);
> +
> +/**
The API is correct, but the flags should simply be returned, not or-ed.
I think it should be kept as simple as possible: a function called
get_somthing() is expected to return it without doing anything else.
Sorry if I wasn't clear in my previous message.
If there is a need to do a OR with mp->flags, it has to be done in the caller,
i.e. rte_mempool_populate_default().
On Thursday 07 September 2017 01:29 PM, Olivier MATZ wrote:
> On Wed, Sep 06, 2017 at 04:58:31PM +0530, Santosh Shukla wrote:
>> Allow mempool driver to advertise his pool capability.
>> For that pupose, an api(rte_mempool_ops_get_capabilities)
> typo: pupose -> purpose
v6.
>> ...
>> --- a/lib/librte_mempool/rte_mempool.c
>> +++ b/lib/librte_mempool/rte_mempool.c
>> @@ -528,6 +528,12 @@ rte_mempool_populate_default(struct rte_mempool *mp)
>> if (mp->nb_mem_chunks != 0)
>> return -EEXIST;
>>
>> + /* Get mempool capability */
> capability -> capabilities
v6.
>> + ret = rte_mempool_ops_get_capabilities(mp, &mp->flags);
>> + if (ret < 0)
>> + RTE_LOG(DEBUG, MEMPOOL, "get_capability not supported for %s\n",
>> + mp->name);
>> +
> I think the error can be ignored only if it's -ENOTSUP.
> Else, the error should be propagated.
v6.
>
>> --- 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);
>>
>> +/**
>> + * Get the mempool capability.
>> + */
> capability -> capabilities
>
v6.
>> +typedef int (*rte_mempool_get_capabilities_t)(const struct rte_mempool *mp,
>> + unsigned int *flags);
>> +
>> /** Structure defining mempool operations structure */
>> struct rte_mempool_ops {
>> char name[RTE_MEMPOOL_OPS_NAMESIZE]; /**< Name of mempool ops struct. */
>> @@ -397,6 +403,10 @@ 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. */
>> + /**
>> + * Get the pool capability
>> + */
>> + rte_mempool_get_capabilities_t get_capabilities;
> capability -> capabilities
>
v6.
>> } __rte_cache_aligned;
>>
>> #define RTE_MEMPOOL_MAX_OPS_IDX 16 /**< Max registered ops structs */
>> @@ -509,6 +519,22 @@ unsigned
>> rte_mempool_ops_get_count(const struct rte_mempool *mp);
>>
>> /**
>> + * @internal wrapper for mempool_ops get_capabilities callback.
>> + *
>> + * @param mp [in]
>> + * Pointer to the memory pool.
>> + * @param flags [out]
>> + * Pointer to the mempool flag.
>> + * @return
>> + * - 0: Success; mempool driver has advetised his pool capability by Oring to
>> + * flags param.
>> + * - <0: Error; code of capability function.
>> + */
>> +int
>> +rte_mempool_ops_get_capabilities(const struct rte_mempool *mp,
>> + unsigned int *flags);
>> +
>> +/**
> The API is correct, but the flags should simply be returned, not or-ed.
> I think it should be kept as simple as possible: a function called
> get_somthing() is expected to return it without doing anything else.
> Sorry if I wasn't clear in my previous message.
>
> If there is a need to do a OR with mp->flags, it has to be done in the caller,
> i.e. rte_mempool_populate_default().
>
pl. confirm : you want below approach:
unsigned int flags;
rte_mempool_ops_get_capabilities(mp, &flags)
mp->flags |= flags;
is that okay with you? i'll queue in v6
On Thu, Sep 07, 2017 at 01:45:58PM +0530, santosh wrote:
> > The API is correct, but the flags should simply be returned, not or-ed.
> > I think it should be kept as simple as possible: a function called
> > get_somthing() is expected to return it without doing anything else.
> > Sorry if I wasn't clear in my previous message.
> >
> > If there is a need to do a OR with mp->flags, it has to be done in the caller,
> > i.e. rte_mempool_populate_default().
> >
> pl. confirm : you want below approach:
>
> unsigned int flags;
> rte_mempool_ops_get_capabilities(mp, &flags)
> mp->flags |= flags;
>
> is that okay with you? i'll queue in v6
>
yes, thanks
@@ -528,6 +528,12 @@ rte_mempool_populate_default(struct rte_mempool *mp)
if (mp->nb_mem_chunks != 0)
return -EEXIST;
+ /* Get mempool capability */
+ ret = rte_mempool_ops_get_capabilities(mp, &mp->flags);
+ if (ret < 0)
+ RTE_LOG(DEBUG, MEMPOOL, "get_capability not supported for %s\n",
+ mp->name);
+
if (rte_xen_dom0_supported()) {
pg_sz = RTE_PGSIZE_2M;
pg_shift = rte_bsf32(pg_sz);
@@ -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);
+/**
+ * Get the mempool capability.
+ */
+typedef int (*rte_mempool_get_capabilities_t)(const struct rte_mempool *mp,
+ unsigned int *flags);
+
/** Structure defining mempool operations structure */
struct rte_mempool_ops {
char name[RTE_MEMPOOL_OPS_NAMESIZE]; /**< Name of mempool ops struct. */
@@ -397,6 +403,10 @@ 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. */
+ /**
+ * Get the pool capability
+ */
+ rte_mempool_get_capabilities_t get_capabilities;
} __rte_cache_aligned;
#define RTE_MEMPOOL_MAX_OPS_IDX 16 /**< Max registered ops structs */
@@ -509,6 +519,22 @@ unsigned
rte_mempool_ops_get_count(const struct rte_mempool *mp);
/**
+ * @internal wrapper for mempool_ops get_capabilities callback.
+ *
+ * @param mp [in]
+ * Pointer to the memory pool.
+ * @param flags [out]
+ * Pointer to the mempool flag.
+ * @return
+ * - 0: Success; mempool driver has advetised his pool capability by Oring to
+ * flags param.
+ * - <0: Error; code of capability function.
+ */
+int
+rte_mempool_ops_get_capabilities(const struct rte_mempool *mp,
+ unsigned int *flags);
+
+/**
* @internal wrapper for mempool_ops free callback.
*
* @param mp
@@ -37,6 +37,7 @@
#include <rte_mempool.h>
#include <rte_errno.h>
+#include <rte_dev.h>
/* indirect jump table to support external memory pools. */
struct rte_mempool_ops_table rte_mempool_ops_table = {
@@ -85,6 +86,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->get_capabilities = h->get_capabilities;
rte_spinlock_unlock(&rte_mempool_ops_table.sl);
@@ -123,6 +125,19 @@ rte_mempool_ops_get_count(const struct rte_mempool *mp)
return ops->get_count(mp);
}
+/* wrapper to get external mempool capability. */
+int
+rte_mempool_ops_get_capabilities(const struct rte_mempool *mp,
+ unsigned int *flags)
+{
+ struct rte_mempool_ops *ops;
+
+ ops = rte_mempool_get_ops(mp->ops_index);
+
+ RTE_FUNC_PTR_OR_ERR_RET(ops->get_capabilities, -ENOTSUP);
+ return ops->get_capabilities(mp, flags);
+}
+
/* sets mempool ops previously registered by rte_mempool_register_ops. */
int
rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name,
@@ -41,3 +41,10 @@ DPDK_16.07 {
rte_mempool_set_ops_byname;
} DPDK_2.0;
+
+DPDK_17.11 {
+ global:
+
+ rte_mempool_ops_get_capabilities;
+
+} DPDK_16.07;