From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4F26E45BB9; Thu, 24 Oct 2024 05:21:34 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1FB454338A; Thu, 24 Oct 2024 05:20:55 +0200 (CEST) Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by mails.dpdk.org (Postfix) with ESMTP id EB5B64336F for ; Thu, 24 Oct 2024 05:20:44 +0200 (CEST) Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-71e3fce4a60so324256b3a.0 for ; Wed, 23 Oct 2024 20:20:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1729740044; x=1730344844; 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=z+2t1/jXDBYTsGZDsO8iUjDDpsBbo38RX6zfL+xpIgQ=; b=bLj/5ez3hqTK4BnYKkZVgKmVmUNcHr4kHHiCdZ6HVifzyVqNoX5xnTPdtnO1yWGrKc CNvM49aEPGBapYpKb+mU+dAlpH7joy48pUiQjjkODWnhXGJV5LStYVYwJbX3titvZVzR Fp9XSfSTw0fxicYoyaV1ysuTjp5BEsd0pGdxr5TPqxhQFIzaTFj3I9Mi90yQX2MVn+z0 n3cB6COEjVgDxziFeewCakFZDrBxoXHSize6t0dLg6+9UoEHIF+V7xDQ7LK1lSKV21JY MRl46tlWP9L3g8a2mXL4FfAQgWDMDS2BfLN3M+ST8xynymtyXuHlzxWGBN0MxF9m9cOM /jww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729740044; x=1730344844; 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=z+2t1/jXDBYTsGZDsO8iUjDDpsBbo38RX6zfL+xpIgQ=; b=eCBgKwhoJSjxOz82SCHDpVoss5sIROHNm1/Tmd1KHGHSIgvyOTUP/fFxRa7/Lk2Cwx csUg4ELUy+HZckwubEC30xPspDqeQZtkpo3/9Kfn7Ah2bvbPHx9Ivzt374MeyrCOdMiq crQfN7qeMudFmgHHCFo+pivEX7X8LAdClaQahFN4ulpx7Sl++e5UuYGrNN8tOewxVR32 Cp0wfioJvN6p9OkkDOd0jOpEGuyjTZfWH/iq8DnitJpjWSOZrWYonCTvmekUtnuu18SB +USTBEHMLJAbWBk1Ddf9gw38V9OXYZXASCvnNATuxc7Vk12CA7J3Gp4btbRctqc3SIXU 2awA== X-Gm-Message-State: AOJu0YyspcVwU3MeTyUZ3L4Q8XKtKeimgMYSggmV67L80N7ridH5f6Sr 5zxow4zfix4fk7G4lGlTdO6Py6p9CwwOuFjwDYjTzXi4NV9mNVucrbrUBNBhlw7U5LT6Mzyg0RU m X-Google-Smtp-Source: AGHT+IEXhk4dKBfPwDJHOd1n3RSISNLVqJS7bz0qXNES6G1VuajjK9vmE9kdAy5Gx4p6bnSNzHBMxg== X-Received: by 2002:a05:6a00:1804:b0:71e:792b:4517 with SMTP id d2e1a72fcca58-72045e78207mr619661b3a.14.1729740044032; Wed, 23 Oct 2024 20:20:44 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71ec1324d41sm6999533b3a.57.2024.10.23.20.20.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 20:20:43 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff , =?UTF-8?q?Morten=20Br=C3=B8rup?= , Bruce Richardson , Chengwen Feng , Dmitry Kozlyuk Subject: [PATCH v27 08/14] eal: initialize log before everything else Date: Wed, 23 Oct 2024 20:18:46 -0700 Message-ID: <20241024032026.415122-9-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241024032026.415122-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20241024032026.415122-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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 Acked-by: Tyler Retzlaff Acked-by: Morten Brørup Acked-by: Bruce Richardson Acked-by: Chengwen Feng --- 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_syslog.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 a609d40ee0..118c1f593b 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."); @@ -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; diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index 9a0a1cf211..62d3d281c4 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -926,6 +926,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."); @@ -949,9 +958,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); @@ -1103,13 +1109,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_vfio_enable("vfio")) { rte_eal_init_alert("Cannot init VFIO"); diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c index cd8420a82c..33f044d7cc 100644 --- a/lib/eal/windows/eal.c +++ b/lib/eal/windows/eal.c @@ -249,9 +249,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 #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_syslog.c b/lib/log/log_syslog.c index c1f25d2686..ce34fa4f22 100644 --- a/lib/log/log_syslog.c +++ b/lib/log/log_syslog.c @@ -81,18 +81,16 @@ static cookie_io_functions_t log_syslog_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+", log_syslog_func); - if (log_stream == NULL) - return -1; - openlog(id, LOG_NDELAY | LOG_PID | LOG_PERROR, log_facility); - eal_log_set_default(log_stream); - - return 0; + log_stream = fopencookie(NULL, "w+", log_syslog_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.45.2