Skip to contentSkip to conversation

add rte ring reset api and use it to flush a ring by hash

PATCH Superseded Gavin Hu 7 participants 23 messages Jan 2, 2019 – Oct 24, 2019 Arm/Amlogic Meson SoC support

v4 of 10 Superseded Latest is v10 →

lore
Share & tools
lore

Gavin Hu

author
#0 lore raw

v4 cover add rte ring reset api and use it to flush a ring by hash

V4: Include the ring perf test case enhancement patch in the series.

V3: Allow experimental API for meson build

V2: Fix the coding style issue(commit message line too long)

V1: To flush a ring not in use, dequeue one by one is wasting cpu cycles. The patch is to just resetting the head and tail indices to save cpu cycle.

Gavin Hu (2):
ring: add reset api to flush the ring when not in use
hash: flush the rings instead of dequeuing one by one

Joyce Kong (1):
test/ring: ring perf test case enhancement

 lib/librte_hash/Makefile             |  2 +-
 lib/librte_hash/meson.build          |  3 ++
 lib/librte_hash/rte_cuckoo_hash.c    | 11 ++---
 lib/librte_ring/rte_ring.h           | 20 +++++++++
 lib/librte_ring/rte_ring_version.map |  7 +++
 test/test/test_ring_perf.c           | 82 ++++++++++++++++++++++++++++++++++--
 6 files changed, 114 insertions(+), 11 deletions(-)
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH v4 1/3 test/ring: ring perf test case enhancement

From: Joyce Kong <[email protected]>

Run ring perf test on all available cores to really verify MPMC operations. The old way of running on a pair of cores is not enough for MPMC rings. We used this test case for ring optimization and it was really helpful for measuring the ring performance in multi-core environment.

---
 test/test/test_ring_perf.c | 82 ++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 79 insertions(+), 3 deletions(-)
test/test/test_ring_perf.c +79 -3
index ebb3939..01c6937 100644
@@ -9,7 +9,7 @@
 #include <rte_cycles.h>
 #include <rte_launch.h>
 #include <rte_pause.h>
-
+#include <string.h>
 #include "test.h"
 
 /*
@@ -20,6 +20,7 @@
  *  * Empty ring dequeue
  *  * Enqueue/dequeue of bursts in 1 threads
  *  * Enqueue/dequeue of bursts in 2 threads
+ *  * Enqueue/dequeue of bursts in all available threads
  */
 
 #define RING_NAME "RING_PERF"
@@ -248,9 +249,80 @@ run_on_core_pair(struct lcore_pair *cores, struct rte_ring *r,
 	}
 }
 
+static rte_atomic32_t synchro;
+static uint64_t queue_count[RTE_MAX_LCORE];
+
+#define TIME_MS 100
+
+static int
+load_loop_fn(void *p)
+{
+	uint64_t time_diff = 0;
+	uint64_t begin = 0;
+	uint64_t hz = rte_get_timer_hz();
+	uint64_t lcount = 0;
+	const unsigned int lcore = rte_lcore_id();
+	struct thread_params *params = p;
+	void *burst[MAX_BURST] = {0};
+
+	/* wait synchro for slaves */
+	if (lcore != rte_get_master_lcore())
+		while (rte_atomic32_read(&synchro) == 0)
+			rte_pause();
+
+	begin = rte_get_timer_cycles();
+	while (time_diff < hz * TIME_MS / 1000) {
+		rte_ring_mp_enqueue_bulk(params->r, burst, params->size, NULL);
+		rte_ring_mc_dequeue_bulk(params->r, burst, params->size, NULL);
+		lcount++;
+		time_diff = rte_get_timer_cycles() - begin;
+	}
+	queue_count[lcore] = lcount;
+	return 0;
+}
+
+static int
+run_on_all_cores(struct rte_ring *r)
+{
+	uint64_t total = 0;
+	unsigned int i, c;
+	struct thread_params param;
+
+	memset(&param, 0, sizeof(struct thread_params));
+	for (i = 0; i < RTE_DIM(bulk_sizes); i++) {
+		printf("\nBulk enq/dequeue count on size %u\n", bulk_sizes[i]);
+		param.size = bulk_sizes[i];
+		param.r = r;
+
+		/* clear synchro and start slaves */
+		rte_atomic32_set(&synchro, 0);
+		if (rte_eal_mp_remote_launch(load_loop_fn,
+				&param, SKIP_MASTER) < 0)
+			return -1;
+
+		/* start synchro and launch test on master */
+		rte_atomic32_set(&synchro, 1);
+		load_loop_fn(&param);
+
+		rte_eal_mp_wait_lcore();
+
+		RTE_LCORE_FOREACH(c) {
+			printf("Core [%u] count = %"PRIu64"\n",
+					c, queue_count[c]);
+			total += queue_count[c];
+		}
+
+		printf("Total count (size: %u): %"PRIu64"\n", bulk_sizes[i],
+						total);
+	}
+
+	return 0;
+}
+
 /*
- * Test function that determines how long an enqueue + dequeue of a single item
- * takes on a single lcore. Result is for comparison with the bulk enq+deq.
+ * Test function that determines how long an enqueue + dequeue of a single
+ * item takes on a single lcore. Result is for comparison with the bulk
+ * enq+deq.
  */
 static void
 test_single_enqueue_dequeue(struct rte_ring *r)
