Skip to contentSkip to conversation

reorder: introduce new APIs

PATCH Superseded Volodymyr Fialko 3 participants 13 messages Jan 20, 2023 – Feb 20, 2023

lore
Share & tools
lore
#0 lore raw

cover reorder: introduce new APIs

This patch series provides new APIs for reorder library and test cases for them.

Volodymyr Fialko (3):
reorder: add new drain up to seq number API
reorder: add ability to set min sequence number
test/reorder: add cases to cover new API

 app/test/test_reorder.c   | 160 ++++++++++++++++++++++++++++++++++++++
 lib/reorder/rte_reorder.c | 108 +++++++++++++++++++++++++
 lib/reorder/rte_reorder.h |  43 ++++++++++
 lib/reorder/version.map   |   2 +
 4 files changed, 313 insertions(+)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/3 reorder: add new drain up to seq number API

Introduce new reorder drain API:
rte_reorder_drain_up_to_seqn - exhaustively drain all inserted mbufs up to the given sequence number.

Currently there's no ability to force the drain from reorder buffer, i.e. only consecutive ordered or ready packets could be drained. New function would give user ability to drain inserted packets, without need to wait for missing or newer packets.

---
 lib/reorder/rte_reorder.c | 77 +++++++++++++++++++++++++++++++++++++++
 lib/reorder/rte_reorder.h | 25 +++++++++++++
 lib/reorder/version.map   |  1 +
 3 files changed, 103 insertions(+)
lib/reorder/rte_reorder.c +77 -0
index 385ee479da..57cc1b286b 100644
@@ -406,3 +406,80 @@ rte_reorder_drain(struct rte_reorder_buffer *b, struct rte_mbuf **mbufs,
 
 	return drain_cnt;
 }
+
+/* Binary search seqn in ready buffer */
+static inline uint32_t
+ready_buffer_seqn_find(const struct cir_buffer *ready_buf, const uint32_t seqn)
+{
+	uint32_t mid, value, position, high;
+	uint32_t low = 0;
+
+	if (ready_buf->tail > ready_buf->head)
+		high = ready_buf->tail - ready_buf->head;
+	else
+		high = ready_buf->head - ready_buf->tail;
+
+	while (low <= high) {
+		mid = low + (high - low) / 2;
+		position = (ready_buf->tail + mid) & ready_buf->mask;
+		value = *rte_reorder_seqn(ready_buf->entries[position]);
+		if (seqn == value)
+			return mid;
+		else if (seqn > value)
+			low = mid + 1;
+		else
+			high = mid - 1;
+	}
+
+	return low;
+}
+
+unsigned int
+rte_reorder_drain_up_to_seqn(struct rte_reorder_buffer *b, struct rte_mbuf **mbufs,
+		const unsigned int max_mbufs, const rte_reorder_seqn_t seqn)
+{
+	uint32_t i, position, offset;
+	unsigned int drain_cnt = 0;
+
+	struct cir_buffer *order_buf = &b->order_buf,
+			*ready_buf = &b->ready_buf;
+
+	/* Seqn in Ready buffer */
+	if (seqn < b->min_seqn) {
+		/* All sequence numbers are higher then given */
+		if (*rte_reorder_seqn(ready_buf->entries[ready_buf->tail]) > seqn)
+			return 0;
+
+		offset = ready_buffer_seqn_find(ready_buf, seqn);
+
+		for (i = 0; (i < offset) && (drain_cnt < max_mbufs); i++) {
+			position = (ready_buf->tail + i) & ready_buf->mask;
+			mbufs[drain_cnt++] = ready_buf->entries[position];
+			ready_buf->entries[position] = NULL;
+		}
+		ready_buf->tail = (ready_buf->tail + i) & ready_buf->mask;
+
+		return drain_cnt;
+	}
+
+	/* Seqn in Order buffer, add all buffers from Ready buffer */
+	while ((drain_cnt < max_mbufs) && (ready_buf->tail != ready_buf->head)) {
+		mbufs[drain_cnt++] = ready_buf->entries[ready_buf->tail];
+		ready_buf->entries[ready_buf->tail] = NULL;
+		ready_buf->tail = (ready_buf->tail + 1) & ready_buf->mask;
+	}
+
+	/* Fetch buffers from Order buffer up to given sequence number (exclusive) */
+	offset = RTE_MIN(seqn - b->min_seqn, b->order_buf.size);
+	for (i = 0; (i < offset) && (drain_cnt < max_mbufs); i++) {
+		position = (order_buf->head + i) & order_buf->mask;
+		if (order_buf->entries[position] == NULL)
+			continue;
+		mbufs[drain_cnt++] = order_buf->entries[position];
+		order_buf->entries[position] = NULL;
+	}
+	b->min_seqn += i;
+	order_buf->head = (order_buf->head + i) & order_buf->mask;
+
+	return drain_cnt;
+}
lib/reorder/rte_reorder.h +25 -0
index 5abdb258e2..c5b354b53d 100644
@@ -167,6 +167,31 @@ unsigned int
 rte_reorder_drain(struct rte_reorder_buffer *b, struct rte_mbuf **mbufs,
 		unsigned max_mbufs);
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice
+ *
+ * Fetch set of reordered packets up to specified sequence number (exclusive)
+ *
+ * Returns a set of in-order packets from the reorder buffer structure.
+ * Gaps may be present since reorder buffer will try to fetch all possible packets up to given
+ * sequence number.
+ *
+ * @param b
+ *   Reorder buffer instance from which packets are to be drained.
+ * @param mbufs
+ *   Array of mbufs where reordered packets will be inserted from reorder buffer.
+ * @param max_mbufs
+ *   The number of elements in the mbufs array.
+ * @param seqn
+ *   Sequence number up to which buffer will be drained.
+ * @return
+ *   Number of mbuf pointers written to mbufs. 0 <= N < max_mbufs.
+ */
+__rte_experimental
+unsigned int
+rte_reorder_drain_up_to_seqn(struct rte_reorder_buffer *b, struct rte_mbuf **mbufs,
+		unsigned int max_mbufs, rte_reorder_seqn_t seqn);
 #ifdef __cplusplus
 }
 #endif
