Skip to contentSkip to conversation

eal:Fix log messages always being printed from rte_eal_cpu_init

PATCH Superseded Keith Wiles 5 participants 16 messages Jun 7, 2015 – Aug 3, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 eal:Fix log messages always being printed from rte_eal_cpu_init

The RTE_LOG(DEBUG, ...) messages in rte_eal_cpu_init() are printed even when the log level on the command line was set to INFO or lower.

The problem is the rte_eal_cpu_init() routine was called before the command line args are scanned. Setting --log-level=7 now correctly does not print the messages from the rte_eal_cpu_init() routine.

---
 lib/librte_eal/bsdapp/eal/eal.c   | 43 ++++++++++++++++++++++++++++++++++-----
 lib/librte_eal/linuxapp/eal/eal.c | 43 ++++++++++++++++++++++++++++++++++-----
 2 files changed, 76 insertions(+), 10 deletions(-)
lib/librte_eal/bsdapp/eal/eal.c +38 -5
index 43e8a47..ca10f2c 100644
@@ -306,6 +306,38 @@ eal_get_hugepage_mem_size(void)
 	return (size < SIZE_MAX) ? (size_t)(size) : SIZE_MAX;
 }
 
+/* Parse the arguments for --log-level only */
+static void
+eal_log_level_parse(int argc, char **argv)
+{
+	int opt;
+	char **argvopt;
+	int option_index;
+
+	argvopt = argv;
+
+	eal_reset_internal_config(&internal_config);
+
+	while ((opt = getopt_long(argc, argvopt, eal_short_options,
+				  eal_long_options, &option_index)) != EOF) {
+
+		int ret;
+
+		/* getopt is not happy, stop right now */
+		if (opt == '?')
+			break;
+
+		ret = (opt == OPT_LOG_LEVEL_NUM)?
+			eal_parse_common_option(opt, optarg, &internal_config) : 0;
+
+		/* common parser is not happy */
+		if (ret < 0)
+			break;
+	}
+
+	optind = 0; /* reset getopt lib */
+}
+
 /* Parse the argument given in the command line of the application */
 static int
 eal_parse_args(int argc, char **argv)
@@ -317,8 +349,6 @@ eal_parse_args(int argc, char **argv)
 
 	argvopt = argv;
 
