[dpdk-dev] [PATCH v3 02/10] examples/l2fwd-event: add infra for eventdev

pbhagavatula at marvell.com pbhagavatula at marvell.com
Thu Sep 19 12:13:38 CEST 2019


From: Sunil Kumar Kori <skori at marvell.com>

Add infra to select event device as a mode to process packets through
command line arguments. Also, allow the user to select the schedule type
to be either RTE_SCHED_TYPE_ORDERED or RTE_SCHED_TYPE_ATOMIC.

Usage:

`--mode="eventdev"` or `--mode="poll"`
`--eventq-sync="ordered"` or `--eventq-sync="atomic"`

Signed-off-by: Sunil Kumar Kori <skori at marvell.com>
---
 examples/l2fwd-event/Makefile         |   1 +
 examples/l2fwd-event/l2fwd_eventdev.c | 107 ++++++++++++++++++++++++++
 examples/l2fwd-event/l2fwd_eventdev.h |  62 +++++++++++++++
 examples/l2fwd-event/main.c           |  22 +++++-
 examples/l2fwd-event/meson.build      |   3 +-
 5 files changed, 192 insertions(+), 3 deletions(-)
 create mode 100644 examples/l2fwd-event/l2fwd_eventdev.c
 create mode 100644 examples/l2fwd-event/l2fwd_eventdev.h

diff --git a/examples/l2fwd-event/Makefile b/examples/l2fwd-event/Makefile
index a156c4162..bfe0058a2 100644
--- a/examples/l2fwd-event/Makefile
+++ b/examples/l2fwd-event/Makefile
@@ -7,6 +7,7 @@ APP = l2fwd-event
 
 # all source are stored in SRCS-y
 SRCS-y := main.c
+SRCS-y += l2fwd_eventdev.c
 
 # Build using pkg-config variables if possible
 ifeq ($(shell pkg-config --exists libdpdk && echo 0),0)