lib/reorder/version.map +1 -0
index e114d17730..e3f41ea7ef 100644
@@ -16,4 +16,5 @@ EXPERIMENTAL {
 	global:
 
 	rte_reorder_seqn_dynfield_offset;
+	rte_reorder_drain_up_to_seqn;
 };
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH 1/3] reorder: add new drain up to seq number API

We are waiting for a detailed review.
The series could be merged without review.

Please fix cosmetic comments below and send a new version to check CI result.

20/01/2023 11:21, Volodymyr Fialko:

Quoted 10 lines

Introduce new reorder drain API:
rte_reorder_drain_up_to_seqn - exhaustively drain all inserted mbufs up to the given sequence number.

Currently there's no ability to force the drain from reorder buffer, i.e. only consecutive ordered or ready packets could be drained. New function would give user ability to drain inserted packets, without need to wait for missing or newer packets.

[...]

Quoted 22 lines
lib/reorder/rte_reorder.h +16 -0
@@ -167,6 +167,31 @@ unsigned int
 rte_reorder_drain(struct rte_reorder_buffer *b, struct rte_mbuf **mbufs,
 		unsigned max_mbufs);
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice
+ *
+ * Fetch set of reordered packets up to specified sequence number (exclusive)
+ *
+ * Returns a set of in-order packets from the reorder buffer structure.
+ * Gaps may be present since reorder buffer will try to fetch all possible packets up to given
+ * sequence number.
+ *
+ * @param b
+ *   Reorder buffer instance from which packets are to be drained.
+ * @param mbufs
+ *   Array of mbufs where reordered packets will be inserted from reorder buffer.
+ * @param max_mbufs
+ *   The number of elements in the mbufs array.

lib/reorder/rte_reorder.h unsigned int · line 195

Quoted 10 lines
lib/reorder/rte_reorder.h +9 -0
+ * @param seqn
+ *   Sequence number up to which buffer will be drained.
+ * @return
+ *   Number of mbuf pointers written to mbufs. 0 <= N < max_mbufs.
+ */
+__rte_experimental
+unsigned int
+rte_reorder_drain_up_to_seqn(struct rte_reorder_buffer *b, struct rte_mbuf **mbufs,
+		unsigned int max_mbufs, rte_reorder_seqn_t seqn);
 #ifdef __cplusplus

blank line missing

lib/reorder/version.map EXPERIMENTAL { · line 19

Quoted 7 lines
lib/reorder/version.map +1 -0
@@ -16,4 +16,5 @@ EXPERIMENTAL {
 	global:
 
 	rte_reorder_seqn_dynfield_offset;
+	rte_reorder_drain_up_to_seqn;

Please add a comment "# added in 23.03" as we do in other libs.

#3 lore raw

PATCH 2/3 reorder: add ability to set min sequence number

In reply to Volodymyr Fialko

Add API rte_reorder_min_seqn_set to allow user to specify minimum sequence number.
Currently sequence number of first inserted packet is used as minimum sequence number. But for case when we want to wait for packets before the received one this will not work.

---
 lib/reorder/rte_reorder.c | 31 +++++++++++++++++++++++++++++++
 lib/reorder/rte_reorder.h | 18 ++++++++++++++++++
 lib/reorder/version.map   |  1 +
 3 files changed, 50 insertions(+)
lib/reorder/rte_reorder.c +31 -0
index 57cc1b286b..0d4c7209f9 100644
@@ -483,3 +483,34 @@ rte_reorder_drain_up_to_seqn(struct rte_reorder_buffer *b, struct rte_mbuf **mbu
 
 	return drain_cnt;
 }
+
+static bool
+rte_reorder_is_empty(const struct rte_reorder_buffer *b)
+{
+	const struct cir_buffer *order_buf = &b->order_buf, *ready_buf = &b->ready_buf;
+	unsigned int i;
+
+	/* Ready buffer does not have gaps */
+	if (ready_buf->tail != ready_buf->head)
+		return false;
+
+	/* Order buffer could have gaps, iterate */
+	for (i = 0; i < order_buf->size; i++) {
+		if (order_buf->entries[i] != NULL)
+			return false;
+	}
+
+	return true;
+}
+
+unsigned int
+rte_reorder_min_seqn_set(struct rte_reorder_buffer *b, uint32_t min_seqn)
+{
+	if (!rte_reorder_is_empty(b))
+		return -ENOTEMPTY;
+
+	b->min_seqn = min_seqn;
+	b->is_initialized = true;
+
+	return 0;
+}
lib/reorder/rte_reorder.h +18 -0
index c5b354b53d..9f6710bad2 100644
@@ -192,6 +192,24 @@ __rte_experimental
 unsigned int
 rte_reorder_drain_up_to_seqn(struct rte_reorder_buffer *b, struct rte_mbuf **mbufs,
 		unsigned int max_mbufs, rte_reorder_seqn_t seqn);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice
+ *
+ * Set minimum sequence number of packet allowed to be buffered.
+ * To successfully set new value reorder buffer has to be empty(after create, reset or drain_all).
+ *
+ * @param b
+ *   Empty reorder buffer instance to modify.
+ * @param min_seqn
+ *   New sequence number to set.
+ * @return
+ *   0 on success, a negative value otherwise.
+ */
+__rte_experimental
+unsigned int
+rte_reorder_min_seqn_set(struct rte_reorder_buffer *b, uint32_t min_seqn);
 #ifdef __cplusplus
 }
 #endif
lib/reorder/version.map +1 -0
index e3f41ea7ef..aafdf0b5ae 100644
@@ -17,4 +17,5 @@ EXPERIMENTAL {
 
 	rte_reorder_seqn_dynfield_offset;
 	rte_reorder_drain_up_to_seqn;
+	rte_reorder_min_seqn_set;
 };
Signature · 1 line
2.34.1
#4 lore raw

PATCH 3/3 test/reorder: add cases to cover new API

In reply to Volodymyr Fialko

Add new test cases to cover rte_reorder_drain_up_to_seqn and rte_reorder_min_seqn_set.

---
 app/test/test_reorder.c | 160 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 160 insertions(+)
app/test/test_reorder.c +160 -0
index f0714a5c18..c345a72e0c 100644
@@ -335,6 +335,164 @@ test_reorder_drain(void)
 	return ret;
 }
 
