From mboxrd@z Thu Jan 1 00:00:00 1970 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=9TXonmgrj9JRfxo2MJSzXHTPVExiDyHbT8PRPuw5BIM=; b=tmlSvqI/mT5ZFF+amazXwT3k53P3YpjPoOpcJHyJIPtB8uHNjCnMKkT2CP+s58l4G+ qgOtnPh04762PXiX0L1vWwjIjaumE8oAZHm1/g86o3CkNKlcLEwShGCZ8UfyXur+j7w5 kTTMJrK49XjpmwM9NnDK9IQYrw8JfxMsStOgXuA4PRYJ6oPusYuYnivakRvUR081OWwZ yE37OQs3D3kOE++A/8TLoeQW2zwIY4is7ZNaQI+08wtsMJuuRwJ5utB8V9zqYsgKbTF5 91jE3Xl4038iM13IESPsrzApJt+iqg3ouyMGiXfvmE7B4BgzPo4LSCbKcOcdta5i4/Uf cW4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; bh=9TXonmgrj9JRfxo2MJSzXHTPVExiDyHbT8PRPuw5BIM=; b=Z3FOSrPoz3AkHm7nSBfARm7h4H/Cd6oqG2iOj2sQpe84mTzp1IkNrSUDnbPO1OF+wj /LtdimVkOXmVw7bKF/ddmVyfzCcd+mFYzQBLSgSJyRspu59CytB6VmNlPVpX2IhZ+vN3 kgK5nRWARKy/E+tZmFVjkuZyrwY8hOHFcRzGLPEDCTbDbhqeslGedkVyjv/+nm/UH9Ge IEZ6wma9U7b3KSvSMdz+0NJP6jguQRpWFqwuzb+OwsoFqWuZTA+jWmEOSYGUCqBBldIf JxLXbYTZtabIdIL1KzNg88fMyYE+VNuDwCo0FLUOC5Zu6AzvVBx2j9ZB5JRPBguW2IPi tYAw== X-Gm-Message-State: ALoCoQmQwj2Zu9mHG3I85s9zPRAilYp62tM1yYn0Wy9wf5em+uGZY8K6AWqGNlGDbrJSqgqAvuHKm19AFM6qme1SuB4RLrus0w== X-Received: by 10.98.68.146 with SMTP id m18mr23850188pfi.77.1450895857184; Wed, 23 Dec 2015 10:37:37 -0800 (PST) Received: from xeon-e3 (static-50-53-82-155.bvtn.or.frontiernet.net. [50.53.82.155]) by smtp.gmail.com with ESMTPSA id d74sm49447236pfj.20.2015.12.23.10.37.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Dec 2015 10:37:36 -0800 (PST) Date: Wed, 23 Dec 2015 10:37:44 -0800 From: Stephen Hemminger To: Huawei Xie Message-ID: <20151223103744.28551da7@xeon-e3> In-Reply-To: <1450801074-29361-2-git-send-email-huawei.xie@intel.com> 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 Subject: Re: [dpdk-dev] [PATCH v3 1/2] mbuf: provide rte_pktmbuf_alloc_bulk API 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: Wed, 23 Dec 2015 18:37:38 -0000 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.