From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 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 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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; -- 2.39.2