+static void
+buffer_to_reorder_move(struct rte_mbuf **mbuf, struct rte_reorder_buffer *b)
+{
+	rte_reorder_insert(b, *mbuf);
+	*mbuf = NULL;
+}
+
+static int
+test_reorder_drain_up_to_seqn(void)
+{
+	struct rte_mempool *p = test_params->p;
+	struct rte_reorder_buffer *b = NULL;
+	const unsigned int num_bufs = 10;
+	const unsigned int size = 4;
+	unsigned int i, cnt;
+	int ret = 0;
+
+	struct rte_mbuf *bufs[num_bufs];
+	struct rte_mbuf *robufs[num_bufs];
+
+	/* initialize all robufs to NULL */
+	memset(robufs, 0, sizeof(robufs));
+
+	/* This would create a reorder buffer instance consisting of:
+	 * reorder_seq = 0
+	 * ready_buf: RB[size] = {NULL, NULL, NULL, NULL}
+	 * order_buf: OB[size] = {NULL, NULL, NULL, NULL}
+	 */
+	b = rte_reorder_create("test_drain_up_to_seqn", rte_socket_id(), size);
+	TEST_ASSERT_NOT_NULL(b, "Failed to create reorder buffer");
+
+	for (i = 0; i < num_bufs; i++) {
+		bufs[i] = rte_pktmbuf_alloc(p);
+		TEST_ASSERT_NOT_NULL(bufs[i], "Packet allocation failed\n");
+		*rte_reorder_seqn(bufs[i]) = i;
+	}
+
+	/* Insert packet with seqn 1 and 3:
+	 * RB[] = {NULL, NULL, NULL, NULL}
+	 * OB[] = {1, 2, 3, NULL}
+	 */
+	buffer_to_reorder_move(&bufs[1], b);
+	buffer_to_reorder_move(&bufs[2], b);
+	buffer_to_reorder_move(&bufs[3], b);
+	/* Draining 1, 2 */
+	cnt = rte_reorder_drain_up_to_seqn(b, robufs, num_bufs, 3);
+	if (cnt != 2) {
+		printf("%s:%d:%d: number of expected packets not drained\n",
+				__func__, __LINE__, cnt);
+		ret = -1;
+		goto exit;
+	}
+	for (i = 0; i < 2; i++)
+		rte_pktmbuf_free(robufs[i]);
+	memset(robufs, 0, sizeof(robufs));
+
+	/* Insert more packets
+	 * RB[] = {NULL, NULL, NULL, NULL}
+	 * OB[] = {3, 4, NULL, 6}
+	 */
+	buffer_to_reorder_move(&bufs[4], b);
+	buffer_to_reorder_move(&bufs[6], b);
+	/* Insert more packets to utilize Ready buffer
+	 * RB[] = {3, NULL, 5, 6}
+	 * OB[] = {NULL, NULL, 8, NULL}
+	 */
+	buffer_to_reorder_move(&bufs[8], b);
+
+	/* Drain 3 and 5 */
+	cnt = rte_reorder_drain_up_to_seqn(b, robufs, num_bufs, 6);
+	if (cnt != 2) {
+		printf("%s:%d:%d: number of expected packets not drained\n",
+				__func__, __LINE__, cnt);
+		ret = -1;
+		goto exit;
+	}
+	for (i = 0; i < 2; i++)
+		rte_pktmbuf_free(robufs[i]);
+	memset(robufs, 0, sizeof(robufs));
+
+	ret = 0;
+exit:
+	rte_reorder_free(b);
+	for (i = 0; i < num_bufs; i++) {
+		rte_pktmbuf_free(bufs[i]);
+		rte_pktmbuf_free(robufs[i]);
+	}
+	return ret;
+}
+
+static int
+test_reorder_set_seqn(void)
+{
+	struct rte_mempool *p = test_params->p;
+	struct rte_reorder_buffer *b = NULL;
+	const unsigned int num_bufs = 7;
+	const unsigned int size = 4;
+	unsigned int i;
+	int ret = 0;
+
+	struct rte_mbuf *bufs[num_bufs];
+
+	/* This would create a reorder buffer instance consisting of:
+	 * reorder_seq = 0
+	 * ready_buf: RB[size] = {NULL, NULL, NULL, NULL}
+	 * order_buf: OB[size] = {NULL, NULL, NULL, NULL}
+	 */
+	b = rte_reorder_create("test_min_seqn_set", rte_socket_id(), size);
+	TEST_ASSERT_NOT_NULL(b, "Failed to create reorder buffer");
+
+	for (i = 0; i < num_bufs; i++) {
+		bufs[i] = rte_pktmbuf_alloc(p);
+		if (bufs[i] == NULL) {
+			printf("Packet allocation failed\n");
+			goto exit;
+		}
+		*rte_reorder_seqn(bufs[i]) = i;
+	}
+
+	ret = rte_reorder_min_seqn_set(b, 5);
+	if (ret != 0) {
+		printf("%s:%d: Error in setting min sequence number\n", __func__, __LINE__);
+		ret = -1;
+		goto exit;
+	}
+
+	ret = rte_reorder_insert(b, bufs[0]);
+	if (ret >= 0) {
+		printf("%s:%d: Insertion with value less the min seq number\n", __func__, __LINE__);
+		ret = -1;
+		goto exit;
+	}
+
+	ret = rte_reorder_insert(b, bufs[5]);
+	if (ret != 0) {
+		printf("%s:%d: Error inserting packet with valid seqn\n", __func__, __LINE__);
+		ret = -1;
+		goto exit;
+	}
+	bufs[5] = NULL;
+
+	ret = rte_reorder_min_seqn_set(b, 0);
+	if (ret >= 0) {
+		printf("%s:%d: Error in setting min sequence number with non-empty buffer\n",
+				__func__, __LINE__);
+		ret = -1;
+		goto exit;
+	}
+
+	ret = 0;
+exit:
+	rte_reorder_free(b);
+	for (i = 0; i < num_bufs; i++)
+		rte_pktmbuf_free(bufs[i]);
+
+	return ret;
+}
+
 static int
 test_setup(void)
 {
@@ -385,6 +543,8 @@ static struct unit_test_suite reorder_test_suite  = {
 		TEST_CASE(test_reorder_free),
 		TEST_CASE(test_reorder_insert),
 		TEST_CASE(test_reorder_drain),
+		TEST_CASE(test_reorder_drain_up_to_seqn),
+		TEST_CASE(test_reorder_set_seqn),
 		TEST_CASES_END()
 	}
 };
