From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dispatch1-us1.ppe-hosted.com (dispatch1-us1.ppe-hosted.com [67.231.154.164]) by dpdk.org (Postfix) with ESMTP id 9C26A1B1D0 for ; Thu, 15 Feb 2018 12:35:56 +0100 (CET) X-Virus-Scanned: Proofpoint Essentials engine Received: from webmail.solarflare.com (webmail.solarflare.com [12.187.104.26]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1-us3.ppe-hosted.com (Proofpoint Essentials ESMTP Server) with ESMTPS id 4E0F89C0053; Thu, 15 Feb 2018 11:35:55 +0000 (UTC) Received: from sfocexch01r.SolarFlarecom.com (10.20.40.34) by ocex03.SolarFlarecom.com (10.20.40.36) with Microsoft SMTP Server (TLS) id 15.0.1044.25; Thu, 15 Feb 2018 03:35:52 -0800 Received: from ocex03.SolarFlarecom.com (10.20.40.36) by sfocexch01r.SolarFlarecom.com (10.20.40.34) with Microsoft SMTP Server (TLS) id 15.0.1044.25; Thu, 15 Feb 2018 03:35:50 -0800 Received: from opal.uk.solarflarecom.com (10.17.10.1) by ocex03.SolarFlarecom.com (10.20.40.36) with Microsoft SMTP Server (TLS) id 15.0.1044.25 via Frontend Transport; Thu, 15 Feb 2018 03:35:50 -0800 Received: from uklogin.uk.solarflarecom.com (uklogin.uk.solarflarecom.com [10.17.10.10]) by opal.uk.solarflarecom.com (8.13.8/8.13.8) with ESMTP id w1FBZnvb003376; Thu, 15 Feb 2018 11:35:49 GMT Received: from uklogin.uk.solarflarecom.com (localhost.localdomain [127.0.0.1]) by uklogin.uk.solarflarecom.com (8.13.8/8.13.8) with ESMTP id w1FBZnkk022367; Thu, 15 Feb 2018 11:35:49 GMT From: Andrew Rybchenko To: CC: Thomas Monjalon , Olivier Matz , Ivan Malov Date: Thu, 15 Feb 2018 11:35:43 +0000 Message-ID: <1518694544-22334-1-git-send-email-arybchenko@solarflare.com> X-Mailer: git-send-email 1.8.2.3 In-Reply-To: <1516899647-8541-1-git-send-email-arybchenko@solarflare.com> References: <1516899647-8541-1-git-send-email-arybchenko@solarflare.com> MIME-Version: 1.0 Content-Type: text/plain X-MDID: 1518694556-cslQ3AwHD5aA Subject: [dpdk-dev] [PATCH v2] eal: register log type and pick level from EAL args X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Feb 2018 11:35:56 -0000 From: Ivan Malov Dynamic log types are registered on RTE_INIT() step. This allows one to set log levels by EAL options on application launch. However, this does not allow to manage log types if they are created during runtime. EAL does not store log levels and types passed from the command line. Thus, they cannot be picked later. This is an obvious flaw since it would be better to be able to pick levels for dynamic types registered for runtime-determined facilities such as NIC ports. This patch provides a mechanism to store log levels passed from EAL options and adds an API to register log types and pick levels from the internal storage. Signed-off-by: Ivan Malov Signed-off-by: Andrew Rybchenko Reviewed-by: Andy Moreton --- lib/librte_eal/common/eal_common_log.c | 36 ++++++++++++++++++++++ lib/librte_eal/common/eal_common_options.c | 23 ++++++++++++++ lib/librte_eal/common/include/rte_log.h | 48 ++++++++++++++++++++++++++++++ lib/librte_eal/rte_eal_version.map | 1 + 4 files changed, 108 insertions(+) diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c index 37b2e20..a271926 100644 --- a/lib/librte_eal/common/eal_common_log.c +++ b/lib/librte_eal/common/eal_common_log.c @@ -23,6 +23,10 @@ struct rte_logs rte_logs = { .file = NULL, }; +/** Global list of valid EAL log level options */ +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; @@ -186,6 +190,38 @@ rte_log_register(const char *name) return ret; } +/* Register an extended log type and try to pick its level from EAL options */ +int __rte_experimental +rte_log_register_type_and_pick_level(const char *name, uint32_t level_def) +{ + struct rte_eal_opt_loglevel *opt_ll; + uint32_t level = level_def; + int type; + + type = rte_log_register(name); + if (type < 0) + return type; + + TAILQ_FOREACH(opt_ll, &opt_loglevel_list, next) { + regex_t r; + + if (opt_ll->level > RTE_LOG_DEBUG) + continue; + + if (regcomp(&r, opt_ll->re_type, 0) != 0) + continue; + + if (regexec(&r, name, 0, NULL, 0) == 0) + level = opt_ll->level; + + regfree(&r); + } + + rte_logs.dynamic_types[type].loglevel = level; + + return type; +} + struct logtype { uint32_t log_id; const char *logtype; diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c index 9f2f8d2..d29b85f 100644 --- a/lib/librte_eal/common/eal_common_options.c +++ b/lib/librte_eal/common/eal_common_options.c @@ -946,6 +946,29 @@ eal_parse_log_level(const char *arg) printf("cannot set log level %s,%lu\n", type, tmp); goto fail; + } else { + struct rte_eal_opt_loglevel *opt_ll; + + /* + * Save the type (regexp string) and the loglevel + * in the global storage so that it could be used + * to configure dynamic logtypes which are absent + * at the moment of EAL option processing but may + * be registered during runtime. + */ + opt_ll = malloc(sizeof(*opt_ll)); + if (opt_ll == NULL) + goto fail; + + opt_ll->re_type = strdup(type); + if (opt_ll->re_type == NULL) { + free(opt_ll); + goto fail; + } + + opt_ll->level = tmp; + + TAILQ_INSERT_HEAD(&opt_loglevel_list, opt_ll, next); } free(str); diff --git a/lib/librte_eal/common/include/rte_log.h b/lib/librte_eal/common/include/rte_log.h index 9029c78..5f4799e 100644 --- a/lib/librte_eal/common/include/rte_log.h +++ b/lib/librte_eal/common/include/rte_log.h @@ -20,6 +20,7 @@ extern "C" { #include #include #include +#include #include #include @@ -85,6 +86,32 @@ extern struct rte_logs rte_logs; #define RTE_LOG_DEBUG 8U /**< Debug-level messages. */ /** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * Entry definition for the storage to keep EAL log level options + * which are found to have log type regular expressions specified. + */ +struct rte_eal_opt_loglevel { + /** Next list entry */ + TAILQ_ENTRY(rte_eal_opt_loglevel) next; + /** Regular expression string obtained from the option */ + char *re_type; + /** Log level value obtained from the option */ + uint32_t level; +}; + +TAILQ_HEAD(rte_eal_opt_loglevel_list, rte_eal_opt_loglevel); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * Global list of EAL log level options featuring log type expressions + */ +extern struct rte_eal_opt_loglevel_list opt_loglevel_list; + +/** * Change the stream that will be used by the logging system. * * This can be done at any time. The f argument represents the stream @@ -195,6 +222,27 @@ int rte_log_cur_msg_logtype(void); int rte_log_register(const char *name); /** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * Register a dynamic log type and try to pick its level from EAL options + * + * rte_log_register() is called inside. If successful, the function tries + * to search for matching regexp in the list of EAL log level options and + * pick the level from the last matching entry. If nothing can be applied + * from the list, the level will be set to the user-defined default value. + * + * @param name + * Name for the log type to be registered + * @param level_def + * Fallback level to be set if the global list has no matching options + * @return + * - >=0: the newly registered log type + * - <0: rte_log_register() error value + */ +int rte_log_register_type_and_pick_level(const char *name, uint32_t level_def); + +/** * Dump log information. * * Dump the global level and the registered log types. diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map index d123602..f331f54 100644 --- a/lib/librte_eal/rte_eal_version.map +++ b/lib/librte_eal/rte_eal_version.map @@ -221,6 +221,7 @@ EXPERIMENTAL { rte_eal_hotplug_add; rte_eal_hotplug_remove; rte_eal_mbuf_user_pool_ops; + rte_log_register_type_and_pick_level; rte_mp_action_register; rte_mp_action_unregister; rte_mp_sendmsg; -- 2.7.4