From patchwork Wed Jun 28 17:58:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 129078 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 8395242D82; Wed, 28 Jun 2023 19:58:38 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1EDFA41138; Wed, 28 Jun 2023 19:58:34 +0200 (CEST) Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by mails.dpdk.org (Postfix) with ESMTP id 6BA2240151 for ; Wed, 28 Jun 2023 19:58:32 +0200 (CEST) Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1b80bce2592so1273615ad.2 for ; Wed, 28 Jun 2023 10:58:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20221208.gappssmtp.com; s=20221208; t=1687975111; x=1690567111; 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=tvXiIXZpBRp3ib4jXS9jUY5f0cGBdfQa0cAlZSJQmr8=; b=IeP/TXtexKhL4zMr7qiobBmP+4+1Om4eP/tYUMGXuqHp6/SiGnjTprnJP/70cnylGA 7JZGE7tD+B0o2gSV61IuaPy8Blv8STqmEY5IAi1D8vbhoG3SeJuOxDyjsiOM3TWarpg/ OTLwgWQA+XV4TX1UP03YeUXHCql9GhCs/R95HARpCyOYftyPRGt3xlnZXjGOKD2B0daE xD4fgr9VgdwqufGsF9HNTmBS7Mvk6Sg/KqGqCQnnFfeB375xYdjXfRliqpOy6rI6IOlI xBpAX7j3RNfjN7h7awRS8qQeS6B2PGdMBi5yVw4EFAKGrjiA8Gxi1f7CM4L2bmYXxc0y zxag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687975111; x=1690567111; 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=tvXiIXZpBRp3ib4jXS9jUY5f0cGBdfQa0cAlZSJQmr8=; b=JsemMJNqPoVnP4a2Eorffnd1ajgr8HyZNSx8jS8x+6SdoiWSCMMl9KnB/IaRkYVWq8 jxftszxjgJgKSaN09FCJg/H4crbCc4MvRK7Eig0k8rQAG1k1nbehZmrl2iUkn3tq9HBv 0cue6rMLP1TUpymR+U9pS79YI/u5OmbJOIkRG8v0VJeVWtx48/w7Ti/cJnf9U18CoScO 22J0qHT8Tk9WwO6JmO7xWz16h/cImYIgJ+W646h5TSLiI0NIfBSDEhY8FQDRqKKJ7dAD 51u4FAQNttwWG6UaeosfLZlH4LCuRr5e/HyPmeo1n+yiKAL+BKn0fPxwyPNfB+MIGewO 4Kcg== X-Gm-Message-State: AC+VfDz5v6uGO//skTZ7c8uTnvk955I4xbA6km3KgNAkxp8CpUPInYa0 2zuLo+pMIxIz8D7xGvkqKg7rkxx3BFlrYXld3RhPBw== X-Google-Smtp-Source: ACHHUZ78HoJqdmxXyB/GohOVlzx6KSe6aXLr04vdxvz5PIWoenSvsOGzY6+FoQ9R6cg5phxdoWL+mw== X-Received: by 2002:a17:902:d305:b0:1b5:5bf2:b7d2 with SMTP id b5-20020a170902d30500b001b55bf2b7d2mr9406895plc.49.1687975111025; Wed, 28 Jun 2023 10:58:31 -0700 (PDT) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id g11-20020a170902868b00b001b80d399730sm5047875plo.242.2023.06.28.10.58.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jun 2023 10:58:30 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Bruce Richardson Subject: [PATCH v5 1/6] eal: unify logging code for FreeBsd and Linux Date: Wed, 28 Jun 2023 10:58:22 -0700 Message-Id: <20230628175827.471909-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230628175827.471909-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20230628175827.471909-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 logging code was not using syslog and did not have the same options as Linux. Move the log writing code to common source tree. Also fix a number of argument parsing bugs: 1. If application is given a bogus option, the error message would get printed twice. Once during scan for log level and again during parsing of arguments. 2. A bad argument give to --log-level option was given the code would keep going. 3. The syslog facility argument was parsed too late to all log to be initialized before other errors. Signed-off-by: Stephen Hemminger --- .../freebsd_gsg/freebsd_eal_parameters.rst | 27 ++++ lib/eal/common/eal_log.h | 5 + lib/eal/freebsd/eal.c | 55 ++------ lib/eal/linux/eal.c | 48 +------ lib/eal/linux/eal_log.c | 61 --------- lib/eal/linux/meson.build | 1 - lib/eal/unix/eal_log.c | 121 ++++++++++++++++++ lib/eal/unix/meson.build | 1 + 8 files changed, 173 insertions(+), 146 deletions(-) delete mode 100644 lib/eal/linux/eal_log.c create mode 100644 lib/eal/unix/eal_log.c diff --git a/doc/guides/freebsd_gsg/freebsd_eal_parameters.rst b/doc/guides/freebsd_gsg/freebsd_eal_parameters.rst index fba467a2ce92..9270d9fa3bfc 100644 --- a/doc/guides/freebsd_gsg/freebsd_eal_parameters.rst +++ b/doc/guides/freebsd_gsg/freebsd_eal_parameters.rst @@ -18,3 +18,30 @@ FreeBSD-specific EAL parameters ------------------------------- There are currently no FreeBSD-specific EAL command-line parameters available. + +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/lib/eal/common/eal_log.h b/lib/eal/common/eal_log.h index c784fa604389..31dc489350f6 100644 --- a/lib/eal/common/eal_log.h +++ b/lib/eal/common/eal_log.h @@ -13,6 +13,11 @@ */ int eal_log_init(const char *id, int facility); +/* + * Scan command line args for log settings. + */ +int eal_log_level_parse(int argc, char * const argv[]); + /* * Determine where log data is written when no call to rte_openlog_stream. */ diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index 7008303e112a..bb9a2b1653d9 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -52,6 +52,7 @@ #include "eal_hugepages.h" #include "eal_options.h" #include "eal_memcfg.h" +#include "eal_log.h" #include "eal_trace.h" #define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL) @@ -363,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) @@ -610,7 +569,11 @@ rte_eal_init(int argc, char **argv) eal_save_args(argc, argv); /* set log level as early as possible */ - eal_log_level_parse(argc, argv); + if (eal_log_level_parse(argc, argv) < 0) { + rte_eal_init_alert("invalid log option."); + rte_errno = EINVAL; + return -1; + } if (rte_eal_cpu_init() < 0) { rte_eal_init_alert("Cannot detect lcores."); @@ -759,6 +722,12 @@ 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; + 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 145afafde234..d7f268fc8116 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) { @@ -649,7 +610,7 @@ eal_parse_args(int argc, char **argv) goto out; } - /* eal_log_level_parse() already handled this option */ + /* eal_log_level_parse() already handled these */ if (opt == OPT_LOG_LEVEL_NUM) continue; @@ -993,7 +954,12 @@ 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); + if (eal_log_level_parse(argc, argv) < 0) { + rte_eal_init_alert("invalid log option."); + rte_errno = EINVAL; + __atomic_store_n(&run_once, 0, __ATOMIC_RELAXED); + return -1; + } /* clone argv to report out later in telemetry */ eal_save_args(argc, argv); diff --git a/lib/eal/linux/eal_log.c b/lib/eal/linux/eal_log.c deleted file mode 100644 index d44416fd6570..000000000000 --- a/lib/eal/linux/eal_log.c +++ /dev/null @@ -1,61 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * Copyright(c) 2010-2014 Intel Corporation - */ - -#include -#include -#include - -#include - -#include "eal_log.h" - -/* - * default log function - */ -static ssize_t -console_log_write(__rte_unused void *c, const char *buf, size_t size) -{ - ssize_t ret; - - /* write on stderr */ - ret = fwrite(buf, 1, size, stderr); - fflush(stderr); - - /* Syslog error levels are from 0 to 7, so subtract 1 to convert */ - syslog(rte_log_cur_msg_loglevel() - 1, "%.*s", (int)size, buf); - - return ret; -} - -static int -console_log_close(__rte_unused void *c) -{ - closelog(); - return 0; -} - -static cookie_io_functions_t console_log_func = { - .write = console_log_write, - .close = console_log_close, -}; - -/* - * set the log to default function, called during eal init process, - * once memzones are available. - */ -int -eal_log_init(const char *id, int facility) -{ - FILE *log_stream; - - log_stream = fopencookie(NULL, "w+", console_log_func); - if (log_stream == NULL) - return -1; - - openlog(id, LOG_NDELAY | LOG_PID, facility); - - eal_log_set_default(log_stream); - - return 0; -} diff --git a/lib/eal/linux/meson.build b/lib/eal/linux/meson.build index 5af456db9edb..e99ebed25692 100644 --- a/lib/eal/linux/meson.build +++ b/lib/eal/linux/meson.build @@ -11,7 +11,6 @@ sources += files( 'eal_hugepage_info.c', 'eal_interrupts.c', 'eal_lcore.c', - 'eal_log.c', 'eal_memalloc.c', 'eal_memory.c', 'eal_thread.c', diff --git a/lib/eal/unix/eal_log.c b/lib/eal/unix/eal_log.c new file mode 100644 index 000000000000..f8a5c853f2df --- /dev/null +++ b/lib/eal/unix/eal_log.c @@ -0,0 +1,121 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2010-2014 Intel Corporation + */ + +#include +#include +#include +#include + +#include + +#include "eal_log.h" +#include "eal_internal_cfg.h" +#include "eal_options.h" +#include "eal_private.h" + +/* + * default log function + */ +static ssize_t +console_log_write(__rte_unused void *c, const char *buf, size_t size) +{ + ssize_t ret; + + /* write on stderr */ + ret = fwrite(buf, 1, size, stderr); + fflush(stderr); + + /* Syslog error levels are from 0 to 7, so subtract 1 to convert */ + syslog(rte_log_cur_msg_loglevel() - 1, "%.*s", (int)size, buf); + +#ifdef RTE_EXEC_ENV_LINUX + /* Handle glibc quirk: write function should return the number of bytes + * copied from buf, or 0 on error. (The function must not return a negative value.) + * FreeBSD expects that write function behaves like write(2). + */ + if (ret < 0) + ret = 0; +#endif + + return ret; +} + +static int +console_log_close(__rte_unused void *c) +{ + closelog(); + return 0; +} + +static cookie_io_functions_t console_log_func = { + .write = console_log_write, + .close = console_log_close, +}; + + +/* + * Parse the arguments for --log-level and --syslog + */ +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; + char * const old_optarg = optarg; +#ifdef RTE_EXEC_ENV_FREEBSD + const int old_optrset = optreset; +#endif + + optind = 1; +#ifdef RTE_EXEC_ENV_FREEBSD + optreset = 1; +#endif + + 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; +#ifdef RTE_EXEC_ENV_FREEBSD + optreset = old_optreset; +#endif + return 0; +} + +/* + * set the log to default function, called during eal init process, + * once memzones are available. + */ +int +eal_log_init(const char *id, int facility) +{ + FILE *log_stream; + + log_stream = fopencookie(NULL, "w+", console_log_func); + if (log_stream == NULL) + return -1; + + openlog(id, LOG_NDELAY | LOG_PID, facility); + + eal_log_set_default(log_stream); + + return 0; +} diff --git a/lib/eal/unix/meson.build b/lib/eal/unix/meson.build index cc7d67dd321d..37d07594df29 100644 --- a/lib/eal/unix/meson.build +++ b/lib/eal/unix/meson.build @@ -6,6 +6,7 @@ sources += files( 'eal_file.c', 'eal_filesystem.c', 'eal_firmware.c', + 'eal_log.c', 'eal_unix_memory.c', 'eal_unix_thread.c', 'eal_unix_timer.c', From patchwork Wed Jun 28 17:58:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 129079 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 7382342D82; Wed, 28 Jun 2023 19:58:45 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 373E742BC9; Wed, 28 Jun 2023 19:58:37 +0200 (CEST) Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by mails.dpdk.org (Postfix) with ESMTP id 7B68C40E2D for ; Wed, 28 Jun 2023 19:58:33 +0200 (CEST) Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1b809354a15so1358885ad.1 for ; Wed, 28 Jun 2023 10:58:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20221208.gappssmtp.com; s=20221208; t=1687975112; x=1690567112; 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=aFjKo6J4vWeRRCmVV+Rnr9f2wmRMmQKTwPLzfJX+Zig=; b=QoAH45mZWwwHJNldwyjBElKlRc/eYcVVaunhTg7D86NtWQwLcth65peFRa9U/u7Uoa cxv7uiEILXO8GLd3ntAxaSesGX2aQ6yHHaFI/HDYFrgEE/Deg2NTcog0LxkZQQ2STAjg AiMFyFHCZtoQx6ux76kZUEwXHxMWfk8vMg6hwPZUI/Aaq8j2vKytbxFE73UKlxV0Tvdd RmGiioEh3XQ2XEsWoej+01CggDp/K9JmReiojNqX0/t8fablaeOQtSZ7nL0RzHk62vmA RT+r+y8bc1PetWSVUi8eVeNvWm1/vrupabqiSQI6+DD49FCd8kwWdFau7Kip/+HPC4cH QbdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687975112; x=1690567112; 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=aFjKo6J4vWeRRCmVV+Rnr9f2wmRMmQKTwPLzfJX+Zig=; b=mGdgDds0pIpfdShltowhpvZECLmo1Za9gHqxhEUPIRyp6vevtJB8BmluSKDgHUK0at EBJ7tLi6yLpBvxEAVVauDc1n2IORC15yGNb37//1EFEQasLIAfW9BPdWcGNDa+2rd2ny JGiAh0bYTFa19v/MK22q/X1c+Bgu0bHcjL2s8Zd/OacDGyEsZqlnmpdnuLHRCi+yy4ib 6t0AX0DsF04VJAaj9jM01OGw/m27EbhXRSqvRC66Bk0N5fP7zSqGBpjuLLfDWEY0bbmc gP5SNnEjRRJPf4BQzH4vvnhCnoTL6tBSgcBCiOWFhUgmMnzl3y5riGM2JaITON5Tkzye 8mNQ== X-Gm-Message-State: AC+VfDwpOdQ/jskWqJH4YQ67nTEKh7LzrR4gKxMx1UBKgxupi4fRyeIo ujusp0pa7IZuMIy5S6fzQKRsz2kEjtL73SXI0cQXeA== X-Google-Smtp-Source: ACHHUZ6tMonIqY9rBnBaj7pQcYjapvHcPWgVciry/yc0SdbUdQkyZ2+Z0eroBRmIju9AsNnMR7n46Q== X-Received: by 2002:a17:902:c1c5:b0:1b8:11b9:d40a with SMTP id c5-20020a170902c1c500b001b811b9d40amr5652148plc.69.1687975112237; Wed, 28 Jun 2023 10:58:32 -0700 (PDT) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id g11-20020a170902868b00b001b80d399730sm5047875plo.242.2023.06.28.10.58.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jun 2023 10:58:31 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Keith Wiles , Dmitry Kozlyuk , Narcisa Ana Maria Vasile , Dmitry Malloy , Pallavi Kadam Subject: [PATCH v5 2/6] eal: turn off getopt_long error message during eal_log_level Date: Wed, 28 Jun 2023 10:58:23 -0700 Message-Id: <20230628175827.471909-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230628175827.471909-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20230628175827.471909-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 If DPDK application is given a bogus option, the error message would get printed twice. Once during scan for log level and again during parsing of arguments. Example: # ./build/app/dpdk-testpmd --bogus ./build/app/dpdk-testpmd: unrecognized option '--bogus' EAL: Detected CPU lcores: 16 EAL: Detected NUMA nodes: 1 ./build/app/dpdk-testpmd: unrecognized option '--bogus' Usage: ./build/app/dpdk-testpmd [options] Fix by suppressing printing error message on first pass. Signed-off-by: Keith Wiles Signed-off-by: Stephen Hemminger --- lib/eal/unix/eal_log.c | 3 +++ lib/eal/windows/eal.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/lib/eal/unix/eal_log.c b/lib/eal/unix/eal_log.c index f8a5c853f2df..3f54284494d7 100644 --- a/lib/eal/unix/eal_log.c +++ b/lib/eal/unix/eal_log.c @@ -64,12 +64,14 @@ eal_log_level_parse(int argc, char *const argv[]) int option_index, opt; const int old_optind = optind; const int old_optopt = optopt; + const int old_opterr = opterr; char * const old_optarg = optarg; #ifdef RTE_EXEC_ENV_FREEBSD const int old_optrset = optreset; #endif optind = 1; + opterr = 0; #ifdef RTE_EXEC_ENV_FREEBSD optreset = 1; #endif @@ -94,6 +96,7 @@ eal_log_level_parse(int argc, char *const argv[]) optind = old_optind; optopt = old_optopt; optarg = old_optarg; + opterr = old_opterr; #ifdef RTE_EXEC_ENV_FREEBSD optreset = old_optreset; #endif diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c index 2d7a0e9ab27e..0800a9e5c2d2 100644 --- a/lib/eal/windows/eal.c +++ b/lib/eal/windows/eal.c @@ -106,6 +106,8 @@ eal_log_level_parse(int argc, char **argv) struct internal_config *internal_conf = eal_get_internal_configuration(); + opterr = 0; + argvopt = argv; eal_reset_internal_config(internal_conf); @@ -143,6 +145,7 @@ eal_parse_args(int argc, char **argv) eal_get_internal_configuration(); argvopt = argv; + opterr = 1; while ((opt = getopt_long(argc, argvopt, eal_short_options, eal_long_options, &option_index)) != EOF) { From patchwork Wed Jun 28 17:58:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 129080 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 9F7B742D82; Wed, 28 Jun 2023 19:58:51 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7ADD342D0D; Wed, 28 Jun 2023 19:58:38 +0200 (CEST) Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by mails.dpdk.org (Postfix) with ESMTP id 7D43B42B8B for ; Wed, 28 Jun 2023 19:58:34 +0200 (CEST) Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1b8033987baso8744235ad.0 for ; Wed, 28 Jun 2023 10:58:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20221208.gappssmtp.com; s=20221208; t=1687975113; x=1690567113; 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=l2wLPETSatqrqW/abs51daUJaAiV13v3uq1MS6O1kj0=; b=i23g3MIU9GT+09ze/klAwfoeLajYVDD992iIT7hX7tvbrIKm3iyxmJQKJk3kR+mtKl ToEZu1mD+0RrJEJdK3u4X2yC0QV9TdNfZTW5YexvFyWaw8LrLjQ07/qZpw6yKAruRvhm ENvIvGoIa6yzocnShsjzmAvf0azPK7gDIUKTb/E5mOf6XBjt5NTRl93ezsvjE7xL9508 XyEtlWZEvqSsQzdw0oPjJPm2yNr/1Fyu/vJB9Gw7uP7ScS4pVrNDd1vtSJgK9WghBmSe JzKCNi+ERuaQiLVEL/1CESJnsjFVntkFHtOApUIZd5cld+tgzz5uWo0OxaYBqtZG3UCA r4AA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687975113; x=1690567113; 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=l2wLPETSatqrqW/abs51daUJaAiV13v3uq1MS6O1kj0=; b=ercc5cE45m7XveloYFse4z3k8x/k+yPwVoQPofoeLEAcNGywZL1rIfQi1mBzAJNUu1 tUyg2kEOL0IJYpMzYaayHc4AW0ckghotPfITfnqi7s/F88BKqFli0KYS9NhDV5jKJKSI Q7gFnGYgkkmbcRRz2/J3LGVrImQ5PQvKr/kCh1W9i5GRowOpDpqJM3yWdmtGV72Lj6a+ UU/BX5m1ki1V5lppaabt5XGlZuarkPxP1vqbwHA5boDwFPaskrcr++8gafRf7k9O2wLv v9z6CJo3EJgTnEFkwsITX/IO3RlrXrSMGiFIc7t6Mo0mxonsnE8pQce42MIYf4dA3tWu pAnQ== X-Gm-Message-State: AC+VfDw5ictSMRbsg7Ve1Osf5axpDN6yCY+hhTkgQe4Jw6X3T7h0YVqX 2vIs32wUL69r8ALsWyAmWXqsbV/inBlP3o/rsEkgzw== X-Google-Smtp-Source: ACHHUZ43TwWKvckvjfhAl1NsgVr0iC/BmqbE02EpLWbIQq0+oK60Yj3qASL//uuO7J/Owft7slvLRg== X-Received: by 2002:a17:902:e888:b0:1b0:4c6c:716 with SMTP id w8-20020a170902e88800b001b04c6c0716mr2485143plg.4.1687975113479; Wed, 28 Jun 2023 10:58:33 -0700 (PDT) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id g11-20020a170902868b00b001b80d399730sm5047875plo.242.2023.06.28.10.58.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jun 2023 10:58:32 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Bruce Richardson Subject: [PATCH v5 3/6] eal: fix handling of syslog facility Date: Wed, 28 Jun 2023 10:58:24 -0700 Message-Id: <20230628175827.471909-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230628175827.471909-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20230628175827.471909-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 syslog facility option needs to be parsed before log_init is called. Also help message whas missing the required argument. Signed-off-by: Stephen Hemminger --- lib/eal/common/eal_common_options.c | 2 +- lib/eal/freebsd/eal.c | 2 +- lib/eal/linux/eal.c | 2 +- lib/eal/unix/eal_log.c | 1 + 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index 03059336987d..005da4d12001 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -2193,7 +2193,7 @@ eal_common_usage(void) " --"OPT_VMWARE_TSC_MAP" Use VMware TSC map instead of native RDTSC\n" " --"OPT_PROC_TYPE" Type of this process (primary|secondary|auto)\n" #ifndef RTE_EXEC_ENV_WINDOWS - " --"OPT_SYSLOG" Set syslog facility\n" + " --"OPT_SYSLOG"= Set syslog facility\n" #endif " --"OPT_LOG_LEVEL"= Set global log level\n" " --"OPT_LOG_LEVEL"=:\n" diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index bb9a2b1653d9..104507b61514 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -394,7 +394,7 @@ eal_parse_args(int argc, char **argv) } /* eal_log_level_parse() already handled this option */ - if (opt == OPT_LOG_LEVEL_NUM) + if (opt == OPT_LOG_LEVEL_NUM || opt == OPT_SYSLOG_NUM) continue; ret = eal_parse_common_option(opt, optarg, internal_conf); diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index d7f268fc8116..e30c44380e30 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -611,7 +611,7 @@ eal_parse_args(int argc, char **argv) } /* eal_log_level_parse() already handled these */ - if (opt == OPT_LOG_LEVEL_NUM) + if (opt == OPT_LOG_LEVEL_NUM || opt == OPT_SYSLOG_NUM) continue; ret = eal_parse_common_option(opt, optarg, internal_conf); diff --git a/lib/eal/unix/eal_log.c b/lib/eal/unix/eal_log.c index 3f54284494d7..93cf04fae043 100644 --- a/lib/eal/unix/eal_log.c +++ b/lib/eal/unix/eal_log.c @@ -80,6 +80,7 @@ eal_log_level_parse(int argc, char *const argv[]) eal_long_options, &option_index)) != EOF) { switch (opt) { + case OPT_SYSLOG_NUM: case OPT_LOG_LEVEL_NUM: if (eal_parse_common_option(opt, optarg, internal_conf) < 0) return -1; From patchwork Wed Jun 28 17:58:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 129081 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 7ED6F42D82; Wed, 28 Jun 2023 19:58:57 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A92CE42D1D; Wed, 28 Jun 2023 19:58:39 +0200 (CEST) Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by mails.dpdk.org (Postfix) with ESMTP id 75B9F42B8B for ; Wed, 28 Jun 2023 19:58:35 +0200 (CEST) Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1b852785a65so5035ad.0 for ; Wed, 28 Jun 2023 10:58:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20221208.gappssmtp.com; s=20221208; t=1687975114; x=1690567114; 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=q5LcU2GuyWyfjdj1xNxQ3NqciqeusB9CJaomlTrvuhs=; b=Gb42C8uMGzQJjUHkIDz2KMa4kHrZTCBZezP00DJojlwrktFB9u4/5WABxIwS44XDRV ac/6FvsblnfJj2+wjbKAJ12YsUtiV+jucVdiyV3WBUtavcxjpSDMARfIOtfLJokg0vOu YDiCrRKpJ6lIzV6HWXCh0yG2J5Per6GQGoGg4JUuBAWvdURT5kSlJtvRoQGdow500sbF jKteYGqjcOJbS+VuwpFOWPJ+myyJ/qR3CuicaykEK2+JQ4NtJQvA8sSNZqcwi+UL/FuL LE1nkI06NA+yVXAHGRkDHKe/UqSjLoAr5mH+OMARWGUyOngGCCBKkctqr6Fvw4W2tKZP keZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687975114; x=1690567114; 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=q5LcU2GuyWyfjdj1xNxQ3NqciqeusB9CJaomlTrvuhs=; b=gY/kxCCYjovrV/DLtaN6omzM2zvDB5lAENcJQZ17gi14BlgUL8pVr5UtLOy1TYiQyw N+2fwn/1Uh2SeN5lX7K2BUfzL5d9+Ohfx3VjSGtq2uFcPMayqy4qxompsKeibm7ghnXY e9U9kHM74rxXkiNB0v1YQZEJki9kR9mXlCvMDAivxJc+j8RWYgvpE6pHmHB1fzGbP8hN iurUkuO2jDQziKS4GZh1HX4xrnaGL7tOlpfYBxUrdLFryYFUBittOEpaAwgekURl5FIX ePeagj31P+CFFQ/OIjKr1B4vCqpuabVpTZy+tBckOzoVwRFNrsbXqPlLBwVkXl+Ce882 GAwg== X-Gm-Message-State: AC+VfDzYdsC+KqwaUjc4IxYIl5HxaIzxAOBV7MaAx+CMgohdzlbpiGss aI9HuWr5YVjLF0InwgYyCRXOA/IjlchM5KorYpSdkQ== X-Google-Smtp-Source: ACHHUZ7vk/YdIkDFrkzZwPeTDfy58QrGXNGQih+oIaryoXiE9IZRFY9y15NmOWVkq3X4hpmxVyUUFw== X-Received: by 2002:a17:903:1cf:b0:1b6:a91d:bd1f with SMTP id e15-20020a17090301cf00b001b6a91dbd1fmr2412884plh.6.1687975114482; Wed, 28 Jun 2023 10:58:34 -0700 (PDT) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id g11-20020a170902868b00b001b80d399730sm5047875plo.242.2023.06.28.10.58.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jun 2023 10:58:33 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v5 4/6] eal: skip stdio on console logging Date: Wed, 28 Jun 2023 10:58:25 -0700 Message-Id: <20230628175827.471909-5-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230628175827.471909-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20230628175827.471909-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 There is no need to use stdio when logging to console. Using the write system call directly avoids unnecessary copy to stdio output buffer. Signed-off-by: Stephen Hemminger --- lib/eal/unix/eal_log.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/eal/unix/eal_log.c b/lib/eal/unix/eal_log.c index 93cf04fae043..7921417b050a 100644 --- a/lib/eal/unix/eal_log.c +++ b/lib/eal/unix/eal_log.c @@ -6,6 +6,7 @@ #include #include #include +#include #include @@ -23,8 +24,7 @@ console_log_write(__rte_unused void *c, const char *buf, size_t size) ssize_t ret; /* write on stderr */ - ret = fwrite(buf, 1, size, stderr); - fflush(stderr); + ret = write(STDERR_FILENO, buf, size); /* Syslog error levels are from 0 to 7, so subtract 1 to convert */ syslog(rte_log_cur_msg_loglevel() - 1, "%.*s", (int)size, buf); From patchwork Wed Jun 28 17:58:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 129082 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 8545C42D82; Wed, 28 Jun 2023 19:59:05 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 46E0442D3F; Wed, 28 Jun 2023 19:58:41 +0200 (CEST) Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by mails.dpdk.org (Postfix) with ESMTP id 4B0FB42BFE for ; Wed, 28 Jun 2023 19:58:37 +0200 (CEST) Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1b7f223994fso1493205ad.3 for ; Wed, 28 Jun 2023 10:58:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20221208.gappssmtp.com; s=20221208; t=1687975116; x=1690567116; 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=nE2jNT5rnryaJFXWUIFUABW5PA5MQ6/vAjoD8y7GhEI=; b=P6wxS6gVH7NYrgIvhlKyUOPZwg4DDg0JDCIos70AzaoLQhJFh3LbYofhq2BjQM6SGr J5l7u+q6B8aT4X0KY2DUHNFSPmqDGiC9whPCej+V6XFeoTtGCzfUTtK8WRWbajxVwhkZ sO0x9Mjso/wVzr1PN1yBOSUNSdkJlfy8DG1cWcbMrN2UiMnRzBOrP/OBYJZR4gB5y25b W64Y/lsi5J+0PMzNEG6MxGR40WjCzkmt/H5fjsWKnUmoSfL7ksaixQ1kYNmQs9fcKO1Q XmwLbyYtC3VpI7MDY9jdgX50Rx0BDEw9xa5+w79AU9+0GIWrqOKegxFceyy7zXtdNg2y tVJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687975116; x=1690567116; 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=nE2jNT5rnryaJFXWUIFUABW5PA5MQ6/vAjoD8y7GhEI=; b=WyZN0lh+Wc/qGriU4pIdr/Gq0gdnA16n/cH9FeQ7JF5HkYvL/Uz5VT/3JeY5VLmnTW 45R0fR8lLsVjSYgodiAVmobSyt3mEJ/WCCvTnAO+U/3CsroV+Iz/Ya2/kcmabnr4w26V B9odsfjhHYAKX2lp9RuRh7ezdHzoZoJOE8p/U2iu2xBzhSFcW/lg7ho4brrhWV3CYgNx EF8dS9PdXcU2rgbvvFG12ja0kqY7lW2Y5VFv4o9il8mz4HUl9NB7K4EvAw53ae2KRZdq PV2gPIOKQPuHozqrRSyK01A7dP3Bacnl6Xc5Ydc7BUFmm4ePvD6VpZvPlPJo/XiS8Ajq R68w== X-Gm-Message-State: AC+VfDyAQSepct/G0jqdQ7EDmI6yisKtcj8iSgJC1Z/3YgCO6a3yIf3O kbxOF4Ro/CITNNspMRZa9GwMCe81fLs/AeNC7zthbg== X-Google-Smtp-Source: ACHHUZ4/b+Ki77np1aGegy6SJ5KDgJKGEQ/ggA/kprEd92fwKi0PajQ5afTdP4SRlGhMz/FoAVrwQQ== X-Received: by 2002:a17:903:1105:b0:1b6:6985:ff8d with SMTP id n5-20020a170903110500b001b66985ff8dmr17351492plh.42.1687975116298; Wed, 28 Jun 2023 10:58:36 -0700 (PDT) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id g11-20020a170902868b00b001b80d399730sm5047875plo.242.2023.06.28.10.58.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jun 2023 10:58:34 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v5 5/6] eal: allow user to set default log stream before init Date: Wed, 28 Jun 2023 10:58:26 -0700 Message-Id: <20230628175827.471909-6-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230628175827.471909-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20230628175827.471909-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_log_set_default(stderr); Signed-off-by: Stephen Hemminger --- lib/eal/common/eal_common_log.c | 6 ++++++ lib/eal/common/eal_log.h | 1 + lib/eal/unix/eal_log.c | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/lib/eal/common/eal_common_log.c b/lib/eal/common/eal_common_log.c index bd7b188ceb4a..9b158c201205 100644 --- a/lib/eal/common/eal_common_log.c +++ b/lib/eal/common/eal_common_log.c @@ -535,6 +535,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/eal/common/eal_log.h b/lib/eal/common/eal_log.h index 31dc489350f6..268c2a264382 100644 --- a/lib/eal/common/eal_log.h +++ b/lib/eal/common/eal_log.h @@ -22,6 +22,7 @@ int eal_log_level_parse(int argc, char * const argv[]); * Determine where log data is written when no call to rte_openlog_stream. */ void eal_log_set_default(FILE *default_log); +FILE *eal_log_get_default(void); /* * Save a log option for later. diff --git a/lib/eal/unix/eal_log.c b/lib/eal/unix/eal_log.c index 7921417b050a..3bfe5853095f 100644 --- a/lib/eal/unix/eal_log.c +++ b/lib/eal/unix/eal_log.c @@ -113,6 +113,10 @@ eal_log_init(const char *id, int facility) { FILE *log_stream; + /* has 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; From patchwork Wed Jun 28 17:58:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 129083 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 29F3942D82; Wed, 28 Jun 2023 19:59:12 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 63C3C42D35; Wed, 28 Jun 2023 19:58:42 +0200 (CEST) Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by mails.dpdk.org (Postfix) with ESMTP id 0786942D10 for ; Wed, 28 Jun 2023 19:58:39 +0200 (CEST) Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1b7fb1a82c4so1528075ad.1 for ; Wed, 28 Jun 2023 10:58:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20221208.gappssmtp.com; s=20221208; t=1687975118; x=1690567118; 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=RY8J9r9mCUW4V1UoowqIgtEXc5CryfGDGywTRhgsi5o=; b=wNhrZuwMHo1dNozCbvktWIt3FLgGAISvCBBetJUjYajRPEtsvRelf1tEGYwTuuBrAe L9ZuVoVuLZqbUk/JN0//r/kgEj4KUzK5FpeNK1muG1xPjL75uo+NqWgnxObQuXBC87UI hBy8OFmO1I+rkqX6oFJJGmuFD1D3MpfllWnLiCupxMDiTsQQ0lI46dRirdHMauwwMuCt MfqhqUBAuKHXKieySoHIkbGb24018BSOdYNG4PqAzuwSny7QJEeoQ69Lq09kCBa4NJAm JC58RkQa+hWoG8ZEr/pySWUskFZ54AvCFPaImuKpecfJMwa/UXyBxk6ittYLWY/gQuJE qUag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687975118; x=1690567118; 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=RY8J9r9mCUW4V1UoowqIgtEXc5CryfGDGywTRhgsi5o=; b=ESfR4EDSKMXzAE6i5mSDHz/zWM8GLtN/pyHvrvS7r2aY81InRxBOTSVo2oyiTVxLYy Smvb5FlQf5tLlLLe0KAFiFeDBOn+SIiuZsuGEqP8OT/05ecoZma4EJj9kh0wTrxZYXLn 4i5JpUj9w50LbiwWoxburrhPjARaXLqWEPXXRCyciD8Dbt5dylT/EMDn14l320ZwYWRQ sy78MGAiXAiLmRPef2Dx5JjbXd51mZOe8ilhtp1vPvKCvYVHxVmfI5mqdEtBXxL+Cj78 fKijm+Ek/D/KmI3OVBmQ/mVCg8j/4YiSOcyaCqNym2X+SVJqmagKAiPeXmSibzcggeK9 yyoQ== X-Gm-Message-State: AC+VfDyIbD+7tiXW5hX6PZW2E2LLSCB+46/4gr5HS0kgFMABaVl7Y+Tn u9PtxmupIBkNaw/1DGUC47oDeeTsaFDmRnpieXmaRg== X-Google-Smtp-Source: ACHHUZ5FkNhLpPZxei2PhKQqZ2R+JZyIKJ/js4KCib4I3qJnTb18a3bYs4Rmc6FG2aanVBaT7XBtLg== X-Received: by 2002:a17:903:41c5:b0:1b6:8863:8c9f with SMTP id u5-20020a17090341c500b001b688638c9fmr13009463ple.6.1687975117876; Wed, 28 Jun 2023 10:58:37 -0700 (PDT) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id g11-20020a170902868b00b001b80d399730sm5047875plo.242.2023.06.28.10.58.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jun 2023 10:58:36 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Bruce Richardson , Anatoly Burakov Subject: [PATCH v5 6/6] eal: add option to put timestamp on console output Date: Wed, 28 Jun 2023 10:58:27 -0700 Message-Id: <20230628175827.471909-7-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230628175827.471909-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20230628175827.471909-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. 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 --- .../freebsd_gsg/freebsd_eal_parameters.rst | 5 +++ doc/guides/linux_gsg/linux_eal_parameters.rst | 5 +++ lib/eal/common/eal_common_options.c | 6 +++ lib/eal/common/eal_internal_cfg.h | 3 ++ lib/eal/common/eal_options.h | 2 + lib/eal/freebsd/eal.c | 4 +- lib/eal/linux/eal.c | 4 +- lib/eal/unix/eal_log.c | 44 +++++++++++++++++-- 8 files changed, 67 insertions(+), 6 deletions(-) diff --git a/doc/guides/freebsd_gsg/freebsd_eal_parameters.rst b/doc/guides/freebsd_gsg/freebsd_eal_parameters.rst index 9270d9fa3bfc..99cff10e963c 100644 --- a/doc/guides/freebsd_gsg/freebsd_eal_parameters.rst +++ b/doc/guides/freebsd_gsg/freebsd_eal_parameters.rst @@ -45,3 +45,8 @@ Other options local5 local6 local7 + +* ``--log-timestamp`` + + Add a timestamp of seconds and microseconds to each log message + written to standard output. diff --git a/doc/guides/linux_gsg/linux_eal_parameters.rst b/doc/guides/linux_gsg/linux_eal_parameters.rst index ea8f38139119..719ca6851625 100644 --- a/doc/guides/linux_gsg/linux_eal_parameters.rst +++ b/doc/guides/linux_gsg/linux_eal_parameters.rst @@ -135,3 +135,8 @@ Other options local5 local6 local7 + +* ``--log-timestamp`` + + Add a timestamp of seconds and microseconds to each log message + written to standard output. diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index 005da4d12001..67fe6efb4526 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -76,6 +76,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 }, @@ -1835,6 +1836,10 @@ eal_parse_common_option(int opt, const char *optarg, } #ifndef RTE_EXEC_ENV_WINDOWS + case OPT_LOG_TIMESTAMP_NUM: + conf->log_timestamp = 1; + break; + case OPT_TRACE_NUM: { if (eal_trace_args_save(optarg) < 0) { RTE_LOG(ERR, EAL, "invalid parameters for --" @@ -2194,6 +2199,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_internal_cfg.h b/lib/eal/common/eal_internal_cfg.h index 167ec501fa79..ca502d5dd365 100644 --- a/lib/eal/common/eal_internal_cfg.h +++ b/lib/eal/common/eal_internal_cfg.h @@ -84,7 +84,10 @@ struct internal_config { /**< true if storing all pages within single files (per-page-size, * per-node) non-legacy mode only. */ + uint8_t log_timestamp; /**< add timestamp to console output */ + struct timespec log_start_time; /**< monotonic clock when started */ volatile int syslog_facility; /**< facility passed to openlog() */ + /** default interrupt mode for VFIO */ volatile enum rte_intr_mode vfio_intr_mode; /** the shared VF token for VFIO-PCI bound PF and VFs devices */ diff --git a/lib/eal/common/eal_options.h b/lib/eal/common/eal_options.h index 3cc9cb641284..cc9723868e3c 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/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index 104507b61514..ae3a736e862d 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -394,7 +394,9 @@ eal_parse_args(int argc, char **argv) } /* eal_log_level_parse() already handled this option */ - if (opt == OPT_LOG_LEVEL_NUM || opt == OPT_SYSLOG_NUM) + if (opt == OPT_LOG_LEVEL_NUM || + opt == OPT_SYSLOG_NUM || + opt == OPT_LOG_TIMESTAMP_NUM) continue; ret = eal_parse_common_option(opt, optarg, internal_conf); diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index e30c44380e30..6deb694e7242 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -611,7 +611,9 @@ eal_parse_args(int argc, char **argv) } /* eal_log_level_parse() already handled these */ - if (opt == OPT_LOG_LEVEL_NUM || opt == OPT_SYSLOG_NUM) + if (opt == OPT_LOG_LEVEL_NUM || + opt == OPT_SYSLOG_NUM || + opt == OPT_LOG_TIMESTAMP_NUM) continue; ret = eal_parse_common_option(opt, optarg, internal_conf); diff --git a/lib/eal/unix/eal_log.c b/lib/eal/unix/eal_log.c index 3bfe5853095f..172b332b8417 100644 --- a/lib/eal/unix/eal_log.c +++ b/lib/eal/unix/eal_log.c @@ -5,7 +5,9 @@ #include #include #include +#include #include +#include #include #include @@ -19,12 +21,38 @@ * default log function */ static ssize_t -console_log_write(__rte_unused void *c, const char *buf, size_t size) +console_log_write(void *c, const char *buf, size_t size) { + const struct internal_config *internal_conf = c; ssize_t ret; - /* write on stderr */ - ret = write(STDERR_FILENO, buf, size); + /* add optional timestamp for stderr */ + if (internal_conf->log_timestamp) { + struct iovec iov[2]; + struct timespec ts; + char tbuf[64]; + + /* format up monotonic timestamp */ + clock_gettime(CLOCK_MONOTONIC, &ts); + ts.tv_sec -= internal_conf->log_start_time.tv_sec; + ts.tv_nsec -= internal_conf->log_start_time.tv_nsec; + if (ts.tv_nsec < 0) { + --ts.tv_sec; + ts.tv_nsec += 1000000000ul; + } + + /* use writev to put timestamp and buf in single operation */ + iov[0].iov_base = tbuf; + iov[0].iov_len = snprintf(tbuf, sizeof(tbuf), "[%8lu.%06lu] ", + ts.tv_sec, ts.tv_nsec / 1000u); + + /* casts are to unconstify the buf */ + iov[1].iov_base = (void *)(uintptr_t)buf; + iov[1].iov_len = size; + ret = writev(STDERR_FILENO, iov, 2); + } else { + ret = write(STDERR_FILENO, buf, size); + } /* Syslog error levels are from 0 to 7, so subtract 1 to convert */ syslog(rte_log_cur_msg_loglevel() - 1, "%.*s", (int)size, buf); @@ -82,6 +110,7 @@ eal_log_level_parse(int argc, char *const argv[]) switch (opt) { case OPT_SYSLOG_NUM: case OPT_LOG_LEVEL_NUM: + case OPT_LOG_TIMESTAMP_NUM: if (eal_parse_common_option(opt, optarg, internal_conf) < 0) return -1; break; @@ -111,13 +140,20 @@ eal_log_level_parse(int argc, char *const argv[]) int eal_log_init(const char *id, int facility) { + struct internal_config *internal_conf = eal_get_internal_configuration(); FILE *log_stream; /* has user has already setup a log stream */ if (eal_log_get_default()) return 0; - log_stream = fopencookie(NULL, "w+", console_log_func); + if (internal_conf->process_type == RTE_PROC_PRIMARY && + internal_conf->log_timestamp) { + if (clock_gettime(CLOCK_MONOTONIC, &internal_conf->log_start_time) < 0) + return -1; + } + + log_stream = fopencookie(internal_conf, "w+", console_log_func); if (log_stream == NULL) return -1;