DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] Is ”rte_mempool_mp_put_bulk()“ multi-producer safe?
@ 2013-08-13  6:27 dvr
  2013-08-13 11:47 ` Olivier MATZ
  0 siblings, 1 reply; 2+ messages in thread
From: dvr @ 2013-08-13  6:27 UTC (permalink / raw)
  To: dev

[-- Attachment #1: Type: text/plain, Size: 1480 bytes --]

hi,
    all
    I'm confused with some code about mempool:   
   
    rte_mempool.h   ( lib/ librte_mempool ,about line 668) 
    rte_mempool_mp_put_bulk();   //put serveral objects back in the mempool(multi-producers safe)
    rte_mempool_sp_put_bulk();   //put serveral objects back in the mempool(NOT multi-producers safe)
 
    rte_mempool.h   ( lib/ librte_mempool ,about line 563) 
    __mempool_put_bulk()
    {
         ......
         if(unlikely(cache_size==0 || is_mp==0))   
               goto ring_enqueue;
         ......
         //add in cache while there is enough room
        while(cache_add_count>0) {
             cache_objs[cache_len]=*obj_table;
             obj_table++;
             cache_len++;
             n--;
             cache_add_count--;
        }
             ......
       ring_enqueue:
        ......
       if(is_mp)
            rte_ring_mp_enqueue_bulk();
       else
            rte_ring_sp_enqueue_bulk();
        ......
    }
 
    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".
    Another question: how many thread we can have on a core? just one?
 
    Any help will be appreciate!
    Regards
Maria

[-- Attachment #2: Type: text/html, Size: 3691 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [dpdk-dev] Is ”rte_mempool_mp_put_bulk()“ multi-producer safe?
  2013-08-13  6:27 [dpdk-dev] Is ”rte_mempool_mp_put_bulk()“ multi-producer safe? dvr
@ 2013-08-13 11:47 ` Olivier MATZ
  0 siblings, 0 replies; 2+ messages in thread
From: Olivier MATZ @ 2013-08-13 11:47 UTC (permalink / raw)
  To: dvr; +Cc: dev

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-08-13 11:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-13  6:27 [dpdk-dev] Is ”rte_mempool_mp_put_bulk()“ multi-producer safe? dvr
2013-08-13 11:47 ` Olivier MATZ

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).