@@ -394,6 +466,10 @@ test_ring_perf(void)
 		printf("\n### Testing using two NUMA nodes ###\n");
 		run_on_core_pair(&cores, r, enqueue_bulk, dequeue_bulk);
 	}
+
+	printf("\n### Testing using all slave nodes ###\n");
+	run_on_all_cores(r);
+
 	rte_ring_free(r);
 	return 0;
 }
Signature · 1 line
2.7.4
#2 lore raw

Re: [PATCH v4 1/3] test/ring: ring perf test case enhancement

Quoted 7 lines

Small comment about the email addresses,
Please do not use uppercase so we can match/grep more easily.

#3 lore raw

Re: [PATCH v4 1/3] test/ring: ring perf test case enhancement

Quoted 21 lines

-----Original Message-----
From: Thomas Monjalon <[email protected]>
Sent: Wednesday, January 2, 2019 8:49 PM
To: Gavin Hu (Arm Technology China) <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Honnappa Nagarahalli <[email protected]>; nd <[email protected]>; [email protected]; Joyce Kong (Arm Technology China) <[email protected]>
Subject: Re: [PATCH v4 1/3] test/ring: ring perf test case enhancement

Quoted 7 lines
Quoted 3 lines

Small comment about the email addresses,
Please do not use uppercase so we can match/grep more easily.

Thanks for reminding, already fixed this in v5.

author
#4 lore raw

PATCH v4 2/3 ring: add reset api to flush the ring when not in use

In reply to Gavin Hu

Currently, the flush is done by dequeuing the ring in a while loop. It is much simpler to flush the queue by resetting the head and tail indices.

---
 lib/librte_ring/rte_ring.h           | 20 ++++++++++++++++++++
 lib/librte_ring/rte_ring_version.map |  7 +++++++
 2 files changed, 27 insertions(+)
lib/librte_ring/rte_ring.h +20 -0
index af5444a..2830300 100644
@@ -671,6 +671,26 @@ rte_ring_dequeue(struct rte_ring *r, void **obj_p)
 }
 
 /**
+ * Flush a ring.
+ *
+ * This function flush all the elements in a ring
+ *
+ * @b EXPERIMENTAL: this API may change without prior notice
+ *
+ * @warning
+ * Make sure the ring is not in use while calling this function.
+ *
+ * @param r
+ *   A pointer to the ring structure.
+ */
+static inline void __rte_experimental
+rte_ring_reset(struct rte_ring *r)
+{
+	r->prod.head = r->cons.head = 0;
+	r->prod.tail = r->cons.tail = 0;
+}
+
+/**
  * Return the number of entries in a ring.
  *
  * @param r
lib/librte_ring/rte_ring_version.map +7 -0
index d935efd..581d9ca 100644
@@ -17,3 +17,10 @@ DPDK_2.2 {
 	rte_ring_free;
 
 } DPDK_2.0;
+
+EXPERIMENTAL {
+    global:
+
+	rte_ring_reset;
+
+};
Signature · 1 line
2.7.4
author
#5 lore raw

PATCH v4 3/3 hash: flush the rings instead of dequeuing one by one

In reply to Gavin Hu

Within rte_hash_reset, calling a while loop to dequeue one by one from the ring, while not using them at all, is wasting cycles, The patch just flush the ring by resetting the indices can save cpu cycles.

Fixes b26473ff8f4a ("hash: add reset function")
Fixes 75706568a7eb ("hash: add extendable bucket feature")
---
 lib/librte_hash/Makefile          |  2 +-
 lib/librte_hash/meson.build       |  3 +++
 lib/librte_hash/rte_cuckoo_hash.c | 11 ++++-------
 3 files changed, 8 insertions(+), 8 deletions(-)
lib/librte_hash/Makefile +1 -1
index c8c435d..5669d83 100644
@@ -6,7 +6,7 @@ include $(RTE_SDK)/mk/rte.vars.mk
 # library name
 LIB = librte_hash.a
 
-CFLAGS += -O3
+CFLAGS += -O3 -DALLOW_EXPERIMENTAL_API
 CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR)
 LDLIBS += -lrte_eal -lrte_ring
 
lib/librte_hash/meson.build +3 -0
index efc06ed..ebf70de 100644
@@ -14,3 +14,6 @@ headers = files('rte_cmp_arm64.h',
 
 sources = files('rte_cuckoo_hash.c', 'rte_fbk_hash.c')
 deps += ['ring']
+
+# rte ring reset is not yet part of stable API
+allow_experimental_apis = true
lib/librte_hash/rte_cuckoo_hash.c +4 -7
index c01489b..4b08049 100644
@@ -559,7 +559,6 @@ __hash_rw_reader_unlock(const struct rte_hash *h)
 void
 rte_hash_reset(struct rte_hash *h)
 {
-	void *ptr;
 	uint32_t tot_ring_cnt, i;
 
 	if (h == NULL)
@@ -570,16 +569,14 @@ rte_hash_reset(struct rte_hash *h)
 	memset(h->key_store, 0, h->key_entry_size * (h->entries + 1));
 	*h->tbl_chng_cnt = 0;
 
-	/* clear the free ring */
-	while (rte_ring_dequeue(h->free_slots, &ptr) == 0)
-		continue;
+	/* reset the free ring */
+	rte_ring_reset(h->free_slots);
 
