From patchwork Thu Mar 21 16:00:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138667 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 0F29A43D17; Thu, 21 Mar 2024 17:18:25 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EDD5042E05; Thu, 21 Mar 2024 17:18:24 +0100 (CET) Received: from mail-yb1-f170.google.com (mail-yb1-f170.google.com [209.85.219.170]) by mails.dpdk.org (Postfix) with ESMTP id 6CDEC427E1 for ; Thu, 21 Mar 2024 17:18:23 +0100 (CET) Received: by mail-yb1-f170.google.com with SMTP id 3f1490d57ef6-dcd7c526cc0so1235970276.1 for ; Thu, 21 Mar 2024 09:18:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711037903; x=1711642703; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Hf75PC3cGL3/aHUnTvzOVFoCo+jxSQLWlI0Kn+D/zko=; b=DPcQHNpaTg4i/sYKty6MkL8JJ6/Gg1Du1YU2RSb3GQ+x5iwG+k44REJ0To8H+6NsSG Mcdn8QCq68UfBqIrnruPhbyt91DSq6rbtulGDunj14Ora4W5zAGcCVtzcnqX2MFuk6kA e0DmLTGpiz+z1GGw8ds76ybSnvc8RbQAKPbCuUh0XDfQAyqz2emBCxhFuByVUiCsfRxp yYLAeBR13y8ovYmRWNmMzZNp1D+n+CB1vbl79NLJ/ZfeCqkcDI6+VDWNbNVr3gLrrYKu gO4fKpt4h+KdnuonXy1Rd/SPbKn9m6m3w9Oe27hQuU//JXzOClI3HrJ+wB45senyCRpj IMOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711037903; x=1711642703; 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=Hf75PC3cGL3/aHUnTvzOVFoCo+jxSQLWlI0Kn+D/zko=; b=EfnxAaMa06tv0Ohi3i/rKlXJbV2MfO64Qqj1hW4XBMZwnfe/Z2k6+Lq9QIAuVlIjeo zx8X/dqhZvJqlIpbdjLt+ySFqZo6ugawplrJWd4jVdZuTUW0XzwmYNpZr6Mns3UFum86 sqzz27xUx4jfrFhYXNky/Y6Y3cjMup9Bsnso61e2Nf0SxwYfVH6fq43vtWu/MOiFzbWa Phhi71qBYproj3uhiEFytLGObvoxXSfyZaUrVw5TNZkAGsaWAiC5dNIZnsp0g67aj0Kk 1ozmgfoqI1b3VhBZcbd6J3EUEQwK7U9XytXoNCqAVVk1w7qr8d6yW2Lih1eWzS5t96TK FPWg== X-Gm-Message-State: AOJu0YwxVdxJL65z6yHNnmKPFWZPz2mNJKHwLJCJYAgN+HAE0u8RnqeE lX6imyayOCzGDChZi3MpMkr46S/6rivaMlmqhit0hQoQptrrC8RrKKz5dWSlp2D0t5qw36gzQgl J X-Google-Smtp-Source: AGHT+IGyy1NRs56yUVIwhlz0kcEKO0QFToMVjiNofnMuT/gxMrPXkbyatDFJb2ulED2iGTbdefm9WA== X-Received: by 2002:a05:6a20:438f:b0:1a3:59ac:a626 with SMTP id i15-20020a056a20438f00b001a359aca626mr6962224pzl.41.1711037517358; Thu, 21 Mar 2024 09:11:57 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id w62-20020a638241000000b005e485fbd455sm41815pgd.45.2024.03.21.09.11.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 09:11:56 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff , Dmitry Kozlyuk Subject: [PATCH v10 01/10] windows: make getopt functions have const properties Date: Thu, 21 Mar 2024 09:00:17 -0700 Message-ID: <20240321161146.340421-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240321161146.340421-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240321161146.340421-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 Having different prototypes on different platforms can lead to lots of unnecessary workarounds. Looks like the version of getopt used from windows was based on an older out of date version from FreeBSD. This patch changes getopt, getopt_long, etc to have the same const attributes as Linux and FreeBSD. The changes are derived from the current FreeBSD version of getopt_long. Signed-off-by: Stephen Hemminger Acked-by: Tyler Retzlaff Acked-by: Dmitry Kozlyuk --- lib/eal/windows/getopt.c | 23 ++++++++++++----------- lib/eal/windows/include/getopt.h | 8 ++++---- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/eal/windows/getopt.c b/lib/eal/windows/getopt.c index a1f51c6c2318..50ff71b9300d 100644 --- a/lib/eal/windows/getopt.c +++ b/lib/eal/windows/getopt.c @@ -20,7 +20,7 @@ #include #include -const char *optarg; /* argument associated with option */ +char *optarg; /* argument associated with option */ int opterr = 1; /* if error message should be printed */ int optind = 1; /* index into parent argv vector */ int optopt = '?'; /* character checked for validity */ @@ -39,9 +39,9 @@ static void pass(const char *a) {(void) a; } #define BADARG ((*options == ':') ? (int)':' : (int)'?') #define INORDER 1 -#define EMSG "" +static char EMSG[] = ""; -static const char *place = EMSG; /* option letter processing */ +static char *place = EMSG; /* option letter processing */ /* XXX: set optreset to 1 rather than these two */ static int nonopt_start = -1; /* first non option argument (for permute) */ @@ -80,7 +80,7 @@ gcd(int a, int b) */ static void permute_args(int panonopt_start, int panonopt_end, int opt_end, - char **nargv) + char * const *nargv) { int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos; char *swap; @@ -101,11 +101,12 @@ permute_args(int panonopt_start, int panonopt_end, int opt_end, pos -= nnonopts; else pos += nopts; + swap = nargv[pos]; /* LINTED const cast */ - ((char **) nargv)[pos] = nargv[cstart]; + ((char **)(uintptr_t)nargv)[pos] = nargv[cstart]; /* LINTED const cast */ - ((char **)nargv)[cstart] = swap; + ((char **)(uintptr_t)nargv)[cstart] = swap; } } } @@ -116,7 +117,7 @@ permute_args(int panonopt_start, int panonopt_end, int opt_end, * Returns -1 if short_too is set and the option does not match long_options. */ static int -parse_long_options(char **nargv, const char *options, +parse_long_options(char * const *nargv, const char *options, const struct option *long_options, int *idx, int short_too) { const char *current_argv; @@ -236,7 +237,7 @@ parse_long_options(char **nargv, const char *options, * Parse argc/argv argument vector. Called by user level routines. */ static int -getopt_internal(int nargc, char **nargv, const char *options, +getopt_internal(int nargc, char *const nargv[], const char *options, const struct option *long_options, int *idx, int flags) { char *oli; /* option letter list index */ @@ -434,7 +435,7 @@ getopt_internal(int nargc, char **nargv, const char *options, * Parse argc/argv argument vector. */ int -getopt(int nargc, char *nargv[], const char *options) +getopt(int nargc, char *const nargv[], const char *options) { return getopt_internal(nargc, nargv, options, NULL, NULL, FLAG_PERMUTE); @@ -445,7 +446,7 @@ getopt(int nargc, char *nargv[], const char *options) * Parse argc/argv argument vector. */ int -getopt_long(int nargc, char *nargv[], const char *options, +getopt_long(int nargc, char *const nargv[], const char *options, const struct option *long_options, int *idx) { @@ -458,7 +459,7 @@ getopt_long(int nargc, char *nargv[], const char *options, * Parse argc/argv argument vector. */ int -getopt_long_only(int nargc, char *nargv[], const char *options, +getopt_long_only(int nargc, char *const nargv[], const char *options, const struct option *long_options, int *idx) { diff --git a/lib/eal/windows/include/getopt.h b/lib/eal/windows/include/getopt.h index 6f57af454b17..e4cf6873cb0c 100644 --- a/lib/eal/windows/include/getopt.h +++ b/lib/eal/windows/include/getopt.h @@ -44,7 +44,7 @@ /** argument to current option, or NULL if it has none */ -extern const char *optarg; +extern char *optarg; /** Current position in arg string. Starts from 1. * Setting to 0 resets state. */ @@ -80,14 +80,14 @@ struct option { }; /** Compat: getopt */ -int getopt(int argc, char *argv[], const char *options); +int getopt(int argc, char *const argv[], const char *options); /** Compat: getopt_long */ -int getopt_long(int argc, char *argv[], const char *options, +int getopt_long(int argc, char *const argv[], const char *options, const struct option *longopts, int *longindex); /** Compat: getopt_long_only */ -int getopt_long_only(int nargc, char *argv[], const char *options, +int getopt_long_only(int nargc, char *const argv[], const char *options, const struct option *long_options, int *idx); From patchwork Thu Mar 21 16:00:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138670 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 C653143D17; Thu, 21 Mar 2024 17:19:04 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AC74742E39; Thu, 21 Mar 2024 17:18:54 +0100 (CET) Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) by mails.dpdk.org (Postfix) with ESMTP id 7CA8B42E09 for ; Thu, 21 Mar 2024 17:18:52 +0100 (CET) Received: by mail-qk1-f178.google.com with SMTP id af79cd13be357-78a2093cd44so93349985a.0 for ; Thu, 21 Mar 2024 09:18:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711037932; x=1711642732; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=va7MWJRuAR3nLxH5zGMYb78QbpeyFQrBUnnO1GsDymY=; b=gS0nZDxZWq6ZrPbrWvP3FpE3zskM8o2jntgoJZHyiyb9QzBOi13u2mQHijXMk5VgOW 84W8kii6J9x0IcYSiahdqnyJYINZAv7F2evxC0YDCPLnl67ylhSQffNxL5Ph3HR+MEDv kJXmkzr7UhFc2+rht4l7rGFaqCArb9qb0WYs1vYBJt0/K5ygJNvZH4fr/3vo08kcYPgE hs3GiXFD/MvKjqcXfJFPay+drNfrLVQUfuosemEQzJPRwOzSJmc8YjFnihX7b/AHuxZH eSiX+4KwxLfFUI2C3wLKM8soTQZpPA5Tfcz73kSrLGzqLntrdRzhxDERCgInuUb4wHP4 Jwvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711037932; x=1711642732; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=va7MWJRuAR3nLxH5zGMYb78QbpeyFQrBUnnO1GsDymY=; b=UYLEuiewFHOV87sys+yfsCbe7BKtANMZ+RBxdEaURfJ90WbluKTh/F3m+ElOmQegJX e8MAnI6+wNAtHZj471CK63YanwWhekTiCpQ5y2Xh4im7Sn5YcPMtevV6wQ2qohG2vm71 szCVbvjr2DpvijhuXkmz2GqZOzUYgWPNz/ATyBgBmI+NxiCMPSTviok9P/o/LoturIXV p6VV0eq8WWRwtGL17QO0oWBYTlz3KNPmKhsXLB0lyVvIEyhqyIs0ZNM2kKkc01gUDCwq ePDRA035N3DAmvrvN7bc/7IGuGpchM/KtKkp9B53slmFobm9b9Z5zKOeDRtDDsJ9o1H5 3C5Q== X-Gm-Message-State: AOJu0YwVuOJUUx3ZedOunJJj+AWTZz8Oy9I00wSB6ftr725SUCh3NLXT sB8Zl4vCJTHBF9017SOq1ySUOb0wXVJBGzAGdMppthEqczTfgESp09ImVq1/cXDalwpHjJqQC8t u X-Google-Smtp-Source: AGHT+IH+RCR8/OOEPPLFLO6+5PUXkSJAY31XYdim4DQOqOtkOc3ZjoSYxJ3K+G6mWmsn/IMlR1E6/A== X-Received: by 2002:a05:6a20:2d95:b0:1a3:7f25:fb4c with SMTP id bf21-20020a056a202d9500b001a37f25fb4cmr2001636pzb.51.1711037518079; Thu, 21 Mar 2024 09:11:58 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id w62-20020a638241000000b005e485fbd455sm41815pgd.45.2024.03.21.09.11.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 09:11:57 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v10 02/10] log: unify logging code Date: Thu, 21 Mar 2024 09:00:18 -0700 Message-ID: <20240321161146.340421-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240321161146.340421-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240321161146.340421-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org FreeBSD and Linux logging code can use common code. This also fixes FreeBSD not using syslog. Signed-off-by: Stephen Hemminger --- doc/guides/linux_gsg/linux_eal_parameters.rst | 27 ------------------- doc/guides/prog_guide/log_lib.rst | 18 +++++++++++-- lib/eal/freebsd/eal.c | 8 ++++++ lib/log/log_freebsd.c | 12 --------- lib/log/{log_linux.c => log_unix.c} | 0 lib/log/meson.build | 12 ++++++--- 6 files changed, 32 insertions(+), 45 deletions(-) delete mode 100644 lib/log/log_freebsd.c rename lib/log/{log_linux.c => log_unix.c} (100%) diff --git a/doc/guides/linux_gsg/linux_eal_parameters.rst b/doc/guides/linux_gsg/linux_eal_parameters.rst index ea8f38139119..d86f94d8a85d 100644 --- a/doc/guides/linux_gsg/linux_eal_parameters.rst +++ b/doc/guides/linux_gsg/linux_eal_parameters.rst @@ -108,30 +108,3 @@ Memory-related options * ``--match-allocations`` Free hugepages back to system exactly as they were originally allocated. - -Other options -~~~~~~~~~~~~~ - -* ``--syslog `` - - Set syslog facility. Valid syslog facilities are:: - - auth - cron - daemon - ftp - kern - lpr - mail - news - syslog - user - uucp - local0 - local1 - local2 - local3 - local4 - local5 - local6 - local7 diff --git a/doc/guides/prog_guide/log_lib.rst b/doc/guides/prog_guide/log_lib.rst index ff9d1b54a2c8..aacb36c36ce0 100644 --- a/doc/guides/prog_guide/log_lib.rst +++ b/doc/guides/prog_guide/log_lib.rst @@ -5,8 +5,8 @@ Log Library =========== The DPDK Log library provides the logging functionality for other DPDK libraries and drivers. -By default, in a Linux application, logs are sent to syslog and also to the console. -On FreeBSD and Windows applications, logs are sent only to the console. +By default, in a Linux (or FreeBSD) application, logs are sent to syslog and also to the console. +In Windows applications, logs are sent only to the console. However, the log function can be overridden by the user to use a different logging mechanism. Log Levels @@ -29,6 +29,7 @@ will be emitted by the application to the log output. That level can be configured either by the application calling the relevant APIs from the logging library, or by the user passing the ``--log-level`` parameter to the EAL via the application. + Setting Global Log Level ~~~~~~~~~~~~~~~~~~~~~~~~ @@ -59,6 +60,19 @@ For example:: Within an application, the same result can be got using the ``rte_log_set_level_pattern()`` or ``rte_log_set_level_regex()`` APIs. + +Setting syslog facility +~~~~~~~~~~~~~~~~~~~~~~~ + +On Linux and FreeBSD, where syslog is used a ``facility`` argument can be +used to specify what type of program is logging. +The default facility is ``daemon`` but it can be overridden +by the ``--syslog`` EAL parameter. See ``syslog.3`` man page for full values. +For example:: + + /path/to/app --syslog local0 + + Using Logging APIs to Generate Log Messages ------------------------------------------- diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index bab77118e967..a57ee8406f0c 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -53,6 +53,7 @@ #include "eal_options.h" #include "eal_memcfg.h" #include "eal_trace.h" +#include "log_internal.h" #define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL) @@ -760,6 +761,13 @@ rte_eal_init(int argc, char **argv) #endif } + if (eal_log_init(getprogname(), internal_conf->syslog_facility) < 0) { + rte_eal_init_alert("Cannot init logging."); + rte_errno = ENOMEM; + rte_atomic_store_explicit(&run_once, 0, rte_memory_order_relaxed); + return -1; + } + /* in secondary processes, memory init may allocate additional fbarrays * not present in primary processes, so to avoid any potential issues, * initialize memzones first. diff --git a/lib/log/log_freebsd.c b/lib/log/log_freebsd.c deleted file mode 100644 index 698d3c542337..000000000000 --- a/lib/log/log_freebsd.c +++ /dev/null @@ -1,12 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * Copyright(c) 2023 Intel Corporation - */ - -#include -#include "log_internal.h" - -int -eal_log_init(__rte_unused const char *id, __rte_unused int facility) -{ - return 0; -} diff --git a/lib/log/log_linux.c b/lib/log/log_unix.c similarity index 100% rename from lib/log/log_linux.c rename to lib/log/log_unix.c diff --git a/lib/log/meson.build b/lib/log/meson.build index 0d4319b36f77..60516a0b2a2d 100644 --- a/lib/log/meson.build +++ b/lib/log/meson.build @@ -2,8 +2,12 @@ # Copyright(c) 2023 Intel Corporation includes += global_inc -sources = files( - 'log.c', - 'log_' + exec_env + '.c', -) +sources = files('log.c') + +if is_windows + sources += files('log_windows.c') +else + sources += files('log_unix.c') +endif + headers = files('rte_log.h') From patchwork Thu Mar 21 16:00:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138669 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 9D03043D17; Thu, 21 Mar 2024 17:18:56 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 070BD42E2B; Thu, 21 Mar 2024 17:18:53 +0100 (CET) Received: from mail-ot1-f43.google.com (mail-ot1-f43.google.com [209.85.210.43]) by mails.dpdk.org (Postfix) with ESMTP id C636C42DF5 for ; Thu, 21 Mar 2024 17:18:49 +0100 (CET) Received: by mail-ot1-f43.google.com with SMTP id 46e09a7af769-6e67cf739d0so610569a34.1 for ; Thu, 21 Mar 2024 09:18:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711037929; x=1711642729; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JV9iooaRFKWJsG/qcC/BNXRXSAU9mzx1fb/qZlAxld4=; b=ENSzjwo6lVlsZ6vWtKs1Or0lpP/zO5oKNh8Jdw7gMMI38ECQohpugS035o5dZnRGgL 8yFegueNR4tmGDvIfVEzxSQGPkNKHoqhfn3C9AhaU/SjsALYo0yZ+49pu0s5DiFOP9oL He9Zx2BniisaPyEaAAnQRJHafQlqkNnBD3DGo5oprqrid5u3qG8E3z6IwHQP2fPcR03R 6oN4KpbzW5PbAQv7pzWHFhG9sBAbZlCEg7gHknSPaRzPfgod78uYOKMaAJogAUI2WEuo 4XpuOV0I06ky+SAy7n8e7o1nSqJGOy6R8BpPDTU19KihKXdpBl77qSF0uNlfaGXhxRxN iQTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711037929; x=1711642729; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JV9iooaRFKWJsG/qcC/BNXRXSAU9mzx1fb/qZlAxld4=; b=gj8foD9E7LUCofNZGHppXh8pchnq7Tg7Nz0f3Lz248zCu76syZlUMwmdE/RjmleqnH //MMo+Fss4mKwmW7jp5+PSJz+gUZqy4GejsKI5mtQ/5aIXbLM7QFVfPJ+Vbmul6V7yDZ JoH0wQdWJ8g2QSJAvB9dz5eTLC9KXB1aEPbWWr6QD5KqUGh241Vo2qVzPoNrgGtvvVLn 90LiBo8PzouCGSJFkdkyRR0Rf1+WpZ9BMTD+muGkbHdvl/5V/7dHsiqHni9xY6DAjZml Fx9j3svsLva2qKNo3GgGCxyBRKtCbflky7ZH79P7+lQNYg6IjUjJxcwLenv8/V5fxQRa H9uQ== X-Gm-Message-State: AOJu0Yzn6VpgCH8aaSoHitHucbFF3h2P7TT+YtWfqVwY/HnzIICqFnqX t5YH6DvT3s0kWY2/s7RudhKVqrqN+NGVCLvPGPGTrwj3vtHnMjUO8/Z/vA+frmtnc4Q7dVn1qTo e X-Google-Smtp-Source: AGHT+IHzZfken6osKM7EkSPxM2N1K9/ZLONPWLmRqP/n+4unp7/gIZVD+yHyaOd3WK896M0XLTTm1Q== X-Received: by 2002:a05:6a20:8f08:b0:1a1:6a75:1442 with SMTP id b8-20020a056a208f0800b001a16a751442mr21824846pzk.11.1711037518714; Thu, 21 Mar 2024 09:11:58 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id w62-20020a638241000000b005e485fbd455sm41815pgd.45.2024.03.21.09.11.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 09:11:58 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v10 03/10] eal: make eal_log_level_parse common Date: Thu, 21 Mar 2024 09:00:19 -0700 Message-ID: <20240321161146.340421-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240321161146.340421-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240321161146.340421-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The code to parse for log-level option should be same on all OS variants. Signed-off-by: Stephen Hemminger Acked-by: Tyler Retzlaff --- lib/eal/common/eal_common_options.c | 46 +++++++++++++++++++++++++++++ lib/eal/common/eal_options.h | 1 + lib/eal/freebsd/eal.c | 42 -------------------------- lib/eal/linux/eal.c | 39 ------------------------ lib/eal/windows/eal.c | 35 ---------------------- 5 files changed, 47 insertions(+), 116 deletions(-) diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index e541f0793964..7310d10dfd78 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -1640,6 +1640,51 @@ eal_parse_huge_unlink(const char *arg, struct hugepage_file_discipline *out) return -1; } +/* Parse the all arguments looking for --log-level */ +int +eal_log_level_parse(int argc, char * const argv[]) +{ + struct internal_config *internal_conf = eal_get_internal_configuration(); + int option_index, opt; + const int old_optind = optind; + const int old_optopt = optopt; + const int old_opterr = opterr; + char *old_optarg = optarg; +#ifdef RTE_EXEC_ENV_FREEBSD + const int old_optreset = optreset; + optreset = 1; +#endif + + optind = 1; + opterr = 0; + + while ((opt = getopt_long(argc, argv, eal_short_options, + eal_long_options, &option_index)) != EOF) { + + switch (opt) { + case OPT_LOG_LEVEL_NUM: + if (eal_parse_common_option(opt, optarg, internal_conf) < 0) + return -1; + break; + case '?': + /* getopt is not happy, stop right now */ + goto out; + default: + continue; + } + } +out: + /* restore getopt lib */ + optind = old_optind; + optopt = old_optopt; + optarg = old_optarg; + opterr = old_opterr; +#ifdef RTE_EXEC_ENV_FREEBSD + optreset = old_optreset; +#endif + return 0; +} + int eal_parse_common_option(int opt, const char *optarg, struct internal_config *conf) @@ -2173,6 +2218,7 @@ rte_vect_set_max_simd_bitwidth(uint16_t bitwidth) return 0; } + void eal_common_usage(void) { diff --git a/lib/eal/common/eal_options.h b/lib/eal/common/eal_options.h index 3cc9cb641284..f3f2e104f6d7 100644 --- a/lib/eal/common/eal_options.h +++ b/lib/eal/common/eal_options.h @@ -96,6 +96,7 @@ enum { extern const char eal_short_options[]; extern const struct option eal_long_options[]; +int eal_log_level_parse(int argc, char * const argv[]); int eal_parse_common_option(int opt, const char *argv, struct internal_config *conf); int eal_option_device_parse(void); diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index a57ee8406f0c..94927472edfe 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -364,48 +364,6 @@ eal_get_hugepage_mem_size(void) return (size < SIZE_MAX) ? (size_t)(size) : SIZE_MAX; } -/* Parse the arguments for --log-level only */ -static void -eal_log_level_parse(int argc, char **argv) -{ - int opt; - char **argvopt; - int option_index; - const int old_optind = optind; - const int old_optopt = optopt; - const int old_optreset = optreset; - char * const old_optarg = optarg; - struct internal_config *internal_conf = - eal_get_internal_configuration(); - - argvopt = argv; - optind = 1; - optreset = 1; - - while ((opt = getopt_long(argc, argvopt, eal_short_options, - eal_long_options, &option_index)) != EOF) { - - int ret; - - /* getopt is not happy, stop right now */ - if (opt == '?') - break; - - ret = (opt == OPT_LOG_LEVEL_NUM) ? - eal_parse_common_option(opt, optarg, internal_conf) : 0; - - /* common parser is not happy */ - if (ret < 0) - break; - } - - /* restore getopt lib */ - optind = old_optind; - optopt = old_optopt; - optreset = old_optreset; - optarg = old_optarg; -} - /* Parse the argument given in the command line of the application */ static int eal_parse_args(int argc, char **argv) diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index fd422f1f6236..bffeb1f34eb9 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -546,45 +546,6 @@ eal_parse_vfio_vf_token(const char *vf_token) return -1; } -/* Parse the arguments for --log-level only */ -static void -eal_log_level_parse(int argc, char **argv) -{ - int opt; - char **argvopt; - int option_index; - const int old_optind = optind; - const int old_optopt = optopt; - char * const old_optarg = optarg; - struct internal_config *internal_conf = - eal_get_internal_configuration(); - - argvopt = argv; - optind = 1; - - while ((opt = getopt_long(argc, argvopt, eal_short_options, - eal_long_options, &option_index)) != EOF) { - - int ret; - - /* getopt is not happy, stop right now */ - if (opt == '?') - break; - - ret = (opt == OPT_LOG_LEVEL_NUM) ? - eal_parse_common_option(opt, optarg, internal_conf) : 0; - - /* common parser is not happy */ - if (ret < 0) - break; - } - - /* restore getopt lib */ - optind = old_optind; - optopt = old_optopt; - optarg = old_optarg; -} - static int eal_parse_huge_worker_stack(const char *arg) { diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c index 52f0e7462dd8..85171b27687e 100644 --- a/lib/eal/windows/eal.c +++ b/lib/eal/windows/eal.c @@ -96,41 +96,6 @@ eal_usage(const char *prgname) } } -/* Parse the arguments for --log-level only */ -static void -eal_log_level_parse(int argc, char **argv) -{ - int opt; - char **argvopt; - int option_index; - struct internal_config *internal_conf = - eal_get_internal_configuration(); - - argvopt = argv; - - eal_reset_internal_config(internal_conf); - - while ((opt = getopt_long(argc, argvopt, eal_short_options, - eal_long_options, &option_index)) != EOF) { - - int ret; - - /* getopt is not happy, stop right now */ - if (opt == '?') - break; - - ret = (opt == OPT_LOG_LEVEL_NUM) ? - eal_parse_common_option(opt, optarg, - internal_conf) : 0; - - /* common parser is not happy */ - if (ret < 0) - break; - } - - optind = 0; /* reset getopt lib */ -} - /* Parse the argument given in the command line of the application */ static int eal_parse_args(int argc, char **argv) From patchwork Thu Mar 21 16:00:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138668 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 C0B5443D17; Thu, 21 Mar 2024 17:18:51 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AD3A942E25; Thu, 21 Mar 2024 17:18:51 +0100 (CET) Received: from mail-oa1-f47.google.com (mail-oa1-f47.google.com [209.85.160.47]) by mails.dpdk.org (Postfix) with ESMTP id 46DE942DF5 for ; Thu, 21 Mar 2024 17:18:46 +0100 (CET) Received: by mail-oa1-f47.google.com with SMTP id 586e51a60fabf-22963f0e12cso558618fac.1 for ; Thu, 21 Mar 2024 09:18:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711037925; x=1711642725; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yzObJr6ChIwzux7DbvCuaGZqdyle5ax9Ncxqa7ENDn0=; b=rVCNHq5KvGJCsrw02nbZXTYDmvCbj3qpwRZsq2pxruxgahbce3RSzOTg4XUto1JL2I XB+R//lSI5kU9nC2opmA7bAauFPK0Q9iM4U3Q4HUX7/EN+Bf4TpktCEnqF5PQqHAWS5f cZRwa8OkjLjOKQY0d2lKiLTMXlypsj2d89my1RvfHWZpCLhW1THH/ZQvXjiircUr8W9R P6VgBI9kE92gzCwrgTq/kakJiQuNbkzCVyizuihAb1LEATZJAgdf5l5W9oQZrlUO+Oug i942FlCVaH9XW/JBcb/Knjp9oCJcOww5tBARa5UC46C9z4qaGzQHDE4uRX6vcapeJj77 ZYyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711037925; x=1711642725; 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=yzObJr6ChIwzux7DbvCuaGZqdyle5ax9Ncxqa7ENDn0=; b=eR+iwgEeU5kG1l2OAg0+AyZkYFaUcdg3P6jVn8RWj+N6mWbuTmZlKO7C+R+IkzTaVZ S7nW9Bib2DdBjJlcXRQbhtXvXejUVmFnO2j0DLNHJeRRSXI14xA9V9yxmU5HJoxSt7eg +L04NB321aX+4ym1eFNOnCaP6VM98o3Mi460j/7ioW/DHRjRq4tyQEcEl7SSyg0/VAZw Z53EC3OOP80xneK/lCu1DEU29pLMCkMClJCddC4GHjK0VMZtCQGVcLzMMg9D73KGDCH+ T9eU4m8NkJ+AWIS1eZO7rpBHIAbIw1xWL418pje0jvMyia8bCx+gD+/jgK6xUaBgWkRB nDrg== X-Gm-Message-State: AOJu0YzZ99ZN/vWexZ8vmbfIIsIk+Xv691H4NvTZzKtBWfPz9pUSSoZy U198ZVVlcHU1/4BMliKNZY9Yop9V/BR8DeRebTNwns5+3zSR2MIaWFH77qdcynoAtPjZzwhCtBe H X-Google-Smtp-Source: AGHT+IEsdB49fSUDvWcD7XDRMO2W8sUZKNSfdM+d86FSfRO1VqD/VKOrX34mG9lK+EotWozVC79Aew== X-Received: by 2002:a05:6a20:ba9c:b0:1a3:4e19:183c with SMTP id fb28-20020a056a20ba9c00b001a34e19183cmr6647454pzb.52.1711037519369; Thu, 21 Mar 2024 09:11:59 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id w62-20020a638241000000b005e485fbd455sm41815pgd.45.2024.03.21.09.11.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 09:11:59 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v10 04/10] eal: initialize log earlier in startup Date: Thu, 21 Mar 2024 09:00:20 -0700 Message-ID: <20240321161146.340421-5-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240321161146.340421-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240321161146.340421-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Want to make sure that as many log messages as possible get added with the real log stream. Despite the comment, there is no dependency on memzones in current code. Signed-off-by: Stephen Hemminger --- lib/eal/freebsd/eal.c | 14 +++++++------- lib/eal/linux/eal.c | 16 ++++++++-------- lib/eal/unix/eal_unix_log.c | 0 lib/log/log_unix.c | 4 ++-- 4 files changed, 17 insertions(+), 17 deletions(-) create mode 100644 lib/eal/unix/eal_unix_log.c diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index 94927472edfe..777770176339 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -571,6 +571,13 @@ rte_eal_init(int argc, char **argv) /* set log level as early as possible */ eal_log_level_parse(argc, argv); + if (eal_log_init(getprogname(), internal_conf->syslog_facility) < 0) { + rte_eal_init_alert("Cannot init logging."); + rte_errno = ENOMEM; + rte_atomic_store_explicit(&run_once, 0, rte_memory_order_relaxed); + return -1; + } + if (rte_eal_cpu_init() < 0) { rte_eal_init_alert("Cannot detect lcores."); rte_errno = ENOTSUP; @@ -719,13 +726,6 @@ rte_eal_init(int argc, char **argv) #endif } - if (eal_log_init(getprogname(), internal_conf->syslog_facility) < 0) { - rte_eal_init_alert("Cannot init logging."); - rte_errno = ENOMEM; - rte_atomic_store_explicit(&run_once, 0, rte_memory_order_relaxed); - return -1; - } - /* in secondary processes, memory init may allocate additional fbarrays * not present in primary processes, so to avoid any potential issues, * initialize memzones first. diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index bffeb1f34eb9..e515f3cbc8a8 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -959,6 +959,14 @@ rte_eal_init(int argc, char **argv) /* clone argv to report out later in telemetry */ eal_save_args(argc, argv); + if (eal_log_init(program_invocation_short_name, + internal_conf->syslog_facility) < 0) { + rte_eal_init_alert("Cannot init logging."); + rte_errno = ENOMEM; + rte_atomic_store_explicit(&run_once, 0, rte_memory_order_relaxed); + return -1; + } + if (rte_eal_cpu_init() < 0) { rte_eal_init_alert("Cannot detect lcores."); rte_errno = ENOTSUP; @@ -1107,14 +1115,6 @@ rte_eal_init(int argc, char **argv) #endif } - if (eal_log_init(program_invocation_short_name, - internal_conf->syslog_facility) < 0) { - rte_eal_init_alert("Cannot init logging."); - rte_errno = ENOMEM; - rte_atomic_store_explicit(&run_once, 0, rte_memory_order_relaxed); - return -1; - } - #ifdef VFIO_PRESENT if (rte_eal_vfio_setup() < 0) { rte_eal_init_alert("Cannot init VFIO"); diff --git a/lib/eal/unix/eal_unix_log.c b/lib/eal/unix/eal_unix_log.c new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/lib/log/log_unix.c b/lib/log/log_unix.c index 2dfb0c974b1d..ae38b4bf3a59 100644 --- a/lib/log/log_unix.c +++ b/lib/log/log_unix.c @@ -41,8 +41,8 @@ static cookie_io_functions_t console_log_func = { }; /* - * set the log to default function, called during eal init process, - * once memzones are available. + * set the log to default function, called early in eal init process; + * before lcore's and memzones are setup. */ int eal_log_init(const char *id, int facility) From patchwork Thu Mar 21 16:00:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138671 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 1127743D17; Thu, 21 Mar 2024 17:19:22 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E955F42E19; Thu, 21 Mar 2024 17:19:21 +0100 (CET) Received: from mail-qt1-f178.google.com (mail-qt1-f178.google.com [209.85.160.178]) by mails.dpdk.org (Postfix) with ESMTP id 1ACA942E05 for ; Thu, 21 Mar 2024 17:19:20 +0100 (CET) Received: by mail-qt1-f178.google.com with SMTP id d75a77b69052e-42a0ba5098bso8578211cf.0 for ; Thu, 21 Mar 2024 09:19:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711037959; x=1711642759; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OchZbGiqZYOKIHTgrKGiYo+f+aYAEtmo0dzG4HlbOOM=; b=iAQ7QrurP7mVx6kh1tMEjYsjCLcCukZ2W4UHScYIGjhATXQzhNwAB1ok5BrfdLibwF fEeWiEPfERHa4z8rhQOSYRs2NioHkHJM92K5teWPLdX96kF9sfBULOmS2PLrAjsiq5OU 2Gel/vfGZY+s4Co3htkAxuDxhK1U5+6jvteRocZDASiBayr3iIs/5fgmdtK3qkGBoTTR HjCdhWSeXaHxGMsSatj+ecSSFBPdXGvReMZAaEZc+1mOjt8L6W+KrZb7QRUJMzt82CJs Lbh9d21ftr0TyXH2JcEpvL747vTvVUzEg3yO8qnOYc92eZyBcOHNhv1gkQuSRZsDe0dO M7aA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711037959; x=1711642759; 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=OchZbGiqZYOKIHTgrKGiYo+f+aYAEtmo0dzG4HlbOOM=; b=J5AeuPjZF+TlNo606fUifknR2kyq7be53CVngiJJ5i4bOQyE0Vi9TWIvgQGqOAQlBJ ErrikIOMTd6we52vOJ7CuWWSHB51lMzYUVjAy1QlCiA0efIeXju1eCzFoGZTgAMQYCGz ZEyG0ahhGLAIdoKU4oYzbkhaO0e5AAKbQv3kKOB1NmiudePxzvsh1EQfTqGYo0TdGYck TWLNDf+wyEUjEMpHldHlHihBayNyMCiojO9aIuQUeSY3gtartHbBBgVibDGFsibArxVx SLnoRyPz46wM4sUOyTANHwsUnojHHB94+pQA5YIBlC06u2CvwloJYcUm7KKpBGWUy+qo vteg== X-Gm-Message-State: AOJu0YxBGY6dslU4hRKL7YTbkhNWzPJwha33gInpg6znU9cUYq6A84in LuTQXi5xRiq5RRfwpo0oABGbrkhVX8lBNnKA5t2T4v7nBy7v27j1K4OisyMrGxXFtNo7tWtaZ4Z S X-Google-Smtp-Source: AGHT+IF/FnG2u4VU5tIKfxowIopkyowg6LfbVqrj2H5GZvt02yKJvab7NRbLaMKlsIP+k6DyoPzg+Q== X-Received: by 2002:a05:6358:99a6:b0:17b:b52c:c121 with SMTP id j38-20020a05635899a600b0017bb52cc121mr10487051rwb.13.1711037521063; Thu, 21 Mar 2024 09:12:01 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id w62-20020a638241000000b005e485fbd455sm41815pgd.45.2024.03.21.09.12.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 09:12:00 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v10 06/10] eal: change rte_exit() output to match rte_log() Date: Thu, 21 Mar 2024 09:00:22 -0700 Message-ID: <20240321161146.340421-7-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240321161146.340421-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240321161146.340421-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 rte_exit() output format confuses the timestamp and coloring options. Change it to use be a single line with proper prefix. Before: [ 0.006481] EAL: Error - exiting with code: 1 Cause: [ 0.006489] Cannot init EAL: Permission denied After: [ 0.006238] EAL: Error - exiting with code: 1 [ 0.006250] EAL: Cause: Cannot init EAL: Permission denied Signed-off-by: Stephen Hemminger ACked-by: Tyler Retzlaff --- lib/eal/common/eal_common_debug.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/eal/common/eal_common_debug.c b/lib/eal/common/eal_common_debug.c index 3e77995896d5..568883830f20 100644 --- a/lib/eal/common/eal_common_debug.c +++ b/lib/eal/common/eal_common_debug.c @@ -34,17 +34,18 @@ void rte_exit(int exit_code, const char *format, ...) { va_list ap; + char *msg = NULL; if (exit_code != 0) - RTE_LOG(CRIT, EAL, "Error - exiting with code: %d\n" - " Cause: ", exit_code); + EAL_LOG(CRIT, "Error - exiting with code: %d", exit_code); va_start(ap, format); - rte_vlog(RTE_LOG_CRIT, RTE_LOGTYPE_EAL, format, ap); + vasprintf(&msg, format, ap); va_end(ap); + rte_log(RTE_LOG_CRIT, RTE_LOGTYPE_EAL, "EAL: Cause: %s", msg); + if (rte_eal_cleanup() != 0 && rte_errno != EALREADY) - EAL_LOG(CRIT, - "EAL could not release all resources"); + EAL_LOG(CRIT, "EAL could not release all resources"); exit(exit_code); } From patchwork Thu Mar 21 16:00:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138672 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 C073F43D17; Thu, 21 Mar 2024 17:19:27 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 21BF742E3D; Thu, 21 Mar 2024 17:19:23 +0100 (CET) Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) by mails.dpdk.org (Postfix) with ESMTP id 05A6642E1B for ; Thu, 21 Mar 2024 17:19:22 +0100 (CET) Received: by mail-qk1-f178.google.com with SMTP id af79cd13be357-789f1b59a28so75638885a.3 for ; Thu, 21 Mar 2024 09:19:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711037961; x=1711642761; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YasWm7iHbQbdWvAWYjHC7AHoqXZSd0sHra3BoBBQ/fw=; b=DhMVvFflzQpu0+FwkAdWhMQO8dO+IlhqQEjaysW/G81U2e9BZjJMD6rjdMf0lBBQFr Yv/jFuayCRfwdVNTD0ZtOIXpBG4Rq81sQg+XwRO0TmzWzgFoHQhHY9PMRBuYiDHXGPj4 V3hEmV5NL8pFRnzVNCvdo79gZGdbXzhg3VrzTnQ5Xb1/KZG+DP5Yd9XnGkkdwIB48/ex xvaM5v/jadu5A/CXCDouL53Ch8cogM0Cu1oBYkTjrxbipGPmlo4QUYliapjPUsJltBSC UFjzmFMJJCSH4xHjJRkySbx26l24UDYJDPluVPgfxjdMkyDejoHh+/a3hBVeDZkA1CJP uZZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711037961; x=1711642761; 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=YasWm7iHbQbdWvAWYjHC7AHoqXZSd0sHra3BoBBQ/fw=; b=A4nwd7WM6XSli0Hq08ryzLsHMqZxUDUbDkg6DMCk7DZtXbUs5EyOGhNul8g2evXN9a BP005UpG4e01uH/iZxAQoebWdLgHo7STI3A8yrZBMFPHTyL6zGbMsChA3GNFdomSUUVn Pe6ani2V2WslCAdjfHXxQliLz75uMpy2Rpn/fYwbImnnsJ2xUbxbN6TnZpHTBL4fYTab e2i/e/AVidBATDFoLXIHQw56wF6OCzlunydGOkCgIWgDrmMG4A56U+yjvzT9VjIWbQDc WxiGFj2H3KwnXWAVyq5MzCedso75JnAKZ9CtRy6/a8MHssBwpZ/OqS/yvuTKIFDNaoDq BGnQ== X-Gm-Message-State: AOJu0YyrUBjnfxi8Hzbo8Cnaf9GIsA7FGp7+c1vSR1BphqoVgczLlDEF Ao7ZiST69oTtdSmFo3X+a9S2FTnl5G7NZSP6cnTWGB+eKICdihgL5jfBf9S8fBxSVcGVmza39Pi J X-Google-Smtp-Source: AGHT+IFuJ2g+Xz0x4n2/EaHugsIoUMxIK3PsbH/nRpU8fCdWidx402cYQpVvteEikCXqnvgaEv3TLg== X-Received: by 2002:a05:6358:d5aa:b0:17b:416a:38ba with SMTP id ms42-20020a056358d5aa00b0017b416a38bamr24642865rwb.26.1711037522728; Thu, 21 Mar 2024 09:12:02 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id w62-20020a638241000000b005e485fbd455sm41815pgd.45.2024.03.21.09.12.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 09:12:02 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v10 08/10] eal: add option to put timestamp on console output Date: Thu, 21 Mar 2024 09:00:24 -0700 Message-ID: <20240321161146.340421-9-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240321161146.340421-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240321161146.340421-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. There are multiple timestamp formats similar to Linux dmesg. The default is time relative since startup. Other alternatives are delta, ctime, reltime and iso formats. Example: $ dpdk-testpmd --log-timestamp -- -i EAL: Detected CPU lcores: 8 EAL: Detected NUMA nodes: 1 [ 0.000083] EAL: Detected static linkage of DPDK [ 0.002000] EAL: Multi-process socket /var/run/dpdk/rte/mp_socket [ 0.003507] EAL: Selected IOVA mode 'VA' [ 0.006272] testpmd: No probed ethernet devices Interactive-mode selected [ 0.029567] testpmd: create a new mbuf pool : n=203456, size=2176, socket=0 [ 0.029588] testpmd: preferred mempool ops selected: ring_mp_mc Signed-off-by: Stephen Hemminger --- app/test/test_eal_flags.c | 17 ++++ doc/guides/prog_guide/log_lib.rst | 10 ++ lib/eal/common/eal_common_options.c | 14 ++- lib/eal/common/eal_options.h | 2 + lib/log/log_internal.h | 9 ++ lib/log/log_unix.c | 152 +++++++++++++++++++++++++++- lib/log/log_windows.c | 6 ++ lib/log/version.map | 1 + 8 files changed, 205 insertions(+), 6 deletions(-) diff --git a/app/test/test_eal_flags.c b/app/test/test_eal_flags.c index 6cb4b0675730..eeb1799381d7 100644 --- a/app/test/test_eal_flags.c +++ b/app/test/test_eal_flags.c @@ -1055,6 +1055,14 @@ 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" }; + + /* Try running with --log-timestamp=iso */ + const char * const argv24[] = {prgname, prefix, mp_flag, + "--log-timestamp=iso" }; + /* run all tests also applicable to FreeBSD first */ if (launch_proc(argv0) == 0) { @@ -1162,6 +1170,15 @@ 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; + } + if (launch_proc(argv24) != 0) { + printf("Error - process did not run ok with --log-timestamp=iso parameter\n"); + goto fail; + } + rmdir(hugepath_dir3); rmdir(hugepath_dir2); diff --git a/doc/guides/prog_guide/log_lib.rst b/doc/guides/prog_guide/log_lib.rst index aacb36c36ce0..1d6b2e3cea5d 100644 --- a/doc/guides/prog_guide/log_lib.rst +++ b/doc/guides/prog_guide/log_lib.rst @@ -73,6 +73,16 @@ For example:: /path/to/app --syslog local0 +Console timestamp +~~~~~~~~~~~~~~~~~ + +On Linux and FreeBSD, an optional timestamp can be added before each +message by adding the ``--log-timestamp`` option. +For example:: + + /path/to/app --log-level=lib.*:debug --log-timestamp + + Using Logging APIs to Generate Log Messages ------------------------------------------- diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index 7310d10dfd78..4e2c3d0f255c 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -77,6 +77,7 @@ eal_long_options[] = { {OPT_IOVA_MODE, 1, NULL, OPT_IOVA_MODE_NUM }, {OPT_LCORES, 1, NULL, OPT_LCORES_NUM }, {OPT_LOG_LEVEL, 1, NULL, OPT_LOG_LEVEL_NUM }, + {OPT_LOG_TIMESTAMP, 2, NULL, OPT_LOG_TIMESTAMP_NUM }, {OPT_TRACE, 1, NULL, OPT_TRACE_NUM }, {OPT_TRACE_DIR, 1, NULL, OPT_TRACE_DIR_NUM }, {OPT_TRACE_BUF_SIZE, 1, NULL, OPT_TRACE_BUF_SIZE_NUM }, @@ -1663,6 +1664,7 @@ eal_log_level_parse(int argc, char * const argv[]) switch (opt) { case OPT_LOG_LEVEL_NUM: + case OPT_LOG_TIMESTAMP_NUM: if (eal_parse_common_option(opt, optarg, internal_conf) < 0) return -1; break; @@ -1890,7 +1892,7 @@ eal_parse_common_option(int opt, const char *optarg, break; #endif - case OPT_LOG_LEVEL_NUM: { + case OPT_LOG_LEVEL_NUM: if (eal_parse_log_level(optarg) < 0) { EAL_LOG(ERR, "invalid parameters for --" @@ -1898,9 +1900,16 @@ eal_parse_common_option(int opt, const char *optarg, return -1; } break; - } #ifndef RTE_EXEC_ENV_WINDOWS + case OPT_LOG_TIMESTAMP_NUM: + if (eal_log_timestamp(optarg) < 0) { + EAL_LOG(ERR, "invalid parameters for --" + OPT_LOG_TIMESTAMP); + return -1; + } + break; + case OPT_TRACE_NUM: { if (eal_trace_args_save(optarg) < 0) { EAL_LOG(ERR, "invalid parameters for --" @@ -2261,6 +2270,7 @@ eal_common_usage(void) " --"OPT_PROC_TYPE" Type of this process (primary|secondary|auto)\n" #ifndef RTE_EXEC_ENV_WINDOWS " --"OPT_SYSLOG" Set syslog facility\n" + " --"OPT_LOG_TIMESTAMP" Timestamp log output\n" #endif " --"OPT_LOG_LEVEL"= Set global log level\n" " --"OPT_LOG_LEVEL"=:\n" diff --git a/lib/eal/common/eal_options.h b/lib/eal/common/eal_options.h index f3f2e104f6d7..e24c9eca53ca 100644 --- a/lib/eal/common/eal_options.h +++ b/lib/eal/common/eal_options.h @@ -35,6 +35,8 @@ enum { OPT_LCORES_NUM, #define OPT_LOG_LEVEL "log-level" OPT_LOG_LEVEL_NUM, +#define OPT_LOG_TIMESTAMP "log-timestamp" + OPT_LOG_TIMESTAMP_NUM, #define OPT_TRACE "trace" OPT_TRACE_NUM, #define OPT_TRACE_DIR "trace-dir" diff --git a/lib/log/log_internal.h b/lib/log/log_internal.h index c77e687e28bc..0e18d147cf98 100644 --- a/lib/log/log_internal.h +++ b/lib/log/log_internal.h @@ -5,8 +5,10 @@ #ifndef LOG_INTERNAL_H #define LOG_INTERNAL_H +#include #include #include +#include #include @@ -44,4 +46,11 @@ const char *eal_log_level2str(uint32_t level); __rte_internal void rte_eal_log_cleanup(void); +/* + * Add timestamp to console logs + */ +__rte_internal +int eal_log_timestamp(const char *fmt); + + #endif /* LOG_INTERNAL_H */ diff --git a/lib/log/log_unix.c b/lib/log/log_unix.c index c56f80ac6967..cb8f17bc83ef 100644 --- a/lib/log/log_unix.c +++ b/lib/log/log_unix.c @@ -2,28 +2,169 @@ * Copyright(c) 2010-2014 Intel Corporation */ +#include #include +#include #include +#include #include +#include +#include #include #include "log_internal.h" +enum eal_log_time_format { + EAL_LOG_TIMESTAMP_NONE = 0, + EAL_LOG_TIMESTAMP_TIME, /* time since start */ + EAL_LOG_TIMESTAMP_DELTA, /* time since last message */ + EAL_LOG_TIMESTAMP_RELTIME, + EAL_LOG_TIMESTAMP_CTIME, + EAL_LOG_TIMESTAMP_ISO, +}; + +static struct { + enum eal_log_time_format time_format; + struct timespec start_time; + struct timespec last_time; + struct tm last_tm; +} log = { + .time_format = EAL_LOG_TIMESTAMP_NONE, +}; + +int +eal_log_timestamp(const char *str) +{ + if (str == NULL) + log.time_format = EAL_LOG_TIMESTAMP_TIME; + else if (strcmp(str, "notime") == 0) + log.time_format = EAL_LOG_TIMESTAMP_NONE; + else if (strcmp(str, "reltime") == 0) + log.time_format = EAL_LOG_TIMESTAMP_RELTIME; + else if (strcmp(str, "delta") == 0) + log.time_format = EAL_LOG_TIMESTAMP_DELTA; + else if (strcmp(str, "ctime") == 0) + log.time_format = EAL_LOG_TIMESTAMP_CTIME; + else if (strcmp(str, "iso") == 0) + log.time_format = EAL_LOG_TIMESTAMP_ISO; + else + return -1; + + return 0; +} + +static struct timespec +timespec_sub(const struct timespec *t0, const struct timespec *t1) +{ + struct timespec ts; + + ts.tv_sec = t0->tv_sec - t1->tv_sec; + ts.tv_nsec = t0->tv_nsec - t1->tv_nsec; + if (ts.tv_nsec < 0) { + ts.tv_sec--; + ts.tv_nsec += 1000000000L; + } + return ts; +} + +static ssize_t +console_log_timestamp(char *tsbuf, size_t tsbuflen) +{ + struct timespec now, ts; + struct tm *tm, cur; + + switch (log.time_format) { + case EAL_LOG_TIMESTAMP_NONE: + return 0; + + case EAL_LOG_TIMESTAMP_TIME: + if (clock_gettime(CLOCK_MONOTONIC, &now) < 0) + return 0; + + ts = timespec_sub(&now, &log.start_time); + + return snprintf(tsbuf, tsbuflen, "%6lu.%06lu", + ts.tv_sec, ts.tv_nsec / 1000u); + + case EAL_LOG_TIMESTAMP_DELTA: + if (clock_gettime(CLOCK_MONOTONIC, &now) < 0) + return 0; + + ts = timespec_sub(&now, &log.last_time); + log.last_time = now; + + return snprintf(tsbuf, tsbuflen, "<%6lu.%06lu>", + ts.tv_sec, ts.tv_nsec / 1000u); + + case EAL_LOG_TIMESTAMP_RELTIME: + if (clock_gettime(CLOCK_REALTIME, &now) < 0) + return 0; + + tm = localtime_r(&now.tv_sec, &cur); + ts = timespec_sub(&now, &log.last_time); + log.last_time = now; + + /* if minute, day, hour hasn't changed then print delta */ + if (cur.tm_min != log.last_tm.tm_min || + cur.tm_hour != log.last_tm.tm_hour || + cur.tm_yday != log.last_tm.tm_yday) { + log.last_tm = cur; + return strftime(tsbuf, tsbuflen, "%b%e %H:%M", tm); + } else { + return snprintf(tsbuf, tsbuflen, "+%4lu.%06lu", + ts.tv_sec, ts.tv_nsec / 1000u); + } + + case EAL_LOG_TIMESTAMP_CTIME: { + char cbuf[32]; /* "Wed Jun 30 21:49:08 1993\n" */ + + if (clock_gettime(CLOCK_REALTIME, &now) < 0) + return 0; + + /* .24s is to remove newline from ctime result */ + return snprintf(tsbuf, tsbuflen, "%.24s", + ctime_r(&now.tv_sec, cbuf)); + } + + case EAL_LOG_TIMESTAMP_ISO: { + char dbuf[64]; /* "2024-05-01T22:11:00" */ + if (clock_gettime(CLOCK_REALTIME, &now) < 0) + return 0; + tm = localtime_r(&now.tv_sec, &cur); + + /* make "2024-05-01T22:11:00,123456+0100" */ + if (strftime(dbuf, sizeof(dbuf), "%Y-%m-%dT%H:%M:%S", tm) == 0) + return 0; + + return snprintf(tsbuf, tsbuflen, "%s,%06lu%+03ld:%02ld", dbuf, + now.tv_nsec / 1000u, + tm->tm_gmtoff / 3600, + (tm->tm_gmtoff / 60) % 60); + } + } + + return 0; +} + /* * default log function */ static ssize_t -console_log_write(__rte_unused void *c, const char *buf, size_t size) +console_log_write(__rte_unused void *c, const char *msg, size_t size) { + char buf[128]; ssize_t ret; - /* write on stderr */ - ret = fwrite(buf, 1, size, stderr); + ret = console_log_timestamp(buf, sizeof(buf)); + if (ret == 0) + ret = fwrite(msg, 1, size, stderr); + else + ret = fprintf(stderr, "[%s] %.*s", buf, (int)size, msg); 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); + syslog(rte_log_cur_msg_loglevel() - 1, "%.*s", (int)size, msg); return ret; } @@ -49,6 +190,9 @@ eal_log_init(const char *id, int facility) { FILE *log_stream; + clock_gettime(CLOCK_MONOTONIC, &log.start_time); + log.last_time = log.start_time; + /* skip if user has already setup a log stream */ if (eal_log_get_default()) return 0; diff --git a/lib/log/log_windows.c b/lib/log/log_windows.c index a6a08895501e..8aa68a181bec 100644 --- a/lib/log/log_windows.c +++ b/lib/log/log_windows.c @@ -6,6 +6,12 @@ #include #include "log_internal.h" +int +eal_log_timestamp(__rte_unused const char *fmt) +{ + return -1; /* not implemented */ +} + /* set the log to default function, called during eal init process. */ int eal_log_init(__rte_unused const char *id, __rte_unused int facility) diff --git a/lib/log/version.map b/lib/log/version.map index 6ecc656d1d65..697cdb3cb1b2 100644 --- a/lib/log/version.map +++ b/lib/log/version.map @@ -31,5 +31,6 @@ INTERNAL { eal_log_save_pattern; eal_log_save_regexp; eal_log_set_default; + eal_log_timestamp; rte_eal_log_cleanup; };