-	eal_reset_internal_config(&internal_config);
-
 	while ((opt = getopt_long(argc, argvopt, eal_short_options,
 				  eal_long_options, &option_index)) != EOF) {
 
@@ -447,6 +477,12 @@ rte_eal_init(int argc, char **argv)
 	if (rte_eal_log_early_init() < 0)
 		rte_panic("Cannot init early logs\n");
 
+	eal_log_level_parse(argc, argv);
+
+	/* set log level as early as possible */
+	rte_set_log_level(internal_config.log_level);
+
+	RTE_LOG(INFO, EAL,  "DPDK Version %s\n", rte_version());
 	if (rte_eal_cpu_init() < 0)
 		rte_panic("Cannot detect lcores\n");
 
@@ -454,9 +490,6 @@ rte_eal_init(int argc, char **argv)
 	if (fctret < 0)
 		exit(1);
 
-	/* set log level as early as possible */
-	rte_set_log_level(internal_config.log_level);
-
 	if (internal_config.no_hugetlbfs == 0 &&
 			internal_config.process_type != RTE_PROC_SECONDARY &&
 			eal_hugepage_info_init() < 0)
lib/librte_eal/linuxapp/eal/eal.c +38 -5

67 lines not on this page · raw message

Signature · 1 line
2.3.0
#1 lore raw

PATCH 1/1 log:Change magic number on RTE_LOG_LEVEL to a define

Config files used RTE_LOG_LEVEL=8 to set log level to DEBUG. Using a the RTE_LOG_XXXX is easier to maintain.

Converted the RTE_LOG_XXXX defines into a enum of values with the same names for to reduct maintaining the values and allow debuggers to print the name of the value.

---
 config/common_bsdapp                    |  8 +++++++-
 config/common_linuxapp                  |  8 +++++++-
 lib/librte_eal/common/eal_common_log.c  |  4 ++--
 lib/librte_eal/common/include/rte_log.h | 19 +++++++++++--------
 4 files changed, 27 insertions(+), 12 deletions(-)
config/common_bsdapp +7 -1
index 0b169c8..97bbcbd 100644
@@ -93,12 +93,18 @@ CONFIG_RTE_MAX_NUMA_NODES=8
 CONFIG_RTE_MAX_MEMSEG=256
 CONFIG_RTE_MAX_MEMZONE=2560
 CONFIG_RTE_MAX_TAILQ=32
-CONFIG_RTE_LOG_LEVEL=8
 CONFIG_RTE_LOG_HISTORY=256
 CONFIG_RTE_EAL_ALLOW_INV_SOCKET_ID=n
 CONFIG_RTE_EAL_ALWAYS_PANIC_ON_ERROR=n
 
 #
+# Log level use: RTE_LOG_XXX
+#   XXX = NOOP, EMERG, ALERT, CRIT, ERR, WARNING, NOTICE, INFO or DEBUG
+#   Look in rte_log.h for others if any.
+#
+CONFIG_RTE_LOG_LEVEL=RTE_LOG_DEBUG
+
+#
 # FreeBSD contiguous memory driver settings
 #
 CONFIG_RTE_CONTIGMEM_MAX_NUM_BUFS=64
config/common_linuxapp +7 -1
index 5deb55a..886fc66 100644
@@ -93,7 +93,6 @@ CONFIG_RTE_MAX_NUMA_NODES=8
 CONFIG_RTE_MAX_MEMSEG=256
 CONFIG_RTE_MAX_MEMZONE=2560
 CONFIG_RTE_MAX_TAILQ=32
-CONFIG_RTE_LOG_LEVEL=8
 CONFIG_RTE_LOG_HISTORY=256
 CONFIG_RTE_LIBEAL_USE_HPET=n
 CONFIG_RTE_EAL_ALLOW_INV_SOCKET_ID=n
@@ -102,6 +101,13 @@ CONFIG_RTE_EAL_IGB_UIO=y
 CONFIG_RTE_EAL_VFIO=y
 
 #
+# Log level use: RTE_LOG_XXX
+#   XXX = NOOP, EMERG, ALERT, CRIT, ERR, WARNING, NOTICE, INFO or DEBUG
+#   Look in rte_log.h for others if any.
+#
+CONFIG_RTE_LOG_LEVEL=RTE_LOG_DEBUG
+
+#
 # Special configurations in PCI Config Space for high performance
 #
 CONFIG_RTE_PCI_CONFIG=n
lib/librte_eal/common/eal_common_log.c +2 -2
index fe3d7d5..3dcceab 100644
@@ -82,7 +82,7 @@ static struct log_history_list log_history;
 /* global log structure */
 struct rte_logs rte_logs = {
 	.type = ~0,
-	.level = RTE_LOG_DEBUG,
+	.level = RTE_LOG_LEVEL,
 	.file = NULL,
 };
 
@@ -93,7 +93,7 @@ static int history_enabled = 1;
 
 /**
  * This global structure stores some informations about the message
- * that is currently beeing processed by one lcore
+ * that is currently being processed by one lcore
  */
 struct log_cur_msg {
 	uint32_t loglevel; /**< log level - see rte_log.h */
lib/librte_eal/common/include/rte_log.h +11 -8
index 3b467c1..e7e893e 100644
@@ -89,14 +89,17 @@ extern struct rte_logs rte_logs;
 #define RTE_LOGTYPE_USER8   0x80000000 /**< User-defined log type 8. */
 
 /* Can't use 0, as it gives compiler warnings */
-#define RTE_LOG_EMERG    1U  /**< System is unusable.               */
-#define RTE_LOG_ALERT    2U  /**< Action must be taken immediately. */
-#define RTE_LOG_CRIT     3U  /**< Critical conditions.              */
-#define RTE_LOG_ERR      4U  /**< Error conditions.                 */
-#define RTE_LOG_WARNING  5U  /**< Warning conditions.               */
-#define RTE_LOG_NOTICE   6U  /**< Normal but significant condition. */
-#define RTE_LOG_INFO     7U  /**< Informational.                    */
-#define RTE_LOG_DEBUG    8U  /**< Debug-level messages.             */
+enum {
+	RTE_LOG_NOOP = 0,   /**< Noop not used (zero entry)        */
+	RTE_LOG_EMERG,      /**< System is unusable.               */
+	RTE_LOG_ALERT,      /**< Action must be taken immediately. */
+	RTE_LOG_CRIT,       /**< Critical conditions.              */
+	RTE_LOG_ERR,        /**< Error conditions.                 */
+	RTE_LOG_WARNING,    /**< Warning conditions.               */
+	RTE_LOG_NOTICE,     /**< Normal but significant condition. */
+	RTE_LOG_INFO,       /**< Informational.                    */
+	RTE_LOG_DEBUG       /**< Debug-level messages.             */
+};
 
 /** The default log stream. */
 extern FILE *eal_default_log_stream;
Signature · 1 line
2.3.0
#10 lore raw
In reply to Keith Wiles
Quoted 8 lines · Keith Wiles

The RTE_LOG(DEBUG, ...) messages in rte_eal_cpu_init() are printed even when the log level on the command line was set to INFO or lower.

The problem is the rte_eal_cpu_init() routine was called before the command line args are scanned. Setting --log-level=7 now correctly does not print the messages from the rte_eal_cpu_init() routine.

This seems a good idea - make it easy to reduce the verbosity on startup if so desired. Some comments below.

Quoted 58 lines
---
 lib/librte_eal/bsdapp/eal/eal.c   | 43 ++++++++++++++++++++++++++++++++++-----
 lib/librte_eal/linuxapp/eal/eal.c | 43 ++++++++++++++++++++++++++++++++++-----
 2 files changed, 76 insertions(+), 10 deletions(-)
lib/librte_eal/bsdapp/eal/eal.c +32 -2
index 43e8a47..ca10f2c 100644
@@ -306,6 +306,38 @@ eal_get_hugepage_mem_size(void)
 	return (size < SIZE_MAX) ? (size_t)(size) : SIZE_MAX;
 }
 
+/* Parse the arguments for --log-level only */
+static void
+eal_log_level_parse(int argc, char **argv)
+{
+	int opt;
+	char **argvopt;
+	int option_index;
+
+	argvopt = argv;
+
+	eal_reset_internal_config(&internal_config);
+
+	while ((opt = getopt_long(argc, argvopt, eal_short_options,
+				  eal_long_options, &option_index)) != EOF) {
+
+		int ret;
+
+		/* getopt is not happy, stop right now */
+		if (opt == '?')
+			break;
+
+		ret = (opt == OPT_LOG_LEVEL_NUM)?
+			eal_parse_common_option(opt, optarg, &internal_config) : 0;
+
+		/* common parser is not happy */
+		if (ret < 0)
+			break;
+	}
+
+	optind = 0; /* reset getopt lib */
+}
+
 /* Parse the argument given in the command line of the application */
 static int
 eal_parse_args(int argc, char **argv)
@@ -317,8 +349,6 @@ eal_parse_args(int argc, char **argv)
 
 	argvopt = argv;
 
-	eal_reset_internal_config(&internal_config);
-
 	while ((opt = getopt_long(argc, argvopt, eal_short_options,
 				  eal_long_options, &option_index)) != EOF) {
 

lib/librte_eal/bsdapp/eal/eal.c rte_eal_init(int argc, char **argv) · line 485

Quoted 9 lines
lib/librte_eal/bsdapp/eal/eal.c +6 -0
@@ -447,6 +477,12 @@ rte_eal_init(int argc, char **argv)
 	if (rte_eal_log_early_init() < 0)
 		rte_panic("Cannot init early logs\n");
 
+	eal_log_level_parse(argc, argv);
+
+	/* set log level as early as possible */
+	rte_set_log_level(internal_config.log_level);
+
+	RTE_LOG(INFO, EAL,  "DPDK Version %s\n", rte_version());

There is already the -v option to the EAL to print the DPDK version. Just add that flag to any command, as it has no other effects. I don't think we need to increase the verbosity of startup by always printing it.

Quoted 43 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -3
 	if (rte_eal_cpu_init() < 0)
 		rte_panic("Cannot detect lcores\n");
 
@@ -454,9 +490,6 @@ rte_eal_init(int argc, char **argv)
 	if (fctret < 0)
 		exit(1);
 
-	/* set log level as early as possible */
-	rte_set_log_level(internal_config.log_level);
-
 	if (internal_config.no_hugetlbfs == 0 &&
 			internal_config.process_type != RTE_PROC_SECONDARY &&
 			eal_hugepage_info_init() < 0)
lib/librte_eal/linuxapp/eal/eal.c +22 -0
index bd770cf..090ec99 100644
@@ -499,6 +499,38 @@ eal_get_hugepage_mem_size(void)
 	return (size < SIZE_MAX) ? (size_t)(size) : SIZE_MAX;
 }
 
+/* Parse the arguments for --log-level only */
+static void
+eal_log_level_parse(int argc, char **argv)
+{
+	int opt;
+	char **argvopt;
+	int option_index;
+
+	argvopt = argv;
+
+	eal_reset_internal_config(&internal_config);
+
+	while ((opt = getopt_long(argc, argvopt, eal_short_options,
+				  eal_long_options, &option_index)) != EOF) {
+
+		int ret;
+
+		/* getopt is not happy, stop right now */
+		if (opt == '?')
+			break;
+
+		ret = (opt == OPT_LOG_LEVEL_NUM)?

lib/librte_eal/linuxapp/eal/eal.c eal_get_hugepage_mem_size(void) · line 533

Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal.c +10 -0
+			eal_parse_common_option(opt, optarg, &internal_config) : 0;
+
+		/* common parser is not happy */
+		if (ret < 0)
+			break;
+	}
+
+	optind = 0; /* reset getopt lib */
+}
+

This function looks duplicated for linux and bsd. Can we move it to one of the common files instead?

Regards,
/Bruce

#11 lore raw
Quoted 79 lines · Bruce
Quoted 9 lines · Keith Wiles

The RTE_LOG(DEBUG, ...) messages in rte_eal_cpu_init() are printed even when the log level on the command line was set to INFO or lower.

The problem is the rte_eal_cpu_init() routine was called before the command line args are scanned. Setting --log-level=7 now correctly does not print the messages from the rte_eal_cpu_init() routine.

This seems a good idea - make it easy to reduce the verbosity on startup if
so desired. Some comments below.

Quoted 64 lines
---
 lib/librte_eal/bsdapp/eal/eal.c   | 43
++++++++++++++++++++++++++++++++++-----
 lib/librte_eal/linuxapp/eal/eal.c | 43
++++++++++++++++++++++++++++++++++-----
 2 files changed, 76 insertions(+), 10 deletions(-)
lib/librte_eal/bsdapp/eal/eal.c +32 -2
index 43e8a47..ca10f2c 100644
@@ -306,6 +306,38 @@ eal_get_hugepage_mem_size(void)
 	return (size < SIZE_MAX) ? (size_t)(size) : SIZE_MAX;
 }
 
+/* Parse the arguments for --log-level only */
+static void
+eal_log_level_parse(int argc, char **argv)
+{
+	int opt;
+	char **argvopt;
+	int option_index;
+
+	argvopt = argv;
+
+	eal_reset_internal_config(&internal_config);
+
+	while ((opt = getopt_long(argc, argvopt, eal_short_options,
+				  eal_long_options, &option_index)) != EOF) {
+
+		int ret;
+
+		/* getopt is not happy, stop right now */
+		if (opt == '?')
+			break;
+
+		ret = (opt == OPT_LOG_LEVEL_NUM)?
+			eal_parse_common_option(opt, optarg, &internal_config) : 0;
+
+		/* common parser is not happy */
+		if (ret < 0)
+			break;
+	}
+
+	optind = 0; /* reset getopt lib */
+}
+
 /* Parse the argument given in the command line of the application */
 static int
 eal_parse_args(int argc, char **argv)
@@ -317,8 +349,6 @@ eal_parse_args(int argc, char **argv)
 
 	argvopt = argv;
 