-	/* clear free extendable bucket ring and memory */
+	/* flush free extendable bucket ring and memory */
 	if (h->ext_table_support) {
 		memset(h->buckets_ext, 0, h->num_buckets *
 						sizeof(struct rte_hash_bucket));
-		while (rte_ring_dequeue(h->free_ext_bkts, &ptr) == 0)
-			continue;
+		rte_ring_reset(h->free_ext_bkts);
 	}
 
 	/* Repopulate the free slots ring. Entry zero is reserved for key misses */
Signature · 1 line
2.7.4
#6 lore raw
In reply to Gavin Hu

02/01/2019 01:55, Gavin Hu:

Quoted 9 lines

V4: Include the ring perf test case enhancement patch in the series.

V3: Allow experimental API for meson build

V2: Fix the coding style issue(commit message line too long)

V1: To flush a ring not in use, dequeue one by one is wasting cpu cycles. The patch is to just resetting the head and tail indices to save cpu cycle.

It is too late for adding this API in 19.02, but we should review and give opinion, so it will be ready to integrate in early February.

#7 lore raw
Quoted 3 lines

02/01/2019 01:55, Gavin Hu:

Quoted 1 line

V4: Include the ring perf test case enhancement patch in the series.

This change is not related to this patch. Should be a separate patch? There were comments provided:
http://mails.dpdk.org/archives/dev/2018-December/121893.html
http://mails.dpdk.org/archives/dev/2018-December/122157.html

Do you plan to address these?

Quoted 12 lines
Quoted 8 lines

V3: Allow experimental API for meson build

V2: Fix the coding style issue(commit message line too long)

V1: To flush a ring not in use, dequeue one by one is wasting cpu cycles. The patch is to just resetting the head and tail indices to save cpu cycle.

It is too late for adding this API in 19.02, but we should review and give opinion, so it will be ready to integrate in early February.

#8 lore raw
Quoted 14 lines

-----Original Message-----
From: Honnappa Nagarahalli <[email protected]>
Sent: Thursday, January 3, 2019 2:41 AM
To: Thomas Monjalon <[email protected]>; Gavin Hu (Arm Technology China) <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; nd <[email protected]>; [email protected]; nd <[email protected]>
Subject: RE: [PATCH v4 0/3] add rte ring reset api and use it to flush a ring by hash

Quoted 1 line
Quoted 3 lines
Quoted 2 lines

02/01/2019 01:55, Gavin Hu:

Quoted 1 line

V4: Include the ring perf test case enhancement patch in the series.

This change is not related to this patch. Should be a separate patch?

I included it in this patch set to avoid patches scattering here and there, Anyway I updated the title of the cover letter to reflect this.

Quoted 5 lines

There were comments provided:
http://mails.dpdk.org/archives/dev/2018-December/121893.html
http://mails.dpdk.org/archives/dev/2018-December/122157.html

Do you plan to address these?

One was addressed in v4 and the other was address in new v5. Thanks!

Quoted 13 lines
Quoted 13 lines
Quoted 9 lines

V3: Allow experimental API for meson build

V2: Fix the coding style issue(commit message line too long)

V1: To flush a ring not in use, dequeue one by one is wasting cpu cycles. The patch is to just resetting the head and tail indices to save cpu cycle.

It is too late for adding this API in 19.02, but we should review and give opinion, so it will be ready to integrate in early February.

author
#9 lore raw

v5 cover ring test enhancement and new ring reset api and use it by hash

In reply to Gavin Hu

V5:
1. Commit message tweaking for ring test case enhancement patch
2. Upper to lower for mails to make match/grep more easily

V4:
1. Include the ring perf test case enhancement patch in the series.
2. Replace ARRAY_SIZE with RTE_DIM.
3. Call memset to avoid clang compling complains.

V3: Allow experimental API for meson build

V2: Fix the coding style issue(commit message line too long)

V1: To flush a ring not in use, dequeue one by one is wasting cpu cycles. The patch is to just resetting the head and tail indices to save cpu cycle.

Gavin Hu (2):
ring: add reset API to flush the ring when not in use
hash: flush the rings instead of dequeuing one by one

Joyce Kong (1):
test/ring: ring perf test case enhancement

 lib/librte_hash/Makefile             |  2 +-
 lib/librte_hash/meson.build          |  3 ++
 lib/librte_hash/rte_cuckoo_hash.c    | 11 ++---
 lib/librte_ring/rte_ring.h           | 20 +++++++++
 lib/librte_ring/rte_ring_version.map |  7 +++
 test/test/test_ring_perf.c           | 82 ++++++++++++++++++++++++++++++++++--
 6 files changed, 114 insertions(+), 11 deletions(-)
Signature · 1 line
2.7.4
author
#10 lore raw

PATCH v5 1/3 test/ring: ring perf test case enhancement

From: Joyce Kong <[email protected]>

Run ring perf test on all available cores to really verify MPMC operations. The old way of running on a pair of cores is not enough for MPMC rings.

---
 test/test/test_ring_perf.c | 82 ++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 79 insertions(+), 3 deletions(-)
test/test/test_ring_perf.c +79 -3
index ebb3939..01c6937 100644
@@ -9,7 +9,7 @@
 #include <rte_cycles.h>
 #include <rte_launch.h>
 #include <rte_pause.h>
