linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Lobakin <alexandr.lobakin@intel.com>
To: Michal Kubecek <mkubecek@suse.cz>
Cc: "David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Alexander Lobakin <alexandr.lobakin@intel.com>,
	Jesse Brandeburg <jesse.brandeburg@intel.com>,
	Lukasz Czapnik <lukasz.czapnik@intel.com>,
	Marcin Kubiak <marcin.kubiak@intel.com>,
	Michal Kubiak <michal.kubiak@intel.com>,
	Michal Swiatkowski <michal.swiatkowski@intel.com>,
	Jonathan Corbet <corbet@lwn.net>,
	Netanel Belgazal <netanel@amazon.com>,
	Arthur Kiyanovski <akiyano@amazon.com>,
	Guy Tzalik <gtzalik@amazon.com>,
	Saeed Bishara <saeedb@amazon.com>,
	Ioana Ciornei <ioana.ciornei@nxp.com>,
	Claudiu Manoil <claudiu.manoil@nxp.com>,
	Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
	Marcin Wojtas <mw@semihalf.com>,
	Russell King <linux@armlinux.org.uk>,
	Edward Cree <ecree.xilinx@gmail.com>,
	Martin Habets <habetsm.xilinx@gmail.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Jason Wang <jasowang@redhat.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Jesper Dangaard Brouer <hawk@kernel.org>,
	John Fastabend <john.fastabend@gmail.com>,
	Andrii Nakryiko <andrii@kernel.org>,
	Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
	Yonghong Song <yhs@fb.com>, KP Singh <kpsingh@kernel.org>,
	Shay Agroskin <shayagr@amazon.com>,
	Sameeh Jubran <sameehj@amazon.com>,
	Alexander Duyck <alexanderduyck@fb.com>,
	Danielle Ratson <danieller@nvidia.com>,
	Ido Schimmel <idosch@nvidia.com>, Andrew Lunn <andrew@lunn.ch>,
	Vladyslav Tarasiuk <vladyslavt@nvidia.com>,
	Arnd Bergmann <arnd@arndb.de>,
	Andrew Morton <akpm@linux-foundation.org>,
	Jian Shen <shenjian15@huawei.com>,
	Petr Vorel <petr.vorel@gmail.com>, Dan Murphy <dmurphy@ti.com>,
	Yangbo Lu <yangbo.lu@nxp.com>,
	Zheng Yongjun <zhengyongjun3@huawei.com>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	YueHaibing <yuehaibing@huawei.com>,
	Johannes Berg <johannes@sipsolutions.net>,
	netdev@vger.kernel.org, linux-doc@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	virtualization@lists.linux-foundation.org, bpf@vger.kernel.org
Subject: [PATCH ethtool-next 3/5] stats: add support for per-channel statistics [blocks]
Date: Tue,  3 Aug 2021 18:51:38 +0200	[thread overview]
Message-ID: <20210803165140.172-4-alexandr.lobakin@intel.com> (raw)
In-Reply-To: <20210803165140.172-1-alexandr.lobakin@intel.com>

Treat ETHTOOL_A_STATS_GRP_STAT_BLOCK as a block of the standard
stats for one channel and print them prefixed with "channel%u-".
The index will be started from 0 and incremented automatically
for each new attr of that type.
This means that stats blocks should follow each other one by one
according to their channel number, otherwise the output can mess
up with the indices.

Signed-off-by: Alexander Lobakin <alexandr.lobakin@intel.com>
Reviewed-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
---
 netlink/stats.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 63 insertions(+), 4 deletions(-)

diff --git a/netlink/stats.c b/netlink/stats.c
index 9d950b77d656..36a9dad97f15 100644
--- a/netlink/stats.c
+++ b/netlink/stats.c
@@ -87,8 +87,8 @@ err_close_rmon:
 	return 1;
 }
 