-	eal_reset_internal_config(&internal_config);
-
 	while ((opt = getopt_long(argc, argvopt, eal_short_options,
 				  eal_long_options, &option_index)) != EOF) {
 
@@ -447,6 +477,12 @@ rte_eal_init(int argc, char **argv)
 	if (rte_eal_log_early_init() < 0)
 		rte_panic("Cannot init early logs\n");
 
Quoted 12 lines

lib/librte_eal/bsdapp/eal/eal.c rte_eal_init(int argc, char **argv) · line 485

Quoted 6 lines
lib/librte_eal/bsdapp/eal/eal.c +6 -0
+	eal_log_level_parse(argc, argv);
+
+	/* set log level as early as possible */
+	rte_set_log_level(internal_config.log_level);
+
+	RTE_LOG(INFO, EAL,  "DPDK Version %s\n", rte_version());

There is already the -v option to the EAL to print the DPDK version. Just add
that flag to any command, as it has no other effects. I don't think we need to
increase the verbosity of startup by always printing it.

OK will remove, but it is one of the things you always need to know when someone submits the startup messages. This way you do not have to put it in the email or ask them to tell you.

Quoted 51 lines
Quoted 51 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -3
 	if (rte_eal_cpu_init() < 0)
 		rte_panic("Cannot detect lcores\n");
 
@@ -454,9 +490,6 @@ rte_eal_init(int argc, char **argv)
 	if (fctret < 0)
 		exit(1);
 
-	/* set log level as early as possible */
-	rte_set_log_level(internal_config.log_level);
-
 	if (internal_config.no_hugetlbfs == 0 &&
 			internal_config.process_type != RTE_PROC_SECONDARY &&
 			eal_hugepage_info_init() < 0)
lib/librte_eal/linuxapp/eal/eal.c +28 -0
index bd770cf..090ec99 100644
@@ -499,6 +499,38 @@ eal_get_hugepage_mem_size(void)
 	return (size < SIZE_MAX) ? (size_t)(size) : SIZE_MAX;
 }
 
+/* Parse the arguments for --log-level only */
+static void
+eal_log_level_parse(int argc, char **argv)
+{
+	int opt;
+	char **argvopt;
+	int option_index;
+
+	argvopt = argv;
+
+	eal_reset_internal_config(&internal_config);
+
+	while ((opt = getopt_long(argc, argvopt, eal_short_options,
+				  eal_long_options, &option_index)) != EOF) {
+
+		int ret;
+
+		/* getopt is not happy, stop right now */
+		if (opt == '?')
+			break;
+
+		ret = (opt == OPT_LOG_LEVEL_NUM)?
+			eal_parse_common_option(opt, optarg, &internal_config) : 0;
+
+		/* common parser is not happy */
+		if (ret < 0)
+			break;
+	}
Quoted 8 lines

lib/librte_eal/linuxapp/eal/eal.c eal_get_hugepage_mem_size(void) · line 533

Quoted 4 lines
lib/librte_eal/linuxapp/eal/eal.c +4 -0
+
+	optind = 0; /* reset getopt lib */
+}
+

This function looks duplicated for linux and bsd. Can we move it to one of the
common files instead?

I looked at moving this function to the common location, but the problem is all of the routines of this type are all static functions. I did not want to add yet another global function to the mix. I will look at it and see what I can do.

Quoted 3 lines

Regards,
/Bruce

#12 lore raw
Quoted 160 lines · Keith
Quoted 79 lines · Bruce
Quoted 9 lines · Keith Wiles

The RTE_LOG(DEBUG, ...) messages in rte_eal_cpu_init() are printed even when the log level on the command line was set to INFO or lower.

The problem is the rte_eal_cpu_init() routine was called before the command line args are scanned. Setting --log-level=7 now correctly does not print the messages from the rte_eal_cpu_init() routine.

This seems a good idea - make it easy to reduce the verbosity on startup if
so desired. Some comments below.

Quoted 64 lines
---
 lib/librte_eal/bsdapp/eal/eal.c   | 43
++++++++++++++++++++++++++++++++++-----
 lib/librte_eal/linuxapp/eal/eal.c | 43
++++++++++++++++++++++++++++++++++-----
 2 files changed, 76 insertions(+), 10 deletions(-)
lib/librte_eal/bsdapp/eal/eal.c +32 -2
index 43e8a47..ca10f2c 100644
@@ -306,6 +306,38 @@ eal_get_hugepage_mem_size(void)
 	return (size < SIZE_MAX) ? (size_t)(size) : SIZE_MAX;
 }
 
+/* Parse the arguments for --log-level only */
+static void
+eal_log_level_parse(int argc, char **argv)
+{
+	int opt;
+	char **argvopt;
+	int option_index;
+
+	argvopt = argv;
+
+	eal_reset_internal_config(&internal_config);
+
+	while ((opt = getopt_long(argc, argvopt, eal_short_options,
+				  eal_long_options, &option_index)) != EOF) {
+
+		int ret;
+
+		/* getopt is not happy, stop right now */
+		if (opt == '?')
+			break;
+
+		ret = (opt == OPT_LOG_LEVEL_NUM)?
+			eal_parse_common_option(opt, optarg, &internal_config) : 0;
+
+		/* common parser is not happy */
+		if (ret < 0)
+			break;
+	}
+
+	optind = 0; /* reset getopt lib */
+}
+
 /* Parse the argument given in the command line of the application */
 static int
 eal_parse_args(int argc, char **argv)
@@ -317,8 +349,6 @@ eal_parse_args(int argc, char **argv)
 
 	argvopt = argv;
 
-	eal_reset_internal_config(&internal_config);
-
 	while ((opt = getopt_long(argc, argvopt, eal_short_options,
 				  eal_long_options, &option_index)) != EOF) {
 
@@ -447,6 +477,12 @@ rte_eal_init(int argc, char **argv)
 	if (rte_eal_log_early_init() < 0)
 		rte_panic("Cannot init early logs\n");
 
Quoted 12 lines

lib/librte_eal/bsdapp/eal/eal.c rte_eal_init(int argc, char **argv) · line 485

Quoted 6 lines
lib/librte_eal/bsdapp/eal/eal.c +6 -0
+	eal_log_level_parse(argc, argv);
+
+	/* set log level as early as possible */
+	rte_set_log_level(internal_config.log_level);
+
+	RTE_LOG(INFO, EAL,  "DPDK Version %s\n", rte_version());

There is already the -v option to the EAL to print the DPDK version. Just add
that flag to any command, as it has no other effects. I don't think we need to
increase the verbosity of startup by always printing it.

OK will remove, but it is one of the things you always need to know when someone submits the startup messages. This way you do not have to put it in the email or ask them to tell you.

Quoted 51 lines
Quoted 51 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -3
 	if (rte_eal_cpu_init() < 0)
 		rte_panic("Cannot detect lcores\n");
 
@@ -454,9 +490,6 @@ rte_eal_init(int argc, char **argv)
 	if (fctret < 0)
 		exit(1);
 
-	/* set log level as early as possible */
-	rte_set_log_level(internal_config.log_level);
-
 	if (internal_config.no_hugetlbfs == 0 &&
 			internal_config.process_type != RTE_PROC_SECONDARY &&
 			eal_hugepage_info_init() < 0)
lib/librte_eal/linuxapp/eal/eal.c +28 -0
index bd770cf..090ec99 100644
@@ -499,6 +499,38 @@ eal_get_hugepage_mem_size(void)
 	return (size < SIZE_MAX) ? (size_t)(size) : SIZE_MAX;
 }
 
+/* Parse the arguments for --log-level only */
+static void
+eal_log_level_parse(int argc, char **argv)
+{
+	int opt;
+	char **argvopt;
+	int option_index;
+
+	argvopt = argv;
+
+	eal_reset_internal_config(&internal_config);
+
+	while ((opt = getopt_long(argc, argvopt, eal_short_options,
+				  eal_long_options, &option_index)) != EOF) {
+
+		int ret;
+
+		/* getopt is not happy, stop right now */
+		if (opt == '?')
+			break;
+
+		ret = (opt == OPT_LOG_LEVEL_NUM)?
+			eal_parse_common_option(opt, optarg, &internal_config) : 0;
+
+		/* common parser is not happy */
+		if (ret < 0)
+			break;
+	}
Quoted 8 lines

lib/librte_eal/linuxapp/eal/eal.c eal_get_hugepage_mem_size(void) · line 533

Quoted 4 lines
lib/librte_eal/linuxapp/eal/eal.c +4 -0
+
+	optind = 0; /* reset getopt lib */
+}
+

