From patchwork Sat Mar 30 03:00: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: 138981 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 A213043D8B; Sat, 30 Mar 2024 04:04:43 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E80B9402C6; Sat, 30 Mar 2024 04:04:42 +0100 (CET) Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by mails.dpdk.org (Postfix) with ESMTP id BC64A402C3 for ; Sat, 30 Mar 2024 04:04:41 +0100 (CET) Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-6e703e0e5deso2065242b3a.3 for ; Fri, 29 Mar 2024 20:04:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711767881; x=1712372681; 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=TrbyCUkQahAsp7quxJ8Q+iazOouOsY2LVkbBTCDCj5ryd5f3QDcRtqFrnYADKax4y8 lRB5L950DqkOkQSy3NZatSbLUGbMF+xcsldWl/TTy0Wti1aRz6FSKsEEkUmnzzGjwPth KDHP87AJnvYRnePhiNaApX7POE07Kfp89oVO+5x/9/OqObPrUZlfG99c7YuEqlqOXyOr TWTJuzk+4RaxtkyVeYdKQnEylMmfgkuz4o+OmpxjqSxIDGDElf2vHRIKIqzOiIMQTA21 3ZlUsUz9GryxxMoOp4w5VLbP5dXJL5VCI8aS/KgeozwdXW7bHE9UfhAKB/Dk94cJfziq 4eNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711767881; x=1712372681; 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=ASTCfie8GJRxQ5bkQpBIaeZRjClwsdJkiAAjXjiHP6JQZbhBKv+bhDWOHlZumrIj9r lSEx/PahUQehgS0JlEKiDHlhCfimFFu+03k3yUlTN2LlD2/O0a2NN4i0TPeDsTfGlaqt IE4b3I8ZgHJy+OBm8RDGXgf7Ib0+/QRGj4HtGX1BC8QqLgezZHj+3zJ3VffEBPFljMvr XsvUjzPw+kIxJ1F/n904cxa9zBnVzHKUtLsRWRQsHg1YFghwzNZfAL9dl4UPUl9leQC5 aSg0iewGhzOCBhIMcOs17ZqCFlxhiU/il29J5nids3ChTq9/OE9N3fLJS8kTy2D3lWUJ bxXw== X-Gm-Message-State: AOJu0YxSewGTsLv6rE8Di841Vv5RH+Rpkpt6uG9pq6PicOIKgDWkPzuB UWNA7hRw1OvPRMCqrAkD//5yIyZu+EoY5ln7OxzVTUjh9B3zpvIVKznK1JMeyjKT8GzEi853Hof 3 X-Google-Smtp-Source: AGHT+IFCTLwP6pitgwiHMjAyZ8oedma2zqieNE8sN8pWnOKZ6GBcadxfvsXTdORLCKf4SttZgBUd9Q== X-Received: by 2002:a05:6a00:14ca:b0:6ea:baed:a136 with SMTP id w10-20020a056a0014ca00b006eabaeda136mr4349464pfu.8.1711767880759; Fri, 29 Mar 2024 20:04:40 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id o3-20020a056a00214300b006e6288ef4besm3655486pfk.54.2024.03.29.20.04.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 20:04:40 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff , Thomas Monjalon Subject: [PATCH v19 01/15] maintainers: add for log library Date: Fri, 29 Mar 2024 20:00:44 -0700 Message-ID: <20240330030429.4630-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240330030429.4630-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240330030429.4630-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 Sat Mar 30 03:00: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: 138982 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 C8C1843D8B; Sat, 30 Mar 2024 04:04:54 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8844840647; Sat, 30 Mar 2024 04:04:47 +0100 (CET) Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by mails.dpdk.org (Postfix) with ESMTP id 5F593402C3 for ; Sat, 30 Mar 2024 04:04:42 +0100 (CET) Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-6e88e4c8500so2009399b3a.2 for ; Fri, 29 Mar 2024 20:04:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711767881; x=1712372681; 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=p3plLGrS0dNmlQomvEWTynIMnCllWBx7Q9Ctum5QKWVaESV3NAiCLNI0LIwfp03Z7q kCU2ra08jM0GKU9q9k5OWPzFx/HR8W0OXJmVgbGZ0S868mTVHNv84yb/XwGP8UPoDzv7 W72ecj3JsHDN8+gQXuEqszw6aeePPwpEfbopLuZVOZH14cK3l5GXVMkAx2qBNGRekV55 H5kc1R6gdkQ/LDsYo0V9Mn0uOJwe5W6mno+z+U9JWNgqzk4sbPkmnY1eVfStR9Ezoi4z QVa9NTDrOVaBjX5fpz02ILJ2WCHW/B0dmrUMr3S9p/IVDh2Z4UAkr/nakQW3YThHK4VF dfvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711767881; x=1712372681; 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=LkUsG+IckrjUTTKUAZYQoqnPR6oBFjPNpfuUB4z9/enfyMJB/Eh5Kdl34aUVVfswT6 8OrjQoshEj/kqNGoX53gVrGR+EvoOHtaFGfcRdzNkSoq9YJjyB3vHn/cPJTXsIQPpOoU m95zB8e3hr7NICHng4ug60zODESThi3RmdCwLpl4zU3rBFLGgsDPVyfj1Nvx/baGweKD R4iAny1782J/Y0kRBP2PLzlWJbEl4OoqNcxGeqaJL7mhwsNCNBdDAIP0M2Ji5IdLZLyt +bxt8TdF/7Gk7ujT2L92K75cqBKUHi5f2UPnpqwLfMV6vI75EeT0oG0IaGNgpmcRe8Za 1PNQ== X-Gm-Message-State: AOJu0Yx2pIgp9VVn5tdGr+epTeDTltT0yoz3Lr18qQGxg6gCEPHEOtbw sHvw/TUBKrsESkf7PuS46G+ftDZlLZcWE8aHyzRY9hR8oelGUsmNeFyMBxSCqgmZ35exqazLF4C n X-Google-Smtp-Source: AGHT+IGsBtqcThx5BW03iXzFpqgqykwBkVGY8HwM4xDrLkgirhu18S2Dxxm0UMR3oA1rzdJNEuOaJw== X-Received: by 2002:a05:6a00:1ca2:b0:6ea:f3fe:321c with SMTP id y34-20020a056a001ca200b006eaf3fe321cmr1075083pfw.19.1711767881627; Fri, 29 Mar 2024 20:04:41 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id o3-20020a056a00214300b006e6288ef4besm3655486pfk.54.2024.03.29.20.04.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 20:04:41 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff , Dmitry Kozlyuk , Pallavi Kadam Subject: [PATCH v19 02/15] windows: make getopt functions have const properties Date: Fri, 29 Mar 2024 20:00:45 -0700 Message-ID: <20240330030429.4630-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240330030429.4630-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240330030429.4630-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 Sat Mar 30 03:00:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138983 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 B2DF743D8B; Sat, 30 Mar 2024 04:05:01 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CFB5840698; Sat, 30 Mar 2024 04:04:48 +0100 (CET) Received: from mail-oa1-f48.google.com (mail-oa1-f48.google.com [209.85.160.48]) by mails.dpdk.org (Postfix) with ESMTP id 37D17402C9 for ; Sat, 30 Mar 2024 04:04:43 +0100 (CET) Received: by mail-oa1-f48.google.com with SMTP id 586e51a60fabf-22a8df1df8fso1428402fac.2 for ; Fri, 29 Mar 2024 20:04:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711767882; x=1712372682; 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=BJGpkraAY/jYHdd07BpbtgoAqg5aFA+AsXyF0a73U9Jrl+vKSOq565hD44t7Unxr6i ahEHxP3CHo7rZNqtOntk8RK0RUrBTtsl3r9Rh5qCIh4ocsO9B1DcZVCRT4AqhXfzV/L/ ZDyV+uM2JKMo/0LRbP+GAWafiy1O4d4PcpAvbMyYipelo2tDGQYkEGrq75gcs9m9i7Uy cBzIKBNlb/Uh120sbjmm0cKrWTj7aW0ashwCrVuNbzdyOu0cMx29yM5nSpyFJ/iP0pEV YUojaAUP2GlSRftl18GArv3d/eKGFzUazVv/QEdAx5A7Fish5xEipIn68/KsvwBCKTSw hhaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711767882; x=1712372682; 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=PFzpD/vKbVdrXIvAxyWZAPJOW0pWIWRcwmI/hvgWhb6MicVFOUdmhFNWD23qvtrSLQ BgheKTvwPfW1zzW53l1AsT/rUKcGKDplZKP3FORB1CJgS25asPoejmZYhyh01Skx3rcY UKa9CRiYQjdepdfgcPF8vzfMXHOINzAQx0DI+gQUayPp/pCyhnGDxPPAh8IdYHIWac3c a4dhVE17nUvGvONAyyLDe5tlrE9OblUR1iN46cz0dwsuGDo/siogbtV8icpAISqyYZ3f QCCyfT7obUi3dqom6O9I9hHoeYsd/uceujQvqYpgXRX30H9q30A3BV9JVZ4FKNkQbVhn XByQ== X-Gm-Message-State: AOJu0Yw47xT407m4bpaW0rF6NlAGKM07GffMyHm2GtUuTNb1hTrDTfEA ewuZyLsqlrzBVurskMnh+EWwTBxn82wQVsNUuaNEWgnCoAupPH/7erVyklVgEGd5zTDhOIA3p19 l X-Google-Smtp-Source: AGHT+IEH+nGUmvDdVYDG+ufjYA1PQ2eWJJz75onORJmLSx1EMojjFemfKnzEXDSTxm2+gNFnDEovBQ== X-Received: by 2002:a05:6870:1697:b0:229:f61d:7e52 with SMTP id j23-20020a056870169700b00229f61d7e52mr4408908oae.34.1711767882500; Fri, 29 Mar 2024 20:04:42 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id o3-20020a056a00214300b006e6288ef4besm3655486pfk.54.2024.03.29.20.04.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 20:04:42 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff , Dmitry Kozlyuk , Pallavi Kadam Subject: [PATCH v19 03/15] windows: add os shim for localtime_r Date: Fri, 29 Mar 2024 20:00:46 -0700 Message-ID: <20240330030429.4630-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240330030429.4630-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240330030429.4630-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 Sat Mar 30 03:00:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138984 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 2FD4743D8B; Sat, 30 Mar 2024 04:05:09 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3DEEB40A6B; Sat, 30 Mar 2024 04:04:50 +0100 (CET) Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) by mails.dpdk.org (Postfix) with ESMTP id 712C3402EC for ; Sat, 30 Mar 2024 04:04:44 +0100 (CET) Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-5d81b08d6f2so1835711a12.0 for ; Fri, 29 Mar 2024 20:04:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711767883; x=1712372683; 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=bxw4jAAaqsxGku4lpq45STN5dgeO8yP8V9jfx/LvUZas6ulotOzX8adyCoc+kcdLqb itYfgxgUwuoJDOsPjHr0CMVMRJHRAJW5/HYdljyHpHh/AUme/E8p/50vmNakIDXBgTFm RY3PDlretEV/dmwF2+3vkq6YxqsRSyE3s7eMruZimTxRZwlvzZ6tU+hHRrf1Y3HHz9oT 8kyu2SpPteWiEj7Dmq8/QmvHH94mLbkk5rHdwePRYoYd16GYAkgxsL8UhG89S0SJt6o+ tEUUfscZutYuj6EHPa5BhgpR9TGFMem2sH6oX8NQGpu8yIyykFuUjE6mYA/IQIioj8so gGKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711767883; x=1712372683; 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=UxZGgaHlFJnrazj5rydLra4nuIYFXWVQSJnIpOf3SLIikWcJzB4SEOl3c+JmqR3Qhv OZvPnD3Ptj8XjGJs/np+OGmGVY1Vc/BphPe2Ref7CbzmZawJ6i3MpFIghMb4KZc9YiMY /SAQg0XsOEKJhpb437PMbXvuFfJYV64BrnDKh2vhEnAutFCZm6cWgfv44XmSZLewSLBL 2XJkpY6EUxQrKgZ8a2cIjLPSnE1+DTaCN5wRRQYoKir2aOxNpDu/GO3s70dczXrTwsZS X7NTiaFvueeM+5JSgQdL3R+t54Xx1uB6Z4nadhabx+5AlwaygzmkLpLr3MsXvpiMW28w GDtg== X-Gm-Message-State: AOJu0Yx4gvh15SpTY/NU0/Dwg2uRW1E9ZVhps9pUb0mwgaB3QsHvIsz7 7rUbYrC6d8ET1j5iMrOtZiBVDR8sTxRYZ0fFXTFsgkLpOCJZNXfTXk3NKCKksccSe6y6B3OHPjm U X-Google-Smtp-Source: AGHT+IE28d8uac5RJFvvGmRYq0jwFucpohQ8dfz9fxkNIe7Kg94Ds8tWEmLCnfxsBTRHK/TRO79Esw== X-Received: by 2002:a05:6a20:4323:b0:1a3:c8a9:6deb with SMTP id h35-20020a056a20432300b001a3c8a96debmr4427287pzk.48.1711767883598; Fri, 29 Mar 2024 20:04:43 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id o3-20020a056a00214300b006e6288ef4besm3655486pfk.54.2024.03.29.20.04.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 20:04:43 -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 v19 04/15] windows: common wrapper for vasprintf and asprintf Date: Fri, 29 Mar 2024 20:00:47 -0700 Message-ID: <20240330030429.4630-5-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240330030429.4630-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240330030429.4630-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 Sat Mar 30 03:00:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138985 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 5956743D8B; Sat, 30 Mar 2024 04:05:16 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9468B410E3; Sat, 30 Mar 2024 04:04:51 +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 168CD40608 for ; Sat, 30 Mar 2024 04:04:45 +0100 (CET) Received: by mail-oa1-f54.google.com with SMTP id 586e51a60fabf-229b2396180so1462889fac.0 for ; Fri, 29 Mar 2024 20:04:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711767884; x=1712372684; 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=oylTyprsFpwPpe8phZt+NMrUDlOJl3lOTI0kWg62AlIbORyisH61NrVqyBOYPt9iBz 4s6S+KhpzM0yJU81RGal6WKI+0UGWqVKiJguzslkIJS9c6r8h6um8mPOahQbbaiUREKO l57GN+82Ue2cDtrqchwC44WoelUw9jbJHT3CODVVPu6Q6vIhFn/VE7S/bm2VlQ4JbNSF 6U2dOeNwIS95/O5KNHawirtqLGIkhMjTNGj0U2ZrTOt0nkbBPBVDEEC/qJYvHulcXl8N 3z/r4FdFj1xyIWgndOGGZoPbF+S0gpelJkV+vzJb3V5aVR/BvK4nMBGxKhkA5vOYjhba ud2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711767884; x=1712372684; 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=QfUyJ8pNjOr/I5Tmm+Jki2gWPZWGUqL9ppdgiW2XRthg4yBSOvUVBihUzYu57mjcN0 00QFbaUKTi9baNRSsTUOV0Ra1zVqlMB+vBMxpSUaB4YIOLifrtJ9HagKZ5Zryj3y6SI/ WW2DhgKW8LS+P89jQMaBr1T5BjdXYU5s8dpHU57C9XwICnSKuG8Qi8G3Jc2zzHfd1IMP KeI+Uf7OVt/qh+swh3jpiXQcVjgZVUs7+jW7uKJrw43Z6ZZSHDQG5eq/oj8GIqRy+xjZ 6BGN3sxncKjPsHc7QJYIN9kz3UoUTYzaZiBHTSLtJ9Ar2F09EJScgK7YP6HQ6argM+9e gjjQ== X-Gm-Message-State: AOJu0Ywi9eGmYcfOwQHZQA/23T194U9yusAsXUPciPs5674brlT0WFXY 2O9XTO3OJtrDZPPDzvJmSbF10vEmNxj6v90RBF10oEdjsPcrWC6yksrOIZ+qtbGk0w26KHbZc3a / X-Google-Smtp-Source: AGHT+IF1O1D+ITASAFfZVN2qfMn2MV9+DsiemlCGOOn81VR3mvrdOvryHE30E0Q0lLm+B4CpsaJUJg== X-Received: by 2002:a05:6870:3481:b0:221:8a03:6de7 with SMTP id n1-20020a056870348100b002218a036de7mr3794304oah.32.1711767884446; Fri, 29 Mar 2024 20:04:44 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id o3-20020a056a00214300b006e6288ef4besm3655486pfk.54.2024.03.29.20.04.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 20:04:44 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff , Bruce Richardson , Dmitry Kozlyuk , Pallavi Kadam Subject: [PATCH v19 05/15] eal: make eal_log_level_parse common Date: Fri, 29 Mar 2024 20:00:48 -0700 Message-ID: <20240330030429.4630-6-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240330030429.4630-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240330030429.4630-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 Sat Mar 30 03:00:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138987 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 A7B6B43D8B; Sat, 30 Mar 2024 04:05:31 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 37E6D41153; Sat, 30 Mar 2024 04:04:55 +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 F1F1E40647 for ; Sat, 30 Mar 2024 04:04:46 +0100 (CET) Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-6eaf1a3e917so450447b3a.2 for ; Fri, 29 Mar 2024 20:04:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711767885; x=1712372685; 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=imKGv4sLKtQJpGw9vJzQUW4NgQ5VtGQ5oKxQ/yPRZACk3Th5ysLlBLewRwNiwCfpVO +W98sjsVd86DTm7TpjxIlrURNKIBdPWX+kv0NO+DOtZicXIlwrdUzqbzgBs3Q0qWcCvB OpkY1gu+Bukl1k1HUyWM7mcDlQNCldStWZBI/L1x7iC2E6R5AMJlh+sVB6Z6eK0DPvyt 6iDZHlqUaHxxQJ5XQrRVEJO4VGSUoC9IVjQ/TeBG+nCPoh73jxEkan7fQ4NJ9bSSgr0w zCp68TIxEmWVTcxFHzstnFbgbAUyNpzFtHCDW6BGDkKKVk0dg/Bzr1iHE7KT/L92RGT6 EtFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711767885; x=1712372685; 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=hH2HkFGBSTjZ1La9SG86ShyIrj5A24hoYLbt6O72uh6oxk4ZhOkQ34ufDuv/Qx0crs PtN9s7tS45Zt0sUkpfVWHP+LhHx/+Sjr+WBSNi5E3ikyiW/XbrDGtoy8d4lDKdXtxC0O q2ZbqG11rR9wPKKDRfXOxn2v5GLWdvze6eEr1hKoS/1Jhj9+CNS1Updf4kGxv+meHtd5 WQAKXYQiYrem5D+9kAmlIzQWHxEXd0BknViy6meDcsc/qndSoOyp92grtS6kEChfZ2PG Rc9fjcnPJyKkT0lVJEsWMARD4Joxz1B3R0uQBR5MC9pidXQESyVd/aqbvvcMZF5FL+Ag ZzTA== X-Gm-Message-State: AOJu0Yz0AfNE/xMDXlLAy2nQBr0Hptt31wzXG+f27O6lSiHduhXnM3oK qbbjXnLQE+EcZOmvIIpkpjl1s4SNNy/0Q0wCGf14IaFF2Wxnn+jVYoKDK47biyuFCpMc2pkfFWo f X-Google-Smtp-Source: AGHT+IHPMeotA3ECprMtGnXTGsR+CQ0wjNbQLUaeBQJlnpVOQSg/q7lBuosU+SFj68XXv5RGkD+L3Q== X-Received: by 2002:a05:6a00:b46:b0:6ea:8e21:e94d with SMTP id p6-20020a056a000b4600b006ea8e21e94dmr4178928pfo.26.1711767885193; Fri, 29 Mar 2024 20:04:45 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id o3-20020a056a00214300b006e6288ef4besm3655486pfk.54.2024.03.29.20.04.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 20:04:44 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff , Bruce Richardson Subject: [PATCH v19 06/15] eal: do not duplicate rte_init_alert() messages Date: Fri, 29 Mar 2024 20:00:49 -0700 Message-ID: <20240330030429.4630-7-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240330030429.4630-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240330030429.4630-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 Sat Mar 30 03:00:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138986 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 DE8C043D8B; Sat, 30 Mar 2024 04:05:22 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 24537410FD; Sat, 30 Mar 2024 04:04:53 +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 B651940608 for ; Sat, 30 Mar 2024 04:04:46 +0100 (CET) Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-6e709e0c123so2226054b3a.1 for ; Fri, 29 Mar 2024 20:04:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711767886; x=1712372686; 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=yG7CMRwhrRAqzw5vPUy8ufFOpxTnJiGZNgL1geelQA6P/q2IRKgAvJmDLu9Gv1BpAL 7C6R+QeliGNdlsOC9F3JgnRoSHjUD2vlYTW3KoEAry8NmgkwY8CPNayacAjVbsSAP9fP Lm0SLrttRObVVsSoQg06UOYyK4WS/j0H86f+JaRC8nlMrIcXCoHCav4GnMbRwpUORGng hC0looc0BUbe9LDrxwefb5jXJBKuGbCUiuDgvJ6W8oxaUWlPiSbCSAW5W1VkOqEslTKw /m7UgL/gYdYOe7OQx1q7RbFhQAJ38H01hfBvTjTRmpy94FcfZpitrjU/R8wSweUhqvhy MzXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711767886; x=1712372686; 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=AXNf++IpU1r1SpC/t4zRx20YLxds0sesZN/nqE9TdYnDocICqp7fG3Nac3S19XC6rW AH+zgMBVVucc1AT+G5Atl1MBCqjjbHFVUTXaKvaLjGwxGG7LHD7UyBbWZz5s2/VkZteb 25KbcHZTPfkjgGteGwdwpcA4hFmahvuyhfyj/DddIb/HCT00dq1BoaCMyTWdaGD3PO5M hUi4WMzfVGlulxWxOMphWVs13KqQnW/ki9INNsB5mISEKR94Yx0FvSd9To2ClEhsfTrO C3pJe2bQbT7mAWdYgso6ayTA7V6uTZRGHPmnD4J9hpXUIikWHv+JHGqyudtc95TOlWCo u+/w== X-Gm-Message-State: AOJu0YyTos2EMsSa6dvReD49TLcPNYHDaIbBmdDysbjiD/Ejm+deCwz/ NDwbEqw+yQ9LZnMLyBwfYfVhhOWOWsgtsvqFxdqDsm1QVRsU1TE1j81EzZoJigwHZGiHxE7FB47 7 X-Google-Smtp-Source: AGHT+IFWdb4SA+CIwFY9/I3XsKlfMGcdGNg8sQlkDdQIGTrwSuKH6+1f9KievRBE0S/xIc3NchbPbQ== X-Received: by 2002:a05:6a00:9289:b0:6ea:bb00:dae3 with SMTP id jw9-20020a056a00928900b006eabb00dae3mr4182272pfb.0.1711767885945; Fri, 29 Mar 2024 20:04:45 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id o3-20020a056a00214300b006e6288ef4besm3655486pfk.54.2024.03.29.20.04.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 20:04:45 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff Subject: [PATCH v19 07/15] eal: change rte_exit() output to match rte_log() Date: Fri, 29 Mar 2024 20:00:50 -0700 Message-ID: <20240330030429.4630-8-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240330030429.4630-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240330030429.4630-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 Sat Mar 30 03:00:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138988 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 43F7243D8B; Sat, 30 Mar 2024 04:05:38 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6DEF9427D8; Sat, 30 Mar 2024 04:04:56 +0100 (CET) Received: from mail-ot1-f43.google.com (mail-ot1-f43.google.com [209.85.210.43]) by mails.dpdk.org (Postfix) with ESMTP id AA59A40685 for ; Sat, 30 Mar 2024 04:04:47 +0100 (CET) Received: by mail-ot1-f43.google.com with SMTP id 46e09a7af769-6e6d063e88bso1651520a34.3 for ; Fri, 29 Mar 2024 20:04:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711767887; x=1712372687; 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=B9F/UYZjG0Eu4nTzoWZQs17OwOtEHkXa5uljSpmk5bE=; b=L5lfUR3tE/GgzJRiEG3+nztu5LtsLTMdEg4K+LvtWR/EYE2xmosurH57P2qz6R8O24 ls0cbvkekmUsIytwSije9gAZoXW+NTBfuSc9XtIXE+sdnqoyOwB7b2EmS2IIujbOFEcC rxolTvl//Nqt1zY3PrW5RcvWFfWHbW+Pn8SS01OcMPab782JSRKjE/RuBHWRrZB1+u1f jRTPnpktD2psC+zQK1mBlupuhdRjCFFtezeZEjPYeL8crW++4dJGL4V/PNzGFWDvTzpg cbI1NGHmS5rdsD6unIEl/RZwJVHBBt4ytpZQ+48rTX0HeoJ+WGl0uLX3cqsjjKc3vnyb HrTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711767887; x=1712372687; 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=B9F/UYZjG0Eu4nTzoWZQs17OwOtEHkXa5uljSpmk5bE=; b=QdA3dWABudSPxBATbgVN5s3bbEy/OpwVtskuigJ3fbe+HCTCZE64PcSFL0woBwlJr0 4L2bcn3tuv76TmITc4BbbLeqoGwxGfMA1vHjN69wav7qYTxnXCKChsbSocbdA2DWLaHc t3nreki4HHzadglyt94LtfqjLHuG/+AGnGnNSKAyYLxTwDTdTOyPKyFBIoQzVo0oq1Ja 6nTfc1+m5+KC3LrdsYOwQLdXsvT/ucYQxRiGU1VauSk8wTsuFP3yB61tH0Iq3bQB4aWS AsCzbeniA4wYlZXIjuu/jxtgrXskQW0zfpWOMU8wJOUwHvUg1sVOy3XJVTBguEmOeAIL S/BA== X-Gm-Message-State: AOJu0YzRkJ5DQhSp4IJQogVztYoAmvDdtvDSbf2I7VpUPXcizGWkX+vn PHXn+Oseg5myTo6QMDXyX2nf0y+I0ExIs6VphlSyVRJpK74F4ypuVsdsx1Lg3FewlNzPndEdrvz S X-Google-Smtp-Source: AGHT+IGpFZiQI+uhEhcxuUfZUntA6hffqudzWyySZiEFdjloe0iR2rT2tRDQYszpzu1Edmg8LEZUDw== X-Received: by 2002:a54:468b:0:b0:3c2:18a7:dd70 with SMTP id k11-20020a54468b000000b003c218a7dd70mr3444786oic.55.1711767886861; Fri, 29 Mar 2024 20:04:46 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id o3-20020a056a00214300b006e6288ef4besm3655486pfk.54.2024.03.29.20.04.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 20:04:46 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Bruce Richardson , Dmitry Kozlyuk , Tyler Retzlaff , Pallavi Kadam Subject: [PATCH v19 08/15] log: move handling of syslog facility out of eal Date: Fri, 29 Mar 2024 20:00:51 -0700 Message-ID: <20240330030429.4630-9-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240330030429.4630-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240330030429.4630-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.c | 2 ++ 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 + 10 files changed, 70 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.c b/lib/log/log.c index 255f757d94..4b24e145b6 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -2,6 +2,7 @@ * Copyright(c) 2010-2014 Intel Corporation */ +#include #include #include #include @@ -12,6 +13,7 @@ #include #include +#include #include #include 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 Sat Mar 30 03:00:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138989 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 281FD43D8B; Sat, 30 Mar 2024 04:05:45 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B2B98427E4; Sat, 30 Mar 2024 04:04:58 +0100 (CET) Received: from mail-oi1-f181.google.com (mail-oi1-f181.google.com [209.85.167.181]) by mails.dpdk.org (Postfix) with ESMTP id 648F74068E for ; Sat, 30 Mar 2024 04:04:48 +0100 (CET) Received: by mail-oi1-f181.google.com with SMTP id 5614622812f47-3bbbc6e51d0so1534323b6e.3 for ; Fri, 29 Mar 2024 20:04:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711767888; x=1712372688; 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=SZI/zAeGlulnSqRmN6ne+YyfE3QxbV6y1hFyAwon20wXwLRnzqdPX4RM9LhElGiSBz LoU8+eieBLVa6wMiKQC/wIXv4Sj2/RvZSHz6OZFzov0QLaEGSy/UqrXwSYHmx9boymeb DYub6mCuHsf6PDEFKivJbkupsR8dIa9UKj8mR1l6vo1Iw2bbt6/YL/JN3kY8fUv6pSb5 qxgQaISlWZUGYbcj7tCj3SQ5fm2HxgtvyuA8C+AkMF38519s3tYaXChrshvWJEGKsBVl g2VUxMCy6yCL36evgMLx4GqW6K0Xzn3EMN677FrraA535H0PzQQflKAtJW4GhVemiI3k 23eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711767888; x=1712372688; 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=CrMm46pnqDb2hu0uI3ZMM18nvq4D1uMTt/tqozZ9zJp1wlmY/NLyKurOnAoRl6GgP4 PGWpQnSTKCPOV0840nCpNiznkgsO1nm6tz3dPej+r0yYJTIxJiQpHHAMasvurrMhh9oP 1mc0jqF04cpAFpwdcmRmyvoODUqQZOBd94iOjRrZ0nx2hkPeaoGRd9uY0m3dYe7Fv0NY s7JM3x2FCNisDD5Z4zpex0EIYCh0u6dujc2Sey1fWJFs3hRfUqm/6/1qJjw5MpBTQcVH iX52j2VHD8t4FCZ5NXTQyyVYHXI+jhuruDbpnA3CNQqwyhIzKcRGRzPtZ4dvRDOq+nwE qicQ== X-Gm-Message-State: AOJu0YxtA7SjMFUBS70iaiaoiclwlHFYs7rkAMp3QzwbTmvnY0XRwSL1 /kGgZeLM9JoN3SzVGsRCoWn+0uN+W/ce/uxEtCehnoZZoxiOlTVrLCpvl8Yps1szwH1CxgOGHsq X X-Google-Smtp-Source: AGHT+IEwwUaC/vSD3a5zL65Ap5iLYDGbFFbr1yVGJgdenhf5p8jmU26RtPsuQq8YzR1hUFuJ3/yE7w== X-Received: by 2002:a05:6808:1211:b0:3c3:782c:d049 with SMTP id a17-20020a056808121100b003c3782cd049mr4059848oil.58.1711767887737; Fri, 29 Mar 2024 20:04:47 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id o3-20020a056a00214300b006e6288ef4besm3655486pfk.54.2024.03.29.20.04.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 20:04:47 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff , Bruce Richardson , Dmitry Kozlyuk , Pallavi Kadam Subject: [PATCH v19 09/15] eal: initialize log before everything else Date: Fri, 29 Mar 2024 20:00:52 -0700 Message-ID: <20240330030429.4630-10-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240330030429.4630-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240330030429.4630-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 Sat Mar 30 03:00:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138990 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 0FC8743D8B; Sat, 30 Mar 2024 04:05:52 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 29167427E9; Sat, 30 Mar 2024 04:05:00 +0100 (CET) Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by mails.dpdk.org (Postfix) with ESMTP id 5A517406B6 for ; Sat, 30 Mar 2024 04:04:49 +0100 (CET) Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-6ea9a60f7f5so2098737b3a.3 for ; Fri, 29 Mar 2024 20:04:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711767888; x=1712372688; 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=DyES1Rd7PjLKXezWsT8D1+VxR7yrYboVhk48nlLmRG0=; b=ratFwOhLtjFbbdWQIAhBPXrlztlxAkNKpEq8510lim0vwS9OqvlQ+7HRtkR474nQdQ IPpdxWNY+wtNnbJMVljrIfuZFiFQ5iDFoUmCDlLofu1hg9nj+E0egkkglAzIZXUE1qEw RiUUAQ79y5EA6tEVsbDNmp5uheN2CeHjOk8E6ayviTNuUKBl21N8noBVCp8KbsfG8mL1 vO7OdwlMx20rD4z2K1ooAIyLzjMjw1Kw0soQiGcTKUHN2cFRQnH2sx+kwdSL+EpMrHC8 A1BpiFVW0W0XPUDu/OU+CVQVOTpakEZZjs8LN4Ci0QG+pRkkagA1IqNZu0XVw9nrgZZa 8X8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711767888; x=1712372688; 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=DyES1Rd7PjLKXezWsT8D1+VxR7yrYboVhk48nlLmRG0=; b=hE7h2//+UCp2NT9uuJW87nN6gvybXBMh4JbpIOYQxCK/2a8S0O0ESgxdIZm9c16DF4 k6ZcPGQfoaj55DX4GadNXYhSblmGCcmXBZ+EeprdEcnB/reAxGZPHZK9zGDUvCA2a29i rcsiUVtIZDk18PfZnQ/BzoouOHhIG1E+UkhWDqYuHP7kQrTRY8qlPBgGHr4HiPoxTUy2 Gat+qPl0GGtVeHXyoh8SeSdFmPuNpUK95zcCnjMkZ+WsPxBa/wLcdpGz8h8CGADCJcX5 qgiqe8gFE7GSOn928XAPF6/STxcq8LUrTIDuxunUu/J7H1iuUhGEnMW3Q1t3Bjy8j0E+ iEmQ== X-Gm-Message-State: AOJu0YwgoECPOhHUsyWrAb9TCTGUDUweAButurqnXGprJDsZkigVeNvl Om7PNWHH1NdP2zKR1dlOeQaya60wRNancEKjiZRldCurFRnXK3dZLR2EKpBRc0i5SODLe9XfcF+ O X-Google-Smtp-Source: AGHT+IHUyJ35ukuB9xNZJdGT34qqiVQt2PxTJmei+EvRYKqcCAUJWVKkzSF+M3ME7jhQQjZBjsWifQ== X-Received: by 2002:a05:6a00:1705:b0:6ea:baf6:5720 with SMTP id h5-20020a056a00170500b006eabaf65720mr4229586pfc.3.1711767888506; Fri, 29 Mar 2024 20:04:48 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id o3-20020a056a00214300b006e6288ef4besm3655486pfk.54.2024.03.29.20.04.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 20:04:48 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v19 10/15] log: drop syslog support, and make code common Date: Fri, 29 Mar 2024 20:00:53 -0700 Message-ID: <20240330030429.4630-11-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240330030429.4630-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240330030429.4630-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 | 41 +++++------ lib/log/log_freebsd.c | 11 --- 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 - 9 files changed, 23 insertions(+), 179 deletions(-) delete mode 100644 lib/log/log_freebsd.c delete mode 100644 lib/log/log_linux.c delete mode 100644 lib/log/log_windows.c diff --git a/app/test/test_eal_flags.c b/app/test/test_eal_flags.c index 6cb4b06757..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 4b24e145b6..3fe86ddcd7 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -57,9 +57,6 @@ TAILQ_HEAD(rte_eal_opt_loglevel_list, rte_eal_opt_loglevel); static struct rte_eal_opt_loglevel_list opt_loglevel_list = TAILQ_HEAD_INITIALIZER(opt_loglevel_list); -/* Stream to use for logging if rte_logs.file is NULL */ -static FILE *default_log_stream; - /** * This global structure stores some information about the message * that is currently being processed by one lcore @@ -72,8 +69,6 @@ struct log_cur_msg { /* per core log */ static RTE_DEFINE_PER_LCORE(struct log_cur_msg, log_cur_msg); -/* default logs */ - /* Change the stream that will be used by logging system */ int rte_openlog_stream(FILE *f) @@ -87,17 +82,7 @@ rte_log_get_stream(void) { FILE *f = rte_logs.file; - if (f == NULL) { - /* - * Grab the current value of stderr here, rather than - * just initializing default_log_stream to stderr. This - * ensures that we will always use the current value - * of stderr, even if the application closes and - * reopens it. - */ - return default_log_stream != NULL ? default_log_stream : stderr; - } - return f; + return (f == NULL) ? stderr : f; } /* Set global log level */ @@ -507,14 +492,19 @@ 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; - #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG RTE_LOG(NOTICE, EAL, "Debug dataplane logs available - lower performance\n"); @@ -527,8 +517,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_logs.file; + + /* don't close stderr on the application */ + if (log_stream != NULL) + fclose(log_stream); + + rte_logs.file = NULL; } diff --git a/lib/log/log_freebsd.c b/lib/log/log_freebsd.c deleted file mode 100644 index 33a0925c43..0000000000 --- a/lib/log/log_freebsd.c +++ /dev/null @@ -1,11 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * Copyright(c) 2023 Intel Corporation - */ - -#include -#include "log_internal.h" - -void -eal_log_init(__rte_unused const char *id) -{ -} 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 Sat Mar 30 03:00:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138991 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 5827D43D8B; Sat, 30 Mar 2024 04:05:58 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5B8FD42D26; Sat, 30 Mar 2024 04:05:01 +0100 (CET) Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by mails.dpdk.org (Postfix) with ESMTP id 0783F406B6 for ; Sat, 30 Mar 2024 04:04:50 +0100 (CET) Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-6e6ee9e3cffso1729428b3a.1 for ; Fri, 29 Mar 2024 20:04:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711767889; x=1712372689; 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=ef+4W+K/w1vN13UT87NF7vTe2NZwGZarLjZdNpClf5Y=; b=0TIGlq6g7ASPUA+IeFOhu+aAHiiHBcmftlpAts1rZj1y8o9fLAvOdK5ni0lI74piKz 7NjzvqnfK4q8ha3eLxYpI9SPQ222C5kXwEw97hCUXTvi5/EwB0mZKv2pjPgXJHK4gS+M 8GxVdenLSEzIVvA11xSUJQSK7JcwO9SgCKdPEyiP7XWMMOFaO6XyezX7VXFUtNJXbdCl AuaSBSwKE1hdcNw2tUpZENwwLQPjLZZLRCkQCX8faAplUe8RhOqMAMMbqHO5xnUeKVV7 buiqqe8/1Lsrb0KJRxDbwSIgmKm53sORyWKgDIG+8BGPdVe/EjkSiqCm2+hjVBHEuRz3 qExg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711767889; x=1712372689; 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=ef+4W+K/w1vN13UT87NF7vTe2NZwGZarLjZdNpClf5Y=; b=MepygEvmmJBwxRdzXTuDoKGRZPPou6liEoE8jsbx0X11NeOgL4xRmJT0PbTRiA90yz eBke3OjH/unP41bCwpZtRF6y5vAXURPyIT+1/vLH//KvbXOQWVYEa5bcqNL/J9DRtkwg FxQZnZH2maEgrGgk7RVTiHXTJ3MrJwbQ+AnCfo3Ol93WKtlFrvrc94EB/KMVAQ4J89lS dZz8pl2aQVr4EYf1Kqa2xO2Hx1Zzm9g0nrQsdN/c5d34zWy3keXhNbzJq6r/R02ZvCwl e34s+qDt5zuyqx1xLym/QaVBvaqS2kdNAEGnbfokBGzg2ObuzRFr/u39aqUSiNAPVm5o K2RA== X-Gm-Message-State: AOJu0YxFFZYtK1nYUtT/30QxrFwRFAK95tqDbJQOnBpIWZ+7LDu+LaTc o8ipkUgAFODwBn3rXMtpBzx2LMI8jOcTjRWJhKpJJiNt0iXHDhCUrVPjE3hp3p/0CQUY6ACTb4R 5 X-Google-Smtp-Source: AGHT+IHvcCxK3i9OotumUVWSTQWkFaBLLvmxDuhFYGOrrodDuJoTvXhEBxBcefucFqNHK6aHVPzPRg== X-Received: by 2002:a05:6a00:1994:b0:6ea:f43b:b961 with SMTP id d20-20020a056a00199400b006eaf43bb961mr1705048pfl.6.1711767889246; Fri, 29 Mar 2024 20:04:49 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id o3-20020a056a00214300b006e6288ef4besm3655486pfk.54.2024.03.29.20.04.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 20:04:48 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v19 11/15] log: add hook for printing log messages Date: Fri, 29 Mar 2024 20:00:54 -0700 Message-ID: <20240330030429.4630-12-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240330030429.4630-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240330030429.4630-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 | 14 +++++++++++++- lib/log/log_private.h | 11 +++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 lib/log/log_private.h diff --git a/lib/log/log.c b/lib/log/log.c index 3fe86ddcd7..71b00528d0 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -18,6 +18,7 @@ #include #include "log_internal.h" +#include "log_private.h" #ifdef RTE_EXEC_ENV_WINDOWS #define strdup _strdup @@ -28,16 +29,19 @@ struct rte_log_dynamic_type { uint32_t loglevel; }; + /** 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 { @@ -74,6 +78,7 @@ int rte_openlog_stream(FILE *f) { rte_logs.file = f; + rte_logs.print_func = log_print; return 0; } @@ -470,7 +475,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; } @@ -499,6 +504,13 @@ eal_log_syslog(const char *mode __rte_unused) return -1; } +/* default log print function */ +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 */ diff --git a/lib/log/log_private.h b/lib/log/log_private.h new file mode 100644 index 0000000000..afd833c3bd --- /dev/null +++ b/lib/log/log_private.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ + +#ifndef LOG_PRIVATE_H +#define LOG_PRIVATE_H + +typedef int (*log_print_t)(FILE *f, uint32_t level, const char *fmt, va_list ap); + +__rte_format_printf(3, 0) +int log_print(FILE *f, uint32_t level, const char *format, va_list ap); + +#endif /* LOG_PRIVATE_H */ From patchwork Sat Mar 30 03:00:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138992 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 0A71B43D8B; Sat, 30 Mar 2024 04:06:06 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1E18A42D78; Sat, 30 Mar 2024 04:05:03 +0100 (CET) Received: from mail-oa1-f41.google.com (mail-oa1-f41.google.com [209.85.160.41]) by mails.dpdk.org (Postfix) with ESMTP id 39A3040A7A for ; Sat, 30 Mar 2024 04:04:51 +0100 (CET) Received: by mail-oa1-f41.google.com with SMTP id 586e51a60fabf-2228c4c5ac3so1392332fac.0 for ; Fri, 29 Mar 2024 20:04:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711767890; x=1712372690; 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=nkVZHqEP7AxA8KGxGB3koBSjfs7Koy7ghponGnIe8/g=; b=ocUm7LAzsKly0FsYOGceJGRCp/RvtfqeoEruG3YJUPhAWd6EXJdyUljzX1CW9SBAdK 51eUkg8DH3Byjrd0D5UW8u8kEJ7PI5CHy6tgu5HJoPLFUrpJzKaSrofqK/Mkmsp/jSFy emuyz/qHmunCyTssQwCM1SSvE92Gjfs34L6CP+ceeKLvAjFYZe0KEtg4ZuANHoNswkYE Gg57fzIy8yNaTxliWtqhWivqzFshrWwhtMiBIQtfrxBcOoETKYyw6gcsrDCY1K39o6fR +0+XDMcz7UeYd2VQlsU/gO3Xz1NonWFUHuXfQem8FekHoJSt6UuZGFESseU/DfEjIQ55 G6gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711767890; x=1712372690; 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=nkVZHqEP7AxA8KGxGB3koBSjfs7Koy7ghponGnIe8/g=; b=qqB7crPlPnozeole5DPCFPe6ApErj2YM9cDoAicMigOj9rNlJLfLNYU67wk0jgjzx6 uho3KrcdQbsLHIEEZd9rwr8Ky6U1lx6a2RZ2c3wwIHoBO/QAkLUyz/UXrMuGXDzUQ/G/ Mx7+z7lIVifMasHKRBFzxzVA6O/Xsu9XXQArDh6cA7h6txMmHcMTq97pMHSHAWjWggEB WnR0hRQXVQLMxs1QnlbTi9uaQfaekIKVqpSPNkGGQ8nAkXpoObDKyT7DoLX1bRdNbxNs MbEIL5ov4IV4t1BLDZG1WycpqQyUwcYi9S6RxkLd3dFfQfU1uDRRpNNR2wC7uqRPqOZ/ Bcag== X-Gm-Message-State: AOJu0YyUGdFuR8vlh9eAmnbUiQ3rmZS7JPzGCo0KgEdvcUMCfhA9Gz66 BN4JgblPPuY8c+ijUEMbb012kOkqwrgRW7+dDfyXdu8A4WYZtnovUbYQolBfvm78jL0q94o1LQg b X-Google-Smtp-Source: AGHT+IEh02rkFKEk6q2wj+A/GH7VVMAYigp2B+c4vu3IBUY4G7c+f/6/uPta2X0FWxvfcMQMxXFW8g== X-Received: by 2002:a05:6870:1086:b0:21e:f03b:8836 with SMTP id 6-20020a056870108600b0021ef03b8836mr2951580oaq.52.1711767890428; Fri, 29 Mar 2024 20:04:50 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id o3-20020a056a00214300b006e6288ef4besm3655486pfk.54.2024.03.29.20.04.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 20:04:49 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Bruce Richardson , Dmitry Kozlyuk , Tyler Retzlaff , Pallavi Kadam Subject: [PATCH v19 12/15] log: add timestamp option Date: Fri, 29 Mar 2024 20:00:55 -0700 Message-ID: <20240330030429.4630-13-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240330030429.4630-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240330030429.4630-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 | 10 +- lib/log/log_internal.h | 9 ++ lib/log/log_private.h | 7 + lib/log/log_timestamp.c | 204 ++++++++++++++++++++++++++++ lib/log/meson.build | 6 +- lib/log/version.map | 1 + 13 files changed, 309 insertions(+), 10 deletions(-) create mode 100644 lib/log/log_timestamp.c 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 71b00528d0..3c15f2a560 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -21,7 +21,7 @@ #include "log_private.h" #ifdef RTE_EXEC_ENV_WINDOWS -#define strdup _strdup +#include #endif struct rte_log_dynamic_type { @@ -29,13 +29,13 @@ struct rte_log_dynamic_type { uint32_t loglevel; }; - /** 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 = { @@ -359,7 +359,6 @@ static const struct logtype logtype_strings[] = { RTE_INIT_PRIO(log_init, LOG) { uint32_t i; - rte_log_set_global_level(RTE_LOG_DEBUG); rte_logs.dynamic_types = calloc(RTE_LOGTYPE_FIRST_EXT_ID, @@ -517,6 +516,11 @@ log_print(FILE *f, uint32_t level __rte_unused, const char *format, va_list ap) void eal_log_init(const char *id __rte_unused) { + if (log_timestamp_enabled()) + rte_logs.print_func = log_print_with_timestamp; + else + rte_logs.print_func = log_print; + #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG RTE_LOG(NOTICE, EAL, "Debug dataplane logs available - lower performance\n"); diff --git a/lib/log/log_internal.h b/lib/log/log_internal.h index 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/log_private.h b/lib/log/log_private.h index afd833c3bd..070baee8dd 100644 --- a/lib/log/log_private.h +++ b/lib/log/log_private.h @@ -8,4 +8,11 @@ typedef int (*log_print_t)(FILE *f, uint32_t level, const char *fmt, va_list ap) __rte_format_printf(3, 0) int log_print(FILE *f, uint32_t level, const char *format, va_list ap); +bool log_timestamp_enabled(void); + +ssize_t log_timestamp(char *tsbuf, size_t tsbuflen); + +__rte_format_printf(3, 0) +int log_print_with_timestamp(FILE *f, uint32_t level, const char *format, va_list ap); + #endif /* LOG_PRIVATE_H */ diff --git a/lib/log/log_timestamp.c b/lib/log/log_timestamp.c new file mode 100644 index 0000000000..ecabf72506 --- /dev/null +++ b/lib/log/log_timestamp.c @@ -0,0 +1,204 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +#include +#include +#include +#include +#include +#include +#include + +#include + +#ifdef RTE_EXEC_ENV_WINDOWS +#include +#endif + +#include "log_internal.h" +#include "log_private.h" + +static enum { + LOG_TIMESTAMP_NONE = 0, + LOG_TIMESTAMP_TIME, /* time since start */ + LOG_TIMESTAMP_DELTA, /* time since last message */ + LOG_TIMESTAMP_RELTIME, /* relative time since last message */ + LOG_TIMESTAMP_CTIME, /* Unix standard time format */ + LOG_TIMESTAMP_ISO, /* ISO8601 time format */ +} log_time_format; + +static struct { + struct timespec started; /* when log was initialized */ + struct timespec previous; /* when last msg was printed */ +} log_time; + +/* Set the log timestamp format */ +int +eal_log_timestamp(const char *str) +{ + if (str == NULL) + log_time_format = LOG_TIMESTAMP_TIME; + else if (strcmp(str, "notime") == 0) + log_time_format = LOG_TIMESTAMP_NONE; + else if (strcmp(str, "reltime") == 0) + log_time_format = LOG_TIMESTAMP_RELTIME; + else if (strcmp(str, "delta") == 0) + log_time_format = LOG_TIMESTAMP_DELTA; + else if (strcmp(str, "ctime") == 0) + log_time_format = LOG_TIMESTAMP_CTIME; + else if (strcmp(str, "iso") == 0) + log_time_format = LOG_TIMESTAMP_ISO; + else + return -1; + + return 0; +} + +bool +log_timestamp_enabled(void) +{ + return log_time_format != LOG_TIMESTAMP_NONE; +} + +/* 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. + * Surprisingly, can't just use strftime() for this; + * since want microseconds and the timezone offset format differs. + */ +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, &log_time.previous); + log_time.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 */ +ssize_t +log_timestamp(char *tsbuf, size_t tsbuflen) +{ + struct timespec now, delta; + + switch (log_time_format) { + case LOG_TIMESTAMP_NONE: + return 0; + + case LOG_TIMESTAMP_TIME: + if (clock_gettime(CLOCK_MONOTONIC, &now) < 0) + return 0; + + delta = timespec_sub(&now, &log_time.started); + + return snprintf(tsbuf, tsbuflen, "%6lu.%06lu", + (unsigned long)delta.tv_sec, + (unsigned long)delta.tv_nsec / 1000u); + + case LOG_TIMESTAMP_DELTA: + if (clock_gettime(CLOCK_MONOTONIC, &now) < 0) + return 0; + + delta = timespec_sub(&now, &log_time.previous); + log_time.previous = now; + + return snprintf(tsbuf, tsbuflen, "<%6lu.%06lu>", + (unsigned long)delta.tv_sec, + (unsigned long)delta.tv_nsec / 1000u); + + case LOG_TIMESTAMP_RELTIME: + if (clock_gettime(CLOCK_REALTIME, &now) < 0) + return 0; + + return format_reltime(tsbuf, tsbuflen, &now); + + case 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 LOG_TIMESTAMP_ISO: + if (clock_gettime(CLOCK_REALTIME, &now) < 0) + return 0; + + return format_iso8601(tsbuf, tsbuflen, &now); + } + + return 0; +} + +/* print timestamp before message */ +int +log_print_with_timestamp(FILE *f, uint32_t level, const char *format, va_list ap) +{ + char tsbuf[128]; + + if (log_timestamp(tsbuf, sizeof(tsbuf)) > 0) + fprintf(f, "[%s] ", tsbuf); + + return log_print(f, level, format, ap); +} + +RTE_INIT_PRIO(log_timestamp_init, LOG) +{ + clock_gettime(CLOCK_MONOTONIC, &log_time.started); + log_time.previous = log_time.started; +} diff --git a/lib/log/meson.build b/lib/log/meson.build index 891f77a237..04235f6ee5 100644 --- a/lib/log/meson.build +++ b/lib/log/meson.build @@ -2,5 +2,9 @@ # Copyright(c) 2023 Intel Corporation includes += global_inc -sources = files('log.c') +sources = files( + 'log.c', + 'log_timestamp.c', +) + headers = files('rte_log.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 Sat Mar 30 03:00:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138993 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 4772F43D8B; Sat, 30 Mar 2024 04:06:12 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4ADD742D89; Sat, 30 Mar 2024 04:05:04 +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 0F92140A7A for ; Sat, 30 Mar 2024 04:04:52 +0100 (CET) Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-6e6b6f86975so1656906b3a.1 for ; Fri, 29 Mar 2024 20:04:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711767891; x=1712372691; 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=F08iCjqZi4sMXW/XVhSNwhyPFqam6Vw4whM/OZTQKzI=; b=uv7lnreS2IfPruUkeyBfw8mLWHK85Ci8ghKGR8XZ34UJrVLBBHxRoCp0rTuVUFwdXI Vx/BpOt2QJ14teEC/EVBdJnb3S8M39iGvlpDV5t1ZwoYjiDsqsVmyoJwgFbfdhvkoT1/ WCaBBAgGDMijF8z++KJJb4KEdBiFs3qE8alqTVS/Wp9NbO3KbDf6rbV1F3qMsDb3yv4H fSLoc/5279KfKaSJwTAVTvfSHeZ8nc7DWsJuBqxg4TMdHt4aSKL9PLE3wFcLKyjCE601 nZ6qN8+89r3lLsszyC6/pK023Dw/9a4lWiTF8tj9RmTLrtzHGdYVuRu5Wt+KiBTJdxgN 8+wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711767891; x=1712372691; 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=F08iCjqZi4sMXW/XVhSNwhyPFqam6Vw4whM/OZTQKzI=; b=fG5F8o39+vRJmBWhTxSFSjDi47ToKKJf3waXnjk1dXLUwyUohWj2ubGVAfVCB2I1eZ ONQMSVQGuFMHtRmL2CYn8H/mnWtifClByufbVEETfPnIuaeHF2WlP/KfjDP9FihkyyCw RVGtQYXZkoivgK+LeoX8dTkXqnE7f8T06DvO+0h+oFHKTj8kggykVojSadlrrcQxA8s8 NB3t6+vhvo+VbZVT0M9BpaveCI9BJUqTE9/kFywlE3kf++PDe1KhHZ0aPIMS7KJuJnRD JUpWwknpcKqiQTauWJwG/vGzJw2Gy5l3NcKqrodPaKkHFV/VzEpn9WpWGiBth0MreXvx uG8w== X-Gm-Message-State: AOJu0Yxjxw7FChEeP2NrKGg2ic8QHXgk5Qud1KatR+xRwsAlCivEQNhg LC9Asde4HahGSiNv+FGIRUK55vsUpOzUP+HUqHmXuSTSW4mGeH0tYfVi+DrQP2DjPS+72W1o4/5 4 X-Google-Smtp-Source: AGHT+IGENLTdtsrXv92w6NhQyqzrez+FugytV1zDhZuH2D8dDdowpxgV2jlwjffJpSF7hqe6RlftBg== X-Received: by 2002:a05:6a21:1690:b0:1a6:fe1d:727f with SMTP id np16-20020a056a21169000b001a6fe1d727fmr3014595pzb.53.1711767891242; Fri, 29 Mar 2024 20:04:51 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id o3-20020a056a00214300b006e6288ef4besm3655486pfk.54.2024.03.29.20.04.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 20:04:50 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v19 13/15] log: add optional support of syslog Date: Fri, 29 Mar 2024 20:00:56 -0700 Message-ID: <20240330030429.4630-14-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240330030429.4630-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240330030429.4630-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 | 25 +++--- lib/log/log_private.h | 4 + lib/log/log_stubs.c | 28 ++++++ lib/log/log_syslog.c | 89 +++++++++++++++++++ lib/log/meson.build | 6 ++ 9 files changed, 165 insertions(+), 41 deletions(-) create mode 100644 lib/log/log_stubs.c create mode 100644 lib/log/log_syslog.c 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 3c15f2a560..ddb8400d73 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -12,18 +12,19 @@ #include #include #include +#include #include #include #include -#include "log_internal.h" -#include "log_private.h" - #ifdef RTE_EXEC_ENV_WINDOWS #include #endif +#include "log_internal.h" +#include "log_private.h" + struct rte_log_dynamic_type { const char *name; uint32_t loglevel; @@ -496,13 +497,6 @@ 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; -} - /* default log print function */ int log_print(FILE *f, uint32_t level __rte_unused, const char *format, va_list ap) @@ -514,8 +508,17 @@ log_print(FILE *f, uint32_t level __rte_unused, const char *format, va_list ap) * Called by rte_eal_init */ void -eal_log_init(const char *id __rte_unused) +eal_log_init(const char *id) { +#ifdef RTE_EXEC_ENV_WINDOWS + RTE_SET_USED(id); +#else + bool is_terminal = isatty(STDERR_FILENO); + + if (log_syslog_enabled(is_terminal)) + log_syslog_open(id, is_terminal); + else +#endif if (log_timestamp_enabled()) rte_logs.print_func = log_print_with_timestamp; else diff --git a/lib/log/log_private.h b/lib/log/log_private.h index 070baee8dd..0e7d10ffca 100644 --- a/lib/log/log_private.h +++ b/lib/log/log_private.h @@ -15,4 +15,8 @@ ssize_t log_timestamp(char *tsbuf, size_t tsbuflen); __rte_format_printf(3, 0) int log_print_with_timestamp(FILE *f, uint32_t level, const char *format, va_list ap); +bool log_syslog_enabled(bool is_tty); +void log_syslog_open(const char *id, bool is_terminal); + + #endif /* LOG_PRIVATE_H */ diff --git a/lib/log/log_stubs.c b/lib/log/log_stubs.c new file mode 100644 index 0000000000..cb34217af8 --- /dev/null +++ b/lib/log/log_stubs.c @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2010-2014 Intel Corporation + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "log_internal.h" +#include "log_private.h" + +/* Stubs for Windows */ +int +eal_log_syslog(const char *str __rte_unused) +{ + return -1; +} diff --git a/lib/log/log_syslog.c b/lib/log/log_syslog.c new file mode 100644 index 0000000000..33eff3a1cf --- /dev/null +++ b/lib/log/log_syslog.c @@ -0,0 +1,89 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +#include +#include +#include +#include + +#include +#include + +#include "log_internal.h" +#include "log_private.h" + +static enum { + LOG_SYSLOG_NONE = 0, /* do not use syslog */ + LOG_SYSLOG_AUTO, /* use syslog only if not a terminal */ + LOG_SYSLOG_ALWAYS, /* always use syslog */ + LOG_SYSLOG_BOTH, /* log to both syslog and stderr */ +} log_syslog_opt; + +int +eal_log_syslog(const char *str) +{ + if (str == NULL || strcmp(str, "auto") == 0) + log_syslog_opt = LOG_SYSLOG_AUTO; + else if (strcmp(str, "both") == 0) + log_syslog_opt = LOG_SYSLOG_BOTH; + else if (strcmp(str, "always") == 0) + log_syslog_opt = LOG_SYSLOG_ALWAYS; + else + return -1; + return 0; +} + +bool +log_syslog_enabled(bool is_terminal) +{ + switch (log_syslog_opt) { + default: + return false; + + case LOG_SYSLOG_ALWAYS: + case LOG_SYSLOG_BOTH: + return true; + + case LOG_SYSLOG_AUTO: + return !is_terminal; + } +} + +/* + * wrapper for log stream to put messages into syslog + * useful for cases like: + * rte_hex_dump(rte_get_log_stream(), ...) + */ +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, +}; + +void +log_syslog_open(const char *id, bool is_terminal) +{ + int flags = LOG_NDELAY | LOG_PID; + + if (log_syslog_opt == LOG_SYSLOG_BOTH) + flags |= LOG_PERROR; + + 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) + rte_openlog_stream(log_stream); +} diff --git a/lib/log/meson.build b/lib/log/meson.build index 04235f6ee5..37507299e7 100644 --- a/lib/log/meson.build +++ b/lib/log/meson.build @@ -7,4 +7,10 @@ sources = files( 'log_timestamp.c', ) +if is_windows + sources += files('log_stubs.c') +else + sources += files('log_syslog.c') +endif + headers = files('rte_log.h') From patchwork Sat Mar 30 03:00:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138994 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 EFDBF43D8B; Sat, 30 Mar 2024 04:06:18 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8232442D7D; Sat, 30 Mar 2024 04:05:05 +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 D53E640A7A for ; Sat, 30 Mar 2024 04:04:52 +0100 (CET) Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-6ea9a60f7f5so2098762b3a.3 for ; Fri, 29 Mar 2024 20:04:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711767892; x=1712372692; 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=ww8CUWIQ8YnJlzWRLIjlLDsitSx2+/jhf75yL3uVx1w=; b=Bq5/5qeiGv4lwTuSjffmdqivgpQ4PLFCkaJY2nZJjzRUurD5SBUaf4dKWisV8Gt/Qr v3Bs8dPNY4rc4OeZZoF2t4H6l+oAmAUyV90EhrJguAihzsP7dP2d4c3pnsgfpLOKKaFL KIUd06x3mUd+OCkkbTejtJ1pWVb/c6WsuxI0FYI6kRoA+2sHVCbMPg/duhFhPgGCKYIh XhEl4WFHhLk0VSPRW7RGt4CJvzEk6GSc77vVnAGUpqseoHwn5xjRQQbejv+rFYPHyOBP 7bNm+TKrZZPLbKrcRbtrowAhhJOw0cYLBAEFYTipj9k1nEPR1yY50XahWf2YXFqEFyxv dnNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711767892; x=1712372692; 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=ww8CUWIQ8YnJlzWRLIjlLDsitSx2+/jhf75yL3uVx1w=; b=m9zxaJ4S8bwk8/rrlLD+IRP0WJLY5w6capx41fVSp5bqqAvOxt9Rb6NjcijTOArATc rihUTCGeoON1dN/dYSlaMzW5vXsMT4nw/GCYsoOt3pbIbVq7iE5RMqXAZA0EcgFmTHaI lHVFxHzj9azKCGk8OaOA4nThrBALozC84HXw8bHZQbrjxMWZuRhdxaHM3ymWBFaIDM1M CDBo3OZ3RiN/bmj2P/wY1WUc0AbBo4WfbL/4+sDLeToyEpoFcBbdmsb33n5F1L5lbwGC Y4TuCA0kRAwb6/J0gsKGU2lL3AddQsWWpxNHloWYKL9+kXQSJIZ1yd08Hx4oKnf2S5mn KuMA== X-Gm-Message-State: AOJu0YwpGw/S3WLZbWCSEJqoXXUyR6po2ezf0fghTVgGWnlmXb8nSmeq klY/VgYE16ceXCVOmsRwHnjwSEvWJxQJJteldLZt5W5+0RAnnj/0RzhEBFGCLDU8WcHrqu4L4Wi q X-Google-Smtp-Source: AGHT+IFftd4hSgivmSjjLy1q/zXTnawprDqzGqghAKiE03vS90zBzx7oJitrFKHnxYXXCtlYjjUB0Q== X-Received: by 2002:a05:6a00:1c99:b0:6ea:afd1:90e6 with SMTP id y25-20020a056a001c9900b006eaafd190e6mr3475571pfw.6.1711767892057; Fri, 29 Mar 2024 20:04:52 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id o3-20020a056a00214300b006e6288ef4besm3655486pfk.54.2024.03.29.20.04.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 20:04:51 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v19 14/15] log: add support for systemd journal Date: Fri, 29 Mar 2024 20:00:57 -0700 Message-ID: <20240330030429.4630-15-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240330030429.4630-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240330030429.4630-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 --- doc/guides/prog_guide/log_lib.rst | 14 ++ lib/eal/common/eal_common_options.c | 11 ++ lib/eal/common/eal_options.h | 2 + lib/log/log.c | 5 + lib/log/log_internal.h | 3 + lib/log/log_journal.c | 216 ++++++++++++++++++++++++++++ lib/log/log_private.h | 4 + lib/log/log_stubs.c | 6 + lib/log/meson.build | 5 + lib/log/version.map | 1 + 10 files changed, 267 insertions(+) create mode 100644 lib/log/log_journal.c diff --git a/doc/guides/prog_guide/log_lib.rst b/doc/guides/prog_guide/log_lib.rst index abaedc7212..476dedb097 100644 --- a/doc/guides/prog_guide/log_lib.rst +++ b/doc/guides/prog_guide/log_lib.rst @@ -100,6 +100,20 @@ option. There are three possible settings for this option: If ``--syslog`` option is not specified, then only console (stderr) will be used. +Messages can be redirected to systemd journal which is an enhanced version of syslog with the ``--log-journal`` option. + +There are three possible settings for this option: + +*auto* + If stderr is redirected to journal by ``systemd`` service + then use journal socket to instead of stderr for log. + This is the default. + +*never* + Do not try to use journal. + +*always* + Always try to direct messages to journal socket. 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..9a82118184 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_JOURNAL, 2, NULL, OPT_LOG_JOURNAL_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 }, @@ -1617,6 +1618,7 @@ eal_log_level_parse(int argc, char * const argv[]) switch (opt) { case OPT_LOG_LEVEL_NUM: case OPT_SYSLOG_NUM: + case OPT_LOG_JOURNAL_NUM: case OPT_LOG_TIMESTAMP_NUM: if (eal_parse_common_option(opt, optarg, internal_conf) < 0) return -1; @@ -1843,6 +1845,14 @@ eal_parse_common_option(int opt, const char *optarg, return -1; } break; + + case OPT_LOG_JOURNAL_NUM: + if (eal_log_journal(optarg) < 0) { + EAL_LOG(ERR, "invalid parameters for --" + OPT_LOG_JOURNAL); + return -1; + } + break; #endif case OPT_LOG_LEVEL_NUM: @@ -2223,6 +2233,7 @@ eal_common_usage(void) " --"OPT_PROC_TYPE" Type of this process (primary|secondary|auto)\n" #ifndef RTE_EXEC_ENV_WINDOWS " --"OPT_SYSLOG"[=] Enable use of syslog\n" + " --"OPT_LOG_JOURNAL"[=] Enable use of systemd journal\n" #endif " --"OPT_LOG_LEVEL"= Set global log level\n" " --"OPT_LOG_LEVEL"=:\n" diff --git a/lib/eal/common/eal_options.h b/lib/eal/common/eal_options.h index e24c9eca53..c5a1c70288 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_JOURNAL "log-journal" + OPT_LOG_JOURNAL_NUM, #define OPT_LOG_TIMESTAMP "log-timestamp" OPT_LOG_TIMESTAMP_NUM, #define OPT_TRACE "trace" diff --git a/lib/log/log.c b/lib/log/log.c index ddb8400d73..d97bde984e 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -515,6 +515,11 @@ eal_log_init(const char *id) #else bool is_terminal = isatty(STDERR_FILENO); +#ifdef RTE_EXEC_ENV_LINUX + if (log_journal_enabled(id)) + rte_logs.print_func = journal_print; + else +#endif if (log_syslog_enabled(is_terminal)) log_syslog_open(id, is_terminal); else diff --git a/lib/log/log_internal.h b/lib/log/log_internal.h index 7c7d44eed2..82fdc21ac2 100644 --- a/lib/log/log_internal.h +++ b/lib/log/log_internal.h @@ -29,6 +29,9 @@ int eal_log_save_pattern(const char *pattern, uint32_t level); __rte_internal int eal_log_syslog(const char *name); +__rte_internal +int eal_log_journal(const char *opt); + /* * Convert log level to string. */ diff --git a/lib/log/log_journal.c b/lib/log/log_journal.c new file mode 100644 index 0000000000..f7b5aafc9d --- /dev/null +++ b/lib/log/log_journal.c @@ -0,0 +1,216 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "log_internal.h" +#include "log_private.h" + +static enum { + LOG_JOURNAL_NEVER = 0, /* do not use journal */ + LOG_JOURNAL_AUTO, /* use if stderr is set to journal */ + LOG_JOURNAL_ALWAYS, /* always try to use journal */ +} log_journal_opt = LOG_JOURNAL_AUTO; + +static int log_journal_fd = -1; + +int +eal_log_journal(const char *str) +{ + if (str == NULL || strcmp(str, "auto") == 0) + log_journal_opt = LOG_JOURNAL_AUTO; + else if (strcmp(str, "always") == 0) + log_journal_opt = LOG_JOURNAL_ALWAYS; + else if (strcmp(str, "never") == 0) + log_journal_opt = LOG_JOURNAL_NEVER; + else + return -1; + return 0; +} + +/* + * send structured message using journal protocol + * See: https://systemd.io/JOURNAL_NATIVE_PROTOCOL/ + */ +static int +journal_send(uint32_t level, const char *buf, size_t len) +{ + struct iovec iov[3]; + const unsigned int niov = RTE_DIM(iov); + char msg[] = "MESSAGE="; + char pbuf[16]; /* "PRIORITY=N\n" */ + + 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 = pbuf; + iov[2].iov_len = snprintf(pbuf, sizeof(pbuf), + "PRIORITY=%i\n", level - 1); + + return writev(log_journal_fd, iov, niov); +} + +int +journal_print(FILE *f __rte_unused, uint32_t level, + const char *format, va_list ap) +{ + char *buf = NULL; + size_t len; + int ret; + + len = vasprintf(&buf, format, ap); + if (len == 0) + return 0; + + /* check that message ends with newline, if not add one */ + if (buf[len - 1] != '\n') { + char *nbuf; + + nbuf = realloc(buf, len + 1); + if (nbuf == NULL) { + free(buf); + return 0; + } + buf = nbuf; + buf[len++] = '\n'; + } + + ret = journal_send(level, buf, len); + free(buf); + return ret; +} + +/* 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 int +journal_log_close(__rte_unused void *c) +{ + close(log_journal_fd); + log_journal_fd = -1; + return 0; +} + +static cookie_io_functions_t journal_log_func = { + .write = journal_log_write, + .close = journal_log_close, +}; + +/* + * 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(void) +{ + struct sockaddr_un sun = { + .sun_family = AF_UNIX, + .sun_path = "/run/systemd/journal/socket", + }; + int s; + + s = socket(AF_UNIX, SOCK_DGRAM, 0); + if (s < 0) { + perror("socket"); + return -1; + } + + if (connect(s, (struct sockaddr *)&sun, sizeof(sun)) < 0) { + perror("connect"); + close(s); + return -1; + } + + return s; +} + +bool log_journal_enabled(const char *id) +{ + FILE *log_stream; + char *syslog_id = NULL; + ssize_t len; + + if (log_journal_opt == LOG_JOURNAL_NEVER) + return false; + + if (log_journal_opt == LOG_JOURNAL_AUTO && + !is_journal(STDERR_FILENO)) + return false; + + log_journal_fd = open_journal(); + if (log_journal_fd < 0) + return false; + + /* Send identifier as first message */ + len = asprintf(&syslog_id, "SYSLOG_IDENTIFIER=%s\nSYSLOG_PID=%u", + id, getpid()); + if (len == 0) + goto error; + + if (write(log_journal_fd, syslog_id, len) != len) { + perror("write"); + goto error; + } + + free(syslog_id); + + /* redirect other log messages to journal */ + log_stream = fopencookie(NULL, "w", journal_log_func); + if (log_stream != NULL) { + rte_openlog_stream(log_stream); + return true; + } + +error: + free(syslog_id); + close(log_journal_fd); + log_journal_fd = -1; + return false; +} diff --git a/lib/log/log_private.h b/lib/log/log_private.h index 0e7d10ffca..988579fc08 100644 --- a/lib/log/log_private.h +++ b/lib/log/log_private.h @@ -18,5 +18,9 @@ int log_print_with_timestamp(FILE *f, uint32_t level, const char *format, va_lis bool log_syslog_enabled(bool is_tty); void log_syslog_open(const char *id, bool is_terminal); +bool log_journal_enabled(const char *id); + +__rte_format_printf(3, 0) +int journal_print(FILE *f, uint32_t level, const char *format, va_list ap); #endif /* LOG_PRIVATE_H */ diff --git a/lib/log/log_stubs.c b/lib/log/log_stubs.c index cb34217af8..803a6e9f6b 100644 --- a/lib/log/log_stubs.c +++ b/lib/log/log_stubs.c @@ -26,3 +26,9 @@ eal_log_syslog(const char *str __rte_unused) { return -1; } + +int +eal_log_journal(const char *str __rte_unused) +{ + return -1; +} diff --git a/lib/log/meson.build b/lib/log/meson.build index 37507299e7..5b9be7f6f1 100644 --- a/lib/log/meson.build +++ b/lib/log/meson.build @@ -7,10 +7,15 @@ sources = files( 'log_timestamp.c', ) +if is_linux + sources += files('log_journal.c') +endif + if is_windows sources += files('log_stubs.c') else sources += files('log_syslog.c') endif + headers = files('rte_log.h') diff --git a/lib/log/version.map b/lib/log/version.map index 14d6681a5f..7af97ece43 100644 --- a/lib/log/version.map +++ b/lib/log/version.map @@ -26,6 +26,7 @@ INTERNAL { global: eal_log_init; + eal_log_journal; eal_log_level2str; eal_log_save_pattern; eal_log_save_regexp; From patchwork Sat Mar 30 03:00:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138995 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 ACEC343D8B; Sat, 30 Mar 2024 04:06:25 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B3F6342D99; Sat, 30 Mar 2024 04:05:06 +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 BD36641104 for ; Sat, 30 Mar 2024 04:04:53 +0100 (CET) Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-6ea80de0e97so1682125b3a.2 for ; Fri, 29 Mar 2024 20:04:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711767893; x=1712372693; 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=VkK4F13YG5mZA4a0cEYatTcU1uoLlLFo0sOonnBvIt4=; b=kD2e/eo3Q/eUvVHV5V0EOoMM1MSHDqS8dSWxgzZclbNToPGqeYVO4aDeIhZDAy8lVk dxNr1goKLinzYdT3Ggfn1GAX1SZgXs0Gw/SmMrAyZS/X44KxRY6+8KGc8lH5tEjLbpy4 AIG2HM7mjroS2T3HJZn9GnkSw5cLCapNxoV49WNpCBHc5g0WwMlgIWpfZ7CQoMvJG5ES +nqsJ4+1ktHcly+HYv0/g5w72YOnDYox8WDFR0LPZ+rZTs2XKEsnf1OThtbbDpW7ZnM/ QrmUhNNqrGlYnB2sYrd3JFSwNV39MFtoMFRd5Izc2jlL5a0rsDq0Ge4XDuRsWWeXcqAF By8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711767893; x=1712372693; 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=VkK4F13YG5mZA4a0cEYatTcU1uoLlLFo0sOonnBvIt4=; b=wigtSLkSIP/KTeltL0W7cwkuzjB/OzcpruPlHrNFXnlmYsKcqYWDtnpy4O+vCsyraA JAQYnss1J1TAnav8xEGo8F7D0UNiKdJN1xyWODK776wO/uafjHhiEL2NHmgsUjHF8yFU /WkdfAFueB3zVZt99eCPlBs00o9QleQdiiiH6rSbXt9osDSIGNXtD+2D/sPcJxkMhFBo TKSngVWGyNZn4634W2Csk0NruvcYmeG43NoBVmYPgG9sZ7puSxT4/iZq3Ivz/Wg6Ztd9 tSL2cGugwlrO4a25vLbMaMWgU1nuVT+BXcCHcrIjpf/dqbvXYEhU8r1GmjO6kupRa1P2 f00Q== X-Gm-Message-State: AOJu0YyATxNZsNtnUz9Z8mX04gjSOEFSc8zKzxKF4U7tMkVxmHsrjzI7 AiV17aY23hfSN6OPTqAeV1Pwh9yT1giamT3pTl62E0k5833Lk/nl8qTq9KCM15j1BYz1O27pt0A w X-Google-Smtp-Source: AGHT+IEdR+QJMWcyX8xmWzXLItlC8Xvth9faPxomT0H0cIF19R3Eh+7eJwArAmNFIgmxYOcSZUQUIQ== X-Received: by 2002:a05:6a20:3d90:b0:1a3:81d2:29f with SMTP id s16-20020a056a203d9000b001a381d2029fmr4189815pzi.17.1711767892830; Fri, 29 Mar 2024 20:04:52 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id o3-20020a056a00214300b006e6288ef4besm3655486pfk.54.2024.03.29.20.04.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 20:04:52 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v19 15/15] log: colorize log output Date: Fri, 29 Mar 2024 20:00:58 -0700 Message-ID: <20240330030429.4630-16-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240330030429.4630-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240330030429.4630-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 | 6 +- lib/log/log.c | 24 +++-- lib/log/log_color.c | 160 ++++++++++++++++++++++++++++ lib/log/log_internal.h | 5 + lib/log/log_private.h | 8 ++ lib/log/meson.build | 2 +- lib/log/version.map | 1 + 10 files changed, 247 insertions(+), 10 deletions(-) create mode 100644 lib/log/log_color.c 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 476dedb097..f46720fe34 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 ~~~~~~~~~~~~~ @@ -115,7 +130,6 @@ There are three possible settings for this option: *always* Always try to direct messages to journal socket. - 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 9a82118184..70fdf3f5a1 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -73,6 +73,7 @@ eal_long_options[] = { {OPT_HUGE_UNLINK, 2, NULL, OPT_HUGE_UNLINK_NUM }, {OPT_IOVA_MODE, 1, NULL, OPT_IOVA_MODE_NUM }, {OPT_LCORES, 1, NULL, OPT_LCORES_NUM }, + {OPT_LOG_COLOR, 2, NULL, OPT_LOG_COLOR_NUM }, {OPT_LOG_LEVEL, 1, NULL, OPT_LOG_LEVEL_NUM }, {OPT_LOG_JOURNAL, 2, NULL, OPT_LOG_JOURNAL_NUM }, {OPT_LOG_TIMESTAMP, 2, NULL, OPT_LOG_TIMESTAMP_NUM }, @@ -1620,6 +1621,7 @@ eal_log_level_parse(int argc, char * const argv[]) case OPT_SYSLOG_NUM: case OPT_LOG_JOURNAL_NUM: case OPT_LOG_TIMESTAMP_NUM: + case OPT_LOG_COLOR_NUM: if (eal_parse_common_option(opt, optarg, internal_conf) < 0) return -1; break; @@ -1872,6 +1874,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) { @@ -2240,6 +2250,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 c5a1c70288..c0686c2544 100644 --- a/lib/eal/common/eal_options.h +++ b/lib/eal/common/eal_options.h @@ -33,10 +33,12 @@ enum { OPT_HUGE_UNLINK_NUM, #define OPT_LCORES "lcores" OPT_LCORES_NUM, -#define OPT_LOG_LEVEL "log-level" - OPT_LOG_LEVEL_NUM, +#define OPT_LOG_COLOR "log-color" + OPT_LOG_COLOR_NUM, #define OPT_LOG_JOURNAL "log-journal" OPT_LOG_JOURNAL_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" diff --git a/lib/log/log.c b/lib/log/log.c index d97bde984e..a2254b461b 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -510,10 +510,14 @@ log_print(FILE *f, uint32_t level __rte_unused, const char *format, va_list ap) void eal_log_init(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); #ifdef RTE_EXEC_ENV_LINUX if (log_journal_enabled(id)) @@ -523,11 +527,19 @@ eal_log_init(const char *id) if (log_syslog_enabled(is_terminal)) log_syslog_open(id, is_terminal); else -#endif - if (log_timestamp_enabled()) - rte_logs.print_func = log_print_with_timestamp; - else - rte_logs.print_func = log_print; +#endif /* RTE_EXEC_ENV_WINDOWS */ + + if (log_color_enabled(is_terminal)) { + if (log_timestamp_enabled()) + rte_logs.print_func = color_print_with_timestamp; + else + rte_logs.print_func = color_print; + } else { + if (log_timestamp_enabled()) + rte_logs.print_func = log_print_with_timestamp; + else + rte_logs.print_func = log_print; + } #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG RTE_LOG(NOTICE, EAL, diff --git a/lib/log/log_color.c b/lib/log/log_color.c new file mode 100644 index 0000000000..2bed521bc0 --- /dev/null +++ b/lib/log/log_color.c @@ -0,0 +1,160 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ + +#include +#include +#include +#include +#include +#include + +#include +#include + +#ifdef RTE_EXEC_ENV_WINDOWS +#include +#endif + +#include "log_internal.h" +#include "log_private.h" + +enum { + LOG_COLOR_AUTO = 0, /* default */ + LOG_COLOR_NEVER, + LOG_COLOR_ALWAYS, +} log_color_mode; + +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; +} + +/* + * 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) + log_color_mode = LOG_COLOR_ALWAYS; + else if (strcmp(mode, "never") == 0) + log_color_mode = LOG_COLOR_NEVER; + else if (strcmp(mode, "auto") == 0) + log_color_mode = LOG_COLOR_AUTO; + else + return -1; + + return 0; +} + +bool +log_color_enabled(bool is_terminal) +{ + switch (log_color_mode) { + default: + case LOG_COLOR_NEVER: + return false; + case LOG_COLOR_ALWAYS: + return true; + case LOG_COLOR_AUTO: + return is_terminal; + } +} + +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); +} + +int +color_print_with_timestamp(FILE *f, uint32_t level, + const char *format, va_list ap) +{ + char tsbuf[128]; + + if (log_timestamp(tsbuf, sizeof(tsbuf)) > 0) + color_fprintf(f, COLOR_GREEN, "[%s] ", tsbuf); + + return color_print(f, level, format, ap); +} diff --git a/lib/log/log_internal.h b/lib/log/log_internal.h index 82fdc21ac2..bba7041ea3 100644 --- a/lib/log/log_internal.h +++ b/lib/log/log_internal.h @@ -50,5 +50,10 @@ void rte_eal_log_cleanup(void); __rte_internal int eal_log_timestamp(const char *fmt); +/* + * Enable or disable color in log messages + */ +__rte_internal +int eal_log_color(const char *mode); #endif /* LOG_INTERNAL_H */ diff --git a/lib/log/log_private.h b/lib/log/log_private.h index 988579fc08..bb93584f29 100644 --- a/lib/log/log_private.h +++ b/lib/log/log_private.h @@ -23,4 +23,12 @@ bool log_journal_enabled(const char *id); __rte_format_printf(3, 0) int journal_print(FILE *f, uint32_t level, const char *format, va_list ap); +bool log_color_enabled(bool is_tty); + +__rte_format_printf(3, 0) +int color_print(FILE *f, uint32_t level, const char *format, va_list ap); + +__rte_format_printf(3, 0) +int color_print_with_timestamp(FILE *f, uint32_t level, const char *format, va_list ap); + #endif /* LOG_PRIVATE_H */ diff --git a/lib/log/meson.build b/lib/log/meson.build index 5b9be7f6f1..3467cb5e9d 100644 --- a/lib/log/meson.build +++ b/lib/log/meson.build @@ -4,6 +4,7 @@ includes += global_inc sources = files( 'log.c', + 'log_color.c', 'log_timestamp.c', ) @@ -17,5 +18,4 @@ else sources += files('log_syslog.c') endif - headers = files('rte_log.h') diff --git a/lib/log/version.map b/lib/log/version.map index 7af97ece43..eb3200dcde 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_journal; eal_log_level2str;