From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf0-f195.google.com (mail-pf0-f195.google.com [209.85.192.195]) by dpdk.org (Postfix) with ESMTP id 4B3812BFA for ; Wed, 25 Apr 2018 05:17:58 +0200 (CEST) Received: by mail-pf0-f195.google.com with SMTP id j5so13972146pfh.2 for ; Tue, 24 Apr 2018 20:17:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dEV2qy3kxbI0jGYrzp82yXAq9AVncETKmVTNzfMePfk=; b=I0ikgdZK30s8Wl6zpvFqXCmJnRXe37w7+/Udy6UDExpMAPOzl26UDA8yrA7KgUeth8 gh+vxFpECuJTkolIB3dlbWBv5/P0wm42kUHxfGXf/1GnZ/WHPkrUvMtL4lYeasFsf8OU PmcUkwUoQglohaqq/0mO7VNHfbOZ9KmV+Gtzz4QMO096sUYfWqlrLKCzVgMCec82H4zy d3g9tQAeQ32mCD5Opx9GrZrU1mCLy04/9WvRaA/yXmL9K7hD2hpsI1viopz+J5qslK2I 88C2iGSFKQC8yNTSsi/EIi/FsO7lRjn+F/dR2RcMgV1MGxzT9IAs1eNOXLR9jnTrMuqy 3tvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=dEV2qy3kxbI0jGYrzp82yXAq9AVncETKmVTNzfMePfk=; b=RMWBzfUDgwbEgfEHHkbc/bgpHZl3L8mk0mLkLoKqjo5Y40lRA/pVYwyX0YU6TRDuTl u4uSDmlBvzfPK83rARpNlofw2uqBWiup/l0m5SGsElyUxdwgeY4S+loydvlLq5VRmcy7 Akul1hbW2+lCzl+P/er+vqbxIA+xAZZO1dx50slsUWzGqIuqH+PhCqAGnSRIurh951b5 hWqcJs39Imk7jfeqIH5fxEjEYJYayvk5SN0tlpL9hPxVWi+xBuBHU4XNQn1PG1UDVOWI WKveh6F85GrkwoY+bEq5oyACiSxMDlfCSbE6Jc6kxfmSSSfNOkIfGqAdvqMAkPfRTqIY yOmw== X-Gm-Message-State: ALQs6tCky2IhDDbfDUEDWkDeDFUzhD+JY5XN7n+fk+sjRDkFWmNYTKUN MWHnJXx/9CkLVdSHhf6wSsh89QXfQ3Y= X-Google-Smtp-Source: AIpwx4+Mg771b4GtpTqwzHrW9crM/Bw3KfmE0Bd3Z9aWCO4KIcIVqXtdLoV/zlGucgdteAk/ldKZCQ== X-Received: by 10.99.100.65 with SMTP id y62mr22675050pgb.362.1524626277105; Tue, 24 Apr 2018 20:17:57 -0700 (PDT) Received: from xeon-e3.lan (204-195-71-95.wavecable.com. [204.195.71.95]) by smtp.gmail.com with ESMTPSA id x5sm20137303pfh.115.2018.04.24.20.17.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Apr 2018 20:17:55 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Tue, 24 Apr 2018 20:17:48 -0700 Message-Id: <20180425031750.30973-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180425031750.30973-1-stephen@networkplumber.org> References: <20180425031750.30973-1-stephen@networkplumber.org> Subject: [dpdk-dev] [PATCH v3 3/5] eal: make eal_log_level save private 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: Wed, 25 Apr 2018 03:17:58 -0000 We don't want format of eal log level saved values to be visible in ABI. Move to private storage in eal_common_log. Includes minor optimization. Compile the regular expression for each log match once, rather than each time it is used. Signed-off-by: Stephen Hemminger --- lib/librte_eal/common/eal_common_log.c | 51 +++++++++++++++++----- lib/librte_eal/common/eal_common_options.c | 26 ++--------- lib/librte_eal/common/eal_private.h | 5 +++ lib/librte_eal/common/include/rte_log.h | 26 ----------- 4 files changed, 49 insertions(+), 59 deletions(-) diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c index 36b9d6e08134..c04bcde87853 100644 --- a/lib/librte_eal/common/eal_common_log.c +++ b/lib/librte_eal/common/eal_common_log.c @@ -23,8 +23,19 @@ struct rte_logs rte_logs = { .file = NULL, }; -/** Global list of valid EAL log level options */ -struct rte_eal_opt_loglevel_list opt_loglevel_list = +struct rte_eal_opt_loglevel { + /** Next list entry */ + TAILQ_ENTRY(rte_eal_opt_loglevel) next; + /** Compiled regular expression obtained from the option */ + regex_t re_match; + /** Log level value obtained from the option */ + uint32_t level; +}; + +TAILQ_HEAD(rte_eal_opt_loglevel_list, rte_eal_opt_loglevel); + +/** List of valid EAL log level options */ +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 */ @@ -119,6 +130,33 @@ rte_log_set_level_regexp(const char *pattern, uint32_t level) return 0; } +/* + * 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. + */ +int rte_log_save_regexp(const char *regex, int tmp) +{ + struct rte_eal_opt_loglevel *opt_ll; + + opt_ll = malloc(sizeof(*opt_ll)); + if (opt_ll == NULL) + return -1; + + if (regcomp(&opt_ll->re_match, regex, 0) != 0) + goto fail; + + opt_ll->level = tmp; + + TAILQ_INSERT_HEAD(&opt_loglevel_list, opt_ll, next); + return 0; +fail: + free(opt_ll); + return -1; +} + /* get the current loglevel for the message being processed */ int rte_log_cur_msg_loglevel(void) { @@ -203,18 +241,11 @@ rte_log_register_type_and_pick_level(const char *name, uint32_t level_def) 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) + if (regexec(&opt_ll->re_match, name, 0, NULL, 0) == 0) level = opt_ll->level; - - regfree(&r); } rte_logs.dynamic_types[type].loglevel = level; diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c index bf4296b03264..522aa9ea6974 100644 --- a/lib/librte_eal/common/eal_common_options.c +++ b/lib/librte_eal/common/eal_common_options.c @@ -27,6 +27,7 @@ #include "eal_internal_cfg.h" #include "eal_options.h" #include "eal_filesystem.h" +#include "eal_private.h" #define BITS_PER_HEX 4 #define LCORE_OPT_LST 1 @@ -985,29 +986,8 @@ eal_parse_log_level(const char *arg) fprintf(stderr, "cannot set log level %s,%d\n", type, priority); 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 = priority; - - TAILQ_INSERT_HEAD(&opt_loglevel_list, opt_ll, next); + } else if (rte_log_save_regexp(type, priority) < 0) { + goto fail; } free(str); diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h index 6a8dde824313..a2d2def2bac7 100644 --- a/lib/librte_eal/common/eal_private.h +++ b/lib/librte_eal/common/eal_private.h @@ -82,6 +82,11 @@ int rte_eal_timer_init(void); */ 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); + /** * 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/common/include/rte_log.h b/lib/librte_eal/common/include/rte_log.h index 5f4799e1b795..2d817c3da7c1 100644 --- a/lib/librte_eal/common/include/rte_log.h +++ b/lib/librte_eal/common/include/rte_log.h @@ -85,32 +85,6 @@ 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. * -- 2.17.0