In order for all log messages (including CPU mismatch) to
come out through the logging library, it must be initialized
as early in rte_eal_init() as possible on all platforms.
Where it was done before was likely historical based on
the support of non-OS isolated CPU's which required a shared
memory buffer; that support was dropped before DPDK was
publicly released.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
lib/eal/freebsd/eal.c | 12 +++++++++---
lib/eal/linux/eal.c | 19 +++++++++----------
lib/eal/windows/eal.c | 8 ++++++--
lib/log/log_freebsd.c | 3 +--
lib/log/log_internal.h | 2 +-
lib/log/log_linux.c | 14 ++++++--------
lib/log/log_windows.c | 4 +---
7 files changed, 33 insertions(+), 29 deletions(-)
@@ -52,6 +52,7 @@
#include "eal_options.h"
#include "eal_memcfg.h"
#include "eal_trace.h"
+#include "log_internal.h"
#define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL)
@@ -546,6 +547,14 @@ rte_eal_init(int argc, char **argv)
bool has_phys_addr;
enum rte_iova_mode iova_mode;
+ /* setup log as early as possible */
+ if (eal_log_level_parse(argc, argv) < 0) {
+ rte_eal_init_alert("invalid log arguments.");
+ rte_errno = EINVAL;
+ return -1;
+ }
+ eal_log_init(getprogname());
+
/* checks if the machine is adequate */
if (!rte_cpu_is_supported()) {
rte_eal_init_alert("unsupported cpu type.");
@@ -572,9 +581,6 @@ rte_eal_init(int argc, char **argv)
/* clone argv to report out later in telemetry */
eal_save_args(argc, argv);
- /* set log level as early as possible */
- eal_log_level_parse(argc, argv);
-
if (rte_eal_cpu_init() < 0) {
rte_eal_init_alert("Cannot detect lcores.");
rte_errno = ENOTSUP;
@@ -936,6 +936,15 @@ rte_eal_init(int argc, char **argv)
struct internal_config *internal_conf =
eal_get_internal_configuration();
+ /* setup log as early as possible */
+ if (eal_log_level_parse(argc, argv) < 0) {
+ rte_eal_init_alert("invalid log arguments.");
+ rte_errno = EINVAL;
+ return -1;
+ }
+
+ eal_log_init(program_invocation_short_name);
+
/* checks if the machine is adequate */
if (!rte_cpu_is_supported()) {
rte_eal_init_alert("unsupported cpu type.");
@@ -959,9 +968,6 @@ rte_eal_init(int argc, char **argv)
eal_reset_internal_config(internal_conf);
- /* set log level as early as possible */
- eal_log_level_parse(argc, argv);
-
/* clone argv to report out later in telemetry */
eal_save_args(argc, argv);
@@ -1113,13 +1119,6 @@ rte_eal_init(int argc, char **argv)
#endif
}
- if (eal_log_init(program_invocation_short_name) < 0) {
- rte_eal_init_alert("Cannot init logging.");
- rte_errno = ENOMEM;
- rte_atomic_store_explicit(&run_once, 0, rte_memory_order_relaxed);
- return -1;
- }
-
#ifdef VFIO_PRESENT
if (rte_eal_vfio_setup() < 0) {
rte_eal_init_alert("Cannot init VFIO");
@@ -250,9 +250,13 @@ rte_eal_init(int argc, char **argv)
char cpuset[RTE_CPU_AFFINITY_STR_LEN];
char thread_name[RTE_THREAD_NAME_SIZE];
- eal_log_init(NULL);
+ if (eal_log_level_parse(argc, argv) < 0) {
+ rte_eal_init_alert("invalid log arguments.");
+ rte_errno = EINVAL;
+ return -1;
+ }
- eal_log_level_parse(argc, argv);
+ eal_log_init(NULL);
if (eal_create_cpu_map() < 0) {
rte_eal_init_alert("Cannot discover CPU and NUMA.");
@@ -5,8 +5,7 @@
#include <rte_common.h>
#include "log_internal.h"
-int
+void
eal_log_init(__rte_unused const char *id)
{
- return 0;
}
@@ -14,7 +14,7 @@
* Initialize the default log stream.
*/
__rte_internal
-int eal_log_init(const char *id);
+void eal_log_init(const char *id);
/*
* Determine where log data is written when no call to rte_openlog_stream.
@@ -87,18 +87,16 @@ static cookie_io_functions_t console_log_func = {
* set the log to default function, called during eal init process,
* once memzones are available.
*/
-int
+void
eal_log_init(const char *id)
{
FILE *log_stream;
- log_stream = fopencookie(NULL, "w+", console_log_func);
- if (log_stream == NULL)
- return -1;
-
openlog(id, LOG_NDELAY | LOG_PID, log_facility);
- eal_log_set_default(log_stream);
-
- return 0;
+ log_stream = fopencookie(NULL, "w+", console_log_func);
+ if (log_stream != NULL)
+ eal_log_set_default(log_stream);
+ else
+ eal_log_set_default(stderr);
}
@@ -13,12 +13,10 @@ eal_log_syslog(const char *name __rte_unused)
}
/* set the log to default function, called during eal init process. */
-int
+void
eal_log_init(__rte_unused const char *id)
{
rte_openlog_stream(stderr);
eal_log_set_default(stderr);
-
- return 0;
}