This function looks duplicated for linux and bsd. Can we move it to one of the
common files instead?

Quoted 4 lines

I looked at moving this function to the common location, but the problem is all of the routines of this type are all static functions. I did not want to add yet another global function to the mix. I will look at it and see what I can do.

Well it looks like a fair number of the functions in eal.c are common between both versions. I could try to move them all or just leave the code as is. What do you want here?

Quoted 4 lines
Quoted 3 lines

Regards,
/Bruce

#13 lore raw

PATCH v2 1/1 eal:Fix log messages always being printed from rte_eal_cpu_init

In reply to Keith Wiles

The RTE_LOG(DEBUG, ...) messages in rte_eal_cpu_init() are printed even when the log level on the command line was set to INFO or lower.

The problem is the rte_eal_cpu_init() routine was called before the command line args are scanned. Setting --log-level=7 now correctly does not print the messages from the rte_eal_cpu_init() routine.

---
 lib/librte_eal/bsdapp/eal/eal.c   | 42 ++++++++++++++++++++++++++++++++++-----
 lib/librte_eal/linuxapp/eal/eal.c | 42 ++++++++++++++++++++++++++++++++++-----
 2 files changed, 74 insertions(+), 10 deletions(-)
lib/librte_eal/bsdapp/eal/eal.c +37 -5
index 43e8a47..0112617 100644
@@ -306,6 +306,38 @@ eal_get_hugepage_mem_size(void)
 	return (size < SIZE_MAX) ? (size_t)(size) : SIZE_MAX;
 }
 
+/* Parse the arguments for --log-level only */
+static void
+eal_log_level_parse(int argc, char **argv)
+{
+	int opt;
+	char **argvopt;
+	int option_index;
+
+	argvopt = argv;
+
+	eal_reset_internal_config(&internal_config);
+
+	while ((opt = getopt_long(argc, argvopt, eal_short_options,
+				  eal_long_options, &option_index)) != EOF) {
+
+		int ret;
+
+		/* getopt is not happy, stop right now */
+		if (opt == '?')
+			break;
+
+		ret = (opt == OPT_LOG_LEVEL_NUM)?
+			eal_parse_common_option(opt, optarg, &internal_config) : 0;
+
+		/* common parser is not happy */
+		if (ret < 0)
+			break;
+	}
+
+	optind = 0; /* reset getopt lib */
+}
+
 /* Parse the argument given in the command line of the application */
 static int
 eal_parse_args(int argc, char **argv)
@@ -317,8 +349,6 @@ eal_parse_args(int argc, char **argv)
 
 	argvopt = argv;
 
