DPDK patches and discussions
 help / color / mirror / Atom feed
From: Anoob Joseph <anoob.joseph@caviumnetworks.com>
To: Bruce Richardson <bruce.richardson@intel.com>,
	Jerin Jacob <jerin.jacob@caviumnetworks.com>,
	Pablo de Lara <pablo.de.lara.guarch@intel.com>
Cc: Anoob Joseph <anoob.joseph@caviumnetworks.com>,
	Hemant Agrawal <hemant.agrawal@nxp.com>,
	Narayana Prasad <narayanaprasad.athreya@caviumnetworks.com>,
	Nikhil Rao <nikhil.rao@intel.com>,
	Pavan Nikhilesh <pbhagavatula@caviumnetworks.com>,
	Sunil Kumar Kori <sunil.kori@nxp.com>,
	dev@dpdk.org
Subject: [dpdk-dev] [PATCH 03/20] eventdev: add eventmode CL options framework
Date: Fri,  8 Jun 2018 22:54:02 +0530	[thread overview]
Message-ID: <1528478659-15859-4-git-send-email-anoob.joseph@caviumnetworks.com> (raw)
In-Reply-To: <1528478659-15859-1-git-send-email-anoob.joseph@caviumnetworks.com>

Adding usage prints and CL parsing routines for eventmode. Option to
select packet transfer mode is also added.

Signed-off-by: Anoob Joseph <anoob.joseph@caviumnetworks.com>
---
 lib/librte_eventdev/rte_eventmode_helper.c | 128 +++++++++++++++++++++++++++++
 lib/librte_eventdev/rte_eventmode_helper.h |  50 +++++++++++
 2 files changed, 178 insertions(+)

diff --git a/lib/librte_eventdev/rte_eventmode_helper.c b/lib/librte_eventdev/rte_eventmode_helper.c
index b7ff056..14ea493 100644
--- a/lib/librte_eventdev/rte_eventmode_helper.c
+++ b/lib/librte_eventdev/rte_eventmode_helper.c
@@ -1,7 +1,135 @@
 /* SPDX-License-Identifier: BSD-3-Clause
  * Copyright(c) 2018 Cavium, Inc
  */
+#include <getopt.h>
 
 #include <rte_eventmode_helper.h>
+#include <rte_malloc.h>
 
 #include "rte_eventmode_helper_internal.h"
