DPDK patches and discussions
 help / color / mirror / Atom feed
From: Srikanth Kaka <srikanth.k@oneconvergence.com>
To: Matan Azrad <matan@nvidia.com>,
	Viacheslav Ovsiienko <viacheslavo@nvidia.com>
Cc: dev@dpdk.org, Vag Singh <vag.singh@oneconvergence.com>,
	Anand Thulasiram <avelu@juniper.net>,
	Srikanth Kaka <srikanth.k@oneconvergence.com>
Subject: [dpdk-dev] [PATCH v2 29/41] net/mlx5: added stats support
Date: Fri,  8 Oct 2021 00:13:38 +0530	[thread overview]
Message-ID: <20211007184350.73858-30-srikanth.k@oneconvergence.com> (raw)
In-Reply-To: <20211007184350.73858-1-srikanth.k@oneconvergence.com>

Initialize device stats and fetch them using sysctl.

Signed-off-by: Srikanth Kaka <srikanth.k@oneconvergence.com>
Signed-off-by: Vag Singh <vag.singh@oneconvergence.com>
Signed-off-by: Anand Thulasiram <avelu@juniper.net>
---
 drivers/net/mlx5/freebsd/mlx5_ethdev_os.c | 217 ++++++++++++++++++++++
 1 file changed, 217 insertions(+)

diff --git a/drivers/net/mlx5/freebsd/mlx5_ethdev_os.c b/drivers/net/mlx5/freebsd/mlx5_ethdev_os.c
index db16027244..a6e28ea4bb 100644
--- a/drivers/net/mlx5/freebsd/mlx5_ethdev_os.c
+++ b/drivers/net/mlx5/freebsd/mlx5_ethdev_os.c
@@ -6,6 +6,7 @@
 #include <stdio.h>
 #include <stdint.h>
 #include <net/if_media.h>
+#include <sys/sysctl.h>
 #include <sys/ioctl.h>
 #include <time.h>
 
@@ -18,6 +19,8 @@
 
 #include "mlx5.h"
 
