From patchwork Tue Mar 26 01:56:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138785 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 D76F343D4E; Tue, 26 Mar 2024 02:58:45 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D044940A77; Tue, 26 Mar 2024 02:58:42 +0100 (CET) Received: from mail-yw1-f176.google.com (mail-yw1-f176.google.com [209.85.128.176]) by mails.dpdk.org (Postfix) with ESMTP id D0E1F402E1 for ; Tue, 26 Mar 2024 02:58:40 +0100 (CET) Received: by mail-yw1-f176.google.com with SMTP id 00721157ae682-609ff069a40so56336217b3.1 for ; Mon, 25 Mar 2024 18:58:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711418320; x=1712023120; 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=g4Sln/ZtZo8gN3QqSfXSrXMyUiX2+gv20WVamIfBv4P/H0zBeb0yq6pk3G3zAnRsAm G0aC1l56IrTfi9655tBxWrQgOycP+a8/MIkzFcyfyc+OSuONSwnWz/pobJYmPJZ0iAEt Sm5T2v1Rs4F2BXRR7uhJLfNaR/pVDDJq8uU1ddkzk0oT4Ed3WfOXAt0xv1DmYd36trTT vmZ02Evb50svp0JalHsbx4ZV576wsCmaPueYhxYLDg8An+Uad+6hOhJydSsJIsqvY8wx Nk3IVcvtCjX3BdWRif2P4ipcuyQaWA3apgJluIqPXLvXDRReYve2nQazVP7Ylvq360xn mKoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711418320; x=1712023120; 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=RHtIx3zGgMUa+4aJ+27J21DjXcKs/Li9VcT9wRtxcglZPPIZaPfQ1CJqR5gOFgjdvZ +838X0kfRvzC4jyaJdAwTZr8oMHUpVVt5oPcH74C8L48IKaOJ5za66Q5g8PXXbDdSuPa ctlxrPWkAIc0Bbm21Sbto0VNLG0gMWZXOBO83fYZryupMFEqP6hmnjo5L2UDf7z7y2/E aGOhD4GTuNZLmTpLR0YsAFMBOhNkyKf23s4/LiI4nU0GjJpeVo9tE0CHA8TKbURpwfMh k/OTzzwZB2sB8KAAgvmLqFEnbIe2Ib5DG6OW4pgRmjch1OsAmDm/DuGES3IpHH7qTbPD zXrA== X-Gm-Message-State: AOJu0YyK6uBIRbv0iB1EppFKqWgAiepknb+G5iSv6UBhyKaj+7hw5rCg eW1DX0o7PYW5TwglfPLPa/V2mZX2MXZ/1ATc26x7gQ9p17EzuCDZPqk4Z/anPOec7vb1++9Y3hK P X-Google-Smtp-Source: AGHT+IHxTX2M7Hf8eOvILvVB2W6i+iD6X9E4bxBWPi0ZRNXZmuXG513YxYoVsB7zK4luxYqxxm9CnA== X-Received: by 2002:a0d:cd84:0:b0:60a:a1e:6e11 with SMTP id p126-20020a0dcd84000000b0060a0a1e6e11mr7447801ywd.45.1711418319212; Mon, 25 Mar 2024 18:58:39 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id u19-20020a63d353000000b005dc88b232a5sm6571541pgi.26.2024.03.25.18.58.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 18:58:38 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff , Dmitry Kozlyuk , Pallavi Kadam Subject: [PATCH v13 01/11] windows: make getopt functions have const properties Date: Mon, 25 Mar 2024 18:56:56 -0700 Message-ID: <20240326015827.825648-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240326015827.825648-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240326015827.825648-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 Acked-by: Morten Brørup --- 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 Tue Mar 26 01:56:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138786 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 0D5FB43D4E; Tue, 26 Mar 2024 02:58:52 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 271CC40A8A; Tue, 26 Mar 2024 02:58:44 +0100 (CET) Received: from mail-oo1-f51.google.com (mail-oo1-f51.google.com [209.85.161.51]) by mails.dpdk.org (Postfix) with ESMTP id 360D840A6F for ; Tue, 26 Mar 2024 02:58:41 +0100 (CET) Received: by mail-oo1-f51.google.com with SMTP id 006d021491bc7-5a4b35ff84eso2748000eaf.2 for ; Mon, 25 Mar 2024 18:58:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711418320; x=1712023120; 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=Ml0gchs9dNogvSJKCUa91H765fGAaDYpR/DhR359d/Q=; b=xbiYW24kIG7Qwc0ImikXW0nIWKac6V+ifayNXjSVd79yJNqUtjKWUBWSQUcyR66qYh XAKmck3Nismb15NoLyYLdUYPW9dYKmgFO27ej7NG5e5NYaQFG6heDq9OedyRO25p03Mn AbaCzLCt3K0H9HviS+CgkIlbHkSBWco2x3uX8EEiIxM4wEi4QhGpBw0vEo7Eg5wezueJ 8xbS+tQ0a3Qq0anZGr0kKCXtlZrhGT8KIM81utxcYh1ZXpHX/pnOdnpQfGBpHhs3RB/G L+cWJxLTtT5sKjTbWNbWY65RZw/639P5dRv6arN3vm/ER15FMEL49lvKp/TwG6RmFfK6 AL+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711418320; x=1712023120; 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=Ml0gchs9dNogvSJKCUa91H765fGAaDYpR/DhR359d/Q=; b=INNramOu1xw9zj9kJnRwfOC0M9hAn4XCCv7oc2yIexCWb1c4Mt4JAPMK7GoVR88pJb pytca32qMuzsIt/k5l0iSRlAK4uOFpaGmF5H9H6uoMwWw9X0L2Zl5VQ1nJBp5FazTcyW YTFTxrFZYmnarIoR7BlqhRa1T5KkEMla+3yq07+QUb5hzlwQomwo8cxvjveZmI0o6x52 TMFVeC2t8+OlWrfSA75er8kGHafokVNiVs7L4TPb42hmkFKjTJp1PO1qxDN3i31Ek8vA hI8z7gAgm0CQB++r6oFM9bU/4KQu90mLh37GWpA2WnGpD5XGtQ6rQYvImLgdogiSLXIa oSEg== X-Gm-Message-State: AOJu0Yz4Gz5uwTsk7VDc5KO+Il/zTA5O1C36kBye0vdT/KbTI+nYaGrB wsqHuwqA0JS81tZ2vs1Zu7aGkiz3rTovtSpaxRyCaFWoZIBjNsWPvRP1byK3Gxu63pbA2IDDEvb W X-Google-Smtp-Source: AGHT+IF6L6WkqUMKJ+Y5UerCrx0bDpv3LIkgYrkzj6Ij6wUet1rdqS5UYfKGTSa+v5DXcZjgssynEg== X-Received: by 2002:a05:6358:6184:b0:17c:1e44:a489 with SMTP id w4-20020a056358618400b0017c1e44a489mr9182614rww.32.1711418320241; Mon, 25 Mar 2024 18:58:40 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id u19-20020a63d353000000b005dc88b232a5sm6571541pgi.26.2024.03.25.18.58.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 18:58:39 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Dmitry Kozlyuk , Tyler Retzlaff , Pallavi Kadam Subject: [PATCH v13 02/11] windows: add os shim for localtime_r Date: Mon, 25 Mar 2024 18:56:57 -0700 Message-ID: <20240326015827.825648-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240326015827.825648-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240326015827.825648-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 Windows does not have localtime_r but it does have a similar function that can be used instead. Signed-off-by: Stephen Hemminger --- lib/eal/windows/include/rte_os_shim.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/eal/windows/include/rte_os_shim.h b/lib/eal/windows/include/rte_os_shim.h index eda8113662..e9741a9df2 100644 --- a/lib/eal/windows/include/rte_os_shim.h +++ b/lib/eal/windows/include/rte_os_shim.h @@ -110,4 +110,14 @@ rte_clock_gettime(clockid_t clock_id, struct timespec *tp) } #define clock_gettime(clock_id, tp) rte_clock_gettime(clock_id, tp) +static inline struct tm * +rte_localtime_r(const time_t *timer, struct tm *buf) +{ + if (localtime_s(buf, timer) == 0) + return buf; + else + return NULL; +} +#define localtime_r(timer, buf) rte_localtime_r(timer, buf) + #endif /* _RTE_OS_SHIM_ */ From patchwork Tue Mar 26 01:56:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138787 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 DFC0943D4E; Tue, 26 Mar 2024 02:58:57 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4359E40DCA; Tue, 26 Mar 2024 02:58:46 +0100 (CET) Received: from mail-oi1-f170.google.com (mail-oi1-f170.google.com [209.85.167.170]) by mails.dpdk.org (Postfix) with ESMTP id 3471640A6F for ; Tue, 26 Mar 2024 02:58:42 +0100 (CET) Received: by mail-oi1-f170.google.com with SMTP id 5614622812f47-3c38eced701so3093441b6e.1 for ; Mon, 25 Mar 2024 18:58:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711418321; x=1712023121; 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=VznX8QPVhFNRoTGdoYpoiuUzGpJgs0yrP5zN1E9FVx5MHG/Py4sFxPHEeYIvx/O4LC y1UREacX0s+i7ADK35cd2N1GLY4sJHbwbsOYWDZ8zq3YexN7hPU0l412ZvdRd9GQVYaw YH7UvhRUujuZ78VJASm2Qrzp9EHevzKyTXWSGPAe50FfoLfKaAzwqZq8XvTf0IToBVrZ PUtEP97fuG5A4TM4uXrWA0xSU83KXBvVe0ni3Zp+iZfE5+X+CD107Ii19tSD7C7Vg1WO uTiW/PR7IsO6T4HtxAtAPbo5rUm9oFoxxxMYeBzlEmKa4vOLIlP+GhC7sl4x2tpW1RCf aSGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711418321; x=1712023121; 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=lnC0y9pKNVw/sJvluhaBUllcRO1IKkTbuPPUDFdvWMDO+jjn51paawVt7RCxt3z2dR ff36qLfaD8e1HYjyee2b7FlzC7IZJNnfeG4jTBgwz/kMbfhJqqZtal/W/Bvhf0o9GVsH AqrVKLMuZ+o5sfHhH8AqcUN4IwnSyXqkz5HHFoB3Vs21ujxwNZ6m+s051yArePOljD0l EaCQxc9u9RRJuW7Rq286FHyNBQGYk3QButmI5//f9Cb1ELsfncLZzN/2+fWJ61BY+cI2 a94T95ya7Rvz0+QX5IoNIidZg2IcW0nsHxwk+NBhVLKiQtLdbBWUxgx0pTFLcU/jY6Vz 22Sw== X-Gm-Message-State: AOJu0Yx1pP5JRxPNAc3s6oIsIL2/S2TxmyQ/UQeU5EKSvRyB7AuA+pfZ zgC0t8k92hL+C28PTq2JOeYxfArTImQCceIrYLYjz0oiFMUF1oMU7kBhCKzFqa5ZTgJ7dzgv/26 s X-Google-Smtp-Source: AGHT+IEq98GoTCHQ7zv2pjtaC26mAzRqgAysqs5pZu3LIDWJAnp5aUT284VQDoVXTSlAlrIeU7BhBQ== X-Received: by 2002:a05:6358:d03:b0:17c:263a:5b8e with SMTP id v3-20020a0563580d0300b0017c263a5b8emr10102909rwj.14.1711418321245; Mon, 25 Mar 2024 18:58:41 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id u19-20020a63d353000000b005dc88b232a5sm6571541pgi.26.2024.03.25.18.58.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 18:58:40 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Bruce Richardson , Dmitry Kozlyuk , Tyler Retzlaff , Pallavi Kadam Subject: [PATCH v13 03/11] eal: make eal_log_level_parse common Date: Mon, 25 Mar 2024 18:56:58 -0700 Message-ID: <20240326015827.825648-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240326015827.825648-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240326015827.825648-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 Tue Mar 26 01:56:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138788 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 1A87743D4E; Tue, 26 Mar 2024 02:59:04 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8BDD240DDD; Tue, 26 Mar 2024 02:58:47 +0100 (CET) Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by mails.dpdk.org (Postfix) with ESMTP id EA9F040A7D for ; Tue, 26 Mar 2024 02:58:42 +0100 (CET) Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1dddbe47ac1so37761775ad.1 for ; Mon, 25 Mar 2024 18:58:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711418322; x=1712023122; 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=Nh0kwJZczl7Ip84rM45p7bkIxbx1PvWHhZQN32IBpACG/z5KDqB5AqjPU9auxlBZsM dFQCfnnQAAjNAGhSpOTsQaqp9mr1f1rQg8guTjeJGzkFzd3PvEWFGQ8+9jUbc29UFdjt bBQDa5gOpnNYHGer0bwJFakAiGpvRH5FKAUGaDrodupH1OjPswJD2QtUD4J6aazVyzxn o074DTWs9bJozlRg8TCSj/faO4RwtLKL0Zw6vsinW7+EUdX5Es7VIdeYT8wS2bGGI014 7K6vNJgueMuQTrlET+QkdmBEfJZ5WiR43YV7GXHOIgq0fhClx5HfbcPynrGkjS1oBB94 /JsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711418322; x=1712023122; 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=Qcr1MXVExZAwgO8EwfO1Pjjc/xEGR8cJePBBqBl8FrvO/LLiM2y8K2alEz8KKf0HgY dXvlTVbUFsySYjSBxg6ky2DzVxTIQ0jdK0xWG4dvVmEFJK0YBhuUgXh42InJFk3waXTg ROE9+jGViiVca17CZ8GXBzedCPrEVuHFlisNWD+Kgl8673EjnqB4sc7AXHX+3Icw8WEE ytdrWaWWH3908atiXzNxFDFff4iVMn0GI8rHVpZ0PQqriWjuQ1n20oTals0VGHlcXuHS AGwWW/7iNVryY0d1alRr27C45MJ3k69ZAKZJ5u57I7dXJMxaY9Q7EkU0QTzrKgvTUIlI 7CKQ== X-Gm-Message-State: AOJu0Yx/VM0/s4xtqqreWw9wh5Jpqr9dS8tW1VzKX7tPRNDA8GR7LvdS clhY8TlLLVWxxUXaeRu77q0ylxW2bKwx0XEVkxdLbEEII3YvYb3/WkM80d5f78ABlh/NDyiI4xa a X-Google-Smtp-Source: AGHT+IF4yplOQ6zzqliVl8Fk09M63UEMsts0x54aaNqLfZsAfJ/dAXC24kz4MoJNHCX6bKPtePfFbA== X-Received: by 2002:a17:902:c1d5:b0:1e0:c070:b082 with SMTP id c21-20020a170902c1d500b001e0c070b082mr164266plc.14.1711418322061; Mon, 25 Mar 2024 18:58:42 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id u19-20020a63d353000000b005dc88b232a5sm6571541pgi.26.2024.03.25.18.58.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 18:58:41 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Bruce Richardson Subject: [PATCH v13 04/11] eal: do not duplicate rte_init_alert() messages Date: Mon, 25 Mar 2024 18:56:59 -0700 Message-ID: <20240326015827.825648-5-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240326015827.825648-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240326015827.825648-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 Tue Mar 26 01:57:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138789 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 33A1143D4E; Tue, 26 Mar 2024 02:59:11 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BE5FB40E03; Tue, 26 Mar 2024 02:58:48 +0100 (CET) Received: from mail-oo1-f52.google.com (mail-oo1-f52.google.com [209.85.161.52]) by mails.dpdk.org (Postfix) with ESMTP id 9F69F40A7F for ; Tue, 26 Mar 2024 02:58:43 +0100 (CET) Received: by mail-oo1-f52.google.com with SMTP id 006d021491bc7-5a470320194so2656994eaf.3 for ; Mon, 25 Mar 2024 18:58:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711418323; x=1712023123; 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=zmgn2TMY0pSmt2vzjAmFWex3Ac/CzGg0VZQ9Pce9n7s=; b=to3eoP4HY8GfHipxOPYzJb8A95ZvbN8/9BygwujkCG+2ipf7Km5jc1Q3tovZ+iBjiI kN/nEGqS8lf8j2PLT/GogZ4Mz0oi1QI0pax/yGDXkBFbJ/yW8ECvS60xw6F9isW0Dt9y +L5q8m+/lccDbLRUjdvGYn7ijFI2c5h20EsHENPyeujXoqeAKH7dw0DuOmumEkApadeT H+bO2kOoNwcYogQZiamIBKH+zCJENYJ5l9OLS/l7c3QCe+Gn2mQB0t4rSQmYkVoKp/MS AZSFKvw+NwzEECpkjNG6sgSN/fhSlzi+zyzhY+eBksc2B/WGXQdUHfqTGmVN4KUqERDG xbRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711418323; x=1712023123; 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=zmgn2TMY0pSmt2vzjAmFWex3Ac/CzGg0VZQ9Pce9n7s=; b=M0bDMQsmvMN9nkNUYZZJ5csIYblTUFtKnJeXNR/Q+iRS9SzIyrl5FA7y7l4+9slwCm bFJxhJhutf4sitTe1yquw2AqS/V0p/mufTCn1SG1icStMCv8fPQDvRYtCca+s2K9UVMI zt9lkKCGYN2/86+HcYZK+Zk7DwLpe7peTEKIqea0myvq5zHJjs851UPn7qHx0DMqBbLS ojPQJii7+WKIR4gZBRx6N8ymvPr0q7bMX1HQ/ULP8VOqRwdtxKnpRAw5jlBREIiQaENz ddaoRvYSpU88+tsjCeGY8CBr4UacWRwCGy7g8SDAsp+VfimuKgFPJ5CyhcsYRXIPnLry JEpw== X-Gm-Message-State: AOJu0YyI/1aTPSlfckDK8Yh4nmBFvpzE4WAmT+tf9MY2zSlrR1lQZRfl LaoNUH7HrswfQ2s1Ugz0knk5cM5y50FNmxBNzNjRyxJJ8fnLdRqTDgW1ClWUpXBqCmeL/HYcWaL e X-Google-Smtp-Source: AGHT+IHQ/8iRVuQk0enP1qzdMJ80bTg5Kvb7fcTVI74IfhFvwuytvX2JEsx+djWw4YnP+R8y1Iu2bw== X-Received: by 2002:a05:6358:2621:b0:17e:7c4b:bb56 with SMTP id l33-20020a056358262100b0017e7c4bbb56mr10158195rwc.15.1711418322902; Mon, 25 Mar 2024 18:58:42 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id u19-20020a63d353000000b005dc88b232a5sm6571541pgi.26.2024.03.25.18.58.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 18:58:42 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v13 05/11] eal: change rte_exit() output to match rte_log() Date: Mon, 25 Mar 2024 18:57:00 -0700 Message-ID: <20240326015827.825648-6-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240326015827.825648-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240326015827.825648-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 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/eal/common/eal_common_debug.c b/lib/eal/common/eal_common_debug.c index 3e77995896..71bb5a7d34 100644 --- a/lib/eal/common/eal_common_debug.c +++ b/lib/eal/common/eal_common_debug.c @@ -34,17 +34,17 @@ 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); + if (vasprintf(&msg, format, ap) > 0) + rte_log(RTE_LOG_CRIT, RTE_LOGTYPE_EAL, "EAL: Cause - %s", msg); va_end(ap); 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 Tue Mar 26 01:57:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138790 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 5F85543D4E; Tue, 26 Mar 2024 02:59:17 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E6B0040E2D; Tue, 26 Mar 2024 02:58:49 +0100 (CET) Received: from mail-yb1-f174.google.com (mail-yb1-f174.google.com [209.85.219.174]) by mails.dpdk.org (Postfix) with ESMTP id 8EDD140DC9 for ; Tue, 26 Mar 2024 02:58:45 +0100 (CET) Received: by mail-yb1-f174.google.com with SMTP id 3f1490d57ef6-dcc84ae94c1so4791908276.1 for ; Mon, 25 Mar 2024 18:58:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711418325; x=1712023125; 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=iWMb27jiysM7jNvXpWkAuTUerKMNeB5ARcowu2NtE7A=; b=OHkeXoXcMRx+i7akyvOUoE6588qasqMS2xvg7F978o6R26CFEjAg5fDs9wV+wT+IdW ahn0f+49ti7CG0kDvS+P+qMT+iKQNt4odyGiswMAIuJcMVwJgebbd9+47obspr6RaZAo 4q+pRLXEwry5RGgXPYMYHzHO3Ox35sxmLz878HgR8h1Zz4/n+9MV4qwlLatLYudG6kBd 4bsddftDZIIiiMmlcdAWxbJ91BTbom2l4Xx5H15O2HUZJd+90x64tUL9F/fUhrOqdYgV 4FbCcTg2W9TsabgeOpe/+TO39hE7UkSGI7kaA/EjNBq4nBI/+ZTuUKwYTtFXIgW2Y9bv J9bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711418325; x=1712023125; 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=iWMb27jiysM7jNvXpWkAuTUerKMNeB5ARcowu2NtE7A=; b=EhSnAkLrffg95dIHguZoG151H2vh1S//tiEhg7v0kTKG/3eiN8qkGI+YhBughoDPdm blAaQ2t3OsRHTt1r0qGbelmeoYsGfXNRphDf7yTjPTEHFBASAiiHYpaoesaYfg9Ft+xT c3+FhK7okAFiFofBsuwVs0GTVm8+wknyq8ysQAESLekvPWKrV2ggo8B1+piBkRZ3y5Tm RRfsgRxj+69e+Yc91MvzB+zogV3MSc5DSvzcZ5C1tMU+NiW7H+nzH0BEjoGdvDzQOXAR lFXo+zrOElwToXxPjLqdCSey83Aj1MNHixv84tXzLTaD+qvABEqPn/y7FzNzgQWrQHKA WUOA== X-Gm-Message-State: AOJu0YymcRToLyNiFWgDhB6OHsLO2ajinOPSEb9kmyIZLLRqJcBvp0F4 eySoqgGCL/M05cRm4L1/djRuUnneWcVK8h9zDDqFQqxeu1fT/nl+IIjG3ppeVF44aA74oOHkMzz y X-Google-Smtp-Source: AGHT+IF6CsUx6m3m3PfVGg25rT/GIQCc7zBkDhQQ52aN8KXnwgj5RiLb4jbGILI/odBqQRtK8afxTA== X-Received: by 2002:a25:5f4d:0:b0:dcc:4cdc:e98f with SMTP id h13-20020a255f4d000000b00dcc4cdce98fmr1631909ybm.34.1711418323932; Mon, 25 Mar 2024 18:58:43 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id u19-20020a63d353000000b005dc88b232a5sm6571541pgi.26.2024.03.25.18.58.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 18:58:43 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Bruce Richardson , Dmitry Kozlyuk , Tyler Retzlaff , Pallavi Kadam Subject: [PATCH v13 06/11] log: move handling of syslog facility out of eal Date: Mon, 25 Mar 2024 18:57:01 -0700 Message-ID: <20240326015827.825648-7-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240326015827.825648-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240326015827.825648-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 facility property is better handled in lib/log rather than in eal. This also allows for changes to what syslog flag means in later steps. Signed-off-by: Stephen Hemminger --- lib/eal/common/eal_common_options.c | 51 ++--------------------------- lib/eal/freebsd/eal.c | 5 ++- lib/eal/linux/eal.c | 7 ++-- lib/eal/windows/eal.c | 6 ++-- lib/log/log_freebsd.c | 2 +- lib/log/log_internal.h | 5 ++- lib/log/log_linux.c | 47 ++++++++++++++++++++++++-- lib/log/log_windows.c | 8 ++++- lib/log/version.map | 1 + 9 files changed, 68 insertions(+), 64 deletions(-) diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index 5435399b85..661b2db211 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 @@ -349,10 +346,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 +1290,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) { @@ -1663,6 +1615,7 @@ eal_log_level_parse(int argc, char * const argv[]) switch (opt) { case OPT_LOG_LEVEL_NUM: + case OPT_SYSLOG_NUM: if (eal_parse_common_option(opt, optarg, internal_conf) < 0) return -1; break; @@ -1882,7 +1835,7 @@ eal_parse_common_option(int opt, const char *optarg, #ifndef RTE_EXEC_ENV_WINDOWS case OPT_SYSLOG_NUM: - if (eal_parse_syslog(optarg, conf) < 0) { + if (eal_log_syslog(optarg) < 0) { EAL_LOG(ERR, "invalid parameters for --" OPT_SYSLOG); return -1; diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index 17b56f38aa..6552f9c138 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -392,8 +391,8 @@ eal_parse_args(int argc, char **argv) goto out; } - /* eal_log_level_parse() already handled this option */ - if (opt == OPT_LOG_LEVEL_NUM) + /* eal_log_level_parse() already handled these */ + if (opt == OPT_LOG_LEVEL_NUM || opt == OPT_LOG_SYSLOG_NUM) continue; ret = eal_parse_common_option(opt, optarg, internal_conf); diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index 23dc26b124..3d0c34063e 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -610,8 +610,8 @@ eal_parse_args(int argc, char **argv) goto out; } - /* eal_log_level_parse() already handled this option */ - if (opt == OPT_LOG_LEVEL_NUM) + /* eal_log_level_parse() already handled these options */ + if (opt == OPT_LOG_LEVEL_NUM || opt == OPT_SYSLOG_NUM) continue; ret = eal_parse_common_option(opt, optarg, internal_conf); @@ -1106,8 +1106,7 @@ rte_eal_init(int argc, char **argv) #endif } - if (eal_log_init(program_invocation_short_name, - internal_conf->syslog_facility) < 0) { + if (eal_log_init(program_invocation_short_name) < 0) { rte_eal_init_alert("Cannot init logging."); rte_errno = ENOMEM; rte_atomic_store_explicit(&run_once, 0, rte_memory_order_relaxed); diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c index 85171b2768..2519a30017 100644 --- a/lib/eal/windows/eal.c +++ b/lib/eal/windows/eal.c @@ -120,8 +120,8 @@ eal_parse_args(int argc, char **argv) return -1; } - /* eal_log_level_parse() already handled this option */ - if (opt == OPT_LOG_LEVEL_NUM) + /* eal_log_level_parse() already handled these options */ + if (opt == OPT_LOG_LEVEL_NUM || opt == OPT_SYSLOG_NUM) continue; ret = eal_parse_common_option(opt, optarg, internal_conf); @@ -250,7 +250,7 @@ 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_init(NULL); eal_log_level_parse(argc, argv); diff --git a/lib/log/log_freebsd.c b/lib/log/log_freebsd.c index 698d3c5423..953e371bee 100644 --- a/lib/log/log_freebsd.c +++ b/lib/log/log_freebsd.c @@ -6,7 +6,7 @@ #include "log_internal.h" int -eal_log_init(__rte_unused const char *id, __rte_unused int facility) +eal_log_init(__rte_unused const char *id) { return 0; } diff --git a/lib/log/log_internal.h b/lib/log/log_internal.h index 451629f1c1..cb15cdff08 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); +int eal_log_init(const char *id); /* * Determine where log data is written when no call to rte_openlog_stream. @@ -30,6 +30,9 @@ int eal_log_save_regexp(const char *regexp, uint32_t level); __rte_internal int eal_log_save_pattern(const char *pattern, uint32_t level); +__rte_internal +int eal_log_syslog(const char *name); + /* * Convert log level to string. */ diff --git a/lib/log/log_linux.c b/lib/log/log_linux.c index 2dfb0c974b..47aa074da2 100644 --- a/lib/log/log_linux.c +++ b/lib/log/log_linux.c @@ -3,13 +3,56 @@ */ #include +#include #include #include +#include #include #include "log_internal.h" +static int log_facility = LOG_DAEMON; + +static const struct { + const char *name; + int value; +} facilitys[] = { + { "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 }, +}; + +int +eal_log_syslog(const char *name) +{ + unsigned int i; + + for (i = 0; i < RTE_DIM(facilitys); i++) { + if (!strcmp(name, facilitys[i].name)) { + log_facility = facilitys[i].value; + return 0; + } + } + return -1; +} + /* * default log function */ @@ -45,7 +88,7 @@ static cookie_io_functions_t console_log_func = { * once memzones are available. */ int -eal_log_init(const char *id, int facility) +eal_log_init(const char *id) { FILE *log_stream; @@ -53,7 +96,7 @@ eal_log_init(const char *id, int facility) if (log_stream == NULL) return -1; - openlog(id, LOG_NDELAY | LOG_PID, facility); + openlog(id, LOG_NDELAY | LOG_PID, log_facility); eal_log_set_default(log_stream); diff --git a/lib/log/log_windows.c b/lib/log/log_windows.c index a6a0889550..a3a756351d 100644 --- a/lib/log/log_windows.c +++ b/lib/log/log_windows.c @@ -6,9 +6,15 @@ #include #include "log_internal.h" +int +eal_log_syslog(const char *name __rte_unused) +{ + return -1; /* not used */ +} + /* set the log to default function, called during eal init process. */ int -eal_log_init(__rte_unused const char *id, __rte_unused int facility) +eal_log_init(__rte_unused const char *id) { rte_openlog_stream(stderr); diff --git a/lib/log/version.map b/lib/log/version.map index 0648f8831a..9c6c49bf06 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_syslog; rte_eal_log_cleanup; }; From patchwork Tue Mar 26 01:57:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138791 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 A0FCC43D4E; Tue, 26 Mar 2024 02:59:23 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 40D8440E72; Tue, 26 Mar 2024 02:58:52 +0100 (CET) Received: from mail-yb1-f178.google.com (mail-yb1-f178.google.com [209.85.219.178]) by mails.dpdk.org (Postfix) with ESMTP id 8AA7340A6F for ; Tue, 26 Mar 2024 02:58:46 +0100 (CET) Received: by mail-yb1-f178.google.com with SMTP id 3f1490d57ef6-dd161eb03afso4407900276.0 for ; Mon, 25 Mar 2024 18:58:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711418326; x=1712023126; 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=4M9+aL33xz9p3faWYrmQuGaljl8l4a8e5Kpsjet52VA=; b=PcTSIMnDRqXTHIHWAvKq6V58oF7A/xcMHTJ5RoJdkWKWkuLA068i/c4mtLid7ujgUU IzIFnv/inFG5+c6fbdFwwnqxuX3ILCwJOk4cz2R6OZuGoXi0NVGOLgXzayf5sWWm/PCw HQGpIrzce7RY6yIduVtONbMpVR9ZeIfmM13vdZz2XDy0JuttLavrsGqnONl79Qgr26Wf jgpDmA7EpZVp2u7blB+/xR1U9CjGJwjBB2OfDqUt9vRoGvod1ofLFvEapWmy6HLg/+BO OX/TU0ttG8E0JLU8T5YuftjlI5yF6mOfIkx/M7gn1qI/0+yi3sF5Zj6/PewSjhfehpY/ oMlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711418326; x=1712023126; 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=4M9+aL33xz9p3faWYrmQuGaljl8l4a8e5Kpsjet52VA=; b=UYiOB8kG4HzNeolQEE6MO0jHMj1VPTUKi537r5TWMrpVTCtdkQ/YuJrNEAST59Z7RO lTNd88UeRufiUX8vvGpWCtGbKPyOU567xzRJrfhomZvzK3QgwL7ukWrI/Hf+YSGzzWgp 3osjdIF50XGH+PvHHFETHkZgn8234QhndLKy1FgK9i4IVBiQFRrJ7lOWb5iG7X/z2QHT 2g6WdgRLAlqnSD4tLTGNctqYOj0TAfUPS+gYFOGWfmopbwT6fonZryR1MNFhpm23k/qZ kvRJJ/5cHvLv45/9HB9ctBuQ40+29AcWWENU2XjhsrLUnaOzb+hUgMh0B74KWmev1e81 xAIw== X-Gm-Message-State: AOJu0YyVSo0gdINjd37+VxHEE1FARWS1pg8rCzeJ7Tazm1+Ier9AK5x7 90UFvh/TsdCjkvNc6UnGXLAcqzzGGrKliGHGOzPhnApmB7kHTv+MWtKF7vc83z6X8a9X9QTBqXB / X-Google-Smtp-Source: AGHT+IEDPVRXz16VBk5heO/vf5VSYL9lHsb5Srfb0tsh/Q4qRa5X33HKzc/iKwbRfGygl6vrnzupBg== X-Received: by 2002:a25:bccb:0:b0:dcf:bc57:cd61 with SMTP id l11-20020a25bccb000000b00dcfbc57cd61mr1276845ybm.50.1711418325927; Mon, 25 Mar 2024 18:58:45 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id u19-20020a63d353000000b005dc88b232a5sm6571541pgi.26.2024.03.25.18.58.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 18:58:45 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Bruce Richardson , Dmitry Kozlyuk , Tyler Retzlaff , Pallavi Kadam Subject: [PATCH v13 07/11] eal: initialize log before everything else Date: Mon, 25 Mar 2024 18:57:02 -0700 Message-ID: <20240326015827.825648-8-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240326015827.825648-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240326015827.825648-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 In order for all log messages (including CPU mismatch) to come out through the logging library, it must be initialized as early in rte_eal_init() as possible on all platforms. Where it was done before was likely historical based on the support of non-OS isolated CPU's which required a shared memory buffer; that support was dropped before DPDK was publicly released. Signed-off-by: Stephen Hemminger --- lib/eal/freebsd/eal.c | 12 +++++++++--- lib/eal/linux/eal.c | 19 +++++++++---------- lib/eal/windows/eal.c | 8 ++++++-- lib/log/log_freebsd.c | 3 +-- lib/log/log_internal.h | 2 +- lib/log/log_linux.c | 14 ++++++-------- lib/log/log_windows.c | 4 +--- 7 files changed, 33 insertions(+), 29 deletions(-) diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index 6552f9c138..55ff27a4da 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -52,6 +52,7 @@ #include "eal_options.h" #include "eal_memcfg.h" #include "eal_trace.h" +#include "log_internal.h" #define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL) @@ -546,6 +547,14 @@ rte_eal_init(int argc, char **argv) bool has_phys_addr; enum rte_iova_mode iova_mode; + /* setup log as early as possible */ + if (eal_log_level_parse(argc, argv) < 0) { + rte_eal_init_alert("invalid log arguments."); + rte_errno = EINVAL; + return -1; + } + eal_log_init(getprogname()); + /* checks if the machine is adequate */ if (!rte_cpu_is_supported()) { rte_eal_init_alert("unsupported cpu type."); @@ -565,9 +574,6 @@ rte_eal_init(int argc, char **argv) /* 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); - 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 3d0c34063e..b9a0fb1742 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -936,6 +936,15 @@ rte_eal_init(int argc, char **argv) struct internal_config *internal_conf = eal_get_internal_configuration(); + /* setup log as early as possible */ + if (eal_log_level_parse(argc, argv) < 0) { + rte_eal_init_alert("invalid log arguments."); + rte_errno = EINVAL; + return -1; + } + + eal_log_init(program_invocation_short_name); + /* checks if the machine is adequate */ if (!rte_cpu_is_supported()) { rte_eal_init_alert("unsupported cpu type."); @@ -952,9 +961,6 @@ 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); - /* clone argv to report out later in telemetry */ eal_save_args(argc, argv); @@ -1106,13 +1112,6 @@ rte_eal_init(int argc, char **argv) #endif } - if (eal_log_init(program_invocation_short_name) < 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/windows/eal.c b/lib/eal/windows/eal.c index 2519a30017..74b3ece30c 100644 --- a/lib/eal/windows/eal.c +++ b/lib/eal/windows/eal.c @@ -250,9 +250,13 @@ 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); + if (eal_log_level_parse(argc, argv) < 0) { + rte_eal_init_alert("invalid log arguments."); + rte_errno = EINVAL; + return -1; + } - 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."); diff --git a/lib/log/log_freebsd.c b/lib/log/log_freebsd.c index 953e371bee..33a0925c43 100644 --- a/lib/log/log_freebsd.c +++ b/lib/log/log_freebsd.c @@ -5,8 +5,7 @@ #include #include "log_internal.h" -int +void eal_log_init(__rte_unused const char *id) { - return 0; } diff --git a/lib/log/log_internal.h b/lib/log/log_internal.h index cb15cdff08..d5fabd7ef7 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); +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 index 47aa074da2..6d7dc8f3ab 100644 --- a/lib/log/log_linux.c +++ b/lib/log/log_linux.c @@ -87,18 +87,16 @@ static cookie_io_functions_t console_log_func = { * set the log to default function, called during eal init process, * once memzones are available. */ -int +void eal_log_init(const char *id) { FILE *log_stream; - log_stream = fopencookie(NULL, "w+", console_log_func); - if (log_stream == NULL) - return -1; - openlog(id, LOG_NDELAY | LOG_PID, log_facility); - eal_log_set_default(log_stream); - - return 0; + log_stream = fopencookie(NULL, "w+", console_log_func); + if (log_stream != NULL) + eal_log_set_default(log_stream); + else + eal_log_set_default(stderr); } diff --git a/lib/log/log_windows.c b/lib/log/log_windows.c index a3a756351d..d7c30e4cfa 100644 --- a/lib/log/log_windows.c +++ b/lib/log/log_windows.c @@ -13,12 +13,10 @@ eal_log_syslog(const char *name __rte_unused) } /* set the log to default function, called during eal init process. */ -int +void eal_log_init(__rte_unused const char *id) { rte_openlog_stream(stderr); eal_log_set_default(stderr); - - return 0; } From patchwork Tue Mar 26 01:57:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138792 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 29F0C43D4E; Tue, 26 Mar 2024 02:59:29 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D864840E68; Tue, 26 Mar 2024 02:58:53 +0100 (CET) Received: from mail-vs1-f45.google.com (mail-vs1-f45.google.com [209.85.217.45]) by mails.dpdk.org (Postfix) with ESMTP id 81AA840DDA for ; Tue, 26 Mar 2024 02:58:47 +0100 (CET) Received: by mail-vs1-f45.google.com with SMTP id ada2fe7eead31-4767bcb4ebdso2146040137.0 for ; Mon, 25 Mar 2024 18:58:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711418327; x=1712023127; 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=1/x8ncg9xdOGd9rk7YaJdxnL7XVS6cGgMwNAwMjCJwM=; b=WjpfMuLwz0e1+mBk7uzcoIGbAOYiynk7wsdCOuZc2BP++tbFkOX6yXHEW9C3Xb1lA5 IRepl89vuEqH2Sueausx641EQsU37swIc+BS0B9ZvLMsF4JjuP1M7gxeKUfHdYozOOmd VoavKnXNcuz73Hhw++ucsY/azARhDrwPWFx+wZ/JScGpxUOn2pgjmHulME7pQzsoYKLN 9loXISYSvkeTZgrCxfpuVaohdWWfPaBIQfcAZ1XvSfMGoGapNP+l1F0IDshb+RSnmr/h 7F46wNRuLyNPyZeOi36apZSN/57qPpiYCANgUGh2l4WMIBO1GAvVf3bfvs7xYH8C1R63 kzzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711418327; x=1712023127; 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=1/x8ncg9xdOGd9rk7YaJdxnL7XVS6cGgMwNAwMjCJwM=; b=udOiJgmhO2jXVuvcK6kxLme4Uwfurb7VRr3cVjPKttXTbiti6O4+JJuS688tj0vX8k Ud5r5zw7j8Ozxh5eCVWFHPfIkE6czb6CXS8B/gvQe9yKpDGMEWMIwrMSLZCCFZfnetwa UCmgJqs44ChyFIsaUV/xQhaZWgI6zP61b1sthL9PmKkXorGg4poqc+OCOC32yswotifR OfeNYnvkNFCUzogehULOQlwSStWNpP+60+1PrrFj55BU537sFycTcbe3DA5mcn4ZDjAy EB6+/QVMFeRXhTXV6JOKrrQt648irQZ5nIXle9OQzyzHUMjp7x5KuUeSWYi4R6HW31iL Z6Rg== X-Gm-Message-State: AOJu0YyJkTHszj0sO300cOCFZ9sJUY9J9kwU2nGKDq/JQG1XO9+3N4DV aeb2fbQJ8j6vCxybfpLOES0ZvDXva4XYUDZk0tH0V6wcFVHMWHvwFoyhPghvztcoolJeqhAHYb3 c X-Google-Smtp-Source: AGHT+IFT5prWKjIFuJNoCYNhy3O2WiH5PrBrDDPLVY+N9w838QxjhgcVlT4ZcyKMtlr7VcEiY5NhQg== X-Received: by 2002:a05:6102:2225:b0:478:22aa:bab7 with SMTP id d5-20020a056102222500b0047822aabab7mr2229841vsb.19.1711418326800; Mon, 25 Mar 2024 18:58:46 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id u19-20020a63d353000000b005dc88b232a5sm6571541pgi.26.2024.03.25.18.58.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 18:58:46 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v13 08/11] log: drop syslog support, and make code common Date: Mon, 25 Mar 2024 18:57:03 -0700 Message-ID: <20240326015827.825648-9-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240326015827.825648-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240326015827.825648-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 makes the log setup code common across all platforms. Drops syslog support for now, will come back in later patch. Signed-off-by: Stephen Hemminger --- app/test/test_eal_flags.c | 11 ++- lib/eal/common/eal_common_options.c | 3 - lib/log/log.c | 29 +++++--- lib/log/log_internal.h | 6 -- lib/log/log_linux.c | 102 ---------------------------- lib/log/log_windows.c | 22 ------ lib/log/meson.build | 5 +- lib/log/version.map | 1 - 8 files changed, 26 insertions(+), 153 deletions(-) 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..36e3185a10 100644 --- a/app/test/test_eal_flags.c +++ b/app/test/test_eal_flags.c @@ -984,11 +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 empty --syslog */ + const char *argv3[] = {prgname, prefix, mp_flag, "--syslog"}; /* 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"}; + const char *argv4[] = {prgname, prefix, mp_flag, "--syslog", "always"}; /* 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 */ @@ -1083,8 +1082,8 @@ test_misc_flags(void) 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"); + if (launch_proc(argv4) != 0) { + printf("Error - process did not with --syslog always flag\n"); goto fail; } if (launch_proc(argv5) == 0) { diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index 661b2db211..9ab512e8a1 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -2212,9 +2212,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/log/log.c b/lib/log/log.c index 255f757d94..f597da2e39 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -70,12 +70,13 @@ 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) { + if (rte_logs.file != NULL) + fclose(rte_logs.file); + rte_logs.file = f; return 0; } @@ -505,13 +506,20 @@ rte_log(uint32_t level, uint32_t logtype, const char *format, ...) return ret; } +/* Placeholder */ +int +eal_log_syslog(const char *mode __rte_unused) +{ + return -1; +} + /* - * Called by environment-specific initialization functions. + * Called by rte_eal_init */ void -eal_log_set_default(FILE *default_log) +eal_log_init(const char *id __rte_unused) { - default_log_stream = default_log; + default_log_stream = stderr; #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG RTE_LOG(NOTICE, EAL, @@ -525,8 +533,11 @@ eal_log_set_default(FILE *default_log) void rte_eal_log_cleanup(void) { - if (default_log_stream) { - fclose(default_log_stream); - default_log_stream = NULL; - } + FILE *log_stream = rte_log_get_stream(); + + /* don't close stderr on the application */ + if (log_stream != stderr) + fclose(log_stream); + + rte_logs.file = NULL; } diff --git a/lib/log/log_internal.h b/lib/log/log_internal.h index d5fabd7ef7..3c46328e7b 100644 --- a/lib/log/log_internal.h +++ b/lib/log/log_internal.h @@ -16,12 +16,6 @@ __rte_internal void eal_log_init(const char *id); -/* - * Determine where log data is written when no call to rte_openlog_stream. - */ -__rte_internal -void eal_log_set_default(FILE *default_log); - /* * Save a log option for later. */ diff --git a/lib/log/log_linux.c b/lib/log/log_linux.c deleted file mode 100644 index 6d7dc8f3ab..0000000000 --- a/lib/log/log_linux.c +++ /dev/null @@ -1,102 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * Copyright(c) 2010-2014 Intel Corporation - */ - -#include -#include -#include -#include - -#include -#include - -#include "log_internal.h" - -static int log_facility = LOG_DAEMON; - -static const struct { - const char *name; - int value; -} facilitys[] = { - { "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 }, -}; - -int -eal_log_syslog(const char *name) -{ - unsigned int i; - - for (i = 0; i < RTE_DIM(facilitys); i++) { - if (!strcmp(name, facilitys[i].name)) { - log_facility = facilitys[i].value; - return 0; - } - } - return -1; -} - -/* - * 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. - */ -void -eal_log_init(const char *id) -{ - FILE *log_stream; - - openlog(id, LOG_NDELAY | LOG_PID, log_facility); - - log_stream = fopencookie(NULL, "w+", console_log_func); - if (log_stream != NULL) - eal_log_set_default(log_stream); - else - eal_log_set_default(stderr); -} diff --git a/lib/log/log_windows.c b/lib/log/log_windows.c deleted file mode 100644 index d7c30e4cfa..0000000000 --- a/lib/log/log_windows.c +++ /dev/null @@ -1,22 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * Copyright(c) 2017-2018 Intel Corporation - */ - -#include -#include -#include "log_internal.h" - -int -eal_log_syslog(const char *name __rte_unused) -{ - return -1; /* not used */ -} - -/* set the log to default function, called during eal init process. */ -void -eal_log_init(__rte_unused const char *id) -{ - rte_openlog_stream(stderr); - - eal_log_set_default(stderr); -} 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') diff --git a/lib/log/version.map b/lib/log/version.map index 9c6c49bf06..32b9680c31 100644 --- a/lib/log/version.map +++ b/lib/log/version.map @@ -29,7 +29,6 @@ INTERNAL { eal_log_level2str; eal_log_save_pattern; eal_log_save_regexp; - eal_log_set_default; eal_log_syslog; rte_eal_log_cleanup; }; From patchwork Tue Mar 26 01:57:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138793 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 51BD843D4E; Tue, 26 Mar 2024 02:59:35 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 09BEE40DC9; Tue, 26 Mar 2024 02:58:55 +0100 (CET) Received: from mail-oa1-f49.google.com (mail-oa1-f49.google.com [209.85.160.49]) by mails.dpdk.org (Postfix) with ESMTP id 49C4D40DFB for ; Tue, 26 Mar 2024 02:58:48 +0100 (CET) Received: by mail-oa1-f49.google.com with SMTP id 586e51a60fabf-22a639aedb6so78112fac.3 for ; Mon, 25 Mar 2024 18:58:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711418327; x=1712023127; 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=zu4Y35qfKTRMkWDem+dq2ZFz0NT/aAm4UNjlX7qaan4=; b=xfr9GGpW+m4ZcIkUaGni30cMeql/PTaerJGKogSvGTBnM51YuBqq5IJ8NvruKwhgyB s0JLL6nOLHkVI1/rqZUxOkBObpynC+wahFGxBK25WvycBgrBFiG7ou1wuOXYv+4SkCL+ ZEA0jwOz1eY583cdRvnR6pyeMqYUuTFWpMo5fpGBRtT+zcu7n/AUHX/y2Bea27N5kyEo zapa0eVBuBHe3+FjVyhEaw06NuzQvQicMhyqdbJluBNdkcNRq1Dshfpu+A7zOSOqMzCv cSPNE7EtIYqbyEX6dsCMfdAIbLHxD1LJQbmYsJCKkrIdrGZ7MzZ97uvxlYg3bfm2/mQl ACGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711418327; x=1712023127; 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=zu4Y35qfKTRMkWDem+dq2ZFz0NT/aAm4UNjlX7qaan4=; b=G4LEKc30BN7439NfOHhuHarOE9cdYHaGEKvRixacHzmCOFh+YabG3yBLo73pz4N1CV TCq5EWD745psZR0rryR7DkvRzy9Ak5yAJuvTfRFsu/jT1mwXEzMfNUiffLd41swqx6ZT cRKNLfryzREaUThENzZa7Y7RBpn0NMT/Pjzw77ryNCFnmAvjlOr3zY2IPN3Oijz5X2ar sOPpIadTh6h78pDWuuYXIeffZbkyFI42vC0M75OJQEvWn4herJ6pJeTXObHI7OHVplCt 8atxwlQ9IKQHFQiUmIBOz+2LZ9YDXMtdk65mDnj5O6wQ5LCi4l4Od6X+LLJYB3EvfTio MhYA== X-Gm-Message-State: AOJu0Ywz2ugZfNzp92VhwzY+r4QrG5aJgAvudT+yGXIrodDnhI+0vgoQ SyH6IZ0mgaaKuNvRJ7i7U5wyiGxPbzdB3MFEJ/WVrhc1JVy/XoxEoiBCn86ygmrRBIUMsE8lE+V p X-Google-Smtp-Source: AGHT+IFMcsG2OplwAnkb63rkcN3GpjP7iy6ZFyS8JQKWFySkowbnOvOrcrdVRZfJc9SEWwYtflpxsA== X-Received: by 2002:a05:6871:3426:b0:22a:5423:45ff with SMTP id nh38-20020a056871342600b0022a542345ffmr2857019oac.40.1711418327572; Mon, 25 Mar 2024 18:58:47 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id u19-20020a63d353000000b005dc88b232a5sm6571541pgi.26.2024.03.25.18.58.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 18:58:47 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v13 09/11] log: add hook for printing log messages Date: Mon, 25 Mar 2024 18:57:04 -0700 Message-ID: <20240326015827.825648-10-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240326015827.825648-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240326015827.825648-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. Signed-off-by: Stephen Hemminger --- lib/log/log.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/log/log.c b/lib/log/log.c index f597da2e39..acd4c320b6 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 { @@ -78,6 +83,7 @@ rte_openlog_stream(FILE *f) fclose(rte_logs.file); rte_logs.file = f; + rte_logs.print_func = log_print; return 0; } @@ -484,7 +490,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; } @@ -513,6 +519,15 @@ eal_log_syslog(const char *mode __rte_unused) return -1; } +/* 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); +} + /* * Called by rte_eal_init */ From patchwork Tue Mar 26 01:57:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138794 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 2A54F43D4E; Tue, 26 Mar 2024 02:59:41 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 74C8640EDF; Tue, 26 Mar 2024 02:58:56 +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 5F30D40E25 for ; Tue, 26 Mar 2024 02:58:49 +0100 (CET) Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1dddbe47ac1so37762175ad.1 for ; Mon, 25 Mar 2024 18:58:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711418328; x=1712023128; 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=5NEetilwhR4Q/D6gAt1h7WlScvJ3pu4XZM/NJM6EmTI=; b=HTvAKaXHP663vyaiB/sgwhHz2DOm0if3mtv1R301OpNSIQ25KE4WoBqw3Fgt8oFH9P Xe0t5LE5257w3vJCZ1/bs/EeZabk54XcRvtAPL+LnA1eKzS9CcHSwbt6kJ33Z+m4F7F7 UmGii06bqWMz5XCp3lTuP40JFWHBg3E6MIDLeXZjRCXLIbwdxGaNcasGShBRVkS0eXmC C2K7QLHCX/terDtR/cQVEpKtRfKQKT7Xv99Gfx/4QvhhZXg9+20/FxwCmaAAxRikSXUd R0//fpT8hCrEdwys+MlvVf+22jOEiO9y6rpJlWpf5sxIpH9jzD29IM1SPPxGNmI2gp3b DhzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711418328; x=1712023128; 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=5NEetilwhR4Q/D6gAt1h7WlScvJ3pu4XZM/NJM6EmTI=; b=KnrLNx2h/tukz/JqLKcVF93yEemOzTbKYILY4MYwFK7TSdKm6/u+yu/zMwmQLwjBRz EHRWeMpjj5s2cH9/oxvsU4z9D0ZXAWPAM3rdagjQjjqvHCAvZwLXg3a16/OgcUOVWcbF e2d81yeeLWFA96j4B91oXB1Q8dH1PxteKPD+AtafGntCzjMWoEQNMeWI8f+92yOADYYF GOWxYYaKxkrH0dN+ERt0BzcW30Ys/mPpG3kdo2d3ZSSVyUYDL/M6Ub/oMlKu1uWb1N2d 7KzocO3oydUxKHExTs63J/AdeiaqxE1WEJOIywWn6Xn5mj4VhDtPzmmBm4swZKjz/4lL 7rxA== X-Gm-Message-State: AOJu0YywwY0CPX9h0xbWu1cz7rjbMenoL+UngWLLNA2rxom67ga0OSnk MVWcwMEyIjHHTrhyQBo6tJvO1jt18BlszPweUuNdVzSnCHKL4TRWIgVt0OJYpWH6EiPku/ThJBq u X-Google-Smtp-Source: AGHT+IFUaxQgK7VgjZwrNYIrp08nTcpS6sEIF8V/NM2V1apEamzJgyQwUxQbx8U0cpfaDxNvuvlvxw== X-Received: by 2002:a17:902:c451:b0:1dd:dcd3:662c with SMTP id m17-20020a170902c45100b001dddcd3662cmr149369plm.4.1711418328480; Mon, 25 Mar 2024 18:58:48 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id u19-20020a63d353000000b005dc88b232a5sm6571541pgi.26.2024.03.25.18.58.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 18:58:48 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Bruce Richardson , Dmitry Kozlyuk , Tyler Retzlaff , Pallavi Kadam Subject: [PATCH v13 10/11] log: add timestamp option Date: Mon, 25 Mar 2024 18:57:05 -0700 Message-ID: <20240326015827.825648-11-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240326015827.825648-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240326015827.825648-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 | 26 ++++ doc/guides/prog_guide/log_lib.rst | 26 ++++ lib/eal/common/eal_common_options.c | 14 ++- lib/eal/common/eal_options.h | 2 + lib/eal/freebsd/eal.c | 6 +- lib/eal/linux/eal.c | 4 +- lib/eal/windows/eal.c | 4 +- lib/log/log.c | 183 +++++++++++++++++++++++++++- lib/log/log_internal.h | 9 ++ lib/log/version.map | 1 + 10 files changed, 268 insertions(+), 7 deletions(-) diff --git a/app/test/test_eal_flags.c b/app/test/test_eal_flags.c index 36e3185a10..e54f6e8b7f 100644 --- a/app/test/test_eal_flags.c +++ b/app/test/test_eal_flags.c @@ -1054,6 +1054,19 @@ 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" }; + + /* Try running with invalid timestamp */ + const char * const argv25[] = {prgname, prefix, mp_flag, + "--log-timestamp=invalid" }; + + /* run all tests also applicable to FreeBSD first */ if (launch_proc(argv0) == 0) { @@ -1161,6 +1174,19 @@ 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; + } + if (launch_proc(argv25) == 0) { + printf("Error - process did run ok with --log-timestamp=invalid 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 ff9d1b54a2..504eefe1d2 100644 --- a/doc/guides/prog_guide/log_lib.rst +++ b/doc/guides/prog_guide/log_lib.rst @@ -59,6 +59,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. +Log timestamp +~~~~~~~~~~~~~ + +An optional timestamp can be added before each message +by adding the ``--log-timestamp`` option. +For example:: + + /path/to/app --log-level=lib.*:debug --log-timestamp + +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 9ab512e8a1..5173835c2c 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 }, @@ -1616,6 +1617,7 @@ eal_log_level_parse(int argc, char * const argv[]) switch (opt) { case OPT_LOG_LEVEL_NUM: case OPT_SYSLOG_NUM: + case OPT_LOG_TIMESTAMP_NUM: if (eal_parse_common_option(opt, optarg, internal_conf) < 0) return -1; break; @@ -1843,7 +1845,7 @@ eal_parse_common_option(int opt, const char *optarg, break; #endif - case OPT_LOG_LEVEL_NUM: { + case OPT_LOG_LEVEL_NUM: if (eal_parse_log_level(optarg) < 0) { EAL_LOG(ERR, "invalid parameters for --" @@ -1851,7 +1853,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: { @@ -2216,6 +2225,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 f3f2e104f6..e24c9eca53 100644 --- a/lib/eal/common/eal_options.h +++ b/lib/eal/common/eal_options.h @@ -35,6 +35,8 @@ enum { OPT_LCORES_NUM, #define OPT_LOG_LEVEL "log-level" OPT_LOG_LEVEL_NUM, +#define OPT_LOG_TIMESTAMP "log-timestamp" + OPT_LOG_TIMESTAMP_NUM, #define OPT_TRACE "trace" OPT_TRACE_NUM, #define OPT_TRACE_DIR "trace-dir" diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index 55ff27a4da..662a829ce8 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -392,8 +392,10 @@ eal_parse_args(int argc, char **argv) goto out; } - /* eal_log_level_parse() already handled these */ - if (opt == OPT_LOG_LEVEL_NUM || opt == OPT_LOG_SYSLOG_NUM) + /* eal_log_level_parse() already handled these options */ + if (opt == OPT_LOG_LEVEL_NUM || + opt == OPT_SYSLOG_NUM || + opt == OPT_LOG_TIMESTAMP_NUM) continue; ret = eal_parse_common_option(opt, optarg, internal_conf); diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index b9a0fb1742..8cbea480e0 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -611,7 +611,9 @@ eal_parse_args(int argc, char **argv) } /* eal_log_level_parse() already handled these options */ - if (opt == OPT_LOG_LEVEL_NUM || opt == OPT_SYSLOG_NUM) + if (opt == OPT_LOG_LEVEL_NUM || + opt == OPT_SYSLOG_NUM || + opt == OPT_LOG_TIMESTAMP_NUM) continue; ret = eal_parse_common_option(opt, optarg, internal_conf); diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c index 74b3ece30c..4283c920c8 100644 --- a/lib/eal/windows/eal.c +++ b/lib/eal/windows/eal.c @@ -121,7 +121,9 @@ eal_parse_args(int argc, char **argv) } /* eal_log_level_parse() already handled these options */ - if (opt == OPT_LOG_LEVEL_NUM || opt == OPT_SYSLOG_NUM) + if (opt == OPT_LOG_LEVEL_NUM || + opt == OPT_SYSLOG_NUM || + opt == OPT_LOG_TIMESTAMP_NUM) continue; ret = eal_parse_common_option(opt, optarg, internal_conf); diff --git a/lib/log/log.c b/lib/log/log.c index acd4c320b6..2dca91306e 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,11 @@ 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 */ + size_t dynamic_types_len; struct rte_log_dynamic_type *dynamic_types; } rte_logs = { @@ -375,6 +390,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, @@ -519,6 +537,152 @@ eal_log_syslog(const char *mode __rte_unused) return -1; } +/* 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 current timespec into ISO8601 format */ +static ssize_t +format_iso8601(char *tsbuf, size_t tsbuflen, const struct timespec *now) +{ + struct tm *tm, tbuf; + char dbuf[64]; /* "2024-05-01T22:11:00" */ + char zbuf[16] = { }; /* "+0800" */ + + tm = localtime_r(&now->tv_sec, &tbuf); + + /* 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 +hhmm */ + if (strftime(zbuf, sizeof(zbuf), "%z", tm) == 0) + return 0; + + /* the result for strftime is "+hhmm" but ISO wants "+hh:mm" */ + return snprintf(tsbuf, tsbuflen, "%s,%06lu%.3s:%.2s", + dbuf, now->tv_nsec / 1000u, + zbuf, zbuf + 3); +} + +/* + * Make a timestamp where if the minute, hour or day has + * changed from the last message, then print abbreviated + * "Month day hour:minute" format. + * Otherwise print delta from last printed message as +sec.usec + */ +static ssize_t +format_reltime(char *tsbuf, size_t tsbuflen, const struct timespec *now) +{ + struct tm *tm, tbuf; + static struct tm last_tm; + struct timespec delta; + + tm = localtime_r(&now->tv_sec, &tbuf); + 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 != last_tm.tm_min || + tm->tm_hour != last_tm.tm_hour || + tm->tm_yday != last_tm.tm_yday) { + last_tm = *tm; + return strftime(tsbuf, tsbuflen, "%b%d %H:%M", tm); + } else { + return snprintf(tsbuf, tsbuflen, "+%3lu.%06lu", + (unsigned long)delta.tv_sec, + (unsigned long)delta.tv_nsec / 1000u); + } +} + +/* Format up a timestamp based on current format */ +static ssize_t +format_timestamp(char *tsbuf, size_t tsbuflen) +{ + struct timespec now, delta; + + 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; + + return format_reltime(tsbuf, tsbuflen, &now); + + 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: + if (clock_gettime(CLOCK_REALTIME, &now) < 0) + return 0; + + return format_iso8601(tsbuf, tsbuflen, &now); + } + + return 0; +} + /* default log print function */ __rte_format_printf(3, 0) static int @@ -528,12 +692,29 @@ 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); +} + /* * Called by rte_eal_init */ void eal_log_init(const char *id __rte_unused) { + if (rte_logs.time_format != EAL_LOG_TIMESTAMP_NONE) + rte_logs.print_func = log_print_with_timestamp; + default_log_stream = stderr; #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG diff --git a/lib/log/log_internal.h b/lib/log/log_internal.h index 3c46328e7b..7c7d44eed2 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 @@ -39,4 +41,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 32b9680c31..14d6681a5f 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_syslog; + eal_log_timestamp; rte_eal_log_cleanup; }; From patchwork Tue Mar 26 01:57:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138795 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 1C72643D4E; Tue, 26 Mar 2024 02:59:47 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3DE9340F16; Tue, 26 Mar 2024 02:58:58 +0100 (CET) Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) by mails.dpdk.org (Postfix) with ESMTP id 4E51840E72 for ; Tue, 26 Mar 2024 02:58:51 +0100 (CET) Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-6e6ee9e3cffso3432073b3a.1 for ; Mon, 25 Mar 2024 18:58:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711418330; x=1712023130; 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=KJS5/q3KJdNArsmP3Gyhmj2rTE5gG5JGMGT1XobfKp8=; b=ncTAG67sAgi/Y+ikCy9dG0YA0uwrKX/2wRyxF7WdjOY8fod9XsD0LGxgkJ62eos09m NBzNzr3wMPxQJhhw1g2G4XoKounC0iFtSs3mT/KV3dz1WUZYmjNd6UAKJep3mNO3iiVC nbzSCS3E5EzXfFxbsdf5OjFQig9Zyb7hK49VoQnCmIZ2c2Fpsn7Ipojy2uV2BkW4u8A9 smks3EVCkhrs8WVzck2Yn+hD/w38iJ3BafEYfGihg2VLXv8FWSWIQtNY5eyKfadqB39Q rJMPyWnnoqgGT8DeyONXS3chNYPXR+K7YD+VOrVnFweNi0dStxzEvyuDH+pVUGzQshwm OtQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711418330; x=1712023130; 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=KJS5/q3KJdNArsmP3Gyhmj2rTE5gG5JGMGT1XobfKp8=; b=EEYwzNEldR08jUNfbQ+ObNOg+PR9Lm2OTkkp0cSsTtZ6npgxHrJWsc23Gr9OdnJCtz 26pPRamsU4u0lRRuMkzI9nV/Zv5BZPefaiTojdzrB+JlZyKFE3sDHsbZ59QukdDQC4NM d2uquhxl+SqXshB0BTJ1H0JUNN5oHcXSRQF+YELQj1bjK5CUzUWLSQZSja2OnXrcWhpV V0vdaW+Qkq+rQDW/pkkKmnu0CeSKfslCOPZft7iHLyAwWooburiaUkxZ5/fyAQMXY+Na 1n1y1KvHe+RZUQwqqtLYDUbQv9nzLjU+LBvlI+/GcwNI/iacibOyCyXJd3LO7vV2Xdzu CcNg== X-Gm-Message-State: AOJu0YxfycORwfz4uuWEUXZxa2TH8JybGALwYsFVCyZmkC6oh4kPiadk iic24ueA7vj62SZUKokhwJ5cEaY4/Vgr7xXYRIvtBMH+Ei4Y4tWhKqPZf2wHe5HIy5qQhXcePdG K X-Google-Smtp-Source: AGHT+IG7E4xh9HBQy3V5tbnyQWr9SVKQqvZ1blFz8stp2786pbs0kprp9ac+/BsukgGqLaRP1JCPlg== X-Received: by 2002:a05:6a00:928e:b0:6e7:6bc4:ef8c with SMTP id jw14-20020a056a00928e00b006e76bc4ef8cmr181366pfb.3.1711418329442; Mon, 25 Mar 2024 18:58:49 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id u19-20020a63d353000000b005dc88b232a5sm6571541pgi.26.2024.03.25.18.58.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 18:58:49 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v13 11/11] log: add optional support of syslog Date: Mon, 25 Mar 2024 18:57:06 -0700 Message-ID: <20240326015827.825648-12-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240326015827.825648-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240326015827.825648-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 Log to syslog only if option is specified. And if syslog is used then normally only log to syslog, don't duplicate output. Also enables syslog support on FreeBSD. Signed-off-by: Stephen Hemminger --- app/test/test_eal_flags.c | 5 +- doc/guides/linux_gsg/linux_eal_parameters.rst | 27 ----- doc/guides/prog_guide/log_lib.rst | 17 +++ lib/eal/common/eal_common_options.c | 2 +- lib/log/log.c | 101 ++++++++++++++++-- 5 files changed, 114 insertions(+), 38 deletions(-) diff --git a/app/test/test_eal_flags.c b/app/test/test_eal_flags.c index e54f6e8b7f..08f4866461 100644 --- a/app/test/test_eal_flags.c +++ b/app/test/test_eal_flags.c @@ -987,9 +987,10 @@ test_misc_flags(void) /* With empty --syslog */ const char *argv3[] = {prgname, prefix, mp_flag, "--syslog"}; /* With valid --syslog */ - const char *argv4[] = {prgname, prefix, mp_flag, "--syslog", "always"}; + const char *argv4[] = {prgname, prefix, mp_flag, "--syslog=both"}; /* With invalid --syslog */ - const char *argv5[] = {prgname, prefix, mp_flag, "--syslog", "error"}; + const char *argv5[] = {prgname, prefix, mp_flag, "--syslog=invalid"}; + /* 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}; 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/log_lib.rst b/doc/guides/prog_guide/log_lib.rst index 504eefe1d2..abaedc7212 100644 --- a/doc/guides/prog_guide/log_lib.rst +++ b/doc/guides/prog_guide/log_lib.rst @@ -83,6 +83,23 @@ To prefix all console messages with ISO format time the syntax is:: /path/to/app --log-timestamp=iso +Log output +~~~~~~~~~~ + +If desired, messages can be redirected to syslog (on Linux and FreeBSD) with the ``--syslog`` +option. There are three possible settings for this option: + +*always* + Redirect all log output to syslog. + +*auto* + Use console if it is a terminal, and use syslog if is not. + +*both* + Print to both console and syslog. + +If ``--syslog`` option is not specified, then only console (stderr) will be used. + 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 5173835c2c..16884c5aa3 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -91,7 +91,7 @@ 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_SYSLOG, 2, 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 }, diff --git a/lib/log/log.c b/lib/log/log.c index 2dca91306e..d8974c66db 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -13,15 +13,17 @@ #include #include +#ifdef RTE_EXEC_ENV_WINDOWS +#include +#else +#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; @@ -36,14 +38,25 @@ enum eal_log_time_format { EAL_LOG_TIMESTAMP_ISO, }; +enum eal_log_syslog { + EAL_LOG_SYSLOG_NONE = 0, /* do not use syslog */ + EAL_LOG_SYSLOG_AUTO, /* use syslog only if not a terminal */ + EAL_LOG_SYSLOG_ALWAYS, /* always use syslog */ + EAL_LOG_SYSLOG_BOTH, /* log to both syslog and stderr */ +}; + 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. */ +#ifndef RTE_EXEC_ENV_WINDOWS + enum eal_log_syslog syslog_opt; +#endif log_print_t print_func; enum eal_log_time_format time_format; @@ -532,9 +545,23 @@ rte_log(uint32_t level, uint32_t logtype, const char *format, ...) /* Placeholder */ int -eal_log_syslog(const char *mode __rte_unused) +eal_log_syslog(const char *str) { +#ifdef RTE_EXEC_ENV_WINDOWS + RTE_SET_USED(str); return -1; +#else + if (str == NULL || strcmp(str, "auto") == 0) + /* log to syslog only if stderr is not a terminal */ + rte_logs.syslog_opt = EAL_LOG_SYSLOG_AUTO; + else if (strcmp(str, "both") == 0) + rte_logs.syslog_opt = EAL_LOG_SYSLOG_BOTH; + else if (strcmp(str, "always") == 0) + rte_logs.syslog_opt = EAL_LOG_SYSLOG_ALWAYS; + else + return -1; + return 0; +#endif } /* Set the log timestamp format */ @@ -706,17 +733,75 @@ log_print_with_timestamp(FILE *f, uint32_t level, return log_print(f, level, format, ap); } +#ifndef RTE_EXEC_ENV_WINDOWS /* - * Called by rte_eal_init + * wrapper for log stream to put messages into syslog + * useful for cases like: + * rte_hex_dump(rte_get_log_stream(), ...) */ -void -eal_log_init(const char *id __rte_unused) +static ssize_t +syslog_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); + return size; +} + +static int +syslog_log_close(__rte_unused void *c) { + closelog(); + return 0; +} + +static cookie_io_functions_t syslog_log_func = { + .write = syslog_log_write, + .close = syslog_log_close, +}; +#endif + + +/* Choose how log output is directed */ +static void +log_output_selection(const char *id) +{ + RTE_SET_USED(id); + +#ifndef RTE_EXEC_ENV_WINDOWS + bool is_terminal = isatty(STDERR_FILENO); + + if (!(rte_logs.syslog_opt == EAL_LOG_SYSLOG_NONE || + (rte_logs.syslog_opt == EAL_LOG_SYSLOG_AUTO && is_terminal))) { + int flags = LOG_NDELAY | LOG_PID; + +#ifdef LOG_PERROR + if (rte_logs.syslog_opt == EAL_LOG_SYSLOG_BOTH) + flags |= LOG_PERROR; +#endif + openlog(id, flags, is_terminal ? LOG_USER : LOG_DAEMON); + + /* redirect other log messages to syslog as well */ + FILE *log_stream = fopencookie(NULL, "w", syslog_log_func); + if (log_stream != NULL) + default_log_stream = log_stream; + return; + } +#endif if (rte_logs.time_format != EAL_LOG_TIMESTAMP_NONE) rte_logs.print_func = log_print_with_timestamp; +} +/* + * Called by rte_eal_init + */ +void +eal_log_init(const char *id) +{ + rte_logs.print_func = log_print; default_log_stream = stderr; + log_output_selection(id); + #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG RTE_LOG(NOTICE, EAL, "Debug dataplane logs available - lower performance\n");