All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>
Subject: [PATCH v2 3/5] eal: make eal_log_level save private
Date: Tue, 24 Apr 2018 09:58:06 -0700	[thread overview]
Message-ID: <20180424165808.23292-4-stephen@networkplumber.org> (raw)
In-Reply-To: <20180424165808.23292-1-stephen@networkplumber.org>

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 <stephen@networkplumber.org>
---
 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 a27192620d9e..c47e53b3db74 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_eal_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 13c05bbe9b70..038e75d86348 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_eal_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..d505a9a3c76f 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_eal_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

  parent reply	other threads:[~2018-04-24 16:58 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-24 16:58 [PATCH v2 0/5] logging enhancements Stephen Hemminger
2018-04-24 16:58 ` [PATCH v2 1/5] eal: make syslog facility table const Stephen Hemminger
2018-04-24 16:58 ` [PATCH v2 2/5] eal: allow symbolic log levels Stephen Hemminger
2018-04-24 16:58 ` Stephen Hemminger [this message]
2018-04-24 23:55   ` [PATCH v2 3/5] eal: make eal_log_level save private Thomas Monjalon
2018-04-24 16:58 ` [PATCH v2 4/5] log: add ability to match dynamic log based on shell pattern Stephen Hemminger
2018-04-25  0:02   ` Thomas Monjalon
2018-04-25  0:08   ` Thomas Monjalon
2018-04-24 16:58 ` [PATCH v2 5/5] doc: update guides for current preferrred log level syntax Stephen Hemminger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180424165808.23292-4-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.