-
+#include <string.h>
 #include "test.h"
 
 /*
@@ -20,6 +20,7 @@
  *  * Empty ring dequeue
  *  * Enqueue/dequeue of bursts in 1 threads
  *  * Enqueue/dequeue of bursts in 2 threads
+ *  * Enqueue/dequeue of bursts in all available threads
  */
 
 #define RING_NAME "RING_PERF"
@@ -248,9 +249,80 @@ run_on_core_pair(struct lcore_pair *cores, struct rte_ring *r,
 	}
 }
 
+static rte_atomic32_t synchro;
+static uint64_t queue_count[RTE_MAX_LCORE];
+
+#define TIME_MS 100
+
+static int
+load_loop_fn(void *p)
+{
+	uint64_t time_diff = 0;
+	uint64_t begin = 0;
+	uint64_t hz = rte_get_timer_hz();
+	uint64_t lcount = 0;
+	const unsigned int lcore = rte_lcore_id();
+	struct thread_params *params = p;
+	void *burst[MAX_BURST] = {0};
+
+	/* wait synchro for slaves */
+	if (lcore != rte_get_master_lcore())
+		while (rte_atomic32_read(&synchro) == 0)
+			rte_pause();
+
+	begin = rte_get_timer_cycles();
+	while (time_diff < hz * TIME_MS / 1000) {
+		rte_ring_mp_enqueue_bulk(params->r, burst, params->size, NULL);
+		rte_ring_mc_dequeue_bulk(params->r, burst, params->size, NULL);
+		lcount++;
+		time_diff = rte_get_timer_cycles() - begin;
+	}
+	queue_count[lcore] = lcount;
+	return 0;
+}
+
+static int
+run_on_all_cores(struct rte_ring *r)
+{
+	uint64_t total = 0;
+	unsigned int i, c;
+	struct thread_params param;
+
+	memset(&param, 0, sizeof(struct thread_params));
+	for (i = 0; i < RTE_DIM(bulk_sizes); i++) {
+		printf("\nBulk enq/dequeue count on size %u\n", bulk_sizes[i]);
+		param.size = bulk_sizes[i];
+		param.r = r;
+
+		/* clear synchro and start slaves */
+		rte_atomic32_set(&synchro, 0);
+		if (rte_eal_mp_remote_launch(load_loop_fn,
+				&param, SKIP_MASTER) < 0)
+			return -1;
+
+		/* start synchro and launch test on master */
+		rte_atomic32_set(&synchro, 1);
+		load_loop_fn(&param);
+
+		rte_eal_mp_wait_lcore();
+
+		RTE_LCORE_FOREACH(c) {
+			printf("Core [%u] count = %"PRIu64"\n",
+					c, queue_count[c]);
+			total += queue_count[c];
+		}
+
+		printf("Total count (size: %u): %"PRIu64"\n", bulk_sizes[i],
+						total);
+	}
+
+	return 0;
+}
+
 /*
- * Test function that determines how long an enqueue + dequeue of a single item
- * takes on a single lcore. Result is for comparison with the bulk enq+deq.
+ * Test function that determines how long an enqueue + dequeue of a single
+ * item takes on a single lcore. Result is for comparison with the bulk
+ * enq+deq.
  */
 static void
 test_single_enqueue_dequeue(struct rte_ring *r)
@@ -394,6 +466,10 @@ test_ring_perf(void)
 		printf("\n### Testing using two NUMA nodes ###\n");
 		run_on_core_pair(&cores, r, enqueue_bulk, dequeue_bulk);
 	}
+
+	printf("\n### Testing using all slave nodes ###\n");
+	run_on_all_cores(r);
+
 	rte_ring_free(r);
 	return 0;
 }
Signature · 1 line
2.7.4
#11 lore raw

Re: [PATCH v5 1/3] test/ring: ring perf test case enhancement

03/01/2019 03:38, gavin hu:

Quoted 5 lines

From: Joyce Kong <[email protected]>

Run ring perf test on all available cores to really verify MPMC operations. The old way of running on a pair of cores is not enough for MPMC rings.

Quoted 7 lines

Sorry Gavin, there is a misunderstanding.
I was suggesting to not use uppercase in email addresses, but please keep uppercase in names in front of the addresses. Example:
Real Name <[email protected]>

As for many guidelines, in doubt, you can check the git history. Thanks

#12 lore raw

Re: [PATCH v5 1/3] test/ring: ring perf test case enhancement

Quoted 27 lines

-----Original Message-----
From: Thomas Monjalon <[email protected]>
Sent: Thursday, January 3, 2019 3:40 PM
To: Gavin Hu (Arm Technology China) <[email protected]>
Cc: [email protected]; nd <[email protected]>; [email protected]; [email protected]; Honnappa Nagarahalli <[email protected]>; [email protected]; [email protected]; [email protected]; Joyce Kong (Arm Technology China) <[email protected]>
Subject: Re: [PATCH v5 1/3] test/ring: ring perf test case enhancement

03/01/2019 03:38, gavin hu:

Quoted 5 lines

From: Joyce Kong <[email protected]>

Run ring perf test on all available cores to really verify MPMC operations. The old way of running on a pair of cores is not enough for MPMC rings.

Quoted 7 lines
Quoted 8 lines