-	eal_reset_internal_config(&internal_config);
-
 	while ((opt = getopt_long(argc, argvopt, eal_short_options,
 				  eal_long_options, &option_index)) != EOF) {
 
@@ -447,6 +477,11 @@ rte_eal_init(int argc, char **argv)
 	if (rte_eal_log_early_init() < 0)
 		rte_panic("Cannot init early logs\n");
 
+	eal_log_level_parse(argc, argv);
+
+	/* set log level as early as possible */
+	rte_set_log_level(internal_config.log_level);
+
 	if (rte_eal_cpu_init() < 0)
 		rte_panic("Cannot detect lcores\n");
 
@@ -454,9 +489,6 @@ rte_eal_init(int argc, char **argv)
 	if (fctret < 0)
 		exit(1);
 
-	/* set log level as early as possible */
-	rte_set_log_level(internal_config.log_level);
-
 	if (internal_config.no_hugetlbfs == 0 &&
 			internal_config.process_type != RTE_PROC_SECONDARY &&
 			eal_hugepage_info_init() < 0)
lib/librte_eal/linuxapp/eal/eal.c +37 -5

66 lines not on this page · raw message

Signature · 1 line
2.3.0
#14 lore raw

Hello Keith,

Quoted 7 lines · Keith Wiles

The RTE_LOG(DEBUG, ...) messages in rte_eal_cpu_init() are printed even when the log level on the command line was set to INFO or lower.

The problem is the rte_eal_cpu_init() routine was called before the command line args are scanned. Setting --log-level=7 now correctly does not print the messages from the rte_eal_cpu_init() routine.

Quoted 8 lines
---
 lib/librte_eal/bsdapp/eal/eal.c   | 42
++++++++++++++++++++++++++++++++++-----
 lib/librte_eal/linuxapp/eal/eal.c | 42
++++++++++++++++++++++++++++++++++-----
 2 files changed, 74 insertions(+), 10 deletions(-)

We could have a different solution, but this patch is the quickest answer to the described problem.
Please, fix the checkpatch error / warnings, then, ack.

Signature · 1 line
David Marchand
#15 lore raw

2015-06-19 11:54, David Marchand:

Quoted 8 lines · Keith Wiles
Quoted 7 lines

The RTE_LOG(DEBUG, ...) messages in rte_eal_cpu_init() are printed even when the log level on the command line was set to INFO or lower.

The problem is the rte_eal_cpu_init() routine was called before the command line args are scanned. Setting --log-level=7 now correctly does not print the messages from the rte_eal_cpu_init() routine.

Quoted 5 lines
Quoted 1 line

We could have a different solution, but this patch is the quickest answer to the described problem.
Please, fix the checkpatch error / warnings, then, ack.

I fixed the checkpatch warnings.

Applied, thanks

I would prefer avoiding such copy/paste for bsdapp and linuxapp. Ravi Kerur worked on factorizing EAL code but we never found the right time to apply them and there are some concerns about the organizations of some code areas. I suggest to try to apply these ideas just after 2.1.0-rc1, when most of the pending EAL patches will be merged.
We'll have to do it piece by piece to avoid a "big review" effect.

#2 lore raw

Re: [PATCH] log:Change magic number on RTE_LOG_LEVEL to a define

In reply to Keith Wiles

2015-06-06 19:04, Keith Wiles:

Quoted 6 lines
config/common_bsdapp +0 -0
@@ -93,12 +93,18 @@ CONFIG_RTE_MAX_NUMA_NODES=8
 CONFIG_RTE_MAX_MEMSEG=256
 CONFIG_RTE_MAX_MEMZONE=2560
 CONFIG_RTE_MAX_TAILQ=32

config/common_bsdapp CONFIG_RTE_MAX_NUMA_NODES=8 · line 104

Quoted 10 lines
config/common_bsdapp +4 -1
-CONFIG_RTE_LOG_LEVEL=8
 CONFIG_RTE_LOG_HISTORY=256
 CONFIG_RTE_EAL_ALLOW_INV_SOCKET_ID=n
 CONFIG_RTE_EAL_ALWAYS_PANIC_ON_ERROR=n
 
 #
+# Log level use: RTE_LOG_XXX
+#   XXX = NOOP, EMERG, ALERT, CRIT, ERR, WARNING, NOTICE, INFO or DEBUG
+#   Look in rte_log.h for others if any.
+#

I think this comment is useless.

config/common_bsdapp CONFIG_RTE_MAX_NUMA_NODES=8 · line 105

Quoted 1 line
config/common_bsdapp +1 -0
+CONFIG_RTE_LOG_LEVEL=RTE_LOG_DEBUG

Yes, easier to read.
Please do not move line without good reason. It was more logic to see it along with LOG_HISTORY.

lib/librte_eal/common/eal_common_log.c static struct log_history_list log_history; · line 87

Quoted 10 lines
lib/librte_eal/common/eal_common_log.c +1 -1
@@ -82,7 +82,7 @@ static struct log_history_list log_history;
 /* global log structure */
 struct rte_logs rte_logs = {
 	.type = ~0,
-	.level = RTE_LOG_DEBUG,
+	.level = RTE_LOG_LEVEL,
 	.file = NULL,
 };

OK, more consistent.
It was set to RTE_LOG_LEVEL later anyway. (this comment would be useful in the commit message)

lib/librte_eal/common/eal_common_log.c static struct log_history_list log_history;

Quoted 11 lines
lib/librte_eal/common/eal_common_log.c +2 -8
 /* Can't use 0, as it gives compiler warnings */
-#define RTE_LOG_EMERG    1U  /**< System is unusable.               */
-#define RTE_LOG_ALERT    2U  /**< Action must be taken immediately. */
-#define RTE_LOG_CRIT     3U  /**< Critical conditions.              */
-#define RTE_LOG_ERR      4U  /**< Error conditions.                 */
-#define RTE_LOG_WARNING  5U  /**< Warning conditions.               */
-#define RTE_LOG_NOTICE   6U  /**< Normal but significant condition. */
-#define RTE_LOG_INFO     7U  /**< Informational.                    */
-#define RTE_LOG_DEBUG    8U  /**< Debug-level messages.             */
+enum {
+	RTE_LOG_NOOP = 0,   /**< Noop not used (zero entry)        */

NOOP is useless: EMERG may be = 1

lib/librte_eal/common/eal_common_log.c

Quoted 9 lines
lib/librte_eal/common/eal_common_log.c +9 -0
+	RTE_LOG_EMERG,      /**< System is unusable.               */
+	RTE_LOG_ALERT,      /**< Action must be taken immediately. */
+	RTE_LOG_CRIT,       /**< Critical conditions.              */
+	RTE_LOG_ERR,        /**< Error conditions.                 */
+	RTE_LOG_WARNING,    /**< Warning conditions.               */
+	RTE_LOG_NOTICE,     /**< Normal but significant condition. */
+	RTE_LOG_INFO,       /**< Informational.                    */
+	RTE_LOG_DEBUG       /**< Debug-level messages.             */
+};

What is the benefit of this change?

#3 lore raw

Re: [PATCH] log:Change magic number on RTE_LOG_LEVEL to a define

Quoted 12 lines · Thomas Monjalon

2015-06-06 19:04, Keith Wiles:

Quoted 11 lines
config/common_bsdapp +0 -1
@@ -93,12 +93,18 @@ CONFIG_RTE_MAX_NUMA_NODES=8
 CONFIG_RTE_MAX_MEMSEG=256
 CONFIG_RTE_MAX_MEMZONE=2560
 CONFIG_RTE_MAX_TAILQ=32
-CONFIG_RTE_LOG_LEVEL=8
 CONFIG_RTE_LOG_HISTORY=256
 CONFIG_RTE_EAL_ALLOW_INV_SOCKET_ID=n
 CONFIG_RTE_EAL_ALWAYS_PANIC_ON_ERROR=n
 
Quoted 7 lines

config/common_bsdapp CONFIG_RTE_MAX_NUMA_NODES=8 · line 104

Quoted 5 lines
config/common_bsdapp +4 -0
 #
+# Log level use: RTE_LOG_XXX
+#   XXX = NOOP, EMERG, ALERT, CRIT, ERR, WARNING, NOTICE, INFO or DEBUG
+#   Look in rte_log.h for others if any.
+#

I think this comment is useless.

I do not think the comment is useless as some may not understand what values the Log level can be set too in the future. Not commenting the change would be a problem IMO. This is also why the line was moved.

Quoted 7 lines

config/common_bsdapp CONFIG_RTE_MAX_NUMA_NODES=8 · line 105

Quoted 2 lines
config/common_bsdapp +1 -0
+CONFIG_RTE_LOG_LEVEL=RTE_LOG_DEBUG

Yes, easier to read.
Please do not move line without good reason. It was more logic to see it along
with LOG_HISTORY.

Moving the line was for the comment and now it is a enum value instead of a magic number. Magic numbers are bad right? Adding a comment to help the user set this value is always reasonable IMO unless the comment is not correct, is this the case?

Quoted 16 lines

lib/librte_eal/common/eal_common_log.c static struct log_history_list log_history; · line 87

Quoted 11 lines
lib/librte_eal/common/eal_common_log.c +1 -1
@@ -82,7 +82,7 @@ static struct log_history_list log_history;
 /* global log structure */
 struct rte_logs rte_logs = {
 	.type = ~0,
-	.level = RTE_LOG_DEBUG,
+	.level = RTE_LOG_LEVEL,
 	.file = NULL,
 };

OK, more consistent.
It was set to RTE_LOG_LEVEL later anyway. (this comment would be useful in the commit message)

Quoted 13 lines

lib/librte_eal/common/eal_common_log.c static struct log_history_list log_history;

Quoted 11 lines
lib/librte_eal/common/eal_common_log.c +2 -8
 /* Can't use 0, as it gives compiler warnings */
-#define RTE_LOG_EMERG    1U  /**< System is unusable.               */
-#define RTE_LOG_ALERT    2U  /**< Action must be taken immediately. */
-#define RTE_LOG_CRIT     3U  /**< Critical conditions.              */
-#define RTE_LOG_ERR      4U  /**< Error conditions.                 */
-#define RTE_LOG_WARNING  5U  /**< Warning conditions.               */
-#define RTE_LOG_NOTICE   6U  /**< Normal but significant condition. */
-#define RTE_LOG_INFO     7U  /**< Informational.                    */
-#define RTE_LOG_DEBUG    8U  /**< Debug-level messages.             */
+enum {
+	RTE_LOG_NOOP = 0,   /**< Noop not used (zero entry)        */

NOOP is useless: EMERG may be = 1

Does it really matter if I used RTE_LOG_NOOP, just to make sure someone did not try to use zero here. Instead of setting the RTE_LOG_EMERG=1, I can change it to be the way you suggest, but I think it does not hurt anything does it?

Quoted 12 lines

lib/librte_eal/common/eal_common_log.c

Quoted 10 lines
lib/librte_eal/common/eal_common_log.c +9 -0
+	RTE_LOG_EMERG,      /**< System is unusable.               */
+	RTE_LOG_ALERT,      /**< Action must be taken immediately. */
+	RTE_LOG_CRIT,       /**< Critical conditions.              */
+	RTE_LOG_ERR,        /**< Error conditions.                 */
+	RTE_LOG_WARNING,    /**< Warning conditions.               */
+	RTE_LOG_NOTICE,     /**< Normal but significant condition. */
+	RTE_LOG_INFO,       /**< Informational.                    */
+	RTE_LOG_DEBUG       /**< Debug-level messages.             */
+};

What is the benefit of this change?

The change is to use a enum in place of using magic numbers, plus you get the benefit of seeing the enum name in the debugger instead of a number. It makes the code more readable IMHO.

Quoted 2 lines

To me the code is fine and the only change would be the RTE_LOG_NOOP being remove and RTE_LOG_EMERG=1.

‹
Regards,
++Keith
Intel Corporation

#4 lore raw

Re: [PATCH] log:Change magic number on RTE_LOG_LEVEL to a define

Quoted 23 lines · Keith
Quoted 12 lines · Thomas Monjalon

2015-06-06 19:04, Keith Wiles:

Quoted 11 lines
config/common_bsdapp +0 -1
@@ -93,12 +93,18 @@ CONFIG_RTE_MAX_NUMA_NODES=8
 CONFIG_RTE_MAX_MEMSEG=256
 CONFIG_RTE_MAX_MEMZONE=2560
 CONFIG_RTE_MAX_TAILQ=32
-CONFIG_RTE_LOG_LEVEL=8
 CONFIG_RTE_LOG_HISTORY=256
 CONFIG_RTE_EAL_ALLOW_INV_SOCKET_ID=n
 CONFIG_RTE_EAL_ALWAYS_PANIC_ON_ERROR=n
 
Quoted 8 lines

config/common_bsdapp

Quoted 6 lines
config/common_bsdapp +2 -0
 #
+# Log level use: RTE_LOG_XXX
+#   XXX = NOOP, EMERG, ALERT, CRIT, ERR, WARNING, NOTICE, INFO or

DEBUG

config/common_bsdapp +2 -0
+#   Look in rte_log.h for others if any.
+#

I think this comment is useless.

Quoted 10 lines

I do not think the comment is useless as some may not understand what values the Log level can be set too in the future. Not commenting the change would be a problem IMO. This is also why the line was moved.

Quoted 7 lines
Quoted 2 lines

+CONFIG_RTE_LOG_LEVEL=RTE_LOG_DEBUG

Yes, easier to read.
Please do not move line without good reason. It was more logic to see it along
with LOG_HISTORY.

Maybe moving LOG_HISTORY with LOG_LEVEL would have been a better option.

Quoted 58 lines

Moving the line was for the comment and now it is a enum value instead of a magic number. Magic numbers are bad right? Adding a comment to help the user set this value is always reasonable IMO unless the comment is not correct, is this the case?

Quoted 16 lines

lib/librte_eal/common/eal_common_log.c static struct log_history_list log_history; · line 87

Quoted 11 lines
lib/librte_eal/common/eal_common_log.c +1 -1
@@ -82,7 +82,7 @@ static struct log_history_list log_history;
 /* global log structure */
 struct rte_logs rte_logs = {
 	.type = ~0,
-	.level = RTE_LOG_DEBUG,
+	.level = RTE_LOG_LEVEL,
 	.file = NULL,
 };

OK, more consistent.
It was set to RTE_LOG_LEVEL later anyway. (this comment would be useful in the commit message)

Quoted 13 lines

lib/librte_eal/common/eal_common_log.c static struct log_history_list log_history;

Quoted 11 lines
lib/librte_eal/common/eal_common_log.c +2 -8
 /* Can't use 0, as it gives compiler warnings */
-#define RTE_LOG_EMERG    1U  /**< System is unusable.               */
-#define RTE_LOG_ALERT    2U  /**< Action must be taken immediately. */
-#define RTE_LOG_CRIT     3U  /**< Critical conditions.              */
-#define RTE_LOG_ERR      4U  /**< Error conditions.                 */
-#define RTE_LOG_WARNING  5U  /**< Warning conditions.               */
-#define RTE_LOG_NOTICE   6U  /**< Normal but significant condition. */
-#define RTE_LOG_INFO     7U  /**< Informational.                    */
-#define RTE_LOG_DEBUG    8U  /**< Debug-level messages.             */
+enum {
+	RTE_LOG_NOOP = 0,   /**< Noop not used (zero entry)        */

NOOP is useless: EMERG may be = 1

Does it really matter if I used RTE_LOG_NOOP, just to make sure someone did not try to use zero here. Instead of setting the RTE_LOG_EMERG=1, I can change it to be the way you suggest, but I think it does not hurt anything does it?

Quoted 12 lines

lib/librte_eal/common/eal_common_log.c

Quoted 10 lines
lib/librte_eal/common/eal_common_log.c +9 -0
+	RTE_LOG_EMERG,      /**< System is unusable.               */
+	RTE_LOG_ALERT,      /**< Action must be taken immediately. */
+	RTE_LOG_CRIT,       /**< Critical conditions.              */
+	RTE_LOG_ERR,        /**< Error conditions.                 */
+	RTE_LOG_WARNING,    /**< Warning conditions.               */
+	RTE_LOG_NOTICE,     /**< Normal but significant condition. */
+	RTE_LOG_INFO,       /**< Informational.                    */
+	RTE_LOG_DEBUG       /**< Debug-level messages.             */
+};

What is the benefit of this change?

The change is to use a enum in place of using magic numbers, plus you get the benefit of seeing the enum name in the debugger instead of a number. It makes the code more readable IMHO.

Quoted 2 lines
Quoted 11 lines

To me the code is fine and the only change would be the RTE_LOG_NOOP being remove and RTE_LOG_EMERG=1.

‹
Regards,
++Keith
Intel Corporation

—
Regards,
++Keith
Intel Corporation

#5 lore raw

Re: [PATCH] log:Change magic number on RTE_LOG_LEVEL to a define

In reply to Wiles, Keith

2015-08-02 19:10, Wiles, Keith:

Quoted 9 lines · Thomas Monjalon
Quoted 7 lines

2015-06-06 19:04, Keith Wiles:

config/common_bsdapp CONFIG_RTE_MAX_NUMA_NODES=8 · line 104

Quoted 4 lines
config/common_bsdapp +4 -0
+# Log level use: RTE_LOG_XXX
+#   XXX = NOOP, EMERG, ALERT, CRIT, ERR, WARNING, NOTICE, INFO or DEBUG
+#   Look in rte_log.h for others if any.
+#

I think this comment is useless.

Quoted 3 lines

I do not think the comment is useless as some may not understand what values the Log level can be set too in the future. Not commenting the change would be a problem IMO. This is also why the line was moved.

It is already documented in the API doc.
I agree having some comments in the config files would be convenient but:
- this one is 3 lines long
- currently comments are only used to separate sections
Maybe you can do a oneline:
# Minimum log level compiled: DEBUG, INFO, NOTICE, WARNING or ERR
I think it is important to tell it is a minimum log level, i.e. compiled logs. And probably it is not needed to suggest a minimum level higher than ERR.

Quoted 9 lines
Quoted 4 lines

lib/librte_eal/common/include/rte_log.h extern struct rte_logs rte_logs; · line 93

Quoted 2 lines
lib/librte_eal/common/include/rte_log.h +2 -0
+enum {
+	RTE_LOG_NOOP = 0,   /**< Noop not used (zero entry)        */

NOOP is useless: EMERG may be = 1

Does it really matter if I used RTE_LOG_NOOP, just to make sure someone did not try to use zero here. Instead of setting the RTE_LOG_EMERG=1, I can change it to be the way you suggest, but I think it does not hurt anything does it?

We avoid adding code without real use which could cause confusion.

Quoted 12 lines
Quoted 11 lines

lib/librte_eal/common/include/rte_log.h extern struct rte_logs rte_logs; · line 102

Quoted 9 lines
lib/librte_eal/common/include/rte_log.h +9 -0
+	RTE_LOG_EMERG,      /**< System is unusable.               */
+	RTE_LOG_ALERT,      /**< Action must be taken immediately. */
+	RTE_LOG_CRIT,       /**< Critical conditions.              */
+	RTE_LOG_ERR,        /**< Error conditions.                 */
+	RTE_LOG_WARNING,    /**< Warning conditions.               */
+	RTE_LOG_NOTICE,     /**< Normal but significant condition. */
+	RTE_LOG_INFO,       /**< Informational.                    */
+	RTE_LOG_DEBUG       /**< Debug-level messages.             */
+};

What is the benefit of this change?

Quoted 3 lines

The change is to use a enum in place of using magic numbers, plus you get the benefit of seeing the enum name in the debugger instead of a number. It makes the code more readable IMHO.

OK so a comment in the commit message could give the debugger justification.

#6 lore raw

Re: [PATCH] log:Change magic number on RTE_LOG_LEVEL to a define

Quoted 16 lines · Thomas Monjalon

2015-08-02 19:10, Wiles, Keith:

Quoted 6 lines
Quoted 3 lines · Thomas Monjalon

2015-06-06 19:04, Keith Wiles:

Review

Quoted 2 lines
(quoted diff) +2 -0
+# Log level use: RTE_LOG_XXX
+#   XXX = NOOP, EMERG, ALERT, CRIT, ERR, WARNING, NOTICE, INFO or

DEBUG

Quoted 8 lines
Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+#   Look in rte_log.h for others if any.
+#

I think this comment is useless.

I do not think the comment is useless as some may not understand what values the Log level can be set too in the future. Not commenting the change would be a problem IMO. This is also why the line was moved.

Quoted 9 lines

It is already documented in the API doc.
I agree having some comments in the config files would be convenient but:
- this one is 3 lines long
- currently comments are only used to separate sections
Maybe you can do a oneline:
# Minimum log level compiled: DEBUG, INFO, NOTICE, WARNING or ERR
I think it is important to tell it is a minimum log level, i.e. compiled logs.
And probably it is not needed to suggest a minimum level higher than ERR.

I will reduce the comment to one line, should I move the LOG_HISTORY down to under LOG_LEVEL?

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

lib/librte_eal/common/include/rte_log.h extern struct rte_logs rte_logs; · line 93

Quoted 3 lines
lib/librte_eal/common/include/rte_log.h +2 -0
+enum {
+	RTE_LOG_NOOP = 0,   /**< Noop not used (zero entry)        */

NOOP is useless: EMERG may be = 1

Quoted 6 lines
Quoted 4 lines

Does it really matter if I used RTE_LOG_NOOP, just to make sure someone did not try to use zero here. Instead of setting the RTE_LOG_EMERG=1, I can change it to be the way you suggest, but I think it does not hurt anything does it?

We avoid adding code without real use which could cause confusion.

I will remove NOOP and set EMERG=1.

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines

lib/librte_eal/common/include/rte_log.h extern struct rte_logs rte_logs; · line 102

Quoted 10 lines
lib/librte_eal/common/include/rte_log.h +9 -0
+	RTE_LOG_EMERG,      /**< System is unusable.               */
+	RTE_LOG_ALERT,      /**< Action must be taken immediately. */
+	RTE_LOG_CRIT,       /**< Critical conditions.              */
+	RTE_LOG_ERR,        /**< Error conditions.                 */
+	RTE_LOG_WARNING,    /**< Warning conditions.               */
+	RTE_LOG_NOTICE,     /**< Normal but significant condition. */
+	RTE_LOG_INFO,       /**< Informational.                    */
+	RTE_LOG_DEBUG       /**< Debug-level messages.             */
+};

What is the benefit of this change?

Quoted 7 lines
Quoted 4 lines

The change is to use a enum in place of using magic numbers, plus you get
the benefit of seeing the enum name in the debugger instead of a number. It makes the code more readable IMHO.

OK so a comment in the commit message could give the debugger justification.

OK will add the debugger comment to the commit log.

Quoted 2 lines

‹
Regards,
++Keith
Intel Corporation

#7 lore raw

Re: [PATCH] log:Change magic number on RTE_LOG_LEVEL to a define

2015-08-02 20:58, Wiles, Keith:

Quoted 28 lines · Thomas Monjalon
Quoted 17 lines

2015-08-02 19:10, Wiles, Keith:

Quoted 6 lines
Quoted 3 lines · Thomas Monjalon

2015-06-06 19:04, Keith Wiles:

Review

Quoted 2 lines
(quoted diff) +2 -0
+# Log level use: RTE_LOG_XXX
+#   XXX = NOOP, EMERG, ALERT, CRIT, ERR, WARNING, NOTICE, INFO or

DEBUG

Quoted 8 lines
Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+#   Look in rte_log.h for others if any.
+#

I think this comment is useless.

I do not think the comment is useless as some may not understand what values the Log level can be set too in the future. Not commenting the change would be a problem IMO. This is also why the line was moved.

Quoted 9 lines

It is already documented in the API doc.
I agree having some comments in the config files would be convenient but:
- this one is 3 lines long
- currently comments are only used to separate sections
Maybe you can do a oneline:
# Minimum log level compiled: DEBUG, INFO, NOTICE, WARNING or ERR
I think it is important to tell it is a minimum log level, i.e. compiled logs.
And probably it is not needed to suggest a minimum level higher than ERR.

Quoted 2 lines

I will reduce the comment to one line, should I move the LOG_HISTORY down to under LOG_LEVEL?

Yes please.

Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
Quoted 11 lines

lib/librte_eal/common/include/rte_log.h extern struct rte_logs rte_logs; · line 102

Quoted 9 lines
lib/librte_eal/common/include/rte_log.h +9 -0
+	RTE_LOG_EMERG,      /**< System is unusable.               */
+	RTE_LOG_ALERT,      /**< Action must be taken immediately. */
+	RTE_LOG_CRIT,       /**< Critical conditions.              */
+	RTE_LOG_ERR,        /**< Error conditions.                 */
+	RTE_LOG_WARNING,    /**< Warning conditions.               */
+	RTE_LOG_NOTICE,     /**< Normal but significant condition. */
+	RTE_LOG_INFO,       /**< Informational.                    */
+	RTE_LOG_DEBUG       /**< Debug-level messages.             */
+};

