From b22e77c026205ef087cda1448fa2214fb005b39c Mon Sep 17 00:00:00 2001 From: Ivan Malov Date: Wed, 21 Mar 2018 11:28:16 +0000 Subject: [PATCH] eal: register log type and pick level from args 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 Acked-by: Ferruh Yigit --- 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 37b2e20e53..a27192620d 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 0be80cb159..8a51adee6a 100644 --- a/lib/librte_eal/common/eal_common_options.c +++ b/lib/librte_eal/common/eal_common_options.c @@ -947,6 +947,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 9029c7856d..5f4799e1b7 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 @@ -84,6 +85,32 @@ extern struct rte_logs rte_logs; #define RTE_LOG_INFO 7U /**< Informational. */ #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. * @@ -194,6 +221,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. * diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map index d123602354..f331f54c9c 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.20.1