Skip to contentSkip to conversation

improve options help

PATCH Superseded Thomas Monjalon 14 participants 133 messages Mar 9, 2021 – Sep 25, 2024

lore
Share & tools
lore
#0 lore raw

cover improve options help

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
Signature · 1 line
2.30.1
#1 lore raw

PATCH 1/11 eal: explain argv behaviour during init

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.

---
 lib/librte_eal/include/rte_eal.h | 2 ++
 1 file changed, 2 insertions(+)
lib/librte_eal/include/rte_eal.h +2 -0
index eaf6469e50..0cbeedb594 100644
@@ -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(),
Signature · 1 line
2.30.1
#2 lore raw

PATCH 2/11 eal: improve options usage text

In reply to Thomas Monjalon

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.

---
 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(-)
lib/librte_eal/common/eal_common_options.c +5 -6
index 622c7bc429..0635b0d4ce 100644
@@ -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"
lib/librte_eal/freebsd/eal.c +4 -4
index afbbb1c523..f466616566 100644
@@ -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
lib/librte_eal/linux/eal.c +6 -6
index bc966150a5..7c1d296192 100644
@@ -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
lib/librte_eal/windows/eal.c +4 -6
index 2fc3d6141c..ec13ac1a9f 100644
@@ -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 */
Signature · 1 line
2.30.1
#3 lore raw

PATCH 3/11 eal: use macros for help option

In reply to Thomas Monjalon

The macros OPT_HELP and OPT_HELP_NUM were not used where appropriate.

---
 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(-)
lib/librte_eal/common/eal_common_options.c +1 -1
index 0635b0d4ce..52fedb81e5 100644
@@ -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"
lib/librte_eal/freebsd/eal.c +1 -1
index f466616566..66adfca2d1 100644
@@ -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:
lib/librte_eal/linux/eal.c +1 -1
index 7c1d296192..6f73616f86 100644
@@ -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);
 
lib/librte_eal/windows/eal.c +1 -1
index ec13ac1a9f..4dd2fc1403 100644
@@ -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:
Signature · 1 line
2.30.1
#4 lore raw

PATCH 4/11 eal: move private log functions

In reply to Thomas Monjalon

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
---
 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
lib/librte_eal/common/eal_common_log.c +10 -8
index c5554badb2..85364ee47a 100644
@@ -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;
 
lib/librte_eal/common/eal_common_options.c +3 -2
index 52fedb81e5..02374ee09e 100644
@@ -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);
lib/librte_eal/common/eal_log.h new file +27 -0
new file mode 100644
index 0000000000..c057301769
@@ -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 */
lib/librte_eal/common/eal_private.h +0 -29
index b8a0d20021..e3512111d9 100644
@@ -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
lib/librte_eal/linux/eal.c +2 -1
index 6f73616f86..e4feeb2b0e 100644
@@ -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);
lib/librte_eal/linux/eal_log.c +2 -2
index 43c8460bfb..1a08139eb5 100644
@@ -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;
 
lib/librte_eal/windows/eal.c +2 -1
index 4dd2fc1403..5bca3ace1c 100644
@@ -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);
 
lib/librte_eal/windows/eal_log.c +4 -2
index 875981f139..d4ea47f1c8 100644
@@ -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);
 
Signature · 1 line
2.30.1
#5 lore raw

PATCH 5/11 eal: introduce maximum log level macro

In reply to Thomas Monjalon

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.

---
 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(-)
lib/librte_eal/common/eal_common_log.c +4 -4
index 85364ee47a..7f40c36f7e 100644
@@ -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) {
lib/librte_eal/common/eal_common_options.c +1 -1
index 02374ee09e..febc99612a 100644
@@ -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;
 	}
lib/librte_eal/include/rte_log.h +1 -0
index 173004fd71..394e8682b9 100644
@@ -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.
Signature · 1 line
2.30.1
#6 lore raw

Re: [dpdk-dev] [PATCH 05/11] eal: introduce maximum log level macro

10/03/2021 00:31, Thomas Monjalon:

lib/librte_eal/common/eal_common_options.c eal_parse_log_priority(const char *level) · line 1252

Quoted 8 lines
lib/librte_eal/common/eal_common_options.c +1 -1
@@ -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 <=

#7 lore raw

PATCH 6/11 eal: catch invalid log level number

In reply to Thomas Monjalon

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.

---
 lib/librte_eal/common/eal_common_options.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_eal/common/eal_common_options.c +1 -1
index febc99612a..5b9ce286ff 100644
@@ -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;
 	}
Signature · 1 line
2.30.1
#8 lore raw

Re: [dpdk-dev] [PATCH 06/11] eal: catch invalid log level number

Quoted 6 lines · Thomas Monjalon

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.

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.

Quoted 17 lines
---
 lib/librte_eal/common/eal_common_options.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_eal/common/eal_common_options.c +1 -1
index febc99612a..5b9ce286ff 100644
@@ -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;
 	}
#9 lore raw

Re: [dpdk-dev] [PATCH 06/11] eal: catch invalid log level number

10/03/2021 13:19, Bruce Richardson:

Quoted 6 lines · Thomas Monjalon
Quoted 5 lines

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.

Quoted 7 lines
Quoted 1 line

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 ;)

#10 lore raw

Re: [dpdk-dev] [PATCH 06/11] eal: catch invalid log level number

Quoted 9 lines · Thomas Monjalon

10/03/2021 13:19, Bruce Richardson:

Quoted 8 lines · Thomas Monjalon
Quoted 6 lines

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.

Quoted 8 lines
Quoted 5 lines

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.

#11 lore raw

Re: [dpdk-dev] [PATCH 06/11] eal: catch invalid log level number

10/03/2021 14:26, Bruce Richardson:

Quoted 16 lines · Thomas Monjalon
Quoted 15 lines

10/03/2021 13:19, Bruce Richardson:

Quoted 13 lines · Thomas Monjalon
Quoted 6 lines

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.

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.

Quoted 6 lines
Quoted 2 lines

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.

#12 lore raw

Re: [dpdk-dev] [PATCH 06/11] eal: catch invalid log level number

Quoted 25 lines

From: dev [mailto:[email protected]] On Behalf Of Thomas Monjalon
Sent: Wednesday, March 10, 2021 2:36 PM

10/03/2021 14:26, Bruce Richardson:

Quoted 8 lines · Thomas Monjalon
Quoted 7 lines

10/03/2021 13:19, Bruce Richardson:

Quoted 6 lines · Thomas Monjalon
Quoted 5 lines

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.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

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

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

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

Quoted 5 lines
Quoted 4 lines
Quoted 1 line

reduce it, and 9 is a more expected max value than 8.

Why 9 is more expected?

Quoted 7 lines
Quoted 3 lines

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

#13 lore raw

Re: [dpdk-dev] [PATCH 06/11] eal: catch invalid log level number

In reply to Thomas Monjalon
Quoted 20 lines · Thomas Monjalon

10/03/2021 14:26, Bruce Richardson:

Quoted 19 lines · Thomas Monjalon
Quoted 17 lines

10/03/2021 13:19, Bruce Richardson:

Quoted 6 lines · Thomas Monjalon
Quoted 5 lines

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.

Quoted 7 lines
Quoted 1 line

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?

Quoted 7 lines
Quoted 3 lines

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

#14 lore raw

Re: [dpdk-dev] [PATCH 06/11] eal: catch invalid log level number

In reply to Bruce Richardson
Quoted 6 lines · On Wed, 10 Mar 2021 12:19:24 +0000 Bruce Richardson…
Quoted 5 lines · Thomas Monjalon

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.

Quoted 7 lines
Quoted 1 line

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.

#15 lore raw

PATCH 7/11 eal: add log level help

In reply to Thomas Monjalon

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).

---
 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(-)
lib/librte_eal/common/eal_common_log.c +19 -5
index 7f40c36f7e..e46ae7b112 100644
@@ -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));
 	}
 }
 
lib/librte_eal/common/eal_common_options.c +31 -13

72 lines not on this page · raw message

lib/librte_eal/common/eal_log.h +5 -0
index c057301769..4ca630b0f7 100644
@@ -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 */
lib/librte_eal/include/rte_log.h +11 -0
index 394e8682b9..e6192892c3 100644
@@ -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.
  *
lib/librte_eal/version.map +3 -0
index fce90a112f..6b7876a0b9 100644
@@ -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 {
Signature · 1 line
2.30.1
#16 lore raw

Re: [dpdk-dev] [PATCH 07/11] eal: add log level help

Quoted 9 lines · On Wed, 10 Mar 2021 00:31:11 +0100 Thomas Monjalon <[email protected]> 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().

Quoted 7 lines

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).

In /usr/include/sys/syslog.h are some tables of strings for syslog values. Not sure how portable this is and across what versions.

#17 lore raw

PATCH 8/11 app: fix exit messages

In reply to Thomas Monjalon

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.

---
 .../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(-)
app/test-compress-perf/comp_perf_options_parse.c +1 -1
index 04a8d2fbee..019eddb7bd 100644
@@ -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:
app/test-crypto-perf/cperf_options_parsing.c +1 -1
index 0466f7baf8..40b6dfb648 100644
@@ -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:
app/test-flow-perf/main.c +28 -31

166 lines not on this page · raw message

app/test-pmd/parameters.c +2 -2
index c8acd5d1b7..55ecea6338 100644
@@ -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]);
app/test-regex/main.c +1 -2
index aea4fa6b88..7bb87bb1b8 100644
@@ -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;
 		}
 	}
Signature · 1 line
2.30.1
Acked-by on v1 8/11
#18 lore raw

Re: [dpdk-dev] [PATCH 08/11] app: fix exit messages

Hi

Quoted 7 lines

-----Original Message-----
From: Thomas Monjalon <[email protected]>
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.

