From patchwork Tue Apr 6 13:11:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Monjalon X-Patchwork-Id: 90667 X-Patchwork-Delegate: david.marchand@redhat.com 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 53EA0A0546; Tue, 6 Apr 2021 15:11:52 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4F101140F36; Tue, 6 Apr 2021 15:11:50 +0200 (CEST) Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by mails.dpdk.org (Postfix) with ESMTP id C1EE9140F2E for ; Tue, 6 Apr 2021 15:11:48 +0200 (CEST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 4A1EC5C003E; Tue, 6 Apr 2021 09:11:48 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Tue, 06 Apr 2021 09:11:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm3; bh=m6YfMseFRrGxM nF83ZOiAKiQO5VRubjDqS8WNIz8uLg=; b=gwZHWExpcNQyjL5mBl/qm/+zH55yx 4fHdKSICVdPdHZRRnch3OSiMGwMNuyxyj+yHRpRrlRbP8DT79UOkYjoP0Lg8Dozi /HNVIfidQl90HmDgMsQ7LnEswz5Ym/Vkf8YBjFYblUIrV+3g2w+rTYARAbFOEXuH OgbYV0JERU03oxBcBH9m6mBPGs839V2y+Kois5doLvneN6qs8cW7OFfEOWPWpEKf M4bCz6XeoJRne6wcU1fYh3e7jkQMiAgBjDfQOlG5gtvoCNjaLPmysnz7XFlS87FK ovIiu7szkLmH6J49R/KjCWvZNOT5WeI7jSOdS3OwtPATsMvjzXxKhltVQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=m6YfMseFRrGxMnF83ZOiAKiQO5VRubjDqS8WNIz8uLg=; b=Eh23A7Yt 7Kyqklvc61U8WhFvQgBYrI73a+ScRoaFfGRMKfNpDcwCKFYWbRZ/Lf7BHkQvmJUa Jrwo71c4Q/zkOYFy3hPBSS0GhmrVwTE+sr6n7r6MlSGnOIdEeiThRSCLAsDTAfcf bytVzAEgZSLq/URymCiGU0aqKKBldjV8JJzrh7UGWlvIOD+FqpQtN3DaPe6UBczc impsJZo+LSpUyACS35Locu6hpDS8crqRgrmrbMLl+869QAY/7nxZuQVmBo288v74 r5wjBGf70NCNWduInt3JOyhL4cOi52eJotOfBEKHAvEmprI1cMDemN2sqQ4IBuqq jyUPvi243omngQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudejhedgtdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefvhhhomhgr shcuofhonhhjrghlohhnuceothhhohhmrghssehmohhnjhgrlhhonhdrnhgvtheqnecugg ftrfgrthhtvghrnhepvdehgfeivdejgedtveehfefhteelfefgieevgfffveefjeegtdfg uedthedtgeevnecukfhppeejjedrudefgedrvddtfedrudekgeenucevlhhushhtvghruf hiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehthhhomhgrshesmhhonhhjrghl ohhnrdhnvght X-ME-Proxy: Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id 2AC8D24005A; Tue, 6 Apr 2021 09:11:46 -0400 (EDT) From: Thomas Monjalon To: dev@dpdk.org Cc: david.marchand@redhat.com, Bruce Richardson , Andrew Rybchenko , Dmitry Kozlyuk , Narcisa Ana Maria Vasile , Dmitry Malloy , Pallavi Kadam Date: Tue, 6 Apr 2021 15:11:34 +0200 Message-Id: <20210406131137.1732110-2-thomas@monjalon.net> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210406131137.1732110-1-thomas@monjalon.net> References: <20210405193000.1113542-1-thomas@monjalon.net> <20210406131137.1732110-1-thomas@monjalon.net> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v6 1/4] log: move private functions 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 Sender: "dev" Some private log functions had a wrong "rte_" prefix. All private log functions are moved from eal_private.h to the new file eal_log.h: rte_eal_log_init -> eal_log_init rte_log_save_regexp -> eal_log_save_regexp rte_log_save_pattern -> eal_log_save_pattern eal_log_set_default The static functions in the file eal_common_log.c are renamed: rte_log_save_level -> log_save_level rte_log_lookup -> log_lookup rte_log_init -> log_init __rte_log_register -> log_register Signed-off-by: Thomas Monjalon Acked-by: Bruce Richardson Acked-by: Andrew Rybchenko Reviewed-by: David Marchand --- lib/librte_eal/common/eal_common_log.c | 28 +++++++++++---------- lib/librte_eal/common/eal_common_options.c | 5 ++-- lib/librte_eal/common/eal_log.h | 27 ++++++++++++++++++++ lib/librte_eal/common/eal_private.h | 29 ---------------------- lib/librte_eal/linux/eal.c | 3 ++- lib/librte_eal/linux/eal_log.c | 4 +-- lib/librte_eal/windows/eal.c | 3 ++- lib/librte_eal/windows/eal_log.c | 6 +++-- 8 files changed, 55 insertions(+), 50 deletions(-) create mode 100644 lib/librte_eal/common/eal_log.h diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c index c5554badb2..058fa10ffc 100644 --- a/lib/librte_eal/common/eal_common_log.c +++ b/lib/librte_eal/common/eal_common_log.c @@ -15,7 +15,7 @@ #include #include -#include "eal_private.h" +#include "eal_log.h" struct rte_log_dynamic_type { const char *name; @@ -178,8 +178,8 @@ rte_log_set_level_regexp(const char *regex, uint32_t level) * Save the type string and the loglevel for later dynamic * logtypes which may register later. */ -static int rte_log_save_level(int priority, - const char *regex, const char *pattern) +static int +log_save_level(uint32_t priority, const char *regex, const char *pattern) { struct rte_eal_opt_loglevel *opt_ll = NULL; @@ -207,9 +207,10 @@ static int rte_log_save_level(int priority, return -1; } -int rte_log_save_regexp(const char *regex, int tmp) +int +eal_log_save_regexp(const char *regex, uint32_t level) { - return rte_log_save_level(tmp, regex, NULL); + return log_save_level(level, regex, NULL); } /* set log level based on globbing pattern */ @@ -232,9 +233,10 @@ rte_log_set_level_pattern(const char *pattern, uint32_t level) return 0; } -int rte_log_save_pattern(const char *pattern, int priority) +int +eal_log_save_pattern(const char *pattern, uint32_t level) { - return rte_log_save_level(priority, NULL, pattern); + return log_save_level(level, NULL, pattern); } /* get the current loglevel for the message being processed */ @@ -250,7 +252,7 @@ int rte_log_cur_msg_logtype(void) } static int -rte_log_lookup(const char *name) +log_lookup(const char *name) { size_t i; @@ -268,7 +270,7 @@ rte_log_lookup(const char *name) * is not yet registered. */ static int -__rte_log_register(const char *name, int id) +log_register(const char *name, int id) { char *dup_name = strdup(name); @@ -288,7 +290,7 @@ rte_log_register(const char *name) struct rte_log_dynamic_type *new_dynamic_types; int id, ret; - id = rte_log_lookup(name); + id = log_lookup(name); if (id >= 0) return id; @@ -299,7 +301,7 @@ rte_log_register(const char *name) return -ENOMEM; rte_logs.dynamic_types = new_dynamic_types; - ret = __rte_log_register(name, rte_logs.dynamic_types_len); + ret = log_register(name, rte_logs.dynamic_types_len); if (ret < 0) return ret; @@ -376,7 +378,7 @@ static const struct logtype logtype_strings[] = { }; /* Logging should be first initializer (before drivers and bus) */ -RTE_INIT_PRIO(rte_log_init, LOG) +RTE_INIT_PRIO(log_init, LOG) { uint32_t i; @@ -389,7 +391,7 @@ RTE_INIT_PRIO(rte_log_init, LOG) /* register legacy log types */ for (i = 0; i < RTE_DIM(logtype_strings); i++) - __rte_log_register(logtype_strings[i].logtype, + log_register(logtype_strings[i].logtype, logtype_strings[i].log_id); rte_logs.dynamic_types_len = RTE_LOGTYPE_FIRST_EXT_ID; diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c index 622c7bc429..cd1a2856c9 100644 --- a/lib/librte_eal/common/eal_common_options.c +++ b/lib/librte_eal/common/eal_common_options.c @@ -41,6 +41,7 @@ #include "eal_options.h" #include "eal_filesystem.h" #include "eal_private.h" +#include "eal_log.h" #ifndef RTE_EXEC_ENV_WINDOWS #include "eal_trace.h" #endif @@ -1299,7 +1300,7 @@ eal_parse_log_level(const char *arg) regex, priority); goto fail; } - if (rte_log_save_regexp(regex, priority) < 0) + if (eal_log_save_regexp(regex, priority) < 0) goto fail; } else if (pattern) { if (rte_log_set_level_pattern(pattern, priority) < 0) { @@ -1307,7 +1308,7 @@ eal_parse_log_level(const char *arg) pattern, priority); goto fail; } - if (rte_log_save_pattern(pattern, priority) < 0) + if (eal_log_save_pattern(pattern, priority) < 0) goto fail; } else { rte_log_set_global_level(priority); diff --git a/lib/librte_eal/common/eal_log.h b/lib/librte_eal/common/eal_log.h new file mode 100644 index 0000000000..684650a17b --- /dev/null +++ b/lib/librte_eal/common/eal_log.h @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2021 Mellanox Technologies, Ltd + */ + +#ifndef EAL_LOG_H +#define EAL_LOG_H + +#include +#include + +/* + * Initialize the default log stream. + */ +int eal_log_init(const char *id, int facility); + +/* + * Determine where log data is written when no call to rte_openlog_stream. + */ +void eal_log_set_default(FILE *default_log); + +/* + * Save a log option for later. + */ +int eal_log_save_regexp(const char *regexp, uint32_t level); +int eal_log_save_pattern(const char *pattern, uint32_t level); + +#endif /* EAL_LOG_H */ diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h index b8a0d20021..e3512111d9 100644 --- a/lib/librte_eal/common/eal_private.h +++ b/lib/librte_eal/common/eal_private.h @@ -79,19 +79,6 @@ struct rte_config *rte_eal_get_configuration(void); */ int rte_eal_memzone_init(void); -/** - * Common log initialization function (private to eal). Determines - * where log data is written when no call to rte_openlog_stream is - * in effect. - * - * @param default_log - * The default log stream to be used. - * @return - * - 0 on success - * - Negative on error - */ -void eal_log_set_default(FILE *default_log); - /** * Fill configuration with number of physical and logical processors * @@ -143,22 +130,6 @@ int rte_eal_memory_init(void); */ int rte_eal_timer_init(void); -/** - * Init the default log stream - * - * This function is private to EAL. - * - * @return - * 0 on success, negative on error - */ -int rte_eal_log_init(const char *id, int facility); - -/** - * Save the log regexp for later - */ -int rte_log_save_regexp(const char *type, int priority); -int rte_log_save_pattern(const char *pattern, int priority); - /** * Init tail queues for non-EAL library structures. This is to allow * the rings, mempools, etc. lists to be shared among multiple processes diff --git a/lib/librte_eal/linux/eal.c b/lib/librte_eal/linux/eal.c index abbb537746..ac27dd4274 100644 --- a/lib/librte_eal/linux/eal.c +++ b/lib/librte_eal/linux/eal.c @@ -58,6 +58,7 @@ #include "eal_hugepages.h" #include "eal_memcfg.h" #include "eal_trace.h" +#include "eal_log.h" #include "eal_options.h" #include "eal_vfio.h" #include "hotplug_mp.h" @@ -1160,7 +1161,7 @@ rte_eal_init(int argc, char **argv) #endif } - if (rte_eal_log_init(logid, internal_conf->syslog_facility) < 0) { + if (eal_log_init(logid, internal_conf->syslog_facility) < 0) { rte_eal_init_alert("Cannot init logging."); rte_errno = ENOMEM; __atomic_store_n(&run_once, 0, __ATOMIC_RELAXED); diff --git a/lib/librte_eal/linux/eal_log.c b/lib/librte_eal/linux/eal_log.c index 2095df74c5..c0aa1007c4 100644 --- a/lib/librte_eal/linux/eal_log.c +++ b/lib/librte_eal/linux/eal_log.c @@ -17,7 +17,7 @@ #include #include -#include "eal_private.h" +#include "eal_log.h" /* * default log function @@ -46,7 +46,7 @@ static cookie_io_functions_t console_log_func = { * once memzones are available. */ int -rte_eal_log_init(const char *id, int facility) +eal_log_init(const char *id, int facility) { FILE *log_stream; diff --git a/lib/librte_eal/windows/eal.c b/lib/librte_eal/windows/eal.c index 2fc3d6141c..68a1fd1d21 100644 --- a/lib/librte_eal/windows/eal.c +++ b/lib/librte_eal/windows/eal.c @@ -22,6 +22,7 @@ #include "eal_hugepages.h" #include "eal_trace.h" +#include "eal_log.h" #include "eal_windows.h" #define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL) @@ -267,7 +268,7 @@ rte_eal_init(int argc, char **argv) eal_get_internal_configuration(); int ret; - rte_eal_log_init(NULL, 0); + eal_log_init(NULL, 0); eal_log_level_parse(argc, argv); diff --git a/lib/librte_eal/windows/eal_log.c b/lib/librte_eal/windows/eal_log.c index 875981f139..d4ea47f1c8 100644 --- a/lib/librte_eal/windows/eal_log.c +++ b/lib/librte_eal/windows/eal_log.c @@ -2,11 +2,13 @@ * Copyright(c) 2017-2018 Intel Corporation */ -#include "eal_private.h" +#include +#include +#include "eal_log.h" /* set the log to default function, called during eal init process. */ int -rte_eal_log_init(__rte_unused const char *id, __rte_unused int facility) +eal_log_init(__rte_unused const char *id, __rte_unused int facility) { rte_openlog_stream(stderr); From patchwork Tue Apr 6 13:11:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Monjalon X-Patchwork-Id: 90668 X-Patchwork-Delegate: david.marchand@redhat.com 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 E64BEA0546; Tue, 6 Apr 2021 15:11:59 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 764CD140F40; Tue, 6 Apr 2021 15:11:52 +0200 (CEST) Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by mails.dpdk.org (Postfix) with ESMTP id 8BE5C140F3A for ; Tue, 6 Apr 2021 15:11:50 +0200 (CEST) Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 2D34B5C0102; Tue, 6 Apr 2021 09:11:50 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Tue, 06 Apr 2021 09:11:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm3; bh=zLVkjlbOx1yDl 7HkZUPrSdhfQlS89ly4MKFlZ+gnceo=; b=E3SIpdgKgpH3eOzUnRs2Qm+3RjAYD BNFQK3olJyByEyh4X61Ypcy/QMAuYr9JFP9IteJPpKCGQuYGdRW+GC7pZmNXwKh8 VyLUvyZ4KCPDlGovehY4hVVkqymCbFPeQpRLUR9TaJHyKjxu8kQHarlH5ooqEUnz gEe0ur7kaWYg/QGiwJrHWHwpsS8GKe52auCcMeigfAZeERYuq0LjCX9woLl0TPM1 o9zmwcTV8vWkJ+N061r+ixaNbBUixqDLZYxdnJ/TWBx1PjW1iefJA7PmACbnJW+j YwPnNiItujfHt2aEL7B/nFAN9fM+wxzUPtxuco5/xdkyuQBGwVPnf9eiQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=zLVkjlbOx1yDl7HkZUPrSdhfQlS89ly4MKFlZ+gnceo=; b=oVWQ14jH QGkCkQ3y1wDrxYcISpsR41AusHPIXpCU/VnRym652ZOGJLAXyRdkOMA04rnBBKKt MpsGMcZ18leQmAa370EzhwxlFV7ixHuCD9Bw/8RTmYTZ49+qBIF0Xzq0vEZ8vYTL S3XLV/mo8Q3VJI0sez9s4FaeQ7T2cEicFoUvuGPCTlGGNPdjc+VTqbssxhq7AF4N V2Ronu7tLB91j8Gf9s8yr466uZx9HRbuG5HGmJ8jLLmK3crrBMKImZTJZfeDoMDR cOwxKgoYD19zGg31g0zW4BLteRFQlaGDrwCBASfGOTx6iwEYZsfPgll89xnKStr0 oKlOb6xsvDzVfw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudejhedgtdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefvhhhomhgr shcuofhonhhjrghlohhnuceothhhohhmrghssehmohhnjhgrlhhonhdrnhgvtheqnecugg ftrfgrthhtvghrnhepvdehgfeivdejgedtveehfefhteelfefgieevgfffveefjeegtdfg uedthedtgeevnecukfhppeejjedrudefgedrvddtfedrudekgeenucevlhhushhtvghruf hiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehthhhomhgrshesmhhonhhjrghl ohhnrdhnvght X-ME-Proxy: Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id 096E624005A; Tue, 6 Apr 2021 09:11:48 -0400 (EDT) From: Thomas Monjalon To: dev@dpdk.org Cc: david.marchand@redhat.com, Bruce Richardson , Andrew Rybchenko Date: Tue, 6 Apr 2021 15:11:35 +0200 Message-Id: <20210406131137.1732110-3-thomas@monjalon.net> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210406131137.1732110-1-thomas@monjalon.net> References: <20210405193000.1113542-1-thomas@monjalon.net> <20210406131137.1732110-1-thomas@monjalon.net> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v6 2/4] log: introduce macro for maximum level 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 Sender: "dev" RTE_DIM(...) and RTE_LOG_DEBUG were used to get the highest log level. For better clarity a new constant RTE_LOG_MAX is introduced and mapped to RTE_LOG_DEBUG. Signed-off-by: Thomas Monjalon Acked-by: Bruce Richardson Acked-by: Andrew Rybchenko Reviewed-by: David Marchand --- lib/librte_eal/common/eal_common_log.c | 8 ++++---- lib/librte_eal/common/eal_common_options.c | 2 +- lib/librte_eal/include/rte_log.h | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c index 058fa10ffc..b9b982fdb5 100644 --- a/lib/librte_eal/common/eal_common_log.c +++ b/lib/librte_eal/common/eal_common_log.c @@ -140,7 +140,7 @@ rte_log_set_level(uint32_t type, uint32_t level) { if (type >= rte_logs.dynamic_types_len) return -1; - if (level > RTE_LOG_DEBUG) + if (level > RTE_LOG_MAX) return -1; rte_logs.dynamic_types[type].loglevel = level; @@ -155,7 +155,7 @@ rte_log_set_level_regexp(const char *regex, uint32_t level) regex_t r; size_t i; - if (level > RTE_LOG_DEBUG) + if (level > RTE_LOG_MAX) return -1; if (regcomp(&r, regex, 0) != 0) @@ -219,7 +219,7 @@ rte_log_set_level_pattern(const char *pattern, uint32_t level) { size_t i; - if (level > RTE_LOG_DEBUG) + if (level > RTE_LOG_MAX) return -1; for (i = 0; i < rte_logs.dynamic_types_len; i++) { @@ -323,7 +323,7 @@ rte_log_register_type_and_pick_level(const char *name, uint32_t level_def) return type; TAILQ_FOREACH(opt_ll, &opt_loglevel_list, next) { - if (opt_ll->level > RTE_LOG_DEBUG) + if (opt_ll->level > RTE_LOG_MAX) continue; if (opt_ll->pattern) { diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c index cd1a2856c9..38b72fb665 100644 --- a/lib/librte_eal/common/eal_common_options.c +++ b/lib/librte_eal/common/eal_common_options.c @@ -1249,7 +1249,7 @@ eal_parse_log_priority(const char *level) return -1; /* look for named values, skip 0 which is not a valid level */ - for (i = 1; i < RTE_DIM(levels); i++) { + for (i = 1; i <= RTE_LOG_MAX; i++) { if (strncmp(levels[i], level, len) == 0) return i; } diff --git a/lib/librte_eal/include/rte_log.h b/lib/librte_eal/include/rte_log.h index 21a7d16340..424dfa3fd0 100644 --- a/lib/librte_eal/include/rte_log.h +++ b/lib/librte_eal/include/rte_log.h @@ -72,6 +72,7 @@ extern "C" { #define RTE_LOG_NOTICE 6U /**< Normal but significant condition. */ #define RTE_LOG_INFO 7U /**< Informational. */ #define RTE_LOG_DEBUG 8U /**< Debug-level messages. */ +#define RTE_LOG_MAX RTE_LOG_DEBUG /**< Most detailed log level. */ /** * Change the stream that will be used by the logging system. From patchwork Tue Apr 6 13:11:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Monjalon X-Patchwork-Id: 90669 X-Patchwork-Delegate: david.marchand@redhat.com 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 C2258A0546; Tue, 6 Apr 2021 15:12:06 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A3DE4140F5D; Tue, 6 Apr 2021 15:11:54 +0200 (CEST) Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by mails.dpdk.org (Postfix) with ESMTP id D5017140F3E for ; Tue, 6 Apr 2021 15:11:51 +0200 (CEST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 7EAD95C009F; Tue, 6 Apr 2021 09:11:51 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Tue, 06 Apr 2021 09:11:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm3; bh=zQz8ZcofkXN67 fgoxI9rvLy38vrHic5K38f7t1jD3U8=; b=VTpKRPVlIczBiONGXytu0PMDroozg sIYmXqL/CTZF59Sx/tU7v43+mNSvyTlhpajXI0MhqqiZYy1P+yCKPYZg4Fex9BXM jbh5Llixl+iEJHqvKQZqFBPAWcamAA8mKaHLz9CDwdOx2NjXhP6t15YqUxmGiVB5 SuuSWoW3/kguOGuk/N3GGu2cqXzz1z7d0RQX1gAKUUzAGKdBPgNUWnGDXj601uKb WK692/dhdPuHBp86hEuCPdM06+5h2XKFJeKmc8ObEo7MAk5qSXD0tg0waKXvilLG 34hspVjSq1G/xmy4bPy6lwMVCq3onGlyeQnLgMhDZ1l5dJ9zM8fb85+fA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=zQz8ZcofkXN67fgoxI9rvLy38vrHic5K38f7t1jD3U8=; b=F0KH9Bnq q6WzCQln+WRfnSzLga6sjW5VXGQzy52WEWHLKExDNbia1MQ1IidkMf+pMeTi8bkp M/ghsVlRWIs4vGlm2RcvTVbyPaPHhrP4YyWjQ6yHZRjNJHAPv6Bi7RSN5a3gkJ1h W9GtMwcdwvCBSm7FK4kAgHD1X2KQ4ImTTJuzdP+VEOrtXERnYc8Bc9/u/jVCkrnX ptuUeKVF7JkoJMoNDueBgXnYvSrPxLskN7XXA7HL2e0m0lou4828f+HEnLLtAu+v eMiWUe+2Bw0WaXJbyk6Uu5MqaSLpMO8vYHpBtA8YK/+ZYFYcfN656X2NQbZdMA68 YVH66OA5lYe50w== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudejhedgtdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefvhhhomhgr shcuofhonhhjrghlohhnuceothhhohhmrghssehmohhnjhgrlhhonhdrnhgvtheqnecugg ftrfgrthhtvghrnhepvdehgfeivdejgedtveehfefhteelfefgieevgfffveefjeegtdfg uedthedtgeevnecukfhppeejjedrudefgedrvddtfedrudekgeenucevlhhushhtvghruf hiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehthhhomhgrshesmhhonhhjrghl ohhnrdhnvght X-ME-Proxy: Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id C87B724005C; Tue, 6 Apr 2021 09:11:50 -0400 (EDT) From: Thomas Monjalon To: dev@dpdk.org Cc: david.marchand@redhat.com, Bruce Richardson , Andrew Rybchenko Date: Tue, 6 Apr 2021 15:11:36 +0200 Message-Id: <20210406131137.1732110-4-thomas@monjalon.net> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210406131137.1732110-1-thomas@monjalon.net> References: <20210405193000.1113542-1-thomas@monjalon.net> <20210406131137.1732110-1-thomas@monjalon.net> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v6 3/4] log: catch invalid level option number 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 Sender: "dev" The parsing check for invalid log level was not trying to catch irrelevant numeric values. A log level 0 becomes a failure in parsing so it can be caught early. A log level higher than the max (8) is accepted with a warning message. Signed-off-by: Thomas Monjalon Acked-by: Bruce Richardson Acked-by: Andrew Rybchenko Reviewed-by: David Marchand --- lib/librte_eal/common/eal_common_options.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c index 38b72fb665..7075a051b8 100644 --- a/lib/librte_eal/common/eal_common_options.c +++ b/lib/librte_eal/common/eal_common_options.c @@ -1289,10 +1289,15 @@ eal_parse_log_level(const char *arg) } priority = eal_parse_log_priority(level); - if (priority < 0) { - fprintf(stderr, "invalid log priority: %s\n", level); + if (priority <= 0) { + fprintf(stderr, "Invalid log level: %s\n", level); goto fail; } + if (priority > (int)RTE_LOG_MAX) { + fprintf(stderr, "Log level %d higher than maximum (%d)\n", + priority, RTE_LOG_MAX); + priority = RTE_LOG_MAX; + } if (regex) { if (rte_log_set_level_regexp(regex, priority) < 0) { From patchwork Tue Apr 6 13:11:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Monjalon X-Patchwork-Id: 90670 X-Patchwork-Delegate: david.marchand@redhat.com 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 EB472A0546; Tue, 6 Apr 2021 15:12:14 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2D92C140F74; Tue, 6 Apr 2021 15:11:56 +0200 (CEST) Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by mails.dpdk.org (Postfix) with ESMTP id 964F4140F50 for ; Tue, 6 Apr 2021 15:11:54 +0200 (CEST) Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 406455C00CE; Tue, 6 Apr 2021 09:11:54 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Tue, 06 Apr 2021 09:11:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm3; bh=uIvL+0w/mmmGq lgwm4LGyM4G/54P53GXnzWLHDgIuf0=; b=ag8UQ+okeBw4nJk1X4q3UIXeqjkTL +jhw4nybHSZC4KUF7RCmo4h5yQ0CxoNxbT05SIB3jti9zqcPdymrU2QPr3Cp6jiy tWci5DnKT9xdbhxUfJuElT76wPwXM1OrMz3Tjwf2bZBkvlqLuraL31/30ZYVs4tA KmBEo4gpogxbpyowS6BbfMUDvnVS3g3OLPM7++sqgEwIr/1/YfYGMJ+d0KF4Rorh SBr5Eg4DSd1l7GqxFsNoUEkT2mn6q2B58+9pyCsBhVFpyp+FGNa40wEqfFv4KKxN nIvA8ugYZOjwadojTu/kstTXLu5bfsyNNZGiZAxYIo3R4Ci5srliwm6kg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=uIvL+0w/mmmGqlgwm4LGyM4G/54P53GXnzWLHDgIuf0=; b=AhFNXx4y GqoKG3PEAFIYO/DyysIambyKJROD8czOPOr0Jp/TzWfMgy29PvcbjPN7hc6pKqH8 W0jIvI5NsbaZl9/PPQiHor4sCi+oQ/+py+5xk0XfwjJa5FwHsskuev16S3IcA6mh WPbt02LTBfgY9Y6/xDz9Mr3XKk8tYAs8m936EHlvl3vuM6Lic23KYKMJ3iNyML2K jV86YU6+TjMVjOTcQQbmGJXH7u/yMV9NFQL6+8aKWeLDjgxeWJqjC2HB8ucCQXTZ DnxgMMuRtVVVcocd+ciQQkMjeDSACuFJuKN/I5tFJQZ+qD99+chk964SyTAJ33Wk zxPeva/ysuAa9g== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudejhedgtdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefvhhhomhgr shcuofhonhhjrghlohhnuceothhhohhmrghssehmohhnjhgrlhhonhdrnhgvtheqnecugg ftrfgrthhtvghrnhepvdehgfeivdejgedtveehfefhteelfefgieevgfffveefjeegtdfg uedthedtgeevnecukfhppeejjedrudefgedrvddtfedrudekgeenucevlhhushhtvghruf hiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehthhhomhgrshesmhhonhhjrghl ohhnrdhnvght X-ME-Proxy: Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id EB612240065; Tue, 6 Apr 2021 09:11:52 -0400 (EDT) From: Thomas Monjalon To: dev@dpdk.org Cc: david.marchand@redhat.com, Bruce Richardson , Andrew Rybchenko , Ray Kinsella , Neil Horman Date: Tue, 6 Apr 2021 15:11:37 +0200 Message-Id: <20210406131137.1732110-5-thomas@monjalon.net> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210406131137.1732110-1-thomas@monjalon.net> References: <20210405193000.1113542-1-thomas@monjalon.net> <20210406131137.1732110-1-thomas@monjalon.net> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v6 4/4] log: add option argument help 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 Sender: "dev" The option --log-level was not completely described in the usage text, and it was difficult to guess the names of the log types and levels. A new value "help" is accepted after --log-level to give more details about the syntax and listing the log types and levels. The array "levels" used for level name parsing is replaced with a (modified) existing function which was used in rte_log_dump(). The new function rte_log_list_types() is exported in the API for allowing an application to give this info to the user if not exposing the EAL option --log-level. The list of log types cannot include all drivers if not linked in the application (shared object plugin case). Signed-off-by: Thomas Monjalon Acked-by: Bruce Richardson Acked-by: Andrew Rybchenko --- lib/librte_eal/common/eal_common_log.c | 51 +++++++++++++++++++--- lib/librte_eal/common/eal_common_options.c | 44 +++++++++++++------ lib/librte_eal/common/eal_log.h | 5 +++ lib/librte_eal/include/rte_log.h | 11 +++++ lib/librte_eal/version.map | 1 + 5 files changed, 94 insertions(+), 18 deletions(-) diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c index b9b982fdb5..4c6766a360 100644 --- a/lib/librte_eal/common/eal_common_log.c +++ b/lib/librte_eal/common/eal_common_log.c @@ -397,12 +397,12 @@ RTE_INIT_PRIO(log_init, LOG) rte_logs.dynamic_types_len = RTE_LOGTYPE_FIRST_EXT_ID; } -static const char * -loglevel_to_string(uint32_t level) +const char * +eal_log_level2str(uint32_t level) { switch (level) { case 0: return "disabled"; - case RTE_LOG_EMERG: return "emerg"; + case RTE_LOG_EMERG: return "emergency"; case RTE_LOG_ALERT: return "alert"; case RTE_LOG_CRIT: return "critical"; case RTE_LOG_ERR: return "error"; @@ -414,6 +414,47 @@ loglevel_to_string(uint32_t level) } } +static int +log_type_compare(const void *a, const void *b) +{ + const struct rte_log_dynamic_type *type_a = a; + const struct rte_log_dynamic_type *type_b = b; + + if (type_a->name == NULL && type_b->name == NULL) + return 0; + if (type_a->name == NULL) + return -1; + if (type_b->name == NULL) + return 1; + return strcmp(type_a->name, type_b->name); +} + +/* Dump name of each logtype, one per line. */ +void +rte_log_list_types(FILE *out, const char *prefix) +{ + struct rte_log_dynamic_type *sorted_types; + const size_t type_size = sizeof(rte_logs.dynamic_types[0]); + const size_t type_count = rte_logs.dynamic_types_len; + const size_t total_size = type_size * type_count; + size_t type; + + sorted_types = malloc(total_size); + if (sorted_types == NULL) { + /* no sorting - unlikely */ + sorted_types = rte_logs.dynamic_types; + } else { + memcpy(sorted_types, rte_logs.dynamic_types, total_size); + qsort(sorted_types, type_count, type_size, log_type_compare); + } + + for (type = 0; type < type_count; ++type) { + if (sorted_types[type].name == NULL) + continue; + fprintf(out, "%s%s\n", prefix, sorted_types[type].name); + } +} + /* dump global level and registered log types */ void rte_log_dump(FILE *f) @@ -421,14 +462,14 @@ rte_log_dump(FILE *f) size_t i; fprintf(f, "global log level is %s\n", - loglevel_to_string(rte_log_get_global_level())); + eal_log_level2str(rte_log_get_global_level())); for (i = 0; i < rte_logs.dynamic_types_len; i++) { if (rte_logs.dynamic_types[i].name == NULL) continue; fprintf(f, "id %zu: %s, level is %s\n", i, rte_logs.dynamic_types[i].name, - loglevel_to_string(rte_logs.dynamic_types[i].loglevel)); + eal_log_level2str(rte_logs.dynamic_types[i].loglevel)); } } diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c index 7075a051b8..2951b1aca2 100644 --- a/lib/librte_eal/common/eal_common_options.c +++ b/lib/librte_eal/common/eal_common_options.c @@ -1227,19 +1227,31 @@ eal_parse_syslog(const char *facility, struct internal_config *conf) } #endif +static void +eal_log_usage(void) +{ + unsigned int level; + + printf("Log type is a pattern matching items of this list" + " (plugins may be missing):\n"); + rte_log_list_types(stdout, "\t"); + printf("\n"); + printf("Syntax using globbing pattern: "); + printf("--"OPT_LOG_LEVEL" pattern:level\n"); + printf("Syntax using regular expression: "); + printf("--"OPT_LOG_LEVEL" regexp,level\n"); + printf("Syntax for the global level: "); + printf("--"OPT_LOG_LEVEL" level\n"); + printf("Logs are emitted if allowed by both global and specific levels.\n"); + printf("\n"); + printf("Log level can be a number or the first letters of its name:\n"); + for (level = 1; level <= RTE_LOG_MAX; level++) + printf("\t%d %s\n", level, eal_log_level2str(level)); +} + static int eal_parse_log_priority(const char *level) { - static const char * const levels[] = { - [RTE_LOG_EMERG] = "emergency", - [RTE_LOG_ALERT] = "alert", - [RTE_LOG_CRIT] = "critical", - [RTE_LOG_ERR] = "error", - [RTE_LOG_WARNING] = "warning", - [RTE_LOG_NOTICE] = "notice", - [RTE_LOG_INFO] = "info", - [RTE_LOG_DEBUG] = "debug", - }; size_t len = strlen(level); unsigned long tmp; char *end; @@ -1250,7 +1262,7 @@ eal_parse_log_priority(const char *level) /* look for named values, skip 0 which is not a valid level */ for (i = 1; i <= RTE_LOG_MAX; i++) { - if (strncmp(levels[i], level, len) == 0) + if (strncmp(eal_log_level2str(i), level, len) == 0) return i; } @@ -1274,6 +1286,11 @@ eal_parse_log_level(const char *arg) char *str, *level; int priority; + if (strcmp(arg, "help") == 0) { + eal_log_usage(); + exit(EXIT_SUCCESS); + } + str = strdup(arg); if (str == NULL) return -1; @@ -2068,9 +2085,10 @@ eal_common_usage(void) #ifndef RTE_EXEC_ENV_WINDOWS " --"OPT_SYSLOG" Set syslog facility\n" #endif - " --"OPT_LOG_LEVEL"= Set global log level\n" - " --"OPT_LOG_LEVEL"=:\n" + " --"OPT_LOG_LEVEL"= Set global log level\n" + " --"OPT_LOG_LEVEL"=:\n" " Set specific log level\n" + " --"OPT_LOG_LEVEL"=help Show log types and levels\n" #ifndef RTE_EXEC_ENV_WINDOWS " --"OPT_TRACE"=\n" " Enable trace based on regular expression trace name.\n" diff --git a/lib/librte_eal/common/eal_log.h b/lib/librte_eal/common/eal_log.h index 684650a17b..c784fa6043 100644 --- a/lib/librte_eal/common/eal_log.h +++ b/lib/librte_eal/common/eal_log.h @@ -24,4 +24,9 @@ void eal_log_set_default(FILE *default_log); int eal_log_save_regexp(const char *regexp, uint32_t level); int eal_log_save_pattern(const char *pattern, uint32_t level); +/* + * Convert log level to string. + */ +const char *eal_log_level2str(uint32_t level); + #endif /* EAL_LOG_H */ diff --git a/lib/librte_eal/include/rte_log.h b/lib/librte_eal/include/rte_log.h index 424dfa3fd0..ccbb7ccd81 100644 --- a/lib/librte_eal/include/rte_log.h +++ b/lib/librte_eal/include/rte_log.h @@ -240,6 +240,17 @@ int rte_log_register(const char *name); __rte_experimental int rte_log_register_type_and_pick_level(const char *name, uint32_t level_def); +/** + * Dump name of each logtype, one per line. + * + * @param out + * Stream where the list is sent. + * @param prefix + * String preceding each logtype in the output. + */ +__rte_experimental +void rte_log_list_types(FILE *out, const char *prefix); + /** * Dump log information. * diff --git a/lib/librte_eal/version.map b/lib/librte_eal/version.map index e23745ae6e..6c14fea27b 100644 --- a/lib/librte_eal/version.map +++ b/lib/librte_eal/version.map @@ -411,6 +411,7 @@ EXPERIMENTAL { rte_power_pause; # added in 21.05 + rte_log_list_types; rte_thread_key_create; rte_thread_key_delete; rte_thread_value_get;