From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stephen Hemminger Subject: Re: [PATCH v3 1/2] mbuf: provide rte_pktmbuf_alloc_bulk API Date: Wed, 23 Dec 2015 10:37:44 -0800 Message-ID: <20151223103744.28551da7@xeon-e3> References: <1450055682-51953-1-git-send-email-huawei.xie@intel.com> <1450801074-29361-1-git-send-email-huawei.xie@intel.com> <1450801074-29361-2-git-send-email-huawei.xie@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: dev@dpdk.org, dprovan@bivio.net To: Huawei Xie Return-path: Received: from mail-pf0-f169.google.com (mail-pf0-f169.google.com [209.85.192.169]) by dpdk.org (Postfix) with ESMTP id C107E8D3A for ; Wed, 23 Dec 2015 19:37:37 +0100 (CET) Received: by mail-pf0-f169.google.com with SMTP id 78so53705035pfw.2 for ; Wed, 23 Dec 2015 10:37:37 -0800 (PST) In-Reply-To: <1450801074-29361-2-git-send-email-huawei.xie@intel.com> List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Wed, 23 Dec 2015 00:17:53 +0800 Huawei Xie wrote: > + > + rc = rte_mempool_get_bulk(pool, (void **)mbufs, count); > + if (unlikely(rc)) > + return rc; > + > + switch (count % 4) { > + case 0: while (idx != count) { > + RTE_MBUF_ASSERT(rte_mbuf_refcnt_read(mbufs[idx]) == 0); > + rte_mbuf_refcnt_set(mbufs[idx], 1); > + rte_pktmbuf_reset(mbufs[idx]); > + idx++; > + case 3: > + RTE_MBUF_ASSERT(rte_mbuf_refcnt_read(mbufs[idx]) == 0); > + rte_mbuf_refcnt_set(mbufs[idx], 1); > + rte_pktmbuf_reset(mbufs[idx]); > + idx++; > + case 2: > + RTE_MBUF_ASSERT(rte_mbuf_refcnt_read(mbufs[idx]) == 0); > + rte_mbuf_refcnt_set(mbufs[idx], 1); > + rte_pktmbuf_reset(mbufs[idx]); > + idx++; > + case 1: > + RTE_MBUF_ASSERT(rte_mbuf_refcnt_read(mbufs[idx]) == 0); > + rte_mbuf_refcnt_set(mbufs[idx], 1); > + rte_pktmbuf_reset(mbufs[idx]); > + idx++; > + } > + } > + return 0; > +} Since function will not work if count can not be 0 (otherwise rte_mempool_get_bulk will fail), why not: 1. Document that assumption 2. Use that assumption to speed up code. switch(count % 4) { do { case 0: ... case 1: ... } while (idx != count); } Also you really need to add a big block comment about this loop, to explain what it does and why.