Quoted 7 lines

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.

---

Best,
Ori

Acked-by on v1 8/11
#19 lore raw

Re: [dpdk-dev] [PATCH 08/11] app: fix exit messages

In reply to Thomas Monjalon

Hi,

Quoted 13 lines

-----Original Message-----
From: Thomas Monjalon <[email protected]>
Sent: Wednesday, March 10, 2021 1:31 AM
To: [email protected]
Cc: [email protected]; Declan Doherty <[email protected]>; Ciara Power <[email protected]>; Wisam Monther <[email protected]>; Xiaoyun Li <[email protected]>; Ori Kam <[email protected]>
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.

Quoted 6 lines

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.

BRs,
Wisam Jaddo

#20 lore raw

PATCH 9/11 app: hook in EAL usage help

In reply to Thomas Monjalon

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.

---
 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(-)
app/pdump/main.c +2 -0
index 63bbe65cd8..8641017f48 100644
@@ -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);
 
app/proc-info/main.c +2 -0
index b9587f7ded..e7d86bfa9d 100644
@@ -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) {
app/test-acl/main.c +2 -0
index 2cb2fe2579..9f95cb0fbf 100644
@@ -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");
app/test-bbdev/main.c +2 -1
index ff65173fdb..5960ec18b2 100644
@@ -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;
app/test-compress-perf/comp_perf_options.h +2 -0
index 0b777521c5..7dd785fba1 100644
@@ -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);
app/test-compress-perf/comp_perf_options_parse.c +4 -4
index 019eddb7bd..39d7fd8c69 100644
@@ -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;
 		}
 	}
app/test-compress-perf/main.c +2 -1
index cc9951a9b1..dcd347528e 100644
@@ -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");
app/test-crypto-perf/cperf_options.h +2 -0
index 9664a4b343..5f4a780614 100644
@@ -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);
 
app/test-crypto-perf/cperf_options_parsing.c +4 -4
index 40b6dfb648..3777bc7509 100644
@@ -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;
 		}
 	}
app/test-crypto-perf/main.c +2 -1
index 49af812d8b..497c4c5226 100644
@@ -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");
app/test-fib/main.c +8 -0
index b0a97b0d7e..420fe17c39 100644
@@ -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");
app/test-flow-perf/main.c +3 -1
index 0aef767350..949a5e3e11 100644
@@ -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");
app/test-pmd/parameters.c +2 -2
index 55ecea6338..7f41021d4d 100644
@@ -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
app/test-pmd/testpmd.c +2 -0
index 1a57324b1b..1a60830037 100644
@@ -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",
app/test-pmd/testpmd.h +1 -0
index ce83f31f0d..37348246f8 100644
@@ -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);
app/test-regex/main.c +2 -1
index 7bb87bb1b8..ba09b20126 100644
@@ -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");
app/test-sad/main.c +7 -0
index 1024757add..14a8263f8c 100644
@@ -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");
Signature · 1 line
2.30.1
Acked-by on v1 9/11
#21 lore raw

Re: [dpdk-dev] [PATCH 09/11] app: hook in EAL usage help

Hi,

Quoted 15 lines

-----Original Message-----
From: Thomas Monjalon <[email protected]>
Sent: Wednesday, March 10, 2021 1:31 AM
To: [email protected]
Cc: [email protected]; Reshma Pattan <[email protected]>; Maryam Tahhan <[email protected]>; Konstantin Ananyev <[email protected]>; Nicolas Chautru <[email protected]>; Declan Doherty <[email protected]>; Ciara Power <[email protected]>; Vladimir Medvedkin <[email protected]>; Wisam Monther <[email protected]>; Xiaoyun Li <[email protected]>; Ori Kam <[email protected]>; Bernard Iremonger <[email protected]>
Subject: [PATCH 09/11] app: hook in EAL usage help

Quoted 5 lines

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.

BRs,
Wisam Jaddo

#22 lore raw

PATCH 10/11 app/regex: fix usage text

In reply to Thomas Monjalon

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

---
 app/test-regex/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
app/test-regex/main.c +2 -2
index ba09b20126..73ba227fba 100644
@@ -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;
 		}
Signature · 1 line
2.30.1
Acked-by on v1 10/11
#23 lore raw

Re: [dpdk-dev] [PATCH 10/11] app/regex: fix usage text

Hi

Quoted 32 lines

-----Original Message-----
From: Thomas Monjalon <[email protected]>
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.

---
 app/test-regex/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
app/test-regex/main.c +2 -2
index ba09b20126..73ba227fba 100644
@@ -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]);
app/test-regex/main.c +0 -1
 			break;
 		}
--
Quoted 1 line

2.30.1

Best,
Ori

#24 lore raw

PATCH 11/11 app/testpmd: fix usage text

In reply to Thomas Monjalon

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.

---
 app/test-pmd/parameters.c | 26 ++------------------------
 1 file changed, 2 insertions(+), 24 deletions(-)
app/test-pmd/parameters.c +2 -24
index 7f41021d4d..efcbf1e845 100644
@@ -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");
 }
Signature · 1 line
2.30.1
Acked-by on v1 11/11
#25 lore raw

Re: [dpdk-dev] [PATCH 11/11] app/testpmd: fix usage text

Quoted 8 lines · Thomas Monjalon

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.

Quoted 51 lines
---
 app/test-pmd/parameters.c | 26 ++------------------------
 1 file changed, 2 insertions(+), 24 deletions(-)
app/test-pmd/parameters.c +2 -25
index 7f41021d4d..efcbf1e845 100644
@@ -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

#26 lore raw
In reply to Thomas Monjalon
Quoted 40 lines · On Wed, 10 Mar 2021 00:31:04 +0100 Thomas Monjalon <[email protected]> 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 +
Quoted 9 lines
 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/

#27 lore raw

v2 cover improve options help

In reply to Thomas Monjalon

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
Signature · 1 line
2.30.1
#28 lore raw

PATCH v2 1/11 eal: explain argv behaviour during init

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.

---
 lib/librte_eal/include/rte_eal.h | 2 ++
 1 file changed, 2 insertions(+)
lib/librte_eal/include/rte_eal.h +2 -0
index eaf6469e50..0cbeedb594 100644
@@ -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(),
Signature · 1 line
2.30.1
#29 lore raw

Re: [dpdk-dev] [PATCH v2 01/11] eal: explain argv behaviour during init

Quoted 9 lines · On Wed, 10 Mar 2021 14:28:15 +0100 Thomas Monjalon <[email protected]> wrote:

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.

Quoted 3 lines

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

I would rather that rte_eal_init() treat the argv arguments as immutable (ie const). Modifying input arguments is confusing and can cause some issues.

Other functions (getopt, getopt_long, execv) in glibc use:

	char *const argv[];

It would be good if EAL was the same.

#30 lore raw

PATCH v2 2/11 eal: improve options usage text

In reply to Thomas Monjalon

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.

---
 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(-)
lib/librte_eal/common/eal_common_options.c +5 -6
index 622c7bc429..0635b0d4ce 100644
@@ -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"
lib/librte_eal/freebsd/eal.c +4 -4
index afbbb1c523..f466616566 100644
@@ -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
lib/librte_eal/linux/eal.c +6 -6
index bc966150a5..7c1d296192 100644
@@ -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
lib/librte_eal/windows/eal.c +4 -6
index 2fc3d6141c..ec13ac1a9f 100644
@@ -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 */
Signature · 1 line
2.30.1
#31 lore raw

PATCH v2 3/11 eal: use macros for help option

In reply to Thomas Monjalon

The macros OPT_HELP and OPT_HELP_NUM were not used where appropriate.

---
 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(-)
lib/librte_eal/common/eal_common_options.c +1 -1
index 0635b0d4ce..52fedb81e5 100644
@@ -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"
lib/librte_eal/freebsd/eal.c +1 -1
index f466616566..66adfca2d1 100644
@@ -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:
lib/librte_eal/linux/eal.c +1 -1
index 7c1d296192..6f73616f86 100644
@@ -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);
 
lib/librte_eal/windows/eal.c +1 -1
index ec13ac1a9f..4dd2fc1403 100644
@@ -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:
Signature · 1 line
2.30.1
#32 lore raw

PATCH v2 4/11 eal: move private log functions

In reply to Thomas Monjalon

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
---
 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
lib/librte_eal/common/eal_common_log.c +10 -8
index c5554badb2..aee7c44c6a 100644
@@ -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;
 
lib/librte_eal/common/eal_common_options.c +3 -2
index 52fedb81e5..02374ee09e 100644
@@ -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);
lib/librte_eal/common/eal_log.h new file +27 -0
new file mode 100644
index 0000000000..684650a17b
@@ -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 */
lib/librte_eal/common/eal_private.h +0 -29
index b8a0d20021..e3512111d9 100644
@@ -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
lib/librte_eal/linux/eal.c +2 -1
index 6f73616f86..e4feeb2b0e 100644
@@ -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);
lib/librte_eal/linux/eal_log.c +2 -2
index 43c8460bfb..1a08139eb5 100644
@@ -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;
 
lib/librte_eal/windows/eal.c +2 -1
index 4dd2fc1403..5bca3ace1c 100644
@@ -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);
 
lib/librte_eal/windows/eal_log.c +4 -2
index 875981f139..d4ea47f1c8 100644
@@ -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);
 
Signature · 1 line
2.30.1
#33 lore raw

PATCH v2 5/11 eal: introduce maximum log level macro

In reply to Thomas Monjalon

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.

---
 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(-)
lib/librte_eal/common/eal_common_log.c +4 -4
index aee7c44c6a..40cac36f89 100644
@@ -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) {
lib/librte_eal/common/eal_common_options.c +1 -1
index 02374ee09e..3675e55fc9 100644
@@ -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;
 	}