+
+#define CMD_LINE_OPT_TRANSFER_MODE	"transfer-mode"
+
+static const char short_options[] =
+	""
+	;
+
+enum {
+	/* long options mapped to a short option */
+
+	/* first long only option value must be >= 256, so that we won't
+	 * conflict with short options
+	 */
+	CMD_LINE_OPT_MIN_NUM = 256,
+	CMD_LINE_OPT_TRANSFER_MODE_NUM,
+};
+
+static const struct option lgopts[] = {
+	{CMD_LINE_OPT_TRANSFER_MODE, 1, 0, CMD_LINE_OPT_TRANSFER_MODE_NUM},
+	{NULL, 0, 0, 0}
+};
+
+/* Internal functions */
+
+static int32_t
+internal_parse_decimal(const char *str)
+{
+	char *end = NULL;
+	unsigned long num;
+
+	num = strtoul(str, &end, 10);
+	if ((str[0] == '\0') || (end == NULL) || (*end != '\0'))
+		return -1;
+
+	return num;
+}
+
+/* Global functions */
+
+void
+rte_eventmode_helper_print_options_list(void)
+{
+	fprintf(stderr, " --"
+		" [--transfer-mode MODE]"
+		);
+}
+
+void
+rte_eventmode_helper_print_options_description(void)
+{
+	fprintf(stderr,
+		"  --transfer-mode MODE\n"
+		"               0: Packet transfer via polling (default)\n"
+		"               1: Packet transfer via eventdev\n"
+		"\n");
+}
+
+static int
+em_parse_transfer_mode(struct rte_eventmode_helper_conf *conf,
+		const char *optarg)
+{
+	int32_t parsed_dec;
+
+	parsed_dec = internal_parse_decimal(optarg);
+	if (parsed_dec != RTE_EVENTMODE_HELPER_PKT_TRANSFER_MODE_POLL &&
+	    parsed_dec != RTE_EVENTMODE_HELPER_PKT_TRANSFER_MODE_EVENT) {
+		RTE_EM_HLPR_LOG_ERR("Unsupported packet transfer mode");
+		return -1;
+	}
+	conf->mode = parsed_dec;
+	return 0;
+}
+
+static void
+em_initialize_helper_conf(struct rte_eventmode_helper_conf *conf)
+{
+	/* Set default conf */
+
+	/* Packet transfer mode: poll */
+	conf->mode = RTE_EVENTMODE_HELPER_PKT_TRANSFER_MODE_POLL;
+}
+
+struct rte_eventmode_helper_conf *
+rte_eventmode_helper_parse_args(int argc, char **argv)
+{
+	int32_t opt, ret;
+	struct rte_eventmode_helper_conf *conf = NULL;
+
+	/* Allocate memory for conf */
+	conf = rte_zmalloc("eventmode-helper-conf",
+			sizeof(struct rte_eventmode_helper_conf),
+			RTE_CACHE_LINE_SIZE);
+	if (conf == NULL) {
+		RTE_EM_HLPR_LOG_ERR(
+			"Failed allocating memory for eventmode helper conf");
+			goto err;
+	}
+
+	/* Initialize conf with default values */
+	em_initialize_helper_conf(conf);
+
+	while ((opt = getopt_long(argc, argv, short_options,
+				lgopts, NULL)) != EOF) {
+		switch (opt) {
+
+		/* Packet transfer mode */
+		case CMD_LINE_OPT_TRANSFER_MODE_NUM:
+			ret = em_parse_transfer_mode(conf, optarg);
+			if (ret < 0) {
+				RTE_EM_HLPR_LOG_ERR(
+					"Invalid packet transfer mode");
+				goto err;
+			}
+			break;
+		default:
+			goto err;
+		}
+	}
+	return conf;
+
+err:
+	if (conf != NULL)
+		rte_free(conf);
+
+	return NULL;
+}
diff --git a/lib/librte_eventdev/rte_eventmode_helper.h b/lib/librte_eventdev/rte_eventmode_helper.h
index 5d39bd3..bfe4fa9 100644
--- a/lib/librte_eventdev/rte_eventmode_helper.h
+++ b/lib/librte_eventdev/rte_eventmode_helper.h
@@ -3,4 +3,54 @@
  */
 #ifndef _RTE_EVENTMODE_HELPER_H_
 #define _RTE_EVENTMODE_HELPER_H_
+
+/* Packet transfer mode of the application */
+enum rte_eventmode_helper_pkt_transfer_mode {
+	RTE_EVENTMODE_HELPER_PKT_TRANSFER_MODE_POLL = 0,
+	RTE_EVENTMODE_HELPER_PKT_TRANSFER_MODE_EVENT,
+};
+
+struct rte_eventmode_helper_conf {
+	enum rte_eventmode_helper_pkt_transfer_mode mode;
+		/**< Packet transfer mode of the application */
+	void *mode_params;
+		/**< Mode specific parameters */
+};
+
+/* Common helper functions for command line parsing */
+
+/**
+ * Print event mode options list
+ *
+ */
+void
+rte_eventmode_helper_print_options_list(void);
+
+/**
+ * Print event mode options description
+ *
+ */
+void
+rte_eventmode_helper_print_options_description(void);
+
+/**
+ * Parse event mode arguments
+ *
+ * The application can call this function in it's argument parsing routine to
+ * parse the event mode specific args and create the conf accordingly. This
+ * function is to be executed on the MASTER lcore only.
+ *
+ * @param argc
+ *   A non-negative value. If it is greater than 0, the array members
+ *   for argv[0] through argv[argc] (non-inclusive) shall contain pointers
+ *   to strings.
+ * @param argv
+ *   An array of strings. The contents of the array, as well as the strings
+ *   which are pointed to by the array, may be modified by this function.
+ * @return
+ *   Configuration generated by parsing the event mode args.
+ */
+struct rte_eventmode_helper_conf *
+rte_eventmode_helper_parse_args(int argc, char **argv);
+
 #endif /* _RTE_EVENTMODE_HELPER_H_ */