+static unsigned int xstats_n;
+
 /**
  * Get interface name from private structure.
  *
@@ -721,6 +724,220 @@ int mlx5_get_module_eeprom(struct rte_eth_dev *dev,
 	return -ENOTSUP;
 }
 
+/**
+ * Read device counters table.
+ *
+ * @param dev
+ *   Pointer to Ethernet device.
+ * @param[in] pf
+ *   PF index in case of bonding device, -1 otherwise
+ * @param[out] stats
+ *   Counters table output buffer.
+ */
+static void
+_mlx5_os_read_dev_counters(struct rte_eth_dev *dev, uint64_t *stats)
+{
+	struct mlx5_priv *priv = dev->data->dev_private;
+	struct mlx5_xstats_ctrl *xstats_ctrl = &priv->xstats_ctrl;
+	char stat_key[RTE_ETH_XSTATS_NAME_SIZE + 16];
+	unsigned int i;
+	size_t len = sizeof(uint64_t);
+	uint64_t val;
+	int ibvindex, ret;
+
+	ibvindex = mlx5_get_ibvindex(priv->sh->ibdev_path);
+
+	for (i = 0; i != xstats_ctrl->mlx5_stats_n; ++i) {
+		snprintf(stat_key, sizeof(stat_key), "dev.mce.%d.%s",
+			 ibvindex, xstats_ctrl->info[i].ctr_name);
+		ret = sysctlbyname(stat_key, &val, &len, NULL, 0);
+		if (ret == -1) {
+			DRV_LOG(WARNING, "port %u failed to get statistics: %s",
+				dev->data->port_id, strerror(errno));
+			continue;
+		}
+		stats[i] += val;
+	}
+}
+
+/**
+ * Read device counters.
+ *
+ * @param dev
+ *   Pointer to Ethernet device.
+ * @param[out] stats
+ *   Counters table output buffer.
+ */
+int
+mlx5_os_read_dev_counters(struct rte_eth_dev *dev, uint64_t *stats)
+{
+	struct mlx5_priv *priv = dev->data->dev_private;
+	struct mlx5_xstats_ctrl *xstats_ctrl = &priv->xstats_ctrl;
+	int i;
+
+	memset(stats, 0, sizeof(*stats) * xstats_ctrl->mlx5_stats_n);
+	_mlx5_os_read_dev_counters(dev, stats);
+	/* Read IB counters. */
+	for (i = 0; i != xstats_ctrl->mlx5_stats_n; ++i) {
+		if (!xstats_ctrl->info[i].dev)
+			continue;
+		xstats_ctrl->xstats[i] = stats[i];
+	}
+	return 0;
+}
+
+/**
+ * Query the number of statistics.
+ *
+ * @param dev
+ *   Pointer to Ethernet device.
+ *
+ * @return
+ *   Number of statistics on success.
+ */
+int
+mlx5_os_get_stats_n(struct rte_eth_dev *dev)
+{
+	RTE_SET_USED(dev);
+	return xstats_n;
+}
+
+static const struct mlx5_counter_ctrl mlx5_counters_init[] = {
+	{
+		.dpdk_name = "rx_port_unicast_bytes",
+		.ctr_name = "vstats.rx_unicast_bytes",
+	},
+	{
+		.dpdk_name = "rx_port_multicast_bytes",
+		.ctr_name = "vstats.rx_multicast_bytes",
+	},
+	{
+		.dpdk_name = "rx_port_broadcast_bytes",
+		.ctr_name = "vstats.rx_broadcast_bytes",
+	},
+	{
+		.dpdk_name = "rx_port_unicast_packets",
+		.ctr_name = "vstats.rx_unicast_packets",
+	},
+	{
+		.dpdk_name = "rx_port_multicast_packets",
+		.ctr_name = "vstats.rx_multicast_packets",
+	},
+	{
+		.dpdk_name = "rx_port_broadcast_packets",
+		.ctr_name = "vstats.rx_broadcast_packets",
+	},
+	{
+		.dpdk_name = "tx_port_unicast_bytes",
+		.ctr_name = "vstats.tx_unicast_bytes",
+	},
+	{
+		.dpdk_name = "tx_port_multicast_bytes",
+		.ctr_name = "vstats.tx_multicast_bytes",
+	},
+	{
+		.dpdk_name = "tx_port_broadcast_bytes",
+		.ctr_name = "vstats.tx_broadcast_bytes",
+	},
+	{
+		.dpdk_name = "tx_port_unicast_packets",
+		.ctr_name = "vstats.tx_unicast_packets",
+	},
+	{
+		.dpdk_name = "tx_port_multicast_packets",
+		.ctr_name = "vstats.tx_multicast_packets",
+	},
+	{
+		.dpdk_name = "tx_port_broadcast_packets",
+		.ctr_name = "vstats.tx_broadcast_packets",
+	},
+	{
+		.dpdk_name = "rx_wqe_err",
+		.ctr_name = "vstats.rx_wqe_err",
+	},
+	{
+		.dpdk_name = "rx_crc_align_errors",
+		.ctr_name = "pstats.crc_align_errors",
+	},
+	{
+		.dpdk_name = "rx_in_range_len_errors",
+		.ctr_name = "pstats.in_range_len_errors",
+	},
+	{
+		.dpdk_name = "rx_symbol_err",
+		.ctr_name = "pstats.symbol_err",
+	},
+	{
+		.dpdk_name = "tx_errors_packets",
+		.ctr_name = "vstats.tx_error_packets",
+	},
+	{
+		.dpdk_name = "rx_out_of_buffer",
+		.ctr_name = "vstats.rx_out_of_buffer",
+	},
+	{
+		.dpdk_name = "lro_bytes",
+		.ctr_name = "vstats.lro_bytes",
+	},
+	{
+		.dpdk_name = "lro_packets",
+		.ctr_name = "vstats.lro_packets",
+	},
+	{
+		.dpdk_name = "tso_bytes",
+		.ctr_name = "vstats.tso_bytes",
+	},
+	{
+		.dpdk_name = "tso_packets",
+		.ctr_name = "vstats.tso_packets",
+	},
+	/* Representor only */
+	{
+		.dpdk_name = "rx_packets",
+		.ctr_name = "vstats.rx_packets",
+	},
+	{
+		.dpdk_name = "rx_bytes",
+		.ctr_name = "vstats.rx_bytes",
+	},
+	{
+		.dpdk_name = "tx_packets",
+		.ctr_name = "vstats.tx_packets",
+	},
+	{
+		.dpdk_name = "tx_bytes",
+		.ctr_name = "vstats.tx_bytes",
+	},
+};
+
+/**
+ * Init the structures to read device counters.
+ *
+ * @param dev
+ *   Pointer to Ethernet device.
+ */
+void
+mlx5_os_stats_init(struct rte_eth_dev *dev)
+{
+	struct mlx5_priv *priv = dev->data->dev_private;
+	struct mlx5_xstats_ctrl *xstats_ctrl = &priv->xstats_ctrl;
+	struct mlx5_stats_ctrl *stats_ctrl = &priv->stats_ctrl;
+	unsigned int i, idx;
+
+	xstats_n = RTE_DIM(mlx5_counters_init);
+	xstats_ctrl->mlx5_stats_n = 0;
+
+	for (i = 0; i != xstats_n; ++i) {
+		idx = xstats_ctrl->mlx5_stats_n++;
+
+		xstats_ctrl->dev_table_idx[idx] = i;
+		xstats_ctrl->info[idx] = mlx5_counters_init[i];
+	}
+	xstats_ctrl->stats_n = xstats_n;
+	mlx5_os_read_dev_counters(dev, xstats_ctrl->base);
+	stats_ctrl->imissed = 0;
+}
+
 /**
  * Get MAC address by querying netdevice.
  *
-- 
2.30.2


  parent reply	other threads:[~2021-10-08 10:58 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-07 18:43 [dpdk-dev] [PATCH v2 00/41] add MLX5 FreeBSD support Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 01/41] common/mlx5: add glue files for FreeBSD Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 02/41] common/mlx5: add memory APIs Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 03/41] common/mlx5: add FreeBSD getter functions Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 04/41] common/mlx5: add mlx5_glue_constructor Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 05/41] common/mlx5: add meson support for FreeBSD Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 06/41] net/mlx5: implement device attribute getter Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 07/41] common/mlx5: retrieve the device index and name Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 08/41] common/mlx5: derive PCI addr from device path Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 09/41] net/mlx5: get the FreeBSD interface name Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 10/41] net/mlx5: socket for inter-process communication Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 11/41] common/mlx5: add mr reg/dereg API Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 12/41] net/mlx5: add helpers for MR & HW operations Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 13/41] net/mlx5: define MR callbacks Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 14/41] net/mlx5: add open IB device routines Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 15/41] common/mlx5: add PF_INET socket interface Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 16/41] common/mlx5: add VLAN vmwa structures Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 17/41] net/mlx5: add vlan vmwa stub Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 18/41] net/mlx5: add get MAC Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 19/41] net/mlx5: add get MTU Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 20/41] net/mlx5: add OS MAC routines Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 21/41] net/mlx5: add set MTU routine Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 22/41] net/mlx5: add link state callbacks Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 23/41] net/mlx5: add link update callback Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 24/41] net/mlx5: read device clock Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 25/41] net/mlx5: handle async device events Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 26/41] net/mlx5: add callback to check dev is removed Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 27/41] net/mlx5: add flow control callbacks Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 28/41] net/mlx5: add module callbacks Srikanth Kaka
2021-10-07 18:43 ` Srikanth Kaka [this message]
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 30/41] net/mlx5: add stubs for bonding Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 31/41] net/mlx5: add stub to read hw counters Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 32/41] net/mlx5: add multiprocess support Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 33/41] net/mlx5: add initialization routines Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 34/41] net/mlx5: add flow workspace APIs Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 35/41] net/mlx5: add pci probe and dev spawn support Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 36/41] net/mlx5: set file descriptor as non-blocking Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 37/41] net/mlx5: add routine to extract pdn Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 38/41] net/mlx5: set promisc and allmulti modes Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 39/41] common/mlx5: add stub for mlx5_translate_port_name Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 40/41] net/mlx5: add meson support for FreeBSD Srikanth Kaka
2021-10-07 18:43 ` [dpdk-dev] [PATCH v2 41/41] doc/mlx5: update docs with FreeBSD information Srikanth Kaka
2022-05-18  8:21 ` [dpdk-dev] [PATCH v2 00/41] add MLX5 FreeBSD support 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=20211007184350.73858-30-srikanth.k@oneconvergence.com \
    --to=srikanth.k@oneconvergence.com \
    --cc=avelu@juniper.net \
    --cc=dev@dpdk.org \
    --cc=matan@nvidia.com \
    --cc=vag.singh@oneconvergence.com \
    --cc=viacheslavo@nvidia.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).