lib/librte_eal/include/rte_log.h +1 -0
index 173004fd71..394e8682b9 100644
@@ -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.
Signature · 1 line
2.30.1
#34 lore raw

PATCH v2 6/11 eal: catch invalid log level number

In reply to Thomas Monjalon

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.

---
 lib/librte_eal/common/eal_common_options.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_eal/common/eal_common_options.c +1 -1
index 3675e55fc9..da0aaf831e 100644
@@ -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;
 	}
Signature · 1 line
2.30.1
#35 lore raw

PATCH v2 7/11 eal: add log level help

In reply to Thomas Monjalon

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).

---
 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(-)
lib/librte_eal/common/eal_common_log.c +19 -5
index 40cac36f89..d695b04068 100644
@@ -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));
 	}
 }
 
lib/librte_eal/common/eal_common_options.c +31 -13

72 lines not on this page · raw message

lib/librte_eal/common/eal_log.h +5 -0
index 684650a17b..c784fa6043 100644
@@ -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 */
lib/librte_eal/include/rte_log.h +11 -0
index 394e8682b9..e6192892c3 100644
@@ -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.
  *
lib/librte_eal/version.map +3 -0
index fce90a112f..6b7876a0b9 100644
@@ -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 {
Signature · 1 line
2.30.1
#36 lore raw

PATCH v2 8/11 app: fix exit messages

In reply to Thomas Monjalon

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.

---
 .../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(-)
app/test-compress-perf/comp_perf_options_parse.c +1 -1
index 04a8d2fbee..019eddb7bd 100644
@@ -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:
app/test-crypto-perf/cperf_options_parsing.c +1 -1
index 0466f7baf8..40b6dfb648 100644
@@ -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:
app/test-flow-perf/main.c +28 -31

166 lines not on this page · raw message

app/test-pmd/parameters.c +2 -2
index c8acd5d1b7..55ecea6338 100644
@@ -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]);
app/test-regex/main.c +1 -2
index aea4fa6b88..7bb87bb1b8 100644
@@ -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;
 		}
 	}
Signature · 1 line
2.30.1
#37 lore raw

PATCH v2 9/11 app: hook in EAL usage help

In reply to Thomas Monjalon

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.

---
 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(-)
app/pdump/main.c +2 -0
index 63bbe65cd8..8641017f48 100644
@@ -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);
 
app/proc-info/main.c +2 -0
index b9587f7ded..e7d86bfa9d 100644
@@ -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) {
app/test-acl/main.c +2 -0
index 2cb2fe2579..9f95cb0fbf 100644
@@ -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");
app/test-bbdev/main.c +2 -1
index ff65173fdb..5960ec18b2 100644
@@ -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;
app/test-compress-perf/comp_perf_options.h +2 -0
index 0b777521c5..7dd785fba1 100644
@@ -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);
app/test-compress-perf/comp_perf_options_parse.c +4 -4
index 019eddb7bd..39d7fd8c69 100644
@@ -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;
 		}
 	}
app/test-compress-perf/main.c +2 -1
index cc9951a9b1..dcd347528e 100644
@@ -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");
app/test-crypto-perf/cperf_options.h +2 -0
index 9664a4b343..5f4a780614 100644
@@ -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);
 
app/test-crypto-perf/cperf_options_parsing.c +4 -4
index 40b6dfb648..3777bc7509 100644
@@ -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;
 		}
 	}
app/test-crypto-perf/main.c +2 -1
index 49af812d8b..497c4c5226 100644
@@ -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");
app/test-fib/main.c +8 -0
index b0a97b0d7e..420fe17c39 100644
@@ -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");
app/test-flow-perf/main.c +3 -1
index 0aef767350..949a5e3e11 100644
@@ -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");
app/test-pmd/parameters.c +2 -2
index 55ecea6338..7f41021d4d 100644
@@ -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
app/test-pmd/testpmd.c +2 -0
index 1a57324b1b..1a60830037 100644
@@ -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",
app/test-pmd/testpmd.h +1 -0
index ce83f31f0d..37348246f8 100644
@@ -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);
app/test-regex/main.c +2 -1
index 7bb87bb1b8..ba09b20126 100644
@@ -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");
app/test-sad/main.c +7 -0
index 1024757add..14a8263f8c 100644
@@ -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");
Signature · 1 line
2.30.1
#38 lore raw

PATCH v2 10/11 app/regex: fix usage text

In reply to Thomas Monjalon

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

---
 app/test-regex/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
app/test-regex/main.c +2 -2
index ba09b20126..73ba227fba 100644
@@ -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;
 		}
Signature · 1 line
2.30.1
#39 lore raw

PATCH v2 11/11 app/testpmd: fix usage text

In reply to Thomas Monjalon

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.

---
 app/test-pmd/parameters.c | 26 ++------------------------
 1 file changed, 2 insertions(+), 24 deletions(-)
app/test-pmd/parameters.c +2 -24
index 7f41021d4d..efcbf1e845 100644
@@ -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");
 }
Signature · 1 line
2.30.1
#40 lore raw

v3 cover improve options help

In reply to Thomas Monjalon

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
Signature · 1 line
2.30.1
#41 lore raw

PATCH v3 1/11 eal: explain argv behaviour during init

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.

---
 lib/librte_eal/include/rte_eal.h | 2 ++
 1 file changed, 2 insertions(+)
lib/librte_eal/include/rte_eal.h +2 -0
index eaf6469e50..0cbeedb594 100644
@@ -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(),
Signature · 1 line
2.30.1
#42 lore raw

PATCH v3 2/11 eal: improve options usage text

In reply to Thomas Monjalon

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.

---
 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(-)
lib/librte_eal/common/eal_common_options.c +5 -6
index 622c7bc429..0635b0d4ce 100644
@@ -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"
lib/librte_eal/freebsd/eal.c +4 -4
index afbbb1c523..f466616566 100644
@@ -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
lib/librte_eal/linux/eal.c +6 -6
index bc966150a5..7c1d296192 100644
@@ -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
lib/librte_eal/windows/eal.c +4 -6
index 2fc3d6141c..ec13ac1a9f 100644
@@ -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 */
Signature · 1 line
2.30.1
#43 lore raw

PATCH v3 3/11 eal: use macros for help option

In reply to Thomas Monjalon

The macros OPT_HELP and OPT_HELP_NUM were not used where appropriate.

---
 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(-)
lib/librte_eal/common/eal_common_options.c +1 -1
index 0635b0d4ce..52fedb81e5 100644
@@ -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"
lib/librte_eal/freebsd/eal.c +1 -1
index f466616566..66adfca2d1 100644
@@ -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:
lib/librte_eal/linux/eal.c +1 -1
index 7c1d296192..6f73616f86 100644
@@ -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);
 
lib/librte_eal/windows/eal.c +1 -1
index ec13ac1a9f..4dd2fc1403 100644
@@ -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:
Signature · 1 line
2.30.1
#44 lore raw

PATCH v3 4/11 eal: move private log functions

In reply to Thomas Monjalon

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
---
 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
lib/librte_eal/common/eal_common_log.c +10 -8
index c5554badb2..aee7c44c6a 100644
@@ -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;
 
lib/librte_eal/common/eal_common_options.c +3 -2
index 52fedb81e5..02374ee09e 100644
@@ -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);
lib/librte_eal/common/eal_log.h new file +27 -0
new file mode 100644
index 0000000000..684650a17b
@@ -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 */
lib/librte_eal/common/eal_private.h +0 -29
index b8a0d20021..e3512111d9 100644
@@ -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
lib/librte_eal/linux/eal.c +2 -1
index 6f73616f86..e4feeb2b0e 100644
@@ -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);
lib/librte_eal/linux/eal_log.c +2 -2
index 43c8460bfb..1a08139eb5 100644
@@ -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;
 
lib/librte_eal/windows/eal.c +2 -1
index 4dd2fc1403..5bca3ace1c 100644
@@ -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);
 
lib/librte_eal/windows/eal_log.c +4 -2
index 875981f139..d4ea47f1c8 100644
@@ -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);
 
Signature · 1 line
2.30.1
#45 lore raw

PATCH v3 5/11 eal: introduce maximum log level macro

In reply to Thomas Monjalon

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.

---
 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(-)
lib/librte_eal/common/eal_common_log.c +4 -4
index aee7c44c6a..40cac36f89 100644
@@ -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) {
lib/librte_eal/common/eal_common_options.c +1 -1
index 02374ee09e..3675e55fc9 100644
@@ -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;
 	}
lib/librte_eal/include/rte_log.h +1 -0
index 173004fd71..394e8682b9 100644
@@ -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.
Signature · 1 line
2.30.1
#46 lore raw

PATCH v3 6/11 eal: catch invalid log level number

In reply to Thomas Monjalon

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.

---
 lib/librte_eal/common/eal_common_options.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
lib/librte_eal/common/eal_common_options.c +7 -2
index 3675e55fc9..2df3ae04ea 100644
@@ -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) {
Signature · 1 line
2.30.1
#47 lore raw

PATCH v3 7/11 eal: add log level help

In reply to Thomas Monjalon

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).

---
 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(-)
lib/librte_eal/common/eal_common_log.c +19 -5
index 40cac36f89..d695b04068 100644
@@ -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));
 	}
 }
 
lib/librte_eal/common/eal_common_options.c +31 -13

72 lines not on this page · raw message

lib/librte_eal/common/eal_log.h +5 -0
index 684650a17b..c784fa6043 100644
@@ -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 */
lib/librte_eal/include/rte_log.h +11 -0
index 394e8682b9..e6192892c3 100644
@@ -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.
  *
