DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH 00/11] improve options help
@ 2021-03-09 23:31 Thomas Monjalon
  2021-03-09 23:31 ` [dpdk-dev] [PATCH 01/11] eal: explain argv behaviour during init Thomas Monjalon
                   ` (17 more replies)
  0 siblings, 18 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-09 23:31 UTC (permalink / raw)
  To: dev; +Cc: david.marchand

The main intent of this series is to provide a nice help
for the --log-level option.
More patches are added to improve options help in general.

Thomas Monjalon (11):
  eal: explain argv behaviour during init
  eal: improve options usage text
  eal: use macros for help option
  eal: move private log functions
  eal: introduce maximum log level macro
  eal: catch invalid log level number
  eal: add log level help
  app: fix exit messages
  app: hook in EAL usage help
  app/regex: fix usage text
  app/testpmd: fix usage text

 app/pdump/main.c                              |  2 +
 app/proc-info/main.c                          |  2 +
 app/test-acl/main.c                           |  2 +
 app/test-bbdev/main.c                         |  3 +-
 app/test-compress-perf/comp_perf_options.h    |  2 +
 .../comp_perf_options_parse.c                 | 10 +--
 app/test-compress-perf/main.c                 |  3 +-
 app/test-crypto-perf/cperf_options.h          |  2 +
 app/test-crypto-perf/cperf_options_parsing.c  | 10 +--
 app/test-crypto-perf/main.c                   |  3 +-
 app/test-fib/main.c                           |  8 +++
 app/test-flow-perf/main.c                     | 63 +++++++++---------
 app/test-pmd/parameters.c                     | 34 ++--------
 app/test-pmd/testpmd.c                        |  2 +
 app/test-pmd/testpmd.h                        |  1 +
 app/test-regex/main.c                         | 10 +--
 app/test-sad/main.c                           |  7 ++
 lib/librte_eal/common/eal_common_log.c        | 50 +++++++++-----
 lib/librte_eal/common/eal_common_options.c    | 66 ++++++++++++-------
 lib/librte_eal/common/eal_log.h               | 32 +++++++++
 lib/librte_eal/common/eal_private.h           | 29 --------
 lib/librte_eal/freebsd/eal.c                  | 10 +--
 lib/librte_eal/include/rte_eal.h              |  2 +
 lib/librte_eal/include/rte_log.h              | 12 ++++
 lib/librte_eal/linux/eal.c                    | 17 ++---
 lib/librte_eal/linux/eal_log.c                |  4 +-
 lib/librte_eal/version.map                    |  3 +
 lib/librte_eal/windows/eal.c                  | 15 ++---
 lib/librte_eal/windows/eal_log.c              |  6 +-
 29 files changed, 237 insertions(+), 173 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_log.h

-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH 01/11] eal: explain argv behaviour during init
  2021-03-09 23:31 [dpdk-dev] [PATCH 00/11] improve options help Thomas Monjalon
@ 2021-03-09 23:31 ` Thomas Monjalon
  2021-03-09 23:31 ` [dpdk-dev] [PATCH 02/11] eal: improve options usage text Thomas Monjalon
                   ` (16 subsequent siblings)
  17 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-09 23:31 UTC (permalink / raw)
  To: dev; +Cc: david.marchand

After argument parsing done by rte_eal_init(),
the remaining arguments are to be parsed by the application
by progressing in the argv array.
In this context, the first string represented by argv[0] is still
the same program name as the original argv[0],
while the next strings are the application arguments.
This is because rte_eal_init() manipulates the argv array
after EAL parsing, before returning to the application.

This note was missing in the doxygen comment of the API.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 lib/librte_eal/include/rte_eal.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/librte_eal/include/rte_eal.h b/lib/librte_eal/include/rte_eal.h
index eaf6469e50..0cbeedb594 100644
--- a/lib/librte_eal/include/rte_eal.h
+++ b/lib/librte_eal/include/rte_eal.h
@@ -76,6 +76,8 @@ int rte_eal_iopl_init(void);
  * @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.
+ *   The program name pointer argv[0] is copied into the last parsed argv
+ *   so that argv[0] is still the same after deducing the parsed arguments.
  * @return
  *   - On success, the number of parsed arguments, which is greater or
  *     equal to zero. After the call to rte_eal_init(),
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH 02/11] eal: improve options usage text
  2021-03-09 23:31 [dpdk-dev] [PATCH 00/11] improve options help Thomas Monjalon
  2021-03-09 23:31 ` [dpdk-dev] [PATCH 01/11] eal: explain argv behaviour during init Thomas Monjalon
@ 2021-03-09 23:31 ` Thomas Monjalon
  2021-03-09 23:31 ` [dpdk-dev] [PATCH 03/11] eal: use macros for help option Thomas Monjalon
                   ` (15 subsequent siblings)
  17 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-09 23:31 UTC (permalink / raw)
  To: dev
  Cc: david.marchand, Bruce Richardson, Dmitry Kozlyuk,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam

The description of the EAL options was printed before the application
description provided via the hook.
It is better to let the application print the global syntax
and describes the detail of the EAL options below.

Also, some useless lines are removed,
and the alignment of few options is fixed.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 lib/librte_eal/common/eal_common_options.c | 11 +++++------
 lib/librte_eal/freebsd/eal.c               |  8 ++++----
 lib/librte_eal/linux/eal.c                 | 12 ++++++------
 lib/librte_eal/windows/eal.c               | 10 ++++------
 4 files changed, 19 insertions(+), 22 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 622c7bc429..0635b0d4ce 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -2022,8 +2022,7 @@ rte_vect_set_max_simd_bitwidth(uint16_t bitwidth)
 void
 eal_common_usage(void)
 {
-	printf("[options]\n\n"
-	       "EAL common options:\n"
+	printf("EAL common options:\n"
 	       "  -c COREMASK         Hexadecimal bitmask of cores to run on\n"
 	       "  -l CORELIST         List of cores to run on\n"
 	       "                      The argument format is <c1>[-c2][,c3[-c4],...]\n"
@@ -2053,7 +2052,7 @@ eal_common_usage(void)
 	       "  --"OPT_VDEV"              Add a virtual device.\n"
 	       "                      The argument format is <driver><id>[,key=val,...]\n"
 	       "                      (ex: --vdev=net_pcap0,iface=eth2).\n"
-	       "  --"OPT_IOVA_MODE"   Set IOVA mode. 'pa' for IOVA_PA\n"
+	       "  --"OPT_IOVA_MODE"         Set IOVA mode. 'pa' for IOVA_PA\n"
 	       "                      'va' for IOVA_VA\n"
 	       "  -d LIB.so|DIR       Add a driver or driver directory\n"
 	       "                      (can be used multiple times)\n"
@@ -2092,11 +2091,11 @@ eal_common_usage(void)
 #endif /* !RTE_EXEC_ENV_WINDOWS */
 	       "  -v                  Display version information on startup\n"
 	       "  -h, --help          This help\n"
-	       "  --"OPT_IN_MEMORY"   Operate entirely in memory. This will\n"
+	       "  --"OPT_IN_MEMORY"         Operate entirely in memory. This will\n"
 	       "                      disable secondary process support\n"
 	       "  --"OPT_BASE_VIRTADDR"     Base virtual address\n"
-	       "  --"OPT_TELEMETRY"   Enable telemetry support (on by default)\n"
-	       "  --"OPT_NO_TELEMETRY"   Disable telemetry support\n"
+	       "  --"OPT_TELEMETRY"         Enable telemetry support (on by default)\n"
+	       "  --"OPT_NO_TELEMETRY"      Disable telemetry support\n"
 	       "  --"OPT_FORCE_MAX_SIMD_BITWIDTH" Force the max SIMD bitwidth\n"
 	       "\nEAL options for DEBUG use only:\n"
 	       "  --"OPT_HUGE_UNLINK"       Unlink hugepage files after init\n"
diff --git a/lib/librte_eal/freebsd/eal.c b/lib/librte_eal/freebsd/eal.c
index afbbb1c523..f466616566 100644
--- a/lib/librte_eal/freebsd/eal.c
+++ b/lib/librte_eal/freebsd/eal.c
@@ -421,13 +421,13 @@ eal_usage(const char *prgname)
 {
 	rte_usage_hook_t hook = eal_get_application_usage_hook();
 
-	printf("\nUsage: %s ", prgname);
-	eal_common_usage();
-	/* Allow the application to print its usage message too if hook is set */
 	if (hook) {
-		printf("===== Application Usage =====\n\n");
+		/* Print application usage through EAL options parsing. */
 		(hook)(prgname);
+		printf("\n");
 	}
+
+	eal_common_usage();
 }
 
 static inline size_t
diff --git a/lib/librte_eal/linux/eal.c b/lib/librte_eal/linux/eal.c
index bc966150a5..7c1d296192 100644
--- a/lib/librte_eal/linux/eal.c
+++ b/lib/librte_eal/linux/eal.c
@@ -534,7 +534,12 @@ eal_usage(const char *prgname)
 {
 	rte_usage_hook_t hook = eal_get_application_usage_hook();
 
-	printf("\nUsage: %s ", prgname);
+	if (hook) {
+		/* Print application usage through EAL options parsing. */
+		(hook)(prgname);
+		printf("\n");
+	}
+
 	eal_common_usage();
 	printf("EAL Linux options:\n"
 	       "  --"OPT_SOCKET_MEM"        Memory to allocate on sockets (comma separated values)\n"
@@ -548,11 +553,6 @@ eal_usage(const char *prgname)
 	       "  --"OPT_SINGLE_FILE_SEGMENTS" Put all hugepage memory in single files\n"
 	       "  --"OPT_MATCH_ALLOCATIONS" Free hugepages exactly as allocated\n"
 	       "\n");
-	/* Allow the application to print its usage message too if hook is set */
-	if (hook) {
-		printf("===== Application Usage =====\n\n");
-		(hook)(prgname);
-	}
 }
 
 static int
diff --git a/lib/librte_eal/windows/eal.c b/lib/librte_eal/windows/eal.c
index 2fc3d6141c..ec13ac1a9f 100644
--- a/lib/librte_eal/windows/eal.c
+++ b/lib/librte_eal/windows/eal.c
@@ -79,15 +79,13 @@ eal_usage(const char *prgname)
 {
 	rte_usage_hook_t hook = eal_get_application_usage_hook();
 
-	printf("\nUsage: %s ", prgname);
-	eal_common_usage();
-	/* Allow the application to print its usage message too
-	 * if hook is set
-	 */
 	if (hook) {
-		printf("===== Application Usage =====\n\n");
+		/* Print application usage through EAL options parsing. */
 		(hook)(prgname);
+		printf("\n");
 	}
+
+	eal_common_usage();
 }
 
 /* Parse the arguments for --log-level only */
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH 03/11] eal: use macros for help option
  2021-03-09 23:31 [dpdk-dev] [PATCH 00/11] improve options help Thomas Monjalon
  2021-03-09 23:31 ` [dpdk-dev] [PATCH 01/11] eal: explain argv behaviour during init Thomas Monjalon
  2021-03-09 23:31 ` [dpdk-dev] [PATCH 02/11] eal: improve options usage text Thomas Monjalon
@ 2021-03-09 23:31 ` Thomas Monjalon
  2021-03-09 23:31 ` [dpdk-dev] [PATCH 04/11] eal: move private log functions Thomas Monjalon
                   ` (14 subsequent siblings)
  17 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-09 23:31 UTC (permalink / raw)
  To: dev
  Cc: david.marchand, Bruce Richardson, Dmitry Kozlyuk,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam

The macros OPT_HELP and OPT_HELP_NUM were not used where appropriate.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 lib/librte_eal/common/eal_common_options.c | 2 +-
 lib/librte_eal/freebsd/eal.c               | 2 +-
 lib/librte_eal/linux/eal.c                 | 2 +-
 lib/librte_eal/windows/eal.c               | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 0635b0d4ce..52fedb81e5 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -2090,7 +2090,7 @@ eal_common_usage(void)
 	       "                      must be specified once only.\n"
 #endif /* !RTE_EXEC_ENV_WINDOWS */
 	       "  -v                  Display version information on startup\n"
-	       "  -h, --help          This help\n"
+	       "  -h, --"OPT_HELP"          This help\n"
 	       "  --"OPT_IN_MEMORY"         Operate entirely in memory. This will\n"
 	       "                      disable secondary process support\n"
 	       "  --"OPT_BASE_VIRTADDR"     Base virtual address\n"
diff --git a/lib/librte_eal/freebsd/eal.c b/lib/librte_eal/freebsd/eal.c
index f466616566..66adfca2d1 100644
--- a/lib/librte_eal/freebsd/eal.c
+++ b/lib/librte_eal/freebsd/eal.c
@@ -549,7 +549,7 @@ eal_parse_args(int argc, char **argv)
 			}
 			break;
 		}
-		case 'h':
+		case OPT_HELP_NUM:
 			eal_usage(prgname);
 			exit(EXIT_SUCCESS);
 		default:
diff --git a/lib/librte_eal/linux/eal.c b/lib/librte_eal/linux/eal.c
index 7c1d296192..6f73616f86 100644
--- a/lib/librte_eal/linux/eal.c
+++ b/lib/librte_eal/linux/eal.c
@@ -716,7 +716,7 @@ eal_parse_args(int argc, char **argv)
 			continue;
 
 		switch (opt) {
-		case 'h':
+		case OPT_HELP_NUM:
 			eal_usage(prgname);
 			exit(EXIT_SUCCESS);
 
diff --git a/lib/librte_eal/windows/eal.c b/lib/librte_eal/windows/eal.c
index ec13ac1a9f..4dd2fc1403 100644
--- a/lib/librte_eal/windows/eal.c
+++ b/lib/librte_eal/windows/eal.c
@@ -158,7 +158,7 @@ eal_parse_args(int argc, char **argv)
 			continue;
 
 		switch (opt) {
-		case 'h':
+		case OPT_HELP_NUM:
 			eal_usage(prgname);
 			exit(EXIT_SUCCESS);
 		default:
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH 04/11] eal: move private log functions
  2021-03-09 23:31 [dpdk-dev] [PATCH 00/11] improve options help Thomas Monjalon
                   ` (2 preceding siblings ...)
  2021-03-09 23:31 ` [dpdk-dev] [PATCH 03/11] eal: use macros for help option Thomas Monjalon
@ 2021-03-09 23:31 ` Thomas Monjalon
  2021-03-09 23:31 ` [dpdk-dev] [PATCH 05/11] eal: introduce maximum log level macro Thomas Monjalon
                   ` (13 subsequent siblings)
  17 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-09 23:31 UTC (permalink / raw)
  To: dev
  Cc: david.marchand, Dmitry Kozlyuk, Narcisa Ana Maria Vasile,
	Dmitry Malloy, Pallavi Kadam

Some private log functions had a wrong "rte_" prefix.

All private log functions are moved from eal_private.h
to the new file eal_log.h:
	rte_eal_log_init -> eal_log_init
	rte_log_save_regexp -> eal_log_save_regexp
	rte_log_save_pattern -> eal_log_save_pattern
	eal_log_set_default

The static functions in the file eal_common_log.c are renamed:
	rte_log_save_level -> log_save_level
	rte_log_init -> log_init

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 lib/librte_eal/common/eal_common_log.c     | 18 ++++++++------
 lib/librte_eal/common/eal_common_options.c |  5 ++--
 lib/librte_eal/common/eal_log.h            | 27 ++++++++++++++++++++
 lib/librte_eal/common/eal_private.h        | 29 ----------------------
 lib/librte_eal/linux/eal.c                 |  3 ++-
 lib/librte_eal/linux/eal_log.c             |  4 +--
 lib/librte_eal/windows/eal.c               |  3 ++-
 lib/librte_eal/windows/eal_log.c           |  6 +++--
 8 files changed, 50 insertions(+), 45 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_log.h

diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c
index c5554badb2..85364ee47a 100644
--- a/lib/librte_eal/common/eal_common_log.c
+++ b/lib/librte_eal/common/eal_common_log.c
@@ -15,7 +15,7 @@
 #include <rte_log.h>
 #include <rte_per_lcore.h>
 
-#include "eal_private.h"
+#include "eal_log.h"
 
 struct rte_log_dynamic_type {
 	const char *name;
@@ -178,8 +178,8 @@ rte_log_set_level_regexp(const char *regex, uint32_t level)
  * Save the type string and the loglevel for later dynamic
  * logtypes which may register later.
  */
-static int rte_log_save_level(int priority,
-			      const char *regex, const char *pattern)
+static int
+log_save_level(int priority, const char *regex, const char *pattern)
 {
 	struct rte_eal_opt_loglevel *opt_ll = NULL;
 
@@ -207,9 +207,10 @@ static int rte_log_save_level(int priority,
 	return -1;
 }
 
-int rte_log_save_regexp(const char *regex, int tmp)
+int
+eal_log_save_regexp(const char *regex, int tmp)
 {
-	return rte_log_save_level(tmp, regex, NULL);
+	return log_save_level(tmp, regex, NULL);
 }
 
 /* set log level based on globbing pattern */
@@ -232,9 +233,10 @@ rte_log_set_level_pattern(const char *pattern, uint32_t level)
 	return 0;
 }
 
-int rte_log_save_pattern(const char *pattern, int priority)
+int
+eal_log_save_pattern(const char *pattern, int priority)
 {
-	return rte_log_save_level(priority, NULL, pattern);
+	return log_save_level(priority, NULL, pattern);
 }
 
 /* get the current loglevel for the message being processed */
@@ -376,7 +378,7 @@ static const struct logtype logtype_strings[] = {
 };
 
 /* Logging should be first initializer (before drivers and bus) */
-RTE_INIT_PRIO(rte_log_init, LOG)
+RTE_INIT_PRIO(log_init, LOG)
 {
 	uint32_t i;
 
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 52fedb81e5..02374ee09e 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -41,6 +41,7 @@
 #include "eal_options.h"
 #include "eal_filesystem.h"
 #include "eal_private.h"
+#include "eal_log.h"
 #ifndef RTE_EXEC_ENV_WINDOWS
 #include "eal_trace.h"
 #endif
@@ -1299,7 +1300,7 @@ eal_parse_log_level(const char *arg)
 				regex, priority);
 			goto fail;
 		}
-		if (rte_log_save_regexp(regex, priority) < 0)
+		if (eal_log_save_regexp(regex, priority) < 0)
 			goto fail;
 	} else if (pattern) {
 		if (rte_log_set_level_pattern(pattern, priority) < 0) {
@@ -1307,7 +1308,7 @@ eal_parse_log_level(const char *arg)
 				pattern, priority);
 			goto fail;
 		}
-		if (rte_log_save_pattern(pattern, priority) < 0)
+		if (eal_log_save_pattern(pattern, priority) < 0)
 			goto fail;
 	} else {
 		rte_log_set_global_level(priority);
diff --git a/lib/librte_eal/common/eal_log.h b/lib/librte_eal/common/eal_log.h
new file mode 100644
index 0000000000..c057301769
--- /dev/null
+++ b/lib/librte_eal/common/eal_log.h
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2021 Mellanox Technologies, Ltd
+ */
+
+#ifndef EAL_LOG_H
+#define EAL_LOG_H
+
+#include <stdio.h>
+#include <stdint.h>
+
+/*
+ * Initialize the default log stream.
+ */
+int eal_log_init(const char *id, int facility);
+
+/*
+ * Determine where log data is written when no call to rte_openlog_stream.
+ */
+void eal_log_set_default(FILE *default_log);
+
+/*
+ * Save a log option for later.
+ */
+int eal_log_save_regexp(const char *regexp, int priority);
+int eal_log_save_pattern(const char *pattern, int priority);
+
+#endif /* EAL_LOG_H */
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index b8a0d20021..e3512111d9 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -79,19 +79,6 @@ struct rte_config *rte_eal_get_configuration(void);
  */
 int rte_eal_memzone_init(void);
 
-/**
- * Common log initialization function (private to eal).  Determines
- * where log data is written when no call to rte_openlog_stream is
- * in effect.
- *
- * @param default_log
- *   The default log stream to be used.
- * @return
- *   - 0 on success
- *   - Negative on error
- */
-void eal_log_set_default(FILE *default_log);
-
 /**
  * Fill configuration with number of physical and logical processors
  *
@@ -143,22 +130,6 @@ int rte_eal_memory_init(void);
  */
 int rte_eal_timer_init(void);
 
-/**
- * Init the default log stream
- *
- * This function is private to EAL.
- *
- * @return
- *   0 on success, negative on error
- */
-int rte_eal_log_init(const char *id, int facility);
-
-/**
- * Save the log regexp for later
- */
-int rte_log_save_regexp(const char *type, int priority);
-int rte_log_save_pattern(const char *pattern, int priority);
-
 /**
  * Init tail queues for non-EAL library structures. This is to allow
  * the rings, mempools, etc. lists to be shared among multiple processes
diff --git a/lib/librte_eal/linux/eal.c b/lib/librte_eal/linux/eal.c
index 6f73616f86..e4feeb2b0e 100644
--- a/lib/librte_eal/linux/eal.c
+++ b/lib/librte_eal/linux/eal.c
@@ -58,6 +58,7 @@
 #include "eal_hugepages.h"
 #include "eal_memcfg.h"
 #include "eal_trace.h"
+#include "eal_log.h"
 #include "eal_options.h"
 #include "eal_vfio.h"
 #include "hotplug_mp.h"
@@ -1160,7 +1161,7 @@ rte_eal_init(int argc, char **argv)
 #endif
 	}
 
-	if (rte_eal_log_init(logid, internal_conf->syslog_facility) < 0) {
+	if (eal_log_init(logid, internal_conf->syslog_facility) < 0) {
 		rte_eal_init_alert("Cannot init logging.");
 		rte_errno = ENOMEM;
 		__atomic_store_n(&run_once, 0, __ATOMIC_RELAXED);
diff --git a/lib/librte_eal/linux/eal_log.c b/lib/librte_eal/linux/eal_log.c
index 43c8460bfb..1a08139eb5 100644
--- a/lib/librte_eal/linux/eal_log.c
+++ b/lib/librte_eal/linux/eal_log.c
@@ -17,7 +17,7 @@
 #include <rte_spinlock.h>
 #include <rte_log.h>
 
-#include "eal_private.h"
+#include "eal_log.h"
 
 /*
  * default log function
@@ -46,7 +46,7 @@ static cookie_io_functions_t console_log_func = {
  * once memzones are available.
  */
 int
-rte_eal_log_init(const char *id, int facility)
+eal_log_init(const char *id, int facility)
 {
 	FILE *log_stream;
 
diff --git a/lib/librte_eal/windows/eal.c b/lib/librte_eal/windows/eal.c
index 4dd2fc1403..5bca3ace1c 100644
--- a/lib/librte_eal/windows/eal.c
+++ b/lib/librte_eal/windows/eal.c
@@ -22,6 +22,7 @@
 
 #include "eal_hugepages.h"
 #include "eal_trace.h"
+#include "eal_log.h"
 #include "eal_windows.h"
 
 #define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL)
@@ -265,7 +266,7 @@ rte_eal_init(int argc, char **argv)
 		eal_get_internal_configuration();
 	int ret;
 
-	rte_eal_log_init(NULL, 0);
+	eal_log_init(NULL, 0);
 
 	eal_log_level_parse(argc, argv);
 
diff --git a/lib/librte_eal/windows/eal_log.c b/lib/librte_eal/windows/eal_log.c
index 875981f139..d4ea47f1c8 100644
--- a/lib/librte_eal/windows/eal_log.c
+++ b/lib/librte_eal/windows/eal_log.c
@@ -2,11 +2,13 @@
  * Copyright(c) 2017-2018 Intel Corporation
  */
 
-#include "eal_private.h"
+#include <rte_common.h>
+#include <rte_log.h>
+#include "eal_log.h"
 
 /* set the log to default function, called during eal init process. */
 int
-rte_eal_log_init(__rte_unused const char *id, __rte_unused int facility)
+eal_log_init(__rte_unused const char *id, __rte_unused int facility)
 {
 	rte_openlog_stream(stderr);
 
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH 05/11] eal: introduce maximum log level macro
  2021-03-09 23:31 [dpdk-dev] [PATCH 00/11] improve options help Thomas Monjalon
                   ` (3 preceding siblings ...)
  2021-03-09 23:31 ` [dpdk-dev] [PATCH 04/11] eal: move private log functions Thomas Monjalon
@ 2021-03-09 23:31 ` Thomas Monjalon
  2021-03-10 12:46   ` Thomas Monjalon
  2021-03-09 23:31 ` [dpdk-dev] [PATCH 06/11] eal: catch invalid log level number Thomas Monjalon
                   ` (12 subsequent siblings)
  17 siblings, 1 reply; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-09 23:31 UTC (permalink / raw)
  To: dev; +Cc: david.marchand

RTE_DIM(...) and RTE_LOG_DEBUG were used to get the highest log level.
For better clarity a new constant RTE_LOG_MAX is introduced
and mapped to RTE_LOG_DEBUG.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 lib/librte_eal/common/eal_common_log.c     | 8 ++++----
 lib/librte_eal/common/eal_common_options.c | 2 +-
 lib/librte_eal/include/rte_log.h           | 1 +
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c
index 85364ee47a..7f40c36f7e 100644
--- a/lib/librte_eal/common/eal_common_log.c
+++ b/lib/librte_eal/common/eal_common_log.c
@@ -140,7 +140,7 @@ rte_log_set_level(uint32_t type, uint32_t level)
 {
 	if (type >= rte_logs.dynamic_types_len)
 		return -1;
-	if (level > RTE_LOG_DEBUG)
+	if (level > RTE_LOG_MAX)
 		return -1;
 
 	rte_logs.dynamic_types[type].loglevel = level;
@@ -155,7 +155,7 @@ rte_log_set_level_regexp(const char *regex, uint32_t level)
 	regex_t r;
 	size_t i;
 
-	if (level > RTE_LOG_DEBUG)
+	if (level > RTE_LOG_MAX)
 		return -1;
 
 	if (regcomp(&r, regex, 0) != 0)
@@ -219,7 +219,7 @@ rte_log_set_level_pattern(const char *pattern, uint32_t level)
 {
 	size_t i;
 
-	if (level > RTE_LOG_DEBUG)
+	if (level > RTE_LOG_MAX)
 		return -1;
 
 	for (i = 0; i < rte_logs.dynamic_types_len; i++) {
@@ -323,7 +323,7 @@ rte_log_register_type_and_pick_level(const char *name, uint32_t level_def)
 		return type;
 
 	TAILQ_FOREACH(opt_ll, &opt_loglevel_list, next) {
-		if (opt_ll->level > RTE_LOG_DEBUG)
+		if (opt_ll->level > RTE_LOG_MAX)
 			continue;
 
 		if (opt_ll->pattern) {
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 02374ee09e..febc99612a 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -1249,7 +1249,7 @@ eal_parse_log_priority(const char *level)
 		return -1;
 
 	/* look for named values, skip 0 which is not a valid level */
-	for (i = 1; i < RTE_DIM(levels); i++) {
+	for (i = 1; i < RTE_LOG_MAX; i++) {
 		if (strncmp(levels[i], level, len) == 0)
 			return i;
 	}
diff --git a/lib/librte_eal/include/rte_log.h b/lib/librte_eal/include/rte_log.h
index 173004fd71..394e8682b9 100644
--- a/lib/librte_eal/include/rte_log.h
+++ b/lib/librte_eal/include/rte_log.h
@@ -72,6 +72,7 @@ extern "C" {
 #define RTE_LOG_NOTICE   6U  /**< Normal but significant condition. */
 #define RTE_LOG_INFO     7U  /**< Informational.                    */
 #define RTE_LOG_DEBUG    8U  /**< Debug-level messages.             */
+#define RTE_LOG_MAX RTE_LOG_DEBUG /**< Most detailed log level.     */
 
 /**
  * Change the stream that will be used by the logging system.
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH 06/11] eal: catch invalid log level number
  2021-03-09 23:31 [dpdk-dev] [PATCH 00/11] improve options help Thomas Monjalon
                   ` (4 preceding siblings ...)
  2021-03-09 23:31 ` [dpdk-dev] [PATCH 05/11] eal: introduce maximum log level macro Thomas Monjalon
@ 2021-03-09 23:31 ` Thomas Monjalon
  2021-03-10 12:19   ` Bruce Richardson
  2021-03-09 23:31 ` [dpdk-dev] [PATCH 07/11] eal: add log level help Thomas Monjalon
                   ` (11 subsequent siblings)
  17 siblings, 1 reply; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-09 23:31 UTC (permalink / raw)
  To: dev; +Cc: david.marchand

The parsing check for invalid log level was not trying to catch
irrelevant numeric values.
A log level 0 or too high is now a failure in options parsing
so it can be caught early.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 lib/librte_eal/common/eal_common_options.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index febc99612a..5b9ce286ff 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -1289,7 +1289,7 @@ eal_parse_log_level(const char *arg)
 	}
 
 	priority = eal_parse_log_priority(level);
-	if (priority < 0) {
+	if (priority <= 0 || priority > (int) RTE_LOG_MAX) {
 		fprintf(stderr, "invalid log priority: %s\n", level);
 		goto fail;
 	}
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH 07/11] eal: add log level help
  2021-03-09 23:31 [dpdk-dev] [PATCH 00/11] improve options help Thomas Monjalon
                   ` (5 preceding siblings ...)
  2021-03-09 23:31 ` [dpdk-dev] [PATCH 06/11] eal: catch invalid log level number Thomas Monjalon
@ 2021-03-09 23:31 ` Thomas Monjalon
  2021-03-09 23:31 ` [dpdk-dev] [PATCH 08/11] app: fix exit messages Thomas Monjalon
                   ` (10 subsequent siblings)
  17 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-09 23:31 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, Ray Kinsella, Neil Horman

The option --log-level was not completely described in the usage text,
and it was difficult to guess the names of the log types and levels.

A new value "help" is accepted after --log-level to give more details
about the syntax and listing the log types and levels.

The array "levels" used for level name parsing is replaced with
a (modified) existing function which was used in rte_log_dump().

The new function rte_log_list_types() is exported in the API
for allowing an application to give this info to the user
if not exposing the EAL option --log-level.
The list of log types cannot include all drivers if not linked in the
application (shared object plugin case).

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 lib/librte_eal/common/eal_common_log.c     | 24 +++++++++---
 lib/librte_eal/common/eal_common_options.c | 44 +++++++++++++++-------
 lib/librte_eal/common/eal_log.h            |  5 +++
 lib/librte_eal/include/rte_log.h           | 11 ++++++
 lib/librte_eal/version.map                 |  3 ++
 5 files changed, 69 insertions(+), 18 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c
index 7f40c36f7e..e46ae7b112 100644
--- a/lib/librte_eal/common/eal_common_log.c
+++ b/lib/librte_eal/common/eal_common_log.c
@@ -397,12 +397,12 @@ RTE_INIT_PRIO(log_init, LOG)
 	rte_logs.dynamic_types_len = RTE_LOGTYPE_FIRST_EXT_ID;
 }
 
-static const char *
-loglevel_to_string(uint32_t level)
+const char *
+eal_log_level2str(uint32_t level)
 {
 	switch (level) {
 	case 0: return "disabled";
-	case RTE_LOG_EMERG: return "emerg";
+	case RTE_LOG_EMERG: return "emergency";
 	case RTE_LOG_ALERT: return "alert";
 	case RTE_LOG_CRIT: return "critical";
 	case RTE_LOG_ERR: return "error";
@@ -414,6 +414,20 @@ loglevel_to_string(uint32_t level)
 	}
 }
 
+/* Dump name of each logtype, one per line. */
+void
+rte_log_list_types(FILE *out, const char *prefix)
+{
+	size_t type;
+
+	for (type = 0; type < rte_logs.dynamic_types_len; ++type) {
+		if (rte_logs.dynamic_types[type].name == NULL)
+			continue;
+		fprintf(out, "%s%s\n",
+				prefix, rte_logs.dynamic_types[type].name);
+	}
+}
+
 /* dump global level and registered log types */
 void
 rte_log_dump(FILE *f)
@@ -421,14 +435,14 @@ rte_log_dump(FILE *f)
 	size_t i;
 
 	fprintf(f, "global log level is %s\n",
-		loglevel_to_string(rte_log_get_global_level()));
+		eal_log_level2str(rte_log_get_global_level()));
 
 	for (i = 0; i < rte_logs.dynamic_types_len; i++) {
 		if (rte_logs.dynamic_types[i].name == NULL)
 			continue;
 		fprintf(f, "id %zu: %s, level is %s\n",
 			i, rte_logs.dynamic_types[i].name,
-			loglevel_to_string(rte_logs.dynamic_types[i].loglevel));
+			eal_log_level2str(rte_logs.dynamic_types[i].loglevel));
 	}
 }
 
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 5b9ce286ff..6c14e788e8 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -1227,19 +1227,31 @@ eal_parse_syslog(const char *facility, struct internal_config *conf)
 }
 #endif
 
+static void
+eal_log_usage(void)
+{
+	unsigned int level;
+
+	printf("Log type is a pattern matching items of this list"
+			" (plugins may be missing):\n");
+	rte_log_list_types(stdout, "\t");
+	printf("\n");
+	printf("Syntax using globbing pattern:     ");
+	printf("--"OPT_LOG_LEVEL" pattern:level\n");
+	printf("Syntax using regular expression:   ");
+	printf("--"OPT_LOG_LEVEL" regexp,level\n");
+	printf("Syntax for the global level:       ");
+	printf("--"OPT_LOG_LEVEL" level\n");
+	printf("Logs are emitted if allowed by both global and specific levels.\n");
+	printf("\n");
+	printf("Log level can be a number or the first letters of its name:\n");
+	for (level = 1; level <= RTE_LOG_MAX; level++)
+		printf("\t%d   %s\n", level, eal_log_level2str(level));
+}
+
 static int
 eal_parse_log_priority(const char *level)
 {
-	static const char * const levels[] = {
-		[RTE_LOG_EMERG]   = "emergency",
-		[RTE_LOG_ALERT]   = "alert",
-		[RTE_LOG_CRIT]    = "critical",
-		[RTE_LOG_ERR]     = "error",
-		[RTE_LOG_WARNING] = "warning",
-		[RTE_LOG_NOTICE]  = "notice",
-		[RTE_LOG_INFO]    = "info",
-		[RTE_LOG_DEBUG]   = "debug",
-	};
 	size_t len = strlen(level);
 	unsigned long tmp;
 	char *end;
@@ -1250,7 +1262,7 @@ eal_parse_log_priority(const char *level)
 
 	/* look for named values, skip 0 which is not a valid level */
 	for (i = 1; i < RTE_LOG_MAX; i++) {
-		if (strncmp(levels[i], level, len) == 0)
+		if (strncmp(eal_log_level2str(i), level, len) == 0)
 			return i;
 	}
 
@@ -1274,6 +1286,11 @@ eal_parse_log_level(const char *arg)
 	char *str, *level;
 	int priority;
 
+	if (strcmp(arg, "help") == 0) {
+		eal_log_usage();
+		exit(EXIT_SUCCESS);
+	}
+
 	str = strdup(arg);
 	if (str == NULL)
 		return -1;
@@ -2062,9 +2079,10 @@ eal_common_usage(void)
 #ifndef RTE_EXEC_ENV_WINDOWS
 	       "  --"OPT_SYSLOG"            Set syslog facility\n"
 #endif
-	       "  --"OPT_LOG_LEVEL"=<int>   Set global log level\n"
-	       "  --"OPT_LOG_LEVEL"=<type-match>:<int>\n"
+	       "  --"OPT_LOG_LEVEL"=<level> Set global log level\n"
+	       "  --"OPT_LOG_LEVEL"=<type-match>:<level>\n"
 	       "                      Set specific log level\n"
+	       "  --"OPT_LOG_LEVEL"=help    Show log types and levels\n"
 #ifndef RTE_EXEC_ENV_WINDOWS
 	       "  --"OPT_TRACE"=<regex-match>\n"
 	       "                      Enable trace based on regular expression trace name.\n"
diff --git a/lib/librte_eal/common/eal_log.h b/lib/librte_eal/common/eal_log.h
index c057301769..4ca630b0f7 100644
--- a/lib/librte_eal/common/eal_log.h
+++ b/lib/librte_eal/common/eal_log.h
@@ -24,4 +24,9 @@ void eal_log_set_default(FILE *default_log);
 int eal_log_save_regexp(const char *regexp, int priority);
 int eal_log_save_pattern(const char *pattern, int priority);
 
+/*
+ * Convert log level to string.
+ */
+const char *eal_log_level2str(uint32_t level);
+
 #endif /* EAL_LOG_H */
diff --git a/lib/librte_eal/include/rte_log.h b/lib/librte_eal/include/rte_log.h
index 394e8682b9..e6192892c3 100644
--- a/lib/librte_eal/include/rte_log.h
+++ b/lib/librte_eal/include/rte_log.h
@@ -240,6 +240,17 @@ int rte_log_register(const char *name);
 __rte_experimental
 int rte_log_register_type_and_pick_level(const char *name, uint32_t level_def);
 
+/**
+ * Dump name of each logtype, one per line.
+ *
+ * @param out
+ *   Stream where the list is sent.
+ * @param prefix
+ *   String preceding each logtype in the output.
+ */
+__rte_experimental
+void rte_log_list_types(FILE *out, const char *prefix);
+
 /**
  * Dump log information.
  *
diff --git a/lib/librte_eal/version.map b/lib/librte_eal/version.map
index fce90a112f..6b7876a0b9 100644
--- a/lib/librte_eal/version.map
+++ b/lib/librte_eal/version.map
@@ -412,6 +412,9 @@ EXPERIMENTAL {
 	rte_thread_tls_key_delete;
 	rte_thread_tls_value_get;
 	rte_thread_tls_value_set;
+
+	# added in 21.05
+	rte_log_list_types;
 };
 
 INTERNAL {
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH 08/11] app: fix exit messages
  2021-03-09 23:31 [dpdk-dev] [PATCH 00/11] improve options help Thomas Monjalon
                   ` (6 preceding siblings ...)
  2021-03-09 23:31 ` [dpdk-dev] [PATCH 07/11] eal: add log level help Thomas Monjalon
@ 2021-03-09 23:31 ` Thomas Monjalon
  2021-03-10  7:10   ` Ori Kam
  2021-03-10  9:23   ` Wisam Monther
  2021-03-09 23:31 ` [dpdk-dev] [PATCH 09/11] app: hook in EAL usage help Thomas Monjalon
                   ` (9 subsequent siblings)
  17 siblings, 2 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-09 23:31 UTC (permalink / raw)
  To: dev
  Cc: david.marchand, Declan Doherty, Ciara Power, Wisam Jaddo,
	Xiaoyun Li, Ori Kam

Some applications were printing useless messages with rte_exit()
after showing the help. Using exit() is enough in this case.

Some applications were using a redundant printf or fprintf() before
calling rte_exit(). The messages are unified in a single rte_exit().

Some rte_exit() calls were missing a line feed or returning a wrong code.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 .../comp_perf_options_parse.c                 |  2 +-
 app/test-crypto-perf/cperf_options_parsing.c  |  2 +-
 app/test-flow-perf/main.c                     | 59 +++++++++----------
 app/test-pmd/parameters.c                     |  4 +-
 app/test-regex/main.c                         |  3 +-
 5 files changed, 33 insertions(+), 37 deletions(-)

diff --git a/app/test-compress-perf/comp_perf_options_parse.c b/app/test-compress-perf/comp_perf_options_parse.c
index 04a8d2fbee..019eddb7bd 100644
--- a/app/test-compress-perf/comp_perf_options_parse.c
+++ b/app/test-compress-perf/comp_perf_options_parse.c
@@ -620,7 +620,7 @@ comp_perf_options_parse(struct comp_test_data *test_data, int argc, char **argv)
 		switch (opt) {
 		case 'h':
 			usage(argv[0]);
-			rte_exit(EXIT_SUCCESS, "Displayed help\n");
+			exit(EXIT_SUCCESS);
 			break;
 		/* long options */
 		case 0:
diff --git a/app/test-crypto-perf/cperf_options_parsing.c b/app/test-crypto-perf/cperf_options_parsing.c
index 0466f7baf8..40b6dfb648 100644
--- a/app/test-crypto-perf/cperf_options_parsing.c
+++ b/app/test-crypto-perf/cperf_options_parsing.c
@@ -983,7 +983,7 @@ cperf_options_parse(struct cperf_options *options, int argc, char **argv)
 		switch (opt) {
 		case 'h':
 			usage(argv[0]);
-			rte_exit(EXIT_SUCCESS, "Displayed help\n");
+			exit(EXIT_SUCCESS);
 			break;
 		/* long options */
 		case 0:
diff --git a/app/test-flow-perf/main.c b/app/test-flow-perf/main.c
index 99d0463456..0aef767350 100644
--- a/app/test-flow-perf/main.c
+++ b/app/test-flow-perf/main.c
@@ -639,7 +639,7 @@ args_parse(int argc, char **argv)
 		case 0:
 			if (strcmp(lgopts[opt_idx].name, "help") == 0) {
 				usage(argv[0]);
-				rte_exit(EXIT_SUCCESS, "Displayed help\n");
+				exit(EXIT_SUCCESS);
 			}
 
 			if (strcmp(lgopts[opt_idx].name, "group") == 0) {
@@ -647,7 +647,7 @@ args_parse(int argc, char **argv)
 				if (n >= 0)
 					flow_group = n;
 				else
-					rte_exit(EXIT_SUCCESS,
+					rte_exit(EXIT_FAILURE,
 						"flow group should be >= 0\n");
 				printf("group %d / ", flow_group);
 			}
@@ -667,7 +667,7 @@ args_parse(int argc, char **argv)
 				if (n > 0)
 					hairpin_queues_num = n;
 				else
-					rte_exit(EXIT_SUCCESS,
+					rte_exit(EXIT_FAILURE,
 						"Hairpin queues should be > 0\n");
 
 				flow_actions[actions_idx++] =
@@ -680,7 +680,7 @@ args_parse(int argc, char **argv)
 				if (n > 0)
 					hairpin_queues_num = n;
 				else
-					rte_exit(EXIT_SUCCESS,
+					rte_exit(EXIT_FAILURE,
 						"Hairpin queues should be > 0\n");
 
 				flow_actions[actions_idx++] =
@@ -704,11 +704,9 @@ args_parse(int argc, char **argv)
 							break;
 						}
 						/* Reached last item with no match */
-						if (i == (RTE_DIM(flow_options) - 1)) {
-							fprintf(stderr, "Invalid encap item: %s\n", token);
-							usage(argv[0]);
-							rte_exit(EXIT_SUCCESS, "Invalid encap item\n");
-						}
+						if (i == (RTE_DIM(flow_options) - 1))
+							rte_exit(EXIT_FAILURE,
+								"Invalid encap item: %s\n", token);
 					}
 					token = strtok(NULL, ",");
 				}
@@ -730,11 +728,9 @@ args_parse(int argc, char **argv)
 							break;
 						}
 						/* Reached last item with no match */
-						if (i == (RTE_DIM(flow_options) - 1)) {
-							fprintf(stderr, "Invalid decap item: %s\n", token);
-							usage(argv[0]);
-							rte_exit(EXIT_SUCCESS, "Invalid decap item\n");
-						}
+						if (i == (RTE_DIM(flow_options) - 1))
+							rte_exit(EXIT_FAILURE,
+								"Invalid decap item %s\n", token);
 					}
 					token = strtok(NULL, ",");
 				}
@@ -747,9 +743,9 @@ args_parse(int argc, char **argv)
 				if (n >= DEFAULT_RULES_BATCH)
 					rules_batch = n;
 				else {
-					printf("\n\nrules_batch should be >= %d\n",
+					rte_exit(EXIT_FAILURE,
+						"rules_batch should be >= %d\n",
 						DEFAULT_RULES_BATCH);
-					rte_exit(EXIT_SUCCESS, " ");
 				}
 			}
 			if (strcmp(lgopts[opt_idx].name,
@@ -758,7 +754,8 @@ args_parse(int argc, char **argv)
 				if (n >= (int) rules_batch)
 					rules_count = n;
 				else {
-					printf("\n\nrules_count should be >= %d\n",
+					rte_exit(EXIT_FAILURE,
+						"rules_count should be >= %d\n",
 						rules_batch);
 				}
 			}
@@ -786,23 +783,23 @@ args_parse(int argc, char **argv)
 			if (strcmp(lgopts[opt_idx].name, "cores") == 0) {
 				n = atoi(optarg);
 				if ((int) rte_lcore_count() <= n) {
-					printf("\nError: you need %d cores to run on multi-cores\n"
+					rte_exit(EXIT_FAILURE,
+						"Error: you need %d cores to run on multi-cores\n"
 						"Existing cores are: %d\n", n, rte_lcore_count());
-					rte_exit(EXIT_FAILURE, " ");
 				}
 				if (n <= RTE_MAX_LCORE && n > 0)
 					mc_pool.cores_count = n;
 				else {
-					printf("Error: cores count must be > 0 "
-						" and < %d\n", RTE_MAX_LCORE);
-					rte_exit(EXIT_FAILURE, " ");
+					rte_exit(EXIT_FAILURE,
+						"Error: cores count must be > 0 and < %d\n",
+						RTE_MAX_LCORE);
 				}
 			}
 			break;
 		default:
-			fprintf(stderr, "Invalid option: %s\n", argv[optind]);
 			usage(argv[0]);
-			rte_exit(EXIT_SUCCESS, "Invalid option\n");
+			rte_exit(EXIT_FAILURE, "Invalid option: %s\n",
+					argv[optind]);
 			break;
 		}
 	}
@@ -936,7 +933,7 @@ create_meter_rule(int port_id, uint32_t counter)
 		printf("Port %u create meter idx(%d) error(%d) message: %s\n",
 			port_id, counter, error.type,
 			error.message ? error.message : "(no stated reason)");
-		rte_exit(EXIT_FAILURE, "error in creating meter");
+		rte_exit(EXIT_FAILURE, "Error in creating meter\n");
 	}
 }
 
@@ -949,7 +946,7 @@ destroy_meter_rule(int port_id, uint32_t counter)
 		printf("Port %u destroy meter(%d) error(%d) message: %s\n",
 			port_id, counter, error.type,
 			error.message ? error.message : "(no stated reason)");
-		rte_exit(EXIT_FAILURE, "Error in deleting meter rule");
+		rte_exit(EXIT_FAILURE, "Error in deleting meter rule\n");
 	}
 }
 
@@ -1097,7 +1094,7 @@ destroy_flows(int port_id, uint8_t core_id, struct rte_flow **flows_list)
 		memset(&error, 0x33, sizeof(error));
 		if (rte_flow_destroy(port_id, flows_list[i], &error)) {
 			print_flow_error(error);
-			rte_exit(EXIT_FAILURE, "Error in deleting flow");
+			rte_exit(EXIT_FAILURE, "Error in deleting flow\n");
 		}
 
 		/*
@@ -1160,7 +1157,7 @@ insert_flows(int port_id, uint8_t core_id)
 	flows_list = rte_zmalloc("flows_list",
 		(sizeof(struct rte_flow *) * rules_count_per_core) + 1, 0);
 	if (flows_list == NULL)
-		rte_exit(EXIT_FAILURE, "No Memory available!");
+		rte_exit(EXIT_FAILURE, "No Memory available!\n");
 
 	cpu_time_used = 0;
 	flow_index = 0;
@@ -1180,7 +1177,7 @@ insert_flows(int port_id, uint8_t core_id)
 
 		if (flow == NULL) {
 			print_flow_error(error);
-			rte_exit(EXIT_FAILURE, "error in creating flow");
+			rte_exit(EXIT_FAILURE, "Error in creating flow\n");
 		}
 		flows_list[flow_index++] = flow;
 	}
@@ -1199,7 +1196,7 @@ insert_flows(int port_id, uint8_t core_id)
 
 		if (!flow) {
 			print_flow_error(error);
-			rte_exit(EXIT_FAILURE, "error in creating flow");
+			rte_exit(EXIT_FAILURE, "Error in creating flow\n");
 		}
 
 		flows_list[flow_index++] = flow;
@@ -1517,7 +1514,7 @@ packet_per_second_stats(void)
 	old = rte_zmalloc("old",
 		sizeof(struct lcore_info) * RTE_MAX_LCORE, 0);
 	if (old == NULL)
-		rte_exit(EXIT_FAILURE, "No Memory available!");
+		rte_exit(EXIT_FAILURE, "No Memory available!\n");
 
 	memcpy(old, lcore_infos,
 		sizeof(struct lcore_info) * RTE_MAX_LCORE);
diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c
index c8acd5d1b7..55ecea6338 100644
--- a/app/test-pmd/parameters.c
+++ b/app/test-pmd/parameters.c
@@ -632,7 +632,7 @@ launch_args_parse(int argc, char** argv)
 		case 0: /*long options */
 			if (!strcmp(lgopts[opt_idx].name, "help")) {
 				usage(argv[0]);
-				rte_exit(EXIT_SUCCESS, "Displayed help\n");
+				exit(EXIT_SUCCESS);
 			}
 #ifdef RTE_LIB_CMDLINE
 			if (!strcmp(lgopts[opt_idx].name, "interactive")) {
@@ -1369,7 +1369,7 @@ launch_args_parse(int argc, char** argv)
 			break;
 		case 'h':
 			usage(argv[0]);
-			rte_exit(EXIT_SUCCESS, "Displayed help\n");
+			exit(EXIT_SUCCESS);
 			break;
 		default:
 			usage(argv[0]);
diff --git a/app/test-regex/main.c b/app/test-regex/main.c
index aea4fa6b88..7bb87bb1b8 100644
--- a/app/test-regex/main.c
+++ b/app/test-regex/main.c
@@ -154,9 +154,8 @@ args_parse(int argc, char **argv, char *rules_file, char *data_file,
 			usage("RegEx test app");
 			break;
 		default:
-			fprintf(stderr, "Invalid option: %s\n", argv[optind]);
 			usage("RegEx test app");
-			rte_exit(EXIT_FAILURE, "Invalid option\n");
+			rte_exit(EXIT_FAILURE, "Invalid option: %s\n", argv[optind]);
 			break;
 		}
 	}
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH 09/11] app: hook in EAL usage help
  2021-03-09 23:31 [dpdk-dev] [PATCH 00/11] improve options help Thomas Monjalon
                   ` (7 preceding siblings ...)
  2021-03-09 23:31 ` [dpdk-dev] [PATCH 08/11] app: fix exit messages Thomas Monjalon
@ 2021-03-09 23:31 ` Thomas Monjalon
  2021-03-10  9:25   ` Wisam Monther
  2021-03-09 23:31 ` [dpdk-dev] [PATCH 10/11] app/regex: fix usage text Thomas Monjalon
                   ` (8 subsequent siblings)
  17 siblings, 1 reply; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-09 23:31 UTC (permalink / raw)
  To: dev
  Cc: david.marchand, Reshma Pattan, Maryam Tahhan, Konstantin Ananyev,
	Nicolas Chautru, Declan Doherty, Ciara Power, Vladimir Medvedkin,
	Wisam Jaddo, Xiaoyun Li, Ori Kam, Bernard Iremonger

Use rte_set_application_usage_hook() in the test applications,
so the full help including EAL options can be printed in one go
with the EAL option -h or --help.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 app/pdump/main.c                                 | 2 ++
 app/proc-info/main.c                             | 2 ++
 app/test-acl/main.c                              | 2 ++
 app/test-bbdev/main.c                            | 3 ++-
 app/test-compress-perf/comp_perf_options.h       | 2 ++
 app/test-compress-perf/comp_perf_options_parse.c | 8 ++++----
 app/test-compress-perf/main.c                    | 3 ++-
 app/test-crypto-perf/cperf_options.h             | 2 ++
 app/test-crypto-perf/cperf_options_parsing.c     | 8 ++++----
 app/test-crypto-perf/main.c                      | 3 ++-
 app/test-fib/main.c                              | 8 ++++++++
 app/test-flow-perf/main.c                        | 4 +++-
 app/test-pmd/parameters.c                        | 4 ++--
 app/test-pmd/testpmd.c                           | 2 ++
 app/test-pmd/testpmd.h                           | 1 +
 app/test-regex/main.c                            | 3 ++-
 app/test-sad/main.c                              | 7 +++++++
 17 files changed, 49 insertions(+), 15 deletions(-)

diff --git a/app/pdump/main.c b/app/pdump/main.c
index 63bbe65cd8..8641017f48 100644
--- a/app/pdump/main.c
+++ b/app/pdump/main.c
@@ -974,6 +974,8 @@ main(int argc, char **argv)
 	char mp_flag[] = "--proc-type=secondary";
 	char *argp[argc + 2];
 
+	rte_set_application_usage_hook(pdump_usage);
+
 	/* catch ctrl-c so we can print on exit */
 	signal(SIGINT, signal_handler);
 
diff --git a/app/proc-info/main.c b/app/proc-info/main.c
index b9587f7ded..e7d86bfa9d 100644
--- a/app/proc-info/main.c
+++ b/app/proc-info/main.c
@@ -1361,6 +1361,8 @@ main(int argc, char **argv)
 	char *argp[argc + 4];
 	uint16_t nb_ports;
 
+	rte_set_application_usage_hook(proc_info_usage);
+
 	/* preparse app arguments */
 	ret = proc_info_preparse_args(argc, argv);
 	if (ret < 0) {
diff --git a/app/test-acl/main.c b/app/test-acl/main.c
index 2cb2fe2579..9f95cb0fbf 100644
--- a/app/test-acl/main.c
+++ b/app/test-acl/main.c
@@ -1080,6 +1080,8 @@ main(int argc, char **argv)
 	int ret;
 	uint32_t lcore;
 
+	rte_set_application_usage_hook(print_usage);
+
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
 		rte_panic("Cannot init EAL\n");
diff --git a/app/test-bbdev/main.c b/app/test-bbdev/main.c
index ff65173fdb..5960ec18b2 100644
--- a/app/test-bbdev/main.c
+++ b/app/test-bbdev/main.c
@@ -340,7 +340,8 @@ main(int argc, char **argv)
 {
 	int ret;
 
-	/* Init EAL */
+	rte_set_application_usage_hook(print_usage);
+
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
 		return 1;
diff --git a/app/test-compress-perf/comp_perf_options.h b/app/test-compress-perf/comp_perf_options.h
index 0b777521c5..7dd785fba1 100644
--- a/app/test-compress-perf/comp_perf_options.h
+++ b/app/test-compress-perf/comp_perf_options.h
@@ -73,6 +73,8 @@ struct comp_test_data {
 	uint32_t cyclecount_delay;
 };
 
+void comp_perf_usage(const char *progname);
+
 int
 comp_perf_options_parse(struct comp_test_data *test_data, int argc,
 			char **argv);
diff --git a/app/test-compress-perf/comp_perf_options_parse.c b/app/test-compress-perf/comp_perf_options_parse.c
index 019eddb7bd..39d7fd8c69 100644
--- a/app/test-compress-perf/comp_perf_options_parse.c
+++ b/app/test-compress-perf/comp_perf_options_parse.c
@@ -38,8 +38,8 @@ struct name_id_map {
 	uint32_t id;
 };
 
-static void
-usage(char *progname)
+void
+comp_perf_usage(const char *progname)
 {
 	printf("%s [EAL options] --\n"
 		" --ptest throughput / verify / pmd-cyclecount\n"
@@ -619,7 +619,7 @@ comp_perf_options_parse(struct comp_test_data *test_data, int argc, char **argv)
 	while ((opt = getopt_long(argc, argv, "h", lgopts, &opt_idx)) != EOF) {
 		switch (opt) {
 		case 'h':
-			usage(argv[0]);
+			comp_perf_usage(argv[0]);
 			exit(EXIT_SUCCESS);
 			break;
 		/* long options */
@@ -631,7 +631,7 @@ comp_perf_options_parse(struct comp_test_data *test_data, int argc, char **argv)
 			break;
 
 		default:
-			usage(argv[0]);
+			comp_perf_usage(argv[0]);
 			return -EINVAL;
 		}
 	}
diff --git a/app/test-compress-perf/main.c b/app/test-compress-perf/main.c
index cc9951a9b1..dcd347528e 100644
--- a/app/test-compress-perf/main.c
+++ b/app/test-compress-perf/main.c
@@ -323,7 +323,8 @@ main(int argc, char **argv)
 	uint8_t cdev_id;
 	uint32_t lcore_id;
 
-	/* Initialise DPDK EAL */
+	rte_set_application_usage_hook(comp_perf_usage);
+
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
 		rte_exit(EXIT_FAILURE, "Invalid EAL arguments!\n");
diff --git a/app/test-crypto-perf/cperf_options.h b/app/test-crypto-perf/cperf_options.h
index 9664a4b343..5f4a780614 100644
--- a/app/test-crypto-perf/cperf_options.h
+++ b/app/test-crypto-perf/cperf_options.h
@@ -153,6 +153,8 @@ struct cperf_options {
 	uint8_t imix_distribution_count;
 };
 
+void cperf_usage(const char *progname);
+
 void
 cperf_options_default(struct cperf_options *options);
 
diff --git a/app/test-crypto-perf/cperf_options_parsing.c b/app/test-crypto-perf/cperf_options_parsing.c
index 40b6dfb648..3777bc7509 100644
--- a/app/test-crypto-perf/cperf_options_parsing.c
+++ b/app/test-crypto-perf/cperf_options_parsing.c
@@ -19,8 +19,8 @@ struct name_id_map {
 	uint32_t id;
 };
 
-static void
-usage(char *progname)
+void
+cperf_usage(const char *progname)
 {
 	printf("%s [EAL options] --\n"
 		" --silent: disable options dump\n"
@@ -982,7 +982,7 @@ cperf_options_parse(struct cperf_options *options, int argc, char **argv)
 	while ((opt = getopt_long(argc, argv, "h", lgopts, &opt_idx)) != EOF) {
 		switch (opt) {
 		case 'h':
-			usage(argv[0]);
+			cperf_usage(argv[0]);
 			exit(EXIT_SUCCESS);
 			break;
 		/* long options */
@@ -994,7 +994,7 @@ cperf_options_parse(struct cperf_options *options, int argc, char **argv)
 			break;
 
 		default:
-			usage(argv[0]);
+			cperf_usage(argv[0]);
 			return -EINVAL;
 		}
 	}
diff --git a/app/test-crypto-perf/main.c b/app/test-crypto-perf/main.c
index 49af812d8b..497c4c5226 100644
--- a/app/test-crypto-perf/main.c
+++ b/app/test-crypto-perf/main.c
@@ -519,7 +519,8 @@ main(int argc, char **argv)
 	int ret;
 	uint32_t lcore_id;
 
-	/* Initialise DPDK EAL */
+	rte_set_application_usage_hook(cperf_usage);
+
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
 		rte_exit(EXIT_FAILURE, "Invalid EAL arguments!\n");
diff --git a/app/test-fib/main.c b/app/test-fib/main.c
index b0a97b0d7e..420fe17c39 100644
--- a/app/test-fib/main.c
+++ b/app/test-fib/main.c
@@ -648,6 +648,12 @@ print_usage(void)
 		config.prgname);
 }
 
+static void
+usage_hook(const char *prgname __rte_unused)
+{
+	print_usage();
+}
+
 static int
 check_config(void)
 {
@@ -1209,6 +1215,8 @@ main(int argc, char **argv)
 	FILE *fl = NULL;
 	uint8_t depth_lim;
 
+	rte_set_application_usage_hook(usage_hook);
+
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
 		rte_panic("Cannot init EAL\n");
diff --git a/app/test-flow-perf/main.c b/app/test-flow-perf/main.c
index 0aef767350..949a5e3e11 100644
--- a/app/test-flow-perf/main.c
+++ b/app/test-flow-perf/main.c
@@ -115,7 +115,7 @@ static struct multi_cores_pool mc_pool = {
 };
 
 static void
-usage(char *progname)
+usage(const char *progname)
 {
 	printf("\nusage: %s\n", progname);
 	printf("\nControl configurations:\n");
@@ -1849,6 +1849,8 @@ main(int argc, char **argv)
 	uint16_t port;
 	struct rte_flow_error error;
 
+	rte_set_application_usage_hook(usage);
+
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
 		rte_exit(EXIT_FAILURE, "EAL init failed\n");
diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c
index 55ecea6338..7f41021d4d 100644
--- a/app/test-pmd/parameters.c
+++ b/app/test-pmd/parameters.c
@@ -46,8 +46,8 @@
 
 #include "testpmd.h"
 
-static void
-usage(char* progname)
+void
+usage(const char *progname)
 {
 	printf("usage: %s [EAL options] -- "
 #ifdef RTE_LIB_CMDLINE
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 1a57324b1b..1a60830037 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -3771,6 +3771,8 @@ main(int argc, char** argv)
 		rte_exit(EXIT_FAILURE, "Cannot register log type");
 	rte_log_set_level(testpmd_logtype, RTE_LOG_DEBUG);
 
+	rte_set_application_usage_hook(usage);
+
 	diag = rte_eal_init(argc, argv);
 	if (diag < 0)
 		rte_exit(EXIT_FAILURE, "Cannot init EAL: %s\n",
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index ce83f31f0d..37348246f8 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -763,6 +763,7 @@ inc_tx_burst_stats(struct fwd_stream *fs, uint16_t nb_tx)
 unsigned int parse_item_list(char* str, const char* item_name,
 			unsigned int max_items,
 			unsigned int *parsed_items, int check_unique_values);
+void usage(const char *progname);
 void launch_args_parse(int argc, char** argv);
 void cmdline_read_from_file(const char *filename);
 void prompt(void);
diff --git a/app/test-regex/main.c b/app/test-regex/main.c
index 7bb87bb1b8..ba09b20126 100644
--- a/app/test-regex/main.c
+++ b/app/test-regex/main.c
@@ -616,7 +616,8 @@ main(int argc, char **argv)
 	uint32_t i;
 	struct qps_per_lcore *qps_per_lcore;
 
-	/* Init EAL. */
+	rte_set_application_usage_hook(usage);
+
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
 		rte_exit(EXIT_FAILURE, "EAL init failed\n");
diff --git a/app/test-sad/main.c b/app/test-sad/main.c
index 1024757add..14a8263f8c 100644
--- a/app/test-sad/main.c
+++ b/app/test-sad/main.c
@@ -149,7 +149,12 @@ print_usage(void)
 		"[-p <parallel lookup on all available cores>]\n"
 		"[-c <init sad supporting read/write concurrency>]\n",
 		config.prgname);
+}
 
+static void
+usage_hook(const char *prgname __rte_unused)
+{
+	print_usage();
 }
 
 static int
@@ -620,6 +625,8 @@ main(int argc, char **argv)
 	struct rte_ipsec_sad_conf conf = {0};
 	unsigned int lcore_id;
 
+	rte_set_application_usage_hook(usage_hook);
+
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
 		rte_panic("Cannot init EAL\n");
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH 10/11] app/regex: fix usage text
  2021-03-09 23:31 [dpdk-dev] [PATCH 00/11] improve options help Thomas Monjalon
                   ` (8 preceding siblings ...)
  2021-03-09 23:31 ` [dpdk-dev] [PATCH 09/11] app: hook in EAL usage help Thomas Monjalon
@ 2021-03-09 23:31 ` Thomas Monjalon
  2021-03-10  7:08   ` Ori Kam
  2021-03-09 23:31 ` [dpdk-dev] [PATCH 11/11] app/testpmd: " Thomas Monjalon
                   ` (7 subsequent siblings)
  17 siblings, 1 reply; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-09 23:31 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, Ori Kam

The usage syntax help includes the program name which was fake.
It is replaced with the real name from argv.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 app/test-regex/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/app/test-regex/main.c b/app/test-regex/main.c
index ba09b20126..73ba227fba 100644
--- a/app/test-regex/main.c
+++ b/app/test-regex/main.c
@@ -151,10 +151,10 @@ args_parse(int argc, char **argv, char *rules_file, char *data_file,
 			*nb_lcores = atoi(optarg);
 			break;
 		case ARG_HELP:
-			usage("RegEx test app");
+			usage(argv[0]);
 			break;
 		default:
-			usage("RegEx test app");
+			usage(argv[0]);
 			rte_exit(EXIT_FAILURE, "Invalid option: %s\n", argv[optind]);
 			break;
 		}
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH 11/11] app/testpmd: fix usage text
  2021-03-09 23:31 [dpdk-dev] [PATCH 00/11] improve options help Thomas Monjalon
                   ` (9 preceding siblings ...)
  2021-03-09 23:31 ` [dpdk-dev] [PATCH 10/11] app/regex: fix usage text Thomas Monjalon
@ 2021-03-09 23:31 ` Thomas Monjalon
  2021-03-12 19:09   ` Ajit Khaparde
  2021-03-10  0:45 ` [dpdk-dev] [PATCH 00/11] improve options help Stephen Hemminger
                   ` (6 subsequent siblings)
  17 siblings, 1 reply; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-09 23:31 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, Xiaoyun Li

The options help text was including an incomplete and redundant
summary of the options before explaining each. The summary is dropped.

The details of the option --hairpin-mode had an extra space,
breaking the alignment with the next line.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 app/test-pmd/parameters.c | 26 ++------------------------
 1 file changed, 2 insertions(+), 24 deletions(-)

diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c
index 7f41021d4d..efcbf1e845 100644
--- a/app/test-pmd/parameters.c
+++ b/app/test-pmd/parameters.c
@@ -49,29 +49,7 @@
 void
 usage(const char *progname)
 {
-	printf("usage: %s [EAL options] -- "
-#ifdef RTE_LIB_CMDLINE
-	       "[--interactive|-i] "
-	       "[--cmdline-file=FILENAME] "
-#endif
-	       "[--help|-h] | [--auto-start|-a] | ["
-	       "--tx-first | --stats-period=PERIOD | "
-	       "--coremask=COREMASK --portmask=PORTMASK --numa "
-	       "--portlist=PORTLIST "
-	       "--mbuf-size= | --total-num-mbufs= | "
-	       "--nb-cores= | --nb-ports= | "
-#ifdef RTE_LIB_CMDLINE
-	       "--eth-peers-configfile= | "
-	       "--eth-peer=X,M:M:M:M:M:M | "
-	       "--tx-ip=SRC,DST | --tx-udp=PORT | "
-#endif
-	       "--pkt-filter-mode= |"
-	       "--rss-ip | --rss-udp | --rss-level-inner | --rss-level-outer |"
-	       "--rxpt= | --rxht= | --rxwt= |"
-	       " --rxfreet= | --txpt= | --txht= | --txwt= | --txfreet= | "
-	       "--txrst= | --tx-offloads= | | --rx-offloads= | "
-	       "--vxlan-gpe-port= | --geneve-parsed-port= | "
-	       "--record-core-cycles | --record-burst-stats]\n",
+	printf("\nUsage: %s [EAL options] -- [testpmd options]\n\n",
 	       progname);
 #ifdef RTE_LIB_CMDLINE
 	printf("  --interactive: run in interactive mode.\n");
@@ -221,7 +199,7 @@ usage(const char *progname)
 	       "enabled\n");
 	printf("  --record-core-cycles: enable measurement of CPU cycles.\n");
 	printf("  --record-burst-stats: enable display of RX and TX bursts.\n");
-	printf("  --hairpin-mode=0xXX: bitmask set the hairpin port mode.\n "
+	printf("  --hairpin-mode=0xXX: bitmask set the hairpin port mode.\n"
 	       "    0x10 - explicit Tx rule, 0x02 - hairpin ports paired\n"
 	       "    0x01 - hairpin ports loop, 0x00 - hairpin port self\n");
 }
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH 00/11] improve options help
  2021-03-09 23:31 [dpdk-dev] [PATCH 00/11] improve options help Thomas Monjalon
                   ` (10 preceding siblings ...)
  2021-03-09 23:31 ` [dpdk-dev] [PATCH 11/11] app/testpmd: " Thomas Monjalon
@ 2021-03-10  0:45 ` Stephen Hemminger
  2021-03-10 13:28 ` [dpdk-dev] [PATCH v2 " Thomas Monjalon
                   ` (5 subsequent siblings)
  17 siblings, 0 replies; 121+ messages in thread
From: Stephen Hemminger @ 2021-03-10  0:45 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev, david.marchand

On Wed, 10 Mar 2021 00:31:04 +0100
Thomas Monjalon <thomas@monjalon.net> wrote:

> The main intent of this series is to provide a nice help
> for the --log-level option.
> More patches are added to improve options help in general.
> 
> Thomas Monjalon (11):
>   eal: explain argv behaviour during init
>   eal: improve options usage text
>   eal: use macros for help option
>   eal: move private log functions
>   eal: introduce maximum log level macro
>   eal: catch invalid log level number
>   eal: add log level help
>   app: fix exit messages
>   app: hook in EAL usage help
>   app/regex: fix usage text
>   app/testpmd: fix usage text
> 
>  app/pdump/main.c                              |  2 +
>  app/proc-info/main.c                          |  2 +
>  app/test-acl/main.c                           |  2 +
>  app/test-bbdev/main.c                         |  3 +-
>  app/test-compress-perf/comp_perf_options.h    |  2 +
>  .../comp_perf_options_parse.c                 | 10 +--
>  app/test-compress-perf/main.c                 |  3 +-
>  app/test-crypto-perf/cperf_options.h          |  2 +
>  app/test-crypto-perf/cperf_options_parsing.c  | 10 +--
>  app/test-crypto-perf/main.c                   |  3 +-
>  app/test-fib/main.c                           |  8 +++
>  app/test-flow-perf/main.c                     | 63 +++++++++---------
>  app/test-pmd/parameters.c                     | 34 ++--------
>  app/test-pmd/testpmd.c                        |  2 +
>  app/test-pmd/testpmd.h                        |  1 +
>  app/test-regex/main.c                         | 10 +--
>  app/test-sad/main.c                           |  7 ++
>  lib/librte_eal/common/eal_common_log.c        | 50 +++++++++-----
>  lib/librte_eal/common/eal_common_options.c    | 66 ++++++++++++-------
>  lib/librte_eal/common/eal_log.h               | 32 +++++++++
>  lib/librte_eal/common/eal_private.h           | 29 --------
>  lib/librte_eal/freebsd/eal.c                  | 10 +--
>  lib/librte_eal/include/rte_eal.h              |  2 +
>  lib/librte_eal/include/rte_log.h              | 12 ++++
>  lib/librte_eal/linux/eal.c                    | 17 ++---
>  lib/librte_eal/linux/eal_log.c                |  4 +-
>  lib/librte_eal/version.map                    |  3 +
>  lib/librte_eal/windows/eal.c                  | 15 ++---
>  lib/librte_eal/windows/eal_log.c              |  6 +-
>  29 files changed, 237 insertions(+), 173 deletions(-)
>  create mode 100644 lib/librte_eal/common/eal_log.h
> 

It probably isn't worth the effort, but python argparse style
is much easier (and self documenting) compared to the C getopt stuff.
There are several C versions of similar libraries.
   https://github.com/cofyc/argparse
   https://www.argtable.org/


^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH 10/11] app/regex: fix usage text
  2021-03-09 23:31 ` [dpdk-dev] [PATCH 10/11] app/regex: fix usage text Thomas Monjalon
@ 2021-03-10  7:08   ` Ori Kam
  0 siblings, 0 replies; 121+ messages in thread
From: Ori Kam @ 2021-03-10  7:08 UTC (permalink / raw)
  To: NBU-Contact-Thomas Monjalon, dev; +Cc: david.marchand

Hi

> -----Original Message-----
> From: Thomas Monjalon <thomas@monjalon.net>
> Subject: [PATCH 10/11] app/regex: fix usage text
> 
> The usage syntax help includes the program name which was fake.
> It is replaced with the real name from argv.
> 
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> ---
>  app/test-regex/main.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/app/test-regex/main.c b/app/test-regex/main.c
> index ba09b20126..73ba227fba 100644
> --- a/app/test-regex/main.c
> +++ b/app/test-regex/main.c
> @@ -151,10 +151,10 @@ args_parse(int argc, char **argv, char *rules_file,
> char *data_file,
>  			*nb_lcores = atoi(optarg);
>  			break;
>  		case ARG_HELP:
> -			usage("RegEx test app");
> +			usage(argv[0]);
>  			break;
>  		default:
> -			usage("RegEx test app");
> +			usage(argv[0]);
>  			rte_exit(EXIT_FAILURE, "Invalid option: %s\n",
> argv[optind]);
>  			break;
>  		}
> --
> 2.30.1
Acked-by: Ori Kam <orika@nvidia.com>

Best,
Ori

^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH 08/11] app: fix exit messages
  2021-03-09 23:31 ` [dpdk-dev] [PATCH 08/11] app: fix exit messages Thomas Monjalon
@ 2021-03-10  7:10   ` Ori Kam
  2021-03-10  9:23   ` Wisam Monther
  1 sibling, 0 replies; 121+ messages in thread
From: Ori Kam @ 2021-03-10  7:10 UTC (permalink / raw)
  To: NBU-Contact-Thomas Monjalon, dev
  Cc: david.marchand, Declan Doherty, Ciara Power, Wisam Monther, Xiaoyun Li

Hi

> -----Original Message-----
> From: Thomas Monjalon <thomas@monjalon.net>
> Subject: [PATCH 08/11] app: fix exit messages
> 
> Some applications were printing useless messages with rte_exit()
> after showing the help. Using exit() is enough in this case.
> 
> Some applications were using a redundant printf or fprintf() before
> calling rte_exit(). The messages are unified in a single rte_exit().
> 
> Some rte_exit() calls were missing a line feed or returning a wrong code.
> 
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> ---


Acked-by: Ori Kam <orika@nvidia.com>
Best,
Ori

^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH 08/11] app: fix exit messages
  2021-03-09 23:31 ` [dpdk-dev] [PATCH 08/11] app: fix exit messages Thomas Monjalon
  2021-03-10  7:10   ` Ori Kam
@ 2021-03-10  9:23   ` Wisam Monther
  1 sibling, 0 replies; 121+ messages in thread
From: Wisam Monther @ 2021-03-10  9:23 UTC (permalink / raw)
  To: NBU-Contact-Thomas Monjalon, dev
  Cc: david.marchand, Declan Doherty, Ciara Power, Xiaoyun Li, Ori Kam

Hi,

> -----Original Message-----
> From: Thomas Monjalon <thomas@monjalon.net>
> Sent: Wednesday, March 10, 2021 1:31 AM
> To: dev@dpdk.org
> Cc: david.marchand@redhat.com; Declan Doherty
> <declan.doherty@intel.com>; Ciara Power <ciara.power@intel.com>; Wisam
> Monther <wisamm@nvidia.com>; Xiaoyun Li <xiaoyun.li@intel.com>; Ori
> Kam <orika@nvidia.com>
> Subject: [PATCH 08/11] app: fix exit messages
> 
> Some applications were printing useless messages with rte_exit() after
> showing the help. Using exit() is enough in this case.
> 
> Some applications were using a redundant printf or fprintf() before calling
> rte_exit(). The messages are unified in a single rte_exit().
> 
> Some rte_exit() calls were missing a line feed or returning a wrong code.
> 
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>

Acked-by: Wisam Jaddo <wisamm@nvidia.com>

BRs,
Wisam Jaddo 

^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH 09/11] app: hook in EAL usage help
  2021-03-09 23:31 ` [dpdk-dev] [PATCH 09/11] app: hook in EAL usage help Thomas Monjalon
@ 2021-03-10  9:25   ` Wisam Monther
  0 siblings, 0 replies; 121+ messages in thread
From: Wisam Monther @ 2021-03-10  9:25 UTC (permalink / raw)
  To: NBU-Contact-Thomas Monjalon, dev
  Cc: david.marchand, Reshma Pattan, Maryam Tahhan, Konstantin Ananyev,
	Nicolas Chautru, Declan Doherty, Ciara Power, Vladimir Medvedkin,
	Xiaoyun Li, Ori Kam, Bernard Iremonger

Hi,

> -----Original Message-----
> From: Thomas Monjalon <thomas@monjalon.net>
> Sent: Wednesday, March 10, 2021 1:31 AM
> To: dev@dpdk.org
> Cc: david.marchand@redhat.com; Reshma Pattan
> <reshma.pattan@intel.com>; Maryam Tahhan
> <maryam.tahhan@intel.com>; Konstantin Ananyev
> <konstantin.ananyev@intel.com>; Nicolas Chautru
> <nicolas.chautru@intel.com>; Declan Doherty <declan.doherty@intel.com>;
> Ciara Power <ciara.power@intel.com>; Vladimir Medvedkin
> <vladimir.medvedkin@intel.com>; Wisam Monther <wisamm@nvidia.com>;
> Xiaoyun Li <xiaoyun.li@intel.com>; Ori Kam <orika@nvidia.com>; Bernard
> Iremonger <bernard.iremonger@intel.com>
> Subject: [PATCH 09/11] app: hook in EAL usage help
> 
> Use rte_set_application_usage_hook() in the test applications, so the full
> help including EAL options can be printed in one go with the EAL option -h or -
> -help.
> 
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>

Acked-by: Wisam Jaddo <wisamm@nvidia.com>

BRs,
Wisam Jaddo

^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH 06/11] eal: catch invalid log level number
  2021-03-09 23:31 ` [dpdk-dev] [PATCH 06/11] eal: catch invalid log level number Thomas Monjalon
@ 2021-03-10 12:19   ` Bruce Richardson
  2021-03-10 12:33     ` Thomas Monjalon
  2021-03-10 15:16     ` Stephen Hemminger
  0 siblings, 2 replies; 121+ messages in thread
From: Bruce Richardson @ 2021-03-10 12:19 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev, david.marchand

On Wed, Mar 10, 2021 at 12:31:10AM +0100, Thomas Monjalon wrote:
> The parsing check for invalid log level was not trying to catch
> irrelevant numeric values.
> A log level 0 or too high is now a failure in options parsing
> so it can be caught early.
> 
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>

One thing I'd note here is that our log range of 1 to 8 is a little
strange, and that it would be nice if we could accept 9 as a valid log
level too on the cmdline. Ideally 0 would also be acceptable, for all
logging off, but it's more likely that people want to up the log level than
reduce it, and 9 is a more expected max value than 8.

> ---
>  lib/librte_eal/common/eal_common_options.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
> index febc99612a..5b9ce286ff 100644
> --- a/lib/librte_eal/common/eal_common_options.c
> +++ b/lib/librte_eal/common/eal_common_options.c
> @@ -1289,7 +1289,7 @@ eal_parse_log_level(const char *arg)
>  	}
>  
>  	priority = eal_parse_log_priority(level);
> -	if (priority < 0) {
> +	if (priority <= 0 || priority > (int) RTE_LOG_MAX) {
>  		fprintf(stderr, "invalid log priority: %s\n", level);
>  		goto fail;
>  	}

^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH 06/11] eal: catch invalid log level number
  2021-03-10 12:19   ` Bruce Richardson
@ 2021-03-10 12:33     ` Thomas Monjalon
  2021-03-10 13:26       ` Bruce Richardson
  2021-03-10 15:16     ` Stephen Hemminger
  1 sibling, 1 reply; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-10 12:33 UTC (permalink / raw)
  To: Bruce Richardson; +Cc: dev, david.marchand

10/03/2021 13:19, Bruce Richardson:
> On Wed, Mar 10, 2021 at 12:31:10AM +0100, Thomas Monjalon wrote:
> > The parsing check for invalid log level was not trying to catch
> > irrelevant numeric values.
> > A log level 0 or too high is now a failure in options parsing
> > so it can be caught early.
> > 
> > Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> 
> One thing I'd note here is that our log range of 1 to 8 is a little
> strange, and that it would be nice if we could accept 9 as a valid log
> level too on the cmdline. Ideally 0 would also be acceptable, for all
> logging off, but it's more likely that people want to up the log level than
> reduce it, and 9 is a more expected max value than 8.

Why 9 is more expected?

Note that log level numbers are old-school,
now we can use symbolic names ;)




^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH 05/11] eal: introduce maximum log level macro
  2021-03-09 23:31 ` [dpdk-dev] [PATCH 05/11] eal: introduce maximum log level macro Thomas Monjalon
@ 2021-03-10 12:46   ` Thomas Monjalon
  0 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-10 12:46 UTC (permalink / raw)
  To: dev; +Cc: david.marchand

10/03/2021 00:31, Thomas Monjalon:
> --- a/lib/librte_eal/common/eal_common_options.c
> +++ b/lib/librte_eal/common/eal_common_options.c
> @@ -1249,7 +1249,7 @@ eal_parse_log_priority(const char *level)
>  		return -1;
>  
>  	/* look for named values, skip 0 which is not a valid level */
> -	for (i = 1; i < RTE_DIM(levels); i++) {
> +	for (i = 1; i < RTE_LOG_MAX; i++) {

Bug: it should be <=




^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH 06/11] eal: catch invalid log level number
  2021-03-10 12:33     ` Thomas Monjalon
@ 2021-03-10 13:26       ` Bruce Richardson
  2021-03-10 13:35         ` Thomas Monjalon
  0 siblings, 1 reply; 121+ messages in thread
From: Bruce Richardson @ 2021-03-10 13:26 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev, david.marchand

On Wed, Mar 10, 2021 at 01:33:20PM +0100, Thomas Monjalon wrote:
> 10/03/2021 13:19, Bruce Richardson:
> > On Wed, Mar 10, 2021 at 12:31:10AM +0100, Thomas Monjalon wrote:
> > > The parsing check for invalid log level was not trying to catch
> > > irrelevant numeric values.
> > > A log level 0 or too high is now a failure in options parsing
> > > so it can be caught early.
> > > 
> > > Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> > 
> > One thing I'd note here is that our log range of 1 to 8 is a little
> > strange, and that it would be nice if we could accept 9 as a valid log
> > level too on the cmdline. Ideally 0 would also be acceptable, for all
> > logging off, but it's more likely that people want to up the log level than
> > reduce it, and 9 is a more expected max value than 8.
> 
> Why 9 is more expected?
> 

Because a scale of 0-9 is more logical in the decimal system.
We could also generalize that any number >8 is just reduced to 8 and
we issue a warning and continue.


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v2 00/11] improve options help
  2021-03-09 23:31 [dpdk-dev] [PATCH 00/11] improve options help Thomas Monjalon
                   ` (11 preceding siblings ...)
  2021-03-10  0:45 ` [dpdk-dev] [PATCH 00/11] improve options help Stephen Hemminger
@ 2021-03-10 13:28 ` Thomas Monjalon
  2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 01/11] eal: explain argv behaviour during init Thomas Monjalon
                     ` (10 more replies)
  2021-03-12 18:17 ` [dpdk-dev] [PATCH v3 00/11] improve options help Thomas Monjalon
                   ` (4 subsequent siblings)
  17 siblings, 11 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-10 13:28 UTC (permalink / raw)
  To: dev; +Cc: david.marchand

The main intent of this series is to provide a nice help
for the --log-level option.
More patches are added to improve options help in general.


v2:
    - fix use of the new macro RTE_LOG_MAX in level parsing
    - improve parameters type and name while moving functions


Thomas Monjalon (11):
  eal: explain argv behaviour during init
  eal: improve options usage text
  eal: use macros for help option
  eal: move private log functions
  eal: introduce maximum log level macro
  eal: catch invalid log level number
  eal: add log level help
  app: fix exit messages
  app: hook in EAL usage help
  app/regex: fix usage text
  app/testpmd: fix usage text

 app/pdump/main.c                              |  2 +
 app/proc-info/main.c                          |  2 +
 app/test-acl/main.c                           |  2 +
 app/test-bbdev/main.c                         |  3 +-
 app/test-compress-perf/comp_perf_options.h    |  2 +
 .../comp_perf_options_parse.c                 | 10 +--
 app/test-compress-perf/main.c                 |  3 +-
 app/test-crypto-perf/cperf_options.h          |  2 +
 app/test-crypto-perf/cperf_options_parsing.c  | 10 +--
 app/test-crypto-perf/main.c                   |  3 +-
 app/test-fib/main.c                           |  8 +++
 app/test-flow-perf/main.c                     | 63 +++++++++---------
 app/test-pmd/parameters.c                     | 34 ++--------
 app/test-pmd/testpmd.c                        |  2 +
 app/test-pmd/testpmd.h                        |  1 +
 app/test-regex/main.c                         | 10 +--
 app/test-sad/main.c                           |  7 ++
 lib/librte_eal/common/eal_common_log.c        | 50 +++++++++-----
 lib/librte_eal/common/eal_common_options.c    | 66 ++++++++++++-------
 lib/librte_eal/common/eal_log.h               | 32 +++++++++
 lib/librte_eal/common/eal_private.h           | 29 --------
 lib/librte_eal/freebsd/eal.c                  | 10 +--
 lib/librte_eal/include/rte_eal.h              |  2 +
 lib/librte_eal/include/rte_log.h              | 12 ++++
 lib/librte_eal/linux/eal.c                    | 17 ++---
 lib/librte_eal/linux/eal_log.c                |  4 +-
 lib/librte_eal/version.map                    |  3 +
 lib/librte_eal/windows/eal.c                  | 15 ++---
 lib/librte_eal/windows/eal_log.c              |  6 +-
 29 files changed, 237 insertions(+), 173 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_log.h

-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v2 01/11] eal: explain argv behaviour during init
  2021-03-10 13:28 ` [dpdk-dev] [PATCH v2 " Thomas Monjalon
@ 2021-03-10 13:28   ` Thomas Monjalon
  2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 02/11] eal: improve options usage text Thomas Monjalon
                     ` (9 subsequent siblings)
  10 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-10 13:28 UTC (permalink / raw)
  To: dev; +Cc: david.marchand

After argument parsing done by rte_eal_init(),
the remaining arguments are to be parsed by the application
by progressing in the argv array.
In this context, the first string represented by argv[0] is still
the same program name as the original argv[0],
while the next strings are the application arguments.
This is because rte_eal_init() manipulates the argv array
after EAL parsing, before returning to the application.

This note was missing in the doxygen comment of the API.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 lib/librte_eal/include/rte_eal.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/librte_eal/include/rte_eal.h b/lib/librte_eal/include/rte_eal.h
index eaf6469e50..0cbeedb594 100644
--- a/lib/librte_eal/include/rte_eal.h
+++ b/lib/librte_eal/include/rte_eal.h
@@ -76,6 +76,8 @@ int rte_eal_iopl_init(void);
  * @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.
+ *   The program name pointer argv[0] is copied into the last parsed argv
+ *   so that argv[0] is still the same after deducing the parsed arguments.
  * @return
  *   - On success, the number of parsed arguments, which is greater or
  *     equal to zero. After the call to rte_eal_init(),
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v2 02/11] eal: improve options usage text
  2021-03-10 13:28 ` [dpdk-dev] [PATCH v2 " Thomas Monjalon
  2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 01/11] eal: explain argv behaviour during init Thomas Monjalon
@ 2021-03-10 13:28   ` Thomas Monjalon
  2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 03/11] eal: use macros for help option Thomas Monjalon
                     ` (8 subsequent siblings)
  10 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-10 13:28 UTC (permalink / raw)
  To: dev
  Cc: david.marchand, Bruce Richardson, Dmitry Kozlyuk,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam

The description of the EAL options was printed before the application
description provided via the hook.
It is better to let the application print the global syntax
and describes the detail of the EAL options below.

Also, some useless lines are removed,
and the alignment of few options is fixed.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 lib/librte_eal/common/eal_common_options.c | 11 +++++------
 lib/librte_eal/freebsd/eal.c               |  8 ++++----
 lib/librte_eal/linux/eal.c                 | 12 ++++++------
 lib/librte_eal/windows/eal.c               | 10 ++++------
 4 files changed, 19 insertions(+), 22 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 622c7bc429..0635b0d4ce 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -2022,8 +2022,7 @@ rte_vect_set_max_simd_bitwidth(uint16_t bitwidth)
 void
 eal_common_usage(void)
 {
-	printf("[options]\n\n"
-	       "EAL common options:\n"
+	printf("EAL common options:\n"
 	       "  -c COREMASK         Hexadecimal bitmask of cores to run on\n"
 	       "  -l CORELIST         List of cores to run on\n"
 	       "                      The argument format is <c1>[-c2][,c3[-c4],...]\n"
@@ -2053,7 +2052,7 @@ eal_common_usage(void)
 	       "  --"OPT_VDEV"              Add a virtual device.\n"
 	       "                      The argument format is <driver><id>[,key=val,...]\n"
 	       "                      (ex: --vdev=net_pcap0,iface=eth2).\n"
-	       "  --"OPT_IOVA_MODE"   Set IOVA mode. 'pa' for IOVA_PA\n"
+	       "  --"OPT_IOVA_MODE"         Set IOVA mode. 'pa' for IOVA_PA\n"
 	       "                      'va' for IOVA_VA\n"
 	       "  -d LIB.so|DIR       Add a driver or driver directory\n"
 	       "                      (can be used multiple times)\n"
@@ -2092,11 +2091,11 @@ eal_common_usage(void)
 #endif /* !RTE_EXEC_ENV_WINDOWS */
 	       "  -v                  Display version information on startup\n"
 	       "  -h, --help          This help\n"
-	       "  --"OPT_IN_MEMORY"   Operate entirely in memory. This will\n"
+	       "  --"OPT_IN_MEMORY"         Operate entirely in memory. This will\n"
 	       "                      disable secondary process support\n"
 	       "  --"OPT_BASE_VIRTADDR"     Base virtual address\n"
-	       "  --"OPT_TELEMETRY"   Enable telemetry support (on by default)\n"
-	       "  --"OPT_NO_TELEMETRY"   Disable telemetry support\n"
+	       "  --"OPT_TELEMETRY"         Enable telemetry support (on by default)\n"
+	       "  --"OPT_NO_TELEMETRY"      Disable telemetry support\n"
 	       "  --"OPT_FORCE_MAX_SIMD_BITWIDTH" Force the max SIMD bitwidth\n"
 	       "\nEAL options for DEBUG use only:\n"
 	       "  --"OPT_HUGE_UNLINK"       Unlink hugepage files after init\n"
diff --git a/lib/librte_eal/freebsd/eal.c b/lib/librte_eal/freebsd/eal.c
index afbbb1c523..f466616566 100644
--- a/lib/librte_eal/freebsd/eal.c
+++ b/lib/librte_eal/freebsd/eal.c
@@ -421,13 +421,13 @@ eal_usage(const char *prgname)
 {
 	rte_usage_hook_t hook = eal_get_application_usage_hook();
 
-	printf("\nUsage: %s ", prgname);
-	eal_common_usage();
-	/* Allow the application to print its usage message too if hook is set */
 	if (hook) {
-		printf("===== Application Usage =====\n\n");
+		/* Print application usage through EAL options parsing. */
 		(hook)(prgname);
+		printf("\n");
 	}
+
+	eal_common_usage();
 }
 
 static inline size_t
diff --git a/lib/librte_eal/linux/eal.c b/lib/librte_eal/linux/eal.c
index bc966150a5..7c1d296192 100644
--- a/lib/librte_eal/linux/eal.c
+++ b/lib/librte_eal/linux/eal.c
@@ -534,7 +534,12 @@ eal_usage(const char *prgname)
 {
 	rte_usage_hook_t hook = eal_get_application_usage_hook();
 
-	printf("\nUsage: %s ", prgname);
+	if (hook) {
+		/* Print application usage through EAL options parsing. */
+		(hook)(prgname);
+		printf("\n");
+	}
+
 	eal_common_usage();
 	printf("EAL Linux options:\n"
 	       "  --"OPT_SOCKET_MEM"        Memory to allocate on sockets (comma separated values)\n"
@@ -548,11 +553,6 @@ eal_usage(const char *prgname)
 	       "  --"OPT_SINGLE_FILE_SEGMENTS" Put all hugepage memory in single files\n"
 	       "  --"OPT_MATCH_ALLOCATIONS" Free hugepages exactly as allocated\n"
 	       "\n");
-	/* Allow the application to print its usage message too if hook is set */
-	if (hook) {
-		printf("===== Application Usage =====\n\n");
-		(hook)(prgname);
-	}
 }
 
 static int
diff --git a/lib/librte_eal/windows/eal.c b/lib/librte_eal/windows/eal.c
index 2fc3d6141c..ec13ac1a9f 100644
--- a/lib/librte_eal/windows/eal.c
+++ b/lib/librte_eal/windows/eal.c
@@ -79,15 +79,13 @@ eal_usage(const char *prgname)
 {
 	rte_usage_hook_t hook = eal_get_application_usage_hook();
 
-	printf("\nUsage: %s ", prgname);
-	eal_common_usage();
-	/* Allow the application to print its usage message too
-	 * if hook is set
-	 */
 	if (hook) {
-		printf("===== Application Usage =====\n\n");
+		/* Print application usage through EAL options parsing. */
 		(hook)(prgname);
+		printf("\n");
 	}
+
+	eal_common_usage();
 }
 
 /* Parse the arguments for --log-level only */
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v2 03/11] eal: use macros for help option
  2021-03-10 13:28 ` [dpdk-dev] [PATCH v2 " Thomas Monjalon
  2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 01/11] eal: explain argv behaviour during init Thomas Monjalon
  2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 02/11] eal: improve options usage text Thomas Monjalon
@ 2021-03-10 13:28   ` Thomas Monjalon
  2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 04/11] eal: move private log functions Thomas Monjalon
                     ` (7 subsequent siblings)
  10 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-10 13:28 UTC (permalink / raw)
  To: dev
  Cc: david.marchand, Bruce Richardson, Dmitry Kozlyuk,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam

The macros OPT_HELP and OPT_HELP_NUM were not used where appropriate.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 lib/librte_eal/common/eal_common_options.c | 2 +-
 lib/librte_eal/freebsd/eal.c               | 2 +-
 lib/librte_eal/linux/eal.c                 | 2 +-
 lib/librte_eal/windows/eal.c               | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 0635b0d4ce..52fedb81e5 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -2090,7 +2090,7 @@ eal_common_usage(void)
 	       "                      must be specified once only.\n"
 #endif /* !RTE_EXEC_ENV_WINDOWS */
 	       "  -v                  Display version information on startup\n"
-	       "  -h, --help          This help\n"
+	       "  -h, --"OPT_HELP"          This help\n"
 	       "  --"OPT_IN_MEMORY"         Operate entirely in memory. This will\n"
 	       "                      disable secondary process support\n"
 	       "  --"OPT_BASE_VIRTADDR"     Base virtual address\n"
diff --git a/lib/librte_eal/freebsd/eal.c b/lib/librte_eal/freebsd/eal.c
index f466616566..66adfca2d1 100644
--- a/lib/librte_eal/freebsd/eal.c
+++ b/lib/librte_eal/freebsd/eal.c
@@ -549,7 +549,7 @@ eal_parse_args(int argc, char **argv)
 			}
 			break;
 		}
-		case 'h':
+		case OPT_HELP_NUM:
 			eal_usage(prgname);
 			exit(EXIT_SUCCESS);
 		default:
diff --git a/lib/librte_eal/linux/eal.c b/lib/librte_eal/linux/eal.c
index 7c1d296192..6f73616f86 100644
--- a/lib/librte_eal/linux/eal.c
+++ b/lib/librte_eal/linux/eal.c
@@ -716,7 +716,7 @@ eal_parse_args(int argc, char **argv)
 			continue;
 
 		switch (opt) {
-		case 'h':
+		case OPT_HELP_NUM:
 			eal_usage(prgname);
 			exit(EXIT_SUCCESS);
 
diff --git a/lib/librte_eal/windows/eal.c b/lib/librte_eal/windows/eal.c
index ec13ac1a9f..4dd2fc1403 100644
--- a/lib/librte_eal/windows/eal.c
+++ b/lib/librte_eal/windows/eal.c
@@ -158,7 +158,7 @@ eal_parse_args(int argc, char **argv)
 			continue;
 
 		switch (opt) {
-		case 'h':
+		case OPT_HELP_NUM:
 			eal_usage(prgname);
 			exit(EXIT_SUCCESS);
 		default:
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v2 04/11] eal: move private log functions
  2021-03-10 13:28 ` [dpdk-dev] [PATCH v2 " Thomas Monjalon
                     ` (2 preceding siblings ...)
  2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 03/11] eal: use macros for help option Thomas Monjalon
@ 2021-03-10 13:28   ` Thomas Monjalon
  2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 05/11] eal: introduce maximum log level macro Thomas Monjalon
                     ` (6 subsequent siblings)
  10 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-10 13:28 UTC (permalink / raw)
  To: dev
  Cc: david.marchand, Dmitry Kozlyuk, Narcisa Ana Maria Vasile,
	Dmitry Malloy, Pallavi Kadam

Some private log functions had a wrong "rte_" prefix.

All private log functions are moved from eal_private.h
to the new file eal_log.h:
	rte_eal_log_init -> eal_log_init
	rte_log_save_regexp -> eal_log_save_regexp
	rte_log_save_pattern -> eal_log_save_pattern
	eal_log_set_default

The static functions in the file eal_common_log.c are renamed:
	rte_log_save_level -> log_save_level
	rte_log_init -> log_init

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 lib/librte_eal/common/eal_common_log.c     | 18 ++++++++------
 lib/librte_eal/common/eal_common_options.c |  5 ++--
 lib/librte_eal/common/eal_log.h            | 27 ++++++++++++++++++++
 lib/librte_eal/common/eal_private.h        | 29 ----------------------
 lib/librte_eal/linux/eal.c                 |  3 ++-
 lib/librte_eal/linux/eal_log.c             |  4 +--
 lib/librte_eal/windows/eal.c               |  3 ++-
 lib/librte_eal/windows/eal_log.c           |  6 +++--
 8 files changed, 50 insertions(+), 45 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_log.h

diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c
index c5554badb2..aee7c44c6a 100644
--- a/lib/librte_eal/common/eal_common_log.c
+++ b/lib/librte_eal/common/eal_common_log.c
@@ -15,7 +15,7 @@
 #include <rte_log.h>
 #include <rte_per_lcore.h>
 
-#include "eal_private.h"
+#include "eal_log.h"
 
 struct rte_log_dynamic_type {
 	const char *name;
@@ -178,8 +178,8 @@ rte_log_set_level_regexp(const char *regex, uint32_t level)
  * Save the type string and the loglevel for later dynamic
  * logtypes which may register later.
  */
-static int rte_log_save_level(int priority,
-			      const char *regex, const char *pattern)
+static int
+log_save_level(uint32_t priority, const char *regex, const char *pattern)
 {
 	struct rte_eal_opt_loglevel *opt_ll = NULL;
 
@@ -207,9 +207,10 @@ static int rte_log_save_level(int priority,
 	return -1;
 }
 
-int rte_log_save_regexp(const char *regex, int tmp)
+int
+eal_log_save_regexp(const char *regex, uint32_t level)
 {
-	return rte_log_save_level(tmp, regex, NULL);
+	return log_save_level(level, regex, NULL);
 }
 
 /* set log level based on globbing pattern */
@@ -232,9 +233,10 @@ rte_log_set_level_pattern(const char *pattern, uint32_t level)
 	return 0;
 }
 
-int rte_log_save_pattern(const char *pattern, int priority)
+int
+eal_log_save_pattern(const char *pattern, uint32_t level)
 {
-	return rte_log_save_level(priority, NULL, pattern);
+	return log_save_level(level, NULL, pattern);
 }
 
 /* get the current loglevel for the message being processed */
@@ -376,7 +378,7 @@ static const struct logtype logtype_strings[] = {
 };
 
 /* Logging should be first initializer (before drivers and bus) */
-RTE_INIT_PRIO(rte_log_init, LOG)
+RTE_INIT_PRIO(log_init, LOG)
 {
 	uint32_t i;
 
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 52fedb81e5..02374ee09e 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -41,6 +41,7 @@
 #include "eal_options.h"
 #include "eal_filesystem.h"
 #include "eal_private.h"
+#include "eal_log.h"
 #ifndef RTE_EXEC_ENV_WINDOWS
 #include "eal_trace.h"
 #endif
@@ -1299,7 +1300,7 @@ eal_parse_log_level(const char *arg)
 				regex, priority);
 			goto fail;
 		}
-		if (rte_log_save_regexp(regex, priority) < 0)
+		if (eal_log_save_regexp(regex, priority) < 0)
 			goto fail;
 	} else if (pattern) {
 		if (rte_log_set_level_pattern(pattern, priority) < 0) {
@@ -1307,7 +1308,7 @@ eal_parse_log_level(const char *arg)
 				pattern, priority);
 			goto fail;
 		}
-		if (rte_log_save_pattern(pattern, priority) < 0)
+		if (eal_log_save_pattern(pattern, priority) < 0)
 			goto fail;
 	} else {
 		rte_log_set_global_level(priority);
diff --git a/lib/librte_eal/common/eal_log.h b/lib/librte_eal/common/eal_log.h
new file mode 100644
index 0000000000..684650a17b
--- /dev/null
+++ b/lib/librte_eal/common/eal_log.h
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2021 Mellanox Technologies, Ltd
+ */
+
+#ifndef EAL_LOG_H
+#define EAL_LOG_H
+
+#include <stdio.h>
+#include <stdint.h>
+
+/*
+ * Initialize the default log stream.
+ */
+int eal_log_init(const char *id, int facility);
+
+/*
+ * Determine where log data is written when no call to rte_openlog_stream.
+ */
+void eal_log_set_default(FILE *default_log);
+
+/*
+ * Save a log option for later.
+ */
+int eal_log_save_regexp(const char *regexp, uint32_t level);
+int eal_log_save_pattern(const char *pattern, uint32_t level);
+
+#endif /* EAL_LOG_H */
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index b8a0d20021..e3512111d9 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -79,19 +79,6 @@ struct rte_config *rte_eal_get_configuration(void);
  */
 int rte_eal_memzone_init(void);
 
-/**
- * Common log initialization function (private to eal).  Determines
- * where log data is written when no call to rte_openlog_stream is
- * in effect.
- *
- * @param default_log
- *   The default log stream to be used.
- * @return
- *   - 0 on success
- *   - Negative on error
- */
-void eal_log_set_default(FILE *default_log);
-
 /**
  * Fill configuration with number of physical and logical processors
  *
@@ -143,22 +130,6 @@ int rte_eal_memory_init(void);
  */
 int rte_eal_timer_init(void);
 
-/**
- * Init the default log stream
- *
- * This function is private to EAL.
- *
- * @return
- *   0 on success, negative on error
- */
-int rte_eal_log_init(const char *id, int facility);
-
-/**
- * Save the log regexp for later
- */
-int rte_log_save_regexp(const char *type, int priority);
-int rte_log_save_pattern(const char *pattern, int priority);
-
 /**
  * Init tail queues for non-EAL library structures. This is to allow
  * the rings, mempools, etc. lists to be shared among multiple processes
diff --git a/lib/librte_eal/linux/eal.c b/lib/librte_eal/linux/eal.c
index 6f73616f86..e4feeb2b0e 100644
--- a/lib/librte_eal/linux/eal.c
+++ b/lib/librte_eal/linux/eal.c
@@ -58,6 +58,7 @@
 #include "eal_hugepages.h"
 #include "eal_memcfg.h"
 #include "eal_trace.h"
+#include "eal_log.h"
 #include "eal_options.h"
 #include "eal_vfio.h"
 #include "hotplug_mp.h"
@@ -1160,7 +1161,7 @@ rte_eal_init(int argc, char **argv)
 #endif
 	}
 
-	if (rte_eal_log_init(logid, internal_conf->syslog_facility) < 0) {
+	if (eal_log_init(logid, internal_conf->syslog_facility) < 0) {
 		rte_eal_init_alert("Cannot init logging.");
 		rte_errno = ENOMEM;
 		__atomic_store_n(&run_once, 0, __ATOMIC_RELAXED);
diff --git a/lib/librte_eal/linux/eal_log.c b/lib/librte_eal/linux/eal_log.c
index 43c8460bfb..1a08139eb5 100644
--- a/lib/librte_eal/linux/eal_log.c
+++ b/lib/librte_eal/linux/eal_log.c
@@ -17,7 +17,7 @@
 #include <rte_spinlock.h>
 #include <rte_log.h>
 
-#include "eal_private.h"
+#include "eal_log.h"
 
 /*
  * default log function
@@ -46,7 +46,7 @@ static cookie_io_functions_t console_log_func = {
  * once memzones are available.
  */
 int
-rte_eal_log_init(const char *id, int facility)
+eal_log_init(const char *id, int facility)
 {
 	FILE *log_stream;
 
diff --git a/lib/librte_eal/windows/eal.c b/lib/librte_eal/windows/eal.c
index 4dd2fc1403..5bca3ace1c 100644
--- a/lib/librte_eal/windows/eal.c
+++ b/lib/librte_eal/windows/eal.c
@@ -22,6 +22,7 @@
 
 #include "eal_hugepages.h"
 #include "eal_trace.h"
+#include "eal_log.h"
 #include "eal_windows.h"
 
 #define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL)
@@ -265,7 +266,7 @@ rte_eal_init(int argc, char **argv)
 		eal_get_internal_configuration();
 	int ret;
 
-	rte_eal_log_init(NULL, 0);
+	eal_log_init(NULL, 0);
 
 	eal_log_level_parse(argc, argv);
 
diff --git a/lib/librte_eal/windows/eal_log.c b/lib/librte_eal/windows/eal_log.c
index 875981f139..d4ea47f1c8 100644
--- a/lib/librte_eal/windows/eal_log.c
+++ b/lib/librte_eal/windows/eal_log.c
@@ -2,11 +2,13 @@
  * Copyright(c) 2017-2018 Intel Corporation
  */
 
-#include "eal_private.h"
+#include <rte_common.h>
+#include <rte_log.h>
+#include "eal_log.h"
 
 /* set the log to default function, called during eal init process. */
 int
-rte_eal_log_init(__rte_unused const char *id, __rte_unused int facility)
+eal_log_init(__rte_unused const char *id, __rte_unused int facility)
 {
 	rte_openlog_stream(stderr);
 
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v2 05/11] eal: introduce maximum log level macro
  2021-03-10 13:28 ` [dpdk-dev] [PATCH v2 " Thomas Monjalon
                     ` (3 preceding siblings ...)
  2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 04/11] eal: move private log functions Thomas Monjalon
@ 2021-03-10 13:28   ` Thomas Monjalon
  2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 06/11] eal: catch invalid log level number Thomas Monjalon
                     ` (5 subsequent siblings)
  10 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-10 13:28 UTC (permalink / raw)
  To: dev; +Cc: david.marchand

RTE_DIM(...) and RTE_LOG_DEBUG were used to get the highest log level.
For better clarity a new constant RTE_LOG_MAX is introduced
and mapped to RTE_LOG_DEBUG.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 lib/librte_eal/common/eal_common_log.c     | 8 ++++----
 lib/librte_eal/common/eal_common_options.c | 2 +-
 lib/librte_eal/include/rte_log.h           | 1 +
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c
index aee7c44c6a..40cac36f89 100644
--- a/lib/librte_eal/common/eal_common_log.c
+++ b/lib/librte_eal/common/eal_common_log.c
@@ -140,7 +140,7 @@ rte_log_set_level(uint32_t type, uint32_t level)
 {
 	if (type >= rte_logs.dynamic_types_len)
 		return -1;
-	if (level > RTE_LOG_DEBUG)
+	if (level > RTE_LOG_MAX)
 		return -1;
 
 	rte_logs.dynamic_types[type].loglevel = level;
@@ -155,7 +155,7 @@ rte_log_set_level_regexp(const char *regex, uint32_t level)
 	regex_t r;
 	size_t i;
 
-	if (level > RTE_LOG_DEBUG)
+	if (level > RTE_LOG_MAX)
 		return -1;
 
 	if (regcomp(&r, regex, 0) != 0)
@@ -219,7 +219,7 @@ rte_log_set_level_pattern(const char *pattern, uint32_t level)
 {
 	size_t i;
 
-	if (level > RTE_LOG_DEBUG)
+	if (level > RTE_LOG_MAX)
 		return -1;
 
 	for (i = 0; i < rte_logs.dynamic_types_len; i++) {
@@ -323,7 +323,7 @@ rte_log_register_type_and_pick_level(const char *name, uint32_t level_def)
 		return type;
 
 	TAILQ_FOREACH(opt_ll, &opt_loglevel_list, next) {
-		if (opt_ll->level > RTE_LOG_DEBUG)
+		if (opt_ll->level > RTE_LOG_MAX)
 			continue;
 
 		if (opt_ll->pattern) {
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 02374ee09e..3675e55fc9 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -1249,7 +1249,7 @@ eal_parse_log_priority(const char *level)
 		return -1;
 
 	/* look for named values, skip 0 which is not a valid level */
-	for (i = 1; i < RTE_DIM(levels); i++) {
+	for (i = 1; i <= RTE_LOG_MAX; i++) {
 		if (strncmp(levels[i], level, len) == 0)
 			return i;
 	}
diff --git a/lib/librte_eal/include/rte_log.h b/lib/librte_eal/include/rte_log.h
index 173004fd71..394e8682b9 100644
--- a/lib/librte_eal/include/rte_log.h
+++ b/lib/librte_eal/include/rte_log.h
@@ -72,6 +72,7 @@ extern "C" {
 #define RTE_LOG_NOTICE   6U  /**< Normal but significant condition. */
 #define RTE_LOG_INFO     7U  /**< Informational.                    */
 #define RTE_LOG_DEBUG    8U  /**< Debug-level messages.             */
+#define RTE_LOG_MAX RTE_LOG_DEBUG /**< Most detailed log level.     */
 
 /**
  * Change the stream that will be used by the logging system.
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v2 06/11] eal: catch invalid log level number
  2021-03-10 13:28 ` [dpdk-dev] [PATCH v2 " Thomas Monjalon
                     ` (4 preceding siblings ...)
  2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 05/11] eal: introduce maximum log level macro Thomas Monjalon
@ 2021-03-10 13:28   ` Thomas Monjalon
  2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 07/11] eal: add log level help Thomas Monjalon
                     ` (4 subsequent siblings)
  10 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-10 13:28 UTC (permalink / raw)
  To: dev; +Cc: david.marchand

The parsing check for invalid log level was not trying to catch
irrelevant numeric values.
A log level 0 or too high is now a failure in options parsing
so it can be caught early.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 lib/librte_eal/common/eal_common_options.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 3675e55fc9..da0aaf831e 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -1289,7 +1289,7 @@ eal_parse_log_level(const char *arg)
 	}
 
 	priority = eal_parse_log_priority(level);
-	if (priority < 0) {
+	if (priority <= 0 || priority > (int) RTE_LOG_MAX) {
 		fprintf(stderr, "invalid log priority: %s\n", level);
 		goto fail;
 	}
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v2 07/11] eal: add log level help
  2021-03-10 13:28 ` [dpdk-dev] [PATCH v2 " Thomas Monjalon
                     ` (5 preceding siblings ...)
  2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 06/11] eal: catch invalid log level number Thomas Monjalon
@ 2021-03-10 13:28   ` Thomas Monjalon
  2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 08/11] app: fix exit messages Thomas Monjalon
                     ` (3 subsequent siblings)
  10 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-10 13:28 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, Ray Kinsella, Neil Horman

The option --log-level was not completely described in the usage text,
and it was difficult to guess the names of the log types and levels.

A new value "help" is accepted after --log-level to give more details
about the syntax and listing the log types and levels.

The array "levels" used for level name parsing is replaced with
a (modified) existing function which was used in rte_log_dump().

The new function rte_log_list_types() is exported in the API
for allowing an application to give this info to the user
if not exposing the EAL option --log-level.
The list of log types cannot include all drivers if not linked in the
application (shared object plugin case).

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 lib/librte_eal/common/eal_common_log.c     | 24 +++++++++---
 lib/librte_eal/common/eal_common_options.c | 44 +++++++++++++++-------
 lib/librte_eal/common/eal_log.h            |  5 +++
 lib/librte_eal/include/rte_log.h           | 11 ++++++
 lib/librte_eal/version.map                 |  3 ++
 5 files changed, 69 insertions(+), 18 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c
index 40cac36f89..d695b04068 100644
--- a/lib/librte_eal/common/eal_common_log.c
+++ b/lib/librte_eal/common/eal_common_log.c
@@ -397,12 +397,12 @@ RTE_INIT_PRIO(log_init, LOG)
 	rte_logs.dynamic_types_len = RTE_LOGTYPE_FIRST_EXT_ID;
 }
 
-static const char *
-loglevel_to_string(uint32_t level)
+const char *
+eal_log_level2str(uint32_t level)
 {
 	switch (level) {
 	case 0: return "disabled";
-	case RTE_LOG_EMERG: return "emerg";
+	case RTE_LOG_EMERG: return "emergency";
 	case RTE_LOG_ALERT: return "alert";
 	case RTE_LOG_CRIT: return "critical";
 	case RTE_LOG_ERR: return "error";
@@ -414,6 +414,20 @@ loglevel_to_string(uint32_t level)
 	}
 }
 
+/* Dump name of each logtype, one per line. */
+void
+rte_log_list_types(FILE *out, const char *prefix)
+{
+	size_t type;
+
+	for (type = 0; type < rte_logs.dynamic_types_len; ++type) {
+		if (rte_logs.dynamic_types[type].name == NULL)
+			continue;
+		fprintf(out, "%s%s\n",
+				prefix, rte_logs.dynamic_types[type].name);
+	}
+}
+
 /* dump global level and registered log types */
 void
 rte_log_dump(FILE *f)
@@ -421,14 +435,14 @@ rte_log_dump(FILE *f)
 	size_t i;
 
 	fprintf(f, "global log level is %s\n",
-		loglevel_to_string(rte_log_get_global_level()));
+		eal_log_level2str(rte_log_get_global_level()));
 
 	for (i = 0; i < rte_logs.dynamic_types_len; i++) {
 		if (rte_logs.dynamic_types[i].name == NULL)
 			continue;
 		fprintf(f, "id %zu: %s, level is %s\n",
 			i, rte_logs.dynamic_types[i].name,
-			loglevel_to_string(rte_logs.dynamic_types[i].loglevel));
+			eal_log_level2str(rte_logs.dynamic_types[i].loglevel));
 	}
 }
 
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index da0aaf831e..188456e4ae 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -1227,19 +1227,31 @@ eal_parse_syslog(const char *facility, struct internal_config *conf)
 }
 #endif
 
+static void
+eal_log_usage(void)
+{
+	unsigned int level;
+
+	printf("Log type is a pattern matching items of this list"
+			" (plugins may be missing):\n");
+	rte_log_list_types(stdout, "\t");
+	printf("\n");
+	printf("Syntax using globbing pattern:     ");
+	printf("--"OPT_LOG_LEVEL" pattern:level\n");
+	printf("Syntax using regular expression:   ");
+	printf("--"OPT_LOG_LEVEL" regexp,level\n");
+	printf("Syntax for the global level:       ");
+	printf("--"OPT_LOG_LEVEL" level\n");
+	printf("Logs are emitted if allowed by both global and specific levels.\n");
+	printf("\n");
+	printf("Log level can be a number or the first letters of its name:\n");
+	for (level = 1; level <= RTE_LOG_MAX; level++)
+		printf("\t%d   %s\n", level, eal_log_level2str(level));
+}
+
 static int
 eal_parse_log_priority(const char *level)
 {
-	static const char * const levels[] = {
-		[RTE_LOG_EMERG]   = "emergency",
-		[RTE_LOG_ALERT]   = "alert",
-		[RTE_LOG_CRIT]    = "critical",
-		[RTE_LOG_ERR]     = "error",
-		[RTE_LOG_WARNING] = "warning",
-		[RTE_LOG_NOTICE]  = "notice",
-		[RTE_LOG_INFO]    = "info",
-		[RTE_LOG_DEBUG]   = "debug",
-	};
 	size_t len = strlen(level);
 	unsigned long tmp;
 	char *end;
@@ -1250,7 +1262,7 @@ eal_parse_log_priority(const char *level)
 
 	/* look for named values, skip 0 which is not a valid level */
 	for (i = 1; i <= RTE_LOG_MAX; i++) {
-		if (strncmp(levels[i], level, len) == 0)
+		if (strncmp(eal_log_level2str(i), level, len) == 0)
 			return i;
 	}
 
@@ -1274,6 +1286,11 @@ eal_parse_log_level(const char *arg)
 	char *str, *level;
 	int priority;
 
+	if (strcmp(arg, "help") == 0) {
+		eal_log_usage();
+		exit(EXIT_SUCCESS);
+	}
+
 	str = strdup(arg);
 	if (str == NULL)
 		return -1;
@@ -2062,9 +2079,10 @@ eal_common_usage(void)
 #ifndef RTE_EXEC_ENV_WINDOWS
 	       "  --"OPT_SYSLOG"            Set syslog facility\n"
 #endif
-	       "  --"OPT_LOG_LEVEL"=<int>   Set global log level\n"
-	       "  --"OPT_LOG_LEVEL"=<type-match>:<int>\n"
+	       "  --"OPT_LOG_LEVEL"=<level> Set global log level\n"
+	       "  --"OPT_LOG_LEVEL"=<type-match>:<level>\n"
 	       "                      Set specific log level\n"
+	       "  --"OPT_LOG_LEVEL"=help    Show log types and levels\n"
 #ifndef RTE_EXEC_ENV_WINDOWS
 	       "  --"OPT_TRACE"=<regex-match>\n"
 	       "                      Enable trace based on regular expression trace name.\n"
diff --git a/lib/librte_eal/common/eal_log.h b/lib/librte_eal/common/eal_log.h
index 684650a17b..c784fa6043 100644
--- a/lib/librte_eal/common/eal_log.h
+++ b/lib/librte_eal/common/eal_log.h
@@ -24,4 +24,9 @@ void eal_log_set_default(FILE *default_log);
 int eal_log_save_regexp(const char *regexp, uint32_t level);
 int eal_log_save_pattern(const char *pattern, uint32_t level);
 
+/*
+ * Convert log level to string.
+ */
+const char *eal_log_level2str(uint32_t level);
+
 #endif /* EAL_LOG_H */
diff --git a/lib/librte_eal/include/rte_log.h b/lib/librte_eal/include/rte_log.h
index 394e8682b9..e6192892c3 100644
--- a/lib/librte_eal/include/rte_log.h
+++ b/lib/librte_eal/include/rte_log.h
@@ -240,6 +240,17 @@ int rte_log_register(const char *name);
 __rte_experimental
 int rte_log_register_type_and_pick_level(const char *name, uint32_t level_def);
 
+/**
+ * Dump name of each logtype, one per line.
+ *
+ * @param out
+ *   Stream where the list is sent.
+ * @param prefix
+ *   String preceding each logtype in the output.
+ */
+__rte_experimental
+void rte_log_list_types(FILE *out, const char *prefix);
+
 /**
  * Dump log information.
  *
diff --git a/lib/librte_eal/version.map b/lib/librte_eal/version.map
index fce90a112f..6b7876a0b9 100644
--- a/lib/librte_eal/version.map
+++ b/lib/librte_eal/version.map
@@ -412,6 +412,9 @@ EXPERIMENTAL {
 	rte_thread_tls_key_delete;
 	rte_thread_tls_value_get;
 	rte_thread_tls_value_set;
+
+	# added in 21.05
+	rte_log_list_types;
 };
 
 INTERNAL {
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v2 08/11] app: fix exit messages
  2021-03-10 13:28 ` [dpdk-dev] [PATCH v2 " Thomas Monjalon
                     ` (6 preceding siblings ...)
  2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 07/11] eal: add log level help Thomas Monjalon
@ 2021-03-10 13:28   ` Thomas Monjalon
  2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 09/11] app: hook in EAL usage help Thomas Monjalon
                     ` (2 subsequent siblings)
  10 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-10 13:28 UTC (permalink / raw)
  To: dev
  Cc: david.marchand, Wisam Jaddo, Ori Kam, Declan Doherty,
	Ciara Power, Xiaoyun Li

Some applications were printing useless messages with rte_exit()
after showing the help. Using exit() is enough in this case.

Some applications were using a redundant printf or fprintf() before
calling rte_exit(). The messages are unified in a single rte_exit().

Some rte_exit() calls were missing a line feed or returning a wrong code.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Wisam Jaddo <wisamm@nvidia.com>
Acked-by: Ori Kam <orika@nvidia.com>
---
 .../comp_perf_options_parse.c                 |  2 +-
 app/test-crypto-perf/cperf_options_parsing.c  |  2 +-
 app/test-flow-perf/main.c                     | 59 +++++++++----------
 app/test-pmd/parameters.c                     |  4 +-
 app/test-regex/main.c                         |  3 +-
 5 files changed, 33 insertions(+), 37 deletions(-)

diff --git a/app/test-compress-perf/comp_perf_options_parse.c b/app/test-compress-perf/comp_perf_options_parse.c
index 04a8d2fbee..019eddb7bd 100644
--- a/app/test-compress-perf/comp_perf_options_parse.c
+++ b/app/test-compress-perf/comp_perf_options_parse.c
@@ -620,7 +620,7 @@ comp_perf_options_parse(struct comp_test_data *test_data, int argc, char **argv)
 		switch (opt) {
 		case 'h':
 			usage(argv[0]);
-			rte_exit(EXIT_SUCCESS, "Displayed help\n");
+			exit(EXIT_SUCCESS);
 			break;
 		/* long options */
 		case 0:
diff --git a/app/test-crypto-perf/cperf_options_parsing.c b/app/test-crypto-perf/cperf_options_parsing.c
index 0466f7baf8..40b6dfb648 100644
--- a/app/test-crypto-perf/cperf_options_parsing.c
+++ b/app/test-crypto-perf/cperf_options_parsing.c
@@ -983,7 +983,7 @@ cperf_options_parse(struct cperf_options *options, int argc, char **argv)
 		switch (opt) {
 		case 'h':
 			usage(argv[0]);
-			rte_exit(EXIT_SUCCESS, "Displayed help\n");
+			exit(EXIT_SUCCESS);
 			break;
 		/* long options */
 		case 0:
diff --git a/app/test-flow-perf/main.c b/app/test-flow-perf/main.c
index 99d0463456..0aef767350 100644
--- a/app/test-flow-perf/main.c
+++ b/app/test-flow-perf/main.c
@@ -639,7 +639,7 @@ args_parse(int argc, char **argv)
 		case 0:
 			if (strcmp(lgopts[opt_idx].name, "help") == 0) {
 				usage(argv[0]);
-				rte_exit(EXIT_SUCCESS, "Displayed help\n");
+				exit(EXIT_SUCCESS);
 			}
 
 			if (strcmp(lgopts[opt_idx].name, "group") == 0) {
@@ -647,7 +647,7 @@ args_parse(int argc, char **argv)
 				if (n >= 0)
 					flow_group = n;
 				else
-					rte_exit(EXIT_SUCCESS,
+					rte_exit(EXIT_FAILURE,
 						"flow group should be >= 0\n");
 				printf("group %d / ", flow_group);
 			}
@@ -667,7 +667,7 @@ args_parse(int argc, char **argv)
 				if (n > 0)
 					hairpin_queues_num = n;
 				else
-					rte_exit(EXIT_SUCCESS,
+					rte_exit(EXIT_FAILURE,
 						"Hairpin queues should be > 0\n");
 
 				flow_actions[actions_idx++] =
@@ -680,7 +680,7 @@ args_parse(int argc, char **argv)
 				if (n > 0)
 					hairpin_queues_num = n;
 				else
-					rte_exit(EXIT_SUCCESS,
+					rte_exit(EXIT_FAILURE,
 						"Hairpin queues should be > 0\n");
 
 				flow_actions[actions_idx++] =
@@ -704,11 +704,9 @@ args_parse(int argc, char **argv)
 							break;
 						}
 						/* Reached last item with no match */
-						if (i == (RTE_DIM(flow_options) - 1)) {
-							fprintf(stderr, "Invalid encap item: %s\n", token);
-							usage(argv[0]);
-							rte_exit(EXIT_SUCCESS, "Invalid encap item\n");
-						}
+						if (i == (RTE_DIM(flow_options) - 1))
+							rte_exit(EXIT_FAILURE,
+								"Invalid encap item: %s\n", token);
 					}
 					token = strtok(NULL, ",");
 				}
@@ -730,11 +728,9 @@ args_parse(int argc, char **argv)
 							break;
 						}
 						/* Reached last item with no match */
-						if (i == (RTE_DIM(flow_options) - 1)) {
-							fprintf(stderr, "Invalid decap item: %s\n", token);
-							usage(argv[0]);
-							rte_exit(EXIT_SUCCESS, "Invalid decap item\n");
-						}
+						if (i == (RTE_DIM(flow_options) - 1))
+							rte_exit(EXIT_FAILURE,
+								"Invalid decap item %s\n", token);
 					}
 					token = strtok(NULL, ",");
 				}
@@ -747,9 +743,9 @@ args_parse(int argc, char **argv)
 				if (n >= DEFAULT_RULES_BATCH)
 					rules_batch = n;
 				else {
-					printf("\n\nrules_batch should be >= %d\n",
+					rte_exit(EXIT_FAILURE,
+						"rules_batch should be >= %d\n",
 						DEFAULT_RULES_BATCH);
-					rte_exit(EXIT_SUCCESS, " ");
 				}
 			}
 			if (strcmp(lgopts[opt_idx].name,
@@ -758,7 +754,8 @@ args_parse(int argc, char **argv)
 				if (n >= (int) rules_batch)
 					rules_count = n;
 				else {
-					printf("\n\nrules_count should be >= %d\n",
+					rte_exit(EXIT_FAILURE,
+						"rules_count should be >= %d\n",
 						rules_batch);
 				}
 			}
@@ -786,23 +783,23 @@ args_parse(int argc, char **argv)
 			if (strcmp(lgopts[opt_idx].name, "cores") == 0) {
 				n = atoi(optarg);
 				if ((int) rte_lcore_count() <= n) {
-					printf("\nError: you need %d cores to run on multi-cores\n"
+					rte_exit(EXIT_FAILURE,
+						"Error: you need %d cores to run on multi-cores\n"
 						"Existing cores are: %d\n", n, rte_lcore_count());
-					rte_exit(EXIT_FAILURE, " ");
 				}
 				if (n <= RTE_MAX_LCORE && n > 0)
 					mc_pool.cores_count = n;
 				else {
-					printf("Error: cores count must be > 0 "
-						" and < %d\n", RTE_MAX_LCORE);
-					rte_exit(EXIT_FAILURE, " ");
+					rte_exit(EXIT_FAILURE,
+						"Error: cores count must be > 0 and < %d\n",
+						RTE_MAX_LCORE);
 				}
 			}
 			break;
 		default:
-			fprintf(stderr, "Invalid option: %s\n", argv[optind]);
 			usage(argv[0]);
-			rte_exit(EXIT_SUCCESS, "Invalid option\n");
+			rte_exit(EXIT_FAILURE, "Invalid option: %s\n",
+					argv[optind]);
 			break;
 		}
 	}
@@ -936,7 +933,7 @@ create_meter_rule(int port_id, uint32_t counter)
 		printf("Port %u create meter idx(%d) error(%d) message: %s\n",
 			port_id, counter, error.type,
 			error.message ? error.message : "(no stated reason)");
-		rte_exit(EXIT_FAILURE, "error in creating meter");
+		rte_exit(EXIT_FAILURE, "Error in creating meter\n");
 	}
 }
 
@@ -949,7 +946,7 @@ destroy_meter_rule(int port_id, uint32_t counter)
 		printf("Port %u destroy meter(%d) error(%d) message: %s\n",
 			port_id, counter, error.type,
 			error.message ? error.message : "(no stated reason)");
-		rte_exit(EXIT_FAILURE, "Error in deleting meter rule");
+		rte_exit(EXIT_FAILURE, "Error in deleting meter rule\n");
 	}
 }
 
@@ -1097,7 +1094,7 @@ destroy_flows(int port_id, uint8_t core_id, struct rte_flow **flows_list)
 		memset(&error, 0x33, sizeof(error));
 		if (rte_flow_destroy(port_id, flows_list[i], &error)) {
 			print_flow_error(error);
-			rte_exit(EXIT_FAILURE, "Error in deleting flow");
+			rte_exit(EXIT_FAILURE, "Error in deleting flow\n");
 		}
 
 		/*
@@ -1160,7 +1157,7 @@ insert_flows(int port_id, uint8_t core_id)
 	flows_list = rte_zmalloc("flows_list",
 		(sizeof(struct rte_flow *) * rules_count_per_core) + 1, 0);
 	if (flows_list == NULL)
-		rte_exit(EXIT_FAILURE, "No Memory available!");
+		rte_exit(EXIT_FAILURE, "No Memory available!\n");
 
 	cpu_time_used = 0;
 	flow_index = 0;
@@ -1180,7 +1177,7 @@ insert_flows(int port_id, uint8_t core_id)
 
 		if (flow == NULL) {
 			print_flow_error(error);
-			rte_exit(EXIT_FAILURE, "error in creating flow");
+			rte_exit(EXIT_FAILURE, "Error in creating flow\n");
 		}
 		flows_list[flow_index++] = flow;
 	}
@@ -1199,7 +1196,7 @@ insert_flows(int port_id, uint8_t core_id)
 
 		if (!flow) {
 			print_flow_error(error);
-			rte_exit(EXIT_FAILURE, "error in creating flow");
+			rte_exit(EXIT_FAILURE, "Error in creating flow\n");
 		}
 
 		flows_list[flow_index++] = flow;
@@ -1517,7 +1514,7 @@ packet_per_second_stats(void)
 	old = rte_zmalloc("old",
 		sizeof(struct lcore_info) * RTE_MAX_LCORE, 0);
 	if (old == NULL)
-		rte_exit(EXIT_FAILURE, "No Memory available!");
+		rte_exit(EXIT_FAILURE, "No Memory available!\n");
 
 	memcpy(old, lcore_infos,
 		sizeof(struct lcore_info) * RTE_MAX_LCORE);
diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c
index c8acd5d1b7..55ecea6338 100644
--- a/app/test-pmd/parameters.c
+++ b/app/test-pmd/parameters.c
@@ -632,7 +632,7 @@ launch_args_parse(int argc, char** argv)
 		case 0: /*long options */
 			if (!strcmp(lgopts[opt_idx].name, "help")) {
 				usage(argv[0]);
-				rte_exit(EXIT_SUCCESS, "Displayed help\n");
+				exit(EXIT_SUCCESS);
 			}
 #ifdef RTE_LIB_CMDLINE
 			if (!strcmp(lgopts[opt_idx].name, "interactive")) {
@@ -1369,7 +1369,7 @@ launch_args_parse(int argc, char** argv)
 			break;
 		case 'h':
 			usage(argv[0]);
-			rte_exit(EXIT_SUCCESS, "Displayed help\n");
+			exit(EXIT_SUCCESS);
 			break;
 		default:
 			usage(argv[0]);
diff --git a/app/test-regex/main.c b/app/test-regex/main.c
index aea4fa6b88..7bb87bb1b8 100644
--- a/app/test-regex/main.c
+++ b/app/test-regex/main.c
@@ -154,9 +154,8 @@ args_parse(int argc, char **argv, char *rules_file, char *data_file,
 			usage("RegEx test app");
 			break;
 		default:
-			fprintf(stderr, "Invalid option: %s\n", argv[optind]);
 			usage("RegEx test app");
-			rte_exit(EXIT_FAILURE, "Invalid option\n");
+			rte_exit(EXIT_FAILURE, "Invalid option: %s\n", argv[optind]);
 			break;
 		}
 	}
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v2 09/11] app: hook in EAL usage help
  2021-03-10 13:28 ` [dpdk-dev] [PATCH v2 " Thomas Monjalon
                     ` (7 preceding siblings ...)
  2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 08/11] app: fix exit messages Thomas Monjalon
@ 2021-03-10 13:28   ` Thomas Monjalon
  2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 10/11] app/regex: fix usage text Thomas Monjalon
  2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 11/11] app/testpmd: " Thomas Monjalon
  10 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-10 13:28 UTC (permalink / raw)
  To: dev
  Cc: david.marchand, Wisam Jaddo, Reshma Pattan, Maryam Tahhan,
	Konstantin Ananyev, Nicolas Chautru, Declan Doherty, Ciara Power,
	Vladimir Medvedkin, Xiaoyun Li, Ori Kam, Bernard Iremonger

Use rte_set_application_usage_hook() in the test applications,
so the full help including EAL options can be printed in one go
with the EAL option -h or --help.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Wisam Jaddo <wisamm@nvidia.com>
---
 app/pdump/main.c                                 | 2 ++
 app/proc-info/main.c                             | 2 ++
 app/test-acl/main.c                              | 2 ++
 app/test-bbdev/main.c                            | 3 ++-
 app/test-compress-perf/comp_perf_options.h       | 2 ++
 app/test-compress-perf/comp_perf_options_parse.c | 8 ++++----
 app/test-compress-perf/main.c                    | 3 ++-
 app/test-crypto-perf/cperf_options.h             | 2 ++
 app/test-crypto-perf/cperf_options_parsing.c     | 8 ++++----
 app/test-crypto-perf/main.c                      | 3 ++-
 app/test-fib/main.c                              | 8 ++++++++
 app/test-flow-perf/main.c                        | 4 +++-
 app/test-pmd/parameters.c                        | 4 ++--
 app/test-pmd/testpmd.c                           | 2 ++
 app/test-pmd/testpmd.h                           | 1 +
 app/test-regex/main.c                            | 3 ++-
 app/test-sad/main.c                              | 7 +++++++
 17 files changed, 49 insertions(+), 15 deletions(-)

diff --git a/app/pdump/main.c b/app/pdump/main.c
index 63bbe65cd8..8641017f48 100644
--- a/app/pdump/main.c
+++ b/app/pdump/main.c
@@ -974,6 +974,8 @@ main(int argc, char **argv)
 	char mp_flag[] = "--proc-type=secondary";
 	char *argp[argc + 2];
 
+	rte_set_application_usage_hook(pdump_usage);
+
 	/* catch ctrl-c so we can print on exit */
 	signal(SIGINT, signal_handler);
 
diff --git a/app/proc-info/main.c b/app/proc-info/main.c
index b9587f7ded..e7d86bfa9d 100644
--- a/app/proc-info/main.c
+++ b/app/proc-info/main.c
@@ -1361,6 +1361,8 @@ main(int argc, char **argv)
 	char *argp[argc + 4];
 	uint16_t nb_ports;
 
+	rte_set_application_usage_hook(proc_info_usage);
+
 	/* preparse app arguments */
 	ret = proc_info_preparse_args(argc, argv);
 	if (ret < 0) {
diff --git a/app/test-acl/main.c b/app/test-acl/main.c
index 2cb2fe2579..9f95cb0fbf 100644
--- a/app/test-acl/main.c
+++ b/app/test-acl/main.c
@@ -1080,6 +1080,8 @@ main(int argc, char **argv)
 	int ret;
 	uint32_t lcore;
 
+	rte_set_application_usage_hook(print_usage);
+
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
 		rte_panic("Cannot init EAL\n");
diff --git a/app/test-bbdev/main.c b/app/test-bbdev/main.c
index ff65173fdb..5960ec18b2 100644
--- a/app/test-bbdev/main.c
+++ b/app/test-bbdev/main.c
@@ -340,7 +340,8 @@ main(int argc, char **argv)
 {
 	int ret;
 
-	/* Init EAL */
+	rte_set_application_usage_hook(print_usage);
+
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
 		return 1;
diff --git a/app/test-compress-perf/comp_perf_options.h b/app/test-compress-perf/comp_perf_options.h
index 0b777521c5..7dd785fba1 100644
--- a/app/test-compress-perf/comp_perf_options.h
+++ b/app/test-compress-perf/comp_perf_options.h
@@ -73,6 +73,8 @@ struct comp_test_data {
 	uint32_t cyclecount_delay;
 };
 
+void comp_perf_usage(const char *progname);
+
 int
 comp_perf_options_parse(struct comp_test_data *test_data, int argc,
 			char **argv);
diff --git a/app/test-compress-perf/comp_perf_options_parse.c b/app/test-compress-perf/comp_perf_options_parse.c
index 019eddb7bd..39d7fd8c69 100644
--- a/app/test-compress-perf/comp_perf_options_parse.c
+++ b/app/test-compress-perf/comp_perf_options_parse.c
@@ -38,8 +38,8 @@ struct name_id_map {
 	uint32_t id;
 };
 
-static void
-usage(char *progname)
+void
+comp_perf_usage(const char *progname)
 {
 	printf("%s [EAL options] --\n"
 		" --ptest throughput / verify / pmd-cyclecount\n"
@@ -619,7 +619,7 @@ comp_perf_options_parse(struct comp_test_data *test_data, int argc, char **argv)
 	while ((opt = getopt_long(argc, argv, "h", lgopts, &opt_idx)) != EOF) {
 		switch (opt) {
 		case 'h':
-			usage(argv[0]);
+			comp_perf_usage(argv[0]);
 			exit(EXIT_SUCCESS);
 			break;
 		/* long options */
@@ -631,7 +631,7 @@ comp_perf_options_parse(struct comp_test_data *test_data, int argc, char **argv)
 			break;
 
 		default:
-			usage(argv[0]);
+			comp_perf_usage(argv[0]);
 			return -EINVAL;
 		}
 	}
diff --git a/app/test-compress-perf/main.c b/app/test-compress-perf/main.c
index cc9951a9b1..dcd347528e 100644
--- a/app/test-compress-perf/main.c
+++ b/app/test-compress-perf/main.c
@@ -323,7 +323,8 @@ main(int argc, char **argv)
 	uint8_t cdev_id;
 	uint32_t lcore_id;
 
-	/* Initialise DPDK EAL */
+	rte_set_application_usage_hook(comp_perf_usage);
+
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
 		rte_exit(EXIT_FAILURE, "Invalid EAL arguments!\n");
diff --git a/app/test-crypto-perf/cperf_options.h b/app/test-crypto-perf/cperf_options.h
index 9664a4b343..5f4a780614 100644
--- a/app/test-crypto-perf/cperf_options.h
+++ b/app/test-crypto-perf/cperf_options.h
@@ -153,6 +153,8 @@ struct cperf_options {
 	uint8_t imix_distribution_count;
 };
 
+void cperf_usage(const char *progname);
+
 void
 cperf_options_default(struct cperf_options *options);
 
diff --git a/app/test-crypto-perf/cperf_options_parsing.c b/app/test-crypto-perf/cperf_options_parsing.c
index 40b6dfb648..3777bc7509 100644
--- a/app/test-crypto-perf/cperf_options_parsing.c
+++ b/app/test-crypto-perf/cperf_options_parsing.c
@@ -19,8 +19,8 @@ struct name_id_map {
 	uint32_t id;
 };
 
-static void
-usage(char *progname)
+void
+cperf_usage(const char *progname)
 {
 	printf("%s [EAL options] --\n"
 		" --silent: disable options dump\n"
@@ -982,7 +982,7 @@ cperf_options_parse(struct cperf_options *options, int argc, char **argv)
 	while ((opt = getopt_long(argc, argv, "h", lgopts, &opt_idx)) != EOF) {
 		switch (opt) {
 		case 'h':
-			usage(argv[0]);
+			cperf_usage(argv[0]);
 			exit(EXIT_SUCCESS);
 			break;
 		/* long options */
@@ -994,7 +994,7 @@ cperf_options_parse(struct cperf_options *options, int argc, char **argv)
 			break;
 
 		default:
-			usage(argv[0]);
+			cperf_usage(argv[0]);
 			return -EINVAL;
 		}
 	}
diff --git a/app/test-crypto-perf/main.c b/app/test-crypto-perf/main.c
index 49af812d8b..497c4c5226 100644
--- a/app/test-crypto-perf/main.c
+++ b/app/test-crypto-perf/main.c
@@ -519,7 +519,8 @@ main(int argc, char **argv)
 	int ret;
 	uint32_t lcore_id;
 
-	/* Initialise DPDK EAL */
+	rte_set_application_usage_hook(cperf_usage);
+
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
 		rte_exit(EXIT_FAILURE, "Invalid EAL arguments!\n");
diff --git a/app/test-fib/main.c b/app/test-fib/main.c
index b0a97b0d7e..420fe17c39 100644
--- a/app/test-fib/main.c
+++ b/app/test-fib/main.c
@@ -648,6 +648,12 @@ print_usage(void)
 		config.prgname);
 }
 
+static void
+usage_hook(const char *prgname __rte_unused)
+{
+	print_usage();
+}
+
 static int
 check_config(void)
 {
@@ -1209,6 +1215,8 @@ main(int argc, char **argv)
 	FILE *fl = NULL;
 	uint8_t depth_lim;
 
+	rte_set_application_usage_hook(usage_hook);
+
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
 		rte_panic("Cannot init EAL\n");
diff --git a/app/test-flow-perf/main.c b/app/test-flow-perf/main.c
index 0aef767350..949a5e3e11 100644
--- a/app/test-flow-perf/main.c
+++ b/app/test-flow-perf/main.c
@@ -115,7 +115,7 @@ static struct multi_cores_pool mc_pool = {
 };
 
 static void
-usage(char *progname)
+usage(const char *progname)
 {
 	printf("\nusage: %s\n", progname);
 	printf("\nControl configurations:\n");
@@ -1849,6 +1849,8 @@ main(int argc, char **argv)
 	uint16_t port;
 	struct rte_flow_error error;
 
+	rte_set_application_usage_hook(usage);
+
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
 		rte_exit(EXIT_FAILURE, "EAL init failed\n");
diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c
index 55ecea6338..7f41021d4d 100644
--- a/app/test-pmd/parameters.c
+++ b/app/test-pmd/parameters.c
@@ -46,8 +46,8 @@
 
 #include "testpmd.h"
 
-static void
-usage(char* progname)
+void
+usage(const char *progname)
 {
 	printf("usage: %s [EAL options] -- "
 #ifdef RTE_LIB_CMDLINE
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 1a57324b1b..1a60830037 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -3771,6 +3771,8 @@ main(int argc, char** argv)
 		rte_exit(EXIT_FAILURE, "Cannot register log type");
 	rte_log_set_level(testpmd_logtype, RTE_LOG_DEBUG);
 
+	rte_set_application_usage_hook(usage);
+
 	diag = rte_eal_init(argc, argv);
 	if (diag < 0)
 		rte_exit(EXIT_FAILURE, "Cannot init EAL: %s\n",
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index ce83f31f0d..37348246f8 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -763,6 +763,7 @@ inc_tx_burst_stats(struct fwd_stream *fs, uint16_t nb_tx)
 unsigned int parse_item_list(char* str, const char* item_name,
 			unsigned int max_items,
 			unsigned int *parsed_items, int check_unique_values);
+void usage(const char *progname);
 void launch_args_parse(int argc, char** argv);
 void cmdline_read_from_file(const char *filename);
 void prompt(void);
diff --git a/app/test-regex/main.c b/app/test-regex/main.c
index 7bb87bb1b8..ba09b20126 100644
--- a/app/test-regex/main.c
+++ b/app/test-regex/main.c
@@ -616,7 +616,8 @@ main(int argc, char **argv)
 	uint32_t i;
 	struct qps_per_lcore *qps_per_lcore;
 
-	/* Init EAL. */
+	rte_set_application_usage_hook(usage);
+
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
 		rte_exit(EXIT_FAILURE, "EAL init failed\n");
diff --git a/app/test-sad/main.c b/app/test-sad/main.c
index 1024757add..14a8263f8c 100644
--- a/app/test-sad/main.c
+++ b/app/test-sad/main.c
@@ -149,7 +149,12 @@ print_usage(void)
 		"[-p <parallel lookup on all available cores>]\n"
 		"[-c <init sad supporting read/write concurrency>]\n",
 		config.prgname);
+}
 
+static void
+usage_hook(const char *prgname __rte_unused)
+{
+	print_usage();
 }
 
 static int
@@ -620,6 +625,8 @@ main(int argc, char **argv)
 	struct rte_ipsec_sad_conf conf = {0};
 	unsigned int lcore_id;
 
+	rte_set_application_usage_hook(usage_hook);
+
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
 		rte_panic("Cannot init EAL\n");
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v2 10/11] app/regex: fix usage text
  2021-03-10 13:28 ` [dpdk-dev] [PATCH v2 " Thomas Monjalon
                     ` (8 preceding siblings ...)
  2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 09/11] app: hook in EAL usage help Thomas Monjalon
@ 2021-03-10 13:28   ` Thomas Monjalon
  2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 11/11] app/testpmd: " Thomas Monjalon
  10 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-10 13:28 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, Ori Kam

The usage syntax help includes the program name which was fake.
It is replaced with the real name from argv.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Ori Kam <orika@nvidia.com>
---
 app/test-regex/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/app/test-regex/main.c b/app/test-regex/main.c
index ba09b20126..73ba227fba 100644
--- a/app/test-regex/main.c
+++ b/app/test-regex/main.c
@@ -151,10 +151,10 @@ args_parse(int argc, char **argv, char *rules_file, char *data_file,
 			*nb_lcores = atoi(optarg);
 			break;
 		case ARG_HELP:
-			usage("RegEx test app");
+			usage(argv[0]);
 			break;
 		default:
-			usage("RegEx test app");
+			usage(argv[0]);
 			rte_exit(EXIT_FAILURE, "Invalid option: %s\n", argv[optind]);
 			break;
 		}
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v2 11/11] app/testpmd: fix usage text
  2021-03-10 13:28 ` [dpdk-dev] [PATCH v2 " Thomas Monjalon
                     ` (9 preceding siblings ...)
  2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 10/11] app/regex: fix usage text Thomas Monjalon
@ 2021-03-10 13:28   ` Thomas Monjalon
  10 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-10 13:28 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, Xiaoyun Li

The options help text was including an incomplete and redundant
summary of the options before explaining each. The summary is dropped.

The details of the option --hairpin-mode had an extra space,
breaking the alignment with the next line.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 app/test-pmd/parameters.c | 26 ++------------------------
 1 file changed, 2 insertions(+), 24 deletions(-)

diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c
index 7f41021d4d..efcbf1e845 100644
--- a/app/test-pmd/parameters.c
+++ b/app/test-pmd/parameters.c
@@ -49,29 +49,7 @@
 void
 usage(const char *progname)
 {
-	printf("usage: %s [EAL options] -- "
-#ifdef RTE_LIB_CMDLINE
-	       "[--interactive|-i] "
-	       "[--cmdline-file=FILENAME] "
-#endif
-	       "[--help|-h] | [--auto-start|-a] | ["
-	       "--tx-first | --stats-period=PERIOD | "
-	       "--coremask=COREMASK --portmask=PORTMASK --numa "
-	       "--portlist=PORTLIST "
-	       "--mbuf-size= | --total-num-mbufs= | "
-	       "--nb-cores= | --nb-ports= | "
-#ifdef RTE_LIB_CMDLINE
-	       "--eth-peers-configfile= | "
-	       "--eth-peer=X,M:M:M:M:M:M | "
-	       "--tx-ip=SRC,DST | --tx-udp=PORT | "
-#endif
-	       "--pkt-filter-mode= |"
-	       "--rss-ip | --rss-udp | --rss-level-inner | --rss-level-outer |"
-	       "--rxpt= | --rxht= | --rxwt= |"
-	       " --rxfreet= | --txpt= | --txht= | --txwt= | --txfreet= | "
-	       "--txrst= | --tx-offloads= | | --rx-offloads= | "
-	       "--vxlan-gpe-port= | --geneve-parsed-port= | "
-	       "--record-core-cycles | --record-burst-stats]\n",
+	printf("\nUsage: %s [EAL options] -- [testpmd options]\n\n",
 	       progname);
 #ifdef RTE_LIB_CMDLINE
 	printf("  --interactive: run in interactive mode.\n");
@@ -221,7 +199,7 @@ usage(const char *progname)
 	       "enabled\n");
 	printf("  --record-core-cycles: enable measurement of CPU cycles.\n");
 	printf("  --record-burst-stats: enable display of RX and TX bursts.\n");
-	printf("  --hairpin-mode=0xXX: bitmask set the hairpin port mode.\n "
+	printf("  --hairpin-mode=0xXX: bitmask set the hairpin port mode.\n"
 	       "    0x10 - explicit Tx rule, 0x02 - hairpin ports paired\n"
 	       "    0x01 - hairpin ports loop, 0x00 - hairpin port self\n");
 }
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH 06/11] eal: catch invalid log level number
  2021-03-10 13:26       ` Bruce Richardson
@ 2021-03-10 13:35         ` Thomas Monjalon
  2021-03-10 16:35           ` Morten Brørup
  2021-03-10 16:52           ` Bruce Richardson
  0 siblings, 2 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-10 13:35 UTC (permalink / raw)
  To: Bruce Richardson; +Cc: dev, david.marchand

10/03/2021 14:26, Bruce Richardson:
> On Wed, Mar 10, 2021 at 01:33:20PM +0100, Thomas Monjalon wrote:
> > 10/03/2021 13:19, Bruce Richardson:
> > > On Wed, Mar 10, 2021 at 12:31:10AM +0100, Thomas Monjalon wrote:
> > > > The parsing check for invalid log level was not trying to catch
> > > > irrelevant numeric values.
> > > > A log level 0 or too high is now a failure in options parsing
> > > > so it can be caught early.
> > > > 
> > > > Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> > > 
> > > One thing I'd note here is that our log range of 1 to 8 is a little
> > > strange, and that it would be nice if we could accept 9 as a valid log
> > > level too on the cmdline. Ideally 0 would also be acceptable, for all
> > > logging off, but it's more likely that people want to up the log level than
> > > reduce it, and 9 is a more expected max value than 8.
> > 
> > Why 9 is more expected?
> > 
> 
> Because a scale of 0-9 is more logical in the decimal system.
> We could also generalize that any number >8 is just reduced to 8 and
> we issue a warning and continue.

In this case, we should accept any high value, not limiting arbitrary
to 9, and emit a warning.



^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH 06/11] eal: catch invalid log level number
  2021-03-10 12:19   ` Bruce Richardson
  2021-03-10 12:33     ` Thomas Monjalon
@ 2021-03-10 15:16     ` Stephen Hemminger
  1 sibling, 0 replies; 121+ messages in thread
From: Stephen Hemminger @ 2021-03-10 15:16 UTC (permalink / raw)
  To: Bruce Richardson; +Cc: Thomas Monjalon, dev, david.marchand

On Wed, 10 Mar 2021 12:19:24 +0000
Bruce Richardson <bruce.richardson@intel.com> wrote:

> On Wed, Mar 10, 2021 at 12:31:10AM +0100, Thomas Monjalon wrote:
> > The parsing check for invalid log level was not trying to catch
> > irrelevant numeric values.
> > A log level 0 or too high is now a failure in options parsing
> > so it can be caught early.
> > 
> > Signed-off-by: Thomas Monjalon <thomas@monjalon.net>  
> 
> One thing I'd note here is that our log range of 1 to 8 is a little
> strange, and that it would be nice if we could accept 9 as a valid log
> level too on the cmdline. Ideally 0 would also be acceptable, for all
> logging off, but it's more likely that people want to up the log level than
> reduce it, and 9 is a more expected max value than 8.

It all goes back to syslog values.



^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH 06/11] eal: catch invalid log level number
  2021-03-10 13:35         ` Thomas Monjalon
@ 2021-03-10 16:35           ` Morten Brørup
  2021-03-10 16:52           ` Bruce Richardson
  1 sibling, 0 replies; 121+ messages in thread
From: Morten Brørup @ 2021-03-10 16:35 UTC (permalink / raw)
  To: Thomas Monjalon, Bruce Richardson; +Cc: dev, david.marchand

> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Thomas Monjalon
> Sent: Wednesday, March 10, 2021 2:36 PM
> 
> 10/03/2021 14:26, Bruce Richardson:
> > On Wed, Mar 10, 2021 at 01:33:20PM +0100, Thomas Monjalon wrote:
> > > 10/03/2021 13:19, Bruce Richardson:
> > > > On Wed, Mar 10, 2021 at 12:31:10AM +0100, Thomas Monjalon wrote:
> > > > > The parsing check for invalid log level was not trying to catch
> > > > > irrelevant numeric values.
> > > > > A log level 0 or too high is now a failure in options parsing
> > > > > so it can be caught early.
> > > > >
> > > > > Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> > > >
> > > > One thing I'd note here is that our log range of 1 to 8 is a little
> > > > strange, and that it would be nice if we could accept 9 as a valid
> log
> > > > level too on the cmdline. Ideally 0 would also be acceptable, for all
> > > > logging off, but it's more likely that people want to up the log
> level than
> > > > reduce it, and 9 is a more expected max value than 8.
> > >
> > > Why 9 is more expected?
> > >
> >
> > Because a scale of 0-9 is more logical in the decimal system.
> > We could also generalize that any number >8 is just reduced to 8 and
> > we issue a warning and continue.
> 
> In this case, we should accept any high value, not limiting arbitrary
> to 9, and emit a warning.
> 

I don't care which levels are acceptable. For reference, SYSLOG levels go from 0 to 7 (both inclusive).

-Morten

^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH 06/11] eal: catch invalid log level number
  2021-03-10 13:35         ` Thomas Monjalon
  2021-03-10 16:35           ` Morten Brørup
@ 2021-03-10 16:52           ` Bruce Richardson
  1 sibling, 0 replies; 121+ messages in thread
From: Bruce Richardson @ 2021-03-10 16:52 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev, david.marchand

On Wed, Mar 10, 2021 at 02:35:47PM +0100, Thomas Monjalon wrote:
> 10/03/2021 14:26, Bruce Richardson:
> > On Wed, Mar 10, 2021 at 01:33:20PM +0100, Thomas Monjalon wrote:
> > > 10/03/2021 13:19, Bruce Richardson:
> > > > On Wed, Mar 10, 2021 at 12:31:10AM +0100, Thomas Monjalon wrote:
> > > > > The parsing check for invalid log level was not trying to catch
> > > > > irrelevant numeric values.
> > > > > A log level 0 or too high is now a failure in options parsing
> > > > > so it can be caught early.
> > > > > 
> > > > > Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> > > > 
> > > > One thing I'd note here is that our log range of 1 to 8 is a little
> > > > strange, and that it would be nice if we could accept 9 as a valid log
> > > > level too on the cmdline. Ideally 0 would also be acceptable, for all
> > > > logging off, but it's more likely that people want to up the log level than
> > > > reduce it, and 9 is a more expected max value than 8.
> > > 
> > > Why 9 is more expected?
> > > 
> > 
> > Because a scale of 0-9 is more logical in the decimal system.
> > We could also generalize that any number >8 is just reduced to 8 and
> > we issue a warning and continue.
> 
> In this case, we should accept any high value, not limiting arbitrary
> to 9, and emit a warning.
> 
+1

^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v3 00/11] improve options help
  2021-03-09 23:31 [dpdk-dev] [PATCH 00/11] improve options help Thomas Monjalon
                   ` (12 preceding siblings ...)
  2021-03-10 13:28 ` [dpdk-dev] [PATCH v2 " Thomas Monjalon
@ 2021-03-12 18:17 ` Thomas Monjalon
  2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 01/11] eal: explain argv behaviour during init Thomas Monjalon
                     ` (11 more replies)
  2021-03-21 22:31 ` [dpdk-dev] [PATCH v4 " Thomas Monjalon
                   ` (3 subsequent siblings)
  17 siblings, 12 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-12 18:17 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, bruce.richardson, mb

The main intent of this series is to provide a nice help
for the --log-level option.
More patches are added to improve options help in general.


v3:
    - fix use of RTE_LOG_MAX
    - accept (with warning) log level higher than RTE_LOG_MAX
v2:
    - fix use of the new macro RTE_LOG_MAX in level parsing
    - improve parameters type and name while moving functions


Thomas Monjalon (11):
  eal: explain argv behaviour during init
  eal: improve options usage text
  eal: use macros for help option
  eal: move private log functions
  eal: introduce maximum log level macro
  eal: catch invalid log level number
  eal: add log level help
  app: fix exit messages
  app: hook in EAL usage help
  app/regex: fix usage text
  app/testpmd: fix usage text

 app/pdump/main.c                              |  2 +
 app/proc-info/main.c                          |  2 +
 app/test-acl/main.c                           |  2 +
 app/test-bbdev/main.c                         |  3 +-
 app/test-compress-perf/comp_perf_options.h    |  2 +
 .../comp_perf_options_parse.c                 | 10 +--
 app/test-compress-perf/main.c                 |  3 +-
 app/test-crypto-perf/cperf_options.h          |  2 +
 app/test-crypto-perf/cperf_options_parsing.c  | 10 +--
 app/test-crypto-perf/main.c                   |  3 +-
 app/test-fib/main.c                           |  8 ++
 app/test-flow-perf/main.c                     | 63 ++++++++--------
 app/test-pmd/parameters.c                     | 34 ++-------
 app/test-pmd/testpmd.c                        |  2 +
 app/test-pmd/testpmd.h                        |  1 +
 app/test-regex/main.c                         | 10 +--
 app/test-sad/main.c                           |  7 ++
 lib/librte_eal/common/eal_common_log.c        | 50 ++++++++-----
 lib/librte_eal/common/eal_common_options.c    | 73 ++++++++++++-------
 lib/librte_eal/common/eal_log.h               | 32 ++++++++
 lib/librte_eal/common/eal_private.h           | 29 --------
 lib/librte_eal/freebsd/eal.c                  | 10 +--
 lib/librte_eal/include/rte_eal.h              |  2 +
 lib/librte_eal/include/rte_log.h              | 12 +++
 lib/librte_eal/linux/eal.c                    | 17 +++--
 lib/librte_eal/linux/eal_log.c                |  4 +-
 lib/librte_eal/version.map                    |  3 +
 lib/librte_eal/windows/eal.c                  | 15 ++--
 lib/librte_eal/windows/eal_log.c              |  6 +-
 29 files changed, 243 insertions(+), 174 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_log.h

-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v3 01/11] eal: explain argv behaviour during init
  2021-03-12 18:17 ` [dpdk-dev] [PATCH v3 00/11] improve options help Thomas Monjalon
@ 2021-03-12 18:17   ` Thomas Monjalon
  2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 02/11] eal: improve options usage text Thomas Monjalon
                     ` (10 subsequent siblings)
  11 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-12 18:17 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, bruce.richardson, mb

After argument parsing done by rte_eal_init(),
the remaining arguments are to be parsed by the application
by progressing in the argv array.
In this context, the first string represented by argv[0] is still
the same program name as the original argv[0],
while the next strings are the application arguments.
This is because rte_eal_init() manipulates the argv array
after EAL parsing, before returning to the application.

This note was missing in the doxygen comment of the API.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 lib/librte_eal/include/rte_eal.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/librte_eal/include/rte_eal.h b/lib/librte_eal/include/rte_eal.h
index eaf6469e50..0cbeedb594 100644
--- a/lib/librte_eal/include/rte_eal.h
+++ b/lib/librte_eal/include/rte_eal.h
@@ -76,6 +76,8 @@ int rte_eal_iopl_init(void);
  * @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.
+ *   The program name pointer argv[0] is copied into the last parsed argv
+ *   so that argv[0] is still the same after deducing the parsed arguments.
  * @return
  *   - On success, the number of parsed arguments, which is greater or
  *     equal to zero. After the call to rte_eal_init(),
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v3 02/11] eal: improve options usage text
  2021-03-12 18:17 ` [dpdk-dev] [PATCH v3 00/11] improve options help Thomas Monjalon
  2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 01/11] eal: explain argv behaviour during init Thomas Monjalon
@ 2021-03-12 18:17   ` Thomas Monjalon
  2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 03/11] eal: use macros for help option Thomas Monjalon
                     ` (9 subsequent siblings)
  11 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-12 18:17 UTC (permalink / raw)
  To: dev
  Cc: david.marchand, bruce.richardson, mb, Dmitry Kozlyuk,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam

The description of the EAL options was printed before the application
description provided via the hook.
It is better to let the application print the global syntax
and describes the detail of the EAL options below.

Also, some useless lines are removed,
and the alignment of few options is fixed.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 lib/librte_eal/common/eal_common_options.c | 11 +++++------
 lib/librte_eal/freebsd/eal.c               |  8 ++++----
 lib/librte_eal/linux/eal.c                 | 12 ++++++------
 lib/librte_eal/windows/eal.c               | 10 ++++------
 4 files changed, 19 insertions(+), 22 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 622c7bc429..0635b0d4ce 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -2022,8 +2022,7 @@ rte_vect_set_max_simd_bitwidth(uint16_t bitwidth)
 void
 eal_common_usage(void)
 {
-	printf("[options]\n\n"
-	       "EAL common options:\n"
+	printf("EAL common options:\n"
 	       "  -c COREMASK         Hexadecimal bitmask of cores to run on\n"
 	       "  -l CORELIST         List of cores to run on\n"
 	       "                      The argument format is <c1>[-c2][,c3[-c4],...]\n"
@@ -2053,7 +2052,7 @@ eal_common_usage(void)
 	       "  --"OPT_VDEV"              Add a virtual device.\n"
 	       "                      The argument format is <driver><id>[,key=val,...]\n"
 	       "                      (ex: --vdev=net_pcap0,iface=eth2).\n"
-	       "  --"OPT_IOVA_MODE"   Set IOVA mode. 'pa' for IOVA_PA\n"
+	       "  --"OPT_IOVA_MODE"         Set IOVA mode. 'pa' for IOVA_PA\n"
 	       "                      'va' for IOVA_VA\n"
 	       "  -d LIB.so|DIR       Add a driver or driver directory\n"
 	       "                      (can be used multiple times)\n"
@@ -2092,11 +2091,11 @@ eal_common_usage(void)
 #endif /* !RTE_EXEC_ENV_WINDOWS */
 	       "  -v                  Display version information on startup\n"
 	       "  -h, --help          This help\n"
-	       "  --"OPT_IN_MEMORY"   Operate entirely in memory. This will\n"
+	       "  --"OPT_IN_MEMORY"         Operate entirely in memory. This will\n"
 	       "                      disable secondary process support\n"
 	       "  --"OPT_BASE_VIRTADDR"     Base virtual address\n"
-	       "  --"OPT_TELEMETRY"   Enable telemetry support (on by default)\n"
-	       "  --"OPT_NO_TELEMETRY"   Disable telemetry support\n"
+	       "  --"OPT_TELEMETRY"         Enable telemetry support (on by default)\n"
+	       "  --"OPT_NO_TELEMETRY"      Disable telemetry support\n"
 	       "  --"OPT_FORCE_MAX_SIMD_BITWIDTH" Force the max SIMD bitwidth\n"
 	       "\nEAL options for DEBUG use only:\n"
 	       "  --"OPT_HUGE_UNLINK"       Unlink hugepage files after init\n"
diff --git a/lib/librte_eal/freebsd/eal.c b/lib/librte_eal/freebsd/eal.c
index afbbb1c523..f466616566 100644
--- a/lib/librte_eal/freebsd/eal.c
+++ b/lib/librte_eal/freebsd/eal.c
@@ -421,13 +421,13 @@ eal_usage(const char *prgname)
 {
 	rte_usage_hook_t hook = eal_get_application_usage_hook();
 
-	printf("\nUsage: %s ", prgname);
-	eal_common_usage();
-	/* Allow the application to print its usage message too if hook is set */
 	if (hook) {
-		printf("===== Application Usage =====\n\n");
+		/* Print application usage through EAL options parsing. */
 		(hook)(prgname);
+		printf("\n");
 	}
+
+	eal_common_usage();
 }
 
 static inline size_t
diff --git a/lib/librte_eal/linux/eal.c b/lib/librte_eal/linux/eal.c
index bc966150a5..7c1d296192 100644
--- a/lib/librte_eal/linux/eal.c
+++ b/lib/librte_eal/linux/eal.c
@@ -534,7 +534,12 @@ eal_usage(const char *prgname)
 {
 	rte_usage_hook_t hook = eal_get_application_usage_hook();
 
-	printf("\nUsage: %s ", prgname);
+	if (hook) {
+		/* Print application usage through EAL options parsing. */
+		(hook)(prgname);
+		printf("\n");
+	}
+
 	eal_common_usage();
 	printf("EAL Linux options:\n"
 	       "  --"OPT_SOCKET_MEM"        Memory to allocate on sockets (comma separated values)\n"
@@ -548,11 +553,6 @@ eal_usage(const char *prgname)
 	       "  --"OPT_SINGLE_FILE_SEGMENTS" Put all hugepage memory in single files\n"
 	       "  --"OPT_MATCH_ALLOCATIONS" Free hugepages exactly as allocated\n"
 	       "\n");
-	/* Allow the application to print its usage message too if hook is set */
-	if (hook) {
-		printf("===== Application Usage =====\n\n");
-		(hook)(prgname);
-	}
 }
 
 static int
diff --git a/lib/librte_eal/windows/eal.c b/lib/librte_eal/windows/eal.c
index 2fc3d6141c..ec13ac1a9f 100644
--- a/lib/librte_eal/windows/eal.c
+++ b/lib/librte_eal/windows/eal.c
@@ -79,15 +79,13 @@ eal_usage(const char *prgname)
 {
 	rte_usage_hook_t hook = eal_get_application_usage_hook();
 
-	printf("\nUsage: %s ", prgname);
-	eal_common_usage();
-	/* Allow the application to print its usage message too
-	 * if hook is set
-	 */
 	if (hook) {
-		printf("===== Application Usage =====\n\n");
+		/* Print application usage through EAL options parsing. */
 		(hook)(prgname);
+		printf("\n");
 	}
+
+	eal_common_usage();
 }
 
 /* Parse the arguments for --log-level only */
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v3 03/11] eal: use macros for help option
  2021-03-12 18:17 ` [dpdk-dev] [PATCH v3 00/11] improve options help Thomas Monjalon
  2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 01/11] eal: explain argv behaviour during init Thomas Monjalon
  2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 02/11] eal: improve options usage text Thomas Monjalon
@ 2021-03-12 18:17   ` Thomas Monjalon
  2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 04/11] eal: move private log functions Thomas Monjalon
                     ` (8 subsequent siblings)
  11 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-12 18:17 UTC (permalink / raw)
  To: dev
  Cc: david.marchand, bruce.richardson, mb, Dmitry Kozlyuk,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam

The macros OPT_HELP and OPT_HELP_NUM were not used where appropriate.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 lib/librte_eal/common/eal_common_options.c | 2 +-
 lib/librte_eal/freebsd/eal.c               | 2 +-
 lib/librte_eal/linux/eal.c                 | 2 +-
 lib/librte_eal/windows/eal.c               | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 0635b0d4ce..52fedb81e5 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -2090,7 +2090,7 @@ eal_common_usage(void)
 	       "                      must be specified once only.\n"
 #endif /* !RTE_EXEC_ENV_WINDOWS */
 	       "  -v                  Display version information on startup\n"
-	       "  -h, --help          This help\n"
+	       "  -h, --"OPT_HELP"          This help\n"
 	       "  --"OPT_IN_MEMORY"         Operate entirely in memory. This will\n"
 	       "                      disable secondary process support\n"
 	       "  --"OPT_BASE_VIRTADDR"     Base virtual address\n"
diff --git a/lib/librte_eal/freebsd/eal.c b/lib/librte_eal/freebsd/eal.c
index f466616566..66adfca2d1 100644
--- a/lib/librte_eal/freebsd/eal.c
+++ b/lib/librte_eal/freebsd/eal.c
@@ -549,7 +549,7 @@ eal_parse_args(int argc, char **argv)
 			}
 			break;
 		}
-		case 'h':
+		case OPT_HELP_NUM:
 			eal_usage(prgname);
 			exit(EXIT_SUCCESS);
 		default:
diff --git a/lib/librte_eal/linux/eal.c b/lib/librte_eal/linux/eal.c
index 7c1d296192..6f73616f86 100644
--- a/lib/librte_eal/linux/eal.c
+++ b/lib/librte_eal/linux/eal.c
@@ -716,7 +716,7 @@ eal_parse_args(int argc, char **argv)
 			continue;
 
 		switch (opt) {
-		case 'h':
+		case OPT_HELP_NUM:
 			eal_usage(prgname);
 			exit(EXIT_SUCCESS);
 
diff --git a/lib/librte_eal/windows/eal.c b/lib/librte_eal/windows/eal.c
index ec13ac1a9f..4dd2fc1403 100644
--- a/lib/librte_eal/windows/eal.c
+++ b/lib/librte_eal/windows/eal.c
@@ -158,7 +158,7 @@ eal_parse_args(int argc, char **argv)
 			continue;
 
 		switch (opt) {
-		case 'h':
+		case OPT_HELP_NUM:
 			eal_usage(prgname);
 			exit(EXIT_SUCCESS);
 		default:
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v3 04/11] eal: move private log functions
  2021-03-12 18:17 ` [dpdk-dev] [PATCH v3 00/11] improve options help Thomas Monjalon
                     ` (2 preceding siblings ...)
  2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 03/11] eal: use macros for help option Thomas Monjalon
@ 2021-03-12 18:17   ` Thomas Monjalon
  2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 05/11] eal: introduce maximum log level macro Thomas Monjalon
                     ` (7 subsequent siblings)
  11 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-12 18:17 UTC (permalink / raw)
  To: dev
  Cc: david.marchand, bruce.richardson, mb, Dmitry Kozlyuk,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam

Some private log functions had a wrong "rte_" prefix.

All private log functions are moved from eal_private.h
to the new file eal_log.h:
	rte_eal_log_init -> eal_log_init
	rte_log_save_regexp -> eal_log_save_regexp
	rte_log_save_pattern -> eal_log_save_pattern
	eal_log_set_default

The static functions in the file eal_common_log.c are renamed:
	rte_log_save_level -> log_save_level
	rte_log_init -> log_init

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 lib/librte_eal/common/eal_common_log.c     | 18 ++++++++------
 lib/librte_eal/common/eal_common_options.c |  5 ++--
 lib/librte_eal/common/eal_log.h            | 27 ++++++++++++++++++++
 lib/librte_eal/common/eal_private.h        | 29 ----------------------
 lib/librte_eal/linux/eal.c                 |  3 ++-
 lib/librte_eal/linux/eal_log.c             |  4 +--
 lib/librte_eal/windows/eal.c               |  3 ++-
 lib/librte_eal/windows/eal_log.c           |  6 +++--
 8 files changed, 50 insertions(+), 45 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_log.h

diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c
index c5554badb2..aee7c44c6a 100644
--- a/lib/librte_eal/common/eal_common_log.c
+++ b/lib/librte_eal/common/eal_common_log.c
@@ -15,7 +15,7 @@
 #include <rte_log.h>
 #include <rte_per_lcore.h>
 
-#include "eal_private.h"
+#include "eal_log.h"
 
 struct rte_log_dynamic_type {
 	const char *name;
@@ -178,8 +178,8 @@ rte_log_set_level_regexp(const char *regex, uint32_t level)
  * Save the type string and the loglevel for later dynamic
  * logtypes which may register later.
  */
-static int rte_log_save_level(int priority,
-			      const char *regex, const char *pattern)
+static int
+log_save_level(uint32_t priority, const char *regex, const char *pattern)
 {
 	struct rte_eal_opt_loglevel *opt_ll = NULL;
 
@@ -207,9 +207,10 @@ static int rte_log_save_level(int priority,
 	return -1;
 }
 
-int rte_log_save_regexp(const char *regex, int tmp)
+int
+eal_log_save_regexp(const char *regex, uint32_t level)
 {
-	return rte_log_save_level(tmp, regex, NULL);
+	return log_save_level(level, regex, NULL);
 }
 
 /* set log level based on globbing pattern */
@@ -232,9 +233,10 @@ rte_log_set_level_pattern(const char *pattern, uint32_t level)
 	return 0;
 }
 
-int rte_log_save_pattern(const char *pattern, int priority)
+int
+eal_log_save_pattern(const char *pattern, uint32_t level)
 {
-	return rte_log_save_level(priority, NULL, pattern);
+	return log_save_level(level, NULL, pattern);
 }
 
 /* get the current loglevel for the message being processed */
@@ -376,7 +378,7 @@ static const struct logtype logtype_strings[] = {
 };
 
 /* Logging should be first initializer (before drivers and bus) */
-RTE_INIT_PRIO(rte_log_init, LOG)
+RTE_INIT_PRIO(log_init, LOG)
 {
 	uint32_t i;
 
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 52fedb81e5..02374ee09e 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -41,6 +41,7 @@
 #include "eal_options.h"
 #include "eal_filesystem.h"
 #include "eal_private.h"
+#include "eal_log.h"
 #ifndef RTE_EXEC_ENV_WINDOWS
 #include "eal_trace.h"
 #endif
@@ -1299,7 +1300,7 @@ eal_parse_log_level(const char *arg)
 				regex, priority);
 			goto fail;
 		}
-		if (rte_log_save_regexp(regex, priority) < 0)
+		if (eal_log_save_regexp(regex, priority) < 0)
 			goto fail;
 	} else if (pattern) {
 		if (rte_log_set_level_pattern(pattern, priority) < 0) {
@@ -1307,7 +1308,7 @@ eal_parse_log_level(const char *arg)
 				pattern, priority);
 			goto fail;
 		}
-		if (rte_log_save_pattern(pattern, priority) < 0)
+		if (eal_log_save_pattern(pattern, priority) < 0)
 			goto fail;
 	} else {
 		rte_log_set_global_level(priority);
diff --git a/lib/librte_eal/common/eal_log.h b/lib/librte_eal/common/eal_log.h
new file mode 100644
index 0000000000..684650a17b
--- /dev/null
+++ b/lib/librte_eal/common/eal_log.h
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2021 Mellanox Technologies, Ltd
+ */
+
+#ifndef EAL_LOG_H
+#define EAL_LOG_H
+
+#include <stdio.h>
+#include <stdint.h>
+
+/*
+ * Initialize the default log stream.
+ */
+int eal_log_init(const char *id, int facility);
+
+/*
+ * Determine where log data is written when no call to rte_openlog_stream.
+ */
+void eal_log_set_default(FILE *default_log);
+
+/*
+ * Save a log option for later.
+ */
+int eal_log_save_regexp(const char *regexp, uint32_t level);
+int eal_log_save_pattern(const char *pattern, uint32_t level);
+
+#endif /* EAL_LOG_H */
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index b8a0d20021..e3512111d9 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -79,19 +79,6 @@ struct rte_config *rte_eal_get_configuration(void);
  */
 int rte_eal_memzone_init(void);
 
-/**
- * Common log initialization function (private to eal).  Determines
- * where log data is written when no call to rte_openlog_stream is
- * in effect.
- *
- * @param default_log
- *   The default log stream to be used.
- * @return
- *   - 0 on success
- *   - Negative on error
- */
-void eal_log_set_default(FILE *default_log);
-
 /**
  * Fill configuration with number of physical and logical processors
  *
@@ -143,22 +130,6 @@ int rte_eal_memory_init(void);
  */
 int rte_eal_timer_init(void);
 
-/**
- * Init the default log stream
- *
- * This function is private to EAL.
- *
- * @return
- *   0 on success, negative on error
- */
-int rte_eal_log_init(const char *id, int facility);
-
-/**
- * Save the log regexp for later
- */
-int rte_log_save_regexp(const char *type, int priority);
-int rte_log_save_pattern(const char *pattern, int priority);
-
 /**
  * Init tail queues for non-EAL library structures. This is to allow
  * the rings, mempools, etc. lists to be shared among multiple processes
diff --git a/lib/librte_eal/linux/eal.c b/lib/librte_eal/linux/eal.c
index 6f73616f86..e4feeb2b0e 100644
--- a/lib/librte_eal/linux/eal.c
+++ b/lib/librte_eal/linux/eal.c
@@ -58,6 +58,7 @@
 #include "eal_hugepages.h"
 #include "eal_memcfg.h"
 #include "eal_trace.h"
+#include "eal_log.h"
 #include "eal_options.h"
 #include "eal_vfio.h"
 #include "hotplug_mp.h"
@@ -1160,7 +1161,7 @@ rte_eal_init(int argc, char **argv)
 #endif
 	}
 
-	if (rte_eal_log_init(logid, internal_conf->syslog_facility) < 0) {
+	if (eal_log_init(logid, internal_conf->syslog_facility) < 0) {
 		rte_eal_init_alert("Cannot init logging.");
 		rte_errno = ENOMEM;
 		__atomic_store_n(&run_once, 0, __ATOMIC_RELAXED);
diff --git a/lib/librte_eal/linux/eal_log.c b/lib/librte_eal/linux/eal_log.c
index 43c8460bfb..1a08139eb5 100644
--- a/lib/librte_eal/linux/eal_log.c
+++ b/lib/librte_eal/linux/eal_log.c
@@ -17,7 +17,7 @@
 #include <rte_spinlock.h>
 #include <rte_log.h>
 
-#include "eal_private.h"
+#include "eal_log.h"
 
 /*
  * default log function
@@ -46,7 +46,7 @@ static cookie_io_functions_t console_log_func = {
  * once memzones are available.
  */
 int
-rte_eal_log_init(const char *id, int facility)
+eal_log_init(const char *id, int facility)
 {
 	FILE *log_stream;
 
diff --git a/lib/librte_eal/windows/eal.c b/lib/librte_eal/windows/eal.c
index 4dd2fc1403..5bca3ace1c 100644
--- a/lib/librte_eal/windows/eal.c
+++ b/lib/librte_eal/windows/eal.c
@@ -22,6 +22,7 @@
 
 #include "eal_hugepages.h"
 #include "eal_trace.h"
+#include "eal_log.h"
 #include "eal_windows.h"
 
 #define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL)
@@ -265,7 +266,7 @@ rte_eal_init(int argc, char **argv)
 		eal_get_internal_configuration();
 	int ret;
 
-	rte_eal_log_init(NULL, 0);
+	eal_log_init(NULL, 0);
 
 	eal_log_level_parse(argc, argv);
 
diff --git a/lib/librte_eal/windows/eal_log.c b/lib/librte_eal/windows/eal_log.c
index 875981f139..d4ea47f1c8 100644
--- a/lib/librte_eal/windows/eal_log.c
+++ b/lib/librte_eal/windows/eal_log.c
@@ -2,11 +2,13 @@
  * Copyright(c) 2017-2018 Intel Corporation
  */
 
-#include "eal_private.h"
+#include <rte_common.h>
+#include <rte_log.h>
+#include "eal_log.h"
 
 /* set the log to default function, called during eal init process. */
 int
-rte_eal_log_init(__rte_unused const char *id, __rte_unused int facility)
+eal_log_init(__rte_unused const char *id, __rte_unused int facility)
 {
 	rte_openlog_stream(stderr);
 
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v3 05/11] eal: introduce maximum log level macro
  2021-03-12 18:17 ` [dpdk-dev] [PATCH v3 00/11] improve options help Thomas Monjalon
                     ` (3 preceding siblings ...)
  2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 04/11] eal: move private log functions Thomas Monjalon
@ 2021-03-12 18:17   ` Thomas Monjalon
  2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 06/11] eal: catch invalid log level number Thomas Monjalon
                     ` (6 subsequent siblings)
  11 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-12 18:17 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, bruce.richardson, mb

RTE_DIM(...) and RTE_LOG_DEBUG were used to get the highest log level.
For better clarity a new constant RTE_LOG_MAX is introduced
and mapped to RTE_LOG_DEBUG.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 lib/librte_eal/common/eal_common_log.c     | 8 ++++----
 lib/librte_eal/common/eal_common_options.c | 2 +-
 lib/librte_eal/include/rte_log.h           | 1 +
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c
index aee7c44c6a..40cac36f89 100644
--- a/lib/librte_eal/common/eal_common_log.c
+++ b/lib/librte_eal/common/eal_common_log.c
@@ -140,7 +140,7 @@ rte_log_set_level(uint32_t type, uint32_t level)
 {
 	if (type >= rte_logs.dynamic_types_len)
 		return -1;
-	if (level > RTE_LOG_DEBUG)
+	if (level > RTE_LOG_MAX)
 		return -1;
 
 	rte_logs.dynamic_types[type].loglevel = level;
@@ -155,7 +155,7 @@ rte_log_set_level_regexp(const char *regex, uint32_t level)
 	regex_t r;
 	size_t i;
 
-	if (level > RTE_LOG_DEBUG)
+	if (level > RTE_LOG_MAX)
 		return -1;
 
 	if (regcomp(&r, regex, 0) != 0)
@@ -219,7 +219,7 @@ rte_log_set_level_pattern(const char *pattern, uint32_t level)
 {
 	size_t i;
 
-	if (level > RTE_LOG_DEBUG)
+	if (level > RTE_LOG_MAX)
 		return -1;
 
 	for (i = 0; i < rte_logs.dynamic_types_len; i++) {
@@ -323,7 +323,7 @@ rte_log_register_type_and_pick_level(const char *name, uint32_t level_def)
 		return type;
 
 	TAILQ_FOREACH(opt_ll, &opt_loglevel_list, next) {
-		if (opt_ll->level > RTE_LOG_DEBUG)
+		if (opt_ll->level > RTE_LOG_MAX)
 			continue;
 
 		if (opt_ll->pattern) {
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 02374ee09e..3675e55fc9 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -1249,7 +1249,7 @@ eal_parse_log_priority(const char *level)
 		return -1;
 
 	/* look for named values, skip 0 which is not a valid level */
-	for (i = 1; i < RTE_DIM(levels); i++) {
+	for (i = 1; i <= RTE_LOG_MAX; i++) {
 		if (strncmp(levels[i], level, len) == 0)
 			return i;
 	}
diff --git a/lib/librte_eal/include/rte_log.h b/lib/librte_eal/include/rte_log.h
index 173004fd71..394e8682b9 100644
--- a/lib/librte_eal/include/rte_log.h
+++ b/lib/librte_eal/include/rte_log.h
@@ -72,6 +72,7 @@ extern "C" {
 #define RTE_LOG_NOTICE   6U  /**< Normal but significant condition. */
 #define RTE_LOG_INFO     7U  /**< Informational.                    */
 #define RTE_LOG_DEBUG    8U  /**< Debug-level messages.             */
+#define RTE_LOG_MAX RTE_LOG_DEBUG /**< Most detailed log level.     */
 
 /**
  * Change the stream that will be used by the logging system.
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v3 06/11] eal: catch invalid log level number
  2021-03-12 18:17 ` [dpdk-dev] [PATCH v3 00/11] improve options help Thomas Monjalon
                     ` (4 preceding siblings ...)
  2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 05/11] eal: introduce maximum log level macro Thomas Monjalon
@ 2021-03-12 18:17   ` Thomas Monjalon
  2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 07/11] eal: add log level help Thomas Monjalon
                     ` (5 subsequent siblings)
  11 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-12 18:17 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, bruce.richardson, mb

The parsing check for invalid log level was not trying to catch
irrelevant numeric values.
A log level 0 is now a failure in options parsing so it can be caught early.
A log level higher than the max (8) is accepted with a warning message.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 lib/librte_eal/common/eal_common_options.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 3675e55fc9..2df3ae04ea 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -1289,10 +1289,15 @@ eal_parse_log_level(const char *arg)
 	}
 
 	priority = eal_parse_log_priority(level);
-	if (priority < 0) {
-		fprintf(stderr, "invalid log priority: %s\n", level);
+	if (priority <= 0) {
+		fprintf(stderr, "Invalid log level: %s\n", level);
 		goto fail;
 	}
+	if (priority > (int)RTE_LOG_MAX) {
+		fprintf(stderr, "Log level %d higher than maximum (%d)\n",
+				priority, RTE_LOG_MAX);
+		priority = RTE_LOG_MAX;
+	}
 
 	if (regex) {
 		if (rte_log_set_level_regexp(regex, priority) < 0) {
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v3 07/11] eal: add log level help
  2021-03-12 18:17 ` [dpdk-dev] [PATCH v3 00/11] improve options help Thomas Monjalon
                     ` (5 preceding siblings ...)
  2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 06/11] eal: catch invalid log level number Thomas Monjalon
@ 2021-03-12 18:17   ` Thomas Monjalon
  2021-03-15 10:19     ` Kinsella, Ray
  2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 08/11] app: fix exit messages Thomas Monjalon
                     ` (4 subsequent siblings)
  11 siblings, 1 reply; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-12 18:17 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, bruce.richardson, mb, Ray Kinsella, Neil Horman

The option --log-level was not completely described in the usage text,
and it was difficult to guess the names of the log types and levels.

A new value "help" is accepted after --log-level to give more details
about the syntax and listing the log types and levels.

The array "levels" used for level name parsing is replaced with
a (modified) existing function which was used in rte_log_dump().

The new function rte_log_list_types() is exported in the API
for allowing an application to give this info to the user
if not exposing the EAL option --log-level.
The list of log types cannot include all drivers if not linked in the
application (shared object plugin case).

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 lib/librte_eal/common/eal_common_log.c     | 24 +++++++++---
 lib/librte_eal/common/eal_common_options.c | 44 +++++++++++++++-------
 lib/librte_eal/common/eal_log.h            |  5 +++
 lib/librte_eal/include/rte_log.h           | 11 ++++++
 lib/librte_eal/version.map                 |  3 ++
 5 files changed, 69 insertions(+), 18 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c
index 40cac36f89..d695b04068 100644
--- a/lib/librte_eal/common/eal_common_log.c
+++ b/lib/librte_eal/common/eal_common_log.c
@@ -397,12 +397,12 @@ RTE_INIT_PRIO(log_init, LOG)
 	rte_logs.dynamic_types_len = RTE_LOGTYPE_FIRST_EXT_ID;
 }
 
-static const char *
-loglevel_to_string(uint32_t level)
+const char *
+eal_log_level2str(uint32_t level)
 {
 	switch (level) {
 	case 0: return "disabled";
-	case RTE_LOG_EMERG: return "emerg";
+	case RTE_LOG_EMERG: return "emergency";
 	case RTE_LOG_ALERT: return "alert";
 	case RTE_LOG_CRIT: return "critical";
 	case RTE_LOG_ERR: return "error";
@@ -414,6 +414,20 @@ loglevel_to_string(uint32_t level)
 	}
 }
 
+/* Dump name of each logtype, one per line. */
+void
+rte_log_list_types(FILE *out, const char *prefix)
+{
+	size_t type;
+
+	for (type = 0; type < rte_logs.dynamic_types_len; ++type) {
+		if (rte_logs.dynamic_types[type].name == NULL)
+			continue;
+		fprintf(out, "%s%s\n",
+				prefix, rte_logs.dynamic_types[type].name);
+	}
+}
+
 /* dump global level and registered log types */
 void
 rte_log_dump(FILE *f)
@@ -421,14 +435,14 @@ rte_log_dump(FILE *f)
 	size_t i;
 
 	fprintf(f, "global log level is %s\n",
-		loglevel_to_string(rte_log_get_global_level()));
+		eal_log_level2str(rte_log_get_global_level()));
 
 	for (i = 0; i < rte_logs.dynamic_types_len; i++) {
 		if (rte_logs.dynamic_types[i].name == NULL)
 			continue;
 		fprintf(f, "id %zu: %s, level is %s\n",
 			i, rte_logs.dynamic_types[i].name,
-			loglevel_to_string(rte_logs.dynamic_types[i].loglevel));
+			eal_log_level2str(rte_logs.dynamic_types[i].loglevel));
 	}
 }
 
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 2df3ae04ea..1da6583d71 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -1227,19 +1227,31 @@ eal_parse_syslog(const char *facility, struct internal_config *conf)
 }
 #endif
 
+static void
+eal_log_usage(void)
+{
+	unsigned int level;
+
+	printf("Log type is a pattern matching items of this list"
+			" (plugins may be missing):\n");
+	rte_log_list_types(stdout, "\t");
+	printf("\n");
+	printf("Syntax using globbing pattern:     ");
+	printf("--"OPT_LOG_LEVEL" pattern:level\n");
+	printf("Syntax using regular expression:   ");
+	printf("--"OPT_LOG_LEVEL" regexp,level\n");
+	printf("Syntax for the global level:       ");
+	printf("--"OPT_LOG_LEVEL" level\n");
+	printf("Logs are emitted if allowed by both global and specific levels.\n");
+	printf("\n");
+	printf("Log level can be a number or the first letters of its name:\n");
+	for (level = 1; level <= RTE_LOG_MAX; level++)
+		printf("\t%d   %s\n", level, eal_log_level2str(level));
+}
+
 static int
 eal_parse_log_priority(const char *level)
 {
-	static const char * const levels[] = {
-		[RTE_LOG_EMERG]   = "emergency",
-		[RTE_LOG_ALERT]   = "alert",
-		[RTE_LOG_CRIT]    = "critical",
-		[RTE_LOG_ERR]     = "error",
-		[RTE_LOG_WARNING] = "warning",
-		[RTE_LOG_NOTICE]  = "notice",
-		[RTE_LOG_INFO]    = "info",
-		[RTE_LOG_DEBUG]   = "debug",
-	};
 	size_t len = strlen(level);
 	unsigned long tmp;
 	char *end;
@@ -1250,7 +1262,7 @@ eal_parse_log_priority(const char *level)
 
 	/* look for named values, skip 0 which is not a valid level */
 	for (i = 1; i <= RTE_LOG_MAX; i++) {
-		if (strncmp(levels[i], level, len) == 0)
+		if (strncmp(eal_log_level2str(i), level, len) == 0)
 			return i;
 	}
 
@@ -1274,6 +1286,11 @@ eal_parse_log_level(const char *arg)
 	char *str, *level;
 	int priority;
 
+	if (strcmp(arg, "help") == 0) {
+		eal_log_usage();
+		exit(EXIT_SUCCESS);
+	}
+
 	str = strdup(arg);
 	if (str == NULL)
 		return -1;
@@ -2067,9 +2084,10 @@ eal_common_usage(void)
 #ifndef RTE_EXEC_ENV_WINDOWS
 	       "  --"OPT_SYSLOG"            Set syslog facility\n"
 #endif
-	       "  --"OPT_LOG_LEVEL"=<int>   Set global log level\n"
-	       "  --"OPT_LOG_LEVEL"=<type-match>:<int>\n"
+	       "  --"OPT_LOG_LEVEL"=<level> Set global log level\n"
+	       "  --"OPT_LOG_LEVEL"=<type-match>:<level>\n"
 	       "                      Set specific log level\n"
+	       "  --"OPT_LOG_LEVEL"=help    Show log types and levels\n"
 #ifndef RTE_EXEC_ENV_WINDOWS
 	       "  --"OPT_TRACE"=<regex-match>\n"
 	       "                      Enable trace based on regular expression trace name.\n"
diff --git a/lib/librte_eal/common/eal_log.h b/lib/librte_eal/common/eal_log.h
index 684650a17b..c784fa6043 100644
--- a/lib/librte_eal/common/eal_log.h
+++ b/lib/librte_eal/common/eal_log.h
@@ -24,4 +24,9 @@ void eal_log_set_default(FILE *default_log);
 int eal_log_save_regexp(const char *regexp, uint32_t level);
 int eal_log_save_pattern(const char *pattern, uint32_t level);
 
+/*
+ * Convert log level to string.
+ */
+const char *eal_log_level2str(uint32_t level);
+
 #endif /* EAL_LOG_H */
diff --git a/lib/librte_eal/include/rte_log.h b/lib/librte_eal/include/rte_log.h
index 394e8682b9..e6192892c3 100644
--- a/lib/librte_eal/include/rte_log.h
+++ b/lib/librte_eal/include/rte_log.h
@@ -240,6 +240,17 @@ int rte_log_register(const char *name);
 __rte_experimental
 int rte_log_register_type_and_pick_level(const char *name, uint32_t level_def);
 
+/**
+ * Dump name of each logtype, one per line.
+ *
+ * @param out
+ *   Stream where the list is sent.
+ * @param prefix
+ *   String preceding each logtype in the output.
+ */
+__rte_experimental
+void rte_log_list_types(FILE *out, const char *prefix);
+
 /**
  * Dump log information.
  *
diff --git a/lib/librte_eal/version.map b/lib/librte_eal/version.map
index fce90a112f..6b7876a0b9 100644
--- a/lib/librte_eal/version.map
+++ b/lib/librte_eal/version.map
@@ -412,6 +412,9 @@ EXPERIMENTAL {
 	rte_thread_tls_key_delete;
 	rte_thread_tls_value_get;
 	rte_thread_tls_value_set;
+
+	# added in 21.05
+	rte_log_list_types;
 };
 
 INTERNAL {
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v3 08/11] app: fix exit messages
  2021-03-12 18:17 ` [dpdk-dev] [PATCH v3 00/11] improve options help Thomas Monjalon
                     ` (6 preceding siblings ...)
  2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 07/11] eal: add log level help Thomas Monjalon
@ 2021-03-12 18:17   ` Thomas Monjalon
  2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 09/11] app: hook in EAL usage help Thomas Monjalon
                     ` (3 subsequent siblings)
  11 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-12 18:17 UTC (permalink / raw)
  To: dev
  Cc: david.marchand, bruce.richardson, mb, Wisam Jaddo, Ori Kam,
	Declan Doherty, Ciara Power, Xiaoyun Li

Some applications were printing useless messages with rte_exit()
after showing the help. Using exit() is enough in this case.

Some applications were using a redundant printf or fprintf() before
calling rte_exit(). The messages are unified in a single rte_exit().

Some rte_exit() calls were missing a line feed or returning a wrong code.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Wisam Jaddo <wisamm@nvidia.com>
Acked-by: Ori Kam <orika@nvidia.com>
---
 .../comp_perf_options_parse.c                 |  2 +-
 app/test-crypto-perf/cperf_options_parsing.c  |  2 +-
 app/test-flow-perf/main.c                     | 59 +++++++++----------
 app/test-pmd/parameters.c                     |  4 +-
 app/test-regex/main.c                         |  3 +-
 5 files changed, 33 insertions(+), 37 deletions(-)

diff --git a/app/test-compress-perf/comp_perf_options_parse.c b/app/test-compress-perf/comp_perf_options_parse.c
index 04a8d2fbee..019eddb7bd 100644
--- a/app/test-compress-perf/comp_perf_options_parse.c
+++ b/app/test-compress-perf/comp_perf_options_parse.c
@@ -620,7 +620,7 @@ comp_perf_options_parse(struct comp_test_data *test_data, int argc, char **argv)
 		switch (opt) {
 		case 'h':
 			usage(argv[0]);
-			rte_exit(EXIT_SUCCESS, "Displayed help\n");
+			exit(EXIT_SUCCESS);
 			break;
 		/* long options */
 		case 0:
diff --git a/app/test-crypto-perf/cperf_options_parsing.c b/app/test-crypto-perf/cperf_options_parsing.c
index 0466f7baf8..40b6dfb648 100644
--- a/app/test-crypto-perf/cperf_options_parsing.c
+++ b/app/test-crypto-perf/cperf_options_parsing.c
@@ -983,7 +983,7 @@ cperf_options_parse(struct cperf_options *options, int argc, char **argv)
 		switch (opt) {
 		case 'h':
 			usage(argv[0]);
-			rte_exit(EXIT_SUCCESS, "Displayed help\n");
+			exit(EXIT_SUCCESS);
 			break;
 		/* long options */
 		case 0:
diff --git a/app/test-flow-perf/main.c b/app/test-flow-perf/main.c
index 99d0463456..0aef767350 100644
--- a/app/test-flow-perf/main.c
+++ b/app/test-flow-perf/main.c
@@ -639,7 +639,7 @@ args_parse(int argc, char **argv)
 		case 0:
 			if (strcmp(lgopts[opt_idx].name, "help") == 0) {
 				usage(argv[0]);
-				rte_exit(EXIT_SUCCESS, "Displayed help\n");
+				exit(EXIT_SUCCESS);
 			}
 
 			if (strcmp(lgopts[opt_idx].name, "group") == 0) {
@@ -647,7 +647,7 @@ args_parse(int argc, char **argv)
 				if (n >= 0)
 					flow_group = n;
 				else
-					rte_exit(EXIT_SUCCESS,
+					rte_exit(EXIT_FAILURE,
 						"flow group should be >= 0\n");
 				printf("group %d / ", flow_group);
 			}
@@ -667,7 +667,7 @@ args_parse(int argc, char **argv)
 				if (n > 0)
 					hairpin_queues_num = n;
 				else
-					rte_exit(EXIT_SUCCESS,
+					rte_exit(EXIT_FAILURE,
 						"Hairpin queues should be > 0\n");
 
 				flow_actions[actions_idx++] =
@@ -680,7 +680,7 @@ args_parse(int argc, char **argv)
 				if (n > 0)
 					hairpin_queues_num = n;
 				else
-					rte_exit(EXIT_SUCCESS,
+					rte_exit(EXIT_FAILURE,
 						"Hairpin queues should be > 0\n");
 
 				flow_actions[actions_idx++] =
@@ -704,11 +704,9 @@ args_parse(int argc, char **argv)
 							break;
 						}
 						/* Reached last item with no match */
-						if (i == (RTE_DIM(flow_options) - 1)) {
-							fprintf(stderr, "Invalid encap item: %s\n", token);
-							usage(argv[0]);
-							rte_exit(EXIT_SUCCESS, "Invalid encap item\n");
-						}
+						if (i == (RTE_DIM(flow_options) - 1))
+							rte_exit(EXIT_FAILURE,
+								"Invalid encap item: %s\n", token);
 					}
 					token = strtok(NULL, ",");
 				}
@@ -730,11 +728,9 @@ args_parse(int argc, char **argv)
 							break;
 						}
 						/* Reached last item with no match */
-						if (i == (RTE_DIM(flow_options) - 1)) {
-							fprintf(stderr, "Invalid decap item: %s\n", token);
-							usage(argv[0]);
-							rte_exit(EXIT_SUCCESS, "Invalid decap item\n");
-						}
+						if (i == (RTE_DIM(flow_options) - 1))
+							rte_exit(EXIT_FAILURE,
+								"Invalid decap item %s\n", token);
 					}
 					token = strtok(NULL, ",");
 				}
@@ -747,9 +743,9 @@ args_parse(int argc, char **argv)
 				if (n >= DEFAULT_RULES_BATCH)
 					rules_batch = n;
 				else {
-					printf("\n\nrules_batch should be >= %d\n",
+					rte_exit(EXIT_FAILURE,
+						"rules_batch should be >= %d\n",
 						DEFAULT_RULES_BATCH);
-					rte_exit(EXIT_SUCCESS, " ");
 				}
 			}
 			if (strcmp(lgopts[opt_idx].name,
@@ -758,7 +754,8 @@ args_parse(int argc, char **argv)
 				if (n >= (int) rules_batch)
 					rules_count = n;
 				else {
-					printf("\n\nrules_count should be >= %d\n",
+					rte_exit(EXIT_FAILURE,
+						"rules_count should be >= %d\n",
 						rules_batch);
 				}
 			}
@@ -786,23 +783,23 @@ args_parse(int argc, char **argv)
 			if (strcmp(lgopts[opt_idx].name, "cores") == 0) {
 				n = atoi(optarg);
 				if ((int) rte_lcore_count() <= n) {
-					printf("\nError: you need %d cores to run on multi-cores\n"
+					rte_exit(EXIT_FAILURE,
+						"Error: you need %d cores to run on multi-cores\n"
 						"Existing cores are: %d\n", n, rte_lcore_count());
-					rte_exit(EXIT_FAILURE, " ");
 				}
 				if (n <= RTE_MAX_LCORE && n > 0)
 					mc_pool.cores_count = n;
 				else {
-					printf("Error: cores count must be > 0 "
-						" and < %d\n", RTE_MAX_LCORE);
-					rte_exit(EXIT_FAILURE, " ");
+					rte_exit(EXIT_FAILURE,
+						"Error: cores count must be > 0 and < %d\n",
+						RTE_MAX_LCORE);
 				}
 			}
 			break;
 		default:
-			fprintf(stderr, "Invalid option: %s\n", argv[optind]);
 			usage(argv[0]);
-			rte_exit(EXIT_SUCCESS, "Invalid option\n");
+			rte_exit(EXIT_FAILURE, "Invalid option: %s\n",
+					argv[optind]);
 			break;
 		}
 	}
@@ -936,7 +933,7 @@ create_meter_rule(int port_id, uint32_t counter)
 		printf("Port %u create meter idx(%d) error(%d) message: %s\n",
 			port_id, counter, error.type,
 			error.message ? error.message : "(no stated reason)");
-		rte_exit(EXIT_FAILURE, "error in creating meter");
+		rte_exit(EXIT_FAILURE, "Error in creating meter\n");
 	}
 }
 
@@ -949,7 +946,7 @@ destroy_meter_rule(int port_id, uint32_t counter)
 		printf("Port %u destroy meter(%d) error(%d) message: %s\n",
 			port_id, counter, error.type,
 			error.message ? error.message : "(no stated reason)");
-		rte_exit(EXIT_FAILURE, "Error in deleting meter rule");
+		rte_exit(EXIT_FAILURE, "Error in deleting meter rule\n");
 	}
 }
 
@@ -1097,7 +1094,7 @@ destroy_flows(int port_id, uint8_t core_id, struct rte_flow **flows_list)
 		memset(&error, 0x33, sizeof(error));
 		if (rte_flow_destroy(port_id, flows_list[i], &error)) {
 			print_flow_error(error);
-			rte_exit(EXIT_FAILURE, "Error in deleting flow");
+			rte_exit(EXIT_FAILURE, "Error in deleting flow\n");
 		}
 
 		/*
@@ -1160,7 +1157,7 @@ insert_flows(int port_id, uint8_t core_id)
 	flows_list = rte_zmalloc("flows_list",
 		(sizeof(struct rte_flow *) * rules_count_per_core) + 1, 0);
 	if (flows_list == NULL)
-		rte_exit(EXIT_FAILURE, "No Memory available!");
+		rte_exit(EXIT_FAILURE, "No Memory available!\n");
 
 	cpu_time_used = 0;
 	flow_index = 0;
@@ -1180,7 +1177,7 @@ insert_flows(int port_id, uint8_t core_id)
 
 		if (flow == NULL) {
 			print_flow_error(error);
-			rte_exit(EXIT_FAILURE, "error in creating flow");
+			rte_exit(EXIT_FAILURE, "Error in creating flow\n");
 		}
 		flows_list[flow_index++] = flow;
 	}
@@ -1199,7 +1196,7 @@ insert_flows(int port_id, uint8_t core_id)
 
 		if (!flow) {
 			print_flow_error(error);
-			rte_exit(EXIT_FAILURE, "error in creating flow");
+			rte_exit(EXIT_FAILURE, "Error in creating flow\n");
 		}
 
 		flows_list[flow_index++] = flow;
@@ -1517,7 +1514,7 @@ packet_per_second_stats(void)
 	old = rte_zmalloc("old",
 		sizeof(struct lcore_info) * RTE_MAX_LCORE, 0);
 	if (old == NULL)
-		rte_exit(EXIT_FAILURE, "No Memory available!");
+		rte_exit(EXIT_FAILURE, "No Memory available!\n");
 
 	memcpy(old, lcore_infos,
 		sizeof(struct lcore_info) * RTE_MAX_LCORE);
diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c
index c8acd5d1b7..55ecea6338 100644
--- a/app/test-pmd/parameters.c
+++ b/app/test-pmd/parameters.c
@@ -632,7 +632,7 @@ launch_args_parse(int argc, char** argv)
 		case 0: /*long options */
 			if (!strcmp(lgopts[opt_idx].name, "help")) {
 				usage(argv[0]);
-				rte_exit(EXIT_SUCCESS, "Displayed help\n");
+				exit(EXIT_SUCCESS);
 			}
 #ifdef RTE_LIB_CMDLINE
 			if (!strcmp(lgopts[opt_idx].name, "interactive")) {
@@ -1369,7 +1369,7 @@ launch_args_parse(int argc, char** argv)
 			break;
 		case 'h':
 			usage(argv[0]);
-			rte_exit(EXIT_SUCCESS, "Displayed help\n");
+			exit(EXIT_SUCCESS);
 			break;
 		default:
 			usage(argv[0]);
diff --git a/app/test-regex/main.c b/app/test-regex/main.c
index aea4fa6b88..7bb87bb1b8 100644
--- a/app/test-regex/main.c
+++ b/app/test-regex/main.c
@@ -154,9 +154,8 @@ args_parse(int argc, char **argv, char *rules_file, char *data_file,
 			usage("RegEx test app");
 			break;
 		default:
-			fprintf(stderr, "Invalid option: %s\n", argv[optind]);
 			usage("RegEx test app");
-			rte_exit(EXIT_FAILURE, "Invalid option\n");
+			rte_exit(EXIT_FAILURE, "Invalid option: %s\n", argv[optind]);
 			break;
 		}
 	}
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v3 09/11] app: hook in EAL usage help
  2021-03-12 18:17 ` [dpdk-dev] [PATCH v3 00/11] improve options help Thomas Monjalon
                     ` (7 preceding siblings ...)
  2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 08/11] app: fix exit messages Thomas Monjalon
@ 2021-03-12 18:17   ` Thomas Monjalon
  2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 10/11] app/regex: fix usage text Thomas Monjalon
                     ` (2 subsequent siblings)
  11 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-12 18:17 UTC (permalink / raw)
  To: dev
  Cc: david.marchand, bruce.richardson, mb, Wisam Jaddo, Reshma Pattan,
	Maryam Tahhan, Konstantin Ananyev, Nicolas Chautru,
	Declan Doherty, Ciara Power, Vladimir Medvedkin, Xiaoyun Li,
	Ori Kam, Bernard Iremonger

Use rte_set_application_usage_hook() in the test applications,
so the full help including EAL options can be printed in one go
with the EAL option -h or --help.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Wisam Jaddo <wisamm@nvidia.com>
---
 app/pdump/main.c                                 | 2 ++
 app/proc-info/main.c                             | 2 ++
 app/test-acl/main.c                              | 2 ++
 app/test-bbdev/main.c                            | 3 ++-
 app/test-compress-perf/comp_perf_options.h       | 2 ++
 app/test-compress-perf/comp_perf_options_parse.c | 8 ++++----
 app/test-compress-perf/main.c                    | 3 ++-
 app/test-crypto-perf/cperf_options.h             | 2 ++
 app/test-crypto-perf/cperf_options_parsing.c     | 8 ++++----
 app/test-crypto-perf/main.c                      | 3 ++-
 app/test-fib/main.c                              | 8 ++++++++
 app/test-flow-perf/main.c                        | 4 +++-
 app/test-pmd/parameters.c                        | 4 ++--
 app/test-pmd/testpmd.c                           | 2 ++
 app/test-pmd/testpmd.h                           | 1 +
 app/test-regex/main.c                            | 3 ++-
 app/test-sad/main.c                              | 7 +++++++
 17 files changed, 49 insertions(+), 15 deletions(-)

diff --git a/app/pdump/main.c b/app/pdump/main.c
index 63bbe65cd8..8641017f48 100644
--- a/app/pdump/main.c
+++ b/app/pdump/main.c
@@ -974,6 +974,8 @@ main(int argc, char **argv)
 	char mp_flag[] = "--proc-type=secondary";
 	char *argp[argc + 2];
 
+	rte_set_application_usage_hook(pdump_usage);
+
 	/* catch ctrl-c so we can print on exit */
 	signal(SIGINT, signal_handler);
 
diff --git a/app/proc-info/main.c b/app/proc-info/main.c
index b9587f7ded..e7d86bfa9d 100644
--- a/app/proc-info/main.c
+++ b/app/proc-info/main.c
@@ -1361,6 +1361,8 @@ main(int argc, char **argv)
 	char *argp[argc + 4];
 	uint16_t nb_ports;
 
+	rte_set_application_usage_hook(proc_info_usage);
+
 	/* preparse app arguments */
 	ret = proc_info_preparse_args(argc, argv);
 	if (ret < 0) {
diff --git a/app/test-acl/main.c b/app/test-acl/main.c
index 2cb2fe2579..9f95cb0fbf 100644
--- a/app/test-acl/main.c
+++ b/app/test-acl/main.c
@@ -1080,6 +1080,8 @@ main(int argc, char **argv)
 	int ret;
 	uint32_t lcore;
 
+	rte_set_application_usage_hook(print_usage);
+
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
 		rte_panic("Cannot init EAL\n");
diff --git a/app/test-bbdev/main.c b/app/test-bbdev/main.c
index ff65173fdb..5960ec18b2 100644
--- a/app/test-bbdev/main.c
+++ b/app/test-bbdev/main.c
@@ -340,7 +340,8 @@ main(int argc, char **argv)
 {
 	int ret;
 
-	/* Init EAL */
+	rte_set_application_usage_hook(print_usage);
+
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
 		return 1;
diff --git a/app/test-compress-perf/comp_perf_options.h b/app/test-compress-perf/comp_perf_options.h
index 0b777521c5..7dd785fba1 100644
--- a/app/test-compress-perf/comp_perf_options.h
+++ b/app/test-compress-perf/comp_perf_options.h
@@ -73,6 +73,8 @@ struct comp_test_data {
 	uint32_t cyclecount_delay;
 };
 
+void comp_perf_usage(const char *progname);
+
 int
 comp_perf_options_parse(struct comp_test_data *test_data, int argc,
 			char **argv);
diff --git a/app/test-compress-perf/comp_perf_options_parse.c b/app/test-compress-perf/comp_perf_options_parse.c
index 019eddb7bd..39d7fd8c69 100644
--- a/app/test-compress-perf/comp_perf_options_parse.c
+++ b/app/test-compress-perf/comp_perf_options_parse.c
@@ -38,8 +38,8 @@ struct name_id_map {
 	uint32_t id;
 };
 
-static void
-usage(char *progname)
+void
+comp_perf_usage(const char *progname)
 {
 	printf("%s [EAL options] --\n"
 		" --ptest throughput / verify / pmd-cyclecount\n"
@@ -619,7 +619,7 @@ comp_perf_options_parse(struct comp_test_data *test_data, int argc, char **argv)
 	while ((opt = getopt_long(argc, argv, "h", lgopts, &opt_idx)) != EOF) {
 		switch (opt) {
 		case 'h':
-			usage(argv[0]);
+			comp_perf_usage(argv[0]);
 			exit(EXIT_SUCCESS);
 			break;
 		/* long options */
@@ -631,7 +631,7 @@ comp_perf_options_parse(struct comp_test_data *test_data, int argc, char **argv)
 			break;
 
 		default:
-			usage(argv[0]);
+			comp_perf_usage(argv[0]);
 			return -EINVAL;
 		}
 	}
diff --git a/app/test-compress-perf/main.c b/app/test-compress-perf/main.c
index cc9951a9b1..dcd347528e 100644
--- a/app/test-compress-perf/main.c
+++ b/app/test-compress-perf/main.c
@@ -323,7 +323,8 @@ main(int argc, char **argv)
 	uint8_t cdev_id;
 	uint32_t lcore_id;
 
-	/* Initialise DPDK EAL */
+	rte_set_application_usage_hook(comp_perf_usage);
+
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
 		rte_exit(EXIT_FAILURE, "Invalid EAL arguments!\n");
diff --git a/app/test-crypto-perf/cperf_options.h b/app/test-crypto-perf/cperf_options.h
index 9664a4b343..5f4a780614 100644
--- a/app/test-crypto-perf/cperf_options.h
+++ b/app/test-crypto-perf/cperf_options.h
@@ -153,6 +153,8 @@ struct cperf_options {
 	uint8_t imix_distribution_count;
 };
 
+void cperf_usage(const char *progname);
+
 void
 cperf_options_default(struct cperf_options *options);
 
diff --git a/app/test-crypto-perf/cperf_options_parsing.c b/app/test-crypto-perf/cperf_options_parsing.c
index 40b6dfb648..3777bc7509 100644
--- a/app/test-crypto-perf/cperf_options_parsing.c
+++ b/app/test-crypto-perf/cperf_options_parsing.c
@@ -19,8 +19,8 @@ struct name_id_map {
 	uint32_t id;
 };
 
-static void
-usage(char *progname)
+void
+cperf_usage(const char *progname)
 {
 	printf("%s [EAL options] --\n"
 		" --silent: disable options dump\n"
@@ -982,7 +982,7 @@ cperf_options_parse(struct cperf_options *options, int argc, char **argv)
 	while ((opt = getopt_long(argc, argv, "h", lgopts, &opt_idx)) != EOF) {
 		switch (opt) {
 		case 'h':
-			usage(argv[0]);
+			cperf_usage(argv[0]);
 			exit(EXIT_SUCCESS);
 			break;
 		/* long options */
@@ -994,7 +994,7 @@ cperf_options_parse(struct cperf_options *options, int argc, char **argv)
 			break;
 
 		default:
-			usage(argv[0]);
+			cperf_usage(argv[0]);
 			return -EINVAL;
 		}
 	}
diff --git a/app/test-crypto-perf/main.c b/app/test-crypto-perf/main.c
index 49af812d8b..497c4c5226 100644
--- a/app/test-crypto-perf/main.c
+++ b/app/test-crypto-perf/main.c
@@ -519,7 +519,8 @@ main(int argc, char **argv)
 	int ret;
 	uint32_t lcore_id;
 
-	/* Initialise DPDK EAL */
+	rte_set_application_usage_hook(cperf_usage);
+
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
 		rte_exit(EXIT_FAILURE, "Invalid EAL arguments!\n");
diff --git a/app/test-fib/main.c b/app/test-fib/main.c
index b0a97b0d7e..420fe17c39 100644
--- a/app/test-fib/main.c
+++ b/app/test-fib/main.c
@@ -648,6 +648,12 @@ print_usage(void)
 		config.prgname);
 }
 
+static void
+usage_hook(const char *prgname __rte_unused)
+{
+	print_usage();
+}
+
 static int
 check_config(void)
 {
@@ -1209,6 +1215,8 @@ main(int argc, char **argv)
 	FILE *fl = NULL;
 	uint8_t depth_lim;
 
+	rte_set_application_usage_hook(usage_hook);
+
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
 		rte_panic("Cannot init EAL\n");
diff --git a/app/test-flow-perf/main.c b/app/test-flow-perf/main.c
index 0aef767350..949a5e3e11 100644
--- a/app/test-flow-perf/main.c
+++ b/app/test-flow-perf/main.c
@@ -115,7 +115,7 @@ static struct multi_cores_pool mc_pool = {
 };
 
 static void
-usage(char *progname)
+usage(const char *progname)
 {
 	printf("\nusage: %s\n", progname);
 	printf("\nControl configurations:\n");
@@ -1849,6 +1849,8 @@ main(int argc, char **argv)
 	uint16_t port;
 	struct rte_flow_error error;
 
+	rte_set_application_usage_hook(usage);
+
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
 		rte_exit(EXIT_FAILURE, "EAL init failed\n");
diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c
index 55ecea6338..7f41021d4d 100644
--- a/app/test-pmd/parameters.c
+++ b/app/test-pmd/parameters.c
@@ -46,8 +46,8 @@
 
 #include "testpmd.h"
 
-static void
-usage(char* progname)
+void
+usage(const char *progname)
 {
 	printf("usage: %s [EAL options] -- "
 #ifdef RTE_LIB_CMDLINE
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 1a57324b1b..1a60830037 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -3771,6 +3771,8 @@ main(int argc, char** argv)
 		rte_exit(EXIT_FAILURE, "Cannot register log type");
 	rte_log_set_level(testpmd_logtype, RTE_LOG_DEBUG);
 
+	rte_set_application_usage_hook(usage);
+
 	diag = rte_eal_init(argc, argv);
 	if (diag < 0)
 		rte_exit(EXIT_FAILURE, "Cannot init EAL: %s\n",
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index ce83f31f0d..37348246f8 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -763,6 +763,7 @@ inc_tx_burst_stats(struct fwd_stream *fs, uint16_t nb_tx)
 unsigned int parse_item_list(char* str, const char* item_name,
 			unsigned int max_items,
 			unsigned int *parsed_items, int check_unique_values);
+void usage(const char *progname);
 void launch_args_parse(int argc, char** argv);
 void cmdline_read_from_file(const char *filename);
 void prompt(void);
diff --git a/app/test-regex/main.c b/app/test-regex/main.c
index 7bb87bb1b8..ba09b20126 100644
--- a/app/test-regex/main.c
+++ b/app/test-regex/main.c
@@ -616,7 +616,8 @@ main(int argc, char **argv)
 	uint32_t i;
 	struct qps_per_lcore *qps_per_lcore;
 
-	/* Init EAL. */
+	rte_set_application_usage_hook(usage);
+
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
 		rte_exit(EXIT_FAILURE, "EAL init failed\n");
diff --git a/app/test-sad/main.c b/app/test-sad/main.c
index 1024757add..14a8263f8c 100644
--- a/app/test-sad/main.c
+++ b/app/test-sad/main.c
@@ -149,7 +149,12 @@ print_usage(void)
 		"[-p <parallel lookup on all available cores>]\n"
 		"[-c <init sad supporting read/write concurrency>]\n",
 		config.prgname);
+}
 
+static void
+usage_hook(const char *prgname __rte_unused)
+{
+	print_usage();
 }
 
 static int
@@ -620,6 +625,8 @@ main(int argc, char **argv)
 	struct rte_ipsec_sad_conf conf = {0};
 	unsigned int lcore_id;
 
+	rte_set_application_usage_hook(usage_hook);
+
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
 		rte_panic("Cannot init EAL\n");
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v3 10/11] app/regex: fix usage text
  2021-03-12 18:17 ` [dpdk-dev] [PATCH v3 00/11] improve options help Thomas Monjalon
                     ` (8 preceding siblings ...)
  2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 09/11] app: hook in EAL usage help Thomas Monjalon
@ 2021-03-12 18:17   ` Thomas Monjalon
  2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 11/11] app/testpmd: " Thomas Monjalon
  2021-03-15  9:40   ` [dpdk-dev] [PATCH v3 00/11] improve options help Bruce Richardson
  11 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-12 18:17 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, bruce.richardson, mb, Ori Kam

The usage syntax help includes the program name which was fake.
It is replaced with the real name from argv.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Ori Kam <orika@nvidia.com>
---
 app/test-regex/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/app/test-regex/main.c b/app/test-regex/main.c
index ba09b20126..73ba227fba 100644
--- a/app/test-regex/main.c
+++ b/app/test-regex/main.c
@@ -151,10 +151,10 @@ args_parse(int argc, char **argv, char *rules_file, char *data_file,
 			*nb_lcores = atoi(optarg);
 			break;
 		case ARG_HELP:
-			usage("RegEx test app");
+			usage(argv[0]);
 			break;
 		default:
-			usage("RegEx test app");
+			usage(argv[0]);
 			rte_exit(EXIT_FAILURE, "Invalid option: %s\n", argv[optind]);
 			break;
 		}
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v3 11/11] app/testpmd: fix usage text
  2021-03-12 18:17 ` [dpdk-dev] [PATCH v3 00/11] improve options help Thomas Monjalon
                     ` (9 preceding siblings ...)
  2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 10/11] app/regex: fix usage text Thomas Monjalon
@ 2021-03-12 18:17   ` Thomas Monjalon
  2021-03-19  8:59     ` Li, Xiaoyun
  2021-03-15  9:40   ` [dpdk-dev] [PATCH v3 00/11] improve options help Bruce Richardson
  11 siblings, 1 reply; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-12 18:17 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, bruce.richardson, mb, Xiaoyun Li

The options help text was including an incomplete and redundant
summary of the options before explaining each. The summary is dropped.

The details of the option --hairpin-mode had an extra space,
breaking the alignment with the next line.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 app/test-pmd/parameters.c | 26 ++------------------------
 1 file changed, 2 insertions(+), 24 deletions(-)

diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c
index 7f41021d4d..efcbf1e845 100644
--- a/app/test-pmd/parameters.c
+++ b/app/test-pmd/parameters.c
@@ -49,29 +49,7 @@
 void
 usage(const char *progname)
 {
-	printf("usage: %s [EAL options] -- "
-#ifdef RTE_LIB_CMDLINE
-	       "[--interactive|-i] "
-	       "[--cmdline-file=FILENAME] "
-#endif
-	       "[--help|-h] | [--auto-start|-a] | ["
-	       "--tx-first | --stats-period=PERIOD | "
-	       "--coremask=COREMASK --portmask=PORTMASK --numa "
-	       "--portlist=PORTLIST "
-	       "--mbuf-size= | --total-num-mbufs= | "
-	       "--nb-cores= | --nb-ports= | "
-#ifdef RTE_LIB_CMDLINE
-	       "--eth-peers-configfile= | "
-	       "--eth-peer=X,M:M:M:M:M:M | "
-	       "--tx-ip=SRC,DST | --tx-udp=PORT | "
-#endif
-	       "--pkt-filter-mode= |"
-	       "--rss-ip | --rss-udp | --rss-level-inner | --rss-level-outer |"
-	       "--rxpt= | --rxht= | --rxwt= |"
-	       " --rxfreet= | --txpt= | --txht= | --txwt= | --txfreet= | "
-	       "--txrst= | --tx-offloads= | | --rx-offloads= | "
-	       "--vxlan-gpe-port= | --geneve-parsed-port= | "
-	       "--record-core-cycles | --record-burst-stats]\n",
+	printf("\nUsage: %s [EAL options] -- [testpmd options]\n\n",
 	       progname);
 #ifdef RTE_LIB_CMDLINE
 	printf("  --interactive: run in interactive mode.\n");
@@ -221,7 +199,7 @@ usage(const char *progname)
 	       "enabled\n");
 	printf("  --record-core-cycles: enable measurement of CPU cycles.\n");
 	printf("  --record-burst-stats: enable display of RX and TX bursts.\n");
-	printf("  --hairpin-mode=0xXX: bitmask set the hairpin port mode.\n "
+	printf("  --hairpin-mode=0xXX: bitmask set the hairpin port mode.\n"
 	       "    0x10 - explicit Tx rule, 0x02 - hairpin ports paired\n"
 	       "    0x01 - hairpin ports loop, 0x00 - hairpin port self\n");
 }
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH 11/11] app/testpmd: fix usage text
  2021-03-09 23:31 ` [dpdk-dev] [PATCH 11/11] app/testpmd: " Thomas Monjalon
@ 2021-03-12 19:09   ` Ajit Khaparde
  0 siblings, 0 replies; 121+ messages in thread
From: Ajit Khaparde @ 2021-03-12 19:09 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dpdk-dev, David Marchand, Xiaoyun Li

[-- Attachment #1: Type: text/plain, Size: 2691 bytes --]

On Tue, Mar 9, 2021 at 3:32 PM Thomas Monjalon <thomas@monjalon.net> wrote:
>
> The options help text was including an incomplete and redundant
> summary of the options before explaining each. The summary is dropped.
>
> The details of the option --hairpin-mode had an extra space,
> breaking the alignment with the next line.
>
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Ajit Khaparde <ajit.khaparde@broadcom.com>

> ---
>  app/test-pmd/parameters.c | 26 ++------------------------
>  1 file changed, 2 insertions(+), 24 deletions(-)
>
> diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c
> index 7f41021d4d..efcbf1e845 100644
> --- a/app/test-pmd/parameters.c
> +++ b/app/test-pmd/parameters.c
> @@ -49,29 +49,7 @@
>  void
>  usage(const char *progname)
>  {
> -       printf("usage: %s [EAL options] -- "
> -#ifdef RTE_LIB_CMDLINE
> -              "[--interactive|-i] "
> -              "[--cmdline-file=FILENAME] "
> -#endif
> -              "[--help|-h] | [--auto-start|-a] | ["
> -              "--tx-first | --stats-period=PERIOD | "
> -              "--coremask=COREMASK --portmask=PORTMASK --numa "
> -              "--portlist=PORTLIST "
> -              "--mbuf-size= | --total-num-mbufs= | "
> -              "--nb-cores= | --nb-ports= | "
> -#ifdef RTE_LIB_CMDLINE
> -              "--eth-peers-configfile= | "
> -              "--eth-peer=X,M:M:M:M:M:M | "
> -              "--tx-ip=SRC,DST | --tx-udp=PORT | "
> -#endif
> -              "--pkt-filter-mode= |"
> -              "--rss-ip | --rss-udp | --rss-level-inner | --rss-level-outer |"
> -              "--rxpt= | --rxht= | --rxwt= |"
> -              " --rxfreet= | --txpt= | --txht= | --txwt= | --txfreet= | "
> -              "--txrst= | --tx-offloads= | | --rx-offloads= | "
> -              "--vxlan-gpe-port= | --geneve-parsed-port= | "
> -              "--record-core-cycles | --record-burst-stats]\n",
> +       printf("\nUsage: %s [EAL options] -- [testpmd options]\n\n",
>                progname);
>  #ifdef RTE_LIB_CMDLINE
>         printf("  --interactive: run in interactive mode.\n");
> @@ -221,7 +199,7 @@ usage(const char *progname)
>                "enabled\n");
>         printf("  --record-core-cycles: enable measurement of CPU cycles.\n");
>         printf("  --record-burst-stats: enable display of RX and TX bursts.\n");
> -       printf("  --hairpin-mode=0xXX: bitmask set the hairpin port mode.\n "
> +       printf("  --hairpin-mode=0xXX: bitmask set the hairpin port mode.\n"
>                "    0x10 - explicit Tx rule, 0x02 - hairpin ports paired\n"
>                "    0x01 - hairpin ports loop, 0x00 - hairpin port self\n");
>  }
> --
> 2.30.1
>

^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH v3 00/11] improve options help
  2021-03-12 18:17 ` [dpdk-dev] [PATCH v3 00/11] improve options help Thomas Monjalon
                     ` (10 preceding siblings ...)
  2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 11/11] app/testpmd: " Thomas Monjalon
@ 2021-03-15  9:40   ` Bruce Richardson
  2021-03-15 10:47     ` Andrew Rybchenko
  11 siblings, 1 reply; 121+ messages in thread
From: Bruce Richardson @ 2021-03-15  9:40 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev, david.marchand, mb

On Fri, Mar 12, 2021 at 07:17:09PM +0100, Thomas Monjalon wrote:
> The main intent of this series is to provide a nice help
> for the --log-level option.
> More patches are added to improve options help in general.
> 
> 
> v3:
>     - fix use of RTE_LOG_MAX
>     - accept (with warning) log level higher than RTE_LOG_MAX
> v2:
>     - fix use of the new macro RTE_LOG_MAX in level parsing
>     - improve parameters type and name while moving functions
> 
> 
Series-acked-by: Bruce Richardson <bruce.richardson@intel.com>

^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH v3 07/11] eal: add log level help
  2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 07/11] eal: add log level help Thomas Monjalon
@ 2021-03-15 10:19     ` Kinsella, Ray
  2021-03-15 10:31       ` Bruce Richardson
  0 siblings, 1 reply; 121+ messages in thread
From: Kinsella, Ray @ 2021-03-15 10:19 UTC (permalink / raw)
  To: Thomas Monjalon, dev; +Cc: david.marchand, bruce.richardson, mb, Neil Horman



On 12/03/2021 18:17, Thomas Monjalon wrote:
> The option --log-level was not completely described in the usage text,
> and it was difficult to guess the names of the log types and levels.
> 
> A new value "help" is accepted after --log-level to give more details
> about the syntax and listing the log types and levels.
> 
> The array "levels" used for level name parsing is replaced with
> a (modified) existing function which was used in rte_log_dump().
> 
> The new function rte_log_list_types() is exported in the API
> for allowing an application to give this info to the user
> if not exposing the EAL option --log-level.
> The list of log types cannot include all drivers if not linked in the
> application (shared object plugin case).
> 
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> ---
>  lib/librte_eal/common/eal_common_log.c     | 24 +++++++++---
>  lib/librte_eal/common/eal_common_options.c | 44 +++++++++++++++-------
>  lib/librte_eal/common/eal_log.h            |  5 +++
>  lib/librte_eal/include/rte_log.h           | 11 ++++++
>  lib/librte_eal/version.map                 |  3 ++
>  5 files changed, 69 insertions(+), 18 deletions(-)
> 
> diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c
> index 40cac36f89..d695b04068 100644
> --- a/lib/librte_eal/common/eal_common_log.c
> +++ b/lib/librte_eal/common/eal_common_log.c
> @@ -397,12 +397,12 @@ RTE_INIT_PRIO(log_init, LOG)
>  	rte_logs.dynamic_types_len = RTE_LOGTYPE_FIRST_EXT_ID;
>  }
>  
> -static const char *
> -loglevel_to_string(uint32_t level)
> +const char *
> +eal_log_level2str(uint32_t level)
>  {
>  	switch (level) {
>  	case 0: return "disabled";
> -	case RTE_LOG_EMERG: return "emerg";
> +	case RTE_LOG_EMERG: return "emergency";
>  	case RTE_LOG_ALERT: return "alert";
>  	case RTE_LOG_CRIT: return "critical";
>  	case RTE_LOG_ERR: return "error";
> @@ -414,6 +414,20 @@ loglevel_to_string(uint32_t level)
>  	}
>  }
>  
> +/* Dump name of each logtype, one per line. */
> +void
> +rte_log_list_types(FILE *out, const char *prefix)
> +{
> +	size_t type;
> +
> +	for (type = 0; type < rte_logs.dynamic_types_len; ++type) {
> +		if (rte_logs.dynamic_types[type].name == NULL)
> +			continue;
> +		fprintf(out, "%s%s\n",
> +				prefix, rte_logs.dynamic_types[type].name);
> +	}
> +}
> +
>  /* dump global level and registered log types */
>  void
>  rte_log_dump(FILE *f)
> @@ -421,14 +435,14 @@ rte_log_dump(FILE *f)
>  	size_t i;
>  
>  	fprintf(f, "global log level is %s\n",
> -		loglevel_to_string(rte_log_get_global_level()));
> +		eal_log_level2str(rte_log_get_global_level()));
>  
>  	for (i = 0; i < rte_logs.dynamic_types_len; i++) {
>  		if (rte_logs.dynamic_types[i].name == NULL)
>  			continue;
>  		fprintf(f, "id %zu: %s, level is %s\n",
>  			i, rte_logs.dynamic_types[i].name,
> -			loglevel_to_string(rte_logs.dynamic_types[i].loglevel));
> +			eal_log_level2str(rte_logs.dynamic_types[i].loglevel));
>  	}
>  }
>  
> diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
> index 2df3ae04ea..1da6583d71 100644
> --- a/lib/librte_eal/common/eal_common_options.c
> +++ b/lib/librte_eal/common/eal_common_options.c
> @@ -1227,19 +1227,31 @@ eal_parse_syslog(const char *facility, struct internal_config *conf)
>  }
>  #endif
>  
> +static void
> +eal_log_usage(void)
> +{
> +	unsigned int level;
> +
> +	printf("Log type is a pattern matching items of this list"
> +			" (plugins may be missing):\n");
> +	rte_log_list_types(stdout, "\t");
> +	printf("\n");
> +	printf("Syntax using globbing pattern:     ");
> +	printf("--"OPT_LOG_LEVEL" pattern:level\n");
> +	printf("Syntax using regular expression:   ");
> +	printf("--"OPT_LOG_LEVEL" regexp,level\n");
> +	printf("Syntax for the global level:       ");
> +	printf("--"OPT_LOG_LEVEL" level\n");
> +	printf("Logs are emitted if allowed by both global and specific levels.\n");
> +	printf("\n");
> +	printf("Log level can be a number or the first letters of its name:\n");
> +	for (level = 1; level <= RTE_LOG_MAX; level++)
> +		printf("\t%d   %s\n", level, eal_log_level2str(level));
> +}
> +
>  static int
>  eal_parse_log_priority(const char *level)
>  {
> -	static const char * const levels[] = {
> -		[RTE_LOG_EMERG]   = "emergency",
> -		[RTE_LOG_ALERT]   = "alert",
> -		[RTE_LOG_CRIT]    = "critical",
> -		[RTE_LOG_ERR]     = "error",
> -		[RTE_LOG_WARNING] = "warning",
> -		[RTE_LOG_NOTICE]  = "notice",
> -		[RTE_LOG_INFO]    = "info",
> -		[RTE_LOG_DEBUG]   = "debug",
> -	};
>  	size_t len = strlen(level);
>  	unsigned long tmp;
>  	char *end;
> @@ -1250,7 +1262,7 @@ eal_parse_log_priority(const char *level)
>  
>  	/* look for named values, skip 0 which is not a valid level */
>  	for (i = 1; i <= RTE_LOG_MAX; i++) {
> -		if (strncmp(levels[i], level, len) == 0)
> +		if (strncmp(eal_log_level2str(i), level, len) == 0)
>  			return i;
>  	}
>  
> @@ -1274,6 +1286,11 @@ eal_parse_log_level(const char *arg)
>  	char *str, *level;
>  	int priority;
>  
> +	if (strcmp(arg, "help") == 0) {

So I think the convention is to support both "?" and "help".
Qemu does this at least. 

> +		eal_log_usage();
> +		exit(EXIT_SUCCESS);
> +	}
> +
>  	str = strdup(arg);
>  	if (str == NULL)
>  		return -1;
> @@ -2067,9 +2084,10 @@ eal_common_usage(void)
>  #ifndef RTE_EXEC_ENV_WINDOWS
>  	       "  --"OPT_SYSLOG"            Set syslog facility\n"
>  #endif
> -	       "  --"OPT_LOG_LEVEL"=<int>   Set global log level\n"
> -	       "  --"OPT_LOG_LEVEL"=<type-match>:<int>\n"
> +	       "  --"OPT_LOG_LEVEL"=<level> Set global log level\n"
> +	       "  --"OPT_LOG_LEVEL"=<type-match>:<level>\n"
>  	       "                      Set specific log level\n"
> +	       "  --"OPT_LOG_LEVEL"=help    Show log types and levels\n"
>  #ifndef RTE_EXEC_ENV_WINDOWS
>  	       "  --"OPT_TRACE"=<regex-match>\n"
>  	       "                      Enable trace based on regular expression trace name.\n"
> diff --git a/lib/librte_eal/common/eal_log.h b/lib/librte_eal/common/eal_log.h
> index 684650a17b..c784fa6043 100644
> --- a/lib/librte_eal/common/eal_log.h
> +++ b/lib/librte_eal/common/eal_log.h
> @@ -24,4 +24,9 @@ void eal_log_set_default(FILE *default_log);
>  int eal_log_save_regexp(const char *regexp, uint32_t level);
>  int eal_log_save_pattern(const char *pattern, uint32_t level);
>  
> +/*
> + * Convert log level to string.
> + */
> +const char *eal_log_level2str(uint32_t level);
> +
>  #endif /* EAL_LOG_H */
> diff --git a/lib/librte_eal/include/rte_log.h b/lib/librte_eal/include/rte_log.h
> index 394e8682b9..e6192892c3 100644
> --- a/lib/librte_eal/include/rte_log.h
> +++ b/lib/librte_eal/include/rte_log.h
> @@ -240,6 +240,17 @@ int rte_log_register(const char *name);
>  __rte_experimental
>  int rte_log_register_type_and_pick_level(const char *name, uint32_t level_def);
>  
> +/**
> + * Dump name of each logtype, one per line.
> + *
> + * @param out
> + *   Stream where the list is sent.
> + * @param prefix
> + *   String preceding each logtype in the output.
> + */
> +__rte_experimental
> +void rte_log_list_types(FILE *out, const char *prefix);
> +
>  /**
>   * Dump log information.
>   *
> diff --git a/lib/librte_eal/version.map b/lib/librte_eal/version.map
> index fce90a112f..6b7876a0b9 100644
> --- a/lib/librte_eal/version.map
> +++ b/lib/librte_eal/version.map
> @@ -412,6 +412,9 @@ EXPERIMENTAL {
>  	rte_thread_tls_key_delete;
>  	rte_thread_tls_value_get;
>  	rte_thread_tls_value_set;
> +
> +	# added in 21.05
> +	rte_log_list_types;
>  };
>  
>  INTERNAL {
> 

^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH v3 07/11] eal: add log level help
  2021-03-15 10:19     ` Kinsella, Ray
@ 2021-03-15 10:31       ` Bruce Richardson
  2021-03-15 10:42         ` Kinsella, Ray
  0 siblings, 1 reply; 121+ messages in thread
From: Bruce Richardson @ 2021-03-15 10:31 UTC (permalink / raw)
  To: Kinsella, Ray; +Cc: Thomas Monjalon, dev, david.marchand, mb, Neil Horman

On Mon, Mar 15, 2021 at 10:19:47AM +0000, Kinsella, Ray wrote:
> 
> 
> On 12/03/2021 18:17, Thomas Monjalon wrote:
> > The option --log-level was not completely described in the usage text,
> > and it was difficult to guess the names of the log types and levels.
> > 
> > A new value "help" is accepted after --log-level to give more details
> > about the syntax and listing the log types and levels.
> > 
> > The array "levels" used for level name parsing is replaced with
> > a (modified) existing function which was used in rte_log_dump().
> > 
> > The new function rte_log_list_types() is exported in the API
> > for allowing an application to give this info to the user
> > if not exposing the EAL option --log-level.
> > The list of log types cannot include all drivers if not linked in the
> > application (shared object plugin case).
> > 
> > Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> > ---
> >  lib/librte_eal/common/eal_common_log.c     | 24 +++++++++---
> >  lib/librte_eal/common/eal_common_options.c | 44 +++++++++++++++-------
> >  lib/librte_eal/common/eal_log.h            |  5 +++
> >  lib/librte_eal/include/rte_log.h           | 11 ++++++
> >  lib/librte_eal/version.map                 |  3 ++
> >  5 files changed, 69 insertions(+), 18 deletions(-)
> > 
<snip>
> > @@ -1274,6 +1286,11 @@ eal_parse_log_level(const char *arg)
> >  	char *str, *level;
> >  	int priority;
> >  
> > +	if (strcmp(arg, "help") == 0) {
> 
> So I think the convention is to support both "?" and "help".
> Qemu does this at least. 
> 
I've seen "/?" used for help on windows binaries, but "-?" not so much in the
linux world, where --help (and often -h for short) seem to be the standard.

^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH v3 07/11] eal: add log level help
  2021-03-15 10:31       ` Bruce Richardson
@ 2021-03-15 10:42         ` Kinsella, Ray
  2021-03-15 10:52           ` Thomas Monjalon
  0 siblings, 1 reply; 121+ messages in thread
From: Kinsella, Ray @ 2021-03-15 10:42 UTC (permalink / raw)
  To: Bruce Richardson; +Cc: Thomas Monjalon, dev, david.marchand, mb, Neil Horman



On 15/03/2021 10:31, Bruce Richardson wrote:
> On Mon, Mar 15, 2021 at 10:19:47AM +0000, Kinsella, Ray wrote:
>>
>>
>> On 12/03/2021 18:17, Thomas Monjalon wrote:
>>> The option --log-level was not completely described in the usage text,
>>> and it was difficult to guess the names of the log types and levels.
>>>
>>> A new value "help" is accepted after --log-level to give more details
>>> about the syntax and listing the log types and levels.
>>>
>>> The array "levels" used for level name parsing is replaced with
>>> a (modified) existing function which was used in rte_log_dump().
>>>
>>> The new function rte_log_list_types() is exported in the API
>>> for allowing an application to give this info to the user
>>> if not exposing the EAL option --log-level.
>>> The list of log types cannot include all drivers if not linked in the
>>> application (shared object plugin case).
>>>
>>> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
>>> ---
>>>  lib/librte_eal/common/eal_common_log.c     | 24 +++++++++---
>>>  lib/librte_eal/common/eal_common_options.c | 44 +++++++++++++++-------
>>>  lib/librte_eal/common/eal_log.h            |  5 +++
>>>  lib/librte_eal/include/rte_log.h           | 11 ++++++
>>>  lib/librte_eal/version.map                 |  3 ++
>>>  5 files changed, 69 insertions(+), 18 deletions(-)
>>>
> <snip>
>>> @@ -1274,6 +1286,11 @@ eal_parse_log_level(const char *arg)
>>>  	char *str, *level;
>>>  	int priority;
>>>  
>>> +	if (strcmp(arg, "help") == 0) {
>>
>> So I think the convention is to support both "?" and "help".
>> Qemu does this at least. 
>>
> I've seen "/?" used for help on windows binaries, but "-?" not so much in the
> linux world, where --help (and often -h for short) seem to be the standard.
> 

This is slightly different - it is where you are looking to return a list of valid 
values for a parameter. So for instance in qemu mentioned above 

 ~ > qemu-system-x86_64 -cpu ? | head -n 10
Available CPUs:
x86 486                   (alias configured by machine type)
x86 486-v1
x86 Broadwell             (alias configured by machine type)
x86 Broadwell-IBRS        (alias of Broadwell-v3)
x86 Broadwell-noTSX       (alias of Broadwell-v2)
x86 Broadwell-noTSX-IBRS  (alias of Broadwell-v4)
x86 Broadwell-v1          Intel Core Processor (Broadwell)
x86 Broadwell-v2          Intel Core Processor (Broadwell, no TSX)
x86 Broadwell-v3          Intel Core Processor (Broadwell, IBRS)




^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH v3 00/11] improve options help
  2021-03-15  9:40   ` [dpdk-dev] [PATCH v3 00/11] improve options help Bruce Richardson
@ 2021-03-15 10:47     ` Andrew Rybchenko
  0 siblings, 0 replies; 121+ messages in thread
From: Andrew Rybchenko @ 2021-03-15 10:47 UTC (permalink / raw)
  To: Bruce Richardson, Thomas Monjalon; +Cc: dev, david.marchand, mb

On 3/15/21 12:40 PM, Bruce Richardson wrote:
> On Fri, Mar 12, 2021 at 07:17:09PM +0100, Thomas Monjalon wrote:
>> The main intent of this series is to provide a nice help
>> for the --log-level option.
>> More patches are added to improve options help in general.
>>
>>
>> v3:
>>     - fix use of RTE_LOG_MAX
>>     - accept (with warning) log level higher than RTE_LOG_MAX
>> v2:
>>     - fix use of the new macro RTE_LOG_MAX in level parsing
>>     - improve parameters type and name while moving functions
>>
>>
> Series-acked-by: Bruce Richardson <bruce.richardson@intel.com>
> 

Series-acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>

^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH v3 07/11] eal: add log level help
  2021-03-15 10:42         ` Kinsella, Ray
@ 2021-03-15 10:52           ` Thomas Monjalon
  2021-03-15 15:59             ` Stephen Hemminger
  0 siblings, 1 reply; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-15 10:52 UTC (permalink / raw)
  To: Kinsella, Ray; +Cc: Bruce Richardson, dev, david.marchand, mb, Neil Horman

15/03/2021 11:42, Kinsella, Ray:
> 
> On 15/03/2021 10:31, Bruce Richardson wrote:
> > On Mon, Mar 15, 2021 at 10:19:47AM +0000, Kinsella, Ray wrote:
> >>
> >>
> >> On 12/03/2021 18:17, Thomas Monjalon wrote:
> >>> The option --log-level was not completely described in the usage text,
> >>> and it was difficult to guess the names of the log types and levels.
> >>>
> >>> A new value "help" is accepted after --log-level to give more details
> >>> about the syntax and listing the log types and levels.
> >>>
> >>> The array "levels" used for level name parsing is replaced with
> >>> a (modified) existing function which was used in rte_log_dump().
> >>>
> >>> The new function rte_log_list_types() is exported in the API
> >>> for allowing an application to give this info to the user
> >>> if not exposing the EAL option --log-level.
> >>> The list of log types cannot include all drivers if not linked in the
> >>> application (shared object plugin case).
> >>>
> >>> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> >>> ---
> >>>  lib/librte_eal/common/eal_common_log.c     | 24 +++++++++---
> >>>  lib/librte_eal/common/eal_common_options.c | 44 +++++++++++++++-------
> >>>  lib/librte_eal/common/eal_log.h            |  5 +++
> >>>  lib/librte_eal/include/rte_log.h           | 11 ++++++
> >>>  lib/librte_eal/version.map                 |  3 ++
> >>>  5 files changed, 69 insertions(+), 18 deletions(-)
> >>>
> > <snip>
> >>> @@ -1274,6 +1286,11 @@ eal_parse_log_level(const char *arg)
> >>>  	char *str, *level;
> >>>  	int priority;
> >>>  
> >>> +	if (strcmp(arg, "help") == 0) {
> >>
> >> So I think the convention is to support both "?" and "help".
> >> Qemu does this at least. 
> >>
> > I've seen "/?" used for help on windows binaries, but "-?" not so much in the
> > linux world, where --help (and often -h for short) seem to be the standard.
> > 
> 
> This is slightly different - it is where you are looking to return a list of valid 
> values for a parameter. So for instance in qemu mentioned above 
> 
>  ~ > qemu-system-x86_64 -cpu ? | head -n 10

"?" is a special character.
In my zsh, I need to quote it to avoid globbing parsing,
so I'm not a fan.

I will let you extend the syntax in a separate patch :)



^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH v3 07/11] eal: add log level help
  2021-03-15 10:52           ` Thomas Monjalon
@ 2021-03-15 15:59             ` Stephen Hemminger
  2021-03-15 17:01               ` Kinsella, Ray
  0 siblings, 1 reply; 121+ messages in thread
From: Stephen Hemminger @ 2021-03-15 15:59 UTC (permalink / raw)
  To: Thomas Monjalon
  Cc: Kinsella, Ray, Bruce Richardson, dev, david.marchand, mb, Neil Horman

On Mon, 15 Mar 2021 11:52:13 +0100
Thomas Monjalon <thomas@monjalon.net> wrote:

> 15/03/2021 11:42, Kinsella, Ray:
> > 
> > On 15/03/2021 10:31, Bruce Richardson wrote:  
> > > On Mon, Mar 15, 2021 at 10:19:47AM +0000, Kinsella, Ray wrote:  
> > >>
> > >>
> > >> On 12/03/2021 18:17, Thomas Monjalon wrote:  
> > >>> The option --log-level was not completely described in the usage text,
> > >>> and it was difficult to guess the names of the log types and levels.
> > >>>
> > >>> A new value "help" is accepted after --log-level to give more details
> > >>> about the syntax and listing the log types and levels.
> > >>>
> > >>> The array "levels" used for level name parsing is replaced with
> > >>> a (modified) existing function which was used in rte_log_dump().
> > >>>
> > >>> The new function rte_log_list_types() is exported in the API
> > >>> for allowing an application to give this info to the user
> > >>> if not exposing the EAL option --log-level.
> > >>> The list of log types cannot include all drivers if not linked in the
> > >>> application (shared object plugin case).
> > >>>
> > >>> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> > >>> ---
> > >>>  lib/librte_eal/common/eal_common_log.c     | 24 +++++++++---
> > >>>  lib/librte_eal/common/eal_common_options.c | 44 +++++++++++++++-------
> > >>>  lib/librte_eal/common/eal_log.h            |  5 +++
> > >>>  lib/librte_eal/include/rte_log.h           | 11 ++++++
> > >>>  lib/librte_eal/version.map                 |  3 ++
> > >>>  5 files changed, 69 insertions(+), 18 deletions(-)
> > >>>  
> > > <snip>  
> > >>> @@ -1274,6 +1286,11 @@ eal_parse_log_level(const char *arg)
> > >>>  	char *str, *level;
> > >>>  	int priority;
> > >>>  
> > >>> +	if (strcmp(arg, "help") == 0) {  
> > >>
> > >> So I think the convention is to support both "?" and "help".
> > >> Qemu does this at least. 
> > >>  
> > > I've seen "/?" used for help on windows binaries, but "-?" not so much in the
> > > linux world, where --help (and often -h for short) seem to be the standard.
> > >   
> > 
> > This is slightly different - it is where you are looking to return a list of valid 
> > values for a parameter. So for instance in qemu mentioned above 
> > 
> >  ~ > qemu-system-x86_64 -cpu ? | head -n 10  
> 
> "?" is a special character.
> In my zsh, I need to quote it to avoid globbing parsing,
> so I'm not a fan.
> 
> I will let you extend the syntax in a separate patch :)
> 
> 

Also '?' is used by getopt to match unknown option. So qemu might just be
doing that as unintended side effect of any unknown option


^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH v3 07/11] eal: add log level help
  2021-03-15 15:59             ` Stephen Hemminger
@ 2021-03-15 17:01               ` Kinsella, Ray
  0 siblings, 0 replies; 121+ messages in thread
From: Kinsella, Ray @ 2021-03-15 17:01 UTC (permalink / raw)
  To: Stephen Hemminger, Thomas Monjalon
  Cc: Bruce Richardson, dev, david.marchand, mb, Neil Horman



On 15/03/2021 15:59, Stephen Hemminger wrote:
> On Mon, 15 Mar 2021 11:52:13 +0100
> Thomas Monjalon <thomas@monjalon.net> wrote:
> 
>> 15/03/2021 11:42, Kinsella, Ray:
>>>
>>> On 15/03/2021 10:31, Bruce Richardson wrote:  
>>>> On Mon, Mar 15, 2021 at 10:19:47AM +0000, Kinsella, Ray wrote:  
>>>>>
>>>>>
>>>>> On 12/03/2021 18:17, Thomas Monjalon wrote:  
>>>>>> The option --log-level was not completely described in the usage text,
>>>>>> and it was difficult to guess the names of the log types and levels.
>>>>>>
>>>>>> A new value "help" is accepted after --log-level to give more details
>>>>>> about the syntax and listing the log types and levels.
>>>>>>
>>>>>> The array "levels" used for level name parsing is replaced with
>>>>>> a (modified) existing function which was used in rte_log_dump().
>>>>>>
>>>>>> The new function rte_log_list_types() is exported in the API
>>>>>> for allowing an application to give this info to the user
>>>>>> if not exposing the EAL option --log-level.
>>>>>> The list of log types cannot include all drivers if not linked in the
>>>>>> application (shared object plugin case).
>>>>>>
>>>>>> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
>>>>>> ---
>>>>>>  lib/librte_eal/common/eal_common_log.c     | 24 +++++++++---
>>>>>>  lib/librte_eal/common/eal_common_options.c | 44 +++++++++++++++-------
>>>>>>  lib/librte_eal/common/eal_log.h            |  5 +++
>>>>>>  lib/librte_eal/include/rte_log.h           | 11 ++++++
>>>>>>  lib/librte_eal/version.map                 |  3 ++
>>>>>>  5 files changed, 69 insertions(+), 18 deletions(-)
>>>>>>  
>>>> <snip>  
>>>>>> @@ -1274,6 +1286,11 @@ eal_parse_log_level(const char *arg)
>>>>>>  	char *str, *level;
>>>>>>  	int priority;
>>>>>>  
>>>>>> +	if (strcmp(arg, "help") == 0) {  
>>>>>
>>>>> So I think the convention is to support both "?" and "help".
>>>>> Qemu does this at least. 
>>>>>  
>>>> I've seen "/?" used for help on windows binaries, but "-?" not so much in the
>>>> linux world, where --help (and often -h for short) seem to be the standard.
>>>>   
>>>
>>> This is slightly different - it is where you are looking to return a list of valid 
>>> values for a parameter. So for instance in qemu mentioned above 
>>>
>>>  ~ > qemu-system-x86_64 -cpu ? | head -n 10  
>>
>> "?" is a special character.
>> In my zsh, I need to quote it to avoid globbing parsing,
>> so I'm not a fan.
>>
>> I will let you extend the syntax in a separate patch :)
>>
>>
> 
> Also '?' is used by getopt to match unknown option. So qemu might just be
> doing that as unintended side effect of any unknown option
> 

for other unknowns it explicitly complains ... 

~ > qemu-system-x86_64 -cpu unknown
Unable to init server: Could not connect: Connection refused
qemu-system-x86_64: unable to find CPU model 'unknown

^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH v3 11/11] app/testpmd: fix usage text
  2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 11/11] app/testpmd: " Thomas Monjalon
@ 2021-03-19  8:59     ` Li, Xiaoyun
  2021-03-19  9:29       ` Thomas Monjalon
  0 siblings, 1 reply; 121+ messages in thread
From: Li, Xiaoyun @ 2021-03-19  8:59 UTC (permalink / raw)
  To: Thomas Monjalon, dev; +Cc: david.marchand, Richardson, Bruce, mb

Hi

> -----Original Message-----
> From: Thomas Monjalon <thomas@monjalon.net>
> Sent: Saturday, March 13, 2021 02:17
> To: dev@dpdk.org
> Cc: david.marchand@redhat.com; Richardson, Bruce
> <bruce.richardson@intel.com>; mb@smartsharesystems.com; Li, Xiaoyun
> <xiaoyun.li@intel.com>
> Subject: [PATCH v3 11/11] app/testpmd: fix usage text
> 
> The options help text was including an incomplete and redundant summary of
> the options before explaining each. The summary is dropped.
> 
> The details of the option --hairpin-mode had an extra space, breaking the
> alignment with the next line.
> 
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> ---
>  app/test-pmd/parameters.c | 26 ++------------------------
>  1 file changed, 2 insertions(+), 24 deletions(-)
> 
> diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c index
> 7f41021d4d..efcbf1e845 100644
> --- a/app/test-pmd/parameters.c
> +++ b/app/test-pmd/parameters.c
> @@ -49,29 +49,7 @@
>  void
>  usage(const char *progname)
>  {
> -	printf("usage: %s [EAL options] -- "
> -#ifdef RTE_LIB_CMDLINE
> -	       "[--interactive|-i] "
> -	       "[--cmdline-file=FILENAME] "
> -#endif
> -	       "[--help|-h] | [--auto-start|-a] | ["
> -	       "--tx-first | --stats-period=PERIOD | "
> -	       "--coremask=COREMASK --portmask=PORTMASK --numa "
> -	       "--portlist=PORTLIST "
> -	       "--mbuf-size= | --total-num-mbufs= | "
> -	       "--nb-cores= | --nb-ports= | "
> -#ifdef RTE_LIB_CMDLINE
> -	       "--eth-peers-configfile= | "
> -	       "--eth-peer=X,M:M:M:M:M:M | "
> -	       "--tx-ip=SRC,DST | --tx-udp=PORT | "

The patch looks good to me. But I found one issue.
"--tx-ip=SRC,DST | --tx-udp=PORT " These 2 parameters are missing in the detailed usage text below.

And out of curiosity, I compared the detailed usage items and lgopts in launch_args_parse()
There are several missing items in the usage text.
"--ports" (I didn't find this in the parse actually, should this be removed from lgopts?)
"--noisy-lkup-num-reads-writes" (This one is misspelled in the usage text as the 2nd " noisy-lkup-num- writes ")
"--no-numa" "--mp-anon" "--enable-scatter" There 3 parameters are missing in usage text.

BRs
Xiaoyun

> -#endif
> -	       "--pkt-filter-mode= |"
> -	       "--rss-ip | --rss-udp | --rss-level-inner | --rss-level-outer |"
> -	       "--rxpt= | --rxht= | --rxwt= |"
> -	       " --rxfreet= | --txpt= | --txht= | --txwt= | --txfreet= | "
> -	       "--txrst= | --tx-offloads= | | --rx-offloads= | "
> -	       "--vxlan-gpe-port= | --geneve-parsed-port= | "
> -	       "--record-core-cycles | --record-burst-stats]\n",
> +	printf("\nUsage: %s [EAL options] -- [testpmd options]\n\n",
>  	       progname);
>  #ifdef RTE_LIB_CMDLINE
>  	printf("  --interactive: run in interactive mode.\n"); @@ -221,7 +199,7
> @@ usage(const char *progname)
>  	       "enabled\n");
>  	printf("  --record-core-cycles: enable measurement of CPU cycles.\n");
>  	printf("  --record-burst-stats: enable display of RX and TX bursts.\n");
> -	printf("  --hairpin-mode=0xXX: bitmask set the hairpin port mode.\n "
> +	printf("  --hairpin-mode=0xXX: bitmask set the hairpin port mode.\n"
>  	       "    0x10 - explicit Tx rule, 0x02 - hairpin ports paired\n"
>  	       "    0x01 - hairpin ports loop, 0x00 - hairpin port self\n");
>  }
> --
> 2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH v3 11/11] app/testpmd: fix usage text
  2021-03-19  8:59     ` Li, Xiaoyun
@ 2021-03-19  9:29       ` Thomas Monjalon
  0 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-19  9:29 UTC (permalink / raw)
  To: Li, Xiaoyun; +Cc: dev, david.marchand, Richardson, Bruce, mb

19/03/2021 09:59, Li, Xiaoyun:
> The patch looks good to me. But I found one issue.
> "--tx-ip=SRC,DST | --tx-udp=PORT " These 2 parameters are missing in the detailed usage text below.
> 
> And out of curiosity, I compared the detailed usage items and lgopts in launch_args_parse()
> There are several missing items in the usage text.
> "--ports" (I didn't find this in the parse actually, should this be removed from lgopts?)
> "--noisy-lkup-num-reads-writes" (This one is misspelled in the usage text as the 2nd " noisy-lkup-num- writes ")
> "--no-numa" "--mp-anon" "--enable-scatter" There 3 parameters are missing in usage text.

Thanks, I will check each of them.



^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v4 00/11] improve options help
  2021-03-09 23:31 [dpdk-dev] [PATCH 00/11] improve options help Thomas Monjalon
                   ` (13 preceding siblings ...)
  2021-03-12 18:17 ` [dpdk-dev] [PATCH v3 00/11] improve options help Thomas Monjalon
@ 2021-03-21 22:31 ` Thomas Monjalon
  2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 01/11] eal: explain argv behaviour during init Thomas Monjalon
                     ` (11 more replies)
  2021-04-05 19:29 ` [dpdk-dev] [PATCH v5 0/4] log level enhancements Thomas Monjalon
                   ` (2 subsequent siblings)
  17 siblings, 12 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-21 22:31 UTC (permalink / raw)
  To: dev; +Cc: david.marchand

The main intent of this series is to provide a nice help
for the --log-level option.
More patches are added to improve options help in general.


v4:
    - fix more misses in testpmd help
    - add some "Fixes:" lines
v3:
    - fix use of RTE_LOG_MAX
    - accept (with warning) log level higher than RTE_LOG_MAX
v2:
    - fix use of the new macro RTE_LOG_MAX in level parsing
    - improve parameters type and name while moving functions


Thomas Monjalon (11):
  eal: explain argv behaviour during init
  eal: improve options usage text
  eal: use macros for help option
  eal: move private log functions
  eal: introduce maximum log level macro
  eal: catch invalid log level number
  eal: add log level help
  app: fix exit messages
  app: hook in EAL usage help
  app/regex: fix usage text
  app/testpmd: fix usage text

 app/pdump/main.c                              |  2 +
 app/proc-info/main.c                          |  2 +
 app/test-acl/main.c                           |  2 +
 app/test-bbdev/main.c                         |  3 +-
 app/test-compress-perf/comp_perf_options.h    |  2 +
 .../comp_perf_options_parse.c                 | 10 +--
 app/test-compress-perf/main.c                 |  3 +-
 app/test-crypto-perf/cperf_options.h          |  2 +
 app/test-crypto-perf/cperf_options_parsing.c  | 10 +--
 app/test-crypto-perf/main.c                   |  3 +-
 app/test-fib/main.c                           |  8 ++
 app/test-flow-perf/main.c                     | 63 ++++++++--------
 app/test-pmd/parameters.c                     | 43 +++--------
 app/test-pmd/testpmd.c                        |  2 +
 app/test-pmd/testpmd.h                        |  1 +
 app/test-regex/main.c                         | 10 +--
 app/test-sad/main.c                           |  7 ++
 lib/librte_eal/common/eal_common_log.c        | 50 ++++++++-----
 lib/librte_eal/common/eal_common_options.c    | 73 ++++++++++++-------
 lib/librte_eal/common/eal_log.h               | 32 ++++++++
 lib/librte_eal/common/eal_private.h           | 29 --------
 lib/librte_eal/freebsd/eal.c                  | 10 +--
 lib/librte_eal/include/rte_eal.h              |  2 +
 lib/librte_eal/include/rte_log.h              | 12 +++
 lib/librte_eal/linux/eal.c                    | 17 +++--
 lib/librte_eal/linux/eal_log.c                |  4 +-
 lib/librte_eal/version.map                    |  1 +
 lib/librte_eal/windows/eal.c                  | 15 ++--
 lib/librte_eal/windows/eal_log.c              |  6 +-
 29 files changed, 247 insertions(+), 177 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_log.h

-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v4 01/11] eal: explain argv behaviour during init
  2021-03-21 22:31 ` [dpdk-dev] [PATCH v4 " Thomas Monjalon
@ 2021-03-21 22:31   ` Thomas Monjalon
  2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 02/11] eal: improve options usage text Thomas Monjalon
                     ` (10 subsequent siblings)
  11 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-21 22:31 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, Bruce Richardson, Andrew Rybchenko

After argument parsing done by rte_eal_init(),
the remaining arguments are to be parsed by the application
by progressing in the argv array.
In this context, the first string represented by argv[0] is still
the same program name as the original argv[0],
while the next strings are the application arguments.
This is because rte_eal_init() manipulates the argv array
after EAL parsing, before returning to the application.

This note was missing in the doxygen comment of the API.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 lib/librte_eal/include/rte_eal.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/librte_eal/include/rte_eal.h b/lib/librte_eal/include/rte_eal.h
index eaf6469e50..0cbeedb594 100644
--- a/lib/librte_eal/include/rte_eal.h
+++ b/lib/librte_eal/include/rte_eal.h
@@ -76,6 +76,8 @@ int rte_eal_iopl_init(void);
  * @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.
+ *   The program name pointer argv[0] is copied into the last parsed argv
+ *   so that argv[0] is still the same after deducing the parsed arguments.
  * @return
  *   - On success, the number of parsed arguments, which is greater or
  *     equal to zero. After the call to rte_eal_init(),
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v4 02/11] eal: improve options usage text
  2021-03-21 22:31 ` [dpdk-dev] [PATCH v4 " Thomas Monjalon
  2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 01/11] eal: explain argv behaviour during init Thomas Monjalon
@ 2021-03-21 22:31   ` Thomas Monjalon
  2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 03/11] eal: use macros for help option Thomas Monjalon
                     ` (9 subsequent siblings)
  11 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-21 22:31 UTC (permalink / raw)
  To: dev
  Cc: david.marchand, Bruce Richardson, Andrew Rybchenko,
	Dmitry Kozlyuk, Narcisa Ana Maria Vasile, Dmitry Malloy,
	Pallavi Kadam

The description of the EAL options was printed before the application
description provided via the hook.
It is better to let the application print the global syntax
and describes the detail of the EAL options below.

Also, some useless lines are removed,
and the alignment of few options is fixed.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 lib/librte_eal/common/eal_common_options.c | 11 +++++------
 lib/librte_eal/freebsd/eal.c               |  8 ++++----
 lib/librte_eal/linux/eal.c                 | 12 ++++++------
 lib/librte_eal/windows/eal.c               | 10 ++++------
 4 files changed, 19 insertions(+), 22 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 622c7bc429..0635b0d4ce 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -2022,8 +2022,7 @@ rte_vect_set_max_simd_bitwidth(uint16_t bitwidth)
 void
 eal_common_usage(void)
 {
-	printf("[options]\n\n"
-	       "EAL common options:\n"
+	printf("EAL common options:\n"
 	       "  -c COREMASK         Hexadecimal bitmask of cores to run on\n"
 	       "  -l CORELIST         List of cores to run on\n"
 	       "                      The argument format is <c1>[-c2][,c3[-c4],...]\n"
@@ -2053,7 +2052,7 @@ eal_common_usage(void)
 	       "  --"OPT_VDEV"              Add a virtual device.\n"
 	       "                      The argument format is <driver><id>[,key=val,...]\n"
 	       "                      (ex: --vdev=net_pcap0,iface=eth2).\n"
-	       "  --"OPT_IOVA_MODE"   Set IOVA mode. 'pa' for IOVA_PA\n"
+	       "  --"OPT_IOVA_MODE"         Set IOVA mode. 'pa' for IOVA_PA\n"
 	       "                      'va' for IOVA_VA\n"
 	       "  -d LIB.so|DIR       Add a driver or driver directory\n"
 	       "                      (can be used multiple times)\n"
@@ -2092,11 +2091,11 @@ eal_common_usage(void)
 #endif /* !RTE_EXEC_ENV_WINDOWS */
 	       "  -v                  Display version information on startup\n"
 	       "  -h, --help          This help\n"
-	       "  --"OPT_IN_MEMORY"   Operate entirely in memory. This will\n"
+	       "  --"OPT_IN_MEMORY"         Operate entirely in memory. This will\n"
 	       "                      disable secondary process support\n"
 	       "  --"OPT_BASE_VIRTADDR"     Base virtual address\n"
-	       "  --"OPT_TELEMETRY"   Enable telemetry support (on by default)\n"
-	       "  --"OPT_NO_TELEMETRY"   Disable telemetry support\n"
+	       "  --"OPT_TELEMETRY"         Enable telemetry support (on by default)\n"
+	       "  --"OPT_NO_TELEMETRY"      Disable telemetry support\n"
 	       "  --"OPT_FORCE_MAX_SIMD_BITWIDTH" Force the max SIMD bitwidth\n"
 	       "\nEAL options for DEBUG use only:\n"
 	       "  --"OPT_HUGE_UNLINK"       Unlink hugepage files after init\n"
diff --git a/lib/librte_eal/freebsd/eal.c b/lib/librte_eal/freebsd/eal.c
index 62320d610f..6e414f5e7e 100644
--- a/lib/librte_eal/freebsd/eal.c
+++ b/lib/librte_eal/freebsd/eal.c
@@ -421,13 +421,13 @@ eal_usage(const char *prgname)
 {
 	rte_usage_hook_t hook = eal_get_application_usage_hook();
 
-	printf("\nUsage: %s ", prgname);
-	eal_common_usage();
-	/* Allow the application to print its usage message too if hook is set */
 	if (hook) {
-		printf("===== Application Usage =====\n\n");
+		/* Print application usage through EAL options parsing. */
 		(hook)(prgname);
+		printf("\n");
 	}
+
+	eal_common_usage();
 }
 
 static inline size_t
diff --git a/lib/librte_eal/linux/eal.c b/lib/librte_eal/linux/eal.c
index 9ffb4b3314..9aa585e04f 100644
--- a/lib/librte_eal/linux/eal.c
+++ b/lib/librte_eal/linux/eal.c
@@ -534,7 +534,12 @@ eal_usage(const char *prgname)
 {
 	rte_usage_hook_t hook = eal_get_application_usage_hook();
 
-	printf("\nUsage: %s ", prgname);
+	if (hook) {
+		/* Print application usage through EAL options parsing. */
+		(hook)(prgname);
+		printf("\n");
+	}
+
 	eal_common_usage();
 	printf("EAL Linux options:\n"
 	       "  --"OPT_SOCKET_MEM"        Memory to allocate on sockets (comma separated values)\n"
@@ -548,11 +553,6 @@ eal_usage(const char *prgname)
 	       "  --"OPT_SINGLE_FILE_SEGMENTS" Put all hugepage memory in single files\n"
 	       "  --"OPT_MATCH_ALLOCATIONS" Free hugepages exactly as allocated\n"
 	       "\n");
-	/* Allow the application to print its usage message too if hook is set */
-	if (hook) {
-		printf("===== Application Usage =====\n\n");
-		(hook)(prgname);
-	}
 }
 
 static int
diff --git a/lib/librte_eal/windows/eal.c b/lib/librte_eal/windows/eal.c
index 2fc3d6141c..ec13ac1a9f 100644
--- a/lib/librte_eal/windows/eal.c
+++ b/lib/librte_eal/windows/eal.c
@@ -79,15 +79,13 @@ eal_usage(const char *prgname)
 {
 	rte_usage_hook_t hook = eal_get_application_usage_hook();
 
-	printf("\nUsage: %s ", prgname);
-	eal_common_usage();
-	/* Allow the application to print its usage message too
-	 * if hook is set
-	 */
 	if (hook) {
-		printf("===== Application Usage =====\n\n");
+		/* Print application usage through EAL options parsing. */
 		(hook)(prgname);
+		printf("\n");
 	}
+
+	eal_common_usage();
 }
 
 /* Parse the arguments for --log-level only */
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v4 03/11] eal: use macros for help option
  2021-03-21 22:31 ` [dpdk-dev] [PATCH v4 " Thomas Monjalon
  2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 01/11] eal: explain argv behaviour during init Thomas Monjalon
  2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 02/11] eal: improve options usage text Thomas Monjalon
@ 2021-03-21 22:31   ` Thomas Monjalon
  2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 04/11] eal: move private log functions Thomas Monjalon
                     ` (8 subsequent siblings)
  11 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-21 22:31 UTC (permalink / raw)
  To: dev
  Cc: david.marchand, Bruce Richardson, Andrew Rybchenko,
	Dmitry Kozlyuk, Narcisa Ana Maria Vasile, Dmitry Malloy,
	Pallavi Kadam

The macros OPT_HELP and OPT_HELP_NUM were not used where appropriate.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 lib/librte_eal/common/eal_common_options.c | 2 +-
 lib/librte_eal/freebsd/eal.c               | 2 +-
 lib/librte_eal/linux/eal.c                 | 2 +-
 lib/librte_eal/windows/eal.c               | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 0635b0d4ce..52fedb81e5 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -2090,7 +2090,7 @@ eal_common_usage(void)
 	       "                      must be specified once only.\n"
 #endif /* !RTE_EXEC_ENV_WINDOWS */
 	       "  -v                  Display version information on startup\n"
-	       "  -h, --help          This help\n"
+	       "  -h, --"OPT_HELP"          This help\n"
 	       "  --"OPT_IN_MEMORY"         Operate entirely in memory. This will\n"
 	       "                      disable secondary process support\n"
 	       "  --"OPT_BASE_VIRTADDR"     Base virtual address\n"
diff --git a/lib/librte_eal/freebsd/eal.c b/lib/librte_eal/freebsd/eal.c
index 6e414f5e7e..91048efc35 100644
--- a/lib/librte_eal/freebsd/eal.c
+++ b/lib/librte_eal/freebsd/eal.c
@@ -549,7 +549,7 @@ eal_parse_args(int argc, char **argv)
 			}
 			break;
 		}
-		case 'h':
+		case OPT_HELP_NUM:
 			eal_usage(prgname);
 			exit(EXIT_SUCCESS);
 		default:
diff --git a/lib/librte_eal/linux/eal.c b/lib/librte_eal/linux/eal.c
index 9aa585e04f..c8ea590a05 100644
--- a/lib/librte_eal/linux/eal.c
+++ b/lib/librte_eal/linux/eal.c
@@ -716,7 +716,7 @@ eal_parse_args(int argc, char **argv)
 			continue;
 
 		switch (opt) {
-		case 'h':
+		case OPT_HELP_NUM:
 			eal_usage(prgname);
 			exit(EXIT_SUCCESS);
 
diff --git a/lib/librte_eal/windows/eal.c b/lib/librte_eal/windows/eal.c
index ec13ac1a9f..4dd2fc1403 100644
--- a/lib/librte_eal/windows/eal.c
+++ b/lib/librte_eal/windows/eal.c
@@ -158,7 +158,7 @@ eal_parse_args(int argc, char **argv)
 			continue;
 
 		switch (opt) {
-		case 'h':
+		case OPT_HELP_NUM:
 			eal_usage(prgname);
 			exit(EXIT_SUCCESS);
 		default:
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v4 04/11] eal: move private log functions
  2021-03-21 22:31 ` [dpdk-dev] [PATCH v4 " Thomas Monjalon
                     ` (2 preceding siblings ...)
  2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 03/11] eal: use macros for help option Thomas Monjalon
@ 2021-03-21 22:31   ` Thomas Monjalon
  2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 05/11] eal: introduce maximum log level macro Thomas Monjalon
                     ` (7 subsequent siblings)
  11 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-21 22:31 UTC (permalink / raw)
  To: dev
  Cc: david.marchand, Bruce Richardson, Andrew Rybchenko,
	Dmitry Kozlyuk, Narcisa Ana Maria Vasile, Dmitry Malloy,
	Pallavi Kadam

Some private log functions had a wrong "rte_" prefix.

All private log functions are moved from eal_private.h
to the new file eal_log.h:
	rte_eal_log_init -> eal_log_init
	rte_log_save_regexp -> eal_log_save_regexp
	rte_log_save_pattern -> eal_log_save_pattern
	eal_log_set_default

The static functions in the file eal_common_log.c are renamed:
	rte_log_save_level -> log_save_level
	rte_log_init -> log_init

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 lib/librte_eal/common/eal_common_log.c     | 18 ++++++++------
 lib/librte_eal/common/eal_common_options.c |  5 ++--
 lib/librte_eal/common/eal_log.h            | 27 ++++++++++++++++++++
 lib/librte_eal/common/eal_private.h        | 29 ----------------------
 lib/librte_eal/linux/eal.c                 |  3 ++-
 lib/librte_eal/linux/eal_log.c             |  4 +--
 lib/librte_eal/windows/eal.c               |  3 ++-
 lib/librte_eal/windows/eal_log.c           |  6 +++--
 8 files changed, 50 insertions(+), 45 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_log.h

diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c
index c5554badb2..aee7c44c6a 100644
--- a/lib/librte_eal/common/eal_common_log.c
+++ b/lib/librte_eal/common/eal_common_log.c
@@ -15,7 +15,7 @@
 #include <rte_log.h>
 #include <rte_per_lcore.h>
 
-#include "eal_private.h"
+#include "eal_log.h"
 
 struct rte_log_dynamic_type {
 	const char *name;
@@ -178,8 +178,8 @@ rte_log_set_level_regexp(const char *regex, uint32_t level)
  * Save the type string and the loglevel for later dynamic
  * logtypes which may register later.
  */
-static int rte_log_save_level(int priority,
-			      const char *regex, const char *pattern)
+static int
+log_save_level(uint32_t priority, const char *regex, const char *pattern)
 {
 	struct rte_eal_opt_loglevel *opt_ll = NULL;
 
@@ -207,9 +207,10 @@ static int rte_log_save_level(int priority,
 	return -1;
 }
 
-int rte_log_save_regexp(const char *regex, int tmp)
+int
+eal_log_save_regexp(const char *regex, uint32_t level)
 {
-	return rte_log_save_level(tmp, regex, NULL);
+	return log_save_level(level, regex, NULL);
 }
 
 /* set log level based on globbing pattern */
@@ -232,9 +233,10 @@ rte_log_set_level_pattern(const char *pattern, uint32_t level)
 	return 0;
 }
 
-int rte_log_save_pattern(const char *pattern, int priority)
+int
+eal_log_save_pattern(const char *pattern, uint32_t level)
 {
-	return rte_log_save_level(priority, NULL, pattern);
+	return log_save_level(level, NULL, pattern);
 }
 
 /* get the current loglevel for the message being processed */
@@ -376,7 +378,7 @@ static const struct logtype logtype_strings[] = {
 };
 
 /* Logging should be first initializer (before drivers and bus) */
-RTE_INIT_PRIO(rte_log_init, LOG)
+RTE_INIT_PRIO(log_init, LOG)
 {
 	uint32_t i;
 
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 52fedb81e5..02374ee09e 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -41,6 +41,7 @@
 #include "eal_options.h"
 #include "eal_filesystem.h"
 #include "eal_private.h"
+#include "eal_log.h"
 #ifndef RTE_EXEC_ENV_WINDOWS
 #include "eal_trace.h"
 #endif
@@ -1299,7 +1300,7 @@ eal_parse_log_level(const char *arg)
 				regex, priority);
 			goto fail;
 		}
-		if (rte_log_save_regexp(regex, priority) < 0)
+		if (eal_log_save_regexp(regex, priority) < 0)
 			goto fail;
 	} else if (pattern) {
 		if (rte_log_set_level_pattern(pattern, priority) < 0) {
@@ -1307,7 +1308,7 @@ eal_parse_log_level(const char *arg)
 				pattern, priority);
 			goto fail;
 		}
-		if (rte_log_save_pattern(pattern, priority) < 0)
+		if (eal_log_save_pattern(pattern, priority) < 0)
 			goto fail;
 	} else {
 		rte_log_set_global_level(priority);
diff --git a/lib/librte_eal/common/eal_log.h b/lib/librte_eal/common/eal_log.h
new file mode 100644
index 0000000000..684650a17b
--- /dev/null
+++ b/lib/librte_eal/common/eal_log.h
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2021 Mellanox Technologies, Ltd
+ */
+
+#ifndef EAL_LOG_H
+#define EAL_LOG_H
+
+#include <stdio.h>
+#include <stdint.h>
+
+/*
+ * Initialize the default log stream.
+ */
+int eal_log_init(const char *id, int facility);
+
+/*
+ * Determine where log data is written when no call to rte_openlog_stream.
+ */
+void eal_log_set_default(FILE *default_log);
+
+/*
+ * Save a log option for later.
+ */
+int eal_log_save_regexp(const char *regexp, uint32_t level);
+int eal_log_save_pattern(const char *pattern, uint32_t level);
+
+#endif /* EAL_LOG_H */
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index b8a0d20021..e3512111d9 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -79,19 +79,6 @@ struct rte_config *rte_eal_get_configuration(void);
  */
 int rte_eal_memzone_init(void);
 
-/**
- * Common log initialization function (private to eal).  Determines
- * where log data is written when no call to rte_openlog_stream is
- * in effect.
- *
- * @param default_log
- *   The default log stream to be used.
- * @return
- *   - 0 on success
- *   - Negative on error
- */
-void eal_log_set_default(FILE *default_log);
-
 /**
  * Fill configuration with number of physical and logical processors
  *
@@ -143,22 +130,6 @@ int rte_eal_memory_init(void);
  */
 int rte_eal_timer_init(void);
 
-/**
- * Init the default log stream
- *
- * This function is private to EAL.
- *
- * @return
- *   0 on success, negative on error
- */
-int rte_eal_log_init(const char *id, int facility);
-
-/**
- * Save the log regexp for later
- */
-int rte_log_save_regexp(const char *type, int priority);
-int rte_log_save_pattern(const char *pattern, int priority);
-
 /**
  * Init tail queues for non-EAL library structures. This is to allow
  * the rings, mempools, etc. lists to be shared among multiple processes
diff --git a/lib/librte_eal/linux/eal.c b/lib/librte_eal/linux/eal.c
index c8ea590a05..1e7264f1a2 100644
--- a/lib/librte_eal/linux/eal.c
+++ b/lib/librte_eal/linux/eal.c
@@ -58,6 +58,7 @@
 #include "eal_hugepages.h"
 #include "eal_memcfg.h"
 #include "eal_trace.h"
+#include "eal_log.h"
 #include "eal_options.h"
 #include "eal_vfio.h"
 #include "hotplug_mp.h"
@@ -1160,7 +1161,7 @@ rte_eal_init(int argc, char **argv)
 #endif
 	}
 
-	if (rte_eal_log_init(logid, internal_conf->syslog_facility) < 0) {
+	if (eal_log_init(logid, internal_conf->syslog_facility) < 0) {
 		rte_eal_init_alert("Cannot init logging.");
 		rte_errno = ENOMEM;
 		__atomic_store_n(&run_once, 0, __ATOMIC_RELAXED);
diff --git a/lib/librte_eal/linux/eal_log.c b/lib/librte_eal/linux/eal_log.c
index 2095df74c5..c0aa1007c4 100644
--- a/lib/librte_eal/linux/eal_log.c
+++ b/lib/librte_eal/linux/eal_log.c
@@ -17,7 +17,7 @@
 #include <rte_spinlock.h>
 #include <rte_log.h>
 
-#include "eal_private.h"
+#include "eal_log.h"
 
 /*
  * default log function
@@ -46,7 +46,7 @@ static cookie_io_functions_t console_log_func = {
  * once memzones are available.
  */
 int
-rte_eal_log_init(const char *id, int facility)
+eal_log_init(const char *id, int facility)
 {
 	FILE *log_stream;
 
diff --git a/lib/librte_eal/windows/eal.c b/lib/librte_eal/windows/eal.c
index 4dd2fc1403..5bca3ace1c 100644
--- a/lib/librte_eal/windows/eal.c
+++ b/lib/librte_eal/windows/eal.c
@@ -22,6 +22,7 @@
 
 #include "eal_hugepages.h"
 #include "eal_trace.h"
+#include "eal_log.h"
 #include "eal_windows.h"
 
 #define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL)
@@ -265,7 +266,7 @@ rte_eal_init(int argc, char **argv)
 		eal_get_internal_configuration();
 	int ret;
 
-	rte_eal_log_init(NULL, 0);
+	eal_log_init(NULL, 0);
 
 	eal_log_level_parse(argc, argv);
 
diff --git a/lib/librte_eal/windows/eal_log.c b/lib/librte_eal/windows/eal_log.c
index 875981f139..d4ea47f1c8 100644
--- a/lib/librte_eal/windows/eal_log.c
+++ b/lib/librte_eal/windows/eal_log.c
@@ -2,11 +2,13 @@
  * Copyright(c) 2017-2018 Intel Corporation
  */
 
-#include "eal_private.h"
+#include <rte_common.h>
+#include <rte_log.h>
+#include "eal_log.h"
 
 /* set the log to default function, called during eal init process. */
 int
-rte_eal_log_init(__rte_unused const char *id, __rte_unused int facility)
+eal_log_init(__rte_unused const char *id, __rte_unused int facility)
 {
 	rte_openlog_stream(stderr);
 
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v4 05/11] eal: introduce maximum log level macro
  2021-03-21 22:31 ` [dpdk-dev] [PATCH v4 " Thomas Monjalon
                     ` (3 preceding siblings ...)
  2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 04/11] eal: move private log functions Thomas Monjalon
@ 2021-03-21 22:31   ` Thomas Monjalon
  2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 06/11] eal: catch invalid log level number Thomas Monjalon
                     ` (6 subsequent siblings)
  11 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-21 22:31 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, Bruce Richardson, Andrew Rybchenko

RTE_DIM(...) and RTE_LOG_DEBUG were used to get the highest log level.
For better clarity a new constant RTE_LOG_MAX is introduced
and mapped to RTE_LOG_DEBUG.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 lib/librte_eal/common/eal_common_log.c     | 8 ++++----
 lib/librte_eal/common/eal_common_options.c | 2 +-
 lib/librte_eal/include/rte_log.h           | 1 +
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c
index aee7c44c6a..40cac36f89 100644
--- a/lib/librte_eal/common/eal_common_log.c
+++ b/lib/librte_eal/common/eal_common_log.c
@@ -140,7 +140,7 @@ rte_log_set_level(uint32_t type, uint32_t level)
 {
 	if (type >= rte_logs.dynamic_types_len)
 		return -1;
-	if (level > RTE_LOG_DEBUG)
+	if (level > RTE_LOG_MAX)
 		return -1;
 
 	rte_logs.dynamic_types[type].loglevel = level;
@@ -155,7 +155,7 @@ rte_log_set_level_regexp(const char *regex, uint32_t level)
 	regex_t r;
 	size_t i;
 
-	if (level > RTE_LOG_DEBUG)
+	if (level > RTE_LOG_MAX)
 		return -1;
 
 	if (regcomp(&r, regex, 0) != 0)
@@ -219,7 +219,7 @@ rte_log_set_level_pattern(const char *pattern, uint32_t level)
 {
 	size_t i;
 
-	if (level > RTE_LOG_DEBUG)
+	if (level > RTE_LOG_MAX)
 		return -1;
 
 	for (i = 0; i < rte_logs.dynamic_types_len; i++) {
@@ -323,7 +323,7 @@ rte_log_register_type_and_pick_level(const char *name, uint32_t level_def)
 		return type;
 
 	TAILQ_FOREACH(opt_ll, &opt_loglevel_list, next) {
-		if (opt_ll->level > RTE_LOG_DEBUG)
+		if (opt_ll->level > RTE_LOG_MAX)
 			continue;
 
 		if (opt_ll->pattern) {
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 02374ee09e..3675e55fc9 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -1249,7 +1249,7 @@ eal_parse_log_priority(const char *level)
 		return -1;
 
 	/* look for named values, skip 0 which is not a valid level */
-	for (i = 1; i < RTE_DIM(levels); i++) {
+	for (i = 1; i <= RTE_LOG_MAX; i++) {
 		if (strncmp(levels[i], level, len) == 0)
 			return i;
 	}
diff --git a/lib/librte_eal/include/rte_log.h b/lib/librte_eal/include/rte_log.h
index 173004fd71..394e8682b9 100644
--- a/lib/librte_eal/include/rte_log.h
+++ b/lib/librte_eal/include/rte_log.h
@@ -72,6 +72,7 @@ extern "C" {
 #define RTE_LOG_NOTICE   6U  /**< Normal but significant condition. */
 #define RTE_LOG_INFO     7U  /**< Informational.                    */
 #define RTE_LOG_DEBUG    8U  /**< Debug-level messages.             */
+#define RTE_LOG_MAX RTE_LOG_DEBUG /**< Most detailed log level.     */
 
 /**
  * Change the stream that will be used by the logging system.
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v4 06/11] eal: catch invalid log level number
  2021-03-21 22:31 ` [dpdk-dev] [PATCH v4 " Thomas Monjalon
                     ` (4 preceding siblings ...)
  2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 05/11] eal: introduce maximum log level macro Thomas Monjalon
@ 2021-03-21 22:31   ` Thomas Monjalon
  2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 07/11] eal: add log level help Thomas Monjalon
                     ` (5 subsequent siblings)
  11 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-21 22:31 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, Bruce Richardson, Andrew Rybchenko

The parsing check for invalid log level was not trying to catch
irrelevant numeric values.
A log level 0 is now a failure in options parsing so it can be caught early.
A log level higher than the max (8) is accepted with a warning message.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 lib/librte_eal/common/eal_common_options.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 3675e55fc9..2df3ae04ea 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -1289,10 +1289,15 @@ eal_parse_log_level(const char *arg)
 	}
 
 	priority = eal_parse_log_priority(level);
-	if (priority < 0) {
-		fprintf(stderr, "invalid log priority: %s\n", level);
+	if (priority <= 0) {
+		fprintf(stderr, "Invalid log level: %s\n", level);
 		goto fail;
 	}
+	if (priority > (int)RTE_LOG_MAX) {
+		fprintf(stderr, "Log level %d higher than maximum (%d)\n",
+				priority, RTE_LOG_MAX);
+		priority = RTE_LOG_MAX;
+	}
 
 	if (regex) {
 		if (rte_log_set_level_regexp(regex, priority) < 0) {
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v4 07/11] eal: add log level help
  2021-03-21 22:31 ` [dpdk-dev] [PATCH v4 " Thomas Monjalon
                     ` (5 preceding siblings ...)
  2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 06/11] eal: catch invalid log level number Thomas Monjalon
@ 2021-03-21 22:31   ` Thomas Monjalon
  2021-03-23 13:37     ` David Marchand
  2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 08/11] app: fix exit messages Thomas Monjalon
                     ` (4 subsequent siblings)
  11 siblings, 1 reply; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-21 22:31 UTC (permalink / raw)
  To: dev
  Cc: david.marchand, Bruce Richardson, Andrew Rybchenko, Ray Kinsella,
	Neil Horman

The option --log-level was not completely described in the usage text,
and it was difficult to guess the names of the log types and levels.

A new value "help" is accepted after --log-level to give more details
about the syntax and listing the log types and levels.

The array "levels" used for level name parsing is replaced with
a (modified) existing function which was used in rte_log_dump().

The new function rte_log_list_types() is exported in the API
for allowing an application to give this info to the user
if not exposing the EAL option --log-level.
The list of log types cannot include all drivers if not linked in the
application (shared object plugin case).

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 lib/librte_eal/common/eal_common_log.c     | 24 +++++++++---
 lib/librte_eal/common/eal_common_options.c | 44 +++++++++++++++-------
 lib/librte_eal/common/eal_log.h            |  5 +++
 lib/librte_eal/include/rte_log.h           | 11 ++++++
 lib/librte_eal/version.map                 |  1 +
 5 files changed, 67 insertions(+), 18 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c
index 40cac36f89..d695b04068 100644
--- a/lib/librte_eal/common/eal_common_log.c
+++ b/lib/librte_eal/common/eal_common_log.c
@@ -397,12 +397,12 @@ RTE_INIT_PRIO(log_init, LOG)
 	rte_logs.dynamic_types_len = RTE_LOGTYPE_FIRST_EXT_ID;
 }
 
-static const char *
-loglevel_to_string(uint32_t level)
+const char *
+eal_log_level2str(uint32_t level)
 {
 	switch (level) {
 	case 0: return "disabled";
-	case RTE_LOG_EMERG: return "emerg";
+	case RTE_LOG_EMERG: return "emergency";
 	case RTE_LOG_ALERT: return "alert";
 	case RTE_LOG_CRIT: return "critical";
 	case RTE_LOG_ERR: return "error";
@@ -414,6 +414,20 @@ loglevel_to_string(uint32_t level)
 	}
 }
 
+/* Dump name of each logtype, one per line. */
+void
+rte_log_list_types(FILE *out, const char *prefix)
+{
+	size_t type;
+
+	for (type = 0; type < rte_logs.dynamic_types_len; ++type) {
+		if (rte_logs.dynamic_types[type].name == NULL)
+			continue;
+		fprintf(out, "%s%s\n",
+				prefix, rte_logs.dynamic_types[type].name);
+	}
+}
+
 /* dump global level and registered log types */
 void
 rte_log_dump(FILE *f)
@@ -421,14 +435,14 @@ rte_log_dump(FILE *f)
 	size_t i;
 
 	fprintf(f, "global log level is %s\n",
-		loglevel_to_string(rte_log_get_global_level()));
+		eal_log_level2str(rte_log_get_global_level()));
 
 	for (i = 0; i < rte_logs.dynamic_types_len; i++) {
 		if (rte_logs.dynamic_types[i].name == NULL)
 			continue;
 		fprintf(f, "id %zu: %s, level is %s\n",
 			i, rte_logs.dynamic_types[i].name,
-			loglevel_to_string(rte_logs.dynamic_types[i].loglevel));
+			eal_log_level2str(rte_logs.dynamic_types[i].loglevel));
 	}
 }
 
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 2df3ae04ea..1da6583d71 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -1227,19 +1227,31 @@ eal_parse_syslog(const char *facility, struct internal_config *conf)
 }
 #endif
 
+static void
+eal_log_usage(void)
+{
+	unsigned int level;
+
+	printf("Log type is a pattern matching items of this list"
+			" (plugins may be missing):\n");
+	rte_log_list_types(stdout, "\t");
+	printf("\n");
+	printf("Syntax using globbing pattern:     ");
+	printf("--"OPT_LOG_LEVEL" pattern:level\n");
+	printf("Syntax using regular expression:   ");
+	printf("--"OPT_LOG_LEVEL" regexp,level\n");
+	printf("Syntax for the global level:       ");
+	printf("--"OPT_LOG_LEVEL" level\n");
+	printf("Logs are emitted if allowed by both global and specific levels.\n");
+	printf("\n");
+	printf("Log level can be a number or the first letters of its name:\n");
+	for (level = 1; level <= RTE_LOG_MAX; level++)
+		printf("\t%d   %s\n", level, eal_log_level2str(level));
+}
+
 static int
 eal_parse_log_priority(const char *level)
 {
-	static const char * const levels[] = {
-		[RTE_LOG_EMERG]   = "emergency",
-		[RTE_LOG_ALERT]   = "alert",
-		[RTE_LOG_CRIT]    = "critical",
-		[RTE_LOG_ERR]     = "error",
-		[RTE_LOG_WARNING] = "warning",
-		[RTE_LOG_NOTICE]  = "notice",
-		[RTE_LOG_INFO]    = "info",
-		[RTE_LOG_DEBUG]   = "debug",
-	};
 	size_t len = strlen(level);
 	unsigned long tmp;
 	char *end;
@@ -1250,7 +1262,7 @@ eal_parse_log_priority(const char *level)
 
 	/* look for named values, skip 0 which is not a valid level */
 	for (i = 1; i <= RTE_LOG_MAX; i++) {
-		if (strncmp(levels[i], level, len) == 0)
+		if (strncmp(eal_log_level2str(i), level, len) == 0)
 			return i;
 	}
 
@@ -1274,6 +1286,11 @@ eal_parse_log_level(const char *arg)
 	char *str, *level;
 	int priority;
 
+	if (strcmp(arg, "help") == 0) {
+		eal_log_usage();
+		exit(EXIT_SUCCESS);
+	}
+
 	str = strdup(arg);
 	if (str == NULL)
 		return -1;
@@ -2067,9 +2084,10 @@ eal_common_usage(void)
 #ifndef RTE_EXEC_ENV_WINDOWS
 	       "  --"OPT_SYSLOG"            Set syslog facility\n"
 #endif
-	       "  --"OPT_LOG_LEVEL"=<int>   Set global log level\n"
-	       "  --"OPT_LOG_LEVEL"=<type-match>:<int>\n"
+	       "  --"OPT_LOG_LEVEL"=<level> Set global log level\n"
+	       "  --"OPT_LOG_LEVEL"=<type-match>:<level>\n"
 	       "                      Set specific log level\n"
+	       "  --"OPT_LOG_LEVEL"=help    Show log types and levels\n"
 #ifndef RTE_EXEC_ENV_WINDOWS
 	       "  --"OPT_TRACE"=<regex-match>\n"
 	       "                      Enable trace based on regular expression trace name.\n"
diff --git a/lib/librte_eal/common/eal_log.h b/lib/librte_eal/common/eal_log.h
index 684650a17b..c784fa6043 100644
--- a/lib/librte_eal/common/eal_log.h
+++ b/lib/librte_eal/common/eal_log.h
@@ -24,4 +24,9 @@ void eal_log_set_default(FILE *default_log);
 int eal_log_save_regexp(const char *regexp, uint32_t level);
 int eal_log_save_pattern(const char *pattern, uint32_t level);
 
+/*
+ * Convert log level to string.
+ */
+const char *eal_log_level2str(uint32_t level);
+
 #endif /* EAL_LOG_H */
diff --git a/lib/librte_eal/include/rte_log.h b/lib/librte_eal/include/rte_log.h
index 394e8682b9..e6192892c3 100644
--- a/lib/librte_eal/include/rte_log.h
+++ b/lib/librte_eal/include/rte_log.h
@@ -240,6 +240,17 @@ int rte_log_register(const char *name);
 __rte_experimental
 int rte_log_register_type_and_pick_level(const char *name, uint32_t level_def);
 
+/**
+ * Dump name of each logtype, one per line.
+ *
+ * @param out
+ *   Stream where the list is sent.
+ * @param prefix
+ *   String preceding each logtype in the output.
+ */
+__rte_experimental
+void rte_log_list_types(FILE *out, const char *prefix);
+
 /**
  * Dump log information.
  *
diff --git a/lib/librte_eal/version.map b/lib/librte_eal/version.map
index 48a2b55d57..c0686ebaf2 100644
--- a/lib/librte_eal/version.map
+++ b/lib/librte_eal/version.map
@@ -415,6 +415,7 @@ EXPERIMENTAL {
 	rte_thread_tls_value_set;
 
 	# added in 21.05
+	rte_log_list_types;
 	rte_version_minor;
 	rte_version_month;
 	rte_version_prefix;
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v4 08/11] app: fix exit messages
  2021-03-21 22:31 ` [dpdk-dev] [PATCH v4 " Thomas Monjalon
                     ` (6 preceding siblings ...)
  2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 07/11] eal: add log level help Thomas Monjalon
@ 2021-03-21 22:31   ` Thomas Monjalon
  2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 09/11] app: hook in EAL usage help Thomas Monjalon
                     ` (3 subsequent siblings)
  11 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-21 22:31 UTC (permalink / raw)
  To: dev
  Cc: david.marchand, Wisam Jaddo, Ori Kam, Bruce Richardson,
	Andrew Rybchenko, Declan Doherty, Ciara Power, Xiaoyun Li

Some applications were printing useless messages with rte_exit()
after showing the help. Using exit() is enough in this case.

Some applications were using a redundant printf or fprintf() before
calling rte_exit(). The messages are unified in a single rte_exit().

Some rte_exit() calls were missing a line feed or returning a wrong code.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Wisam Jaddo <wisamm@nvidia.com>
Acked-by: Ori Kam <orika@nvidia.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 .../comp_perf_options_parse.c                 |  2 +-
 app/test-crypto-perf/cperf_options_parsing.c  |  2 +-
 app/test-flow-perf/main.c                     | 59 +++++++++----------
 app/test-pmd/parameters.c                     |  4 +-
 app/test-regex/main.c                         |  3 +-
 5 files changed, 33 insertions(+), 37 deletions(-)

diff --git a/app/test-compress-perf/comp_perf_options_parse.c b/app/test-compress-perf/comp_perf_options_parse.c
index 04a8d2fbee..019eddb7bd 100644
--- a/app/test-compress-perf/comp_perf_options_parse.c
+++ b/app/test-compress-perf/comp_perf_options_parse.c
@@ -620,7 +620,7 @@ comp_perf_options_parse(struct comp_test_data *test_data, int argc, char **argv)
 		switch (opt) {
 		case 'h':
 			usage(argv[0]);
-			rte_exit(EXIT_SUCCESS, "Displayed help\n");
+			exit(EXIT_SUCCESS);
 			break;
 		/* long options */
 		case 0:
diff --git a/app/test-crypto-perf/cperf_options_parsing.c b/app/test-crypto-perf/cperf_options_parsing.c
index 0466f7baf8..40b6dfb648 100644
--- a/app/test-crypto-perf/cperf_options_parsing.c
+++ b/app/test-crypto-perf/cperf_options_parsing.c
@@ -983,7 +983,7 @@ cperf_options_parse(struct cperf_options *options, int argc, char **argv)
 		switch (opt) {
 		case 'h':
 			usage(argv[0]);
-			rte_exit(EXIT_SUCCESS, "Displayed help\n");
+			exit(EXIT_SUCCESS);
 			break;
 		/* long options */
 		case 0:
diff --git a/app/test-flow-perf/main.c b/app/test-flow-perf/main.c
index 99d0463456..0aef767350 100644
--- a/app/test-flow-perf/main.c
+++ b/app/test-flow-perf/main.c
@@ -639,7 +639,7 @@ args_parse(int argc, char **argv)
 		case 0:
 			if (strcmp(lgopts[opt_idx].name, "help") == 0) {
 				usage(argv[0]);
-				rte_exit(EXIT_SUCCESS, "Displayed help\n");
+				exit(EXIT_SUCCESS);
 			}
 
 			if (strcmp(lgopts[opt_idx].name, "group") == 0) {
@@ -647,7 +647,7 @@ args_parse(int argc, char **argv)
 				if (n >= 0)
 					flow_group = n;
 				else
-					rte_exit(EXIT_SUCCESS,
+					rte_exit(EXIT_FAILURE,
 						"flow group should be >= 0\n");
 				printf("group %d / ", flow_group);
 			}
@@ -667,7 +667,7 @@ args_parse(int argc, char **argv)
 				if (n > 0)
 					hairpin_queues_num = n;
 				else
-					rte_exit(EXIT_SUCCESS,
+					rte_exit(EXIT_FAILURE,
 						"Hairpin queues should be > 0\n");
 
 				flow_actions[actions_idx++] =
@@ -680,7 +680,7 @@ args_parse(int argc, char **argv)
 				if (n > 0)
 					hairpin_queues_num = n;
 				else
-					rte_exit(EXIT_SUCCESS,
+					rte_exit(EXIT_FAILURE,
 						"Hairpin queues should be > 0\n");
 
 				flow_actions[actions_idx++] =
@@ -704,11 +704,9 @@ args_parse(int argc, char **argv)
 							break;
 						}
 						/* Reached last item with no match */
-						if (i == (RTE_DIM(flow_options) - 1)) {
-							fprintf(stderr, "Invalid encap item: %s\n", token);
-							usage(argv[0]);
-							rte_exit(EXIT_SUCCESS, "Invalid encap item\n");
-						}
+						if (i == (RTE_DIM(flow_options) - 1))
+							rte_exit(EXIT_FAILURE,
+								"Invalid encap item: %s\n", token);
 					}
 					token = strtok(NULL, ",");
 				}
@@ -730,11 +728,9 @@ args_parse(int argc, char **argv)
 							break;
 						}
 						/* Reached last item with no match */
-						if (i == (RTE_DIM(flow_options) - 1)) {
-							fprintf(stderr, "Invalid decap item: %s\n", token);
-							usage(argv[0]);
-							rte_exit(EXIT_SUCCESS, "Invalid decap item\n");
-						}
+						if (i == (RTE_DIM(flow_options) - 1))
+							rte_exit(EXIT_FAILURE,
+								"Invalid decap item %s\n", token);
 					}
 					token = strtok(NULL, ",");
 				}
@@ -747,9 +743,9 @@ args_parse(int argc, char **argv)
 				if (n >= DEFAULT_RULES_BATCH)
 					rules_batch = n;
 				else {
-					printf("\n\nrules_batch should be >= %d\n",
+					rte_exit(EXIT_FAILURE,
+						"rules_batch should be >= %d\n",
 						DEFAULT_RULES_BATCH);
-					rte_exit(EXIT_SUCCESS, " ");
 				}
 			}
 			if (strcmp(lgopts[opt_idx].name,
@@ -758,7 +754,8 @@ args_parse(int argc, char **argv)
 				if (n >= (int) rules_batch)
 					rules_count = n;
 				else {
-					printf("\n\nrules_count should be >= %d\n",
+					rte_exit(EXIT_FAILURE,
+						"rules_count should be >= %d\n",
 						rules_batch);
 				}
 			}
@@ -786,23 +783,23 @@ args_parse(int argc, char **argv)
 			if (strcmp(lgopts[opt_idx].name, "cores") == 0) {
 				n = atoi(optarg);
 				if ((int) rte_lcore_count() <= n) {
-					printf("\nError: you need %d cores to run on multi-cores\n"
+					rte_exit(EXIT_FAILURE,
+						"Error: you need %d cores to run on multi-cores\n"
 						"Existing cores are: %d\n", n, rte_lcore_count());
-					rte_exit(EXIT_FAILURE, " ");
 				}
 				if (n <= RTE_MAX_LCORE && n > 0)
 					mc_pool.cores_count = n;
 				else {
-					printf("Error: cores count must be > 0 "
-						" and < %d\n", RTE_MAX_LCORE);
-					rte_exit(EXIT_FAILURE, " ");
+					rte_exit(EXIT_FAILURE,
+						"Error: cores count must be > 0 and < %d\n",
+						RTE_MAX_LCORE);
 				}
 			}
 			break;
 		default:
-			fprintf(stderr, "Invalid option: %s\n", argv[optind]);
 			usage(argv[0]);
-			rte_exit(EXIT_SUCCESS, "Invalid option\n");
+			rte_exit(EXIT_FAILURE, "Invalid option: %s\n",
+					argv[optind]);
 			break;
 		}
 	}
@@ -936,7 +933,7 @@ create_meter_rule(int port_id, uint32_t counter)
 		printf("Port %u create meter idx(%d) error(%d) message: %s\n",
 			port_id, counter, error.type,
 			error.message ? error.message : "(no stated reason)");
-		rte_exit(EXIT_FAILURE, "error in creating meter");
+		rte_exit(EXIT_FAILURE, "Error in creating meter\n");
 	}
 }
 
@@ -949,7 +946,7 @@ destroy_meter_rule(int port_id, uint32_t counter)
 		printf("Port %u destroy meter(%d) error(%d) message: %s\n",
 			port_id, counter, error.type,
 			error.message ? error.message : "(no stated reason)");
-		rte_exit(EXIT_FAILURE, "Error in deleting meter rule");
+		rte_exit(EXIT_FAILURE, "Error in deleting meter rule\n");
 	}
 }
 
@@ -1097,7 +1094,7 @@ destroy_flows(int port_id, uint8_t core_id, struct rte_flow **flows_list)
 		memset(&error, 0x33, sizeof(error));
 		if (rte_flow_destroy(port_id, flows_list[i], &error)) {
 			print_flow_error(error);
-			rte_exit(EXIT_FAILURE, "Error in deleting flow");
+			rte_exit(EXIT_FAILURE, "Error in deleting flow\n");
 		}
 
 		/*
@@ -1160,7 +1157,7 @@ insert_flows(int port_id, uint8_t core_id)
 	flows_list = rte_zmalloc("flows_list",
 		(sizeof(struct rte_flow *) * rules_count_per_core) + 1, 0);
 	if (flows_list == NULL)
-		rte_exit(EXIT_FAILURE, "No Memory available!");
+		rte_exit(EXIT_FAILURE, "No Memory available!\n");
 
 	cpu_time_used = 0;
 	flow_index = 0;
@@ -1180,7 +1177,7 @@ insert_flows(int port_id, uint8_t core_id)
 
 		if (flow == NULL) {
 			print_flow_error(error);
-			rte_exit(EXIT_FAILURE, "error in creating flow");
+			rte_exit(EXIT_FAILURE, "Error in creating flow\n");
 		}
 		flows_list[flow_index++] = flow;
 	}
@@ -1199,7 +1196,7 @@ insert_flows(int port_id, uint8_t core_id)
 
 		if (!flow) {
 			print_flow_error(error);
-			rte_exit(EXIT_FAILURE, "error in creating flow");
+			rte_exit(EXIT_FAILURE, "Error in creating flow\n");
 		}
 
 		flows_list[flow_index++] = flow;
@@ -1517,7 +1514,7 @@ packet_per_second_stats(void)
 	old = rte_zmalloc("old",
 		sizeof(struct lcore_info) * RTE_MAX_LCORE, 0);
 	if (old == NULL)
-		rte_exit(EXIT_FAILURE, "No Memory available!");
+		rte_exit(EXIT_FAILURE, "No Memory available!\n");
 
 	memcpy(old, lcore_infos,
 		sizeof(struct lcore_info) * RTE_MAX_LCORE);
diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c
index a326c8ce4f..b7d4ef76b0 100644
--- a/app/test-pmd/parameters.c
+++ b/app/test-pmd/parameters.c
@@ -671,7 +671,7 @@ launch_args_parse(int argc, char** argv)
 		case 0: /*long options */
 			if (!strcmp(lgopts[opt_idx].name, "help")) {
 				usage(argv[0]);
-				rte_exit(EXIT_SUCCESS, "Displayed help\n");
+				exit(EXIT_SUCCESS);
 			}
 #ifdef RTE_LIB_CMDLINE
 			if (!strcmp(lgopts[opt_idx].name, "interactive")) {
@@ -1413,7 +1413,7 @@ launch_args_parse(int argc, char** argv)
 			break;
 		case 'h':
 			usage(argv[0]);
-			rte_exit(EXIT_SUCCESS, "Displayed help\n");
+			exit(EXIT_SUCCESS);
 			break;
 		default:
 			usage(argv[0]);
diff --git a/app/test-regex/main.c b/app/test-regex/main.c
index aea4fa6b88..7bb87bb1b8 100644
--- a/app/test-regex/main.c
+++ b/app/test-regex/main.c
@@ -154,9 +154,8 @@ args_parse(int argc, char **argv, char *rules_file, char *data_file,
 			usage("RegEx test app");
 			break;
 		default:
-			fprintf(stderr, "Invalid option: %s\n", argv[optind]);
 			usage("RegEx test app");
-			rte_exit(EXIT_FAILURE, "Invalid option\n");
+			rte_exit(EXIT_FAILURE, "Invalid option: %s\n", argv[optind]);
 			break;
 		}
 	}
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v4 09/11] app: hook in EAL usage help
  2021-03-21 22:31 ` [dpdk-dev] [PATCH v4 " Thomas Monjalon
                     ` (7 preceding siblings ...)
  2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 08/11] app: fix exit messages Thomas Monjalon
@ 2021-03-21 22:31   ` Thomas Monjalon
  2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 10/11] app/regex: fix usage text Thomas Monjalon
                     ` (2 subsequent siblings)
  11 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-21 22:31 UTC (permalink / raw)
  To: dev
  Cc: david.marchand, Wisam Jaddo, Bruce Richardson, Andrew Rybchenko,
	Reshma Pattan, Maryam Tahhan, Konstantin Ananyev,
	Nicolas Chautru, Declan Doherty, Ciara Power, Vladimir Medvedkin,
	Xiaoyun Li, Ori Kam, Bernard Iremonger

Use rte_set_application_usage_hook() in the test applications,
so the full help including EAL options can be printed in one go
with the EAL option -h or --help.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Wisam Jaddo <wisamm@nvidia.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 app/pdump/main.c                                 | 2 ++
 app/proc-info/main.c                             | 2 ++
 app/test-acl/main.c                              | 2 ++
 app/test-bbdev/main.c                            | 3 ++-
 app/test-compress-perf/comp_perf_options.h       | 2 ++
 app/test-compress-perf/comp_perf_options_parse.c | 8 ++++----
 app/test-compress-perf/main.c                    | 3 ++-
 app/test-crypto-perf/cperf_options.h             | 2 ++
 app/test-crypto-perf/cperf_options_parsing.c     | 8 ++++----
 app/test-crypto-perf/main.c                      | 3 ++-
 app/test-fib/main.c                              | 8 ++++++++
 app/test-flow-perf/main.c                        | 4 +++-
 app/test-pmd/parameters.c                        | 4 ++--
 app/test-pmd/testpmd.c                           | 2 ++
 app/test-pmd/testpmd.h                           | 1 +
 app/test-regex/main.c                            | 3 ++-
 app/test-sad/main.c                              | 7 +++++++
 17 files changed, 49 insertions(+), 15 deletions(-)

diff --git a/app/pdump/main.c b/app/pdump/main.c
index 63bbe65cd8..8641017f48 100644
--- a/app/pdump/main.c
+++ b/app/pdump/main.c
@@ -974,6 +974,8 @@ main(int argc, char **argv)
 	char mp_flag[] = "--proc-type=secondary";
 	char *argp[argc + 2];
 
+	rte_set_application_usage_hook(pdump_usage);
+
 	/* catch ctrl-c so we can print on exit */
 	signal(SIGINT, signal_handler);
 
diff --git a/app/proc-info/main.c b/app/proc-info/main.c
index b9587f7ded..e7d86bfa9d 100644
--- a/app/proc-info/main.c
+++ b/app/proc-info/main.c
@@ -1361,6 +1361,8 @@ main(int argc, char **argv)
 	char *argp[argc + 4];
 	uint16_t nb_ports;
 
+	rte_set_application_usage_hook(proc_info_usage);
+
 	/* preparse app arguments */
 	ret = proc_info_preparse_args(argc, argv);
 	if (ret < 0) {
diff --git a/app/test-acl/main.c b/app/test-acl/main.c
index 2cb2fe2579..9f95cb0fbf 100644
--- a/app/test-acl/main.c
+++ b/app/test-acl/main.c
@@ -1080,6 +1080,8 @@ main(int argc, char **argv)
 	int ret;
 	uint32_t lcore;
 
+	rte_set_application_usage_hook(print_usage);
+
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
 		rte_panic("Cannot init EAL\n");
diff --git a/app/test-bbdev/main.c b/app/test-bbdev/main.c
index ff65173fdb..5960ec18b2 100644
--- a/app/test-bbdev/main.c
+++ b/app/test-bbdev/main.c
@@ -340,7 +340,8 @@ main(int argc, char **argv)
 {
 	int ret;
 
-	/* Init EAL */
+	rte_set_application_usage_hook(print_usage);
+
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
 		return 1;
diff --git a/app/test-compress-perf/comp_perf_options.h b/app/test-compress-perf/comp_perf_options.h
index 0b777521c5..7dd785fba1 100644
--- a/app/test-compress-perf/comp_perf_options.h
+++ b/app/test-compress-perf/comp_perf_options.h
@@ -73,6 +73,8 @@ struct comp_test_data {
 	uint32_t cyclecount_delay;
 };
 
+void comp_perf_usage(const char *progname);
+
 int
 comp_perf_options_parse(struct comp_test_data *test_data, int argc,
 			char **argv);
diff --git a/app/test-compress-perf/comp_perf_options_parse.c b/app/test-compress-perf/comp_perf_options_parse.c
index 019eddb7bd..39d7fd8c69 100644
--- a/app/test-compress-perf/comp_perf_options_parse.c
+++ b/app/test-compress-perf/comp_perf_options_parse.c
@@ -38,8 +38,8 @@ struct name_id_map {
 	uint32_t id;
 };
 
-static void
-usage(char *progname)
+void
+comp_perf_usage(const char *progname)
 {
 	printf("%s [EAL options] --\n"
 		" --ptest throughput / verify / pmd-cyclecount\n"
@@ -619,7 +619,7 @@ comp_perf_options_parse(struct comp_test_data *test_data, int argc, char **argv)
 	while ((opt = getopt_long(argc, argv, "h", lgopts, &opt_idx)) != EOF) {
 		switch (opt) {
 		case 'h':
-			usage(argv[0]);
+			comp_perf_usage(argv[0]);
 			exit(EXIT_SUCCESS);
 			break;
 		/* long options */
@@ -631,7 +631,7 @@ comp_perf_options_parse(struct comp_test_data *test_data, int argc, char **argv)
 			break;
 
 		default:
-			usage(argv[0]);
+			comp_perf_usage(argv[0]);
 			return -EINVAL;
 		}
 	}
diff --git a/app/test-compress-perf/main.c b/app/test-compress-perf/main.c
index cc9951a9b1..dcd347528e 100644
--- a/app/test-compress-perf/main.c
+++ b/app/test-compress-perf/main.c
@@ -323,7 +323,8 @@ main(int argc, char **argv)
 	uint8_t cdev_id;
 	uint32_t lcore_id;
 
-	/* Initialise DPDK EAL */
+	rte_set_application_usage_hook(comp_perf_usage);
+
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
 		rte_exit(EXIT_FAILURE, "Invalid EAL arguments!\n");
diff --git a/app/test-crypto-perf/cperf_options.h b/app/test-crypto-perf/cperf_options.h
index 9664a4b343..5f4a780614 100644
--- a/app/test-crypto-perf/cperf_options.h
+++ b/app/test-crypto-perf/cperf_options.h
@@ -153,6 +153,8 @@ struct cperf_options {
 	uint8_t imix_distribution_count;
 };
 
+void cperf_usage(const char *progname);
+
 void
 cperf_options_default(struct cperf_options *options);
 
diff --git a/app/test-crypto-perf/cperf_options_parsing.c b/app/test-crypto-perf/cperf_options_parsing.c
index 40b6dfb648..3777bc7509 100644
--- a/app/test-crypto-perf/cperf_options_parsing.c
+++ b/app/test-crypto-perf/cperf_options_parsing.c
@@ -19,8 +19,8 @@ struct name_id_map {
 	uint32_t id;
 };
 
-static void
-usage(char *progname)
+void
+cperf_usage(const char *progname)
 {
 	printf("%s [EAL options] --\n"
 		" --silent: disable options dump\n"
@@ -982,7 +982,7 @@ cperf_options_parse(struct cperf_options *options, int argc, char **argv)
 	while ((opt = getopt_long(argc, argv, "h", lgopts, &opt_idx)) != EOF) {
 		switch (opt) {
 		case 'h':
-			usage(argv[0]);
+			cperf_usage(argv[0]);
 			exit(EXIT_SUCCESS);
 			break;
 		/* long options */
@@ -994,7 +994,7 @@ cperf_options_parse(struct cperf_options *options, int argc, char **argv)
 			break;
 
 		default:
-			usage(argv[0]);
+			cperf_usage(argv[0]);
 			return -EINVAL;
 		}
 	}
diff --git a/app/test-crypto-perf/main.c b/app/test-crypto-perf/main.c
index 49af812d8b..497c4c5226 100644
--- a/app/test-crypto-perf/main.c
+++ b/app/test-crypto-perf/main.c
@@ -519,7 +519,8 @@ main(int argc, char **argv)
 	int ret;
 	uint32_t lcore_id;
 
-	/* Initialise DPDK EAL */
+	rte_set_application_usage_hook(cperf_usage);
+
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
 		rte_exit(EXIT_FAILURE, "Invalid EAL arguments!\n");
diff --git a/app/test-fib/main.c b/app/test-fib/main.c
index b0a97b0d7e..420fe17c39 100644
--- a/app/test-fib/main.c
+++ b/app/test-fib/main.c
@@ -648,6 +648,12 @@ print_usage(void)
 		config.prgname);
 }
 
+static void
+usage_hook(const char *prgname __rte_unused)
+{
+	print_usage();
+}
+
 static int
 check_config(void)
 {
@@ -1209,6 +1215,8 @@ main(int argc, char **argv)
 	FILE *fl = NULL;
 	uint8_t depth_lim;
 
+	rte_set_application_usage_hook(usage_hook);
+
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
 		rte_panic("Cannot init EAL\n");
diff --git a/app/test-flow-perf/main.c b/app/test-flow-perf/main.c
index 0aef767350..949a5e3e11 100644
--- a/app/test-flow-perf/main.c
+++ b/app/test-flow-perf/main.c
@@ -115,7 +115,7 @@ static struct multi_cores_pool mc_pool = {
 };
 
 static void
-usage(char *progname)
+usage(const char *progname)
 {
 	printf("\nusage: %s\n", progname);
 	printf("\nControl configurations:\n");
@@ -1849,6 +1849,8 @@ main(int argc, char **argv)
 	uint16_t port;
 	struct rte_flow_error error;
 
+	rte_set_application_usage_hook(usage);
+
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
 		rte_exit(EXIT_FAILURE, "EAL init failed\n");
diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c
index b7d4ef76b0..156eff7697 100644
--- a/app/test-pmd/parameters.c
+++ b/app/test-pmd/parameters.c
@@ -46,8 +46,8 @@
 
 #include "testpmd.h"
 
-static void
-usage(char* progname)
+void
+usage(const char *progname)
 {
 	printf("usage: %s [EAL options] -- "
 #ifdef RTE_LIB_CMDLINE
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 98c3248c01..24c241b0f6 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -3779,6 +3779,8 @@ main(int argc, char** argv)
 		rte_exit(EXIT_FAILURE, "Cannot register log type");
 	rte_log_set_level(testpmd_logtype, RTE_LOG_DEBUG);
 
+	rte_set_application_usage_hook(usage);
+
 	diag = rte_eal_init(argc, argv);
 	if (diag < 0)
 		rte_exit(EXIT_FAILURE, "Cannot init EAL: %s\n",
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index af40859170..2ab2c1b3d0 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -764,6 +764,7 @@ inc_tx_burst_stats(struct fwd_stream *fs, uint16_t nb_tx)
 unsigned int parse_item_list(char* str, const char* item_name,
 			unsigned int max_items,
 			unsigned int *parsed_items, int check_unique_values);
+void usage(const char *progname);
 void launch_args_parse(int argc, char** argv);
 void cmdline_read_from_file(const char *filename);
 void prompt(void);
diff --git a/app/test-regex/main.c b/app/test-regex/main.c
index 7bb87bb1b8..ba09b20126 100644
--- a/app/test-regex/main.c
+++ b/app/test-regex/main.c
@@ -616,7 +616,8 @@ main(int argc, char **argv)
 	uint32_t i;
 	struct qps_per_lcore *qps_per_lcore;
 
-	/* Init EAL. */
+	rte_set_application_usage_hook(usage);
+
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
 		rte_exit(EXIT_FAILURE, "EAL init failed\n");
diff --git a/app/test-sad/main.c b/app/test-sad/main.c
index 1024757add..14a8263f8c 100644
--- a/app/test-sad/main.c
+++ b/app/test-sad/main.c
@@ -149,7 +149,12 @@ print_usage(void)
 		"[-p <parallel lookup on all available cores>]\n"
 		"[-c <init sad supporting read/write concurrency>]\n",
 		config.prgname);
+}
 
+static void
+usage_hook(const char *prgname __rte_unused)
+{
+	print_usage();
 }
 
 static int
@@ -620,6 +625,8 @@ main(int argc, char **argv)
 	struct rte_ipsec_sad_conf conf = {0};
 	unsigned int lcore_id;
 
+	rte_set_application_usage_hook(usage_hook);
+
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
 		rte_panic("Cannot init EAL\n");
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v4 10/11] app/regex: fix usage text
  2021-03-21 22:31 ` [dpdk-dev] [PATCH v4 " Thomas Monjalon
                     ` (8 preceding siblings ...)
  2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 09/11] app: hook in EAL usage help Thomas Monjalon
@ 2021-03-21 22:31   ` Thomas Monjalon
  2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 11/11] app/testpmd: " Thomas Monjalon
  2021-03-24 15:03   ` [dpdk-dev] [PATCH v4 00/11] improve options help David Marchand
  11 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-21 22:31 UTC (permalink / raw)
  To: dev
  Cc: david.marchand, stable, Ori Kam, Bruce Richardson,
	Andrew Rybchenko, Yuval Avnery

The usage syntax help includes the program name which was fake.
It is replaced with the real name from argv.

Fixes: de06137cb295 ("app/regex: add RegEx test application")
Cc: stable@dpdk.org

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Ori Kam <orika@nvidia.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 app/test-regex/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/app/test-regex/main.c b/app/test-regex/main.c
index ba09b20126..73ba227fba 100644
--- a/app/test-regex/main.c
+++ b/app/test-regex/main.c
@@ -151,10 +151,10 @@ args_parse(int argc, char **argv, char *rules_file, char *data_file,
 			*nb_lcores = atoi(optarg);
 			break;
 		case ARG_HELP:
-			usage("RegEx test app");
+			usage(argv[0]);
 			break;
 		default:
-			usage("RegEx test app");
+			usage(argv[0]);
 			rte_exit(EXIT_FAILURE, "Invalid option: %s\n", argv[optind]);
 			break;
 		}
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v4 11/11] app/testpmd: fix usage text
  2021-03-21 22:31 ` [dpdk-dev] [PATCH v4 " Thomas Monjalon
                     ` (9 preceding siblings ...)
  2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 10/11] app/regex: fix usage text Thomas Monjalon
@ 2021-03-21 22:31   ` Thomas Monjalon
  2021-03-22  1:45     ` Li, Xiaoyun
  2021-03-22  8:27     ` Jens Freimann
  2021-03-24 15:03   ` [dpdk-dev] [PATCH v4 00/11] improve options help David Marchand
  11 siblings, 2 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-21 22:31 UTC (permalink / raw)
  To: dev
  Cc: david.marchand, stable, Ajit Khaparde, Bruce Richardson,
	Andrew Rybchenko, Xiaoyun Li, Ori Kam, Bing Zhao,
	Bernard Iremonger, Jens Freimann, Kevin Traynor,
	Stephen Hemminger, Maciej Czekaj, Pablo de Lara

The options help text was including an incomplete and redundant
summary of the options before explaining each. The summary is dropped.

The details of the option --hairpin-mode had an extra space,
breaking the alignment with the next line.

There were some mismatches between options in the usage text
	sed -rn 's/.*\(" *--([a-z-]*)[=: ].*/\1/p' app/test-pmd/parameters.c
and the options declared in lgopts array
	sed -rn 's/.*\{.*"(.*)",.*,.*,.*},.*/\1/p' app/test-pmd/parameters.c
The misses were:
	--no-numa
	--enable-scatter
	--tx-ip
	--tx-udp
	--noisy-lkup-num-reads-writes
The option --ports was not implemented.

Fixes: 01817b10d27c ("app/testpmd: change hairpin queues setup")
Fixes: 3c156061b938 ("app/testpmd: add noisy neighbour forwarding mode")
Fixes: bf5b2126bf44 ("app/testpmd: add ability to set Tx IP and UDP parameters")
Fixes: 0499793854f5 ("app/testpmd: add scatter enabling option")
Fixes: 999b2ee0fe45 ("app/testpmd: enable NUMA support by default")
Fixes: af75078fece3 ("first public release")
Cc: stable@dpdk.org

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 app/test-pmd/parameters.c | 35 ++++++++---------------------------
 1 file changed, 8 insertions(+), 27 deletions(-)

diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c
index 156eff7697..4a1d64af89 100644
--- a/app/test-pmd/parameters.c
+++ b/app/test-pmd/parameters.c
@@ -49,29 +49,7 @@
 void
 usage(const char *progname)
 {
-	printf("usage: %s [EAL options] -- "
-#ifdef RTE_LIB_CMDLINE
-	       "[--interactive|-i] "
-	       "[--cmdline-file=FILENAME] "
-#endif
-	       "[--help|-h] | [--auto-start|-a] | ["
-	       "--tx-first | --stats-period=PERIOD | "
-	       "--coremask=COREMASK --portmask=PORTMASK --numa "
-	       "--portlist=PORTLIST "
-	       "--mbuf-size= | --total-num-mbufs= | "
-	       "--nb-cores= | --nb-ports= | "
-#ifdef RTE_LIB_CMDLINE
-	       "--eth-peers-configfile= | "
-	       "--eth-peer=X,M:M:M:M:M:M | "
-	       "--tx-ip=SRC,DST | --tx-udp=PORT | "
-#endif
-	       "--pkt-filter-mode= |"
-	       "--rss-ip | --rss-udp | --rss-level-inner | --rss-level-outer |"
-	       "--rxpt= | --rxht= | --rxwt= |"
-	       " --rxfreet= | --txpt= | --txht= | --txwt= | --txfreet= | "
-	       "--txrst= | --tx-offloads= | | --rx-offloads= | "
-	       "--vxlan-gpe-port= | --geneve-parsed-port= | "
-	       "--record-core-cycles | --record-burst-stats]\n",
+	printf("\nUsage: %s [EAL options] -- [testpmd options]\n\n",
 	       progname);
 #ifdef RTE_LIB_CMDLINE
 	printf("  --interactive: run in interactive mode.\n");
@@ -97,6 +75,7 @@ usage(const char *progname)
 	printf("  --portlist=PORTLIST: list of forwarding ports\n");
 	printf("  --numa: enable NUMA-aware allocation of RX/TX rings and of "
 	       "RX memory buffers (mbufs).\n");
+	printf("  --no-numa: disable NUMA-aware allocation.\n");
 	printf("  --port-numa-config=(port,socket)[,(port,socket)]: "
 	       "specify the socket on which the memory pool "
 	       "used by the port will be allocated.\n");
@@ -136,6 +115,7 @@ usage(const char *progname)
 	       "monitoring on forwarding lcore id N.\n");
 #endif
 	printf("  --disable-crc-strip: disable CRC stripping by hardware.\n");
+	printf("  --enable-scatter: enable scattered Rx.\n");
 	printf("  --enable-lro: enable large receive offload.\n");
 	printf("  --enable-rx-cksum: enable rx hardware checksum offload.\n");
 	printf("  --enable-rx-timestamp: enable rx hardware timestamp offload.\n");
@@ -184,6 +164,8 @@ usage(const char *progname)
 	printf("  --txpkts=X[,Y]*: set TX segment sizes"
 		" or total packet length.\n");
 	printf("  --txonly-multi-flow: generate multiple flows in txonly mode\n");
+	printf("  --tx-ip=src,dst: IP addresses in Tx-only mode\n");
+	printf("  --tx-udp=src[,dst]: UDP ports in Tx-only mode\n");
 	printf("  --eth-link-speed: force link speed.\n");
 	printf("  --disable-link-check: disable check on link status when "
 	       "starting/stopping ports.\n");
@@ -215,14 +197,14 @@ usage(const char *progname)
 	printf("  --noisy-lkup-memory=N: allocate N MB of VNF memory\n");
 	printf("  --noisy-lkup-num-writes=N: do N random writes per packet\n");
 	printf("  --noisy-lkup-num-reads=N: do N random reads per packet\n");
-	printf("  --noisy-lkup-num-writes=N: do N random reads and writes per packet\n");
+	printf("  --noisy-lkup-num-reads-writes=N: do N random reads and writes per packet\n");
 	printf("  --no-iova-contig: mempool memory can be IOVA non contiguous. "
 	       "valid only with --mp-alloc=anon\n");
 	printf("  --rx-mq-mode=0xX: hexadecimal bitmask of RX mq mode can be "
 	       "enabled\n");
 	printf("  --record-core-cycles: enable measurement of CPU cycles.\n");
 	printf("  --record-burst-stats: enable display of RX and TX bursts.\n");
-	printf("  --hairpin-mode=0xXX: bitmask set the hairpin port mode.\n "
+	printf("  --hairpin-mode=0xXX: bitmask set the hairpin port mode.\n"
 	       "    0x10 - explicit Tx rule, 0x02 - hairpin ports paired\n"
 	       "    0x01 - hairpin ports loop, 0x00 - hairpin port self\n");
 }
@@ -549,7 +531,6 @@ launch_args_parse(int argc, char** argv)
 #endif
 		{ "tx-first",			0, 0, 0 },
 		{ "stats-period",		1, 0, 0 },
-		{ "ports",			1, 0, 0 },
 		{ "nb-cores",			1, 0, 0 },
 		{ "nb-ports",			1, 0, 0 },
 		{ "coremask",			1, 0, 0 },
@@ -557,7 +538,7 @@ launch_args_parse(int argc, char** argv)
 		{ "portlist",			1, 0, 0 },
 		{ "numa",			0, 0, 0 },
 		{ "no-numa",			0, 0, 0 },
-		{ "mp-anon",			0, 0, 0 },
+		{ "mp-anon",			0, 0, 0 }, /* deprecated */
 		{ "port-numa-config",           1, 0, 0 },
 		{ "ring-numa-config",           1, 0, 0 },
 		{ "socket-num",			1, 0, 0 },
-- 
2.30.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH v4 11/11] app/testpmd: fix usage text
  2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 11/11] app/testpmd: " Thomas Monjalon
@ 2021-03-22  1:45     ` Li, Xiaoyun
  2021-03-22  8:27     ` Jens Freimann
  1 sibling, 0 replies; 121+ messages in thread
From: Li, Xiaoyun @ 2021-03-22  1:45 UTC (permalink / raw)
  To: Thomas Monjalon, dev
  Cc: david.marchand, stable, Ajit Khaparde, Richardson, Bruce,
	Andrew Rybchenko, Ori Kam, Bing Zhao, Iremonger, Bernard,
	Jens Freimann, Kevin Traynor, Stephen Hemminger, Maciej Czekaj,
	De Lara Guarch, Pablo



> -----Original Message-----
> From: Thomas Monjalon <thomas@monjalon.net>
> Sent: Monday, March 22, 2021 06:31
> To: dev@dpdk.org
> Cc: david.marchand@redhat.com; stable@dpdk.org; Ajit Khaparde
> <ajit.khaparde@broadcom.com>; Richardson, Bruce
> <bruce.richardson@intel.com>; Andrew Rybchenko
> <andrew.rybchenko@oktetlabs.ru>; Li, Xiaoyun <xiaoyun.li@intel.com>; Ori
> Kam <orika@nvidia.com>; Bing Zhao <bingz@nvidia.com>; Iremonger, Bernard
> <bernard.iremonger@intel.com>; Jens Freimann <jfreimann@redhat.com>;
> Kevin Traynor <ktraynor@redhat.com>; Stephen Hemminger
> <stephen@networkplumber.org>; Maciej Czekaj
> <maciej.czekaj@caviumnetworks.com>; De Lara Guarch, Pablo
> <pablo.de.lara.guarch@intel.com>
> Subject: [PATCH v4 11/11] app/testpmd: fix usage text
> 
> The options help text was including an incomplete and redundant summary of
> the options before explaining each. The summary is dropped.
> 
> The details of the option --hairpin-mode had an extra space, breaking the
> alignment with the next line.
> 
> There were some mismatches between options in the usage text
> 	sed -rn 's/.*\(" *--([a-z-]*)[=: ].*/\1/p' app/test-pmd/parameters.c and
> the options declared in lgopts array
> 	sed -rn 's/.*\{.*"(.*)",.*,.*,.*},.*/\1/p' app/test-pmd/parameters.c The
> misses were:
> 	--no-numa
> 	--enable-scatter
> 	--tx-ip
> 	--tx-udp
> 	--noisy-lkup-num-reads-writes
> The option --ports was not implemented.
> 
> Fixes: 01817b10d27c ("app/testpmd: change hairpin queues setup")
> Fixes: 3c156061b938 ("app/testpmd: add noisy neighbour forwarding mode")
> Fixes: bf5b2126bf44 ("app/testpmd: add ability to set Tx IP and UDP parameters")
> Fixes: 0499793854f5 ("app/testpmd: add scatter enabling option")
> Fixes: 999b2ee0fe45 ("app/testpmd: enable NUMA support by default")
> Fixes: af75078fece3 ("first public release")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> Acked-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
> Acked-by: Bruce Richardson <bruce.richardson@intel.com>
> Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
> ---

Acked-by: Xiaoyun Li <xiaoyun.li@intel.com>

^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH v4 11/11] app/testpmd: fix usage text
  2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 11/11] app/testpmd: " Thomas Monjalon
  2021-03-22  1:45     ` Li, Xiaoyun
@ 2021-03-22  8:27     ` Jens Freimann
  2021-03-22  9:05       ` Bing Zhao
  1 sibling, 1 reply; 121+ messages in thread
From: Jens Freimann @ 2021-03-22  8:27 UTC (permalink / raw)
  To: Thomas Monjalon
  Cc: dev, david.marchand, stable, Ajit Khaparde, Bruce Richardson,
	Andrew Rybchenko, Xiaoyun Li, Ori Kam, Bing Zhao,
	Bernard Iremonger, Kevin Traynor, Stephen Hemminger,
	Maciej Czekaj, Pablo de Lara

On Sun, Mar 21, 2021 at 11:31:15PM +0100, Thomas Monjalon wrote:
>The options help text was including an incomplete and redundant
>summary of the options before explaining each. The summary is dropped.
>
>The details of the option --hairpin-mode had an extra space,
>breaking the alignment with the next line.
>
>There were some mismatches between options in the usage text
>	sed -rn 's/.*\(" *--([a-z-]*)[=: ].*/\1/p' app/test-pmd/parameters.c
>and the options declared in lgopts array
>	sed -rn 's/.*\{.*"(.*)",.*,.*,.*},.*/\1/p' app/test-pmd/parameters.c
>The misses were:
>	--no-numa
>	--enable-scatter
>	--tx-ip
>	--tx-udp
>	--noisy-lkup-num-reads-writes
>The option --ports was not implemented.
>
>Fixes: 01817b10d27c ("app/testpmd: change hairpin queues setup")
>Fixes: 3c156061b938 ("app/testpmd: add noisy neighbour forwarding mode")
>Fixes: bf5b2126bf44 ("app/testpmd: add ability to set Tx IP and UDP parameters")
>Fixes: 0499793854f5 ("app/testpmd: add scatter enabling option")
>Fixes: 999b2ee0fe45 ("app/testpmd: enable NUMA support by default")
>Fixes: af75078fece3 ("first public release")
>Cc: stable@dpdk.org
>
>Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
>Acked-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
>Acked-by: Bruce Richardson <bruce.richardson@intel.com>
>Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
>---
> app/test-pmd/parameters.c | 35 ++++++++---------------------------
> 1 file changed, 8 insertions(+), 27 deletions(-)
>

Thank you Thomas!

Reviewed-by: Jens Freimann <jfreimann@redhat.com>

regards,
Jens 


^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH v4 11/11] app/testpmd: fix usage text
  2021-03-22  8:27     ` Jens Freimann
@ 2021-03-22  9:05       ` Bing Zhao
  0 siblings, 0 replies; 121+ messages in thread
From: Bing Zhao @ 2021-03-22  9:05 UTC (permalink / raw)
  To: Jens Freimann, NBU-Contact-Thomas Monjalon
  Cc: dev, david.marchand, stable, Ajit Khaparde, Bruce Richardson,
	Andrew Rybchenko, Xiaoyun Li, Ori Kam, Bernard Iremonger,
	Kevin Traynor, Stephen Hemminger, Maciej Czekaj, Pablo de Lara

Hi Thomas,

> -----Original Message-----
> From: Jens Freimann <jfreimann@redhat.com>
> Sent: Monday, March 22, 2021 4:27 PM
> To: NBU-Contact-Thomas Monjalon <thomas@monjalon.net>
> Cc: dev@dpdk.org; david.marchand@redhat.com; stable@dpdk.org; Ajit
> Khaparde <ajit.khaparde@broadcom.com>; Bruce Richardson
> <bruce.richardson@intel.com>; Andrew Rybchenko
> <andrew.rybchenko@oktetlabs.ru>; Xiaoyun Li <xiaoyun.li@intel.com>;
> Ori Kam <orika@nvidia.com>; Bing Zhao <bingz@nvidia.com>; Bernard
> Iremonger <bernard.iremonger@intel.com>; Kevin Traynor
> <ktraynor@redhat.com>; Stephen Hemminger
> <stephen@networkplumber.org>; Maciej Czekaj
> <maciej.czekaj@caviumnetworks.com>; Pablo de Lara
> <pablo.de.lara.guarch@intel.com>
> Subject: Re: [dpdk-dev] [PATCH v4 11/11] app/testpmd: fix usage text
> 
> External email: Use caution opening links or attachments
> 
> 
> On Sun, Mar 21, 2021 at 11:31:15PM +0100, Thomas Monjalon wrote:
> >The options help text was including an incomplete and redundant
> summary
> >of the options before explaining each. The summary is dropped.
> >
> >The details of the option --hairpin-mode had an extra space,
> breaking
> >the alignment with the next line.
> >
> >There were some mismatches between options in the usage text
> >       sed -rn 's/.*\(" *--([a-z-]*)[=: ].*/\1/p'
> >app/test-pmd/parameters.c and the options declared in lgopts array
> >       sed -rn 's/.*\{.*"(.*)",.*,.*,.*},.*/\1/p'
> >app/test-pmd/parameters.c The misses were:
> >       --no-numa
> >       --enable-scatter
> >       --tx-ip
> >       --tx-udp
> >       --noisy-lkup-num-reads-writes
> >The option --ports was not implemented.
> >
> >Fixes: 01817b10d27c ("app/testpmd: change hairpin queues setup")
> >Fixes: 3c156061b938 ("app/testpmd: add noisy neighbour forwarding
> >mode")
> >Fixes: bf5b2126bf44 ("app/testpmd: add ability to set Tx IP and UDP
> >parameters")
> >Fixes: 0499793854f5 ("app/testpmd: add scatter enabling option")
> >Fixes: 999b2ee0fe45 ("app/testpmd: enable NUMA support by default")
> >Fixes: af75078fece3 ("first public release")
> >Cc: stable@dpdk.org
> >
> >Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> >Acked-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
> >Acked-by: Bruce Richardson <bruce.richardson@intel.com>
> >Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
> >---
> > app/test-pmd/parameters.c | 35 ++++++++---------------------------
> > 1 file changed, 8 insertions(+), 27 deletions(-)
> >
> 
> Thank you Thomas!
> 
> Reviewed-by: Jens Freimann <jfreimann@redhat.com>
> 
> regards,
> Jens

Reviewed-by: Bing Zhao <bingz@nvidia.com>

Thanks a lot for the help.

^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH v4 07/11] eal: add log level help
  2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 07/11] eal: add log level help Thomas Monjalon
@ 2021-03-23 13:37     ` David Marchand
  2021-03-23 15:10       ` Thomas Monjalon
  0 siblings, 1 reply; 121+ messages in thread
From: David Marchand @ 2021-03-23 13:37 UTC (permalink / raw)
  To: Thomas Monjalon
  Cc: dev, Bruce Richardson, Andrew Rybchenko, Ray Kinsella, Neil Horman

On Sun, Mar 21, 2021 at 11:32 PM Thomas Monjalon <thomas@monjalon.net> wrote:
>
> The option --log-level was not completely described in the usage text,
> and it was difficult to guess the names of the log types and levels.
>
> A new value "help" is accepted after --log-level to give more details
> about the syntax and listing the log types and levels.
>
> The array "levels" used for level name parsing is replaced with
> a (modified) existing function which was used in rte_log_dump().

If we forget about the slightly different formatting, why not simply
reuse rte_log_dump?
It has the advantage of listing the default level for each logtype
that a user cannot guess otherwise.


-- 
David Marchand


^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH v4 07/11] eal: add log level help
  2021-03-23 13:37     ` David Marchand
@ 2021-03-23 15:10       ` Thomas Monjalon
  2021-03-23 18:18         ` David Marchand
  0 siblings, 1 reply; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-23 15:10 UTC (permalink / raw)
  To: David Marchand; +Cc: dev, Bruce Richardson, Andrew Rybchenko, Ray Kinsella

23/03/2021 14:37, David Marchand:
> On Sun, Mar 21, 2021 at 11:32 PM Thomas Monjalon <thomas@monjalon.net> wrote:
> >
> > The option --log-level was not completely described in the usage text,
> > and it was difficult to guess the names of the log types and levels.
> >
> > A new value "help" is accepted after --log-level to give more details
> > about the syntax and listing the log types and levels.
> >
> > The array "levels" used for level name parsing is replaced with
> > a (modified) existing function which was used in rte_log_dump().
> 
> If we forget about the slightly different formatting, why not simply
> reuse rte_log_dump?
> It has the advantage of listing the default level for each logtype
> that a user cannot guess otherwise.

I considered rte_log_dump() too much verbose for the help text.
It is printing the global level and the logtype ids.
The need for the end-user in the help is different of a debug dump.




^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH v4 07/11] eal: add log level help
  2021-03-23 15:10       ` Thomas Monjalon
@ 2021-03-23 18:18         ` David Marchand
  2021-03-23 18:41           ` Thomas Monjalon
  0 siblings, 1 reply; 121+ messages in thread
From: David Marchand @ 2021-03-23 18:18 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev, Bruce Richardson, Andrew Rybchenko, Ray Kinsella

On Tue, Mar 23, 2021 at 4:10 PM Thomas Monjalon <thomas@monjalon.net> wrote:
>
> 23/03/2021 14:37, David Marchand:
> > On Sun, Mar 21, 2021 at 11:32 PM Thomas Monjalon <thomas@monjalon.net> wrote:
> > >
> > > The option --log-level was not completely described in the usage text,
> > > and it was difficult to guess the names of the log types and levels.
> > >
> > > A new value "help" is accepted after --log-level to give more details
> > > about the syntax and listing the log types and levels.
> > >
> > > The array "levels" used for level name parsing is replaced with
> > > a (modified) existing function which was used in rte_log_dump().
> >
> > If we forget about the slightly different formatting, why not simply
> > reuse rte_log_dump?
> > It has the advantage of listing the default level for each logtype
> > that a user cannot guess otherwise.
>
> I considered rte_log_dump() too much verbose for the help text.
> It is printing the global level and the logtype ids.

Yes, it gives all the info about the log subsystem.

> The need for the end-user in the help is different of a debug dump.

The result of rte_log_list_types is a list in link-time order.
At least it is worth sorting alphabetically for users.

What about default log levels?


-- 
David Marchand


^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH v4 07/11] eal: add log level help
  2021-03-23 18:18         ` David Marchand
@ 2021-03-23 18:41           ` Thomas Monjalon
  2021-03-24 13:41             ` David Marchand
  0 siblings, 1 reply; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-23 18:41 UTC (permalink / raw)
  To: David Marchand; +Cc: dev, Bruce Richardson, Andrew Rybchenko, Ray Kinsella

23/03/2021 19:18, David Marchand:
> On Tue, Mar 23, 2021 at 4:10 PM Thomas Monjalon <thomas@monjalon.net> wrote:
> > 23/03/2021 14:37, David Marchand:
> > > On Sun, Mar 21, 2021 at 11:32 PM Thomas Monjalon <thomas@monjalon.net> wrote:
> > > >
> > > > The option --log-level was not completely described in the usage text,
> > > > and it was difficult to guess the names of the log types and levels.
> > > >
> > > > A new value "help" is accepted after --log-level to give more details
> > > > about the syntax and listing the log types and levels.
> > > >
> > > > The array "levels" used for level name parsing is replaced with
> > > > a (modified) existing function which was used in rte_log_dump().
> > >
> > > If we forget about the slightly different formatting, why not simply
> > > reuse rte_log_dump?
> > > It has the advantage of listing the default level for each logtype
> > > that a user cannot guess otherwise.
> >
> > I considered rte_log_dump() too much verbose for the help text.
> > It is printing the global level and the logtype ids.
> 
> Yes, it gives all the info about the log subsystem.
> 
> > The need for the end-user in the help is different of a debug dump.
> 
> The result of rte_log_list_types is a list in link-time order.
> At least it is worth sorting alphabetically for users.

Yes sorting could be nice.

> What about default log levels?

No strong opinion. The default is more or less always the same.
If you believe it helps the user, then OK to add default levels.



^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH v4 07/11] eal: add log level help
  2021-03-23 18:41           ` Thomas Monjalon
@ 2021-03-24 13:41             ` David Marchand
  0 siblings, 0 replies; 121+ messages in thread
From: David Marchand @ 2021-03-24 13:41 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev, Bruce Richardson, Andrew Rybchenko, Ray Kinsella

On Tue, Mar 23, 2021 at 7:42 PM Thomas Monjalon <thomas@monjalon.net> wrote:
> > > The need for the end-user in the help is different of a debug dump.
> >
> > The result of rte_log_list_types is a list in link-time order.
> > At least it is worth sorting alphabetically for users.
>
> Yes sorting could be nice.
>
> > What about default log levels?
>
> No strong opinion. The default is more or less always the same.

"more or less" yes.

Looking at your patch that only cares about listing logtypes.
Ok, let's leave it at that, with a sorted list.

I'll try to revisit this later, as finding/restoring default loglevel
during a debugging session is a pain.

-- 
David Marchand


^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH v4 00/11] improve options help
  2021-03-21 22:31 ` [dpdk-dev] [PATCH v4 " Thomas Monjalon
                     ` (10 preceding siblings ...)
  2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 11/11] app/testpmd: " Thomas Monjalon
@ 2021-03-24 15:03   ` David Marchand
  2021-03-24 16:55     ` Thomas Monjalon
  11 siblings, 1 reply; 121+ messages in thread
From: David Marchand @ 2021-03-24 15:03 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev

On Sun, Mar 21, 2021 at 11:31 PM Thomas Monjalon <thomas@monjalon.net> wrote:
>
> The main intent of this series is to provide a nice help
> for the --log-level option.

The changes on usage() and the --log-level help are not related and
could have been separated in two series.

Like a series with:
  eal: use macros for help option
  eal: move private log functions
  eal: introduce maximum log level macro
  eal: catch invalid log level number
  eal: add log level help

About these --log-level related patches, I am ok with them (with just
a comment on sorting logtypes).

Then a series with:
  eal: explain argv behaviour during init
  eal: improve options usage text
  app: fix exit messages
  app: hook in EAL usage help
  app/regex: fix usage text
  app/testpmd: fix usage text

For the usage() patches, the main enhancement comes from hooking the
app/ usage() to rte_set_application_usage_hook().

As for the "eal: improve options usage text" patch, there are two
changes in behavior.

Taking testpmd as an example:

"""
Usage: ./build/app/dpdk-testpmd [EAL options] -- [testpmd options]

  --interactive: run in interactive mode.
  --cmdline-file: execute cli commands before startup.
  --auto-start: start forwarding on init [always when non-interactive].
  --help: display this message and quit.
  --tx-first: start forwarding sending a burst first (only if
interactive is disabled).
  --stats-period=PERIOD: statistics will be shown every PERIOD seconds
(only if interactive is disabled).
[snip]
  --hairpin-mode=0xXX: bitmask set the hairpin port mode.
    0x10 - explicit Tx rule, 0x02 - hairpin ports paired
    0x01 - hairpin ports loop, 0x00 - hairpin port self

EAL common options:
  -c COREMASK         Hexadecimal bitmask of cores to run on
  -l CORELIST         List of cores to run on
                      The argument format is <c1>[-c2][,c3[-c4],...]
                      where c1, c2, etc are core indexes between 0 and 128
  --lcores COREMAP    Map lcore set to physical cpu set
                      The argument format is
[snip]
"""

- The "Usage: " lists [EAL options] first, so I would expect them to
be listed first.
Hence I am not a fan of the reordering.


- Testpmd options are not identified anymore while it was easier
before to find out about it with the "===== Application Usage ====="
banner.
Applications now must add a banner to differentiate their options from
the EAL ones.


-- 
David Marchand


^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH v4 00/11] improve options help
  2021-03-24 15:03   ` [dpdk-dev] [PATCH v4 00/11] improve options help David Marchand
@ 2021-03-24 16:55     ` Thomas Monjalon
  0 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-03-24 16:55 UTC (permalink / raw)
  To: David Marchand; +Cc: dev

24/03/2021 16:03, David Marchand:
> The changes on usage() and the --log-level help are not related and
> could have been separated in two series.

Yes, I will split. It will help merging the non-controversial patches.


> - The "Usage: " lists [EAL options] first, so I would expect them to
> be listed first.
> Hence I am not a fan of the reordering.

If not reordering, we print the EAL options before giving
the line "Usage: ..." with the generic syntax of the application.


> - Testpmd options are not identified anymore while it was easier
> before to find out about it with the "===== Application Usage ====="
> banner.
> Applications now must add a banner to differentiate their options from
> the EAL ones.

I think the banner "Application Usage" is strange when printing
(sic) application usage.
The EAL options are already clearly identified,
so I though it was clear enough:

EAL common options:
[...]
EAL options for DEBUG use only:
[...]
EAL Linux options:
[...]



^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v5 0/4] log level enhancements
  2021-03-09 23:31 [dpdk-dev] [PATCH 00/11] improve options help Thomas Monjalon
                   ` (14 preceding siblings ...)
  2021-03-21 22:31 ` [dpdk-dev] [PATCH v4 " Thomas Monjalon
@ 2021-04-05 19:29 ` Thomas Monjalon
  2021-04-05 19:29   ` [dpdk-dev] [PATCH v5 1/4] log: move private functions Thomas Monjalon
                     ` (5 more replies)
  2021-04-05 19:33 ` [dpdk-dev] [PATCH v5 0/3] cleanup exit and usage messages in apps Thomas Monjalon
  2021-04-05 19:39 ` [dpdk-dev] [PATCH v5 0/4] improve options help Thomas Monjalon
  17 siblings, 6 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-04-05 19:29 UTC (permalink / raw)
  To: dev; +Cc: david.marchand

This series is a part of a bigger one split after v4:
        "improve options help"

The main intent of this series is to provide a nice help
for the --log-level option.

v5:
   - rename more private functions
   - sort log types when printing help

Thomas Monjalon (4):
  log: move private functions
  log: introduce macro for maximum level
  log: catch invalid level option number
  log: add option argument help

 lib/librte_eal/common/eal_common_log.c     | 87 ++++++++++++++++------
 lib/librte_eal/common/eal_common_options.c | 60 ++++++++++-----
 lib/librte_eal/common/eal_log.h            | 32 ++++++++
 lib/librte_eal/common/eal_private.h        | 29 --------
 lib/librte_eal/include/rte_log.h           | 12 +++
 lib/librte_eal/linux/eal.c                 |  3 +-
 lib/librte_eal/linux/eal_log.c             |  4 +-
 lib/librte_eal/version.map                 |  1 +
 lib/librte_eal/windows/eal.c               |  3 +-
 lib/librte_eal/windows/eal_log.c           |  6 +-
 10 files changed, 162 insertions(+), 75 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_log.h

-- 
2.31.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v5 1/4] log: move private functions
  2021-04-05 19:29 ` [dpdk-dev] [PATCH v5 0/4] log level enhancements Thomas Monjalon
@ 2021-04-05 19:29   ` Thomas Monjalon
  2021-04-06 11:28     ` David Marchand
  2021-04-05 19:29   ` [dpdk-dev] [PATCH v5 2/4] log: introduce macro for maximum level Thomas Monjalon
                     ` (4 subsequent siblings)
  5 siblings, 1 reply; 121+ messages in thread
From: Thomas Monjalon @ 2021-04-05 19:29 UTC (permalink / raw)
  To: dev
  Cc: david.marchand, Bruce Richardson, Andrew Rybchenko,
	Dmitry Kozlyuk, Narcisa Ana Maria Vasile, Dmitry Malloy,
	Pallavi Kadam

Some private log functions had a wrong "rte_" prefix.

All private log functions are moved from eal_private.h
to the new file eal_log.h:
	rte_eal_log_init -> eal_log_init
	rte_log_save_regexp -> eal_log_save_regexp
	rte_log_save_pattern -> eal_log_save_pattern
	eal_log_set_default

The static functions in the file eal_common_log.c are renamed:
	rte_log_save_level -> log_save_level
	rte_log_init -> log_init

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 lib/librte_eal/common/eal_common_log.c     | 28 +++++++++++----------
 lib/librte_eal/common/eal_common_options.c |  5 ++--
 lib/librte_eal/common/eal_log.h            | 27 ++++++++++++++++++++
 lib/librte_eal/common/eal_private.h        | 29 ----------------------
 lib/librte_eal/linux/eal.c                 |  3 ++-
 lib/librte_eal/linux/eal_log.c             |  4 +--
 lib/librte_eal/windows/eal.c               |  3 ++-
 lib/librte_eal/windows/eal_log.c           |  6 +++--
 8 files changed, 55 insertions(+), 50 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_log.h

diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c
index c5554badb2..058fa10ffc 100644
--- a/lib/librte_eal/common/eal_common_log.c
+++ b/lib/librte_eal/common/eal_common_log.c
@@ -15,7 +15,7 @@
 #include <rte_log.h>
 #include <rte_per_lcore.h>
 
-#include "eal_private.h"
+#include "eal_log.h"
 
 struct rte_log_dynamic_type {
 	const char *name;
@@ -178,8 +178,8 @@ rte_log_set_level_regexp(const char *regex, uint32_t level)
  * Save the type string and the loglevel for later dynamic
  * logtypes which may register later.
  */
-static int rte_log_save_level(int priority,
-			      const char *regex, const char *pattern)
+static int
+log_save_level(uint32_t priority, const char *regex, const char *pattern)
 {
 	struct rte_eal_opt_loglevel *opt_ll = NULL;
 
@@ -207,9 +207,10 @@ static int rte_log_save_level(int priority,
 	return -1;
 }
 
-int rte_log_save_regexp(const char *regex, int tmp)
+int
+eal_log_save_regexp(const char *regex, uint32_t level)
 {
-	return rte_log_save_level(tmp, regex, NULL);
+	return log_save_level(level, regex, NULL);
 }
 
 /* set log level based on globbing pattern */
@@ -232,9 +233,10 @@ rte_log_set_level_pattern(const char *pattern, uint32_t level)
 	return 0;
 }
 
-int rte_log_save_pattern(const char *pattern, int priority)
+int
+eal_log_save_pattern(const char *pattern, uint32_t level)
 {
-	return rte_log_save_level(priority, NULL, pattern);
+	return log_save_level(level, NULL, pattern);
 }
 
 /* get the current loglevel for the message being processed */
@@ -250,7 +252,7 @@ int rte_log_cur_msg_logtype(void)
 }
 
 static int
-rte_log_lookup(const char *name)
+log_lookup(const char *name)
 {
 	size_t i;
 
@@ -268,7 +270,7 @@ rte_log_lookup(const char *name)
  * is not yet registered.
  */
 static int
-__rte_log_register(const char *name, int id)
+log_register(const char *name, int id)
 {
 	char *dup_name = strdup(name);
 
@@ -288,7 +290,7 @@ rte_log_register(const char *name)
 	struct rte_log_dynamic_type *new_dynamic_types;
 	int id, ret;
 
-	id = rte_log_lookup(name);
+	id = log_lookup(name);
 	if (id >= 0)
 		return id;
 
@@ -299,7 +301,7 @@ rte_log_register(const char *name)
 		return -ENOMEM;
 	rte_logs.dynamic_types = new_dynamic_types;
 
-	ret = __rte_log_register(name, rte_logs.dynamic_types_len);
+	ret = log_register(name, rte_logs.dynamic_types_len);
 	if (ret < 0)
 		return ret;
 
@@ -376,7 +378,7 @@ static const struct logtype logtype_strings[] = {
 };
 
 /* Logging should be first initializer (before drivers and bus) */
-RTE_INIT_PRIO(rte_log_init, LOG)
+RTE_INIT_PRIO(log_init, LOG)
 {
 	uint32_t i;
 
@@ -389,7 +391,7 @@ RTE_INIT_PRIO(rte_log_init, LOG)
 
 	/* register legacy log types */
 	for (i = 0; i < RTE_DIM(logtype_strings); i++)
-		__rte_log_register(logtype_strings[i].logtype,
+		log_register(logtype_strings[i].logtype,
 				logtype_strings[i].log_id);
 
 	rte_logs.dynamic_types_len = RTE_LOGTYPE_FIRST_EXT_ID;
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 622c7bc429..cd1a2856c9 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -41,6 +41,7 @@
 #include "eal_options.h"
 #include "eal_filesystem.h"
 #include "eal_private.h"
+#include "eal_log.h"
 #ifndef RTE_EXEC_ENV_WINDOWS
 #include "eal_trace.h"
 #endif
@@ -1299,7 +1300,7 @@ eal_parse_log_level(const char *arg)
 				regex, priority);
 			goto fail;
 		}
-		if (rte_log_save_regexp(regex, priority) < 0)
+		if (eal_log_save_regexp(regex, priority) < 0)
 			goto fail;
 	} else if (pattern) {
 		if (rte_log_set_level_pattern(pattern, priority) < 0) {
@@ -1307,7 +1308,7 @@ eal_parse_log_level(const char *arg)
 				pattern, priority);
 			goto fail;
 		}
-		if (rte_log_save_pattern(pattern, priority) < 0)
+		if (eal_log_save_pattern(pattern, priority) < 0)
 			goto fail;
 	} else {
 		rte_log_set_global_level(priority);
diff --git a/lib/librte_eal/common/eal_log.h b/lib/librte_eal/common/eal_log.h
new file mode 100644
index 0000000000..684650a17b
--- /dev/null
+++ b/lib/librte_eal/common/eal_log.h
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2021 Mellanox Technologies, Ltd
+ */
+
+#ifndef EAL_LOG_H
+#define EAL_LOG_H
+
+#include <stdio.h>
+#include <stdint.h>
+
+/*
+ * Initialize the default log stream.
+ */
+int eal_log_init(const char *id, int facility);
+
+/*
+ * Determine where log data is written when no call to rte_openlog_stream.
+ */
+void eal_log_set_default(FILE *default_log);
+
+/*
+ * Save a log option for later.
+ */
+int eal_log_save_regexp(const char *regexp, uint32_t level);
+int eal_log_save_pattern(const char *pattern, uint32_t level);
+
+#endif /* EAL_LOG_H */
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index b8a0d20021..e3512111d9 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -79,19 +79,6 @@ struct rte_config *rte_eal_get_configuration(void);
  */
 int rte_eal_memzone_init(void);
 
-/**
- * Common log initialization function (private to eal).  Determines
- * where log data is written when no call to rte_openlog_stream is
- * in effect.
- *
- * @param default_log
- *   The default log stream to be used.
- * @return
- *   - 0 on success
- *   - Negative on error
- */
-void eal_log_set_default(FILE *default_log);
-
 /**
  * Fill configuration with number of physical and logical processors
  *
@@ -143,22 +130,6 @@ int rte_eal_memory_init(void);
  */
 int rte_eal_timer_init(void);
 
-/**
- * Init the default log stream
- *
- * This function is private to EAL.
- *
- * @return
- *   0 on success, negative on error
- */
-int rte_eal_log_init(const char *id, int facility);
-
-/**
- * Save the log regexp for later
- */
-int rte_log_save_regexp(const char *type, int priority);
-int rte_log_save_pattern(const char *pattern, int priority);
-
 /**
  * Init tail queues for non-EAL library structures. This is to allow
  * the rings, mempools, etc. lists to be shared among multiple processes
diff --git a/lib/librte_eal/linux/eal.c b/lib/librte_eal/linux/eal.c
index abbb537746..ac27dd4274 100644
--- a/lib/librte_eal/linux/eal.c
+++ b/lib/librte_eal/linux/eal.c
@@ -58,6 +58,7 @@
 #include "eal_hugepages.h"
 #include "eal_memcfg.h"
 #include "eal_trace.h"
+#include "eal_log.h"
 #include "eal_options.h"
 #include "eal_vfio.h"
 #include "hotplug_mp.h"
@@ -1160,7 +1161,7 @@ rte_eal_init(int argc, char **argv)
 #endif
 	}
 
-	if (rte_eal_log_init(logid, internal_conf->syslog_facility) < 0) {
+	if (eal_log_init(logid, internal_conf->syslog_facility) < 0) {
 		rte_eal_init_alert("Cannot init logging.");
 		rte_errno = ENOMEM;
 		__atomic_store_n(&run_once, 0, __ATOMIC_RELAXED);
diff --git a/lib/librte_eal/linux/eal_log.c b/lib/librte_eal/linux/eal_log.c
index 2095df74c5..c0aa1007c4 100644
--- a/lib/librte_eal/linux/eal_log.c
+++ b/lib/librte_eal/linux/eal_log.c
@@ -17,7 +17,7 @@
 #include <rte_spinlock.h>
 #include <rte_log.h>
 
-#include "eal_private.h"
+#include "eal_log.h"
 
 /*
  * default log function
@@ -46,7 +46,7 @@ static cookie_io_functions_t console_log_func = {
  * once memzones are available.
  */
 int
-rte_eal_log_init(const char *id, int facility)
+eal_log_init(const char *id, int facility)
 {
 	FILE *log_stream;
 
diff --git a/lib/librte_eal/windows/eal.c b/lib/librte_eal/windows/eal.c
index 2fc3d6141c..68a1fd1d21 100644
--- a/lib/librte_eal/windows/eal.c
+++ b/lib/librte_eal/windows/eal.c
@@ -22,6 +22,7 @@
 
 #include "eal_hugepages.h"
 #include "eal_trace.h"
+#include "eal_log.h"
 #include "eal_windows.h"
 
 #define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL)
@@ -267,7 +268,7 @@ rte_eal_init(int argc, char **argv)
 		eal_get_internal_configuration();
 	int ret;
 
-	rte_eal_log_init(NULL, 0);
+	eal_log_init(NULL, 0);
 
 	eal_log_level_parse(argc, argv);
 
diff --git a/lib/librte_eal/windows/eal_log.c b/lib/librte_eal/windows/eal_log.c
index 875981f139..d4ea47f1c8 100644
--- a/lib/librte_eal/windows/eal_log.c
+++ b/lib/librte_eal/windows/eal_log.c
@@ -2,11 +2,13 @@
  * Copyright(c) 2017-2018 Intel Corporation
  */
 
-#include "eal_private.h"
+#include <rte_common.h>
+#include <rte_log.h>
+#include "eal_log.h"
 
 /* set the log to default function, called during eal init process. */
 int
-rte_eal_log_init(__rte_unused const char *id, __rte_unused int facility)
+eal_log_init(__rte_unused const char *id, __rte_unused int facility)
 {
 	rte_openlog_stream(stderr);
 
-- 
2.31.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v5 2/4] log: introduce macro for maximum level
  2021-04-05 19:29 ` [dpdk-dev] [PATCH v5 0/4] log level enhancements Thomas Monjalon
  2021-04-05 19:29   ` [dpdk-dev] [PATCH v5 1/4] log: move private functions Thomas Monjalon
@ 2021-04-05 19:29   ` Thomas Monjalon
  2021-04-05 19:29   ` [dpdk-dev] [PATCH v5 3/4] log: catch invalid level option number Thomas Monjalon
                     ` (3 subsequent siblings)
  5 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-04-05 19:29 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, Bruce Richardson, Andrew Rybchenko

RTE_DIM(...) and RTE_LOG_DEBUG were used to get the highest log level.
For better clarity a new constant RTE_LOG_MAX is introduced
and mapped to RTE_LOG_DEBUG.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 lib/librte_eal/common/eal_common_log.c     | 8 ++++----
 lib/librte_eal/common/eal_common_options.c | 2 +-
 lib/librte_eal/include/rte_log.h           | 1 +
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c
index 058fa10ffc..b9b982fdb5 100644
--- a/lib/librte_eal/common/eal_common_log.c
+++ b/lib/librte_eal/common/eal_common_log.c
@@ -140,7 +140,7 @@ rte_log_set_level(uint32_t type, uint32_t level)
 {
 	if (type >= rte_logs.dynamic_types_len)
 		return -1;
-	if (level > RTE_LOG_DEBUG)
+	if (level > RTE_LOG_MAX)
 		return -1;
 
 	rte_logs.dynamic_types[type].loglevel = level;
@@ -155,7 +155,7 @@ rte_log_set_level_regexp(const char *regex, uint32_t level)
 	regex_t r;
 	size_t i;
 
-	if (level > RTE_LOG_DEBUG)
+	if (level > RTE_LOG_MAX)
 		return -1;
 
 	if (regcomp(&r, regex, 0) != 0)
@@ -219,7 +219,7 @@ rte_log_set_level_pattern(const char *pattern, uint32_t level)
 {
 	size_t i;
 
-	if (level > RTE_LOG_DEBUG)
+	if (level > RTE_LOG_MAX)
 		return -1;
 
 	for (i = 0; i < rte_logs.dynamic_types_len; i++) {
@@ -323,7 +323,7 @@ rte_log_register_type_and_pick_level(const char *name, uint32_t level_def)
 		return type;
 
 	TAILQ_FOREACH(opt_ll, &opt_loglevel_list, next) {
-		if (opt_ll->level > RTE_LOG_DEBUG)
+		if (opt_ll->level > RTE_LOG_MAX)
 			continue;
 
 		if (opt_ll->pattern) {
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index cd1a2856c9..38b72fb665 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -1249,7 +1249,7 @@ eal_parse_log_priority(const char *level)
 		return -1;
 
 	/* look for named values, skip 0 which is not a valid level */
-	for (i = 1; i < RTE_DIM(levels); i++) {
+	for (i = 1; i <= RTE_LOG_MAX; i++) {
 		if (strncmp(levels[i], level, len) == 0)
 			return i;
 	}
diff --git a/lib/librte_eal/include/rte_log.h b/lib/librte_eal/include/rte_log.h
index 21a7d16340..424dfa3fd0 100644
--- a/lib/librte_eal/include/rte_log.h
+++ b/lib/librte_eal/include/rte_log.h
@@ -72,6 +72,7 @@ extern "C" {
 #define RTE_LOG_NOTICE   6U  /**< Normal but significant condition. */
 #define RTE_LOG_INFO     7U  /**< Informational.                    */
 #define RTE_LOG_DEBUG    8U  /**< Debug-level messages.             */
+#define RTE_LOG_MAX RTE_LOG_DEBUG /**< Most detailed log level.     */
 
 /**
  * Change the stream that will be used by the logging system.
-- 
2.31.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v5 3/4] log: catch invalid level option number
  2021-04-05 19:29 ` [dpdk-dev] [PATCH v5 0/4] log level enhancements Thomas Monjalon
  2021-04-05 19:29   ` [dpdk-dev] [PATCH v5 1/4] log: move private functions Thomas Monjalon
  2021-04-05 19:29   ` [dpdk-dev] [PATCH v5 2/4] log: introduce macro for maximum level Thomas Monjalon
@ 2021-04-05 19:29   ` Thomas Monjalon
  2021-04-05 19:30   ` [dpdk-dev] [PATCH v5 4/4] log: add option argument help Thomas Monjalon
                     ` (2 subsequent siblings)
  5 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-04-05 19:29 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, Bruce Richardson, Andrew Rybchenko

The parsing check for invalid log level was not trying to catch
irrelevant numeric values.
A log level 0 becomes a failure in parsing so it can be caught early.
A log level higher than the max (8) is accepted with a warning message.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 lib/librte_eal/common/eal_common_options.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 38b72fb665..7075a051b8 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -1289,10 +1289,15 @@ eal_parse_log_level(const char *arg)
 	}
 
 	priority = eal_parse_log_priority(level);
-	if (priority < 0) {
-		fprintf(stderr, "invalid log priority: %s\n", level);
+	if (priority <= 0) {
+		fprintf(stderr, "Invalid log level: %s\n", level);
 		goto fail;
 	}
+	if (priority > (int)RTE_LOG_MAX) {
+		fprintf(stderr, "Log level %d higher than maximum (%d)\n",
+				priority, RTE_LOG_MAX);
+		priority = RTE_LOG_MAX;
+	}
 
 	if (regex) {
 		if (rte_log_set_level_regexp(regex, priority) < 0) {
-- 
2.31.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v5 4/4] log: add option argument help
  2021-04-05 19:29 ` [dpdk-dev] [PATCH v5 0/4] log level enhancements Thomas Monjalon
                     ` (2 preceding siblings ...)
  2021-04-05 19:29   ` [dpdk-dev] [PATCH v5 3/4] log: catch invalid level option number Thomas Monjalon
@ 2021-04-05 19:30   ` Thomas Monjalon
  2021-04-06 13:11   ` [dpdk-dev] [PATCH v6 0/4] log level enhancements Thomas Monjalon
  2021-04-08 16:47   ` [dpdk-dev] [PATCH v7 0/4] log level enhancements Thomas Monjalon
  5 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-04-05 19:30 UTC (permalink / raw)
  To: dev
  Cc: david.marchand, Bruce Richardson, Andrew Rybchenko, Ray Kinsella,
	Neil Horman

The option --log-level was not completely described in the usage text,
and it was difficult to guess the names of the log types and levels.

A new value "help" is accepted after --log-level to give more details
about the syntax and listing the log types and levels.

The array "levels" used for level name parsing is replaced with
a (modified) existing function which was used in rte_log_dump().

The new function rte_log_list_types() is exported in the API
for allowing an application to give this info to the user
if not exposing the EAL option --log-level.
The list of log types cannot include all drivers if not linked in the
application (shared object plugin case).

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 lib/librte_eal/common/eal_common_log.c     | 51 +++++++++++++++++++---
 lib/librte_eal/common/eal_common_options.c | 44 +++++++++++++------
 lib/librte_eal/common/eal_log.h            |  5 +++
 lib/librte_eal/include/rte_log.h           | 11 +++++
 lib/librte_eal/version.map                 |  1 +
 5 files changed, 94 insertions(+), 18 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c
index b9b982fdb5..4c6766a360 100644
--- a/lib/librte_eal/common/eal_common_log.c
+++ b/lib/librte_eal/common/eal_common_log.c
@@ -397,12 +397,12 @@ RTE_INIT_PRIO(log_init, LOG)
 	rte_logs.dynamic_types_len = RTE_LOGTYPE_FIRST_EXT_ID;
 }
 
-static const char *
-loglevel_to_string(uint32_t level)
+const char *
+eal_log_level2str(uint32_t level)
 {
 	switch (level) {
 	case 0: return "disabled";
-	case RTE_LOG_EMERG: return "emerg";
+	case RTE_LOG_EMERG: return "emergency";
 	case RTE_LOG_ALERT: return "alert";
 	case RTE_LOG_CRIT: return "critical";
 	case RTE_LOG_ERR: return "error";
@@ -414,6 +414,47 @@ loglevel_to_string(uint32_t level)
 	}
 }
 
+static int
+log_type_compare(const void *a, const void *b)
+{
+	const struct rte_log_dynamic_type *type_a = a;
+	const struct rte_log_dynamic_type *type_b = b;
+
+	if (type_a->name == NULL && type_b->name == NULL)
+		return 0;
+	if (type_a->name == NULL)
+		return -1;
+	if (type_b->name == NULL)
+		return 1;
+	return strcmp(type_a->name, type_b->name);
+}
+
+/* Dump name of each logtype, one per line. */
+void
+rte_log_list_types(FILE *out, const char *prefix)
+{
+	struct rte_log_dynamic_type *sorted_types;
+	const size_t type_size = sizeof(rte_logs.dynamic_types[0]);
+	const size_t type_count = rte_logs.dynamic_types_len;
+	const size_t total_size = type_size * type_count;
+	size_t type;
+
+	sorted_types = malloc(total_size);
+	if (sorted_types == NULL) {
+		/* no sorting - unlikely */
+		sorted_types = rte_logs.dynamic_types;
+	} else {
+		memcpy(sorted_types, rte_logs.dynamic_types, total_size);
+		qsort(sorted_types, type_count, type_size, log_type_compare);
+	}
+
+	for (type = 0; type < type_count; ++type) {
+		if (sorted_types[type].name == NULL)
+			continue;
+		fprintf(out, "%s%s\n", prefix, sorted_types[type].name);
+	}
+}
+
 /* dump global level and registered log types */
 void
 rte_log_dump(FILE *f)
@@ -421,14 +462,14 @@ rte_log_dump(FILE *f)
 	size_t i;
 
 	fprintf(f, "global log level is %s\n",
-		loglevel_to_string(rte_log_get_global_level()));
+		eal_log_level2str(rte_log_get_global_level()));
 
 	for (i = 0; i < rte_logs.dynamic_types_len; i++) {
 		if (rte_logs.dynamic_types[i].name == NULL)
 			continue;
 		fprintf(f, "id %zu: %s, level is %s\n",
 			i, rte_logs.dynamic_types[i].name,
-			loglevel_to_string(rte_logs.dynamic_types[i].loglevel));
+			eal_log_level2str(rte_logs.dynamic_types[i].loglevel));
 	}
 }
 
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 7075a051b8..2951b1aca2 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -1227,19 +1227,31 @@ eal_parse_syslog(const char *facility, struct internal_config *conf)
 }
 #endif
 
+static void
+eal_log_usage(void)
+{
+	unsigned int level;
+
+	printf("Log type is a pattern matching items of this list"
+			" (plugins may be missing):\n");
+	rte_log_list_types(stdout, "\t");
+	printf("\n");
+	printf("Syntax using globbing pattern:     ");
+	printf("--"OPT_LOG_LEVEL" pattern:level\n");
+	printf("Syntax using regular expression:   ");
+	printf("--"OPT_LOG_LEVEL" regexp,level\n");
+	printf("Syntax for the global level:       ");
+	printf("--"OPT_LOG_LEVEL" level\n");
+	printf("Logs are emitted if allowed by both global and specific levels.\n");
+	printf("\n");
+	printf("Log level can be a number or the first letters of its name:\n");
+	for (level = 1; level <= RTE_LOG_MAX; level++)
+		printf("\t%d   %s\n", level, eal_log_level2str(level));
+}
+
 static int
 eal_parse_log_priority(const char *level)
 {
-	static const char * const levels[] = {
-		[RTE_LOG_EMERG]   = "emergency",
-		[RTE_LOG_ALERT]   = "alert",
-		[RTE_LOG_CRIT]    = "critical",
-		[RTE_LOG_ERR]     = "error",
-		[RTE_LOG_WARNING] = "warning",
-		[RTE_LOG_NOTICE]  = "notice",
-		[RTE_LOG_INFO]    = "info",
-		[RTE_LOG_DEBUG]   = "debug",
-	};
 	size_t len = strlen(level);
 	unsigned long tmp;
 	char *end;
@@ -1250,7 +1262,7 @@ eal_parse_log_priority(const char *level)
 
 	/* look for named values, skip 0 which is not a valid level */
 	for (i = 1; i <= RTE_LOG_MAX; i++) {
-		if (strncmp(levels[i], level, len) == 0)
+		if (strncmp(eal_log_level2str(i), level, len) == 0)
 			return i;
 	}
 
@@ -1274,6 +1286,11 @@ eal_parse_log_level(const char *arg)
 	char *str, *level;
 	int priority;
 
+	if (strcmp(arg, "help") == 0) {
+		eal_log_usage();
+		exit(EXIT_SUCCESS);
+	}
+
 	str = strdup(arg);
 	if (str == NULL)
 		return -1;
@@ -2068,9 +2085,10 @@ eal_common_usage(void)
 #ifndef RTE_EXEC_ENV_WINDOWS
 	       "  --"OPT_SYSLOG"            Set syslog facility\n"
 #endif
-	       "  --"OPT_LOG_LEVEL"=<int>   Set global log level\n"
-	       "  --"OPT_LOG_LEVEL"=<type-match>:<int>\n"
+	       "  --"OPT_LOG_LEVEL"=<level> Set global log level\n"
+	       "  --"OPT_LOG_LEVEL"=<type-match>:<level>\n"
 	       "                      Set specific log level\n"
+	       "  --"OPT_LOG_LEVEL"=help    Show log types and levels\n"
 #ifndef RTE_EXEC_ENV_WINDOWS
 	       "  --"OPT_TRACE"=<regex-match>\n"
 	       "                      Enable trace based on regular expression trace name.\n"
diff --git a/lib/librte_eal/common/eal_log.h b/lib/librte_eal/common/eal_log.h
index 684650a17b..c784fa6043 100644
--- a/lib/librte_eal/common/eal_log.h
+++ b/lib/librte_eal/common/eal_log.h
@@ -24,4 +24,9 @@ void eal_log_set_default(FILE *default_log);
 int eal_log_save_regexp(const char *regexp, uint32_t level);
 int eal_log_save_pattern(const char *pattern, uint32_t level);
 
+/*
+ * Convert log level to string.
+ */
+const char *eal_log_level2str(uint32_t level);
+
 #endif /* EAL_LOG_H */
diff --git a/lib/librte_eal/include/rte_log.h b/lib/librte_eal/include/rte_log.h
index 424dfa3fd0..ccbb7ccd81 100644
--- a/lib/librte_eal/include/rte_log.h
+++ b/lib/librte_eal/include/rte_log.h
@@ -240,6 +240,17 @@ int rte_log_register(const char *name);
 __rte_experimental
 int rte_log_register_type_and_pick_level(const char *name, uint32_t level_def);
 
+/**
+ * Dump name of each logtype, one per line.
+ *
+ * @param out
+ *   Stream where the list is sent.
+ * @param prefix
+ *   String preceding each logtype in the output.
+ */
+__rte_experimental
+void rte_log_list_types(FILE *out, const char *prefix);
+
 /**
  * Dump log information.
  *
diff --git a/lib/librte_eal/version.map b/lib/librte_eal/version.map
index e23745ae6e..6c14fea27b 100644
--- a/lib/librte_eal/version.map
+++ b/lib/librte_eal/version.map
@@ -411,6 +411,7 @@ EXPERIMENTAL {
 	rte_power_pause;
 
 	# added in 21.05
+	rte_log_list_types;
 	rte_thread_key_create;
 	rte_thread_key_delete;
 	rte_thread_value_get;
-- 
2.31.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v5 0/3] cleanup exit and usage messages in apps
  2021-03-09 23:31 [dpdk-dev] [PATCH 00/11] improve options help Thomas Monjalon
                   ` (15 preceding siblings ...)
  2021-04-05 19:29 ` [dpdk-dev] [PATCH v5 0/4] log level enhancements Thomas Monjalon
@ 2021-04-05 19:33 ` Thomas Monjalon
  2021-04-05 19:33   ` [dpdk-dev] [PATCH v5 1/3] app: fix exit messages Thomas Monjalon
                     ` (3 more replies)
  2021-04-05 19:39 ` [dpdk-dev] [PATCH v5 0/4] improve options help Thomas Monjalon
  17 siblings, 4 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-04-05 19:33 UTC (permalink / raw)
  To: dev; +Cc: david.marchand

This series is a part of a bigger one split after v4:
        "improve options help"

v5: no change

Thomas Monjalon (3):
  app: fix exit messages
  app/regex: fix usage text
  app/testpmd: fix usage text

 .../comp_perf_options_parse.c                 |  2 +-
 app/test-crypto-perf/cperf_options_parsing.c  |  2 +-
 app/test-flow-perf/main.c                     | 59 +++++++++----------
 app/test-pmd/parameters.c                     | 39 ++++--------
 app/test-regex/main.c                         |  7 +--
 5 files changed, 43 insertions(+), 66 deletions(-)

-- 
2.31.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v5 1/3] app: fix exit messages
  2021-04-05 19:33 ` [dpdk-dev] [PATCH v5 0/3] cleanup exit and usage messages in apps Thomas Monjalon
@ 2021-04-05 19:33   ` Thomas Monjalon
  2021-04-05 19:33   ` [dpdk-dev] [PATCH v5 2/3] app/regex: fix usage text Thomas Monjalon
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-04-05 19:33 UTC (permalink / raw)
  To: dev
  Cc: david.marchand, Wisam Jaddo, Ori Kam, Bruce Richardson,
	Andrew Rybchenko, Declan Doherty, Ciara Power, Xiaoyun Li

Some applications were printing useless messages with rte_exit()
after showing the help. Using exit() is enough in this case.

Some applications were using a redundant printf or fprintf() before
calling rte_exit(). The messages are unified in a single rte_exit().

Some rte_exit() calls were missing a line feed or returning a wrong code.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Wisam Jaddo <wisamm@nvidia.com>
Acked-by: Ori Kam <orika@nvidia.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 .../comp_perf_options_parse.c                 |  2 +-
 app/test-crypto-perf/cperf_options_parsing.c  |  2 +-
 app/test-flow-perf/main.c                     | 59 +++++++++----------
 app/test-pmd/parameters.c                     |  4 +-
 app/test-regex/main.c                         |  3 +-
 5 files changed, 33 insertions(+), 37 deletions(-)

diff --git a/app/test-compress-perf/comp_perf_options_parse.c b/app/test-compress-perf/comp_perf_options_parse.c
index 04a8d2fbee..019eddb7bd 100644
--- a/app/test-compress-perf/comp_perf_options_parse.c
+++ b/app/test-compress-perf/comp_perf_options_parse.c
@@ -620,7 +620,7 @@ comp_perf_options_parse(struct comp_test_data *test_data, int argc, char **argv)
 		switch (opt) {
 		case 'h':
 			usage(argv[0]);
-			rte_exit(EXIT_SUCCESS, "Displayed help\n");
+			exit(EXIT_SUCCESS);
 			break;
 		/* long options */
 		case 0:
diff --git a/app/test-crypto-perf/cperf_options_parsing.c b/app/test-crypto-perf/cperf_options_parsing.c
index 0466f7baf8..40b6dfb648 100644
--- a/app/test-crypto-perf/cperf_options_parsing.c
+++ b/app/test-crypto-perf/cperf_options_parsing.c
@@ -983,7 +983,7 @@ cperf_options_parse(struct cperf_options *options, int argc, char **argv)
 		switch (opt) {
 		case 'h':
 			usage(argv[0]);
-			rte_exit(EXIT_SUCCESS, "Displayed help\n");
+			exit(EXIT_SUCCESS);
 			break;
 		/* long options */
 		case 0:
diff --git a/app/test-flow-perf/main.c b/app/test-flow-perf/main.c
index 99d0463456..0aef767350 100644
--- a/app/test-flow-perf/main.c
+++ b/app/test-flow-perf/main.c
@@ -639,7 +639,7 @@ args_parse(int argc, char **argv)
 		case 0:
 			if (strcmp(lgopts[opt_idx].name, "help") == 0) {
 				usage(argv[0]);
-				rte_exit(EXIT_SUCCESS, "Displayed help\n");
+				exit(EXIT_SUCCESS);
 			}
 
 			if (strcmp(lgopts[opt_idx].name, "group") == 0) {
@@ -647,7 +647,7 @@ args_parse(int argc, char **argv)
 				if (n >= 0)
 					flow_group = n;
 				else
-					rte_exit(EXIT_SUCCESS,
+					rte_exit(EXIT_FAILURE,
 						"flow group should be >= 0\n");
 				printf("group %d / ", flow_group);
 			}
@@ -667,7 +667,7 @@ args_parse(int argc, char **argv)
 				if (n > 0)
 					hairpin_queues_num = n;
 				else
-					rte_exit(EXIT_SUCCESS,
+					rte_exit(EXIT_FAILURE,
 						"Hairpin queues should be > 0\n");
 
 				flow_actions[actions_idx++] =
@@ -680,7 +680,7 @@ args_parse(int argc, char **argv)
 				if (n > 0)
 					hairpin_queues_num = n;
 				else
-					rte_exit(EXIT_SUCCESS,
+					rte_exit(EXIT_FAILURE,
 						"Hairpin queues should be > 0\n");
 
 				flow_actions[actions_idx++] =
@@ -704,11 +704,9 @@ args_parse(int argc, char **argv)
 							break;
 						}
 						/* Reached last item with no match */
-						if (i == (RTE_DIM(flow_options) - 1)) {
-							fprintf(stderr, "Invalid encap item: %s\n", token);
-							usage(argv[0]);
-							rte_exit(EXIT_SUCCESS, "Invalid encap item\n");
-						}
+						if (i == (RTE_DIM(flow_options) - 1))
+							rte_exit(EXIT_FAILURE,
+								"Invalid encap item: %s\n", token);
 					}
 					token = strtok(NULL, ",");
 				}
@@ -730,11 +728,9 @@ args_parse(int argc, char **argv)
 							break;
 						}
 						/* Reached last item with no match */
-						if (i == (RTE_DIM(flow_options) - 1)) {
-							fprintf(stderr, "Invalid decap item: %s\n", token);
-							usage(argv[0]);
-							rte_exit(EXIT_SUCCESS, "Invalid decap item\n");
-						}
+						if (i == (RTE_DIM(flow_options) - 1))
+							rte_exit(EXIT_FAILURE,
+								"Invalid decap item %s\n", token);
 					}
 					token = strtok(NULL, ",");
 				}
@@ -747,9 +743,9 @@ args_parse(int argc, char **argv)
 				if (n >= DEFAULT_RULES_BATCH)
 					rules_batch = n;
 				else {
-					printf("\n\nrules_batch should be >= %d\n",
+					rte_exit(EXIT_FAILURE,
+						"rules_batch should be >= %d\n",
 						DEFAULT_RULES_BATCH);
-					rte_exit(EXIT_SUCCESS, " ");
 				}
 			}
 			if (strcmp(lgopts[opt_idx].name,
@@ -758,7 +754,8 @@ args_parse(int argc, char **argv)
 				if (n >= (int) rules_batch)
 					rules_count = n;
 				else {
-					printf("\n\nrules_count should be >= %d\n",
+					rte_exit(EXIT_FAILURE,
+						"rules_count should be >= %d\n",
 						rules_batch);
 				}
 			}
@@ -786,23 +783,23 @@ args_parse(int argc, char **argv)
 			if (strcmp(lgopts[opt_idx].name, "cores") == 0) {
 				n = atoi(optarg);
 				if ((int) rte_lcore_count() <= n) {
-					printf("\nError: you need %d cores to run on multi-cores\n"
+					rte_exit(EXIT_FAILURE,
+						"Error: you need %d cores to run on multi-cores\n"
 						"Existing cores are: %d\n", n, rte_lcore_count());
-					rte_exit(EXIT_FAILURE, " ");
 				}
 				if (n <= RTE_MAX_LCORE && n > 0)
 					mc_pool.cores_count = n;
 				else {
-					printf("Error: cores count must be > 0 "
-						" and < %d\n", RTE_MAX_LCORE);
-					rte_exit(EXIT_FAILURE, " ");
+					rte_exit(EXIT_FAILURE,
+						"Error: cores count must be > 0 and < %d\n",
+						RTE_MAX_LCORE);
 				}
 			}
 			break;
 		default:
-			fprintf(stderr, "Invalid option: %s\n", argv[optind]);
 			usage(argv[0]);
-			rte_exit(EXIT_SUCCESS, "Invalid option\n");
+			rte_exit(EXIT_FAILURE, "Invalid option: %s\n",
+					argv[optind]);
 			break;
 		}
 	}
@@ -936,7 +933,7 @@ create_meter_rule(int port_id, uint32_t counter)
 		printf("Port %u create meter idx(%d) error(%d) message: %s\n",
 			port_id, counter, error.type,
 			error.message ? error.message : "(no stated reason)");
-		rte_exit(EXIT_FAILURE, "error in creating meter");
+		rte_exit(EXIT_FAILURE, "Error in creating meter\n");
 	}
 }
 
@@ -949,7 +946,7 @@ destroy_meter_rule(int port_id, uint32_t counter)
 		printf("Port %u destroy meter(%d) error(%d) message: %s\n",
 			port_id, counter, error.type,
 			error.message ? error.message : "(no stated reason)");
-		rte_exit(EXIT_FAILURE, "Error in deleting meter rule");
+		rte_exit(EXIT_FAILURE, "Error in deleting meter rule\n");
 	}
 }
 
@@ -1097,7 +1094,7 @@ destroy_flows(int port_id, uint8_t core_id, struct rte_flow **flows_list)
 		memset(&error, 0x33, sizeof(error));
 		if (rte_flow_destroy(port_id, flows_list[i], &error)) {
 			print_flow_error(error);
-			rte_exit(EXIT_FAILURE, "Error in deleting flow");
+			rte_exit(EXIT_FAILURE, "Error in deleting flow\n");
 		}
 
 		/*
@@ -1160,7 +1157,7 @@ insert_flows(int port_id, uint8_t core_id)
 	flows_list = rte_zmalloc("flows_list",
 		(sizeof(struct rte_flow *) * rules_count_per_core) + 1, 0);
 	if (flows_list == NULL)
-		rte_exit(EXIT_FAILURE, "No Memory available!");
+		rte_exit(EXIT_FAILURE, "No Memory available!\n");
 
 	cpu_time_used = 0;
 	flow_index = 0;
@@ -1180,7 +1177,7 @@ insert_flows(int port_id, uint8_t core_id)
 
 		if (flow == NULL) {
 			print_flow_error(error);
-			rte_exit(EXIT_FAILURE, "error in creating flow");
+			rte_exit(EXIT_FAILURE, "Error in creating flow\n");
 		}
 		flows_list[flow_index++] = flow;
 	}
@@ -1199,7 +1196,7 @@ insert_flows(int port_id, uint8_t core_id)
 
 		if (!flow) {
 			print_flow_error(error);
-			rte_exit(EXIT_FAILURE, "error in creating flow");
+			rte_exit(EXIT_FAILURE, "Error in creating flow\n");
 		}
 
 		flows_list[flow_index++] = flow;
@@ -1517,7 +1514,7 @@ packet_per_second_stats(void)
 	old = rte_zmalloc("old",
 		sizeof(struct lcore_info) * RTE_MAX_LCORE, 0);
 	if (old == NULL)
-		rte_exit(EXIT_FAILURE, "No Memory available!");
+		rte_exit(EXIT_FAILURE, "No Memory available!\n");
 
 	memcpy(old, lcore_infos,
 		sizeof(struct lcore_info) * RTE_MAX_LCORE);
diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c
index a326c8ce4f..b7d4ef76b0 100644
--- a/app/test-pmd/parameters.c
+++ b/app/test-pmd/parameters.c
@@ -671,7 +671,7 @@ launch_args_parse(int argc, char** argv)
 		case 0: /*long options */
 			if (!strcmp(lgopts[opt_idx].name, "help")) {
 				usage(argv[0]);
-				rte_exit(EXIT_SUCCESS, "Displayed help\n");
+				exit(EXIT_SUCCESS);
 			}
 #ifdef RTE_LIB_CMDLINE
 			if (!strcmp(lgopts[opt_idx].name, "interactive")) {
@@ -1413,7 +1413,7 @@ launch_args_parse(int argc, char** argv)
 			break;
 		case 'h':
 			usage(argv[0]);
-			rte_exit(EXIT_SUCCESS, "Displayed help\n");
+			exit(EXIT_SUCCESS);
 			break;
 		default:
 			usage(argv[0]);
diff --git a/app/test-regex/main.c b/app/test-regex/main.c
index aea4fa6b88..7bb87bb1b8 100644
--- a/app/test-regex/main.c
+++ b/app/test-regex/main.c
@@ -154,9 +154,8 @@ args_parse(int argc, char **argv, char *rules_file, char *data_file,
 			usage("RegEx test app");
 			break;
 		default:
-			fprintf(stderr, "Invalid option: %s\n", argv[optind]);
 			usage("RegEx test app");
-			rte_exit(EXIT_FAILURE, "Invalid option\n");
+			rte_exit(EXIT_FAILURE, "Invalid option: %s\n", argv[optind]);
 			break;
 		}
 	}
-- 
2.31.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v5 2/3] app/regex: fix usage text
  2021-04-05 19:33 ` [dpdk-dev] [PATCH v5 0/3] cleanup exit and usage messages in apps Thomas Monjalon
  2021-04-05 19:33   ` [dpdk-dev] [PATCH v5 1/3] app: fix exit messages Thomas Monjalon
@ 2021-04-05 19:33   ` Thomas Monjalon
  2021-04-05 19:33   ` [dpdk-dev] [PATCH v5 3/3] app/testpmd: " Thomas Monjalon
  2021-04-09 12:31   ` [dpdk-dev] [PATCH v5 0/3] cleanup exit and usage messages in apps David Marchand
  3 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-04-05 19:33 UTC (permalink / raw)
  To: dev
  Cc: david.marchand, stable, Ori Kam, Bruce Richardson,
	Andrew Rybchenko, Yuval Avnery

The usage syntax help includes the program name which was fake.
It is replaced with the real name from argv.

Fixes: de06137cb295 ("app/regex: add RegEx test application")
Cc: stable@dpdk.org

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Ori Kam <orika@nvidia.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 app/test-regex/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/app/test-regex/main.c b/app/test-regex/main.c
index 7bb87bb1b8..f18dc2eef8 100644
--- a/app/test-regex/main.c
+++ b/app/test-regex/main.c
@@ -151,10 +151,10 @@ args_parse(int argc, char **argv, char *rules_file, char *data_file,
 			*nb_lcores = atoi(optarg);
 			break;
 		case ARG_HELP:
-			usage("RegEx test app");
+			usage(argv[0]);
 			break;
 		default:
-			usage("RegEx test app");
+			usage(argv[0]);
 			rte_exit(EXIT_FAILURE, "Invalid option: %s\n", argv[optind]);
 			break;
 		}
-- 
2.31.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v5 3/3] app/testpmd: fix usage text
  2021-04-05 19:33 ` [dpdk-dev] [PATCH v5 0/3] cleanup exit and usage messages in apps Thomas Monjalon
  2021-04-05 19:33   ` [dpdk-dev] [PATCH v5 1/3] app: fix exit messages Thomas Monjalon
  2021-04-05 19:33   ` [dpdk-dev] [PATCH v5 2/3] app/regex: fix usage text Thomas Monjalon
@ 2021-04-05 19:33   ` Thomas Monjalon
  2021-04-09 12:31   ` [dpdk-dev] [PATCH v5 0/3] cleanup exit and usage messages in apps David Marchand
  3 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-04-05 19:33 UTC (permalink / raw)
  To: dev
  Cc: david.marchand, stable, Ajit Khaparde, Bruce Richardson,
	Andrew Rybchenko, Xiaoyun Li, Jens Freimann, Bing Zhao, Ori Kam,
	Kevin Traynor, Bernard Iremonger, Stephen Hemminger,
	Pablo de Lara, Maciej Czekaj

The options help text was including an incomplete and redundant
summary of the options before explaining each. The summary is dropped.

The details of the option --hairpin-mode had an extra space,
breaking the alignment with the next line.

There were some mismatches between options in the usage text
	sed -rn 's/.*\(" *--([a-z-]*)[=: ].*/\1/p' app/test-pmd/parameters.c
and the options declared in lgopts array
	sed -rn 's/.*\{.*"(.*)",.*,.*,.*},.*/\1/p' app/test-pmd/parameters.c
The misses were:
	--no-numa
	--enable-scatter
	--tx-ip
	--tx-udp
	--noisy-lkup-num-reads-writes
The option --ports was not implemented.

Fixes: 01817b10d27c ("app/testpmd: change hairpin queues setup")
Fixes: 3c156061b938 ("app/testpmd: add noisy neighbour forwarding mode")
Fixes: bf5b2126bf44 ("app/testpmd: add ability to set Tx IP and UDP parameters")
Fixes: 0499793854f5 ("app/testpmd: add scatter enabling option")
Fixes: 999b2ee0fe45 ("app/testpmd: enable NUMA support by default")
Fixes: af75078fece3 ("first public release")
Cc: stable@dpdk.org

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
Acked-by: Xiaoyun Li <xiaoyun.li@intel.com>
Reviewed-by: Jens Freimann <jfreimann@redhat.com>
Reviewed-by: Bing Zhao <bingz@nvidia.com>
---
 app/test-pmd/parameters.c | 35 ++++++++---------------------------
 1 file changed, 8 insertions(+), 27 deletions(-)

diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c
index b7d4ef76b0..f3954c1c63 100644
--- a/app/test-pmd/parameters.c
+++ b/app/test-pmd/parameters.c
@@ -49,29 +49,7 @@
 static void
 usage(char* progname)
 {
-	printf("usage: %s [EAL options] -- "
-#ifdef RTE_LIB_CMDLINE
-	       "[--interactive|-i] "
-	       "[--cmdline-file=FILENAME] "
-#endif
-	       "[--help|-h] | [--auto-start|-a] | ["
-	       "--tx-first | --stats-period=PERIOD | "
-	       "--coremask=COREMASK --portmask=PORTMASK --numa "
-	       "--portlist=PORTLIST "
-	       "--mbuf-size= | --total-num-mbufs= | "
-	       "--nb-cores= | --nb-ports= | "
-#ifdef RTE_LIB_CMDLINE
-	       "--eth-peers-configfile= | "
-	       "--eth-peer=X,M:M:M:M:M:M | "
-	       "--tx-ip=SRC,DST | --tx-udp=PORT | "
-#endif
-	       "--pkt-filter-mode= |"
-	       "--rss-ip | --rss-udp | --rss-level-inner | --rss-level-outer |"
-	       "--rxpt= | --rxht= | --rxwt= |"
-	       " --rxfreet= | --txpt= | --txht= | --txwt= | --txfreet= | "
-	       "--txrst= | --tx-offloads= | | --rx-offloads= | "
-	       "--vxlan-gpe-port= | --geneve-parsed-port= | "
-	       "--record-core-cycles | --record-burst-stats]\n",
+	printf("\nUsage: %s [EAL options] -- [testpmd options]\n\n",
 	       progname);
 #ifdef RTE_LIB_CMDLINE
 	printf("  --interactive: run in interactive mode.\n");
@@ -97,6 +75,7 @@ usage(char* progname)
 	printf("  --portlist=PORTLIST: list of forwarding ports\n");
 	printf("  --numa: enable NUMA-aware allocation of RX/TX rings and of "
 	       "RX memory buffers (mbufs).\n");
+	printf("  --no-numa: disable NUMA-aware allocation.\n");
 	printf("  --port-numa-config=(port,socket)[,(port,socket)]: "
 	       "specify the socket on which the memory pool "
 	       "used by the port will be allocated.\n");
@@ -136,6 +115,7 @@ usage(char* progname)
 	       "monitoring on forwarding lcore id N.\n");
 #endif
 	printf("  --disable-crc-strip: disable CRC stripping by hardware.\n");
+	printf("  --enable-scatter: enable scattered Rx.\n");
 	printf("  --enable-lro: enable large receive offload.\n");
 	printf("  --enable-rx-cksum: enable rx hardware checksum offload.\n");
 	printf("  --enable-rx-timestamp: enable rx hardware timestamp offload.\n");
@@ -184,6 +164,8 @@ usage(char* progname)
 	printf("  --txpkts=X[,Y]*: set TX segment sizes"
 		" or total packet length.\n");
 	printf("  --txonly-multi-flow: generate multiple flows in txonly mode\n");
+	printf("  --tx-ip=src,dst: IP addresses in Tx-only mode\n");
+	printf("  --tx-udp=src[,dst]: UDP ports in Tx-only mode\n");
 	printf("  --eth-link-speed: force link speed.\n");
 	printf("  --disable-link-check: disable check on link status when "
 	       "starting/stopping ports.\n");
@@ -215,14 +197,14 @@ usage(char* progname)
 	printf("  --noisy-lkup-memory=N: allocate N MB of VNF memory\n");
 	printf("  --noisy-lkup-num-writes=N: do N random writes per packet\n");
 	printf("  --noisy-lkup-num-reads=N: do N random reads per packet\n");
-	printf("  --noisy-lkup-num-writes=N: do N random reads and writes per packet\n");
+	printf("  --noisy-lkup-num-reads-writes=N: do N random reads and writes per packet\n");
 	printf("  --no-iova-contig: mempool memory can be IOVA non contiguous. "
 	       "valid only with --mp-alloc=anon\n");
 	printf("  --rx-mq-mode=0xX: hexadecimal bitmask of RX mq mode can be "
 	       "enabled\n");
 	printf("  --record-core-cycles: enable measurement of CPU cycles.\n");
 	printf("  --record-burst-stats: enable display of RX and TX bursts.\n");
-	printf("  --hairpin-mode=0xXX: bitmask set the hairpin port mode.\n "
+	printf("  --hairpin-mode=0xXX: bitmask set the hairpin port mode.\n"
 	       "    0x10 - explicit Tx rule, 0x02 - hairpin ports paired\n"
 	       "    0x01 - hairpin ports loop, 0x00 - hairpin port self\n");
 }
@@ -549,7 +531,6 @@ launch_args_parse(int argc, char** argv)
 #endif
 		{ "tx-first",			0, 0, 0 },
 		{ "stats-period",		1, 0, 0 },
-		{ "ports",			1, 0, 0 },
 		{ "nb-cores",			1, 0, 0 },
 		{ "nb-ports",			1, 0, 0 },
 		{ "coremask",			1, 0, 0 },
@@ -557,7 +538,7 @@ launch_args_parse(int argc, char** argv)
 		{ "portlist",			1, 0, 0 },
 		{ "numa",			0, 0, 0 },
 		{ "no-numa",			0, 0, 0 },
-		{ "mp-anon",			0, 0, 0 },
+		{ "mp-anon",			0, 0, 0 }, /* deprecated */
 		{ "port-numa-config",           1, 0, 0 },
 		{ "ring-numa-config",           1, 0, 0 },
 		{ "socket-num",			1, 0, 0 },
-- 
2.31.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v5 0/4] improve options help
  2021-03-09 23:31 [dpdk-dev] [PATCH 00/11] improve options help Thomas Monjalon
                   ` (16 preceding siblings ...)
  2021-04-05 19:33 ` [dpdk-dev] [PATCH v5 0/3] cleanup exit and usage messages in apps Thomas Monjalon
@ 2021-04-05 19:39 ` Thomas Monjalon
  2021-04-05 19:39   ` [dpdk-dev] [PATCH v5 1/4] eal: explain argv behaviour during init Thomas Monjalon
                     ` (3 more replies)
  17 siblings, 4 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-04-05 19:39 UTC (permalink / raw)
  To: dev; +Cc: david.marchand

After v4, this series is split in several parts.
The remaining 4 patches of this series are low priority.

Patches 1 and 3 are simple improvements.

Patches 2 and 4 lead to a new formatting of the usage text.
It is a matter of taste and should be discussed more.

v5: no change

Thomas Monjalon (4):
  eal: explain argv behaviour during init
  eal: improve options usage text
  eal: use macros for help option
  app: hook in EAL usage help

 app/pdump/main.c                                 |  2 ++
 app/proc-info/main.c                             |  2 ++
 app/test-acl/main.c                              |  2 ++
 app/test-bbdev/main.c                            |  3 ++-
 app/test-compress-perf/comp_perf_options.h       |  2 ++
 app/test-compress-perf/comp_perf_options_parse.c |  8 ++++----
 app/test-compress-perf/main.c                    |  3 ++-
 app/test-crypto-perf/cperf_options.h             |  2 ++
 app/test-crypto-perf/cperf_options_parsing.c     |  8 ++++----
 app/test-crypto-perf/main.c                      |  3 ++-
 app/test-fib/main.c                              |  8 ++++++++
 app/test-flow-perf/main.c                        |  4 +++-
 app/test-pmd/parameters.c                        |  4 ++--
 app/test-pmd/testpmd.c                           |  2 ++
 app/test-pmd/testpmd.h                           |  1 +
 app/test-regex/main.c                            |  3 ++-
 app/test-sad/main.c                              |  7 +++++++
 lib/librte_eal/common/eal_common_options.c       | 13 ++++++-------
 lib/librte_eal/freebsd/eal.c                     | 10 +++++-----
 lib/librte_eal/include/rte_eal.h                 |  2 ++
 lib/librte_eal/linux/eal.c                       | 14 +++++++-------
 lib/librte_eal/windows/eal.c                     | 12 +++++-------
 22 files changed, 74 insertions(+), 41 deletions(-)

-- 
2.31.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v5 1/4] eal: explain argv behaviour during init
  2021-04-05 19:39 ` [dpdk-dev] [PATCH v5 0/4] improve options help Thomas Monjalon
@ 2021-04-05 19:39   ` Thomas Monjalon
  2021-04-05 19:39   ` [dpdk-dev] [PATCH v5 2/4] eal: improve options usage text Thomas Monjalon
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-04-05 19:39 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, Bruce Richardson, Andrew Rybchenko

After argument parsing done by rte_eal_init(),
the remaining arguments are to be parsed by the application
by progressing in the argv array.
In this context, the first string represented by argv[0] is still
the same program name as the original argv[0],
while the next strings are the application arguments.
This is because rte_eal_init() manipulates the argv array
after EAL parsing, before returning to the application.

This note was missing in the doxygen comment of the API.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 lib/librte_eal/include/rte_eal.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/librte_eal/include/rte_eal.h b/lib/librte_eal/include/rte_eal.h
index eaf6469e50..0cbeedb594 100644
--- a/lib/librte_eal/include/rte_eal.h
+++ b/lib/librte_eal/include/rte_eal.h
@@ -76,6 +76,8 @@ int rte_eal_iopl_init(void);
  * @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.
+ *   The program name pointer argv[0] is copied into the last parsed argv
+ *   so that argv[0] is still the same after deducing the parsed arguments.
  * @return
  *   - On success, the number of parsed arguments, which is greater or
  *     equal to zero. After the call to rte_eal_init(),
-- 
2.31.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v5 2/4] eal: improve options usage text
  2021-04-05 19:39 ` [dpdk-dev] [PATCH v5 0/4] improve options help Thomas Monjalon
  2021-04-05 19:39   ` [dpdk-dev] [PATCH v5 1/4] eal: explain argv behaviour during init Thomas Monjalon
@ 2021-04-05 19:39   ` Thomas Monjalon
  2021-04-05 19:39   ` [dpdk-dev] [PATCH v5 3/4] eal: use macros for help option Thomas Monjalon
  2021-04-05 19:39   ` [dpdk-dev] [PATCH v5 4/4] app: hook in EAL usage help Thomas Monjalon
  3 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-04-05 19:39 UTC (permalink / raw)
  To: dev
  Cc: david.marchand, Bruce Richardson, Andrew Rybchenko,
	Dmitry Kozlyuk, Narcisa Ana Maria Vasile, Dmitry Malloy,
	Pallavi Kadam

The description of the EAL options was printed before the application
description provided via the hook.
It is better to let the application print the global syntax
and describes the detail of the EAL options below.

Also, some useless lines are removed,
and the alignment of few options is fixed.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 lib/librte_eal/common/eal_common_options.c | 11 +++++------
 lib/librte_eal/freebsd/eal.c               |  8 ++++----
 lib/librte_eal/linux/eal.c                 | 12 ++++++------
 lib/librte_eal/windows/eal.c               | 10 ++++------
 4 files changed, 19 insertions(+), 22 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 2951b1aca2..08a85614c9 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -2045,8 +2045,7 @@ rte_vect_set_max_simd_bitwidth(uint16_t bitwidth)
 void
 eal_common_usage(void)
 {
-	printf("[options]\n\n"
-	       "EAL common options:\n"
+	printf("EAL common options:\n"
 	       "  -c COREMASK         Hexadecimal bitmask of cores to run on\n"
 	       "  -l CORELIST         List of cores to run on\n"
 	       "                      The argument format is <c1>[-c2][,c3[-c4],...]\n"
@@ -2076,7 +2075,7 @@ eal_common_usage(void)
 	       "  --"OPT_VDEV"              Add a virtual device.\n"
 	       "                      The argument format is <driver><id>[,key=val,...]\n"
 	       "                      (ex: --vdev=net_pcap0,iface=eth2).\n"
-	       "  --"OPT_IOVA_MODE"   Set IOVA mode. 'pa' for IOVA_PA\n"
+	       "  --"OPT_IOVA_MODE"         Set IOVA mode. 'pa' for IOVA_PA\n"
 	       "                      'va' for IOVA_VA\n"
 	       "  -d LIB.so|DIR       Add a driver or driver directory\n"
 	       "                      (can be used multiple times)\n"
@@ -2116,11 +2115,11 @@ eal_common_usage(void)
 #endif /* !RTE_EXEC_ENV_WINDOWS */
 	       "  -v                  Display version information on startup\n"
 	       "  -h, --help          This help\n"
-	       "  --"OPT_IN_MEMORY"   Operate entirely in memory. This will\n"
+	       "  --"OPT_IN_MEMORY"         Operate entirely in memory. This will\n"
 	       "                      disable secondary process support\n"
 	       "  --"OPT_BASE_VIRTADDR"     Base virtual address\n"
-	       "  --"OPT_TELEMETRY"   Enable telemetry support (on by default)\n"
-	       "  --"OPT_NO_TELEMETRY"   Disable telemetry support\n"
+	       "  --"OPT_TELEMETRY"         Enable telemetry support (on by default)\n"
+	       "  --"OPT_NO_TELEMETRY"      Disable telemetry support\n"
 	       "  --"OPT_FORCE_MAX_SIMD_BITWIDTH" Force the max SIMD bitwidth\n"
 	       "\nEAL options for DEBUG use only:\n"
 	       "  --"OPT_HUGE_UNLINK"       Unlink hugepage files after init\n"
diff --git a/lib/librte_eal/freebsd/eal.c b/lib/librte_eal/freebsd/eal.c
index 32442e5ba6..4e10d37253 100644
--- a/lib/librte_eal/freebsd/eal.c
+++ b/lib/librte_eal/freebsd/eal.c
@@ -421,13 +421,13 @@ eal_usage(const char *prgname)
 {
 	rte_usage_hook_t hook = eal_get_application_usage_hook();
 
-	printf("\nUsage: %s ", prgname);
-	eal_common_usage();
-	/* Allow the application to print its usage message too if hook is set */
 	if (hook) {
-		printf("===== Application Usage =====\n\n");
+		/* Print application usage through EAL options parsing. */
 		(hook)(prgname);
+		printf("\n");
 	}
+
+	eal_common_usage();
 }
 
 static inline size_t
diff --git a/lib/librte_eal/linux/eal.c b/lib/librte_eal/linux/eal.c
index ac27dd4274..4f36f9b1f5 100644
--- a/lib/librte_eal/linux/eal.c
+++ b/lib/librte_eal/linux/eal.c
@@ -535,7 +535,12 @@ eal_usage(const char *prgname)
 {
 	rte_usage_hook_t hook = eal_get_application_usage_hook();
 
-	printf("\nUsage: %s ", prgname);
+	if (hook) {
+		/* Print application usage through EAL options parsing. */
+		(hook)(prgname);
+		printf("\n");
+	}
+
 	eal_common_usage();
 	printf("EAL Linux options:\n"
 	       "  --"OPT_SOCKET_MEM"        Memory to allocate on sockets (comma separated values)\n"
@@ -549,11 +554,6 @@ eal_usage(const char *prgname)
 	       "  --"OPT_SINGLE_FILE_SEGMENTS" Put all hugepage memory in single files\n"
 	       "  --"OPT_MATCH_ALLOCATIONS" Free hugepages exactly as allocated\n"
 	       "\n");
-	/* Allow the application to print its usage message too if hook is set */
-	if (hook) {
-		printf("===== Application Usage =====\n\n");
-		(hook)(prgname);
-	}
 }
 
 static int
diff --git a/lib/librte_eal/windows/eal.c b/lib/librte_eal/windows/eal.c
index 68a1fd1d21..25921eecb2 100644
--- a/lib/librte_eal/windows/eal.c
+++ b/lib/librte_eal/windows/eal.c
@@ -80,15 +80,13 @@ eal_usage(const char *prgname)
 {
 	rte_usage_hook_t hook = eal_get_application_usage_hook();
 
-	printf("\nUsage: %s ", prgname);
-	eal_common_usage();
-	/* Allow the application to print its usage message too
-	 * if hook is set
-	 */
 	if (hook) {
-		printf("===== Application Usage =====\n\n");
+		/* Print application usage through EAL options parsing. */
 		(hook)(prgname);
+		printf("\n");
 	}
+
+	eal_common_usage();
 }
 
 /* Parse the arguments for --log-level only */
-- 
2.31.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v5 3/4] eal: use macros for help option
  2021-04-05 19:39 ` [dpdk-dev] [PATCH v5 0/4] improve options help Thomas Monjalon
  2021-04-05 19:39   ` [dpdk-dev] [PATCH v5 1/4] eal: explain argv behaviour during init Thomas Monjalon
  2021-04-05 19:39   ` [dpdk-dev] [PATCH v5 2/4] eal: improve options usage text Thomas Monjalon
@ 2021-04-05 19:39   ` Thomas Monjalon
  2021-04-05 19:39   ` [dpdk-dev] [PATCH v5 4/4] app: hook in EAL usage help Thomas Monjalon
  3 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-04-05 19:39 UTC (permalink / raw)
  To: dev
  Cc: david.marchand, Bruce Richardson, Andrew Rybchenko,
	Dmitry Kozlyuk, Narcisa Ana Maria Vasile, Dmitry Malloy,
	Pallavi Kadam

The macros OPT_HELP and OPT_HELP_NUM were not used where appropriate.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 lib/librte_eal/common/eal_common_options.c | 2 +-
 lib/librte_eal/freebsd/eal.c               | 2 +-
 lib/librte_eal/linux/eal.c                 | 2 +-
 lib/librte_eal/windows/eal.c               | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 08a85614c9..1da6583d71 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -2114,7 +2114,7 @@ eal_common_usage(void)
 	       "                      must be specified once only.\n"
 #endif /* !RTE_EXEC_ENV_WINDOWS */
 	       "  -v                  Display version information on startup\n"
-	       "  -h, --help          This help\n"
+	       "  -h, --"OPT_HELP"          This help\n"
 	       "  --"OPT_IN_MEMORY"         Operate entirely in memory. This will\n"
 	       "                      disable secondary process support\n"
 	       "  --"OPT_BASE_VIRTADDR"     Base virtual address\n"
diff --git a/lib/librte_eal/freebsd/eal.c b/lib/librte_eal/freebsd/eal.c
index 4e10d37253..73229ff9c4 100644
--- a/lib/librte_eal/freebsd/eal.c
+++ b/lib/librte_eal/freebsd/eal.c
@@ -549,7 +549,7 @@ eal_parse_args(int argc, char **argv)
 			}
 			break;
 		}
-		case 'h':
+		case OPT_HELP_NUM:
 			eal_usage(prgname);
 			exit(EXIT_SUCCESS);
 		default:
diff --git a/lib/librte_eal/linux/eal.c b/lib/librte_eal/linux/eal.c
index 4f36f9b1f5..d3615de641 100644
--- a/lib/librte_eal/linux/eal.c
+++ b/lib/librte_eal/linux/eal.c
@@ -717,7 +717,7 @@ eal_parse_args(int argc, char **argv)
 			continue;
 
 		switch (opt) {
-		case 'h':
+		case OPT_HELP_NUM:
 			eal_usage(prgname);
 			exit(EXIT_SUCCESS);
 
diff --git a/lib/librte_eal/windows/eal.c b/lib/librte_eal/windows/eal.c
index 25921eecb2..5bca3ace1c 100644
--- a/lib/librte_eal/windows/eal.c
+++ b/lib/librte_eal/windows/eal.c
@@ -159,7 +159,7 @@ eal_parse_args(int argc, char **argv)
 			continue;
 
 		switch (opt) {
-		case 'h':
+		case OPT_HELP_NUM:
 			eal_usage(prgname);
 			exit(EXIT_SUCCESS);
 		default:
-- 
2.31.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v5 4/4] app: hook in EAL usage help
  2021-04-05 19:39 ` [dpdk-dev] [PATCH v5 0/4] improve options help Thomas Monjalon
                     ` (2 preceding siblings ...)
  2021-04-05 19:39   ` [dpdk-dev] [PATCH v5 3/4] eal: use macros for help option Thomas Monjalon
@ 2021-04-05 19:39   ` Thomas Monjalon
  2021-04-06 13:32     ` Jerin Jacob
  3 siblings, 1 reply; 121+ messages in thread
From: Thomas Monjalon @ 2021-04-05 19:39 UTC (permalink / raw)
  To: dev
  Cc: david.marchand, Wisam Jaddo, Bruce Richardson, Andrew Rybchenko,
	Reshma Pattan, Maryam Tahhan, Konstantin Ananyev,
	Nicolas Chautru, Declan Doherty, Ciara Power, Vladimir Medvedkin,
	Xiaoyun Li, Ori Kam, Bernard Iremonger

Use rte_set_application_usage_hook() in the test applications,
so the full help including EAL options can be printed in one go
with the EAL option -h or --help.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Wisam Jaddo <wisamm@nvidia.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 app/pdump/main.c                                 | 2 ++
 app/proc-info/main.c                             | 2 ++
 app/test-acl/main.c                              | 2 ++
 app/test-bbdev/main.c                            | 3 ++-
 app/test-compress-perf/comp_perf_options.h       | 2 ++
 app/test-compress-perf/comp_perf_options_parse.c | 8 ++++----
 app/test-compress-perf/main.c                    | 3 ++-
 app/test-crypto-perf/cperf_options.h             | 2 ++
 app/test-crypto-perf/cperf_options_parsing.c     | 8 ++++----
 app/test-crypto-perf/main.c                      | 3 ++-
 app/test-fib/main.c                              | 8 ++++++++
 app/test-flow-perf/main.c                        | 4 +++-
 app/test-pmd/parameters.c                        | 4 ++--
 app/test-pmd/testpmd.c                           | 2 ++
 app/test-pmd/testpmd.h                           | 1 +
 app/test-regex/main.c                            | 3 ++-
 app/test-sad/main.c                              | 7 +++++++
 17 files changed, 49 insertions(+), 15 deletions(-)

diff --git a/app/pdump/main.c b/app/pdump/main.c
index 63bbe65cd8..8641017f48 100644
--- a/app/pdump/main.c
+++ b/app/pdump/main.c
@@ -974,6 +974,8 @@ main(int argc, char **argv)
 	char mp_flag[] = "--proc-type=secondary";
 	char *argp[argc + 2];
 
+	rte_set_application_usage_hook(pdump_usage);
+
 	/* catch ctrl-c so we can print on exit */
 	signal(SIGINT, signal_handler);
 
diff --git a/app/proc-info/main.c b/app/proc-info/main.c
index b9587f7ded..e7d86bfa9d 100644
--- a/app/proc-info/main.c
+++ b/app/proc-info/main.c
@@ -1361,6 +1361,8 @@ main(int argc, char **argv)
 	char *argp[argc + 4];
 	uint16_t nb_ports;
 
+	rte_set_application_usage_hook(proc_info_usage);
+
 	/* preparse app arguments */
 	ret = proc_info_preparse_args(argc, argv);
 	if (ret < 0) {
diff --git a/app/test-acl/main.c b/app/test-acl/main.c
index 2cb2fe2579..9f95cb0fbf 100644
--- a/app/test-acl/main.c
+++ b/app/test-acl/main.c
@@ -1080,6 +1080,8 @@ main(int argc, char **argv)
 	int ret;
 	uint32_t lcore;
 
+	rte_set_application_usage_hook(print_usage);
+
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
 		rte_panic("Cannot init EAL\n");
diff --git a/app/test-bbdev/main.c b/app/test-bbdev/main.c
index ff65173fdb..5960ec18b2 100644
--- a/app/test-bbdev/main.c
+++ b/app/test-bbdev/main.c
@@ -340,7 +340,8 @@ main(int argc, char **argv)
 {
 	int ret;
 
-	/* Init EAL */
+	rte_set_application_usage_hook(print_usage);
+
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
 		return 1;
diff --git a/app/test-compress-perf/comp_perf_options.h b/app/test-compress-perf/comp_perf_options.h
index 0b777521c5..7dd785fba1 100644
--- a/app/test-compress-perf/comp_perf_options.h
+++ b/app/test-compress-perf/comp_perf_options.h
@@ -73,6 +73,8 @@ struct comp_test_data {
 	uint32_t cyclecount_delay;
 };
 
+void comp_perf_usage(const char *progname);
+
 int
 comp_perf_options_parse(struct comp_test_data *test_data, int argc,
 			char **argv);
diff --git a/app/test-compress-perf/comp_perf_options_parse.c b/app/test-compress-perf/comp_perf_options_parse.c
index 019eddb7bd..39d7fd8c69 100644
--- a/app/test-compress-perf/comp_perf_options_parse.c
+++ b/app/test-compress-perf/comp_perf_options_parse.c
@@ -38,8 +38,8 @@ struct name_id_map {
 	uint32_t id;
 };
 
-static void
-usage(char *progname)
+void
+comp_perf_usage(const char *progname)
 {
 	printf("%s [EAL options] --\n"
 		" --ptest throughput / verify / pmd-cyclecount\n"
@@ -619,7 +619,7 @@ comp_perf_options_parse(struct comp_test_data *test_data, int argc, char **argv)
 	while ((opt = getopt_long(argc, argv, "h", lgopts, &opt_idx)) != EOF) {
 		switch (opt) {
 		case 'h':
-			usage(argv[0]);
+			comp_perf_usage(argv[0]);
 			exit(EXIT_SUCCESS);
 			break;
 		/* long options */
@@ -631,7 +631,7 @@ comp_perf_options_parse(struct comp_test_data *test_data, int argc, char **argv)
 			break;
 
 		default:
-			usage(argv[0]);
+			comp_perf_usage(argv[0]);
 			return -EINVAL;
 		}
 	}
diff --git a/app/test-compress-perf/main.c b/app/test-compress-perf/main.c
index cc9951a9b1..dcd347528e 100644
--- a/app/test-compress-perf/main.c
+++ b/app/test-compress-perf/main.c
@@ -323,7 +323,8 @@ main(int argc, char **argv)
 	uint8_t cdev_id;
 	uint32_t lcore_id;
 
-	/* Initialise DPDK EAL */
+	rte_set_application_usage_hook(comp_perf_usage);
+
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
 		rte_exit(EXIT_FAILURE, "Invalid EAL arguments!\n");
diff --git a/app/test-crypto-perf/cperf_options.h b/app/test-crypto-perf/cperf_options.h
index 9664a4b343..5f4a780614 100644
--- a/app/test-crypto-perf/cperf_options.h
+++ b/app/test-crypto-perf/cperf_options.h
@@ -153,6 +153,8 @@ struct cperf_options {
 	uint8_t imix_distribution_count;
 };
 
+void cperf_usage(const char *progname);
+
 void
 cperf_options_default(struct cperf_options *options);
 
diff --git a/app/test-crypto-perf/cperf_options_parsing.c b/app/test-crypto-perf/cperf_options_parsing.c
index 40b6dfb648..3777bc7509 100644
--- a/app/test-crypto-perf/cperf_options_parsing.c
+++ b/app/test-crypto-perf/cperf_options_parsing.c
@@ -19,8 +19,8 @@ struct name_id_map {
 	uint32_t id;
 };
 
-static void
-usage(char *progname)
+void
+cperf_usage(const char *progname)
 {
 	printf("%s [EAL options] --\n"
 		" --silent: disable options dump\n"
@@ -982,7 +982,7 @@ cperf_options_parse(struct cperf_options *options, int argc, char **argv)
 	while ((opt = getopt_long(argc, argv, "h", lgopts, &opt_idx)) != EOF) {
 		switch (opt) {
 		case 'h':
-			usage(argv[0]);
+			cperf_usage(argv[0]);
 			exit(EXIT_SUCCESS);
 			break;
 		/* long options */
@@ -994,7 +994,7 @@ cperf_options_parse(struct cperf_options *options, int argc, char **argv)
 			break;
 
 		default:
-			usage(argv[0]);
+			cperf_usage(argv[0]);
 			return -EINVAL;
 		}
 	}
diff --git a/app/test-crypto-perf/main.c b/app/test-crypto-perf/main.c
index 49af812d8b..497c4c5226 100644
--- a/app/test-crypto-perf/main.c
+++ b/app/test-crypto-perf/main.c
@@ -519,7 +519,8 @@ main(int argc, char **argv)
 	int ret;
 	uint32_t lcore_id;
 
-	/* Initialise DPDK EAL */
+	rte_set_application_usage_hook(cperf_usage);
+
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
 		rte_exit(EXIT_FAILURE, "Invalid EAL arguments!\n");
diff --git a/app/test-fib/main.c b/app/test-fib/main.c
index b0a97b0d7e..420fe17c39 100644
--- a/app/test-fib/main.c
+++ b/app/test-fib/main.c
@@ -648,6 +648,12 @@ print_usage(void)
 		config.prgname);
 }
 
+static void
+usage_hook(const char *prgname __rte_unused)
+{
+	print_usage();
+}
+
 static int
 check_config(void)
 {
@@ -1209,6 +1215,8 @@ main(int argc, char **argv)
 	FILE *fl = NULL;
 	uint8_t depth_lim;
 
+	rte_set_application_usage_hook(usage_hook);
+
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
 		rte_panic("Cannot init EAL\n");
diff --git a/app/test-flow-perf/main.c b/app/test-flow-perf/main.c
index 0aef767350..949a5e3e11 100644
--- a/app/test-flow-perf/main.c
+++ b/app/test-flow-perf/main.c
@@ -115,7 +115,7 @@ static struct multi_cores_pool mc_pool = {
 };
 
 static void
-usage(char *progname)
+usage(const char *progname)
 {
 	printf("\nusage: %s\n", progname);
 	printf("\nControl configurations:\n");
@@ -1849,6 +1849,8 @@ main(int argc, char **argv)
 	uint16_t port;
 	struct rte_flow_error error;
 
+	rte_set_application_usage_hook(usage);
+
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
 		rte_exit(EXIT_FAILURE, "EAL init failed\n");
diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c
index f3954c1c63..4a1d64af89 100644
--- a/app/test-pmd/parameters.c
+++ b/app/test-pmd/parameters.c
@@ -46,8 +46,8 @@
 
 #include "testpmd.h"
 
-static void
-usage(char* progname)
+void
+usage(const char *progname)
 {
 	printf("\nUsage: %s [EAL options] -- [testpmd options]\n\n",
 	       progname);
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 96d2e0fcec..007ae429a1 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -3781,6 +3781,8 @@ main(int argc, char** argv)
 		rte_exit(EXIT_FAILURE, "Cannot register log type");
 	rte_log_set_level(testpmd_logtype, RTE_LOG_DEBUG);
 
+	rte_set_application_usage_hook(usage);
+
 	diag = rte_eal_init(argc, argv);
 	if (diag < 0)
 		rte_exit(EXIT_FAILURE, "Cannot init EAL: %s\n",
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index a87ccb0f0f..1f9408ebb9 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -764,6 +764,7 @@ inc_tx_burst_stats(struct fwd_stream *fs, uint16_t nb_tx)
 unsigned int parse_item_list(char* str, const char* item_name,
 			unsigned int max_items,
 			unsigned int *parsed_items, int check_unique_values);
+void usage(const char *progname);
 void launch_args_parse(int argc, char** argv);
 void cmdline_read_from_file(const char *filename);
 void prompt(void);
diff --git a/app/test-regex/main.c b/app/test-regex/main.c
index f18dc2eef8..73ba227fba 100644
--- a/app/test-regex/main.c
+++ b/app/test-regex/main.c
@@ -616,7 +616,8 @@ main(int argc, char **argv)
 	uint32_t i;
 	struct qps_per_lcore *qps_per_lcore;
 
-	/* Init EAL. */
+	rte_set_application_usage_hook(usage);
+
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
 		rte_exit(EXIT_FAILURE, "EAL init failed\n");
diff --git a/app/test-sad/main.c b/app/test-sad/main.c
index 1024757add..14a8263f8c 100644
--- a/app/test-sad/main.c
+++ b/app/test-sad/main.c
@@ -149,7 +149,12 @@ print_usage(void)
 		"[-p <parallel lookup on all available cores>]\n"
 		"[-c <init sad supporting read/write concurrency>]\n",
 		config.prgname);
+}
 
+static void
+usage_hook(const char *prgname __rte_unused)
+{
+	print_usage();
 }
 
 static int
@@ -620,6 +625,8 @@ main(int argc, char **argv)
 	struct rte_ipsec_sad_conf conf = {0};
 	unsigned int lcore_id;
 
+	rte_set_application_usage_hook(usage_hook);
+
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
 		rte_panic("Cannot init EAL\n");
-- 
2.31.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH v5 1/4] log: move private functions
  2021-04-05 19:29   ` [dpdk-dev] [PATCH v5 1/4] log: move private functions Thomas Monjalon
@ 2021-04-06 11:28     ` David Marchand
  2021-04-06 12:08       ` Thomas Monjalon
  0 siblings, 1 reply; 121+ messages in thread
From: David Marchand @ 2021-04-06 11:28 UTC (permalink / raw)
  To: Thomas Monjalon
  Cc: dev, Bruce Richardson, Andrew Rybchenko, Dmitry Kozlyuk,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam

On Mon, Apr 5, 2021 at 9:30 PM Thomas Monjalon <thomas@monjalon.net> wrote:
>
> Some private log functions had a wrong "rte_" prefix.
>
> All private log functions are moved from eal_private.h
> to the new file eal_log.h:
>         rte_eal_log_init -> eal_log_init
>         rte_log_save_regexp -> eal_log_save_regexp
>         rte_log_save_pattern -> eal_log_save_pattern
>         eal_log_set_default
>
> The static functions in the file eal_common_log.c are renamed:
>         rte_log_save_level -> log_save_level
>         rte_log_init -> log_init

+ rte_log_lookup -> log_lookup
+ __rte_log_register -> log_register

>
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> Acked-by: Bruce Richardson <bruce.richardson@intel.com>
> Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>

Reviewed-by: David Marchand <david.marchand@redhat.com>


-- 
David Marchand


^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH v5 1/4] log: move private functions
  2021-04-06 11:28     ` David Marchand
@ 2021-04-06 12:08       ` Thomas Monjalon
  0 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-04-06 12:08 UTC (permalink / raw)
  To: David Marchand
  Cc: dev, Bruce Richardson, Andrew Rybchenko, Dmitry Kozlyuk,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam

06/04/2021 13:28, David Marchand:
> On Mon, Apr 5, 2021 at 9:30 PM Thomas Monjalon <thomas@monjalon.net> wrote:
> >
> > Some private log functions had a wrong "rte_" prefix.
> >
> > All private log functions are moved from eal_private.h
> > to the new file eal_log.h:
> >         rte_eal_log_init -> eal_log_init
> >         rte_log_save_regexp -> eal_log_save_regexp
> >         rte_log_save_pattern -> eal_log_save_pattern
> >         eal_log_set_default
> >
> > The static functions in the file eal_common_log.c are renamed:
> >         rte_log_save_level -> log_save_level
> >         rte_log_init -> log_init
> 
> + rte_log_lookup -> log_lookup
> + __rte_log_register -> log_register

I'm worried because this is what I have in my local git tree:

    All private log functions are moved from eal_private.h
    to the new file eal_log.h:
    	rte_eal_log_init -> eal_log_init
    	rte_log_save_regexp -> eal_log_save_regexp
    	rte_log_save_pattern -> eal_log_save_pattern
    	eal_log_set_default
    
    The static functions in the file eal_common_log.c are renamed:
    	rte_log_save_level -> log_save_level
    	rte_log_lookup -> log_lookup
    	rte_log_init -> log_init
    	__rte_log_register -> log_register

I wonder what else is not reflected in this v5 compared to my tree.



^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v6 0/4] log level enhancements
  2021-04-05 19:29 ` [dpdk-dev] [PATCH v5 0/4] log level enhancements Thomas Monjalon
                     ` (3 preceding siblings ...)
  2021-04-05 19:30   ` [dpdk-dev] [PATCH v5 4/4] log: add option argument help Thomas Monjalon
@ 2021-04-06 13:11   ` Thomas Monjalon
  2021-04-06 13:11     ` [dpdk-dev] [PATCH v6 1/4] log: move private functions Thomas Monjalon
                       ` (3 more replies)
  2021-04-08 16:47   ` [dpdk-dev] [PATCH v7 0/4] log level enhancements Thomas Monjalon
  5 siblings, 4 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-04-06 13:11 UTC (permalink / raw)
  To: dev; +Cc: david.marchand

This series is a part of a bigger one split after v4:
        "improve options help"

The main intent of this series is to provide a nice help
for the --log-level option.

v6:
   - fix commit log
v5:
   - rename more private functions
   - sort log types when printing help

Thomas Monjalon (4):
  log: move private functions
  log: introduce macro for maximum level
  log: catch invalid level option number
  log: add option argument help

 lib/librte_eal/common/eal_common_log.c     | 87 ++++++++++++++++------
 lib/librte_eal/common/eal_common_options.c | 60 ++++++++++-----
 lib/librte_eal/common/eal_log.h            | 32 ++++++++
 lib/librte_eal/common/eal_private.h        | 29 --------
 lib/librte_eal/include/rte_log.h           | 12 +++
 lib/librte_eal/linux/eal.c                 |  3 +-
 lib/librte_eal/linux/eal_log.c             |  4 +-
 lib/librte_eal/version.map                 |  1 +
 lib/librte_eal/windows/eal.c               |  3 +-
 lib/librte_eal/windows/eal_log.c           |  6 +-
 10 files changed, 162 insertions(+), 75 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_log.h

-- 
2.31.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v6 1/4] log: move private functions
  2021-04-06 13:11   ` [dpdk-dev] [PATCH v6 0/4] log level enhancements Thomas Monjalon
@ 2021-04-06 13:11     ` Thomas Monjalon
  2021-04-06 13:11     ` [dpdk-dev] [PATCH v6 2/4] log: introduce macro for maximum level Thomas Monjalon
                       ` (2 subsequent siblings)
  3 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-04-06 13:11 UTC (permalink / raw)
  To: dev
  Cc: david.marchand, Bruce Richardson, Andrew Rybchenko,
	Dmitry Kozlyuk, Narcisa Ana Maria Vasile, Dmitry Malloy,
	Pallavi Kadam

Some private log functions had a wrong "rte_" prefix.

All private log functions are moved from eal_private.h
to the new file eal_log.h:
	rte_eal_log_init -> eal_log_init
	rte_log_save_regexp -> eal_log_save_regexp
	rte_log_save_pattern -> eal_log_save_pattern
	eal_log_set_default

The static functions in the file eal_common_log.c are renamed:
	rte_log_save_level -> log_save_level
	rte_log_lookup -> log_lookup
	rte_log_init -> log_init
	__rte_log_register -> log_register

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
Reviewed-by: David Marchand <david.marchand@redhat.com>
---
 lib/librte_eal/common/eal_common_log.c     | 28 +++++++++++----------
 lib/librte_eal/common/eal_common_options.c |  5 ++--
 lib/librte_eal/common/eal_log.h            | 27 ++++++++++++++++++++
 lib/librte_eal/common/eal_private.h        | 29 ----------------------
 lib/librte_eal/linux/eal.c                 |  3 ++-
 lib/librte_eal/linux/eal_log.c             |  4 +--
 lib/librte_eal/windows/eal.c               |  3 ++-
 lib/librte_eal/windows/eal_log.c           |  6 +++--
 8 files changed, 55 insertions(+), 50 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_log.h

diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c
index c5554badb2..058fa10ffc 100644
--- a/lib/librte_eal/common/eal_common_log.c
+++ b/lib/librte_eal/common/eal_common_log.c
@@ -15,7 +15,7 @@
 #include <rte_log.h>
 #include <rte_per_lcore.h>
 
-#include "eal_private.h"
+#include "eal_log.h"
 
 struct rte_log_dynamic_type {
 	const char *name;
@@ -178,8 +178,8 @@ rte_log_set_level_regexp(const char *regex, uint32_t level)
  * Save the type string and the loglevel for later dynamic
  * logtypes which may register later.
  */
-static int rte_log_save_level(int priority,
-			      const char *regex, const char *pattern)
+static int
+log_save_level(uint32_t priority, const char *regex, const char *pattern)
 {
 	struct rte_eal_opt_loglevel *opt_ll = NULL;
 
@@ -207,9 +207,10 @@ static int rte_log_save_level(int priority,
 	return -1;
 }
 
-int rte_log_save_regexp(const char *regex, int tmp)
+int
+eal_log_save_regexp(const char *regex, uint32_t level)
 {
-	return rte_log_save_level(tmp, regex, NULL);
+	return log_save_level(level, regex, NULL);
 }
 
 /* set log level based on globbing pattern */
@@ -232,9 +233,10 @@ rte_log_set_level_pattern(const char *pattern, uint32_t level)
 	return 0;
 }
 
-int rte_log_save_pattern(const char *pattern, int priority)
+int
+eal_log_save_pattern(const char *pattern, uint32_t level)
 {
-	return rte_log_save_level(priority, NULL, pattern);
+	return log_save_level(level, NULL, pattern);
 }
 
 /* get the current loglevel for the message being processed */
@@ -250,7 +252,7 @@ int rte_log_cur_msg_logtype(void)
 }
 
 static int
-rte_log_lookup(const char *name)
+log_lookup(const char *name)
 {
 	size_t i;
 
@@ -268,7 +270,7 @@ rte_log_lookup(const char *name)
  * is not yet registered.
  */
 static int
-__rte_log_register(const char *name, int id)
+log_register(const char *name, int id)
 {
 	char *dup_name = strdup(name);
 
@@ -288,7 +290,7 @@ rte_log_register(const char *name)
 	struct rte_log_dynamic_type *new_dynamic_types;
 	int id, ret;
 
-	id = rte_log_lookup(name);
+	id = log_lookup(name);
 	if (id >= 0)
 		return id;
 
@@ -299,7 +301,7 @@ rte_log_register(const char *name)
 		return -ENOMEM;
 	rte_logs.dynamic_types = new_dynamic_types;
 
-	ret = __rte_log_register(name, rte_logs.dynamic_types_len);
+	ret = log_register(name, rte_logs.dynamic_types_len);
 	if (ret < 0)
 		return ret;
 
@@ -376,7 +378,7 @@ static const struct logtype logtype_strings[] = {
 };
 
 /* Logging should be first initializer (before drivers and bus) */
-RTE_INIT_PRIO(rte_log_init, LOG)
+RTE_INIT_PRIO(log_init, LOG)
 {
 	uint32_t i;
 
@@ -389,7 +391,7 @@ RTE_INIT_PRIO(rte_log_init, LOG)
 
 	/* register legacy log types */
 	for (i = 0; i < RTE_DIM(logtype_strings); i++)
-		__rte_log_register(logtype_strings[i].logtype,
+		log_register(logtype_strings[i].logtype,
 				logtype_strings[i].log_id);
 
 	rte_logs.dynamic_types_len = RTE_LOGTYPE_FIRST_EXT_ID;
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 622c7bc429..cd1a2856c9 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -41,6 +41,7 @@
 #include "eal_options.h"
 #include "eal_filesystem.h"
 #include "eal_private.h"
+#include "eal_log.h"
 #ifndef RTE_EXEC_ENV_WINDOWS
 #include "eal_trace.h"
 #endif
@@ -1299,7 +1300,7 @@ eal_parse_log_level(const char *arg)
 				regex, priority);
 			goto fail;
 		}
-		if (rte_log_save_regexp(regex, priority) < 0)
+		if (eal_log_save_regexp(regex, priority) < 0)
 			goto fail;
 	} else if (pattern) {
 		if (rte_log_set_level_pattern(pattern, priority) < 0) {
@@ -1307,7 +1308,7 @@ eal_parse_log_level(const char *arg)
 				pattern, priority);
 			goto fail;
 		}
-		if (rte_log_save_pattern(pattern, priority) < 0)
+		if (eal_log_save_pattern(pattern, priority) < 0)
 			goto fail;
 	} else {
 		rte_log_set_global_level(priority);
diff --git a/lib/librte_eal/common/eal_log.h b/lib/librte_eal/common/eal_log.h
new file mode 100644
index 0000000000..684650a17b
--- /dev/null
+++ b/lib/librte_eal/common/eal_log.h
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2021 Mellanox Technologies, Ltd
+ */
+
+#ifndef EAL_LOG_H
+#define EAL_LOG_H
+
+#include <stdio.h>
+#include <stdint.h>
+
+/*
+ * Initialize the default log stream.
+ */
+int eal_log_init(const char *id, int facility);
+
+/*
+ * Determine where log data is written when no call to rte_openlog_stream.
+ */
+void eal_log_set_default(FILE *default_log);
+
+/*
+ * Save a log option for later.
+ */
+int eal_log_save_regexp(const char *regexp, uint32_t level);
+int eal_log_save_pattern(const char *pattern, uint32_t level);
+
+#endif /* EAL_LOG_H */
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index b8a0d20021..e3512111d9 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -79,19 +79,6 @@ struct rte_config *rte_eal_get_configuration(void);
  */
 int rte_eal_memzone_init(void);
 
-/**
- * Common log initialization function (private to eal).  Determines
- * where log data is written when no call to rte_openlog_stream is
- * in effect.
- *
- * @param default_log
- *   The default log stream to be used.
- * @return
- *   - 0 on success
- *   - Negative on error
- */
-void eal_log_set_default(FILE *default_log);
-
 /**
  * Fill configuration with number of physical and logical processors
  *
@@ -143,22 +130,6 @@ int rte_eal_memory_init(void);
  */
 int rte_eal_timer_init(void);
 
-/**
- * Init the default log stream
- *
- * This function is private to EAL.
- *
- * @return
- *   0 on success, negative on error
- */
-int rte_eal_log_init(const char *id, int facility);
-
-/**
- * Save the log regexp for later
- */
-int rte_log_save_regexp(const char *type, int priority);
-int rte_log_save_pattern(const char *pattern, int priority);
-
 /**
  * Init tail queues for non-EAL library structures. This is to allow
  * the rings, mempools, etc. lists to be shared among multiple processes
diff --git a/lib/librte_eal/linux/eal.c b/lib/librte_eal/linux/eal.c
index abbb537746..ac27dd4274 100644
--- a/lib/librte_eal/linux/eal.c
+++ b/lib/librte_eal/linux/eal.c
@@ -58,6 +58,7 @@
 #include "eal_hugepages.h"
 #include "eal_memcfg.h"
 #include "eal_trace.h"
+#include "eal_log.h"
 #include "eal_options.h"
 #include "eal_vfio.h"
 #include "hotplug_mp.h"
@@ -1160,7 +1161,7 @@ rte_eal_init(int argc, char **argv)
 #endif
 	}
 
-	if (rte_eal_log_init(logid, internal_conf->syslog_facility) < 0) {
+	if (eal_log_init(logid, internal_conf->syslog_facility) < 0) {
 		rte_eal_init_alert("Cannot init logging.");
 		rte_errno = ENOMEM;
 		__atomic_store_n(&run_once, 0, __ATOMIC_RELAXED);
diff --git a/lib/librte_eal/linux/eal_log.c b/lib/librte_eal/linux/eal_log.c
index 2095df74c5..c0aa1007c4 100644
--- a/lib/librte_eal/linux/eal_log.c
+++ b/lib/librte_eal/linux/eal_log.c
@@ -17,7 +17,7 @@
 #include <rte_spinlock.h>
 #include <rte_log.h>
 
-#include "eal_private.h"
+#include "eal_log.h"
 
 /*
  * default log function
@@ -46,7 +46,7 @@ static cookie_io_functions_t console_log_func = {
  * once memzones are available.
  */
 int
-rte_eal_log_init(const char *id, int facility)
+eal_log_init(const char *id, int facility)
 {
 	FILE *log_stream;
 
diff --git a/lib/librte_eal/windows/eal.c b/lib/librte_eal/windows/eal.c
index 2fc3d6141c..68a1fd1d21 100644
--- a/lib/librte_eal/windows/eal.c
+++ b/lib/librte_eal/windows/eal.c
@@ -22,6 +22,7 @@
 
 #include "eal_hugepages.h"
 #include "eal_trace.h"
+#include "eal_log.h"
 #include "eal_windows.h"
 
 #define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL)
@@ -267,7 +268,7 @@ rte_eal_init(int argc, char **argv)
 		eal_get_internal_configuration();
 	int ret;
 
-	rte_eal_log_init(NULL, 0);
+	eal_log_init(NULL, 0);
 
 	eal_log_level_parse(argc, argv);
 
diff --git a/lib/librte_eal/windows/eal_log.c b/lib/librte_eal/windows/eal_log.c
index 875981f139..d4ea47f1c8 100644
--- a/lib/librte_eal/windows/eal_log.c
+++ b/lib/librte_eal/windows/eal_log.c
@@ -2,11 +2,13 @@
  * Copyright(c) 2017-2018 Intel Corporation
  */
 
-#include "eal_private.h"
+#include <rte_common.h>
+#include <rte_log.h>
+#include "eal_log.h"
 
 /* set the log to default function, called during eal init process. */
 int
-rte_eal_log_init(__rte_unused const char *id, __rte_unused int facility)
+eal_log_init(__rte_unused const char *id, __rte_unused int facility)
 {
 	rte_openlog_stream(stderr);
 
-- 
2.31.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v6 2/4] log: introduce macro for maximum level
  2021-04-06 13:11   ` [dpdk-dev] [PATCH v6 0/4] log level enhancements Thomas Monjalon
  2021-04-06 13:11     ` [dpdk-dev] [PATCH v6 1/4] log: move private functions Thomas Monjalon
@ 2021-04-06 13:11     ` Thomas Monjalon
  2021-04-06 14:32       ` David Marchand
  2021-04-06 13:11     ` [dpdk-dev] [PATCH v6 3/4] log: catch invalid level option number Thomas Monjalon
  2021-04-06 13:11     ` [dpdk-dev] [PATCH v6 4/4] log: add option argument help Thomas Monjalon
  3 siblings, 1 reply; 121+ messages in thread
From: Thomas Monjalon @ 2021-04-06 13:11 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, Bruce Richardson, Andrew Rybchenko

RTE_DIM(...) and RTE_LOG_DEBUG were used to get the highest log level.
For better clarity a new constant RTE_LOG_MAX is introduced
and mapped to RTE_LOG_DEBUG.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 lib/librte_eal/common/eal_common_log.c     | 8 ++++----
 lib/librte_eal/common/eal_common_options.c | 2 +-
 lib/librte_eal/include/rte_log.h           | 1 +
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c
index 058fa10ffc..b9b982fdb5 100644
--- a/lib/librte_eal/common/eal_common_log.c
+++ b/lib/librte_eal/common/eal_common_log.c
@@ -140,7 +140,7 @@ rte_log_set_level(uint32_t type, uint32_t level)
 {
 	if (type >= rte_logs.dynamic_types_len)
 		return -1;
-	if (level > RTE_LOG_DEBUG)
+	if (level > RTE_LOG_MAX)
 		return -1;
 
 	rte_logs.dynamic_types[type].loglevel = level;
@@ -155,7 +155,7 @@ rte_log_set_level_regexp(const char *regex, uint32_t level)
 	regex_t r;
 	size_t i;
 
-	if (level > RTE_LOG_DEBUG)
+	if (level > RTE_LOG_MAX)
 		return -1;
 
 	if (regcomp(&r, regex, 0) != 0)
@@ -219,7 +219,7 @@ rte_log_set_level_pattern(const char *pattern, uint32_t level)
 {
 	size_t i;
 
-	if (level > RTE_LOG_DEBUG)
+	if (level > RTE_LOG_MAX)
 		return -1;
 
 	for (i = 0; i < rte_logs.dynamic_types_len; i++) {
@@ -323,7 +323,7 @@ rte_log_register_type_and_pick_level(const char *name, uint32_t level_def)
 		return type;
 
 	TAILQ_FOREACH(opt_ll, &opt_loglevel_list, next) {
-		if (opt_ll->level > RTE_LOG_DEBUG)
+		if (opt_ll->level > RTE_LOG_MAX)
 			continue;
 
 		if (opt_ll->pattern) {
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index cd1a2856c9..38b72fb665 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -1249,7 +1249,7 @@ eal_parse_log_priority(const char *level)
 		return -1;
 
 	/* look for named values, skip 0 which is not a valid level */
-	for (i = 1; i < RTE_DIM(levels); i++) {
+	for (i = 1; i <= RTE_LOG_MAX; i++) {
 		if (strncmp(levels[i], level, len) == 0)
 			return i;
 	}
diff --git a/lib/librte_eal/include/rte_log.h b/lib/librte_eal/include/rte_log.h
index 21a7d16340..424dfa3fd0 100644
--- a/lib/librte_eal/include/rte_log.h
+++ b/lib/librte_eal/include/rte_log.h
@@ -72,6 +72,7 @@ extern "C" {
 #define RTE_LOG_NOTICE   6U  /**< Normal but significant condition. */
 #define RTE_LOG_INFO     7U  /**< Informational.                    */
 #define RTE_LOG_DEBUG    8U  /**< Debug-level messages.             */
+#define RTE_LOG_MAX RTE_LOG_DEBUG /**< Most detailed log level.     */
 
 /**
  * Change the stream that will be used by the logging system.
-- 
2.31.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v6 3/4] log: catch invalid level option number
  2021-04-06 13:11   ` [dpdk-dev] [PATCH v6 0/4] log level enhancements Thomas Monjalon
  2021-04-06 13:11     ` [dpdk-dev] [PATCH v6 1/4] log: move private functions Thomas Monjalon
  2021-04-06 13:11     ` [dpdk-dev] [PATCH v6 2/4] log: introduce macro for maximum level Thomas Monjalon
@ 2021-04-06 13:11     ` Thomas Monjalon
  2021-04-06 14:35       ` David Marchand
  2021-04-06 13:11     ` [dpdk-dev] [PATCH v6 4/4] log: add option argument help Thomas Monjalon
  3 siblings, 1 reply; 121+ messages in thread
From: Thomas Monjalon @ 2021-04-06 13:11 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, Bruce Richardson, Andrew Rybchenko

The parsing check for invalid log level was not trying to catch
irrelevant numeric values.
A log level 0 becomes a failure in parsing so it can be caught early.
A log level higher than the max (8) is accepted with a warning message.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 lib/librte_eal/common/eal_common_options.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 38b72fb665..7075a051b8 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -1289,10 +1289,15 @@ eal_parse_log_level(const char *arg)
 	}
 
 	priority = eal_parse_log_priority(level);
-	if (priority < 0) {
-		fprintf(stderr, "invalid log priority: %s\n", level);
+	if (priority <= 0) {
+		fprintf(stderr, "Invalid log level: %s\n", level);
 		goto fail;
 	}
+	if (priority > (int)RTE_LOG_MAX) {
+		fprintf(stderr, "Log level %d higher than maximum (%d)\n",
+				priority, RTE_LOG_MAX);
+		priority = RTE_LOG_MAX;
+	}
 
 	if (regex) {
 		if (rte_log_set_level_regexp(regex, priority) < 0) {
-- 
2.31.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v6 4/4] log: add option argument help
  2021-04-06 13:11   ` [dpdk-dev] [PATCH v6 0/4] log level enhancements Thomas Monjalon
                       ` (2 preceding siblings ...)
  2021-04-06 13:11     ` [dpdk-dev] [PATCH v6 3/4] log: catch invalid level option number Thomas Monjalon
@ 2021-04-06 13:11     ` Thomas Monjalon
  2021-04-06 14:28       ` David Marchand
  2021-04-06 16:04       ` Thomas Monjalon
  3 siblings, 2 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-04-06 13:11 UTC (permalink / raw)
  To: dev
  Cc: david.marchand, Bruce Richardson, Andrew Rybchenko, Ray Kinsella,
	Neil Horman

The option --log-level was not completely described in the usage text,
and it was difficult to guess the names of the log types and levels.

A new value "help" is accepted after --log-level to give more details
about the syntax and listing the log types and levels.

The array "levels" used for level name parsing is replaced with
a (modified) existing function which was used in rte_log_dump().

The new function rte_log_list_types() is exported in the API
for allowing an application to give this info to the user
if not exposing the EAL option --log-level.
The list of log types cannot include all drivers if not linked in the
application (shared object plugin case).

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 lib/librte_eal/common/eal_common_log.c     | 51 +++++++++++++++++++---
 lib/librte_eal/common/eal_common_options.c | 44 +++++++++++++------
 lib/librte_eal/common/eal_log.h            |  5 +++
 lib/librte_eal/include/rte_log.h           | 11 +++++
 lib/librte_eal/version.map                 |  1 +
 5 files changed, 94 insertions(+), 18 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c
index b9b982fdb5..4c6766a360 100644
--- a/lib/librte_eal/common/eal_common_log.c
+++ b/lib/librte_eal/common/eal_common_log.c
@@ -397,12 +397,12 @@ RTE_INIT_PRIO(log_init, LOG)
 	rte_logs.dynamic_types_len = RTE_LOGTYPE_FIRST_EXT_ID;
 }
 
-static const char *
-loglevel_to_string(uint32_t level)
+const char *
+eal_log_level2str(uint32_t level)
 {
 	switch (level) {
 	case 0: return "disabled";
-	case RTE_LOG_EMERG: return "emerg";
+	case RTE_LOG_EMERG: return "emergency";
 	case RTE_LOG_ALERT: return "alert";
 	case RTE_LOG_CRIT: return "critical";
 	case RTE_LOG_ERR: return "error";
@@ -414,6 +414,47 @@ loglevel_to_string(uint32_t level)
 	}
 }
 
+static int
+log_type_compare(const void *a, const void *b)
+{
+	const struct rte_log_dynamic_type *type_a = a;
+	const struct rte_log_dynamic_type *type_b = b;
+
+	if (type_a->name == NULL && type_b->name == NULL)
+		return 0;
+	if (type_a->name == NULL)
+		return -1;
+	if (type_b->name == NULL)
+		return 1;
+	return strcmp(type_a->name, type_b->name);
+}
+
+/* Dump name of each logtype, one per line. */
+void
+rte_log_list_types(FILE *out, const char *prefix)
+{
+	struct rte_log_dynamic_type *sorted_types;
+	const size_t type_size = sizeof(rte_logs.dynamic_types[0]);
+	const size_t type_count = rte_logs.dynamic_types_len;
+	const size_t total_size = type_size * type_count;
+	size_t type;
+
+	sorted_types = malloc(total_size);
+	if (sorted_types == NULL) {
+		/* no sorting - unlikely */
+		sorted_types = rte_logs.dynamic_types;
+	} else {
+		memcpy(sorted_types, rte_logs.dynamic_types, total_size);
+		qsort(sorted_types, type_count, type_size, log_type_compare);
+	}
+
+	for (type = 0; type < type_count; ++type) {
+		if (sorted_types[type].name == NULL)
+			continue;
+		fprintf(out, "%s%s\n", prefix, sorted_types[type].name);
+	}
+}
+
 /* dump global level and registered log types */
 void
 rte_log_dump(FILE *f)
@@ -421,14 +462,14 @@ rte_log_dump(FILE *f)
 	size_t i;
 
 	fprintf(f, "global log level is %s\n",
-		loglevel_to_string(rte_log_get_global_level()));
+		eal_log_level2str(rte_log_get_global_level()));
 
 	for (i = 0; i < rte_logs.dynamic_types_len; i++) {
 		if (rte_logs.dynamic_types[i].name == NULL)
 			continue;
 		fprintf(f, "id %zu: %s, level is %s\n",
 			i, rte_logs.dynamic_types[i].name,
-			loglevel_to_string(rte_logs.dynamic_types[i].loglevel));
+			eal_log_level2str(rte_logs.dynamic_types[i].loglevel));
 	}
 }
 
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 7075a051b8..2951b1aca2 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -1227,19 +1227,31 @@ eal_parse_syslog(const char *facility, struct internal_config *conf)
 }
 #endif
 
+static void
+eal_log_usage(void)
+{
+	unsigned int level;
+
+	printf("Log type is a pattern matching items of this list"
+			" (plugins may be missing):\n");
+	rte_log_list_types(stdout, "\t");
+	printf("\n");
+	printf("Syntax using globbing pattern:     ");
+	printf("--"OPT_LOG_LEVEL" pattern:level\n");
+	printf("Syntax using regular expression:   ");
+	printf("--"OPT_LOG_LEVEL" regexp,level\n");
+	printf("Syntax for the global level:       ");
+	printf("--"OPT_LOG_LEVEL" level\n");
+	printf("Logs are emitted if allowed by both global and specific levels.\n");
+	printf("\n");
+	printf("Log level can be a number or the first letters of its name:\n");
+	for (level = 1; level <= RTE_LOG_MAX; level++)
+		printf("\t%d   %s\n", level, eal_log_level2str(level));
+}
+
 static int
 eal_parse_log_priority(const char *level)
 {
-	static const char * const levels[] = {
-		[RTE_LOG_EMERG]   = "emergency",
-		[RTE_LOG_ALERT]   = "alert",
-		[RTE_LOG_CRIT]    = "critical",
-		[RTE_LOG_ERR]     = "error",
-		[RTE_LOG_WARNING] = "warning",
-		[RTE_LOG_NOTICE]  = "notice",
-		[RTE_LOG_INFO]    = "info",
-		[RTE_LOG_DEBUG]   = "debug",
-	};
 	size_t len = strlen(level);
 	unsigned long tmp;
 	char *end;
@@ -1250,7 +1262,7 @@ eal_parse_log_priority(const char *level)
 
 	/* look for named values, skip 0 which is not a valid level */
 	for (i = 1; i <= RTE_LOG_MAX; i++) {
-		if (strncmp(levels[i], level, len) == 0)
+		if (strncmp(eal_log_level2str(i), level, len) == 0)
 			return i;
 	}
 
@@ -1274,6 +1286,11 @@ eal_parse_log_level(const char *arg)
 	char *str, *level;
 	int priority;
 
+	if (strcmp(arg, "help") == 0) {
+		eal_log_usage();
+		exit(EXIT_SUCCESS);
+	}
+
 	str = strdup(arg);
 	if (str == NULL)
 		return -1;
@@ -2068,9 +2085,10 @@ eal_common_usage(void)
 #ifndef RTE_EXEC_ENV_WINDOWS
 	       "  --"OPT_SYSLOG"            Set syslog facility\n"
 #endif
-	       "  --"OPT_LOG_LEVEL"=<int>   Set global log level\n"
-	       "  --"OPT_LOG_LEVEL"=<type-match>:<int>\n"
+	       "  --"OPT_LOG_LEVEL"=<level> Set global log level\n"
+	       "  --"OPT_LOG_LEVEL"=<type-match>:<level>\n"
 	       "                      Set specific log level\n"
+	       "  --"OPT_LOG_LEVEL"=help    Show log types and levels\n"
 #ifndef RTE_EXEC_ENV_WINDOWS
 	       "  --"OPT_TRACE"=<regex-match>\n"
 	       "                      Enable trace based on regular expression trace name.\n"
diff --git a/lib/librte_eal/common/eal_log.h b/lib/librte_eal/common/eal_log.h
index 684650a17b..c784fa6043 100644
--- a/lib/librte_eal/common/eal_log.h
+++ b/lib/librte_eal/common/eal_log.h
@@ -24,4 +24,9 @@ void eal_log_set_default(FILE *default_log);
 int eal_log_save_regexp(const char *regexp, uint32_t level);
 int eal_log_save_pattern(const char *pattern, uint32_t level);
 
+/*
+ * Convert log level to string.
+ */
+const char *eal_log_level2str(uint32_t level);
+
 #endif /* EAL_LOG_H */
diff --git a/lib/librte_eal/include/rte_log.h b/lib/librte_eal/include/rte_log.h
index 424dfa3fd0..ccbb7ccd81 100644
--- a/lib/librte_eal/include/rte_log.h
+++ b/lib/librte_eal/include/rte_log.h
@@ -240,6 +240,17 @@ int rte_log_register(const char *name);
 __rte_experimental
 int rte_log_register_type_and_pick_level(const char *name, uint32_t level_def);
 
+/**
+ * Dump name of each logtype, one per line.
+ *
+ * @param out
+ *   Stream where the list is sent.
+ * @param prefix
+ *   String preceding each logtype in the output.
+ */
+__rte_experimental
+void rte_log_list_types(FILE *out, const char *prefix);
+
 /**
  * Dump log information.
  *
diff --git a/lib/librte_eal/version.map b/lib/librte_eal/version.map
index e23745ae6e..6c14fea27b 100644
--- a/lib/librte_eal/version.map
+++ b/lib/librte_eal/version.map
@@ -411,6 +411,7 @@ EXPERIMENTAL {
 	rte_power_pause;
 
 	# added in 21.05
+	rte_log_list_types;
 	rte_thread_key_create;
 	rte_thread_key_delete;
 	rte_thread_value_get;
-- 
2.31.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH v5 4/4] app: hook in EAL usage help
  2021-04-05 19:39   ` [dpdk-dev] [PATCH v5 4/4] app: hook in EAL usage help Thomas Monjalon
@ 2021-04-06 13:32     ` Jerin Jacob
  2021-04-06 14:05       ` Thomas Monjalon
  0 siblings, 1 reply; 121+ messages in thread
From: Jerin Jacob @ 2021-04-06 13:32 UTC (permalink / raw)
  To: Thomas Monjalon
  Cc: dpdk-dev, David Marchand, Wisam Jaddo, Bruce Richardson,
	Andrew Rybchenko, Reshma Pattan, Maryam Tahhan,
	Konstantin Ananyev, Nicolas Chautru, Declan Doherty, Ciara Power,
	Vladimir Medvedkin, Xiaoyun Li, Ori Kam, Bernard Iremonger

On Tue, Apr 6, 2021 at 1:10 AM Thomas Monjalon <thomas@monjalon.net> wrote:
>
> Use rte_set_application_usage_hook() in the test applications,
> so the full help including EAL options can be printed in one go
> with the EAL option -h or --help.
>
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> Acked-by: Wisam Jaddo <wisamm@nvidia.com>
> Acked-by: Bruce Richardson <bruce.richardson@intel.com>
> Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
> ---
>  app/pdump/main.c                                 | 2 ++
>  app/proc-info/main.c                             | 2 ++
>  app/test-acl/main.c                              | 2 ++
>  app/test-bbdev/main.c                            | 3 ++-
>  app/test-compress-perf/comp_perf_options.h       | 2 ++
>  app/test-compress-perf/comp_perf_options_parse.c | 8 ++++----
>  app/test-compress-perf/main.c                    | 3 ++-
>  app/test-crypto-perf/cperf_options.h             | 2 ++
>  app/test-crypto-perf/cperf_options_parsing.c     | 8 ++++----
>  app/test-crypto-perf/main.c                      | 3 ++-
>  app/test-fib/main.c                              | 8 ++++++++
>  app/test-flow-perf/main.c                        | 4 +++-
>  app/test-pmd/parameters.c                        | 4 ++--
>  app/test-pmd/testpmd.c                           | 2 ++
>  app/test-pmd/testpmd.h                           | 1 +
>  app/test-regex/main.c                            | 3 ++-
>  app/test-sad/main.c                              | 7 +++++++

>
> +       rte_set_application_usage_hook(print_usage);

All DPDK APIs, We are having rte_<subsystem><...><verb> kind of API
name convention.
I think, it is better to change to rte_application_usage_hook_set() to
express the hierarchy.

^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH v5 4/4] app: hook in EAL usage help
  2021-04-06 13:32     ` Jerin Jacob
@ 2021-04-06 14:05       ` Thomas Monjalon
  2021-04-06 14:13         ` Jerin Jacob
  0 siblings, 1 reply; 121+ messages in thread
From: Thomas Monjalon @ 2021-04-06 14:05 UTC (permalink / raw)
  To: Jerin Jacob
  Cc: dpdk-dev, David Marchand, Wisam Jaddo, Bruce Richardson,
	Andrew Rybchenko, Reshma Pattan, Maryam Tahhan,
	Konstantin Ananyev, Nicolas Chautru, Declan Doherty, Ciara Power,
	Vladimir Medvedkin, Xiaoyun Li, Ori Kam, Bernard Iremonger

06/04/2021 15:32, Jerin Jacob:
> On Tue, Apr 6, 2021 at 1:10 AM Thomas Monjalon <thomas@monjalon.net> wrote:
> >
> > Use rte_set_application_usage_hook() in the test applications,
> > so the full help including EAL options can be printed in one go
> > with the EAL option -h or --help.
[...]
> > +       rte_set_application_usage_hook(print_usage);
> 
> All DPDK APIs, We are having rte_<subsystem><...><verb> kind of API
> name convention.
> I think, it is better to change to rte_application_usage_hook_set() to
> express the hierarchy.

The naming of this function is not fantastic.
Without thinking about a better name, we should ask if we want to go
through a deprecation of this function name?



^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH v5 4/4] app: hook in EAL usage help
  2021-04-06 14:05       ` Thomas Monjalon
@ 2021-04-06 14:13         ` Jerin Jacob
  0 siblings, 0 replies; 121+ messages in thread
From: Jerin Jacob @ 2021-04-06 14:13 UTC (permalink / raw)
  To: Thomas Monjalon
  Cc: dpdk-dev, David Marchand, Wisam Jaddo, Bruce Richardson,
	Andrew Rybchenko, Reshma Pattan, Maryam Tahhan,
	Konstantin Ananyev, Nicolas Chautru, Declan Doherty, Ciara Power,
	Vladimir Medvedkin, Xiaoyun Li, Ori Kam, Bernard Iremonger

On Tue, Apr 6, 2021 at 7:35 PM Thomas Monjalon <thomas@monjalon.net> wrote:
>
> 06/04/2021 15:32, Jerin Jacob:
> > On Tue, Apr 6, 2021 at 1:10 AM Thomas Monjalon <thomas@monjalon.net> wrote:
> > >
> > > Use rte_set_application_usage_hook() in the test applications,
> > > so the full help including EAL options can be printed in one go
> > > with the EAL option -h or --help.
> [...]
> > > +       rte_set_application_usage_hook(print_usage);
> >
> > All DPDK APIs, We are having rte_<subsystem><...><verb> kind of API
> > name convention.
> > I think, it is better to change to rte_application_usage_hook_set() to
> > express the hierarchy.
>
> The naming of this function is not fantastic.
> Without thinking about a better name, we should ask if we want to go
> through a deprecation of this function name?

I thought it is a new function introduced by this series. Ignore my
comment as the function is already present in the codebase.


>
>

^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH v6 4/4] log: add option argument help
  2021-04-06 13:11     ` [dpdk-dev] [PATCH v6 4/4] log: add option argument help Thomas Monjalon
@ 2021-04-06 14:28       ` David Marchand
  2021-04-06 14:58         ` Thomas Monjalon
  2021-04-06 16:04       ` Thomas Monjalon
  1 sibling, 1 reply; 121+ messages in thread
From: David Marchand @ 2021-04-06 14:28 UTC (permalink / raw)
  To: Thomas Monjalon
  Cc: dev, Bruce Richardson, Andrew Rybchenko, Ray Kinsella, Neil Horman

On Tue, Apr 6, 2021 at 3:12 PM Thomas Monjalon <thomas@monjalon.net> wrote:
> @@ -414,6 +414,47 @@ loglevel_to_string(uint32_t level)
>         }
>  }
>
> +static int
> +log_type_compare(const void *a, const void *b)
> +{
> +       const struct rte_log_dynamic_type *type_a = a;
> +       const struct rte_log_dynamic_type *type_b = b;
> +
> +       if (type_a->name == NULL && type_b->name == NULL)
> +               return 0;
> +       if (type_a->name == NULL)
> +               return -1;
> +       if (type_b->name == NULL)
> +               return 1;
> +       return strcmp(type_a->name, type_b->name);
> +}
> +
> +/* Dump name of each logtype, one per line. */
> +void
> +rte_log_list_types(FILE *out, const char *prefix)
> +{
> +       struct rte_log_dynamic_type *sorted_types;
> +       const size_t type_size = sizeof(rte_logs.dynamic_types[0]);
> +       const size_t type_count = rte_logs.dynamic_types_len;
> +       const size_t total_size = type_size * type_count;
> +       size_t type;
> +
> +       sorted_types = malloc(total_size);
> +       if (sorted_types == NULL) {
> +               /* no sorting - unlikely */
> +               sorted_types = rte_logs.dynamic_types;
> +       } else {
> +               memcpy(sorted_types, rte_logs.dynamic_types, total_size);
> +               qsort(sorted_types, type_count, type_size, log_type_compare);
> +       }
> +
> +       for (type = 0; type < type_count; ++type) {
> +               if (sorted_types[type].name == NULL)
> +                       continue;
> +               fprintf(out, "%s%s\n", prefix, sorted_types[type].name);
> +       }


Missing something like:

if (sorted_types != rte_logs.dynamic_types)
    free(sorted_types);


> +}
> +


-- 
David Marchand


^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH v6 2/4] log: introduce macro for maximum level
  2021-04-06 13:11     ` [dpdk-dev] [PATCH v6 2/4] log: introduce macro for maximum level Thomas Monjalon
@ 2021-04-06 14:32       ` David Marchand
  0 siblings, 0 replies; 121+ messages in thread
From: David Marchand @ 2021-04-06 14:32 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev, Bruce Richardson, Andrew Rybchenko

On Tue, Apr 6, 2021 at 3:11 PM Thomas Monjalon <thomas@monjalon.net> wrote:
>
> RTE_DIM(...) and RTE_LOG_DEBUG were used to get the highest log level.
> For better clarity a new constant RTE_LOG_MAX is introduced
> and mapped to RTE_LOG_DEBUG.
>
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> Acked-by: Bruce Richardson <bruce.richardson@intel.com>
> Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>

Reviewed-by: David Marchand <david.marchand@redhat.com>


-- 
David Marchand


^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH v6 3/4] log: catch invalid level option number
  2021-04-06 13:11     ` [dpdk-dev] [PATCH v6 3/4] log: catch invalid level option number Thomas Monjalon
@ 2021-04-06 14:35       ` David Marchand
  0 siblings, 0 replies; 121+ messages in thread
From: David Marchand @ 2021-04-06 14:35 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev, Bruce Richardson, Andrew Rybchenko

On Tue, Apr 6, 2021 at 3:12 PM Thomas Monjalon <thomas@monjalon.net> wrote:
>
> The parsing check for invalid log level was not trying to catch
> irrelevant numeric values.
> A log level 0 becomes a failure in parsing so it can be caught early.
> A log level higher than the max (8) is accepted with a warning message.
>
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> Acked-by: Bruce Richardson <bruce.richardson@intel.com>
> Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>

Reviewed-by: David Marchand <david.marchand@redhat.com>


-- 
David Marchand


^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH v6 4/4] log: add option argument help
  2021-04-06 14:28       ` David Marchand
@ 2021-04-06 14:58         ` Thomas Monjalon
  0 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-04-06 14:58 UTC (permalink / raw)
  To: David Marchand; +Cc: dev, Bruce Richardson, Andrew Rybchenko, Ray Kinsella

06/04/2021 16:28, David Marchand:
> On Tue, Apr 6, 2021 at 3:12 PM Thomas Monjalon <thomas@monjalon.net> wrote:
> > +void
> > +rte_log_list_types(FILE *out, const char *prefix)
> > +{
> > +       struct rte_log_dynamic_type *sorted_types;
> > +       const size_t type_size = sizeof(rte_logs.dynamic_types[0]);
> > +       const size_t type_count = rte_logs.dynamic_types_len;
> > +       const size_t total_size = type_size * type_count;
> > +       size_t type;
> > +
> > +       sorted_types = malloc(total_size);
> > +       if (sorted_types == NULL) {
> > +               /* no sorting - unlikely */
> > +               sorted_types = rte_logs.dynamic_types;
> > +       } else {
> > +               memcpy(sorted_types, rte_logs.dynamic_types, total_size);
> > +               qsort(sorted_types, type_count, type_size, log_type_compare);
> > +       }
> > +
> > +       for (type = 0; type < type_count; ++type) {
> > +               if (sorted_types[type].name == NULL)
> > +                       continue;
> > +               fprintf(out, "%s%s\n", prefix, sorted_types[type].name);
> > +       }
> 
> Missing something like:
> 
> if (sorted_types != rte_logs.dynamic_types)
>     free(sorted_types);

No, what is missing really is coffee, but I don't drink some ;)
Thank you for the good review.



^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH v6 4/4] log: add option argument help
  2021-04-06 13:11     ` [dpdk-dev] [PATCH v6 4/4] log: add option argument help Thomas Monjalon
  2021-04-06 14:28       ` David Marchand
@ 2021-04-06 16:04       ` Thomas Monjalon
  2021-04-06 16:35         ` David Marchand
  1 sibling, 1 reply; 121+ messages in thread
From: Thomas Monjalon @ 2021-04-06 16:04 UTC (permalink / raw)
  To: dev
  Cc: david.marchand, Bruce Richardson, Andrew Rybchenko, Ray Kinsella,
	Neil Horman

06/04/2021 15:11, Thomas Monjalon:
> --- a/lib/librte_eal/version.map
> +++ b/lib/librte_eal/version.map
>  	# added in 21.05
> +	rte_log_list_types;

The symbol should be added in the .def as well.




^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH v6 4/4] log: add option argument help
  2021-04-06 16:04       ` Thomas Monjalon
@ 2021-04-06 16:35         ` David Marchand
  0 siblings, 0 replies; 121+ messages in thread
From: David Marchand @ 2021-04-06 16:35 UTC (permalink / raw)
  To: Thomas Monjalon
  Cc: dev, Bruce Richardson, Andrew Rybchenko, Ray Kinsella, Neil Horman

On Tue, Apr 6, 2021 at 6:04 PM Thomas Monjalon <thomas@monjalon.net> wrote:
>
> 06/04/2021 15:11, Thomas Monjalon:
> > --- a/lib/librte_eal/version.map
> > +++ b/lib/librte_eal/version.map
> >       # added in 21.05
> > +     rte_log_list_types;
>
> The symbol should be added in the .def as well.
>

Yes, and I'm fed up with this .def thing.
Sent a patch.


-- 
David Marchand


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v7 0/4] log level enhancements
  2021-04-05 19:29 ` [dpdk-dev] [PATCH v5 0/4] log level enhancements Thomas Monjalon
                     ` (4 preceding siblings ...)
  2021-04-06 13:11   ` [dpdk-dev] [PATCH v6 0/4] log level enhancements Thomas Monjalon
@ 2021-04-08 16:47   ` Thomas Monjalon
  2021-04-08 16:47     ` [dpdk-dev] [PATCH v7 1/4] log: move private functions Thomas Monjalon
                       ` (4 more replies)
  5 siblings, 5 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-04-08 16:47 UTC (permalink / raw)
  To: dev; +Cc: david.marchand

This series is a part of a bigger one split after v4:
        "improve options help"

The main intent of this series is to provide a nice help
for the --log-level option.

v7:
   - free sorted array of log types
v6:
   - fix commit log
v5:
   - rename more private functions
   - sort log types when printing help

Thomas Monjalon (4):
  log: move private functions
  log: introduce macro for maximum level
  log: catch invalid level option number
  log: add option argument help

 lib/librte_eal/common/eal_common_log.c     | 90 ++++++++++++++++------
 lib/librte_eal/common/eal_common_options.c | 60 ++++++++++-----
 lib/librte_eal/common/eal_log.h            | 32 ++++++++
 lib/librte_eal/common/eal_private.h        | 29 -------
 lib/librte_eal/include/rte_log.h           | 12 +++
 lib/librte_eal/linux/eal.c                 |  3 +-
 lib/librte_eal/linux/eal_log.c             |  4 +-
 lib/librte_eal/version.map                 |  1 +
 lib/librte_eal/windows/eal.c               |  3 +-
 lib/librte_eal/windows/eal_log.c           |  6 +-
 10 files changed, 165 insertions(+), 75 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_log.h

-- 
2.31.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v7 1/4] log: move private functions
  2021-04-08 16:47   ` [dpdk-dev] [PATCH v7 0/4] log level enhancements Thomas Monjalon
@ 2021-04-08 16:47     ` Thomas Monjalon
  2021-04-08 16:47     ` [dpdk-dev] [PATCH v7 2/4] log: introduce macro for maximum level Thomas Monjalon
                       ` (3 subsequent siblings)
  4 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-04-08 16:47 UTC (permalink / raw)
  To: dev
  Cc: david.marchand, Bruce Richardson, Andrew Rybchenko,
	Dmitry Kozlyuk, Narcisa Ana Maria Vasile, Dmitry Malloy,
	Pallavi Kadam

Some private log functions had a wrong "rte_" prefix.

All private log functions are moved from eal_private.h
to the new file eal_log.h:
	rte_eal_log_init -> eal_log_init
	rte_log_save_regexp -> eal_log_save_regexp
	rte_log_save_pattern -> eal_log_save_pattern
	eal_log_set_default

The static functions in the file eal_common_log.c are renamed:
	rte_log_save_level -> log_save_level
	rte_log_lookup -> log_lookup
	rte_log_init -> log_init
	__rte_log_register -> log_register

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
Reviewed-by: David Marchand <david.marchand@redhat.com>
---
 lib/librte_eal/common/eal_common_log.c     | 28 +++++++++++----------
 lib/librte_eal/common/eal_common_options.c |  5 ++--
 lib/librte_eal/common/eal_log.h            | 27 ++++++++++++++++++++
 lib/librte_eal/common/eal_private.h        | 29 ----------------------
 lib/librte_eal/linux/eal.c                 |  3 ++-
 lib/librte_eal/linux/eal_log.c             |  4 +--
 lib/librte_eal/windows/eal.c               |  3 ++-
 lib/librte_eal/windows/eal_log.c           |  6 +++--
 8 files changed, 55 insertions(+), 50 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_log.h

diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c
index c5554badb2..058fa10ffc 100644
--- a/lib/librte_eal/common/eal_common_log.c
+++ b/lib/librte_eal/common/eal_common_log.c
@@ -15,7 +15,7 @@
 #include <rte_log.h>
 #include <rte_per_lcore.h>
 
-#include "eal_private.h"
+#include "eal_log.h"
 
 struct rte_log_dynamic_type {
 	const char *name;
@@ -178,8 +178,8 @@ rte_log_set_level_regexp(const char *regex, uint32_t level)
  * Save the type string and the loglevel for later dynamic
  * logtypes which may register later.
  */
-static int rte_log_save_level(int priority,
-			      const char *regex, const char *pattern)
+static int
+log_save_level(uint32_t priority, const char *regex, const char *pattern)
 {
 	struct rte_eal_opt_loglevel *opt_ll = NULL;
 
@@ -207,9 +207,10 @@ static int rte_log_save_level(int priority,
 	return -1;
 }
 
-int rte_log_save_regexp(const char *regex, int tmp)
+int
+eal_log_save_regexp(const char *regex, uint32_t level)
 {
-	return rte_log_save_level(tmp, regex, NULL);
+	return log_save_level(level, regex, NULL);
 }
 
 /* set log level based on globbing pattern */
@@ -232,9 +233,10 @@ rte_log_set_level_pattern(const char *pattern, uint32_t level)
 	return 0;
 }
 
-int rte_log_save_pattern(const char *pattern, int priority)
+int
+eal_log_save_pattern(const char *pattern, uint32_t level)
 {
-	return rte_log_save_level(priority, NULL, pattern);
+	return log_save_level(level, NULL, pattern);
 }
 
 /* get the current loglevel for the message being processed */
@@ -250,7 +252,7 @@ int rte_log_cur_msg_logtype(void)
 }
 
 static int
-rte_log_lookup(const char *name)
+log_lookup(const char *name)
 {
 	size_t i;
 
@@ -268,7 +270,7 @@ rte_log_lookup(const char *name)
  * is not yet registered.
  */
 static int
-__rte_log_register(const char *name, int id)
+log_register(const char *name, int id)
 {
 	char *dup_name = strdup(name);
 
@@ -288,7 +290,7 @@ rte_log_register(const char *name)
 	struct rte_log_dynamic_type *new_dynamic_types;
 	int id, ret;
 
-	id = rte_log_lookup(name);
+	id = log_lookup(name);
 	if (id >= 0)
 		return id;
 
@@ -299,7 +301,7 @@ rte_log_register(const char *name)
 		return -ENOMEM;
 	rte_logs.dynamic_types = new_dynamic_types;
 
-	ret = __rte_log_register(name, rte_logs.dynamic_types_len);
+	ret = log_register(name, rte_logs.dynamic_types_len);
 	if (ret < 0)
 		return ret;
 
@@ -376,7 +378,7 @@ static const struct logtype logtype_strings[] = {
 };
 
 /* Logging should be first initializer (before drivers and bus) */
-RTE_INIT_PRIO(rte_log_init, LOG)
+RTE_INIT_PRIO(log_init, LOG)
 {
 	uint32_t i;
 
@@ -389,7 +391,7 @@ RTE_INIT_PRIO(rte_log_init, LOG)
 
 	/* register legacy log types */
 	for (i = 0; i < RTE_DIM(logtype_strings); i++)
-		__rte_log_register(logtype_strings[i].logtype,
+		log_register(logtype_strings[i].logtype,
 				logtype_strings[i].log_id);
 
 	rte_logs.dynamic_types_len = RTE_LOGTYPE_FIRST_EXT_ID;
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 622c7bc429..cd1a2856c9 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -41,6 +41,7 @@
 #include "eal_options.h"
 #include "eal_filesystem.h"
 #include "eal_private.h"
+#include "eal_log.h"
 #ifndef RTE_EXEC_ENV_WINDOWS
 #include "eal_trace.h"
 #endif
@@ -1299,7 +1300,7 @@ eal_parse_log_level(const char *arg)
 				regex, priority);
 			goto fail;
 		}
-		if (rte_log_save_regexp(regex, priority) < 0)
+		if (eal_log_save_regexp(regex, priority) < 0)
 			goto fail;
 	} else if (pattern) {
 		if (rte_log_set_level_pattern(pattern, priority) < 0) {
@@ -1307,7 +1308,7 @@ eal_parse_log_level(const char *arg)
 				pattern, priority);
 			goto fail;
 		}
-		if (rte_log_save_pattern(pattern, priority) < 0)
+		if (eal_log_save_pattern(pattern, priority) < 0)
 			goto fail;
 	} else {
 		rte_log_set_global_level(priority);
diff --git a/lib/librte_eal/common/eal_log.h b/lib/librte_eal/common/eal_log.h
new file mode 100644
index 0000000000..684650a17b
--- /dev/null
+++ b/lib/librte_eal/common/eal_log.h
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2021 Mellanox Technologies, Ltd
+ */
+
+#ifndef EAL_LOG_H
+#define EAL_LOG_H
+
+#include <stdio.h>
+#include <stdint.h>
+
+/*
+ * Initialize the default log stream.
+ */
+int eal_log_init(const char *id, int facility);
+
+/*
+ * Determine where log data is written when no call to rte_openlog_stream.
+ */
+void eal_log_set_default(FILE *default_log);
+
+/*
+ * Save a log option for later.
+ */
+int eal_log_save_regexp(const char *regexp, uint32_t level);
+int eal_log_save_pattern(const char *pattern, uint32_t level);
+
+#endif /* EAL_LOG_H */
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index b8a0d20021..e3512111d9 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -79,19 +79,6 @@ struct rte_config *rte_eal_get_configuration(void);
  */
 int rte_eal_memzone_init(void);
 
-/**
- * Common log initialization function (private to eal).  Determines
- * where log data is written when no call to rte_openlog_stream is
- * in effect.
- *
- * @param default_log
- *   The default log stream to be used.
- * @return
- *   - 0 on success
- *   - Negative on error
- */
-void eal_log_set_default(FILE *default_log);
-
 /**
  * Fill configuration with number of physical and logical processors
  *
@@ -143,22 +130,6 @@ int rte_eal_memory_init(void);
  */
 int rte_eal_timer_init(void);
 
-/**
- * Init the default log stream
- *
- * This function is private to EAL.
- *
- * @return
- *   0 on success, negative on error
- */
-int rte_eal_log_init(const char *id, int facility);
-
-/**
- * Save the log regexp for later
- */
-int rte_log_save_regexp(const char *type, int priority);
-int rte_log_save_pattern(const char *pattern, int priority);
-
 /**
  * Init tail queues for non-EAL library structures. This is to allow
  * the rings, mempools, etc. lists to be shared among multiple processes
diff --git a/lib/librte_eal/linux/eal.c b/lib/librte_eal/linux/eal.c
index abbb537746..ac27dd4274 100644
--- a/lib/librte_eal/linux/eal.c
+++ b/lib/librte_eal/linux/eal.c
@@ -58,6 +58,7 @@
 #include "eal_hugepages.h"
 #include "eal_memcfg.h"
 #include "eal_trace.h"
+#include "eal_log.h"
 #include "eal_options.h"
 #include "eal_vfio.h"
 #include "hotplug_mp.h"
@@ -1160,7 +1161,7 @@ rte_eal_init(int argc, char **argv)
 #endif
 	}
 
-	if (rte_eal_log_init(logid, internal_conf->syslog_facility) < 0) {
+	if (eal_log_init(logid, internal_conf->syslog_facility) < 0) {
 		rte_eal_init_alert("Cannot init logging.");
 		rte_errno = ENOMEM;
 		__atomic_store_n(&run_once, 0, __ATOMIC_RELAXED);
diff --git a/lib/librte_eal/linux/eal_log.c b/lib/librte_eal/linux/eal_log.c
index 2095df74c5..c0aa1007c4 100644
--- a/lib/librte_eal/linux/eal_log.c
+++ b/lib/librte_eal/linux/eal_log.c
@@ -17,7 +17,7 @@
 #include <rte_spinlock.h>
 #include <rte_log.h>
 
-#include "eal_private.h"
+#include "eal_log.h"
 
 /*
  * default log function
@@ -46,7 +46,7 @@ static cookie_io_functions_t console_log_func = {
  * once memzones are available.
  */
 int
-rte_eal_log_init(const char *id, int facility)
+eal_log_init(const char *id, int facility)
 {
 	FILE *log_stream;
 
diff --git a/lib/librte_eal/windows/eal.c b/lib/librte_eal/windows/eal.c
index 2fc3d6141c..68a1fd1d21 100644
--- a/lib/librte_eal/windows/eal.c
+++ b/lib/librte_eal/windows/eal.c
@@ -22,6 +22,7 @@
 
 #include "eal_hugepages.h"
 #include "eal_trace.h"
+#include "eal_log.h"
 #include "eal_windows.h"
 
 #define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL)
@@ -267,7 +268,7 @@ rte_eal_init(int argc, char **argv)
 		eal_get_internal_configuration();
 	int ret;
 
-	rte_eal_log_init(NULL, 0);
+	eal_log_init(NULL, 0);
 
 	eal_log_level_parse(argc, argv);
 
diff --git a/lib/librte_eal/windows/eal_log.c b/lib/librte_eal/windows/eal_log.c
index 875981f139..d4ea47f1c8 100644
--- a/lib/librte_eal/windows/eal_log.c
+++ b/lib/librte_eal/windows/eal_log.c
@@ -2,11 +2,13 @@
  * Copyright(c) 2017-2018 Intel Corporation
  */
 
-#include "eal_private.h"
+#include <rte_common.h>
+#include <rte_log.h>
+#include "eal_log.h"
 
 /* set the log to default function, called during eal init process. */
 int
-rte_eal_log_init(__rte_unused const char *id, __rte_unused int facility)
+eal_log_init(__rte_unused const char *id, __rte_unused int facility)
 {
 	rte_openlog_stream(stderr);
 
-- 
2.31.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v7 2/4] log: introduce macro for maximum level
  2021-04-08 16:47   ` [dpdk-dev] [PATCH v7 0/4] log level enhancements Thomas Monjalon
  2021-04-08 16:47     ` [dpdk-dev] [PATCH v7 1/4] log: move private functions Thomas Monjalon
@ 2021-04-08 16:47     ` Thomas Monjalon
  2021-04-08 16:47     ` [dpdk-dev] [PATCH v7 3/4] log: catch invalid level option number Thomas Monjalon
                       ` (2 subsequent siblings)
  4 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-04-08 16:47 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, Bruce Richardson, Andrew Rybchenko

RTE_DIM(...) and RTE_LOG_DEBUG were used to get the highest log level.
For better clarity a new constant RTE_LOG_MAX is introduced
and mapped to RTE_LOG_DEBUG.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
Reviewed-by: David Marchand <david.marchand@redhat.com>
---
 lib/librte_eal/common/eal_common_log.c     | 8 ++++----
 lib/librte_eal/common/eal_common_options.c | 2 +-
 lib/librte_eal/include/rte_log.h           | 1 +
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c
index 058fa10ffc..b9b982fdb5 100644
--- a/lib/librte_eal/common/eal_common_log.c
+++ b/lib/librte_eal/common/eal_common_log.c
@@ -140,7 +140,7 @@ rte_log_set_level(uint32_t type, uint32_t level)
 {
 	if (type >= rte_logs.dynamic_types_len)
 		return -1;
-	if (level > RTE_LOG_DEBUG)
+	if (level > RTE_LOG_MAX)
 		return -1;
 
 	rte_logs.dynamic_types[type].loglevel = level;
@@ -155,7 +155,7 @@ rte_log_set_level_regexp(const char *regex, uint32_t level)
 	regex_t r;
 	size_t i;
 
-	if (level > RTE_LOG_DEBUG)
+	if (level > RTE_LOG_MAX)
 		return -1;
 
 	if (regcomp(&r, regex, 0) != 0)
@@ -219,7 +219,7 @@ rte_log_set_level_pattern(const char *pattern, uint32_t level)
 {
 	size_t i;
 
-	if (level > RTE_LOG_DEBUG)
+	if (level > RTE_LOG_MAX)
 		return -1;
 
 	for (i = 0; i < rte_logs.dynamic_types_len; i++) {
@@ -323,7 +323,7 @@ rte_log_register_type_and_pick_level(const char *name, uint32_t level_def)
 		return type;
 
 	TAILQ_FOREACH(opt_ll, &opt_loglevel_list, next) {
-		if (opt_ll->level > RTE_LOG_DEBUG)
+		if (opt_ll->level > RTE_LOG_MAX)
 			continue;
 
 		if (opt_ll->pattern) {
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index cd1a2856c9..38b72fb665 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -1249,7 +1249,7 @@ eal_parse_log_priority(const char *level)
 		return -1;
 
 	/* look for named values, skip 0 which is not a valid level */
-	for (i = 1; i < RTE_DIM(levels); i++) {
+	for (i = 1; i <= RTE_LOG_MAX; i++) {
 		if (strncmp(levels[i], level, len) == 0)
 			return i;
 	}
diff --git a/lib/librte_eal/include/rte_log.h b/lib/librte_eal/include/rte_log.h
index 21a7d16340..424dfa3fd0 100644
--- a/lib/librte_eal/include/rte_log.h
+++ b/lib/librte_eal/include/rte_log.h
@@ -72,6 +72,7 @@ extern "C" {
 #define RTE_LOG_NOTICE   6U  /**< Normal but significant condition. */
 #define RTE_LOG_INFO     7U  /**< Informational.                    */
 #define RTE_LOG_DEBUG    8U  /**< Debug-level messages.             */
+#define RTE_LOG_MAX RTE_LOG_DEBUG /**< Most detailed log level.     */
 
 /**
  * Change the stream that will be used by the logging system.
-- 
2.31.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v7 3/4] log: catch invalid level option number
  2021-04-08 16:47   ` [dpdk-dev] [PATCH v7 0/4] log level enhancements Thomas Monjalon
  2021-04-08 16:47     ` [dpdk-dev] [PATCH v7 1/4] log: move private functions Thomas Monjalon
  2021-04-08 16:47     ` [dpdk-dev] [PATCH v7 2/4] log: introduce macro for maximum level Thomas Monjalon
@ 2021-04-08 16:47     ` Thomas Monjalon
  2021-04-08 16:47     ` [dpdk-dev] [PATCH v7 4/4] log: add option argument help Thomas Monjalon
  2021-04-09 10:55     ` [dpdk-dev] [PATCH v7 0/4] log level enhancements David Marchand
  4 siblings, 0 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-04-08 16:47 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, Bruce Richardson, Andrew Rybchenko

The parsing check for invalid log level was not trying to catch
irrelevant numeric values.
A log level 0 becomes a failure in parsing so it can be caught early.
A log level higher than the max (8) is accepted with a warning message.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
Reviewed-by: David Marchand <david.marchand@redhat.com>
---
 lib/librte_eal/common/eal_common_options.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 38b72fb665..7075a051b8 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -1289,10 +1289,15 @@ eal_parse_log_level(const char *arg)
 	}
 
 	priority = eal_parse_log_priority(level);
-	if (priority < 0) {
-		fprintf(stderr, "invalid log priority: %s\n", level);
+	if (priority <= 0) {
+		fprintf(stderr, "Invalid log level: %s\n", level);
 		goto fail;
 	}
+	if (priority > (int)RTE_LOG_MAX) {
+		fprintf(stderr, "Log level %d higher than maximum (%d)\n",
+				priority, RTE_LOG_MAX);
+		priority = RTE_LOG_MAX;
+	}
 
 	if (regex) {
 		if (rte_log_set_level_regexp(regex, priority) < 0) {
-- 
2.31.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* [dpdk-dev] [PATCH v7 4/4] log: add option argument help
  2021-04-08 16:47   ` [dpdk-dev] [PATCH v7 0/4] log level enhancements Thomas Monjalon
                       ` (2 preceding siblings ...)
  2021-04-08 16:47     ` [dpdk-dev] [PATCH v7 3/4] log: catch invalid level option number Thomas Monjalon
@ 2021-04-08 16:47     ` Thomas Monjalon
  2021-04-09  9:31       ` David Marchand
  2021-04-13 16:55       ` Kinsella, Ray
  2021-04-09 10:55     ` [dpdk-dev] [PATCH v7 0/4] log level enhancements David Marchand
  4 siblings, 2 replies; 121+ messages in thread
From: Thomas Monjalon @ 2021-04-08 16:47 UTC (permalink / raw)
  To: dev
  Cc: david.marchand, Bruce Richardson, Andrew Rybchenko, Ray Kinsella,
	Neil Horman

The option --log-level was not completely described in the usage text,
and it was difficult to guess the names of the log types and levels.

A new value "help" is accepted after --log-level to give more details
about the syntax and listing the log types and levels.

The array "levels" used for level name parsing is replaced with
a (modified) existing function which was used in rte_log_dump().

The new function rte_log_list_types() is exported in the API
for allowing an application to give this info to the user
if not exposing the EAL option --log-level.
The list of log types cannot include all drivers if not linked in the
application (shared object plugin case).

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 lib/librte_eal/common/eal_common_log.c     | 54 ++++++++++++++++++++--
 lib/librte_eal/common/eal_common_options.c | 44 ++++++++++++------
 lib/librte_eal/common/eal_log.h            |  5 ++
 lib/librte_eal/include/rte_log.h           | 11 +++++
 lib/librte_eal/version.map                 |  1 +
 5 files changed, 97 insertions(+), 18 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c
index b9b982fdb5..4c1d514770 100644
--- a/lib/librte_eal/common/eal_common_log.c
+++ b/lib/librte_eal/common/eal_common_log.c
@@ -397,12 +397,12 @@ RTE_INIT_PRIO(log_init, LOG)
 	rte_logs.dynamic_types_len = RTE_LOGTYPE_FIRST_EXT_ID;
 }
 
-static const char *
-loglevel_to_string(uint32_t level)
+const char *
+eal_log_level2str(uint32_t level)
 {
 	switch (level) {
 	case 0: return "disabled";
-	case RTE_LOG_EMERG: return "emerg";
+	case RTE_LOG_EMERG: return "emergency";
 	case RTE_LOG_ALERT: return "alert";
 	case RTE_LOG_CRIT: return "critical";
 	case RTE_LOG_ERR: return "error";
@@ -414,6 +414,50 @@ loglevel_to_string(uint32_t level)
 	}
 }
 
+static int
+log_type_compare(const void *a, const void *b)
+{
+	const struct rte_log_dynamic_type *type_a = a;
+	const struct rte_log_dynamic_type *type_b = b;
+
+	if (type_a->name == NULL && type_b->name == NULL)
+		return 0;
+	if (type_a->name == NULL)
+		return -1;
+	if (type_b->name == NULL)
+		return 1;
+	return strcmp(type_a->name, type_b->name);
+}
+
+/* Dump name of each logtype, one per line. */
+void
+rte_log_list_types(FILE *out, const char *prefix)
+{
+	struct rte_log_dynamic_type *sorted_types;
+	const size_t type_size = sizeof(rte_logs.dynamic_types[0]);
+	const size_t type_count = rte_logs.dynamic_types_len;
+	const size_t total_size = type_size * type_count;
+	size_t type;
+
+	sorted_types = malloc(total_size);
+	if (sorted_types == NULL) {
+		/* no sorting - unlikely */
+		sorted_types = rte_logs.dynamic_types;
+	} else {
+		memcpy(sorted_types, rte_logs.dynamic_types, total_size);
+		qsort(sorted_types, type_count, type_size, log_type_compare);
+	}
+
+	for (type = 0; type < type_count; ++type) {
+		if (sorted_types[type].name == NULL)
+			continue;
+		fprintf(out, "%s%s\n", prefix, sorted_types[type].name);
+	}
+
+	if (sorted_types != rte_logs.dynamic_types)
+		free(sorted_types);
+}
+
 /* dump global level and registered log types */
 void
 rte_log_dump(FILE *f)
@@ -421,14 +465,14 @@ rte_log_dump(FILE *f)
 	size_t i;
 
 	fprintf(f, "global log level is %s\n",
-		loglevel_to_string(rte_log_get_global_level()));
+		eal_log_level2str(rte_log_get_global_level()));
 
 	for (i = 0; i < rte_logs.dynamic_types_len; i++) {
 		if (rte_logs.dynamic_types[i].name == NULL)
 			continue;
 		fprintf(f, "id %zu: %s, level is %s\n",
 			i, rte_logs.dynamic_types[i].name,
-			loglevel_to_string(rte_logs.dynamic_types[i].loglevel));
+			eal_log_level2str(rte_logs.dynamic_types[i].loglevel));
 	}
 }
 
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 7075a051b8..2951b1aca2 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -1227,19 +1227,31 @@ eal_parse_syslog(const char *facility, struct internal_config *conf)
 }
 #endif
 
+static void
+eal_log_usage(void)
+{
+	unsigned int level;
+
+	printf("Log type is a pattern matching items of this list"
+			" (plugins may be missing):\n");
+	rte_log_list_types(stdout, "\t");
+	printf("\n");
+	printf("Syntax using globbing pattern:     ");
+	printf("--"OPT_LOG_LEVEL" pattern:level\n");
+	printf("Syntax using regular expression:   ");
+	printf("--"OPT_LOG_LEVEL" regexp,level\n");
+	printf("Syntax for the global level:       ");
+	printf("--"OPT_LOG_LEVEL" level\n");
+	printf("Logs are emitted if allowed by both global and specific levels.\n");
+	printf("\n");
+	printf("Log level can be a number or the first letters of its name:\n");
+	for (level = 1; level <= RTE_LOG_MAX; level++)
+		printf("\t%d   %s\n", level, eal_log_level2str(level));
+}
+
 static int
 eal_parse_log_priority(const char *level)
 {
-	static const char * const levels[] = {
-		[RTE_LOG_EMERG]   = "emergency",
-		[RTE_LOG_ALERT]   = "alert",
-		[RTE_LOG_CRIT]    = "critical",
-		[RTE_LOG_ERR]     = "error",
-		[RTE_LOG_WARNING] = "warning",
-		[RTE_LOG_NOTICE]  = "notice",
-		[RTE_LOG_INFO]    = "info",
-		[RTE_LOG_DEBUG]   = "debug",
-	};
 	size_t len = strlen(level);
 	unsigned long tmp;
 	char *end;
@@ -1250,7 +1262,7 @@ eal_parse_log_priority(const char *level)
 
 	/* look for named values, skip 0 which is not a valid level */
 	for (i = 1; i <= RTE_LOG_MAX; i++) {
-		if (strncmp(levels[i], level, len) == 0)
+		if (strncmp(eal_log_level2str(i), level, len) == 0)
 			return i;
 	}
 
@@ -1274,6 +1286,11 @@ eal_parse_log_level(const char *arg)
 	char *str, *level;
 	int priority;
 
+	if (strcmp(arg, "help") == 0) {
+		eal_log_usage();
+		exit(EXIT_SUCCESS);
+	}
+
 	str = strdup(arg);
 	if (str == NULL)
 		return -1;
@@ -2068,9 +2085,10 @@ eal_common_usage(void)
 #ifndef RTE_EXEC_ENV_WINDOWS
 	       "  --"OPT_SYSLOG"            Set syslog facility\n"
 #endif
-	       "  --"OPT_LOG_LEVEL"=<int>   Set global log level\n"
-	       "  --"OPT_LOG_LEVEL"=<type-match>:<int>\n"
+	       "  --"OPT_LOG_LEVEL"=<level> Set global log level\n"
+	       "  --"OPT_LOG_LEVEL"=<type-match>:<level>\n"
 	       "                      Set specific log level\n"
+	       "  --"OPT_LOG_LEVEL"=help    Show log types and levels\n"
 #ifndef RTE_EXEC_ENV_WINDOWS
 	       "  --"OPT_TRACE"=<regex-match>\n"
 	       "                      Enable trace based on regular expression trace name.\n"
diff --git a/lib/librte_eal/common/eal_log.h b/lib/librte_eal/common/eal_log.h
index 684650a17b..c784fa6043 100644
--- a/lib/librte_eal/common/eal_log.h
+++ b/lib/librte_eal/common/eal_log.h
@@ -24,4 +24,9 @@ void eal_log_set_default(FILE *default_log);
 int eal_log_save_regexp(const char *regexp, uint32_t level);
 int eal_log_save_pattern(const char *pattern, uint32_t level);
 
+/*
+ * Convert log level to string.
+ */
+const char *eal_log_level2str(uint32_t level);
+
 #endif /* EAL_LOG_H */
diff --git a/lib/librte_eal/include/rte_log.h b/lib/librte_eal/include/rte_log.h
index 424dfa3fd0..ccbb7ccd81 100644
--- a/lib/librte_eal/include/rte_log.h
+++ b/lib/librte_eal/include/rte_log.h
@@ -240,6 +240,17 @@ int rte_log_register(const char *name);
 __rte_experimental
 int rte_log_register_type_and_pick_level(const char *name, uint32_t level_def);
 
+/**
+ * Dump name of each logtype, one per line.
+ *
+ * @param out
+ *   Stream where the list is sent.
+ * @param prefix
+ *   String preceding each logtype in the output.
+ */
+__rte_experimental
+void rte_log_list_types(FILE *out, const char *prefix);
+
 /**
  * Dump log information.
  *
diff --git a/lib/librte_eal/version.map b/lib/librte_eal/version.map
index fc305c1c71..aa86b9e4fb 100644
--- a/lib/librte_eal/version.map
+++ b/lib/librte_eal/version.map
@@ -412,6 +412,7 @@ EXPERIMENTAL {
 
 	# added in 21.05
 	rte_intr_callback_unregister_sync;
+	rte_log_list_types;
 	rte_thread_key_create;
 	rte_thread_key_delete;
 	rte_thread_value_get;
-- 
2.31.1


^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH v7 4/4] log: add option argument help
  2021-04-08 16:47     ` [dpdk-dev] [PATCH v7 4/4] log: add option argument help Thomas Monjalon
@ 2021-04-09  9:31       ` David Marchand
  2021-04-13 16:55       ` Kinsella, Ray
  1 sibling, 0 replies; 121+ messages in thread
From: David Marchand @ 2021-04-09  9:31 UTC (permalink / raw)
  To: Thomas Monjalon
  Cc: dev, Bruce Richardson, Andrew Rybchenko, Ray Kinsella, Neil Horman

On Thu, Apr 8, 2021 at 6:47 PM Thomas Monjalon <thomas@monjalon.net> wrote:
>
> The option --log-level was not completely described in the usage text,
> and it was difficult to guess the names of the log types and levels.
>
> A new value "help" is accepted after --log-level to give more details
> about the syntax and listing the log types and levels.
>
> The array "levels" used for level name parsing is replaced with
> a (modified) existing function which was used in rte_log_dump().
>
> The new function rte_log_list_types() is exported in the API
> for allowing an application to give this info to the user
> if not exposing the EAL option --log-level.
> The list of log types cannot include all drivers if not linked in the
> application (shared object plugin case).
>
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> Acked-by: Bruce Richardson <bruce.richardson@intel.com>
> Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>

Reviewed-by: David Marchand <david.marchand@redhat.com>

-- 
David Marchand


^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH v7 0/4] log level enhancements
  2021-04-08 16:47   ` [dpdk-dev] [PATCH v7 0/4] log level enhancements Thomas Monjalon
                       ` (3 preceding siblings ...)
  2021-04-08 16:47     ` [dpdk-dev] [PATCH v7 4/4] log: add option argument help Thomas Monjalon
@ 2021-04-09 10:55     ` David Marchand
  4 siblings, 0 replies; 121+ messages in thread
From: David Marchand @ 2021-04-09 10:55 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev

On Thu, Apr 8, 2021 at 6:47 PM Thomas Monjalon <thomas@monjalon.net> wrote:
>
> This series is a part of a bigger one split after v4:
>         "improve options help"
>
> The main intent of this series is to provide a nice help
> for the --log-level option.

Series applied, thanks.


-- 
David Marchand


^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH v5 0/3] cleanup exit and usage messages in apps
  2021-04-05 19:33 ` [dpdk-dev] [PATCH v5 0/3] cleanup exit and usage messages in apps Thomas Monjalon
                     ` (2 preceding siblings ...)
  2021-04-05 19:33   ` [dpdk-dev] [PATCH v5 3/3] app/testpmd: " Thomas Monjalon
@ 2021-04-09 12:31   ` David Marchand
  3 siblings, 0 replies; 121+ messages in thread
From: David Marchand @ 2021-04-09 12:31 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev

On Mon, Apr 5, 2021 at 9:33 PM Thomas Monjalon <thomas@monjalon.net> wrote:
>
> This series is a part of a bigger one split after v4:
>         "improve options help"
>
> v5: no change

Previous versions lgtm, hence for the series,
Acked-by: David Marchand <david.marchand@redhat.com>

Series applied, thanks.


-- 
David Marchand


^ permalink raw reply	[flat|nested] 121+ messages in thread

* Re: [dpdk-dev] [PATCH v7 4/4] log: add option argument help
  2021-04-08 16:47     ` [dpdk-dev] [PATCH v7 4/4] log: add option argument help Thomas Monjalon
  2021-04-09  9:31       ` David Marchand
@ 2021-04-13 16:55       ` Kinsella, Ray
  1 sibling, 0 replies; 121+ messages in thread
From: Kinsella, Ray @ 2021-04-13 16:55 UTC (permalink / raw)
  To: Thomas Monjalon, dev
  Cc: david.marchand, Bruce Richardson, Andrew Rybchenko, Neil Horman



On 08/04/2021 17:47, Thomas Monjalon wrote:
> The option --log-level was not completely described in the usage text,
> and it was difficult to guess the names of the log types and levels.
> 
> A new value "help" is accepted after --log-level to give more details
> about the syntax and listing the log types and levels.
> 
> The array "levels" used for level name parsing is replaced with
> a (modified) existing function which was used in rte_log_dump().
> 
> The new function rte_log_list_types() is exported in the API
> for allowing an application to give this info to the user
> if not exposing the EAL option --log-level.
> The list of log types cannot include all drivers if not linked in the
> application (shared object plugin case).
> 
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> Acked-by: Bruce Richardson <bruce.richardson@intel.com>
> Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
> ---
>  lib/librte_eal/common/eal_common_log.c     | 54 ++++++++++++++++++++--
>  lib/librte_eal/common/eal_common_options.c | 44 ++++++++++++------
>  lib/librte_eal/common/eal_log.h            |  5 ++
>  lib/librte_eal/include/rte_log.h           | 11 +++++
>  lib/librte_eal/version.map                 |  1 +
>  5 files changed, 97 insertions(+), 18 deletions(-)

Acked-by: Ray Kinsella <mdr@ashroe.eu>

^ permalink raw reply	[flat|nested] 121+ messages in thread

end of thread, other threads:[~2021-04-13 16:55 UTC | newest]

Thread overview: 121+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-09 23:31 [dpdk-dev] [PATCH 00/11] improve options help Thomas Monjalon
2021-03-09 23:31 ` [dpdk-dev] [PATCH 01/11] eal: explain argv behaviour during init Thomas Monjalon
2021-03-09 23:31 ` [dpdk-dev] [PATCH 02/11] eal: improve options usage text Thomas Monjalon
2021-03-09 23:31 ` [dpdk-dev] [PATCH 03/11] eal: use macros for help option Thomas Monjalon
2021-03-09 23:31 ` [dpdk-dev] [PATCH 04/11] eal: move private log functions Thomas Monjalon
2021-03-09 23:31 ` [dpdk-dev] [PATCH 05/11] eal: introduce maximum log level macro Thomas Monjalon
2021-03-10 12:46   ` Thomas Monjalon
2021-03-09 23:31 ` [dpdk-dev] [PATCH 06/11] eal: catch invalid log level number Thomas Monjalon
2021-03-10 12:19   ` Bruce Richardson
2021-03-10 12:33     ` Thomas Monjalon
2021-03-10 13:26       ` Bruce Richardson
2021-03-10 13:35         ` Thomas Monjalon
2021-03-10 16:35           ` Morten Brørup
2021-03-10 16:52           ` Bruce Richardson
2021-03-10 15:16     ` Stephen Hemminger
2021-03-09 23:31 ` [dpdk-dev] [PATCH 07/11] eal: add log level help Thomas Monjalon
2021-03-09 23:31 ` [dpdk-dev] [PATCH 08/11] app: fix exit messages Thomas Monjalon
2021-03-10  7:10   ` Ori Kam
2021-03-10  9:23   ` Wisam Monther
2021-03-09 23:31 ` [dpdk-dev] [PATCH 09/11] app: hook in EAL usage help Thomas Monjalon
2021-03-10  9:25   ` Wisam Monther
2021-03-09 23:31 ` [dpdk-dev] [PATCH 10/11] app/regex: fix usage text Thomas Monjalon
2021-03-10  7:08   ` Ori Kam
2021-03-09 23:31 ` [dpdk-dev] [PATCH 11/11] app/testpmd: " Thomas Monjalon
2021-03-12 19:09   ` Ajit Khaparde
2021-03-10  0:45 ` [dpdk-dev] [PATCH 00/11] improve options help Stephen Hemminger
2021-03-10 13:28 ` [dpdk-dev] [PATCH v2 " Thomas Monjalon
2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 01/11] eal: explain argv behaviour during init Thomas Monjalon
2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 02/11] eal: improve options usage text Thomas Monjalon
2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 03/11] eal: use macros for help option Thomas Monjalon
2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 04/11] eal: move private log functions Thomas Monjalon
2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 05/11] eal: introduce maximum log level macro Thomas Monjalon
2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 06/11] eal: catch invalid log level number Thomas Monjalon
2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 07/11] eal: add log level help Thomas Monjalon
2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 08/11] app: fix exit messages Thomas Monjalon
2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 09/11] app: hook in EAL usage help Thomas Monjalon
2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 10/11] app/regex: fix usage text Thomas Monjalon
2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 11/11] app/testpmd: " Thomas Monjalon
2021-03-12 18:17 ` [dpdk-dev] [PATCH v3 00/11] improve options help Thomas Monjalon
2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 01/11] eal: explain argv behaviour during init Thomas Monjalon
2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 02/11] eal: improve options usage text Thomas Monjalon
2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 03/11] eal: use macros for help option Thomas Monjalon
2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 04/11] eal: move private log functions Thomas Monjalon
2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 05/11] eal: introduce maximum log level macro Thomas Monjalon
2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 06/11] eal: catch invalid log level number Thomas Monjalon
2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 07/11] eal: add log level help Thomas Monjalon
2021-03-15 10:19     ` Kinsella, Ray
2021-03-15 10:31       ` Bruce Richardson
2021-03-15 10:42         ` Kinsella, Ray
2021-03-15 10:52           ` Thomas Monjalon
2021-03-15 15:59             ` Stephen Hemminger
2021-03-15 17:01               ` Kinsella, Ray
2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 08/11] app: fix exit messages Thomas Monjalon
2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 09/11] app: hook in EAL usage help Thomas Monjalon
2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 10/11] app/regex: fix usage text Thomas Monjalon
2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 11/11] app/testpmd: " Thomas Monjalon
2021-03-19  8:59     ` Li, Xiaoyun
2021-03-19  9:29       ` Thomas Monjalon
2021-03-15  9:40   ` [dpdk-dev] [PATCH v3 00/11] improve options help Bruce Richardson
2021-03-15 10:47     ` Andrew Rybchenko
2021-03-21 22:31 ` [dpdk-dev] [PATCH v4 " Thomas Monjalon
2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 01/11] eal: explain argv behaviour during init Thomas Monjalon
2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 02/11] eal: improve options usage text Thomas Monjalon
2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 03/11] eal: use macros for help option Thomas Monjalon
2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 04/11] eal: move private log functions Thomas Monjalon
2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 05/11] eal: introduce maximum log level macro Thomas Monjalon
2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 06/11] eal: catch invalid log level number Thomas Monjalon
2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 07/11] eal: add log level help Thomas Monjalon
2021-03-23 13:37     ` David Marchand
2021-03-23 15:10       ` Thomas Monjalon
2021-03-23 18:18         ` David Marchand
2021-03-23 18:41           ` Thomas Monjalon
2021-03-24 13:41             ` David Marchand
2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 08/11] app: fix exit messages Thomas Monjalon
2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 09/11] app: hook in EAL usage help Thomas Monjalon
2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 10/11] app/regex: fix usage text Thomas Monjalon
2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 11/11] app/testpmd: " Thomas Monjalon
2021-03-22  1:45     ` Li, Xiaoyun
2021-03-22  8:27     ` Jens Freimann
2021-03-22  9:05       ` Bing Zhao
2021-03-24 15:03   ` [dpdk-dev] [PATCH v4 00/11] improve options help David Marchand
2021-03-24 16:55     ` Thomas Monjalon
2021-04-05 19:29 ` [dpdk-dev] [PATCH v5 0/4] log level enhancements Thomas Monjalon
2021-04-05 19:29   ` [dpdk-dev] [PATCH v5 1/4] log: move private functions Thomas Monjalon
2021-04-06 11:28     ` David Marchand
2021-04-06 12:08       ` Thomas Monjalon
2021-04-05 19:29   ` [dpdk-dev] [PATCH v5 2/4] log: introduce macro for maximum level Thomas Monjalon
2021-04-05 19:29   ` [dpdk-dev] [PATCH v5 3/4] log: catch invalid level option number Thomas Monjalon
2021-04-05 19:30   ` [dpdk-dev] [PATCH v5 4/4] log: add option argument help Thomas Monjalon
2021-04-06 13:11   ` [dpdk-dev] [PATCH v6 0/4] log level enhancements Thomas Monjalon
2021-04-06 13:11     ` [dpdk-dev] [PATCH v6 1/4] log: move private functions Thomas Monjalon
2021-04-06 13:11     ` [dpdk-dev] [PATCH v6 2/4] log: introduce macro for maximum level Thomas Monjalon
2021-04-06 14:32       ` David Marchand
2021-04-06 13:11     ` [dpdk-dev] [PATCH v6 3/4] log: catch invalid level option number Thomas Monjalon
2021-04-06 14:35       ` David Marchand
2021-04-06 13:11     ` [dpdk-dev] [PATCH v6 4/4] log: add option argument help Thomas Monjalon
2021-04-06 14:28       ` David Marchand
2021-04-06 14:58         ` Thomas Monjalon
2021-04-06 16:04       ` Thomas Monjalon
2021-04-06 16:35         ` David Marchand
2021-04-08 16:47   ` [dpdk-dev] [PATCH v7 0/4] log level enhancements Thomas Monjalon
2021-04-08 16:47     ` [dpdk-dev] [PATCH v7 1/4] log: move private functions Thomas Monjalon
2021-04-08 16:47     ` [dpdk-dev] [PATCH v7 2/4] log: introduce macro for maximum level Thomas Monjalon
2021-04-08 16:47     ` [dpdk-dev] [PATCH v7 3/4] log: catch invalid level option number Thomas Monjalon
2021-04-08 16:47     ` [dpdk-dev] [PATCH v7 4/4] log: add option argument help Thomas Monjalon
2021-04-09  9:31       ` David Marchand
2021-04-13 16:55       ` Kinsella, Ray
2021-04-09 10:55     ` [dpdk-dev] [PATCH v7 0/4] log level enhancements David Marchand
2021-04-05 19:33 ` [dpdk-dev] [PATCH v5 0/3] cleanup exit and usage messages in apps Thomas Monjalon
2021-04-05 19:33   ` [dpdk-dev] [PATCH v5 1/3] app: fix exit messages Thomas Monjalon
2021-04-05 19:33   ` [dpdk-dev] [PATCH v5 2/3] app/regex: fix usage text Thomas Monjalon
2021-04-05 19:33   ` [dpdk-dev] [PATCH v5 3/3] app/testpmd: " Thomas Monjalon
2021-04-09 12:31   ` [dpdk-dev] [PATCH v5 0/3] cleanup exit and usage messages in apps David Marchand
2021-04-05 19:39 ` [dpdk-dev] [PATCH v5 0/4] improve options help Thomas Monjalon
2021-04-05 19:39   ` [dpdk-dev] [PATCH v5 1/4] eal: explain argv behaviour during init Thomas Monjalon
2021-04-05 19:39   ` [dpdk-dev] [PATCH v5 2/4] eal: improve options usage text Thomas Monjalon
2021-04-05 19:39   ` [dpdk-dev] [PATCH v5 3/4] eal: use macros for help option Thomas Monjalon
2021-04-05 19:39   ` [dpdk-dev] [PATCH v5 4/4] app: hook in EAL usage help Thomas Monjalon
2021-04-06 13:32     ` Jerin Jacob
2021-04-06 14:05       ` Thomas Monjalon
2021-04-06 14:13         ` Jerin Jacob

DPDK patches and discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.dpdk.org/dev/0 dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dev dev/ https://inbox.dpdk.org/dev \
		dev@dpdk.org
	public-inbox-index dev

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git