What is the benefit of this change?

The change is to use a enum in place of using magic numbers, plus you get
the benefit of seeing the enum name in the debugger instead of a number. It makes the code more readable IMHO.

Quoted 4 lines
Quoted 2 lines

OK so a comment in the commit message could give the debugger justification.

OK will add the debugger comment to the commit log.

Thanks
Please also explain that rte_logs was set after options parsing, defaulting to RTE_LOG_LEVEL, and it is now initialized at RTE_LOG_LEVEL without behavioral change.

#8 lore raw

PATCH v2 1/1 log:Change magic number on RTE_LOG_LEVEL to an enum name

In reply to Keith Wiles

Config files used RTE_LOG_LEVEL=8 to set log level to DEBUG. Using a the RTE_LOG_XXXX is easier to maintain.

Converted the RTE_LOG_XXXX define into a enum of values with the same names to reduce maintaining the define values.

The change is to use an enum in place of a magic number, plus we get the benefit of seeing the enum name in the debugger instead of a number.

The rte_logs was set after options parsing, defaulting to RTE_LOG_LEVEL, and it is now initialized at RTE_LOG_LEVEL without behavioral change.

---
 config/common_bsdapp                    |  6 ++++--
 config/common_linuxapp                  |  6 ++++--
 lib/librte_eal/common/eal_common_log.c  |  4 ++--
 lib/librte_eal/common/include/rte_log.h | 18 ++++++++++--------
 4 files changed, 20 insertions(+), 14 deletions(-)
