From patchwork Mon Mar 18 22:02:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138472 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2175243CEE; Mon, 18 Mar 2024 23:04:51 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D9747409FA; Mon, 18 Mar 2024 23:04:46 +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 6F3DF40299 for ; Mon, 18 Mar 2024 23:04:45 +0100 (CET) Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-6e73e8bdea2so524622b3a.0 for ; Mon, 18 Mar 2024 15:04:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1710799484; x=1711404284; 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=va7MWJRuAR3nLxH5zGMYb78QbpeyFQrBUnnO1GsDymY=; b=S1YQQ8AInZZ53KKTDYVnQMYpPzb3eotNaf+s+N0oRt7kcTzfIjjOnYIeN7ggLT/TqF rfuWIEDoU5M3+9apqBIUGq5MtZs0b/axZLVFdsvyPeZ3QGSfAfnReEf1mVXmZlCz0ZCn r6ihYb235OE3SuINnyOUv1vsk3ZpRI2/tKqnfX7AaEMbI7/VIHuvX1L9/d9OkvTwHdFZ VX/1nuAqBNE71IJGexoaOoCwSSkImUpGXWxGslROCOx+PJPri2dL+Kn8k9hvZoYWnDdg c3S0UyDtIBzvHJfDTeMlHtimIgzCr6o9ctMEOwVbvTeAJJIkF6//VMAipoRSqJ4bRv6A TKQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710799484; x=1711404284; 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=va7MWJRuAR3nLxH5zGMYb78QbpeyFQrBUnnO1GsDymY=; b=OHdrj2Hf/A5DiEpFVtHkTWed0c1YrCAjGe0ytHH13QzwfnccI6xt2KfhBU3/4LgK1p fptvDM/PA3n1Cy4iz+PTEa6LbYEyx5FGYwdhfc1G4jLvlQx8zqPtg0DKLsxfd7VHG/Jr 5HYhLCKfXdBgyrQVtvcGftbIOIogtmH3jkstmibPIe/ZXoKV3wm/G7n9vBGnHYyMB+Zz G6w1dlb8svAgPXuZSvq333j443q6wZoeRvhFnqOyqF5PktrzNkRsLj3+WpbrzryMWPrw qsuVo/GnZabS0FiRumldHR2oc9JXgeNMNSnVWjXfmNYZkERppKfynAb3U6bwww+D8EzZ y+Zw== X-Gm-Message-State: AOJu0Yy0xbKSH8YEx1BGReEdkJyigEKTqlgUkXBwUFj7crKPTIBxMK55 7Yn+PQa6ZNZhg45/LT2WrTgm49vqTF61E0imn5wYI3H8m+oOugqXJOq6PUmhnrEoym8xKWyUnvo 8 X-Google-Smtp-Source: AGHT+IF2zsCHMi9Qk6XHY9BkJnCsMYmSICl6BWqM0hw5bLN5b+StcNy3c64kpwXLzNpcinXRB8+Ivw== X-Received: by 2002:a05:6a20:8f21:b0:1a3:6a53:edf with SMTP id b33-20020a056a208f2100b001a36a530edfmr2944571pzk.13.1710799484389; Mon, 18 Mar 2024 15:04:44 -0700 (PDT) Received: from hermes.local (204-195-123-141.wavecable.com. [204.195.123.141]) by smtp.gmail.com with ESMTPSA id y6-20020a637d06000000b005dc88b232a5sm7747140pgc.26.2024.03.18.15.04.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Mar 2024 15:04:43 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v9 1/5] log: unify logging code Date: Mon, 18 Mar 2024 15:02:57 -0700 Message-ID: <20240318220432.7486-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240318220432.7486-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240318220432.7486-1-stephen@networkplumber.org> MIME-Version: 1.0 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 FreeBSD and Linux logging code can use common code. This also fixes FreeBSD not using syslog. Signed-off-by: Stephen Hemminger --- doc/guides/linux_gsg/linux_eal_parameters.rst | 27 ------------------- doc/guides/prog_guide/log_lib.rst | 18 +++++++++++-- lib/eal/freebsd/eal.c | 8 ++++++ lib/log/log_freebsd.c | 12 --------- lib/log/{log_linux.c => log_unix.c} | 0 lib/log/meson.build | 12 ++++++--- 6 files changed, 32 insertions(+), 45 deletions(-) delete mode 100644 lib/log/log_freebsd.c rename lib/log/{log_linux.c => log_unix.c} (100%) diff --git a/doc/guides/linux_gsg/linux_eal_parameters.rst b/doc/guides/linux_gsg/linux_eal_parameters.rst index ea8f38139119..d86f94d8a85d 100644 --- a/doc/guides/linux_gsg/linux_eal_parameters.rst +++ b/doc/guides/linux_gsg/linux_eal_parameters.rst @@ -108,30 +108,3 @@ Memory-related options * ``--match-allocations`` Free hugepages back to system exactly as they were originally allocated. - -Other options -~~~~~~~~~~~~~ - -* ``--syslog `` - - Set syslog facility. Valid syslog facilities are:: - - auth - cron - daemon - ftp - kern - lpr - mail - news - syslog - user - uucp - local0 - local1 - local2 - local3 - local4 - local5 - local6 - local7 diff --git a/doc/guides/prog_guide/log_lib.rst b/doc/guides/prog_guide/log_lib.rst index ff9d1b54a2c8..aacb36c36ce0 100644 --- a/doc/guides/prog_guide/log_lib.rst +++ b/doc/guides/prog_guide/log_lib.rst @@ -5,8 +5,8 @@ Log Library =========== The DPDK Log library provides the logging functionality for other DPDK libraries and drivers. -By default, in a Linux application, logs are sent to syslog and also to the console. -On FreeBSD and Windows applications, logs are sent only to the console. +By default, in a Linux (or FreeBSD) application, logs are sent to syslog and also to the console. +In Windows applications, logs are sent only to the console. However, the log function can be overridden by the user to use a different logging mechanism. Log Levels @@ -29,6 +29,7 @@ will be emitted by the application to the log output. That level can be configured either by the application calling the relevant APIs from the logging library, or by the user passing the ``--log-level`` parameter to the EAL via the application. + Setting Global Log Level ~~~~~~~~~~~~~~~~~~~~~~~~ @@ -59,6 +60,19 @@ For example:: Within an application, the same result can be got using the ``rte_log_set_level_pattern()`` or ``rte_log_set_level_regex()`` APIs. + +Setting syslog facility +~~~~~~~~~~~~~~~~~~~~~~~ + +On Linux and FreeBSD, where syslog is used a ``facility`` argument can be +used to specify what type of program is logging. +The default facility is ``daemon`` but it can be overridden +by the ``--syslog`` EAL parameter. See ``syslog.3`` man page for full values. +For example:: + + /path/to/app --syslog local0 + + Using Logging APIs to Generate Log Messages ------------------------------------------- diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index bab77118e967..a57ee8406f0c 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -53,6 +53,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) @@ -760,6 +761,13 @@ rte_eal_init(int argc, char **argv) #endif } + if (eal_log_init(getprogname(), internal_conf->syslog_facility) < 0) { + rte_eal_init_alert("Cannot init logging."); + rte_errno = ENOMEM; + rte_atomic_store_explicit(&run_once, 0, rte_memory_order_relaxed); + return -1; + } + /* in secondary processes, memory init may allocate additional fbarrays * not present in primary processes, so to avoid any potential issues, * initialize memzones first. diff --git a/lib/log/log_freebsd.c b/lib/log/log_freebsd.c deleted file mode 100644 index 698d3c542337..000000000000 --- a/lib/log/log_freebsd.c +++ /dev/null @@ -1,12 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * Copyright(c) 2023 Intel Corporation - */ - -#include -#include "log_internal.h" - -int -eal_log_init(__rte_unused const char *id, __rte_unused int facility) -{ - return 0; -} diff --git a/lib/log/log_linux.c b/lib/log/log_unix.c similarity index 100% rename from lib/log/log_linux.c rename to lib/log/log_unix.c diff --git a/lib/log/meson.build b/lib/log/meson.build index 0d4319b36f77..60516a0b2a2d 100644 --- a/lib/log/meson.build +++ b/lib/log/meson.build @@ -2,8 +2,12 @@ # Copyright(c) 2023 Intel Corporation includes += global_inc -sources = files( - 'log.c', - 'log_' + exec_env + '.c', -) +sources = files('log.c') + +if is_windows + sources += files('log_windows.c') +else + sources += files('log_unix.c') +endif + headers = files('rte_log.h') From patchwork Mon Mar 18 22:02:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138473 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id C797C43CEE; Mon, 18 Mar 2024 23:04:57 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 110D540A6E; Mon, 18 Mar 2024 23:04:49 +0100 (CET) Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) by mails.dpdk.org (Postfix) with ESMTP id CABEC4069D for ; Mon, 18 Mar 2024 23:04:46 +0100 (CET) Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-6e6b6e000a4so3535286b3a.0 for ; Mon, 18 Mar 2024 15:04:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1710799486; x=1711404286; 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=JV9iooaRFKWJsG/qcC/BNXRXSAU9mzx1fb/qZlAxld4=; b=diV4L+/9R+l0f0afeBeu5oMGj+NA4lSGouAUhrT2DasxTc89VvaciJK4t7vQ80iTsP YUF0x0Vud8SHVDe2OLljjECq0VYn1OfSWLcZ2d+FH0gGOlQO6ZpxpTkjlBx3Ylvm7Vdz 0MT8GivwooepM6KrTnwOsD/N7GPM7QHfhApl4ad7f1xxY9bvSNMlstzcNpXtpVTXZujZ Db6YE+GliyjBBpJu1fj15Wm7xfkBaXDDSDbufWkWONcqVAShhY9J03dSPGTajRoEiyCp hv4oUpkCaC0FI+tqVu9BeazuHnsZeS++JrBdoIWDXvH0o9w42ChaMa0ve+p1ocTWDkU8 qyiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710799486; x=1711404286; 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=JV9iooaRFKWJsG/qcC/BNXRXSAU9mzx1fb/qZlAxld4=; b=NbDLUFuZC0vXhvE5+7nac71vqEjKZ3BWGttT4AjBmLybDZeMuM1E+O1up/UBKjtRbm JdHxu1i2/Jkh8Im2XX2o/dvHK/LAMk/f45k0QVx4iuVzpg+SZahTp3zQVbR4vbvSZ7WJ 72l7rLMhhPqYq52kk9abps6emptDFweNxOz7gJMdtSbY4X6j9bLYBLhhQcztNX7VhaJC 8cd3bnRsJM442ddtocz/2uuo5goXHe31fZZb0erkiAp1qoxEp5rITscMeB0YwuZcnQsu nQPTjDPIZT5j8xWOE332GM6XzXD9w7gnn5OtlRifm3eUqIqGCF+au39G0s+cdnkY8S/V Bzlw== X-Gm-Message-State: AOJu0YyGJAgyJxRKeM+HR474KOSzIQ8l5ixNjfragHxKA4ZuOmPsLPG3 eNoht33Zo9jiAObwZUdbIE+mDIKE/Q8cJRXWYCUEc4MsJh6UxRCexjWuam4NxZ5ProPxuMjPpZh 5 X-Google-Smtp-Source: AGHT+IEJjv/PtDpmCdTLks2JIDwyIQDRw8vrNn1gZiEDD8XmTp4/ZZUPRJIcwlpoBYPq9/ncIo44Kg== X-Received: by 2002:a05:6a21:3a82:b0:1a3:4e27:c8d1 with SMTP id zv2-20020a056a213a8200b001a34e27c8d1mr1303351pzb.25.1710799485963; Mon, 18 Mar 2024 15:04:45 -0700 (PDT) Received: from hermes.local (204-195-123-141.wavecable.com. [204.195.123.141]) by smtp.gmail.com with ESMTPSA id y6-20020a637d06000000b005dc88b232a5sm7747140pgc.26.2024.03.18.15.04.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Mar 2024 15:04:44 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v9 2/5] eal: make eal_log_level_parse common Date: Mon, 18 Mar 2024 15:02:58 -0700 Message-ID: <20240318220432.7486-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240318220432.7486-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240318220432.7486-1-stephen@networkplumber.org> MIME-Version: 1.0 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 The code to parse for log-level option should be same on all OS variants. Signed-off-by: Stephen Hemminger --- lib/eal/common/eal_common_options.c | 46 +++++++++++++++++++++++++++++ lib/eal/common/eal_options.h | 1 + lib/eal/freebsd/eal.c | 42 -------------------------- lib/eal/linux/eal.c | 39 ------------------------ lib/eal/windows/eal.c | 35 ---------------------- 5 files changed, 47 insertions(+), 116 deletions(-) diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index e541f0793964..7310d10dfd78 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -1640,6 +1640,51 @@ eal_parse_huge_unlink(const char *arg, struct hugepage_file_discipline *out) return -1; } +/* Parse the all arguments looking for --log-level */ +int +eal_log_level_parse(int argc, char * const argv[]) +{ + struct internal_config *internal_conf = eal_get_internal_configuration(); + int option_index, opt; + const int old_optind = optind; + const int old_optopt = optopt; + const int old_opterr = opterr; + char *old_optarg = optarg; +#ifdef RTE_EXEC_ENV_FREEBSD + const int old_optreset = optreset; + optreset = 1; +#endif + + optind = 1; + opterr = 0; + + while ((opt = getopt_long(argc, argv, eal_short_options, + eal_long_options, &option_index)) != EOF) { + + switch (opt) { + case OPT_LOG_LEVEL_NUM: + if (eal_parse_common_option(opt, optarg, internal_conf) < 0) + return -1; + break; + case '?': + /* getopt is not happy, stop right now */ + goto out; + default: + continue; + } + } +out: + /* restore getopt lib */ + optind = old_optind; + optopt = old_optopt; + optarg = old_optarg; + opterr = old_opterr; +#ifdef RTE_EXEC_ENV_FREEBSD + optreset = old_optreset; +#endif + return 0; +} + int eal_parse_common_option(int opt, const char *optarg, struct internal_config *conf) @@ -2173,6 +2218,7 @@ rte_vect_set_max_simd_bitwidth(uint16_t bitwidth) return 0; } + void eal_common_usage(void) { diff --git a/lib/eal/common/eal_options.h b/lib/eal/common/eal_options.h index 3cc9cb641284..f3f2e104f6d7 100644 --- a/lib/eal/common/eal_options.h +++ b/lib/eal/common/eal_options.h @@ -96,6 +96,7 @@ enum { extern const char eal_short_options[]; extern const struct option eal_long_options[]; +int eal_log_level_parse(int argc, char * const argv[]); int eal_parse_common_option(int opt, const char *argv, struct internal_config *conf); int eal_option_device_parse(void); diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index a57ee8406f0c..94927472edfe 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -364,48 +364,6 @@ 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; - const int old_optind = optind; - const int old_optopt = optopt; - const int old_optreset = optreset; - char * const old_optarg = optarg; - struct internal_config *internal_conf = - eal_get_internal_configuration(); - - argvopt = argv; - optind = 1; - optreset = 1; - - 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_conf) : 0; - - /* common parser is not happy */ - if (ret < 0) - break; - } - - /* restore getopt lib */ - optind = old_optind; - optopt = old_optopt; - optreset = old_optreset; - optarg = old_optarg; -} - /* Parse the argument given in the command line of the application */ static int eal_parse_args(int argc, char **argv) diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index fd422f1f6236..bffeb1f34eb9 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -546,45 +546,6 @@ eal_parse_vfio_vf_token(const char *vf_token) return -1; } -/* Parse the arguments for --log-level only */ -static void -eal_log_level_parse(int argc, char **argv) -{ - int opt; - char **argvopt; - int option_index; - const int old_optind = optind; - const int old_optopt = optopt; - char * const old_optarg = optarg; - struct internal_config *internal_conf = - eal_get_internal_configuration(); - - argvopt = argv; - optind = 1; - - 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_conf) : 0; - - /* common parser is not happy */ - if (ret < 0) - break; - } - - /* restore getopt lib */ - optind = old_optind; - optopt = old_optopt; - optarg = old_optarg; -} - static int eal_parse_huge_worker_stack(const char *arg) { diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c index 52f0e7462dd8..85171b27687e 100644 --- a/lib/eal/windows/eal.c +++ b/lib/eal/windows/eal.c @@ -96,41 +96,6 @@ eal_usage(const char *prgname) } } -/* Parse the arguments for --log-level only */ -static void -eal_log_level_parse(int argc, char **argv) -{ - int opt; - char **argvopt; - int option_index; - struct internal_config *internal_conf = - eal_get_internal_configuration(); - - argvopt = argv; - - eal_reset_internal_config(internal_conf); - - 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_conf) : 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) From patchwork Mon Mar 18 22:02:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138474 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 616FE43CEE; Mon, 18 Mar 2024 23:05:04 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3FD1640A79; Mon, 18 Mar 2024 23:04:50 +0100 (CET) Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by mails.dpdk.org (Postfix) with ESMTP id E303640A6E for ; Mon, 18 Mar 2024 23:04:47 +0100 (CET) Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-6e7224cb3f2so1116993b3a.1 for ; Mon, 18 Mar 2024 15:04:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1710799487; x=1711404287; 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=h26vCz6XxR4JOVNqKDtIA/aTK4iPIJYOD/gXXJVesxQ=; b=rB0bjqdo14vmEsGmQZkiZyzF82a4e4KkjPFJWZkyFk2CrpeVXVAxjPmJ2jhvEs9YKM 4HDJYdrbcsXzwAN6V8KyJKq1nyG9zGgm7xQcpcyuPY0Po7OIKY6V3OJ4s/NhYGUleYgi bnEdbUamkkXQpOockx5YJfiMvxNmRn4VZba6p7KrmADwBwG4CmSf433lgobl6R78MfaW 1UALFG9KByzwq10BEc0AEd1S8kINUs6c/ja9xbhdUm/Sv5UE1BfLA/0LUBjq8jzqqxpd ucaFtQO5h3SpFijc2uoAWH4WkQDVHiF7mxQTZcos7Bv45VOfZUl2tLHb0tCVQvahUuWF oB4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710799487; x=1711404287; 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=h26vCz6XxR4JOVNqKDtIA/aTK4iPIJYOD/gXXJVesxQ=; b=I76z6JEjvWlmHjK/MZyzs+cYNSCPHgVdLUrDoIIOK/FYCxbeSSDyswI/FqjinTCWLU 7kAhb4CM4bCwrzI3HErf/vH2Ql0QkK94fvH+fjEZAnMUSi/284jTgZqUZRXXP9axCmOO 7E/InwfVlk2W7GXU2aV2O5yXolmdUsHqeRlIT1aT4pIN/Fx+Nr7atUwr5cYer7jP8dc3 LMmAAjMI7wO1hVTZxzZzbst+SnJWb4onJ6L9oNlDhpKX1X6cF1OaU/0ahGxRCpiEhCAV xvANz1olzJdZ+WcNCNX6O4Uqc+uqZcV/EnInlSw5f9cH3HfZc89UxCMMBCMtPylfGTr4 Fn4w== X-Gm-Message-State: AOJu0Yz4Ex1HRMYnDWKKDwJS/meCxr2MgDEHp5+Eoc1vtyTWISu0WlVs c2FVFG2oWwDIBg1SROTWTny8UmuE2k2hJRQgttaodWLCA7D6Ce4aybi/oqXQw+jyQ0h0+9cB9l7 O X-Google-Smtp-Source: AGHT+IGG7Mhk7kuaVzqv+0GJ6n5abA1/SkcPzn1eVlUEutzuhD1Nw/3IJIIj2coCrEpjZD6Auv7ITw== X-Received: by 2002:a05:6a20:ce47:b0:1a3:4b24:149a with SMTP id id7-20020a056a20ce4700b001a34b24149amr1256954pzb.29.1710799487098; Mon, 18 Mar 2024 15:04:47 -0700 (PDT) Received: from hermes.local (204-195-123-141.wavecable.com. [204.195.123.141]) by smtp.gmail.com with ESMTPSA id y6-20020a637d06000000b005dc88b232a5sm7747140pgc.26.2024.03.18.15.04.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Mar 2024 15:04:46 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v9 3/5] eal: initialize logging before plugins Date: Mon, 18 Mar 2024 15:02:59 -0700 Message-ID: <20240318220432.7486-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240318220432.7486-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240318220432.7486-1-stephen@networkplumber.org> MIME-Version: 1.0 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 Want to make sure that as many log messages as possible get added with the real log stream. Signed-off-by: Stephen Hemminger --- lib/eal/freebsd/eal.c | 14 +++++++------- lib/eal/linux/eal.c | 16 ++++++++-------- lib/eal/unix/eal_unix_log.c | 0 3 files changed, 15 insertions(+), 15 deletions(-) create mode 100644 lib/eal/unix/eal_unix_log.c diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index 94927472edfe..6f0080c4d8c6 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -593,6 +593,13 @@ rte_eal_init(int argc, char **argv) internal_conf->in_memory = false; } + if (eal_log_init(getprogname(), internal_conf->syslog_facility) < 0) { + rte_eal_init_alert("Cannot init logging."); + rte_errno = ENOMEM; + rte_atomic_store_explicit(&run_once, 0, rte_memory_order_relaxed); + return -1; + } + if (eal_plugins_init() < 0) { rte_eal_init_alert("Cannot init plugins"); rte_errno = EINVAL; @@ -719,13 +726,6 @@ rte_eal_init(int argc, char **argv) #endif } - if (eal_log_init(getprogname(), internal_conf->syslog_facility) < 0) { - rte_eal_init_alert("Cannot init logging."); - rte_errno = ENOMEM; - rte_atomic_store_explicit(&run_once, 0, rte_memory_order_relaxed); - return -1; - } - /* in secondary processes, memory init may allocate additional fbarrays * not present in primary processes, so to avoid any potential issues, * initialize memzones first. diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index bffeb1f34eb9..e24f24b1b0ce 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -973,6 +973,14 @@ rte_eal_init(int argc, char **argv) return -1; } + if (eal_log_init(program_invocation_short_name, + internal_conf->syslog_facility) < 0) { + rte_eal_init_alert("Cannot init logging."); + rte_errno = ENOMEM; + rte_atomic_store_explicit(&run_once, 0, rte_memory_order_relaxed); + return -1; + } + if (eal_plugins_init() < 0) { rte_eal_init_alert("Cannot init plugins"); rte_errno = EINVAL; @@ -1107,14 +1115,6 @@ rte_eal_init(int argc, char **argv) #endif } - if (eal_log_init(program_invocation_short_name, - internal_conf->syslog_facility) < 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/unix/eal_unix_log.c b/lib/eal/unix/eal_unix_log.c new file mode 100644 index 000000000000..e69de29bb2d1 From patchwork Mon Mar 18 22:03:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138475 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id E94B843CEE; Mon, 18 Mar 2024 23:05:10 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8F56540DCA; Mon, 18 Mar 2024 23:04:52 +0100 (CET) Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by mails.dpdk.org (Postfix) with ESMTP id 2CE1E40A71 for ; Mon, 18 Mar 2024 23:04:49 +0100 (CET) Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-6e6f69e850bso3763932b3a.0 for ; Mon, 18 Mar 2024 15:04:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1710799488; x=1711404288; 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=T8d4wbz8UaPAWAX98FuZk1eIKsZOb9m1Xynp/hHjNCo=; b=1x/DuWghv5zagI5s20Zm6IN6OtnuyeygY7vN68iVRoMd1GlHiSUWchg76hndVJnRLE zHS8IrgdM+DiILK4OzMj9lW8Vmp7pN10KDYWV1xRLE07kdA24u7aXPsf7TsAAvuOc8Ni FwVBKhPhzX5Qft0wyhWTQMVfPP8egM0rHJk/C1/dqMLdiY8xOOkTkH47UQfeyJbsy9Q6 fDe0AUav31NWYt6qh7pH9L6D+5dAE2DdyTDgozQtq5b4zO1xi3cC2aCOz4fUWmxA85ay dycpWT0K4XSSmKlAymgjSx1gMEX2G7roW1M1NK5nUF0zFnRs2K9z6+fAoaUxlE3xMEfx vSLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710799488; x=1711404288; 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=T8d4wbz8UaPAWAX98FuZk1eIKsZOb9m1Xynp/hHjNCo=; b=dpHqdEt0UjwMCo9wT1/F+LRs39Z/RRiw4owtSh5n4rvKVoWzhl7a/lh+PGkOb5n2A1 As1dq3niUk83uDUKC8xevTcgylMqwLHQfbshGROjcSQoy8Y4wyrGd/EmeQPVf87Tnlyi zYUn91a/VbolXQbSrMpQgO48RuFY5bQ36ZdxXKpj5xp9M1F5hUfFCiNna11cWjpvsmjS PWUEYnsuJar2Ehmo3L39h/HrLChHkqZlpqg9o4W90jmWoo4ytLLyrJMOFaABJZ5romoP l9k9ezTpZNCq/trj82TGXMRiA2RzhfEj/cUMck+s3s2y8xD2UntYRbxClhY+L86WWQvn zVlg== X-Gm-Message-State: AOJu0YyrdkAyGDuZCA51ZsOYCuHjWjHkFqfHo0EYEZku0Z8sQwBViHoO sY8ll4GizrVQLNEzArrczec6iTUZkb89v3F1Y5q1DNdEy20JW6/nJtpU2Bh1S9l3RMoJOj8o9uh I X-Google-Smtp-Source: AGHT+IHG4Sg5ew3IOWoFgdgPzXGv/CoxE8pRwzr8RcTilVYewTptGB7DjmnK7bOf+9N5xWX5QgS75Q== X-Received: by 2002:a05:6a20:a111:b0:1a3:677c:23c1 with SMTP id q17-20020a056a20a11100b001a3677c23c1mr4583748pzk.12.1710799488349; Mon, 18 Mar 2024 15:04:48 -0700 (PDT) Received: from hermes.local (204-195-123-141.wavecable.com. [204.195.123.141]) by smtp.gmail.com with ESMTPSA id y6-20020a637d06000000b005dc88b232a5sm7747140pgc.26.2024.03.18.15.04.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Mar 2024 15:04:47 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v9 4/5] eal: allow user to set default log stream before init Date: Mon, 18 Mar 2024 15:03:00 -0700 Message-ID: <20240318220432.7486-5-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240318220432.7486-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240318220432.7486-1-stephen@networkplumber.org> MIME-Version: 1.0 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 It is useful for application to be able to set the default log stream before call rte_eal_init(). This makes all messages go to the new default. For example, to skip using syslog; just doing rte_openlog_stream(stderr); There is no reason for helper command line applications to clutter syslog with messages. Signed-off-by: Stephen Hemminger --- app/dumpcap/main.c | 3 +++ app/pdump/main.c | 3 +++ app/proc-info/main.c | 3 +++ lib/log/log.c | 6 ++++++ lib/log/log_internal.h | 2 ++ lib/log/log_unix.c | 4 ++++ lib/log/version.map | 1 + 7 files changed, 22 insertions(+) diff --git a/app/dumpcap/main.c b/app/dumpcap/main.c index cc0f66b2bc61..27934ca7e688 100644 --- a/app/dumpcap/main.c +++ b/app/dumpcap/main.c @@ -633,6 +633,9 @@ static void dpdk_init(void) rte_panic("No memory\n"); } + /* keep any logging away from syslog. */ + rte_openlog_stream(stderr); + if (rte_eal_init(eal_argc, eal_argv) < 0) rte_exit(EXIT_FAILURE, "EAL init failed: is primary process running?\n"); } diff --git a/app/pdump/main.c b/app/pdump/main.c index a9205e130bb1..7b9ba68b1a14 100644 --- a/app/pdump/main.c +++ b/app/pdump/main.c @@ -995,6 +995,9 @@ main(int argc, char **argv) argc += 2; + /* keep any logging away from syslog. */ + rte_openlog_stream(stderr); + diag = rte_eal_init(argc, argp); if (diag < 0) rte_panic("Cannot init EAL\n"); diff --git a/app/proc-info/main.c b/app/proc-info/main.c index b672aaefbe99..24ee52c4ac7a 100644 --- a/app/proc-info/main.c +++ b/app/proc-info/main.c @@ -2149,6 +2149,9 @@ main(int argc, char **argv) argc += 4; + /* keep any logging away from syslog. */ + rte_openlog_stream(stderr); + ret = rte_eal_init(argc, argp); if (ret < 0) rte_panic("Cannot init EAL\n"); diff --git a/lib/log/log.c b/lib/log/log.c index 255f757d94cc..4cc944305057 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -519,6 +519,12 @@ eal_log_set_default(FILE *default_log) #endif } +FILE * +eal_log_get_default(void) +{ + return default_log_stream; +} + /* * Called by eal_cleanup */ diff --git a/lib/log/log_internal.h b/lib/log/log_internal.h index 451629f1c1ba..c77e687e28bc 100644 --- a/lib/log/log_internal.h +++ b/lib/log/log_internal.h @@ -21,6 +21,8 @@ int eal_log_init(const char *id, int facility); */ __rte_internal void eal_log_set_default(FILE *default_log); +__rte_internal +FILE *eal_log_get_default(void); /* * Save a log option for later. diff --git a/lib/log/log_unix.c b/lib/log/log_unix.c index 2dfb0c974b1d..a415bae5774d 100644 --- a/lib/log/log_unix.c +++ b/lib/log/log_unix.c @@ -49,6 +49,10 @@ eal_log_init(const char *id, int facility) { FILE *log_stream; + /* skip if user has already setup a log stream */ + if (eal_log_get_default()) + return 0; + log_stream = fopencookie(NULL, "w+", console_log_func); if (log_stream == NULL) return -1; diff --git a/lib/log/version.map b/lib/log/version.map index 0648f8831aff..6ecc656d1d65 100644 --- a/lib/log/version.map +++ b/lib/log/version.map @@ -25,6 +25,7 @@ DPDK_24 { INTERNAL { global: + eal_log_get_default; eal_log_init; eal_log_level2str; eal_log_save_pattern; From patchwork Mon Mar 18 22:03:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138476 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id E00A643CEE; Mon, 18 Mar 2024 23:05:17 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C041040DDC; Mon, 18 Mar 2024 23:04:53 +0100 (CET) Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by mails.dpdk.org (Postfix) with ESMTP id 5008040A80 for ; Mon, 18 Mar 2024 23:04:50 +0100 (CET) Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-6e46dcd8feaso2884084b3a.2 for ; Mon, 18 Mar 2024 15:04:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1710799489; x=1711404289; 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=mm+yD9goF61yhxXIeT7u6e0EGZS37olmLkVeOSQvEYg=; b=slokKUREpEXYLmj/5IWwAb7SW5Qh7rR7bTS+MZ/svb7oO8b6okftQkbM8YponuYNP2 B5V7uKwAlJ6I3rad+c5RiuXFfmrqAWpu3g+DFFH1ymmPlKCmDfndh/db0Wvl+A/RUJlD 5PIwIJu1dKGMTzDcYp/KxAVbIjXPKX45V962TykI9QLHBOMtTPyHrv1U8E669chHnlOe lbWG4Wvfwp3EmM15I/QGvlrW5RivSZD+NtjGWxu/mSTAtQto8aFv0s9HLF6sheafM/Gc LUnH1MsKAdsQgbX5Q+M66DNQiDOd51tczbPEN2Kkm8q8HBCJaaBM7cxsMMAyEL+Szegc Fmlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710799489; x=1711404289; 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=mm+yD9goF61yhxXIeT7u6e0EGZS37olmLkVeOSQvEYg=; b=cAQ6ImLoxaVAlA1zFmk8NyHKbBaQSVsre+db5IFenA6nmWLja5Lysjwm0JM8MZt0je Seyzs9nnfWuVu/WUDOk9oY3UDffbO1JWUnRHUB1ZzH22drob0vzX69WZdTDazEjlXKEV 70xzRzO3AWTkexXwLsGgDxRZq2XKGuzO+OHLlKjZeetnCObPwVq2V6gN4RHWLepJymU0 yVTLqxzRLn4cmZKs1z3+VuCqp/y1nM0tCRoL+mxZuAkY4COO7GWAKWYPkVXm65VGbG3b n6HyMDaYyLt1z+eBj8hWO4562UBez/mEES/jRomJaQC3qYn+gOv3MCv4fIuCPGKeetQe Bn5g== X-Gm-Message-State: AOJu0Yw7Splh6QzqtHcf3WBbycZGPBX3SKpvPdoE8JpwcyKw6gVe8dkE If8JCqauc4n54ojzRMMlT+64PN7zqJ54oK7RZUQPPuEsaMY/0fL5qNaebhVDYB3JTZ3L8ZWUDJz H X-Google-Smtp-Source: AGHT+IH70RiyMjPPc43se9rub7eK5uF1h+/FxahRP6Ycse7HJe69kQpRTu8adjooc20MQQPucu7W5g== X-Received: by 2002:a05:6a00:850:b0:6e6:b4e0:c3db with SMTP id q16-20020a056a00085000b006e6b4e0c3dbmr1139705pfk.24.1710799489332; Mon, 18 Mar 2024 15:04:49 -0700 (PDT) Received: from hermes.local (204-195-123-141.wavecable.com. [204.195.123.141]) by smtp.gmail.com with ESMTPSA id y6-20020a637d06000000b005dc88b232a5sm7747140pgc.26.2024.03.18.15.04.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Mar 2024 15:04:48 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v9 5/5] eal: add option to put timestamp on console output Date: Mon, 18 Mar 2024 15:03:01 -0700 Message-ID: <20240318220432.7486-6-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240318220432.7486-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240318220432.7486-1-stephen@networkplumber.org> MIME-Version: 1.0 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 When debugging driver or startup issues, it is useful to have a timestamp on each message printed. The messages in syslog already have a timestamp, but often syslog is not available during testing. The timestamp format is chosen to look like the default Linux dmesg timestamp. The first few lines are not timestamped because the flag is stored in internal configuration which is stored in shared memory which is not setup up until a little later in startup process. This logging skips the unnecessary step of going through stdio, which makes it more robust against being called in interrupt handlers etc. Example: $ dpdk-testpmd --log-timestamp -- -i EAL: Detected CPU lcores: 16 EAL: Detected NUMA nodes: 1 EAL: Detected static linkage of DPDK EAL: Multi-process socket /var/run/dpdk/rte/mp_socket EAL: Selected IOVA mode 'VA' [ 0.112264] testpmd: No probed ethernet devices Interactive-mode selected [ 0.184573] testpmd: create a new mbuf pool : n=163456, size=2176, socket=0 [ 0.184612] testpmd: preferred mempool ops selected: ring_mp_mc Signed-off-by: Stephen Hemminger Acked-by: Morten Brørup --- app/test/test_eal_flags.c | 9 ++++++++ doc/guides/prog_guide/log_lib.rst | 10 +++++++++ lib/eal/common/eal_common_options.c | 10 +++++++-- lib/eal/common/eal_options.h | 2 ++ lib/log/log_internal.h | 9 ++++++++ lib/log/log_unix.c | 32 +++++++++++++++++++++++++++-- lib/log/log_windows.c | 6 ++++++ lib/log/version.map | 1 + 8 files changed, 75 insertions(+), 4 deletions(-) diff --git a/app/test/test_eal_flags.c b/app/test/test_eal_flags.c index 6cb4b0675730..07a038fb6051 100644 --- a/app/test/test_eal_flags.c +++ b/app/test/test_eal_flags.c @@ -1055,6 +1055,10 @@ test_misc_flags(void) const char * const argv22[] = {prgname, prefix, mp_flag, "--huge-worker-stack=512"}; + /* Try running with --log-timestamp */ + const char * const argv23[] = {prgname, prefix, mp_flag, + "--log-timestamp" }; + /* run all tests also applicable to FreeBSD first */ if (launch_proc(argv0) == 0) { @@ -1162,6 +1166,11 @@ test_misc_flags(void) printf("Error - process did not run ok with --huge-worker-stack=size parameter\n"); goto fail; } + if (launch_proc(argv23) != 0) { + printf("Error - process did not run ok with --log-timestamp parameter\n"); + goto fail; + } + rmdir(hugepath_dir3); rmdir(hugepath_dir2); diff --git a/doc/guides/prog_guide/log_lib.rst b/doc/guides/prog_guide/log_lib.rst index aacb36c36ce0..1d6b2e3cea5d 100644 --- a/doc/guides/prog_guide/log_lib.rst +++ b/doc/guides/prog_guide/log_lib.rst @@ -73,6 +73,16 @@ For example:: /path/to/app --syslog local0 +Console timestamp +~~~~~~~~~~~~~~~~~ + +On Linux and FreeBSD, an optional timestamp can be added before each +message by adding the ``--log-timestamp`` option. +For example:: + + /path/to/app --log-level=lib.*:debug --log-timestamp + + Using Logging APIs to Generate Log Messages ------------------------------------------- diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index 7310d10dfd78..9bc95433d27c 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -77,6 +77,7 @@ eal_long_options[] = { {OPT_IOVA_MODE, 1, NULL, OPT_IOVA_MODE_NUM }, {OPT_LCORES, 1, NULL, OPT_LCORES_NUM }, {OPT_LOG_LEVEL, 1, NULL, OPT_LOG_LEVEL_NUM }, + {OPT_LOG_TIMESTAMP, 0, NULL, OPT_LOG_TIMESTAMP_NUM }, {OPT_TRACE, 1, NULL, OPT_TRACE_NUM }, {OPT_TRACE_DIR, 1, NULL, OPT_TRACE_DIR_NUM }, {OPT_TRACE_BUF_SIZE, 1, NULL, OPT_TRACE_BUF_SIZE_NUM }, @@ -1663,6 +1664,7 @@ eal_log_level_parse(int argc, char * const argv[]) switch (opt) { case OPT_LOG_LEVEL_NUM: + case OPT_LOG_TIMESTAMP_NUM: if (eal_parse_common_option(opt, optarg, internal_conf) < 0) return -1; break; @@ -1890,7 +1892,7 @@ eal_parse_common_option(int opt, const char *optarg, break; #endif - case OPT_LOG_LEVEL_NUM: { + case OPT_LOG_LEVEL_NUM: if (eal_parse_log_level(optarg) < 0) { EAL_LOG(ERR, "invalid parameters for --" @@ -1898,7 +1900,10 @@ eal_parse_common_option(int opt, const char *optarg, return -1; } break; - } + + case OPT_LOG_TIMESTAMP_NUM: + eal_log_enable_timestamp(); + break; #ifndef RTE_EXEC_ENV_WINDOWS case OPT_TRACE_NUM: { @@ -2261,6 +2266,7 @@ eal_common_usage(void) " --"OPT_PROC_TYPE" Type of this process (primary|secondary|auto)\n" #ifndef RTE_EXEC_ENV_WINDOWS " --"OPT_SYSLOG" Set syslog facility\n" + " --"OPT_LOG_TIMESTAMP" Timestamp log output\n" #endif " --"OPT_LOG_LEVEL"= Set global log level\n" " --"OPT_LOG_LEVEL"=:\n" diff --git a/lib/eal/common/eal_options.h b/lib/eal/common/eal_options.h index f3f2e104f6d7..e24c9eca53ca 100644 --- a/lib/eal/common/eal_options.h +++ b/lib/eal/common/eal_options.h @@ -35,6 +35,8 @@ enum { OPT_LCORES_NUM, #define OPT_LOG_LEVEL "log-level" OPT_LOG_LEVEL_NUM, +#define OPT_LOG_TIMESTAMP "log-timestamp" + OPT_LOG_TIMESTAMP_NUM, #define OPT_TRACE "trace" OPT_TRACE_NUM, #define OPT_TRACE_DIR "trace-dir" diff --git a/lib/log/log_internal.h b/lib/log/log_internal.h index c77e687e28bc..1af27fe8f9d3 100644 --- a/lib/log/log_internal.h +++ b/lib/log/log_internal.h @@ -5,8 +5,10 @@ #ifndef LOG_INTERNAL_H #define LOG_INTERNAL_H +#include #include #include +#include #include @@ -44,4 +46,11 @@ const char *eal_log_level2str(uint32_t level); __rte_internal void rte_eal_log_cleanup(void); +/* + * Add timestamp to console logs + */ +__rte_internal +void eal_log_enable_timestamp(void); + + #endif /* LOG_INTERNAL_H */ diff --git a/lib/log/log_unix.c b/lib/log/log_unix.c index a415bae5774d..71ce366b6825 100644 --- a/lib/log/log_unix.c +++ b/lib/log/log_unix.c @@ -2,24 +2,52 @@ * Copyright(c) 2010-2014 Intel Corporation */ +#include #include #include +#include #include +#include +#include #include #include "log_internal.h" +static bool timestamp_enabled; +static struct timespec log_started; + +void +eal_log_enable_timestamp(void) +{ + timestamp_enabled = true; + clock_gettime(CLOCK_MONOTONIC, &log_started); +} + /* * default log function */ static ssize_t console_log_write(__rte_unused void *c, const char *buf, size_t size) { + struct timespec ts; ssize_t ret; - /* write on stderr */ - ret = fwrite(buf, 1, size, stderr); + if (timestamp_enabled) { + clock_gettime(CLOCK_MONOTONIC, &ts); + ts.tv_sec -= log_started.tv_sec; + ts.tv_nsec -= log_started.tv_nsec; + if (ts.tv_nsec < 0) { + --ts.tv_sec; + ts.tv_nsec += 1000000000ul; + } + + ret = fprintf(stderr, "[%8lu.%06lu] %.*s", + ts.tv_sec, ts.tv_nsec / 1000u, + (int) size, buf); + } else { + ret = fwrite(buf, 1, size, stderr); + } fflush(stderr); /* Syslog error levels are from 0 to 7, so subtract 1 to convert */ diff --git a/lib/log/log_windows.c b/lib/log/log_windows.c index a6a08895501e..0c471bfb15f6 100644 --- a/lib/log/log_windows.c +++ b/lib/log/log_windows.c @@ -6,6 +6,12 @@ #include #include "log_internal.h" +void +eal_log_enable_timestamp(void) +{ + /* not implemented */ +} + /* set the log to default function, called during eal init process. */ int eal_log_init(__rte_unused const char *id, __rte_unused int facility) diff --git a/lib/log/version.map b/lib/log/version.map index 6ecc656d1d65..32c555f29e79 100644 --- a/lib/log/version.map +++ b/lib/log/version.map @@ -25,6 +25,7 @@ DPDK_24 { INTERNAL { global: + eal_log_enable_timestamp; eal_log_get_default; eal_log_init; eal_log_level2str;