DPDK patches and discussions
 help / color / mirror / Atom feed
From: Andrew Rybchenko <arybchenko@solarflare.com>
To: <dev@dpdk.org>
Cc: Ivan Malov <ivan.malov@oktetlabs.ru>
Subject: [dpdk-dev] [PATCH 3/6] net/sfc: add support for per-port dynamic logging
Date: Thu, 25 Jan 2018 17:00:44 +0000	[thread overview]
Message-ID: <1516899647-8541-4-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>

Signed-off-by: Ivan Malov <ivan.malov@oktetlabs.ru>
Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
Reviewed-by: Andy Moreton <amoreton@solarflare.com>
---
 doc/guides/nics/sfc_efx.rst  |  6 ++++++
 drivers/net/sfc/sfc.c        | 32 ++++++++++++++++++++++++++++++++
 drivers/net/sfc/sfc.h        |  5 +++++
 drivers/net/sfc/sfc_ethdev.c |  3 +++
 drivers/net/sfc/sfc_log.h    | 41 ++++++++++++++++++++++++++++++++---------
 5 files changed, 78 insertions(+), 9 deletions(-)

diff --git a/doc/guides/nics/sfc_efx.rst b/doc/guides/nics/sfc_efx.rst
index 4d89cfd..8d5eb30 100644
--- a/doc/guides/nics/sfc_efx.rst
+++ b/doc/guides/nics/sfc_efx.rst
@@ -324,3 +324,9 @@ SFC EFX PMD provides the following log types available for control:
 - ``pmd.net.sfc.driver`` (default level is **6** - ``RTE_LOG_NOTICE``)
 
   Affects driver-wide messages unrelated to any particular devices.
+
+- ``pmd.net.sfc.main`` (default level is **6** - ``RTE_LOG_NOTICE``)
+
+  Matches a subset of per-port log types registered during runtime.
+  A full name for a particular type may be obtained by appending a
+  dot and a PCI device identifier (``XXXX:XX:XX.X``) to the prefix.
diff --git a/drivers/net/sfc/sfc.c b/drivers/net/sfc/sfc.c
index ac5fdca..d31b0b1 100644
--- a/drivers/net/sfc/sfc.c
+++ b/drivers/net/sfc/sfc.c
@@ -843,3 +843,35 @@ sfc_unprobe(struct sfc_adapter *sa)
 	sfc_flow_fini(sa);
 	sa->state = SFC_ADAPTER_UNINITIALIZED;
 }
+
+uint32_t
+sfc_register_logtype(struct sfc_adapter *sa, const char *lt_prefix_str,
+		     uint32_t ll_default)
+{
+	size_t lt_prefix_str_size = strlen(lt_prefix_str);
+	size_t lt_str_size_max;
+	char *lt_str = NULL;
+	int ret;
+
+	if (SIZE_MAX - PCI_PRI_STR_SIZE - 1 > lt_prefix_str_size) {
+		++lt_prefix_str_size; /* Reserve space for prefix separator */
+		lt_str_size_max = lt_prefix_str_size + PCI_PRI_STR_SIZE + 1;
+	} else {
+		return RTE_LOGTYPE_PMD;
+	}
+
+	lt_str = rte_zmalloc("logtype_str", lt_str_size_max, 0);
+	if (lt_str == NULL)
+		return RTE_LOGTYPE_PMD;
+
+	strncpy(lt_str, lt_prefix_str, lt_prefix_str_size);
+	lt_str[lt_prefix_str_size - 1] = '.';
+	rte_pci_device_name(&sa->pci_addr, lt_str + lt_prefix_str_size,
+			    lt_str_size_max - lt_prefix_str_size);
+	lt_str[lt_str_size_max - 1] = '\0';
+
+	ret = rte_log_register_type_and_pick_level(lt_str, ll_default);
+	rte_free(lt_str);
+
+	return (ret < 0) ? RTE_LOGTYPE_PMD : ret;
+}
diff --git a/drivers/net/sfc/sfc.h b/drivers/net/sfc/sfc.h
index 7557534..768578e 100644
--- a/drivers/net/sfc/sfc.h
+++ b/drivers/net/sfc/sfc.h
@@ -170,6 +170,7 @@ struct sfc_adapter {
 	uint16_t			port_id;
 	struct rte_eth_dev		*eth_dev;
 	struct rte_kvargs		*kvargs;
+	uint32_t			logtype_main;
 	bool				debug_init;
 	int				socket_id;
 	efsys_bar_t			mem_bar;
@@ -302,6 +303,10 @@ int sfc_dma_alloc(const struct sfc_adapter *sa, const char *name, uint16_t id,
 		  size_t len, int socket_id, efsys_mem_t *esmp);
 void sfc_dma_free(const struct sfc_adapter *sa, efsys_mem_t *esmp);
 
+uint32_t sfc_register_logtype(struct sfc_adapter *sa,
+			      const char *lt_prefix_str,
+			      uint32_t ll_default);
+
 int sfc_probe(struct sfc_adapter *sa);
 void sfc_unprobe(struct sfc_adapter *sa);
 int sfc_attach(struct sfc_adapter *sa);
diff --git a/drivers/net/sfc/sfc_ethdev.c b/drivers/net/sfc/sfc_ethdev.c
index f167120..a244d27 100644
--- a/drivers/net/sfc/sfc_ethdev.c
+++ b/drivers/net/sfc/sfc_ethdev.c
@@ -1937,6 +1937,9 @@ sfc_eth_dev_init(struct rte_eth_dev *dev)
 	/* Copy PCI device info to the dev->data */
 	rte_eth_copy_pci_info(dev, pci_dev);
 
+	sa->logtype_main = sfc_register_logtype(sa, SFC_LOGTYPE_MAIN_STR,
+						RTE_LOG_NOTICE);
+
 	rc = sfc_kvargs_parse(sa);
 	if (rc != 0)
 		goto fail_kvargs_parse;
diff --git a/drivers/net/sfc/sfc_log.h b/drivers/net/sfc/sfc_log.h
index ecafffc..ec903db 100644
--- a/drivers/net/sfc/sfc_log.h
+++ b/drivers/net/sfc/sfc_log.h
@@ -22,14 +22,17 @@ extern uint32_t sfc_logtype_driver;
 		RTE_FMT("PMD: " RTE_FMT_HEAD(__VA_ARGS__ ,) "\n",	\
 			RTE_FMT_TAIL(__VA_ARGS__ ,)))
 
