From mboxrd@z Thu Jan 1 00:00:00 1970 From: Olivier MATZ Subject: Re: =?gbk?b?SXMgobFydGVfbWVtcG9vbF9tcF9wdXRfYnVsaygpobAg?= =?gbk?q?multi-producer_safe=3F?= Date: Tue, 13 Aug 2013 13:47:32 +0200 Message-ID: <520A1CD4.3020601@6wind.com> References: <48188b20.1c74c.140765b52ce.Coremail.jinxiu.1006@163.com> Mime-Version: 1.0 Content-Type: text/plain; charset=gbk Content-Transfer-Encoding: 7bit Cc: dev-VfR2kkLFssw@public.gmane.org To: dvr Return-path: In-Reply-To: <48188b20.1c74c.140765b52ce.Coremail.jinxiu.1006-9Onoh4P/yGk@public.gmane.org> List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces-VfR2kkLFssw@public.gmane.org Sender: "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