Signature · 1 line
2.34.1
#5 lore raw

RE: [PATCH 3/3] test/reorder: add cases to cover new API

Depends-on: series-26425 ("lib/reorder: fix drain/free issues")

Test failure is caused by this bug in drain/api test - http://patches.dpdk.org/project/dpdk/list/?series=26425
It wasn't seen before seen before because drain was the last test, but now following test receive pointer to same packet twice due to double free.

Quoted 194 lines

-----Original Message-----
From: Volodymyr Fialko <[email protected]>
Sent: Friday, January 20, 2023 11:22 AM
To: [email protected]; Reshma Pattan <[email protected]>
Cc: Jerin Jacob Kollanukkaran <[email protected]>; Anoob Joseph <[email protected]>; Volodymyr Fialko <[email protected]>
Subject: [PATCH 3/3] test/reorder: add cases to cover new API

Add new test cases to cover rte_reorder_drain_up_to_seqn and rte_reorder_min_seqn_set.

---
 app/test/test_reorder.c | 160 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 160 insertions(+)
app/test/test_reorder.c +160 -1
@@ -335,6 +335,164 @@ test_reorder_drain(void)
 	return ret;
 }
 
+static void
+buffer_to_reorder_move(struct rte_mbuf **mbuf, struct
+rte_reorder_buffer *b) {
+	rte_reorder_insert(b, *mbuf);
+	*mbuf = NULL;
+}
+
+static int
+test_reorder_drain_up_to_seqn(void)
+{
+	struct rte_mempool *p = test_params->p;
+	struct rte_reorder_buffer *b = NULL;
+	const unsigned int num_bufs = 10;
+	const unsigned int size = 4;
+	unsigned int i, cnt;
+	int ret = 0;
+
+	struct rte_mbuf *bufs[num_bufs];
+	struct rte_mbuf *robufs[num_bufs];
+
+	/* initialize all robufs to NULL */
+	memset(robufs, 0, sizeof(robufs));
+
+	/* This would create a reorder buffer instance consisting of:
+	 * reorder_seq = 0
+	 * ready_buf: RB[size] = {NULL, NULL, NULL, NULL}
+	 * order_buf: OB[size] = {NULL, NULL, NULL, NULL}
+	 */
+	b = rte_reorder_create("test_drain_up_to_seqn", rte_socket_id(), size);
+	TEST_ASSERT_NOT_NULL(b, "Failed to create reorder buffer");
+
+	for (i = 0; i < num_bufs; i++) {
+		bufs[i] = rte_pktmbuf_alloc(p);
+		TEST_ASSERT_NOT_NULL(bufs[i], "Packet allocation failed\n");
+		*rte_reorder_seqn(bufs[i]) = i;
+	}
+
+	/* Insert packet with seqn 1 and 3:
+	 * RB[] = {NULL, NULL, NULL, NULL}
+	 * OB[] = {1, 2, 3, NULL}
+	 */
+	buffer_to_reorder_move(&bufs[1], b);
+	buffer_to_reorder_move(&bufs[2], b);
+	buffer_to_reorder_move(&bufs[3], b);
+	/* Draining 1, 2 */
+	cnt = rte_reorder_drain_up_to_seqn(b, robufs, num_bufs, 3);
+	if (cnt != 2) {
+		printf("%s:%d:%d: number of expected packets not drained\n",
+				__func__, __LINE__, cnt);
+		ret = -1;
+		goto exit;
+	}
+	for (i = 0; i < 2; i++)
+		rte_pktmbuf_free(robufs[i]);
+	memset(robufs, 0, sizeof(robufs));
+
+	/* Insert more packets
+	 * RB[] = {NULL, NULL, NULL, NULL}
+	 * OB[] = {3, 4, NULL, 6}
+	 */
+	buffer_to_reorder_move(&bufs[4], b);
+	buffer_to_reorder_move(&bufs[6], b);
+	/* Insert more packets to utilize Ready buffer
+	 * RB[] = {3, NULL, 5, 6}
+	 * OB[] = {NULL, NULL, 8, NULL}
+	 */
+	buffer_to_reorder_move(&bufs[8], b);
+
+	/* Drain 3 and 5 */
+	cnt = rte_reorder_drain_up_to_seqn(b, robufs, num_bufs, 6);
+	if (cnt != 2) {
+		printf("%s:%d:%d: number of expected packets not drained\n",
+				__func__, __LINE__, cnt);
+		ret = -1;
+		goto exit;
+	}
+	for (i = 0; i < 2; i++)
+		rte_pktmbuf_free(robufs[i]);
+	memset(robufs, 0, sizeof(robufs));
+
+	ret = 0;
+exit:
+	rte_reorder_free(b);
+	for (i = 0; i < num_bufs; i++) {
+		rte_pktmbuf_free(bufs[i]);
+		rte_pktmbuf_free(robufs[i]);
+	}
+	return ret;
+}
+
+static int
+test_reorder_set_seqn(void)
+{
+	struct rte_mempool *p = test_params->p;
+	struct rte_reorder_buffer *b = NULL;
+	const unsigned int num_bufs = 7;
+	const unsigned int size = 4;
+	unsigned int i;
+	int ret = 0;
+
+	struct rte_mbuf *bufs[num_bufs];
+
+	/* This would create a reorder buffer instance consisting of:
+	 * reorder_seq = 0
+	 * ready_buf: RB[size] = {NULL, NULL, NULL, NULL}
+	 * order_buf: OB[size] = {NULL, NULL, NULL, NULL}
+	 */
+	b = rte_reorder_create("test_min_seqn_set", rte_socket_id(), size);
+	TEST_ASSERT_NOT_NULL(b, "Failed to create reorder buffer");
+
+	for (i = 0; i < num_bufs; i++) {
+		bufs[i] = rte_pktmbuf_alloc(p);
+		if (bufs[i] == NULL) {
+			printf("Packet allocation failed\n");
+			goto exit;
+		}
+		*rte_reorder_seqn(bufs[i]) = i;
+	}
+
+	ret = rte_reorder_min_seqn_set(b, 5);
+	if (ret != 0) {
+		printf("%s:%d: Error in setting min sequence number\n", __func__, __LINE__);
+		ret = -1;
+		goto exit;
+	}
+
+	ret = rte_reorder_insert(b, bufs[0]);
+	if (ret >= 0) {
+		printf("%s:%d: Insertion with value less the min seq number\n", __func__, __LINE__);
+		ret = -1;
+		goto exit;
+	}
+
+	ret = rte_reorder_insert(b, bufs[5]);
+	if (ret != 0) {
+		printf("%s:%d: Error inserting packet with valid seqn\n", __func__, __LINE__);
+		ret = -1;
+		goto exit;
+	}
+	bufs[5] = NULL;
+
+	ret = rte_reorder_min_seqn_set(b, 0);
+	if (ret >= 0) {
+		printf("%s:%d: Error in setting min sequence number with non-empty buffer\n",
+				__func__, __LINE__);
+		ret = -1;
+		goto exit;
+	}
+
+	ret = 0;
+exit:
+	rte_reorder_free(b);
+	for (i = 0; i < num_bufs; i++)
+		rte_pktmbuf_free(bufs[i]);
+
+	return ret;
+}
+
 static int
 test_setup(void)
 {
@@ -385,6 +543,8 @@ static struct unit_test_suite reorder_test_suite  = {
 		TEST_CASE(test_reorder_free),
 		TEST_CASE(test_reorder_insert),
 		TEST_CASE(test_reorder_drain),
+		TEST_CASE(test_reorder_drain_up_to_seqn),
+		TEST_CASE(test_reorder_set_seqn),
 		TEST_CASES_END()
 	}
 };
