From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.droids-corp.org (zoll.droids-corp.org [94.23.50.67]) by dpdk.org (Postfix) with ESMTP id EE8661F3 for ; Tue, 13 Aug 2013 13:46:37 +0200 (CEST) Received: from was59-1-82-226-113-214.fbx.proxad.net ([82.226.113.214] helo=[192.168.0.10]) by mail.droids-corp.org with esmtpsa (TLS1.0:DHE_RSA_CAMELLIA_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1V9D4C-0003LS-Gp; Tue, 13 Aug 2013 13:47:15 +0200 Message-ID: <520A1CD4.3020601@6wind.com> Date: Tue, 13 Aug 2013 13:47:32 +0200 From: Olivier MATZ User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.12) Gecko/20130116 Icedove/10.0.12 MIME-Version: 1.0 To: dvr References: <48188b20.1c74c.140765b52ce.Coremail.jinxiu.1006@163.com> In-Reply-To: <48188b20.1c74c.140765b52ce.Coremail.jinxiu.1006@163.com> Content-Type: text/plain; charset=gbk Content-Transfer-Encoding: 7bit Cc: dev@dpdk.org Subject: Re: [dpdk-dev] =?gbk?b?SXMgobFydGVfbWVtcG9vbF9tcF9wdXRfYnVsaygpobAg?= =?gbk?q?multi-producer_safe=3F?= X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Aug 2013 11:46:38 -0000 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