lib/librte_eal/version.map +3 -0
index fce90a112f..6b7876a0b9 100644
@@ -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 {
Signature · 1 line
2.30.1
#48 lore raw

Re: [dpdk-dev] [PATCH v3 07/11] eal: add log level help

Quoted 138 lines · Thomas Monjalon

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).

---
 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(-)
lib/librte_eal/common/eal_common_log.c +19 -5
index 40cac36f89..d695b04068 100644
@@ -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));
 	}
 }
 
lib/librte_eal/common/eal_common_options.c +23 -11
index 2df3ae04ea..1da6583d71 100644
@@ -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;
 	}
 

lib/librte_eal/common/eal_common_options.c eal_parse_log_level(const char *arg) · line 1289

Quoted 4 lines
lib/librte_eal/common/eal_common_options.c +1 -0
@@ -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.

Quoted 71 lines
lib/librte_eal/common/eal_common_options.c +7 -2
+		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"
lib/librte_eal/common/eal_log.h +5 -0
index 684650a17b..c784fa6043 100644
@@ -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 */
lib/librte_eal/include/rte_log.h +11 -0
index 394e8682b9..e6192892c3 100644
@@ -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.
  *
lib/librte_eal/version.map +3 -0
index fce90a112f..6b7876a0b9 100644
@@ -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 {
#49 lore raw

Re: [dpdk-dev] [PATCH v3 07/11] eal: add log level help

Quoted 27 lines · Ray
Quoted 24 lines · Thomas Monjalon

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).

---
 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>

Quoted 9 lines

lib/librte_eal/common/eal_common_options.c eal_parse_log_level(const char *arg) · line 1289

Quoted 5 lines
lib/librte_eal/common/eal_common_options.c +1 -0
@@ -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.

#50 lore raw

Re: [dpdk-dev] [PATCH v3 07/11] eal: add log level help

Quoted 33 lines · Bruce Richardson
Quoted 27 lines · Ray
Quoted 24 lines · Thomas Monjalon

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).

---
 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>

Quoted 4 lines
Quoted 4 lines
lib/librte_eal/common/eal_common_options.c +0 -0
@@ -1274,6 +1286,11 @@ eal_parse_log_level(const char *arg)
 	char *str, *level;
 	int priority;
 
Quoted 8 lines
Quoted 5 lines

lib/librte_eal/common/eal_common_options.c eal_parse_log_level(const char *arg) · line 1289

Quoted 1 line
lib/librte_eal/common/eal_common_options.c +1 -0
+	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)
#51 lore raw

Re: [dpdk-dev] [PATCH v3 07/11] eal: add log level help

15/03/2021 11:42, Kinsella, Ray:

Quoted 40 lines · Bruce Richardson
Quoted 38 lines · Ray
Quoted 27 lines · Thomas Monjalon
Quoted 24 lines

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).

---
 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>

Quoted 9 lines

lib/librte_eal/common/eal_common_options.c eal_parse_log_level(const char *arg) · line 1289

Quoted 5 lines
lib/librte_eal/common/eal_common_options.c +1 -0
@@ -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.

Quoted 8 lines
Quoted 3 lines

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 :)

#52 lore raw

Re: [dpdk-dev] [PATCH v3 07/11] eal: add log level help

Quoted 48 lines · On Mon, 15 Mar 2021 11:52:13 +0100 Thomas Monjalon <[email protected]> wrote:

15/03/2021 11:42, Kinsella, Ray:

Quoted 47 lines · Bruce Richardson
Quoted 33 lines · Ray
Quoted 27 lines · Thomas Monjalon
Quoted 24 lines

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).

---
 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>

Quoted 4 lines
Quoted 4 lines
lib/librte_eal/common/eal_common_options.c +0 -0
@@ -1274,6 +1286,11 @@ eal_parse_log_level(const char *arg)
 	char *str, *level;
 	int priority;
 
Quoted 8 lines
Quoted 5 lines

lib/librte_eal/common/eal_common_options.c eal_parse_log_level(const char *arg) · line 1289

Quoted 1 line
lib/librte_eal/common/eal_common_options.c +1 -0
+	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

Quoted 9 lines
Quoted 1 line

~ > 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

#53 lore raw

Re: [dpdk-dev] [PATCH v3 07/11] eal: add log level help

Quoted 57 lines · Stephen Hemminger
Quoted 54 lines · On Mon, 15 Mar 2021 11:52:13 +0100 Thomas Monjalon <[email protected]> wrote:

15/03/2021 11:42, Kinsella, Ray:

Quoted 40 lines · Bruce Richardson
Quoted 38 lines · Ray
Quoted 27 lines · Thomas Monjalon
Quoted 24 lines

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).

---
 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>

Quoted 9 lines

lib/librte_eal/common/eal_common_options.c eal_parse_log_level(const char *arg) · line 1289

Quoted 5 lines
lib/librte_eal/common/eal_common_options.c +1 -0
@@ -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.

Quoted 8 lines
Quoted 3 lines

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.

Quoted 7 lines
Quoted 3 lines

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

#54 lore raw

PATCH v3 8/11 app: fix exit messages

In reply to Thomas Monjalon

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.

---
 .../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(-)
app/test-compress-perf/comp_perf_options_parse.c +1 -1
index 04a8d2fbee..019eddb7bd 100644
@@ -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:
app/test-crypto-perf/cperf_options_parsing.c +1 -1
index 0466f7baf8..40b6dfb648 100644
@@ -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:
app/test-flow-perf/main.c +28 -31

166 lines not on this page · raw message

app/test-pmd/parameters.c +2 -2
index c8acd5d1b7..55ecea6338 100644
@@ -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]);
app/test-regex/main.c +1 -2
index aea4fa6b88..7bb87bb1b8 100644
@@ -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;
 		}
 	}
Signature · 1 line
2.30.1
#55 lore raw

PATCH v3 9/11 app: hook in EAL usage help

In reply to Thomas Monjalon

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.

---
 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(-)
app/pdump/main.c +2 -0
index 63bbe65cd8..8641017f48 100644
@@ -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);
 
app/proc-info/main.c +2 -0
index b9587f7ded..e7d86bfa9d 100644
@@ -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) {
app/test-acl/main.c +2 -0
index 2cb2fe2579..9f95cb0fbf 100644
@@ -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");
app/test-bbdev/main.c +2 -1
index ff65173fdb..5960ec18b2 100644
@@ -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;
app/test-compress-perf/comp_perf_options.h +2 -0
index 0b777521c5..7dd785fba1 100644
@@ -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);
app/test-compress-perf/comp_perf_options_parse.c +4 -4
index 019eddb7bd..39d7fd8c69 100644
@@ -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;
 		}
 	}
app/test-compress-perf/main.c +2 -1
index cc9951a9b1..dcd347528e 100644
@@ -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");
app/test-crypto-perf/cperf_options.h +2 -0
index 9664a4b343..5f4a780614 100644
@@ -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);
 
app/test-crypto-perf/cperf_options_parsing.c +4 -4
index 40b6dfb648..3777bc7509 100644
@@ -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;
 		}
 	}
app/test-crypto-perf/main.c +2 -1
index 49af812d8b..497c4c5226 100644
@@ -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");
app/test-fib/main.c +8 -0
index b0a97b0d7e..420fe17c39 100644
@@ -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");
app/test-flow-perf/main.c +3 -1
index 0aef767350..949a5e3e11 100644
@@ -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");
app/test-pmd/parameters.c +2 -2
index 55ecea6338..7f41021d4d 100644
@@ -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
app/test-pmd/testpmd.c +2 -0
index 1a57324b1b..1a60830037 100644
@@ -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",
app/test-pmd/testpmd.h +1 -0
index ce83f31f0d..37348246f8 100644
@@ -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);
app/test-regex/main.c +2 -1
index 7bb87bb1b8..ba09b20126 100644
@@ -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");
app/test-sad/main.c +7 -0
index 1024757add..14a8263f8c 100644
@@ -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");
Signature · 1 line
2.30.1
#56 lore raw

PATCH v3 10/11 app/regex: fix usage text

In reply to Thomas Monjalon

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

---
 app/test-regex/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
app/test-regex/main.c +2 -2
index ba09b20126..73ba227fba 100644
@@ -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;
 		}
Signature · 1 line
2.30.1
#57 lore raw

PATCH v3 11/11 app/testpmd: fix usage text

In reply to Thomas Monjalon

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.

---
 app/test-pmd/parameters.c | 26 ++------------------------
 1 file changed, 2 insertions(+), 24 deletions(-)
app/test-pmd/parameters.c +2 -24
index 7f41021d4d..efcbf1e845 100644
@@ -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");
 }
Signature · 1 line
2.30.1
#58 lore raw

Re: [dpdk-dev] [PATCH v3 11/11] app/testpmd: fix usage text

Hi

Quoted 33 lines

-----Original Message-----
From: Thomas Monjalon <[email protected]>
Sent: Saturday, March 13, 2021 02:17
To: [email protected]
Cc: [email protected]; Richardson, Bruce <[email protected]>; [email protected]; Li, Xiaoyun <[email protected]>
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.

---
 app/test-pmd/parameters.c | 26 ++------------------------
 1 file changed, 2 insertions(+), 24 deletions(-)
app/test-pmd/parameters.c index renamed from app/test-pmd/parameters.c +0 -0

7f41021d4d..efcbf1e845 100644

