[dpdk-dev] [PATCH v1 2/2] examples/packet_ordering: add ring callback

Vipin Varghese vipin.varghese at intel.com
Thu Jun 6 20:33:55 CEST 2019


update example with ring register-unregister for
enqueue-dequeue callabck.

Signed-off-by: Vipin Varghese <vipin.varghese at intel.com>
---
 examples/packet_ordering/Makefile    |  1 +
 examples/packet_ordering/main.c      | 40 ++++++++++++++++++++++++++++
 examples/packet_ordering/meson.build |  1 +
 3 files changed, 42 insertions(+)

diff --git a/examples/packet_ordering/Makefile b/examples/packet_ordering/Makefile
index 2c3187a41..3322b4024 100644
--- a/examples/packet_ordering/Makefile
+++ b/examples/packet_ordering/Makefile
@@ -50,6 +50,7 @@ include $(RTE_SDK)/mk/rte.vars.mk
 
 CFLAGS += -O3
 CFLAGS += $(WERROR_FLAGS)
+CFLAGS += -DALLOW_EXPERIMENTAL_API
 
 include $(RTE_SDK)/mk/rte.extapp.mk
 endif
diff --git a/examples/packet_ordering/main.c b/examples/packet_ordering/main.c
index ca312029e..98d4a7a77 100644
--- a/examples/packet_ordering/main.c
+++ b/examples/packet_ordering/main.c
@@ -71,6 +71,28 @@ volatile struct app_stats {
 	} tx __rte_cache_aligned;
 } app_stats;
 
+#ifdef RTE_RING_ENQDEQ_CALLBACKS
+unsigned int dump_ring(__rte_unused struct rte_ring *r,
+		__rte_unused void *obj_table,
+		__rte_unused unsigned int n,
+		__rte_unused void *cb_arg);
+
+unsigned int dump_ring(__rte_unused struct rte_ring *r,
+		__rte_unused void *obj_table,
+		__rte_unused unsigned int n,
+		__rte_unused void *cb_arg)
+{
+
+#if 0
+	if (likely(n))
+		printf(" ring (%p) obj (%p) n (%u)\n",
+				r, obj_table, n);
+#endif
+
+	return n;
+}
+#endif
+
 /**
  * Get the last enabled lcore ID
  *
@@ -699,6 +721,15 @@ main(int argc, char **argv)
 	worker_args.ring_in  = rx_to_workers;
 	worker_args.ring_out = workers_to_tx;
 
+#ifdef RTE_RING_ENQDEQ_CALLBACKS
+	if (rte_ring_preenq_callback_register(rte_ring_lookup("rx_to_workers"),
+			dump_ring, NULL))
+		printf("failed preenq_callback_register - rx_to_workers\n");
+	if (rte_ring_pstdeq_callback_register(rte_ring_lookup("workers_to_tx"),
+			dump_ring, NULL))
+		printf("failed pstdeq_callback_register - rx_to_workers\n");
+#endif
+
 	/* Start worker_thread() on all the available slave cores but the last 1 */
 	for (lcore_id = 0; lcore_id <= get_previous_lcore_id(last_lcore_id); lcore_id++)
 		if (rte_lcore_is_enabled(lcore_id) && lcore_id != master_lcore_id)
@@ -724,6 +755,15 @@ main(int argc, char **argv)
 			return -1;
 	}
 
+#ifdef RTE_RING_ENQDEQ_CALLBACKS
+	if (rte_ring_preenq_callback_unregister(
+			rte_ring_lookup("rx_to_workers"), dump_ring, NULL))
+		printf("failed preenq_callback_unregister - rx_to_workers\n");
+	if (rte_ring_pstdeq_callback_unregister(
+			rte_ring_lookup("workers_to_tx"), dump_ring, NULL))
+		printf("failed pstdeq_callback_unregister - rx_to_workers\n");
+#endif
+
 	print_stats();
 	return 0;
 }
diff --git a/examples/packet_ordering/meson.build b/examples/packet_ordering/meson.build
index 6c2fccdcb..a3776946f 100644
--- a/examples/packet_ordering/meson.build
+++ b/examples/packet_ordering/meson.build
@@ -7,6 +7,7 @@
 # DPDK instance, use 'make'
 
 deps += 'reorder'
+allow_experimental_apis = true
 sources = files(
 	'main.c'
 )
-- 
2.17.1



More information about the dev mailing list