From patchwork Thu Jun 29 15:58:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 129119 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 90FF742D8D; Thu, 29 Jun 2023 17:59:22 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3FCB341104; Thu, 29 Jun 2023 17:59:20 +0200 (CEST) Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) by mails.dpdk.org (Postfix) with ESMTP id 36CD8406B7 for ; Thu, 29 Jun 2023 17:59:17 +0200 (CEST) Received: by mail-pg1-f174.google.com with SMTP id 41be03b00d2f7-55b1238a013so598096a12.3 for ; Thu, 29 Jun 2023 08:59:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20221208.gappssmtp.com; s=20221208; t=1688054356; x=1690646356; 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=qOUhFNDBJzTW/ylgqhJjNMUgMVnNVNu77BRkvSIbP6o=; b=3ABgOLbhE0PisNCZcIxifS/mQEbk0SwkQUyXeBnhUFr8P9eilNWzMHUDcmpama+fZI rRiA4RS5COfbwcvyz88y6hWCpjDIFODjFD8w3OMqheGa1irOOjxNFQ4tIp77MZN/rSPI meUeSs3Dlj1WPDT8Bu6FZ3uIZ26f1KzzsOnOqXDdBcXtLYgRpquA7pcoANNQ9J3HYoHw cJ+7jK+cROy7aSO/5A6HrzN7CNvW3s+9oIQK0UhHGHJotdt3r4HhFq7XdB1oyKAWjQWq yHST2C8B31Q5GjFd5C6RIGvSyc4rBMpqmclp6ZhkPR7+V99fPSXqGPy2cmwcGYvMnVQF B8vA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688054356; x=1690646356; 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=qOUhFNDBJzTW/ylgqhJjNMUgMVnNVNu77BRkvSIbP6o=; b=bZlypOI2hQaKTxTod621lUh247xedP/sPJJeCGyEZ+FCGANFNxmFK/2rxjPUVVxhfK z9kBYjRypUtfO1ApBchLBG9xTzFMTvqmCuBR1L3ghXeKjHbMgl71ZSUEuh4VHmYWSBAb dVYpDu0hdabdXPKODszLqRRt4hAgnDAi9QnGWi0ncpIzgIgYfJ7qIParIX89Io3YqxIH 3Baj34bkH6hKPdxrPS695iiwiP7Bw9xYZpK96orpFxAulZiBpHfUZhg4vv1J7Oz4pHI5 6gj5AAD2clQv/q4SpXbkjC7tewVvEkVaCZhVcsOpCPs5v/wxf6o/XsQ59KnYPAztvClX Z0Cg== X-Gm-Message-State: AC+VfDwgodJYPvUn5+8L7xpL2NkIDyMgiQ6CxjuPEa4MZ/y9DpW8NsaC bM1Lnb83tH6xotseVgWexx3pZkwNJzyhL/8oFsuhQA== X-Google-Smtp-Source: ACHHUZ7RR+6WVLs0cnswTZV6Wr49e7AXKvn3D13gPt6F7SfwoNgJykG7NW6E15c43FQBIqr86FAtlA== X-Received: by 2002:a05:6a20:72a5:b0:122:92d0:452a with SMTP id o37-20020a056a2072a500b0012292d0452amr52349pzk.37.1688054356094; Thu, 29 Jun 2023 08:59:16 -0700 (PDT) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id c6-20020a63ea06000000b0055b553157a5sm471716pgi.71.2023.06.29.08.59.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jun 2023 08:59:15 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Bruce Richardson , Dmitry Kozlyuk , Narcisa Ana Maria Vasile , Dmitry Malloy , Pallavi Kadam Subject: [PATCH v6 1/6] eal: unify logging code Date: Thu, 29 Jun 2023 08:58:38 -0700 Message-Id: <20230629155858.75668-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230629155858.75668-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20230629155858.75668-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. Use a common set of functions for that. Pre-parsing for log level is common to all OS's. Now the pre-scan can return an error. A bad argument give to --log-level option was given the code would keep going. Signed-off-by: Stephen Hemminger make log_parse common to windows --- .../freebsd_gsg/freebsd_eal_parameters.rst | 27 +++++++++ lib/eal/common/eal_common_log.c | 46 ++++++++++++++++ lib/eal/common/eal_log.h | 5 ++ lib/eal/freebsd/eal.c | 55 ++++--------------- lib/eal/linux/eal.c | 46 ++-------------- lib/eal/linux/meson.build | 1 - lib/eal/{linux => unix}/eal_log.c | 11 ++++ lib/eal/unix/meson.build | 1 + lib/eal/windows/eal.c | 35 ------------ 9 files changed, 108 insertions(+), 119 deletions(-) rename lib/eal/{linux => unix}/eal_log.c (76%) 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_common_log.c b/lib/eal/common/eal_common_log.c index bd7b188ceb4a..7e2f010fa371 100644 --- a/lib/eal/common/eal_common_log.c +++ b/lib/eal/common/eal_common_log.c @@ -2,6 +2,7 @@ * Copyright(c) 2010-2014 Intel Corporation */ +#include #include #include #include @@ -16,6 +17,8 @@ #include #include "eal_log.h" +#include "eal_internal_cfg.h" +#include "eal_options.h" #include "eal_private.h" struct rte_log_dynamic_type { @@ -223,6 +226,49 @@ log_save_level(uint32_t priority, const char *regex, const char *pattern) 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; + char * const old_optarg = optarg; +#ifdef RTE_EXEC_ENV_FREEBSD + const int old_optreset = optreset; + optreset = 1; +#endif + + optind = 1; + + 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; +} + int eal_log_save_regexp(const char *regex, uint32_t level) { 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..c9475560d986 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) { @@ -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/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/linux/eal_log.c b/lib/eal/unix/eal_log.c similarity index 76% rename from lib/eal/linux/eal_log.c rename to lib/eal/unix/eal_log.c index d44416fd6570..85d817c2d31e 100644 --- a/lib/eal/linux/eal_log.c +++ b/lib/eal/unix/eal_log.c @@ -9,6 +9,8 @@ #include #include "eal_log.h" +#include "eal_internal_cfg.h" +#include "eal_private.h" /* * default log function @@ -25,6 +27,15 @@ console_log_write(__rte_unused void *c, const char *buf, size_t 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); +#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; } 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', diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c index 2d7a0e9ab27e..240d5b8ad3e4 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 Thu Jun 29 15:58:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 129120 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 CAA3142D8D; Thu, 29 Jun 2023 17:59:28 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5D8E442BAC; Thu, 29 Jun 2023 17:59:21 +0200 (CEST) Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by mails.dpdk.org (Postfix) with ESMTP id 64989410E4 for ; Thu, 29 Jun 2023 17:59:18 +0200 (CEST) Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-668704a5b5bso804188b3a.0 for ; Thu, 29 Jun 2023 08:59:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20221208.gappssmtp.com; s=20221208; t=1688054357; x=1690646357; 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=y3fHgsR0tPxSTSC5fciugWqXet9+wOwAz2x0F1wMyv0=; b=ruGHCNgQzA0oybSV/d1jXJrAnB1VZ5G8pjouQ4xXP+eF5uTSHfOEDnLFFCmUZbhlNL qReS5HUy2Vdsic7HAqRZj64ZOScfr4iYOKUM8/DO1rW+pGPKZQc/kcnCaLswAtNVU9Iz djb2rvPGvz7ewqmdvX1UJTD20iaXx4N4sVMm4ykBDQS15I4ikb+QOBjx7Sy7kGyzizH1 2GsSTQFbBaQ4qezs3HhaUW4Oz7gPxa02mmVleIpVWhA1zpk5Mqz3Mn/Ki2EdFBhPQ2Dm Zq4kQ7U3d59tnkMEW/8Oup+FiN1MivGN1QogC3uzk+VBCqMaWICXA2DZZyONruZ4k89Z sa1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688054357; x=1690646357; 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=y3fHgsR0tPxSTSC5fciugWqXet9+wOwAz2x0F1wMyv0=; b=e6x3slIiSCnTbV1Bhi+rIvTwt9S4uYD2bo098VeihREGqQuOzN0gx0RohDHGAE4XrQ gkpoPdnBzIr82/82XvB/q3dY9X/T75m7MpDGtiXZ6gBqMJDINe8PhevdOr+qfwGBqU5E JLUX+KbaLMg7/nIZDDdxwA13laceUemqlIPSVbiwW44HXggFX4tau7UvFo4E1m8Yw8yD Zjh1Pp35KfiBMOiRv4OaP9dCwhhGoI5HTEap3gf96mYMUbyG3IOM2J+VclCbOptV/o6o YBM2iNcwykiVkgYwD+2oEufKhkTNZ7Ra0j5lmDH5xja2P7rKwDJpDnm4epd04H40Lo8Z P8wA== X-Gm-Message-State: AC+VfDy+hXkclDLtzwiHDMz8ReE3mgNEtNbutOxlLed77meBH000e37n MOnGkeSSouOvrhgxoakYxdWCbYY9TMTUhbjIHJ2Y8Q== X-Google-Smtp-Source: ACHHUZ5FG4lJ/wQaSRlMU41HuW9hSIMekTbqHbAJ1Fz66Vwg2220HS1h1gWTs8qgUDkIWZ2PEJd42w== X-Received: by 2002:a05:6a20:488:b0:126:3c08:77fa with SMTP id 8-20020a056a20048800b001263c0877famr16916pzc.48.1688054357325; Thu, 29 Jun 2023 08:59:17 -0700 (PDT) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id c6-20020a63ea06000000b0055b553157a5sm471716pgi.71.2023.06.29.08.59.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jun 2023 08:59:16 -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 v6 2/6] eal: turn off getopt_long error message during eal_log_level Date: Thu, 29 Jun 2023 08:58:39 -0700 Message-Id: <20230629155858.75668-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230629155858.75668-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20230629155858.75668-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/common/eal_common_log.c | 3 +++ lib/eal/windows/eal.c | 1 + 2 files changed, 4 insertions(+) diff --git a/lib/eal/common/eal_common_log.c b/lib/eal/common/eal_common_log.c index 7e2f010fa371..ada3ed5ebec9 100644 --- a/lib/eal/common/eal_common_log.c +++ b/lib/eal/common/eal_common_log.c @@ -235,6 +235,7 @@ 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_optreset = optreset; @@ -242,6 +243,7 @@ eal_log_level_parse(int argc, char *const argv[]) #endif optind = 1; + opterr = 0; while ((opt = getopt_long(argc, argv, eal_short_options, eal_long_options, &option_index)) != EOF) { @@ -263,6 +265,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 240d5b8ad3e4..c6006c48ddef 100644 --- a/lib/eal/windows/eal.c +++ b/lib/eal/windows/eal.c @@ -108,6 +108,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 Thu Jun 29 15:58:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 129121 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 9E03442D8D; Thu, 29 Jun 2023 17:59:34 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8AE09406B7; Thu, 29 Jun 2023 17:59:22 +0200 (CEST) Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by mails.dpdk.org (Postfix) with ESMTP id 3C21E41101 for ; Thu, 29 Jun 2023 17:59:19 +0200 (CEST) Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-6686c74183cso775724b3a.1 for ; Thu, 29 Jun 2023 08:59:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20221208.gappssmtp.com; s=20221208; t=1688054358; x=1690646358; 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=pp72RlIvGuDF0mhsFUm63/uvVcS7XvB1ShVEfHsSG9g=; b=LeU4f5pOG2qhRbPRgjl8ok+62TmuljmbkfOhre2nuktERAyt4j/V1AdajuUOq0M0EW e3F/5PDR6ARWGdKzA2aFJv6dOv94wfnqHWckRx+ifCRSvxm0WNBoGx8LWfrVUvs+09dN bFRnol1eXWqePOySQYwrOOtCm3D1YoLyfAjp9pMtcW+ywAfD8DoWSrN0kSeMDsgSuxM2 NwxS6Ku95s8GNUytrg0jp3X5wENSMkDo9r+8A5lNHwXp+jagD0y1ySRqT2t/ePlE5urE pc2hl3TbmC28ymPFKznQqni2VAm2ngpDqdAndciERy2BRjYY9lbBYCKPv4ceAqB/mTi3 DBJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688054358; x=1690646358; 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=pp72RlIvGuDF0mhsFUm63/uvVcS7XvB1ShVEfHsSG9g=; b=B4FHVLm6hbjClmqHaa/m4yrHzrQfqLlyAoc9wLo8VO/eHF4ENecH2RPWMmOv6pqrvd IirkDutp77XXu6whaoZUtJokpxEMLSH/v5oitX4CDk1PAMN0IJRkc3IPipzheoQUXdft G4sQICrXV7HBzKAZblypKnqkLDvyUONczyycsVTKCUkpBc2S4gt+dpnPl4sGeyLGnz4I pcl9bZ5FGzjGHjiJ2ROwaTsLeqH+87UAw0bhQQ5A13g0mzXrHcnnw+nuMsqJtCOH8wzV 0jco8vZTDGB5ah5emCqAEDKBDqyXFgAcX9UehYnwmeKo26yOsfG1VAgW1Uufw6iyWwQD dWzw== X-Gm-Message-State: ABy/qLY2wKFN7Ogh1Sp4zlDFctW31DiZZunqtTx7nV5woGUYNklQh3mr mR/BfZpFfybPAGhhftghB+GJV0EpaxqmaCSwp+NVXA== X-Google-Smtp-Source: APBJJlH+UT0ESOkSazj7op/HiL9XJHewX6SZK/Qd/tQg14FHwRroNE5NgKHaM/Vm7HhhJUhHjwKRLg== X-Received: by 2002:aa7:88cf:0:b0:674:ff6d:1b39 with SMTP id k15-20020aa788cf000000b00674ff6d1b39mr399033pff.9.1688054358180; Thu, 29 Jun 2023 08:59:18 -0700 (PDT) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id c6-20020a63ea06000000b0055b553157a5sm471716pgi.71.2023.06.29.08.59.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jun 2023 08:59:17 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v6 3/6] eal: fix help message for syslog option Date: Thu, 29 Jun 2023 08:58:40 -0700 Message-Id: <20230629155858.75668-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230629155858.75668-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20230629155858.75668-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 flag takes facility argument. Signed-off-by: Stephen Hemminger --- lib/eal/common/eal_common_options.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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" From patchwork Thu Jun 29 15:58:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 129122 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 B176C42D8D; Thu, 29 Jun 2023 17:59:40 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A531A42D12; Thu, 29 Jun 2023 17:59:23 +0200 (CEST) Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by mails.dpdk.org (Postfix) with ESMTP id 02BC7427EE for ; Thu, 29 Jun 2023 17:59:21 +0200 (CEST) Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-66f5faba829so614346b3a.3 for ; Thu, 29 Jun 2023 08:59:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20221208.gappssmtp.com; s=20221208; t=1688054360; x=1690646360; 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=IPVc1lS3Y2TP5Wbd8OIZTKngZ1wvW69emU7an/lir2g=; b=BE1XC8u5dGo7hoOi8NQAvehf+qJ0yxTXYU8Rev+Xrc67R9rcyKFGJBz+j0YXaLqGN5 gwo0xTwro6RytzYiv9SFIkWTiehCm9yuoL4dhtfo0QBLurtrYMya/dsspdr0d76DsJJN rPWmODXP473Umd45N0kpmhWAinUKJV0D/R6Qy1lAnN90uFuuv34eGmN5/Y8VB3VMUVmV gaaqyGciSwuFVPiQQoCT/MPps82YpJ9/Onc0ILqYFNr+ut2oCPZHHevDMekpMyPtqwlP aEYdSEt87SyKifspK2nvHpWe7B1zW+lFZPqAWEHd+OCYZ4IzQAjbLoz6S5p8AAlN+/Lo XdBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688054360; x=1690646360; 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=IPVc1lS3Y2TP5Wbd8OIZTKngZ1wvW69emU7an/lir2g=; b=l6/pWbi7kG/WngV1mwjKW7ckq1ieNnhzAgIYVlAfvVxIoKgMIxosdw82grWavKRYFM /0ZomAcjsZ9Ge1FR+ufQmb1FaclMkvsFRMCncbjK4zmtB7karloNxJaTTTUxEqDMJt+O 0BWqP68ltKIoJna2omjI+kMJJLwbEAsWYyLTG8tubqtBimysgZOkABpPfPASU4G/WwH1 cBtFQYmLD8TAxFiHnqQq3ulJU2kxIAIOo8nODfZShIxSJRDLy8wPuhZIpBbKAFY6yV7n UJYFZ/FOqwYJeHfMRIEkw4gBIxMrbf4S3YZuCKI5DAIZt/8M1H2rB2aqHIMqQmuibigj LMow== X-Gm-Message-State: AC+VfDwyawxxAbZEuEK5jsH7D120fgTGhFjcOj8SQLBRx8EFTGRp7LPt f/6HeJjwGBYgp+lhWom3XXNKYU2FsFWWGvaYN8kNmA== X-Google-Smtp-Source: ACHHUZ56P8fO57ptaxZ7uG50PvOQa6Y4hRg9ybYTTTgt4jnD+D98mLQuLS/ztc8hzSJwodp3DGviOA== X-Received: by 2002:a05:6a20:8f0b:b0:123:21f9:625e with SMTP id b11-20020a056a208f0b00b0012321f9625emr276256pzk.0.1688054359846; Thu, 29 Jun 2023 08:59:19 -0700 (PDT) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id c6-20020a63ea06000000b0055b553157a5sm471716pgi.71.2023.06.29.08.59.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jun 2023 08:59:18 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v6 4/6] eal: skip stdio on console logging Date: Thu, 29 Jun 2023 08:58:41 -0700 Message-Id: <20230629155858.75668-5-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230629155858.75668-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20230629155858.75668-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 85d817c2d31e..151f30eb6071 100644 --- a/lib/eal/unix/eal_log.c +++ b/lib/eal/unix/eal_log.c @@ -5,6 +5,7 @@ #include #include #include +#include #include @@ -21,8 +22,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 Thu Jun 29 15:58:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 129123 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 DBA7142D8D; Thu, 29 Jun 2023 17:59:48 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 32F9B42D3B; Thu, 29 Jun 2023 17:59:26 +0200 (CEST) Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by mails.dpdk.org (Postfix) with ESMTP id 2EEE142BFE for ; Thu, 29 Jun 2023 17:59:22 +0200 (CEST) Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-66869feb7d1so551538b3a.3 for ; Thu, 29 Jun 2023 08:59:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20221208.gappssmtp.com; s=20221208; t=1688054361; x=1690646361; 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=2REMwfqBNFQRsvdAmxlcKkjoRSmPem4p2WHk4M7Y314=; b=fGmeOgAVCRnP/iMTJALcntq50GwM2USRxQUJ7yRH3DdwJeJliD6m1sYRtl/BnC/fdR Ws/aKeXsmqiF+dj2Xrfqm3GuqVJUT94GkDZ5tElicCMTdcqrLzgmB/v85967saq297+a 0Z3dE9v+nWR5DqNoc/UcDsrqCIjRVFDpcj7h1VajiJ5eEBxQRQHMilRhEuU3sbR1ySWg PIrM2BAK4wXWEGDJQLa7Znv+UKRk3+TdQTjOmbjelYRia/m+9gEtaLHciYNRcUiTrFE/ GeBgOXodukDLaf5riffXCWBA7TI9i4fsclF8+0hmLqMgBjHiaknE4eA4uvbLELXOE1SM hj2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688054361; x=1690646361; 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=2REMwfqBNFQRsvdAmxlcKkjoRSmPem4p2WHk4M7Y314=; b=TzGPGHidsH57maUSyIfxqVa96MWDpXjbf98VWEppRhmxlhwui9TGPrRlcqqGuZgsLV twpYU9Pg6UDmSl5UM7NWrea/8j4kwvNMEsBbqQgvtbwiew8GKMYCNs6bAR4vEyYTFsOO s8LDo3kKE6waW+MBg3XdNCFL3Xviccxx4pGN7KHLWMZwSmH69yK/bvOHqDJ4aaeoydSo FU4MpHAdynjPTWV49ijy8eAo2woaAu44iRy+C2aEjSOyA1oAWChjMUiOjq45rNC3krZE V27p3thIrup5op6Jg8EEJt3m6il/uTan4ktNklEwYKjcJ6fIauYGBpiS0U8tDr5S6WlZ 1A0A== X-Gm-Message-State: ABy/qLa7p+kucvMvoJLs0yHeaTf3lfzvv/mvkvv7lS4LarjMDFYZbC12 w0kWR6NLnJph+2A6LikipZqcV34Cl7IUbpn2vi+q9A== X-Google-Smtp-Source: APBJJlGHCVtUiA+/l5GLa4Xpo/5PynBq/owmG/M+XxW5G9hNtHycEOrR/c6gd6g7158+vYiAFrk/zQ== X-Received: by 2002:a62:1850:0:b0:67a:31b7:456c with SMTP id 77-20020a621850000000b0067a31b7456cmr363553pfy.9.1688054361144; Thu, 29 Jun 2023 08:59:21 -0700 (PDT) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id c6-20020a63ea06000000b0055b553157a5sm471716pgi.71.2023.06.29.08.59.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jun 2023 08:59:20 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Reshma Pattan , Maryam Tahhan Subject: [PATCH v6 5/6] eal: allow user to set default log stream before init Date: Thu, 29 Jun 2023 08:58:42 -0700 Message-Id: <20230629155858.75668-6-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230629155858.75668-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20230629155858.75668-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/eal/common/eal_common_log.c | 6 ++++++ lib/eal/common/eal_log.h | 1 + lib/eal/unix/eal_log.c | 4 ++++ 6 files changed, 20 insertions(+) diff --git a/app/dumpcap/main.c b/app/dumpcap/main.c index 64294bbfb3e6..bf31eef13cf4 100644 --- a/app/dumpcap/main.c +++ b/app/dumpcap/main.c @@ -639,6 +639,9 @@ static void dpdk_init(void) eal_argv[i++] = strdup(file_prefix); } + /* 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 c94606275b28..82c67350e4ab 100644 --- a/app/pdump/main.c +++ b/app/pdump/main.c @@ -989,6 +989,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 53e852a07c14..371b1f382d66 100644 --- a/app/proc-info/main.c +++ b/app/proc-info/main.c @@ -1774,6 +1774,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/eal/common/eal_common_log.c b/lib/eal/common/eal_common_log.c index ada3ed5ebec9..827830916eb7 100644 --- a/lib/eal/common/eal_common_log.c +++ b/lib/eal/common/eal_common_log.c @@ -584,6 +584,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 151f30eb6071..98753cb52e09 100644 --- a/lib/eal/unix/eal_log.c +++ b/lib/eal/unix/eal_log.c @@ -60,6 +60,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 Thu Jun 29 15:58:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 129124 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 F1B0942D8D; Thu, 29 Jun 2023 17:59:55 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5D4B242D3F; Thu, 29 Jun 2023 17:59:27 +0200 (CEST) Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by mails.dpdk.org (Postfix) with ESMTP id A720A42D16 for ; Thu, 29 Jun 2023 17:59:23 +0200 (CEST) Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-666e6541c98so792666b3a.2 for ; Thu, 29 Jun 2023 08:59:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20221208.gappssmtp.com; s=20221208; t=1688054362; x=1690646362; 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=lAIrpS6MObewvYnezgpPNOdksDU/ff4Ab6jZlAk0MoA=; b=valDGgT+PCa07LCqAi53YA4SgwYe88+A3k5oz7XWyvQXt8Zzdr/cDUIa2GbhSDIfgY AXydHHz2hPNoz+l16CdZxqulW8KT76R84F0SbTZNMoaZDHTtgcffchUWeNBCDvxRgJR/ lt8+N3i/ZYaSFGMqtykEnR/4Tibv4+kzjuNb0C45j972ytTb0bd2QzK+R2Wjrjpk5+Rk Wzbl2ZYNbQsCclpJxLbVWyLgiq4whiBLWpo6afU7m0ZFy+93oBJ5h5ypff+DZGDx14QH BDc3zBjAmcQRoJuweyZh1MO5Fhs6QJVStmEwDCL10F7phjNYCV8sloGqFUgo3ALN1HVm 7CSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688054362; x=1690646362; 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=lAIrpS6MObewvYnezgpPNOdksDU/ff4Ab6jZlAk0MoA=; b=PAGVzawf5OViMSr5Qj7I49T7iek6mg8s7/20kvhkYkEf137+Zcet89UtD85oTYbr9d Jftw9byWNFJ2U6dkOLtIAJXIbbl2jH+dtYl7IF2nrt+k0CHsuzloj5V2hXtovz9ciQJ3 gmWaH86wGg7OXh2VtUu/JKmrJtHTxNU2+nCnIHVR0b1+S8xd4J5ZF/ihI0Pw80NBBP7i N5e9+tEYj1hhYCEaTvwkLkBt3n9bAciYKRRwAvtjJ7dy4Gjk89ZEQRGebJyDBULTTich cAFVNtjVS4I3itDwR9trsI+hPhpb0cns13EBVHGhgXAdpK5Jl36B3cdoYYjXQVEhIT3y vnMg== X-Gm-Message-State: ABy/qLYP+7D9+YpIRzHZpdVXBPYoLuINGfhco3M9wWpePvXtVwCcFXn+ +HTjsHjBAI4JJ9AA+aKe/hj3KRGZDJYHQXYQHkIJow== X-Google-Smtp-Source: APBJJlGTm6Lj95Hc0V83leTBB7gOQjkpW/GdR1O6Lv6sF6Kc1ll+D/l0bwu28zF05fFRyO5taaJKlA== X-Received: by 2002:a05:6a00:1591:b0:668:7b5b:c1aa with SMTP id u17-20020a056a00159100b006687b5bc1aamr329941pfk.20.1688054362643; Thu, 29 Jun 2023 08:59:22 -0700 (PDT) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id c6-20020a63ea06000000b0055b553157a5sm471716pgi.71.2023.06.29.08.59.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jun 2023 08:59:21 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Bruce Richardson , Anatoly Burakov Subject: [PATCH v6 6/6] eal: add option to put timestamp on console output Date: Thu, 29 Jun 2023 08:58:43 -0700 Message-Id: <20230629155858.75668-7-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230629155858.75668-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20230629155858.75668-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 --- app/test/test_eal_flags.c | 9 ++++ .../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/unix/eal_log.c | 43 +++++++++++++++++-- 7 files changed, 69 insertions(+), 4 deletions(-) diff --git a/app/test/test_eal_flags.c b/app/test/test_eal_flags.c index d2b91e20750e..57637728d811 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/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/unix/eal_log.c b/lib/eal/unix/eal_log.c index 98753cb52e09..1ee94a5ee1e6 100644 --- a/lib/eal/unix/eal_log.c +++ b/lib/eal/unix/eal_log.c @@ -4,7 +4,9 @@ #include #include +#include #include +#include #include #include @@ -17,12 +19,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); @@ -58,13 +86,20 @@ static cookie_io_functions_t console_log_func = { 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;