-- 
2.7.4

  parent reply	other threads:[~2018-06-08 17:25 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-08 17:23 [dpdk-dev] [PATCH 00/20] add eventmode helper functions Anoob Joseph
2018-06-08 17:24 ` [dpdk-dev] [PATCH 01/20] eventdev: add files for eventmode helper Anoob Joseph
2018-06-27  6:20   ` Sunil Kumar Kori
2018-06-28 10:43     ` Joseph, Anoob
2018-06-28 10:47       ` Ananyev, Konstantin
2018-06-28 10:58         ` Joseph, Anoob
2018-06-28 11:44           ` Ananyev, Konstantin
2018-06-28 11:54             ` Joseph, Anoob
2018-07-03  6:27       ` Sunil Kumar Kori
2018-07-03 13:13         ` Joseph, Anoob
2018-07-04 10:49           ` Sunil Kumar Kori
2018-06-08 17:24 ` [dpdk-dev] [PATCH 02/20] eventdev: add routines for logging " Anoob Joseph
2018-06-08 17:24 ` Anoob Joseph [this message]
2018-06-08 17:24 ` [dpdk-dev] [PATCH 04/20] eventdev: allow application to set ethernet portmask Anoob Joseph
2018-06-08 17:24 ` [dpdk-dev] [PATCH 05/20] eventdev: add framework for eventmode conf Anoob Joseph
2018-06-08 17:24 ` [dpdk-dev] [PATCH 06/20] eventdev: add common initialize routine for eventmode devs Anoob Joseph
2018-06-08 17:24 ` [dpdk-dev] [PATCH 07/20] eventdev: add eventdevice init for eventmode Anoob Joseph
2018-06-08 17:24 ` [dpdk-dev] [PATCH 08/20] eventdev: add eventdev port-lcore link Anoob Joseph
2018-06-08 17:24 ` [dpdk-dev] [PATCH 09/20] eventdev: add option to specify schedule mode for app stage Anoob Joseph
2018-06-08 17:24 ` [dpdk-dev] [PATCH 10/20] eventdev: add placeholder for ethdev init Anoob Joseph
2018-06-08 17:24 ` [dpdk-dev] [PATCH 11/20] eventdev: add Rx adapter init in eventmode Anoob Joseph
2018-06-08 17:24 ` [dpdk-dev] [PATCH 12/20] eventdev: add routine to validate conf Anoob Joseph
2018-06-08 17:24 ` [dpdk-dev] [PATCH 13/20] eventdev: add default conf for event devs field in conf Anoob Joseph
2018-06-08 17:24 ` [dpdk-dev] [PATCH 14/20] eventdev: add default conf for Rx adapter conf Anoob Joseph
2018-06-08 17:24 ` [dpdk-dev] [PATCH 15/20] eventdev: add default conf for event port-lcore link Anoob Joseph
2018-06-08 17:24 ` [dpdk-dev] [PATCH 16/20] eventdev: add routines to display the eventmode conf Anoob Joseph
2018-06-08 17:24 ` [dpdk-dev] [PATCH 17/20] eventdev: add routine to access eventmode link info Anoob Joseph
2018-06-08 17:24 ` [dpdk-dev] [PATCH 18/20] eventdev: add routine to access event queue for eth Tx Anoob Joseph
2018-06-08 17:24 ` [dpdk-dev] [PATCH 19/20] eventdev: add routine to launch eventmode workers Anoob Joseph
2018-06-08 17:24 ` [dpdk-dev] [PATCH 20/20] examples/l2fwd: add eventmode for l2fwd Anoob Joseph
2018-06-11  8:32 ` [dpdk-dev] [PATCH 00/20] add eventmode helper functions Jerin Jacob

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1528478659-15859-4-git-send-email-anoob.joseph@caviumnetworks.com \
    --to=anoob.joseph@caviumnetworks.com \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=hemant.agrawal@nxp.com \
    --cc=jerin.jacob@caviumnetworks.com \
    --cc=narayanaprasad.athreya@caviumnetworks.com \
    --cc=nikhil.rao@intel.com \
    --cc=pablo.de.lara.guarch@intel.com \
    --cc=pbhagavatula@caviumnetworks.com \
    --cc=sunil.kori@nxp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).