Skip to content

Commit

Permalink
mempool: fix default ops for an empty mempool
Browse files Browse the repository at this point in the history
[ upstream commit c2c6b2f413051b022488518d040508b9ea6e0130 ]

An empty mempool's ops were not initialised to a default value wrt to
what the application requested via the flags parameter.  As
rte_mempool_create() relies on rte_mempool_create_empty(), simply move
this ops initialisation to rte_mempool_create_empty().

Fixes: aa10457 ("mempool: make mempool populate and free api public")

Signed-off-by: David Marchand <david.marchand@redhat.com>
Reviewed-by: Bruce Richardson <bruce.richardson@intel.com>
Reviewed-by: Morten Brørup <mb@smartsharesystems.com>
  • Loading branch information
david-marchand authored and bluca committed Oct 18, 2023
1 parent ece5485 commit f44ac41
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions lib/librte_mempool/rte_mempool.c
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,22 @@ rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,
STAILQ_INIT(&mp->elt_list);
STAILQ_INIT(&mp->mem_list);

/*
* Since we have 4 combinations of the SP/SC/MP/MC examine the flags to
* set the correct index into the table of ops structs.
*/
if ((flags & MEMPOOL_F_SP_PUT) && (flags & MEMPOOL_F_SC_GET))
ret = rte_mempool_set_ops_byname(mp, "ring_sp_sc", NULL);
else if (flags & MEMPOOL_F_SP_PUT)
ret = rte_mempool_set_ops_byname(mp, "ring_sp_mc", NULL);
else if (flags & MEMPOOL_F_SC_GET)
ret = rte_mempool_set_ops_byname(mp, "ring_mp_sc", NULL);
else
ret = rte_mempool_set_ops_byname(mp, "ring_mp_mc", NULL);

if (ret)
goto exit_unlock;

/*
* local_cache pointer is set even if cache_size is zero.
* The local_cache points to just past the elt_pa[] array.
Expand Down Expand Up @@ -923,30 +939,13 @@ rte_mempool_create(const char *name, unsigned n, unsigned elt_size,
rte_mempool_obj_cb_t *obj_init, void *obj_init_arg,
int socket_id, unsigned flags)
{
int ret;
struct rte_mempool *mp;

mp = rte_mempool_create_empty(name, n, elt_size, cache_size,
private_data_size, socket_id, flags);
if (mp == NULL)
return NULL;

/*
* Since we have 4 combinations of the SP/SC/MP/MC examine the flags to
* set the correct index into the table of ops structs.
*/
if ((flags & MEMPOOL_F_SP_PUT) && (flags & MEMPOOL_F_SC_GET))
ret = rte_mempool_set_ops_byname(mp, "ring_sp_sc", NULL);
else if (flags & MEMPOOL_F_SP_PUT)
ret = rte_mempool_set_ops_byname(mp, "ring_sp_mc", NULL);
else if (flags & MEMPOOL_F_SC_GET)
ret = rte_mempool_set_ops_byname(mp, "ring_mp_sc", NULL);
else
ret = rte_mempool_set_ops_byname(mp, "ring_mp_mc", NULL);

if (ret)
goto fail;

/* call the mempool priv initializer */
if (mp_init)
mp_init(mp, mp_init_arg);
Expand Down

0 comments on commit f44ac41

Please sign in to comment.