DPDK patches and discussions
 help / color / mirror / Atom feed
From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: Bruce Richardson <bruce.richardson@intel.com>,
	Kevin Laatz <kevin.laatz@intel.com>
Subject: [dpdk-dev] [PATCH 1/4] telemetry: use rte_log for logging
Date: Wed, 10 Mar 2021 17:24:27 +0000	[thread overview]
Message-ID: <20210310172430.412405-2-bruce.richardson@intel.com> (raw)
In-Reply-To: <20210310172430.412405-1-bruce.richardson@intel.com>

Rather than passing back an error string to the caller, take as input the
rte_log function to use, and just use regular logging.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 lib/librte_eal/freebsd/eal.c         | 10 ++--
 lib/librte_eal/linux/eal.c           | 10 ++--
 lib/librte_telemetry/rte_telemetry.h | 15 ++++--
 lib/librte_telemetry/telemetry.c     | 72 +++++++++++++---------------
 4 files changed, 49 insertions(+), 58 deletions(-)

diff --git a/lib/librte_eal/freebsd/eal.c b/lib/librte_eal/freebsd/eal.c
index e2cdad5283..b8a798bc7d 100644
--- a/lib/librte_eal/freebsd/eal.c
+++ b/lib/librte_eal/freebsd/eal.c
@@ -941,15 +941,11 @@ rte_eal_init(int argc, char **argv)
 		return -1;
 	}
 	if (!internal_conf->no_telemetry) {
-		const char *error_str = NULL;
+		uint32_t tlog = rte_log_register_type_and_pick_level(
+				"lib.telemetry", RTE_LOG_WARNING);
 		if (rte_telemetry_init(rte_eal_get_runtime_dir(),
-				&internal_conf->ctrl_cpuset, &error_str)
-				!= 0) {
-			rte_eal_init_alert(error_str);
+				&internal_conf->ctrl_cpuset, rte_log, tlog) != 0)
 			return -1;
-		}
-		if (error_str != NULL)
-			RTE_LOG(NOTICE, EAL, "%s\n", error_str);
 	}

 	eal_mcfg_complete();
diff --git a/lib/librte_eal/linux/eal.c b/lib/librte_eal/linux/eal.c
index 6c34ac8903..23e3a32036 100644
--- a/lib/librte_eal/linux/eal.c
+++ b/lib/librte_eal/linux/eal.c
@@ -1314,15 +1314,11 @@ rte_eal_init(int argc, char **argv)
 		return -1;
 	}
 	if (!internal_conf->no_telemetry) {
-		const char *error_str = NULL;
+		uint32_t tlog = rte_log_register_type_and_pick_level(
+				"lib.telemetry", RTE_LOG_WARNING);
 		if (rte_telemetry_init(rte_eal_get_runtime_dir(),
-				&internal_conf->ctrl_cpuset, &error_str)
-				!= 0) {
-			rte_eal_init_alert(error_str);
+				&internal_conf->ctrl_cpuset, rte_log, tlog) != 0)
 			return -1;
-		}
-		if (error_str != NULL)
-			RTE_LOG(NOTICE, EAL, "%s\n", error_str);
 	}

 	eal_mcfg_complete();
diff --git a/lib/librte_telemetry/rte_telemetry.h b/lib/librte_telemetry/rte_telemetry.h
index f8e54dc68e..2c3da3ab7f 100644
--- a/lib/librte_telemetry/rte_telemetry.h
+++ b/lib/librte_telemetry/rte_telemetry.h
@@ -292,6 +292,12 @@ __rte_experimental
 int
 rte_telemetry_register_cmd(const char *cmd, telemetry_cb fn, const char *help);

+/**
+ * @internal
+ * Log function type, to allow passing as parameter if necessary
+ */
+typedef int (*rte_log_fn)(uint32_t level, uint32_t logtype, const char *format, ...);
+
 /**
  * @internal
  * Initialize Telemetry.
@@ -300,9 +306,10 @@ rte_telemetry_register_cmd(const char *cmd, telemetry_cb fn, const char *help);
  * The runtime directory of DPDK.
  * @param cpuset
  * The CPU set to be used for setting the thread affinity.
- * @param err_str
- * This err_str pointer should point to NULL on entry. In the case of an error
- * or warning, it will be non-NULL on exit.
+ * @param log_fn
+ * Function pointer to the rte_log function for logging use
+ * @param registered_logtype
+ * The registered log type to use for logging
  *
  * @return
  *  0 on success.
@@ -312,7 +319,7 @@ rte_telemetry_register_cmd(const char *cmd, telemetry_cb fn, const char *help);
 __rte_internal
 int
 rte_telemetry_init(const char *runtime_dir, rte_cpuset_t *cpuset,
-		const char **err_str);
+		rte_log_fn log_fn, uint32_t registered_logtype);

 /**
  * Get a pointer to a container with memory allocated. The container is to be
diff --git a/lib/librte_telemetry/telemetry.c b/lib/librte_telemetry/telemetry.c
index b142729da4..18f2ae2e2f 100644
--- a/lib/librte_telemetry/telemetry.c
+++ b/lib/librte_telemetry/telemetry.c
@@ -16,6 +16,7 @@
 #include <rte_common.h>
 #include <rte_spinlock.h>
 #include <rte_version.h>
+#include <rte_log.h>

 #include "rte_telemetry.h"
 #include "telemetry_json.h"
@@ -48,7 +49,15 @@ struct socket {
 static struct socket v2_socket; /* socket for v2 telemetry */
 static struct socket v1_socket; /* socket for v1 telemetry */
 #endif /* !RTE_EXEC_ENV_WINDOWS */