app/test-pmd/parameters.c +0 -5
@@ -49,29 +49,7 @@
 void
 usage(const char *progname)
 {
-	printf("usage: %s [EAL options] -- "
-#ifdef RTE_LIB_CMDLINE
-	       "[--interactive|-i] "
-	       "[--cmdline-file=FILENAME] "
-#endif

app/test-pmd/parameters.c line 66

Quoted 10 lines
app/test-pmd/parameters.c +0 -10
-	       "[--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

Quoted 23 lines
app/test-pmd/parameters.c +1 -8
-#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)

app/test-pmd/parameters.c +1 -2
 	       "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

#59 lore raw

Re: [dpdk-dev] [PATCH v3 11/11] app/testpmd: fix usage text

19/03/2021 09:59, Li, Xiaoyun:

Quoted 8 lines

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.

#60 lore raw
In reply to Thomas Monjalon
Quoted 5 lines · Thomas Monjalon

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.

Quoted 8 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

#61 lore raw
Quoted 14 lines · Bruce Richardson
Quoted 5 lines · Thomas Monjalon

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.

Quoted 8 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

Quoted 2 lines
#62 lore raw

v4 cover improve options help

In reply to Thomas Monjalon

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
Signature · 1 line
2.30.1
#63 lore raw

PATCH v4 1/11 eal: explain argv behaviour during init

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.

---
 lib/librte_eal/include/rte_eal.h | 2 ++
 1 file changed, 2 insertions(+)
lib/librte_eal/include/rte_eal.h +2 -0
index eaf6469e50..0cbeedb594 100644
@@ -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(),
Signature · 1 line
2.30.1
#64 lore raw

PATCH v4 2/11 eal: improve options usage text

In reply to Thomas Monjalon

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.

---
 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(-)
lib/librte_eal/common/eal_common_options.c +5 -6
index 622c7bc429..0635b0d4ce 100644
@@ -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"
lib/librte_eal/freebsd/eal.c +4 -4
index 62320d610f..6e414f5e7e 100644
@@ -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
lib/librte_eal/linux/eal.c +6 -6
index 9ffb4b3314..9aa585e04f 100644
@@ -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
lib/librte_eal/windows/eal.c +4 -6
index 2fc3d6141c..ec13ac1a9f 100644
@@ -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 */
Signature · 1 line
2.30.1
#65 lore raw

PATCH v4 3/11 eal: use macros for help option

In reply to Thomas Monjalon

The macros OPT_HELP and OPT_HELP_NUM were not used where appropriate.

---
 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(-)
lib/librte_eal/common/eal_common_options.c +1 -1
index 0635b0d4ce..52fedb81e5 100644
@@ -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"
lib/librte_eal/freebsd/eal.c +1 -1
index 6e414f5e7e..91048efc35 100644
@@ -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:
lib/librte_eal/linux/eal.c +1 -1
index 9aa585e04f..c8ea590a05 100644
@@ -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);
 
lib/librte_eal/windows/eal.c +1 -1
index ec13ac1a9f..4dd2fc1403 100644
@@ -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:
Signature · 1 line
2.30.1
#66 lore raw

PATCH v4 4/11 eal: move private log functions

In reply to Thomas Monjalon

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
---
 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
lib/librte_eal/common/eal_common_log.c +10 -8
index c5554badb2..aee7c44c6a 100644
@@ -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;
 
lib/librte_eal/common/eal_common_options.c +3 -2
index 52fedb81e5..02374ee09e 100644
@@ -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);
lib/librte_eal/common/eal_log.h new file +27 -0
new file mode 100644
index 0000000000..684650a17b
@@ -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 */
lib/librte_eal/common/eal_private.h +0 -29
index b8a0d20021..e3512111d9 100644
@@ -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
lib/librte_eal/linux/eal.c +2 -1
index c8ea590a05..1e7264f1a2 100644
@@ -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);
lib/librte_eal/linux/eal_log.c +2 -2
index 2095df74c5..c0aa1007c4 100644
@@ -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;
 
lib/librte_eal/windows/eal.c +2 -1
index 4dd2fc1403..5bca3ace1c 100644
@@ -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);
 
lib/librte_eal/windows/eal_log.c +4 -2
index 875981f139..d4ea47f1c8 100644
@@ -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);
 
Signature · 1 line
2.30.1
#67 lore raw

PATCH v4 5/11 eal: introduce maximum log level macro

In reply to Thomas Monjalon

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.

---
 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(-)
lib/librte_eal/common/eal_common_log.c +4 -4
index aee7c44c6a..40cac36f89 100644
@@ -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) {
lib/librte_eal/common/eal_common_options.c +1 -1
index 02374ee09e..3675e55fc9 100644
@@ -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;
 	}
lib/librte_eal/include/rte_log.h +1 -0
index 173004fd71..394e8682b9 100644
@@ -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.
Signature · 1 line
2.30.1
#68 lore raw

PATCH v4 6/11 eal: catch invalid log level number

In reply to Thomas Monjalon

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.

---
 lib/librte_eal/common/eal_common_options.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
lib/librte_eal/common/eal_common_options.c +7 -2
index 3675e55fc9..2df3ae04ea 100644
@@ -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) {
Signature · 1 line
2.30.1
#69 lore raw

PATCH v4 7/11 eal: add log level help

In reply to Thomas Monjalon

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).

---
 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(-)
lib/librte_eal/common/eal_common_log.c +19 -5
index 40cac36f89..d695b04068 100644
@@ -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));
 	}
 }
 
lib/librte_eal/common/eal_common_options.c +31 -13

72 lines not on this page · raw message

lib/librte_eal/common/eal_log.h +5 -0
index 684650a17b..c784fa6043 100644
@@ -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 */
lib/librte_eal/include/rte_log.h +11 -0
index 394e8682b9..e6192892c3 100644
@@ -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.
  *
lib/librte_eal/version.map +1 -0
index 48a2b55d57..c0686ebaf2 100644
@@ -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;
Signature · 1 line
2.30.1
#70 lore raw

Re: [dpdk-dev] [PATCH v4 07/11] eal: add log level help

Quoted 9 lines · Thomas Monjalon

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.

Signature · 1 line
David Marchand
#71 lore raw

Re: [dpdk-dev] [PATCH v4 07/11] eal: add log level help

23/03/2021 14:37, David Marchand:

Quoted 8 lines · Thomas Monjalon
Quoted 7 lines

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.

Quoted 7 lines
Quoted 2 lines

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.

#72 lore raw

Re: [dpdk-dev] [PATCH v4 07/11] eal: add log level help

Quoted 13 lines · Thomas Monjalon

23/03/2021 14:37, David Marchand:

Quoted 11 lines · Thomas Monjalon
Quoted 9 lines

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().

Quoted 7 lines
Quoted 4 lines

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.

Quoted 1 line

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?

Signature · 1 line
David Marchand
#73 lore raw

Re: [dpdk-dev] [PATCH v4 07/11] eal: add log level help

23/03/2021 19:18, David Marchand:

Quoted 21 lines · Thomas Monjalon
Quoted 12 lines

23/03/2021 14:37, David Marchand:

Quoted 11 lines · Thomas Monjalon
Quoted 9 lines

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().

Quoted 7 lines
Quoted 4 lines

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.

Quoted 6 lines

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

Quoted 1 line

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.

Quoted 1 line

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.

#74 lore raw

Re: [dpdk-dev] [PATCH v4 07/11] eal: add log level help

Quoted 10 lines · Thomas Monjalon
Quoted 4 lines
Quoted 1 line

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.

Quoted 1 line

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.

Signature · 1 line
David Marchand
#75 lore raw

PATCH v4 8/11 app: fix exit messages

In reply to Thomas Monjalon

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.

---
 .../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(-)
app/test-compress-perf/comp_perf_options_parse.c +1 -1
index 04a8d2fbee..019eddb7bd 100644
@@ -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:
app/test-crypto-perf/cperf_options_parsing.c +1 -1
index 0466f7baf8..40b6dfb648 100644
@@ -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:
app/test-flow-perf/main.c +28 -31

166 lines not on this page · raw message

app/test-pmd/parameters.c +2 -2
index a326c8ce4f..b7d4ef76b0 100644
@@ -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]);
app/test-regex/main.c +1 -2
index aea4fa6b88..7bb87bb1b8 100644
@@ -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;
 		}
 	}
Signature · 1 line
2.30.1
#76 lore raw

PATCH v4 9/11 app: hook in EAL usage help

In reply to Thomas Monjalon

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.

---
 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(-)
app/pdump/main.c +2 -0
index 63bbe65cd8..8641017f48 100644
@@ -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);
 
app/proc-info/main.c +2 -0
index b9587f7ded..e7d86bfa9d 100644
@@ -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) {
app/test-acl/main.c +2 -0
index 2cb2fe2579..9f95cb0fbf 100644
@@ -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");
app/test-bbdev/main.c +2 -1
index ff65173fdb..5960ec18b2 100644
@@ -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;
app/test-compress-perf/comp_perf_options.h +2 -0
index 0b777521c5..7dd785fba1 100644
@@ -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);
app/test-compress-perf/comp_perf_options_parse.c +4 -4
index 019eddb7bd..39d7fd8c69 100644
@@ -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;
 		}
 	}
app/test-compress-perf/main.c +2 -1
index cc9951a9b1..dcd347528e 100644
@@ -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");
app/test-crypto-perf/cperf_options.h +2 -0
index 9664a4b343..5f4a780614 100644
@@ -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);
 
app/test-crypto-perf/cperf_options_parsing.c +4 -4
index 40b6dfb648..3777bc7509 100644
@@ -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;
 		}
 	}
app/test-crypto-perf/main.c +2 -1
index 49af812d8b..497c4c5226 100644
@@ -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");
app/test-fib/main.c +8 -0
index b0a97b0d7e..420fe17c39 100644
@@ -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");
app/test-flow-perf/main.c +3 -1
index 0aef767350..949a5e3e11 100644
@@ -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");
app/test-pmd/parameters.c +2 -2
index b7d4ef76b0..156eff7697 100644
@@ -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
app/test-pmd/testpmd.c +2 -0
index 98c3248c01..24c241b0f6 100644
@@ -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",
app/test-pmd/testpmd.h +1 -0
index af40859170..2ab2c1b3d0 100644
@@ -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);
app/test-regex/main.c +2 -1
index 7bb87bb1b8..ba09b20126 100644
@@ -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");
app/test-sad/main.c +7 -0
index 1024757add..14a8263f8c 100644
@@ -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");
Signature · 1 line
2.30.1
#77 lore raw

