From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <arybchenko@solarflare.com>
Received: from dispatch1-us1.ppe-hosted.com (dispatch1-us1.ppe-hosted.com
 [67.231.154.164]) by dpdk.org (Postfix) with ESMTP id 2D48ED14E
 for <dev@dpdk.org>; Mon, 16 Apr 2018 15:25:01 +0200 (CEST)
X-Virus-Scanned: Proofpoint Essentials engine
Received: from webmail.solarflare.com (webmail.solarflare.com [12.187.104.26])
 (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits))
 (No client certificate requested)
 by mx1-us4.ppe-hosted.com (Proofpoint Essentials ESMTP Server) with ESMTPS id
 0B0B0140224; Mon, 16 Apr 2018 13:25:00 +0000 (UTC)
Received: from sfocexch01r.SolarFlarecom.com (10.20.40.34) by
 ocex03.SolarFlarecom.com (10.20.40.36) with Microsoft SMTP Server (TLS) id
 15.0.1044.25; Mon, 16 Apr 2018 06:24:54 -0700
Received: from ocex03.SolarFlarecom.com (10.20.40.36) by
 sfocexch01r.SolarFlarecom.com (10.20.40.34) with Microsoft SMTP Server (TLS)
 id 15.0.1044.25; Mon, 16 Apr 2018 06:24:47 -0700
Received: from opal.uk.solarflarecom.com (10.17.10.1) by
 ocex03.SolarFlarecom.com (10.20.40.36) with Microsoft SMTP Server (TLS) id
 15.0.1044.25 via Frontend Transport; Mon, 16 Apr 2018 06:24:46 -0700
Received: from uklogin.uk.solarflarecom.com (uklogin.uk.solarflarecom.com
 [10.17.10.10])
 by opal.uk.solarflarecom.com (8.13.8/8.13.8) with ESMTP id w3GDOjOt012300;
 Mon, 16 Apr 2018 14:24:45 +0100
Received: from uklogin.uk.solarflarecom.com (localhost.localdomain [127.0.0.1])
 by uklogin.uk.solarflarecom.com (8.13.8/8.13.8) with ESMTP id w3GDOiRZ017332; 
 Mon, 16 Apr 2018 14:24:45 +0100
From: Andrew Rybchenko <arybchenko@solarflare.com>
To: <dev@dpdk.org>
CC: Olivier MATZ <olivier.matz@6wind.com>, "Artem V. Andreev"
 <Artem.Andreev@oktetlabs.ru>
Date: Mon, 16 Apr 2018 14:24:40 +0100
Message-ID: <1523885080-17168-12-git-send-email-arybchenko@solarflare.com>
X-Mailer: git-send-email 1.8.2.3
In-Reply-To: <1523885080-17168-1-git-send-email-arybchenko@solarflare.com>
References: <1511539591-20966-1-git-send-email-arybchenko@solarflare.com>
 <1523885080-17168-1-git-send-email-arybchenko@solarflare.com>
MIME-Version: 1.0
Content-Type: text/plain
X-MDID: 1523885100-N9VZbn+fTFmk
Subject: [dpdk-dev] [PATCH v4 11/11] mempool: support flushing the default
	cache of the mempool
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Mon, 16 Apr 2018 13:25:01 -0000

From: "Artem V. Andreev" <Artem.Andreev@oktetlabs.ru>

Mempool get/put API cares about cache itself, but sometimes it is
required to flush the cache explicitly.

The function is moved in the file since it now requires
rte_mempool_default_cache().

Signed-off-by: Artem V. Andreev <Artem.Andreev@oktetlabs.ru>
Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
Acked-by: Olivier Matz <olivier.matz@6wind.com>
---
v3 -> v4:
 - none

v2 -> v3:
 - none

v1 -> v2:
 - none

 lib/librte_mempool/rte_mempool.h | 36 ++++++++++++++++++++----------------
 1 file changed, 20 insertions(+), 16 deletions(-)

diff --git a/lib/librte_mempool/rte_mempool.h b/lib/librte_mempool/rte_mempool.h
index 314f909..3e06ae0 100644
--- a/lib/librte_mempool/rte_mempool.h
+++ b/lib/librte_mempool/rte_mempool.h
@@ -1169,22 +1169,6 @@ void
 rte_mempool_cache_free(struct rte_mempool_cache *cache);
 
 /**
- * Flush a user-owned mempool cache to the specified mempool.
- *
- * @param cache
- *   A pointer to the mempool cache.
- * @param mp
- *   A pointer to the mempool.
- */
-static __rte_always_inline void
-rte_mempool_cache_flush(struct rte_mempool_cache *cache,
-			struct rte_mempool *mp)
-{
-	rte_mempool_ops_enqueue_bulk(mp, cache->objs, cache->len);
-	cache->len = 0;
-}
-
-/**
  * Get a pointer to the per-lcore default mempool cache.
  *
  * @param mp
@@ -1207,6 +1191,26 @@ rte_mempool_default_cache(struct rte_mempool *mp, unsigned lcore_id)
 }
 
 /**
+ * Flush a user-owned mempool cache to the specified mempool.
+ *
+ * @param cache
+ *   A pointer to the mempool cache.
+ * @param mp
+ *   A pointer to the mempool.
+ */
+static __rte_always_inline void
+rte_mempool_cache_flush(struct rte_mempool_cache *cache,
+			struct rte_mempool *mp)
+{
+	if (cache == NULL)
+		cache = rte_mempool_default_cache(mp, rte_lcore_id());
+	if (cache == NULL || cache->len == 0)
+		return;
+	rte_mempool_ops_enqueue_bulk(mp, cache->objs, cache->len);
+	cache->len = 0;
+}
+
+/**
  * @internal Put several objects back in the mempool; used internally.
  * @param mp
  *   A pointer to the mempool structure.
-- 
2.7.4