[dpdk-dev] Is ”rte_mempool_mp_put_bulk()“ multi-producer safe?

Olivier MATZ olivier.matz at 6wind.com
Tue Aug 13 13:47:32 CEST 2013


Hi,

>     My question is :rte_mempool_mp_put_bulk() and
> rte_mempool_sp_put_bulk() call the same function  __mempool_put_bulk()
> with different "is_mp" value. If is_mp=1, that is ,multi-producer, the
> code will add these objects in cache while there is enough room, when
> two thread enqueue objects at the same time, isn't it unsafe?but the
> annotation show this function is "multi-producer safe".

This is not the only difference: rte_mempool_mp_put() will call
rte_ring_mp_enqueue() to add the objects from cache to the common
pool. This function uses a compare_and_set() to update the head/tail
indexes.

And rte_mempool_sp_put() uses rte_ring_mp_enqueue() which is simpler but
not thread safe.

>     Another question: how many thread we can have on a core? just one?

Yes. Both mempool and ring are designed to run with one pthread per
lcore: mempool uses a per-lcore cache, and the ring_mp/mc functions
assume that a pthread is not interrupted by another pthread.

Regards,
Olivier



More information about the dev mailing list