PATCH v4 10/11 app/regex: fix usage text

In reply to Thomas Monjalon

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")
---
 app/test-regex/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
app/test-regex/main.c +2 -2
index ba09b20126..73ba227fba 100644
@@ -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;
 		}
Signature · 1 line
2.30.1
#78 lore raw

PATCH v4 11/11 app/testpmd: fix usage text

In reply to Thomas Monjalon

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")
---
 app/test-pmd/parameters.c | 35 ++++++++---------------------------
 1 file changed, 8 insertions(+), 27 deletions(-)
app/test-pmd/parameters.c +8 -27
index 156eff7697..4a1d64af89 100644
@@ -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 },
Signature · 1 line
2.30.1
Acked-by on v4 11/11
#79 lore raw

Re: [dpdk-dev] [PATCH v4 11/11] app/testpmd: fix usage text

Quoted 44 lines

-----Original Message-----
From: Thomas Monjalon <[email protected]>
Sent: Monday, March 22, 2021 06:31
To: [email protected]
Cc: [email protected]; [email protected]; Ajit Khaparde <[email protected]>; Richardson, Bruce <[email protected]>; Andrew Rybchenko <[email protected]>; Li, Xiaoyun <[email protected]>; Ori Kam <[email protected]>; Bing Zhao <[email protected]>; Iremonger, Bernard <[email protected]>; Jens Freimann <[email protected]>; Kevin Traynor <[email protected]>; Stephen Hemminger <[email protected]>; Maciej Czekaj <[email protected]>; De Lara Guarch, Pablo <[email protected]>
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")
Quoted 5 lines

---

Reviewed-by on v4 11/11
#80 lore raw

Re: [dpdk-dev] [PATCH v4 11/11] app/testpmd: fix usage text

In reply to Thomas Monjalon
Quoted 26 lines · Thomas Monjalon

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")
Quoted 8 lines

---
app/test-pmd/parameters.c | 35 ++++++++---------------------------

1 file changed, 8 insertions(+), 27 deletions(-)

Thank you Thomas!

regards,
Jens

Reviewed-by
#81 lore raw

Re: [dpdk-dev] [PATCH v4 11/11] app/testpmd: fix usage text

Hi Thomas,

Quoted 59 lines

-----Original Message-----
From: Jens Freimann <[email protected]>
Sent: Monday, March 22, 2021 4:27 PM
To: NBU-Contact-Thomas Monjalon <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Ajit Khaparde <[email protected]>; Bruce Richardson <[email protected]>; Andrew Rybchenko <[email protected]>; Xiaoyun Li <[email protected]>; Ori Kam <[email protected]>; Bing Zhao <[email protected]>; Bernard Iremonger <[email protected]>; Kevin Traynor <[email protected]>; Stephen Hemminger <[email protected]>; Maciej Czekaj <[email protected]>; Pablo de Lara <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v4 11/11] app/testpmd: fix usage text

External email: Use caution opening links or attachments

Quoted 1 line · Thomas Monjalon

The options help text was including an incomplete and redundant

summary

Quoted 3 lines

of the options before explaining each. The summary is dropped.

The details of the option --hairpin-mode had an extra space,

breaking

Quoted 24 lines

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")
Quoted 8 lines

---
app/test-pmd/parameters.c | 35 ++++++++---------------------------

1 file changed, 8 insertions(+), 27 deletions(-)
Quoted 6 lines

Thank you Thomas!

regards,
Jens

Thanks a lot for the help.

#82 lore raw
In reply to Thomas Monjalon
Quoted 3 lines · Thomas Monjalon

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.

Signature · 1 line
David Marchand
#83 lore raw

24/03/2021 16:03, David Marchand:

Quoted 2 lines

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.

Quoted 3 lines

- 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.

Quoted 5 lines

- 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:
[...]

#84 lore raw

v5 cover log level enhancements

In reply to Thomas Monjalon

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
Signature · 1 line
2.31.1
#85 lore raw

PATCH v5 1/4 log: move private functions

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
---
 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
lib/librte_eal/common/eal_common_log.c +15 -13
index c5554badb2..058fa10ffc 100644
@@ -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;
lib/librte_eal/common/eal_common_options.c +3 -2
index 622c7bc429..cd1a2856c9 100644
@@ -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);
lib/librte_eal/common/eal_log.h new file +27 -0
new file mode 100644
index 0000000000..684650a17b
@@ -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 */
lib/librte_eal/common/eal_private.h +0 -29
index b8a0d20021..e3512111d9 100644
@@ -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
lib/librte_eal/linux/eal.c +2 -1
index abbb537746..ac27dd4274 100644
@@ -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);
lib/librte_eal/linux/eal_log.c +2 -2
index 2095df74c5..c0aa1007c4 100644
@@ -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;
 
lib/librte_eal/windows/eal.c +2 -1
index 2fc3d6141c..68a1fd1d21 100644
@@ -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);
 
lib/librte_eal/windows/eal_log.c +4 -2
index 875981f139..d4ea47f1c8 100644
@@ -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);
 
Signature · 1 line
2.31.1
Reviewed-by on v5 1/4
#86 lore raw

Re: [dpdk-dev] [PATCH v5 1/4] log: move private functions

Quoted 5 lines · Thomas Monjalon

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:

Quoted 8 lines
        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

Quoted 4 lines
Signature · 1 line
David Marchand
#87 lore raw

Re: [dpdk-dev] [PATCH v5 1/4] log: move private functions

06/04/2021 13:28, David Marchand:

Quoted 11 lines · Thomas Monjalon
Quoted 10 lines

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
Quoted 6 lines
Quoted 3 lines

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.

#88 lore raw

PATCH v5 2/4 log: introduce macro for maximum level

In reply to Thomas Monjalon

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.

---
 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(-)
lib/librte_eal/common/eal_common_log.c +4 -4
index 058fa10ffc..b9b982fdb5 100644
@@ -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) {
lib/librte_eal/common/eal_common_options.c +1 -1
index cd1a2856c9..38b72fb665 100644
@@ -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;
 	}
lib/librte_eal/include/rte_log.h +1 -0
index 21a7d16340..424dfa3fd0 100644
@@ -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.
Signature · 1 line
2.31.1
#89 lore raw

PATCH v5 3/4 log: catch invalid level option number

In reply to Thomas Monjalon

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.

---
 lib/librte_eal/common/eal_common_options.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
lib/librte_eal/common/eal_common_options.c +7 -2
index 38b72fb665..7075a051b8 100644
@@ -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) {
Signature · 1 line
2.31.1
#90 lore raw

PATCH v5 4/4 log: add option argument help

In reply to Thomas Monjalon

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).

---
 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(-)
lib/librte_eal/common/eal_common_log.c +46 -5
index b9b982fdb5..4c6766a360 100644
@@ -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));
 	}
 }
 
lib/librte_eal/common/eal_common_options.c +31 -13

72 lines not on this page · raw message

lib/librte_eal/common/eal_log.h +5 -0
index 684650a17b..c784fa6043 100644
@@ -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 */
lib/librte_eal/include/rte_log.h +11 -0
index 424dfa3fd0..ccbb7ccd81 100644
@@ -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.
  *
lib/librte_eal/version.map +1 -0
index e23745ae6e..6c14fea27b 100644
@@ -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;
Signature · 1 line
2.31.1
#91 lore raw

v6 cover log level enhancements

In reply to Thomas Monjalon

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
Signature · 1 line
2.31.1
#92 lore raw

PATCH v6 1/4 log: move private functions

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
---
 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
lib/librte_eal/common/eal_common_log.c +15 -13
index c5554badb2..058fa10ffc 100644
@@ -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;
lib/librte_eal/common/eal_common_options.c +3 -2
index 622c7bc429..cd1a2856c9 100644
@@ -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);
lib/librte_eal/common/eal_log.h new file +27 -0
new file mode 100644
index 0000000000..684650a17b
@@ -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 */
lib/librte_eal/common/eal_private.h +0 -29
index b8a0d20021..e3512111d9 100644
@@ -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
lib/librte_eal/linux/eal.c +2 -1
index abbb537746..ac27dd4274 100644
@@ -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);
lib/librte_eal/linux/eal_log.c +2 -2
index 2095df74c5..c0aa1007c4 100644
@@ -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;
 
lib/librte_eal/windows/eal.c +2 -1
index 2fc3d6141c..68a1fd1d21 100644
@@ -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);
 
lib/librte_eal/windows/eal_log.c +4 -2
index 875981f139..d4ea47f1c8 100644
@@ -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);
 
Signature · 1 line
2.31.1
#93 lore raw

PATCH v6 2/4 log: introduce macro for maximum level

In reply to Thomas Monjalon

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.

---
 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(-)
lib/librte_eal/common/eal_common_log.c +4 -4
index 058fa10ffc..b9b982fdb5 100644
@@ -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) {
lib/librte_eal/common/eal_common_options.c +1 -1
index cd1a2856c9..38b72fb665 100644
@@ -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;
 	}
lib/librte_eal/include/rte_log.h +1 -0
index 21a7d16340..424dfa3fd0 100644
@@ -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.
Signature · 1 line
2.31.1
Reviewed-by on v6 2/4
#94 lore raw

Re: [dpdk-dev] [PATCH v6 2/4] log: introduce macro for maximum level

Quoted 8 lines · Thomas Monjalon

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.

Signature · 1 line
David Marchand
#95 lore raw

PATCH v6 3/4 log: catch invalid level option number

