From patchwork Thu Mar 28 23:49:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138966 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 127C143D73; Fri, 29 Mar 2024 00:52:14 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DBAF5410EE; Fri, 29 Mar 2024 00:52:09 +0100 (CET) Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by mails.dpdk.org (Postfix) with ESMTP id 885FA40042 for ; Fri, 29 Mar 2024 00:52:07 +0100 (CET) Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-6e6b6f86975so1038571b3a.1 for ; Thu, 28 Mar 2024 16:52:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711669927; x=1712274727; 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=Jg4gJVsR4dN+khFlEZjtz8EwwUHChpN4QN82VjySz0w=; b=oYsLRb4E/gFFvuGJhKUax/FdItodtb6H/5HZMP2mR6uzM3V6G3d+nRDRs0f/dtubgI P4HtWHn5ETOxpD84JmYuwVf1oAvrDDhdEu1aTu2Qr+5a7LjohdGWmslj1tu07CRGDaOz DPFIveQm/71rk6kHH4u9Lx6/fkcp3nnOjUvdpSSdEgfDh6aV9VvpMRsN1KHuaSe4eNoq UbQV5tFibdJlsbNoAdKOFuAzDkjT2ZCRl1H5jVshJeRRpTshGKL4ux/Y31bM/2gmYW/f /FKaumK7t6+KzQG46eNXKUJVbdTDJr+oUzosl5B234WKNXbjrGOIgz9pUFtT9nSWnnUf DsQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711669927; x=1712274727; 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=Jg4gJVsR4dN+khFlEZjtz8EwwUHChpN4QN82VjySz0w=; b=GDLjvUZkeiNHMHMbd7fGUvvO7b/30lm+OCIBSm3xhLXP7BgFFEjPEWy675Vv5LgEiy FToym/vi5dQuObFseTAMO5Ykp1OuA4A4ZFfg/XnP+6JzPvxnF56KWlXEDIwLVlrwAx4n o+dck6Hi7k8z5WY4AOzmIAPdB1MFhDrlBuoTMIX5/VtXaC2n5WbNJAUzBhIJRkZwBFqy 0aRvjSm36YWTmPBmly+Gos6FhZQ9iDYfdQmHVg3879GuzgRgt6+d5zyg7dB/69IFOlZD osC3MTLmdJhMH36WrYHFBAwDUtX7UbMQoC+5l9wV46RG8ecM/eSEmLLaw4Vt6E5B7fFC 0ipg== X-Gm-Message-State: AOJu0YyHJl4VkpHf4gv4gyeNROqKhY+gnwBXhhl5d+4Z4y51kBcGGUSg 7XNM++MMlXmBEUatPCtSygQWYsIE8i0j+Mif5wZyxxXB+MnpWuu8XjI2dAoIFUj2uaLFZFm3J7n G X-Google-Smtp-Source: AGHT+IHRvsyq7x1XJrZfq/Nr4fmkBZzn3HwMtPbg5Kc1ytwPf7+nNDYNSsF4o4hzvNdQEjvgjuGw8Q== X-Received: by 2002:a05:6a00:1382:b0:6ea:44a2:8268 with SMTP id t2-20020a056a00138200b006ea44a28268mr827794pfg.19.1711669926766; Thu, 28 Mar 2024 16:52:06 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id g21-20020a631115000000b005df58c83e89sm1875650pgl.84.2024.03.28.16.52.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 16:52:06 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff , Thomas Monjalon Subject: [PATCH v18 01/15] maintainers: add for log library Date: Thu, 28 Mar 2024 16:49:31 -0700 Message-ID: <20240328235156.5768-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240328235156.5768-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240328235156.5768-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 Acked-by: Tyler Retzlaff --- 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 From patchwork Thu Mar 28 23:49:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138967 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 4063943D73; Fri, 29 Mar 2024 00:52:23 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id ABC4C4161A; Fri, 29 Mar 2024 00:52:11 +0100 (CET) Received: from mail-ot1-f42.google.com (mail-ot1-f42.google.com [209.85.210.42]) by mails.dpdk.org (Postfix) with ESMTP id 9E1AB40A6E for ; Fri, 29 Mar 2024 00:52:08 +0100 (CET) Received: by mail-ot1-f42.google.com with SMTP id 46e09a7af769-6e6a9e2e2b6so835488a34.1 for ; Thu, 28 Mar 2024 16:52:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711669928; x=1712274728; 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=fXDP3EAZszW3khXLJCW9HzY/EWyn/YIYnt+aFG//6+m6TCU92UY8hkdcROO0gHDH5E bvNG3rkVEFf/s13kaiSssQ0e66856M+7s8mYUY432JZR9AwCHSuxh8BHHM8Xi67tttGq ZhoO5pq3glZviA6e1v1hXA9Mj1xTj4dUgXMz6xqwBiB5/2L3bdyxk7RGGaIDg4JRcyTv lYqVaXINIRwd1PbZxF4uyNhEx4V2YkGf2w7yJEpTGa3ba5MreVQm8lD6n0viKENzxGev JvdSgxf3/LLWT4O/RnMd3i6TEXQo845NGucaxlnMGusYyZMzb5yvioN3Jc137atF+/hJ 8V6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711669928; x=1712274728; 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=C46hbn0YqAYG6jioT82z9p4D/GZWBw30IrzKkQwA3U07afTv0pZUjXm89ncEFsLxAr hT4ctlcSEpXye4PaSAZZL4+LBGuzRuYjCg2fU0K1J2/PUAaocoCIOYSzyXfRLvBjqGi7 rUg1q7eBdwA6O5ZxPn83VuOYTRo9eciNQfwZzrG3bC+qBz9RdehNbrcqW+CV0rLiD1Pd G2Jb4ZGkUZvGPZKmDSYDWVzW4nRfrSNI/V4jt7jQ3trv+T2TBN/O3U98kEFINRZGRcFL f36hN6tra2QqmqjwuzfxNcA+XfU5vMnZQOdjGCNGMfW6jY09kv3NN3f/RL12SUSEyvjx PcXQ== X-Gm-Message-State: AOJu0YzeoO722Qeh+8FaGA10lDeN/t3s/sB7Aw0++81R89+m/RJ6hFVr e4vXteu7jJ1R3EbxE+qyhePXGWaHcZ77Gx5rMBv5tyHIcP55omowPYe81LjRlfSpFIiak+/bXkM B X-Google-Smtp-Source: AGHT+IEKygypftkPcFdbBZEz3J/H/nkamnI7BotvDQQcEPiS7ZLJwONLIFIueC5iE6swEhEoRXfRpQ== X-Received: by 2002:a9d:7495:0:b0:6e4:4393:8565 with SMTP id t21-20020a9d7495000000b006e443938565mr811904otk.25.1711669927800; Thu, 28 Mar 2024 16:52:07 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id g21-20020a631115000000b005df58c83e89sm1875650pgl.84.2024.03.28.16.52.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 16:52:07 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff , Dmitry Kozlyuk , Pallavi Kadam Subject: [PATCH v18 02/15] windows: make getopt functions have const properties Date: Thu, 28 Mar 2024 16:49:32 -0700 Message-ID: <20240328235156.5768-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240328235156.5768-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240328235156.5768-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 Thu Mar 28 23:49:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138968 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 DC9EB43D73; Fri, 29 Mar 2024 00:52:29 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1192B427D7; Fri, 29 Mar 2024 00:52:13 +0100 (CET) Received: from mail-oo1-f42.google.com (mail-oo1-f42.google.com [209.85.161.42]) by mails.dpdk.org (Postfix) with ESMTP id 8F778410E3 for ; Fri, 29 Mar 2024 00:52:09 +0100 (CET) Received: by mail-oo1-f42.google.com with SMTP id 006d021491bc7-5a58009fe88so856018eaf.0 for ; Thu, 28 Mar 2024 16:52:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711669929; x=1712274729; 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=ZlrKTSbTZG9U7EVa2nyOT/6+zSdva+byCe6SWEMtVSw=; b=n/9xuf4XacId2U6FW8dKOd61jEvjhM4QV7CCOc4WLQcMeSKXESqrEb6a/PjqRyng+W UP11JwA8Xj6QTqkSgq2ZqMfCbBhuNRGrKEOQxFn6fHkGybFyF6XPfAh2PVelVHYoW56p Z8M6hXLqqkfWE2ec5Rs0SLiR517vEt3SJw4ulD6KDmJZGs8iCknZZsQ+dOOADb7VVvG9 fFN92s8yTo2pujWYS7tsghzI5/k7+kZRwgu45SEQzy9eyRmlxk44EVuGYWEt3VMIjRGG tiOkmkAnBDDF3FktKlzBvLQROEqRvS8S8Squkog97etQiOMOeqajUfIoAfNBM6+DdyiQ 4ybg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711669929; x=1712274729; 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=ZlrKTSbTZG9U7EVa2nyOT/6+zSdva+byCe6SWEMtVSw=; b=di1gdHmrA5LhPJ7NRIjRHnvpW7rKSOmNHC0oSXltLLN92CBELsMJk5kiKiZYxO1XUT N3zgdO7jEhovqUJr0AXrPOUE7653TsfqnQwKQNpWSQWZKEZy94RB0Z98nRH7oFG9Kd61 wra7c6csdeXnLWfZr8OIXWLDVpoQ6WHyN5SXHe6jfaYgfRMqgZpEScAr/h3mgif8XErB ggVinbHyFfoeydU2KNuyIUHD1q3xx/Bohjt5IEoA5EyUYe9PgAKeWUqycuYw5QeLCPU+ jwWbB+oVw5LrzFnXh5Vn5NbsxIyrvlSH9MR+WCAz07u3AkvBxyoMiiCZ1OKzh3r0o0Xb mTRQ== X-Gm-Message-State: AOJu0YyoB/FEwkpZId17j7JntDOEhir75wewJ14/A0QbDtcjV1JEswkP vsjLkZSoXRfBvdljsxi7QjRdIBk+sC1hRmS5ocu+vQmGwebjfZQAPiIjC0cdAkSVhtEmoxyfbV7 i X-Google-Smtp-Source: AGHT+IGvv1I7ClZBD4KsqLy0NCN8hOQg2IwfK4wk7d4TX75UFxKB+5OOOd53z08zgXhMBZ8gtsmyrA== X-Received: by 2002:a05:6358:33a4:b0:17b:57ee:7b7e with SMTP id i36-20020a05635833a400b0017b57ee7b7emr902891rwd.26.1711669928710; Thu, 28 Mar 2024 16:52:08 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id g21-20020a631115000000b005df58c83e89sm1875650pgl.84.2024.03.28.16.52.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 16:52:08 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff , Dmitry Kozlyuk , Pallavi Kadam Subject: [PATCH v18 03/15] windows: add os shim for localtime_r Date: Thu, 28 Mar 2024 16:49:33 -0700 Message-ID: <20240328235156.5768-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240328235156.5768-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240328235156.5768-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 Acked-by: Tyler Retzlaff --- 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 Thu Mar 28 23:49:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138969 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 740CE43D73; Fri, 29 Mar 2024 00:52:37 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4F40D427DD; Fri, 29 Mar 2024 00:52:14 +0100 (CET) Received: from mail-oa1-f54.google.com (mail-oa1-f54.google.com [209.85.160.54]) by mails.dpdk.org (Postfix) with ESMTP id 73389410FD for ; Fri, 29 Mar 2024 00:52:10 +0100 (CET) Received: by mail-oa1-f54.google.com with SMTP id 586e51a60fabf-222ba2a19bdso923565fac.1 for ; Thu, 28 Mar 2024 16:52:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711669930; x=1712274730; 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=YwHfWcdLNfli8f+JFimP9JJamA7SW0tTDfnLjdRpUKc=; b=il7yCD0NHNdqm0Awrmwuqr/GZwS8t1lJTcR6wX89IKEWsemxliPJ+NiUbzFVJroR3y d9t/HoVxmkl5p6b18oXF25HRwM9rICCnL5Jbi8I/p4/pJjsNztZ0yUeJp/4KfTHAx9CC teVtUY0vSkfOenvig9J1uB+vgwnJmX0YtoL6UzQf5iBPKaWz7c0MLCZ248J00kwGEsFk dQFmC0Yobsjw2hHfstdI9hZR/zbAFaLDogLstgwZu7wToHTJVFLHBjI+dNBLzMLZLtEF VdwArnIwvjdTnI37byBhfdn7hkImQub/4Kb6s0GYS6xMGmBfmbMrtykxPjL5+oRzanV/ iNfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711669930; x=1712274730; 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=YwHfWcdLNfli8f+JFimP9JJamA7SW0tTDfnLjdRpUKc=; b=TzUu4YxEdUCmPN65f3ZrXI6o6LnTdD2P0vVvn8c43JF1ac3oW6lUdm0moNbJ62jLa/ HawdeffVuxIPLw1ould601zm0dSsiy/QI3K3NTEHvgIULFVkHFUySi4br3tq9o5IPjDg B+y2qLVASmwRy1aE0l29k0J3LxuYTVVW6SpOo9zWhmPxeoUoBkBvC2QiXBrXjffkji6Y fRVjOYt8GbWRoE5gVcgASvKRRj7VXRRBSFI4XQOceaKcuc1wyeaqB/0Z4gaYKaXuFfoa x2ynKUDb1ucyjXGurC6thLP8M5X8pXGYmeRS9m1V3DJEHTR+4PHKc4DFwDUIssWMbDbp kEpQ== X-Gm-Message-State: AOJu0Ywr1g4ACaEJs3eGY6cgfwYAxokSQhjhXeiP9QJKs1e5VCnzhobl jgYnfCeiMbTFAPcVtmYMDQqKv5VtJEHVDU0ofBasHsU0N+kRyb8CJbiA9U3XORuPzvuaTQ/RPkb d X-Google-Smtp-Source: AGHT+IFAVZGpd753c6BgcbE3Qqna85oBFls64xaCZRfwOI1pVaGD5C5hosIFrlnGEFhXPLWpxPhvZQ== X-Received: by 2002:a05:6870:96a4:b0:229:ec0e:7361 with SMTP id o36-20020a05687096a400b00229ec0e7361mr789286oaq.29.1711669929788; Thu, 28 Mar 2024 16:52:09 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id g21-20020a631115000000b005df58c83e89sm1875650pgl.84.2024.03.28.16.52.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 16:52:09 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff , Chenbo Xia , Nipun Gupta , Dmitry Kozlyuk , Pallavi Kadam , Bruce Richardson , David Marchand , Nick Connolly , Ranjit Menon , Khoa To Subject: [PATCH v18 04/15] windows: common wrapper for vasprintf and asprintf Date: Thu, 28 Mar 2024 16:49:34 -0700 Message-ID: <20240328235156.5768-5-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240328235156.5768-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240328235156.5768-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 Replace the windows version of asprintf() that was only usable in eal. With a more generic one that supports both vasprintf() and asprintf(). This also eliminates duplicate code. Fixes: 8f4de2dba9b9 ("bus/pci: fill bus specific information") Fixes: 9ec521006db0 ("eal/windows: hide asprintf shim") Signed-off-by: Stephen Hemminger Acked-by: Tyler Retzlaff --- drivers/bus/pci/pci_common.c | 32 ------------------ lib/eal/common/eal_private.h | 10 ------ lib/eal/windows/eal.c | 28 ---------------- lib/eal/windows/include/rte_os_shim.h | 48 +++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 70 deletions(-) diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c index 889a48d2af..80691c75a3 100644 --- a/drivers/bus/pci/pci_common.c +++ b/drivers/bus/pci/pci_common.c @@ -45,38 +45,6 @@ const char *rte_pci_get_sysfs_path(void) return path; } -#ifdef RTE_EXEC_ENV_WINDOWS -#define asprintf pci_asprintf - -static int -__rte_format_printf(2, 3) -pci_asprintf(char **buffer, const char *format, ...) -{ - int size, ret; - va_list arg; - - va_start(arg, format); - size = vsnprintf(NULL, 0, format, arg); - va_end(arg); - if (size < 0) - return -1; - size++; - - *buffer = malloc(size); - if (*buffer == NULL) - return -1; - - va_start(arg, format); - ret = vsnprintf(*buffer, size, format, arg); - va_end(arg); - if (ret != size - 1) { - free(*buffer); - return -1; - } - return ret; -} -#endif /* RTE_EXEC_ENV_WINDOWS */ - static struct rte_devargs * pci_devargs_lookup(const struct rte_pci_addr *pci_addr) { diff --git a/lib/eal/common/eal_private.h b/lib/eal/common/eal_private.h index 71523cfdb8..da8d77a134 100644 --- a/lib/eal/common/eal_private.h +++ b/lib/eal/common/eal_private.h @@ -737,16 +737,6 @@ void __rte_thread_init(unsigned int lcore_id, rte_cpuset_t *cpuset); */ void __rte_thread_uninit(void); -/** - * asprintf(3) replacement for Windows. - */ -#ifdef RTE_EXEC_ENV_WINDOWS -__rte_format_printf(2, 3) -int eal_asprintf(char **buffer, const char *format, ...); - -#define asprintf(buffer, format, ...) \ - eal_asprintf(buffer, format, ##__VA_ARGS__) -#endif #define EAL_LOG(level, ...) \ RTE_LOG_LINE(level, EAL, "" __VA_ARGS__) diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c index 52f0e7462d..8ca00c0f95 100644 --- a/lib/eal/windows/eal.c +++ b/lib/eal/windows/eal.c @@ -503,34 +503,6 @@ rte_eal_init(int argc, char **argv) return fctret; } -/* Don't use MinGW asprintf() to have identical code with all toolchains. */ -int -eal_asprintf(char **buffer, const char *format, ...) -{ - int size, ret; - va_list arg; - - va_start(arg, format); - size = vsnprintf(NULL, 0, format, arg); - va_end(arg); - if (size < 0) - return -1; - size++; - - *buffer = malloc(size); - if (*buffer == NULL) - return -1; - - va_start(arg, format); - ret = vsnprintf(*buffer, size, format, arg); - va_end(arg); - if (ret != size - 1) { - free(*buffer); - return -1; - } - return ret; -} - int rte_vfio_container_dma_map(__rte_unused int container_fd, __rte_unused uint64_t vaddr, diff --git a/lib/eal/windows/include/rte_os_shim.h b/lib/eal/windows/include/rte_os_shim.h index e9741a9df2..65153fdb38 100644 --- a/lib/eal/windows/include/rte_os_shim.h +++ b/lib/eal/windows/include/rte_os_shim.h @@ -3,6 +3,7 @@ #ifndef _RTE_OS_SHIM_ #define _RTE_OS_SHIM_ +#include #include #include @@ -120,4 +121,51 @@ rte_localtime_r(const time_t *timer, struct tm *buf) } #define localtime_r(timer, buf) rte_localtime_r(timer, buf) +/* print to allocated string */ +__rte_format_printf(2, 0) +static inline int +rte_vasprintf(char **strp, const char *fmt, va_list ap) +{ + char *str; + int len, ret; + + *strp = NULL; + + /* determine size of buffer needed */ + len = _vscprintf(fmt, ap); + if (len < 0) + return -1; + + len += 1; /* for nul termination */ + str = malloc(len); + if (str == NULL) + return -1; + + ret = vsnprintf(str, len, fmt, ap); + if (ret < 0) { + free(str); + return -1; + } else { + *strp = str; + return ret; + } +} +#define vasprintf(strp, fmt, ap) rte_vasprintf(strp, fmt, ap) + +__rte_format_printf(2, 3) +static inline int +rte_asprintf(char **strp, const char *fmt, ...) +{ + int ret; + + va_list ap; + + va_start(ap, fmt); + ret = rte_vasprintf(strp, fmt, ap); + va_end(ap); + + return ret; +} + +#define asprintf(strp, fmt, ...) rte_asprintf(strp, fmt, __VA_ARGS__) #endif /* _RTE_OS_SHIM_ */ From patchwork Thu Mar 28 23:49:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138970 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 8C8DA43D73; Fri, 29 Mar 2024 00:52:44 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BCC3C427E6; Fri, 29 Mar 2024 00:52:19 +0100 (CET) Received: from mail-oo1-f53.google.com (mail-oo1-f53.google.com [209.85.161.53]) by mails.dpdk.org (Postfix) with ESMTP id 82C434114B for ; Fri, 29 Mar 2024 00:52:11 +0100 (CET) Received: by mail-oo1-f53.google.com with SMTP id 006d021491bc7-5a529a1f69aso806610eaf.3 for ; Thu, 28 Mar 2024 16:52:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711669931; x=1712274731; 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=3fWTOM3e44i9f5Ui4EGaJfHlyx0x5XrATeUx6W8j5PI=; b=GbASJ57x3Or79oeQGdkHreM6K9o8Sc0tuv+gwkNcxe6pwe7Iwky8/qw3tVa6fQxwN2 sV9cCfP71O2yAb7ejJlvRem2OW2mwfNjR5LoqHjClZld2v1o9gG1TlYSxPYud08jbFHF yDKk2AW8Su4DhqkXoqv/3/ktBCxhR+/CmpSHr5JhZwJ89FsFdLkFK6LqI+zAnunILrlz SEsW6fTZJIEZbZ094wxIjrZ/H8hN9SuZDdxGeETqYQtsXFsfMPwpJRuxKfbrytNBy88L ValINKTcoyy1ZH5h0hDnzAp+xGIr4pkhL/3fnpwFNIqYgxiQN34IVapjBfUu+UFRH20O Lx7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711669931; x=1712274731; 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=3fWTOM3e44i9f5Ui4EGaJfHlyx0x5XrATeUx6W8j5PI=; b=KPta80T3PYU6H3M1NMn0etaTcoCcW57tH6Uih2JBYT+xFxlEQG8hcIfFjArJ+G9MdG xLE8viZSARi6ljVQ7HNXeNnUdfQQ1GnXWSlMxALpHAKqjfwA63gN4pySvCu75uvAAyRr XGwybcMfRig8MvMwTuscjrgQXvqwgBwafNQjfJdg1zYmRE0Creb9UT5qvxgAdafpoz8y cmQ3FEDCn2ged4tSYN4Fk3miCJ2s/1KSl26XWJb68IbhoO0FpRuxYzUVTiYNvgEaEFki QRgDwfHIAqT45Xlc+GInsm9wdiMS+832mhRo3P1MmV8nyZIbLVBSpqJ/RUzXDp1yeNBq 1TGw== X-Gm-Message-State: AOJu0YwzSz1IB0Rf9hYjXR3vp3gyFImpksB4sedl5ddvq+FEF/OC8tPM BBANgXADq4exgPjLlrVR0fPNbgG9ZLN2wkA+iK7/MeJA5VBfHj7nsYDSZnxww9k6h8f1i/xgiOB g X-Google-Smtp-Source: AGHT+IEs37SxIz7L/rv3vS4X8VkaV/6rR3twOOx4yRHN/5ssaJol8nSTtuwbAZtYu5arUKTMNgg7oA== X-Received: by 2002:a05:6358:7215:b0:17e:b81b:3d0 with SMTP id h21-20020a056358721500b0017eb81b03d0mr893098rwa.23.1711669930754; Thu, 28 Mar 2024 16:52:10 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id g21-20020a631115000000b005df58c83e89sm1875650pgl.84.2024.03.28.16.52.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 16:52:10 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff , Bruce Richardson , Dmitry Kozlyuk , Pallavi Kadam Subject: [PATCH v18 05/15] eal: make eal_log_level_parse common Date: Thu, 28 Mar 2024 16:49:35 -0700 Message-ID: <20240328235156.5768-6-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240328235156.5768-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240328235156.5768-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The code to parse for log-level option should be same on all OS variants. Signed-off-by: Stephen Hemminger Acked-by: Tyler Retzlaff --- lib/eal/common/eal_common_options.c | 46 +++++++++++++++++++++++++++++ lib/eal/common/eal_options.h | 1 + lib/eal/freebsd/eal.c | 42 -------------------------- lib/eal/linux/eal.c | 39 ------------------------ lib/eal/windows/eal.c | 35 ---------------------- 5 files changed, 47 insertions(+), 116 deletions(-) diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index 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 8ca00c0f95..44e20643f2 100644 --- a/lib/eal/windows/eal.c +++ b/lib/eal/windows/eal.c @@ -96,41 +96,6 @@ eal_usage(const char *prgname) } } -/* Parse the arguments for --log-level only */ -static void -eal_log_level_parse(int argc, char **argv) -{ - int opt; - char **argvopt; - int option_index; - struct internal_config *internal_conf = - eal_get_internal_configuration(); - - argvopt = argv; - - eal_reset_internal_config(internal_conf); - - while ((opt = getopt_long(argc, argvopt, eal_short_options, - eal_long_options, &option_index)) != EOF) { - - int ret; - - /* getopt is not happy, stop right now */ - if (opt == '?') - break; - - ret = (opt == OPT_LOG_LEVEL_NUM) ? - eal_parse_common_option(opt, optarg, - internal_conf) : 0; - - /* common parser is not happy */ - if (ret < 0) - break; - } - - optind = 0; /* reset getopt lib */ -} - /* Parse the argument given in the command line of the application */ static int eal_parse_args(int argc, char **argv) From patchwork Thu Mar 28 23:49:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138971 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 49DB243D73; Fri, 29 Mar 2024 00:52:51 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1F964427E5; Fri, 29 Mar 2024 00:52:21 +0100 (CET) Received: from mail-oa1-f53.google.com (mail-oa1-f53.google.com [209.85.160.53]) by mails.dpdk.org (Postfix) with ESMTP id 59B8F4114B for ; Fri, 29 Mar 2024 00:52:12 +0100 (CET) Received: by mail-oa1-f53.google.com with SMTP id 586e51a60fabf-222b6a05bb1so965779fac.3 for ; Thu, 28 Mar 2024 16:52:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711669931; x=1712274731; 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=jpuKRgSOIbpBBbsAGPHwAR/lg4j9u3JMjpynNGAPSTY=; b=HlQUSSo4tv6XoGEVSjN63GGzlO+Uj6NmxQYMTkD++ze+IFSjBXYdlq5SIDnPixQ07O Rn1z2NnSeYHfuW/0QkJIgCBsbgP7Xc33+aAr3Ca2S6a/HPt8eVEbu+ULmxbMf4ZpaxdW 32GAhO84mH0gAuD/Why8iZUSCbJMU6WFMyZAdo1bEdAwyvTvScS5ahwlfFFmpCUqJy0L tEFrwJqU6+CPSRCndjK8PJ4VpUkrpDXLW2XgmKLqDGn4KrZvD1xgM/Edxp4C/WfNDx7/ N23hYPn3eIHmAZd/FYYsZzaJK3A3h6P78/s1fwgXgyHw5cC/eCC0aHQWBpg39DdJ4tAW tRYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711669931; x=1712274731; 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=jpuKRgSOIbpBBbsAGPHwAR/lg4j9u3JMjpynNGAPSTY=; b=iuFnh9Tg2NGBIJ+M3A39JbU0e95Q8KQjsovBIkWRjAReBKUk1AFBu4yHI/fNN7Vnea n8rC6k4uJgqkJSY5JZDWWywQL7NLHXTmO4earvLvMszpJtxwP2JA0VHMcILSxEkXgJ+j s7w1nof84nRlzRvkQwGFuaQkIJJ6EIQ2MqT5UJfk7yaGpFBidTiTxFVHBQQWsBEEbKMA 6O80z5ecTYMfc7hNBbNpf4TrI0ry17zyvXDON6WYEk3VKXdzLqupMorr0Wt04A+wsKq4 E2trhT6zFLRdb0Wh3a60LCaRpIgsmCQWB9w7+On0qlEh6/UifppDQ4M5j1e/zxvV1UN3 nwAA== X-Gm-Message-State: AOJu0YyXp/cGlfHqmdyOFTdLhJToGptfshh/E6HxAIO7otRvGjfkz9VH RuZ2tOLypKyPQr83oP3mXwuONNCtcLki9MkSKmeL0XYMyrN0IWuUpz8vFgci3p9ixX1IBmnyXnQ e X-Google-Smtp-Source: AGHT+IFm94rrjJdgAuSaaQcLuozuN40YAHnteQ6tNVeZihoZRhAS/SlRim+iFqFHVyekdePZ2fC9Tg== X-Received: by 2002:a05:6870:c34f:b0:229:c1d4:83bf with SMTP id e15-20020a056870c34f00b00229c1d483bfmr685678oak.8.1711669931561; Thu, 28 Mar 2024 16:52:11 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id g21-20020a631115000000b005df58c83e89sm1875650pgl.84.2024.03.28.16.52.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 16:52:11 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff , Bruce Richardson Subject: [PATCH v18 06/15] eal: do not duplicate rte_init_alert() messages Date: Thu, 28 Mar 2024 16:49:36 -0700 Message-ID: <20240328235156.5768-7-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240328235156.5768-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240328235156.5768-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 Acked-by: Tyler Retzlaff --- 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 Thu Mar 28 23:49:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138972 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 1BDC143D73; Fri, 29 Mar 2024 00:52:58 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5EED842D2A; Fri, 29 Mar 2024 00:52:22 +0100 (CET) Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by mails.dpdk.org (Postfix) with ESMTP id 5C0F540042 for ; Fri, 29 Mar 2024 00:52:13 +0100 (CET) Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-6e7425a6714so1347980b3a.0 for ; Thu, 28 Mar 2024 16:52:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711669932; x=1712274732; 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=26JyS8a5xAOFLsVay3Kok3WHu0A/W2PjaWn3v8PwBA0=; b=1k+fnV12bTKUuJDYze4R5JC+xJ/DveqNtGqEoquGVLc/dZS/0rVSdQT3yZjuDSl62s 6Zl3PgHuHAN8OGvFoO1NJHXDLVd0z+9CxJwS5atD3r3DebQw0wR5kSTqqhqo//cechJM 8P/XXx3n4qKqLtx7xOkNHWKzZEt3Gi2rgqanIUrDlO764PnkYmn1dOgAqBumdgtPWl3j fwC/lmTT+vW+ZffsdVsG5M7UTG1+EVGO8uUOh4dRh+9aUceIqF6VaTAEPulPQfxU3oGC h6PlAeAxTdhgp8Pj0eNyaIcrHEssl5cvLUukHn7tNOfYx2JRRXTD1QPsqNpLDiqqBJmv ZgiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711669932; x=1712274732; 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=26JyS8a5xAOFLsVay3Kok3WHu0A/W2PjaWn3v8PwBA0=; b=kyjwd33AoajLXnoAD1Wb1jyLFs6hqvxBVQ2HxT7eepHExHduj4C0/elkC1FstmaHxS ZAfTeG456pJG2qiSDZbd8ToPsOD2TIDxtWs6aLKDLOyM18L/ofy5ZDyqdNDHYyXj7QNW ZdYZlEq0LI3dhiVhYllIiQMmnuyeVCR4PJIFbBuDz12t7coYN7RjDS/4WmatygwKYBPn PLrJpXRil/3j1gQXZA/dsrWV/R4kg/SE0hsADlOeOySU8ARGlVLfTgceEF89GiQ5LnRp BTjxKDFuXsapHhvxpfwPqdUMIGGO/YYsC3SMZUfzSyRS++Ll2fqzUnxcWs6qkCWNTFW1 W+YA== X-Gm-Message-State: AOJu0YwXTAwE9FHWxtZ6GAGkUyHArgAzB9Cm3DaI5N485hXVCdgL27dv 4fTu2A0KkFvhKC9rI+AXpgMnqzx61vtcQm0MxpHLLZ8axI74lJMJaNiG1P88ZCdlqcjpEDdyfxo 8 X-Google-Smtp-Source: AGHT+IFDfjn5/pe0ALaeb8l0jNH5ZjWKoXUpibLlP7hnzMMK5a6Zj9ScsIVtfEcK7x8G1op30QqXSA== X-Received: by 2002:a05:6a00:4656:b0:6ea:b7b1:ef26 with SMTP id kp22-20020a056a00465600b006eab7b1ef26mr898452pfb.26.1711669932552; Thu, 28 Mar 2024 16:52:12 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id g21-20020a631115000000b005df58c83e89sm1875650pgl.84.2024.03.28.16.52.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 16:52:12 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff Subject: [PATCH v18 07/15] eal: change rte_exit() output to match rte_log() Date: Thu, 28 Mar 2024 16:49:37 -0700 Message-ID: <20240328235156.5768-8-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240328235156.5768-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240328235156.5768-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..ad2be63cbb 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[256]; 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); + vsnprintf(msg, sizeof(msg), format, ap); va_end(ap); + rte_log(RTE_LOG_CRIT, RTE_LOGTYPE_EAL, "EAL: Cause - %s", msg); + if (rte_eal_cleanup() != 0 && rte_errno != EALREADY) - EAL_LOG(CRIT, - "EAL could not release all resources"); + EAL_LOG(CRIT, "EAL could not release all resources"); exit(exit_code); } From patchwork Thu Mar 28 23:49:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138973 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 CCAAF43D73; Fri, 29 Mar 2024 00:53:04 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A40A942D6A; Fri, 29 Mar 2024 00:52:23 +0100 (CET) Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by mails.dpdk.org (Postfix) with ESMTP id 469FB427DB for ; Fri, 29 Mar 2024 00:52:14 +0100 (CET) Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-6e6f4ad4c57so1260063b3a.2 for ; Thu, 28 Mar 2024 16:52:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711669933; x=1712274733; 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=RT6FK6frw1PCVteueJi1ZqrqlTyPs8vb+PKGspmqbu4=; b=kaRCj0oFTneoZgFvDfghhI2BV0YgzlGCibKZd1R7W/qNj5K0IKwdek+jmGPPspD22Z erIhpyv3iLQbRgSXyslSKrV5dZYFwVzdUb0X7i/bjQpbacseB3dUXYL1b2FSZfd7cGgG GETzYO19VG5cQhDjt6R5VIx/wmQdtTCemu/6HHOukBjcteX86cXuAL2la4JA7oGBA7EH fuJKDcm4hSuSeIKF8A4GbuTQtb2C9XWTf38Eo/iH/AiggdiBx3QAHFIz3mzoTwp/AnIu hXa7uu846WQdw6YXbeQYFS4QZUe7uYjDtnTOFNug8MpM6Sw/I6ItVss1DXHbWOryG6Jt 0pFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711669933; x=1712274733; 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=RT6FK6frw1PCVteueJi1ZqrqlTyPs8vb+PKGspmqbu4=; b=Nq0SB21Qh1s9Km00ZBp7yFbl30hMAbPnTLFJAQ8PMA2EjtWKNTCYnt3rKUor5xosNO Gfzs55YQ9/aUhtsUlppEd4AIL4HNGPAl7QuOdigbJaCau3mNv9xTsMFRy5rUyeVjzi6m Wev5rw9EFRc+DQWJeB2wVtakJU47rmigOrV/aUpdnKQ1MrcbgM8NuNR1ub8CAR/g4GVD Gpies+0dWwzSYKgy8oA0uxBBhXtAgY6DZ0mXBWkeXgPqteh0CWXZNxIhL64aEzmaNnIL tVYyWFnQ3Jhpv+7VchUJ04uzGSfoSX3COO2B7lnqszr61Z/kl8ynWTCPHtUmS/zjVE7S l9VQ== X-Gm-Message-State: AOJu0YzhntygA1OAFlQZcQSd7Y/9TSeuAIXVYUm5BaeV/UP/1fK6VAW6 YP9NdHmBw7xdYy30VXXLwCPhN/mQnXtN/J5Gm11iCDEvpg2z5vM7EYpR2pkkJggkCsZ+RiVc+y8 Q X-Google-Smtp-Source: AGHT+IHitgqeb9QiuQNG3sWu52c+Hiy+pYtq8Hcwy4J3TJqvJcuXHZxvsTRebBk5vhYeJm9Ym4PBuQ== X-Received: by 2002:a05:6a00:1c91:b0:6ea:c7e7:549f with SMTP id y17-20020a056a001c9100b006eac7e7549fmr930445pfw.23.1711669933501; Thu, 28 Mar 2024 16:52:13 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id g21-20020a631115000000b005df58c83e89sm1875650pgl.84.2024.03.28.16.52.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 16:52:13 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Bruce Richardson , Dmitry Kozlyuk , Tyler Retzlaff , Pallavi Kadam Subject: [PATCH v18 08/15] log: move handling of syslog facility out of eal Date: Thu, 28 Mar 2024 16:49:38 -0700 Message-ID: <20240328235156.5768-9-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240328235156.5768-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240328235156.5768-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 44e20643f2..14e498a643 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 Thu Mar 28 23:49:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138974 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 DAD8643D73; Fri, 29 Mar 2024 00:53:11 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CF11D42D78; Fri, 29 Mar 2024 00:52:24 +0100 (CET) Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) by mails.dpdk.org (Postfix) with ESMTP id 2B6F4427E0 for ; Fri, 29 Mar 2024 00:52:15 +0100 (CET) Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-6e6b22af648so1914695b3a.0 for ; Thu, 28 Mar 2024 16:52:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711669934; x=1712274734; 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=H59mhlAdyxEr4u2r9yRQ9QfdFZHNUN65SqDMuFQaDNc=; b=AYKt5TST9+gv/Ja5dy5qtHf3WscGsoQPV+jIpKKy5E7HphNi/St1lVzDhS3Oba1Fb4 ll3tiXFinIZrLreEsKaTS/RgkCmBifePvUTMduQuRLgWKcY/t14QFLWiNlrNd62vCiJP ijRCttHYTG00JgqP79WKkSWSM+E/tMUEmOxOhKnS+iSirBH+GkkBUPvNVz3V0NB5EZNl ANb8DnYo0HDpcM76lS6KMhLrO2k9q0/KuysTp72pyJ46tWmOWHDmlNwDcXOUpKfOgh3n YoSMaSitTrn3YWOk9dYsSs6X/yEM/8Ld0izh3mgPJiRKqIMnRtwrmFjaYv3caSNMa4oG S3nA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711669934; x=1712274734; 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=H59mhlAdyxEr4u2r9yRQ9QfdFZHNUN65SqDMuFQaDNc=; b=jRGhrobQVLwQ4kkJoJGcplDwRExSye+9OXd0TzoQAlzRZ+g8cCy4MRF9MFNj3wWv2S DwC0CrXhAJoZEVoi/z9KKUQViG6l8NlM5tNzRbHTulu7z2zWShL4nQsVVXKLSYGpeFDB cw3VzFy+DsiiNAlk7xzJCHLwQm4yVMeaTUE1CrfcpJangfp2SuVawfMv4u+r6vy1cCWr slof1R9f3d12gHe5v8YJBpfFnVHi98gZ8bCqpYIIMm9Uuyh3N9gXOEJ4lGPCw7VTJTGm 9uNo4sOSVCYwQYDh7jWAYOqQeWTx1t/xteft3m9m/8OQh0RNLGx+e+F5NJIFAGX14QTV jnIA== X-Gm-Message-State: AOJu0Yz9O5bg8fE//1gmZqQRJLmGdi51sHnhM4rgtARvkbnGYCCpolwe SL3sEUXA16si6T9f+j+LilVaTGGJ1NYHz0XYAZXwoy6oSInN2JfcomzLNairJmsw1bH71KcL5JF L X-Google-Smtp-Source: AGHT+IE8vvwyGKgZJ6W2EWkYwbroGZZ+1PAQoN5CjKq4vI9HH8t5acamAhZ+IbiaSNXvZTy+adjYsQ== X-Received: by 2002:a05:6a20:734d:b0:1a5:6a5f:b0b8 with SMTP id v13-20020a056a20734d00b001a56a5fb0b8mr1324329pzc.25.1711669934351; Thu, 28 Mar 2024 16:52:14 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id g21-20020a631115000000b005df58c83e89sm1875650pgl.84.2024.03.28.16.52.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 16:52:14 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff , Bruce Richardson , Dmitry Kozlyuk , Pallavi Kadam Subject: [PATCH v18 09/15] eal: initialize log before everything else Date: Thu, 28 Mar 2024 16:49:39 -0700 Message-ID: <20240328235156.5768-10-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240328235156.5768-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240328235156.5768-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 Acked-by: Tyler Retzlaff --- lib/eal/freebsd/eal.c | 12 +++++++++--- lib/eal/linux/eal.c | 19 +++++++++---------- lib/eal/windows/eal.c | 8 ++++++-- lib/log/log_freebsd.c | 3 +-- lib/log/log_internal.h | 2 +- lib/log/log_linux.c | 14 ++++++-------- lib/log/log_windows.c | 4 +--- 7 files changed, 33 insertions(+), 29 deletions(-) diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index 6552f9c138..55ff27a4da 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -52,6 +52,7 @@ #include "eal_options.h" #include "eal_memcfg.h" #include "eal_trace.h" +#include "log_internal.h" #define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL) @@ -546,6 +547,14 @@ rte_eal_init(int argc, char **argv) bool has_phys_addr; enum rte_iova_mode iova_mode; + /* setup log as early as possible */ + if (eal_log_level_parse(argc, argv) < 0) { + rte_eal_init_alert("invalid log arguments."); + rte_errno = EINVAL; + return -1; + } + eal_log_init(getprogname()); + /* checks if the machine is adequate */ if (!rte_cpu_is_supported()) { rte_eal_init_alert("unsupported cpu type."); @@ -565,9 +574,6 @@ rte_eal_init(int argc, char **argv) /* clone argv to report out later in telemetry */ eal_save_args(argc, argv); - /* set log level as early as possible */ - eal_log_level_parse(argc, argv); - if (rte_eal_cpu_init() < 0) { rte_eal_init_alert("Cannot detect lcores."); rte_errno = ENOTSUP; diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index 3d0c34063e..b9a0fb1742 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -936,6 +936,15 @@ rte_eal_init(int argc, char **argv) struct internal_config *internal_conf = eal_get_internal_configuration(); + /* setup log as early as possible */ + if (eal_log_level_parse(argc, argv) < 0) { + rte_eal_init_alert("invalid log arguments."); + rte_errno = EINVAL; + return -1; + } + + eal_log_init(program_invocation_short_name); + /* checks if the machine is adequate */ if (!rte_cpu_is_supported()) { rte_eal_init_alert("unsupported cpu type."); @@ -952,9 +961,6 @@ rte_eal_init(int argc, char **argv) eal_reset_internal_config(internal_conf); - /* set log level as early as possible */ - eal_log_level_parse(argc, argv); - /* clone argv to report out later in telemetry */ eal_save_args(argc, argv); @@ -1106,13 +1112,6 @@ rte_eal_init(int argc, char **argv) #endif } - if (eal_log_init(program_invocation_short_name) < 0) { - rte_eal_init_alert("Cannot init logging."); - rte_errno = ENOMEM; - rte_atomic_store_explicit(&run_once, 0, rte_memory_order_relaxed); - return -1; - } - #ifdef VFIO_PRESENT if (rte_eal_vfio_setup() < 0) { rte_eal_init_alert("Cannot init VFIO"); diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c index 14e498a643..e59aba954e 100644 --- a/lib/eal/windows/eal.c +++ b/lib/eal/windows/eal.c @@ -250,9 +250,13 @@ rte_eal_init(int argc, char **argv) char cpuset[RTE_CPU_AFFINITY_STR_LEN]; char thread_name[RTE_THREAD_NAME_SIZE]; - eal_log_init(NULL); + if (eal_log_level_parse(argc, argv) < 0) { + rte_eal_init_alert("invalid log arguments."); + rte_errno = EINVAL; + return -1; + } - eal_log_level_parse(argc, argv); + eal_log_init(NULL); if (eal_create_cpu_map() < 0) { rte_eal_init_alert("Cannot discover CPU and NUMA."); diff --git a/lib/log/log_freebsd.c b/lib/log/log_freebsd.c index 953e371bee..33a0925c43 100644 --- a/lib/log/log_freebsd.c +++ b/lib/log/log_freebsd.c @@ -5,8 +5,7 @@ #include #include "log_internal.h" -int +void eal_log_init(__rte_unused const char *id) { - return 0; } diff --git a/lib/log/log_internal.h b/lib/log/log_internal.h index cb15cdff08..d5fabd7ef7 100644 --- a/lib/log/log_internal.h +++ b/lib/log/log_internal.h @@ -14,7 +14,7 @@ * Initialize the default log stream. */ __rte_internal -int eal_log_init(const char *id); +void eal_log_init(const char *id); /* * Determine where log data is written when no call to rte_openlog_stream. diff --git a/lib/log/log_linux.c b/lib/log/log_linux.c index 47aa074da2..6d7dc8f3ab 100644 --- a/lib/log/log_linux.c +++ b/lib/log/log_linux.c @@ -87,18 +87,16 @@ static cookie_io_functions_t console_log_func = { * set the log to default function, called during eal init process, * once memzones are available. */ -int +void eal_log_init(const char *id) { FILE *log_stream; - log_stream = fopencookie(NULL, "w+", console_log_func); - if (log_stream == NULL) - return -1; - openlog(id, LOG_NDELAY | LOG_PID, log_facility); - eal_log_set_default(log_stream); - - return 0; + log_stream = fopencookie(NULL, "w+", console_log_func); + if (log_stream != NULL) + eal_log_set_default(log_stream); + else + eal_log_set_default(stderr); } diff --git a/lib/log/log_windows.c b/lib/log/log_windows.c index a3a756351d..d7c30e4cfa 100644 --- a/lib/log/log_windows.c +++ b/lib/log/log_windows.c @@ -13,12 +13,10 @@ eal_log_syslog(const char *name __rte_unused) } /* set the log to default function, called during eal init process. */ -int +void eal_log_init(__rte_unused const char *id) { rte_openlog_stream(stderr); eal_log_set_default(stderr); - - return 0; } From patchwork Thu Mar 28 23:49:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138975 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 2B97543D73; Fri, 29 Mar 2024 00:53:18 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 190A342D89; Fri, 29 Mar 2024 00:52:26 +0100 (CET) Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by mails.dpdk.org (Postfix) with ESMTP id 13EAC427E0 for ; Fri, 29 Mar 2024 00:52:16 +0100 (CET) Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-6e8f51d0bf0so1352818b3a.3 for ; Thu, 28 Mar 2024 16:52:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711669935; x=1712274735; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1/x8ncg9xdOGd9rk7YaJdxnL7XVS6cGgMwNAwMjCJwM=; b=G9R1SOXgNYt9suQPkH0y91qTm3XK0pdgc988hXHJzNbWZad4UQ3VseH6Od3hDyaMrn Wu2CSJ0xf88BKJTJ7Cv3uf+PQTI7wePe0vZe4R4NG71aKeEFsZDGMIGgVuU8ZpvRwr+s BarYgLrCPkuoG3fEbcIY2udpV2db68NopIanZTt07iL7ktUeywvrH64ngZsFoRHtJKm9 IxW7ebxd1A4ciDNnoyrkf8YEgHerHPa3IruvBjVKeZe3KOfCKi5Kxm2QvMktS4oh51WS VhUvcdUpEj0fMNgD4FA76GyHI8VNGqdcqO1o3JVoDo8VcRbY+Q4w/k0oYm3SmfC517KV mRLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711669935; x=1712274735; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1/x8ncg9xdOGd9rk7YaJdxnL7XVS6cGgMwNAwMjCJwM=; b=b2GKI2phwtFW2SI+1jymCIOK5ME7ovAWQd7/zQ1PQmoy2YYq12mXzJaTMZzhWYwyE4 xfAzMC9EYxIpgiwFLP2Pj/UV937PpAulusSbvu33NxyiHg6liOVRxVGs+J53x8e5SNFl jmPK8+tSLzKriOS01v861noyEPZ26pCHbJ8w11V+I216tLYIWLC3DsCN7DHNOoHjDOlH HVPDv8TXk7+NxOfUVR+2b1opInoZqxgH08p7Pxp2jDxjFaMi4CTiWPLpwIM+FbvUn39c IfWin3T+BPy9EK+eQOTF8G3wwO1+F+qHdTYPyunJFLBEvtFjnfurSyfcI7tIeOnWe20e +TgA== X-Gm-Message-State: AOJu0YwKnDuIMDgjWJvt3QYc7EdBjP9lRu/cE4AtkmP/SKKIVYnbgwDa 3oO3+L1MlGrVGd/IxsDgea5q1gEAbS3J+5OLoUePTexi4E1XtqY5FmhX4WGPPwwoYrtF8EPnaF2 J X-Google-Smtp-Source: AGHT+IEAgR+F9JKbR5pB5vGCppq51KmOza6DIn6owHZBGg3jsuWa2/Q5oBU3M1+P7+wxrILfVOFFOA== X-Received: by 2002:a05:6a00:190b:b0:6e6:b9a8:5cfc with SMTP id y11-20020a056a00190b00b006e6b9a85cfcmr798978pfi.31.1711669935175; Thu, 28 Mar 2024 16:52:15 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id g21-20020a631115000000b005df58c83e89sm1875650pgl.84.2024.03.28.16.52.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 16:52:14 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v18 10/15] log: drop syslog support, and make code common Date: Thu, 28 Mar 2024 16:49:40 -0700 Message-ID: <20240328235156.5768-11-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240328235156.5768-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240328235156.5768-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org This patch makes the log setup code common across all platforms. Drops syslog support for now, will come back in later patch. Signed-off-by: Stephen Hemminger --- app/test/test_eal_flags.c | 11 ++- lib/eal/common/eal_common_options.c | 3 - lib/log/log.c | 29 +++++--- lib/log/log_internal.h | 6 -- lib/log/log_linux.c | 102 ---------------------------- lib/log/log_windows.c | 22 ------ lib/log/meson.build | 5 +- lib/log/version.map | 1 - 8 files changed, 26 insertions(+), 153 deletions(-) delete mode 100644 lib/log/log_linux.c delete mode 100644 lib/log/log_windows.c diff --git a/app/test/test_eal_flags.c b/app/test/test_eal_flags.c index 6cb4b06757..36e3185a10 100644 --- a/app/test/test_eal_flags.c +++ b/app/test/test_eal_flags.c @@ -984,11 +984,10 @@ test_misc_flags(void) const char *argv1[] = {prgname, prefix, mp_flag, "--no-pci"}; /* With -v */ const char *argv2[] = {prgname, prefix, mp_flag, "-v"}; + /* With empty --syslog */ + const char *argv3[] = {prgname, prefix, mp_flag, "--syslog"}; /* With valid --syslog */ - const char *argv3[] = {prgname, prefix, mp_flag, - "--syslog", "syslog"}; - /* With empty --syslog (should fail) */ - const char *argv4[] = {prgname, prefix, mp_flag, "--syslog"}; + const char *argv4[] = {prgname, prefix, mp_flag, "--syslog", "always"}; /* With invalid --syslog */ const char *argv5[] = {prgname, prefix, mp_flag, "--syslog", "error"}; /* With no-sh-conf, also use no-huge to ensure this test runs on BSD */ @@ -1083,8 +1082,8 @@ test_misc_flags(void) printf("Error - process did not run ok with --syslog flag\n"); goto fail; } - if (launch_proc(argv4) == 0) { - printf("Error - process run ok with empty --syslog flag\n"); + if (launch_proc(argv4) != 0) { + printf("Error - process did not with --syslog always flag\n"); goto fail; } if (launch_proc(argv5) == 0) { diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index 661b2db211..9ab512e8a1 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -2212,9 +2212,6 @@ eal_common_usage(void) " (can be used multiple times)\n" " --"OPT_VMWARE_TSC_MAP" Use VMware TSC map instead of native RDTSC\n" " --"OPT_PROC_TYPE" Type of this process (primary|secondary|auto)\n" -#ifndef RTE_EXEC_ENV_WINDOWS - " --"OPT_SYSLOG" Set syslog facility\n" -#endif " --"OPT_LOG_LEVEL"= Set global log level\n" " --"OPT_LOG_LEVEL"=:\n" " Set specific log level\n" diff --git a/lib/log/log.c b/lib/log/log.c index 255f757d94..f597da2e39 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -70,12 +70,13 @@ struct log_cur_msg { /* per core log */ static RTE_DEFINE_PER_LCORE(struct log_cur_msg, log_cur_msg); -/* default logs */ - /* Change the stream that will be used by logging system */ int rte_openlog_stream(FILE *f) { + if (rte_logs.file != NULL) + fclose(rte_logs.file); + rte_logs.file = f; return 0; } @@ -505,13 +506,20 @@ rte_log(uint32_t level, uint32_t logtype, const char *format, ...) return ret; } +/* Placeholder */ +int +eal_log_syslog(const char *mode __rte_unused) +{ + return -1; +} + /* - * Called by environment-specific initialization functions. + * Called by rte_eal_init */ void -eal_log_set_default(FILE *default_log) +eal_log_init(const char *id __rte_unused) { - default_log_stream = default_log; + default_log_stream = stderr; #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG RTE_LOG(NOTICE, EAL, @@ -525,8 +533,11 @@ eal_log_set_default(FILE *default_log) void rte_eal_log_cleanup(void) { - if (default_log_stream) { - fclose(default_log_stream); - default_log_stream = NULL; - } + FILE *log_stream = rte_log_get_stream(); + + /* don't close stderr on the application */ + if (log_stream != stderr) + fclose(log_stream); + + rte_logs.file = NULL; } diff --git a/lib/log/log_internal.h b/lib/log/log_internal.h index d5fabd7ef7..3c46328e7b 100644 --- a/lib/log/log_internal.h +++ b/lib/log/log_internal.h @@ -16,12 +16,6 @@ __rte_internal void eal_log_init(const char *id); -/* - * Determine where log data is written when no call to rte_openlog_stream. - */ -__rte_internal -void eal_log_set_default(FILE *default_log); - /* * Save a log option for later. */ diff --git a/lib/log/log_linux.c b/lib/log/log_linux.c deleted file mode 100644 index 6d7dc8f3ab..0000000000 --- a/lib/log/log_linux.c +++ /dev/null @@ -1,102 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * Copyright(c) 2010-2014 Intel Corporation - */ - -#include -#include -#include -#include - -#include -#include - -#include "log_internal.h" - -static int log_facility = LOG_DAEMON; - -static const struct { - const char *name; - int value; -} facilitys[] = { - { "auth", LOG_AUTH }, - { "cron", LOG_CRON }, - { "daemon", LOG_DAEMON }, - { "ftp", LOG_FTP }, - { "kern", LOG_KERN }, - { "lpr", LOG_LPR }, - { "mail", LOG_MAIL }, - { "news", LOG_NEWS }, - { "syslog", LOG_SYSLOG }, - { "user", LOG_USER }, - { "uucp", LOG_UUCP }, - { "local0", LOG_LOCAL0 }, - { "local1", LOG_LOCAL1 }, - { "local2", LOG_LOCAL2 }, - { "local3", LOG_LOCAL3 }, - { "local4", LOG_LOCAL4 }, - { "local5", LOG_LOCAL5 }, - { "local6", LOG_LOCAL6 }, - { "local7", LOG_LOCAL7 }, -}; - -int -eal_log_syslog(const char *name) -{ - unsigned int i; - - for (i = 0; i < RTE_DIM(facilitys); i++) { - if (!strcmp(name, facilitys[i].name)) { - log_facility = facilitys[i].value; - return 0; - } - } - return -1; -} - -/* - * default log function - */ -static ssize_t -console_log_write(__rte_unused void *c, const char *buf, size_t size) -{ - ssize_t ret; - - /* write on stderr */ - ret = fwrite(buf, 1, size, stderr); - fflush(stderr); - - /* Syslog error levels are from 0 to 7, so subtract 1 to convert */ - syslog(rte_log_cur_msg_loglevel() - 1, "%.*s", (int)size, buf); - - return ret; -} - -static int -console_log_close(__rte_unused void *c) -{ - closelog(); - return 0; -} - -static cookie_io_functions_t console_log_func = { - .write = console_log_write, - .close = console_log_close, -}; - -/* - * set the log to default function, called during eal init process, - * once memzones are available. - */ -void -eal_log_init(const char *id) -{ - FILE *log_stream; - - openlog(id, LOG_NDELAY | LOG_PID, log_facility); - - log_stream = fopencookie(NULL, "w+", console_log_func); - if (log_stream != NULL) - eal_log_set_default(log_stream); - else - eal_log_set_default(stderr); -} diff --git a/lib/log/log_windows.c b/lib/log/log_windows.c deleted file mode 100644 index d7c30e4cfa..0000000000 --- a/lib/log/log_windows.c +++ /dev/null @@ -1,22 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * Copyright(c) 2017-2018 Intel Corporation - */ - -#include -#include -#include "log_internal.h" - -int -eal_log_syslog(const char *name __rte_unused) -{ - return -1; /* not used */ -} - -/* set the log to default function, called during eal init process. */ -void -eal_log_init(__rte_unused const char *id) -{ - rte_openlog_stream(stderr); - - eal_log_set_default(stderr); -} diff --git a/lib/log/meson.build b/lib/log/meson.build index 0d4319b36f..891f77a237 100644 --- a/lib/log/meson.build +++ b/lib/log/meson.build @@ -2,8 +2,5 @@ # Copyright(c) 2023 Intel Corporation includes += global_inc -sources = files( - 'log.c', - 'log_' + exec_env + '.c', -) +sources = files('log.c') headers = files('rte_log.h') diff --git a/lib/log/version.map b/lib/log/version.map index 9c6c49bf06..32b9680c31 100644 --- a/lib/log/version.map +++ b/lib/log/version.map @@ -29,7 +29,6 @@ INTERNAL { eal_log_level2str; eal_log_save_pattern; eal_log_save_regexp; - eal_log_set_default; eal_log_syslog; rte_eal_log_cleanup; }; From patchwork Thu Mar 28 23:49:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138976 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 5611343D73; Fri, 29 Mar 2024 00:53:24 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4DE5842D97; Fri, 29 Mar 2024 00:52:27 +0100 (CET) Received: from mail-ot1-f54.google.com (mail-ot1-f54.google.com [209.85.210.54]) by mails.dpdk.org (Postfix) with ESMTP id 91084427E5 for ; Fri, 29 Mar 2024 00:52:16 +0100 (CET) Received: by mail-ot1-f54.google.com with SMTP id 46e09a7af769-6e6a1d24770so854309a34.0 for ; Thu, 28 Mar 2024 16:52:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711669936; x=1712274736; 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=giTdfr+RN6uyZUtqeZRydi6pfOybpgRHCGsV9B26rK/UYq5BQWgez2vL8l/SH/1ej4 AfXen0cI4P9ymnFJsEIdCuHzisD8ynchcJ2hkpbpXHV4zU0IGfiwwcM2DUZhhvkoRavH hSnrWAeLpWV7cH/QZNPScsEfduZTPoPcHSxm5Xn31dYw87SBQNG9scYRjP5TDHMj9uxK X+teupiwZ/NXJzGyQLavONG8Tjc7PfDAQ8G196R4QuSz9Wfu8AcWenSdSWFswk6uTE7r EGiL0cCkknWBrXjSb/eYULOG1xsb3MWYill10NVSluKN01XEfDRddcGosdLDIxCYiWIS kn9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711669936; x=1712274736; 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=Bkpe/8xYjEEPSOVyNPqKx1ClUpsXIo4SZ5ZMK8OqStYoIGUxBYrQOcEl38amrFLOYT 27E1beavSbDbBzNI8t/eckCu2akE7igtuO1j5SO3SWGAkOrw1fgpLVNaWEmo+CFFUMhQ zrQJa4dan0XHhD+UHSWyjXOh0VN4yXrzO33nrgFqbReLO4aa1BzDDV33RcXzeH6JWa76 4KYlMTYoztTU20gVnMtgMyi2vZWJioihorQ34X2a/oBEjpyVBSTV00wj3/sXMGAsc0Uw so1A7GOJHaNRP4gc599MPvgrAA9tZ0TtnykdfHUzEEr+eSOjlFnZbpmV3+QNIPdbvZeO wtlg== X-Gm-Message-State: AOJu0YynSxGquvXsCpUjoRuPGVrZHzM2GeK6f0c8L4+Kt0oAG6uhNYXl YYgZYhb6fpzT2awLz78673vLuG21ex0+V9BNvKlAJukKLE07GBw072bYcoZmKw7pHKHf2EyQ7S0 m X-Google-Smtp-Source: AGHT+IFpJZ40oO6ELHJ6eBVXACsd2se9xYSACfkOn76iiKCNRiAlwsHmnTB9XhGj98oyt0NZDM/VLg== X-Received: by 2002:a05:6870:ac0b:b0:22a:5423:45ff with SMTP id kw11-20020a056870ac0b00b0022a542345ffmr739184oab.40.1711669935927; Thu, 28 Mar 2024 16:52:15 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id g21-20020a631115000000b005df58c83e89sm1875650pgl.84.2024.03.28.16.52.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 16:52:15 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v18 11/15] log: add hook for printing log messages Date: Thu, 28 Mar 2024 16:49:41 -0700 Message-ID: <20240328235156.5768-12-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240328235156.5768-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240328235156.5768-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 Thu Mar 28 23:49:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138977 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 78A8A43D73; Fri, 29 Mar 2024 00:53:31 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0DBEB42DB4; Fri, 29 Mar 2024 00:52:29 +0100 (CET) Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) by mails.dpdk.org (Postfix) with ESMTP id D0DDE427E0 for ; Fri, 29 Mar 2024 00:52:17 +0100 (CET) Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-6ea8a0d1a05so1707750b3a.1 for ; Thu, 28 Mar 2024 16:52:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711669937; x=1712274737; 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=MuuUKuy04wC8oOx2lXEbjzqM5ix5agkbbo8uAghO0J4=; b=WGfDE0l0PSFE+QpBOd5xExs2c5oC+r3zz3HGHwcqAqWKZTF0+jJwu3LZFPPODADSYJ Dk1MKIjZbonAggp1yUrZhLyr9EOiRTca0WGtxfnhHriaPwUUBjzVfyH/yiRpuZ9w5Nls i7RiCAtY/aJR2ABJSu4m+qdE4YCfwbET8GO+P+xByV0GY1kF9mi0HKins0x5UPNxkNGG Ewk46tjgdOkn5bTiagvhf0qUG30rWpwl77n4zFl+LCzFKZO300v7H6P7AlCTyFlDNbHo /XU/s3bUpfIcqiSZAdllSinT9/jDNdNbE+y2AIg0uG/Tusgrh/9MB3BYpxgX+eZO0sbp TP1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711669937; x=1712274737; 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=MuuUKuy04wC8oOx2lXEbjzqM5ix5agkbbo8uAghO0J4=; b=PVjU+vmb9j4WnbhjEGZBb3M13atCAOkYTpOeutTmSpijcc4vLazRXTq130T9GKC77z nZuJ+1LunlElQvVHSpysKoOt84K/Vn1sLFfyYnmS40yauUbhERRruVkfn9OKDXjjJ6Qp 37YteU7gy30Jf+c/eUX2aq9k4V3NChyTzHaWCseW0wv+IkEsD23zbJ67RukpxwsbH9Z1 aLI3WoaW9ZN3uH/RYg2qu/EnV1/iG32cZt91CsfIa/7//LQEuk4yvt4Qyvcp2as46KL3 YgPl4JowtdpRJpP8Ql0Tx5F6LbRf9mdcyTqc9L3xwwUXSt9qg921SsNhduH12E+zp0WM 4duQ== X-Gm-Message-State: AOJu0YyRU/ne445pHJed6ffxf9iIM+4/C8GXY8CJM/wjuuWURHhgVBrs JH6qhHDu/kZou8vmDyvTVfEDFSxm8undlSdk8W1Z+TyHcU+yPx8c+qWJ2Bu28ZZNh5rsXmiaN1R R X-Google-Smtp-Source: AGHT+IH+wTRqBWWGbxwCi/UtQkA7WV1746WEXGMNbudgPGrjpTdqIc9V2P40G6vEcT9ccXeEaa61jg== X-Received: by 2002:a05:6a21:6d94:b0:1a1:6cf3:265b with SMTP id wl20-20020a056a216d9400b001a16cf3265bmr1102518pzb.18.1711669936830; Thu, 28 Mar 2024 16:52:16 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id g21-20020a631115000000b005df58c83e89sm1875650pgl.84.2024.03.28.16.52.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 16:52:16 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Bruce Richardson , Dmitry Kozlyuk , Tyler Retzlaff , Pallavi Kadam Subject: [PATCH v18 12/15] log: add timestamp option Date: Thu, 28 Mar 2024 16:49:42 -0700 Message-ID: <20240328235156.5768-13-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240328235156.5768-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240328235156.5768-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org When debugging driver or startup issues, it is useful to have a timestamp on each message printed. The messages in syslog already have a timestamp, but often syslog is not available during testing. There are multiple timestamp formats similar to Linux dmesg. The default is time relative since startup (when first step of logging initialization is done by constructor). Other alternative formats are delta, ctime, reltime and iso formats. Example: $ dpdk-testpmd --log-timestamp -- -i [ 0.008610] EAL: Detected CPU lcores: 8 [ 0.008634] EAL: Detected NUMA nodes: 1 [ 0.008792] EAL: Detected static linkage of DPDK [ 0.010620] EAL: Multi-process socket /var/run/dpdk/rte/mp_socket [ 0.012618] EAL: Selected IOVA mode 'VA' [ 0.016675] testpmd: No probed ethernet devices Interactive-mode selected Signed-off-by: Stephen Hemminger --- app/test/test_eal_flags.c | 26 ++++ doc/guides/prog_guide/log_lib.rst | 26 ++++ lib/eal/common/eal_common_options.c | 14 ++- lib/eal/common/eal_options.h | 2 + lib/eal/freebsd/eal.c | 6 +- lib/eal/linux/eal.c | 4 +- lib/eal/windows/eal.c | 4 +- lib/log/log.c | 183 +++++++++++++++++++++++++++- lib/log/log_internal.h | 9 ++ lib/log/version.map | 1 + 10 files changed, 268 insertions(+), 7 deletions(-) diff --git a/app/test/test_eal_flags.c b/app/test/test_eal_flags.c index 36e3185a10..e54f6e8b7f 100644 --- a/app/test/test_eal_flags.c +++ b/app/test/test_eal_flags.c @@ -1054,6 +1054,19 @@ test_misc_flags(void) const char * const argv22[] = {prgname, prefix, mp_flag, "--huge-worker-stack=512"}; + /* Try running with --log-timestamp */ + const char * const argv23[] = {prgname, prefix, mp_flag, + "--log-timestamp" }; + + /* Try running with --log-timestamp=iso */ + const char * const argv24[] = {prgname, prefix, mp_flag, + "--log-timestamp=iso" }; + + /* Try running with invalid timestamp */ + const char * const argv25[] = {prgname, prefix, mp_flag, + "--log-timestamp=invalid" }; + + /* run all tests also applicable to FreeBSD first */ if (launch_proc(argv0) == 0) { @@ -1161,6 +1174,19 @@ test_misc_flags(void) printf("Error - process did not run ok with --huge-worker-stack=size parameter\n"); goto fail; } + if (launch_proc(argv23) != 0) { + printf("Error - process did not run ok with --log-timestamp parameter\n"); + goto fail; + } + if (launch_proc(argv24) != 0) { + printf("Error - process did not run ok with --log-timestamp=iso parameter\n"); + goto fail; + } + if (launch_proc(argv25) == 0) { + printf("Error - process did run ok with --log-timestamp=invalid parameter\n"); + goto fail; + } + rmdir(hugepath_dir3); rmdir(hugepath_dir2); diff --git a/doc/guides/prog_guide/log_lib.rst b/doc/guides/prog_guide/log_lib.rst index ff9d1b54a2..504eefe1d2 100644 --- a/doc/guides/prog_guide/log_lib.rst +++ b/doc/guides/prog_guide/log_lib.rst @@ -59,6 +59,32 @@ For example:: Within an application, the same result can be got using the ``rte_log_set_level_pattern()`` or ``rte_log_set_level_regex()`` APIs. +Log timestamp +~~~~~~~~~~~~~ + +An optional timestamp can be added before each message +by adding the ``--log-timestamp`` option. +For example:: + + /path/to/app --log-level=lib.*:debug --log-timestamp + +Multiple timestamp alternative timestamp formats are available: + +.. csv-table:: Log time stamp format + :header: "Format", "Description", "Example" + :widths: 6, 30, 32 + + "ctime", "Unix ctime", "``[Wed Mar 20 07:26:12 2024]``" + "delta", "Offset since last", "``[< 3.162373>]``" + "reltime", "Seconds since last or time if minute changed", "``[ +3.001791]`` or ``[Mar20 07:26:12]``" + "iso", "ISO-8601", "``[2024-03-20T07:26:12−07:00]``" + +To prefix all console messages with ISO format time the syntax is:: + + /path/to/app --log-timestamp=iso + + + Using Logging APIs to Generate Log Messages ------------------------------------------- diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index 9ab512e8a1..5173835c2c 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -74,6 +74,7 @@ eal_long_options[] = { {OPT_IOVA_MODE, 1, NULL, OPT_IOVA_MODE_NUM }, {OPT_LCORES, 1, NULL, OPT_LCORES_NUM }, {OPT_LOG_LEVEL, 1, NULL, OPT_LOG_LEVEL_NUM }, + {OPT_LOG_TIMESTAMP, 2, NULL, OPT_LOG_TIMESTAMP_NUM }, {OPT_TRACE, 1, NULL, OPT_TRACE_NUM }, {OPT_TRACE_DIR, 1, NULL, OPT_TRACE_DIR_NUM }, {OPT_TRACE_BUF_SIZE, 1, NULL, OPT_TRACE_BUF_SIZE_NUM }, @@ -1616,6 +1617,7 @@ eal_log_level_parse(int argc, char * const argv[]) switch (opt) { case OPT_LOG_LEVEL_NUM: case OPT_SYSLOG_NUM: + case OPT_LOG_TIMESTAMP_NUM: if (eal_parse_common_option(opt, optarg, internal_conf) < 0) return -1; break; @@ -1843,7 +1845,7 @@ eal_parse_common_option(int opt, const char *optarg, break; #endif - case OPT_LOG_LEVEL_NUM: { + case OPT_LOG_LEVEL_NUM: if (eal_parse_log_level(optarg) < 0) { EAL_LOG(ERR, "invalid parameters for --" @@ -1851,7 +1853,14 @@ eal_parse_common_option(int opt, const char *optarg, return -1; } break; - } + + case OPT_LOG_TIMESTAMP_NUM: + if (eal_log_timestamp(optarg) < 0) { + EAL_LOG(ERR, "invalid parameters for --" + OPT_LOG_TIMESTAMP); + return -1; + } + break; #ifndef RTE_EXEC_ENV_WINDOWS case OPT_TRACE_NUM: { @@ -2216,6 +2225,7 @@ eal_common_usage(void) " --"OPT_LOG_LEVEL"=:\n" " Set specific log level\n" " --"OPT_LOG_LEVEL"=help Show log types and levels\n" + " --"OPT_LOG_TIMESTAMP"[=] Timestamp log output\n" #ifndef RTE_EXEC_ENV_WINDOWS " --"OPT_TRACE"=\n" " Enable trace based on regular expression trace name.\n" diff --git a/lib/eal/common/eal_options.h b/lib/eal/common/eal_options.h index f3f2e104f6..e24c9eca53 100644 --- a/lib/eal/common/eal_options.h +++ b/lib/eal/common/eal_options.h @@ -35,6 +35,8 @@ enum { OPT_LCORES_NUM, #define OPT_LOG_LEVEL "log-level" OPT_LOG_LEVEL_NUM, +#define OPT_LOG_TIMESTAMP "log-timestamp" + OPT_LOG_TIMESTAMP_NUM, #define OPT_TRACE "trace" OPT_TRACE_NUM, #define OPT_TRACE_DIR "trace-dir" diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index 55ff27a4da..662a829ce8 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -392,8 +392,10 @@ eal_parse_args(int argc, char **argv) goto out; } - /* eal_log_level_parse() already handled these */ - if (opt == OPT_LOG_LEVEL_NUM || opt == OPT_LOG_SYSLOG_NUM) + /* eal_log_level_parse() already handled these options */ + if (opt == OPT_LOG_LEVEL_NUM || + opt == OPT_SYSLOG_NUM || + opt == OPT_LOG_TIMESTAMP_NUM) continue; ret = eal_parse_common_option(opt, optarg, internal_conf); diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index b9a0fb1742..8cbea480e0 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -611,7 +611,9 @@ eal_parse_args(int argc, char **argv) } /* eal_log_level_parse() already handled these options */ - if (opt == OPT_LOG_LEVEL_NUM || opt == OPT_SYSLOG_NUM) + if (opt == OPT_LOG_LEVEL_NUM || + opt == OPT_SYSLOG_NUM || + opt == OPT_LOG_TIMESTAMP_NUM) continue; ret = eal_parse_common_option(opt, optarg, internal_conf); diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c index e59aba954e..b251dc3e1b 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 Thu Mar 28 23:49:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138979 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 0851343D73; Fri, 29 Mar 2024 00:53:46 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 15A1642DBD; Fri, 29 Mar 2024 00:52:33 +0100 (CET) Received: from mail-oo1-f49.google.com (mail-oo1-f49.google.com [209.85.161.49]) by mails.dpdk.org (Postfix) with ESMTP id E1D9342B71 for ; Fri, 29 Mar 2024 00:52:19 +0100 (CET) Received: by mail-oo1-f49.google.com with SMTP id 006d021491bc7-5a4a2d99598so840667eaf.2 for ; Thu, 28 Mar 2024 16:52:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711669939; x=1712274739; 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=GvIiQ00/+ZWT077nwyatKCF+plHPu2a/G6R1AK5lzAo=; b=Fm92+UCGMVE0FlJ4tsAUI8hu4VBic72JTDRBuFC1J7SiSvmXJ8r4WprTqRAC98fjpw V67z9jvoowR4vH59kk6IYZFDzsa+6pgJZWRJJYXhe3nshu6GiXkBvHiedFVyBjz3DCVr 3zDOrH0tAN63cBSPLeg0Q1JUhCWI8maLyWtf4+3w5jyJhxz7zwvnyqXsGHvJzaHEeZN2 bqjc6SuxPuWqddpWcNHiz1hD7kywYGDlzTTyXhW24RDXR1lr1NbTEG2OQqaq9NLrHKkk aGTSwTUVLJijs8zDuDI1j9f3E//IVP9f8i1ukLH+YOKIicdG72v3h1kjS8nyvY3DsVul 5YbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711669939; x=1712274739; 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=GvIiQ00/+ZWT077nwyatKCF+plHPu2a/G6R1AK5lzAo=; b=G9xHGuNBuwBCvcvf4eCi1Jjdtb4rSv4go0ISF0Ymz902ikhAPz/gV6Ut1Qjy1zY4dX R7t6jlLYfv9I/uEVWJKcbOg3fiGM5RKeM7T6SICcH+q71b7UuxnsRK5r5qmy/F33QpMp uqLxa1shGd6A2YRygIHzIIP6Gq/w7Mq01ExjAlU3ueEjTeQ7++mkIAxzk60OAtwJAZnT lB37Y8sDHPDNKSgPxUKqfFMLC6CQidtNWk9UOgN0xiIIc1mqguihr2sdP7QeuqAWXaz8 YMuj/0JqHPIDabXPRCYs0zqk9hcejqZoMpRfLKkDbxD14hS44RGqRGLfsJ//YcwAD9jl zhRA== X-Gm-Message-State: AOJu0Yy4EAgGff2yMtM9D4591pD5Sz1omuJgOIGD7q5LUyZUcM+wRQYw UlcXaG+4MkDFnOuv2KLGI141+HSye/EB4oeFwXZmGYbqodReAK1/qsbGmKwmTTsWk95VFcs545y N X-Google-Smtp-Source: AGHT+IEnNEXmC6foRHGbfZPaamX2kLV7zBcjOq5rJyWpCzNthV360jk8W5rZE9Hm6B8/yf5rp31H1g== X-Received: by 2002:a05:6358:5316:b0:183:645b:cf87 with SMTP id n22-20020a056358531600b00183645bcf87mr1007543rwf.17.1711669937634; Thu, 28 Mar 2024 16:52:17 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id g21-20020a631115000000b005df58c83e89sm1875650pgl.84.2024.03.28.16.52.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 16:52:17 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v18 13/15] log: add optional support of syslog Date: Thu, 28 Mar 2024 16:49:43 -0700 Message-ID: <20240328235156.5768-14-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240328235156.5768-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240328235156.5768-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Log to syslog only if option is specified. And if syslog is used then normally only log to syslog, don't duplicate output. Also enables syslog support on FreeBSD. Signed-off-by: Stephen Hemminger --- app/test/test_eal_flags.c | 5 +- doc/guides/linux_gsg/linux_eal_parameters.rst | 27 ---- doc/guides/prog_guide/log_lib.rst | 17 +++ lib/eal/common/eal_common_options.c | 5 +- lib/log/log.c | 121 ++++++++++++++++-- 5 files changed, 137 insertions(+), 38 deletions(-) diff --git a/app/test/test_eal_flags.c b/app/test/test_eal_flags.c index e54f6e8b7f..08f4866461 100644 --- a/app/test/test_eal_flags.c +++ b/app/test/test_eal_flags.c @@ -987,9 +987,10 @@ test_misc_flags(void) /* With empty --syslog */ const char *argv3[] = {prgname, prefix, mp_flag, "--syslog"}; /* With valid --syslog */ - const char *argv4[] = {prgname, prefix, mp_flag, "--syslog", "always"}; + const char *argv4[] = {prgname, prefix, mp_flag, "--syslog=both"}; /* With invalid --syslog */ - const char *argv5[] = {prgname, prefix, mp_flag, "--syslog", "error"}; + const char *argv5[] = {prgname, prefix, mp_flag, "--syslog=invalid"}; + /* With no-sh-conf, also use no-huge to ensure this test runs on BSD */ const char *argv6[] = {prgname, "-m", DEFAULT_MEM_SIZE, no_shconf, nosh_prefix, no_huge}; diff --git a/doc/guides/linux_gsg/linux_eal_parameters.rst b/doc/guides/linux_gsg/linux_eal_parameters.rst index ea8f381391..d86f94d8a8 100644 --- a/doc/guides/linux_gsg/linux_eal_parameters.rst +++ b/doc/guides/linux_gsg/linux_eal_parameters.rst @@ -108,30 +108,3 @@ Memory-related options * ``--match-allocations`` Free hugepages back to system exactly as they were originally allocated. - -Other options -~~~~~~~~~~~~~ - -* ``--syslog `` - - Set syslog facility. Valid syslog facilities are:: - - auth - cron - daemon - ftp - kern - lpr - mail - news - syslog - user - uucp - local0 - local1 - local2 - local3 - local4 - local5 - local6 - local7 diff --git a/doc/guides/prog_guide/log_lib.rst b/doc/guides/prog_guide/log_lib.rst index 504eefe1d2..abaedc7212 100644 --- a/doc/guides/prog_guide/log_lib.rst +++ b/doc/guides/prog_guide/log_lib.rst @@ -83,6 +83,23 @@ To prefix all console messages with ISO format time the syntax is:: /path/to/app --log-timestamp=iso +Log output +~~~~~~~~~~ + +If desired, messages can be redirected to syslog (on Linux and FreeBSD) with the ``--syslog`` +option. There are three possible settings for this option: + +*always* + Redirect all log output to syslog. + +*auto* + Use console if it is a terminal, and use syslog if is not. + +*both* + Print to both console and syslog. + +If ``--syslog`` option is not specified, then only console (stderr) will be used. + Using Logging APIs to Generate Log Messages diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index 5173835c2c..9ca7db04aa 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 }, @@ -2221,6 +2221,9 @@ eal_common_usage(void) " (can be used multiple times)\n" " --"OPT_VMWARE_TSC_MAP" Use VMware TSC map instead of native RDTSC\n" " --"OPT_PROC_TYPE" Type of this process (primary|secondary|auto)\n" +#ifndef RTE_EXEC_ENV_WINDOWS + " --"OPT_SYSLOG"[=] Enable use of syslog\n" +#endif " --"OPT_LOG_LEVEL"= Set global log level\n" " --"OPT_LOG_LEVEL"=:\n" " Set specific log level\n" diff --git a/lib/log/log.c b/lib/log/log.c index 2dca91306e..ec0d55273e 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,95 @@ log_print_with_timestamp(FILE *f, uint32_t level, return log_print(f, level, format, ap); } +#ifndef RTE_EXEC_ENV_WINDOWS +static bool +using_syslog(bool is_terminal) +{ + switch (rte_logs.syslog_opt) { + default: + return false; + + case EAL_LOG_SYSLOG_ALWAYS: + case EAL_LOG_SYSLOG_BOTH: + return true; + + case EAL_LOG_SYSLOG_AUTO: + return !is_terminal; + } +} + /* - * 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, +}; + +static void +log_open_syslog(const char *id, bool 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; +} +#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 (using_syslog(is_terminal)) { + log_open_syslog(id, is_terminal); + 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 Thu Mar 28 23:49:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138978 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 DA98943D73; Fri, 29 Mar 2024 00:53:38 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4698341151; Fri, 29 Mar 2024 00:52:31 +0100 (CET) Received: from mail-oo1-f49.google.com (mail-oo1-f49.google.com [209.85.161.49]) by mails.dpdk.org (Postfix) with ESMTP id 36486427E0 for ; Fri, 29 Mar 2024 00:52:19 +0100 (CET) Received: by mail-oo1-f49.google.com with SMTP id 006d021491bc7-5a56a5f597dso912848eaf.2 for ; Thu, 28 Mar 2024 16:52:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711669938; x=1712274738; 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=46SG9RLhZSJQXgtr6/M3XC3YSSvsoh/NwdGR6vHqARE=; b=UhKcPzqjuPFcSmzWzNLJ25il3HdtOBi8hXrv7NgoGErV93Gyt6WUrpEmEOiJde+unl ci9t2kMve9KJ2tbIxaa44MUNGlRLGn0G8byrTXB6VVC27VSu+V/yDjJ02BylJAQnxm4t BAWFoeko4RKFx51DIf+TP+kJK2Cm1WuDRSJdbKfJ8QhKtwKJ00KBvzLQJ9jGIIZJRHYb vcBnBPVrZPhx23QYZ5a4SU6FZ85QJRhQb/SiqFqntc5XKyTnbvG7nB2qUIbDWz0z5Toc eZzkRtMhyrr3sdXsrUpwT+23zp3iN2PR65XUZRmunsV/VH6HHq6hMZyDSbXOyhONQyki FWaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711669938; x=1712274738; 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=46SG9RLhZSJQXgtr6/M3XC3YSSvsoh/NwdGR6vHqARE=; b=FdDUGyUanVXYxDGLCU9+sN8LP1V/cUZavX9nHsh6FYJQjCcFr66ZPtJbG+ndjk4yeA CukEqC2S/bDShsbFztmUyM7tyzh6Tuyw7eTwMzOE9xItdpU6m+oulGMsXLgKVPzFbrjT EVnOmJbs/s7+hqyaoKP5c5IcvvBbrf9Kcb1aIlhcF+ARSRulFlE0HOonzCIYPVMbMRBU 2ZVnXOZwgo4C1uMx72+N331lO29PJD0RL0tnsVUqlsP1YChEUKrtzXGebBD6DjJbTgK8 xa5VbXq2oU637r66puT5vwKjSl7wY2c5/z3LIIGgjRV6K1dfm7Z0wpp6XEak8cPzEYKo RAMg== X-Gm-Message-State: AOJu0Yw6JpSGNAjfWemuvDZZk33oov+qfPZlLlGGciCFp9jFMJLCP9Fv SOoBQ+C6gpFEQItqLYfYjSbw4pBPTyelMA9B34tswX8MdmCuimbUkHs12ZEjTAx6eS8r1hTmFV7 l X-Google-Smtp-Source: AGHT+IFu1b7IW+GTHnB11Y7ksoNjjN6ZX49pKVJJ94bSD/48ntdJ1dbNkVYSUsjJyZNf9COzP0sHgg== X-Received: by 2002:a05:6358:590e:b0:17f:5ef7:1579 with SMTP id g14-20020a056358590e00b0017f5ef71579mr1093713rwf.12.1711669938493; Thu, 28 Mar 2024 16:52:18 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id g21-20020a631115000000b005df58c83e89sm1875650pgl.84.2024.03.28.16.52.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 16:52:18 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v18 14/15] log: add support for systemd journal Date: Thu, 28 Mar 2024 16:49:44 -0700 Message-ID: <20240328235156.5768-15-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240328235156.5768-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240328235156.5768-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 | 154 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 152 insertions(+), 2 deletions(-) diff --git a/lib/log/log.c b/lib/log/log.c index ec0d55273e..650d294120 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; @@ -775,6 +780,138 @@ static cookie_io_functions_t syslog_log_func = { .close = syslog_log_close, }; +/* + * send message using journal protocol to journald + */ +static int +journal_send(uint32_t level, const char *buf, size_t len) +{ + struct iovec iov[3]; + char msg[] = "MESSAGE="; + char prio[32]; + int ret; + + iov[0].iov_base = msg; + iov[0].iov_len = strlen(msg); + + iov[1].iov_base = (char *)(uintptr_t)buf; + iov[1].iov_len = len; + + /* priority value between 0 ("emerg") and 7 ("debug") */ + iov[2].iov_base = prio; + iov[2].iov_len = snprintf(prio, sizeof(prio), + "PRIORITY=%i\n", level - 1); + + ret = writev(rte_logs.journal_fd, iov, 3); + return ret; +} + +__rte_format_printf(3, 0) +static int +journal_print(FILE *f __rte_unused, uint32_t level, const char *format, va_list ap) +{ + char buf[BUFSIZ]; + size_t len; + + len = vsnprintf(buf, sizeof(buf), format, ap); + if (len == 0) + return 0; + + /* check for truncation */ + if (len >= sizeof(buf) - 1) + len = sizeof(buf) - 1; + + /* check that message ends with newline, if not add one */ + if (buf[len - 1] != '\n') + buf[len++] = '\n'; + + return journal_send(level, buf, len); +} + +/* wrapper for log stream to put messages into journal */ +static ssize_t +journal_log_write(__rte_unused void *c, const char *buf, size_t size) +{ + return journal_send(rte_log_cur_msg_loglevel(), buf, size); +} + +static cookie_io_functions_t journal_log_func = { + .write = journal_log_write, +}; + +/* + * 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 +is_journal(int fd) +{ + char *jenv, *endp = NULL; + struct stat st; + unsigned long dev, ino; + + jenv = getenv("JOURNAL_STREAM"); + if (jenv == NULL) + return false; + + if (fstat(fd, &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; + + free(syslog_id); + + /* redirect other log messages to journal */ + FILE *log_stream = fopencookie(NULL, "w", journal_log_func); + if (log_stream != NULL) + default_log_stream = log_stream; + + return s; + +error: + free(syslog_id); + close(s); + return -1; +} + static void log_open_syslog(const char *id, bool is_terminal) { @@ -797,11 +934,24 @@ log_open_syslog(const char *id, bool is_terminal) 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 (!is_terminal && is_journal(STDERR_FILENO)) { + 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 (using_syslog(is_terminal)) { log_open_syslog(id, is_terminal); return; From patchwork Thu Mar 28 23:49:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138980 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 3D58B43D73; Fri, 29 Mar 2024 00:53:51 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id ABC7342DD5; Fri, 29 Mar 2024 00:52:34 +0100 (CET) Received: from mail-oo1-f45.google.com (mail-oo1-f45.google.com [209.85.161.45]) by mails.dpdk.org (Postfix) with ESMTP id 305E842D0C for ; Fri, 29 Mar 2024 00:52:20 +0100 (CET) Received: by mail-oo1-f45.google.com with SMTP id 006d021491bc7-5a4a102145fso756729eaf.3 for ; Thu, 28 Mar 2024 16:52:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711669939; x=1712274739; 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=8y4fO2IxafOGdKbX1uE26QnkEVjNCqSc9vkZoCMYRwo=; b=JE8sZVrL2PAykGsONTEQ57qO37dRcQP7Zp9i9jjtnur34xIC6Bp+FbgJISX7J4FWXO 1elG7fzYawIo94xQqqfrmQ1+9PMGch5ySvVWPWB2GfqE9uIMUcjCHevGN/D4acxZleLJ 0SMqGbhTZyooWzkq41t9sjiT0nDWNAg9teyFN9jIyZweIoQZ7p0bP4VPmw3PTb4DUrm8 crRf8XG5WG73r83AqMVMqCX38MaPdgsih3pVhxDP93gKRvO4dUAvFtZfm96Nx9bY2WgB yVFASa+kYWL6uWzX5D95aLq72xj8GIjFzvM95j2XpFOnnDoL5tXF3q1G182YuV3jEJii dvhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711669939; x=1712274739; 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=8y4fO2IxafOGdKbX1uE26QnkEVjNCqSc9vkZoCMYRwo=; b=SNt5VMAzyChz2X67eCjeISJb/qqch7/7Aaxn2po597NceB2/AkKrLYt8DnDVf1rBBQ DvPpYZ7mVueFzNkFu4U/WfqBHpaohr/NbRi18GCLXXNxWrwlwVPWbQcz2+lnYFpx363l JCJ8LT0qnxRYoPAhyX5CbcwoBdSBJiCIJuwjz8kp7UF94uH1+J15dvVjNYW76OXPOTwB ztSZiS26ovcYTONaljPotVeiKc208Hqn3QQexw+aH0BMzuF8HNE5KyzD0FErRMvUJ1mI vzSqzxbxo0DFVB9Eadn+KEvTM3/TxqPMLmrKmwU3YRFBxIZ+GkN6yNafc4VMTa2e61tG W3Hg== X-Gm-Message-State: AOJu0YwzdMRyuYnvqRWdjX9pO7vK4wR+ggyizZ9g8ygpV9xCvoj+IlpM HGe0EDr0FSHZxNVr+YdVyRg77dLNHpgz/mLTQWLNqpLkUCfZqJJT9uEsjoZgCsKOvtUYFVdt+eI 4 X-Google-Smtp-Source: AGHT+IHUHSdG4Mp8DjkFzplUhdqP7PuxwwTbuOrb3fmzbWek0toR5vkD23P/DVD4BzwMBFpSiH/afQ== X-Received: by 2002:a05:6359:4ca8:b0:17c:2ce0:f55 with SMTP id kk40-20020a0563594ca800b0017c2ce00f55mr808353rwc.19.1711669939304; Thu, 28 Mar 2024 16:52:19 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id g21-20020a631115000000b005df58c83e89sm1875650pgl.84.2024.03.28.16.52.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 16:52:18 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v18 15/15] log: colorize log output Date: Thu, 28 Mar 2024 16:49:45 -0700 Message-ID: <20240328235156.5768-16-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240328235156.5768-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240328235156.5768-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 --- app/test/test_eal_flags.c | 24 ++++ doc/guides/prog_guide/log_lib.rst | 16 ++- lib/eal/common/eal_common_options.c | 11 ++ lib/eal/common/eal_options.h | 2 + lib/log/log.c | 168 +++++++++++++++++++++++++++- lib/log/log_internal.h | 5 + lib/log/version.map | 1 + 7 files changed, 223 insertions(+), 4 deletions(-) diff --git a/app/test/test_eal_flags.c b/app/test/test_eal_flags.c index 08f4866461..c6c05e2e1d 100644 --- a/app/test/test_eal_flags.c +++ b/app/test/test_eal_flags.c @@ -1067,6 +1067,18 @@ test_misc_flags(void) const char * const argv25[] = {prgname, prefix, mp_flag, "--log-timestamp=invalid" }; + /* Try running with --log-color */ + const char * const argv26[] = {prgname, prefix, mp_flag, + "--log-color" }; + + /* Try running with --log-color=never */ + const char * const argv27[] = {prgname, prefix, mp_flag, + "--log-color=never" }; + + /* Try running with --log-color=invalid */ + const char * const argv28[] = {prgname, prefix, mp_flag, + "--log-color=invalid" }; + /* run all tests also applicable to FreeBSD first */ @@ -1187,6 +1199,18 @@ test_misc_flags(void) printf("Error - process did run ok with --log-timestamp=invalid parameter\n"); goto fail; } + if (launch_proc(argv26) != 0) { + printf("Error - process did not run ok with --log-color parameter\n"); + goto fail; + } + if (launch_proc(argv27) != 0) { + printf("Error - process did not run ok with --log-color=none parameter\n"); + goto fail; + } + if (launch_proc(argv28) == 0) { + printf("Error - process did run ok with --log-timestamp=invalid parameter\n"); + goto fail; + } rmdir(hugepath_dir3); 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 9ca7db04aa..5e7ab29ae3 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, 2, 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 }, @@ -1618,6 +1619,7 @@ eal_log_level_parse(int argc, char * const argv[]) case OPT_LOG_LEVEL_NUM: case OPT_SYSLOG_NUM: case OPT_LOG_TIMESTAMP_NUM: + case OPT_LOG_COLOR_NUM: if (eal_parse_common_option(opt, optarg, internal_conf) < 0) return -1; break; @@ -1862,6 +1864,14 @@ eal_parse_common_option(int opt, const char *optarg, } break; + case OPT_LOG_COLOR_NUM: + if (eal_log_color(optarg) < 0) { + EAL_LOG(ERR, "invalid parameters for --" + OPT_LOG_COLOR); + return -1; + } + break; + #ifndef RTE_EXEC_ENV_WINDOWS case OPT_TRACE_NUM: { if (eal_trace_args_save(optarg) < 0) { @@ -2229,6 +2239,7 @@ eal_common_usage(void) " Set specific log level\n" " --"OPT_LOG_LEVEL"=help Show log types and levels\n" " --"OPT_LOG_TIMESTAMP"[=] Timestamp log output\n" + " --"OPT_LOG_COLOR"[=] Colorize log messages\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 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 650d294120..75c5e2af78 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,76 @@ 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 +}; + +/* Standard terminal escape codes for colors and bold */ +static const char * const color_code[] = { + [COLOR_NONE] = "", + [COLOR_RED] = "\033[31m", + [COLOR_GREEN] = "\033[32m", + [COLOR_YELLOW] = "\033[33m", + [COLOR_BLUE] = "\033[34m", + [COLOR_MAGENTA] = "\033[35m", + [COLOR_CYAN] = "\033[36m", + [COLOR_WHITE] = "\033[37m", + [COLOR_BOLD] = "\033[1m", + [COLOR_CLEAR] = "\033[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]); + va_end(args); + + 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 @@ -930,14 +1008,87 @@ log_open_syslog(const char *id, bool is_terminal) } #endif +__rte_format_printf(3, 0) +static int +color_print(FILE *f, uint32_t level, const char *format, va_list ap) +{ + char *buf = NULL; + int ret; + + /* need to make temporary buffer for color scan */ + ret = vasprintf(&buf, format, ap); + if (ret > 0) { + ret = color_log_write(f, level, buf); + free(buf); + return ret; + } + + /* 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; + #ifdef RTE_EXEC_ENV_WINDOWS RTE_SET_USED(id); + + is_terminal = _isatty(_fileno(stderr)); #else - bool is_terminal = isatty(STDERR_FILENO); + is_terminal = isatty(STDERR_FILENO); /* If stderr is redirected to systemd journal then upgrade */ if (!is_terminal && is_journal(STDERR_FILENO)) { @@ -957,8 +1108,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;