From patchwork Mon Mar 25 20:46: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: 138771 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 9F40F43D49; Mon, 25 Mar 2024 21:54:24 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7212C40A77; Mon, 25 Mar 2024 21:54:19 +0100 (CET) Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by mails.dpdk.org (Postfix) with ESMTP id 431744067D for ; Mon, 25 Mar 2024 21:54:18 +0100 (CET) Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1dee5daa236so35535895ad.0 for ; Mon, 25 Mar 2024 13:54:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711400057; x=1712004857; 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=MItS1Kg02JktqL+zuDh2N/71zvPrtt5zLFxzrip7H/2+ZuwTKyUz1eRhCGYxfQ/v8F REU2nnF6fN4P7IW3LKmZwGofZkmTGKnIM/9CMEXkmZ5DYFi+I9uL8kOXj2IvLn3kslH1 Rk68xcazhh76vtuZgDkRU0dCLKmsoCrOGG8pNsG9aMqn4wlb5Ra9RgpDYom3ou5XUpoe 2SKvWVaraMnl3l3CKpKUVVhk7C5kLuVY+R9yILWsN6t42oqO3gHHjLD3gGuWUwmhtyiD JRN14Ntwm1Xg/qbMOHehvlenYUlVflNKE2hPXHIHNVe907VgdrMK+tPdwP3W7Yh6ngzp o/lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711400057; x=1712004857; 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=Z6kdu20mhNbbtzkOmdTfql3CT2UN56iKWQ+RWHW9EZr7S76x02KIotRMCkYpIA5rJk GaoTJLAPgUpU1Wu3x6kbm9BKdGLTds3vNKrOztnVzGO2v3VMGVfpi7cvR9Srtg2C+YEg 9tqPeyh4BVA90cdHu7kFKqCX1OS41zLR5P5422tpz/WZrk+xyB0SOZAGoiIN5PAAEb9E 56k2kBXwFji0UGbBIWLrQFi5Tk+mMBwr/LsHl+sKHZfxHfOyW9+qkLcVCDOuc8cDbKVK aB0TBvdgRPhqb+dQTONy9OjO8RQZd2sjVyD5X4I8g1hEaQUec3Qe+70c0Ixc14DUW85A I13A== X-Gm-Message-State: AOJu0YyU2gNn7dLSq9tfJk3jbNU2fCPGOY8sbAyH4xZck5gHVVHIKPo/ 7GrIkUz27Qmv0fLqISF8PSWxEBGBmVmXSDGqHS76Urpy/D+d86Y27K0Ic1KaS83cUTlM+qAz115 o X-Google-Smtp-Source: AGHT+IFYXLB3txJGWqT/r49jZ6r4xkiGopDhBCitkzMId1c07SKK7PiWgrKEC4InVg/FLKdUjbd5Iw== X-Received: by 2002:a17:902:f70e:b0:1e0:e56e:eddd with SMTP id h14-20020a170902f70e00b001e0e56eedddmr602863plo.32.1711400057272; Mon, 25 Mar 2024 13:54:17 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id b18-20020a170903229200b001e0b5eee802sm3164487plh.123.2024.03.25.13.54.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 13:54:16 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff , Dmitry Kozlyuk , Pallavi Kadam Subject: [PATCH v12 01/14] windows: make getopt functions have const properties Date: Mon, 25 Mar 2024 13:46:58 -0700 Message-ID: <20240325205405.669897-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240325205405.669897-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240325205405.669897-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Having different prototypes on different platforms can lead to lots of unnecessary workarounds. Looks like the version of getopt used from windows was based on an older out of date version from FreeBSD. This patch changes getopt, getopt_long, etc to have the same const attributes as Linux and FreeBSD. The changes are derived from the current FreeBSD version of getopt_long. Signed-off-by: Stephen Hemminger Acked-by: Tyler Retzlaff Acked-by: Dmitry Kozlyuk --- lib/eal/windows/getopt.c | 23 ++++++++++++----------- lib/eal/windows/include/getopt.h | 8 ++++---- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/eal/windows/getopt.c b/lib/eal/windows/getopt.c index a1f51c6c23..50ff71b930 100644 --- a/lib/eal/windows/getopt.c +++ b/lib/eal/windows/getopt.c @@ -20,7 +20,7 @@ #include #include -const char *optarg; /* argument associated with option */ +char *optarg; /* argument associated with option */ int opterr = 1; /* if error message should be printed */ int optind = 1; /* index into parent argv vector */ int optopt = '?'; /* character checked for validity */ @@ -39,9 +39,9 @@ static void pass(const char *a) {(void) a; } #define BADARG ((*options == ':') ? (int)':' : (int)'?') #define INORDER 1 -#define EMSG "" +static char EMSG[] = ""; -static const char *place = EMSG; /* option letter processing */ +static char *place = EMSG; /* option letter processing */ /* XXX: set optreset to 1 rather than these two */ static int nonopt_start = -1; /* first non option argument (for permute) */ @@ -80,7 +80,7 @@ gcd(int a, int b) */ static void permute_args(int panonopt_start, int panonopt_end, int opt_end, - char **nargv) + char * const *nargv) { int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos; char *swap; @@ -101,11 +101,12 @@ permute_args(int panonopt_start, int panonopt_end, int opt_end, pos -= nnonopts; else pos += nopts; + swap = nargv[pos]; /* LINTED const cast */ - ((char **) nargv)[pos] = nargv[cstart]; + ((char **)(uintptr_t)nargv)[pos] = nargv[cstart]; /* LINTED const cast */ - ((char **)nargv)[cstart] = swap; + ((char **)(uintptr_t)nargv)[cstart] = swap; } } } @@ -116,7 +117,7 @@ permute_args(int panonopt_start, int panonopt_end, int opt_end, * Returns -1 if short_too is set and the option does not match long_options. */ static int -parse_long_options(char **nargv, const char *options, +parse_long_options(char * const *nargv, const char *options, const struct option *long_options, int *idx, int short_too) { const char *current_argv; @@ -236,7 +237,7 @@ parse_long_options(char **nargv, const char *options, * Parse argc/argv argument vector. Called by user level routines. */ static int -getopt_internal(int nargc, char **nargv, const char *options, +getopt_internal(int nargc, char *const nargv[], const char *options, const struct option *long_options, int *idx, int flags) { char *oli; /* option letter list index */ @@ -434,7 +435,7 @@ getopt_internal(int nargc, char **nargv, const char *options, * Parse argc/argv argument vector. */ int -getopt(int nargc, char *nargv[], const char *options) +getopt(int nargc, char *const nargv[], const char *options) { return getopt_internal(nargc, nargv, options, NULL, NULL, FLAG_PERMUTE); @@ -445,7 +446,7 @@ getopt(int nargc, char *nargv[], const char *options) * Parse argc/argv argument vector. */ int -getopt_long(int nargc, char *nargv[], const char *options, +getopt_long(int nargc, char *const nargv[], const char *options, const struct option *long_options, int *idx) { @@ -458,7 +459,7 @@ getopt_long(int nargc, char *nargv[], const char *options, * Parse argc/argv argument vector. */ int -getopt_long_only(int nargc, char *nargv[], const char *options, +getopt_long_only(int nargc, char *const nargv[], const char *options, const struct option *long_options, int *idx) { diff --git a/lib/eal/windows/include/getopt.h b/lib/eal/windows/include/getopt.h index 6f57af454b..e4cf6873cb 100644 --- a/lib/eal/windows/include/getopt.h +++ b/lib/eal/windows/include/getopt.h @@ -44,7 +44,7 @@ /** argument to current option, or NULL if it has none */ -extern const char *optarg; +extern char *optarg; /** Current position in arg string. Starts from 1. * Setting to 0 resets state. */ @@ -80,14 +80,14 @@ struct option { }; /** Compat: getopt */ -int getopt(int argc, char *argv[], const char *options); +int getopt(int argc, char *const argv[], const char *options); /** Compat: getopt_long */ -int getopt_long(int argc, char *argv[], const char *options, +int getopt_long(int argc, char *const argv[], const char *options, const struct option *longopts, int *longindex); /** Compat: getopt_long_only */ -int getopt_long_only(int nargc, char *argv[], const char *options, +int getopt_long_only(int nargc, char *const argv[], const char *options, const struct option *long_options, int *idx); From patchwork Mon Mar 25 20:46: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: 138772 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 34B4A43D49; Mon, 25 Mar 2024 21:54:31 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CE8CC40A8A; Mon, 25 Mar 2024 21:54:20 +0100 (CET) Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by mails.dpdk.org (Postfix) with ESMTP id EB94540A6C for ; Mon, 25 Mar 2024 21:54:18 +0100 (CET) Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1e0511a4383so34312925ad.2 for ; Mon, 25 Mar 2024 13:54:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711400058; x=1712004858; 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=YbZAthlyaEUUNsR5TLLebEdwQ/pD6jFJO+aJhq4yxXrsP3W7p95EEZ/pDbinh4WVTu yP48Q32hSBqnv0dQwMT8MdqQrRQGABf3Mv8aLGz5G1uifnAZy46Qz8UprprogExDQD8D E0zD2tOhyp8ulztOBBLgpGIJ3EuGp2HHLGCYnD6q8yCAnGAQ+5AjboGVIJVVNWXmAFl+ kiRr5RWpmA0q3XN0k1Rgs3/rJrA/G59mPZnX9wK34cQv+O05wsKZWELuFUub9uhNXFC3 0f3HpOAyHEbYg9RZZxEAVIEvhmv/hM8EPn+h6Lh2FMj6UprdqQlVZjaA8M1zdfieqV7v 6MUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711400058; x=1712004858; 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=nu/nTvo7pZSiqGHdydE3VzfjYxPQEojc702Gck5hp/iaenFByni3VknCtxQtSVMQes FTat1k3W7hn/dFskZz9Ag9viWCBeXtHoO6oVpRg34uYdH0RffSi2oyV565YYGGqOgbk+ 4pNr97CAWijoB7p3MIcl8KGdCbytiYSODD2W9KqCb0DaSPKrIIuHep7FNnqcvhagnRzB leeljaFoWBcmUxNbKC5l/EKLMV/v+BopMrvvRIgjmMyeqtMpzk2CO5GwdUDPRCID2xBK LUe/uFnyrUvh0kl+9ej0+Ksb3D0LB1znVoT3yLnykPPah5a3uWu7WAQ7AsyEGbRHPhhB /bHg== X-Gm-Message-State: AOJu0YyuohCHUYAb9X87zxCkM1dQ8N1iBcns6YPHt3BPb6LMAF5QkdsP nxaKay5IDeKf45GjilSrmW4+Y+VzihXm3+I862sXoBRFfS8Ci++3vTakfGCm7vjxb8zVvWx0Uv+ 8 X-Google-Smtp-Source: AGHT+IEXMKgqKRfeiCh0wW1YhEGye93p/rJkWFoIRs70PAw48AVsjv2Ff39Hsa0qvVPUge/Qt126IA== X-Received: by 2002:a17:903:24e:b0:1e0:6351:ad94 with SMTP id j14-20020a170903024e00b001e06351ad94mr9077185plh.36.1711400058119; Mon, 25 Mar 2024 13:54:18 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id b18-20020a170903229200b001e0b5eee802sm3164487plh.123.2024.03.25.13.54.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 13:54:17 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Dmitry Kozlyuk , Tyler Retzlaff , Pallavi Kadam Subject: [PATCH v12 02/14] windows: add os shim for localtime_r Date: Mon, 25 Mar 2024 13:46:59 -0700 Message-ID: <20240325205405.669897-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240325205405.669897-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240325205405.669897-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 Mon Mar 25 20:47: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: 138773 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 682A643D49; Mon, 25 Mar 2024 21:54:37 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1D59940DC9; Mon, 25 Mar 2024 21:54:23 +0100 (CET) Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by mails.dpdk.org (Postfix) with ESMTP id 1FE8440A87 for ; Mon, 25 Mar 2024 21:54:20 +0100 (CET) Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1e0b889901bso11151715ad.1 for ; Mon, 25 Mar 2024 13:54:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711400059; x=1712004859; 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=wsxdXHG8mJRwN2/w4ehYeTjtn6DfxUp0LmDT05/wTbeoJC5A2m/IDhDdNmSomUZuVM o0YsohZs3YLBI0GUtu+g+He7Cgwr7YW0UI5u5f0QSJcC93taJFZGWqermojQUog6qAX3 TBBG2RxKybOIjEJNNDXvzhHmT2PD7fOtNCtHnj6cvOF33c/2V9DE3DEb28dfDSEaOBfW DYFjuMQ7XLMFLyKZikCO67Zz/DqqFQY9DUF3YcsnOMvCURHyeknWcwo8tr8JPgnoZUT6 cRzTRvoaEeuxrEvde+vy0aEVRuMFzM9Ti/YIMvkx63jVLXVLFWo8hsqV96/yls/wEjTT odNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711400059; x=1712004859; 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=bpnZpLMNIg+k8NDYLR7R8i8OzysgNpGB7mSF4MI5LRH/tVNvzsbS1Zlz4+Zvs9tzvh iv/NfiE9cWgfaKx4YlCNmh15TK+POoxcYX2OFCxk+SZ+kH7B6S/kyJNgcaNQbG0qwrSX n2z9pz7rjjwPGkEoKxmiZCPdLeKetFYhQLlsfWNk6o5Wt8IWNB+nl0JQ1Nft7n8Inqh7 4MrIhYrUVpgxAC8w33hwVcKsx8kw4PC9SqPW72mVtg+ixmyR6R50zge1kR3wSa3WAmjK ndeyWtI/4ZGQfWDsD3XW57Fd6sIUh5OfwdJvVPsngKGF1lFpCGYURGd2Rki80yTPiflV uNeQ== X-Gm-Message-State: AOJu0Yx4r0HqcPrWOhLlLAL49Ndv9h5HJMgQzlLTTY2dCB2lfS17XPPa u+V+3XiP38NKAdIE1PM0AMZ0NvK9JN3gteZbRk8CSY1UmqBO1biDbN3Ljhccs9Kjul3o3WE9Bp+ w X-Google-Smtp-Source: AGHT+IHQIwK3OF5rt8bmFSaEmzCkH6iAWdTU2UUL/HuI0HgX4XE/JFZp9uxCO7PYL/7yf+AzPX/XmQ== X-Received: by 2002:a17:902:a3c6:b0:1e0:9122:abc4 with SMTP id q6-20020a170902a3c600b001e09122abc4mr7721062plb.21.1711400059216; Mon, 25 Mar 2024 13:54:19 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id b18-20020a170903229200b001e0b5eee802sm3164487plh.123.2024.03.25.13.54.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 13:54:18 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Bruce Richardson , Dmitry Kozlyuk , Tyler Retzlaff , Pallavi Kadam Subject: [PATCH v12 03/14] eal: make eal_log_level_parse common Date: Mon, 25 Mar 2024 13:47:00 -0700 Message-ID: <20240325205405.669897-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240325205405.669897-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240325205405.669897-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 Mon Mar 25 20:47: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: 138774 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 3520343D49; Mon, 25 Mar 2024 21:54:44 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 78D9E40DD8; Mon, 25 Mar 2024 21:54:24 +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 E7A2640C35 for ; Mon, 25 Mar 2024 21:54:20 +0100 (CET) Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1e04ac200a6so33569465ad.1 for ; Mon, 25 Mar 2024 13:54:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711400060; x=1712004860; 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=0lwrIJYxvNLf0a39fcRhlraOvEYAA1lH7mWpaTn6q288vpNniCPZVpcMiaRpYt4a2k XhaeyUQBc3BoT5AcgGbdxHevhQH5arMHutBifyz2tOyS7JAc2ira++RswQUXVCMrchbL 2pCdGM51NlpI+R/B/vDhnM8Tx4Tzhje9OJtHkUvCzfOF6Z7eKWh12MSTyKXJCbYOgnpM 07vvz6kD+L+AhifoxWZbaKfHWzZQCGJapKgJtucTjr0N6JO+OUChZdHlFCqu638k5BxP zYraZdIa5liOVx5SFhCNKsyXhF4bpzKe+vXBmUpDSrSAAJmGQyGdVTJ3BCR1l8ZfWZwX F1EQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711400060; x=1712004860; 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=E3G07RR1FrlhBI3n7ndMrq/6Au00mC3/gIab/ev2PnMHbSB3Q8pSpZdz8xz2L1YCvn bTNeRp+QD1zm+wDiiUrsCVVAFl4yRIjbCQIVP6J+LeY3H94vMc2nTqIASGATkTpYA3j1 pYq3A1fYcImaih7sXfVblbMPh4O9juglQzM63Z7rA8Uw/GbebLr/pHvXfNfpV0MWDfWX ce1JblHQSUjEQtkiJksyZs2TLE4qKucJAk4BJ7wnjoxgAFKjBdX/CYSv5wUUbmXCxa/c 8KO+kPaIp78efqCB0EOuDRedJ6RwyoiSxdv0KFUGoLIVXauZVqrfoqmWE1KvX0+TOuJ9 e/iw== X-Gm-Message-State: AOJu0YzurqgedKZMg6n6Lf2ziyuVaPF9aDczXRyQtlWccsr/91DqOTST LLX9FKpOnYEQ/6Gsx7vlqlfcPm9Fckg1FaBhER+mAMlzGrQnOi+oveRoM+zntrz+p233EDUfK0e 0 X-Google-Smtp-Source: AGHT+IEEQwPjz1V90YIKqM817KDpWwBSP7Ql6ZPqU/+Kc2f22bJqNnCvNs7UgzC3embE/XvgM3QAxA== X-Received: by 2002:a17:902:d4d0:b0:1dd:df89:5c2 with SMTP id o16-20020a170902d4d000b001dddf8905c2mr11219004plg.22.1711400060120; Mon, 25 Mar 2024 13:54:20 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id b18-20020a170903229200b001e0b5eee802sm3164487plh.123.2024.03.25.13.54.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 13:54:19 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Bruce Richardson Subject: [PATCH v12 04/14] eal: do not duplicate rte_init_alert() messages Date: Mon, 25 Mar 2024 13:47:01 -0700 Message-ID: <20240325205405.669897-5-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240325205405.669897-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240325205405.669897-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 Mon Mar 25 20:47: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: 138775 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 B361243D49; Mon, 25 Mar 2024 21:54:52 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2E84840E01; Mon, 25 Mar 2024 21:54:26 +0100 (CET) Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by mails.dpdk.org (Postfix) with ESMTP id 088F940DC9 for ; Mon, 25 Mar 2024 21:54:22 +0100 (CET) Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1de0f92e649so33573235ad.0 for ; Mon, 25 Mar 2024 13:54:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711400061; x=1712004861; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=w0CHwUH99LTRr59BzckESo/nF08qFhhomDRK57rezcs=; b=YrntsEdpEVyL47oWwHuqFl6TxCojmU46YHLV/zgnqOCBJT+fvw6cRYnGJ+0pfo60Ir FaEqqx8GIV6dPCNqph7c0Rau9iE2W6As06rGK65uR3Vl/0eAvN9tEADs2kHGniVxLSCc lAYxk1tz2HBYsDD2XS+MxMg9oBAi7GOj3m2SwA0ltmD0YeLpF9XV0S85NxGS5sP+UNHz WbYZyYBTdFcaZSbGG6lljZHoXpShVrxjhIEV4msT4vfFAfUovXnd4Dtji2B70mxxExL8 PF7l/TWCbBClHuppDR+VOrC+2NNtnxs2oDNzDJ92iZfjGZErXzzg/ga63Rdz85ai860f PkIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711400061; x=1712004861; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=w0CHwUH99LTRr59BzckESo/nF08qFhhomDRK57rezcs=; b=lS+KvMxd5fZ+xPMvknVQh4OOf60EGE4vQiHWdVRWp/No48EhmE6Ng+G/iKx4FoSyYc omPYpauIckzwUCmilORSx6Ic2BCsqSnK0lO9FcN+Co9J3y+zHdwXw0E6YdzOXk5R6nE8 ShTi42QVu/DqGAfwoSXFGtYy0PfSyJXl58yJem1MVHPeOQ3TQr1l/UuJGZ25EWmZEmYd QxJxss+aNyNXbmLI3y100YdAyqbXbnrWVb1dUi0F8FyHAPN3YBkW8Ayj+vk+91SZtEdD bp8+5O0ii0m6b0vvV3fH73i0hbaoCfGY5epDbSOJn6SSodOfxC5UT/KTzqi88i9Aasv5 NAdA== X-Gm-Message-State: AOJu0YyQQdNuU8un+UE7O34GPh26dtBJa4WCZnW/3LkqV4lXGalcLxo8 57Yr5iIW6HxdiWECgNSnhLLSSGigCZhvXN+uMLe//zr2v6LpPR33NDTdUyZx4/aak+9/KZO4QLA l X-Google-Smtp-Source: AGHT+IEeL9pZhpam8vOao1u0mYWfDq0I9aAiKtGdnXaSVs8ACq0nSZwTblQeh00purQzr4CLzjR15w== X-Received: by 2002:a17:902:7208:b0:1e0:b1a7:473e with SMTP id ba8-20020a170902720800b001e0b1a7473emr776969plb.67.1711400061104; Mon, 25 Mar 2024 13:54:21 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id b18-20020a170903229200b001e0b5eee802sm3164487plh.123.2024.03.25.13.54.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 13:54:20 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v12 05/14] eal: change rte_exit() output to match rte_log() Date: Mon, 25 Mar 2024 13:47:02 -0700 Message-ID: <20240325205405.669897-6-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240325205405.669897-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240325205405.669897-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The rte_exit() output format confuses the timestamp and coloring options. Change it to use be a single line with proper prefix. Before: [ 0.006481] EAL: Error - exiting with code: 1 Cause: [ 0.006489] Cannot init EAL: Permission denied After: [ 0.006238] EAL: Error - exiting with code: 1 [ 0.006250] EAL: Cause - Cannot init EAL: Permission denied Signed-off-by: Stephen Hemminger Acked-by: Tyler Retzlaff --- lib/eal/common/eal_common_debug.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/eal/common/eal_common_debug.c b/lib/eal/common/eal_common_debug.c index 3e77995896..3f37879144 100644 --- a/lib/eal/common/eal_common_debug.c +++ b/lib/eal/common/eal_common_debug.c @@ -34,17 +34,18 @@ void rte_exit(int exit_code, const char *format, ...) { va_list ap; + char *msg = NULL; if (exit_code != 0) - RTE_LOG(CRIT, EAL, "Error - exiting with code: %d\n" - " Cause: ", exit_code); + EAL_LOG(CRIT, "Error - exiting with code: %d", exit_code); va_start(ap, format); - rte_vlog(RTE_LOG_CRIT, RTE_LOGTYPE_EAL, format, ap); + vasprintf(&msg, format, ap); va_end(ap); + rte_log(RTE_LOG_CRIT, RTE_LOGTYPE_EAL, "EAL: Cause - %s", msg); + if (rte_eal_cleanup() != 0 && rte_errno != EALREADY) - EAL_LOG(CRIT, - "EAL could not release all resources"); + EAL_LOG(CRIT, "EAL could not release all resources"); exit(exit_code); } From patchwork Mon Mar 25 20:47: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: 138776 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 6054743D49; Mon, 25 Mar 2024 21:54:59 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9373240A73; Mon, 25 Mar 2024 21:54:27 +0100 (CET) Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by mails.dpdk.org (Postfix) with ESMTP id 3DBF740DCB for ; Mon, 25 Mar 2024 21:54:23 +0100 (CET) Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-6ea7f2d093aso3069653b3a.3 for ; Mon, 25 Mar 2024 13:54:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711400062; x=1712004862; 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=DeAU4M/YeQznJhJq3jNwWtcCvcERqzx/MKiT+j/lktm0nP8pzeX2oO42Pq+4oZd+To /WbKYHHQ3DnPKEb5BLeYbQQfZIXAl5EDC1+iPDTfPnUcCyMuOPCaROjj1x+qUND147Cl if7T3QOLOalW66QHP/kjeIxFCigaNjkyRaobqFwFqffZXkIPZjM+kr8eFFNNmjqbfncy jcX5GfUmLQB7MFdm8q/cM4ad9jMNC73fRrWIkDWk8CK/LOP7XmflRanr2rPG/cTRJsPp OeFsJTAJGu3juoaqILQgCqqrIfE7eyaM3ozE4CRCwZHk3Kw+g4sfzqaLfkTGcmzOdmFN 6zrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711400062; x=1712004862; 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=dXANRRWcJ77u88vC9KKagUFzG5JzX2E+irZn+jvYXGv4zGPzLS2rP5VU8YUictE7ij XHHyZMOHxxrQxQzwfTI//sxUqndJkAG8X8qMcDJl2FVZn5vU3tlBRmmsG1inRKjdysVz Y9lGDCD47rUidErWm3ZfrCI+r+4Kqe1Yae6MuI1m89SMRmuHBWfkYC5ud2IrrKcxtGR2 GIgnofLweOnwACYtfqbB34Z+AO3VhMBH8IZLHlPfzKypV1v3VYYmmQNUrlmHTzN8Smor fpACNcjPU2wXHs39CMaz+BIu7+9hzMVSwo6ta5xBQMNTX/9N/n+14LUL4pXu4YxqAlDC vvLA== X-Gm-Message-State: AOJu0YytQGAyq9ZyTwGrNI3dFvL29lnE3yVmSUtlnvPOlCB9x7dCvgcd XCuduhmcHrAojTA+ZvGeEmkosg3NpP9MEFKXlsI4k/6LcNAbW6Kml2gFEXZEH6FvVtDa4bc/cPt / X-Google-Smtp-Source: AGHT+IE6A3UUH/MZQxHDzECn4M4uQU8lyPcYTXdYNqB7zB8ozbgMzs6lqGgnoHCEVlNwlKqjiGkt1w== X-Received: by 2002:a05:6a21:7898:b0:1a3:5299:1641 with SMTP id bf24-20020a056a21789800b001a352991641mr8671941pzc.0.1711400062423; Mon, 25 Mar 2024 13:54:22 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id b18-20020a170903229200b001e0b5eee802sm3164487plh.123.2024.03.25.13.54.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 13:54:21 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Bruce Richardson , Dmitry Kozlyuk , Tyler Retzlaff , Pallavi Kadam Subject: [PATCH v12 06/14] log: move handling of syslog facility out of eal Date: Mon, 25 Mar 2024 13:47:03 -0700 Message-ID: <20240325205405.669897-7-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240325205405.669897-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240325205405.669897-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 Mon Mar 25 20:47: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: 138777 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 4E06543D49; Mon, 25 Mar 2024 21:55:05 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DE06C40E54; Mon, 25 Mar 2024 21:54:28 +0100 (CET) Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by mails.dpdk.org (Postfix) with ESMTP id 6E8EE40DCE for ; Mon, 25 Mar 2024 21:54:24 +0100 (CET) Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-6e6b5432439so3671062b3a.1 for ; Mon, 25 Mar 2024 13:54:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711400063; x=1712004863; 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=yt8sOxcACKjNMF6qKstsLWVdnhI7Desd0hXEpONxCMs=; b=p9L7cQ4KHCz/qJX+Y7DHKyrUTFU3tmS9RpV3ii8DrpEFR6MD8Em/v1E/V6klAOx+vr s/h27YPkVjOflJzhcxBS3xMO10m98RiawS1iQbDeJEHECv8y3bphKF+Nhj8VsUXF/Xz2 CfgYl5HVysPGBuw3ea+809OIkZUzae81lD4Pj4/0gkFlddSIAkAUxr6uJhw5dcWPO/tY YTJmJKQwckU6Y8Erm2J6DDpwWJYnehpS1bipqXmOFTQZacnUTKKSin1jIWyrg17Spi7e cAwn1JpigpWMQvUCVH15s7I0cM2ae7xvXIBs6sKY9XT+jDGGno5nHluJl/UmHJMMn7jZ S+5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711400063; x=1712004863; 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=yt8sOxcACKjNMF6qKstsLWVdnhI7Desd0hXEpONxCMs=; b=knFSzPoBh9599yUCvq77n6YgsFFygo9N5oYYIdc9Ds18n5bdbIGYj/PHxBTy7gyPRj JOG45U4dhgBSTk3I092XVV3ZqxVvNe3n28h7Ym/zAb6N2WJGTLOPD/NI9bQwD0iiO344 YsMIS8Wmymt3nx041vLYr3EGIE4Jh4NTrSjcDtyftmZP4bSKzo5RcwNmUze52znARjH/ wh39+hK+g/bPpPNCkP5tkFcQy5wrjSYqNQ0+osBAJcaUZRmSrlGHGUG41nNjuLumuiv/ f3CFZc99di39z6/Egn7uOAbW3qoF2XfujHmdX/F6eL5Uy9A8e+1KXK1E5psrbRESEW3d C3Yw== X-Gm-Message-State: AOJu0YwlquUcZq+pDji3ACXjmtQVwD59DFgo+CtLZgJkdaZHtIhgr8j9 P/6I91VglSKO75p7fz0XKnn6MMBCqZPFqGLxoyRBlGHhWvh5+CY1bhfOiSb9qixJAUypPgCr0ik O X-Google-Smtp-Source: AGHT+IEflYCd1XUvMf1BGOFNRROkOB/RJcJzohkUpsrOpVYX2SuTMgPhUq3i8q8cggS1uxI4dGUI2w== X-Received: by 2002:a05:6a20:6399:b0:1a3:5a55:bfd9 with SMTP id m25-20020a056a20639900b001a35a55bfd9mr6197218pzg.21.1711400063655; Mon, 25 Mar 2024 13:54:23 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id b18-20020a170903229200b001e0b5eee802sm3164487plh.123.2024.03.25.13.54.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 13:54:22 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Bruce Richardson , Dmitry Kozlyuk , Tyler Retzlaff , Pallavi Kadam Subject: [PATCH v12 07/14] eal: initialize log before everything else Date: Mon, 25 Mar 2024 13:47:04 -0700 Message-ID: <20240325205405.669897-8-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240325205405.669897-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240325205405.669897-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 | 8 +++++--- lib/eal/linux/eal.c | 15 +++++---------- lib/eal/windows/eal.c | 3 +-- 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, 20 insertions(+), 29 deletions(-) diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index 6552f9c138..ec3a0c3244 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,10 @@ rte_eal_init(int argc, char **argv) bool has_phys_addr; enum rte_iova_mode iova_mode; + /* setup log as early as possible */ + eal_log_level_parse(argc, argv); + eal_log_init(getprogname()); + /* checks if the machine is adequate */ if (!rte_cpu_is_supported()) { rte_eal_init_alert("unsupported cpu type."); @@ -565,9 +570,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..0a488ee567 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -936,6 +936,11 @@ rte_eal_init(int argc, char **argv) struct internal_config *internal_conf = eal_get_internal_configuration(); + + /* setup log as early as possible */ + eal_log_level_parse(argc, argv); + 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 +957,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 +1108,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..fb2920e1b8 100644 --- a/lib/eal/windows/eal.c +++ b/lib/eal/windows/eal.c @@ -250,9 +250,8 @@ 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); - 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 Mon Mar 25 20:47:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138778 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 61AF743D49; Mon, 25 Mar 2024 21:55:13 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B393F40E8A; Mon, 25 Mar 2024 21:54:30 +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 AC80A40DDC for ; Mon, 25 Mar 2024 21:54:25 +0100 (CET) Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1dddbe47ac1so36493175ad.1 for ; Mon, 25 Mar 2024 13:54:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711400065; x=1712004865; 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=sfqDNKmQuWc9wk5d/DN3Cspo6vZ086ka94ZuCH1RNvE=; b=T4gZYzQ/bSo0Mt34pudbbNYob0lWigL5Fx1RuyA+VxvCBqqXheSmfDZKVeWzB+S0on b3OBk2YbwRdkbNQ3+6Mw8NADHqpldajNy7gX3uuUxypg78kpkNwL/OaUC3bkVZvx16j4 gmNjZIVE/wP7YVp62Uzlsrp++ZDicq0/+SXw3agEDsRUKE2XW/n0+jIhwty3rAHFZ5Af xTv3z2AXMvjvKEYvtUvksLXgFQeaYaizEyZ01xPjJ31GabZh3sDhUJsqmLXI3iDzz+yC sofsKlj9gpSoGD7y2MeraL2j2FfwHqeDJOXm6eBSRIiciyFozxoFAl2qWSBRCRiO5cbg WKQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711400065; x=1712004865; 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=sfqDNKmQuWc9wk5d/DN3Cspo6vZ086ka94ZuCH1RNvE=; b=Sd4AFIQAPdjT+fAr8NWe6U/jGy0I9dvsv/KPZjAJ2fDhq8M3j+DihiUOO1RAJ342bQ UoV6JY46yVNMGwfU+6kzPu/al2DqLp8Z5LR+lJstsH2jt9ZLD96uU/ctA54OfjWZH169 J+WSua3xoqgS6azmgRFDpT0M0jquRVx6GNQ+6vkjZFPp3k17QjOwP6OKJJaxW6fbCEFC buqnJgUnRSb3NQI9xl5At0i8dj6yciL9Cfp4OEk+g+goVkMMTz6wT/76QC+zslVWnXz3 ThQn+HoaA6DdCGoKt/bYBasxF5tL8p9EH6We8rIEDpSf+nULSDXqK9b5hf5YMU/Bdz2o 5HaQ== X-Gm-Message-State: AOJu0Yxvz07Au/oE2daS0L/53OrK/9UFLWODq9cV/Ysk386anrbo4KQY LKNs8ZDcZE1i84Fyt1Fc2kAChW7gaA4RBoAJ8adG5RnMHNFmtyQeDC1UTcqVMAYLV9Q3rwyVN6I N X-Google-Smtp-Source: AGHT+IFQ63kLuy1rJMpmnMDjNoEr8fSHrX2qBbGLTzqcCKektkzGXDGlnjFA1P/2RLNATfIZAYWEnA== X-Received: by 2002:a17:902:d507:b0:1e0:dc6e:45ed with SMTP id b7-20020a170902d50700b001e0dc6e45edmr2042964plg.15.1711400064792; Mon, 25 Mar 2024 13:54:24 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id b18-20020a170903229200b001e0b5eee802sm3164487plh.123.2024.03.25.13.54.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 13:54:24 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v12 08/14] log: drop syslog support, and make code common Date: Mon, 25 Mar 2024 13:47:05 -0700 Message-ID: <20240325205405.669897-9-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240325205405.669897-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240325205405.669897-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 --- 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 - 6 files changed, 21 insertions(+), 144 deletions(-) delete mode 100644 lib/log/log_linux.c delete mode 100644 lib/log/log_windows.c 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 Mon Mar 25 20:47: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: 138779 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 43F3043D49; Mon, 25 Mar 2024 21:55:19 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E756B40EAB; Mon, 25 Mar 2024 21:54:31 +0100 (CET) Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by mails.dpdk.org (Postfix) with ESMTP id 90E8540E0F for ; Mon, 25 Mar 2024 21:54:26 +0100 (CET) Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1e0d6356ce9so6469865ad.3 for ; Mon, 25 Mar 2024 13:54:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711400066; x=1712004866; 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=U3Pm2jWPA8CvWVzSCbpUHJ5X5gWKk93CeDmKEZa2qf2WGzpLw9U2C+aKdtH4As9pQ0 NnlRROzopdzrat3lSGt8RRHozRgv8e8eoB1rNb5p/a+qB7If3JIqr81rz0zXX8iKQO1a Vz5N9We6iQDCGiFS7007RFGcQc/ascpI+CfbIcmplXj9XIEmsxd3YVwtC+yxeW2qFimw U9u5/H/b/qdFBGIG+V9ErbRWU4kSYbKgPfWlCz3QFlm82tZqhDbPhS//sJP2+Pa7fG2P RIT9E9APSiE0qtVQG7Pb/xv7wy20rqHdlRY86QZYGFAmcbL+cRAVOdYgF8qk1eZHKVPd anSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711400066; x=1712004866; 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=Ql56zAVTEj4nPrcpFm+8Pjl3fJk8Ujt8VocUmkLiQaPoJlQD75KB6cG4h0+R0/L3yg m/K3rfUoM9tox7pxxnuAITgaw1/TRTgEHKuFVR6GyhzY7HFbPxVct5OUKhEkVZS6S2N8 NZ9y2GfFT4MZovkxh0/8wk3TQ8vepYP7jeDCuZDDLECSePRlpdY1sWdTLPREMUZX5bBI Oa3hYaQC51zlZckAyNDJqwn1RpmmXsSJHyy9GICxPjj5gsQ/nAYCnengL3v3Cyy5q4jg r36U2tnJkBKjuEnd9fieTwks9jr614elVcJPT5klzvDdaPzMvI4MtapQ1OUF4ffdLKD4 whRg== X-Gm-Message-State: AOJu0YzH9P2HyxYENR1nX2G7Zf9AQFJrsuTulidgQio2Jsp5sRH9voEG wXSmFeGosA9B+A7yhpag2GY/dCg6RyDH3PXndAYCGxvCEKtJ4H5hQ6zWLAN7OnU59XgmsjCw9Sv U X-Google-Smtp-Source: AGHT+IEzhQllpPHYQWlKQvYb+SaxR9fB1T0nyUgfj4k3GAzY9wjEDIGU8/Qo9R76RUoJ01l8pc5HJw== X-Received: by 2002:a17:903:41c8:b0:1e0:c88f:654b with SMTP id u8-20020a17090341c800b001e0c88f654bmr3149091ple.25.1711400065835; Mon, 25 Mar 2024 13:54:25 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id b18-20020a170903229200b001e0b5eee802sm3164487plh.123.2024.03.25.13.54.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 13:54:25 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v12 09/14] log: add hook for printing log messages Date: Mon, 25 Mar 2024 13:47:06 -0700 Message-ID: <20240325205405.669897-10-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240325205405.669897-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240325205405.669897-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 Mon Mar 25 20:47:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138780 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 D2D0843D49; Mon, 25 Mar 2024 21:55:24 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1E2E340ED2; Mon, 25 Mar 2024 21:54:33 +0100 (CET) Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) by mails.dpdk.org (Postfix) with ESMTP id CCB7840E36 for ; Mon, 25 Mar 2024 21:54:27 +0100 (CET) Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1e0025ef1efso29324455ad.1 for ; Mon, 25 Mar 2024 13:54:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711400067; x=1712004867; 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=y0Cx39rmyk4zYo+MPMPIbi0zGI57clzMGNz8uR1x5xA=; b=l98B5dMaj7RQxSvq/sLC4uHAOeLOzTo2dHVRpaFU19qDoPmbfOc1nhChGPUxoqcqTP 4modLuArFr0KYp8dfkxkj8wLMTqvP86FNcdqOdQZzu1XVLwuo7959Fnp11wSB1CvaxEb Oh/4FWriP1vf9DW8dYJOiEQClzQkjZvYVGZb6/Pd6B1LHA2xnxwb4tLCOnt/37GAQY5n WF8d2qRS+C0yR/AL0oRpJExCCHjjR3qSBq5M5adL2YWGFceEEzGgAX7SkSbyi/scU720 bQbizyVWKXHcP/QbeOHQ0VtKa+KVU6MkJf/uSyFMpXQFiGgac/tH/ePx7krw4J6A1lsP ci1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711400067; x=1712004867; 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=y0Cx39rmyk4zYo+MPMPIbi0zGI57clzMGNz8uR1x5xA=; b=q4k7iRqopaohBTR+ZSxma1Jbxvx78lGt4WyUdFQZZcyZPG8+0wQPzgr/AJSfR4g7Dy FMrKUJcWJe8k9nUDncDPnSuH0e6KOT5Tq7lYXp3OTG224jGqWREe3Z+YyjatpGss3G/P RzdSh5kblZRK0MprwBQi39x+UzvU69cfCshu89Ms0ORV9dHvKcXkl2htGs8LI8YVDLAA xutYWOrx1pJiK4JUYfAVXaJ/dO6YhPAulzGJfjE6H838PAEzp2GWGIUVso9pD3A6yr/V MwL10gYEXb6dPozN5uuZPrlzZp8FM3sk49GXBsIsO3r7KuJO7iX6I72dP+X+VMENg4U3 8Mag== X-Gm-Message-State: AOJu0YzKculQfbZCOFp+qbfN95SczdZBTkf8EKuuuA79uwHlU4VE6def imMUxPdn5ppC5e99zAO+vGvjplt0c2HMDVDyvPl57xoKR1BlNjSsDNMUUmUdtPoqrhtWBTYOZvN D X-Google-Smtp-Source: AGHT+IHEO3+zk3PIUyx9WEPP8DEOcc8XmVfYuZAFHtsAvWVezWKjBC1Sv0fKIT7fSSzI67YIFrQJuA== X-Received: by 2002:a17:903:234b:b0:1e0:e2c3:41af with SMTP id c11-20020a170903234b00b001e0e2c341afmr1013130plh.61.1711400066907; Mon, 25 Mar 2024 13:54:26 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id b18-20020a170903229200b001e0b5eee802sm3164487plh.123.2024.03.25.13.54.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 13:54:26 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Bruce Richardson , Dmitry Kozlyuk , Tyler Retzlaff , Pallavi Kadam Subject: [PATCH v12 10/14] log: add timestamp option Date: Mon, 25 Mar 2024 13:47:07 -0700 Message-ID: <20240325205405.669897-11-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240325205405.669897-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240325205405.669897-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org When debugging driver or startup issues, it is useful to have a timestamp on each message printed. The messages in syslog already have a timestamp, but often syslog is not available during testing. There are multiple timestamp formats similar to Linux dmesg. The default is time relative since startup (when first step of logging initialization is done by constructor). Other alternative formats are delta, ctime, reltime and iso formats. Example: $ dpdk-testpmd --log-timestamp -- -i [ 0.008610] EAL: Detected CPU lcores: 8 [ 0.008634] EAL: Detected NUMA nodes: 1 [ 0.008792] EAL: Detected static linkage of DPDK [ 0.010620] EAL: Multi-process socket /var/run/dpdk/rte/mp_socket [ 0.012618] EAL: Selected IOVA mode 'VA' [ 0.016675] testpmd: No probed ethernet devices Interactive-mode selected Signed-off-by: Stephen Hemminger --- app/test/test_eal_flags.c | 17 +++ doc/guides/prog_guide/log_lib.rst | 26 ++++ lib/eal/common/eal_common_options.c | 14 ++- lib/eal/common/eal_options.h | 2 + lib/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, 259 insertions(+), 7 deletions(-) diff --git a/app/test/test_eal_flags.c b/app/test/test_eal_flags.c index 6cb4b06757..eeb1799381 100644 --- a/app/test/test_eal_flags.c +++ b/app/test/test_eal_flags.c @@ -1055,6 +1055,14 @@ test_misc_flags(void) const char * const argv22[] = {prgname, prefix, mp_flag, "--huge-worker-stack=512"}; + /* Try running with --log-timestamp */ + const char * const argv23[] = {prgname, prefix, mp_flag, + "--log-timestamp" }; + + /* Try running with --log-timestamp=iso */ + const char * const argv24[] = {prgname, prefix, mp_flag, + "--log-timestamp=iso" }; + /* run all tests also applicable to FreeBSD first */ if (launch_proc(argv0) == 0) { @@ -1162,6 +1170,15 @@ test_misc_flags(void) printf("Error - process did not run ok with --huge-worker-stack=size parameter\n"); goto fail; } + if (launch_proc(argv23) != 0) { + printf("Error - process did not run ok with --log-timestamp parameter\n"); + goto fail; + } + if (launch_proc(argv24) != 0) { + printf("Error - process did not run ok with --log-timestamp=iso parameter\n"); + goto fail; + } + rmdir(hugepath_dir3); rmdir(hugepath_dir2); diff --git a/doc/guides/prog_guide/log_lib.rst b/doc/guides/prog_guide/log_lib.rst index 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 661b2db211..aa1faad45c 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: { @@ -2219,6 +2228,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 ec3a0c3244..8f41c47f47 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 0a488ee567..16aaefe355 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 fb2920e1b8..bff1316e0b 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 Mon Mar 25 20:47:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138781 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 62E1A43D49; Mon, 25 Mar 2024 21:55:31 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 29D7D40EDB; Mon, 25 Mar 2024 21:54:34 +0100 (CET) Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by mails.dpdk.org (Postfix) with ESMTP id 9D41D40E36 for ; Mon, 25 Mar 2024 21:54:28 +0100 (CET) Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1e0d82c529fso5676955ad.2 for ; Mon, 25 Mar 2024 13:54:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711400068; x=1712004868; 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=BzCso9sKu6dCrjxH8A6EQo0nwJbP6WzCWG5/oETewgQ=; b=ZnfbW7hNVNsxdhVztvhGeX95AmCAu4RGNr/PbVX4a5YX1Od6vBznqshdclOnPoPcfh xBMzICjQ5lnYa0bpfCLTnM1GV9n40NAYLW7BGsNOl+45nYDCV6FVwEqy8auE3K9qhxrs QTUBHWh6ToZI/+WQIneegw4l1CTODJrKcrRcwUM0lZRANyTaKPPk3aE575oBjJN1gSs8 s79LyHGicbZnqzChyAaRonQsNKVYMAdHAfcuyFzieTllts2xkMVQo70W/i3pRGnsAUvg NV68HThmW5A3nnGltEtKtnI9UlR1tFx9xpmxe3fKD4Vh0jMmbi72ljq5YkXGQrx2f6lc CLlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711400068; x=1712004868; 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=BzCso9sKu6dCrjxH8A6EQo0nwJbP6WzCWG5/oETewgQ=; b=RA7nLY/z9+hQ+LChDP1W+2sS8gIy4HQfxpl3u4NjWtHVLKO53WbGTQR0qCNgLkP9rQ cs0aTLzVHubk+2JPFTVTL9q/P8A8FbRRF3YQujyEZfQQ0d2w0qIWNp6sCuygAX1qerLs /74S1zmSM4dsp1NHVqPzJp+LNdwLn9hb0GMh8wqZRGaUM92wb/uyVDG7iUD77sAtFevY kPDcY2ltfRwN1tpVyfNmO44N8dxk5U5O/g8I8Mh8EvNyAuhK+tLfy8wLPIU+qIywbEYn MDQznuzuV7Xfq+aAtUb+QEBYIKCzoa5LhMKjj5gVGnWQ4o1KlTG3X8OxSvMVlsc7tKnV Kb4g== X-Gm-Message-State: AOJu0YxFyrv9uIWcbw198MmzzWyO2AmNRyAIRWpaqORhQB7GXjU30Mi6 BpWO4DCekhd4wsLuv9quAZo3dtc+g7oB3L5zYPnkNiVgRYEc+BVU3SyeJ1zms51Wle3RBFgQ3QZ D X-Google-Smtp-Source: AGHT+IGU1NoqUXTfuqcSERumdWI47EVx+YEnr9woZqwfXZHt5gb5dGKdHn+tnvMM7FP8ImXVSsf/+w== X-Received: by 2002:a17:902:ea05:b0:1e0:a7c2:af8f with SMTP id s5-20020a170902ea0500b001e0a7c2af8fmr7633604plg.5.1711400067717; Mon, 25 Mar 2024 13:54:27 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id b18-20020a170903229200b001e0b5eee802sm3164487plh.123.2024.03.25.13.54.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 13:54:27 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v12 11/14] log: add optional support of syslog Date: Mon, 25 Mar 2024 13:47:08 -0700 Message-ID: <20240325205405.669897-12-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240325205405.669897-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240325205405.669897-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 --- 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 ++++++++++++++++-- 4 files changed, 111 insertions(+), 36 deletions(-) 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 aa1faad45c..6f0fd151c1 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"); From patchwork Mon Mar 25 20:47:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138782 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 C89D243D49; Mon, 25 Mar 2024 21:55:39 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 90156410D0; Mon, 25 Mar 2024 21:54:35 +0100 (CET) Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by mails.dpdk.org (Postfix) with ESMTP id 718E640DDE for ; Mon, 25 Mar 2024 21:54:29 +0100 (CET) Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1e0d82c529fso5677215ad.2 for ; Mon, 25 Mar 2024 13:54:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711400068; x=1712004868; 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=d/UE9ipVPe9mD7+Cgp8jISoE1qnPb3z27iLpF4O0SEQ=; b=3UGI00PJsmcndQHI1xYJRawSNRvOc9vgLc38sOAyCC7MV6bPm1BhtUyP4FJ2guZvbk e53i+0BSdIvPFzZcmk/y4LEgMevL6AbxzZ7khUozkpi0en4BxpJ7zB50I6qAsbAxRlO9 umptKT2OdSvnuusHCuRYlGbIcRk0en/u1mQiOoe/LnZH2WMRPAlP8CvBaFVx2+AShuMd zsxELhy7QvmrG7xJLiwM7Usf/AD/x49S0Dg3HUoWtpG79KVUycCIvO+hPexmB+SuZ9OF GeLVUJ4p+kGwIZhvs6Dk/OEBXmOuUVv1M6AjJzPXnd5KLI+v/ynZevtdg9s0vujdT5dD z2Vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711400068; x=1712004868; 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=d/UE9ipVPe9mD7+Cgp8jISoE1qnPb3z27iLpF4O0SEQ=; b=dUDzi54aoMKucVc0l4q664rriLc4RWi4ppAf6M252M1VA1teQJs63qwTIjAjCGuTMW 6mWJGSrooPBHGJvbLia4duSJL1RULDHNiYObUBBphlPAEF7NGbJL/Bu3Np1gylqPAz0Y NvkPRUFYyifDPU97QaA6uR9g8q3yvacdJ7EJ8cpfze3RFIkGA+UfDFO1GpR6yGMaW85l nvmXKmLDbC2bAKdRUW7YHJZaVCreAyuOnLTPbq4IJKhmQJfuSMz7UGYWv6Q7YnfxkfRv IaCssO6wR78chAIqU9DS2ADCMHyOoVTdbHr545OYFehThYYglbUMDclOXUpQE+XZp6EL Q90A== X-Gm-Message-State: AOJu0YwVVq4KuKJCIRuKptm7GV2T7WIMjs8aP6f8MB+DgiJOR33v6O76 Kgt0UTe07TzlnP7FrgnsrMr2uLmT4QCTvyp5AOiff/7s2rKU0ZIIYy0P++wYTsKo5ZPQGlMGwYp w X-Google-Smtp-Source: AGHT+IHphrNR34HwvHP4H5FbYwTt4xi23qv1e20oBqRi7iho0zwL6TYhZP2M3On29ml7TgUaWxmP1A== X-Received: by 2002:a17:902:e80d:b0:1e0:afa0:d515 with SMTP id u13-20020a170902e80d00b001e0afa0d515mr5797214plg.29.1711400068632; Mon, 25 Mar 2024 13:54:28 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id b18-20020a170903229200b001e0b5eee802sm3164487plh.123.2024.03.25.13.54.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 13:54:28 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v12 12/14] log: add support for systemd journal Date: Mon, 25 Mar 2024 13:47:09 -0700 Message-ID: <20240325205405.669897-13-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240325205405.669897-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240325205405.669897-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org If DPDK application is being run as a systemd service, then it can use the journal protocol which allows putting more information in the log such as priority and other information. The use of journal protocol is automatically detected and handled. Rather than having a dependency on libsystemd, just use the protocol directly as defined in: https://systemd.io/JOURNAL_NATIVE_PROTOCOL/ Signed-off-by: Stephen Hemminger --- lib/log/log.c | 128 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 126 insertions(+), 2 deletions(-) diff --git a/lib/log/log.c b/lib/log/log.c index d8974c66db..0f7bdb3f25 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -17,6 +17,10 @@ #include #else #include +#include +#include +#include +#include #endif #include @@ -56,6 +60,7 @@ static struct rte_logs { FILE *file; /**< Output file set by rte_openlog_stream, or NULL. */ #ifndef RTE_EXEC_ENV_WINDOWS enum eal_log_syslog syslog_opt; + int journal_fd; #endif log_print_t print_func; @@ -758,6 +763,112 @@ static cookie_io_functions_t syslog_log_func = { .write = syslog_log_write, .close = syslog_log_close, }; + + +/* + * send message using journal protocol to journald + */ +__rte_format_printf(3, 0) +static int +journal_print(FILE *f __rte_unused, uint32_t level, const char *format, va_list ap) +{ + struct iovec iov[3]; + char *buf = NULL; + size_t len; + char msg[] = "MESSAGE="; + char *prio; + + iov[0].iov_base = msg; + iov[0].iov_len = strlen(msg); + + len = vasprintf(&buf, format, ap); + if (len == 0) + return 0; + + /* check that message ends with newline, if not add one */ + if (buf[len - 1] != '\n') { + char *clone = alloca(len + 1); + if (clone == NULL) + return 0; + memcpy(clone, buf, len); + clone[len++] = '\n'; + buf = clone; + } + + iov[1].iov_base = buf; + iov[1].iov_len = len; + + /* priority value between 0 ("emerg") and 7 ("debug") */ + len = asprintf(&prio, "PRIORITY=%i\n", level - 1); + iov[2].iov_base = prio; + iov[2].iov_len = len; + + return writev(rte_logs.journal_fd, iov, 3); +} + +/* + * Check if stderr is going to system journal. + * This is the documented way to handle systemd journal + * + * See: https://systemd.io/JOURNAL_NATIVE_PROTOCOL/ + * + */ +static bool +using_journal(void) +{ + char *jenv, *endp = NULL; + struct stat st; + unsigned long dev, ino; + + jenv = getenv("JOURNAL_STREAM"); + if (jenv == NULL) + return false; + + if (fstat(STDERR_FILENO, &st) < 0) + return false; + + /* systemd sets colon-separated list of device and inode number */ + dev = strtoul(jenv, &endp, 10); + if (endp == NULL || *endp != ':') + return false; /* missing colon */ + + ino = strtoul(endp + 1, NULL, 10); + + return dev == st.st_dev && ino == st.st_ino; +} + +/* Connect to systemd's journal service */ +static int +open_journal(const char *id) +{ + char *syslog_id = NULL; + struct sockaddr_un sun = { + .sun_family = AF_UNIX, + .sun_path = "/run/systemd/journal/socket", + }; + ssize_t len; + int s; + + s = socket(AF_UNIX, SOCK_DGRAM, 0); + if (s < 0) + return -1; + + if (connect(s, (struct sockaddr *)&sun, sizeof(sun)) < 0) + goto error; + + /* Send syslog identifier as first message */ + len = asprintf(&syslog_id, "SYSLOG_IDENTIFIER=%s\n", id); + if (len == 0) + goto error; + + if (write(s, syslog_id, len) != len) + goto error; + + return s; +error: + close(s); + return -1; +} #endif @@ -765,11 +876,24 @@ static cookie_io_functions_t syslog_log_func = { static void log_output_selection(const char *id) { +#ifdef RTE_EXEC_ENV_WINDOWS RTE_SET_USED(id); - -#ifndef RTE_EXEC_ENV_WINDOWS +#else bool is_terminal = isatty(STDERR_FILENO); + /* If stderr is redirected to systemd journal then upgrade */ + if (using_journal()) { + int jfd = open_journal(id); + + if (jfd < 0) { + RTE_LOG_LINE(NOTICE, EAL, "Cannot connect to journal: %s", + strerror(errno)); + } else { + rte_logs.print_func = journal_print; + return; + } + } + 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; From patchwork Mon Mar 25 20:47:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138783 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 1525743D49; Mon, 25 Mar 2024 21:55:45 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B6DC9410E3; Mon, 25 Mar 2024 21:54:36 +0100 (CET) Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by mails.dpdk.org (Postfix) with ESMTP id 6435640E8A for ; Mon, 25 Mar 2024 21:54:30 +0100 (CET) Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1def59b537cso30429885ad.2 for ; Mon, 25 Mar 2024 13:54:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711400069; x=1712004869; 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=OOaaujGe+00hpSdaw3PAIH5SQJM8MJfQdAEByjbeKCo=; b=YojyvEaX9hrZA1x+vrL5WfF61Ls6E9W+WNMtUY3VELwisLvEuS2UhvfnI/oiyWdhMU ZqNhN9Gr4zZLGAiz7T1joeMMxSrhbr4ZGSVSCCAiMPGu8cs+P2FI6TTLTiM2lSs1c0jX CCs6NAzwedVKkOg7nNZrlbCCggT+xlz8a64MOZWUn7kzhTO4Z2QywagixlaPqcbplwrC CyVAFkP4RJxI3joDTIsEakx+E/EBc+KZJb5+t/Bt+x4na0R9xpxmhBmz9rHXIpU526hH Sef0Z1KjyzSscHG1x7h3HhjH0Wq7cHsPNPgv4X2FkzhW2AsDB9uvPEaz9Ts3xk+DugVx fY1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711400069; x=1712004869; 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=OOaaujGe+00hpSdaw3PAIH5SQJM8MJfQdAEByjbeKCo=; b=bs8E9UHy4s0I0LdG+xVHqj7zKOe+G/iQsvXti314eV6JHJb3UhwPeE5nFNxnbSVc+W qyvb1ZLoZfGQ4Hfgq/NUDqzv50Emxgoi1xm1ezPDDKtVuulohV+goTOiovadRVayXKkf PxoVy7lS1p3aXPg66Kcr3xI20km5lbFLQApDtewHTqG2nirq19KdhCrHPF541u7kPfiY tWhJyoYaubOygRJWoBjtGLFoEO4T6PAodXoMGnRxJ6LJok5in9zvD2tIuSvlagJFsVTG m6LR/HR2A77XU2VcmN0dstMjBuDZ05XVzRXiO5FDgcaKIeXtTs9w6v3VDv2G1R/K2RQr wiQA== X-Gm-Message-State: AOJu0YzcRgP5Coiokre6G64l5F9f2F5PYxzQ/3ucu+Eed5q4FsKglhmr ZN835MKlMUEM0APJ2ziPCTSPkUWdhZGMRj5IHGB76VsFRrrbUIOLkuRd/tUXhC14arPHyMnbCjs i X-Google-Smtp-Source: AGHT+IHjhaGck0/6Lk9bPD+wrZDyXpecevnjidmllq/KVDso0t+hzuWyWJ+lC7/wyKafaIWp1mw/ow== X-Received: by 2002:a17:903:2308:b0:1e0:b862:5330 with SMTP id d8-20020a170903230800b001e0b8625330mr4987349plh.54.1711400069492; Mon, 25 Mar 2024 13:54:29 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id b18-20020a170903229200b001e0b5eee802sm3164487plh.123.2024.03.25.13.54.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 13:54:29 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v12 13/14] log: colorize log output Date: Mon, 25 Mar 2024 13:47:10 -0700 Message-ID: <20240325205405.669897-14-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240325205405.669897-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240325205405.669897-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Like dmesg, colorize the log output (unless redirected to file). Timestamp is green, the subsystem is in yellow and the message is red if urgent, boldface if an error, and normal for info and debug messages. Signed-off-by: Stephen Hemminger --- doc/guides/prog_guide/log_lib.rst | 16 ++- lib/eal/common/eal_common_options.c | 1 + lib/eal/common/eal_options.h | 2 + lib/log/log.c | 158 +++++++++++++++++++++++++++- lib/log/log_internal.h | 5 + lib/log/version.map | 1 + 6 files changed, 178 insertions(+), 5 deletions(-) diff --git a/doc/guides/prog_guide/log_lib.rst b/doc/guides/prog_guide/log_lib.rst index abaedc7212..40727ebaae 100644 --- a/doc/guides/prog_guide/log_lib.rst +++ b/doc/guides/prog_guide/log_lib.rst @@ -59,6 +59,21 @@ For example:: Within an application, the same result can be got using the ``rte_log_set_level_pattern()`` or ``rte_log_set_level_regex()`` APIs. +Color output +~~~~~~~~~~~~ + +The log library will highlight important messages. +This is controlled by the ``--log-color`` option. +he optional argument ``when`` can be ``auto``, ``never``, or ``always``. +The default setting is ``auto`` which enables color when the output to +``stderr`` is a terminal. +If the ``when`` argument is omitted, it defaults to ``always``. + +For example to turn off all coloring:: + + /path/to/app --log-color=none + + Log timestamp ~~~~~~~~~~~~~ @@ -101,7 +116,6 @@ option. There are three possible settings for this option: 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 6f0fd151c1..23b536b7a0 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -75,6 +75,7 @@ eal_long_options[] = { {OPT_LCORES, 1, NULL, OPT_LCORES_NUM }, {OPT_LOG_LEVEL, 1, NULL, OPT_LOG_LEVEL_NUM }, {OPT_LOG_TIMESTAMP, 2, NULL, OPT_LOG_TIMESTAMP_NUM }, + {OPT_LOG_COLOR, 1, NULL, OPT_LOG_COLOR_NUM }, {OPT_TRACE, 1, NULL, OPT_TRACE_NUM }, {OPT_TRACE_DIR, 1, NULL, OPT_TRACE_DIR_NUM }, {OPT_TRACE_BUF_SIZE, 1, NULL, OPT_TRACE_BUF_SIZE_NUM }, diff --git a/lib/eal/common/eal_options.h b/lib/eal/common/eal_options.h index e24c9eca53..5a63c1dd3a 100644 --- a/lib/eal/common/eal_options.h +++ b/lib/eal/common/eal_options.h @@ -37,6 +37,8 @@ enum { OPT_LOG_LEVEL_NUM, #define OPT_LOG_TIMESTAMP "log-timestamp" OPT_LOG_TIMESTAMP_NUM, +#define OPT_LOG_COLOR "log-color" + OPT_LOG_COLOR_NUM, #define OPT_TRACE "trace" OPT_TRACE_NUM, #define OPT_TRACE_DIR "trace-dir" diff --git a/lib/log/log.c b/lib/log/log.c index 0f7bdb3f25..26a63024be 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -23,6 +23,7 @@ #include #endif +#include #include #include @@ -49,6 +50,12 @@ enum eal_log_syslog { EAL_LOG_SYSLOG_BOTH, /* log to both syslog and stderr */ }; +enum eal_log_color { + EAL_LOG_COLOR_AUTO = 0, /* default */ + EAL_LOG_COLOR_NEVER, + EAL_LOG_COLOR_ALWAYS, +}; + typedef int (*log_print_t)(FILE *f, uint32_t level, const char *fmt, va_list ap); static int log_print(FILE *f, uint32_t level, const char *format, va_list ap); @@ -64,6 +71,7 @@ static struct rte_logs { #endif log_print_t print_func; + enum eal_log_color color_mode; enum eal_log_time_format time_format; struct timespec started; /* when log was initialized */ struct timespec previous; /* when last msg was printed */ @@ -715,6 +723,74 @@ format_timestamp(char *tsbuf, size_t tsbuflen) return 0; } +enum color { + COLOR_NONE, + COLOR_RED, + COLOR_GREEN, + COLOR_YELLOW, + COLOR_BLUE, + COLOR_MAGENTA, + COLOR_CYAN, + COLOR_WHITE, + COLOR_BOLD, + COLOR_CLEAR +}; + +static const char * const color_code[] = { + [COLOR_NONE] = "", + [COLOR_RED] = "\e[31m", + [COLOR_GREEN] = "\e[32m", + [COLOR_YELLOW] = "\e[33m", + [COLOR_BLUE] = "\e[34m", + [COLOR_MAGENTA] = "\e[35m", + [COLOR_CYAN] = "\e[36m", + [COLOR_WHITE] = "\e[37m", + [COLOR_BOLD] = "\e[1m", + [COLOR_CLEAR] = "\e[0m", +}; + +__rte_format_printf(3, 4) +static int color_fprintf(FILE *out, enum color color, const char *fmt, ...) +{ + va_list args; + int ret = 0; + + va_start(args, fmt); + ret = fprintf(out, "%s", color_code[color]); + ret += vfprintf(out, fmt, args); + ret += fprintf(out, "%s", color_code[COLOR_CLEAR]); + + return ret; +} + +static ssize_t +color_log_write(FILE *f, int level, char *msg) +{ + char *cp; + ssize_t ret = 0; + + /* + * use convention that first part of message (up to the ':' character) + * is the subsystem id and should be highlighted. + */ + cp = strchr(msg, ':'); + if (cp) { + /* print first part in yellow */ + ret = color_fprintf(stderr, COLOR_YELLOW, "%.*s", + (int)(cp - msg + 1), msg); + msg = cp + 1; + } + + if (level <= 0 || level >= (int)RTE_LOG_INFO) + ret += fprintf(f, "%s", msg); + else if (level >= (int)RTE_LOG_ERR) + ret += color_fprintf(f, COLOR_BOLD, "%s", msg); + else + ret += color_fprintf(f, COLOR_RED, "%s", msg); + + return ret; +} + /* default log print function */ __rte_format_printf(3, 0) static int @@ -871,16 +947,79 @@ open_journal(const char *id) } #endif +__rte_format_printf(3, 0) +static int +color_print(FILE *f, uint32_t level, const char *format, va_list ap) +{ + char *buf = NULL; + + /* need to make temporary buffer for color scan */ + if (vasprintf(&buf, format, ap) > 0) + return color_log_write(f, level, buf); + + /* if vasprintf fails, print without color */ + return log_print(f, level, format, ap); +} + +__rte_format_printf(3, 0) +static int +color_print_with_timestamp(FILE *f, uint32_t level, + const char *format, va_list ap) +{ + char tsbuf[128]; + + if (format_timestamp(tsbuf, sizeof(tsbuf)) > 0) + color_fprintf(f, COLOR_GREEN, "[%s] ", tsbuf); + + return color_print(f, level, format, ap); +} + +/* + * Controls whether color is enabled: + * modes are: + * always - enable color output regardless + * auto - enable if stderr is a terminal + * never - color output is disabled. + */ +int +eal_log_color(const char *mode) +{ + if (mode == NULL || strcmp(mode, "always") == 0) + rte_logs.color_mode = EAL_LOG_COLOR_ALWAYS; + else if (strcmp(mode, "never") == 0) + rte_logs.color_mode = EAL_LOG_COLOR_NEVER; + else if (strcmp(mode, "auto") == 0) + rte_logs.color_mode = EAL_LOG_COLOR_AUTO; + else + return -1; + + return 0; +} + +static inline bool +use_color(bool is_terminal) +{ + switch (rte_logs.color_mode) { + default: + case EAL_LOG_COLOR_NEVER: + return false; + case EAL_LOG_COLOR_ALWAYS: + return true; + case EAL_LOG_COLOR_AUTO: + return is_terminal; + } + +} /* Choose how log output is directed */ static void log_output_selection(const char *id) { + bool is_terminal = isatty(STDERR_FILENO); + #ifdef RTE_EXEC_ENV_WINDOWS RTE_SET_USED(id); #else - bool is_terminal = isatty(STDERR_FILENO); - /* If stderr is redirected to systemd journal then upgrade */ if (using_journal()) { int jfd = open_journal(id); @@ -911,8 +1050,19 @@ log_output_selection(const char *id) return; } #endif - if (rte_logs.time_format != EAL_LOG_TIMESTAMP_NONE) - rte_logs.print_func = log_print_with_timestamp; + + if (use_color(is_terminal)) { + if (rte_logs.time_format == EAL_LOG_TIMESTAMP_NONE) + rte_logs.print_func = color_print; + else + rte_logs.print_func = color_print_with_timestamp; + } else { + if (rte_logs.time_format == EAL_LOG_TIMESTAMP_NONE) + rte_logs.print_func = log_print; + else + rte_logs.print_func = log_print_with_timestamp; + } + } /* diff --git a/lib/log/log_internal.h b/lib/log/log_internal.h index 7c7d44eed2..525e1397fd 100644 --- a/lib/log/log_internal.h +++ b/lib/log/log_internal.h @@ -47,5 +47,10 @@ void rte_eal_log_cleanup(void); __rte_internal int eal_log_timestamp(const char *fmt); +/* + * Enable or disable color in log messages + */ +__rte_internal +int eal_log_color(const char *mode); #endif /* LOG_INTERNAL_H */ diff --git a/lib/log/version.map b/lib/log/version.map index 14d6681a5f..7fa79b20ff 100644 --- a/lib/log/version.map +++ b/lib/log/version.map @@ -25,6 +25,7 @@ DPDK_24 { INTERNAL { global: + eal_log_color; eal_log_init; eal_log_level2str; eal_log_save_pattern; From patchwork Mon Mar 25 20:47:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138784 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 B3CFD43D49; Mon, 25 Mar 2024 21:55:50 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DDBEC410E8; Mon, 25 Mar 2024 21:54:37 +0100 (CET) Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) by mails.dpdk.org (Postfix) with ESMTP id 32B6B40EAB for ; Mon, 25 Mar 2024 21:54:31 +0100 (CET) Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1e04ac200a6so33570595ad.1 for ; Mon, 25 Mar 2024 13:54:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711400070; x=1712004870; 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=KoJ3CcF3Z+MyxXCt0A3RDjQi4Q1UcyXSa2DzdgV+UAM=; b=wLjoyXvqMQUXla39W3STfBeS6kD1o1inACkkFax6zHqLLrU0qm5DApGxI04pGMMLEK VgFuVkEZuIdsqOXrVtPtRsT06xD7GfdldZyFzBP2MWfyjpyGXSg/yYN7ZrVYbA9apD9p hmS9teCr4S76vpfvCyNs/4ZEEfRX5SiwiVmPkjEzazBMIogDoJCPdp+gzPKeJxLpgOVV pmqm+wXVWhyM21kCeN1OVa4NIHTQLFzoNfXNA64FWTWXZ7ZY4xI1VMUezT9wyj07hONZ Ct7SJaAFtBoIhNTgGI+hVDJ+av4CgGpE1ksUSsM7KQh8mdC3eMmQEwvIGzUc1PJ17CqB DAYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711400070; x=1712004870; 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=KoJ3CcF3Z+MyxXCt0A3RDjQi4Q1UcyXSa2DzdgV+UAM=; b=XOZmW15IREfb4tM/Tnts7R09EteqCHE6e6zTNwjmZHNCMwsObK67f3PN6TGNhGgMju 1B/gr9p72aFdvQ0KR3aCsCmwpHOIQHq8NomJFR2B5lHDV+lxIiXW58nPfDDXz15sbjMn dwxXHqhjlmmtGDYMv/dI8k/Uv80gLNHnGoHcyM0PF88OAwNJwfXvUuIjLa0gs94iDHA6 WsRsykrxhvWRyZslf0LQfVb2tDaqswnDZ7zmcGffsd6MxaF95JOffkt8KLwPCgGCAjZq fH24AHaCtow/jbPYmn2NXcJDUoi5CtRs7fEklgN8W7m04v50612uQkPHvyQsqC+N4NSV aIkQ== X-Gm-Message-State: AOJu0YyVWWrzQLZfGp5PtLQTkvTJl4x9JQbcv3UgYP1jMFGyTZBcFUuH Y9r6ZYJXEoVGHXUeE8eByV25mb3JIud0IE3xkvHU2HqfbhOpfsJPDlzlLxqzyZIlYnx6EE8wwf2 c X-Google-Smtp-Source: AGHT+IGm7KPw14HsAOlw4wPBIc7EVnp+cE9gz4iLTns87X8qeJO9b5Xi1lud/f2vwWJznGXhn6WtLQ== X-Received: by 2002:a17:902:ce82:b0:1e0:c0b9:589e with SMTP id f2-20020a170902ce8200b001e0c0b9589emr5774401plg.25.1711400070412; Mon, 25 Mar 2024 13:54:30 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id b18-20020a170903229200b001e0b5eee802sm3164487plh.123.2024.03.25.13.54.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 13:54:29 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Thomas Monjalon Subject: [PATCH v12 14/14] maintainers: add for log library Date: Mon, 25 Mar 2024 13:47:11 -0700 Message-ID: <20240325205405.669897-15-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240325205405.669897-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240325205405.669897-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 "You touch it you own it" Add myself as maintainer for log library. Signed-off-by: Stephen Hemminger --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index 7abb3aee49..54c28a601d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -180,6 +180,7 @@ F: app/test/test_threads.c F: app/test/test_version.c Logging +M: Stephen Hemminger F: lib/log/ F: doc/guides/prog_guide/log_lib.rst F: app/test/test_logs.c