Sorry Gavin, there is a misunderstanding.
I was suggesting to not use uppercase in email addresses, but please keep uppercase in names in front of the addresses. Example:
Real Name <[email protected]>

As for many guidelines, in doubt, you can check the git history. Thanks

Sorry I misunderstood and I already realized that, I will wait a bit for other comments then Submit a new version to correct this.

author
#13 lore raw

v6 cover ring test enhancement and new ring reset api and use it by hash

In reply to gavin hu

V6: Made upper case for the user name to comply with the convention.

V5:
1. Commit message tweaking for ring test case enhancement patch
2. Upper to lower for mails to make match/grep more easily

V4:
1. Include the ring perf test case enhancement patch in the series.
2. Replace ARRAY_SIZE with RTE_DIM.
3. Call memset to avoid clang compling complains.

V3: Allow experimental API for meson build

V2: Fix the coding style issue(commit message line too long)

V1: To flush a ring not in use, dequeue one by one is wasting cpu cycles. The patch is to just resetting the head and tail indices to save cpu cycle.

Gavin Hu (2):
ring: add reset API to flush the ring when not in use
hash: flush the rings instead of dequeuing one by one

Joyce Kong (1):
test/ring: ring perf test case enhancement

 lib/librte_hash/Makefile             |  2 +-
 lib/librte_hash/meson.build          |  3 ++
 lib/librte_hash/rte_cuckoo_hash.c    | 11 ++---
 lib/librte_ring/rte_ring.h           | 20 +++++++++
 lib/librte_ring/rte_ring_version.map |  7 +++
 test/test/test_ring_perf.c           | 82 ++++++++++++++++++++++++++++++++++--
 6 files changed, 114 insertions(+), 11 deletions(-)
Signature · 1 line
2.7.4
author
#14 lore raw

PATCH v6 1/3 test/ring: ring perf test case enhancement

From: Joyce Kong <[email protected]>

Run ring perf test on all available cores to really verify MPMC operations. The old way of running on a pair of cores is not enough for MPMC rings.

---
 test/test/test_ring_perf.c | 82 ++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 79 insertions(+), 3 deletions(-)
test/test/test_ring_perf.c +79 -3
index ebb3939..01c6937 100644
@@ -9,7 +9,7 @@
 #include <rte_cycles.h>
 #include <rte_launch.h>
 #include <rte_pause.h>
-
+#include <string.h>
 #include "test.h"
 
 /*
@@ -20,6 +20,7 @@
  *  * Empty ring dequeue
  *  * Enqueue/dequeue of bursts in 1 threads
  *  * Enqueue/dequeue of bursts in 2 threads
+ *  * Enqueue/dequeue of bursts in all available threads
  */
 
 #define RING_NAME "RING_PERF"
@@ -248,9 +249,80 @@ run_on_core_pair(struct lcore_pair *cores, struct rte_ring *r,
 	}
 }
 
+static rte_atomic32_t synchro;
+static uint64_t queue_count[RTE_MAX_LCORE];
+
+#define TIME_MS 100
+
+static int
+load_loop_fn(void *p)
+{
+	uint64_t time_diff = 0;
+	uint64_t begin = 0;
+	uint64_t hz = rte_get_timer_hz();
+	uint64_t lcount = 0;
+	const unsigned int lcore = rte_lcore_id();
+	struct thread_params *params = p;
+	void *burst[MAX_BURST] = {0};
+
+	/* wait synchro for slaves */
+	if (lcore != rte_get_master_lcore())
+		while (rte_atomic32_read(&synchro) == 0)
+			rte_pause();
+
+	begin = rte_get_timer_cycles();
+	while (time_diff < hz * TIME_MS / 1000) {
+		rte_ring_mp_enqueue_bulk(params->r, burst, params->size, NULL);
+		rte_ring_mc_dequeue_bulk(params->r, burst, params->size, NULL);
+		lcount++;
+		time_diff = rte_get_timer_cycles() - begin;
+	}
+	queue_count[lcore] = lcount;
+	return 0;
+}
+
+static int
+run_on_all_cores(struct rte_ring *r)
+{
+	uint64_t total = 0;
+	unsigned int i, c;
+	struct thread_params param;
+
+	memset(&param, 0, sizeof(struct thread_params));
+	for (i = 0; i < RTE_DIM(bulk_sizes); i++) {
+		printf("\nBulk enq/dequeue count on size %u\n", bulk_sizes[i]);
+		param.size = bulk_sizes[i];
+		param.r = r;
+
+		/* clear synchro and start slaves */
+		rte_atomic32_set(&synchro, 0);
+		if (rte_eal_mp_remote_launch(load_loop_fn,
+				&param, SKIP_MASTER) < 0)
+			return -1;
+
+		/* start synchro and launch test on master */
+		rte_atomic32_set(&synchro, 1);
+		load_loop_fn(&param);
+
+		rte_eal_mp_wait_lcore();
+
+		RTE_LCORE_FOREACH(c) {
+			printf("Core [%u] count = %"PRIu64"\n",
+					c, queue_count[c]);
+			total += queue_count[c];
+		}
+
+		printf("Total count (size: %u): %"PRIu64"\n", bulk_sizes[i],
+						total);
+	}
+
+	return 0;
+}
+
 /*
- * Test function that determines how long an enqueue + dequeue of a single item
- * takes on a single lcore. Result is for comparison with the bulk enq+deq.
+ * Test function that determines how long an enqueue + dequeue of a single
+ * item takes on a single lcore. Result is for comparison with the bulk
+ * enq+deq.
  */
 static void
 test_single_enqueue_dequeue(struct rte_ring *r)