diff --git a/examples/l2fwd-event/l2fwd_eventdev.c b/examples/l2fwd-event/l2fwd_eventdev.c
new file mode 100644
index 000000000..19efb6d1e
--- /dev/null
+++ b/examples/l2fwd-event/l2fwd_eventdev.c
@@ -0,0 +1,107 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2019 Marvell International Ltd.
+ */
+
+#include <stdbool.h>
+#include <getopt.h>
+
+#include <rte_atomic.h>
+#include <rte_cycles.h>
+#include <rte_ethdev.h>
+#include <rte_eventdev.h>
+#include <rte_event_eth_rx_adapter.h>
+#include <rte_event_eth_tx_adapter.h>
+#include <rte_lcore.h>
+#include <rte_log.h>
+#include <rte_spinlock.h>
+
+#include "l2fwd_common.h"
+#include "l2fwd_eventdev.h"
+
+static void
+parse_mode(const char *optarg)
+{
+	struct eventdev_resources *eventdev_rsrc = get_eventdev_rsrc();
+
+	if (!strncmp(optarg, "poll", 4))
+		eventdev_rsrc->enabled = false;
+	else if (!strncmp(optarg, "eventdev", 8))
+		eventdev_rsrc->enabled = true;
+}
+
+static void
+parse_eventq_sync(const char *optarg)
+{
+	struct eventdev_resources *eventdev_rsrc = get_eventdev_rsrc();
+
+	if (!strncmp(optarg, "ordered", 7))
+		eventdev_rsrc->sync_mode = RTE_SCHED_TYPE_ORDERED;
+	else if (!strncmp(optarg, "atomic", 6))
+		eventdev_rsrc->sync_mode = RTE_SCHED_TYPE_ATOMIC;
+}
+
+static int
+parse_eventdev_args(char **argv, int argc)
+{
+	const struct option eventdev_lgopts[] = {
+		{CMD_LINE_OPT_MODE, 1, 0, CMD_LINE_OPT_MODE_NUM},
+		{CMD_LINE_OPT_EVENTQ_SYNC, 1, 0, CMD_LINE_OPT_EVENTQ_SYNC_NUM},
+		{NULL, 0, 0, 0}
+	};
+	char **argvopt = argv;
+	int32_t option_index;
+	int32_t opt;
+
+	while ((opt = getopt_long(argc, argvopt, "", eventdev_lgopts,
+					&option_index)) != EOF) {
+		switch (opt) {
+		case CMD_LINE_OPT_MODE_NUM:
+			parse_mode(optarg);
+			break;
+
+		case CMD_LINE_OPT_EVENTQ_SYNC_NUM:
+			parse_eventq_sync(optarg);
+			break;
+
+		case '?':
+			/* skip other parameters except eventdev specific */
+			break;
+
+		default:
+			printf("Invalid eventdev parameter\n");
+			return -1;
+		}
+	}
+
+	return 0;
+}
+
+void
+eventdev_resource_setup(void)
+{
+	struct eventdev_resources *eventdev_rsrc = get_eventdev_rsrc();
+	uint32_t service_id;
+	int32_t ret;
+
+	/* Parse eventdev command line options */
+	ret = parse_eventdev_args(eventdev_rsrc->args, eventdev_rsrc->nb_args);
+	if (ret < 0)
+		return;
+
+	if (!rte_event_dev_count())
+		rte_exit(EXIT_FAILURE, "No Eventdev found");
+	/* Start event device service */
+	ret = rte_event_dev_service_id_get(eventdev_rsrc->event_d_id,
+			&service_id);
+	if (ret != -ESRCH && ret != 0)
+		rte_exit(EXIT_FAILURE, "Error in starting eventdev");
+
+	rte_service_runstate_set(service_id, 1);
+	rte_service_set_runstate_mapped_check(service_id, 0);
+	eventdev_rsrc->service_id = service_id;
+
+	/* Start event device */
+	ret = rte_event_dev_start(eventdev_rsrc->event_d_id);
+	if (ret < 0)
+		rte_exit(EXIT_FAILURE, "Error in starting eventdev");
+}
diff --git a/examples/l2fwd-event/l2fwd_eventdev.h b/examples/l2fwd-event/l2fwd_eventdev.h
new file mode 100644
index 000000000..2e8d95e67
--- /dev/null
+++ b/examples/l2fwd-event/l2fwd_eventdev.h
@@ -0,0 +1,62 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2019 Marvell International Ltd.
+ */
+
+#ifndef __L2FWD_EVENTDEV_H__
+#define __L2FWD_EVENTDEV_H__
+
+#include <rte_common.h>
+#include <rte_spinlock.h>
+
+#include "l2fwd_common.h"
+
+#define CMD_LINE_OPT_MODE "mode"
+#define CMD_LINE_OPT_EVENTQ_SYNC "eventq-sync"
+
+enum {
+	CMD_LINE_OPT_MODE_NUM = 265,
+	CMD_LINE_OPT_EVENTQ_SYNC_NUM,
+};
+
+struct eventdev_resources {
+	struct l2fwd_port_statistics *stats;
+	struct rte_mempool *pkt_pool;
+	uint64_t timer_period;
+	uint32_t *dst_ports;
+	uint32_t service_id;
+	uint32_t port_mask;
+	volatile bool *done;
+	uint8_t event_d_id;
+	uint8_t sync_mode;
+	uint8_t tx_mode_q;
+	uint8_t mac_updt;
+	uint8_t enabled;
+	uint8_t nb_args;
+	char **args;
+};
+
+static inline struct eventdev_resources *
+get_eventdev_rsrc(void)
+{
+	static const char name[RTE_MEMZONE_NAMESIZE] = "l2fwd_event_rsrc";
+	const struct rte_memzone *mz;
+
+	mz = rte_memzone_lookup(name);
+
+	if (mz != NULL)
+		return mz->addr;
+
+	mz = rte_memzone_reserve(name, sizeof(struct eventdev_resources), 0, 0);
+	if (mz != NULL) {
+		memset(mz->addr, 0, sizeof(struct eventdev_resources));
+		return mz->addr;
+	}
+
+	rte_exit(EXIT_FAILURE, "Unable to allocate memory for eventdev cfg\n");
+
+	return NULL;
+}
+
+void eventdev_resource_setup(void);
+
+#endif /* __L2FWD_EVENTDEV_H__ */
diff --git a/examples/l2fwd-event/main.c b/examples/l2fwd-event/main.c
index cc47fa203..661f0833f 100644
--- a/examples/l2fwd-event/main.c
+++ b/examples/l2fwd-event/main.c
@@ -42,6 +42,7 @@
 #include <rte_spinlock.h>
 
 #include "l2fwd_common.h"