In reply to Thomas Monjalon

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.

---
 lib/librte_eal/common/eal_common_options.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
lib/librte_eal/common/eal_common_options.c +7 -2
index 38b72fb665..7075a051b8 100644
@@ -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) {
Signature · 1 line
2.31.1
Reviewed-by on v6 3/4
#96 lore raw

Re: [dpdk-dev] [PATCH v6 3/4] log: catch invalid level option number

Quoted 9 lines · Thomas Monjalon

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.

Signature · 1 line
David Marchand
#97 lore raw

PATCH v6 4/4 log: add option argument help

In reply to Thomas Monjalon

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).

---
 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(-)
lib/librte_eal/common/eal_common_log.c +46 -5
index b9b982fdb5..4c6766a360 100644
@@ -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));
 	}
 }
 
lib/librte_eal/common/eal_common_options.c +31 -13

72 lines not on this page · raw message

lib/librte_eal/common/eal_log.h +5 -0
index 684650a17b..c784fa6043 100644
@@ -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 */
lib/librte_eal/include/rte_log.h +11 -0
index 424dfa3fd0..ccbb7ccd81 100644
@@ -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.
  *
lib/librte_eal/version.map +1 -0
index e23745ae6e..6c14fea27b 100644
@@ -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;
Signature · 1 line
2.31.1
#98 lore raw

Re: [dpdk-dev] [PATCH v6 4/4] log: add option argument help

Quoted 33 lines · Thomas Monjalon
lib/librte_eal/common/eal_common_log.c +29 -0
@@ -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;

lib/librte_eal/common/eal_common_log.c loglevel_to_string(uint32_t level) · line 455

Quoted 10 lines
lib/librte_eal/common/eal_common_log.c +10 -0
+       } 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);
Quoted 2 lines
(quoted diff) +2 -0
+}
+
Signature · 1 line
David Marchand
#99 lore raw

Re: [dpdk-dev] [PATCH v6 4/4] log: add option argument help

06/04/2021 16:28, David Marchand:

Quoted 27 lines · Thomas Monjalon
Quoted 13 lines
lib/librte_eal/common/eal_common_log.c +13 -0
+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;

lib/librte_eal/common/eal_common_log.c loglevel_to_string(uint32_t level) · line 455

Quoted 10 lines
lib/librte_eal/common/eal_common_log.c +10 -0
+       } 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:

Quoted 2 lines

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.

#100 lore raw

Re: [dpdk-dev] [PATCH v6 4/4] log: add option argument help

In reply to Thomas Monjalon

06/04/2021 15:11, Thomas Monjalon:

lib/librte_eal/version.map EXPERIMENTAL { · line 414

Quoted 4 lines
lib/librte_eal/version.map +1 -0
 	# added in 21.05
+	rte_log_list_types;

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

#101 lore raw

Re: [dpdk-dev] [PATCH v6 4/4] log: add option argument help

Quoted 9 lines · Thomas Monjalon

06/04/2021 15:11, Thomas Monjalon:

lib/librte_eal/version.map EXPERIMENTAL { · line 414

Quoted 4 lines
lib/librte_eal/version.map +1 -0
      # 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.

Signature · 1 line
David Marchand
#102 lore raw

v7 cover log level enhancements

In reply to Thomas Monjalon

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
Signature · 1 line
2.31.1
#103 lore raw

PATCH v7 1/4 log: move private functions

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
---
 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
lib/librte_eal/common/eal_common_log.c +15 -13
index c5554badb2..058fa10ffc 100644
@@ -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;
lib/librte_eal/common/eal_common_options.c +3 -2
index 622c7bc429..cd1a2856c9 100644
@@ -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);
lib/librte_eal/common/eal_log.h new file +27 -0
new file mode 100644
index 0000000000..684650a17b
@@ -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 */
lib/librte_eal/common/eal_private.h +0 -29
index b8a0d20021..e3512111d9 100644
@@ -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
lib/librte_eal/linux/eal.c +2 -1
index abbb537746..ac27dd4274 100644
@@ -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);
lib/librte_eal/linux/eal_log.c +2 -2
index 2095df74c5..c0aa1007c4 100644
@@ -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;
 
lib/librte_eal/windows/eal.c +2 -1
index 2fc3d6141c..68a1fd1d21 100644
@@ -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);
 
lib/librte_eal/windows/eal_log.c +4 -2
index 875981f139..d4ea47f1c8 100644
@@ -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);
 
Signature · 1 line
2.31.1
#104 lore raw

PATCH v7 2/4 log: introduce macro for maximum level

In reply to Thomas Monjalon

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.

---
 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(-)
lib/librte_eal/common/eal_common_log.c +4 -4
index 058fa10ffc..b9b982fdb5 100644
@@ -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) {
lib/librte_eal/common/eal_common_options.c +1 -1
index cd1a2856c9..38b72fb665 100644
@@ -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;
 	}
lib/librte_eal/include/rte_log.h +1 -0
index 21a7d16340..424dfa3fd0 100644
@@ -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.
Signature · 1 line
2.31.1
#105 lore raw

PATCH v7 3/4 log: catch invalid level option number

In reply to Thomas Monjalon

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.

---
 lib/librte_eal/common/eal_common_options.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
lib/librte_eal/common/eal_common_options.c +7 -2
index 38b72fb665..7075a051b8 100644
@@ -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) {
Signature · 1 line
2.31.1
#106 lore raw

PATCH v7 4/4 log: add option argument help

In reply to Thomas Monjalon

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).

---
 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(-)
lib/librte_eal/common/eal_common_log.c +49 -5
index b9b982fdb5..4c1d514770 100644
@@ -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));
 	}
 }
 
lib/librte_eal/common/eal_common_options.c +31 -13

72 lines not on this page · raw message

lib/librte_eal/common/eal_log.h +5 -0
index 684650a17b..c784fa6043 100644
@@ -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 */
lib/librte_eal/include/rte_log.h +11 -0
index 424dfa3fd0..ccbb7ccd81 100644
@@ -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.
  *
lib/librte_eal/version.map +1 -0
index fc305c1c71..aa86b9e4fb 100644
@@ -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;
Signature · 1 line
2.31.1
Reviewed-by on v7 4/4
#107 lore raw

Re: [dpdk-dev] [PATCH v7 4/4] log: add option argument help

Quoted 16 lines · Thomas Monjalon

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).

Quoted 3 lines
Signature · 1 line
David Marchand
Acked-by on v7 4/4
#108 lore raw

Re: [dpdk-dev] [PATCH v7 4/4] log: add option argument help

In reply to Thomas Monjalon
Quoted 18 lines · Thomas Monjalon

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).

Quoted 7 lines
---
 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(-)
#109 lore raw

Re: [dpdk-dev] [PATCH v7 0/4] log level enhancements

In reply to Thomas Monjalon
Quoted 6 lines · Thomas Monjalon

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.

Signature · 1 line
David Marchand
#110 lore raw

v5 cover cleanup exit and usage messages in apps

In reply to Thomas Monjalon

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(-)
Signature · 1 line
2.31.1
#111 lore raw

PATCH v5 1/3 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.

---
 .../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(-)
app/test-compress-perf/comp_perf_options_parse.c +1 -1
index 04a8d2fbee..019eddb7bd 100644
@@ -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:
app/test-crypto-perf/cperf_options_parsing.c +1 -1
index 0466f7baf8..40b6dfb648 100644
@@ -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:
app/test-flow-perf/main.c +28 -31

166 lines not on this page · raw message

app/test-pmd/parameters.c +2 -2
index a326c8ce4f..b7d4ef76b0 100644
@@ -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]);
app/test-regex/main.c +1 -2
index aea4fa6b88..7bb87bb1b8 100644
@@ -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;
 		}
 	}
Signature · 1 line
2.31.1
#112 lore raw

PATCH v5 2/3 app/regex: fix usage text

In reply to Thomas Monjalon

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")
---
 app/test-regex/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
app/test-regex/main.c +2 -2
index 7bb87bb1b8..f18dc2eef8 100644
@@ -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;
 		}
Signature · 1 line
2.31.1
#113 lore raw

PATCH v5 3/3 app/testpmd: fix usage text

In reply to Thomas Monjalon

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")
---
 app/test-pmd/parameters.c | 35 ++++++++---------------------------
 1 file changed, 8 insertions(+), 27 deletions(-)
app/test-pmd/parameters.c +8 -27
index b7d4ef76b0..f3954c1c63 100644
@@ -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 },
Signature · 1 line
2.31.1
Acked-by on the v5 series
#114 lore raw

Re: [dpdk-dev] [PATCH v5 0/3] cleanup exit and usage messages in apps

In reply to Thomas Monjalon
Quoted 5 lines · Thomas Monjalon

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,

Series applied, thanks.

Signature · 1 line
David Marchand
#115 lore raw

v5 cover improve options help

In reply to Thomas Monjalon

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(-)
Signature · 1 line
2.31.1
#116 lore raw

PATCH v5 1/4 eal: explain argv behaviour during init

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.

---
 lib/librte_eal/include/rte_eal.h | 2 ++
 1 file changed, 2 insertions(+)
lib/librte_eal/include/rte_eal.h +2 -0
index eaf6469e50..0cbeedb594 100644
@@ -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(),
Signature · 1 line
2.31.1
Acked-by on v5 1/4
#117 lore raw

Re: [dpdk-dev] [PATCH v5 1/4] eal: explain argv behaviour during init

Quoted 9 lines · On Mon, 5 Apr 2021 21:39:51 +0200 Thomas Monjalon <[email protected]> wrote:

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.

Quoted 5 lines

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

This old patch is still worth applying

#118 lore raw

PATCH v5 2/4 eal: improve options usage text

In reply to Thomas Monjalon

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.

---
 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(-)