--

2.34.1

#6 lore raw

Re: [PATCH 3/3] test/reorder: add cases to cover new API

In reply to Volodymyr Fialko

20/01/2023 11:21, Volodymyr Fialko:

Quoted 2 lines

Add new test cases to cover rte_reorder_drain_up_to_seqn and rte_reorder_min_seqn_set.

Instead of doing a separate patch, please squash the tests when adding the new API functions in patches 1 & 2.

#7 lore raw
In reply to Volodymyr Fialko
Quoted 9 lines · Volodymyr Fialko

This patch series provides new APIs for reorder library and test cases for them.

Volodymyr Fialko (3):
reorder: add new drain up to seq number API
reorder: add ability to set min sequence number
test/reorder: add cases to cover new API

Quoted 6 lines
 app/test/test_reorder.c   | 160 ++++++++++++++++++++++++++++++++++++++
 lib/reorder/rte_reorder.c | 108 +++++++++++++++++++++++++
 lib/reorder/rte_reorder.h |  43 ++++++++++
 lib/reorder/version.map   |   2 +
 4 files changed, 313 insertions(+)

Volodymyr, don't forget to Cc: the maintainer.

Reshma, can you review this series?
Thanks.

Signature · 1 line
David Marchand
#8 lore raw

v2 cover reorder: introduce new APIs

