From patchwork Wed Jul 5 22:48:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 129314 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 5CDB542DDE; Thu, 6 Jul 2023 00:48:15 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 22C4D42D4D; Thu, 6 Jul 2023 00:48:12 +0200 (CEST) Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) by mails.dpdk.org (Postfix) with ESMTP id AC1A742D46 for ; Thu, 6 Jul 2023 00:48:10 +0200 (CEST) Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-262e44b8bf6so112603a91.1 for ; Wed, 05 Jul 2023 15:48:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20221208.gappssmtp.com; s=20221208; t=1688597289; x=1691189289; 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=NMYGU1aLaJffTe9FX1Ef551Tl8K520p4GCfWy/DHdrs=; b=E0PaxfBRd8dVSsUyVeDivamQK7pAzZy3JSchQdxWP/pVdd5vWRB1OSgR/Yg4JpaSWM R3JnUIl2SbjesuKCXDLD+oOq8HCeDBlt6LIgP6iEo4rAZ2pGqknhkIByWvU9shg07FtQ 8m4Cfn2z/dFdxmTq73yUxH1q0TlJxNsSKMSdOjVKJ2Fggm7K1HkxAtxxQfSLo1zj/ZPe 3/yT8iiAvxAGaX74E/+0D7MWamx0eIk4NNF1YiKJSIIHw8dJkVqx9UjVK40AwG7RPJIK 77duUvjOydBaLi5UXpOy9ZG47WT4P6JzfjLTioB++aCFOCmJJTyBl5tLYiRg2hpxvHMy cmIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688597289; x=1691189289; 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=NMYGU1aLaJffTe9FX1Ef551Tl8K520p4GCfWy/DHdrs=; b=HgX5i3lFGzJi4NKWH1fIDqVIt1LeCuDsCvhvxP/JRCs02R9qL+JC52mEpDTivkANzn kVRfC7ip2tn4C0PWx3N9/5RpQ3bOelzYbXOYd3ASO8ryVvgCsqS5rV2sWT67PPyRKR3H TFuup40Hm90NFjwRkmakERFJCwImt4qhBTbpeh5/5bDEI0JMt/KFMDG6mbvzx+Cnjlp8 Zi0io11gAuXljXm8rwmZqKi2cc4DFIbLvLHss4OlSM4i3FIWJXL/tcdLJdPLsdSNpXQo q9nfPsY882kTHSezwUIcA1Jh/vMHlauYQwIYtzM+uiiVmqTpgp71hAtwLEnFqgqZFpd3 rVwA== X-Gm-Message-State: ABy/qLYdNoS0zaOe6ATgPklrF+opQkiGlGE9d5zXq+QuOygfjIXRwCM6 c0sFjQDUZq23F0B2UrcEtpFnBJkJdCmsCGkewRQ= X-Google-Smtp-Source: APBJJlFNUCYT9LnQF9gHsxQ66SOWLNwF8OQPPrWRR1nDisPniRpb/K8zeNjluvaqqD3hF6K6bfCWdQ== X-Received: by 2002:a17:90b:783:b0:262:cb1c:a782 with SMTP id l3-20020a17090b078300b00262cb1ca782mr70912pjz.37.1688597289480; Wed, 05 Jul 2023 15:48:09 -0700 (PDT) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id bb16-20020a17090b009000b002630bfd35b0sm1906044pjb.7.2023.07.05.15.48.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 15:48:09 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Dmitry Kozlyuk , Narcisa Ana Maria Vasile , Dmitry Malloy , Pallavi Kadam Subject: [PATCH v7 1/5] windows: make getopt functions have const properties Date: Wed, 5 Jul 2023 15:48:01 -0700 Message-Id: <20230705224805.286156-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230705224805.286156-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20230705224805.286156-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 aligns getopt, getopt_long, etc to have the same const attributes as Linux and FreeBSD. The changes are derived from the FreeBSD version of getopt_long. Signed-off-by: Stephen Hemminger Acked-by: Tyler Retzlaff --- 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 Wed Jul 5 22:48:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 129315 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 DF4EF42DDE; Thu, 6 Jul 2023 00:48:21 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3256E42D55; Thu, 6 Jul 2023 00:48:13 +0200 (CEST) Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) by mails.dpdk.org (Postfix) with ESMTP id AA88442D4D for ; Thu, 6 Jul 2023 00:48:11 +0200 (CEST) Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-262e81f6154so108174a91.2 for ; Wed, 05 Jul 2023 15:48:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20221208.gappssmtp.com; s=20221208; t=1688597290; x=1691189290; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pp72RlIvGuDF0mhsFUm63/uvVcS7XvB1ShVEfHsSG9g=; b=ipt4/yz+hMrVYf6xgJ+l5UmLW9a8OhFCKzcO5hOFmSQMYmjsEVpnlri5X1rn/sV7v8 16ZlPMvdW1RQ8pacT56cTa29gM0PsZ3Qe1YO62Xttg94BMKFV/INLgheQmM1UgyHaZJs Be9SKml+J8GSx3MFM6NPxFGeYacexcdC1H0e5+aWofW3HCvo2OZeccfEh014AdIIh0x7 LeuSpNn3T2ta+MbEm2CgpItmr7IpEf8e8B6iIJpTt01TqPdH7a//rObLIlw8zLVMn+U7 9zaEVNTi/j1GoXBqMyfgdZz8EygPYziHfj/6WHLKE+caQ/FT2TflAPwGJVEvBf155QyD PHow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688597290; x=1691189290; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pp72RlIvGuDF0mhsFUm63/uvVcS7XvB1ShVEfHsSG9g=; b=gkL9XjSjXXVbQQoi49UAcYvQymqqHLAdudcJWpekxT59cD/MJbPhQCdg4CpPQ4ExEn RZ1UoIrZUG+a3WwaugEGh9NMRVB3QkN5W+pbcjJWlD7ZyiBbn2ExokGnK7ghqIrBb8Pe RK6PINYiIZK8iQ1Z4DUN38AeqTjq0cVXUk/qwkEVwQZ/HhwmLeY9WtAIewdE4ExxUK1p AKJjiJ6deC9r2ImxF9t+KBhQlTx7t7HUWvEycutLRCLqeRCEX5/SIqzBLn4HK3NIphKl YVbm0TbvDlVnieZsK+Hjt65IbdtFqgMhchWueVzF4wutvp4feZ0v19qlOdOc7ehLfcVs tAYA== X-Gm-Message-State: ABy/qLZQ5PlRiubSJQkhcNzjl1tKlZeA6H3/kb7MiKsID48ufOeTUTD5 gQySLBHom1dWMoPPE1fy7xEXhRB7XKBVWFErYO4= X-Google-Smtp-Source: APBJJlFJEwwCITNwS9KGiYWLd6jsXexyKnyzb0HOBq9paPQH1AFEoYMM4QRf4NrYmkeQCiLxef1aOQ== X-Received: by 2002:a17:90a:faf:b0:262:e961:4060 with SMTP id 44-20020a17090a0faf00b00262e9614060mr107173pjz.16.1688597290584; Wed, 05 Jul 2023 15:48:10 -0700 (PDT) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id bb16-20020a17090b009000b002630bfd35b0sm1906044pjb.7.2023.07.05.15.48.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 15:48:10 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v7 2/5] eal: fix help message for syslog option Date: Wed, 5 Jul 2023 15:48:02 -0700 Message-Id: <20230705224805.286156-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230705224805.286156-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20230705224805.286156-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The --syslog flag takes facility argument. Signed-off-by: Stephen Hemminger --- lib/eal/common/eal_common_options.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index 03059336987d..005da4d12001 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -2193,7 +2193,7 @@ eal_common_usage(void) " --"OPT_VMWARE_TSC_MAP" Use VMware TSC map instead of native RDTSC\n" " --"OPT_PROC_TYPE" Type of this process (primary|secondary|auto)\n" #ifndef RTE_EXEC_ENV_WINDOWS - " --"OPT_SYSLOG" Set syslog facility\n" + " --"OPT_SYSLOG"= Set syslog facility\n" #endif " --"OPT_LOG_LEVEL"= Set global log level\n" " --"OPT_LOG_LEVEL"=:\n" From patchwork Wed Jul 5 22:48:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 129316 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 E1BDF42DDE; Thu, 6 Jul 2023 00:48:27 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5784242D4B; Thu, 6 Jul 2023 00:48:15 +0200 (CEST) Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) by mails.dpdk.org (Postfix) with ESMTP id BFC0142D50 for ; Thu, 6 Jul 2023 00:48:12 +0200 (CEST) Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-262e5e71978so33762a91.1 for ; Wed, 05 Jul 2023 15:48:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20221208.gappssmtp.com; s=20221208; t=1688597292; x=1691189292; 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=2oKzsvdvjYPQihIdA7H/3xJp7JRwySRFEKzx+/Tx6+Y=; b=G1vTiB1SviY15PMAaYfvNNolkSRvuIVgJA3XSS24ZFNaW2e4h2hebvPObNOEMTQk/Y S+ah6csEHViCgvdlpHvdZbN6u7i4pAK7r2QAzPA2+K+t6CxfIBmFvioSx6wCCJx47CSz MoMuLiA7XGETUgSrkEtpEk/7v2ThVWMnubaVvdBehN4AdIVwyUTEwV8D3I/8FuDFY8Rf wDd217oyV9M/pB6UF39P6Ekd1j5JH7vLyZsEwewOWSckyQJe3m4X83Hs/z0S06Kt4NEI m3RfB/jbcilCf88mWcpLcTN/+G/K4fX9SPP5wim7Aj2J5Pp2GwZC4BzbK1UwPuomPbvV wK6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688597292; x=1691189292; 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=2oKzsvdvjYPQihIdA7H/3xJp7JRwySRFEKzx+/Tx6+Y=; b=dOOxvyW0aiYWM3bVf8vSXxLR6aDRIecPqC/Zhy4Hs43ps67O7w+KYlI0aSk0c8Vbjp HWARLurPx3AYVbV+8xKnn+/+MzIDk0ZsNeB3r/2OQZALxH17Ve61m0AF9bTWkdP6mQYY dTzpgo96bQBu9tHgxcSUC+g4Qhd2yoYJavGabyQL7sRYA9MOi3pUaBOnJJZJjef39yPk mWvyoFwfzSF8A21ST9GRniJBCqsxNFiD3/qd+hLeCHulnxwFosDEK4HtvRnicM9BpSMF PZuolukwg3Imr56928+dGpVE/iF2BSokBf2SYq/S0LXH2OG/T84UP6sEk9LeR04GTFAF 3XZQ== X-Gm-Message-State: ABy/qLaoEamUU+5LT6Qh9VmYo1gSxax6SB2DuWhhN2OuKjtjxlxwHeNj SgRV0X+rWdf3EWQMg3PIX132a51Yuh91kVC/PEo= X-Google-Smtp-Source: APBJJlEik641ndqawo+Uqb/cF8Zcq0UcNufUmNqWSKt8SgIyE9tIR5roHm6L28Ce5g4uQsmihCLF6A== X-Received: by 2002:a17:90a:8b07:b0:263:1e6c:16f4 with SMTP id y7-20020a17090a8b0700b002631e6c16f4mr5127145pjn.20.1688597291647; Wed, 05 Jul 2023 15:48:11 -0700 (PDT) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id bb16-20020a17090b009000b002630bfd35b0sm1906044pjb.7.2023.07.05.15.48.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 15:48:11 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Bruce Richardson , Dmitry Kozlyuk , Narcisa Ana Maria Vasile , Dmitry Malloy , Pallavi Kadam Subject: [PATCH v7 3/5] eal: unify logging code Date: Wed, 5 Jul 2023 15:48:03 -0700 Message-Id: <20230705224805.286156-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230705224805.286156-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20230705224805.286156-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org FreeBSD logging code was not using syslog and did not have the same options as Linux. Use a common set of functions for that. Pre-parsing for log level is common to all OS's. Now the pre-scan can return an error. A bad argument give to --log-level option was given the code would keep going. Use opterr to fix duplicate error message on bad option. Signed-off-by: Stephen Hemminger --- .../freebsd_gsg/freebsd_eal_parameters.rst | 27 +++++++++ lib/eal/common/eal_common_log.c | 49 +++++++++++++++++ lib/eal/common/eal_log.h | 5 ++ lib/eal/freebsd/eal.c | 55 ++++--------------- lib/eal/linux/eal.c | 46 ++-------------- lib/eal/linux/meson.build | 1 - lib/eal/{linux => unix}/eal_log.c | 11 ++++ lib/eal/unix/meson.build | 1 + lib/eal/windows/eal.c | 36 +----------- 9 files changed, 112 insertions(+), 119 deletions(-) rename lib/eal/{linux => unix}/eal_log.c (76%) diff --git a/doc/guides/freebsd_gsg/freebsd_eal_parameters.rst b/doc/guides/freebsd_gsg/freebsd_eal_parameters.rst index fba467a2ce92..9270d9fa3bfc 100644 --- a/doc/guides/freebsd_gsg/freebsd_eal_parameters.rst +++ b/doc/guides/freebsd_gsg/freebsd_eal_parameters.rst @@ -18,3 +18,30 @@ FreeBSD-specific EAL parameters ------------------------------- There are currently no FreeBSD-specific EAL command-line parameters available. + +Other options +~~~~~~~~~~~~~ + +* ``--syslog `` + + Set syslog facility. Valid syslog facilities are:: + + auth + cron + daemon + ftp + kern + lpr + mail + news + syslog + user + uucp + local0 + local1 + local2 + local3 + local4 + local5 + local6 + local7 diff --git a/lib/eal/common/eal_common_log.c b/lib/eal/common/eal_common_log.c index bd7b188ceb4a..1b2080e8ef04 100644 --- a/lib/eal/common/eal_common_log.c +++ b/lib/eal/common/eal_common_log.c @@ -2,6 +2,7 @@ * Copyright(c) 2010-2014 Intel Corporation */ +#include #include #include #include @@ -16,6 +17,8 @@ #include #include "eal_log.h" +#include "eal_internal_cfg.h" +#include "eal_options.h" #include "eal_private.h" struct rte_log_dynamic_type { @@ -223,6 +226,52 @@ log_save_level(uint32_t priority, const char *regex, const char *pattern) return -1; } + +/* Parse the all arguments looking for --log-level */ +int +eal_log_level_parse(int argc, char * const argv[]) +{ + struct internal_config *internal_conf = eal_get_internal_configuration(); + int option_index, opt; + const int old_optind = optind; + const int old_optopt = optopt; + 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_log_save_regexp(const char *regex, uint32_t level) { diff --git a/lib/eal/common/eal_log.h b/lib/eal/common/eal_log.h index c784fa604389..31dc489350f6 100644 --- a/lib/eal/common/eal_log.h +++ b/lib/eal/common/eal_log.h @@ -13,6 +13,11 @@ */ int eal_log_init(const char *id, int facility); +/* + * Scan command line args for log settings. + */ +int eal_log_level_parse(int argc, char * const argv[]); + /* * Determine where log data is written when no call to rte_openlog_stream. */ diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index 7008303e112a..bb9a2b1653d9 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -52,6 +52,7 @@ #include "eal_hugepages.h" #include "eal_options.h" #include "eal_memcfg.h" +#include "eal_log.h" #include "eal_trace.h" #define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL) @@ -363,48 +364,6 @@ eal_get_hugepage_mem_size(void) return (size < SIZE_MAX) ? (size_t)(size) : SIZE_MAX; } -/* Parse the arguments for --log-level only */ -static void -eal_log_level_parse(int argc, char **argv) -{ - int opt; - char **argvopt; - int option_index; - const int old_optind = optind; - const int old_optopt = optopt; - const int old_optreset = optreset; - char * const old_optarg = optarg; - struct internal_config *internal_conf = - eal_get_internal_configuration(); - - argvopt = argv; - optind = 1; - optreset = 1; - - while ((opt = getopt_long(argc, argvopt, eal_short_options, - eal_long_options, &option_index)) != EOF) { - - int ret; - - /* getopt is not happy, stop right now */ - if (opt == '?') - break; - - ret = (opt == OPT_LOG_LEVEL_NUM) ? - eal_parse_common_option(opt, optarg, internal_conf) : 0; - - /* common parser is not happy */ - if (ret < 0) - break; - } - - /* restore getopt lib */ - optind = old_optind; - optopt = old_optopt; - optreset = old_optreset; - optarg = old_optarg; -} - /* Parse the argument given in the command line of the application */ static int eal_parse_args(int argc, char **argv) @@ -610,7 +569,11 @@ rte_eal_init(int argc, char **argv) eal_save_args(argc, argv); /* set log level as early as possible */ - eal_log_level_parse(argc, argv); + if (eal_log_level_parse(argc, argv) < 0) { + rte_eal_init_alert("invalid log option."); + rte_errno = EINVAL; + return -1; + } if (rte_eal_cpu_init() < 0) { rte_eal_init_alert("Cannot detect lcores."); @@ -759,6 +722,12 @@ rte_eal_init(int argc, char **argv) #endif } + if (eal_log_init(getprogname(), internal_conf->syslog_facility) < 0) { + rte_eal_init_alert("Cannot init logging."); + rte_errno = ENOMEM; + return -1; + } + /* in secondary processes, memory init may allocate additional fbarrays * not present in primary processes, so to avoid any potential issues, * initialize memzones first. diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index 145afafde234..c9475560d986 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -546,45 +546,6 @@ eal_parse_vfio_vf_token(const char *vf_token) return -1; } -/* Parse the arguments for --log-level only */ -static void -eal_log_level_parse(int argc, char **argv) -{ - int opt; - char **argvopt; - int option_index; - const int old_optind = optind; - const int old_optopt = optopt; - char * const old_optarg = optarg; - struct internal_config *internal_conf = - eal_get_internal_configuration(); - - argvopt = argv; - optind = 1; - - while ((opt = getopt_long(argc, argvopt, eal_short_options, - eal_long_options, &option_index)) != EOF) { - - int ret; - - /* getopt is not happy, stop right now */ - if (opt == '?') - break; - - ret = (opt == OPT_LOG_LEVEL_NUM) ? - eal_parse_common_option(opt, optarg, internal_conf) : 0; - - /* common parser is not happy */ - if (ret < 0) - break; - } - - /* restore getopt lib */ - optind = old_optind; - optopt = old_optopt; - optarg = old_optarg; -} - static int eal_parse_huge_worker_stack(const char *arg) { @@ -993,7 +954,12 @@ rte_eal_init(int argc, char **argv) eal_reset_internal_config(internal_conf); /* set log level as early as possible */ - eal_log_level_parse(argc, argv); + if (eal_log_level_parse(argc, argv) < 0) { + rte_eal_init_alert("invalid log option."); + rte_errno = EINVAL; + __atomic_store_n(&run_once, 0, __ATOMIC_RELAXED); + return -1; + } /* clone argv to report out later in telemetry */ eal_save_args(argc, argv); diff --git a/lib/eal/linux/meson.build b/lib/eal/linux/meson.build index 5af456db9edb..e99ebed25692 100644 --- a/lib/eal/linux/meson.build +++ b/lib/eal/linux/meson.build @@ -11,7 +11,6 @@ sources += files( 'eal_hugepage_info.c', 'eal_interrupts.c', 'eal_lcore.c', - 'eal_log.c', 'eal_memalloc.c', 'eal_memory.c', 'eal_thread.c', diff --git a/lib/eal/linux/eal_log.c b/lib/eal/unix/eal_log.c similarity index 76% rename from lib/eal/linux/eal_log.c rename to lib/eal/unix/eal_log.c index d44416fd6570..85d817c2d31e 100644 --- a/lib/eal/linux/eal_log.c +++ b/lib/eal/unix/eal_log.c @@ -9,6 +9,8 @@ #include #include "eal_log.h" +#include "eal_internal_cfg.h" +#include "eal_private.h" /* * default log function @@ -25,6 +27,15 @@ console_log_write(__rte_unused void *c, const char *buf, size_t size) /* Syslog error levels are from 0 to 7, so subtract 1 to convert */ syslog(rte_log_cur_msg_loglevel() - 1, "%.*s", (int)size, buf); +#ifdef RTE_EXEC_ENV_LINUX + /* Handle glibc quirk: write function should return the number of bytes + * copied from buf, or 0 on error. (The function must not return a negative value.) + * FreeBSD expects that write function behaves like write(2). + */ + if (ret < 0) + ret = 0; +#endif + return ret; } diff --git a/lib/eal/unix/meson.build b/lib/eal/unix/meson.build index cc7d67dd321d..37d07594df29 100644 --- a/lib/eal/unix/meson.build +++ b/lib/eal/unix/meson.build @@ -6,6 +6,7 @@ sources += files( 'eal_file.c', 'eal_filesystem.c', 'eal_firmware.c', + 'eal_log.c', 'eal_unix_memory.c', 'eal_unix_thread.c', 'eal_unix_timer.c', diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c index 2d7a0e9ab27e..c6006c48ddef 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) @@ -143,6 +108,7 @@ eal_parse_args(int argc, char **argv) eal_get_internal_configuration(); argvopt = argv; + opterr = 1; while ((opt = getopt_long(argc, argvopt, eal_short_options, eal_long_options, &option_index)) != EOF) { From patchwork Wed Jul 5 22:48:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 129317 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 96A6242DDE; Thu, 6 Jul 2023 00:48:34 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8EB4E42D61; Thu, 6 Jul 2023 00:48:16 +0200 (CEST) Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) by mails.dpdk.org (Postfix) with ESMTP id E252042D5A for ; Thu, 6 Jul 2023 00:48:13 +0200 (CEST) Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-262e3c597b9so133272a91.0 for ; Wed, 05 Jul 2023 15:48:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20221208.gappssmtp.com; s=20221208; t=1688597293; x=1691189293; 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=tu64yanKVd/U/fBF/GuU00+xQ7H4v2dyUbNhKOpsKv0=; b=2sSn+bI+aTKE1RKQinc1Rb4B+XushAbPGSJ15OpLpzVhGDJvG5pbiVmKl6/+q2UzXk 5BZvOrQuQ9usl9+vOIJ7/sxD6CzjLijK+ac0jqmcGYMLe6O3bEmBnFVJc7VBeVl4VimU UasBu5GoMXbiWk7/UDTBojHn6mozH2+UlsYSQWWuAfB2bNNhPYC4XgoL2ZfuroqS/vIC b9TAXt6RtcdyOv3m2GGB0DmIVqdarUzldzjwWIzIiw7KBimFJtxoRn/dbn6y8ti3hFr8 xmnNPHj+bTkI5aR++J7UV0UM6XQy6GdxrBIotrmpym06eQb6TVvUwRNDFTfVHcklUcQq IdoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688597293; x=1691189293; 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=tu64yanKVd/U/fBF/GuU00+xQ7H4v2dyUbNhKOpsKv0=; b=VycgAkxAGksnDRkiIN2xJ7JaFWFgBshz+rqeZ/N33tZb8BQsRVk+dIJGFPsKIHmvXs lXGDkt2sXInMl1pE6qh1rxT6b1qiyRZKfBuTdijbTFaiGNhBeiaZPUY8RqLJ4R8LSRmR QBQKOle05OJLwvka5QvSgU4763oyjji0bTcqeu8r/h1PydfyMZgEnuqdfVu77xyoS2O6 Wat4VqUetOmihF+GfXQ5pj01zlNhGRX55BDC2TP3vLJkRAO/5zn8LiBFXom/gUptEOMk 0gor3ju/+86Rg2g3R8CkTaxhox6dLfXsLrbZ7C8yCddCNnO4XVWaZHFxDzsDe5L+LG82 oA5Q== X-Gm-Message-State: ABy/qLZ7A1LFccml/Wv6JpG1X33CuFJePQZ9tjNvfYjm42iO29yvdmTU 3uITKiO27IrUlfMxWVtBvDhxqyvJqcEuJrY4o3Y= X-Google-Smtp-Source: APBJJlGZiDJYF+L7r+KzjTZIj01D1Gh+sR3kfxr6o5g/MMnI3MMiiW+9E1Zdr/5sjYCT6+3UC5n+Aw== X-Received: by 2002:a17:90a:ac0d:b0:261:38ca:3c48 with SMTP id o13-20020a17090aac0d00b0026138ca3c48mr150843pjq.11.1688597292798; Wed, 05 Jul 2023 15:48:12 -0700 (PDT) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id bb16-20020a17090b009000b002630bfd35b0sm1906044pjb.7.2023.07.05.15.48.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 15:48:12 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Reshma Pattan , Maryam Tahhan Subject: [PATCH v7 4/5] eal: allow user to set default log stream before init Date: Wed, 5 Jul 2023 15:48:04 -0700 Message-Id: <20230705224805.286156-5-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230705224805.286156-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20230705224805.286156-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org It is useful for application to be able to set the default log stream before call rte_eal_init(). This makes all messages go to the new default. For example, to skip using syslog; just doing rte_openlog_stream(stderr); There is no reason for helper command line applications to clutter syslog with messages. Signed-off-by: Stephen Hemminger --- app/dumpcap/main.c | 3 +++ app/pdump/main.c | 3 +++ app/proc-info/main.c | 3 +++ lib/eal/common/eal_common_log.c | 6 ++++++ lib/eal/common/eal_log.h | 1 + lib/eal/unix/eal_log.c | 4 ++++ 6 files changed, 20 insertions(+) diff --git a/app/dumpcap/main.c b/app/dumpcap/main.c index 64294bbfb3e6..bf31eef13cf4 100644 --- a/app/dumpcap/main.c +++ b/app/dumpcap/main.c @@ -639,6 +639,9 @@ static void dpdk_init(void) eal_argv[i++] = strdup(file_prefix); } + /* keep any logging away from syslog. */ + rte_openlog_stream(stderr); + if (rte_eal_init(eal_argc, eal_argv) < 0) rte_exit(EXIT_FAILURE, "EAL init failed: is primary process running?\n"); } diff --git a/app/pdump/main.c b/app/pdump/main.c index c94606275b28..82c67350e4ab 100644 --- a/app/pdump/main.c +++ b/app/pdump/main.c @@ -989,6 +989,9 @@ main(int argc, char **argv) argc += 2; + /* keep any logging away from syslog. */ + rte_openlog_stream(stderr); + diag = rte_eal_init(argc, argp); if (diag < 0) rte_panic("Cannot init EAL\n"); diff --git a/app/proc-info/main.c b/app/proc-info/main.c index 53e852a07c14..371b1f382d66 100644 --- a/app/proc-info/main.c +++ b/app/proc-info/main.c @@ -1774,6 +1774,9 @@ main(int argc, char **argv) argc += 4; + /* keep any logging away from syslog. */ + rte_openlog_stream(stderr); + ret = rte_eal_init(argc, argp); if (ret < 0) rte_panic("Cannot init EAL\n"); diff --git a/lib/eal/common/eal_common_log.c b/lib/eal/common/eal_common_log.c index 1b2080e8ef04..1533ee871f47 100644 --- a/lib/eal/common/eal_common_log.c +++ b/lib/eal/common/eal_common_log.c @@ -584,6 +584,12 @@ eal_log_set_default(FILE *default_log) #endif } +FILE * +eal_log_get_default(void) +{ + return default_log_stream; +} + /* * Called by eal_cleanup */ diff --git a/lib/eal/common/eal_log.h b/lib/eal/common/eal_log.h index 31dc489350f6..268c2a264382 100644 --- a/lib/eal/common/eal_log.h +++ b/lib/eal/common/eal_log.h @@ -22,6 +22,7 @@ int eal_log_level_parse(int argc, char * const argv[]); * Determine where log data is written when no call to rte_openlog_stream. */ void eal_log_set_default(FILE *default_log); +FILE *eal_log_get_default(void); /* * Save a log option for later. diff --git a/lib/eal/unix/eal_log.c b/lib/eal/unix/eal_log.c index 85d817c2d31e..e66bcc68d07f 100644 --- a/lib/eal/unix/eal_log.c +++ b/lib/eal/unix/eal_log.c @@ -60,6 +60,10 @@ eal_log_init(const char *id, int facility) { FILE *log_stream; + /* has user has already setup a log stream */ + if (eal_log_get_default()) + return 0; + log_stream = fopencookie(NULL, "w+", console_log_func); if (log_stream == NULL) return -1; From patchwork Wed Jul 5 22:48:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 129318 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 C2B6242DDE; Thu, 6 Jul 2023 00:48:40 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AB88A42D67; Thu, 6 Jul 2023 00:48:17 +0200 (CEST) Received: from mail-oa1-f48.google.com (mail-oa1-f48.google.com [209.85.160.48]) by mails.dpdk.org (Postfix) with ESMTP id D26FC400D5 for ; Thu, 6 Jul 2023 00:48:14 +0200 (CEST) Received: by mail-oa1-f48.google.com with SMTP id 586e51a60fabf-1b06777596cso182577fac.2 for ; Wed, 05 Jul 2023 15:48:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20221208.gappssmtp.com; s=20221208; t=1688597294; x=1691189294; 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=qI1WWRT8YfEhxohquvQ6ZC1uXJ/QOhS6iNuG443ytYY=; b=CVrbIr1SKQcRb5vCor/bLmzV8PxK9sawyBhlXwJ/yoZP0LX2GqabZHxcG7TxNUnMjJ Z//kS2N+Wb+o45mVWoge2R/nW/AHBlGnM0XgS+diAPbikYyFeav6XfDonNnqu/VgGc/n Hmln/wp/en94Dtw+VZXOfKTbzDB46o304OsviSb1jAyEQQyeYbKECpe2Ol+yYLHKl4Ef WVQQsSaHeAbPRkurvN1Ci3Tm+l88cpfBw+yPdhtznWjEq0FxviTowX7zuo3sK+05Kyoe 8g9WTJ0pu3rqFZ9sF58SgLQKIus9hDyOGoMObnzjXsB9dBFyGV1UU4tW305Va/nhMtVc YWtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688597294; x=1691189294; 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=qI1WWRT8YfEhxohquvQ6ZC1uXJ/QOhS6iNuG443ytYY=; b=G37cmzA7VGf21UY8k1+Wafi4qU1nreLJu3bCfC0von2Kwjw5sxkpBnLiTce2OL+OBt 3l2BPYJ10KjV1MfadXFoXi7VTkMIONFbXYJRDXvV4/Bj8bDUWThlcJoRy2QCS0TnOKA4 GuLPhL1sOmzvmxj/KKMPPMScjz8JbMiLVw0qB0LP7Wj9a/6h1UUvKoxnTNaWTLhEAeAD EthPamheH0nYy1HL02RZH5GWsnXKohRjW8qvli0j2s7nHaqzpYST6WiCa1d+tF3JSYh5 P3zkQh3+RVDHb0Np5MhCk2/2/jo56+EEB4UNzz57gFUVq5elfZ0rDKRK7dTRVHHOQ49o KS9Q== X-Gm-Message-State: ABy/qLZ/HGatc8qPVG4m9lCgEOjnDcXfk4nE4wVei2779R9TPxdhgjYh jJnPag8QhttEknboch/oxCVaXHA8Uj2wCcL7+Jk= X-Google-Smtp-Source: APBJJlED0koBf/eFwC7KLKB3TDh7XpgFmEsJf0ZNJ/+9L5PAJ/8ALZy/MJ6qlzVP2tibzl5fef3lBA== X-Received: by 2002:a05:6870:4292:b0:1b0:657f:5047 with SMTP id y18-20020a056870429200b001b0657f5047mr388467oah.46.1688597293834; Wed, 05 Jul 2023 15:48:13 -0700 (PDT) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id bb16-20020a17090b009000b002630bfd35b0sm1906044pjb.7.2023.07.05.15.48.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 15:48:13 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Bruce Richardson , Anatoly Burakov Subject: [PATCH v7 5/5] eal: add option to put timestamp on console output Date: Wed, 5 Jul 2023 15:48:05 -0700 Message-Id: <20230705224805.286156-6-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230705224805.286156-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20230705224805.286156-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org When debugging driver or startup issues, it is useful to have a timestamp on each message printed. The messages in syslog already have a timestamp, but often syslog is not available during testing. The timestamp format is chosen to look like the default Linux dmesg timestamp. The first few lines are not timestamped because the flag is stored in internal configuration which is stored in shared memory which is not setup up until a little later in startup process. This logging skips the unnecessary step of going through stdio, which makes it more robust against being called in interrupt handlers etc. Example: $ dpdk-testpmd --log-timestamp -- -i EAL: Detected CPU lcores: 16 EAL: Detected NUMA nodes: 1 EAL: Detected static linkage of DPDK EAL: Multi-process socket /var/run/dpdk/rte/mp_socket EAL: Selected IOVA mode 'VA' [ 0.112264] testpmd: No probed ethernet devices Interactive-mode selected [ 0.184573] testpmd: create a new mbuf pool : n=163456, size=2176, socket=0 [ 0.184612] testpmd: preferred mempool ops selected: ring_mp_mc Signed-off-by: Stephen Hemminger --- app/test/test_eal_flags.c | 9 ++++ .../freebsd_gsg/freebsd_eal_parameters.rst | 5 +++ doc/guides/linux_gsg/linux_eal_parameters.rst | 5 +++ lib/eal/common/eal_common_options.c | 6 +++ lib/eal/common/eal_internal_cfg.h | 3 ++ lib/eal/common/eal_options.h | 2 + lib/eal/unix/eal_log.c | 45 ++++++++++++++++--- 7 files changed, 70 insertions(+), 5 deletions(-) diff --git a/app/test/test_eal_flags.c b/app/test/test_eal_flags.c index d2b91e20750e..57637728d811 100644 --- a/app/test/test_eal_flags.c +++ b/app/test/test_eal_flags.c @@ -1055,6 +1055,10 @@ test_misc_flags(void) const char * const argv22[] = {prgname, prefix, mp_flag, "--huge-worker-stack=512"}; + /* Try running with --log-timestamp */ + const char * const argv23[] = {prgname, prefix, mp_flag, + "--log-timestamp" }; + /* run all tests also applicable to FreeBSD first */ if (launch_proc(argv0) == 0) { @@ -1162,6 +1166,11 @@ test_misc_flags(void) printf("Error - process did not run ok with --huge-worker-stack=size parameter\n"); goto fail; } + if (launch_proc(argv23) != 0) { + printf("Error - process did not run ok with --log-timestamp parameter\n"); + goto fail; + } + rmdir(hugepath_dir3); rmdir(hugepath_dir2); diff --git a/doc/guides/freebsd_gsg/freebsd_eal_parameters.rst b/doc/guides/freebsd_gsg/freebsd_eal_parameters.rst index 9270d9fa3bfc..99cff10e963c 100644 --- a/doc/guides/freebsd_gsg/freebsd_eal_parameters.rst +++ b/doc/guides/freebsd_gsg/freebsd_eal_parameters.rst @@ -45,3 +45,8 @@ Other options local5 local6 local7 + +* ``--log-timestamp`` + + Add a timestamp of seconds and microseconds to each log message + written to standard output. diff --git a/doc/guides/linux_gsg/linux_eal_parameters.rst b/doc/guides/linux_gsg/linux_eal_parameters.rst index ea8f38139119..719ca6851625 100644 --- a/doc/guides/linux_gsg/linux_eal_parameters.rst +++ b/doc/guides/linux_gsg/linux_eal_parameters.rst @@ -135,3 +135,8 @@ Other options local5 local6 local7 + +* ``--log-timestamp`` + + Add a timestamp of seconds and microseconds to each log message + written to standard output. diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index 005da4d12001..67fe6efb4526 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -76,6 +76,7 @@ eal_long_options[] = { {OPT_IOVA_MODE, 1, NULL, OPT_IOVA_MODE_NUM }, {OPT_LCORES, 1, NULL, OPT_LCORES_NUM }, {OPT_LOG_LEVEL, 1, NULL, OPT_LOG_LEVEL_NUM }, + {OPT_LOG_TIMESTAMP, 0, NULL, OPT_LOG_TIMESTAMP_NUM }, {OPT_TRACE, 1, NULL, OPT_TRACE_NUM }, {OPT_TRACE_DIR, 1, NULL, OPT_TRACE_DIR_NUM }, {OPT_TRACE_BUF_SIZE, 1, NULL, OPT_TRACE_BUF_SIZE_NUM }, @@ -1835,6 +1836,10 @@ eal_parse_common_option(int opt, const char *optarg, } #ifndef RTE_EXEC_ENV_WINDOWS + case OPT_LOG_TIMESTAMP_NUM: + conf->log_timestamp = 1; + break; + case OPT_TRACE_NUM: { if (eal_trace_args_save(optarg) < 0) { RTE_LOG(ERR, EAL, "invalid parameters for --" @@ -2194,6 +2199,7 @@ eal_common_usage(void) " --"OPT_PROC_TYPE" Type of this process (primary|secondary|auto)\n" #ifndef RTE_EXEC_ENV_WINDOWS " --"OPT_SYSLOG"= Set syslog facility\n" + " --"OPT_LOG_TIMESTAMP" Timestamp log output\n" #endif " --"OPT_LOG_LEVEL"= Set global log level\n" " --"OPT_LOG_LEVEL"=:\n" diff --git a/lib/eal/common/eal_internal_cfg.h b/lib/eal/common/eal_internal_cfg.h index 167ec501fa79..ca502d5dd365 100644 --- a/lib/eal/common/eal_internal_cfg.h +++ b/lib/eal/common/eal_internal_cfg.h @@ -84,7 +84,10 @@ struct internal_config { /**< true if storing all pages within single files (per-page-size, * per-node) non-legacy mode only. */ + uint8_t log_timestamp; /**< add timestamp to console output */ + struct timespec log_start_time; /**< monotonic clock when started */ volatile int syslog_facility; /**< facility passed to openlog() */ + /** default interrupt mode for VFIO */ volatile enum rte_intr_mode vfio_intr_mode; /** the shared VF token for VFIO-PCI bound PF and VFs devices */ diff --git a/lib/eal/common/eal_options.h b/lib/eal/common/eal_options.h index 3cc9cb641284..cc9723868e3c 100644 --- a/lib/eal/common/eal_options.h +++ b/lib/eal/common/eal_options.h @@ -35,6 +35,8 @@ enum { OPT_LCORES_NUM, #define OPT_LOG_LEVEL "log-level" OPT_LOG_LEVEL_NUM, +#define OPT_LOG_TIMESTAMP "log-timestamp" + OPT_LOG_TIMESTAMP_NUM, #define OPT_TRACE "trace" OPT_TRACE_NUM, #define OPT_TRACE_DIR "trace-dir" diff --git a/lib/eal/unix/eal_log.c b/lib/eal/unix/eal_log.c index e66bcc68d07f..1ee94a5ee1e6 100644 --- a/lib/eal/unix/eal_log.c +++ b/lib/eal/unix/eal_log.c @@ -4,7 +4,10 @@ #include #include +#include #include +#include +#include #include @@ -16,13 +19,38 @@ * default log function */ static ssize_t -console_log_write(__rte_unused void *c, const char *buf, size_t size) +console_log_write(void *c, const char *buf, size_t size) { + const struct internal_config *internal_conf = c; ssize_t ret; - /* write on stderr */ - ret = fwrite(buf, 1, size, stderr); - fflush(stderr); + /* add optional timestamp for stderr */ + if (internal_conf->log_timestamp) { + struct iovec iov[2]; + struct timespec ts; + char tbuf[64]; + + /* format up monotonic timestamp */ + clock_gettime(CLOCK_MONOTONIC, &ts); + ts.tv_sec -= internal_conf->log_start_time.tv_sec; + ts.tv_nsec -= internal_conf->log_start_time.tv_nsec; + if (ts.tv_nsec < 0) { + --ts.tv_sec; + ts.tv_nsec += 1000000000ul; + } + + /* use writev to put timestamp and buf in single operation */ + iov[0].iov_base = tbuf; + iov[0].iov_len = snprintf(tbuf, sizeof(tbuf), "[%8lu.%06lu] ", + ts.tv_sec, ts.tv_nsec / 1000u); + + /* casts are to unconstify the buf */ + iov[1].iov_base = (void *)(uintptr_t)buf; + iov[1].iov_len = size; + ret = writev(STDERR_FILENO, iov, 2); + } else { + ret = write(STDERR_FILENO, buf, size); + } /* Syslog error levels are from 0 to 7, so subtract 1 to convert */ syslog(rte_log_cur_msg_loglevel() - 1, "%.*s", (int)size, buf); @@ -58,13 +86,20 @@ static cookie_io_functions_t console_log_func = { int eal_log_init(const char *id, int facility) { + struct internal_config *internal_conf = eal_get_internal_configuration(); FILE *log_stream; /* has user has already setup a log stream */ if (eal_log_get_default()) return 0; - log_stream = fopencookie(NULL, "w+", console_log_func); + if (internal_conf->process_type == RTE_PROC_PRIMARY && + internal_conf->log_timestamp) { + if (clock_gettime(CLOCK_MONOTONIC, &internal_conf->log_start_time) < 0) + return -1; + } + + log_stream = fopencookie(internal_conf, "w+", console_log_func); if (log_stream == NULL) return -1;