From patchwork Thu Sep 19 15:04:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 144302 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 E085D459D7; Thu, 19 Sep 2024 17:06:27 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 62A1C43377; Thu, 19 Sep 2024 17:06:22 +0200 (CEST) Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) by mails.dpdk.org (Postfix) with ESMTP id A7385406FF for ; Thu, 19 Sep 2024 17:06:20 +0200 (CEST) Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-7c3e1081804so410835a12.3 for ; Thu, 19 Sep 2024 08:06:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1726758380; x=1727363180; 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=tZMh2QZWqYsOZzV79fxAeO8rO9t31loW4A1DTuTr8ec=; b=FyDBcIlEuZlUrjEJaVMfG+NILSMhua2QKCN2hzyfgFvLQ8lfkD6oYMAe+RiW4p+S6d pkYdSVh1ehflnAWwwBc8kM09NE/tVwO+S3/3ITOtFFzamE7PPNYuEfGtgYADXxdQ46Pv NUNlvBbbcAWREKjcTtW2jsoa59cJ+B5NPaov28PnD92Ia1QIsDDdv6EcQDjgwjubFgbu Hi+a/VZEC1Tbxp/YDLxwvMT4PdfLdSDGMGeK1sPztMlD8avmCtkPnP5PLvSo+h2qc+0H oPWbqODrva5x3Mll+dk8aEI4MWo/XgdwPZimNKnHobM4sCnQgk/YMKQHDAGxkvkQJKiE Pmpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726758380; x=1727363180; 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=tZMh2QZWqYsOZzV79fxAeO8rO9t31loW4A1DTuTr8ec=; b=crj6r2ZQV+UGi027FU1i1k+EJLuRlrEOdfOVgJugiNo76TSVKl9yoTnFIB5qyYME1s SaXYjmCgxenbwvEqed7Djk2WM+q0H8rE+wqrhaAfQAcm3NnVteaPMqjer+7ySTc5iKnN bf9SBh6xQ0IfsBigiFBIuORX1iT71XzDk00gIHxdGa2oVEx1IcLv+v6DP9GhUHPv0jB4 cEfC2WdovikYwEik9F77Zb68Z6i70gY4bRrG7U9ICREyZHyL6jqnYUhBLm5N54UOAKW1 z7LAF//XW9FivYq4/cJsxBr7ghV2yZz35f4L6vvvcgkP4pnEXJg/AU0Wq9P2oh8g2QIo ihfg== X-Gm-Message-State: AOJu0YzbflNKVhPgMklBJ+oTh8T4gAvNsyojhGDQN0BPG907JD2XQJGt f+s6StaYWcGFInFOmcHehe1liDpbqLFnTmbENesmAMIJqEYvUTZezy8SK2qD1ng631xbFmHSQl4 s X-Google-Smtp-Source: AGHT+IFKQR18F18cKXJ7zHe3cbLE/fRyNoBoFCwdL2JgG62n2PQENp8x6PBtXYyhKG7iLnsweUL7/g== X-Received: by 2002:a05:6a21:3a81:b0:1cc:e5eb:e91f with SMTP id adf61e73a8af0-1cf75ea273bmr41814189637.1.1726758379817; Thu, 19 Sep 2024 08:06:19 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71944adfd3dsm8620841b3a.92.2024.09.19.08.06.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2024 08:06:19 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff , =?utf-8?q?Morten_Br=C3=B8rup?= , Chengwen Feng , Bruce Richardson Subject: [PATCH v25 01/15] maintainers: add for log library Date: Thu, 19 Sep 2024 08:04:07 -0700 Message-ID: <20240919150609.5281-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240919150609.5281-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240919150609.5281-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 Acked-by: Morten Brørup Acked-by: Chengwen Feng Acked-by: Bruce Richardson --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index c5a703b5c0..ecf6f955cc 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -185,6 +185,7 @@ F: app/test/test_threads.c F: app/test/test_version.c Logging +M: Stephen Hemminger F: lib/log/ F: doc/guides/prog_guide/log_lib.rst F: app/test/test_logs.c From patchwork Thu Sep 19 15:04:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 144303 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 7A5EB459D7; Thu, 19 Sep 2024 17:06:36 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7C65D4337D; Thu, 19 Sep 2024 17:06:23 +0200 (CEST) Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) by mails.dpdk.org (Postfix) with ESMTP id C03B04336A for ; Thu, 19 Sep 2024 17:06:21 +0200 (CEST) Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-718e285544fso705077b3a.1 for ; Thu, 19 Sep 2024 08:06:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1726758381; x=1727363181; 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=IaLvkAy7EZnUXhXV0cLtvwGD9fj1cd6nyd8cZK/jfkk=; b=coAc8zqITlESNPJV/X8RM3KqkLfsaLQ/qT/xHJ2P9z/HgOduCq8fICi6PGG2aioQzZ BulQ4NNF4wSLb71ZsvqdgnZ2gDbJ48HORfJB+hPI8iq4c8PlafHt+dRA+T7OMWxBOS2S oFaBgWPNca2+NNuCrWhK/lE0W9Bg+EZTKWTMx5ZjHNIin9FivVJhW3x8LmJ6uIBSli1z IiAb18g0rrv0Q27cHAR5fM3TkeJ5n/1rShOboAldBbapdKH9HYDlH6+SRkA/bFuuUkJM y8woLZOk9f91GUeLAgtj6xTGoC5BdYjC8jK7TlJl/hg0VmtmoY1BvnAWjmYk2k6ZIA1c 25vQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726758381; x=1727363181; 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=IaLvkAy7EZnUXhXV0cLtvwGD9fj1cd6nyd8cZK/jfkk=; b=OLzPq8oYywaH1jPNQ5m85Y1imh8zfjXWZCL9M0YWHKUTrkYfxJo4Y3gLrBK/NZkef+ fI+oX/BYffERIrL8tOzq95pPZ6rasO51UG8M1JhXkEiaOkBQ2alCquTz+KWAEQPr7XB8 o2+CWFMuLpEIutrhqjh5Fk+P9VIoJub+cSFEHFZa4aB8fW6tYzQXucvgZzyw4tYDa9uk OGHXBjZuyuGkmx4Ywmdju0dpE4P0GM/b/Inb0Y/Hb60APNqRT05QUolDkMK9bp94VJIl CyNPxjKp2+dZewy6aXUL2eEqlxPTH1wxTXriTPSo85yNLBo8fce4K6Q0kdJX5cS4L1YJ aRqQ== X-Gm-Message-State: AOJu0Yw9zDtUKwyaZYTEmvTo4xGqACGbkr5qlw+NJFwT5+f6lJTiSJlo 6D2i52kCCbHNz8WZFcVDpKwMiE0bkSgjBEmZmEr1KGQB8i+bg57XtbOX4GqLbIa9IAtNzSPJ54M Z X-Google-Smtp-Source: AGHT+IFlP8Utfe2AysXj55KNf8nSCzyAHdnzRHgg5031q4EI/YTCfO5vhq3kWsbW09P6hxcahWXF/Q== X-Received: by 2002:a05:6a00:13a9:b0:714:173f:7e6b with SMTP id d2e1a72fcca58-71936a3abdemr33203832b3a.2.1726758380769; Thu, 19 Sep 2024 08:06:20 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71944adfd3dsm8620841b3a.92.2024.09.19.08.06.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2024 08:06:20 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff , Dmitry Kozlyuk , =?utf-8?q?Morten_Br=C3=B8rup?= , Bruce Richardson , Chengwen Feng Subject: [PATCH v25 02/15] windows: make getopt functions have const properties Date: Thu, 19 Sep 2024 08:04:08 -0700 Message-ID: <20240919150609.5281-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240919150609.5281-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240919150609.5281-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Having different prototypes on different platforms can lead to lots of unnecessary workarounds. Looks like the version of getopt used from windows was based on an older out of date version from FreeBSD. This patch changes getopt, getopt_long, etc to have the same const attributes as Linux and FreeBSD. The changes are derived from the current FreeBSD version of getopt_long. Signed-off-by: Stephen Hemminger Acked-by: Tyler Retzlaff Acked-by: Dmitry Kozlyuk Acked-by: Morten Brørup Acked-by: Bruce Richardson Acked-by: Chengwen Feng --- lib/eal/windows/getopt.c | 23 ++++++++++++----------- lib/eal/windows/include/getopt.h | 8 ++++---- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/eal/windows/getopt.c b/lib/eal/windows/getopt.c index a1f51c6c23..50ff71b930 100644 --- a/lib/eal/windows/getopt.c +++ b/lib/eal/windows/getopt.c @@ -20,7 +20,7 @@ #include #include -const char *optarg; /* argument associated with option */ +char *optarg; /* argument associated with option */ int opterr = 1; /* if error message should be printed */ int optind = 1; /* index into parent argv vector */ int optopt = '?'; /* character checked for validity */ @@ -39,9 +39,9 @@ static void pass(const char *a) {(void) a; } #define BADARG ((*options == ':') ? (int)':' : (int)'?') #define INORDER 1 -#define EMSG "" +static char EMSG[] = ""; -static const char *place = EMSG; /* option letter processing */ +static char *place = EMSG; /* option letter processing */ /* XXX: set optreset to 1 rather than these two */ static int nonopt_start = -1; /* first non option argument (for permute) */ @@ -80,7 +80,7 @@ gcd(int a, int b) */ static void permute_args(int panonopt_start, int panonopt_end, int opt_end, - char **nargv) + char * const *nargv) { int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos; char *swap; @@ -101,11 +101,12 @@ permute_args(int panonopt_start, int panonopt_end, int opt_end, pos -= nnonopts; else pos += nopts; + swap = nargv[pos]; /* LINTED const cast */ - ((char **) nargv)[pos] = nargv[cstart]; + ((char **)(uintptr_t)nargv)[pos] = nargv[cstart]; /* LINTED const cast */ - ((char **)nargv)[cstart] = swap; + ((char **)(uintptr_t)nargv)[cstart] = swap; } } } @@ -116,7 +117,7 @@ permute_args(int panonopt_start, int panonopt_end, int opt_end, * Returns -1 if short_too is set and the option does not match long_options. */ static int -parse_long_options(char **nargv, const char *options, +parse_long_options(char * const *nargv, const char *options, const struct option *long_options, int *idx, int short_too) { const char *current_argv; @@ -236,7 +237,7 @@ parse_long_options(char **nargv, const char *options, * Parse argc/argv argument vector. Called by user level routines. */ static int -getopt_internal(int nargc, char **nargv, const char *options, +getopt_internal(int nargc, char *const nargv[], const char *options, const struct option *long_options, int *idx, int flags) { char *oli; /* option letter list index */ @@ -434,7 +435,7 @@ getopt_internal(int nargc, char **nargv, const char *options, * Parse argc/argv argument vector. */ int -getopt(int nargc, char *nargv[], const char *options) +getopt(int nargc, char *const nargv[], const char *options) { return getopt_internal(nargc, nargv, options, NULL, NULL, FLAG_PERMUTE); @@ -445,7 +446,7 @@ getopt(int nargc, char *nargv[], const char *options) * Parse argc/argv argument vector. */ int -getopt_long(int nargc, char *nargv[], const char *options, +getopt_long(int nargc, char *const nargv[], const char *options, const struct option *long_options, int *idx) { @@ -458,7 +459,7 @@ getopt_long(int nargc, char *nargv[], const char *options, * Parse argc/argv argument vector. */ int -getopt_long_only(int nargc, char *nargv[], const char *options, +getopt_long_only(int nargc, char *const nargv[], const char *options, const struct option *long_options, int *idx) { diff --git a/lib/eal/windows/include/getopt.h b/lib/eal/windows/include/getopt.h index 6f57af454b..e4cf6873cb 100644 --- a/lib/eal/windows/include/getopt.h +++ b/lib/eal/windows/include/getopt.h @@ -44,7 +44,7 @@ /** argument to current option, or NULL if it has none */ -extern const char *optarg; +extern char *optarg; /** Current position in arg string. Starts from 1. * Setting to 0 resets state. */ @@ -80,14 +80,14 @@ struct option { }; /** Compat: getopt */ -int getopt(int argc, char *argv[], const char *options); +int getopt(int argc, char *const argv[], const char *options); /** Compat: getopt_long */ -int getopt_long(int argc, char *argv[], const char *options, +int getopt_long(int argc, char *const argv[], const char *options, const struct option *longopts, int *longindex); /** Compat: getopt_long_only */ -int getopt_long_only(int nargc, char *argv[], const char *options, +int getopt_long_only(int nargc, char *const argv[], const char *options, const struct option *long_options, int *idx); From patchwork Thu Sep 19 15:04:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 144304 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 4F4BC459D7; Thu, 19 Sep 2024 17:06:45 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9230A43381; Thu, 19 Sep 2024 17:06:25 +0200 (CEST) Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by mails.dpdk.org (Postfix) with ESMTP id A51A243379 for ; Thu, 19 Sep 2024 17:06:22 +0200 (CEST) Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-719858156f4so762407b3a.3 for ; Thu, 19 Sep 2024 08:06:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1726758382; x=1727363182; 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=lxRrCvLT4Xv7g0jHDEOqMAqfGdL9jPEeURqKg/Cqh74=; b=bQABv6EPf0CWUtUM06QYjRCrdRM571CW8f1qN2GaNAL7lltNnZQVaxBqmLKfq+5Y1k StYFnNJ7d8YGGOqpluUpXDT8RJCPNvCFxSTgeIM6BTfPu0vh9tWB9fjzm49Zu/iEuqjf 6z3aVVc4o0gp/ZDA+IO57Ni1yeMIAICV7jTPSark/Dyb/MFDN5AJMktJKjWHocbkudz9 3SAHjyUCUsNdIWFpalJ0FgCj0ZUKuk+r2rcQEszmxczHtxGtJa49Yij+hqOtRDVMP9y0 vI4K8Q41/0WO6bg2ukAoQKN3LVsaoxL1OEl+mq9EbtoBk1oCjudfqarb5U3X1bAZUE23 PVMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726758382; x=1727363182; 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=lxRrCvLT4Xv7g0jHDEOqMAqfGdL9jPEeURqKg/Cqh74=; b=RfA1CIxgNpxc7WgAO82mp+I8+pIqT9nERcRWDJFqkaRBCk45uyCsmBoTWyYe0hrB46 s3aC6NONgX7/rFuCp+KY2g+ZpXb/PhWoPseXDY01K9RLMdEjilLwM+c1RfAqSCL+wheU rszzffIuk0XLdzQI68C4LUnxsJY2eanaP43W8AluTzJoNV9RG7LxNMGub+rReMhs1ex6 0SRnodtkSrLv1fi0LxB4Xx0eK875J9I3RolI0B6Kdy1fYjt3erF2PxdPd/G8liS4ZlPg t8ihginfY/tNmRkaZMzgAzLqS8CfCU8ecSomgdeuCu0UgnhH+zcgbqBHNYXeYzlRVWkG 0yLg== X-Gm-Message-State: AOJu0YzgZ0nbm9cTsSrODrpd4unXUynTvr3lVQhb5Y+hOAvnovgJgFym 69b/QmEZXhrtCw1TwnAKW8TrfXRbAbXEORs/Cc1I5dE71ZYUeSRBEvAvRBPk3NWh8lj4tntt5dP j X-Google-Smtp-Source: AGHT+IHui10DnSIKwMNgrCwg4tjgDa6HaY6F9e3pJiy3kci1LylR28XCQX/TS8O5U/7u4K2SdDe8Zg== X-Received: by 2002:a05:6a00:14c8:b0:714:3de8:a616 with SMTP id d2e1a72fcca58-719261e1393mr38354400b3a.19.1726758381691; Thu, 19 Sep 2024 08:06:21 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71944adfd3dsm8620841b3a.92.2024.09.19.08.06.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2024 08:06:21 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff , =?utf-8?q?Morten_Br=C3=B8rup?= , Bruce Richardson , Chengwen Feng Subject: [PATCH v25 03/15] windows: add os shim for localtime_r Date: Thu, 19 Sep 2024 08:04:09 -0700 Message-ID: <20240919150609.5281-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240919150609.5281-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240919150609.5281-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 Acked-by: Morten Brørup Acked-by: Bruce Richardson Acked-by: Chengwen Feng --- 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..665c9ac93b 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 *timep, struct tm *result) +{ + if (localtime_s(result, timep) == 0) + return result; + else + return NULL; +} +#define localtime_r(timep, result) rte_localtime_r(timep, result) + #endif /* _RTE_OS_SHIM_ */ From patchwork Thu Sep 19 15:04:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 144305 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 90966459D7; Thu, 19 Sep 2024 17:06:53 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A0F6F43387; Thu, 19 Sep 2024 17:06:26 +0200 (CEST) Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) by mails.dpdk.org (Postfix) with ESMTP id 66B3E4337B for ; Thu, 19 Sep 2024 17:06:23 +0200 (CEST) Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-6e7b121be30so689345a12.1 for ; Thu, 19 Sep 2024 08:06:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1726758382; x=1727363182; 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=bz8TcyCyo/qMLQ26HDQhHI2sgWASKpiCD5ryPdnlOAw=; b=hXVB6tFp1htkCFPRNgXik2O5FR9n+rjpknMigZgcGkxzCXtRRRBG7DPRFJpfXrHlhp AteNZcTtu5Vx5xrl0/kwrQrbeuzGuwHQp7kn2FJzfw9folwuJdXec/wmsgtMZ68SHzyb xyug16Oa2YOWVh+p7MshQ6c/Ts+ndWDq9oIUV8VhiSiY3g/DFFiZpvmPZ+9mhqiVYiHc G3QOcDx7ef3YfpiCMcro0yX5DK9vKmqTEBiklGjwvIP0ZE2mBsQOokZ7sUMER/hh252i qQq+zec68LU8qg/pxQV5LM/FyHtn4Px2FUMyOjIomn5P9DJrxRXnbe/LLZ8Z19eXOxVy /3HA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726758382; x=1727363182; 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=bz8TcyCyo/qMLQ26HDQhHI2sgWASKpiCD5ryPdnlOAw=; b=IeAfthn04zpzt4z6iPzv3x/N04FSgIIwM6a+avniLRxN6GrFMytmpi//3peywnF5YX a947TWIBtg4x6Mo89X67KTVL12LpZEZTO3Kbuynqf+upVFFD0xV6sbOXs74B4CYSGmZY X6VeEFfridms85VKBIJQ4gM3nif+Xu3vwCBRquwuWmVlacoFe4xBzaajZz25bzBIVfWo uDh038IDfvNEbGjaZ2nkFMBtYUlnNsWEi6vLVwDvA4fyEHQkOkBE4u6VGpaeLCXyROqk YsBP2WAxNU1mDG+VBxmjz+JujWo5B8ViPCDvuwnIUYPZDgVjSPhktYmhpWRRoVt2ei2j MGXA== X-Gm-Message-State: AOJu0Yw5FkDT6fpW4TVw47jhjtNrdidRG9iQF5JMOnJgwRiXUM+OZjF3 xJckV6OltrGsJvjaQCDO5yWBl/ZKwh3HCfeRCuStrMUfhqBwiIPQBRA57W6M/RTw2agwPEEgND4 E X-Google-Smtp-Source: AGHT+IGORUaG+Wq1DrNjUBVLpKgZAYso2Oy7VdB8YCIWLIGaBx07xjU0g8ZVRU2nbglr0lDZfTqBdQ== X-Received: by 2002:a05:6a20:c793:b0:1d2:bb49:63ac with SMTP id adf61e73a8af0-1d2bb4965aemr24487884637.40.1726758382489; Thu, 19 Sep 2024 08:06:22 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71944adfd3dsm8620841b3a.92.2024.09.19.08.06.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2024 08:06:22 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff , =?utf-8?q?Morten_Br=C3=B8rup?= , Bruce Richardson Subject: [PATCH v25 04/15] eal: make eal_log_level_parse common Date: Thu, 19 Sep 2024 08:04:10 -0700 Message-ID: <20240919150609.5281-5-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240919150609.5281-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240919150609.5281-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 Acked-by: Morten Brørup Acked-by: Bruce Richardson --- lib/eal/common/eal_common_options.c | 40 +++++++++++++++++++++++++++ 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, 41 insertions(+), 116 deletions(-) diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index f1a5e329a5..eb079a65a9 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -1640,6 +1640,46 @@ 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; + } + } + + /* 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) 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 1229230063..d3b40e81d8 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 d742cc98e2..0ded386472 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 28b78a95a6..a77e590a72 100644 --- a/lib/eal/windows/eal.c +++ b/lib/eal/windows/eal.c @@ -96,41 +96,6 @@ eal_usage(const char *prgname) } } -/* Parse the arguments for --log-level only */ -static void -eal_log_level_parse(int argc, char **argv) -{ - int opt; - char **argvopt; - int option_index; - struct internal_config *internal_conf = - eal_get_internal_configuration(); - - argvopt = argv; - - eal_reset_internal_config(internal_conf); - - while ((opt = getopt_long(argc, argvopt, eal_short_options, - eal_long_options, &option_index)) != EOF) { - - int ret; - - /* getopt is not happy, stop right now */ - if (opt == '?') - break; - - ret = (opt == OPT_LOG_LEVEL_NUM) ? - eal_parse_common_option(opt, optarg, - internal_conf) : 0; - - /* common parser is not happy */ - if (ret < 0) - break; - } - - optind = 0; /* reset getopt lib */ -} - /* Parse the argument given in the command line of the application */ static int eal_parse_args(int argc, char **argv) From patchwork Thu Sep 19 15:04:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 144306 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 77E29459D7; Thu, 19 Sep 2024 17:07:02 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9E4174338C; Thu, 19 Sep 2024 17:06:27 +0200 (CEST) Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by mails.dpdk.org (Postfix) with ESMTP id 385954337F for ; Thu, 19 Sep 2024 17:06:24 +0200 (CEST) Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-71957eb256bso834520b3a.3 for ; Thu, 19 Sep 2024 08:06:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1726758383; x=1727363183; 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=+6hqMhc0E9TDs99Fu5BKypiDNT7B7d94ylR7Fbmsrwg=; b=HCjLiz/rpArPIG6HR4rXOoVJx5PrHBeTt3zlfVb74BE6lh1ZW9Z+a1eIvApMDIv0LZ 7ISIVRbiYN6eC4Jx+Ni4FLPoI2SBmjns0WXHiLfrn2GWAOOLxmLFxT+lWRabTKHA7MUJ bHwbVeLdjtZPaYUWmX62AeJlE6LbmnC5YirNT7qjS/np2g5D+5ntC2ehh8yNFSeD4yKv ENDtv6z+4dQJ9GUHi0qww2xuwyzrw12Fsr0W5cl8BVuoxrh9L2Mdnzw3s8t3/sTOIiEn l8NF4DRlLNrMVy2PDlnuwBZR0VXmoTTz2a+KJ/Z3Nx43jsj3fCq62Ts2BgcIgSejCFif hXwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726758383; x=1727363183; 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=+6hqMhc0E9TDs99Fu5BKypiDNT7B7d94ylR7Fbmsrwg=; b=XADqZzzjb7DpQJeFLFy3kE7qW9dDi3d4fOAFCuoERRyXEgDapJqRNO3qKFXXnDlPzT iFTGckmpJnLfyh8xpqQC63TCjmgCOAvcrg2271630Lg5Iw/e2FSZd8Lk2gvY+kfzpNxY 86h20NSJQ5uIPr4cboidgb+R/xpVYJa1vQyX8jbDlUbdTVTsM6p8T8L4svwSFi1D4JLj ZLUhvzjG7UYLpNSyjp6qLdfXqAEK47vbHc1iPfYlwiF3nZLbQkJbNYqm7veOlDN7aVCe kx98fvAmA/i94rHP0ODhCSVSTqeB4SyQrGCiWvb3xUCoRyqcfgYRnS3IsCB+sQko4Grd DKkw== X-Gm-Message-State: AOJu0Ywja1Gg0rBhRnR/so5vc4E2slEuRp0FOjHndB3MYMxshn1IUu9k FY0C3WylbVjeT9Bm++z6bSG6WL/1Jtf3aAAVipIzH+PhkaQ8S19G2YmTL8zCP+ndSokhVuGcVps M X-Google-Smtp-Source: AGHT+IGZGcuffzG1KBUd0PmWIboSpnLHTbrJ5M1+rCTcZv7N4n0PE0NOE/6kK5LScxWniocC4zswXw== X-Received: by 2002:a05:6a00:b8c:b0:717:8e01:c593 with SMTP id d2e1a72fcca58-71936a366f8mr32918583b3a.3.1726758383338; Thu, 19 Sep 2024 08:06:23 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71944adfd3dsm8620841b3a.92.2024.09.19.08.06.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2024 08:06:22 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff , =?utf-8?q?Morten_Br=C3=B8rup?= , Bruce Richardson , Chengwen Feng Subject: [PATCH v25 05/15] eal: do not duplicate rte_init_alert() messages Date: Thu, 19 Sep 2024 08:04:11 -0700 Message-ID: <20240919150609.5281-6-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240919150609.5281-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240919150609.5281-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 Acked-by: Morten Brørup Acked-by: Bruce Richardson Acked-by: Chengwen Feng --- 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 d3b40e81d8..7b974608e4 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 0ded386472..7c26393d00 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -840,8 +840,7 @@ static int rte_eal_vfio_setup(void) static void rte_eal_init_alert(const char *msg) { - fprintf(stderr, "EAL: FATAL: %s\n", msg); - EAL_LOG(ERR, "%s", msg); + EAL_LOG(ALERT, "%s", msg); } /* From patchwork Thu Sep 19 15:04:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 144307 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 98763459D7; Thu, 19 Sep 2024 17:07:12 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9380B43392; Thu, 19 Sep 2024 17:06:28 +0200 (CEST) Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by mails.dpdk.org (Postfix) with ESMTP id EA5134337F for ; Thu, 19 Sep 2024 17:06:24 +0200 (CEST) Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-718d91eef2eso640751b3a.1 for ; Thu, 19 Sep 2024 08:06:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1726758384; x=1727363184; 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=o2d4foqEUlKX8e/d7INvNR8WQ2O85ZJBZV4qHltV3dM=; b=xxhNig7e/uABCKaff2Fu6mKMHl7ECsVwHrSpjhwZKp5X4pcMV2ziTDV8nLB4E08yih Jo3gBh9q9CSgMN2dxpjcgzfVOV+j2VnNpb8KixqlLBbyKO3zgL+yjiAh0QVfLUHL7kLk s/ByZEyvd5UbnYYgW/M/Li47CSEDks5HwGkezEIVNfT/ko6nhLhw81XLVFRQFi3bGjDY tVTzXV1E5OMfqeA39wYQlo4xrGv/Q4CoIX5BydRS+wl376tw9OZIPGeiXTX9oRrR7rJu HeT2/GgtH9X5oPfdeQIFv0KZOVuvuepg243w/xxSxz/ZRKuo/LfymxnA30PRshTY8RUG ObNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726758384; x=1727363184; 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=o2d4foqEUlKX8e/d7INvNR8WQ2O85ZJBZV4qHltV3dM=; b=IqtYRuhCJYdiTCiVnsDCrtui0dascS6BB5Cb+DZRVmO7l7Ygtt8p86lffmFO19Qrs8 gchOuwvNXtOO2eLpcJfq9V04n1HjQqCWiRiW7DCV1RhytN5IAXhlo9OrXGp+I1ir7jqk Eapf5gQ+UMxgdZmZNyY/PenEV7+FtI/SGwGPbyuym9j07S1Kl5fqTUyDgnupBDSmJgFq Fd2l7n/UcVeWk6chFldWk3eMAlntvVNjP6AMZYqRxPfLR1G7o1FYJA44tYJJZSKv1dVk N1eGuwSwtXswyvjl2TuGNEdlw8953cqoHOBQOSJw4RumDZBZSdgeYKt3SBEOtF3bH8Y8 hKgQ== X-Gm-Message-State: AOJu0YwJSkndf++biWOeAnFdoQdLO+B5QLS3yBDifLbSO5Id74eVM563 rCL0vFX3qEQSv4UK1smWV3mtdGNwaGGMQz11kaC5n+0g930OYouTBXOgRqaOBUrOJKRxpfiYb8V o X-Google-Smtp-Source: AGHT+IHJvOWXh84q3wEGqHqgqigHpDrmuONMFy1TmVsVlFyO0/A+r8dM4n3pr+QnYnx717jgNSppEw== X-Received: by 2002:a05:6a00:1746:b0:70d:2a1b:422c with SMTP id d2e1a72fcca58-7198e2a8f1dmr5660731b3a.7.1726758384121; Thu, 19 Sep 2024 08:06:24 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71944adfd3dsm8620841b3a.92.2024.09.19.08.06.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2024 08:06:23 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff , =?utf-8?q?Morten_Br=C3=B8rup?= , Bruce Richardson , Chengwen Feng Subject: [PATCH v25 06/15] eal: change rte_exit() output to match rte_log() Date: Thu, 19 Sep 2024 08:04:12 -0700 Message-ID: <20240919150609.5281-7-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240919150609.5281-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240919150609.5281-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: Cannot init EAL: Permission denied Signed-off-by: Stephen Hemminger Acked-by: Tyler Retzlaff Acked-by: Morten Brørup Acked-by: Bruce Richardson Acked-by: Chengwen Feng --- lib/eal/common/eal_common_debug.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/eal/common/eal_common_debug.c b/lib/eal/common/eal_common_debug.c index 3e77995896..bcfcd6df6f 100644 --- a/lib/eal/common/eal_common_debug.c +++ b/lib/eal/common/eal_common_debug.c @@ -36,15 +36,13 @@ rte_exit(int exit_code, const char *format, ...) va_list ap; 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); va_end(ap); if (rte_eal_cleanup() != 0 && rte_errno != EALREADY) - EAL_LOG(CRIT, - "EAL could not release all resources"); + EAL_LOG(CRIT, "EAL could not release all resources"); exit(exit_code); } From patchwork Thu Sep 19 15:04:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 144308 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 428B4459D7; Thu, 19 Sep 2024 17:07:21 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A76D243395; Thu, 19 Sep 2024 17:06:29 +0200 (CEST) Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by mails.dpdk.org (Postfix) with ESMTP id 2ABFB43384 for ; Thu, 19 Sep 2024 17:06:26 +0200 (CEST) Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-71971d20ad9so727168b3a.3 for ; Thu, 19 Sep 2024 08:06:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1726758385; x=1727363185; 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=QLgSGjmdnhB0ApmWLgQwYqKYVzNHujCYMc5LbwZDvjo=; b=PZ+s9kNXlvPtcDk0FCXHwzvw5WpACPp7eJkU1F+P8vO9aKmgvztSHSAjbOfb+BIvl8 xEpHpSnSaAGyo/4hSJZQEZOT33kxeB81l/NabZDqQf8NGSmFyoyApBR/SmgLr6KjhOJq X2JIN5wUfcUPvcwlqtwO3FGE0aLHMbHcirHGmD1PCl5bJbsyjSNMe/2t712V8BUSsmA2 ob5UJaVZGdk/KLal1CvVYyb/c31UBs+O6mFGYxLZkxSVlpmvWMAM6vGbWruMqC5LqcpY QL0FVdkaYILbUQO3/owTdL4F9T9uP7iehHmcj4WuRNS3P5TEQoaN3GuDQIed8TS5JSWK MwUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726758385; x=1727363185; 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=QLgSGjmdnhB0ApmWLgQwYqKYVzNHujCYMc5LbwZDvjo=; b=nqgdv39+sJNZs5NXw4ZTRJSZeVMYuIKBSuPVx535k2D1Awe7kzrldwSeVLK7G+bhmp 4zpNBFCsTmyxUpwyoSwXG69WaWYIu4BBB4HLmzYGZsNkD1AA2oClHjYnLT2m2oEj/agY FW7qwIfcqIsCafLW9ILEuM2blF1F6oWVEoxMrXF7a4L0RXsxD+rUlHWTNpc0BnU+s91T 16nOFNfr5O/UIA3CAYSKMYxcjzl6IA0v3U/P+TDsyy2ribcm0360HWMb+hNqZtkhgl0c SOUAW1DtfKGulNy0QCWVrJzOFnIOis7ykp0lQJh8o/mp0/80Lb/GMfTB5Pl6RqaFmqK7 zdBg== X-Gm-Message-State: AOJu0YzwXiI6gYpxhizPzaHeH5mZB8WWPWMl3qhTKdkkzjzQtXgj3krT HsHk4+yYcwqJifl134sctOwUiuIKvwhrTWFxB+aRbSy+CmD7zapw+bh65dNOj3FgZQntHAfJbvW z X-Google-Smtp-Source: AGHT+IFI95xYw9g15Q8DwhjHhAyAdtKN3Zd3fnxAYYIL6/sqEL3uKy/+l18qS3Zt99gqUpgVu5vV5Q== X-Received: by 2002:a05:6a00:2d89:b0:714:2069:d917 with SMTP id d2e1a72fcca58-71936b1d5femr32860823b3a.25.1726758385277; Thu, 19 Sep 2024 08:06:25 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71944adfd3dsm8620841b3a.92.2024.09.19.08.06.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2024 08:06:24 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , =?utf-8?q?Morten_Br?= =?utf-8?q?=C3=B8rup?= , Bruce Richardson , Chengwen Feng Subject: [PATCH v25 07/15] log: move handling of syslog facility out of eal Date: Thu, 19 Sep 2024 08:04:13 -0700 Message-ID: <20240919150609.5281-8-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240919150609.5281-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240919150609.5281-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 Acked-by: Morten Brørup Acked-by: Bruce Richardson Acked-by: Chengwen Feng --- lib/eal/common/eal_common_options.c | 51 ++--------------------------- lib/eal/common/eal_internal_cfg.h | 1 - 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 + 11 files changed, 70 insertions(+), 65 deletions(-) diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index eb079a65a9..918cc013fe 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; @@ -1877,7 +1830,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/common/eal_internal_cfg.h b/lib/eal/common/eal_internal_cfg.h index 167ec501fa..f53ab8b4aa 100644 --- a/lib/eal/common/eal_internal_cfg.h +++ b/lib/eal/common/eal_internal_cfg.h @@ -84,7 +84,6 @@ struct internal_config { /**< true if storing all pages within single files (per-page-size, * per-node) non-legacy mode only. */ - volatile int syslog_facility; /**< facility passed to openlog() */ /** default interrupt mode for VFIO */ volatile enum rte_intr_mode vfio_intr_mode; /** the shared VF token for VFIO-PCI bound PF and VFs devices */ diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index 7b974608e4..a609d40ee0 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 7c26393d00..5aedd348d1 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); @@ -1113,8 +1113,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 a77e590a72..69a8fc8d80 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 19d7f9cdb6..879567ba15 100644 --- a/lib/log/version.map +++ b/lib/log/version.map @@ -30,5 +30,6 @@ INTERNAL { eal_log_save_pattern; eal_log_save_regexp; eal_log_set_default; + eal_log_syslog; rte_eal_log_cleanup; }; From patchwork Thu Sep 19 15:04:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 144309 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 F11EF459D7; Thu, 19 Sep 2024 17:07:31 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0D37B433A1; Thu, 19 Sep 2024 17:06:31 +0200 (CEST) Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by mails.dpdk.org (Postfix) with ESMTP id 4A0BB4338A for ; Thu, 19 Sep 2024 17:06:27 +0200 (CEST) Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-71790ed8c2dso803349b3a.3 for ; Thu, 19 Sep 2024 08:06:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1726758386; x=1727363186; 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=NqyJ/DNYs3QfP1TWRKCfa1lQOhVqst1pXLLaUVumRKM=; b=D8iVgbT2JEkKl+BEiB/a7nteUOdvJqsdJSMKcJdqtSc1TotSr3yW5yUrxWRyCCVjGG GR3eB2btlRNhWimkOnctIOI2Daq3ZbUj0HFe0wqfJ3qK8WjlSJwvH9UBWUT8ExvKyrUx kly0Em0Y5zIn6QcYTkIdM8Ht9csb8FdqneaD9htt4ydyEy2CtvCbulMo4e9FVtK3w+lB Q67Hcymc2vWKQKoMX/jtsTNITKWHDx2wWxhG85Dfg21EQ44nQAWmvPIDpvWxRkj+VpM/ YCL000r+h4TD3NX7qFRAWPUbj0swmE+GGCjvTYMyONLjnpIusmi1qOP78X3wzR/HEjcI xfLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726758386; x=1727363186; 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=NqyJ/DNYs3QfP1TWRKCfa1lQOhVqst1pXLLaUVumRKM=; b=gltf7OxK+ZPwS7GUehZfS6ulAmQIFyV1qNQWcVgPzIR5XYvuaMog6Cg7kXDw6BTJzv Mpwy9uz7aQ2fZZuSgGDU1wOrFnwX2NzKQ7epkl89ufZOpckSnVV54lijxM490mWC3Nez 8efbMnm8JqlJCXynn0wUc68KO2nuO6hRzRGa0EkYOmiBaFIneWSj/xys4FcYQxtHlK/0 2V1j07j1byoXDpgeLcekMLgjkBI8OZ3mDoL7tUNtPpfLIR/1EwgSKUeEWBz4CUMUC5Qb rMD8y1TTYNku5a7sbh8Wp2SpbyoQwpAlw+STe3pcOW+niYP+ktzNs4PuLRkiz3XcAvak bDFA== X-Gm-Message-State: AOJu0Yz2xuWUD6S9fRHESsbgG89abeJtYfSDgO/vVmHC3Q6mMXRoPNFg XMBkWoUWgtEqxUGVkRLlCwqdBccJiC2Vp621DjS/hNFSR3agD1lCkI7nA7ZF5h8UKj55zIxZ5hv Z X-Google-Smtp-Source: AGHT+IF6Flbozyz2egCNvXeSAZ6zhUbDT+kSbPLKxUsQRMZ4lOFmNyL7KDBSq5tj4GH6OCE2NySu7A== X-Received: by 2002:a05:6a00:2e11:b0:717:86e9:cc34 with SMTP id d2e1a72fcca58-719260812cfmr40638424b3a.8.1726758386139; Thu, 19 Sep 2024 08:06:26 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71944adfd3dsm8620841b3a.92.2024.09.19.08.06.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2024 08:06:25 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff , =?utf-8?q?Morten_Br=C3=B8rup?= , Bruce Richardson , Chengwen Feng Subject: [PATCH v25 08/15] eal: initialize log before everything else Date: Thu, 19 Sep 2024 08:04:14 -0700 Message-ID: <20240919150609.5281-9-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240919150609.5281-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240919150609.5281-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 Acked-by: Morten Brørup Acked-by: Bruce Richardson Acked-by: Chengwen Feng --- 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 a609d40ee0..118c1f593b 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."); @@ -572,9 +581,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 5aedd348d1..fab633976d 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."); @@ -959,9 +968,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); @@ -1113,13 +1119,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 69a8fc8d80..c9648b7da7 100644 --- a/lib/eal/windows/eal.c +++ b/lib/eal/windows/eal.c @@ -250,9 +250,13 @@ rte_eal_init(int argc, char **argv) char cpuset[RTE_CPU_AFFINITY_STR_LEN]; char thread_name[RTE_THREAD_NAME_SIZE]; - eal_log_init(NULL); + if (eal_log_level_parse(argc, argv) < 0) { + rte_eal_init_alert("invalid log arguments."); + rte_errno = EINVAL; + return -1; + } - eal_log_level_parse(argc, argv); + eal_log_init(NULL); if (eal_create_cpu_map() < 0) { rte_eal_init_alert("Cannot discover CPU and NUMA."); diff --git a/lib/log/log_freebsd.c b/lib/log/log_freebsd.c index 953e371bee..33a0925c43 100644 --- a/lib/log/log_freebsd.c +++ b/lib/log/log_freebsd.c @@ -5,8 +5,7 @@ #include #include "log_internal.h" -int +void eal_log_init(__rte_unused const char *id) { - return 0; } diff --git a/lib/log/log_internal.h b/lib/log/log_internal.h index cb15cdff08..d5fabd7ef7 100644 --- a/lib/log/log_internal.h +++ b/lib/log/log_internal.h @@ -14,7 +14,7 @@ * Initialize the default log stream. */ __rte_internal -int eal_log_init(const char *id); +void eal_log_init(const char *id); /* * Determine where log data is written when no call to rte_openlog_stream. diff --git a/lib/log/log_linux.c b/lib/log/log_linux.c index 47aa074da2..6d7dc8f3ab 100644 --- a/lib/log/log_linux.c +++ b/lib/log/log_linux.c @@ -87,18 +87,16 @@ static cookie_io_functions_t console_log_func = { * set the log to default function, called during eal init process, * once memzones are available. */ -int +void eal_log_init(const char *id) { FILE *log_stream; - log_stream = fopencookie(NULL, "w+", console_log_func); - if (log_stream == NULL) - return -1; - openlog(id, LOG_NDELAY | LOG_PID, log_facility); - eal_log_set_default(log_stream); - - return 0; + log_stream = fopencookie(NULL, "w+", console_log_func); + if (log_stream != NULL) + eal_log_set_default(log_stream); + else + eal_log_set_default(stderr); } diff --git a/lib/log/log_windows.c b/lib/log/log_windows.c index a3a756351d..d7c30e4cfa 100644 --- a/lib/log/log_windows.c +++ b/lib/log/log_windows.c @@ -13,12 +13,10 @@ eal_log_syslog(const char *name __rte_unused) } /* set the log to default function, called during eal init process. */ -int +void eal_log_init(__rte_unused const char *id) { rte_openlog_stream(stderr); eal_log_set_default(stderr); - - return 0; } From patchwork Thu Sep 19 15:04:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 144310 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 4A6B0459D7; Thu, 19 Sep 2024 17:07:39 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 271EE433A7; Thu, 19 Sep 2024 17:06:32 +0200 (CEST) Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by mails.dpdk.org (Postfix) with ESMTP id CA25C4338E for ; Thu, 19 Sep 2024 17:06:27 +0200 (CEST) Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-719858156f4so762512b3a.3 for ; Thu, 19 Sep 2024 08:06:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1726758387; x=1727363187; 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=Sp/yKejacTlrR5mk4zYsduqztNhl+ZaMsnnxPUs/+tY=; b=u1ZiY8euaLa2PUaaKLAxB8Gcg3xRA9b5+xl6dcofv6o13ASRlBuN+d+Bkj5mX3yqQd EAJ5aAK+JRpfyv991oTQDW9JP10y9L/r1I992E5UCq24+4ej/Y/X90oVYNyEnDXg7KAq ndAMGmyU/NAmCR7qPw+XCZJhXWjQxN8584QublzNJ9kDXKYtO0z9gisLuPQ+3JpQgmnQ t78HQFbNU2yvlVo7sg4/xnS4bb3F3YPWdQ+5ZsE/kkotwbxgAIr+rBTs2r1RQywh/ZQA RfBiJP78oZWl7Wf6O1Nhrnu+WfcyMDW1ROa69sbtNXYJH7yVBfCsUlw+xa5tHOV3D4Ss BJXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726758387; x=1727363187; 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=Sp/yKejacTlrR5mk4zYsduqztNhl+ZaMsnnxPUs/+tY=; b=oiqRIGNRNmCtwWKzbA/NUuN9prU5qiQsdf9OvnydMRg5ExCFhRMbi+F/ooW8je6ee/ Q7l+5v7CMwK9AKLRJMyMz9OJXHEVZghSZJYM8HWc+/ajwIrBZ2Ha9RgegXoY74Z1qptY NmEILrlUXxrPdF3LA2ohz7cB4yMmFlOVBdgfkJgB0aw/VUPW9hTWvWkJLBWxVK5fqChJ 9cPZD7nz8OwRae4Hmuw3R/ZPuTjBhqtxW7WX3cpKdSqaPkYj5Xb53jX3XuQQgOrbFEW0 zwWetZBGJJrRvQ0JBNZiF5NpD4zZPRvdrcnC5tHgCBlyZyQmKjY6BqWz4jomNGArlOTp Bimg== X-Gm-Message-State: AOJu0Yw8fIfIVdaXqLM1uXbUhnZGXXlEUSjUf9TqZQuskJG/w9krvX2u 4wGmKoTzs0dCUoGlGEYV9ibeXs/cCaeFRYikK7iSeQrHzoZ8xyfL0bKMS1wCzkQqoSwbc5QtGMO K X-Google-Smtp-Source: AGHT+IEGU6v4r7ehK1jRXm8DCdKNOYRyD3frPKoLmrGEOvjGYJXVIaxnthveSciEDg1/vbvUipQ0dg== X-Received: by 2002:a05:6a00:2daa:b0:717:9154:b5b6 with SMTP id d2e1a72fcca58-7192606ce9emr41140823b3a.7.1726758386919; Thu, 19 Sep 2024 08:06:26 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71944adfd3dsm8620841b3a.92.2024.09.19.08.06.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2024 08:06:26 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , =?utf-8?q?Morten_Br?= =?utf-8?q?=C3=B8rup?= , Bruce Richardson Subject: [PATCH v25 09/15] log: drop syslog support, and make code common Date: Thu, 19 Sep 2024 08:04:15 -0700 Message-ID: <20240919150609.5281-10-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240919150609.5281-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240919150609.5281-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 Acked-by: Morten Brørup Acked-by: Bruce Richardson --- 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 71d8dba731..a5c0c67357 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 918cc013fe..ea45c79d5c 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -2206,9 +2206,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 879567ba15..a0341196d4 100644 --- a/lib/log/version.map +++ b/lib/log/version.map @@ -29,7 +29,6 @@ INTERNAL { eal_log_level2str; eal_log_save_pattern; eal_log_save_regexp; - eal_log_set_default; eal_log_syslog; rte_eal_log_cleanup; }; From patchwork Thu Sep 19 15:04:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 144311 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 34579459D7; Thu, 19 Sep 2024 17:07:47 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4A960433AA; Thu, 19 Sep 2024 17:06:33 +0200 (CEST) Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) by mails.dpdk.org (Postfix) with ESMTP id 8B42B43390 for ; Thu, 19 Sep 2024 17:06:28 +0200 (CEST) Received: by mail-pg1-f179.google.com with SMTP id 41be03b00d2f7-7d4fa972cbeso702524a12.2 for ; Thu, 19 Sep 2024 08:06:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1726758388; x=1727363188; 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=UCRQWgJapj7+HojJ8oBIRtUN3JgniCpMlRHwhFLw+h4=; b=m1sRgA2TjAw38ytqsHrT5kJ6sar4eKsnDfmX6aGlKRik2PhwU8fWli7+fdsf1Eqln1 IUAWq1QzV5bnL2yxeNlqcwHdAUfMrteLMaFVYqu722Bf1NvGKfssr4xejzwnQ+wuMDIU KLtRcv4bf3Y+aJmN0R1/IKmzmLRSStb2IYH+SIkIyl0KFMxADlc2YVvWPUWF1cPEJBge nxfDDt37mJmh3oExNZPW8INkBU46s7TjRlRG+qSqMR7e6JhmXSYhZa7yhyGrNrRCPAP6 xy8hO+rOvwHiANW/vOUo32xq//zrArujX+Qnq9bIlS6+6othac2XReRdIYK7iZ8RQthU pVpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726758388; x=1727363188; 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=UCRQWgJapj7+HojJ8oBIRtUN3JgniCpMlRHwhFLw+h4=; b=Te0I+/AL2OWXlLTdETK7rMxqW/f7CzZq8eKyhf9kDPgEWPwcqtLd7/hvrUf1LH6Dpa klaYIF6OC6ek8ff2140G41yNl2inHrGWqafN9NV6Bg3/eFYq7mS0azzychyHDed6O3DW qwSOUXSaJTN7jV/DQO3Dz6PrEVZwDnohvtxxysSLuna3Egwgl/mH7yvHTNTRqafcuFIA QV3M3JY/saLJUOA08XQn4c125aIfHFAW6E3L7XmgoOM7BD06raq+uhalTnMX8iz6SUlb FDH6CwJXgzg+8mX5lvryi/z2ING2fh/r4whMHFFheV7NEKFEVx6jJqVjOWmBe4O/tzwG Y3UA== X-Gm-Message-State: AOJu0Yx+5iiL1F5VXD02NOgiFfKXaKnZZfhTW05w9wPGvACF50TyeSWk ONZwXt2oxoPZhyPLKEcKfZQKfC2zEr05/NNy73Lj5f7CEVtkvHM3Sk5SXtJet21ulgpyASXkyoQ J X-Google-Smtp-Source: AGHT+IE+fi8TC9Ca9MUtejNFhWq44gH8E9zrlF+9G48LDWVYNRZxOkGx3dP6RxU+QKasBW38W0ASUg== X-Received: by 2002:a05:6a21:3a41:b0:1cf:5b31:313a with SMTP id adf61e73a8af0-1cf75c7e923mr38773866637.1.1726758387690; Thu, 19 Sep 2024 08:06:27 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71944adfd3dsm8620841b3a.92.2024.09.19.08.06.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2024 08:06:27 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , =?utf-8?q?Morten_Br?= =?utf-8?q?=C3=B8rup?= , Bruce Richardson , Chengwen Feng Subject: [PATCH v25 10/15] log: add hook for printing log messages Date: Thu, 19 Sep 2024 08:04:16 -0700 Message-ID: <20240919150609.5281-11-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240919150609.5281-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240919150609.5281-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 Acked-by: Morten Brørup Acked-by: Bruce Richardson Acked-by: Chengwen Feng --- lib/log/log.c | 6 +++++- lib/log/log_private.h | 9 +++++++++ 2 files changed, 14 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..48543ee941 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 @@ -33,11 +34,13 @@ 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 = vfprintf, }; struct rte_eal_opt_loglevel { @@ -74,6 +77,7 @@ int rte_openlog_stream(FILE *f) { rte_logs.file = f; + rte_logs.print_func = vfprintf; return 0; } @@ -470,7 +474,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, format, ap); fflush(f); return ret; } diff --git a/lib/log/log_private.h b/lib/log/log_private.h new file mode 100644 index 0000000000..67d2463b2f --- /dev/null +++ b/lib/log/log_private.h @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ + +#ifndef LOG_PRIVATE_H +#define LOG_PRIVATE_H + +/* Note: same as vfprintf() */ +typedef int (*log_print_t)(FILE *f, const char *fmt, va_list ap); + +#endif /* LOG_PRIVATE_H */ From patchwork Thu Sep 19 15:04:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 144312 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 6D58A459D7; Thu, 19 Sep 2024 17:07:57 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C95A8433B7; Thu, 19 Sep 2024 17:06:34 +0200 (CEST) Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by mails.dpdk.org (Postfix) with ESMTP id C068843397 for ; Thu, 19 Sep 2024 17:06:29 +0200 (CEST) Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-71971d20ad9so727225b3a.3 for ; Thu, 19 Sep 2024 08:06:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1726758389; x=1727363189; 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=DXbsWp9THxcRQDQthFKd3FlOD3vxmrSwxQgimzXXiMA=; b=l8ftPOL9S1NJKwbpqbNE4g5i7mo1g/1VACHQYl2Ka9JkDnzVTqEzdHNK4TAuWsMfOU rZfy0bkwWVNsuLu0Die/xHmC7pAvCXT0Fv50f7565ZBliQVWfDAZinnNu510RRrxqFZk VmTnr6ivICELqVjdRjIT611gasrpv02cz7zQKQ92Ik200syhXXcrHgsoSlk3M0ji/Yut bfprwG22rhzSq5V1T5OSVODMcTmTX8lShNEU5RunuraQRfq7WnIRiBnM7Gm/gTVQC/tO i9GRE2Beq9K/nCvKooayYzyB8cDy+wPhfJwt+to3yUFme/qOPtwIYWb+zOAuVG2wK1CG utQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726758389; x=1727363189; 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=DXbsWp9THxcRQDQthFKd3FlOD3vxmrSwxQgimzXXiMA=; b=erWk0/h/628c9nbyDja6f7dNDSu1v4+nzXsKG4RGCg9UgS8gtqHV2U7iGMXU5LpnF2 J2OKjuIo1GyydVLn65XzfKPqJeC7nrj1FgY2X30C8miQfCjSYcN9QJpW6MwDeJYn0jv4 jjVdRunwjoIoRBsR3uE6GPzaxOO/MTZDok7GZlT+z3PAMnA6mKtptSW2davZGIjdDtao hM4HiMbg2gmC32ScvK093hnDDoIYZLlVBPlnOgednF0OrObR1ZGQU2Ebc9t5D3BCB2CC 0ydSnG2ZUMeIeNQYdcQxSrM5ztDwJFz5o4tyIuI+X/FXROSa1QbdWpxlWHfMG95QZJbL lWXQ== X-Gm-Message-State: AOJu0Yz0x4Vk+XeKWmeoXSqxzXWrJ4yBXsRiVZ2zdtAKtAfK1md/fk4l TjFbt95cTqk9+gTO2SPz6J+Qu9tHSlNNWZZNjUfYyJh1wvCazA1QMmfb73vAPKndwFRCzT1OEGi 2 X-Google-Smtp-Source: AGHT+IEjOOsED0jbw7+wbQM9ORG/0t/7+ApmRmzEdZHIv9Uk8nNYnlGsO91cHLQmLSd9K53TUT2gJQ== X-Received: by 2002:a05:6a00:3d0d:b0:718:dc17:3b83 with SMTP id d2e1a72fcca58-71936a84fd7mr35969523b3a.16.1726758388539; Thu, 19 Sep 2024 08:06:28 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71944adfd3dsm8620841b3a.92.2024.09.19.08.06.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2024 08:06:28 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , =?utf-8?q?Morten_Br?= =?utf-8?q?=C3=B8rup?= , Bruce Richardson Subject: [PATCH v25 11/15] log: add timestamp option Date: Thu, 19 Sep 2024 08:04:17 -0700 Message-ID: <20240919150609.5281-12-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240919150609.5281-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240919150609.5281-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 Acked-by: Morten Brørup Acked-by: Bruce Richardson --- 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 | 7 +- lib/log/log_internal.h | 9 ++ lib/log/log_private.h | 11 ++ lib/log/log_timestamp.c | 240 ++++++++++++++++++++++++++++ lib/log/meson.build | 6 +- lib/log/version.map | 1 + 13 files changed, 348 insertions(+), 8 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 a5c0c67357..40dd288d5f 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 ea45c79d5c..ec3b5c3dfd 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; @@ -1838,7 +1840,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 --" @@ -1846,7 +1848,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: { @@ -2210,6 +2219,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 118c1f593b..06bccbd026 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 fab633976d..ceaa1f9487 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 c9648b7da7..0fda2abb97 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 48543ee941..6ab856272c 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 { @@ -509,6 +509,11 @@ eal_log_syslog(const char *mode __rte_unused) 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 = vfprintf; + #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 67d2463b2f..67cfe72fc6 100644 --- a/lib/log/log_private.h +++ b/lib/log/log_private.h @@ -3,7 +3,18 @@ #ifndef LOG_PRIVATE_H #define LOG_PRIVATE_H +/* Defined in limits.h on Linux */ +#ifndef LINE_MAX +#define LINE_MAX 2048 /* _POSIX2_LINE_MAX */ +#endif + /* Note: same as vfprintf() */ typedef int (*log_print_t)(FILE *f, const char *fmt, va_list ap); +bool log_timestamp_enabled(void); +ssize_t log_timestamp(char *tsbuf, size_t tsbuflen); + +__rte_format_printf(2, 0) +int log_print_with_timestamp(FILE *f, 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..b4b0bca6a8 --- /dev/null +++ b/lib/log/log_timestamp.c @@ -0,0 +1,240 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#ifdef RTE_EXEC_ENV_WINDOWS +#include +#endif + +#include "log_internal.h" +#include "log_private.h" + +#ifndef NS_PER_SEC +#define NS_PER_SEC 1E9 +#endif + +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 */ + RTE_ATOMIC(uint64_t) last_monotonic; + RTE_ATOMIC(uint64_t) last_realtime; +} 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); +} + +/* + * Format a timestamp which shows time between messages. + */ +static ssize_t +format_delta(char *tsbuf, size_t tsbuflen, const struct timespec *now) +{ + struct timespec delta; + uint64_t ns = rte_timespec_to_ns(now); + uint64_t previous; + + previous = rte_atomic_exchange_explicit(&log_time.last_monotonic, + ns, rte_memory_order_seq_cst); + delta = rte_ns_to_timespec(ns - previous); + + return snprintf(tsbuf, tsbuflen, "<%6lu.%06lu>", + (unsigned long)delta.tv_sec, + (unsigned long)delta.tv_nsec / 1000u); +} + +/* + * 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, *last_tm, tbuf1, tbuf2; + time_t last_sec; + uint64_t ns = rte_timespec_to_ns(now); + uint64_t previous; + + tm = localtime_r(&now->tv_sec, &tbuf1); + + previous = rte_atomic_exchange_explicit(&log_time.last_realtime, + ns, rte_memory_order_seq_cst); + last_sec = previous / NS_PER_SEC; + last_tm = localtime_r(&last_sec, &tbuf2); + if (tm->tm_min == last_tm->tm_min && + tm->tm_hour == last_tm->tm_hour && + tm->tm_yday == last_tm->tm_yday) { + struct timespec elapsed; + + elapsed = rte_ns_to_timespec(ns - previous); + + return snprintf(tsbuf, tsbuflen, "+%3lu.%06lu", + (unsigned long)elapsed.tv_sec, + (unsigned long)elapsed.tv_nsec / 1000u); + } else { + return strftime(tsbuf, tsbuflen, "%b%d %H:%M", tm); + } +} + +/* 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; + + return format_delta(tsbuf, tsbuflen, &now); + + 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, const char *format, va_list ap) +{ + char tsbuf[128]; + char msgbuf[LINE_MAX]; + + if (log_timestamp(tsbuf, sizeof(tsbuf)) > 0) { + vsnprintf(msgbuf, sizeof(msgbuf), format, ap); + return fprintf(f, "[%s] %s", tsbuf, msgbuf); + } + + /* fall back when timestamp is unavailable */ + return vfprintf(f, format, ap); +} + +RTE_INIT_PRIO(log_timestamp_init, LOG) +{ + struct timespec now; + + clock_gettime(CLOCK_MONOTONIC, &now); + log_time.started = now; + rte_atomic_store_explicit(&log_time.last_monotonic, rte_timespec_to_ns(&now), + rte_memory_order_seq_cst); +} 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 a0341196d4..155f8b3bbe 100644 --- a/lib/log/version.map +++ b/lib/log/version.map @@ -30,5 +30,6 @@ INTERNAL { eal_log_save_pattern; eal_log_save_regexp; eal_log_syslog; + eal_log_timestamp; rte_eal_log_cleanup; }; From patchwork Thu Sep 19 15:04:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 144313 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 9AF1B459D7; Thu, 19 Sep 2024 17:08:05 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D82B4433BB; Thu, 19 Sep 2024 17:06:35 +0200 (CEST) Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by mails.dpdk.org (Postfix) with ESMTP id 534E843398 for ; Thu, 19 Sep 2024 17:06:30 +0200 (CEST) Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-7191fb54147so714978b3a.2 for ; Thu, 19 Sep 2024 08:06:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1726758389; x=1727363189; 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=VCMQ7UEmh1fK4gLZEWFsbqtXzdgnRrok0p5y8h8V/NU=; b=dxVEvhFVChuk4fG4WY4OzgNMO5/DfhVVgPpPOEV8lnQw/uYaL61evo2GJLpceemk3M ZQFn24r6yuYUlV6G04MpJueds8/tSX6c9m6v1yfpmweFnWh8VZ0oT+Neo/viFE7BYoN5 IMRJYoDCfLAN8/JR4h00hxJST+y15/17iluSq0qZuStUOx5dFiPS8V8aj8MzjsZ9mCJh ufcymnR7ZVYtqml/zdVt3CvkhRcTfA/bxHdRJvDBvCrfrqABid/A83PqIxDK/qKO5utQ n9Ujb+Y/kuQePoSx2lEYdExx3ov/7tkt7P8tM8ljlyKlxjIXgdh9/5Pn/hfXKF8YzthU YG1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726758389; x=1727363189; 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=VCMQ7UEmh1fK4gLZEWFsbqtXzdgnRrok0p5y8h8V/NU=; b=DAMt6ixx1rap20vDSrpERqJGfZhZchjYJnwhQUw3oYfNA6MelMytjbL8RDHVU0aU9u HJEXEY30Te9f/wmzZ6fOewUQqtU8olPPMDr+DRXvI7u49iHrQpPKQxpKKeb08lpdqr55 hqg9kXsVD0a+WJr1G72RuQ+NW/II54WVVTs5d+eO/8PbRGjRZlYs6BpkTGTe98VmGGu0 2NthgPB37MqUkXEjz4mSpkccxipELFN9iddXtU+FwZeqruUPAurrB7zSOVg5/HydXdeI /daEW0XpULQB6m9RgIgn6KihfLWOz9Rlv27gLSYpN6KhdqYMb1c7XyShZyBZt/Nz6YVw 0ZFQ== X-Gm-Message-State: AOJu0YytTOh++vEr9iTXDjweqs8xV1ZUSLCwO2bgFrD7fjO6SFMKqhRe uOUnSt1MXdTxlBb9stGWcjpX/wTQHZDBjy/JtVYntiJUojTx/cLxRDjHrOZioYSesVV4kBYn3nO + X-Google-Smtp-Source: AGHT+IED6zp5CzvLkjgFuoGhjxOhDa0GI+6wstSCFyBhaiVrgv1OtUbWuFMwkHC6tX6WLP+Y3eVEWw== X-Received: by 2002:a05:6a21:58d:b0:1cf:29a8:8e1c with SMTP id adf61e73a8af0-1cf75f6544fmr39828960637.28.1726758389457; Thu, 19 Sep 2024 08:06:29 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71944adfd3dsm8620841b3a.92.2024.09.19.08.06.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2024 08:06:29 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , =?utf-8?q?Morten_Br?= =?utf-8?q?=C3=B8rup?= , Bruce Richardson , Chengwen Feng Subject: [PATCH v25 12/15] log: add optional support of syslog Date: Thu, 19 Sep 2024 08:04:18 -0700 Message-ID: <20240919150609.5281-13-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240919150609.5281-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240919150609.5281-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 Acked-by: Morten Brørup Acked-by: Bruce Richardson Acked-by: Chengwen Feng --- 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 | 28 +++--- lib/log/log_private.h | 17 ++++ lib/log/log_syslog.c | 88 +++++++++++++++++++ lib/log/meson.build | 4 + lib/log/version.map | 2 +- 9 files changed, 150 insertions(+), 43 deletions(-) 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 40dd288d5f..06295030b2 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 ec3b5c3dfd..ac1aadbef4 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 }, @@ -2215,6 +2215,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 6ab856272c..f748551bc0 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,20 +497,23 @@ 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 rte_eal_init */ void -eal_log_init(const char *id __rte_unused) +eal_log_init(const char *id) { - if (log_timestamp_enabled()) + bool is_terminal; + +#ifdef RTE_EXEC_ENV_WINDOWS + is_terminal = _isatty(_fileno(stderr)); +#else + is_terminal = isatty(STDERR_FILENO); +#endif + + if (log_syslog_enabled(is_terminal)) + log_syslog_open(id, is_terminal); + else if (log_timestamp_enabled()) rte_logs.print_func = log_print_with_timestamp; else rte_logs.print_func = vfprintf; diff --git a/lib/log/log_private.h b/lib/log/log_private.h index 67cfe72fc6..532a481340 100644 --- a/lib/log/log_private.h +++ b/lib/log/log_private.h @@ -17,4 +17,21 @@ ssize_t log_timestamp(char *tsbuf, size_t tsbuflen); __rte_format_printf(2, 0) int log_print_with_timestamp(FILE *f, const char *format, va_list ap); +#ifdef RTE_EXEC_ENV_WINDOWS +static inline bool +log_syslog_enabled(bool is_tty __rte_unused) +{ + return false; +} + +static inline void +log_syslog_open(const char *id __rte_unused, bool is_terminal __rte_unused) +{ +} +#else + +bool log_syslog_enabled(bool is_tty); +void log_syslog_open(const char *id, bool is_terminal); +#endif + #endif /* LOG_PRIVATE_H */ diff --git a/lib/log/log_syslog.c b/lib/log/log_syslog.c new file mode 100644 index 0000000000..fb69921e05 --- /dev/null +++ b/lib/log/log_syslog.c @@ -0,0 +1,88 @@ +/* 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; + } +} + +/* + * When syslog is used, the log stream is redirected to a + * pseudo FILE handle that calls these functions. + */ +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..4ac232786e 100644 --- a/lib/log/meson.build +++ b/lib/log/meson.build @@ -7,4 +7,8 @@ sources = files( 'log_timestamp.c', ) +if not is_windows + sources += files('log_syslog.c') +endif + headers = files('rte_log.h') diff --git a/lib/log/version.map b/lib/log/version.map index 155f8b3bbe..8be6907840 100644 --- a/lib/log/version.map +++ b/lib/log/version.map @@ -29,7 +29,7 @@ INTERNAL { eal_log_level2str; eal_log_save_pattern; eal_log_save_regexp; - eal_log_syslog; + eal_log_syslog; # WINDOWS_NO_EXPORT eal_log_timestamp; rte_eal_log_cleanup; }; From patchwork Thu Sep 19 15:04:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 144314 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 746A7459D7; Thu, 19 Sep 2024 17:08:12 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DDCD2433BE; Thu, 19 Sep 2024 17:06:36 +0200 (CEST) Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by mails.dpdk.org (Postfix) with ESMTP id 34ADD433A3 for ; Thu, 19 Sep 2024 17:06:31 +0200 (CEST) Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-71781f42f75so889589b3a.1 for ; Thu, 19 Sep 2024 08:06:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1726758390; x=1727363190; 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=wuSjSa35Zp6DKCw2curz41jubbYWUKlY61Ld4E16Nmo=; b=ZHcjnLxPayVM43Mki21EEwYhMmUDrnNnPOVaq1qu9QWq+bAd5w3GS8u8A6uXQVs2H8 JReP7kb9sEGBVpvVtv3eVKykq9I0RlJ/aMtYNTPbroRaJINKQqie7ZsCRS1LP67nG3QN 4RnRMa0Uv0U85AmVXcCg0NBWTZrdGGllv8qdn3KJqLqvFpwxG65q8eo67HJjCYgiLfnn kk6/wyMkTK/TQopFDvXfXu4p7RXWt+gORqhxMsCwCrIKGJ9dmHcC4kpAI7mrkv5Y0yl4 qf+oG6QrRC2aE45v6MivJg3vKbSc+u55LRBAWmrOcDpgPbQ5JQYkQwXFdRlvV+28GZEq C6YA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726758390; x=1727363190; 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=wuSjSa35Zp6DKCw2curz41jubbYWUKlY61Ld4E16Nmo=; b=FqZxXjc+9uhRH/5fWqx0M7XwSma+hb5VGiaR7NkWvEsCO7mFH022axHf6xfncC380p 2NnJJ6KaKZaVvLPKSI3fYEhdTqBXW+QhCQLyQMoEoARW9os03NHuT6plsAUaYlkryVxL bLKyCgMv8aoBvMQ2Ebj+MG5hkiwuEHTcBM0rhgR43GBUq9fxmOfaJ+UFrb2sCP9XzrYE axbaYNlAkBqc1vlSJjqe1zEDbE0S/MFendft++5RZXOXVjYRR7VJshFACx9iIO3eAL7I 3B9ud2rW+tzPUjv5sgBtVshzm/gn3HK1nkot4hIA7bqDd11HY5tn88M7ywVpDle/fNcj n+zA== X-Gm-Message-State: AOJu0YxzLZ6Sn4iW1XxR1Bi7CaaNwkzXvA0Wg+86LDGfSyTvKGxrlnDc /OOK4hkvOQXLaEAv3j8lOd6+05EEuv0aQsBFnwTbLcCct0ckP+16TEKbtCURyzf04oI2hFzpAH9 O X-Google-Smtp-Source: AGHT+IG7zBmV9ZklhYPZ73nw+tb4pQOEQfjiSZQRCDsZD9BGJcgJ2jmtcSIxS5lrAcjdfKqWyPDWqg== X-Received: by 2002:a05:6a00:4613:b0:710:5a64:30d5 with SMTP id d2e1a72fcca58-71926065766mr44740247b3a.6.1726758390253; Thu, 19 Sep 2024 08:06:30 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71944adfd3dsm8620841b3a.92.2024.09.19.08.06.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2024 08:06:29 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , =?utf-8?q?Morten_Br?= =?utf-8?q?=C3=B8rup?= , Bruce Richardson Subject: [PATCH v25 13/15] log: add support for systemd journal Date: Thu, 19 Sep 2024 08:04:19 -0700 Message-ID: <20240919150609.5281-14-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240919150609.5281-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240919150609.5281-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 Acked-by: Morten Brørup Acked-by: Bruce Richardson --- doc/guides/prog_guide/log_lib.rst | 14 ++ lib/eal/common/eal_common_options.c | 15 +++ lib/eal/common/eal_options.h | 2 + lib/log/log.c | 4 +- lib/log/log_internal.h | 3 + lib/log/log_journal.c | 200 ++++++++++++++++++++++++++++ lib/log/log_private.h | 16 +++ lib/log/meson.build | 4 + lib/log/version.map | 1 + 9 files changed, 258 insertions(+), 1 deletion(-) 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 ac1aadbef4..6184d27ad3 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; @@ -1840,6 +1842,16 @@ eal_parse_common_option(int opt, const char *optarg, break; #endif +#ifdef RTE_EXEC_ENV_LINUX + 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: if (eal_parse_log_level(optarg) < 0) { EAL_LOG(ERR, @@ -2217,6 +2229,9 @@ 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" +#endif +#ifdef RTE_EXEC_ENV_LINUX + " --"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 f748551bc0..96fa651e81 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -511,7 +511,9 @@ eal_log_init(const char *id) is_terminal = isatty(STDERR_FILENO); #endif - if (log_syslog_enabled(is_terminal)) + if (log_journal_enabled()) + log_journal_open(id); + else if (log_syslog_enabled(is_terminal)) log_syslog_open(id, is_terminal); else if (log_timestamp_enabled()) rte_logs.print_func = log_print_with_timestamp; 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..2475174fce --- /dev/null +++ b/lib/log/log_journal.c @@ -0,0 +1,200 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ + +#include +#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(const char *buf, size_t len) +{ + struct iovec iov[4]; + unsigned int n = 0; + int priority = rte_log_cur_msg_loglevel() - 1; + char msg[] = "MESSAGE="; + char newline = '\n'; + char pbuf[16]; /* "PRIORITY=N\n" */ + + iov[n].iov_base = msg; + iov[n++].iov_len = strlen(msg); + + iov[n].iov_base = (char *)(uintptr_t)buf; + iov[n++].iov_len = len; + + /* if message doesn't end with newline, one will be applied. */ + if (buf[len - 1] != '\n') { + iov[n].iov_base = &newline; + iov[n++].iov_len = 1; + } + + /* priority value between 0 ("emerg") and 7 ("debug") */ + iov[n].iov_base = pbuf; + iov[n++].iov_len = snprintf(pbuf, sizeof(pbuf), + "PRIORITY=%d\n", priority); + + return writev(log_journal_fd, iov, n); +} + + +/* 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(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(void) +{ + 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; + + return true; +} + +void log_journal_open(const char *id) +{ + FILE *log_stream; + char *syslog_id = NULL; + ssize_t len; + + /* 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; + } + +error: + free(syslog_id); + close(log_journal_fd); + log_journal_fd = -1; +} diff --git a/lib/log/log_private.h b/lib/log/log_private.h index 532a481340..d8602681b2 100644 --- a/lib/log/log_private.h +++ b/lib/log/log_private.h @@ -34,4 +34,20 @@ bool log_syslog_enabled(bool is_tty); void log_syslog_open(const char *id, bool is_terminal); #endif +#ifdef RTE_EXEC_ENV_LINUX +bool log_journal_enabled(void); +void log_journal_open(const char *id); +#else +static inline bool +log_journal_enabled(void) +{ + return false; +} + +static inline void +log_journal_open(const char *id __rte_unused) +{ +} +#endif /* !RTE_EXEC_ENV_LINUX */ + #endif /* LOG_PRIVATE_H */ diff --git a/lib/log/meson.build b/lib/log/meson.build index 4ac232786e..86e4452b19 100644 --- a/lib/log/meson.build +++ b/lib/log/meson.build @@ -11,4 +11,8 @@ if not is_windows sources += files('log_syslog.c') endif +if is_linux + sources += files('log_journal.c') +endif + headers = files('rte_log.h') diff --git a/lib/log/version.map b/lib/log/version.map index 8be6907840..800d3943bc 100644 --- a/lib/log/version.map +++ b/lib/log/version.map @@ -26,6 +26,7 @@ INTERNAL { global: eal_log_init; + eal_log_journal; # WINDOWS_NO_EXPORT eal_log_level2str; eal_log_save_pattern; eal_log_save_regexp; From patchwork Thu Sep 19 15:04:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 144315 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 3794D459D7; Thu, 19 Sep 2024 17:08:20 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 48CFA433C1; Thu, 19 Sep 2024 17:06:38 +0200 (CEST) Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) by mails.dpdk.org (Postfix) with ESMTP id E65CA433A3 for ; Thu, 19 Sep 2024 17:06:31 +0200 (CEST) Received: by mail-pg1-f175.google.com with SMTP id 41be03b00d2f7-6e7b121be30so689631a12.1 for ; Thu, 19 Sep 2024 08:06:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1726758391; x=1727363191; 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=A67zJHlmj5y1HXSuG1hOh2ddpgeTFki1nMbA8mHcipM=; b=zmTQd3Km2lWUXb9orsuEnByVIIYoYa5MJqWD2apUYblW3WRQaP6TSN279Nquyz08xp VdRGCuR3XL6O+in1LDW/ugT8hvLIx0IbGJOiabL2lUVjyoSAasKq/lljKQTUZTR2TViY LQfTJTDkZj3iMe4PbI51S0udbK9fjiFs2ByGTcFBDZvFCsY1jj4/5SIvx6s4jrwl5xbC 7J1Paz7NroxjI14GIUeOm9jcTXM7WJnPapTGey8O6MIAhNtB7Te8yZO6KRc0hoaLOywz 1FlS0ZbG3vgLm6S/unNb+iv3vsD3V7DnO4/DVajBOka/CmbNGiprSwyZ5jtT2pMqHhiL ibzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726758391; x=1727363191; 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=A67zJHlmj5y1HXSuG1hOh2ddpgeTFki1nMbA8mHcipM=; b=Avghrz0G++uLKyXgWNE6oajREitk1iTaMQ0OovrrAkLPHlQLbOH8bu9VVjMe3lu2zY YdB2NNa0iRAHhzY9Dlu7xj1DR8fBecYja8RCxjjasb5CnC0XMQm9Z5Elo3mH6UHpGBnw bQMViEyxnzPny+mxntdnS/+mhNELm5Boxssa29NR+uCr0cJVp0sJfS8gLm8wiYLqilgI k634MnBfwQ0OEdfV9SAQlfhJAlyhz4a8KeaSYZYTGHlBHxUxCY/cJ2PayS7Nv+ljgBFb 8WlRRPkFLHFJYs3BI0Pd/64N7lLfjw73MyFb+JQxjp4eCttjuPuMJ6LRNTqkeqekztMq PWnA== X-Gm-Message-State: AOJu0Yz1pQleQWA1aDgurLvLHB3STz4OBgPhoIXJP5h3cYyB0BXuaPCH lKN1OxjpBmtBcQeil/H2XEordgVINhZar9Pl6Jvm2MsxnrZrnHwkCmaN7Owzi8jQloklPN1JORa v X-Google-Smtp-Source: AGHT+IEUB2XLqhm4DxcWlMv3nrmPhSLVjQ1bU3L7nipPn5cpP3D8PMS5k7UX7M3YD4u4OOpedm2pMw== X-Received: by 2002:a05:6a20:c70e:b0:1cf:4748:8868 with SMTP id adf61e73a8af0-1d112b60b6dmr36792997637.16.1726758391032; Thu, 19 Sep 2024 08:06:31 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71944adfd3dsm8620841b3a.92.2024.09.19.08.06.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2024 08:06:30 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , =?utf-8?q?Morten_Br?= =?utf-8?q?=C3=B8rup?= , Bruce Richardson , Chengwen Feng Subject: [PATCH v25 14/15] log: colorize log output Date: Thu, 19 Sep 2024 08:04:20 -0700 Message-ID: <20240919150609.5281-15-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240919150609.5281-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240919150609.5281-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 Acked-by: Morten Brørup Acked-by: Bruce Richardson Acked-by: Chengwen Feng --- app/test/test_eal_flags.c | 24 +++++ doc/guides/prog_guide/log_lib.rst | 15 +++ lib/eal/common/eal_common_options.c | 11 +++ lib/eal/common/eal_options.h | 6 +- lib/log/log.c | 19 ++-- lib/log/log_color.c | 148 ++++++++++++++++++++++++++++ lib/log/log_internal.h | 5 + lib/log/log_private.h | 8 ++ lib/log/meson.build | 1 + lib/log/version.map | 1 + 10 files changed, 230 insertions(+), 8 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 06295030b2..6ee56ec97a 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..647c3fc28a 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 ~~~~~~~~~~~~~ diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index 6184d27ad3..de19b1c258 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; @@ -1869,6 +1871,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) { @@ -2238,6 +2248,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 96fa651e81..8b7b394f49 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -511,14 +511,21 @@ eal_log_init(const char *id) is_terminal = isatty(STDERR_FILENO); #endif - if (log_journal_enabled()) + if (log_journal_enabled()) { log_journal_open(id); - else if (log_syslog_enabled(is_terminal)) + } else if (log_syslog_enabled(is_terminal)) { log_syslog_open(id, is_terminal); - else if (log_timestamp_enabled()) - rte_logs.print_func = log_print_with_timestamp; - else - rte_logs.print_func = vfprintf; + } else if (log_timestamp_enabled()) { + if (log_color_enabled(is_terminal)) + rte_logs.print_func = color_print_with_timestamp; + else + rte_logs.print_func = log_print_with_timestamp; + } else { + if (log_color_enabled(is_terminal)) + rte_logs.print_func = color_print; + else + rte_logs.print_func = vfprintf; + } #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..db11306e55 --- /dev/null +++ b/lib/log/log_color.c @@ -0,0 +1,148 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ + +#include +#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; +} + +/* + * 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, const char *format, va_list ap) +{ + const int level = rte_log_cur_msg_loglevel(); + char *cp, *msg; + char buf[LINE_MAX]; + int ret = 0; + + vsnprintf(buf, LINE_MAX, format, ap); + msg = buf; + + /* + * 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(f, 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; +} + +int +color_print_with_timestamp(FILE *f, 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, 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 d8602681b2..855e32db90 100644 --- a/lib/log/log_private.h +++ b/lib/log/log_private.h @@ -50,4 +50,12 @@ log_journal_open(const char *id __rte_unused) } #endif /* !RTE_EXEC_ENV_LINUX */ +bool log_color_enabled(bool is_tty); + +__rte_format_printf(2, 0) +int color_print(FILE *f, const char *format, va_list ap); + +__rte_format_printf(2, 0) +int color_print_with_timestamp(FILE *f, const char *format, va_list ap); + #endif /* LOG_PRIVATE_H */ diff --git a/lib/log/meson.build b/lib/log/meson.build index 86e4452b19..b3de57b9c7 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', ) diff --git a/lib/log/version.map b/lib/log/version.map index 800d3943bc..09d8a4289b 100644 --- a/lib/log/version.map +++ b/lib/log/version.map @@ -25,6 +25,7 @@ DPDK_25 { INTERNAL { global: + eal_log_color; eal_log_init; eal_log_journal; # WINDOWS_NO_EXPORT eal_log_level2str; From patchwork Thu Sep 19 15:04:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 144316 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 377F6459D7; Thu, 19 Sep 2024 17:08:28 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 408DC433C6; Thu, 19 Sep 2024 17:06:39 +0200 (CEST) Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by mails.dpdk.org (Postfix) with ESMTP id DAF1F433AA for ; Thu, 19 Sep 2024 17:06:32 +0200 (CEST) Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-71970655611so857560b3a.0 for ; Thu, 19 Sep 2024 08:06:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1726758392; x=1727363192; 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=eXb26X7jxB/SNGPRhZgiOkGKBh+kkWqNz3DeeBMolMA=; b=Lr8AkBdxq/1qeoH1ABz6yfDUIIkdhc5LgjRpH9AXMVmUCBlvZbIz8fcuqtr9wqe8qr uB/FvOtxDqG1Gj11GZpoKJjNcpAC7UX7e5BcXUJZzE/8XQ7Sjxnik6FPXnnQa26UNWFT CO8SQRwYcqssBGH27CA4sEG3iIFG0gnziD0umK3eZF4MmwBdcaER2eF4JSLclF3x8rvq BqoGb1AW/76JI98rGJ78XiIEcEmQfrM1/Uvgbfzeig7qv0hz8iAcQzQXf4JRPUfQpi+9 Ii4Adv6S9FX1vq9KU4DkdHzvuFTx9sZ1rDDrczbJUG9uukTzVNpDzaWYtMT8ezkc12Eo Ad6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726758392; x=1727363192; 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=eXb26X7jxB/SNGPRhZgiOkGKBh+kkWqNz3DeeBMolMA=; b=gILUMB2Fe80Oa0wvG3h5el6VRq9tve6L4w48CnvEBqIdZFNNhgSbmfVGf/AH1YKfbC vMOFXH+5jVC5axo0Drjg5DpvMalSTgpuLcfN8BYhr6gJQLdCgZtKcyAt0QVHAsyQwhtA ssKgJJhDUpELEm3Od6tI1PtXv5fKj4lbT+frhAkHt1vPTOvfILz4NeLo2ED3Wy/ooNV6 YsXLvCmHWU4VccV4rKhctnax54trRJOTEo4Kktqd1KJrviSJpglUupn2ApG/x9+3re7N /LZz49HOvCfmCq1ubtCq03Ew51pF1/Xf6ceZZcotFedL6+fddmM84616ha+ObD1PXEMi 3w7Q== X-Gm-Message-State: AOJu0YyqeqiyQBIg97WnqboLYA0MOT1fm3fimwy85qCZUA41mfwQuUsf csEiH7XDqQQrOpSm9a+gn+Je7oCNzbK9vSrd0JV6X+T4o0p1t0Fk/iORLc9daIQOqUilUvKCigF D X-Google-Smtp-Source: AGHT+IEMWb/K/eBNR97Yw/x64E2OiuTf6GnvB73mZSw3X9gU/6X3MYNV4hRerf/4Kh/OPGoUWnVGEw== X-Received: by 2002:a05:6a00:3e29:b0:70d:2b95:d9c0 with SMTP id d2e1a72fcca58-71926090ecdmr40615621b3a.14.1726758391812; Thu, 19 Sep 2024 08:06:31 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71944adfd3dsm8620841b3a.92.2024.09.19.08.06.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2024 08:06:31 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , =?utf-8?q?Morten_Br?= =?utf-8?q?=C3=B8rup?= , Bruce Richardson , Chengwen Feng Subject: [PATCH v25 15/15] doc: add release note about log library Date: Thu, 19 Sep 2024 08:04:21 -0700 Message-ID: <20240919150609.5281-16-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240919150609.5281-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240919150609.5281-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 Significant enough to add some documentation. Signed-off-by: Stephen Hemminger Acked-by: Morten Brørup Acked-by: Bruce Richardson Acked-by: Chengwen Feng Acked-by: Tyler Retzlaff --- doc/guides/rel_notes/release_24_11.rst | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/doc/guides/rel_notes/release_24_11.rst b/doc/guides/rel_notes/release_24_11.rst index 0ff70d9057..d6fb6c137b 100644 --- a/doc/guides/rel_notes/release_24_11.rst +++ b/doc/guides/rel_notes/release_24_11.rst @@ -55,6 +55,33 @@ New Features Also, make sure to start the actual text at the margin. ======================================================= +* **Enhancements to logging library.** + + * Syslog related changes + + * The meaning of the *--syslog* option has changed. + Use of syslog is controlled by the *--syslog* option. + The default is now *auto* which uses syslog only if stderr + is not a terminal device. + + * The syslog facility is now set to **LOG_USER** if stderr is a terminal + and **LOG_DAEMON** otherwise. + + * Syslog is now supported on FreeBSD (but not on Windows). + + * The log is initialized earlier in startup so all messages go through + the library. + + * Added a new option to timestamp log messages, which is useful for + debugging delays in application and driver startup. + + * Log messages are now in color if going to a terminal (similar to dmesg). + The default format shows timestamp in green, subsystem in yellow, + and the message is bold, boldface or normal depending on severity. + + * If the application is a systemd service and the log output is being + sent of standard error then DPDK will switch to journal native protocol. + Removed Items -------------