In reply to Volodymyr Fialko

This patch series provides new APIs for reorder library and test cases for them.

v2:
- squash tests with corresponding API patches
- address minor comments

Volodymyr Fialko (2):
reorder: add new drain up to seq number API
reorder: add ability to set min sequence number

 app/test/test_reorder.c   | 160 ++++++++++++++++++++++++++++++++++++++
 lib/reorder/rte_reorder.c | 109 ++++++++++++++++++++++++++
 lib/reorder/rte_reorder.h |  44 +++++++++++
 lib/reorder/version.map   |   3 +
 4 files changed, 316 insertions(+)
Signature · 1 line
2.34.1
#9 lore raw

PATCH v2 1/2 reorder: add new drain up to seq number API

Introduce new reorder drain API:
rte_reorder_drain_up_to_seqn - exhaustively drain all inserted mbufs up to the given sequence number.

Currently there's no ability to force the drain from reorder buffer, i.e. only consecutive ordered or ready packets could be drained. New function would give user ability to drain inserted packets, without need to wait for missing or newer packets.

---
 app/test/test_reorder.c   | 91 +++++++++++++++++++++++++++++++++++++++
 lib/reorder/rte_reorder.c | 78 +++++++++++++++++++++++++++++++++
 lib/reorder/rte_reorder.h | 26 +++++++++++
 lib/reorder/version.map   |  2 +
 4 files changed, 197 insertions(+)
app/test/test_reorder.c +91 -0
index 7b5e590bac..a37dc28f65 100644
@@ -337,6 +337,96 @@ test_reorder_drain(void)
 	return ret;
 }
 
+static void
+buffer_to_reorder_move(struct rte_mbuf **mbuf, struct rte_reorder_buffer *b)
+{
+	rte_reorder_insert(b, *mbuf);
+	*mbuf = NULL;
+}
+
+static int
+test_reorder_drain_up_to_seqn(void)
+{
+	struct rte_mempool *p = test_params->p;
+	struct rte_reorder_buffer *b = NULL;
+	const unsigned int num_bufs = 10;
+	const unsigned int size = 4;
+	unsigned int i, cnt;
+	int ret = 0;
+
+	struct rte_mbuf *bufs[num_bufs];
+	struct rte_mbuf *robufs[num_bufs];
+
+	/* initialize all robufs to NULL */
+	memset(robufs, 0, sizeof(robufs));
+
+	/* This would create a reorder buffer instance consisting of:
+	 * reorder_seq = 0
+	 * ready_buf: RB[size] = {NULL, NULL, NULL, NULL}
+	 * order_buf: OB[size] = {NULL, NULL, NULL, NULL}
+	 */
+	b = rte_reorder_create("test_drain_up_to_seqn", rte_socket_id(), size);
+	TEST_ASSERT_NOT_NULL(b, "Failed to create reorder buffer");
+
+	for (i = 0; i < num_bufs; i++) {
+		bufs[i] = rte_pktmbuf_alloc(p);
+		TEST_ASSERT_NOT_NULL(bufs[i], "Packet allocation failed\n");
+		*rte_reorder_seqn(bufs[i]) = i;
+	}
+
+	/* Insert packet with seqn 1 and 3:
+	 * RB[] = {NULL, NULL, NULL, NULL}
+	 * OB[] = {1, 2, 3, NULL}
+	 */
+	buffer_to_reorder_move(&bufs[1], b);
+	buffer_to_reorder_move(&bufs[2], b);
+	buffer_to_reorder_move(&bufs[3], b);
+	/* Draining 1, 2 */
+	cnt = rte_reorder_drain_up_to_seqn(b, robufs, num_bufs, 3);
+	if (cnt != 2) {
+		printf("%s:%d:%d: number of expected packets not drained\n",
+				__func__, __LINE__, cnt);
+		ret = -1;
+		goto exit;
+	}
+	for (i = 0; i < 2; i++)
+		rte_pktmbuf_free(robufs[i]);
+	memset(robufs, 0, sizeof(robufs));
+
+	/* Insert more packets
+	 * RB[] = {NULL, NULL, NULL, NULL}
+	 * OB[] = {3, 4, NULL, 6}
+	 */
+	buffer_to_reorder_move(&bufs[4], b);
+	buffer_to_reorder_move(&bufs[6], b);
+	/* Insert more packets to utilize Ready buffer
+	 * RB[] = {3, NULL, 5, 6}
+	 * OB[] = {NULL, NULL, 8, NULL}
+	 */
+	buffer_to_reorder_move(&bufs[8], b);
+
+	/* Drain 3 and 5 */
+	cnt = rte_reorder_drain_up_to_seqn(b, robufs, num_bufs, 6);
+	if (cnt != 2) {
+		printf("%s:%d:%d: number of expected packets not drained\n",
+				__func__, __LINE__, cnt);
+		ret = -1;
+		goto exit;
+	}
+	for (i = 0; i < 2; i++)
+		rte_pktmbuf_free(robufs[i]);
+	memset(robufs, 0, sizeof(robufs));
+
+	ret = 0;
+exit:
+	rte_reorder_free(b);
+	for (i = 0; i < num_bufs; i++) {
+		rte_pktmbuf_free(bufs[i]);
+		rte_pktmbuf_free(robufs[i]);
+	}
+	return ret;
+}
+
 static int
 test_setup(void)
 {
@@ -387,6 +477,7 @@ static struct unit_test_suite reorder_test_suite  = {
 		TEST_CASE(test_reorder_free),
 		TEST_CASE(test_reorder_insert),
 		TEST_CASE(test_reorder_drain),
+		TEST_CASE(test_reorder_drain_up_to_seqn),
 		TEST_CASES_END()
 	}
 };
