DPDK patches and discussions
 help / color / mirror / Atom feed
From: Andrew Rybchenko <arybchenko@solarflare.com>
To: <dev@dpdk.org>
Cc: Thomas Monjalon <thomas@monjalon.net>,
	Olivier Matz <olivier.matz@6wind.com>,
	Ivan Malov <ivan.malov@oktetlabs.ru>
Subject: [dpdk-dev] [PATCH v2] eal: register log type and pick level from EAL args
Date: Thu, 15 Feb 2018 11:35:43 +0000	[thread overview]
Message-ID: <1518694544-22334-1-git-send-email-arybchenko@solarflare.com> (raw)
In-Reply-To: <1516899647-8541-1-git-send-email-arybchenko@solarflare.com>

From: Ivan Malov <ivan.malov@oktetlabs.ru>

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 <ivan.malov@oktetlabs.ru>
Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
Reviewed-by: Andy Moreton <amoreton@solarflare.com>
---
 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 <stdint.h>
 #include <stdio.h>
 #include <stdarg.h>
+#include <sys/queue.h>
 
 #include <rte_common.h>
 #include <rte_config.h>
@@ -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

  parent reply	other threads:[~2018-02-15 11:35 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-25 17:00 [dpdk-dev] [PATCH 0/6] net/sfc: implement dynamic logging Andrew Rybchenko
2018-01-25 17:00 ` [dpdk-dev] [PATCH 1/6] eal: register log type and pick level from EAL args Andrew Rybchenko
2018-01-25 17:00 ` [dpdk-dev] [PATCH 2/6] net/sfc: add support for driver-wide dynamic logging Andrew Rybchenko
2018-01-25 18:42   ` Stephen Hemminger
2018-01-26  6:51     ` Andrew Rybchenko
2018-03-05 14:59   ` Ferruh Yigit
2018-03-06 14:45     ` Andrew Rybchenko
2018-03-06 14:56       ` Andrew Rybchenko
2018-03-06 15:26         ` Ferruh Yigit
2018-01-25 17:00 ` [dpdk-dev] [PATCH 3/6] net/sfc: add support for per-port " Andrew Rybchenko
2018-03-15 15:45   ` Ferruh Yigit
2018-01-25 17:00 ` [dpdk-dev] [PATCH 4/6] net/sfc: prepare to merge init logs with main log type Andrew Rybchenko
2018-01-25 17:00 ` [dpdk-dev] [PATCH 5/6] net/sfc: remove dedicated init log parameter Andrew Rybchenko
2018-01-25 17:00 ` [dpdk-dev] [PATCH 6/6] net/sfc: add dynamic log level for MCDI messages Andrew Rybchenko
2018-01-25 21:38 ` [dpdk-dev] [PATCH 0/6] net/sfc: implement dynamic logging Thomas Monjalon
2018-01-26  5:59   ` Andrew Rybchenko
2018-01-26  7:44     ` Thomas Monjalon
2018-02-15 11:35 ` Andrew Rybchenko [this message]
2018-03-05 15:00 ` Ferruh Yigit
2018-03-21 11:28 ` [dpdk-dev] [PATCH v3 " Andrew Rybchenko
2018-03-21 11:28   ` [dpdk-dev] [PATCH v3 1/6] eal: register log type and pick level from EAL args Andrew Rybchenko
2018-03-22 10:21     ` Ferruh Yigit
2018-03-21 11:28   ` [dpdk-dev] [PATCH v3 2/6] net/sfc: add support for driver-wide dynamic logging Andrew Rybchenko
2018-03-21 11:28   ` [dpdk-dev] [PATCH v3 3/6] net/sfc: add support for per-port " Andrew Rybchenko
2018-03-21 11:28   ` [dpdk-dev] [PATCH v3 4/6] net/sfc: prepare to merge init logs with main log type Andrew Rybchenko
2018-03-21 11:28   ` [dpdk-dev] [PATCH v3 5/6] net/sfc: remove dedicated init log parameter Andrew Rybchenko
2018-03-21 11:28   ` [dpdk-dev] [PATCH v3 6/6] net/sfc: add dynamic log level for MCDI messages Andrew Rybchenko
2018-03-22 10:22   ` [dpdk-dev] [PATCH v3 0/6] net/sfc: implement dynamic logging Ferruh Yigit

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=1518694544-22334-1-git-send-email-arybchenko@solarflare.com \
    --to=arybchenko@solarflare.com \
    --cc=dev@dpdk.org \
    --cc=ivan.malov@oktetlabs.ru \
    --cc=olivier.matz@6wind.com \
    --cc=thomas@monjalon.net \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).