[v3,09/16] lpm: replace RTE_LOGTYPE_LPM with dynamic types

Message ID 20230210010724.890413-10-stephen@networkplumber.org (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series Replace use of static logtypes |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Stephen Hemminger Feb. 10, 2023, 1:07 a.m. UTC
  Split lpm and lpm6 into separate log types since they
are in different files and user may want to change log
levels for IPv4 vs IPv6.

For rib and fib libraries give them own types as well.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/eal/common/eal_common_log.c |  1 -
 lib/eal/include/rte_log.h       |  2 +-
 lib/fib/fib_log.h               | 10 ++++++++++
 lib/fib/rte_fib.c               | 20 ++++++++++++--------
 lib/fib/rte_fib6.c              | 16 +++++++++-------
 lib/lpm/lpm_log.h               |  9 +++++++++
 lib/lpm/rte_lpm.c               | 15 +++++++++------
 lib/lpm/rte_lpm6.c              | 20 ++++++++++++--------
 lib/rib/rib_log.h               |  9 +++++++++
 lib/rib/rte_rib.c               | 12 +++++++-----
 lib/rib/rte_rib6.c              | 12 +++++++-----
 11 files changed, 85 insertions(+), 41 deletions(-)
 create mode 100644 lib/fib/fib_log.h
 create mode 100644 lib/lpm/lpm_log.h
 create mode 100644 lib/rib/rib_log.h
  

Patch

diff --git a/lib/eal/common/eal_common_log.c b/lib/eal/common/eal_common_log.c
index 90d388192712..ff250b9a6d56 100644
--- a/lib/eal/common/eal_common_log.c
+++ b/lib/eal/common/eal_common_log.c
@@ -351,7 +351,6 @@  static const struct logtype logtype_strings[] = {
 	{RTE_LOGTYPE_EAL,        "lib.eal"},
 	{RTE_LOGTYPE_PMD,        "pmd"},
 	{RTE_LOGTYPE_HASH,       "lib.hash"},
-	{RTE_LOGTYPE_LPM,        "lib.lpm"},
 	{RTE_LOGTYPE_KNI,        "lib.kni"},
 	{RTE_LOGTYPE_METER,      "lib.meter"},
 	{RTE_LOGTYPE_SCHED,      "lib.sched"},
diff --git a/lib/eal/include/rte_log.h b/lib/eal/include/rte_log.h
index f583352ec1ea..55067efb0a84 100644
--- a/lib/eal/include/rte_log.h
+++ b/lib/eal/include/rte_log.h
@@ -33,7 +33,7 @@  extern "C" {
 				 /* was RTE_LOGTYPE_TIMER */
 #define RTE_LOGTYPE_PMD        5 /**< Log related to poll mode driver. */
 #define RTE_LOGTYPE_HASH       6 /**< Log related to hash table. */
-#define RTE_LOGTYPE_LPM        7 /**< Log related to LPM. */
+				 /* was RTE_LOGTYPE_LPM */
 #define RTE_LOGTYPE_KNI        8 /**< Log related to KNI. */
 				 /* was RTE_LOGTYPE_ACL */
 				 /* was RTE_LOGTYPE_POWER */
diff --git a/lib/fib/fib_log.h b/lib/fib/fib_log.h
new file mode 100644
index 000000000000..bf2fa88c7451
--- /dev/null
+++ b/lib/fib/fib_log.h
@@ -0,0 +1,10 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Vladimir Medvedkin <medvedkinv@gmail.com>
+ * Copyright(c) 2019 Intel Corporation
+ */
+
+extern int fib_logtype;
+
+#define FIB_LOG(level, fmt, args...)			\
+	rte_log(RTE_LOG_ ## level, fib_logtype,		\
+		"%s(): " fmt "\n", __func__, ##args)
diff --git a/lib/fib/rte_fib.c b/lib/fib/rte_fib.c
index 8af4c4091908..aa2ba735771a 100644
--- a/lib/fib/rte_fib.c
+++ b/lib/fib/rte_fib.c
@@ -8,6 +8,7 @@ 
 
 #include <rte_eal_memconfig.h>
 #include <rte_errno.h>
+#include <rte_log.h>
 #include <rte_malloc.h>
 #include <rte_string_fns.h>
 #include <rte_tailq.h>
@@ -15,8 +16,11 @@ 
 #include <rte_rib.h>
 #include <rte_fib.h>
 
+#include "fib_log.h"
 #include "dir24_8.h"
 
+RTE_LOG_REGISTER_DEFAULT(fib_logtype, INFO);
+
 TAILQ_HEAD(rte_fib_list, rte_tailq_entry);
 static struct rte_tailq_elem rte_fib_tailq = {
 	.name = "RTE_FIB",
@@ -167,8 +171,8 @@  rte_fib_create(const char *name, int socket_id, struct rte_fib_conf *conf)
 
 	rib = rte_rib_create(name, socket_id, &rib_conf);
 	if (rib == NULL) {
-		RTE_LOG(ERR, LPM,
-			"Can not allocate RIB %s\n", name);
+		FIB_LOG(ERR,
+			"Can not allocate RIB %s", name);
 		return NULL;
 	}
 
@@ -192,8 +196,8 @@  rte_fib_create(const char *name, int socket_id, struct rte_fib_conf *conf)
 	/* allocate tailq entry */
 	te = rte_zmalloc("FIB_TAILQ_ENTRY", sizeof(*te), 0);
 	if (te == NULL) {
-		RTE_LOG(ERR, LPM,
-			"Can not allocate tailq entry for FIB %s\n", name);
+		FIB_LOG(ERR,
+			"Can not allocate tailq entry for FIB %s", name);
 		rte_errno = ENOMEM;
 		goto exit;
 	}
@@ -202,7 +206,7 @@  rte_fib_create(const char *name, int socket_id, struct rte_fib_conf *conf)
 	fib = rte_zmalloc_socket(mem_name,
 		sizeof(struct rte_fib),	RTE_CACHE_LINE_SIZE, socket_id);
 	if (fib == NULL) {
-		RTE_LOG(ERR, LPM, "FIB %s memory allocation failed\n", name);
+		FIB_LOG(ERR, "FIB %s memory allocation failed", name);
 		rte_errno = ENOMEM;
 		goto free_te;
 	}
@@ -213,9 +217,9 @@  rte_fib_create(const char *name, int socket_id, struct rte_fib_conf *conf)
 	fib->def_nh = conf->default_nh;
 	ret = init_dataplane(fib, socket_id, conf);
 	if (ret < 0) {
-		RTE_LOG(ERR, LPM,
-			"FIB dataplane struct %s memory allocation failed "
-			"with err %d\n", name, ret);
+		FIB_LOG(ERR,
+			"FIB dataplane struct %s memory allocation failed with err %d",
+			name, ret);
 		rte_errno = -ret;
 		goto free_fib;
 	}
diff --git a/lib/fib/rte_fib6.c b/lib/fib/rte_fib6.c
index 4b8e22b142b9..4ce641f9dcd8 100644
--- a/lib/fib/rte_fib6.c
+++ b/lib/fib/rte_fib6.c
@@ -9,12 +9,14 @@ 
 #include <rte_eal_memconfig.h>
 #include <rte_tailq.h>
 #include <rte_errno.h>
+#include <rte_log.h>
 #include <rte_malloc.h>
 #include <rte_string_fns.h>
 
 #include <rte_rib6.h>
 #include <rte_fib6.h>
 
+#include "fib_log.h"
 #include "trie.h"
 
 TAILQ_HEAD(rte_fib6_list, rte_tailq_entry);
@@ -168,8 +170,8 @@  rte_fib6_create(const char *name, int socket_id, struct rte_fib6_conf *conf)
 
 	rib = rte_rib6_create(name, socket_id, &rib_conf);
 	if (rib == NULL) {
-		RTE_LOG(ERR, LPM,
-			"Can not allocate RIB %s\n", name);
+		FIB_LOG(ERR,
+			"Can not allocate RIB %s", name);
 		return NULL;
 	}
 
@@ -193,8 +195,8 @@  rte_fib6_create(const char *name, int socket_id, struct rte_fib6_conf *conf)
 	/* allocate tailq entry */
 	te = rte_zmalloc("FIB_TAILQ_ENTRY", sizeof(*te), 0);
 	if (te == NULL) {
-		RTE_LOG(ERR, LPM,
-			"Can not allocate tailq entry for FIB %s\n", name);
+		FIB_LOG(ERR,
+			"Can not allocate tailq entry for FIB %s", name);
 		rte_errno = ENOMEM;
 		goto exit;
 	}
@@ -203,7 +205,7 @@  rte_fib6_create(const char *name, int socket_id, struct rte_fib6_conf *conf)
 	fib = rte_zmalloc_socket(mem_name,
 		sizeof(struct rte_fib6), RTE_CACHE_LINE_SIZE, socket_id);
 	if (fib == NULL) {
-		RTE_LOG(ERR, LPM, "FIB %s memory allocation failed\n", name);
+		FIB_LOG(ERR, "FIB %s memory allocation failed", name);
 		rte_errno = ENOMEM;
 		goto free_te;
 	}
@@ -214,8 +216,8 @@  rte_fib6_create(const char *name, int socket_id, struct rte_fib6_conf *conf)
 	fib->def_nh = conf->default_nh;
 	ret = init_dataplane(fib, socket_id, conf);
 	if (ret < 0) {
-		RTE_LOG(ERR, LPM,
-			"FIB dataplane struct %s memory allocation failed\n",
+		FIB_LOG(ERR,
+			"FIB dataplane struct %s memory allocation failed",
 			name);
 		rte_errno = -ret;
 		goto free_fib;
diff --git a/lib/lpm/lpm_log.h b/lib/lpm/lpm_log.h
new file mode 100644
index 000000000000..b4101cfbe238
--- /dev/null
+++ b/lib/lpm/lpm_log.h
@@ -0,0 +1,9 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2010-2014 Intel Corporation
+ * Copyright(c) 2020 Arm Limited
+ */
+
+extern int lpm_logtype;
+#define LPM_LOG(level, fmt, args...)			\
+	rte_log(RTE_LOG_ ## level, lpm_logtype,		\
+		"%s(): " fmt "\n", __func__, ## args)
diff --git a/lib/lpm/rte_lpm.c b/lib/lpm/rte_lpm.c
index cdcd1b7f9e47..363058e118c0 100644
--- a/lib/lpm/rte_lpm.c
+++ b/lib/lpm/rte_lpm.c
@@ -18,6 +18,9 @@ 
 #include <rte_tailq.h>
 
 #include "rte_lpm.h"
+#include "lpm_log.h"
+
+RTE_LOG_REGISTER_DEFAULT(lpm_logtype, INFO);
 
 TAILQ_HEAD(rte_lpm_list, rte_tailq_entry);
 
@@ -189,7 +192,7 @@  rte_lpm_create(const char *name, int socket_id,
 	/* allocate tailq entry */
 	te = rte_zmalloc("LPM_TAILQ_ENTRY", sizeof(*te), 0);
 	if (te == NULL) {
-		RTE_LOG(ERR, LPM, "Failed to allocate tailq entry\n");
+		LPM_LOG(ERR, "Failed to allocate tailq entry");
 		rte_errno = ENOMEM;
 		goto exit;
 	}
@@ -198,7 +201,7 @@  rte_lpm_create(const char *name, int socket_id,
 	i_lpm = rte_zmalloc_socket(mem_name, mem_size,
 			RTE_CACHE_LINE_SIZE, socket_id);
 	if (i_lpm == NULL) {
-		RTE_LOG(ERR, LPM, "LPM memory allocation failed\n");
+		LPM_LOG(ERR, "LPM memory allocation failed");
 		rte_free(te);
 		rte_errno = ENOMEM;
 		goto exit;
@@ -208,7 +211,7 @@  rte_lpm_create(const char *name, int socket_id,
 			(size_t)rules_size, RTE_CACHE_LINE_SIZE, socket_id);
 
 	if (i_lpm->rules_tbl == NULL) {
-		RTE_LOG(ERR, LPM, "LPM rules_tbl memory allocation failed\n");
+		LPM_LOG(ERR, "LPM rules_tbl memory allocation failed");
 		rte_free(i_lpm);
 		i_lpm = NULL;
 		rte_free(te);
@@ -220,7 +223,7 @@  rte_lpm_create(const char *name, int socket_id,
 			(size_t)tbl8s_size, RTE_CACHE_LINE_SIZE, socket_id);
 
 	if (i_lpm->lpm.tbl8 == NULL) {
-		RTE_LOG(ERR, LPM, "LPM tbl8 memory allocation failed\n");
+		LPM_LOG(ERR, "LPM tbl8 memory allocation failed");
 		rte_free(i_lpm->rules_tbl);
 		rte_free(i_lpm);
 		i_lpm = NULL;
@@ -335,7 +338,7 @@  rte_lpm_rcu_qsbr_add(struct rte_lpm *lpm, struct rte_lpm_rcu_config *cfg)
 		params.v = cfg->v;
 		i_lpm->dq = rte_rcu_qsbr_dq_create(&params);
 		if (i_lpm->dq == NULL) {
-			RTE_LOG(ERR, LPM, "LPM defer queue creation failed\n");
+			LPM_LOG(ERR, "LPM defer queue creation failed");
 			return 1;
 		}
 	} else {
@@ -562,7 +565,7 @@  tbl8_free(struct __rte_lpm *i_lpm, uint32_t tbl8_group_start)
 		status = rte_rcu_qsbr_dq_enqueue(i_lpm->dq,
 				(void *)&tbl8_group_start);
 		if (status == 1) {
-			RTE_LOG(ERR, LPM, "Failed to push QSBR FIFO\n");
+			LPM_LOG(ERR, "Failed to push QSBR FIFO");
 			return -rte_errno;
 		}
 	}
diff --git a/lib/lpm/rte_lpm6.c b/lib/lpm/rte_lpm6.c
index 8d21aeddb83c..6c36a637322e 100644
--- a/lib/lpm/rte_lpm6.c
+++ b/lib/lpm/rte_lpm6.c
@@ -20,6 +20,7 @@ 
 #include <rte_tailq.h>
 
 #include "rte_lpm6.h"
+#include "lpm_log.h"
 
 #define RTE_LPM6_TBL24_NUM_ENTRIES        (1 << 24)
 #define RTE_LPM6_TBL8_GROUP_NUM_ENTRIES         256
@@ -279,8 +280,9 @@  rte_lpm6_create(const char *name, int socket_id,
 
 	rules_tbl = rte_hash_create(&rule_hash_tbl_params);
 	if (rules_tbl == NULL) {
-		RTE_LOG(ERR, LPM, "LPM rules hash table allocation failed: %s (%d)",
-				  rte_strerror(rte_errno), rte_errno);
+		LPM_LOG(ERR,
+			"LPM rules hash table allocation failed: %s (%d)",
+			rte_strerror(rte_errno), rte_errno);
 		goto fail_wo_unlock;
 	}
 
@@ -289,8 +291,9 @@  rte_lpm6_create(const char *name, int socket_id,
 			sizeof(uint32_t) * config->number_tbl8s,
 			RTE_CACHE_LINE_SIZE);
 	if (tbl8_pool == NULL) {
-		RTE_LOG(ERR, LPM, "LPM tbl8 pool allocation failed: %s (%d)",
-				  rte_strerror(rte_errno), rte_errno);
+		LPM_LOG(ERR,
+			"LPM tbl8 pool allocation failed: %s (%d)",
+			rte_strerror(rte_errno), rte_errno);
 		rte_errno = ENOMEM;
 		goto fail_wo_unlock;
 	}
@@ -300,8 +303,9 @@  rte_lpm6_create(const char *name, int socket_id,
 			sizeof(struct rte_lpm_tbl8_hdr) * config->number_tbl8s,
 			RTE_CACHE_LINE_SIZE);
 	if (tbl8_hdrs == NULL) {
-		RTE_LOG(ERR, LPM, "LPM tbl8 headers allocation failed: %s (%d)",
-				  rte_strerror(rte_errno), rte_errno);
+		LPM_LOG(ERR,
+			"LPM tbl8 headers allocation failed: %s (%d)",
+			rte_strerror(rte_errno), rte_errno);
 		rte_errno = ENOMEM;
 		goto fail_wo_unlock;
 	}
@@ -329,7 +333,7 @@  rte_lpm6_create(const char *name, int socket_id,
 	/* allocate tailq entry */
 	te = rte_zmalloc("LPM6_TAILQ_ENTRY", sizeof(*te), 0);
 	if (te == NULL) {
-		RTE_LOG(ERR, LPM, "Failed to allocate tailq entry!\n");
+		LPM_LOG(ERR, "Failed to allocate tailq entry!");
 		rte_errno = ENOMEM;
 		goto fail;
 	}
@@ -339,7 +343,7 @@  rte_lpm6_create(const char *name, int socket_id,
 			RTE_CACHE_LINE_SIZE, socket_id);
 
 	if (lpm == NULL) {
-		RTE_LOG(ERR, LPM, "LPM memory allocation failed\n");
+		LPM_LOG(ERR, "LPM memory allocation failed");
 		rte_free(te);
 		rte_errno = ENOMEM;
 		goto fail;
diff --git a/lib/rib/rib_log.h b/lib/rib/rib_log.h
new file mode 100644
index 000000000000..520f4083c0a8
--- /dev/null
+++ b/lib/rib/rib_log.h
@@ -0,0 +1,9 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Vladimir Medvedkin <medvedkinv@gmail.com>
+ * Copyright(c) 2019 Intel Corporation
+ */
+
+extern int rib_logtype;
+#define RIB_LOG(level, fmt, args...)			\
+	rte_log(RTE_LOG_ ## level, rib_logtype,		\
+		"%s(): " fmt "\n", __func__, ##args)
diff --git a/lib/rib/rte_rib.c b/lib/rib/rte_rib.c
index b0794edf66f5..c667e8cfe964 100644
--- a/lib/rib/rte_rib.c
+++ b/lib/rib/rte_rib.c
@@ -15,6 +15,10 @@ 
 
 #include <rte_rib.h>
 
+#include "rib_log.h"
+
+RTE_LOG_REGISTER_DEFAULT(rib_logtype, INFO);
+
 TAILQ_HEAD(rte_rib_list, rte_tailq_entry);
 static struct rte_tailq_elem rte_rib_tailq = {
 	.name = "RTE_RIB",
@@ -412,8 +416,7 @@  rte_rib_create(const char *name, int socket_id, const struct rte_rib_conf *conf)
 		NULL, NULL, NULL, NULL, socket_id, 0);
 
 	if (node_pool == NULL) {
-		RTE_LOG(ERR, LPM,
-			"Can not allocate mempool for RIB %s\n", name);
+		RIB_LOG(ERR, "Can not allocate mempool for RIB %s", name);
 		return NULL;
 	}
 
@@ -437,8 +440,7 @@  rte_rib_create(const char *name, int socket_id, const struct rte_rib_conf *conf)
 	/* allocate tailq entry */
 	te = rte_zmalloc("RIB_TAILQ_ENTRY", sizeof(*te), 0);
 	if (unlikely(te == NULL)) {
-		RTE_LOG(ERR, LPM,
-			"Can not allocate tailq entry for RIB %s\n", name);
+		RIB_LOG(ERR, "Can not allocate tailq entry for RIB %s", name);
 		rte_errno = ENOMEM;
 		goto exit;
 	}
@@ -447,7 +449,7 @@  rte_rib_create(const char *name, int socket_id, const struct rte_rib_conf *conf)
 	rib = rte_zmalloc_socket(mem_name,
 		sizeof(struct rte_rib),	RTE_CACHE_LINE_SIZE, socket_id);
 	if (unlikely(rib == NULL)) {
-		RTE_LOG(ERR, LPM, "RIB %s memory allocation failed\n", name);
+		RIB_LOG(ERR, "RIB %s memory allocation failed", name);
 		rte_errno = ENOMEM;
 		goto free_te;
 	}
diff --git a/lib/rib/rte_rib6.c b/lib/rib/rte_rib6.c
index 19e4ff97c479..4e171d4208d9 100644
--- a/lib/rib/rte_rib6.c
+++ b/lib/rib/rte_rib6.c
@@ -8,6 +8,7 @@ 
 
 #include <rte_eal_memconfig.h>
 #include <rte_errno.h>
+#include <rte_log.h>
 #include <rte_malloc.h>
 #include <rte_mempool.h>
 #include <rte_string_fns.h>
@@ -15,6 +16,8 @@ 
 
 #include <rte_rib6.h>
 
+#include "rib_log.h"
+
 #define RTE_RIB_VALID_NODE	1
 #define RIB6_MAXDEPTH		128
 /* Maximum length of a RIB6 name. */
@@ -481,8 +484,7 @@  rte_rib6_create(const char *name, int socket_id,
 		NULL, NULL, NULL, NULL, socket_id, 0);
 
 	if (node_pool == NULL) {
-		RTE_LOG(ERR, LPM,
-			"Can not allocate mempool for RIB6 %s\n", name);
+		RIB_LOG(ERR, "Can not allocate mempool for RIB6 %s", name);
 		return NULL;
 	}
 
@@ -506,8 +508,8 @@  rte_rib6_create(const char *name, int socket_id,
 	/* allocate tailq entry */
 	te = rte_zmalloc("RIB6_TAILQ_ENTRY", sizeof(*te), 0);
 	if (unlikely(te == NULL)) {
-		RTE_LOG(ERR, LPM,
-			"Can not allocate tailq entry for RIB6 %s\n", name);
+		RIB_LOG(ERR,
+			"Can not allocate tailq entry for RIB6 %s", name);
 		rte_errno = ENOMEM;
 		goto exit;
 	}
@@ -516,7 +518,7 @@  rte_rib6_create(const char *name, int socket_id,
 	rib = rte_zmalloc_socket(mem_name,
 		sizeof(struct rte_rib6), RTE_CACHE_LINE_SIZE, socket_id);
 	if (unlikely(rib == NULL)) {
-		RTE_LOG(ERR, LPM, "RIB6 %s memory allocation failed\n", name);
+		RIB_LOG(ERR, "RIB6 %s memory allocation failed", name);
 		rte_errno = ENOMEM;
 		goto free_te;
 	}