lib/reorder/rte_reorder.c +78 -0

81 lines not on this page · raw message

lib/reorder/rte_reorder.h +26 -0
index 5abdb258e2..db740495be 100644
@@ -167,6 +167,32 @@ unsigned int
 rte_reorder_drain(struct rte_reorder_buffer *b, struct rte_mbuf **mbufs,
 		unsigned max_mbufs);
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice
+ *
+ * Fetch set of reordered packets up to specified sequence number (exclusive)
+ *
+ * Returns a set of in-order packets from the reorder buffer structure.
+ * Gaps may be present since reorder buffer will try to fetch all possible packets up to given
+ * sequence number.
+ *
+ * @param b
+ *   Reorder buffer instance from which packets are to be drained.
+ * @param mbufs
+ *   Array of mbufs where reordered packets will be inserted from reorder buffer.
+ * @param max_mbufs
+ *   The number of elements in the mbufs array.
+ * @param seqn
+ *   Sequence number up to which buffer will be drained.
+ * @return
+ *   Number of mbuf pointers written to mbufs. 0 <= N < max_mbufs.
+ */
+__rte_experimental
+unsigned int
+rte_reorder_drain_up_to_seqn(struct rte_reorder_buffer *b, struct rte_mbuf **mbufs,
+		unsigned int max_mbufs, rte_reorder_seqn_t seqn);
+
 #ifdef __cplusplus
 }
 #endif
lib/reorder/version.map +2 -0
index e114d17730..d322da03bd 100644
@@ -16,4 +16,6 @@ EXPERIMENTAL {
 	global:
 
 	rte_reorder_seqn_dynfield_offset;
+	# added in 23.03
+	rte_reorder_drain_up_to_seqn;
 };
Signature · 1 line
2.34.1
#10 lore raw

PATCH v2 2/2 reorder: add ability to set min sequence number

In reply to Volodymyr Fialko

Add API rte_reorder_min_seqn_set to allow user to specify minimum sequence number.
Currently sequence number of first inserted packet is used as minimum sequence number. But for case when we want to wait for packets before the received one this will not work.

---
 app/test/test_reorder.c   | 69 +++++++++++++++++++++++++++++++++++++++
 lib/reorder/rte_reorder.c | 31 ++++++++++++++++++
 lib/reorder/rte_reorder.h | 18 ++++++++++
 lib/reorder/version.map   |  1 +
 4 files changed, 119 insertions(+)
app/test/test_reorder.c +69 -0
index a37dc28f65..f391597a78 100644
@@ -427,6 +427,74 @@ test_reorder_drain_up_to_seqn(void)
 	return ret;
 }
 