+#include "l2fwd_eventdev.h"
 
 static volatile bool force_quit;
 
@@ -288,7 +289,12 @@ l2fwd_usage(const char *prgname)
 	       "  --[no-]mac-updating: Enable or disable MAC addresses updating (enabled by default)\n"
 	       "      When enabled:\n"
 	       "       - The source MAC address is replaced by the TX port MAC address\n"
-	       "       - The destination MAC address is replaced by 02:00:00:00:00:TX_PORT_ID\n",
+	       "       - The destination MAC address is replaced by 02:00:00:00:00:TX_PORT_ID\n"
+	       "  --mode: Packet transfer mode for I/O, poll or eventdev\n"
+	       "          Default mode = eventdev\n"
+	       "  --eventq-sync:Event queue synchronization method,\n"
+	       "                ordered or atomic.\nDefault: atomic\n"
+	       "                Valid only if --mode=eventdev\n\n",
 	       prgname);
 }
 
@@ -503,6 +509,7 @@ signal_handler(int signum)
 int
 main(int argc, char **argv)
 {
+	struct eventdev_resources *eventdev_rsrc;
 	uint16_t nb_ports_available = 0;
 	struct lcore_queue_conf *qconf;
 	uint32_t nb_ports_in_mask = 0;
@@ -524,6 +531,7 @@ main(int argc, char **argv)
 	signal(SIGINT, signal_handler);
 	signal(SIGTERM, signal_handler);
 
+	eventdev_rsrc = get_eventdev_rsrc();
 	/* parse application arguments (after the EAL ones) */
 	ret = l2fwd_parse_args(argc, argv);
 	if (ret < 0)
@@ -584,6 +592,17 @@ main(int argc, char **argv)
 	if (l2fwd_pktmbuf_pool == NULL)
 		rte_exit(EXIT_FAILURE, "Cannot init mbuf pool\n");
 
+	eventdev_rsrc->port_mask = l2fwd_enabled_port_mask;
+	eventdev_rsrc->pkt_pool = l2fwd_pktmbuf_pool;
+	eventdev_rsrc->dst_ports = l2fwd_dst_ports;
+	eventdev_rsrc->timer_period = timer_period;
+	eventdev_rsrc->mac_updt = mac_updating;
+	eventdev_rsrc->stats = port_statistics;
+	eventdev_rsrc->done = &force_quit;
+
+	/* Configure eventdev parameters if user has requested */
+	eventdev_resource_setup();
+
 	/* Initialize the port/queue configuration of each logical core */
 	RTE_ETH_FOREACH_DEV(portid) {
 		/* skip ports that are not enabled */
@@ -610,7 +629,6 @@ main(int argc, char **argv)
 		printf("Lcore %u: RX port %u\n", rx_lcore_id, portid);
 	}
 
-
 	/* Initialise each port */
 	RTE_ETH_FOREACH_DEV(portid) {
 		struct rte_eth_rxconf rxq_conf;
diff --git a/examples/l2fwd-event/meson.build b/examples/l2fwd-event/meson.build
index 16eadb0b4..b1ad48cc5 100644
--- a/examples/l2fwd-event/meson.build
+++ b/examples/l2fwd-event/meson.build
@@ -8,5 +8,6 @@
 # DPDK instance, use 'make'
 
 sources = files(
-	'main.c'
+	'main.c',
+	'l2fwd_eventdev.c'
 )
-- 
2.17.1



More information about the dev mailing list