-static char telemetry_log_error[1024]; /* Will contain error on init failure */
+
+static const char *socket_dir;
+static rte_cpuset_t *thread_cpuset;
+static rte_log_fn rte_log_ptr;
+static uint32_t logtype;
+
+#define TMTY_LOG(l, ...) \
+	 rte_log_ptr(RTE_LOG_ ## l, logtype, "TELEMETRY: " __VA_ARGS__)
+
 /* list of command callbacks, with one command registered by default */
 static struct cmd_callback callbacks[TELEMETRY_MAX_CALLBACKS];
 static int num_callbacks; /* How many commands are registered */
@@ -344,9 +353,7 @@ socket_listener(void *socket)
 		struct socket *s = (struct socket *)socket;
 		int s_accepted = accept(s->sock, NULL, NULL);
 		if (s_accepted < 0) {
-			snprintf(telemetry_log_error,
-				sizeof(telemetry_log_error),
-				"Error with accept, telemetry thread quitting");
+			TMTY_LOG(ERR, "Error with accept, telemetry thread quitting\n");
 			return NULL;
 		}
 		if (s->num_clients != NULL) {
@@ -388,9 +395,7 @@ create_socket(char *path)
 {
 	int sock = socket(AF_UNIX, SOCK_SEQPACKET, 0);
 	if (sock < 0) {
-		snprintf(telemetry_log_error, sizeof(telemetry_log_error),
-				"Error with socket creation, %s",
-				strerror(errno));
+		TMTY_LOG(ERR, "Error with socket creation, %s\n", strerror(errno));
 		return -1;
 	}

@@ -398,17 +403,13 @@ create_socket(char *path)
 	strlcpy(sun.sun_path, path, sizeof(sun.sun_path));
 	unlink(sun.sun_path);
 	if (bind(sock, (void *) &sun, sizeof(sun)) < 0) {
-		snprintf(telemetry_log_error, sizeof(telemetry_log_error),
-				"Error binding socket: %s",
-				strerror(errno));
+		TMTY_LOG(ERR, "Error binding socket: %s\n", strerror(errno));
 		sun.sun_path[0] = 0;
 		goto error;
 	}

 	if (listen(sock, 1) < 0) {
-		snprintf(telemetry_log_error, sizeof(telemetry_log_error),
-				"Error calling listen for socket: %s",
-				strerror(errno));
+		TMTY_LOG(ERR, "Error calling listen for socket: %s\n", strerror(errno));
 		goto error;
 	}

@@ -421,35 +422,33 @@ create_socket(char *path)
 }

 static int
-telemetry_legacy_init(const char *runtime_dir, rte_cpuset_t *cpuset)
+telemetry_legacy_init(void)
 {
 	pthread_t t_old;

 	if (num_legacy_callbacks == 1) {
-		snprintf(telemetry_log_error, sizeof(telemetry_log_error),
-			 "No legacy callbacks, legacy socket not created");
+		TMTY_LOG(WARNING, "No legacy callbacks, legacy socket not created\n");
 		return -1;
 	}

 	v1_socket.fn = legacy_client_handler;
 	if ((size_t) snprintf(v1_socket.path, sizeof(v1_socket.path),
-			"%s/telemetry", runtime_dir)
-			>= sizeof(v1_socket.path)) {
-		snprintf(telemetry_log_error, sizeof(telemetry_log_error),
-				"Error with socket binding, path too long");
+			"%s/telemetry", socket_dir) >= sizeof(v1_socket.path)) {
+		TMTY_LOG(ERR, "Error with socket binding, path too long\n");
 		return -1;
 	}
 	v1_socket.sock = create_socket(v1_socket.path);
 	if (v1_socket.sock < 0)
 		return -1;
 	pthread_create(&t_old, NULL, socket_listener, &v1_socket);
-	pthread_setaffinity_np(t_old, sizeof(*cpuset), cpuset);
+	pthread_setaffinity_np(t_old, sizeof(*thread_cpuset), thread_cpuset);

+	TMTY_LOG(DEBUG, "Legacy telemetry socket initialized ok\n");
 	return 0;
 }

 static int
-telemetry_v2_init(const char *runtime_dir, rte_cpuset_t *cpuset)
+telemetry_v2_init(void)
 {
 	pthread_t t_new;

@@ -461,10 +460,9 @@ telemetry_v2_init(const char *runtime_dir, rte_cpuset_t *cpuset)
 	rte_telemetry_register_cmd("/help", command_help,
 			"Returns help text for a command. Parameters: string command");
 	v2_socket.fn = client_handler;
-	if (strlcpy(v2_socket.path, get_socket_path(runtime_dir, 2),
+	if (strlcpy(v2_socket.path, get_socket_path(socket_dir, 2),
 			sizeof(v2_socket.path)) >= sizeof(v2_socket.path)) {
-		snprintf(telemetry_log_error, sizeof(telemetry_log_error),
-				"Error with socket binding, path too long");
+		TMTY_LOG(ERR, "Error with socket binding, path too long\n");
 		return -1;
 	}

@@ -472,7 +470,7 @@ telemetry_v2_init(const char *runtime_dir, rte_cpuset_t *cpuset)
 	if (v2_socket.sock < 0)
 		return -1;
 	pthread_create(&t_new, NULL, socket_listener, &v2_socket);
-	pthread_setaffinity_np(t_new, sizeof(*cpuset), cpuset);
+	pthread_setaffinity_np(t_new, sizeof(*thread_cpuset), thread_cpuset);
 	atexit(unlink_sockets);

 	return 0;
@@ -482,23 +480,17 @@ telemetry_v2_init(const char *runtime_dir, rte_cpuset_t *cpuset)

 int32_t
 rte_telemetry_init(const char *runtime_dir, rte_cpuset_t *cpuset,
-		const char **err_str)
+		rte_log_fn log_fn, uint32_t registered_logtype)
 {
+	socket_dir = runtime_dir;
+	thread_cpuset = cpuset;
+	rte_log_ptr = log_fn;
+	logtype = registered_logtype;
 #ifndef RTE_EXEC_ENV_WINDOWS
-	if (telemetry_v2_init(runtime_dir, cpuset) != 0) {
-		*err_str = telemetry_log_error;
+	if (telemetry_v2_init() != 0)
 		return -1;
-	}
-	if (telemetry_legacy_init(runtime_dir, cpuset) != 0) {
-		*err_str = telemetry_log_error;
-	}
-#else /* RTE_EXEC_ENV_WINDOWS */
-	RTE_SET_USED(runtime_dir);
-	RTE_SET_USED(cpuset);
-	RTE_SET_USED(err_str);
-
-	snprintf(telemetry_log_error, sizeof(telemetry_log_error),
-		"DPDK Telemetry is not supported on Windows.");
+	TMTY_LOG(DEBUG, "Telemetry initialized ok\n");
+	telemetry_legacy_init();
 #endif /* RTE_EXEC_ENV_WINDOWS */

 	return 0;
--
2.27.0


  reply	other threads:[~2021-03-10 17:24 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-10 17:24 [dpdk-dev] [PATCH 0/4] telemetry logging improvements and cleanup Bruce Richardson
2021-03-10 17:24 ` Bruce Richardson [this message]
2021-03-11 12:50   ` [dpdk-dev] [PATCH 1/4] telemetry: use rte_log for logging Power, Ciara
2021-03-10 17:24 ` [dpdk-dev] [PATCH 2/4] telemetry: make the legacy registration function internal Bruce Richardson
2021-03-11 12:50   ` Power, Ciara
2021-03-10 17:24 ` [dpdk-dev] [PATCH 3/4] telemetry: create internal-only header file Bruce Richardson
2021-03-11 12:51   ` Power, Ciara
2021-03-10 17:24 ` [dpdk-dev] [PATCH 4/4] telemetry: move init function to internal header Bruce Richardson
2021-03-11 12:51   ` Power, Ciara
2021-03-24 21:11 ` [dpdk-dev] [PATCH 0/4] telemetry logging improvements and cleanup Thomas Monjalon
2021-03-25  8:55   ` Bruce Richardson
2021-03-25 13:57 ` [dpdk-dev] [PATCH v2 " Bruce Richardson
2021-03-25 13:57   ` [dpdk-dev] [PATCH v2 1/4] telemetry: use rte_log for logging Bruce Richardson
2021-03-25 14:09     ` David Marchand
2021-03-25 14:16       ` Bruce Richardson
2021-03-25 13:57   ` [dpdk-dev] [PATCH v2 2/4] telemetry: make the legacy registration function internal Bruce Richardson
2021-03-25 13:57   ` [dpdk-dev] [PATCH v2 3/4] telemetry: rename internal-only header file Bruce Richardson
2021-03-25 13:57   ` [dpdk-dev] [PATCH v2 4/4] telemetry: move init function to internal header Bruce Richardson
2021-03-25 16:36   ` [dpdk-dev] [PATCH v2 0/4] telemetry logging improvements and cleanup Thomas Monjalon

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=20210310172430.412405-2-bruce.richardson@intel.com \
    --to=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=kevin.laatz@intel.com \
    /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).