From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id B351843D55;
	Wed, 27 Mar 2024 17:48:39 +0100 (CET)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 1716E42D6A;
	Wed, 27 Mar 2024 17:47:50 +0100 (CET)
Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com
 [209.85.210.169])
 by mails.dpdk.org (Postfix) with ESMTP id 239074161A
 for <dev@dpdk.org>; Wed, 27 Mar 2024 17:47:44 +0100 (CET)
Received: by mail-pf1-f169.google.com with SMTP id
 d2e1a72fcca58-6e6ee9e3cffso48201b3a.1
 for <dev@dpdk.org>; Wed, 27 Mar 2024 09:47:44 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711558063;
 x=1712162863; darn=dpdk.org; 
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:from:to:cc:subject:date
 :message-id:reply-to;
 bh=lymWiavwrFvAchUcPNDs8TtaMkMHgQ+bVt4jwb/wnmA=;
 b=dgcqLViZmthEBD4wT2aKzsW/4ECJrmnROjo9uTdaRcBFSQwqTdUVTiR0oIQb22wkUW
 W3xtoTXhJXZz78t/3zYz8AaU/kyMaIRlvF4kC531511QpMmAObhXHZjZJVsM5VgZz0Na
 puxcivG9dAIGBdL1gpbhS+sczuiuaplaLwm7DVZgMXK3NgFSs1Pp5jJOtPxorwmXa5VY
 1zbMOTQ+5IdKoYCU0FG43T+7EPWBuARvITjHccxCToQcQv+jgZr0RW0KWAY56he6WpgN
 yeuO4HFCVOn2zAqzqHld//cdiEL36lk7doVd1GaVxdZvTj0yuZZodF8WFrSFhkb3VHGx
 eSYA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1711558063; x=1712162863;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
 :subject:date:message-id:reply-to;
 bh=lymWiavwrFvAchUcPNDs8TtaMkMHgQ+bVt4jwb/wnmA=;
 b=XNlkVIrQlwsvTEULiNpNCaYsl359t0tjpzNjks81EHcd0FbEOqR3C4RR4P55GYhV7y
 FLm+MQb6lKoeR4ZHNaxgvDUO5t2yUkijc1koCalS7H1qAJbPmz8QNxXzg5GKXUD41xyC
 xC/LaygnA2RjRl2KUD8deviNb3LCBTm61TMgfJPlo7qBLKHi1k26KOhuq74thKLnKJpX
 GEtucP6ShvhKbvHssAjyWR99/bBN70lRXwwWfb+Q5XCtI6xWIuA9AkapU/hnnESKnQx8
 MYo0MWWjnu4qL8OJn3LhRDzme9S0PrnZILgyZ9ErDOyLCKFecGw4jhjCF8L8DV0O9trj
 ZjCQ==
X-Gm-Message-State: AOJu0YxlmtQ1R/sF0HW9r5YSUJqWBBYB9pCUiX1AmB+z94mNhVOtb+B0
 J0U1WaxvNIO1WUu3EAGZpTO6UF3AR57MGnWyu/T6uQZORzFaHPO9udWfpMuw6Jxb9lqck4Sn4AL
 g
X-Google-Smtp-Source: AGHT+IGFodsW2Z8/BOC001/j6mX3QLAKxNwoFNDY/m856j64lTEmT3KKh9K/ZbI0OkoZ/hpXhglwVg==
X-Received: by 2002:a05:6a00:92a8:b0:6e7:6bc4:ef8c with SMTP id
 jw40-20020a056a0092a800b006e76bc4ef8cmr241016pfb.3.1711558063281; 
 Wed, 27 Mar 2024 09:47:43 -0700 (PDT)
Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203])
 by smtp.gmail.com with ESMTPSA id
 a33-20020a056a0011e100b006e580678dfbsm5160873pfu.193.2024.03.27.09.47.42
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Wed, 27 Mar 2024 09:47:42 -0700 (PDT)
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
 Bruce Richardson <bruce.richardson@intel.com>,
 Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>,
 Tyler Retzlaff <roretzla@linux.microsoft.com>,
 Pallavi Kadam <pallavi.kadam@intel.com>
Subject: [PATCH v16 09/15] eal: initialize log before everything else
Date: Wed, 27 Mar 2024 09:45:27 -0700
Message-ID: <20240327164726.68732-10-stephen@networkplumber.org>
X-Mailer: git-send-email 2.43.0
In-Reply-To: <20240327164726.68732-1-stephen@networkplumber.org>
References: <20200814173441.23086-1-stephen@networkplumber.org>
 <20240327164726.68732-1-stephen@networkplumber.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org

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

diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c
index 6552f9c138..55ff27a4da 100644
--- a/lib/eal/freebsd/eal.c
+++ b/lib/eal/freebsd/eal.c
@@ -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.");
@@ -565,9 +574,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;
diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c
index 3d0c34063e..b9a0fb1742 100644
--- a/lib/eal/linux/eal.c
+++ b/lib/eal/linux/eal.c
@@ -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.");
@@ -952,9 +961,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);
 
@@ -1106,13 +1112,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");
diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c
index 14e498a643..e59aba954e 100644
--- a/lib/eal/windows/eal.c
+++ b/lib/eal/windows/eal.c
@@ -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.");
diff --git a/lib/log/log_freebsd.c b/lib/log/log_freebsd.c
index 953e371bee..33a0925c43 100644
--- a/lib/log/log_freebsd.c
+++ b/lib/log/log_freebsd.c
@@ -5,8 +5,7 @@
 #include <rte_common.h>
 #include "log_internal.h"
 
-int
+void
 eal_log_init(__rte_unused const char *id)
 {
-	return 0;
 }
diff --git a/lib/log/log_internal.h b/lib/log/log_internal.h
index cb15cdff08..d5fabd7ef7 100644
--- a/lib/log/log_internal.h
+++ b/lib/log/log_internal.h
@@ -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.
diff --git a/lib/log/log_linux.c b/lib/log/log_linux.c
index 47aa074da2..6d7dc8f3ab 100644
--- a/lib/log/log_linux.c
+++ b/lib/log/log_linux.c
@@ -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);
 }
diff --git a/lib/log/log_windows.c b/lib/log/log_windows.c
index a3a756351d..d7c30e4cfa 100644
--- a/lib/log/log_windows.c
+++ b/lib/log/log_windows.c
@@ -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;
 }
-- 
2.43.0