config/common_bsdapp +4 -2
index 2c6eb40..b2e9462 100644
@@ -102,12 +102,14 @@ CONFIG_RTE_MAX_NUMA_NODES=8
 CONFIG_RTE_MAX_MEMSEG=256
 CONFIG_RTE_MAX_MEMZONE=2560
 CONFIG_RTE_MAX_TAILQ=32
-CONFIG_RTE_LOG_LEVEL=8
-CONFIG_RTE_LOG_HISTORY=256
 CONFIG_RTE_EAL_ALLOW_INV_SOCKET_ID=n
 CONFIG_RTE_EAL_ALWAYS_PANIC_ON_ERROR=n
 CONFIG_RTE_MALLOC_DEBUG=n
 
+# RTE_LOG_XXX = DEBUG, INFO, NOTICE, WARNING or ERR
+CONFIG_RTE_LOG_LEVEL=RTE_LOG_DEBUG
+CONFIG_RTE_LOG_HISTORY=256
+
 #
 # FreeBSD contiguous memory driver settings
 #
config/common_linuxapp +4 -2
index bda9a63..eb0f659 100644
@@ -102,8 +102,6 @@ CONFIG_RTE_MAX_NUMA_NODES=8
 CONFIG_RTE_MAX_MEMSEG=256
 CONFIG_RTE_MAX_MEMZONE=2560
 CONFIG_RTE_MAX_TAILQ=32
-CONFIG_RTE_LOG_LEVEL=8
-CONFIG_RTE_LOG_HISTORY=256
 CONFIG_RTE_LIBEAL_USE_HPET=n
 CONFIG_RTE_EAL_ALLOW_INV_SOCKET_ID=n
 CONFIG_RTE_EAL_ALWAYS_PANIC_ON_ERROR=n
@@ -111,6 +109,10 @@ CONFIG_RTE_EAL_IGB_UIO=y
 CONFIG_RTE_EAL_VFIO=y
 CONFIG_RTE_MALLOC_DEBUG=n
 
+# RTE_LOG_XXX = DEBUG, INFO, NOTICE, WARNING or ERR
+CONFIG_RTE_LOG_LEVEL=RTE_LOG_DEBUG
+CONFIG_RTE_LOG_HISTORY=256
+
 #
 # Special configurations in PCI Config Space for high performance
 #
lib/librte_eal/common/eal_common_log.c +2 -2
index 1ae8de7..6ed6743 100644
@@ -82,7 +82,7 @@ static struct log_history_list log_history;
 /* global log structure */
 struct rte_logs rte_logs = {
 	.type = ~0,
-	.level = RTE_LOG_DEBUG,
+	.level = RTE_LOG_LEVEL,
 	.file = NULL,
 };
 
