DPDK patches and discussions
 help / color / mirror / Atom feed
From: Bruce Richardson <bruce.richardson@intel.com>
To: Kevin Laatz <kevin.laatz@intel.com>
Cc: dev@dpdk.org, Bruce Richardson <bruce.richardson@intel.com>,
	stable@dpdk.org
Subject: [dpdk-dev] [PATCH] telemetry: fix error when using ports of different types
Date: Wed, 19 Dec 2018 11:59:50 +0000	[thread overview]
Message-ID: <20181219115950.46386-1-bruce.richardson@intel.com> (raw)

Different NIC ports can have different numbers of xstats on them, which
means that we can't just use the xstats list from the first port registered
in the telemetry library. Instead, we need to check the type of each port -
by checking its ops structure pointer - and register each port type once
with the metrics lib.

CC: stable@dpdk.org
Fixes: fdbdb3f9ce46 ("telemetry: add initial connection socket")

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 lib/librte_telemetry/rte_telemetry.c          | 40 ++++++++++++++-----
 lib/librte_telemetry/rte_telemetry_internal.h |  2 +-
 2 files changed, 32 insertions(+), 10 deletions(-)

diff --git a/lib/librte_telemetry/rte_telemetry.c b/lib/librte_telemetry/rte_telemetry.c
index 016431f12..7fb247eaa 100644
--- a/lib/librte_telemetry/rte_telemetry.c
+++ b/lib/librte_telemetry/rte_telemetry.c
@@ -558,7 +558,7 @@ rte_telemetry_send_ports_stats_values(uint32_t *metric_ids, int num_metric_ids,
 		}
 
 		ret = rte_telemetry_update_metrics_ethdev(telemetry,
-				port_ids[i], telemetry->reg_index);
+				port_ids[i], telemetry->reg_index[i]);
 		if (ret < 0) {
 			TELEMETRY_LOG_ERR("Failed to update ethdev metrics");
 			return -1;
@@ -658,23 +658,45 @@ rte_telemetry_reg_ethdev_to_metrics(uint16_t port_id)
 static int32_t
 rte_telemetry_initial_accept(struct telemetry_impl *telemetry)
 {
+	struct driver_index {
+		const void *dev_ops;
+		int reg_index;
+	} drv_idx[RTE_MAX_ETHPORTS];
+	int nb_drv_idx = 0;
 	uint16_t pid;
 	int ret;
 	int selftest = 0;
 
 	RTE_ETH_FOREACH_DEV(pid) {
-		telemetry->reg_index = rte_telemetry_reg_ethdev_to_metrics(pid);
-		break;
-	}
+		int i;
+		/* Different device types have different numbers of stats, so
+		 * first check if the stats for this type of device have
+		 * already been registered
+		 */
+		for (i = 0; i < nb_drv_idx; i++) {
+			if (rte_eth_devices[pid].dev_ops == drv_idx[i].dev_ops) {
+				telemetry->reg_index[pid] = drv_idx[i].reg_index;
+				break;
+			}
+		}
+		if (i < nb_drv_idx)
+			continue; /* we found a match, go to next port */
 
-	if (telemetry->reg_index < 0) {
-		TELEMETRY_LOG_ERR("Failed to register ethdev metrics");
-		return -1;
+		/* No match, register a new set of xstats for this port */
+		ret = rte_telemetry_reg_ethdev_to_metrics(pid);
+		if (ret < 0) {
+			TELEMETRY_LOG_ERR("Failed to register ethdev metrics");
+			return -1;
+		}
+		telemetry->reg_index[pid] = ret;
+		drv_idx[nb_drv_idx].dev_ops = rte_eth_devices[pid].dev_ops;
+		drv_idx[nb_drv_idx].reg_index = ret;
+		nb_drv_idx++;
 	}
 
 	telemetry->metrics_register_done = 1;
 	if (selftest) {
-		ret = rte_telemetry_socket_messaging_testing(telemetry->reg_index,
+		ret = rte_telemetry_socket_messaging_testing(telemetry->reg_index[0],
 				telemetry->server_fd);
 		if (ret < 0)
 			return -1;
@@ -1299,7 +1321,7 @@ rte_telemetry_socket_messaging_testing(int index, int socket)
 	}
 
 	telemetry->server_fd = socket;
-	telemetry->reg_index = index;
+	telemetry->reg_index[0] = index;
 	TELEMETRY_LOG_INFO("Beginning Telemetry socket message Selftest");
 	rte_telemetry_socket_test_setup(telemetry, &send_fd, &recv_fd);
 	TELEMETRY_LOG_INFO("Register valid client test");
diff --git a/lib/librte_telemetry/rte_telemetry_internal.h b/lib/librte_telemetry/rte_telemetry_internal.h
index de7afda30..c298c3919 100644
--- a/lib/librte_telemetry/rte_telemetry_internal.h
+++ b/lib/librte_telemetry/rte_telemetry_internal.h
@@ -36,7 +36,7 @@ typedef struct telemetry_impl {
 	pthread_t thread_id;
 	int thread_status;
 	uint32_t socket_id;
-	int reg_index;
+	int reg_index[RTE_MAX_ETHPORTS];
 	int metrics_register_done;
 	TAILQ_HEAD(, telemetry_client) client_list_head;
 	struct telemetry_client *request_client;
-- 
2.19.2

             reply	other threads:[~2018-12-19 12:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-19 11:59 Bruce Richardson [this message]
2018-12-20 23:51 ` Thomas Monjalon
2018-12-21 13:27 ` Laatz, Kevin
2018-12-21 15:33   ` [dpdk-dev] [dpdk-stable] " 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=20181219115950.46386-1-bruce.richardson@intel.com \
    --to=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=kevin.laatz@intel.com \
    --cc=stable@dpdk.org \
    /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).