@@ -394,6 +466,10 @@ test_ring_perf(void)
 		printf("\n### Testing using two NUMA nodes ###\n");
 		run_on_core_pair(&cores, r, enqueue_bulk, dequeue_bulk);
 	}
+
+	printf("\n### Testing using all slave nodes ###\n");
+	run_on_all_cores(r);
+
 	rte_ring_free(r);
 	return 0;
 }
Signature · 1 line
2.7.4
#15 lore raw

PATCH v7 1/1 test/ring: ring perf test case enhancement

Run ring perf test on all available cores to really verify MPMC operations. The old way of running on a pair of cores is not enough for MPMC rings.

---

v7:
This patch was separated from the v6 series as less relevant and the other patches in the series(http://patchwork.dpdk.org/cover/56549/) were already merged.

 app/test/test_ring_perf.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 77 insertions(+)
app/test/test_ring_perf.c +77 -0
index b6ad703..70ee46f 100644
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: BSD-3-Clause
  * Copyright(c) 2010-2014 Intel Corporation
+ * Copyright(c) 2019 Arm Limited
  */
 
 
@@ -9,6 +10,7 @@
 #include <rte_cycles.h>
 #include <rte_launch.h>
 #include <rte_pause.h>
+#include <string.h>
 
 #include "test.h"
 
@@ -20,6 +22,7 @@
  *  * Empty ring dequeue
  *  * Enqueue/dequeue of bursts in 1 threads
  *  * Enqueue/dequeue of bursts in 2 threads
+ *  * Enqueue/dequeue of bursts in all available threads
  */
 
 #define RING_NAME "RING_PERF"
@@ -258,6 +261,76 @@ run_on_core_pair(struct lcore_pair *cores, struct rte_ring *r,
 	}
 }
 