@@ -93,7 +93,7 @@ static int history_enabled = 1;
 
 /**
  * This global structure stores some informations about the message
- * that is currently beeing processed by one lcore
+ * that is currently being processed by one lcore
  */
 struct log_cur_msg {
 	uint32_t loglevel; /**< log level - see rte_log.h */
lib/librte_eal/common/include/rte_log.h +10 -8
index 24a55cc..be75a45 100644
@@ -89,14 +89,16 @@ extern struct rte_logs rte_logs;
 #define RTE_LOGTYPE_USER8   0x80000000 /**< User-defined log type 8. */
 
 /* Can't use 0, as it gives compiler warnings */
-#define RTE_LOG_EMERG    1U  /**< System is unusable.               */
-#define RTE_LOG_ALERT    2U  /**< Action must be taken immediately. */
-#define RTE_LOG_CRIT     3U  /**< Critical conditions.              */
-#define RTE_LOG_ERR      4U  /**< Error conditions.                 */
-#define RTE_LOG_WARNING  5U  /**< Warning conditions.               */
-#define RTE_LOG_NOTICE   6U  /**< Normal but significant condition. */
-#define RTE_LOG_INFO     7U  /**< Informational.                    */
-#define RTE_LOG_DEBUG    8U  /**< Debug-level messages.             */
+enum {
+	RTE_LOG_EMERG=1,    /**< System is unusable.               */
+	RTE_LOG_ALERT,      /**< Action must be taken immediately. */
+	RTE_LOG_CRIT,       /**< Critical conditions.              */
+	RTE_LOG_ERR,        /**< Error conditions.                 */
+	RTE_LOG_WARNING,    /**< Warning conditions.               */
+	RTE_LOG_NOTICE,     /**< Normal but significant condition. */
+	RTE_LOG_INFO,       /**< Informational.                    */
+	RTE_LOG_DEBUG       /**< Debug-level messages.             */
+};
 
 /** The default log stream. */
 extern FILE *eal_default_log_stream;
Signature · 1 line
2.3.0
#9 lore raw

Re: [PATCH v2] log:Change magic number on RTE_LOG_LEVEL to an enum name

Quoted 106 lines · On Sun, 2 Aug 2015 16:40:24 -0500 Keith Wiles <[email protected]> wrote:

Config files used RTE_LOG_LEVEL=8 to set log level to DEBUG. Using a the RTE_LOG_XXXX is easier to maintain.

Converted the RTE_LOG_XXXX define into a enum of values with the same names to reduce maintaining the define values.

The change is to use an enum in place of a magic number, plus we get the benefit of seeing the enum name in the debugger instead of a number.

The rte_logs was set after options parsing, defaulting to RTE_LOG_LEVEL, and it is now initialized at RTE_LOG_LEVEL without behavioral change.

---
 config/common_bsdapp                    |  6 ++++--
 config/common_linuxapp                  |  6 ++++--
 lib/librte_eal/common/eal_common_log.c  |  4 ++--
 lib/librte_eal/common/include/rte_log.h | 18 ++++++++++--------
 4 files changed, 20 insertions(+), 14 deletions(-)
config/common_bsdapp +4 -2
index 2c6eb40..b2e9462 100644
@@ -102,12 +102,14 @@ CONFIG_RTE_MAX_NUMA_NODES=8
 CONFIG_RTE_MAX_MEMSEG=256
 CONFIG_RTE_MAX_MEMZONE=2560
 CONFIG_RTE_MAX_TAILQ=32
-CONFIG_RTE_LOG_LEVEL=8
-CONFIG_RTE_LOG_HISTORY=256
 CONFIG_RTE_EAL_ALLOW_INV_SOCKET_ID=n
 CONFIG_RTE_EAL_ALWAYS_PANIC_ON_ERROR=n
 CONFIG_RTE_MALLOC_DEBUG=n
 
+# RTE_LOG_XXX = DEBUG, INFO, NOTICE, WARNING or ERR
+CONFIG_RTE_LOG_LEVEL=RTE_LOG_DEBUG
+CONFIG_RTE_LOG_HISTORY=256
+
 #
 # FreeBSD contiguous memory driver settings
 #
config/common_linuxapp +4 -2
index bda9a63..eb0f659 100644
@@ -102,8 +102,6 @@ CONFIG_RTE_MAX_NUMA_NODES=8
 CONFIG_RTE_MAX_MEMSEG=256
 CONFIG_RTE_MAX_MEMZONE=2560
 CONFIG_RTE_MAX_TAILQ=32
-CONFIG_RTE_LOG_LEVEL=8
-CONFIG_RTE_LOG_HISTORY=256
 CONFIG_RTE_LIBEAL_USE_HPET=n
 CONFIG_RTE_EAL_ALLOW_INV_SOCKET_ID=n
 CONFIG_RTE_EAL_ALWAYS_PANIC_ON_ERROR=n
@@ -111,6 +109,10 @@ CONFIG_RTE_EAL_IGB_UIO=y
 CONFIG_RTE_EAL_VFIO=y
 CONFIG_RTE_MALLOC_DEBUG=n
 
+# RTE_LOG_XXX = DEBUG, INFO, NOTICE, WARNING or ERR
+CONFIG_RTE_LOG_LEVEL=RTE_LOG_DEBUG
+CONFIG_RTE_LOG_HISTORY=256
+
 #
 # Special configurations in PCI Config Space for high performance
 #
lib/librte_eal/common/eal_common_log.c +2 -2
index 1ae8de7..6ed6743 100644
@@ -82,7 +82,7 @@ static struct log_history_list log_history;
 /* global log structure */
 struct rte_logs rte_logs = {
 	.type = ~0,
-	.level = RTE_LOG_DEBUG,
+	.level = RTE_LOG_LEVEL,
 	.file = NULL,
 };
 
@@ -93,7 +93,7 @@ static int history_enabled = 1;
 
 /**
  * This global structure stores some informations about the message
- * that is currently beeing processed by one lcore
+ * that is currently being processed by one lcore
  */
 struct log_cur_msg {
 	uint32_t loglevel; /**< log level - see rte_log.h */
lib/librte_eal/common/include/rte_log.h +1 -8
index 24a55cc..be75a45 100644
@@ -89,14 +89,16 @@ extern struct rte_logs rte_logs;
 #define RTE_LOGTYPE_USER8   0x80000000 /**< User-defined log type 8. */
 
 /* Can't use 0, as it gives compiler warnings */
-#define RTE_LOG_EMERG    1U  /**< System is unusable.               */
-#define RTE_LOG_ALERT    2U  /**< Action must be taken immediately. */
-#define RTE_LOG_CRIT     3U  /**< Critical conditions.              */
-#define RTE_LOG_ERR      4U  /**< Error conditions.                 */
-#define RTE_LOG_WARNING  5U  /**< Warning conditions.               */
-#define RTE_LOG_NOTICE   6U  /**< Normal but significant condition. */
-#define RTE_LOG_INFO     7U  /**< Informational.                    */
-#define RTE_LOG_DEBUG    8U  /**< Debug-level messages.             */
+enum {

lib/librte_eal/common/include/rte_log.h extern struct rte_logs rte_logs; · line 102

Quoted 10 lines
lib/librte_eal/common/include/rte_log.h +9 -0
+	RTE_LOG_EMERG=1,    /**< System is unusable.               */
+	RTE_LOG_ALERT,      /**< Action must be taken immediately. */
+	RTE_LOG_CRIT,       /**< Critical conditions.              */
+	RTE_LOG_ERR,        /**< Error conditions.                 */
+	RTE_LOG_WARNING,    /**< Warning conditions.               */
+	RTE_LOG_NOTICE,     /**< Normal but significant condition. */
+	RTE_LOG_INFO,       /**< Informational.                    */
+	RTE_LOG_DEBUG       /**< Debug-level messages.             */
+};
 

This is technically a source API change. There are cases where you could break build of existing code that was expecting #define's (but I doubt anyone would notice0.