-static int parse_stat(const struct nlattr *attr, const char *grp_name,
-		      const struct stringset *stat_str)
+static int parse_stat(const struct nlattr *attr, const char *ch_name,
+		      const char *grp_name, const struct stringset *stat_str)
 {
 	const struct nlattr *stat;
 	unsigned long long val;
@@ -108,8 +108,12 @@ static int parse_stat(const struct nlattr *attr, const char *grp_name,
 	if (!name || !name[0])
 		return 0;
 
-	if (!is_json_context())
+	if (!is_json_context()) {
+		if (ch_name)
+			fprintf(stdout, "%s-", ch_name);
+
 		fprintf(stdout, "%s-%s: ", grp_name, name);
+	}
 
 	val = mnl_attr_get_u64(stat);
 	print_u64(PRINT_ANY, name, "%llu\n", val);
@@ -117,12 +121,62 @@ static int parse_stat(const struct nlattr *attr, const char *grp_name,
 	return 0;
 }
 
+static int parse_one_block(const struct nlattr *block, const char *grp_name,
+			   const struct stringset *stat_str,
+			   unsigned int channel)
+{
+	char ch_name[ETH_GSTRING_LEN];
+	const struct nlattr *attr;
+
+	snprintf(ch_name, sizeof(ch_name), "channel%u", channel);
+	open_json_object(ch_name);
+
+	mnl_attr_for_each_nested(attr, block) {
+		if (mnl_attr_get_type(attr) != ETHTOOL_A_STATS_GRP_STAT ||
+		    parse_stat(attr, ch_name, grp_name, stat_str))
+			goto err_close_block;
+	}
+
+	close_json_object();
+
+	return 0;
+
+err_close_block:
+	close_json_object();
+
+	return 1;
+}
+
+static int parse_blocks(const struct nlattr *grp, const char *grp_name,
+			const struct stringset *stat_str)
+{
+	const struct nlattr *attr;
+	unsigned int channel = 0;
+
+	open_json_array("per-channel", "");
+
+	mnl_attr_for_each_nested(attr, grp) {
+		if (mnl_attr_get_type(attr) == ETHTOOL_A_STATS_GRP_STAT_BLOCK &&
+		    parse_one_block(attr, grp_name, stat_str, channel++))
+			goto err_close_block;
+	}
+
+	close_json_array("");
+
+	return 0;
+
+err_close_block:
+	close_json_array("");
+
+	return 1;
+}
+
 static int parse_grp(struct nl_context *nlctx, const struct nlattr *grp,
 		     const struct stringset *std_str)
 {
 	const struct nlattr *tb[ETHTOOL_A_STATS_GRP_SS_ID + 1] = {};
 	DECLARE_ATTR_TB_INFO(tb);
-	bool hist_rx = false, hist_tx = false;
+	bool hist_rx = false, hist_tx = false, blocks = false;
 	const struct stringset *stat_str;
 	const struct nlattr *attr;
 	unsigned int ss_id, id;
@@ -156,6 +210,9 @@ static int parse_grp(struct nl_context *nlctx, const struct nlattr *grp,
 		case ETHTOOL_A_STATS_GRP_HIST_TX:
 			hist_tx = true;
 			continue;
+		case ETHTOOL_A_STATS_GRP_STAT_BLOCK:
+			blocks = true;
+			continue;
 		default:
 			continue;
 		}
@@ -170,6 +227,8 @@ static int parse_grp(struct nl_context *nlctx, const struct nlattr *grp,
 	if (hist_tx)
 		parse_rmon_hist(grp, std_name, "tx-pktsNtoM", "tx",
 				ETHTOOL_A_STATS_GRP_HIST_TX);
+	if (blocks)
+		parse_blocks(grp, std_name, stat_str);
 
 	close_json_object();
 
-- 
2.31.1


  parent reply	other threads:[~2021-08-03 16:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-03 16:51 [PATCH ethtool-next 0/5] stats: add support for per-channel and XDP standard stats Alexander Lobakin
2021-08-03 16:51 ` [PATCH ethtool-next 1/5] sync UAPI header copies Alexander Lobakin
2021-08-03 16:51 ` [PATCH ethtool-next 2/5] stats: factor out one stat field printing Alexander Lobakin
2021-08-03 16:51 ` Alexander Lobakin [this message]
2021-08-03 16:51 ` [PATCH ethtool-next 4/5] man: fix typo for "rmon" standard stat type Alexander Lobakin
2021-08-03 16:51 ` [PATCH ethtool-next 5/5] man: mention XDP standard statistics in help and man page Alexander Lobakin

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=20210803165140.172-4-alexandr.lobakin@intel.com \
    --to=alexandr.lobakin@intel.com \
    --cc=akiyano@amazon.com \
    --cc=akpm@linux-foundation.org \
    --cc=alexanderduyck@fb.com \
    --cc=andrew@lunn.ch \
    --cc=andrii@kernel.org \
    --cc=arnd@arndb.de \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=claudiu.manoil@nxp.com \
    --cc=corbet@lwn.net \
    --cc=daniel@iogearbox.net \
    --cc=danieller@nvidia.com \
    --cc=davem@davemloft.net \
    --cc=dmurphy@ti.com \
    --cc=ecree.xilinx@gmail.com \
    --cc=gtzalik@amazon.com \
    --cc=habetsm.xilinx@gmail.com \
    --cc=hawk@kernel.org \
    --cc=hkallweit1@gmail.com \
    --cc=idosch@nvidia.com \
    --cc=ioana.ciornei@nxp.com \
    --cc=jasowang@redhat.com \
    --cc=jesse.brandeburg@intel.com \
    --cc=johannes@sipsolutions.net \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=kpsingh@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=lukasz.czapnik@intel.com \
    --cc=marcin.kubiak@intel.com \
    --cc=michal.kubiak@intel.com \
    --cc=michal.swiatkowski@intel.com \
    --cc=mkubecek@suse.cz \
    --cc=mst@redhat.com \
    --cc=mw@semihalf.com \
    --cc=netanel@amazon.com \
    --cc=netdev@vger.kernel.org \
    --cc=petr.vorel@gmail.com \
    --cc=saeedb@amazon.com \
    --cc=sameehj@amazon.com \
    --cc=shayagr@amazon.com \
    --cc=shenjian15@huawei.com \
    --cc=songliubraving@fb.com \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=vladyslavt@nvidia.com \
    --cc=yangbo.lu@nxp.com \
    --cc=yhs@fb.com \
    --cc=yuehaibing@huawei.com \
    --cc=zhengyongjun3@huawei.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).