+static rte_atomic32_t synchro;
+static uint64_t queue_count[RTE_MAX_LCORE];
+
+#define TIME_MS 100
+
+static int
+load_loop_fn(void *p)
+{
+	uint64_t time_diff = 0;
+	uint64_t begin = 0;
+	uint64_t hz = rte_get_timer_hz();
+	uint64_t lcount = 0;
+	const unsigned int lcore = rte_lcore_id();
+	struct thread_params *params = p;
+	void *burst[MAX_BURST] = {0};
+
+	/* wait synchro for slaves */
+	if (lcore != rte_get_master_lcore())
+		while (rte_atomic32_read(&synchro) == 0)
+			rte_pause();
+
+	begin = rte_get_timer_cycles();
+	while (time_diff < hz * TIME_MS / 1000) {
+		rte_ring_mp_enqueue_bulk(params->r, burst, params->size, NULL);
+		rte_ring_mc_dequeue_bulk(params->r, burst, params->size, NULL);
+		lcount++;
+		time_diff = rte_get_timer_cycles() - begin;
+	}
+	queue_count[lcore] = lcount;
+	return 0;
+}
+
+static int
+run_on_all_cores(struct rte_ring *r)
+{
+	uint64_t total = 0;
+	struct thread_params param;
+	unsigned int i, c;
+
+	memset(&param, 0, sizeof(struct thread_params));
+	for (i = 0; i < RTE_DIM(bulk_sizes); i++) {
+		printf("\nBulk enq/dequeue count on size %u\n", bulk_sizes[i]);
+		param.size = bulk_sizes[i];
+		param.r = r;
+
+		/* clear synchro and start slaves */
+		rte_atomic32_set(&synchro, 0);
+		if (rte_eal_mp_remote_launch(load_loop_fn, &param,
+			SKIP_MASTER) < 0)
+			return -1;
+
+		/* start synchro and launch test on master */
+		rte_atomic32_set(&synchro, 1);
+		load_loop_fn(&param);
+
+		rte_eal_mp_wait_lcore();
+
+		RTE_LCORE_FOREACH(c) {
+			printf("Core [%u] count = %"PRIu64"\n",
+					c, queue_count[c]);
+			total += queue_count[c];
+		}
+
+		printf("Total count (size: %u): %"PRIu64"\n",
+				bulk_sizes[i], total);
+	}
+
+	return 0;
+}
+
 /*
  * Test function that determines how long an enqueue + dequeue of a single item
  * takes on a single lcore. Result is for comparison with the bulk enq+deq.
@@ -404,6 +477,10 @@ test_ring_perf(void)
 		printf("\n### Testing using two NUMA nodes ###\n");
 		run_on_core_pair(&cores, r, enqueue_bulk, dequeue_bulk);
 	}
+
+	printf("\n### Testing using all slave nodes ###\n");
+	run_on_all_cores(r);
+
 	rte_ring_free(r);
 	return 0;
 }
Signature · 1 line
2.7.4
Acked-by on v7 1/1
#16 lore raw

Re: [dpdk-dev] [PATCH v7] test/ring: ring perf test case enhancement

Quoted 10 lines · Joyce Kong

Run ring perf test on all available cores to really verify MPMC operations. The old way of running on a pair of cores is not enough for MPMC rings.

#17 lore raw

Re: [dpdk-dev] [PATCH v7] test/ring: ring perf test case enhancement

Quoted 13 lines · Olivier Matz
Quoted 10 lines · Joyce Kong

Run ring perf test on all available cores to really verify MPMC operations. The old way of running on a pair of cores is not enough for MPMC rings.

Quoted 1 line

Applied, thanks.

Signature · 1 line
David Marchand
author
#18 lore raw

PATCH v6 2/3 ring: add reset API to flush the ring when not in use

In reply to gavin hu

From: Gavin Hu <[email protected]>

Currently, the flush is done by dequeuing the ring in a while loop. It is much simpler to flush the queue by resetting the head and tail indices.

---
 lib/librte_ring/rte_ring.h           | 20 ++++++++++++++++++++
 lib/librte_ring/rte_ring_version.map |  7 +++++++
 2 files changed, 27 insertions(+)
lib/librte_ring/rte_ring.h +20 -0
index af5444a..2830300 100644
@@ -671,6 +671,26 @@ rte_ring_dequeue(struct rte_ring *r, void **obj_p)
 }
 
 /**
+ * Flush a ring.
+ *
+ * This function flush all the elements in a ring
+ *
+ * @b EXPERIMENTAL: this API may change without prior notice
+ *
+ * @warning
+ * Make sure the ring is not in use while calling this function.
+ *
+ * @param r
+ *   A pointer to the ring structure.
+ */
+static inline void __rte_experimental
+rte_ring_reset(struct rte_ring *r)
+{
+	r->prod.head = r->cons.head = 0;
+	r->prod.tail = r->cons.tail = 0;
+}
+
+/**
  * Return the number of entries in a ring.
  *
  * @param r
lib/librte_ring/rte_ring_version.map +7 -0
index d935efd..581d9ca 100644
@@ -17,3 +17,10 @@ DPDK_2.2 {
 	rte_ring_free;
 
 } DPDK_2.0;
+
+EXPERIMENTAL {
+    global:
+
+	rte_ring_reset;
+
+};
Signature · 1 line
2.7.4
author
#19 lore raw

PATCH v6 3/3 hash: flush the rings instead of dequeuing one by one

In reply to gavin hu

From: Gavin Hu <[email protected]>

Within rte_hash_reset, calling a while loop to dequeue one by one from the ring, while not using them at all, is wasting cycles, The patch just flush the ring by resetting the indices can save cpu cycles.

Fixes b26473ff8f4a ("hash: add reset function")
Fixes 75706568a7eb ("hash: add extendable bucket feature")
---
 lib/librte_hash/Makefile          |  2 +-
 lib/librte_hash/meson.build       |  3 +++
 lib/librte_hash/rte_cuckoo_hash.c | 11 ++++-------
 3 files changed, 8 insertions(+), 8 deletions(-)
lib/librte_hash/Makefile +1 -1
index c8c435d..5669d83 100644
@@ -6,7 +6,7 @@ include $(RTE_SDK)/mk/rte.vars.mk
 # library name
 LIB = librte_hash.a
 
-CFLAGS += -O3
+CFLAGS += -O3 -DALLOW_EXPERIMENTAL_API
 CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR)
 LDLIBS += -lrte_eal -lrte_ring
 
lib/librte_hash/meson.build +3 -0
index efc06ed..ebf70de 100644
@@ -14,3 +14,6 @@ headers = files('rte_cmp_arm64.h',
 
 sources = files('rte_cuckoo_hash.c', 'rte_fbk_hash.c')
 deps += ['ring']
+
+# rte ring reset is not yet part of stable API
+allow_experimental_apis = true
lib/librte_hash/rte_cuckoo_hash.c +4 -7
index c01489b..4b08049 100644
@@ -559,7 +559,6 @@ __hash_rw_reader_unlock(const struct rte_hash *h)
 void
 rte_hash_reset(struct rte_hash *h)
 {
-	void *ptr;
 	uint32_t tot_ring_cnt, i;
 
 	if (h == NULL)
@@ -570,16 +569,14 @@ rte_hash_reset(struct rte_hash *h)
 	memset(h->key_store, 0, h->key_entry_size * (h->entries + 1));
 	*h->tbl_chng_cnt = 0;
 
-	/* clear the free ring */
-	while (rte_ring_dequeue(h->free_slots, &ptr) == 0)
-		continue;
+	/* reset the free ring */
+	rte_ring_reset(h->free_slots);
 
-	/* clear free extendable bucket ring and memory */
+	/* flush free extendable bucket ring and memory */
 	if (h->ext_table_support) {
 		memset(h->buckets_ext, 0, h->num_buckets *
 						sizeof(struct rte_hash_bucket));
-		while (rte_ring_dequeue(h->free_ext_bkts, &ptr) == 0)
-			continue;
+		rte_ring_reset(h->free_ext_bkts);
 	}
 
 	/* Repopulate the free slots ring. Entry zero is reserved for key misses */
Signature · 1 line
2.7.4
Acked-by on v6 3/3
#20 lore raw

Re: [PATCH v6 3/3] hash: flush the rings instead of dequeuing one by one