lib/librte_eal/common/eal_common_options.c +5 -6
index 2951b1aca2..08a85614c9 100644
@@ -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"
lib/librte_eal/freebsd/eal.c +4 -4
index 32442e5ba6..4e10d37253 100644
@@ -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
lib/librte_eal/linux/eal.c +6 -6
index ac27dd4274..4f36f9b1f5 100644
@@ -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
lib/librte_eal/windows/eal.c +4 -6
index 68a1fd1d21..25921eecb2 100644
@@ -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 */
Signature · 1 line
2.31.1
Acked-by on v5 2/4
#119 lore raw

Re: [dpdk-dev] [PATCH v5 2/4] eal: improve options usage text

Quoted 11 lines · On Mon, 5 Apr 2021 21:39:52 +0200 Thomas Monjalon <[email protected]> wrote:

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.

The default eal usage is due for an overhaul. Split it into sections and only show a short summary. See git for an example.

But this part is fine, probably hold for 23.11 where users might expect more changes.

#120 lore raw

Re: [dpdk-dev] [PATCH v5 2/4] eal: improve options usage text

In reply to Thomas Monjalon
Quoted 11 lines · On Mon, 5 Apr 2021 21:39:52 +0200 Thomas Monjalon <[email protected]> wrote:

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.

This patch no longer applies, please rebase and resubmit

#121 lore raw

PATCH v5 3/4 eal: use macros for help option

In reply to Thomas Monjalon

The macros OPT_HELP and OPT_HELP_NUM were not used where appropriate.

---
 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(-)
lib/librte_eal/common/eal_common_options.c +1 -1
index 08a85614c9..1da6583d71 100644
@@ -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"
lib/librte_eal/freebsd/eal.c +1 -1
index 4e10d37253..73229ff9c4 100644
@@ -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:
lib/librte_eal/linux/eal.c +1 -1
index 4f36f9b1f5..d3615de641 100644
@@ -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);
 
lib/librte_eal/windows/eal.c +1 -1
index 25921eecb2..5bca3ace1c 100644
@@ -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:
Signature · 1 line
2.31.1
Acked-by on v5 3/4
#122 lore raw

Re: [dpdk-dev] [PATCH v5 3/4] eal: use macros for help option

Quoted 5 lines · On Mon, 5 Apr 2021 21:39:53 +0200 Thomas Monjalon <[email protected]> wrote:

The macros OPT_HELP and OPT_HELP_NUM were not used where appropriate.

Not sure why this never got applied.

#123 lore raw

PATCH v5 4/4 app: hook in EAL usage help

In reply to Thomas Monjalon

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.

---
 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(-)
app/pdump/main.c +2 -0
index 63bbe65cd8..8641017f48 100644
@@ -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);
 
app/proc-info/main.c +2 -0
index b9587f7ded..e7d86bfa9d 100644
@@ -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) {
app/test-acl/main.c +2 -0
index 2cb2fe2579..9f95cb0fbf 100644
@@ -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");
app/test-bbdev/main.c +2 -1
index ff65173fdb..5960ec18b2 100644
@@ -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;
app/test-compress-perf/comp_perf_options.h +2 -0
index 0b777521c5..7dd785fba1 100644
@@ -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);
app/test-compress-perf/comp_perf_options_parse.c +4 -4
index 019eddb7bd..39d7fd8c69 100644
@@ -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;
 		}
 	}
app/test-compress-perf/main.c +2 -1
index cc9951a9b1..dcd347528e 100644
@@ -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");
app/test-crypto-perf/cperf_options.h +2 -0
index 9664a4b343..5f4a780614 100644
@@ -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);
 
app/test-crypto-perf/cperf_options_parsing.c +4 -4
index 40b6dfb648..3777bc7509 100644
@@ -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;
 		}
 	}
app/test-crypto-perf/main.c +2 -1
index 49af812d8b..497c4c5226 100644
@@ -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");
app/test-fib/main.c +8 -0
index b0a97b0d7e..420fe17c39 100644
@@ -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");
app/test-flow-perf/main.c +3 -1
index 0aef767350..949a5e3e11 100644
@@ -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");
app/test-pmd/parameters.c +2 -2
index f3954c1c63..4a1d64af89 100644
@@ -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);
app/test-pmd/testpmd.c +2 -0
index 96d2e0fcec..007ae429a1 100644
@@ -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",
app/test-pmd/testpmd.h +1 -0
index a87ccb0f0f..1f9408ebb9 100644
@@ -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);
app/test-regex/main.c +2 -1
index f18dc2eef8..73ba227fba 100644
@@ -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");
app/test-sad/main.c +7 -0
index 1024757add..14a8263f8c 100644
@@ -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");
Signature · 1 line
2.31.1
#124 lore raw

Re: [dpdk-dev] [PATCH v5 4/4] app: hook in EAL usage help

Quoted 29 lines · Thomas Monjalon

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.

---
 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 +++++++
Quoted 1 line

+ 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.

#125 lore raw

Re: [dpdk-dev] [PATCH v5 4/4] app: hook in EAL usage help

06/04/2021 15:32, Jerin Jacob:

Quoted 5 lines · Thomas Monjalon
Quoted 4 lines

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.

[...]

Quoted 6 lines
Quoted 1 line

+ 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?

#126 lore raw

Re: [dpdk-dev] [PATCH v5 4/4] app: hook in EAL usage help

Quoted 10 lines · Thomas Monjalon

06/04/2021 15:32, Jerin Jacob:

Quoted 5 lines · Thomas Monjalon
Quoted 4 lines

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.

[...]

Quoted 2 lines
Quoted 1 line

+ rte_set_application_usage_hook(print_usage);

Quoted 8 lines
Quoted 4 lines

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.

Quoted 2 lines
#127 lore raw

Re: [dpdk-dev] [PATCH v5 4/4] app: hook in EAL usage help

In reply to Thomas Monjalon

This patch appears stuck in limbo.

Some comments.

app/test-compress-perf/comp_perf_options_parse.c struct name_id_map { · line 42

Quoted 12 lines · On Mon, 5 Apr 2021 21:39:54 +0200 Thomas Monjalon <[email protected]> wrote:
app/test-compress-perf/comp_perf_options_parse.c +2 -2
index 019eddb7bd..39d7fd8c69 100644
@@ -38,8 +38,8 @@ struct name_id_map {
 	uint32_t id;
 };
 
-static void
-usage(char *progname)
+void
+comp_perf_usage(const char *progname)

Why does the hook now need to be a non-static function. Should be possible for the hook to still just be:

static void
usage(const char *progname);

Fits the principle of change as little as possible.

#128 lore raw

Re: [dpdk-dev] [PATCH v5 4/4] app: hook in EAL usage help

In reply to Thomas Monjalon
Quoted 8 lines · On Mon, 5 Apr 2021 21:39:54 +0200 Thomas Monjalon <[email protected]> wrote:

From: Thomas Monjalon <[email protected]>
To: [email protected]
Cc: [email protected], Wisam Jaddo <[email protected]>, Bruce Richardson <[email protected]>, Andrew Rybchenko <[email protected]>, Reshma Pattan <[email protected]>, Maryam Tahhan <[email protected]>, Konstantin Ananyev <[email protected]>, Nicolas Chautru <[email protected]>, Declan Doherty <[email protected]>, Ciara Power <[email protected]>, Vladimir Medvedkin <[email protected]>, Xiaoyun Li <[email protected]>, Ori Kam <[email protected]>, Bernard Iremonger <[email protected]>
Subject: [dpdk-dev] [PATCH v5 4/4] app: hook in EAL usage help
Date: Mon, 5 Apr 2021 21:39:54 +0200
Sender: "dev" <[email protected]>
X-Mailer: git-send-email 2.31.1

Quoted 8 lines

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.

The patch makes sense, but no longer applies.
It needs to be rebased.

#129 lore raw
In reply to Thomas Monjalon
Quoted 31 lines · On Mon, 5 Apr 2021 21:39:50 +0200 Thomas Monjalon <[email protected]> wrote:

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 +
Quoted 9 lines
 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(-)

Thomas, this patchset seems ready but never made it in. What is best disposition for it:
1. Rebase and resubmit?
2. I could add it to the log patch series WIP?
3. Drop it since old?

#130 lore raw

29/06/2023 18:27, Stephen Hemminger:

Quoted 19 lines
Quoted 8 lines · On Mon, 5 Apr 2021 21:39:50 +0200 Thomas Monjalon <[email protected]> wrote:

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.

Quoted 7 lines

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

Quoted 5 lines

Thomas, this patchset seems ready but never made it in. What is best disposition for it:
1. Rebase and resubmit?
2. I could add it to the log patch series WIP?
3. Drop it since old?

I've applied the patches 1 and 3 that you acked.

I let you revisit the patches 2 and 4 if you wish.

#131 lore raw
Quoted 26 lines · On Thu, 06 Jul 2023 10:29:04 +0200 Thomas Monjalon <[email protected]> wrote:

29/06/2023 18:27, Stephen Hemminger:

Quoted 19 lines
Quoted 8 lines · On Mon, 5 Apr 2021 21:39:50 +0200 Thomas Monjalon <[email protected]> wrote:

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.

Quoted 7 lines

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

Quoted 5 lines

Thomas, this patchset seems ready but never made it in. What is best disposition for it:
1. Rebase and resubmit?
2. I could add it to the log patch series WIP?
3. Drop it since old?

Quoted 3 lines

I've applied the patches 1 and 3 that you acked.

I let you revisit the patches 2 and 4 if you wish.

Thanks. Trying to reach 500 patches by 23.08 release.

#132 lore raw

06/07/2023 16:44, Stephen Hemminger:

Quoted 1 line

Trying to reach 500 patches by 23.08 release.

Impossible. It is 23.07 :)