+/** Name prefix for the per-device log type used to report basic information */
+#define SFC_LOGTYPE_MAIN_STR	SFC_LOGTYPE_PREFIX "main"
+
 /* Log PMD message, automatically add prefix and \n */
-#define SFC_LOG(sa, level, ...) \
+#define SFC_LOG(sa, level, type, ...) \
 	do {								\
 		const struct sfc_adapter *__sa = (sa);			\
 									\
-		RTE_LOG(level, PMD,					\
-			RTE_FMT("sfc_efx " PCI_PRI_FMT " #%" PRIu8 ": "	\
-				RTE_FMT_HEAD(__VA_ARGS__,) "\n",	\
+		rte_log(level, type,					\
+			RTE_FMT("PMD: sfc_efx " PCI_PRI_FMT " #%" PRIu8	\
+				": " RTE_FMT_HEAD(__VA_ARGS__ ,) "\n",	\
 				__sa->pci_addr.domain,			\
 				__sa->pci_addr.bus,			\
 				__sa->pci_addr.devid,			\
@@ -39,23 +42,43 @@ extern uint32_t sfc_logtype_driver;
 	} while (0)
 
 #define sfc_err(sa, ...) \
-	SFC_LOG(sa, ERR, __VA_ARGS__)
+	do {								\
+		const struct sfc_adapter *_sa = (sa);			\
+									\
+		SFC_LOG(_sa, RTE_LOG_ERR, _sa->logtype_main,		\
+			__VA_ARGS__);					\
+	} while (0)
 
 #define sfc_warn(sa, ...) \
-	SFC_LOG(sa, WARNING, __VA_ARGS__)
+	do {								\
+		const struct sfc_adapter *_sa = (sa);			\
+									\
+		SFC_LOG(_sa, RTE_LOG_WARNING, _sa->logtype_main,	\
+			__VA_ARGS__);					\
+	} while (0)
 
 #define sfc_notice(sa, ...) \
-	SFC_LOG(sa, NOTICE, __VA_ARGS__)
+	do {								\
+		const struct sfc_adapter *_sa = (sa);			\
+									\
+		SFC_LOG(_sa, RTE_LOG_NOTICE, _sa->logtype_main,		\
+			__VA_ARGS__);					\
+	} while (0)
 
 #define sfc_info(sa, ...) \
-	SFC_LOG(sa, INFO, __VA_ARGS__)
+	do {								\
+		const struct sfc_adapter *_sa = (sa);			\
+									\
+		SFC_LOG(_sa, RTE_LOG_INFO, _sa->logtype_main,		\
+			__VA_ARGS__);					\
+	} while (0)
 
 #define sfc_log_init(sa, ...) \
 	do {								\
 		const struct sfc_adapter *_sa = (sa);			\
 									\
 		if (_sa->debug_init)					\
-			SFC_LOG(_sa, INFO,				\
+			SFC_LOG(_sa, RTE_LOG_INFO, _sa->logtype_main,	\
 				RTE_FMT("%s(): "			\
 					RTE_FMT_HEAD(__VA_ARGS__,),	\
 					__func__,			\
-- 
2.7.4

  parent reply	other threads:[~2018-01-25 17:01 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 " 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 ` Andrew Rybchenko [this message]
2018-03-15 15:45   ` [dpdk-dev] [PATCH 3/6] net/sfc: add support for per-port " 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 ` [dpdk-dev] [PATCH v2] eal: register log type and pick level from EAL args Andrew Rybchenko
2018-03-05 15:00 ` [dpdk-dev] [PATCH 0/6] net/sfc: implement dynamic logging 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=1516899647-8541-4-git-send-email-arybchenko@solarflare.com \
    --to=arybchenko@solarflare.com \
    --cc=dev@dpdk.org \
    --cc=ivan.malov@oktetlabs.ru \
    /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).