From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 7A075A0A02; Thu, 25 Mar 2021 14:57:33 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D2E73140D3A; Thu, 25 Mar 2021 14:57:31 +0100 (CET) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mails.dpdk.org (Postfix) with ESMTP id 7DEFF140D36 for ; Thu, 25 Mar 2021 14:57:30 +0100 (CET) IronPort-SDR: hwzd+8YtEXSunXU+d8Nc5bxV9TuJMxF9MjsH4ge9riPiZNwEtJntcbslYdbCkflQ+BJ+INGXV1 3dIaQurex+KA== X-IronPort-AV: E=McAfee;i="6000,8403,9933"; a="170910538" X-IronPort-AV: E=Sophos;i="5.81,277,1610438400"; d="scan'208";a="170910538" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2021 06:57:30 -0700 IronPort-SDR: Upq2bzQxC4R47B0B3miwuznwnP5Uh7cIwiQTR082G1A0FvXiLaWxQngyyfZYiGB4dEIeGZg915 Xojs6Km8fGDg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,277,1610438400"; d="scan'208";a="436466498" Received: from silpixa00399126.ir.intel.com ([10.237.223.116]) by fmsmga004.fm.intel.com with ESMTP; 25 Mar 2021 06:57:27 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: Bruce Richardson , Ciara Power , Kevin Laatz Date: Thu, 25 Mar 2021 13:57:04 +0000 Message-Id: <20210325135707.325536-2-bruce.richardson@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210325135707.325536-1-bruce.richardson@intel.com> References: <20210310172430.412405-1-bruce.richardson@intel.com> <20210325135707.325536-1-bruce.richardson@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2 1/4] telemetry: use rte_log for logging X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 Acked-by: Ciara Power --- 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 | 74 +++++++++++++--------------- 4 files changed, 50 insertions(+), 59 deletions(-) diff --git a/lib/librte_eal/freebsd/eal.c b/lib/librte_eal/freebsd/eal.c index 62320d610..97ce9976c 100644 --- a/lib/librte_eal/freebsd/eal.c +++ b/lib/librte_eal/freebsd/eal.c @@ -941,16 +941,12 @@ 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(), rte_version(), - &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 9ffb4b331..f6dd67b6d 100644 --- a/lib/librte_eal/linux/eal.c +++ b/lib/librte_eal/linux/eal.c @@ -1314,16 +1314,12 @@ 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(), rte_version(), - &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 027b048d7..d38894b97 100644 --- a/lib/librte_telemetry/rte_telemetry.h +++ b/lib/librte_telemetry/rte_telemetry.h @@ -294,6 +294,12 @@ rte_telemetry_register_cmd(const char *cmd, telemetry_cb fn, const char *help); #ifdef RTE_HAS_CPUSET +/** + * @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. @@ -302,9 +308,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. @@ -314,7 +321,7 @@ rte_telemetry_register_cmd(const char *cmd, telemetry_cb fn, const char *help); __rte_internal int rte_telemetry_init(const char *runtime_dir, const char *rte_version, rte_cpuset_t *cpuset, - const char **err_str); + rte_log_fn log_fn, uint32_t registered_logtype); #endif /* RTE_HAS_CPUSET */ diff --git a/lib/librte_telemetry/telemetry.c b/lib/librte_telemetry/telemetry.c index 14b4ff5ea..042136b82 100644 --- a/lib/librte_telemetry/telemetry.c +++ b/lib/librte_telemetry/telemetry.c @@ -15,6 +15,7 @@ #include #include #include +#include #include "rte_telemetry.h" #include "telemetry_json.h" @@ -49,7 +50,14 @@ static struct socket v1_socket; /* socket for v1 telemetry */ #endif /* !RTE_EXEC_ENV_WINDOWS */ static const char *telemetry_version; /* save rte_version */ -static char telemetry_log_error[1024]; /* Will contain error on init failure */ +static const char *socket_dir; /* runtime directory */ +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 */ @@ -345,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) { @@ -389,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; } @@ -399,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; } @@ -422,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; @@ -462,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; } @@ -473,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,25 +479,20 @@ telemetry_v2_init(const char *runtime_dir, rte_cpuset_t *cpuset) #endif /* !RTE_EXEC_ENV_WINDOWS */ int32_t -rte_telemetry_init(const char *runtime_dir, const char *rte_version, - rte_cpuset_t *cpuset, const char **err_str) +rte_telemetry_init(const char *runtime_dir, const char *rte_version, rte_cpuset_t *cpuset, + rte_log_fn log_fn, uint32_t registered_logtype) { telemetry_version = rte_version; + 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