+static int
+test_reorder_set_seqn(void)
+{
+	struct rte_mempool *p = test_params->p;
+	struct rte_reorder_buffer *b = NULL;
+	const unsigned int num_bufs = 7;
+	const unsigned int size = 4;
+	unsigned int i;
+	int ret = 0;
+
+	struct rte_mbuf *bufs[num_bufs];
+
+	/* This would create a reorder buffer instance consisting of:
+	 * reorder_seq = 0
+	 * ready_buf: RB[size] = {NULL, NULL, NULL, NULL}
+	 * order_buf: OB[size] = {NULL, NULL, NULL, NULL}
+	 */
+	b = rte_reorder_create("test_min_seqn_set", rte_socket_id(), size);
+	TEST_ASSERT_NOT_NULL(b, "Failed to create reorder buffer");
+
+	for (i = 0; i < num_bufs; i++) {
+		bufs[i] = rte_pktmbuf_alloc(p);
+		if (bufs[i] == NULL) {
+			printf("Packet allocation failed\n");
+			goto exit;
+		}
+		*rte_reorder_seqn(bufs[i]) = i;
+	}
+
+	ret = rte_reorder_min_seqn_set(b, 5);
+	if (ret != 0) {
+		printf("%s:%d: Error in setting min sequence number\n", __func__, __LINE__);
+		ret = -1;
+		goto exit;
+	}
+
+	ret = rte_reorder_insert(b, bufs[0]);
+	if (ret >= 0) {
+		printf("%s:%d: Insertion with value less the min seq number\n", __func__, __LINE__);
+		ret = -1;
+		goto exit;
+	}
+
+	ret = rte_reorder_insert(b, bufs[5]);
+	if (ret != 0) {
+		printf("%s:%d: Error inserting packet with valid seqn\n", __func__, __LINE__);
+		ret = -1;
+		goto exit;
+	}
+	bufs[5] = NULL;
+
+	ret = rte_reorder_min_seqn_set(b, 0);
+	if (ret >= 0) {
+		printf("%s:%d: Error in setting min sequence number with non-empty buffer\n",
+				__func__, __LINE__);
+		ret = -1;
+		goto exit;
+	}
+
+	ret = 0;
+exit:
+	rte_reorder_free(b);
+	for (i = 0; i < num_bufs; i++)
+		rte_pktmbuf_free(bufs[i]);
+
+	return ret;
+}
+
 static int
 test_setup(void)
 {
@@ -478,6 +546,7 @@ static struct unit_test_suite reorder_test_suite  = {
 		TEST_CASE(test_reorder_insert),
 		TEST_CASE(test_reorder_drain),
 		TEST_CASE(test_reorder_drain_up_to_seqn),
+		TEST_CASE(test_reorder_set_seqn),
 		TEST_CASES_END()
 	}
 };
lib/reorder/rte_reorder.c +31 -0
index bd0e1f8793..6e029c9e02 100644
@@ -485,3 +485,34 @@ rte_reorder_drain_up_to_seqn(struct rte_reorder_buffer *b, struct rte_mbuf **mbu
 
 	return drain_cnt;
 }
+
+static bool
+rte_reorder_is_empty(const struct rte_reorder_buffer *b)
+{
+	const struct cir_buffer *order_buf = &b->order_buf, *ready_buf = &b->ready_buf;
+	unsigned int i;
+
+	/* Ready buffer does not have gaps */
+	if (ready_buf->tail != ready_buf->head)
+		return false;
+
+	/* Order buffer could have gaps, iterate */
+	for (i = 0; i < order_buf->size; i++) {
+		if (order_buf->entries[i] != NULL)
+			return false;
+	}
+
+	return true;
+}
+
+unsigned int
+rte_reorder_min_seqn_set(struct rte_reorder_buffer *b, rte_reorder_seqn_t min_seqn)
+{
+	if (!rte_reorder_is_empty(b))
+		return -ENOTEMPTY;
+
+	b->min_seqn = min_seqn;
+	b->is_initialized = true;
+
+	return 0;
+}
lib/reorder/rte_reorder.h +18 -0
index db740495be..cc95015fa6 100644
@@ -193,6 +193,24 @@ unsigned int
 rte_reorder_drain_up_to_seqn(struct rte_reorder_buffer *b, struct rte_mbuf **mbufs,
 		unsigned int max_mbufs, rte_reorder_seqn_t seqn);
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice
+ *
+ * Set minimum sequence number of packet allowed to be buffered.
+ * To successfully set new value reorder buffer has to be empty(after create, reset or drain_all).
+ *
+ * @param b
+ *   Empty reorder buffer instance to modify.
+ * @param min_seqn
+ *   New sequence number to set.
+ * @return
+ *   0 on success, a negative value otherwise.
+ */
+__rte_experimental
+unsigned int
+rte_reorder_min_seqn_set(struct rte_reorder_buffer *b, rte_reorder_seqn_t min_seqn);
+
 #ifdef __cplusplus
 }
 #endif
lib/reorder/version.map +1 -0
index d322da03bd..e21b91f526 100644
@@ -18,4 +18,5 @@ EXPERIMENTAL {
 	rte_reorder_seqn_dynfield_offset;
 	# added in 23.03
 	rte_reorder_drain_up_to_seqn;
+	rte_reorder_min_seqn_set;
 };
Signature · 1 line
2.34.1
#11 lore raw
In reply to Volodymyr Fialko

20/02/2023 11:48, Volodymyr Fialko:

Quoted 6 lines

This patch series provides new APIs for reorder library and test cases for them.

v2:
- squash tests with corresponding API patches
- address minor comments

Thanks
In absence of review, I will just wait for the CI to complete before merging.

#12 lore raw

20/02/2023 12:01, Thomas Monjalon:

Quoted 10 lines

20/02/2023 11:48, Volodymyr Fialko:

Quoted 6 lines

This patch series provides new APIs for reorder library and test cases for them.

v2:
- squash tests with corresponding API patches
- address minor comments

Thanks
In absence of review, I will just wait for the CI to complete before merging.

CI looks green.

Applied, thanks.