[dpdk-dev,RFC,6/6] mempool/bucket: implement block dequeue operation

Message ID 1511539591-20966-7-git-send-email-arybchenko@solarflare.com
State Superseded, archived
Delegated to: Thomas Monjalon
Headers show

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Andrew Rybchenko Nov. 24, 2017, 4:06 p.m.
From: "Artem V. Andreev" <Artem.Andreev@oktetlabs.ru>

Signed-off-by: Artem V. Andreev <Artem.Andreev@oktetlabs.ru>
Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
---
 drivers/mempool/bucket/rte_mempool_bucket.c | 38 +++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

Patch

diff --git a/drivers/mempool/bucket/rte_mempool_bucket.c b/drivers/mempool/bucket/rte_mempool_bucket.c
index 4063d2c..ee5a6cf 100644
--- a/drivers/mempool/bucket/rte_mempool_bucket.c
+++ b/drivers/mempool/bucket/rte_mempool_bucket.c
@@ -315,6 +315,42 @@  bucket_dequeue(struct rte_mempool *mp, void **obj_table, unsigned int n)
 	return rc;
 }
 
+static int
+bucket_dequeue_contig_blocks(struct rte_mempool *mp, void **first_obj_table,
+			     unsigned int n)
+{
+	struct bucket_data *data = mp->pool_data;
+	const uint32_t header_size = data->header_size;
+	struct bucket_stack *cur_stack = data->buckets[rte_lcore_id()];
+	unsigned int n_buckets_from_stack = RTE_MIN(n, cur_stack->top);
+	struct bucket_header *hdr;
+	void **first_objp = first_obj_table;
+
+	bucket_adopt_orphans(data);
+
+	n -= n_buckets_from_stack;
+	while (n_buckets_from_stack-- > 0) {
+		hdr = bucket_stack_pop_unsafe(cur_stack);
+		*first_objp++ = (uint8_t *)hdr + header_size;
+	}
+	while (n-- > 0) {
+		if (unlikely(rte_ring_dequeue(data->shared_bucket_ring,
+					      (void **)&hdr) != 0)) {
+			/* Return the already dequeued buckets */
+			while (first_objp-- != first_obj_table) {
+				bucket_stack_push(cur_stack,
+					(uint8_t *)*first_objp - header_size);
+			}
+			rte_errno = ENOBUFS;
+			return -rte_errno;
+		}
+		hdr->lcore_id = rte_lcore_id();
+		*first_objp++ = (uint8_t *)hdr + header_size;
+	}
+
+	return 0;
+}
+
 static unsigned int
 bucket_get_count(const struct rte_mempool *mp)
 {
@@ -468,6 +504,7 @@  bucket_get_info(__rte_unused const struct rte_mempool *mp,
 		mp->trailer_size;
 
 	info->cluster_size = BUCKET_MEM_SIZE / chunk_size;
+	info->contig_block_size = info->cluster_size;
 	return 0;
 }
 
@@ -515,6 +552,7 @@  static const struct rte_mempool_ops ops_bucket = {
 	.get_capabilities = bucket_get_capabilities,
 	.register_memory_area = bucket_register_memory_area,
 	.get_info = bucket_get_info,
+	.dequeue_contig_blocks = bucket_dequeue_contig_blocks,
 };