From patchwork Sun Mar 24 02:33:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138754 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 9044C43D36; Sun, 24 Mar 2024 03:41:27 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8EBF4402E4; Sun, 24 Mar 2024 03:41:24 +0100 (CET) Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by mails.dpdk.org (Postfix) with ESMTP id 8CE0C402D0 for ; Sun, 24 Mar 2024 03:41:21 +0100 (CET) Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1dddb160a37so22163065ad.2 for ; Sat, 23 Mar 2024 19:41:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711248080; x=1711852880; 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=j2bWaQew6uFbTYM7AsbymK+bBIaNZpLFH5iS8177eDI=; b=12yHgDu+SFnE0rVt1vCKKu6CMZXlAZ3svfE8hyLzNouJFQec2Wo6spbvOfsCPj3VMI 6o+dL/vTi4RF5Fn/hdamc4YZxOXxQLGRgxv/5aT/ntBUmI3ZNMhNZS1vIw0kf7bGd1Rf vvM9IZa6qQXlKRG+VWwK0VHQ4yIvoshyhBzjr8f3Vt8NnPgsRLvV3k34H/PLsSjf0gvX VpVKwnIcXMr39Tl7ubAQZ8ZjNseNCWgzCQh2mULX5zMp8lUMRBg1tTATy9538ACjrg+R iftEWv/X/kDc/jUM7ccIfN80Zmm4MuFO5gxnb0d9ukkLaMIH7nBuEasslz3n9XqdbY6C /F7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711248080; x=1711852880; 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=j2bWaQew6uFbTYM7AsbymK+bBIaNZpLFH5iS8177eDI=; b=GCC6t0iFnX8XpijRaNG6+PZkp06XrCk55BDyH0SjZtVpbeWwrN0cUN52UiVMt0pEks SJM/bWkliWjyoUwg03EGHMt06ABLTe+j7BYsFMDURNBxwkm3ZX8hqHiqxgxQze6awaC/ evun+DRUvYpx+2HA6bSsv2CnwA0430/CyLw4J9wI8WdB7REnaGLFulnPnx05Sxc94K7U lAHzbgV63Fh8k3YoBpjKtnhxJn6T6jcUYQDu9miiEqi9b8x3clsXF7C0x79OegZgrBMG Dyx4ACb//Il/V4xEBwUhgyYmrApr4T7KM/XoC8cvMwPa9ZCnKYGGQCE3lmVS2v2UiZbS /yGA== X-Gm-Message-State: AOJu0Yw/OSup3gEdGWnxJLYYvw7tJhE0HyHCnbbKiEsR6Xrn4QuWprlz PGgHODGGX/WGSGx0Bcij0FTU3n0CB60UJVSHmMMUgKAT8OkYd9ZBqTTcyxjRHbv/d7rdTD8agEw B X-Google-Smtp-Source: AGHT+IGMB8EHbNHYCgD6QdcwCa4YQyiR8L1vOmcYTi8wyzC/rPt4iMjlKZzSdBunN6YTPjAhIJ1F0Q== X-Received: by 2002:a17:902:dac5:b0:1e0:2e3f:f192 with SMTP id q5-20020a170902dac500b001e02e3ff192mr5592159plx.8.1711248080593; Sat, 23 Mar 2024 19:41:20 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id q17-20020a17090311d100b001dc3c4e7a12sm2244980plh.14.2024.03.23.19.41.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Mar 2024 19:41:20 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff , Dmitry Kozlyuk , Pallavi Kadam Subject: [PATCH v11 1/9] windows: make getopt functions have const properties Date: Sat, 23 Mar 2024 19:33:23 -0700 Message-ID: <20240324024109.306614-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324024109.306614-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240324024109.306614-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 a1f51c6c23..50ff71b930 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 6f57af454b..e4cf6873cb 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 Sun Mar 24 02:33: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: 138755 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 4519343D36; Sun, 24 Mar 2024 03:41:35 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BA6B9402EA; Sun, 24 Mar 2024 03:41:25 +0100 (CET) Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by mails.dpdk.org (Postfix) with ESMTP id 60473402E0 for ; Sun, 24 Mar 2024 03:41:22 +0100 (CET) Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1df01161b39so25798285ad.3 for ; Sat, 23 Mar 2024 19:41:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711248081; x=1711852881; 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=f6tCps+0XpQikSg0Doh2bMyt6EnKWqar1kRpXEF+gQ8=; b=QF9yiHyGU2tsXSoEOOTuqhePv27OCpbt6rFl8oaZpvdXU4Bw7rUBpSVxz8xGKyPaIx R6BTj4Q50lPXUBq7vtrXSIb4Ap87y/KnugoCoR7gcTlwN30bWwf5jHZGGvJjThyZCZle 5XYwbG3OXZQ0hOem0a4DrgoTHS7C9xoiP4AquXIpj+7JukZZHbdSCejDt9XTjFdTafSd OIFtEoHK7eaOnrZnsEEQiBPDuRCegLh8DWDer7VqWXtLilbK4HrP4omOhNWIb/WcCB0m o/x7G4qBOjqqcbTAdsowyuc3HD3R3H1tj5C8qOFKU19/W3kQJrLPF3C78EsvJfGp2E42 SLsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711248081; x=1711852881; 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=f6tCps+0XpQikSg0Doh2bMyt6EnKWqar1kRpXEF+gQ8=; b=t9z4mGc4Xs/XTJTX9V9Q3zCXD6CA2B7ReV3yXUxXuoi9FX3qWE+prv4rgSbmIAxvCY BFfg6SaxGZiGwhl/ixhVEHCfJVbv55qPHsRVYUpLKNkUwdHd7hbV6bb3iGuF5AaYU3FX flJCrzv8SsLeeJfCW20Z4x1nj9Q6o/SBt7CVKpeVBV3zXjOdOle8i/6J9U0RYs55bvJG kXrlbr55JvJvGJWAA3ZwVGge6lXI5E2kSUGDfV+cCeB9j5qqLxa4EcA6TRXgZnb3rWv7 9xS+Js7j8QuHg37SiGNNWSQhOaRvwTc9FkVgMQB8LcAhFBsSEypyvllmDos4OQslER6l IgUQ== X-Gm-Message-State: AOJu0Yw9EDhAFTzgo6JKl7rJMC1c7pApScRYmWLTjLRRlFmE4wAWYjd8 PLsB1eKme7NL5LnAGYRjDg3obzMQdsDjr0uZ/OsmMATjNmFU5bNVLjx+G7DDcZa07jZ3WxQVMEc U X-Google-Smtp-Source: AGHT+IFk7vlrsdZH+b3QKpDmV+Pktx6iGp59akYQ+xw3nelVVysAI0wm6URsqFP7DyStJKWtE4dE/g== X-Received: by 2002:a17:903:248:b0:1e0:8651:1c71 with SMTP id j8-20020a170903024800b001e086511c71mr4406650plh.50.1711248081488; Sat, 23 Mar 2024 19:41:21 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id q17-20020a17090311d100b001dc3c4e7a12sm2244980plh.14.2024.03.23.19.41.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Mar 2024 19:41:21 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Bruce Richardson , Dmitry Kozlyuk , Tyler Retzlaff , Pallavi Kadam Subject: [PATCH v11 2/9] eal: make eal_log_level_parse common Date: Sat, 23 Mar 2024 19:33:24 -0700 Message-ID: <20240324024109.306614-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324024109.306614-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240324024109.306614-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The code to parse for log-level option should be same on all OS variants. Signed-off-by: Stephen Hemminger --- lib/eal/common/eal_common_options.c | 46 +++++++++++++++++++++++++++++ lib/eal/common/eal_options.h | 1 + lib/eal/freebsd/eal.c | 42 -------------------------- lib/eal/linux/eal.c | 39 ------------------------ lib/eal/windows/eal.c | 35 ---------------------- 5 files changed, 47 insertions(+), 116 deletions(-) diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index e541f07939..5435399b85 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 related ones */ +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 3cc9cb6412..f3f2e104f6 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 bab77118e9..9825bcea0b 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -363,48 +363,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 fd422f1f62..bffeb1f34e 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 52f0e7462d..85171b2768 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 Sun Mar 24 02:33:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138756 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 C063E43D36; Sun, 24 Mar 2024 03:41:42 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EFCD4402F0; Sun, 24 Mar 2024 03:41:26 +0100 (CET) Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) by mails.dpdk.org (Postfix) with ESMTP id 2D53E402E3 for ; Sun, 24 Mar 2024 03:41:23 +0100 (CET) Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-29fbe140c24so2349164a91.0 for ; Sat, 23 Mar 2024 19:41:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711248082; x=1711852882; 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=H26hsjphdH2pd0aElhNbFTheietDSMGNDC4gVBIN+HU=; b=kcP1GWukIhSMgrBWzIvakimaSkBqpHj9qnKXs6MltfnuunIjBFpHyEkWjoJL0rlHlC 4BELFvt2hBch2409qBH30ZWyDobeVbYZ2Odk3V9pHzy/xzAVUJuAPt8ksvGrmsqxcZ3o 0mCoh0G5fjyd5jN6Kmgn0KfXlR2x696WIxQ2cSRbdJrFcobZvx2hxd7AeYpfD8DNHBJy CfGqDtpeWM88imrZU6DGeoKQf1E8rXAWpzAMSmzADcy9L51KAKNNj6riz7W2+qpb7LP0 CC7xuyBtXqKfiZX+WNgIYvj1SCpvBOJpeucaVCDmfxSzc4Uf6n6fQF17KaIxlA0R5Q85 GGnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711248082; x=1711852882; 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=H26hsjphdH2pd0aElhNbFTheietDSMGNDC4gVBIN+HU=; b=N/A7UnReMcqcSUSe3OMmls+kXV3XAJyqohpG6BH1+AezG6Zwn44QeEG+NoxbAEKwW9 F1obXVcKD0/atng2l7F7fIk4DyDE7U4WDnpAmtJ11QR0uu/bSkABfneEo5/ZRG+dU9HE 5dJjmqGd4fiDYh7Yg47KA2mKZ6zgtc9zzlXoTs4xvYgY5Xxjn1Xnpp03aoIwqzlVO/K1 8qpyk885s1csreaAvzYBNrlyoxoXfybZQsJ9ncsh9mtIpL+9lnWm+sniiInWnCsw4qSU IkznUqAhNoANOj6go4oY5ynJJJjZdskElFfGblbLwu2/z9nmUGQJ1hyvk3C5yLv+DAUE 1yaA== X-Gm-Message-State: AOJu0YxcoH/Won8DSlpOXdS8JvDTbhIzb/Q2X2GMFjV1AuuoDqjmbcz5 vzQd6NG/DS4ihg7H/l5BPKOQ1+F8XThgaEbnaVt9OsnOAimhQNOiI9ZWnql7ElYtrNa9a13MxH4 g X-Google-Smtp-Source: AGHT+IFfvx85PusfXZ817p8aWD5Gfo/kv9qK/jA7+z1+kDEhPiVZulGfwHzXPEbY3St8Yo+ZyjqFow== X-Received: by 2002:a17:902:d2cf:b0:1de:f840:fb22 with SMTP id n15-20020a170902d2cf00b001def840fb22mr4378484plc.12.1711248082294; Sat, 23 Mar 2024 19:41:22 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id q17-20020a17090311d100b001dc3c4e7a12sm2244980plh.14.2024.03.23.19.41.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Mar 2024 19:41:21 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Bruce Richardson Subject: [PATCH v11 3/9] eal: do not duplicate rte_init_alert() messages Date: Sat, 23 Mar 2024 19:33:25 -0700 Message-ID: <20240324024109.306614-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324024109.306614-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240324024109.306614-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 message already goes through logging, and does not need to be printed on stderr. Message level should be ALERT to match function name. Signed-off-by: Stephen Hemminger --- lib/eal/freebsd/eal.c | 3 +-- lib/eal/linux/eal.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index 9825bcea0b..17b56f38aa 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -529,8 +529,7 @@ rte_eal_iopl_init(void) static void rte_eal_init_alert(const char *msg) { - fprintf(stderr, "EAL: FATAL: %s\n", msg); - EAL_LOG(ERR, "%s", msg); + EAL_LOG(ALERT, "%s", msg); } /* Launch threads, called at application init(). */ diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index bffeb1f34e..23dc26b124 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -840,8 +840,7 @@ static int rte_eal_vfio_setup(void) static void rte_eal_init_alert(const char *msg) { - fprintf(stderr, "EAL: FATAL: %s\n", msg); - EAL_LOG(ERR, "%s", msg); + EAL_LOG(ALERT, "%s", msg); } /* From patchwork Sun Mar 24 02:33:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138757 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 82A0143D36; Sun, 24 Mar 2024 03:41:52 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8FDD04064E; Sun, 24 Mar 2024 03:41:29 +0100 (CET) Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) by mails.dpdk.org (Postfix) with ESMTP id 0A8B1402E3 for ; Sun, 24 Mar 2024 03:41:24 +0100 (CET) Received: by mail-pj1-f50.google.com with SMTP id 98e67ed59e1d1-29df3333d30so2264893a91.1 for ; Sat, 23 Mar 2024 19:41:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711248083; x=1711852883; 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=w0CHwUH99LTRr59BzckESo/nF08qFhhomDRK57rezcs=; b=1KpBIkMZ2RgCtWpfA/sPyBk8J9ZbioI32dKt/JEp6qcTHooPgYI3vfQYoEbpDcXKUx vvXkIjDhbDbFz/EB3hAb3H2kN9V1vysg2w38ndE/nsPNAz58P7tkhGWd2R87K/cRjyBX hDu2BLVQv+1F0OVhN9ZJBPTMA7aCv9LPkPfCcgVoywuCuvud4uXD41rvuwj6Mnn1yEnk DF7XFenMuDMinICJhdHboIaq/7abGxBntGjfEMeRj9GPopzEnSv6w1UnoaIfqhIbYMFT romgYmgGZMyCkeO63xncImyH5ebBKEL2Q4/Oy5SSkcNrwP/xdljZIq6cO/AW/2JRoSNr Egvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711248083; x=1711852883; 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=w0CHwUH99LTRr59BzckESo/nF08qFhhomDRK57rezcs=; b=O0Cdau+mIrd2bGQbKOdJ+QcNTQGFYW+dOo/YCi+4dqObrGPqTyxWgjGZhVBay2UxTQ DdjY40SlsEYw7THvG0i0JBw6bn2E6eWyHnvv77nk3PvpFbS4bFfYILlhTZJNgHCXtzjc cHjTYTHJOr8DCbJFY/91OX2m+ZQJ1xVZ1SfnlpZuATbkIh+3eG7jDYEn5gQR8ZQwHNRo IuDYuc3URIVcl7OEj11FQpXATpE5HEV53brcML60p7OCM5mpNljjPuedV0Wxznncw0hG a5/MI+3eVfTAsoW7xr1NqoGwJh6EhGDOHsoJ0278Pknla2UJOFLTFxWrVJb2kRM2WHsT 0XIg== X-Gm-Message-State: AOJu0YyfX6txxpmATdZxp4SnQJbsTWH+DUKr02QJibKWE3ITpWrMEi9J z8OsClXTIXC3D+k4N1nw3a5dq2omtD9tyGCNya3dIn720W3esS8yziahFeTvtA39wKfXBL+fEUU Y X-Google-Smtp-Source: AGHT+IEcrGZgiXY9dA6MgMMKrxisAQTLMSL4EHT3h00735eZOVAVwGs7guiBAWiZbPBdScoS61iUdQ== X-Received: by 2002:a05:6a20:6013:b0:1a3:7327:2312 with SMTP id r19-20020a056a20601300b001a373272312mr2749848pza.55.1711248083300; Sat, 23 Mar 2024 19:41:23 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id q17-20020a17090311d100b001dc3c4e7a12sm2244980plh.14.2024.03.23.19.41.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Mar 2024 19:41:22 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v11 4/9] eal: change rte_exit() output to match rte_log() Date: Sat, 23 Mar 2024 19:33:26 -0700 Message-ID: <20240324024109.306614-5-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324024109.306614-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240324024109.306614-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 --- 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 3e77995896..3f37879144 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 Sun Mar 24 02:33:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138758 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 ADAF543D36; Sun, 24 Mar 2024 03:41:59 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A7EAA40689; Sun, 24 Mar 2024 03:41:30 +0100 (CET) Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by mails.dpdk.org (Postfix) with ESMTP id 51494402AB for ; Sun, 24 Mar 2024 03:41:25 +0100 (CET) Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-29de4c33441so2337740a91.1 for ; Sat, 23 Mar 2024 19:41:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711248084; x=1711852884; 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=x+QpptczmU2HgT37jnycUV0rw2tHsNceQn+7f8+yssk=; b=JS9bxvYz1gjwO0DuXfbPzUX2XpNETc0q0bL5hi/d7ISlhe6x2V9BCBcNgImKmjUgHG GRrZ8CWXJGLOKsryzUd+exNBqymuQwl040XIE21kIGFnAjoIfFltiAQWYZ9Fl/YfjH5V htgERFi6QwYgD/lW63UTe6uK0hggFi5/JYRjujjXCKI/M2BrkzIs/bS+hNBNg/ClMU6E V4DL/BcrPd0knb4chRqTYdHldL0ZpTaQRkn+BKJHsspE+AvNxRumW9I0xO2aqrKSdVDo y6apI81WxdZUFGbDUAyvy1McEpR3ICTBd2FSq+VrGOrWluaEFCUE5BckAUWKDMG1x3xg 8MGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711248084; x=1711852884; 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=x+QpptczmU2HgT37jnycUV0rw2tHsNceQn+7f8+yssk=; b=vPXLmbRbQuAZPoyHfaDLRnBdHRhM4n+Ozwab61mGjiOTLKOdj65XLOL4Tw/CPieb1N TysuPtPvi6wZfdZGP/2MFTeYZdnnRc1o7fnt4yzBwuYKH9IjTS3gZYBm9O8TBhtTMsEV mFjbJ5V1MYHSu6/69DUzrYRsoPcfAeiYSYX+GaWBtlQ7UFEs1LVqJ/9g6M+vVctmrDfs WyCohOLVYxgNp17KfLalyyh1aIS3ApqOPZzXSxyCQNGb9eSYBAnSNP1fL9gfVwHZd18o znytDCq8vzyxZcaqYAISb/Cd/U00RVF8qMULigf50xrLLqPqxfuCAviPaia2x3J7NilY OOYg== X-Gm-Message-State: AOJu0Yzv0uLHR5x2OhsLTPhj6yBCvf8QpUDXnGTmqAT+PVeZMoTgHIz+ 4n1nI7tEkl5xQw44IVVN1sKR4dJg2/YKfhrf5AF4yzKaYJWFKPCzi0ZvAw9bv6Uj6AfizM7J8DL G X-Google-Smtp-Source: AGHT+IELe6qMsbDICF1Ey5PT7OkAJIpkSvjtCO6u6YHXoo47FBt/hd8qT/x6Kjs7vGU+6+LLuL/bXg== X-Received: by 2002:a05:6a20:341d:b0:1a3:6a02:3537 with SMTP id i29-20020a056a20341d00b001a36a023537mr2777808pzd.62.1711248084321; Sat, 23 Mar 2024 19:41:24 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id q17-20020a17090311d100b001dc3c4e7a12sm2244980plh.14.2024.03.23.19.41.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Mar 2024 19:41:23 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Anatoly Burakov , Bruce Richardson , Dmitry Kozlyuk , Tyler Retzlaff , Pallavi Kadam Subject: [PATCH v11 5/9] log: drop syslog support, and make code common Date: Sat, 23 Mar 2024 19:33:27 -0700 Message-ID: <20240324024109.306614-6-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324024109.306614-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240324024109.306614-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 This patch removes syslog support from logging. Which allows the logging code to all be common across Linux, Windows and FreeBSD. It also initializes log subsystem much earlier in the init process so that all messages get processed. It drops syslog was only used on Linux. Modern Linux systems have systemd and journal support. A later patch will add direct native journal support. Removing syslog means lots of other parts of the log system can be simplified and made portable. Remove the syslog tests and documentation as well. Signed-off-by: Stephen Hemminger --- app/test/test_eal_flags.c | 21 +------ doc/guides/linux_gsg/linux_eal_parameters.rst | 27 -------- .../prog_guide/env_abstraction_layer.rst | 5 +- doc/guides/prog_guide/log_lib.rst | 3 +- lib/eal/common/eal_common_options.c | 62 ------------------- lib/eal/common/eal_internal_cfg.h | 2 +- lib/eal/common/eal_options.h | 2 - lib/eal/freebsd/eal.c | 9 +-- lib/eal/linux/eal.c | 10 +-- lib/eal/unix/eal_debug.c | 3 +- lib/eal/windows/eal.c | 4 +- lib/log/log.c | 46 +++++--------- lib/log/log_freebsd.c | 12 ---- lib/log/log_internal.h | 2 +- lib/log/log_linux.c | 61 ------------------ lib/log/log_windows.c | 18 ------ lib/log/meson.build | 5 +- 17 files changed, 34 insertions(+), 258 deletions(-) delete mode 100644 lib/log/log_freebsd.c delete mode 100644 lib/log/log_linux.c delete mode 100644 lib/log/log_windows.c diff --git a/app/test/test_eal_flags.c b/app/test/test_eal_flags.c index 6cb4b06757..bea5465168 100644 --- a/app/test/test_eal_flags.c +++ b/app/test/test_eal_flags.c @@ -984,17 +984,10 @@ test_misc_flags(void) const char *argv1[] = {prgname, prefix, mp_flag, "--no-pci"}; /* With -v */ const char *argv2[] = {prgname, prefix, mp_flag, "-v"}; - /* With valid --syslog */ - const char *argv3[] = {prgname, prefix, mp_flag, - "--syslog", "syslog"}; - /* With empty --syslog (should fail) */ - const char *argv4[] = {prgname, prefix, mp_flag, "--syslog"}; - /* With invalid --syslog */ - const char *argv5[] = {prgname, prefix, mp_flag, "--syslog", "error"}; + /* With no-sh-conf, also use no-huge to ensure this test runs on BSD */ const char *argv6[] = {prgname, "-m", DEFAULT_MEM_SIZE, no_shconf, nosh_prefix, no_huge}; - /* With --huge-dir */ const char *argv7[] = {prgname, "-m", DEFAULT_MEM_SIZE, "--file-prefix=hugedir", "--huge-dir", hugepath}; @@ -1079,18 +1072,6 @@ test_misc_flags(void) return 0; #endif - if (launch_proc(argv3) != 0) { - printf("Error - process did not run ok with --syslog flag\n"); - goto fail; - } - if (launch_proc(argv4) == 0) { - printf("Error - process run ok with empty --syslog flag\n"); - goto fail; - } - if (launch_proc(argv5) == 0) { - printf("Error - process run ok with invalid --syslog flag\n"); - goto fail; - } if (launch_proc(argv7) != 0) { printf("Error - process did not run ok with --huge-dir flag\n"); goto fail; diff --git a/doc/guides/linux_gsg/linux_eal_parameters.rst b/doc/guides/linux_gsg/linux_eal_parameters.rst index ea8f381391..d86f94d8a8 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/env_abstraction_layer.rst b/doc/guides/prog_guide/env_abstraction_layer.rst index 9559c12a98..9a73628907 100644 --- a/doc/guides/prog_guide/env_abstraction_layer.rst +++ b/doc/guides/prog_guide/env_abstraction_layer.rst @@ -855,9 +855,8 @@ Signal Safety Other functions are not signal safe because they use one or more library routines that are not themselves signal safe. For example, calling ``rte_panic()`` is not safe in a signal handler - because it uses ``rte_log()`` and ``rte_log()`` calls the - ``syslog()`` library function which is in the list of - signal safe functions in + because it uses ``rte_log()`` and ``rte_log()`` calls library functions + that are not all signal safe. `Signal-Safety manual page `_. The set of functions that are expected to be async-signal-safe in DPDK diff --git a/doc/guides/prog_guide/log_lib.rst b/doc/guides/prog_guide/log_lib.rst index ff9d1b54a2..17ed8426b2 100644 --- a/doc/guides/prog_guide/log_lib.rst +++ b/doc/guides/prog_guide/log_lib.rst @@ -5,8 +5,7 @@ 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, log messages are sent to the stderr. However, the log function can be overridden by the user to use a different logging mechanism. Log Levels diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index 5435399b85..73167d4603 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -6,9 +6,6 @@ #include #include #include -#ifndef RTE_EXEC_ENV_WINDOWS -#include -#endif #include #include #include @@ -93,7 +90,6 @@ eal_long_options[] = { {OPT_PROC_TYPE, 1, NULL, OPT_PROC_TYPE_NUM }, {OPT_SOCKET_MEM, 1, NULL, OPT_SOCKET_MEM_NUM }, {OPT_SOCKET_LIMIT, 1, NULL, OPT_SOCKET_LIMIT_NUM }, - {OPT_SYSLOG, 1, NULL, OPT_SYSLOG_NUM }, {OPT_VDEV, 1, NULL, OPT_VDEV_NUM }, {OPT_VFIO_INTR, 1, NULL, OPT_VFIO_INTR_NUM }, {OPT_VFIO_VF_TOKEN, 1, NULL, OPT_VFIO_VF_TOKEN_NUM }, @@ -349,10 +345,6 @@ eal_reset_internal_config(struct internal_config *internal_cfg) } internal_cfg->base_virtaddr = 0; -#ifdef LOG_DAEMON - internal_cfg->syslog_facility = LOG_DAEMON; -#endif - /* if set to NONE, interrupt mode is determined automatically */ internal_cfg->vfio_intr_mode = RTE_INTR_MODE_NONE; memset(internal_cfg->vfio_vf_token, 0, @@ -1297,47 +1289,6 @@ eal_parse_lcores(const char *lcores) return ret; } -#ifndef RTE_EXEC_ENV_WINDOWS -static int -eal_parse_syslog(const char *facility, struct internal_config *conf) -{ - int i; - static const struct { - const char *name; - int value; - } map[] = { - { "auth", LOG_AUTH }, - { "cron", LOG_CRON }, - { "daemon", LOG_DAEMON }, - { "ftp", LOG_FTP }, - { "kern", LOG_KERN }, - { "lpr", LOG_LPR }, - { "mail", LOG_MAIL }, - { "news", LOG_NEWS }, - { "syslog", LOG_SYSLOG }, - { "user", LOG_USER }, - { "uucp", LOG_UUCP }, - { "local0", LOG_LOCAL0 }, - { "local1", LOG_LOCAL1 }, - { "local2", LOG_LOCAL2 }, - { "local3", LOG_LOCAL3 }, - { "local4", LOG_LOCAL4 }, - { "local5", LOG_LOCAL5 }, - { "local6", LOG_LOCAL6 }, - { "local7", LOG_LOCAL7 }, - { NULL, 0 } - }; - - for (i = 0; map[i].name; i++) { - if (!strcmp(facility, map[i].name)) { - conf->syslog_facility = map[i].value; - return 0; - } - } - return -1; -} -#endif - static void eal_log_usage(void) { @@ -1880,16 +1831,6 @@ eal_parse_common_option(int opt, const char *optarg, } break; -#ifndef RTE_EXEC_ENV_WINDOWS - case OPT_SYSLOG_NUM: - if (eal_parse_syslog(optarg, conf) < 0) { - EAL_LOG(ERR, "invalid parameters for --" - OPT_SYSLOG); - return -1; - } - break; -#endif - case OPT_LOG_LEVEL_NUM: { if (eal_parse_log_level(optarg) < 0) { EAL_LOG(ERR, @@ -2259,9 +2200,6 @@ eal_common_usage(void) " (can be used multiple times)\n" " --"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" -#endif " --"OPT_LOG_LEVEL"= Set global log level\n" " --"OPT_LOG_LEVEL"=:\n" " Set specific log level\n" diff --git a/lib/eal/common/eal_internal_cfg.h b/lib/eal/common/eal_internal_cfg.h index 167ec501fa..ed56a58b8b 100644 --- a/lib/eal/common/eal_internal_cfg.h +++ b/lib/eal/common/eal_internal_cfg.h @@ -84,7 +84,7 @@ struct internal_config { /**< true if storing all pages within single files (per-page-size, * per-node) non-legacy mode only. */ - 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 f3f2e104f6..6b204d6698 100644 --- a/lib/eal/common/eal_options.h +++ b/lib/eal/common/eal_options.h @@ -63,8 +63,6 @@ enum { OPT_SOCKET_MEM_NUM, #define OPT_SOCKET_LIMIT "socket-limit" OPT_SOCKET_LIMIT_NUM, -#define OPT_SYSLOG "syslog" - OPT_SYSLOG_NUM, #define OPT_VDEV "vdev" OPT_VDEV_NUM, #define OPT_VFIO_INTR "vfio-intr" diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index 17b56f38aa..d8628ba632 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -563,12 +562,14 @@ rte_eal_init(int argc, char **argv) eal_reset_internal_config(internal_conf); - /* clone argv to report out later in telemetry */ - eal_save_args(argc, argv); - /* set log level as early as possible */ eal_log_level_parse(argc, argv); + eal_log_init(getprogname()); + + /* clone argv to report out later in telemetry */ + eal_save_args(argc, argv); + if (rte_eal_cpu_init() < 0) { rte_eal_init_alert("Cannot detect lcores."); rte_errno = ENOTSUP; diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index 23dc26b124..913ee62fc6 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -955,6 +955,8 @@ rte_eal_init(int argc, char **argv) /* set log level as early as possible */ eal_log_level_parse(argc, argv); + eal_log_init(program_invocation_short_name); + /* clone argv to report out later in telemetry */ eal_save_args(argc, argv); @@ -1106,14 +1108,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_debug.c b/lib/eal/unix/eal_debug.c index 69ba3758c2..c830cf7f05 100644 --- a/lib/eal/unix/eal_debug.c +++ b/lib/eal/unix/eal_debug.c @@ -43,8 +43,7 @@ static char *safe_itoa(long val, char *buf, size_t len, unsigned int radix) * used in this code since may be called from inside libc or * when malloc poll is corrupt. * - * Most of libc is therefore not safe, include RTE_LOG (calls syslog); - * backtrace_symbols (calls malloc), etc. + * Most of libc is therefore not safe including backtrace_symbols (calls malloc), etc. */ void rte_dump_stack(void) { diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c index 85171b2768..10f7cb840a 100644 --- a/lib/eal/windows/eal.c +++ b/lib/eal/windows/eal.c @@ -250,10 +250,10 @@ rte_eal_init(int argc, char **argv) char cpuset[RTE_CPU_AFFINITY_STR_LEN]; char thread_name[RTE_THREAD_NAME_SIZE]; - eal_log_init(NULL, 0); - eal_log_level_parse(argc, argv); + eal_log_init(NULL); + if (eal_create_cpu_map() < 0) { rte_eal_init_alert("Cannot discover CPU and NUMA."); /* rte_errno is set */ diff --git a/lib/log/log.c b/lib/log/log.c index 255f757d94..4c8666ac93 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -55,9 +55,6 @@ TAILQ_HEAD(rte_eal_opt_loglevel_list, rte_eal_opt_loglevel); static struct rte_eal_opt_loglevel_list opt_loglevel_list = TAILQ_HEAD_INITIALIZER(opt_loglevel_list); -/* Stream to use for logging if rte_logs.file is NULL */ -static FILE *default_log_stream; - /** * This global structure stores some information about the message * that is currently being processed by one lcore @@ -76,6 +73,9 @@ static RTE_DEFINE_PER_LCORE(struct log_cur_msg, log_cur_msg); int rte_openlog_stream(FILE *f) { + if (rte_logs.file != NULL) + fclose(rte_logs.file); + rte_logs.file = f; return 0; } @@ -85,17 +85,7 @@ rte_log_get_stream(void) { FILE *f = rte_logs.file; - if (f == NULL) { - /* - * Grab the current value of stderr here, rather than - * just initializing default_log_stream to stderr. This - * ensures that we will always use the current value - * of stderr, even if the application closes and - * reopens it. - */ - return default_log_stream != NULL ? default_log_stream : stderr; - } - return f; + return (f == NULL) ? stderr : f; } /* Set global log level */ @@ -506,27 +496,25 @@ rte_log(uint32_t level, uint32_t logtype, const char *format, ...) } /* - * Called by environment-specific initialization functions. + * Called by eal_cleanup */ void -eal_log_set_default(FILE *default_log) +rte_eal_log_cleanup(void) { - default_log_stream = default_log; + FILE *f = rte_logs.file; -#if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG - RTE_LOG(NOTICE, EAL, - "Debug dataplane logs available - lower performance\n"); -#endif + if (f != NULL) { + fclose(f); + rte_logs.file = NULL; + } } -/* - * Called by eal_cleanup - */ +/* initialize logging */ void -rte_eal_log_cleanup(void) +eal_log_init(const char *id __rte_unused) { - if (default_log_stream) { - fclose(default_log_stream); - default_log_stream = NULL; - } +#if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG + RTE_LOG(NOTICE, EAL, + "Debug dataplane logs available - lower performance\n"); +#endif } diff --git a/lib/log/log_freebsd.c b/lib/log/log_freebsd.c deleted file mode 100644 index 698d3c5423..0000000000 --- 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_internal.h b/lib/log/log_internal.h index 451629f1c1..4f1ffe999e 100644 --- a/lib/log/log_internal.h +++ b/lib/log/log_internal.h @@ -14,7 +14,7 @@ * Initialize the default log stream. */ __rte_internal -int eal_log_init(const char *id, int facility); +void eal_log_init(const char *id); /* * Determine where log data is written when no call to rte_openlog_stream. diff --git a/lib/log/log_linux.c b/lib/log/log_linux.c deleted file mode 100644 index 2dfb0c974b..0000000000 --- a/lib/log/log_linux.c +++ /dev/null @@ -1,61 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * Copyright(c) 2010-2014 Intel Corporation - */ - -#include -#include -#include - -#include - -#include "log_internal.h" - -/* - * default log function - */ -static ssize_t -console_log_write(__rte_unused void *c, const char *buf, size_t size) -{ - ssize_t ret; - - /* write on stderr */ - ret = fwrite(buf, 1, size, stderr); - fflush(stderr); - - /* Syslog error levels are from 0 to 7, so subtract 1 to convert */ - syslog(rte_log_cur_msg_loglevel() - 1, "%.*s", (int)size, buf); - - return ret; -} - -static int -console_log_close(__rte_unused void *c) -{ - closelog(); - return 0; -} - -static cookie_io_functions_t console_log_func = { - .write = console_log_write, - .close = console_log_close, -}; - -/* - * set the log to default function, called during eal init process, - * once memzones are available. - */ -int -eal_log_init(const char *id, int facility) -{ - FILE *log_stream; - - log_stream = fopencookie(NULL, "w+", console_log_func); - if (log_stream == NULL) - return -1; - - openlog(id, LOG_NDELAY | LOG_PID, facility); - - eal_log_set_default(log_stream); - - return 0; -} diff --git a/lib/log/log_windows.c b/lib/log/log_windows.c deleted file mode 100644 index a6a0889550..0000000000 --- a/lib/log/log_windows.c +++ /dev/null @@ -1,18 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * Copyright(c) 2017-2018 Intel Corporation - */ - -#include -#include -#include "log_internal.h" - -/* set the log to default function, called during eal init process. */ -int -eal_log_init(__rte_unused const char *id, __rte_unused int facility) -{ - rte_openlog_stream(stderr); - - eal_log_set_default(stderr); - - return 0; -} diff --git a/lib/log/meson.build b/lib/log/meson.build index 0d4319b36f..891f77a237 100644 --- a/lib/log/meson.build +++ b/lib/log/meson.build @@ -2,8 +2,5 @@ # Copyright(c) 2023 Intel Corporation includes += global_inc -sources = files( - 'log.c', - 'log_' + exec_env + '.c', -) +sources = files('log.c') headers = files('rte_log.h') From patchwork Sun Mar 24 02:33:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138759 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 93D1443D36; Sun, 24 Mar 2024 03:42:07 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B7CA740693; Sun, 24 Mar 2024 03:41:31 +0100 (CET) Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) by mails.dpdk.org (Postfix) with ESMTP id E31EC402EB for ; Sun, 24 Mar 2024 03:41:25 +0100 (CET) Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-5d8b887bb0cso2193592a12.2 for ; Sat, 23 Mar 2024 19:41:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711248085; x=1711852885; 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=VdEvoGGjU84scNBTJhyFTXSp+Lveq7VDyLhJBdzO3yw=; b=0ciau0+8uP8waaIAgPRZbMiZFiDkm71Di2SWZisph9qaGVnByRLseMHnfRy7gV/1qq Oz856oSVAD+0RFnoRnq6gbkYG5Ry4ff0AW6UiRpKjJLvuOQYiLe9alh/sBHON9zC2fgK qCif9lxv/oUrssEOyEaaOpTU/7IK8ikAV2vBexOCSVv7Vbe6S2L8qvx0cYsIh8cJyKRd 7EIN78DZEu1IMgQcIqo1OZr2+CZhEEaf9yc6IZj98IulYXx4NhijM485zO76iV6MHQ5p gAFZ+ERj6V3bpmMKgNaDvmNdxcLBA2UuKfw/sS28X64bklunZKk9sSHvn7skPp+UJwpa 8o8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711248085; x=1711852885; 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=VdEvoGGjU84scNBTJhyFTXSp+Lveq7VDyLhJBdzO3yw=; b=IH36M2WG0fxCmsUAzbY61Lv73bJVUwPcwdDgEC4qvh51cFUBla1JezhsyyYEbJqTJH u30smXss6yoM1nVwApYIWJO41gOUAh0FEgTzReM0NsvCyv2EmEPa1/bQzMtuq4i9omE+ Uae275Z/ntOdupp6OW9C6A8uFNdpScAAm5buC+iyJ7c4Md2rPbo5DCvcysLDFYozP00h hV0zuFSXf5ffDmBSa+6ZKOvepdVXtjABYTY7QM+rV/7Zr6xv7kA9pSCE6V/BdJcSzcm3 053ka4nmSVnWy0V/XKdV3WZ47+OFXeEAf2axBfVpk27i8Qx0UHUmjwu4YkFDz3K1/NRH 01KQ== X-Gm-Message-State: AOJu0YzSgKp2ZzG3+H0jWlo8S2iw4puugUIHBuRl4lcdk/hk0Tuq/UNC V44nsjAMYwxD+aOPpqf7qre9w1FpYnUqrO/VJ+bvhvzvK+t3lp6DBXWXbfUxLuEv4zb2N6QauSy 1 X-Google-Smtp-Source: AGHT+IG0oFdAT96k4vrSZop5SaKJHVtkLZIwY6iFWpzxW4sIwul8La0GCfx0MkBQ8PNGeMst8keV+Q== X-Received: by 2002:a17:902:d4c3:b0:1e0:1f59:d672 with SMTP id o3-20020a170902d4c300b001e01f59d672mr5214967plg.36.1711248085063; Sat, 23 Mar 2024 19:41:25 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id q17-20020a17090311d100b001dc3c4e7a12sm2244980plh.14.2024.03.23.19.41.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Mar 2024 19:41:24 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v11 6/9] log: add hook for printing log messages Date: Sat, 23 Mar 2024 19:33:28 -0700 Message-ID: <20240324024109.306614-7-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324024109.306614-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240324024109.306614-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 This is useful for when decorating log output for console or journal. Provide basic version in this patch. No functional changes in this patch, just infrastructure addition. Signed-off-by: Stephen Hemminger --- lib/log/log.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/log/log.c b/lib/log/log.c index 4c8666ac93..4cc871911c 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -26,16 +26,21 @@ struct rte_log_dynamic_type { uint32_t loglevel; }; +typedef int (*log_print_t)(FILE *f, uint32_t level, const char *fmt, va_list ap); +static int log_print(FILE *f, uint32_t level, const char *format, va_list ap); + /** The rte_log structure. */ static struct rte_logs { uint32_t type; /**< Bitfield with enabled logs. */ uint32_t level; /**< Log level. */ FILE *file; /**< Output file set by rte_openlog_stream, or NULL. */ + log_print_t print_func; size_t dynamic_types_len; struct rte_log_dynamic_type *dynamic_types; } rte_logs = { .type = UINT32_MAX, .level = RTE_LOG_DEBUG, + .print_func = log_print, }; struct rte_eal_opt_loglevel { @@ -67,8 +72,6 @@ struct log_cur_msg { /* per core log */ static RTE_DEFINE_PER_LCORE(struct log_cur_msg, log_cur_msg); -/* default logs */ - /* Change the stream that will be used by logging system */ int rte_openlog_stream(FILE *f) @@ -77,6 +80,7 @@ rte_openlog_stream(FILE *f) fclose(rte_logs.file); rte_logs.file = f; + rte_logs.print_func = log_print; return 0; } @@ -473,7 +477,7 @@ rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap) RTE_PER_LCORE(log_cur_msg).loglevel = level; RTE_PER_LCORE(log_cur_msg).logtype = logtype; - ret = vfprintf(f, format, ap); + ret = (*rte_logs.print_func)(f, level, format, ap); fflush(f); return ret; } @@ -509,6 +513,15 @@ rte_eal_log_cleanup(void) } } +/* default log print function */ +__rte_format_printf(3, 0) +static int +log_print(FILE *f, uint32_t level __rte_unused, + const char *format, va_list ap) +{ + return vfprintf(f, format, ap); +} + /* initialize logging */ void eal_log_init(const char *id __rte_unused) From patchwork Sun Mar 24 02:33:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138760 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 21CD143D36; Sun, 24 Mar 2024 03:42:15 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D1D764069F; Sun, 24 Mar 2024 03:41:32 +0100 (CET) Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) by mails.dpdk.org (Postfix) with ESMTP id B58B2402EC for ; Sun, 24 Mar 2024 03:41:26 +0100 (CET) Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-29de4c33441so2337750a91.1 for ; Sat, 23 Mar 2024 19:41:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711248086; x=1711852886; 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=KMFs2nnZQjuUChC7i9aa4h6YtbRdRwzjMnZM5qcjWqY=; b=U2N5SLEK+6Q5gVCOzH2HwAomBMst83XK6/5F0ph8Zaa9X/jpbWu3JFtT4ZZ7htznfJ JOycA3Rha5uhT8hZ6bbNcLhKDVN0Y9rVae5c1onpL2OOsLBAene2vVf1ovhmIUAUzIam 6W61R5EGEnuM4E6fvb7Er3my9MniE4GYSWxPEnEDMpfmUsMjrPLCxYcQ4CvU8EBDGLKM Z9/vMTH9/icY5TuiNOKPbGGN7JX3Igci2VZqaNtZL/0kIn/wytee/uXTafBXnJpNVDeb lEC+sy8rxfn9O8MBhFZAcwQq7Wm460L1UI6Q2fvDn3aIknIMmZwXZAJrLYSnXtTpPGMI ZSoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711248086; x=1711852886; 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=KMFs2nnZQjuUChC7i9aa4h6YtbRdRwzjMnZM5qcjWqY=; b=bwmE/BXqhBVL+sCAkOpVO+CuC2Gpp9XzgVN4gGkABpL6birck2pjTYpi7mWtA0JVMC Q1uYCXx446wjOdbaI0Zqvub/s2+Emcham6oaPVMMLp8HafFPf1bJMxSYqx8PG5+zcFH+ P6zKKvS0MF5BQijaYGjaxfw/N9c7RuqjUlO0Di4fo8QtOnp2wjGqZaMbPYMd2CH6Ck7I uigSkG1vawg6XdR81+EmVp6H7DLaZdrFf7SYArra8qJsyoJHeysTpH9eXh1/hw/5gUVI pg9rq1Jhm8wfpb6rtvjCRC8xoe0YR4FmgqLruqzlYEgeWhNk8Lk01AEeoyGLXQDaqXa7 kJ4g== X-Gm-Message-State: AOJu0YwgKButONUkiJ9HsitisJA0nev5kkkIWnAwlQOf+BbNgz0lACBC UW0SVgj/c5wq/nKwzKzz+5UEEd8t1YYShnV+yJKW6cWl3qnTlWx14y4IP4FMN4qQha0pjg3c6rn F X-Google-Smtp-Source: AGHT+IH+gwzOM+SwucIHLDpTB1zs9pHHoGcuuo6q0q5Pu097fJB2KPNhwQbb7o0WduGQ490GLYpEKw== X-Received: by 2002:a05:6a20:7344:b0:1a3:c4ea:f528 with SMTP id v4-20020a056a20734400b001a3c4eaf528mr115537pzc.43.1711248085879; Sat, 23 Mar 2024 19:41:25 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id q17-20020a17090311d100b001dc3c4e7a12sm2244980plh.14.2024.03.23.19.41.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Mar 2024 19:41:25 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v11 7/9] log: add timestamp option Date: Sat, 23 Mar 2024 19:33:29 -0700 Message-ID: <20240324024109.306614-8-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324024109.306614-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240324024109.306614-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 (when first step of logging initialization is done by constructor). Other alternative formats are delta, ctime, reltime and iso formats. Example: $ dpdk-testpmd --log-timestamp -- -i [ 0.008610] EAL: Detected CPU lcores: 8 [ 0.008634] EAL: Detected NUMA nodes: 1 [ 0.008792] EAL: Detected static linkage of DPDK [ 0.010620] EAL: Multi-process socket /var/run/dpdk/rte/mp_socket [ 0.012618] EAL: Selected IOVA mode 'VA' [ 0.016675] testpmd: No probed ethernet devices Interactive-mode selected Signed-off-by: Stephen Hemminger --- app/test/test_eal_flags.c | 17 +++ doc/guides/prog_guide/log_lib.rst | 26 +++++ lib/eal/common/eal_common_options.c | 14 ++- lib/eal/common/eal_options.h | 2 + lib/log/log.c | 168 +++++++++++++++++++++++++++- lib/log/log_internal.h | 9 ++ lib/log/version.map | 1 + 7 files changed, 234 insertions(+), 3 deletions(-) diff --git a/app/test/test_eal_flags.c b/app/test/test_eal_flags.c index bea5465168..def74e34d5 100644 --- a/app/test/test_eal_flags.c +++ b/app/test/test_eal_flags.c @@ -1048,6 +1048,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) { @@ -1143,6 +1151,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 17ed8426b2..83949cce35 100644 --- a/doc/guides/prog_guide/log_lib.rst +++ b/doc/guides/prog_guide/log_lib.rst @@ -58,6 +58,32 @@ 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. +Console timestamp +~~~~~~~~~~~~~~~~~ + +An optional timestamp can be added before each message when printing on the console +by adding the ``--log-timestamp`` option. +For example:: + + /path/to/app --log-level=lib.*:debug --log-timestamp + +Multiple timestamp alternative timestamp formats are available: + +.. csv-table:: Log time stamp format + :header: "Format", "Description", "Example" + :widths: 6, 30, 32 + + "ctime", "Unix ctime", "``[Wed Mar 20 07:26:12 2024]``" + "delta", "Offset since last", "``[< 3.162373>]``" + "reltime", "Seconds since last or time if minute changed", "``[ +3.001791]`` or ``[Mar20 07:26:12]``" + "iso", "ISO-8601", "``[2024-03-20T07:26:12−07:00]``" + +To prefix all console messages with ISO format time the syntax is:: + + /path/to/app --log-timestamp=iso + + + 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 73167d4603..bc6d87266d 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -74,6 +74,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 }, @@ -1614,6 +1615,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; @@ -1831,7 +1833,7 @@ eal_parse_common_option(int opt, const char *optarg, } break; - case OPT_LOG_LEVEL_NUM: { + case OPT_LOG_LEVEL_NUM: if (eal_parse_log_level(optarg) < 0) { EAL_LOG(ERR, "invalid parameters for --" @@ -1839,7 +1841,14 @@ eal_parse_common_option(int opt, const char *optarg, return -1; } break; - } + + case OPT_LOG_TIMESTAMP_NUM: + if (eal_log_timestamp(optarg) < 0) { + EAL_LOG(ERR, "invalid parameters for --" + OPT_LOG_TIMESTAMP); + return -1; + } + break; #ifndef RTE_EXEC_ENV_WINDOWS case OPT_TRACE_NUM: { @@ -2204,6 +2213,7 @@ eal_common_usage(void) " --"OPT_LOG_LEVEL"=:\n" " Set specific log level\n" " --"OPT_LOG_LEVEL"=help Show log types and levels\n" + " --"OPT_LOG_TIMESTAMP" Timestamp log output\n" #ifndef RTE_EXEC_ENV_WINDOWS " --"OPT_TRACE"=\n" " Enable trace based on regular expression trace name.\n" diff --git a/lib/eal/common/eal_options.h b/lib/eal/common/eal_options.h index 6b204d6698..197b7b25ef 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.c b/lib/log/log.c index 4cc871911c..bd488dff1b 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -18,7 +19,7 @@ #include "log_internal.h" #ifdef RTE_EXEC_ENV_WINDOWS -#define strdup _strdup +#include #endif struct rte_log_dynamic_type { @@ -26,6 +27,15 @@ struct rte_log_dynamic_type { uint32_t loglevel; }; +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, +}; + typedef int (*log_print_t)(FILE *f, uint32_t level, const char *fmt, va_list ap); static int log_print(FILE *f, uint32_t level, const char *format, va_list ap); @@ -35,6 +45,12 @@ static struct rte_logs { uint32_t level; /**< Log level. */ FILE *file; /**< Output file set by rte_openlog_stream, or NULL. */ log_print_t print_func; + + enum eal_log_time_format time_format; + struct timespec started; /* when log was initialized */ + struct timespec previous; /* when last msg was printed */ + struct tm last_tm; /* in local time format */ + size_t dynamic_types_len; struct rte_log_dynamic_type *dynamic_types; } rte_logs = { @@ -362,6 +378,9 @@ RTE_INIT_PRIO(log_init, LOG) { uint32_t i; + clock_gettime(CLOCK_MONOTONIC, &rte_logs.started); + rte_logs.previous = rte_logs.started; + rte_log_set_global_level(RTE_LOG_DEBUG); rte_logs.dynamic_types = calloc(RTE_LOGTYPE_FIRST_EXT_ID, @@ -513,6 +532,132 @@ rte_eal_log_cleanup(void) } } +/* Set the log timestamp format */ +int +eal_log_timestamp(const char *str) +{ + if (str == NULL) + rte_logs.time_format = EAL_LOG_TIMESTAMP_TIME; + else if (strcmp(str, "notime") == 0) + rte_logs.time_format = EAL_LOG_TIMESTAMP_NONE; + else if (strcmp(str, "reltime") == 0) + rte_logs.time_format = EAL_LOG_TIMESTAMP_RELTIME; + else if (strcmp(str, "delta") == 0) + rte_logs.time_format = EAL_LOG_TIMESTAMP_DELTA; + else if (strcmp(str, "ctime") == 0) + rte_logs.time_format = EAL_LOG_TIMESTAMP_CTIME; + else if (strcmp(str, "iso") == 0) + rte_logs.time_format = EAL_LOG_TIMESTAMP_ISO; + else + return -1; + + return 0; +} + +/* Subtract two timespec values and handle wraparound */ +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; +} + +/* Format up a timestamp based on current format */ +static ssize_t +format_timestamp(char *tsbuf, size_t tsbuflen) +{ + struct timespec now, delta; + struct tm *tm; + + switch (rte_logs.time_format) { + case EAL_LOG_TIMESTAMP_NONE: + return 0; + + case EAL_LOG_TIMESTAMP_TIME: + if (clock_gettime(CLOCK_MONOTONIC, &now) < 0) + return 0; + + delta = timespec_sub(&now, &rte_logs.started); + + return snprintf(tsbuf, tsbuflen, "%6lu.%06lu", + (unsigned long)delta.tv_sec, + (unsigned long)delta.tv_nsec / 1000u); + + case EAL_LOG_TIMESTAMP_DELTA: + if (clock_gettime(CLOCK_MONOTONIC, &now) < 0) + return 0; + + delta = timespec_sub(&now, &rte_logs.previous); + rte_logs.previous = now; + + return snprintf(tsbuf, tsbuflen, "<%6lu.%06lu>", + (unsigned long)delta.tv_sec, + (unsigned long)delta.tv_nsec / 1000u); + + case EAL_LOG_TIMESTAMP_RELTIME: + if (clock_gettime(CLOCK_REALTIME, &now) < 0) + return 0; + + tm = localtime(&now.tv_sec); + delta = timespec_sub(&now, &rte_logs.previous); + rte_logs.previous = now; + + /* if minute, day, hour hasn't changed then print delta */ + if (tm->tm_min != rte_logs +.last_tm.tm_min || + tm->tm_hour != rte_logs.last_tm.tm_hour || + tm->tm_yday != rte_logs.last_tm.tm_yday) { + rte_logs.last_tm = *tm; + return strftime(tsbuf, tsbuflen, "%b%d %H:%M", tm); + } else { + return snprintf(tsbuf, tsbuflen, "+%4lu.%06lu", + (unsigned long)delta.tv_sec, + (unsigned long)delta.tv_nsec / 1000u); + } + + case EAL_LOG_TIMESTAMP_CTIME: + if (clock_gettime(CLOCK_REALTIME, &now) < 0) + return 0; + + /* trncate to remove newline from ctime result */ + return snprintf(tsbuf, tsbuflen, "%.24s", ctime(&now.tv_sec)); + + case EAL_LOG_TIMESTAMP_ISO: { + char dbuf[64]; /* "2024-05-01T22:11:00" */ + char zbuf[16]; /* "+0800" */ + + if (clock_gettime(CLOCK_REALTIME, &now) < 0) + return 0; + + tm = localtime(&now.tv_sec); + + /* make "2024-05-01T22:11:00,123456+0100" */ + if (strftime(dbuf, sizeof(dbuf), "%Y-%m-%dT%H:%M:%S", tm) == 0) + return 0; + + /* convert timezone to +HH:MM */ + if (strftime(zbuf, sizeof(zbuf), "%z", tm) == 0) + return 0; + /* insert : required in ISO */ + memmove(zbuf + 3, zbuf + 4, 2); + zbuf[3] = ':'; + zbuf[6] = '\0'; + + return snprintf(tsbuf, tsbuflen, "%s,%06lu%s", + dbuf, now.tv_nsec / 1000u, zbuf); + } + } + + return 0; +} + /* default log print function */ __rte_format_printf(3, 0) static int @@ -522,10 +667,31 @@ log_print(FILE *f, uint32_t level __rte_unused, return vfprintf(f, format, ap); } +/* print timestamp before message */ +__rte_format_printf(3, 0) +static int +log_print_with_timestamp(FILE *f, uint32_t level, + const char *format, va_list ap) +{ + char tsbuf[128]; + + if (format_timestamp(tsbuf, sizeof(tsbuf)) > 0) + fprintf(f, "[%s] ", tsbuf); + + return log_print(f, level, format, ap); +} + /* initialize logging */ void eal_log_init(const char *id __rte_unused) { + /* skip if user has already setup a log stream */ + if (rte_logs.file != NULL) + return; + + if (rte_logs.time_format != EAL_LOG_TIMESTAMP_NONE) + rte_logs.print_func = log_print_with_timestamp; + #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG RTE_LOG(NOTICE, EAL, "Debug dataplane logs available - lower performance\n"); diff --git a/lib/log/log_internal.h b/lib/log/log_internal.h index 4f1ffe999e..3544ae49ac 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 @@ -42,4 +44,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/version.map b/lib/log/version.map index 0648f8831a..7fd5b39e3a 100644 --- a/lib/log/version.map +++ b/lib/log/version.map @@ -30,5 +30,6 @@ INTERNAL { eal_log_save_pattern; eal_log_save_regexp; eal_log_set_default; + eal_log_timestamp; rte_eal_log_cleanup; }; From patchwork Sun Mar 24 02:33:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138761 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 6CEA643D36; Sun, 24 Mar 2024 03:42:22 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 08B89406B8; Sun, 24 Mar 2024 03:41:34 +0100 (CET) Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by mails.dpdk.org (Postfix) with ESMTP id 5A08E402EC for ; Sun, 24 Mar 2024 03:41:27 +0100 (CET) Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1e034607879so25623615ad.0 for ; Sat, 23 Mar 2024 19:41:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711248086; x=1711852886; 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=LCYp3m42AR3Bl02fdCxypzjKxWlwIQYVWzlmXEvqwJo=; b=taSHpVp6ukoNZ58mie4uRfNcPRx2b4/Ts8/x3i5VS9xXxdztmpR3u7BTYq7RILS49M KeKv+1Dowf1ZSsjtQBHI9UkpkZZ7ewbEuWiMOcp7UsRQ4l4oAkgDUXsKDXj8/y2tq1n2 ynkCUa0HBgHgxXV3t2V3Kt9miYlZr97Mz7AjOk3Z1CIeCZoRnZhWd6Mitx6+Cd4I6ox1 dxwBxvUVlLhNmFHRHaIAP8uXuy2sl1PtBxVgZhfcTCaEw3KV61VCfUzmoS6V5+yFr7H/ +5C8k+yqlw4IvwpsoA4uBKojlLb8jzERX/cL7B9FLrdo7uQ3YhlXyfp358+jbM+qbbz+ te1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711248086; x=1711852886; 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=LCYp3m42AR3Bl02fdCxypzjKxWlwIQYVWzlmXEvqwJo=; b=mljAY7rwuh5WgABwt2BxboQiO+aSK9NMkA5qf+whQ0Az87SH9i7YLywsqBttjB0idz r1Ynkb0xl5wV+CfaVDA/0/AJk/Qwk+qGT0tCG5QIO600iF0NTKcY4kxP3gtjoPzdIVx9 2G6zKGvYw8DvUeFCoZk6Vtaqd2o4+jEWEnp/NCux1n2z5OvXEG7p0R6UFmnEdaC/2mTe ra3nsSQ1UWqXteU8O5nwytSH13FJiW8l6oJD9TbBoY/FJjflAKKrBMgJi2JnYqanzriM pqC0j1Vd3PiOWnR8dxh7ToofTSIWorgr3xTU5PVkpT0pC8zFCKsO6GxZcrMzPDBAaBQ4 vCtw== X-Gm-Message-State: AOJu0YywQ/Em0Is0WhgKwn/nWtmXvwn75+fZwzNPUTB/MhFHMpfsFwKt c6f1KNb89ZOUjBNtwUlHfkvh25zVshqerot6LSHFejYeoKRZf6q59e4ydLqjtuITFUcSXXr/bcS d X-Google-Smtp-Source: AGHT+IF7XgmNXk8AH99VyNhqznazLQIcdk/PHeLl9qAd7uj56dqWdFRVNuCI5Bk42WTi6n2tq/RsQw== X-Received: by 2002:a17:903:186:b0:1dd:7df8:9ed7 with SMTP id z6-20020a170903018600b001dd7df89ed7mr5526206plg.15.1711248086613; Sat, 23 Mar 2024 19:41:26 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id q17-20020a17090311d100b001dc3c4e7a12sm2244980plh.14.2024.03.23.19.41.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Mar 2024 19:41:26 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v11 8/9] log: add support for systemd journal Date: Sat, 23 Mar 2024 19:33:30 -0700 Message-ID: <20240324024109.306614-9-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324024109.306614-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240324024109.306614-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 being run as a systemd service, then it can use the journal protocol which allows putting more information in the log such as priority and other information. The use of journal protocol is automatically detected and handled. Rather than having a dependency on libsystemd, just use the protocol directly as defined in: https://systemd.io/JOURNAL_NATIVE_PROTOCOL/ The journal protocol supports more information that could be added later. Signed-off-by: Stephen Hemminger --- lib/log/log.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 136 insertions(+), 5 deletions(-) diff --git a/lib/log/log.c b/lib/log/log.c index bd488dff1b..4cfa160e3b 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -13,15 +13,20 @@ #include #include +#ifdef RTE_EXEC_ENV_WINDOWS +#include +#else +#include +#include +#include +#include +#endif + #include #include #include "log_internal.h" -#ifdef RTE_EXEC_ENV_WINDOWS -#include -#endif - struct rte_log_dynamic_type { const char *name; uint32_t loglevel; @@ -39,11 +44,13 @@ enum eal_log_time_format { typedef int (*log_print_t)(FILE *f, uint32_t level, const char *fmt, va_list ap); static int log_print(FILE *f, uint32_t level, const char *format, va_list ap); + /** The rte_log structure. */ static struct rte_logs { uint32_t type; /**< Bitfield with enabled logs. */ uint32_t level; /**< Log level. */ FILE *file; /**< Output file set by rte_openlog_stream, or NULL. */ + int journal_fd; /**< Journal file descriptor if using */ log_print_t print_func; enum eal_log_time_format time_format; @@ -681,6 +688,116 @@ log_print_with_timestamp(FILE *f, uint32_t level, return log_print(f, level, format, ap); } +#ifdef RTE_EXEC_ENV_LINUX +/* + * send message using journal protocol to journald + */ +__rte_format_printf(3, 0) +static int +journal_print(FILE *f __rte_unused, uint32_t level, const char *format, va_list ap) +{ + struct iovec iov[3]; + char *buf = NULL; + size_t len; + char msg[] = "MESSAGE="; + char *prio; + + iov[0].iov_base = msg; + iov[0].iov_len = strlen(msg); + + len = vasprintf(&buf, format, ap); + if (len == 0) + return 0; + + /* check that message ends with newline */ + if (buf[len - 1] != '\n') { + char *clone = alloca(len + 1); + if (clone == NULL) + return 0; + memcpy(clone, buf, len); + clone[len++] = '\n'; + buf = clone; + } + + iov[1].iov_base = buf; + iov[1].iov_len = len; + + /* priority value between 0 ("emerg") and 7 ("debug") */ + len = asprintf(&prio, "PRIORITY=%i\n", level - 1); + iov[2].iov_base = prio; + iov[2].iov_len = len; + + return writev(rte_logs.journal_fd, iov, 3); +} + +static void +journal_send_id(int fd, const char *id) +{ + char *syslog_id = NULL; + size_t len; + + len = asprintf(&syslog_id, "SYSLOG_IDENTIFIER=%s\n", id); + if (len > 0) + write(fd, syslog_id, len); + +} + +/* + * Check if stderr is going to system journal. + * This is the documented way to handle systemd journal + * + * See: https://systemd.io/JOURNAL_NATIVE_PROTOCOL/ + * + */ +static bool +using_journal(void) +{ + char *jenv, *endp = NULL; + struct stat st; + unsigned long dev, ino; + + jenv = getenv("JOURNAL_STREAM"); + if (jenv == NULL) + return false; + + if (fstat(STDERR_FILENO, &st) < 0) + return false; + + /* systemd sets colon-separated list of device and inode number */ + dev = strtoul(jenv, &endp, 10); + if (endp == NULL || *endp != ':') + return false; /* missing colon */ + + ino = strtoul(endp + 1, NULL, 10); + + return dev == st.st_dev && ino == st.st_ino; +} + +/* + * If we are being run as systemd service and stderr is going to journal + * then upgrade to use journal protocol. + */ +static int +open_journal(void) +{ + struct sockaddr_un sun = { + .sun_family = AF_UNIX, + .sun_path = "/run/systemd/journal/socket", + }; + int s; + + s = socket(AF_UNIX, SOCK_DGRAM, 0); + if (s < 0) + return -1; + + if (connect(s, (struct sockaddr *)&sun, sizeof(sun)) < 0) { + close(s); + return -1; + } + return s; +} +#endif + /* initialize logging */ void eal_log_init(const char *id __rte_unused) @@ -689,8 +806,22 @@ eal_log_init(const char *id __rte_unused) if (rte_logs.file != NULL) return; - if (rte_logs.time_format != EAL_LOG_TIMESTAMP_NONE) +#ifdef RTE_EXEC_ENV_LINUX + if (using_journal()) { + int jfd = open_journal(); + + if (jfd < 0) { + RTE_LOG_LINE(NOTICE, EAL, "Cannot connect to journal"); + } else { + rte_logs.journal_fd = jfd; + rte_logs.print_func = journal_print; + journal_send_id(jfd, id); + } + } else +#endif + if (rte_logs.time_format != EAL_LOG_TIMESTAMP_NONE) { rte_logs.print_func = log_print_with_timestamp; + } #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG RTE_LOG(NOTICE, EAL, From patchwork Sun Mar 24 02:33:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138762 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 642A743D36; Sun, 24 Mar 2024 03:42:28 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1FE9C40A6D; Sun, 24 Mar 2024 03:41:35 +0100 (CET) Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by mails.dpdk.org (Postfix) with ESMTP id 4966F4064A for ; Sun, 24 Mar 2024 03:41:28 +0100 (CET) Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1deffa23bb9so24371965ad.2 for ; Sat, 23 Mar 2024 19:41:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711248087; x=1711852887; 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=DmhxcTO2G7R7rt7pFjKteVsBa/8EY55YKFCvUAxoG4I=; b=NUEogCRp41zvGAHI/w9z0AfaT2gAH/4vCEZ9EAkjtfALEQFMgSGTugsh0R5oq6dBqC iEbcaf4/ReolRUCXao4/3mDGIRhmqVHBEpi7pCcYi9kgExU5Iln1Yy9FYyL/ZkBR5eJZ /K2l4c0d3aoGoSnz7Z36OMGwV7a/wofWeE2kuBYHQbJkX+kyy/ycCOhLnM/Gr0QrNRBD sPruzdbNImHuEwIUVJwLydTJIzvZ6tXAkTkMKb2+/DopOzA5oSCEZl1WP69oNmxKEPMs AkUhaGyCg4rpXzPfEhgf3gPKVYJi3tMopPl5zAljK5N8Dd16oDAZxVWNMbVWjpYJ9StQ GSxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711248087; x=1711852887; 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=DmhxcTO2G7R7rt7pFjKteVsBa/8EY55YKFCvUAxoG4I=; b=pkUp2NLaQtdIcacCDKCGbkDulMMwYlFg9lnDAf8S5qjnS6yYH7UcdyQ4CBUkWUlIUl EHUJHeVwq4G1jA/wc4vz2H50PlU/43iXlAnevDPj9/vSx26W9NQzeBo7i4jS3A8tbTCU EtFu2j4ivOCSNhPIYIqGM665aNJeyy1p+qUYNS+ULcD6FJk7eetU/5eShz26uh8i8QQT 83qtyl9wohX5Ee28AE1WuYt6k3qUxjCS5YBe1zEEnwU7J8JTpDB5cXOoC7wbc0mIxxS4 EoRMJhahVOfrqwLRuvcxzLjgktTggnv/9AFXns6halS4MRRonEKCvnaTLc8BjQD1crv1 hzgQ== X-Gm-Message-State: AOJu0YzuXIOGmlCcm9rEHZAW+TLIi9m3/YQIJpMnkY0sjhh6CUj1401U O1+gCi1kqUtUrouBnZCH/sWM2HmZRTB1mbb6fv2gyWm+lBfbxkUrU7+4cROZI+5XQmX0IMM3KrE n X-Google-Smtp-Source: AGHT+IFRH+nr4yLeqrH6sLgIz0L2ylLruCRo3j6KSUII6QJUqGDtXx9pL2n8jIkJaYX2vSAVUDWGLQ== X-Received: by 2002:a17:902:b48b:b0:1dc:abeb:22fe with SMTP id y11-20020a170902b48b00b001dcabeb22femr3227103plr.65.1711248087348; Sat, 23 Mar 2024 19:41:27 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id q17-20020a17090311d100b001dc3c4e7a12sm2244980plh.14.2024.03.23.19.41.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Mar 2024 19:41:27 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v11 9/9] log: colorize log output Date: Sat, 23 Mar 2024 19:33:31 -0700 Message-ID: <20240324024109.306614-10-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324024109.306614-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240324024109.306614-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 Like dmesg, colorize the log output (unless redirected to file). Timestamp is green, the subsystem is in yellow and the message is red if urgent, boldface if an error, and normal for info and debug messages. Signed-off-by: Stephen Hemminger --- doc/guides/prog_guide/log_lib.rst | 14 ++- lib/eal/common/eal_common_options.c | 1 + lib/eal/common/eal_options.h | 2 + lib/log/log.c | 153 +++++++++++++++++++++++++++- lib/log/log_internal.h | 5 + lib/log/version.map | 1 + 6 files changed, 173 insertions(+), 3 deletions(-) diff --git a/doc/guides/prog_guide/log_lib.rst b/doc/guides/prog_guide/log_lib.rst index 83949cce35..e0cb9bb9ed 100644 --- a/doc/guides/prog_guide/log_lib.rst +++ b/doc/guides/prog_guide/log_lib.rst @@ -58,6 +58,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. +Color output +~~~~~~~~~~~~ + +It is useful ot be able see important messages highlighted. This is controlled by the +``--log-color`` option. The optional argument ``when`` can be ``auto``, ``never``, +or ``always``.The default setting is ``auto`` which enables color when the output to +``stderr`` is a terminal. If the ``when`` argument is omitted, it defaults to ``always``. + +For example to turn off all coloring:: + + /path/to/app --log-color=none + + Console timestamp ~~~~~~~~~~~~~~~~~ @@ -83,7 +96,6 @@ To prefix all console messages with ISO format time the syntax is:: /path/to/app --log-timestamp=iso - 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 bc6d87266d..0da6729c64 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -75,6 +75,7 @@ eal_long_options[] = { {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_LOG_COLOR, 1, NULL, OPT_LOG_COLOR_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 }, diff --git a/lib/eal/common/eal_options.h b/lib/eal/common/eal_options.h index 197b7b25ef..c1696d75e5 100644 --- a/lib/eal/common/eal_options.h +++ b/lib/eal/common/eal_options.h @@ -37,6 +37,8 @@ enum { OPT_LOG_LEVEL_NUM, #define OPT_LOG_TIMESTAMP "log-timestamp" OPT_LOG_TIMESTAMP_NUM, +#define OPT_LOG_COLOR "log-color" + OPT_LOG_COLOR_NUM, #define OPT_TRACE "trace" OPT_TRACE_NUM, #define OPT_TRACE_DIR "trace-dir" diff --git a/lib/log/log.c b/lib/log/log.c index 4cfa160e3b..e75ed804ec 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -22,6 +22,7 @@ #include #endif +#include #include #include @@ -41,6 +42,12 @@ enum eal_log_time_format { EAL_LOG_TIMESTAMP_ISO, }; +enum eal_log_color { + EAL_LOG_COLOR_AUTO = 0, /* default */ + EAL_LOG_COLOR_NEVER, + EAL_LOG_COLOR_ALWAYS, +}; + typedef int (*log_print_t)(FILE *f, uint32_t level, const char *fmt, va_list ap); static int log_print(FILE *f, uint32_t level, const char *format, va_list ap); @@ -53,6 +60,7 @@ static struct rte_logs { int journal_fd; /**< Journal file descriptor if using */ log_print_t print_func; + enum eal_log_color color_mode; enum eal_log_time_format time_format; struct timespec started; /* when log was initialized */ struct timespec previous; /* when last msg was printed */ @@ -665,6 +673,74 @@ format_timestamp(char *tsbuf, size_t tsbuflen) return 0; } +enum color { + COLOR_NONE, + COLOR_RED, + COLOR_GREEN, + COLOR_YELLOW, + COLOR_BLUE, + COLOR_MAGENTA, + COLOR_CYAN, + COLOR_WHITE, + COLOR_BOLD, + COLOR_CLEAR +}; + +static const char * const color_code[] = { + [COLOR_NONE] = "", + [COLOR_RED] = "\e[31m", + [COLOR_GREEN] = "\e[32m", + [COLOR_YELLOW] = "\e[33m", + [COLOR_BLUE] = "\e[34m", + [COLOR_MAGENTA] = "\e[35m", + [COLOR_CYAN] = "\e[36m", + [COLOR_WHITE] = "\e[37m", + [COLOR_BOLD] = "\e[1m", + [COLOR_CLEAR] = "\e[0m", +}; + +__rte_format_printf(3, 4) +static int color_fprintf(FILE *out, enum color color, const char *fmt, ...) +{ + va_list args; + int ret = 0; + + va_start(args, fmt); + ret = fprintf(out, "%s", color_code[color]); + ret += vfprintf(out, fmt, args); + ret += fprintf(out, "%s", color_code[COLOR_CLEAR]); + + return ret; +} + +static ssize_t +color_log_write(FILE *f, int level, char *msg) +{ + char *cp; + ssize_t ret = 0; + + /* + * use convention that first part of message (up to the ':' character) + * is the subsystem id and should be highlighted. + */ + cp = strchr(msg, ':'); + if (cp) { + /* print first part in yellow */ + ret = color_fprintf(stderr, COLOR_YELLOW, "%.*s", + (int)(cp - msg + 1), msg); + msg = cp + 1; + } + + if (level <= 0 || level >= (int)RTE_LOG_INFO) + ret += fprintf(f, "%s", msg); + else if (level >= (int)RTE_LOG_ERR) + ret += color_fprintf(f, COLOR_BOLD, "%s", msg); + else + ret += color_fprintf(f, COLOR_RED, "%s", msg); + + return ret; +} + /* default log print function */ __rte_format_printf(3, 0) static int @@ -688,6 +764,70 @@ log_print_with_timestamp(FILE *f, uint32_t level, return log_print(f, level, format, ap); } +__rte_format_printf(3, 0) +static int +color_print(FILE *f, uint32_t level, const char *format, va_list ap) +{ + char *buf = NULL; + + /* need to make temporary buffer for color scan */ + if (vasprintf(&buf, format, ap) > 0) + return color_log_write(f, level, buf); + + /* if vasprintf fails, print without color */ + return log_print(f, level, format, ap); +} + +__rte_format_printf(3, 0) +static int +color_print_with_timestamp(FILE *f, uint32_t level, + const char *format, va_list ap) +{ + char tsbuf[128]; + + if (format_timestamp(tsbuf, sizeof(tsbuf)) > 0) + color_fprintf(f, COLOR_GREEN, "[%s] ", tsbuf); + + return color_print(f, level, format, ap); +} + +/* + * Controls whether color is enabled: + * modes are: + * always - enable color output regardless + * auto - enable if stderr is a terminal + * never - color output is disabled. + */ +int +eal_log_color(const char *mode) +{ + if (mode == NULL || strcmp(mode, "always") == 0) + rte_logs.color_mode = EAL_LOG_COLOR_ALWAYS; + else if (strcmp(mode, "never") == 0) + rte_logs.color_mode = EAL_LOG_COLOR_NEVER; + else if (strcmp(mode, "auto") == 0) + rte_logs.color_mode = EAL_LOG_COLOR_AUTO; + else + return -1; + + return 0; +} + +static bool +use_color(int out_fd) +{ + switch (rte_logs.color_mode) { + default: + case EAL_LOG_COLOR_NEVER: + return false; + case EAL_LOG_COLOR_ALWAYS: + return true; + case EAL_LOG_COLOR_AUTO: + return !!isatty(out_fd); + } + +} + #ifdef RTE_EXEC_ENV_LINUX /* * send message using journal protocol to journald @@ -817,10 +957,19 @@ eal_log_init(const char *id __rte_unused) rte_logs.print_func = journal_print; journal_send_id(jfd, id); } + } else #endif - if (rte_logs.time_format != EAL_LOG_TIMESTAMP_NONE) { - rte_logs.print_func = log_print_with_timestamp; + if (use_color(STDERR_FILENO)) { + if (rte_logs.time_format != EAL_LOG_TIMESTAMP_NONE) + rte_logs.print_func = color_print_with_timestamp; + else + rte_logs.print_func = color_print; + } else { + if (rte_logs.time_format != EAL_LOG_TIMESTAMP_NONE) + rte_logs.print_func = log_print_with_timestamp; + else + rte_logs.print_func = log_print; } #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG diff --git a/lib/log/log_internal.h b/lib/log/log_internal.h index 3544ae49ac..5b8bb6ffc9 100644 --- a/lib/log/log_internal.h +++ b/lib/log/log_internal.h @@ -50,5 +50,10 @@ void rte_eal_log_cleanup(void); __rte_internal int eal_log_timestamp(const char *fmt); +/* + * Enable or disable color in log messages + */ +__rte_internal +int eal_log_color(const char *mode); #endif /* LOG_INTERNAL_H */ diff --git a/lib/log/version.map b/lib/log/version.map index 7fd5b39e3a..9ca561b05b 100644 --- a/lib/log/version.map +++ b/lib/log/version.map @@ -25,6 +25,7 @@ DPDK_24 { INTERNAL { global: + eal_log_color; eal_log_init; eal_log_level2str; eal_log_save_pattern;