From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf0-f52.google.com (mail-lf0-f52.google.com [209.85.215.52]) by dpdk.org (Postfix) with ESMTP id B2D1FF95C for ; Wed, 18 Jan 2017 11:28:20 +0100 (CET) Received: by mail-lf0-f52.google.com with SMTP id v186so7234253lfa.1 for ; Wed, 18 Jan 2017 02:28:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brain4net.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=0QBLvXoHH76njj9gtnkTjbvj5mnqPNYR9nStJFaduY8=; b=WIc1X41hMGL+mW3/Abs824XPHwep+pp9c1sEx+B+91Bb9vN2hhSomGyAivSmT1/zuZ KhYJM81c6Enmqkwo0p1iuahgCfzGBRSUUxNHnpGuKenWlPMJu5tFoFzhWDHF2M7Hweoe /dtmWxF/j48g2wtv0ma2IMAAR8lIsLm4V3POI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=0QBLvXoHH76njj9gtnkTjbvj5mnqPNYR9nStJFaduY8=; b=e1ND7RSBK84M2lVWFiVKIKOTbZsevFfIrrVJVvQW20FZMIKuLl/wRpXXOo6YoR8DYX v5xKpcIqzOdwLZpaiRiNn4APPrhxCASlSsBMuqAZGRUvmzaX3LxFRJ5qprcZViNgzwP8 t5M+n3auKx0XJZNdWy6dxicjOYh6nAtn+PYterudmSwJ5b9ocdmoyCsjvMcxYdBLC82U 7MI+X/EU6PGoZhKpuuajaWzfQBBg8W0LrlSHfrlnqWx8H5grC7Utlb99FSWxU6YSJTO2 1rf8QXKVsdhqXXem8f2bYI+zu/cY3gM2WOMMCRTx0+7ibTceln95pvwjFmjVEQAqussm 12eA== X-Gm-Message-State: AIkVDXIkXLIp4vD8gPllgpA3Zu7eFZKSZ0BHXgG8f258soEHVKNH1rgiS5ShIeb/1I+RCXl2 X-Received: by 10.25.28.199 with SMTP id c190mr891300lfc.173.1484735300311; Wed, 18 Jan 2017 02:28:20 -0800 (PST) Received: from localhost.localdomain ([91.201.72.212]) by smtp.gmail.com with ESMTPSA id o91sm10567640lfg.17.2017.01.18.02.28.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 18 Jan 2017 02:28:19 -0800 (PST) From: Sergey Vyazmitinov To: olivier.matz@6wind.com Cc: konstantin.ananyev@intel.com, stephen@networkplumber.org, yuanhan.liu@linux.intel.com, ferruh.yigit@intel.com, dev@dpdk.org, Sergey Vyazmitinov Date: Wed, 18 Jan 2017 17:28:01 +0700 Message-Id: <1484735282-14876-2-git-send-email-s.vyazmitinov@brain4net.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1484735282-14876-1-git-send-email-s.vyazmitinov@brain4net.com> References: <1484735282-14876-1-git-send-email-s.vyazmitinov@brain4net.com> Subject: [dpdk-dev] [PATCH v4 1/2] kni: add bulk function to free mbufs X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Jan 2017 10:28:20 -0000 Suggested-by: Stephen Hemminger Signed-off-by: Sergey Vyazmitinov --- v3: * Fixed issue with possible different mempools in buffer list. * Fixed issue with wrong rte_pktmbuf_alloc_bulk function return value processing in the kni_allocate_mbufs. --- lib/librte_mbuf/rte_mbuf.h | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h index 4476d75..69d314f 100644 --- a/lib/librte_mbuf/rte_mbuf.h +++ b/lib/librte_mbuf/rte_mbuf.h @@ -306,6 +306,9 @@ extern "C" { /** Alignment constraint of mbuf private area. */ #define RTE_MBUF_PRIV_ALIGN 8 +/** Maximum number of mbufs freed in bulk. */ +#define RTE_MBUF_BULK_FREE 64 + /** * Get the name of a RX offload flag * @@ -1261,6 +1264,52 @@ static inline void rte_pktmbuf_free(struct rte_mbuf *m) } /** + * Free n packets mbuf back into its original mempool. + * + * Free each mbuf, and all its segments in case of chained buffers. Each + * segment is added back into its original mempool. + * + * @param mp + * The packets mempool. + * @param mbufs + * The packets mbufs array to be freed. + * @param n + * Number of packets. + */ +static inline void rte_pktmbuf_free_bulk(struct rte_mbuf **mbufs, + unsigned int n) +{ + void *tofree[RTE_MBUF_BULK_FREE]; + struct rte_mempool *mp = NULL; + unsigned int i, count = 0; + + for (i = 0; i < n; i++) { + struct rte_mbuf *m, *m_next; + + for (m = mbufs[i]; m; m = m_next) { + m_next = m->next; + + if (count > 0 && + (unlikely(m->pool != mp || + count == RTE_MBUF_BULK_FREE))) { + rte_mempool_put_bulk(mp, tofree, count); + count = 0; + } + + mp = m->pool; + + if (likely(__rte_pktmbuf_prefree_seg(m) != NULL)) { + m->next = NULL; + tofree[count++] = m; + } + } + } + + if (likely(count > 0)) + rte_mempool_put_bulk(mp, tofree, count); +} + +/** * Creates a "clone" of the given packet mbuf. * * Walks through all segments of the given packet mbuf, and for each of them: -- 2.7.4