Quoted 10 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of gavin hu
Sent: Wednesday, January 9, 2019 3:32 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Richardson, Bruce <[email protected]>; [email protected]
Subject: [dpdk-dev] [PATCH v6 3/3] hash: flush the rings instead of dequeuing one by one

From: Gavin Hu <[email protected]>

Quoted 8 lines

Within rte_hash_reset, calling a while loop to dequeue one by one from the ring, while not using them at all, is wasting cycles, The patch just flush the ring by resetting the indices can save cpu cycles.

Fixes b26473ff8f4a ("hash: add reset function")
Fixes 75706568a7eb ("hash: add extendable bucket feature")

[Wang, Yipeng] I don't think it is a bug fix applicable to previous stable versions.

Quoted 3 lines

[Wang, Yipeng] Otherwise the hash table change looks good to me and unit test passed on my setup.

author
#21 lore raw

PATCH v5 2/3 ring: add reset API to flush the ring when not in use

In reply to gavin hu

From: Gavin Hu <[email protected]>

Currently, the flush is done by dequeuing the ring in a while loop. It is much simpler to flush the queue by resetting the head and tail indices.

---
 lib/librte_ring/rte_ring.h           | 20 ++++++++++++++++++++
 lib/librte_ring/rte_ring_version.map |  7 +++++++
 2 files changed, 27 insertions(+)
lib/librte_ring/rte_ring.h +20 -0
index af5444a..2830300 100644
@@ -671,6 +671,26 @@ rte_ring_dequeue(struct rte_ring *r, void **obj_p)
 }
 
 /**
+ * Flush a ring.
+ *
+ * This function flush all the elements in a ring
+ *
+ * @b EXPERIMENTAL: this API may change without prior notice
+ *
+ * @warning
+ * Make sure the ring is not in use while calling this function.
+ *
+ * @param r
+ *   A pointer to the ring structure.
+ */
+static inline void __rte_experimental
+rte_ring_reset(struct rte_ring *r)
+{
+	r->prod.head = r->cons.head = 0;
+	r->prod.tail = r->cons.tail = 0;
+}
+
+/**
  * Return the number of entries in a ring.
  *
  * @param r
lib/librte_ring/rte_ring_version.map +7 -0
index d935efd..581d9ca 100644
@@ -17,3 +17,10 @@ DPDK_2.2 {
 	rte_ring_free;
 
 } DPDK_2.0;
+
+EXPERIMENTAL {
+    global:
+
+	rte_ring_reset;
+
+};
Signature · 1 line
2.7.4
author
#22 lore raw

PATCH v5 3/3 hash: flush the rings instead of dequeuing one by one

In reply to gavin hu

From: Gavin Hu <[email protected]>

Within rte_hash_reset, calling a while loop to dequeue one by one from the ring, while not using them at all, is wasting cycles, The patch just flush the ring by resetting the indices can save cpu cycles.

Fixes b26473ff8f4a ("hash: add reset function")
Fixes 75706568a7eb ("hash: add extendable bucket feature")
---
 lib/librte_hash/Makefile          |  2 +-
 lib/librte_hash/meson.build       |  3 +++
 lib/librte_hash/rte_cuckoo_hash.c | 11 ++++-------
 3 files changed, 8 insertions(+), 8 deletions(-)
lib/librte_hash/Makefile +1 -1
index c8c435d..5669d83 100644
@@ -6,7 +6,7 @@ include $(RTE_SDK)/mk/rte.vars.mk
 # library name
 LIB = librte_hash.a
 
-CFLAGS += -O3
+CFLAGS += -O3 -DALLOW_EXPERIMENTAL_API
 CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR)
 LDLIBS += -lrte_eal -lrte_ring
 
lib/librte_hash/meson.build +3 -0
index efc06ed..ebf70de 100644
@@ -14,3 +14,6 @@ headers = files('rte_cmp_arm64.h',
 
 sources = files('rte_cuckoo_hash.c', 'rte_fbk_hash.c')
 deps += ['ring']
+
+# rte ring reset is not yet part of stable API
+allow_experimental_apis = true
lib/librte_hash/rte_cuckoo_hash.c +4 -7
index c01489b..4b08049 100644
@@ -559,7 +559,6 @@ __hash_rw_reader_unlock(const struct rte_hash *h)
 void
 rte_hash_reset(struct rte_hash *h)
 {
-	void *ptr;
 	uint32_t tot_ring_cnt, i;
 
 	if (h == NULL)
@@ -570,16 +569,14 @@ rte_hash_reset(struct rte_hash *h)
 	memset(h->key_store, 0, h->key_entry_size * (h->entries + 1));
 	*h->tbl_chng_cnt = 0;
 
-	/* clear the free ring */
-	while (rte_ring_dequeue(h->free_slots, &ptr) == 0)
-		continue;
+	/* reset the free ring */
+	rte_ring_reset(h->free_slots);
 
-	/* clear free extendable bucket ring and memory */
+	/* flush free extendable bucket ring and memory */
 	if (h->ext_table_support) {
 		memset(h->buckets_ext, 0, h->num_buckets *
 						sizeof(struct rte_hash_bucket));
-		while (rte_ring_dequeue(h->free_ext_bkts, &ptr) == 0)
-			continue;
+		rte_ring_reset(h->free_ext_bkts);
 	}
 
 	/* Repopulate the free slots ring. Entry zero is reserved for key misses */
Signature · 1 line
2.7.4