From patchwork Sat Mar 30 16:42:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138997 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 2212B43D85; Sat, 30 Mar 2024 17:44:53 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8678C4021D; Sat, 30 Mar 2024 17:44:47 +0100 (CET) Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by mails.dpdk.org (Postfix) with ESMTP id 2F6AB4021D for ; Sat, 30 Mar 2024 17:44:45 +0100 (CET) Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-6ea8a0d1a05so2446966b3a.1 for ; Sat, 30 Mar 2024 09:44:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711817084; x=1712421884; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Jg4gJVsR4dN+khFlEZjtz8EwwUHChpN4QN82VjySz0w=; b=0d3TQtbYJzWfuhgCiCXZEDnzcdxBTDCaM1H072UyUKs++6sOrTC1ZNQLI/4aux83yA S9MHTBK1DaKWUqvCxr/7Fi+km6hMpVMqQAMwrfvica468jQqyIodElLR1Mx5NIgnN4uD KAe/gOEhMeg+oNiw2CflAXkXSez0z1/sjFSheQwQcUTxwhWohMyAIoul2xKi8FdHeyh4 cFqBsOlLwkHB4ekddYKs+BoU7JoMUZ8vdUIGIyk7pKrEnF+CAc7xJhBvVBMkWjzKCJfU 9Z8cWa1sm8o94EX7UW9gyfF4pktXyReaBBlPrDKjbO//HX1ooHsEQ8b+hjNABrXqEpF0 ZoHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711817084; x=1712421884; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Jg4gJVsR4dN+khFlEZjtz8EwwUHChpN4QN82VjySz0w=; b=G8xDDJ5IzcsRjwwEl4ZLTGT11tME2fOklRZ2ZG2pZsFI3V2EpUW3uT1LBLnWJpoTfl 2IWoR62034XzdOYLunfDX7aNuaoaZ27UjayPC9daszD1WC/rquzm63Giae97yfpWGvX5 yIXc0LIQUOcrycrrQKReM8NzGL05iM5pK5jlZ1FKVghcUtwR1p3ayGz3jZEsOW0OH5tb bkRHpkjvfSDGt5dlRsyGLrAyUKQWzTdiJgPx00DdnDZbrZaihOdm498wPUBanIILa0VJ D0JBSMWRWjF2qJw2WUnX14GQqpV9MrTh9/EdpkDWYa4SuaLHRt0Hm84aX0H0U28f5lpb PkXQ== X-Gm-Message-State: AOJu0YxIrnLmfH5eHJsYqXsC857meDYaniuWFb/bJZqOBB3vqgEeOerZ 37AouwS5c9+VJowdk6De4YPWqJAhdNJHRH1sPTHOvl6a0FZDc60G77bhJGgav6bhWP2PS5baX0J X X-Google-Smtp-Source: AGHT+IFNN43Uf8i5APeojS+wWb+l8nTIpif1vhzHU1sfxWXHmBQb6UnhAwBfGCKHF/gpcVnY/Cob4g== X-Received: by 2002:a05:6a21:a5a1:b0:1a3:4e27:c8d1 with SMTP id gd33-20020a056a21a5a100b001a34e27c8d1mr12864398pzc.25.1711817084392; Sat, 30 Mar 2024 09:44:44 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id by1-20020a056a02058100b005dc26144d96sm4192417pgb.75.2024.03.30.09.44.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Mar 2024 09:44:44 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff , Thomas Monjalon Subject: [PATCH v20 01/14] maintainers: add for log library Date: Sat, 30 Mar 2024 09:42:12 -0700 Message-ID: <20240330164433.50144-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240330164433.50144-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240330164433.50144-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org "You touch it you own it" Add myself as maintainer for log library. Signed-off-by: Stephen Hemminger Acked-by: Tyler Retzlaff --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index 7abb3aee49..54c28a601d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -180,6 +180,7 @@ F: app/test/test_threads.c F: app/test/test_version.c Logging +M: Stephen Hemminger F: lib/log/ F: doc/guides/prog_guide/log_lib.rst F: app/test/test_logs.c From patchwork Sat Mar 30 16:42:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138998 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 8118843D85; Sat, 30 Mar 2024 17:45:00 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EFA4B402D5; Sat, 30 Mar 2024 17:44:50 +0100 (CET) Received: from mail-io1-f43.google.com (mail-io1-f43.google.com [209.85.166.43]) by mails.dpdk.org (Postfix) with ESMTP id 4856F402BB for ; Sat, 30 Mar 2024 17:44:46 +0100 (CET) Received: by mail-io1-f43.google.com with SMTP id ca18e2360f4ac-7d026c0a08aso131382639f.1 for ; Sat, 30 Mar 2024 09:44:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711817085; x=1712421885; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=j2bWaQew6uFbTYM7AsbymK+bBIaNZpLFH5iS8177eDI=; b=T/aip+PNdfDWe7Nx5btArn3M74shfruzhCEoevpI2L2DDC9iB5RoRTvKyEG68OSot/ tRA3iAxoqF7E2pUPuxIxFE4wlX+c7I5xFtXKIYAgCNpZas4RROEZblRio0q/BBNie/zG 7xOvO7dUCyEtSLj3tY/M07wgqSanKprfWaXeC2uJemG1j452foF469lzJPKM+nNUpbh0 MBsWlRhmnmP9P9FNNms5h340/6hn7k7BcxRlsiErI8WoJEIywgLpGE4Ilbt//Li1qaKT LcGVPjhn6QZNJhKItEP7bIDf6UyVXDN5+Ebdh+RSdiwQS5zW390rG5NWyia0wYTltT6i +zHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711817085; x=1712421885; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=j2bWaQew6uFbTYM7AsbymK+bBIaNZpLFH5iS8177eDI=; b=EIqOn5RYYgM45Yg2KaKj0XtiOiZYDpte2jv0bhxbzmWlTk0csJtMSnn/L7jWsoYUGf ixo4Wl7nAg2/mcV8DgbtJ+sW0UzociYdwnhQ7Wm8ffu8+zz9GMvRIzN95K0I2lDl0ig/ q1Cf35zppK2mwzVEA0w9tzaiJ/Ecgao9GlAfgQqSJKORVO5aWehJTvhBY9EdOK6wZWzf qaXY21w1BJFsJ2BhrgcSkc05wtVstTTCmVNkoizsQjpcGLpteE49qUP0QTEh9REsAaHV ff08cuEQsP7JupOz7CXSA9m9P3nGI+3boZk9nftGwjYpQxdONeXMurntkBUUf42AhrD3 jTAw== X-Gm-Message-State: AOJu0Yz8ykRTKLT16vOnEEU4OzWGt2G1gbU3XZFCnZdIJyknLD1xtWnk 2Hge7gzdQJ9hqEotImb4V5Ugl3bqEgIjVcEIKwavo6KmkCIhk+IWBMWESpfmbrpEGWYWtOh5FF8 7 X-Google-Smtp-Source: AGHT+IF6U8t7Qo2/+G+2RFq/1f9ptvpI9UYXAxPYIosDLLERY+00sBnqa42wUHTG8jckGrrsBs2wtg== X-Received: by 2002:a05:6e02:b22:b0:366:9674:7084 with SMTP id e2-20020a056e020b2200b0036696747084mr6096971ilu.12.1711817085316; Sat, 30 Mar 2024 09:44:45 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id by1-20020a056a02058100b005dc26144d96sm4192417pgb.75.2024.03.30.09.44.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Mar 2024 09:44:44 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff , Dmitry Kozlyuk , Pallavi Kadam Subject: [PATCH v20 02/14] windows: make getopt functions have const properties Date: Sat, 30 Mar 2024 09:42:13 -0700 Message-ID: <20240330164433.50144-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240330164433.50144-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240330164433.50144-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Having different prototypes on different platforms can lead to lots of unnecessary workarounds. Looks like the version of getopt used from windows was based on an older out of date version from FreeBSD. This patch changes getopt, getopt_long, etc to have the same const attributes as Linux and FreeBSD. The changes are derived from the current FreeBSD version of getopt_long. Signed-off-by: Stephen Hemminger Acked-by: Tyler Retzlaff Acked-by: Dmitry Kozlyuk --- lib/eal/windows/getopt.c | 23 ++++++++++++----------- lib/eal/windows/include/getopt.h | 8 ++++---- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/eal/windows/getopt.c b/lib/eal/windows/getopt.c index a1f51c6c23..50ff71b930 100644 --- a/lib/eal/windows/getopt.c +++ b/lib/eal/windows/getopt.c @@ -20,7 +20,7 @@ #include #include -const char *optarg; /* argument associated with option */ +char *optarg; /* argument associated with option */ int opterr = 1; /* if error message should be printed */ int optind = 1; /* index into parent argv vector */ int optopt = '?'; /* character checked for validity */ @@ -39,9 +39,9 @@ static void pass(const char *a) {(void) a; } #define BADARG ((*options == ':') ? (int)':' : (int)'?') #define INORDER 1 -#define EMSG "" +static char EMSG[] = ""; -static const char *place = EMSG; /* option letter processing */ +static char *place = EMSG; /* option letter processing */ /* XXX: set optreset to 1 rather than these two */ static int nonopt_start = -1; /* first non option argument (for permute) */ @@ -80,7 +80,7 @@ gcd(int a, int b) */ static void permute_args(int panonopt_start, int panonopt_end, int opt_end, - char **nargv) + char * const *nargv) { int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos; char *swap; @@ -101,11 +101,12 @@ permute_args(int panonopt_start, int panonopt_end, int opt_end, pos -= nnonopts; else pos += nopts; + swap = nargv[pos]; /* LINTED const cast */ - ((char **) nargv)[pos] = nargv[cstart]; + ((char **)(uintptr_t)nargv)[pos] = nargv[cstart]; /* LINTED const cast */ - ((char **)nargv)[cstart] = swap; + ((char **)(uintptr_t)nargv)[cstart] = swap; } } } @@ -116,7 +117,7 @@ permute_args(int panonopt_start, int panonopt_end, int opt_end, * Returns -1 if short_too is set and the option does not match long_options. */ static int -parse_long_options(char **nargv, const char *options, +parse_long_options(char * const *nargv, const char *options, const struct option *long_options, int *idx, int short_too) { const char *current_argv; @@ -236,7 +237,7 @@ parse_long_options(char **nargv, const char *options, * Parse argc/argv argument vector. Called by user level routines. */ static int -getopt_internal(int nargc, char **nargv, const char *options, +getopt_internal(int nargc, char *const nargv[], const char *options, const struct option *long_options, int *idx, int flags) { char *oli; /* option letter list index */ @@ -434,7 +435,7 @@ getopt_internal(int nargc, char **nargv, const char *options, * Parse argc/argv argument vector. */ int -getopt(int nargc, char *nargv[], const char *options) +getopt(int nargc, char *const nargv[], const char *options) { return getopt_internal(nargc, nargv, options, NULL, NULL, FLAG_PERMUTE); @@ -445,7 +446,7 @@ getopt(int nargc, char *nargv[], const char *options) * Parse argc/argv argument vector. */ int -getopt_long(int nargc, char *nargv[], const char *options, +getopt_long(int nargc, char *const nargv[], const char *options, const struct option *long_options, int *idx) { @@ -458,7 +459,7 @@ getopt_long(int nargc, char *nargv[], const char *options, * Parse argc/argv argument vector. */ int -getopt_long_only(int nargc, char *nargv[], const char *options, +getopt_long_only(int nargc, char *const nargv[], const char *options, const struct option *long_options, int *idx) { diff --git a/lib/eal/windows/include/getopt.h b/lib/eal/windows/include/getopt.h index 6f57af454b..e4cf6873cb 100644 --- a/lib/eal/windows/include/getopt.h +++ b/lib/eal/windows/include/getopt.h @@ -44,7 +44,7 @@ /** argument to current option, or NULL if it has none */ -extern const char *optarg; +extern char *optarg; /** Current position in arg string. Starts from 1. * Setting to 0 resets state. */ @@ -80,14 +80,14 @@ struct option { }; /** Compat: getopt */ -int getopt(int argc, char *argv[], const char *options); +int getopt(int argc, char *const argv[], const char *options); /** Compat: getopt_long */ -int getopt_long(int argc, char *argv[], const char *options, +int getopt_long(int argc, char *const argv[], const char *options, const struct option *longopts, int *longindex); /** Compat: getopt_long_only */ -int getopt_long_only(int nargc, char *argv[], const char *options, +int getopt_long_only(int nargc, char *const argv[], const char *options, const struct option *long_options, int *idx); From patchwork Sat Mar 30 16:42:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 138999 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 686B043D85; Sat, 30 Mar 2024 17:45:07 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 514D7402E4; Sat, 30 Mar 2024 17:44:52 +0100 (CET) Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) by mails.dpdk.org (Postfix) with ESMTP id 00736402C8 for ; Sat, 30 Mar 2024 17:44:46 +0100 (CET) Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-2a04ac98cf7so1939896a91.0 for ; Sat, 30 Mar 2024 09:44:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711817086; x=1712421886; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZlrKTSbTZG9U7EVa2nyOT/6+zSdva+byCe6SWEMtVSw=; b=XHp0kbyZZ68rPwPHhnzXqQqBKCNFwp2+2sjzdVoyzs41jfk1NhCRr0npOcfvjwbE5w OOTn0vTGKpByzInnCGoof5sISkvpoqWN1esYKNzw4nIskNBFUuXNdqp1fDRteTy+WMJa pp3BlFJrv3tZOOMjX3lS64pyFciLaAJzK8QnmdOq9rzT0ILTahFT0SDBc3M39nbMKOsC Kg98n0LIrp/VM0lvJXxz72TRofp7pee6iQlOwanwXIH0PjawNDISCiZegIUzffM7SBaH K9UEuPXjnvaaHqjE/jbCblRPccY/mA1F2bH9qS/n9oRF92K8mtb/7efKv1cxInVukM6a yBLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711817086; x=1712421886; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZlrKTSbTZG9U7EVa2nyOT/6+zSdva+byCe6SWEMtVSw=; b=ogyTAGUvXtvDjK2m8VG3ylC89izVioUO3frmCzGlI0rddjA3Mp2TBmqlfoo3B4frMF ULwmULgzz/Vmt6VcBW5ywfV36oq9gpzuR8wfHkkSjx4+FekwtqgHlA7Uq2jUVG4pngUU a8myqPEpNjNz2VBww1eK58elQVevKXgNfsyi1HvMpySkyHAxqLYvQVTZKX+n2I/OKQE9 puZDsZeKkPHtRco0zwUXdgSY0bOmsr7oqTEZFRKD864X1Y3/4Md+Tk6FIXlveMjg1ULj ve6qrdlY36Yz0OpnRakK46a8vBrasVusITpvOl/1bSHZazklVwbn/Fuam6WmlR4uzKkd imzQ== X-Gm-Message-State: AOJu0Yz0yEEo65FnQnFlueVluDOSm6RNbcBPjZaHsGFj4miI17ZOGxW5 Jyz6xOoYWmNHp7EudzbJJBVv/sZqTudT/cl4Xw+P4vkTtZoH4lwBT0NgaJJ4GMXFSm6hvLiPykW G X-Google-Smtp-Source: AGHT+IEn4UgXSWcfHLJfqeX6ukko13mzwY27mpDjvT3VjX00SzVFj2Hh8Al+dClmiq+gudM5mUX6vw== X-Received: by 2002:a17:90b:3001:b0:2a0:78f4:2dc5 with SMTP id hg1-20020a17090b300100b002a078f42dc5mr11465531pjb.22.1711817086090; Sat, 30 Mar 2024 09:44:46 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id by1-20020a056a02058100b005dc26144d96sm4192417pgb.75.2024.03.30.09.44.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Mar 2024 09:44:45 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff , Dmitry Kozlyuk , Pallavi Kadam Subject: [PATCH v20 03/14] windows: add os shim for localtime_r Date: Sat, 30 Mar 2024 09:42:14 -0700 Message-ID: <20240330164433.50144-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240330164433.50144-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240330164433.50144-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Windows does not have localtime_r but it does have a similar function that can be used instead. Signed-off-by: Stephen Hemminger Acked-by: Tyler Retzlaff --- lib/eal/windows/include/rte_os_shim.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/eal/windows/include/rte_os_shim.h b/lib/eal/windows/include/rte_os_shim.h index eda8113662..e9741a9df2 100644 --- a/lib/eal/windows/include/rte_os_shim.h +++ b/lib/eal/windows/include/rte_os_shim.h @@ -110,4 +110,14 @@ rte_clock_gettime(clockid_t clock_id, struct timespec *tp) } #define clock_gettime(clock_id, tp) rte_clock_gettime(clock_id, tp) +static inline struct tm * +rte_localtime_r(const time_t *timer, struct tm *buf) +{ + if (localtime_s(buf, timer) == 0) + return buf; + else + return NULL; +} +#define localtime_r(timer, buf) rte_localtime_r(timer, buf) + #endif /* _RTE_OS_SHIM_ */ From patchwork Sat Mar 30 16:42:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 139000 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 AEFA443D85; Sat, 30 Mar 2024 17:45:14 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 887F140608; Sat, 30 Mar 2024 17:44:53 +0100 (CET) Received: from mail-oo1-f50.google.com (mail-oo1-f50.google.com [209.85.161.50]) by mails.dpdk.org (Postfix) with ESMTP id D0E01402CC for ; Sat, 30 Mar 2024 17:44:47 +0100 (CET) Received: by mail-oo1-f50.google.com with SMTP id 006d021491bc7-5a480985625so1789869eaf.0 for ; Sat, 30 Mar 2024 09:44:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711817087; x=1712421887; 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=dXQGVN00vloyxnzWUk+uLa0sFv/RhlpggdNfNuUHjWM=; b=QKy2n/jaBVEmXp30m7idjtMNowOHDK51tc5KUMC6S9Q76HejV6zykfYN7ruFCvKSF+ y6QDNXyKnQo8GNFbZgzOmDZ0qM93rMVxDraOmUjXrxqwILyv1e9NpoaDgXjqfafwN/+9 z0AY6bugr+XOD0Y3yS4Tjp5jiJVvrNXrCyak+nzT7Qd5wBSZe+rODFcwx2WYzbH+CWG3 rOaJfw5twiYHFroa5QzoZkS6XJzG2VUFv9db055vD5zs+n/wCD+Prxo5Z7IVqvM/9WtY EhX0n9CmFANSDZnzvEy0sZpuvj0J4hMh6rqdhWeyCrLB73oYzdJGIsh1hB4Z9bPGeckA glDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711817087; x=1712421887; 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=dXQGVN00vloyxnzWUk+uLa0sFv/RhlpggdNfNuUHjWM=; b=TSy+kk2TANR2KltVGAIjQ51l4SNpzwFIWkTbjiv93+bb3JRd22Q3EhllnEgJh6Agto YwvhalH3vnJwmGQUgI3KTZ72Q5ssFJpHUI4gqlcnnUpfdxDoNBZFA4SMd9vPBfkOIVk+ AZOyB89wmZmASf+AQLzWZkaVXoTo5O0ihyfQA8nx3NQ6T4McqrohEG8ssPeHDn1w84V5 ahtqiINXi8W4MRX4x2dwAe9ZyXdrCceRfeuFStp/Cpf7MoeMxPTigidDGjzBYzQzbyP4 CkjELX6gli4mmiDHd2vZoiODHshD0VRBBuisJSNGAeU5pvz10ob+IDnXovnWj2pJrWU+ D5Lg== X-Gm-Message-State: AOJu0YzFbRSdOwXeBM2t73koGM9H/SswYJhlW1KlsR8BO0fvhUWSbsby EmFs54edA4K9LYaFncmqAz5SgvNu5US1dOjl2BANmtcAy3sDKfmyVuRSF9K9jHWkRm6T0Cb3Npj / X-Google-Smtp-Source: AGHT+IHG/mUzAkoaXhXENT1YkKbcNGCKQo9dTyuzQeESdnuemgLLR5RLCmMz8yM7UaCZ3c6oDE6XmA== X-Received: by 2002:a05:6358:3396:b0:183:6537:8771 with SMTP id i22-20020a056358339600b0018365378771mr6519850rwd.23.1711817086970; Sat, 30 Mar 2024 09:44:46 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id by1-20020a056a02058100b005dc26144d96sm4192417pgb.75.2024.03.30.09.44.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Mar 2024 09:44:46 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff , Bruce Richardson , Dmitry Kozlyuk , Pallavi Kadam Subject: [PATCH v20 04/14] eal: make eal_log_level_parse common Date: Sat, 30 Mar 2024 09:42:15 -0700 Message-ID: <20240330164433.50144-5-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240330164433.50144-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240330164433.50144-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The code to parse for log-level option should be same on all OS variants. Signed-off-by: Stephen Hemminger Acked-by: Tyler Retzlaff --- lib/eal/common/eal_common_options.c | 46 +++++++++++++++++++++++++++++ lib/eal/common/eal_options.h | 1 + lib/eal/freebsd/eal.c | 42 -------------------------- lib/eal/linux/eal.c | 39 ------------------------ lib/eal/windows/eal.c | 35 ---------------------- 5 files changed, 47 insertions(+), 116 deletions(-) diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index e541f07939..5435399b85 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -1640,6 +1640,51 @@ eal_parse_huge_unlink(const char *arg, struct hugepage_file_discipline *out) return -1; } +/* Parse the all arguments looking for log related ones */ +int +eal_log_level_parse(int argc, char * const argv[]) +{ + struct internal_config *internal_conf = eal_get_internal_configuration(); + int option_index, opt; + const int old_optind = optind; + const int old_optopt = optopt; + const int old_opterr = opterr; + char *old_optarg = optarg; +#ifdef RTE_EXEC_ENV_FREEBSD + const int old_optreset = optreset; + optreset = 1; +#endif + + optind = 1; + opterr = 0; + + while ((opt = getopt_long(argc, argv, eal_short_options, + eal_long_options, &option_index)) != EOF) { + + switch (opt) { + case OPT_LOG_LEVEL_NUM: + if (eal_parse_common_option(opt, optarg, internal_conf) < 0) + return -1; + break; + case '?': + /* getopt is not happy, stop right now */ + goto out; + default: + continue; + } + } +out: + /* restore getopt lib */ + optind = old_optind; + optopt = old_optopt; + optarg = old_optarg; + opterr = old_opterr; +#ifdef RTE_EXEC_ENV_FREEBSD + optreset = old_optreset; +#endif + return 0; +} + int eal_parse_common_option(int opt, const char *optarg, struct internal_config *conf) @@ -2173,6 +2218,7 @@ rte_vect_set_max_simd_bitwidth(uint16_t bitwidth) return 0; } + void eal_common_usage(void) { diff --git a/lib/eal/common/eal_options.h b/lib/eal/common/eal_options.h index 3cc9cb6412..f3f2e104f6 100644 --- a/lib/eal/common/eal_options.h +++ b/lib/eal/common/eal_options.h @@ -96,6 +96,7 @@ enum { extern const char eal_short_options[]; extern const struct option eal_long_options[]; +int eal_log_level_parse(int argc, char * const argv[]); int eal_parse_common_option(int opt, const char *argv, struct internal_config *conf); int eal_option_device_parse(void); diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index bab77118e9..9825bcea0b 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -363,48 +363,6 @@ eal_get_hugepage_mem_size(void) return (size < SIZE_MAX) ? (size_t)(size) : SIZE_MAX; } -/* Parse the arguments for --log-level only */ -static void -eal_log_level_parse(int argc, char **argv) -{ - int opt; - char **argvopt; - int option_index; - const int old_optind = optind; - const int old_optopt = optopt; - const int old_optreset = optreset; - char * const old_optarg = optarg; - struct internal_config *internal_conf = - eal_get_internal_configuration(); - - argvopt = argv; - optind = 1; - optreset = 1; - - while ((opt = getopt_long(argc, argvopt, eal_short_options, - eal_long_options, &option_index)) != EOF) { - - int ret; - - /* getopt is not happy, stop right now */ - if (opt == '?') - break; - - ret = (opt == OPT_LOG_LEVEL_NUM) ? - eal_parse_common_option(opt, optarg, internal_conf) : 0; - - /* common parser is not happy */ - if (ret < 0) - break; - } - - /* restore getopt lib */ - optind = old_optind; - optopt = old_optopt; - optreset = old_optreset; - optarg = old_optarg; -} - /* Parse the argument given in the command line of the application */ static int eal_parse_args(int argc, char **argv) diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index fd422f1f62..bffeb1f34e 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -546,45 +546,6 @@ eal_parse_vfio_vf_token(const char *vf_token) return -1; } -/* Parse the arguments for --log-level only */ -static void -eal_log_level_parse(int argc, char **argv) -{ - int opt; - char **argvopt; - int option_index; - const int old_optind = optind; - const int old_optopt = optopt; - char * const old_optarg = optarg; - struct internal_config *internal_conf = - eal_get_internal_configuration(); - - argvopt = argv; - optind = 1; - - while ((opt = getopt_long(argc, argvopt, eal_short_options, - eal_long_options, &option_index)) != EOF) { - - int ret; - - /* getopt is not happy, stop right now */ - if (opt == '?') - break; - - ret = (opt == OPT_LOG_LEVEL_NUM) ? - eal_parse_common_option(opt, optarg, internal_conf) : 0; - - /* common parser is not happy */ - if (ret < 0) - break; - } - - /* restore getopt lib */ - optind = old_optind; - optopt = old_optopt; - optarg = old_optarg; -} - static int eal_parse_huge_worker_stack(const char *arg) { diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c index 52f0e7462d..85171b2768 100644 --- a/lib/eal/windows/eal.c +++ b/lib/eal/windows/eal.c @@ -96,41 +96,6 @@ eal_usage(const char *prgname) } } -/* Parse the arguments for --log-level only */ -static void -eal_log_level_parse(int argc, char **argv) -{ - int opt; - char **argvopt; - int option_index; - struct internal_config *internal_conf = - eal_get_internal_configuration(); - - argvopt = argv; - - eal_reset_internal_config(internal_conf); - - while ((opt = getopt_long(argc, argvopt, eal_short_options, - eal_long_options, &option_index)) != EOF) { - - int ret; - - /* getopt is not happy, stop right now */ - if (opt == '?') - break; - - ret = (opt == OPT_LOG_LEVEL_NUM) ? - eal_parse_common_option(opt, optarg, - internal_conf) : 0; - - /* common parser is not happy */ - if (ret < 0) - break; - } - - optind = 0; /* reset getopt lib */ -} - /* Parse the argument given in the command line of the application */ static int eal_parse_args(int argc, char **argv) From patchwork Sat Mar 30 16:42:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 139001 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 2FE3143D85; Sat, 30 Mar 2024 17:45:21 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 32B874064C; Sat, 30 Mar 2024 17:44:55 +0100 (CET) Received: from mail-oa1-f53.google.com (mail-oa1-f53.google.com [209.85.160.53]) by mails.dpdk.org (Postfix) with ESMTP id 733F8402E6 for ; Sat, 30 Mar 2024 17:44:48 +0100 (CET) Received: by mail-oa1-f53.google.com with SMTP id 586e51a60fabf-22a96054726so2131087fac.0 for ; Sat, 30 Mar 2024 09:44:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711817088; x=1712421888; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jpuKRgSOIbpBBbsAGPHwAR/lg4j9u3JMjpynNGAPSTY=; b=hTHjfF1/4y9WyzASfq9tItYQaD7b4WuSIGpELLPt4yEjJYgMELc08/8OBtgesHtWnd vkmPQj920dc4Z8CtEw0XbOurHxieNA/xxl/2xlwe3woUO/eW6mccRhSnYk9fed82Vmj1 bjUeNrmwBlYKGXX53nXnQZ+Z2tRqw8n6ML1NzHQDEFy2dSKFwvyT9d5UgRe/NkmT937M ApGSj701t47AoV56Z9lOO8J/+WYq9OJ6E4dGznnRp3lC5fxWP392RKsehGr1QW2l0gq9 XIFirDdKZSzoeM2Lr5XazD4I2V+qIIYd4yx7HAetA5bfLa5up1YNXkrL7jA7rPPk/SBw XVAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711817088; x=1712421888; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jpuKRgSOIbpBBbsAGPHwAR/lg4j9u3JMjpynNGAPSTY=; b=eihyw3a5YogeUwKt/gmLbGCZy9fWKM5y+IdTWv7zj6CZrx6WC38kBAbSV9Kmb6TCL+ 0P5eungtIHOVWqiGAJVYioHePuMYDzpuo8bz5e8glOoPVi9T58zbMutU8FFFuFzq9TXr gS8M4FMn5+V6O58UhvtFIUFtJ1uq4FO+28hYciKQUaEMc5tV3arscoF3NKM6tHIFh4mW 4DfPqZ3nz/Md/7fqxPOFw3z6MJI1+S2+GAYEBdQ/e/5McjxxqSQf97CaUFc6/Oi8cPIW QwhUKWTOuWFlaXb9bIcq0ZADgQFNK+VGTCspvXumklcPIOX2re3JA7FQaYpX8jLGRkKh aCZg== X-Gm-Message-State: AOJu0YxVHhpziTqpAcJGb3tm6Fck5nCqgBo2GWqQezJXYIrAqmJ/tHw7 DtNJL5RT6mfwBjRbP7qb3hDg69Nl66plmBxT+FuO24mGeXkBqVkBTu5NdiRzNXFhqo7dIWxzHpL a X-Google-Smtp-Source: AGHT+IGqNB6HrtX9Odz9AWaACRLISOeJnzaH9ByVtzytuHmEpNG+7DseTolbI/RXu3jRRaOpcUESxg== X-Received: by 2002:a05:6871:8783:b0:229:fd96:1e40 with SMTP id td3-20020a056871878300b00229fd961e40mr5587638oab.44.1711817087764; Sat, 30 Mar 2024 09:44:47 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id by1-20020a056a02058100b005dc26144d96sm4192417pgb.75.2024.03.30.09.44.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Mar 2024 09:44:47 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff , Bruce Richardson Subject: [PATCH v20 05/14] eal: do not duplicate rte_init_alert() messages Date: Sat, 30 Mar 2024 09:42:16 -0700 Message-ID: <20240330164433.50144-6-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240330164433.50144-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240330164433.50144-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The message already goes through logging, and does not need to be printed on stderr. Message level should be ALERT to match function name. Signed-off-by: Stephen Hemminger Acked-by: Tyler Retzlaff --- lib/eal/freebsd/eal.c | 3 +-- lib/eal/linux/eal.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index 9825bcea0b..17b56f38aa 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -529,8 +529,7 @@ rte_eal_iopl_init(void) static void rte_eal_init_alert(const char *msg) { - fprintf(stderr, "EAL: FATAL: %s\n", msg); - EAL_LOG(ERR, "%s", msg); + EAL_LOG(ALERT, "%s", msg); } /* Launch threads, called at application init(). */ diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index bffeb1f34e..23dc26b124 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -840,8 +840,7 @@ static int rte_eal_vfio_setup(void) static void rte_eal_init_alert(const char *msg) { - fprintf(stderr, "EAL: FATAL: %s\n", msg); - EAL_LOG(ERR, "%s", msg); + EAL_LOG(ALERT, "%s", msg); } /* From patchwork Sat Mar 30 16:42:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 139002 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 ADA7943D85; Sat, 30 Mar 2024 17:45:28 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 687834067E; Sat, 30 Mar 2024 17:44:56 +0100 (CET) Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) by mails.dpdk.org (Postfix) with ESMTP id 37D93402CC for ; Sat, 30 Mar 2024 17:44:49 +0100 (CET) Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-5d3907ff128so2173458a12.3 for ; Sat, 30 Mar 2024 09:44:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711817088; x=1712421888; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=26JyS8a5xAOFLsVay3Kok3WHu0A/W2PjaWn3v8PwBA0=; b=fRmhk+f59GhbuW2UopVoOS3qzLEljlyBAEQA+YtxDY+BP7rBPS9WgHnUr0TujiBO+3 F3hXkLsoSXgW3Up6t7hMTd2vkernK/NeBnHyI+bx3co2Ue/ScIIRLzTjmKEoal00TzQX eKsr/8Mo5KndjydoT90HjkQfIzAcMsEHSX2BmNUYm6X+RBYDsWJn7rzh+QtYT0iMXsJk Ir/xqjZjprVIvkdPU3VLcC4X56Wp+WrxVKg3E2Gb7xLTizp9BB9LdVZTZc2FSSqWF9ZH 41PSUhJ/FMt43K0DXtdKDpW6Bxr//KQoQlny2wjkhI6rVCbLdhgb9d/oy0mFtYq/RqWR O9dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711817088; x=1712421888; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=26JyS8a5xAOFLsVay3Kok3WHu0A/W2PjaWn3v8PwBA0=; b=W6G0fKqw+QtvF2ReA8xAitmvtUF7Hk+CPzCkn/Yo0eTBomZX1bpcgshifW1oknENmr FdZdhxWu18Q95MbDiAGyafq3hrGl1REbra18ngmD8QphYLIPW8EOlycKxRyI68lCGzoi Sw+OEPt9eQaX0KIuXEGZMYA08f3DlNqperEG9m/iTrC+bi/Bo7w9imm+Hbi6YewyR0IK Y2yTyPzvbgB2DMOjeoaofGQ+CkX6VxVQzgur6KtjB69uzuzXBh18zFC4Ehl3D7eOn+V6 VKzVadeVJgVdYYQF9FmbloAR3Sz7riZMddMDxGVmFQFQYeXsQUzUMnuFMvbziycTNiO4 K2Ew== X-Gm-Message-State: AOJu0Yw+la6Uyx7kYwLqpj1R+YmGGxfzAXVgY7/IKjf40LqWGhDttrRK 6LDcorrV9yl+ESIuQuwu6I4LvBWyR0Ia/wXYQJEwwOlJgie4gtplbtgzN/GdgKgkR7gaN2BMDID B X-Google-Smtp-Source: AGHT+IFZGPW9sRQTpRnRyK0hujsh3378sta95CT0Io4htLYptnhL0bRGOaw1OSio23U5spWefwJz6w== X-Received: by 2002:a17:90a:ac9:b0:29e:d30:5b2c with SMTP id r9-20020a17090a0ac900b0029e0d305b2cmr5329658pje.18.1711817088503; Sat, 30 Mar 2024 09:44:48 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id by1-20020a056a02058100b005dc26144d96sm4192417pgb.75.2024.03.30.09.44.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Mar 2024 09:44:48 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff Subject: [PATCH v20 06/14] eal: change rte_exit() output to match rte_log() Date: Sat, 30 Mar 2024 09:42:17 -0700 Message-ID: <20240330164433.50144-7-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240330164433.50144-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240330164433.50144-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The rte_exit() output format confuses the timestamp and coloring options. Change it to use be a single line with proper prefix. Before: [ 0.006481] EAL: Error - exiting with code: 1 Cause: [ 0.006489] Cannot init EAL: Permission denied After: [ 0.006238] EAL: Error - exiting with code: 1 [ 0.006250] EAL: Cause - Cannot init EAL: Permission denied Signed-off-by: Stephen Hemminger Acked-by: Tyler Retzlaff --- lib/eal/common/eal_common_debug.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/eal/common/eal_common_debug.c b/lib/eal/common/eal_common_debug.c index 3e77995896..ad2be63cbb 100644 --- a/lib/eal/common/eal_common_debug.c +++ b/lib/eal/common/eal_common_debug.c @@ -34,17 +34,18 @@ void rte_exit(int exit_code, const char *format, ...) { va_list ap; + char msg[256]; if (exit_code != 0) - RTE_LOG(CRIT, EAL, "Error - exiting with code: %d\n" - " Cause: ", exit_code); + EAL_LOG(CRIT, "Error - exiting with code: %d", exit_code); va_start(ap, format); - rte_vlog(RTE_LOG_CRIT, RTE_LOGTYPE_EAL, format, ap); + vsnprintf(msg, sizeof(msg), format, ap); va_end(ap); + rte_log(RTE_LOG_CRIT, RTE_LOGTYPE_EAL, "EAL: Cause - %s", msg); + if (rte_eal_cleanup() != 0 && rte_errno != EALREADY) - EAL_LOG(CRIT, - "EAL could not release all resources"); + EAL_LOG(CRIT, "EAL could not release all resources"); exit(exit_code); } From patchwork Sat Mar 30 16:42:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 139003 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 7586643D85; Sat, 30 Mar 2024 17:45:37 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 37D2E4069F; Sat, 30 Mar 2024 17:44:59 +0100 (CET) Received: from mail-oi1-f180.google.com (mail-oi1-f180.google.com [209.85.167.180]) by mails.dpdk.org (Postfix) with ESMTP id 2CE2C402CC for ; Sat, 30 Mar 2024 17:44:50 +0100 (CET) Received: by mail-oi1-f180.google.com with SMTP id 5614622812f47-3c35c4d8878so1237915b6e.1 for ; Sat, 30 Mar 2024 09:44:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711817089; x=1712421889; 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=iO2sD0fSP9dyvU3IgpuDhRaIoTHgTw0uQjYjkNwF5Xw=; b=gwLt2PSqZpwZtHbHqxT60Iygk8eXf7hFR9eGdCnTOXNOemr247hreeuR8S3oVup1hP VSN1beZlJcjACAoeb6EzvRRVrysxYprcmbSo9A4zUzYR53nz585LaEVA4NuUXiZMF8iq 6a/GA2dLHqKdNcbGopDsKps1foxH01Mt+eduZkIvcUmVRVH/Kac8pX1tnb3npD3c+h80 tVWfu0/MADhZed9YzLtWWzRCyJGRD17VsjiwhRVcmWf7HmGYajs3ez8eUXGLAKJfRw60 j0kKNYGqnhmHuKn4qYkclAIM6dek/44SfaMXxqRDc4RqbVVXyrEIUMLPUUEh/xRmRCJJ A3SQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711817089; x=1712421889; 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=iO2sD0fSP9dyvU3IgpuDhRaIoTHgTw0uQjYjkNwF5Xw=; b=AWKp4B6swAc3dQCI19Nf+T4/hkBxeMTBzENZ29BrV5p1lE0oiWKW29BLDkR/DKBdgO fInV/3lfWiGDolUZ8n7bY3snku+nOasJOUPGegrLqSoANVt8fk0wTQg/JiOI3pjZJA0S EY1pPRmtrWZzJP9nK0y+3uIJx0lEsFqpdCc3jo2z/KN3KjSh7CokoRU6NZ57nDvn5Z+8 TxA0rIcjQ/jDdfA0up/659J7cPRPUffb2vs0UI+vv2c6URG0V5ToFJjCu6hl00s3UmqV eerjfpt4b06CaQGmROpFn5I6Rvwy/tmEJ21o6F002huIWEquNgxJviWFwOvTq6QinnUY 0pjA== X-Gm-Message-State: AOJu0Yxxzk580M5rb9oZJEBwmZXie9KXopjnx0DZdEZPAYs/m8OfTcsL RA91YDA76hK6Ao4tTpQF0WMlwngjnxcFGKPgJizbfJwkSh/PV7sOiglJG6nt1cUD9Tynug+Dr2j p X-Google-Smtp-Source: AGHT+IFlv8C2MCfvLtWlpt1FlksHq3TDaq9+blagjGoRlyDXCAPMmXhA2gWciljUlV1OQQXiHhxCxQ== X-Received: by 2002:a05:6808:120e:b0:3c3:dfec:d9ee with SMTP id a14-20020a056808120e00b003c3dfecd9eemr5272169oil.32.1711817089408; Sat, 30 Mar 2024 09:44:49 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id by1-20020a056a02058100b005dc26144d96sm4192417pgb.75.2024.03.30.09.44.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Mar 2024 09:44:49 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Bruce Richardson , Dmitry Kozlyuk , Tyler Retzlaff , Pallavi Kadam Subject: [PATCH v20 07/14] log: move handling of syslog facility out of eal Date: Sat, 30 Mar 2024 09:42:18 -0700 Message-ID: <20240330164433.50144-8-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240330164433.50144-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240330164433.50144-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The syslog facility property is better handled in lib/log rather than in eal. This also allows for changes to what syslog flag means in later steps. Signed-off-by: Stephen Hemminger --- lib/eal/common/eal_common_options.c | 51 ++--------------------------- lib/eal/freebsd/eal.c | 5 ++- lib/eal/linux/eal.c | 7 ++-- lib/eal/windows/eal.c | 6 ++-- lib/log/log.c | 2 ++ lib/log/log_freebsd.c | 2 +- lib/log/log_internal.h | 5 ++- lib/log/log_linux.c | 47 ++++++++++++++++++++++++-- lib/log/log_windows.c | 8 ++++- lib/log/version.map | 1 + 10 files changed, 70 insertions(+), 64 deletions(-) diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index 5435399b85..661b2db211 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -6,9 +6,6 @@ #include #include #include -#ifndef RTE_EXEC_ENV_WINDOWS -#include -#endif #include #include #include @@ -349,10 +346,6 @@ eal_reset_internal_config(struct internal_config *internal_cfg) } internal_cfg->base_virtaddr = 0; -#ifdef LOG_DAEMON - internal_cfg->syslog_facility = LOG_DAEMON; -#endif - /* if set to NONE, interrupt mode is determined automatically */ internal_cfg->vfio_intr_mode = RTE_INTR_MODE_NONE; memset(internal_cfg->vfio_vf_token, 0, @@ -1297,47 +1290,6 @@ eal_parse_lcores(const char *lcores) return ret; } -#ifndef RTE_EXEC_ENV_WINDOWS -static int -eal_parse_syslog(const char *facility, struct internal_config *conf) -{ - int i; - static const struct { - const char *name; - int value; - } map[] = { - { "auth", LOG_AUTH }, - { "cron", LOG_CRON }, - { "daemon", LOG_DAEMON }, - { "ftp", LOG_FTP }, - { "kern", LOG_KERN }, - { "lpr", LOG_LPR }, - { "mail", LOG_MAIL }, - { "news", LOG_NEWS }, - { "syslog", LOG_SYSLOG }, - { "user", LOG_USER }, - { "uucp", LOG_UUCP }, - { "local0", LOG_LOCAL0 }, - { "local1", LOG_LOCAL1 }, - { "local2", LOG_LOCAL2 }, - { "local3", LOG_LOCAL3 }, - { "local4", LOG_LOCAL4 }, - { "local5", LOG_LOCAL5 }, - { "local6", LOG_LOCAL6 }, - { "local7", LOG_LOCAL7 }, - { NULL, 0 } - }; - - for (i = 0; map[i].name; i++) { - if (!strcmp(facility, map[i].name)) { - conf->syslog_facility = map[i].value; - return 0; - } - } - return -1; -} -#endif - static void eal_log_usage(void) { @@ -1663,6 +1615,7 @@ eal_log_level_parse(int argc, char * const argv[]) switch (opt) { case OPT_LOG_LEVEL_NUM: + case OPT_SYSLOG_NUM: if (eal_parse_common_option(opt, optarg, internal_conf) < 0) return -1; break; @@ -1882,7 +1835,7 @@ eal_parse_common_option(int opt, const char *optarg, #ifndef RTE_EXEC_ENV_WINDOWS case OPT_SYSLOG_NUM: - if (eal_parse_syslog(optarg, conf) < 0) { + if (eal_log_syslog(optarg) < 0) { EAL_LOG(ERR, "invalid parameters for --" OPT_SYSLOG); return -1; diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index 17b56f38aa..6552f9c138 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -392,8 +391,8 @@ eal_parse_args(int argc, char **argv) goto out; } - /* eal_log_level_parse() already handled this option */ - if (opt == OPT_LOG_LEVEL_NUM) + /* eal_log_level_parse() already handled these */ + if (opt == OPT_LOG_LEVEL_NUM || opt == OPT_LOG_SYSLOG_NUM) continue; ret = eal_parse_common_option(opt, optarg, internal_conf); diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index 23dc26b124..3d0c34063e 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -610,8 +610,8 @@ eal_parse_args(int argc, char **argv) goto out; } - /* eal_log_level_parse() already handled this option */ - if (opt == OPT_LOG_LEVEL_NUM) + /* eal_log_level_parse() already handled these options */ + if (opt == OPT_LOG_LEVEL_NUM || opt == OPT_SYSLOG_NUM) continue; ret = eal_parse_common_option(opt, optarg, internal_conf); @@ -1106,8 +1106,7 @@ rte_eal_init(int argc, char **argv) #endif } - if (eal_log_init(program_invocation_short_name, - internal_conf->syslog_facility) < 0) { + if (eal_log_init(program_invocation_short_name) < 0) { rte_eal_init_alert("Cannot init logging."); rte_errno = ENOMEM; rte_atomic_store_explicit(&run_once, 0, rte_memory_order_relaxed); diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c index 85171b2768..2519a30017 100644 --- a/lib/eal/windows/eal.c +++ b/lib/eal/windows/eal.c @@ -120,8 +120,8 @@ eal_parse_args(int argc, char **argv) return -1; } - /* eal_log_level_parse() already handled this option */ - if (opt == OPT_LOG_LEVEL_NUM) + /* eal_log_level_parse() already handled these options */ + if (opt == OPT_LOG_LEVEL_NUM || opt == OPT_SYSLOG_NUM) continue; ret = eal_parse_common_option(opt, optarg, internal_conf); @@ -250,7 +250,7 @@ rte_eal_init(int argc, char **argv) char cpuset[RTE_CPU_AFFINITY_STR_LEN]; char thread_name[RTE_THREAD_NAME_SIZE]; - eal_log_init(NULL, 0); + eal_log_init(NULL); eal_log_level_parse(argc, argv); diff --git a/lib/log/log.c b/lib/log/log.c index 255f757d94..4b24e145b6 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -2,6 +2,7 @@ * Copyright(c) 2010-2014 Intel Corporation */ +#include #include #include #include @@ -12,6 +13,7 @@ #include #include +#include #include #include diff --git a/lib/log/log_freebsd.c b/lib/log/log_freebsd.c index 698d3c5423..953e371bee 100644 --- a/lib/log/log_freebsd.c +++ b/lib/log/log_freebsd.c @@ -6,7 +6,7 @@ #include "log_internal.h" int -eal_log_init(__rte_unused const char *id, __rte_unused int facility) +eal_log_init(__rte_unused const char *id) { return 0; } diff --git a/lib/log/log_internal.h b/lib/log/log_internal.h index 451629f1c1..cb15cdff08 100644 --- a/lib/log/log_internal.h +++ b/lib/log/log_internal.h @@ -14,7 +14,7 @@ * Initialize the default log stream. */ __rte_internal -int eal_log_init(const char *id, int facility); +int eal_log_init(const char *id); /* * Determine where log data is written when no call to rte_openlog_stream. @@ -30,6 +30,9 @@ int eal_log_save_regexp(const char *regexp, uint32_t level); __rte_internal int eal_log_save_pattern(const char *pattern, uint32_t level); +__rte_internal +int eal_log_syslog(const char *name); + /* * Convert log level to string. */ diff --git a/lib/log/log_linux.c b/lib/log/log_linux.c index 2dfb0c974b..47aa074da2 100644 --- a/lib/log/log_linux.c +++ b/lib/log/log_linux.c @@ -3,13 +3,56 @@ */ #include +#include #include #include +#include #include #include "log_internal.h" +static int log_facility = LOG_DAEMON; + +static const struct { + const char *name; + int value; +} facilitys[] = { + { "auth", LOG_AUTH }, + { "cron", LOG_CRON }, + { "daemon", LOG_DAEMON }, + { "ftp", LOG_FTP }, + { "kern", LOG_KERN }, + { "lpr", LOG_LPR }, + { "mail", LOG_MAIL }, + { "news", LOG_NEWS }, + { "syslog", LOG_SYSLOG }, + { "user", LOG_USER }, + { "uucp", LOG_UUCP }, + { "local0", LOG_LOCAL0 }, + { "local1", LOG_LOCAL1 }, + { "local2", LOG_LOCAL2 }, + { "local3", LOG_LOCAL3 }, + { "local4", LOG_LOCAL4 }, + { "local5", LOG_LOCAL5 }, + { "local6", LOG_LOCAL6 }, + { "local7", LOG_LOCAL7 }, +}; + +int +eal_log_syslog(const char *name) +{ + unsigned int i; + + for (i = 0; i < RTE_DIM(facilitys); i++) { + if (!strcmp(name, facilitys[i].name)) { + log_facility = facilitys[i].value; + return 0; + } + } + return -1; +} + /* * default log function */ @@ -45,7 +88,7 @@ static cookie_io_functions_t console_log_func = { * once memzones are available. */ int -eal_log_init(const char *id, int facility) +eal_log_init(const char *id) { FILE *log_stream; @@ -53,7 +96,7 @@ eal_log_init(const char *id, int facility) if (log_stream == NULL) return -1; - openlog(id, LOG_NDELAY | LOG_PID, facility); + openlog(id, LOG_NDELAY | LOG_PID, log_facility); eal_log_set_default(log_stream); diff --git a/lib/log/log_windows.c b/lib/log/log_windows.c index a6a0889550..a3a756351d 100644 --- a/lib/log/log_windows.c +++ b/lib/log/log_windows.c @@ -6,9 +6,15 @@ #include #include "log_internal.h" +int +eal_log_syslog(const char *name __rte_unused) +{ + return -1; /* not used */ +} + /* set the log to default function, called during eal init process. */ int -eal_log_init(__rte_unused const char *id, __rte_unused int facility) +eal_log_init(__rte_unused const char *id) { rte_openlog_stream(stderr); diff --git a/lib/log/version.map b/lib/log/version.map index 0648f8831a..9c6c49bf06 100644 --- a/lib/log/version.map +++ b/lib/log/version.map @@ -30,5 +30,6 @@ INTERNAL { eal_log_save_pattern; eal_log_save_regexp; eal_log_set_default; + eal_log_syslog; rte_eal_log_cleanup; }; From patchwork Sat Mar 30 16:42:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 139004 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 42C1643D85; Sat, 30 Mar 2024 17:45:45 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7E487406B8; Sat, 30 Mar 2024 17:45:00 +0100 (CET) Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by mails.dpdk.org (Postfix) with ESMTP id 0985E402E4 for ; Sat, 30 Mar 2024 17:44:51 +0100 (CET) Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-6e740fff1d8so2332728b3a.1 for ; Sat, 30 Mar 2024 09:44:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711817090; x=1712421890; 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=pO2H7xpH9AOw1/XCOM50PqskVKuH6K7qnRder6jD5xg=; b=tdRa4utG0EsMq93bkPEXYYOTsgq+Ip+NbrDpyJp6GEoM2LiXugf0P9bX5Hy5Ps9z0D dJZpdtlIlncYkywJqZtvxwcGZI3eAFbyZ6StGls94hXPxwRfwztu/R+nQmVwHUhHckPY Ul5vL/hGr6SihAfZed7mncXGEicuScGOrKaw3Y2IG1D9rBPNOoSeMn0Pv9a1UFYLTjqp +PyWzjV+oocqxTWPx45vDDG7MASkPlxMce/hm3yoW5HE9zgdK+fZfCcS/vmXRAhBQ8H+ k6g1ZtalCKrZ+t+VrQcDrzXGBRQxvYMwTBQjcKxuN+b48TQ6PD3cLw7GuhKkrirU2qYx cSkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711817090; x=1712421890; 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=pO2H7xpH9AOw1/XCOM50PqskVKuH6K7qnRder6jD5xg=; b=j8QjkxFkoWaO1k+xwPzSsQSea/yElHnRA2fAp48gKxAaxQ76FtiLN2l9BHqx89hYHc IhvxPOcIPz6QNcEBHF8fDaJf08ohZ4NQp0TCSGEWq224tP7DMx4AkIbN/bgzPlJkqNgE LCpgDy3nqInSvrVWQzZ3CB9WinA2y0yWT3rwq6Z+jytMB5JnZViZlhq3Oh3veRLWXaH4 kpXY0AP0hsYgZ1Zn2CAC4StcTJVpFaEHYwlRi1t4E3fFblP27wmPL7+Wlz2pHW3kkIol 59PvZEV6iFGwZzu1eReOGkLdL84j5VPIUpiHI4gKRKNgCdlBpVAKfOeoe15v4EzgzOKl 6dUA== X-Gm-Message-State: AOJu0YzRlC9H9E3UkPfEyyMQpm/Yxrrg0PSM7Njywwz1RAg28btpn6F/ VU4NXfyYwdYuE9SziV95bxy/OWYBq2V/yVq6RQcvyubeV4MNskHDZq0LMKIggAj0vLBRFt8gYo5 7 X-Google-Smtp-Source: AGHT+IG25j2jf8qokbj+goUeTizJnU4TvSlZIajSPEHidnfYLF6KmQvIE0wcoH3v1Rnv5tizKy8qAA== X-Received: by 2002:a05:6a00:14ca:b0:6ea:baed:a136 with SMTP id w10-20020a056a0014ca00b006eabaeda136mr5896664pfu.8.1711817090209; Sat, 30 Mar 2024 09:44:50 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id by1-20020a056a02058100b005dc26144d96sm4192417pgb.75.2024.03.30.09.44.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Mar 2024 09:44:49 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff , Bruce Richardson , Dmitry Kozlyuk , Pallavi Kadam Subject: [PATCH v20 08/14] eal: initialize log before everything else Date: Sat, 30 Mar 2024 09:42:19 -0700 Message-ID: <20240330164433.50144-9-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240330164433.50144-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240330164433.50144-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org In order for all log messages (including CPU mismatch) to come out through the logging library, it must be initialized as early in rte_eal_init() as possible on all platforms. Where it was done before was likely historical based on the support of non-OS isolated CPU's which required a shared memory buffer; that support was dropped before DPDK was publicly released. Signed-off-by: Stephen Hemminger Acked-by: Tyler Retzlaff --- lib/eal/freebsd/eal.c | 12 +++++++++--- lib/eal/linux/eal.c | 19 +++++++++---------- lib/eal/windows/eal.c | 8 ++++++-- lib/log/log_freebsd.c | 3 +-- lib/log/log_internal.h | 2 +- lib/log/log_linux.c | 14 ++++++-------- lib/log/log_windows.c | 4 +--- 7 files changed, 33 insertions(+), 29 deletions(-) diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index 6552f9c138..55ff27a4da 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -52,6 +52,7 @@ #include "eal_options.h" #include "eal_memcfg.h" #include "eal_trace.h" +#include "log_internal.h" #define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL) @@ -546,6 +547,14 @@ rte_eal_init(int argc, char **argv) bool has_phys_addr; enum rte_iova_mode iova_mode; + /* setup log as early as possible */ + if (eal_log_level_parse(argc, argv) < 0) { + rte_eal_init_alert("invalid log arguments."); + rte_errno = EINVAL; + return -1; + } + eal_log_init(getprogname()); + /* checks if the machine is adequate */ if (!rte_cpu_is_supported()) { rte_eal_init_alert("unsupported cpu type."); @@ -565,9 +574,6 @@ rte_eal_init(int argc, char **argv) /* clone argv to report out later in telemetry */ eal_save_args(argc, argv); - /* set log level as early as possible */ - eal_log_level_parse(argc, argv); - if (rte_eal_cpu_init() < 0) { rte_eal_init_alert("Cannot detect lcores."); rte_errno = ENOTSUP; diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index 3d0c34063e..b9a0fb1742 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -936,6 +936,15 @@ rte_eal_init(int argc, char **argv) struct internal_config *internal_conf = eal_get_internal_configuration(); + /* setup log as early as possible */ + if (eal_log_level_parse(argc, argv) < 0) { + rte_eal_init_alert("invalid log arguments."); + rte_errno = EINVAL; + return -1; + } + + eal_log_init(program_invocation_short_name); + /* checks if the machine is adequate */ if (!rte_cpu_is_supported()) { rte_eal_init_alert("unsupported cpu type."); @@ -952,9 +961,6 @@ rte_eal_init(int argc, char **argv) eal_reset_internal_config(internal_conf); - /* set log level as early as possible */ - eal_log_level_parse(argc, argv); - /* clone argv to report out later in telemetry */ eal_save_args(argc, argv); @@ -1106,13 +1112,6 @@ rte_eal_init(int argc, char **argv) #endif } - if (eal_log_init(program_invocation_short_name) < 0) { - rte_eal_init_alert("Cannot init logging."); - rte_errno = ENOMEM; - rte_atomic_store_explicit(&run_once, 0, rte_memory_order_relaxed); - return -1; - } - #ifdef VFIO_PRESENT if (rte_eal_vfio_setup() < 0) { rte_eal_init_alert("Cannot init VFIO"); diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c index 2519a30017..74b3ece30c 100644 --- a/lib/eal/windows/eal.c +++ b/lib/eal/windows/eal.c @@ -250,9 +250,13 @@ rte_eal_init(int argc, char **argv) char cpuset[RTE_CPU_AFFINITY_STR_LEN]; char thread_name[RTE_THREAD_NAME_SIZE]; - eal_log_init(NULL); + if (eal_log_level_parse(argc, argv) < 0) { + rte_eal_init_alert("invalid log arguments."); + rte_errno = EINVAL; + return -1; + } - eal_log_level_parse(argc, argv); + eal_log_init(NULL); if (eal_create_cpu_map() < 0) { rte_eal_init_alert("Cannot discover CPU and NUMA."); diff --git a/lib/log/log_freebsd.c b/lib/log/log_freebsd.c index 953e371bee..33a0925c43 100644 --- a/lib/log/log_freebsd.c +++ b/lib/log/log_freebsd.c @@ -5,8 +5,7 @@ #include #include "log_internal.h" -int +void eal_log_init(__rte_unused const char *id) { - return 0; } diff --git a/lib/log/log_internal.h b/lib/log/log_internal.h index cb15cdff08..d5fabd7ef7 100644 --- a/lib/log/log_internal.h +++ b/lib/log/log_internal.h @@ -14,7 +14,7 @@ * Initialize the default log stream. */ __rte_internal -int eal_log_init(const char *id); +void eal_log_init(const char *id); /* * Determine where log data is written when no call to rte_openlog_stream. diff --git a/lib/log/log_linux.c b/lib/log/log_linux.c index 47aa074da2..6d7dc8f3ab 100644 --- a/lib/log/log_linux.c +++ b/lib/log/log_linux.c @@ -87,18 +87,16 @@ static cookie_io_functions_t console_log_func = { * set the log to default function, called during eal init process, * once memzones are available. */ -int +void eal_log_init(const char *id) { FILE *log_stream; - log_stream = fopencookie(NULL, "w+", console_log_func); - if (log_stream == NULL) - return -1; - openlog(id, LOG_NDELAY | LOG_PID, log_facility); - eal_log_set_default(log_stream); - - return 0; + log_stream = fopencookie(NULL, "w+", console_log_func); + if (log_stream != NULL) + eal_log_set_default(log_stream); + else + eal_log_set_default(stderr); } diff --git a/lib/log/log_windows.c b/lib/log/log_windows.c index a3a756351d..d7c30e4cfa 100644 --- a/lib/log/log_windows.c +++ b/lib/log/log_windows.c @@ -13,12 +13,10 @@ eal_log_syslog(const char *name __rte_unused) } /* set the log to default function, called during eal init process. */ -int +void eal_log_init(__rte_unused const char *id) { rte_openlog_stream(stderr); eal_log_set_default(stderr); - - return 0; } From patchwork Sat Mar 30 16:42:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 139005 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 2455E43D85; Sat, 30 Mar 2024 17:45:53 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9C2D440A4B; Sat, 30 Mar 2024 17:45:01 +0100 (CET) Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) by mails.dpdk.org (Postfix) with ESMTP id C90C8402E4 for ; Sat, 30 Mar 2024 17:44:51 +0100 (CET) Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-6e6ca2ac094so2597002b3a.0 for ; Sat, 30 Mar 2024 09:44:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711817091; x=1712421891; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DyES1Rd7PjLKXezWsT8D1+VxR7yrYboVhk48nlLmRG0=; b=K7LdzmTTM5zUUSJm1umrzDtRrfGKZvRk2JKj8Uh9jE4xgGsH2ywRjWj5/MRYe1801g wL71nK7gDvoFUqJcfvp6H6VgfdEzMIMwOcvVDodSZzWDWe99wDDBzqp550Z5iiyuQmkt dp2WXCM5KoRwHkXQHRmmkOnBZFt81CRAi+ZJCji80IGE1YsrUjmkXXtA+PWpK6+tj9mt fFmKihd6fke8o1wImXW2akor4HHF6sZiw1XSdASmmh20/YhShoso0iOroGgVnrF6BKDD eJ7lxY8AhMqWdg5g3NgrEoQKLdDTQzmp6s7OyCmOx7txTUDkgZlT29cwbw5+6DwVL/T9 +svw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711817091; x=1712421891; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DyES1Rd7PjLKXezWsT8D1+VxR7yrYboVhk48nlLmRG0=; b=OsY9iJ387aXK33KmwuDyFY8woepGkxWlpBI4ybXeNnCuLG4lozSGakdqJPojviT5lK 6mRZHLguVGtoOUeC2lv41Y4+o3/Rw20G5gy2+5wIgrR/0lZ3iSB/ebhaLDtfQItDYUWK z8CNe9PG6pAKeWVklEpKV4PToMy3fYNkcLL+hOuZVCJL2ATm8tpTNrey1YHMzYgF0nqS SD5UwCLgzYkvhuVD03hds5gZ4Q4EBqxJ3bGGJSjTjGAkdexKG7rnOJesyg/Fq1o4DAKp q0QafERBnaxseQDwx2cZD57CIbuNuuSWu3Uqm+L2+doUpJvLk8Oi9ZDCs89yN7eDL/FK XfNQ== X-Gm-Message-State: AOJu0Ywbq1TqtQGjm9OVObgS3EKauqTKGI37E33nQ453/GVA/sDz2MqA tUq1WkLm3xSPatd80HvYXvRkxalPB3UbbGkFlkwPCrzjlPJRpgJsitOKYbbhuwXuOaA81MP3mKB I X-Google-Smtp-Source: AGHT+IF3UJnLjZgnrPfPWDB29vkrVVoYk2ri2Kzv43nwPA66WQfPGWP2hPfS/nGLxOmmDWj9XgkD7A== X-Received: by 2002:a05:6a21:78a4:b0:1a3:a99a:cd56 with SMTP id bf36-20020a056a2178a400b001a3a99acd56mr5358026pzc.38.1711817091007; Sat, 30 Mar 2024 09:44:51 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id by1-20020a056a02058100b005dc26144d96sm4192417pgb.75.2024.03.30.09.44.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Mar 2024 09:44:50 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v20 09/14] log: drop syslog support, and make code common Date: Sat, 30 Mar 2024 09:42:20 -0700 Message-ID: <20240330164433.50144-10-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240330164433.50144-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240330164433.50144-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org This patch makes the log setup code common across all platforms. Drops syslog support for now, will come back in later patch. Signed-off-by: Stephen Hemminger --- app/test/test_eal_flags.c | 11 ++- lib/eal/common/eal_common_options.c | 3 - lib/log/log.c | 41 +++++------ lib/log/log_freebsd.c | 11 --- lib/log/log_internal.h | 6 -- lib/log/log_linux.c | 102 ---------------------------- lib/log/log_windows.c | 22 ------ lib/log/meson.build | 5 +- lib/log/version.map | 1 - 9 files changed, 23 insertions(+), 179 deletions(-) delete mode 100644 lib/log/log_freebsd.c delete mode 100644 lib/log/log_linux.c delete mode 100644 lib/log/log_windows.c diff --git a/app/test/test_eal_flags.c b/app/test/test_eal_flags.c index 6cb4b06757..36e3185a10 100644 --- a/app/test/test_eal_flags.c +++ b/app/test/test_eal_flags.c @@ -984,11 +984,10 @@ test_misc_flags(void) const char *argv1[] = {prgname, prefix, mp_flag, "--no-pci"}; /* With -v */ const char *argv2[] = {prgname, prefix, mp_flag, "-v"}; + /* With empty --syslog */ + const char *argv3[] = {prgname, prefix, mp_flag, "--syslog"}; /* With valid --syslog */ - const char *argv3[] = {prgname, prefix, mp_flag, - "--syslog", "syslog"}; - /* With empty --syslog (should fail) */ - const char *argv4[] = {prgname, prefix, mp_flag, "--syslog"}; + const char *argv4[] = {prgname, prefix, mp_flag, "--syslog", "always"}; /* With invalid --syslog */ const char *argv5[] = {prgname, prefix, mp_flag, "--syslog", "error"}; /* With no-sh-conf, also use no-huge to ensure this test runs on BSD */ @@ -1083,8 +1082,8 @@ test_misc_flags(void) printf("Error - process did not run ok with --syslog flag\n"); goto fail; } - if (launch_proc(argv4) == 0) { - printf("Error - process run ok with empty --syslog flag\n"); + if (launch_proc(argv4) != 0) { + printf("Error - process did not with --syslog always flag\n"); goto fail; } if (launch_proc(argv5) == 0) { diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index 661b2db211..9ab512e8a1 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -2212,9 +2212,6 @@ eal_common_usage(void) " (can be used multiple times)\n" " --"OPT_VMWARE_TSC_MAP" Use VMware TSC map instead of native RDTSC\n" " --"OPT_PROC_TYPE" Type of this process (primary|secondary|auto)\n" -#ifndef RTE_EXEC_ENV_WINDOWS - " --"OPT_SYSLOG" Set syslog facility\n" -#endif " --"OPT_LOG_LEVEL"= Set global log level\n" " --"OPT_LOG_LEVEL"=:\n" " Set specific log level\n" diff --git a/lib/log/log.c b/lib/log/log.c index 4b24e145b6..3fe86ddcd7 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -57,9 +57,6 @@ TAILQ_HEAD(rte_eal_opt_loglevel_list, rte_eal_opt_loglevel); static struct rte_eal_opt_loglevel_list opt_loglevel_list = TAILQ_HEAD_INITIALIZER(opt_loglevel_list); -/* Stream to use for logging if rte_logs.file is NULL */ -static FILE *default_log_stream; - /** * This global structure stores some information about the message * that is currently being processed by one lcore @@ -72,8 +69,6 @@ struct log_cur_msg { /* per core log */ static RTE_DEFINE_PER_LCORE(struct log_cur_msg, log_cur_msg); -/* default logs */ - /* Change the stream that will be used by logging system */ int rte_openlog_stream(FILE *f) @@ -87,17 +82,7 @@ rte_log_get_stream(void) { FILE *f = rte_logs.file; - if (f == NULL) { - /* - * Grab the current value of stderr here, rather than - * just initializing default_log_stream to stderr. This - * ensures that we will always use the current value - * of stderr, even if the application closes and - * reopens it. - */ - return default_log_stream != NULL ? default_log_stream : stderr; - } - return f; + return (f == NULL) ? stderr : f; } /* Set global log level */ @@ -507,14 +492,19 @@ rte_log(uint32_t level, uint32_t logtype, const char *format, ...) return ret; } +/* Placeholder */ +int +eal_log_syslog(const char *mode __rte_unused) +{ + return -1; +} + /* - * Called by environment-specific initialization functions. + * Called by rte_eal_init */ void -eal_log_set_default(FILE *default_log) +eal_log_init(const char *id __rte_unused) { - default_log_stream = default_log; - #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG RTE_LOG(NOTICE, EAL, "Debug dataplane logs available - lower performance\n"); @@ -527,8 +517,11 @@ eal_log_set_default(FILE *default_log) void rte_eal_log_cleanup(void) { - if (default_log_stream) { - fclose(default_log_stream); - default_log_stream = NULL; - } + FILE *log_stream = rte_logs.file; + + /* don't close stderr on the application */ + if (log_stream != NULL) + fclose(log_stream); + + rte_logs.file = NULL; } diff --git a/lib/log/log_freebsd.c b/lib/log/log_freebsd.c deleted file mode 100644 index 33a0925c43..0000000000 --- a/lib/log/log_freebsd.c +++ /dev/null @@ -1,11 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * Copyright(c) 2023 Intel Corporation - */ - -#include -#include "log_internal.h" - -void -eal_log_init(__rte_unused const char *id) -{ -} diff --git a/lib/log/log_internal.h b/lib/log/log_internal.h index d5fabd7ef7..3c46328e7b 100644 --- a/lib/log/log_internal.h +++ b/lib/log/log_internal.h @@ -16,12 +16,6 @@ __rte_internal void eal_log_init(const char *id); -/* - * Determine where log data is written when no call to rte_openlog_stream. - */ -__rte_internal -void eal_log_set_default(FILE *default_log); - /* * Save a log option for later. */ diff --git a/lib/log/log_linux.c b/lib/log/log_linux.c deleted file mode 100644 index 6d7dc8f3ab..0000000000 --- a/lib/log/log_linux.c +++ /dev/null @@ -1,102 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * Copyright(c) 2010-2014 Intel Corporation - */ - -#include -#include -#include -#include - -#include -#include - -#include "log_internal.h" - -static int log_facility = LOG_DAEMON; - -static const struct { - const char *name; - int value; -} facilitys[] = { - { "auth", LOG_AUTH }, - { "cron", LOG_CRON }, - { "daemon", LOG_DAEMON }, - { "ftp", LOG_FTP }, - { "kern", LOG_KERN }, - { "lpr", LOG_LPR }, - { "mail", LOG_MAIL }, - { "news", LOG_NEWS }, - { "syslog", LOG_SYSLOG }, - { "user", LOG_USER }, - { "uucp", LOG_UUCP }, - { "local0", LOG_LOCAL0 }, - { "local1", LOG_LOCAL1 }, - { "local2", LOG_LOCAL2 }, - { "local3", LOG_LOCAL3 }, - { "local4", LOG_LOCAL4 }, - { "local5", LOG_LOCAL5 }, - { "local6", LOG_LOCAL6 }, - { "local7", LOG_LOCAL7 }, -}; - -int -eal_log_syslog(const char *name) -{ - unsigned int i; - - for (i = 0; i < RTE_DIM(facilitys); i++) { - if (!strcmp(name, facilitys[i].name)) { - log_facility = facilitys[i].value; - return 0; - } - } - return -1; -} - -/* - * default log function - */ -static ssize_t -console_log_write(__rte_unused void *c, const char *buf, size_t size) -{ - ssize_t ret; - - /* write on stderr */ - ret = fwrite(buf, 1, size, stderr); - fflush(stderr); - - /* Syslog error levels are from 0 to 7, so subtract 1 to convert */ - syslog(rte_log_cur_msg_loglevel() - 1, "%.*s", (int)size, buf); - - return ret; -} - -static int -console_log_close(__rte_unused void *c) -{ - closelog(); - return 0; -} - -static cookie_io_functions_t console_log_func = { - .write = console_log_write, - .close = console_log_close, -}; - -/* - * set the log to default function, called during eal init process, - * once memzones are available. - */ -void -eal_log_init(const char *id) -{ - FILE *log_stream; - - openlog(id, LOG_NDELAY | LOG_PID, log_facility); - - log_stream = fopencookie(NULL, "w+", console_log_func); - if (log_stream != NULL) - eal_log_set_default(log_stream); - else - eal_log_set_default(stderr); -} diff --git a/lib/log/log_windows.c b/lib/log/log_windows.c deleted file mode 100644 index d7c30e4cfa..0000000000 --- a/lib/log/log_windows.c +++ /dev/null @@ -1,22 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * Copyright(c) 2017-2018 Intel Corporation - */ - -#include -#include -#include "log_internal.h" - -int -eal_log_syslog(const char *name __rte_unused) -{ - return -1; /* not used */ -} - -/* set the log to default function, called during eal init process. */ -void -eal_log_init(__rte_unused const char *id) -{ - rte_openlog_stream(stderr); - - eal_log_set_default(stderr); -} diff --git a/lib/log/meson.build b/lib/log/meson.build index 0d4319b36f..891f77a237 100644 --- a/lib/log/meson.build +++ b/lib/log/meson.build @@ -2,8 +2,5 @@ # Copyright(c) 2023 Intel Corporation includes += global_inc -sources = files( - 'log.c', - 'log_' + exec_env + '.c', -) +sources = files('log.c') headers = files('rte_log.h') diff --git a/lib/log/version.map b/lib/log/version.map index 9c6c49bf06..32b9680c31 100644 --- a/lib/log/version.map +++ b/lib/log/version.map @@ -29,7 +29,6 @@ INTERNAL { eal_log_level2str; eal_log_save_pattern; eal_log_save_regexp; - eal_log_set_default; eal_log_syslog; rte_eal_log_cleanup; }; From patchwork Sat Mar 30 16:42:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 139006 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 3498D43D85; Sat, 30 Mar 2024 17:46:00 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CD7D740A75; Sat, 30 Mar 2024 17:45:02 +0100 (CET) Received: from mail-oa1-f44.google.com (mail-oa1-f44.google.com [209.85.160.44]) by mails.dpdk.org (Postfix) with ESMTP id 75F7B402EE for ; Sat, 30 Mar 2024 17:44:52 +0100 (CET) Received: by mail-oa1-f44.google.com with SMTP id 586e51a60fabf-22a96054726so2131120fac.0 for ; Sat, 30 Mar 2024 09:44:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711817092; x=1712421892; 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=PJaBt95mJGUWxHM6IfnmZOombz4LVzOya7YPQnoawfY=; b=fRTRzeLf4wTFUC+Wg+cVLMIZBI4n9evsB9k3McvrbZ42pWFJ5j6U5IZbK8W8xZGy47 dwJtuLx14grJoSi0xHW/i9LuaxwYF7iTssXg3R+Qbxm/LZ0s+iw7dLdhFCkQvX4sKQjF ehqGNUpNoEoEmNjv2oEdOOKGhI73MXMcTdNe+ByV/OBVL2npVNctAmSsIAYPybi0cItG rDEmMumDt2ofsaOdrdcfIrghRoslToP6fzebYVQd50c9aw4R7eFaoer4hJchqb2EXT+t z7O/eYGWBj0A1Y55WGqCdewBUHaCZGqyUskQ23wU9LLLbE5eI4jQm6YaqpYN4cm+Ea49 HnNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711817092; x=1712421892; 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=PJaBt95mJGUWxHM6IfnmZOombz4LVzOya7YPQnoawfY=; b=DqQx9nP1DamwV4AY7IYdfTDnAfuHI56cbwSfGg4dNnkQnRoBe1ZADm0ADl0CehraIM vzSdMklY4iuZkPLGPSyR8OzS7vpCOGXdmy0rtG2L7odpmy/SlQh1FnOi9hXeuoCYUyxG 5hKMw2fy7SrjXroVfN9OmrmPjpYsxb6VFivWfz4JFgE+t+TVJIzy9X4SmWuhNULLfXcu TLvF/Tt8jlKAKjBPVZBHcCvr11yQDyKLGyzrIMRPfFbQB/byxM7WtSJm7I8oCrgxTx0x 4/ypR1+qB2Ji4FJ9rWG6GaAUecMhfH61npnsdlc8sNGSKnrwX+MmY2++ht9sUzn6FpjC 4Qnw== X-Gm-Message-State: AOJu0YwL4quYqIaJxbqS7wuM6M0ohQ6IzWNl5fOEAX6pEvFy7KOEpOFg nUo587BExxga0Q4K6ZlrugTfMUiQYf+Cq6CsglGZighFdCWNHc///2bnSUNj9+WyDZqmDih35Kx a X-Google-Smtp-Source: AGHT+IE1adO28ODmnxVCQKhRFYqS7+Slmxdlk0TJE4keDnHmx+e+qfOWSW+WBKRx9W4ZhvuBlT4cZQ== X-Received: by 2002:a05:6870:2199:b0:22e:dce:39b6 with SMTP id l25-20020a056870219900b0022e0dce39b6mr3642298oae.48.1711817091844; Sat, 30 Mar 2024 09:44:51 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id by1-20020a056a02058100b005dc26144d96sm4192417pgb.75.2024.03.30.09.44.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Mar 2024 09:44:51 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v20 10/14] log: add hook for printing log messages Date: Sat, 30 Mar 2024 09:42:21 -0700 Message-ID: <20240330164433.50144-11-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240330164433.50144-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240330164433.50144-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org This is useful for when decorating log output for console or journal. Provide basic version in this patch. Signed-off-by: Stephen Hemminger --- lib/log/log.c | 7 ++++++- lib/log/log_private.h | 9 +++++++++ 2 files changed, 15 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..979b20c3ef 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -18,6 +18,7 @@ #include #include "log_internal.h" +#include "log_private.h" #ifdef RTE_EXEC_ENV_WINDOWS #define strdup _strdup @@ -28,16 +29,19 @@ struct rte_log_dynamic_type { uint32_t loglevel; }; + /** The rte_log structure. */ static struct rte_logs { uint32_t type; /**< Bitfield with enabled logs. */ uint32_t level; /**< Log level. */ FILE *file; /**< Output file set by rte_openlog_stream, or NULL. */ + log_print_t print_func; size_t dynamic_types_len; struct rte_log_dynamic_type *dynamic_types; } rte_logs = { .type = UINT32_MAX, .level = RTE_LOG_DEBUG, + .print_func = vfprintf, }; struct rte_eal_opt_loglevel { @@ -74,6 +78,7 @@ int rte_openlog_stream(FILE *f) { rte_logs.file = f; + rte_logs.print_func = vfprintf; return 0; } @@ -470,7 +475,7 @@ rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap) RTE_PER_LCORE(log_cur_msg).loglevel = level; RTE_PER_LCORE(log_cur_msg).logtype = logtype; - ret = vfprintf(f, format, ap); + ret = (*rte_logs.print_func)(f, 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 Sat Mar 30 16:42:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 139007 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 B84D343D85; Sat, 30 Mar 2024 17:46:06 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1A790406B6; Sat, 30 Mar 2024 17:45:04 +0100 (CET) Received: from mail-oi1-f177.google.com (mail-oi1-f177.google.com [209.85.167.177]) by mails.dpdk.org (Postfix) with ESMTP id 7AF33402E6 for ; Sat, 30 Mar 2024 17:44:53 +0100 (CET) Received: by mail-oi1-f177.google.com with SMTP id 5614622812f47-3c3aeef1385so2146662b6e.3 for ; Sat, 30 Mar 2024 09:44:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711817093; x=1712421893; 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=MoSMK2mRLCBWYunCS2Wzc1kUkaqeiNh1/1WXRKEZnlg=; b=k9XHnPGbIqJ0UkPrv8ytaZqoqhRC7+gAwYnkvPAGeOsjbE/Z+9nf1ER3YGlOhNU1dS ZLThbJvKIkjChvtXimcCoAYgWow1xVv+mfLMdUTBbBhhXKBNTfGmloafHeHpZ87C/4jK TYJH/zry91elB2uMo6LoZ2yDVAaIf9UOZrfgRm3S1QrJJSP8V5Ryv0xVRbWZ1fcxgTMC Y1Uk8TWZhg/pd0iBjUCO9Qex/uObkW2Cb9qYaLwJvaeUZ1QhbMPPivHqETTbR1zdieBl 8E7eA0GexXCzT0BYm60BWs5CsW2BwclWpKzIRj6L1I+qxkhVWmO+FELpdeJ1jCa1V7N9 N+bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711817093; x=1712421893; 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=MoSMK2mRLCBWYunCS2Wzc1kUkaqeiNh1/1WXRKEZnlg=; b=NyUIZhzj08yHlX1PtxdUTPf2CRIsXSejaNsTrNasvbrhfpvcWyLxX4tjbzwz9cVLjO /Qan6KBZTl6cVa32h13JwhoVyks2OMDPsmZzQnizmtYOd9TJpSPp7RrFHVo9q1P2Q28j MM1Q5G/lHmLh7Ho3WzSBWcOvDYDEdizWuezuwKhD3UdTzZtQA8sNGIdKyhRvvyTfHFJF 53WuWutGSqfWkydLiERRPyhXQ+qpV5oMCc/uw3xQfL+uQgqBtCf08CgVtWVMfhBbSXSr AFJsIwDh9+t5Fb0Q9M+oh42gTrri9oHwW45pC1++11B9IkENCsCqKzZvMaq0O2HJ9IZo 0b2w== X-Gm-Message-State: AOJu0Yw7VpyhI2KblYb0gNCgt9br0oyguDPlb6R7FLEFbLVrpOSeVQeC HtrXfA2If7dq8vhIOoZQQlc1nEnJPBgQsHfzTXuYKq4k+kb59GG4c/RfdXLkfYVma7IecHRKrwh 1 X-Google-Smtp-Source: AGHT+IGht/wJD5RdFRjYbtX9szgGRRn52B5VPGJ0lW2OmnCeAbQjJQsIeotIA7SqRCprZ4oY2NssnA== X-Received: by 2002:a05:6808:1211:b0:3c3:9fe6:2baf with SMTP id a17-20020a056808121100b003c39fe62bafmr6093255oil.20.1711817092763; Sat, 30 Mar 2024 09:44:52 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id by1-20020a056a02058100b005dc26144d96sm4192417pgb.75.2024.03.30.09.44.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Mar 2024 09:44:52 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Bruce Richardson , Dmitry Kozlyuk , Tyler Retzlaff , Pallavi Kadam Subject: [PATCH v20 11/14] log: add timestamp option Date: Sat, 30 Mar 2024 09:42:22 -0700 Message-ID: <20240330164433.50144-12-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240330164433.50144-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240330164433.50144-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org When debugging driver or startup issues, it is useful to have a timestamp on each message printed. The messages in syslog already have a timestamp, but often syslog is not available during testing. There are multiple timestamp formats similar to Linux dmesg. The default is time relative since startup (when first step of logging initialization is done by constructor). Other alternative formats are delta, ctime, reltime and iso formats. Example: $ dpdk-testpmd --log-timestamp -- -i [ 0.008610] EAL: Detected CPU lcores: 8 [ 0.008634] EAL: Detected NUMA nodes: 1 [ 0.008792] EAL: Detected static linkage of DPDK [ 0.010620] EAL: Multi-process socket /var/run/dpdk/rte/mp_socket [ 0.012618] EAL: Selected IOVA mode 'VA' [ 0.016675] testpmd: No probed ethernet devices Interactive-mode selected Signed-off-by: Stephen Hemminger --- app/test/test_eal_flags.c | 26 ++++ doc/guides/prog_guide/log_lib.rst | 26 ++++ lib/eal/common/eal_common_options.c | 14 +- lib/eal/common/eal_options.h | 2 + lib/eal/freebsd/eal.c | 6 +- lib/eal/linux/eal.c | 4 +- lib/eal/windows/eal.c | 4 +- lib/log/log.c | 10 +- lib/log/log_internal.h | 9 ++ lib/log/log_private.h | 11 ++ lib/log/log_timestamp.c | 210 ++++++++++++++++++++++++++++ lib/log/meson.build | 6 +- lib/log/version.map | 1 + 13 files changed, 319 insertions(+), 10 deletions(-) create mode 100644 lib/log/log_timestamp.c diff --git a/app/test/test_eal_flags.c b/app/test/test_eal_flags.c index 36e3185a10..e54f6e8b7f 100644 --- a/app/test/test_eal_flags.c +++ b/app/test/test_eal_flags.c @@ -1054,6 +1054,19 @@ test_misc_flags(void) const char * const argv22[] = {prgname, prefix, mp_flag, "--huge-worker-stack=512"}; + /* Try running with --log-timestamp */ + const char * const argv23[] = {prgname, prefix, mp_flag, + "--log-timestamp" }; + + /* Try running with --log-timestamp=iso */ + const char * const argv24[] = {prgname, prefix, mp_flag, + "--log-timestamp=iso" }; + + /* Try running with invalid timestamp */ + const char * const argv25[] = {prgname, prefix, mp_flag, + "--log-timestamp=invalid" }; + + /* run all tests also applicable to FreeBSD first */ if (launch_proc(argv0) == 0) { @@ -1161,6 +1174,19 @@ test_misc_flags(void) printf("Error - process did not run ok with --huge-worker-stack=size parameter\n"); goto fail; } + if (launch_proc(argv23) != 0) { + printf("Error - process did not run ok with --log-timestamp parameter\n"); + goto fail; + } + if (launch_proc(argv24) != 0) { + printf("Error - process did not run ok with --log-timestamp=iso parameter\n"); + goto fail; + } + if (launch_proc(argv25) == 0) { + printf("Error - process did run ok with --log-timestamp=invalid parameter\n"); + goto fail; + } + rmdir(hugepath_dir3); rmdir(hugepath_dir2); diff --git a/doc/guides/prog_guide/log_lib.rst b/doc/guides/prog_guide/log_lib.rst index ff9d1b54a2..504eefe1d2 100644 --- a/doc/guides/prog_guide/log_lib.rst +++ b/doc/guides/prog_guide/log_lib.rst @@ -59,6 +59,32 @@ For example:: Within an application, the same result can be got using the ``rte_log_set_level_pattern()`` or ``rte_log_set_level_regex()`` APIs. +Log timestamp +~~~~~~~~~~~~~ + +An optional timestamp can be added before each message +by adding the ``--log-timestamp`` option. +For example:: + + /path/to/app --log-level=lib.*:debug --log-timestamp + +Multiple timestamp alternative timestamp formats are available: + +.. csv-table:: Log time stamp format + :header: "Format", "Description", "Example" + :widths: 6, 30, 32 + + "ctime", "Unix ctime", "``[Wed Mar 20 07:26:12 2024]``" + "delta", "Offset since last", "``[< 3.162373>]``" + "reltime", "Seconds since last or time if minute changed", "``[ +3.001791]`` or ``[Mar20 07:26:12]``" + "iso", "ISO-8601", "``[2024-03-20T07:26:12−07:00]``" + +To prefix all console messages with ISO format time the syntax is:: + + /path/to/app --log-timestamp=iso + + + Using Logging APIs to Generate Log Messages ------------------------------------------- diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index 9ab512e8a1..5173835c2c 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -74,6 +74,7 @@ eal_long_options[] = { {OPT_IOVA_MODE, 1, NULL, OPT_IOVA_MODE_NUM }, {OPT_LCORES, 1, NULL, OPT_LCORES_NUM }, {OPT_LOG_LEVEL, 1, NULL, OPT_LOG_LEVEL_NUM }, + {OPT_LOG_TIMESTAMP, 2, NULL, OPT_LOG_TIMESTAMP_NUM }, {OPT_TRACE, 1, NULL, OPT_TRACE_NUM }, {OPT_TRACE_DIR, 1, NULL, OPT_TRACE_DIR_NUM }, {OPT_TRACE_BUF_SIZE, 1, NULL, OPT_TRACE_BUF_SIZE_NUM }, @@ -1616,6 +1617,7 @@ eal_log_level_parse(int argc, char * const argv[]) switch (opt) { case OPT_LOG_LEVEL_NUM: case OPT_SYSLOG_NUM: + case OPT_LOG_TIMESTAMP_NUM: if (eal_parse_common_option(opt, optarg, internal_conf) < 0) return -1; break; @@ -1843,7 +1845,7 @@ eal_parse_common_option(int opt, const char *optarg, break; #endif - case OPT_LOG_LEVEL_NUM: { + case OPT_LOG_LEVEL_NUM: if (eal_parse_log_level(optarg) < 0) { EAL_LOG(ERR, "invalid parameters for --" @@ -1851,7 +1853,14 @@ eal_parse_common_option(int opt, const char *optarg, return -1; } break; - } + + case OPT_LOG_TIMESTAMP_NUM: + if (eal_log_timestamp(optarg) < 0) { + EAL_LOG(ERR, "invalid parameters for --" + OPT_LOG_TIMESTAMP); + return -1; + } + break; #ifndef RTE_EXEC_ENV_WINDOWS case OPT_TRACE_NUM: { @@ -2216,6 +2225,7 @@ eal_common_usage(void) " --"OPT_LOG_LEVEL"=:\n" " Set specific log level\n" " --"OPT_LOG_LEVEL"=help Show log types and levels\n" + " --"OPT_LOG_TIMESTAMP"[=] Timestamp log output\n" #ifndef RTE_EXEC_ENV_WINDOWS " --"OPT_TRACE"=\n" " Enable trace based on regular expression trace name.\n" diff --git a/lib/eal/common/eal_options.h b/lib/eal/common/eal_options.h index f3f2e104f6..e24c9eca53 100644 --- a/lib/eal/common/eal_options.h +++ b/lib/eal/common/eal_options.h @@ -35,6 +35,8 @@ enum { OPT_LCORES_NUM, #define OPT_LOG_LEVEL "log-level" OPT_LOG_LEVEL_NUM, +#define OPT_LOG_TIMESTAMP "log-timestamp" + OPT_LOG_TIMESTAMP_NUM, #define OPT_TRACE "trace" OPT_TRACE_NUM, #define OPT_TRACE_DIR "trace-dir" diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index 55ff27a4da..662a829ce8 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -392,8 +392,10 @@ eal_parse_args(int argc, char **argv) goto out; } - /* eal_log_level_parse() already handled these */ - if (opt == OPT_LOG_LEVEL_NUM || opt == OPT_LOG_SYSLOG_NUM) + /* eal_log_level_parse() already handled these options */ + if (opt == OPT_LOG_LEVEL_NUM || + opt == OPT_SYSLOG_NUM || + opt == OPT_LOG_TIMESTAMP_NUM) continue; ret = eal_parse_common_option(opt, optarg, internal_conf); diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index b9a0fb1742..8cbea480e0 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -611,7 +611,9 @@ eal_parse_args(int argc, char **argv) } /* eal_log_level_parse() already handled these options */ - if (opt == OPT_LOG_LEVEL_NUM || opt == OPT_SYSLOG_NUM) + if (opt == OPT_LOG_LEVEL_NUM || + opt == OPT_SYSLOG_NUM || + opt == OPT_LOG_TIMESTAMP_NUM) continue; ret = eal_parse_common_option(opt, optarg, internal_conf); diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c index 74b3ece30c..4283c920c8 100644 --- a/lib/eal/windows/eal.c +++ b/lib/eal/windows/eal.c @@ -121,7 +121,9 @@ eal_parse_args(int argc, char **argv) } /* eal_log_level_parse() already handled these options */ - if (opt == OPT_LOG_LEVEL_NUM || opt == OPT_SYSLOG_NUM) + if (opt == OPT_LOG_LEVEL_NUM || + opt == OPT_SYSLOG_NUM || + opt == OPT_LOG_TIMESTAMP_NUM) continue; ret = eal_parse_common_option(opt, optarg, internal_conf); diff --git a/lib/log/log.c b/lib/log/log.c index 979b20c3ef..71db4894fa 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -21,7 +21,7 @@ #include "log_private.h" #ifdef RTE_EXEC_ENV_WINDOWS -#define strdup _strdup +#include #endif struct rte_log_dynamic_type { @@ -29,13 +29,13 @@ struct rte_log_dynamic_type { uint32_t loglevel; }; - /** The rte_log structure. */ static struct rte_logs { uint32_t type; /**< Bitfield with enabled logs. */ uint32_t level; /**< Log level. */ FILE *file; /**< Output file set by rte_openlog_stream, or NULL. */ log_print_t print_func; + size_t dynamic_types_len; struct rte_log_dynamic_type *dynamic_types; } rte_logs = { @@ -359,7 +359,6 @@ static const struct logtype logtype_strings[] = { RTE_INIT_PRIO(log_init, LOG) { uint32_t i; - rte_log_set_global_level(RTE_LOG_DEBUG); rte_logs.dynamic_types = calloc(RTE_LOGTYPE_FIRST_EXT_ID, @@ -510,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..04d8eba37b --- /dev/null +++ b/lib/log/log_timestamp.c @@ -0,0 +1,210 @@ +/* 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" + +static enum { + LOG_TIMESTAMP_NONE = 0, + LOG_TIMESTAMP_TIME, /* time since start */ + LOG_TIMESTAMP_DELTA, /* time since last message */ + LOG_TIMESTAMP_RELTIME, /* relative time since last message */ + LOG_TIMESTAMP_CTIME, /* Unix standard time format */ + LOG_TIMESTAMP_ISO, /* ISO8601 time format */ +} log_time_format; + +static struct { + struct timespec started; /* when log was initialized */ + struct timespec previous; /* when last msg was printed */ +} log_time; + +/* Set the log timestamp format */ +int +eal_log_timestamp(const char *str) +{ + if (str == NULL) + log_time_format = LOG_TIMESTAMP_TIME; + else if (strcmp(str, "notime") == 0) + log_time_format = LOG_TIMESTAMP_NONE; + else if (strcmp(str, "reltime") == 0) + log_time_format = LOG_TIMESTAMP_RELTIME; + else if (strcmp(str, "delta") == 0) + log_time_format = LOG_TIMESTAMP_DELTA; + else if (strcmp(str, "ctime") == 0) + log_time_format = LOG_TIMESTAMP_CTIME; + else if (strcmp(str, "iso") == 0) + log_time_format = LOG_TIMESTAMP_ISO; + else + return -1; + + return 0; +} + +bool +log_timestamp_enabled(void) +{ + return log_time_format != LOG_TIMESTAMP_NONE; +} + +/* Subtract two timespec values and handle wraparound */ +static struct timespec +timespec_sub(const struct timespec *t0, const struct timespec *t1) +{ + struct timespec ts; + + ts.tv_sec = t0->tv_sec - t1->tv_sec; + ts.tv_nsec = t0->tv_nsec - t1->tv_nsec; + if (ts.tv_nsec < 0) { + ts.tv_sec--; + ts.tv_nsec += 1000000000L; + } + return ts; +} + +/* + * Format current timespec into ISO8601 format. + * Surprisingly, can't just use strftime() for this; + * since want microseconds and the timezone offset format differs. + */ +static ssize_t +format_iso8601(char *tsbuf, size_t tsbuflen, const struct timespec *now) +{ + struct tm *tm, tbuf; + char dbuf[64]; /* "2024-05-01T22:11:00" */ + char zbuf[16] = { }; /* "+0800" */ + + tm = localtime_r(&now->tv_sec, &tbuf); + + /* make "2024-05-01T22:11:00,123456+0100" */ + if (strftime(dbuf, sizeof(dbuf), "%Y-%m-%dT%H:%M:%S", tm) == 0) + return 0; + + /* convert timezone to +hhmm */ + if (strftime(zbuf, sizeof(zbuf), "%z", tm) == 0) + return 0; + + /* the result for strftime is "+hhmm" but ISO wants "+hh:mm" */ + return snprintf(tsbuf, tsbuflen, "%s,%06lu%.3s:%.2s", + dbuf, now->tv_nsec / 1000u, + zbuf, zbuf + 3); +} + +/* + * Make a timestamp where if the minute, hour or day has + * changed from the last message, then print abbreviated + * "Month day hour:minute" format. + * Otherwise print delta from last printed message as +sec.usec + */ +static ssize_t +format_reltime(char *tsbuf, size_t tsbuflen, const struct timespec *now) +{ + struct tm *tm, tbuf; + static struct tm last_tm; + struct timespec delta; + + tm = localtime_r(&now->tv_sec, &tbuf); + delta = timespec_sub(now, &log_time.previous); + log_time.previous = *now; + + /* if minute, day, hour hasn't changed then print delta */ + if (tm->tm_min != last_tm.tm_min || + tm->tm_hour != last_tm.tm_hour || + tm->tm_yday != last_tm.tm_yday) { + last_tm = *tm; + return strftime(tsbuf, tsbuflen, "%b%d %H:%M", tm); + } else { + return snprintf(tsbuf, tsbuflen, "+%3lu.%06lu", + (unsigned long)delta.tv_sec, + (unsigned long)delta.tv_nsec / 1000u); + } +} + +/* Format up a timestamp based on current format */ +ssize_t +log_timestamp(char *tsbuf, size_t tsbuflen) +{ + struct timespec now, delta; + + switch (log_time_format) { + case LOG_TIMESTAMP_NONE: + return 0; + + case LOG_TIMESTAMP_TIME: + if (clock_gettime(CLOCK_MONOTONIC, &now) < 0) + return 0; + + delta = timespec_sub(&now, &log_time.started); + + return snprintf(tsbuf, tsbuflen, "%6lu.%06lu", + (unsigned long)delta.tv_sec, + (unsigned long)delta.tv_nsec / 1000u); + + case LOG_TIMESTAMP_DELTA: + if (clock_gettime(CLOCK_MONOTONIC, &now) < 0) + return 0; + + delta = timespec_sub(&now, &log_time.previous); + log_time.previous = now; + + return snprintf(tsbuf, tsbuflen, "<%6lu.%06lu>", + (unsigned long)delta.tv_sec, + (unsigned long)delta.tv_nsec / 1000u); + + case LOG_TIMESTAMP_RELTIME: + if (clock_gettime(CLOCK_REALTIME, &now) < 0) + return 0; + + return format_reltime(tsbuf, tsbuflen, &now); + + case LOG_TIMESTAMP_CTIME: + if (clock_gettime(CLOCK_REALTIME, &now) < 0) + return 0; + + /* trncate to remove newline from ctime result */ + return snprintf(tsbuf, tsbuflen, "%.24s", ctime(&now.tv_sec)); + + case LOG_TIMESTAMP_ISO: + if (clock_gettime(CLOCK_REALTIME, &now) < 0) + return 0; + + return format_iso8601(tsbuf, tsbuflen, &now); + } + + return 0; +} + +/* print timestamp before message */ +int +log_print_with_timestamp(FILE *f, 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) +{ + clock_gettime(CLOCK_MONOTONIC, &log_time.started); + log_time.previous = log_time.started; +} diff --git a/lib/log/meson.build b/lib/log/meson.build index 891f77a237..04235f6ee5 100644 --- a/lib/log/meson.build +++ b/lib/log/meson.build @@ -2,5 +2,9 @@ # Copyright(c) 2023 Intel Corporation includes += global_inc -sources = files('log.c') +sources = files( + 'log.c', + 'log_timestamp.c', +) + headers = files('rte_log.h') diff --git a/lib/log/version.map b/lib/log/version.map index 32b9680c31..14d6681a5f 100644 --- a/lib/log/version.map +++ b/lib/log/version.map @@ -30,5 +30,6 @@ INTERNAL { eal_log_save_pattern; eal_log_save_regexp; eal_log_syslog; + eal_log_timestamp; rte_eal_log_cleanup; }; From patchwork Sat Mar 30 16:42:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 139008 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 F2D1943D85; Sat, 30 Mar 2024 17:46:12 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7FDBE410E3; Sat, 30 Mar 2024 17:45:05 +0100 (CET) Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by mails.dpdk.org (Postfix) with ESMTP id 75AE140649 for ; Sat, 30 Mar 2024 17:44:54 +0100 (CET) Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-6ea9a605ca7so2030392b3a.0 for ; Sat, 30 Mar 2024 09:44:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711817093; x=1712421893; 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=/+QKpm6xR98auT0x/M9wU2qUTq8KBmr6BTV8HZE+CCk=; b=JB+xZISF2JsS42k4G8exZN5qiS7yXZC8lzJuSvVk5Jf/kz5nlJwI4EWqgz4rDqgbUa IzgiBhbLnPRfuD83tDSIwRqAxxUBcU5IvIfJnk0wl/RZwwgVKhpp+neAslSptSZwsEs0 +rmX1tZ2w7r3FkkrWN9GahAgYiyUEGO7h9tURCkNQNJuUfXEzrKpUxNW3W1dOf2fVhcD OR8J5Bn2qRXOop88SdaSnbwMcNbfHCpi1217sMEAJ7baz2TmVIr1g4yPZIU25rWd4gGI GCm5P4nG7dcIDNEbJkBsrWm01QnIKxcx6cEmTpdBJ2roniPUWYpkLxioVYfAN0MFo/Xe 91ZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711817093; x=1712421893; 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=/+QKpm6xR98auT0x/M9wU2qUTq8KBmr6BTV8HZE+CCk=; b=HQCti63su0RULLoy3XNm3rKGMKkoF24hvl42aVwEbeUDMcqBw7SxVla5vbd5RxJ8QY IcBg2Gr26HRbeeWy+bOJjrwPfJ03c3CdvNsfCM6sO1GES5389o2/KI5JQre8K7FLTjPg DhItDw8xtisjmwznx8YuEv4QI/TkM0ey0NfrKioAIM/KItHJSStIzY5H5lsaOjUxihJu 4nqwpAlXA4JIGb+7SOd58FLTbmdZ07sAVmkZm0bTWPG79pN1kSf+JQu+R2XBtfn+a7Tr eek7U6Knz60lXsoyOSA2+5/inDUbiPhCKPZ6QNxqb92orBwL0QEmDLsvczShYSConf6L Ck5w== X-Gm-Message-State: AOJu0YyYZ3smR7Ra2jyjiOCCOgR/SyJVFSh1W/nrNCSaviX15UVrhkJ2 HS31PhF2zhO7kSkkkPV1p4L6HeYDfGZrZ3YsaT6FxqyxY2JeURuSWTCi/b4CObB/6OCLn3ewAmS v X-Google-Smtp-Source: AGHT+IERspI1NfZlDHJtCuDoyH95ABRNcc0YuD0WDKSSr4Wl7sZI3JdZW8AxPeRtPwEb3RMBVhYcfQ== X-Received: by 2002:a05:6a20:7f8c:b0:1a3:ae53:fa6b with SMTP id d12-20020a056a207f8c00b001a3ae53fa6bmr7246224pzj.6.1711817093620; Sat, 30 Mar 2024 09:44:53 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id by1-20020a056a02058100b005dc26144d96sm4192417pgb.75.2024.03.30.09.44.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Mar 2024 09:44:53 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v20 12/14] log: add optional support of syslog Date: Sat, 30 Mar 2024 09:42:23 -0700 Message-ID: <20240330164433.50144-13-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240330164433.50144-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240330164433.50144-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Log to syslog only if option is specified. And if syslog is used then normally only log to syslog, don't duplicate output. Also enables syslog support on FreeBSD. Signed-off-by: Stephen Hemminger --- app/test/test_eal_flags.c | 5 +- doc/guides/linux_gsg/linux_eal_parameters.rst | 27 ------ doc/guides/prog_guide/log_lib.rst | 17 ++++ lib/eal/common/eal_common_options.c | 5 +- lib/log/log.c | 25 +++--- lib/log/log_private.h | 4 + lib/log/log_stubs.c | 28 ++++++ lib/log/log_syslog.c | 88 +++++++++++++++++++ lib/log/meson.build | 6 ++ 9 files changed, 164 insertions(+), 41 deletions(-) create mode 100644 lib/log/log_stubs.c create mode 100644 lib/log/log_syslog.c diff --git a/app/test/test_eal_flags.c b/app/test/test_eal_flags.c index e54f6e8b7f..08f4866461 100644 --- a/app/test/test_eal_flags.c +++ b/app/test/test_eal_flags.c @@ -987,9 +987,10 @@ test_misc_flags(void) /* With empty --syslog */ const char *argv3[] = {prgname, prefix, mp_flag, "--syslog"}; /* With valid --syslog */ - const char *argv4[] = {prgname, prefix, mp_flag, "--syslog", "always"}; + const char *argv4[] = {prgname, prefix, mp_flag, "--syslog=both"}; /* With invalid --syslog */ - const char *argv5[] = {prgname, prefix, mp_flag, "--syslog", "error"}; + const char *argv5[] = {prgname, prefix, mp_flag, "--syslog=invalid"}; + /* With no-sh-conf, also use no-huge to ensure this test runs on BSD */ const char *argv6[] = {prgname, "-m", DEFAULT_MEM_SIZE, no_shconf, nosh_prefix, no_huge}; diff --git a/doc/guides/linux_gsg/linux_eal_parameters.rst b/doc/guides/linux_gsg/linux_eal_parameters.rst index ea8f381391..d86f94d8a8 100644 --- a/doc/guides/linux_gsg/linux_eal_parameters.rst +++ b/doc/guides/linux_gsg/linux_eal_parameters.rst @@ -108,30 +108,3 @@ Memory-related options * ``--match-allocations`` Free hugepages back to system exactly as they were originally allocated. - -Other options -~~~~~~~~~~~~~ - -* ``--syslog `` - - Set syslog facility. Valid syslog facilities are:: - - auth - cron - daemon - ftp - kern - lpr - mail - news - syslog - user - uucp - local0 - local1 - local2 - local3 - local4 - local5 - local6 - local7 diff --git a/doc/guides/prog_guide/log_lib.rst b/doc/guides/prog_guide/log_lib.rst index 504eefe1d2..abaedc7212 100644 --- a/doc/guides/prog_guide/log_lib.rst +++ b/doc/guides/prog_guide/log_lib.rst @@ -83,6 +83,23 @@ To prefix all console messages with ISO format time the syntax is:: /path/to/app --log-timestamp=iso +Log output +~~~~~~~~~~ + +If desired, messages can be redirected to syslog (on Linux and FreeBSD) with the ``--syslog`` +option. There are three possible settings for this option: + +*always* + Redirect all log output to syslog. + +*auto* + Use console if it is a terminal, and use syslog if is not. + +*both* + Print to both console and syslog. + +If ``--syslog`` option is not specified, then only console (stderr) will be used. + Using Logging APIs to Generate Log Messages diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index 5173835c2c..9ca7db04aa 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -91,7 +91,7 @@ eal_long_options[] = { {OPT_PROC_TYPE, 1, NULL, OPT_PROC_TYPE_NUM }, {OPT_SOCKET_MEM, 1, NULL, OPT_SOCKET_MEM_NUM }, {OPT_SOCKET_LIMIT, 1, NULL, OPT_SOCKET_LIMIT_NUM }, - {OPT_SYSLOG, 1, NULL, OPT_SYSLOG_NUM }, + {OPT_SYSLOG, 2, NULL, OPT_SYSLOG_NUM }, {OPT_VDEV, 1, NULL, OPT_VDEV_NUM }, {OPT_VFIO_INTR, 1, NULL, OPT_VFIO_INTR_NUM }, {OPT_VFIO_VF_TOKEN, 1, NULL, OPT_VFIO_VF_TOKEN_NUM }, @@ -2221,6 +2221,9 @@ eal_common_usage(void) " (can be used multiple times)\n" " --"OPT_VMWARE_TSC_MAP" Use VMware TSC map instead of native RDTSC\n" " --"OPT_PROC_TYPE" Type of this process (primary|secondary|auto)\n" +#ifndef RTE_EXEC_ENV_WINDOWS + " --"OPT_SYSLOG"[=] Enable use of syslog\n" +#endif " --"OPT_LOG_LEVEL"= Set global log level\n" " --"OPT_LOG_LEVEL"=:\n" " Set specific log level\n" diff --git a/lib/log/log.c b/lib/log/log.c index 71db4894fa..4430b251a1 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,19 +497,21 @@ 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) { +#ifdef RTE_EXEC_ENV_WINDOWS + RTE_SET_USED(id); +#else + bool is_terminal = isatty(STDERR_FILENO); + + if (log_syslog_enabled(is_terminal)) + log_syslog_open(id, is_terminal); + else +#endif if (log_timestamp_enabled()) rte_logs.print_func = log_print_with_timestamp; else diff --git a/lib/log/log_private.h b/lib/log/log_private.h index 67cfe72fc6..c4eb533529 100644 --- a/lib/log/log_private.h +++ b/lib/log/log_private.h @@ -17,4 +17,8 @@ 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); +bool log_syslog_enabled(bool is_tty); +void log_syslog_open(const char *id, bool is_terminal); + + #endif /* LOG_PRIVATE_H */ diff --git a/lib/log/log_stubs.c b/lib/log/log_stubs.c new file mode 100644 index 0000000000..cb34217af8 --- /dev/null +++ b/lib/log/log_stubs.c @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2010-2014 Intel Corporation + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "log_internal.h" +#include "log_private.h" + +/* Stubs for Windows */ +int +eal_log_syslog(const char *str __rte_unused) +{ + return -1; +} diff --git a/lib/log/log_syslog.c b/lib/log/log_syslog.c new file mode 100644 index 0000000000..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..37507299e7 100644 --- a/lib/log/meson.build +++ b/lib/log/meson.build @@ -7,4 +7,10 @@ sources = files( 'log_timestamp.c', ) +if is_windows + sources += files('log_stubs.c') +else + sources += files('log_syslog.c') +endif + headers = files('rte_log.h') From patchwork Sat Mar 30 16:42:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 139009 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 A05A643D85; Sat, 30 Mar 2024 17:46:19 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B4F35410FD; Sat, 30 Mar 2024 17:45:06 +0100 (CET) Received: from mail-oo1-f52.google.com (mail-oo1-f52.google.com [209.85.161.52]) by mails.dpdk.org (Postfix) with ESMTP id 6447440685 for ; Sat, 30 Mar 2024 17:44:55 +0100 (CET) Received: by mail-oo1-f52.google.com with SMTP id 006d021491bc7-5a4817189c8so1869123eaf.1 for ; Sat, 30 Mar 2024 09:44:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711817095; x=1712421895; 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=qnJoWRHGkmu0fB4v4JIaAm7TBXfGnR77iGxZMj9UVUc=; b=cO3c4HmfU0rfLYTtjNnS7nQdAl/J03iPz3kNPQ+LLNnprmbIAmYqUfG+1pm89pxT3/ l78F2u7s2SUnU4Ncmkp0nTWzHOeFodyBFlRFBXoJqpt/KOQ533XaG655S7K6uTA504B8 gKj2GylXqQ2uLlV7cr9c5MSXLcPHevZ+MX3s1mCrZlNnlj2+qJXk30QkllMU2SCvaFvS IkWwBjmYYIzcL4Y+yCW31lKs8isCvwksx05KgJNgd2sOhbQK76A/o9iYESzXZQik7iFc a6+xEHskIIzsfQVzkiS14fD/e9V4aSgqymeAOZaEKNtLW/dwWSTum1v5FUv9uxi+lmdI b+XQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711817095; x=1712421895; 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=qnJoWRHGkmu0fB4v4JIaAm7TBXfGnR77iGxZMj9UVUc=; b=jta18by1gxNU2b/sQzmIR8W4zCD2/0zqHM3f9WF/tSwO3rXAYFKlmvAdohEXrytxiK hTa5jdew854pe8IU/GsJGFLXkMh+cKoX/Tf5C0pvsnCberioRSnqfPDJeGr5I/2cSXjf XkQ0EInnNcyWqBeaJL1Efr7U0EfQjeteZYA2bYW+x3YGnBbaQSHVE1b4maYorgu6BqAF WDbTlhPH9PHZCXy6pj45IE6y+XaCN6+Of47EEwmuHUp/MDa+vl8jKRBDzT14rOVDBD5k aUF/36iL2CC9S5cnyqhHPTqvoyaEEUoW2+0eeprJcjH5Z0Tc6rxIo4pYVGkPeqRgo/E3 ZYhA== X-Gm-Message-State: AOJu0YwFV6mLn0s/GaTaFsDiIFbmEMUgRZj8m2VT8jJEcQ+f25JhSWyw 8nVC3dwud171RkKGlevDExdrGNQcbCjsg/hHFUqOKyn/hMCGpISN7KOstld7YVSEpwlWLABS5zq E X-Google-Smtp-Source: AGHT+IGYYr+FAcruLjnPoMZ4gSlssLWOwAg2TZgRGl4b/tWi428azppx/QUMllsEp2VmZoYgm6Pvtw== X-Received: by 2002:a05:6358:9211:b0:17b:f03e:2bfa with SMTP id d17-20020a056358921100b0017bf03e2bfamr6429406rwb.21.1711817094657; Sat, 30 Mar 2024 09:44:54 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id by1-20020a056a02058100b005dc26144d96sm4192417pgb.75.2024.03.30.09.44.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Mar 2024 09:44:54 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v20 13/14] log: add support for systemd journal Date: Sat, 30 Mar 2024 09:42:24 -0700 Message-ID: <20240330164433.50144-14-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240330164433.50144-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240330164433.50144-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org If DPDK application is being run as a systemd service, then it can use the journal protocol which allows putting more information in the log such as priority and other information. The use of journal protocol is automatically detected and handled. Rather than having a dependency on libsystemd, just use the protocol directly as defined in: https://systemd.io/JOURNAL_NATIVE_PROTOCOL/ Signed-off-by: Stephen Hemminger --- doc/guides/prog_guide/log_lib.rst | 14 ++ lib/eal/common/eal_common_options.c | 11 ++ lib/eal/common/eal_options.h | 2 + lib/log/log.c | 5 + lib/log/log_internal.h | 3 + lib/log/log_journal.c | 200 ++++++++++++++++++++++++++++ lib/log/log_private.h | 2 + lib/log/log_stubs.c | 11 +- lib/log/meson.build | 10 +- lib/log/version.map | 1 + 10 files changed, 255 insertions(+), 4 deletions(-) create mode 100644 lib/log/log_journal.c diff --git a/doc/guides/prog_guide/log_lib.rst b/doc/guides/prog_guide/log_lib.rst index abaedc7212..476dedb097 100644 --- a/doc/guides/prog_guide/log_lib.rst +++ b/doc/guides/prog_guide/log_lib.rst @@ -100,6 +100,20 @@ option. There are three possible settings for this option: If ``--syslog`` option is not specified, then only console (stderr) will be used. +Messages can be redirected to systemd journal which is an enhanced version of syslog with the ``--log-journal`` option. + +There are three possible settings for this option: + +*auto* + If stderr is redirected to journal by ``systemd`` service + then use journal socket to instead of stderr for log. + This is the default. + +*never* + Do not try to use journal. + +*always* + Always try to direct messages to journal socket. Using Logging APIs to Generate Log Messages diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index 9ca7db04aa..9a82118184 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -74,6 +74,7 @@ eal_long_options[] = { {OPT_IOVA_MODE, 1, NULL, OPT_IOVA_MODE_NUM }, {OPT_LCORES, 1, NULL, OPT_LCORES_NUM }, {OPT_LOG_LEVEL, 1, NULL, OPT_LOG_LEVEL_NUM }, + {OPT_LOG_JOURNAL, 2, NULL, OPT_LOG_JOURNAL_NUM }, {OPT_LOG_TIMESTAMP, 2, NULL, OPT_LOG_TIMESTAMP_NUM }, {OPT_TRACE, 1, NULL, OPT_TRACE_NUM }, {OPT_TRACE_DIR, 1, NULL, OPT_TRACE_DIR_NUM }, @@ -1617,6 +1618,7 @@ eal_log_level_parse(int argc, char * const argv[]) switch (opt) { case OPT_LOG_LEVEL_NUM: case OPT_SYSLOG_NUM: + case OPT_LOG_JOURNAL_NUM: case OPT_LOG_TIMESTAMP_NUM: if (eal_parse_common_option(opt, optarg, internal_conf) < 0) return -1; @@ -1843,6 +1845,14 @@ eal_parse_common_option(int opt, const char *optarg, return -1; } break; + + case OPT_LOG_JOURNAL_NUM: + if (eal_log_journal(optarg) < 0) { + EAL_LOG(ERR, "invalid parameters for --" + OPT_LOG_JOURNAL); + return -1; + } + break; #endif case OPT_LOG_LEVEL_NUM: @@ -2223,6 +2233,7 @@ eal_common_usage(void) " --"OPT_PROC_TYPE" Type of this process (primary|secondary|auto)\n" #ifndef RTE_EXEC_ENV_WINDOWS " --"OPT_SYSLOG"[=] Enable use of syslog\n" + " --"OPT_LOG_JOURNAL"[=] Enable use of systemd journal\n" #endif " --"OPT_LOG_LEVEL"= Set global log level\n" " --"OPT_LOG_LEVEL"=:\n" diff --git a/lib/eal/common/eal_options.h b/lib/eal/common/eal_options.h index e24c9eca53..c5a1c70288 100644 --- a/lib/eal/common/eal_options.h +++ b/lib/eal/common/eal_options.h @@ -35,6 +35,8 @@ enum { OPT_LCORES_NUM, #define OPT_LOG_LEVEL "log-level" OPT_LOG_LEVEL_NUM, +#define OPT_LOG_JOURNAL "log-journal" + OPT_LOG_JOURNAL_NUM, #define OPT_LOG_TIMESTAMP "log-timestamp" OPT_LOG_TIMESTAMP_NUM, #define OPT_TRACE "trace" diff --git a/lib/log/log.c b/lib/log/log.c index 4430b251a1..13d68402d9 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -508,6 +508,11 @@ eal_log_init(const char *id) #else bool is_terminal = isatty(STDERR_FILENO); +#ifdef RTE_EXEC_ENV_LINUX + if (log_journal_enabled()) + log_journal_open(id); + else +#endif if (log_syslog_enabled(is_terminal)) log_syslog_open(id, is_terminal); else diff --git a/lib/log/log_internal.h b/lib/log/log_internal.h index 7c7d44eed2..82fdc21ac2 100644 --- a/lib/log/log_internal.h +++ b/lib/log/log_internal.h @@ -29,6 +29,9 @@ int eal_log_save_pattern(const char *pattern, uint32_t level); __rte_internal int eal_log_syslog(const char *name); +__rte_internal +int eal_log_journal(const char *opt); + /* * Convert log level to string. */ diff --git a/lib/log/log_journal.c b/lib/log/log_journal.c new file mode 100644 index 0000000000..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 c4eb533529..91976ab313 100644 --- a/lib/log/log_private.h +++ b/lib/log/log_private.h @@ -20,5 +20,7 @@ int log_print_with_timestamp(FILE *f, const char *format, va_list ap); bool log_syslog_enabled(bool is_tty); void log_syslog_open(const char *id, bool is_terminal); +bool log_journal_enabled(void); +void log_journal_open(const char *id); #endif /* LOG_PRIVATE_H */ diff --git a/lib/log/log_stubs.c b/lib/log/log_stubs.c index cb34217af8..6b2099f57b 100644 --- a/lib/log/log_stubs.c +++ b/lib/log/log_stubs.c @@ -20,9 +20,18 @@ #include "log_internal.h" #include "log_private.h" -/* Stubs for Windows */ +#ifdef RTE_EXEC_ENV_WINDOWS int eal_log_syslog(const char *str __rte_unused) { return -1; } +#endif + +#ifndef RTE_EXEC_ENV_LINUX +int +eal_log_journal(const char *str __rte_unused) +{ + return -1; +} +#endif diff --git a/lib/log/meson.build b/lib/log/meson.build index 37507299e7..0a80027326 100644 --- a/lib/log/meson.build +++ b/lib/log/meson.build @@ -7,10 +7,14 @@ sources = files( 'log_timestamp.c', ) -if is_windows - sources += files('log_stubs.c') -else +if not is_windows sources += files('log_syslog.c') endif +if is_linux + sources += files('log_journal.c') +else + sources += files('log_stubs.c') +endif + headers = files('rte_log.h') diff --git a/lib/log/version.map b/lib/log/version.map index 14d6681a5f..7af97ece43 100644 --- a/lib/log/version.map +++ b/lib/log/version.map @@ -26,6 +26,7 @@ INTERNAL { global: eal_log_init; + eal_log_journal; eal_log_level2str; eal_log_save_pattern; eal_log_save_regexp; From patchwork Sat Mar 30 16:42:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 139010 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 29EDF43D85; Sat, 30 Mar 2024 17:46:26 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2AC6B41148; Sat, 30 Mar 2024 17:45:08 +0100 (CET) Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by mails.dpdk.org (Postfix) with ESMTP id 4E9E640689 for ; Sat, 30 Mar 2024 17:44:56 +0100 (CET) Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-6ea9a605ca7so2030402b3a.0 for ; Sat, 30 Mar 2024 09:44:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711817095; x=1712421895; 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=7RX6O0wRocTiTmWMorYuwBBl7oR+i829l0UHwL0eAjY=; b=J0T8LXat5lEJ7G3gw+vsuzd++PxeGsqubbQxZLQ/UsS5Y6SeAsQ3aQHsrtAJwRGSJX HsTXq4J8EG795uhVBubombeMv+yL/0Hs6ikGniloCm+98/B79daDqL7Bl7yAGu328bnP /ELsltloA8oTUwm4WRMDK7/WLNHpE61C3WiYo8hBCE3cqgsj3hhHNeTmg9v2ruiqnf6A VhzJZ0PTmB8dTkl7HcgVtTLTxL3sact80kuYBk3fyXil6/x5ESafwDIvHAQAP/TCg1Pa BH5Cq+7YRyMTxMJxNQw7pgGIRKaCmXR34tnXKRKi0b9Mh21EXhxQ/x1g+9pJ2FKdu4jB EHQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711817095; x=1712421895; 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=7RX6O0wRocTiTmWMorYuwBBl7oR+i829l0UHwL0eAjY=; b=OGVGviDTtLnCZw2kfjtGgN1HmtcpePYfhyNss++eum//WNkoJhCukeAbAgfgvDYJ0i +tUXWIL4mmQOXm76r/UQY3CJbhjnHx3HFzMM4jQUN3r62Ev9AJJyXmY+vTwo0sSIOI41 WRRMZoS4ctt+hTQpNgfMZ8j+zc7DRjw/xlfgmxSm7QcsPpLQzp2jQVnjSyTG+s37DyZl 0iEl1v9GuYHXLHvFOrv7h20R5dpRFeOi5GcpR9Fn6IIQ9+BJql0XYbGfcRWCNjQszhWj ro/xNjmMeDvmADM2HdGzRPzaptmSxlVcFNgcyDvBG24utHYEJXEq3NfSK1FwbenQaZok Lp4w== X-Gm-Message-State: AOJu0YwyrcrmDI/3CxPudyQyAnpdUYEmcm0fp4rCCOI0STOY+8Ft4VP5 /+MN8iEoC119A6UdoTAfSBeMdwoLs+WPwDiS1PmS6LEtym5ztqbMjYCnNCnMhy+smlOKoBhv6XE + X-Google-Smtp-Source: AGHT+IHmppXbzLNDAwAkp50MhoI+UVYGtBypZplbY0KGjNXXTncLWdp+OLiYfk70M7pZgk2gwbi35Q== X-Received: by 2002:a05:6a00:2395:b0:6ea:b606:6550 with SMTP id f21-20020a056a00239500b006eab6066550mr12274372pfc.4.1711817095414; Sat, 30 Mar 2024 09:44:55 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id by1-20020a056a02058100b005dc26144d96sm4192417pgb.75.2024.03.30.09.44.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Mar 2024 09:44:55 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v20 14/14] log: colorize log output Date: Sat, 30 Mar 2024 09:42:25 -0700 Message-ID: <20240330164433.50144-15-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240330164433.50144-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240330164433.50144-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Like dmesg, colorize the log output (unless redirected to file). Timestamp is green, the subsystem is in yellow and the message is red if urgent, boldface if an error, and normal for info and debug messages. Signed-off-by: Stephen Hemminger --- app/test/test_eal_flags.c | 24 +++++ doc/guides/prog_guide/log_lib.rst | 16 ++- lib/eal/common/eal_common_options.c | 11 +++ lib/eal/common/eal_options.h | 6 +- lib/log/log.c | 24 +++-- lib/log/log_color.c | 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, 235 insertions(+), 9 deletions(-) create mode 100644 lib/log/log_color.c diff --git a/app/test/test_eal_flags.c b/app/test/test_eal_flags.c index 08f4866461..c6c05e2e1d 100644 --- a/app/test/test_eal_flags.c +++ b/app/test/test_eal_flags.c @@ -1067,6 +1067,18 @@ test_misc_flags(void) const char * const argv25[] = {prgname, prefix, mp_flag, "--log-timestamp=invalid" }; + /* Try running with --log-color */ + const char * const argv26[] = {prgname, prefix, mp_flag, + "--log-color" }; + + /* Try running with --log-color=never */ + const char * const argv27[] = {prgname, prefix, mp_flag, + "--log-color=never" }; + + /* Try running with --log-color=invalid */ + const char * const argv28[] = {prgname, prefix, mp_flag, + "--log-color=invalid" }; + /* run all tests also applicable to FreeBSD first */ @@ -1187,6 +1199,18 @@ test_misc_flags(void) printf("Error - process did run ok with --log-timestamp=invalid parameter\n"); goto fail; } + if (launch_proc(argv26) != 0) { + printf("Error - process did not run ok with --log-color parameter\n"); + goto fail; + } + if (launch_proc(argv27) != 0) { + printf("Error - process did not run ok with --log-color=none parameter\n"); + goto fail; + } + if (launch_proc(argv28) == 0) { + printf("Error - process did run ok with --log-timestamp=invalid parameter\n"); + goto fail; + } rmdir(hugepath_dir3); diff --git a/doc/guides/prog_guide/log_lib.rst b/doc/guides/prog_guide/log_lib.rst index 476dedb097..f46720fe34 100644 --- a/doc/guides/prog_guide/log_lib.rst +++ b/doc/guides/prog_guide/log_lib.rst @@ -59,6 +59,21 @@ For example:: Within an application, the same result can be got using the ``rte_log_set_level_pattern()`` or ``rte_log_set_level_regex()`` APIs. +Color output +~~~~~~~~~~~~ + +The log library will highlight important messages. +This is controlled by the ``--log-color`` option. +he optional argument ``when`` can be ``auto``, ``never``, or ``always``. +The default setting is ``auto`` which enables color when the output to +``stderr`` is a terminal. +If the ``when`` argument is omitted, it defaults to ``always``. + +For example to turn off all coloring:: + + /path/to/app --log-color=none + + Log timestamp ~~~~~~~~~~~~~ @@ -115,7 +130,6 @@ There are three possible settings for this option: *always* Always try to direct messages to journal socket. - Using Logging APIs to Generate Log Messages ------------------------------------------- diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index 9a82118184..70fdf3f5a1 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -73,6 +73,7 @@ eal_long_options[] = { {OPT_HUGE_UNLINK, 2, NULL, OPT_HUGE_UNLINK_NUM }, {OPT_IOVA_MODE, 1, NULL, OPT_IOVA_MODE_NUM }, {OPT_LCORES, 1, NULL, OPT_LCORES_NUM }, + {OPT_LOG_COLOR, 2, NULL, OPT_LOG_COLOR_NUM }, {OPT_LOG_LEVEL, 1, NULL, OPT_LOG_LEVEL_NUM }, {OPT_LOG_JOURNAL, 2, NULL, OPT_LOG_JOURNAL_NUM }, {OPT_LOG_TIMESTAMP, 2, NULL, OPT_LOG_TIMESTAMP_NUM }, @@ -1620,6 +1621,7 @@ eal_log_level_parse(int argc, char * const argv[]) case OPT_SYSLOG_NUM: case OPT_LOG_JOURNAL_NUM: case OPT_LOG_TIMESTAMP_NUM: + case OPT_LOG_COLOR_NUM: if (eal_parse_common_option(opt, optarg, internal_conf) < 0) return -1; break; @@ -1872,6 +1874,14 @@ eal_parse_common_option(int opt, const char *optarg, } break; + case OPT_LOG_COLOR_NUM: + if (eal_log_color(optarg) < 0) { + EAL_LOG(ERR, "invalid parameters for --" + OPT_LOG_COLOR); + return -1; + } + break; + #ifndef RTE_EXEC_ENV_WINDOWS case OPT_TRACE_NUM: { if (eal_trace_args_save(optarg) < 0) { @@ -2240,6 +2250,7 @@ eal_common_usage(void) " Set specific log level\n" " --"OPT_LOG_LEVEL"=help Show log types and levels\n" " --"OPT_LOG_TIMESTAMP"[=] Timestamp log output\n" + " --"OPT_LOG_COLOR"[=] Colorize log messages\n" #ifndef RTE_EXEC_ENV_WINDOWS " --"OPT_TRACE"=\n" " Enable trace based on regular expression trace name.\n" diff --git a/lib/eal/common/eal_options.h b/lib/eal/common/eal_options.h index c5a1c70288..c0686c2544 100644 --- a/lib/eal/common/eal_options.h +++ b/lib/eal/common/eal_options.h @@ -33,10 +33,12 @@ enum { OPT_HUGE_UNLINK_NUM, #define OPT_LCORES "lcores" OPT_LCORES_NUM, -#define OPT_LOG_LEVEL "log-level" - OPT_LOG_LEVEL_NUM, +#define OPT_LOG_COLOR "log-color" + OPT_LOG_COLOR_NUM, #define OPT_LOG_JOURNAL "log-journal" OPT_LOG_JOURNAL_NUM, +#define OPT_LOG_LEVEL "log-level" + OPT_LOG_LEVEL_NUM, #define OPT_LOG_TIMESTAMP "log-timestamp" OPT_LOG_TIMESTAMP_NUM, #define OPT_TRACE "trace" diff --git a/lib/log/log.c b/lib/log/log.c index 13d68402d9..856c0a0a29 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -503,10 +503,14 @@ rte_log(uint32_t level, uint32_t logtype, const char *format, ...) void eal_log_init(const char *id) { + bool is_terminal; + #ifdef RTE_EXEC_ENV_WINDOWS RTE_SET_USED(id); + + is_terminal = _isatty(_fileno(stderr)); #else - bool is_terminal = isatty(STDERR_FILENO); + is_terminal = isatty(STDERR_FILENO); #ifdef RTE_EXEC_ENV_LINUX if (log_journal_enabled()) @@ -516,11 +520,19 @@ eal_log_init(const char *id) if (log_syslog_enabled(is_terminal)) log_syslog_open(id, is_terminal); else -#endif - if (log_timestamp_enabled()) - rte_logs.print_func = log_print_with_timestamp; - else - rte_logs.print_func = vfprintf; +#endif /* RTE_EXEC_ENV_WINDOWS */ + + if (log_color_enabled(is_terminal)) { + if (log_timestamp_enabled()) + rte_logs.print_func = color_print_with_timestamp; + else + rte_logs.print_func = color_print; + } else { + if (log_timestamp_enabled()) + rte_logs.print_func = log_print_with_timestamp; + else + rte_logs.print_func = 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..897a10a342 --- /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 91976ab313..5952bfb453 100644 --- a/lib/log/log_private.h +++ b/lib/log/log_private.h @@ -23,4 +23,12 @@ void log_syslog_open(const char *id, bool is_terminal); bool log_journal_enabled(void); void log_journal_open(const char *id); +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 0a80027326..4041feed13 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 7af97ece43..eb3200dcde 100644 --- a/lib/log/version.map +++ b/lib/log/version.map @@ -25,6 +25,7 @@ DPDK_24 { INTERNAL { global: + eal_log_color; eal_log_init; eal_log_journal; eal_log_level2str;