Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH ethtool-next 0/5] stats: add support for per-channel and XDP standard stats
@ 2021-08-03 16:51 Alexander Lobakin
  2021-08-03 16:51 ` [PATCH ethtool-next 1/5] sync UAPI header copies Alexander Lobakin
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Alexander Lobakin @ 2021-08-03 16:51 UTC (permalink / raw)
  To: Michal Kubecek
  Cc: David S. Miller, Jakub Kicinski, Alexander Lobakin,
	Jesse Brandeburg, Lukasz Czapnik, Marcin Kubiak, Michal Kubiak,
	Michal Swiatkowski, Jonathan Corbet, Netanel Belgazal,
	Arthur Kiyanovski, Guy Tzalik, Saeed Bishara, Ioana Ciornei,
	Claudiu Manoil, Thomas Petazzoni, Marcin Wojtas, Russell King,
	Edward Cree, Martin Habets, Michael S. Tsirkin, Jason Wang,
	Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
	John Fastabend, Andrii Nakryiko, Martin KaFai Lau, Song Liu,
	Yonghong Song, KP Singh, Shay Agroskin, Sameeh Jubran,
	Alexander Duyck, Danielle Ratson, Ido Schimmel, Andrew Lunn,
	Vladyslav Tarasiuk, Arnd Bergmann, Andrew Morton, Jian Shen,
	Petr Vorel, Dan Murphy, Yangbo Lu, Zheng Yongjun,
	Heiner Kallweit, YueHaibing, Johannes Berg, netdev, linux-doc,
	linux-kernel, virtualization, bpf

This series adds bits to support per-channel standard statistics,
mentions the new "xdp" group of standard stats landed in Linux with
commit 44eee6116fda ("ethtool, stats: introduce standard XDP statistics")
and fixes one typo in the man page while at it.

The original series for the kernel part is here: [0]

[0] https://lore.kernel.org/netdev/20210803163641.3743-1-alexandr.lobakin@intel.com

Alexander Lobakin (5):
  sync UAPI header copies
  stats: factor out one stat field printing
  stats: add support for per-channel statistics [blocks]
  man: fix typo for "rmon" standard stat type
  man: mention XDP standard statistics in help and man page

 ethtool.8.in                 |   5 +-
 ethtool.c                    |   2 +-
 netlink/stats.c              | 114 +++++++++++++++++++++++++++++------
 uapi/linux/ethtool.h         |   6 +-
 uapi/linux/ethtool_netlink.h |  51 +++++++++++++++-
 uapi/linux/if_link.h         |  20 ++++++
 uapi/linux/net_tstamp.h      |  17 +++++-
 uapi/linux/netlink.h         |   5 +-
 8 files changed, 190 insertions(+), 30 deletions(-)

-- 
2.31.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH ethtool-next 1/5] sync UAPI header copies
  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 ` Alexander Lobakin
  2021-08-03 16:51 ` [PATCH ethtool-next 2/5] stats: factor out one stat field printing Alexander Lobakin
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Alexander Lobakin @ 2021-08-03 16:51 UTC (permalink / raw)
  To: Michal Kubecek
  Cc: David S. Miller, Jakub Kicinski, Alexander Lobakin,
	Jesse Brandeburg, Lukasz Czapnik, Marcin Kubiak, Michal Kubiak,
	Michal Swiatkowski, Jonathan Corbet, Netanel Belgazal,
	Arthur Kiyanovski, Guy Tzalik, Saeed Bishara, Ioana Ciornei,
	Claudiu Manoil, Thomas Petazzoni, Marcin Wojtas, Russell King,
	Edward Cree, Martin Habets, Michael S. Tsirkin, Jason Wang,
	Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
	John Fastabend, Andrii Nakryiko, Martin KaFai Lau, Song Liu,
	Yonghong Song, KP Singh, Shay Agroskin, Sameeh Jubran,
	Alexander Duyck, Danielle Ratson, Ido Schimmel, Andrew Lunn,
	Vladyslav Tarasiuk, Arnd Bergmann, Andrew Morton, Jian Shen,
	Petr Vorel, Dan Murphy, Yangbo Lu, Zheng Yongjun,
	Heiner Kallweit, YueHaibing, Johannes Berg, netdev, linux-doc,
	linux-kernel, virtualization, bpf

+ commit e1d9a90a9bfd ("net: ethernet: rmnet: Support for ingress MAPv5 checksum offload")
+ commit b6e5d27e32ef ("net: ethernet: rmnet: Add support for MAPv5 egress packets")
+ commit d409989b59ad ("netlink: simplify NLMSG_DATA with NLMSG_HDRLEN")
+ commit 00e77ed8e64d ("rtnetlink: add IFLA_PARENT_[DEV|DEV_BUS]_NAME")
+ commit 2d8ea148e553 ("net: fix mistake path for netdev_features_strings")
+ commit 913d026fbfaf ("ethtool: Document correct attribute type")
+ commit d463126e23f1 ("net: sock: extend SO_TIMESTAMPING for PHC binding")
+ commit c156174a6707 ("ethtool: add a new command for getting PHC virtual clocks")
+ commit 583be982d934 ("mctp: Add device handling and netlink interface")
+ commit 3a755cd8b7c6 ("bonding: add new option lacp_active")
+ commit 44eee6116fda ("ethtool, stats: introduce standard XDP statistics")

Signed-off-by: Alexander Lobakin <alexandr.lobakin@intel.com>
Reviewed-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
---
 uapi/linux/ethtool.h         |  6 +++--
 uapi/linux/ethtool_netlink.h | 51 +++++++++++++++++++++++++++++++++++-
 uapi/linux/if_link.h         | 20 ++++++++++++++
 uapi/linux/net_tstamp.h      | 17 ++++++++++--
 uapi/linux/netlink.h         |  5 ++--
 5 files changed, 92 insertions(+), 7 deletions(-)

diff --git a/uapi/linux/ethtool.h b/uapi/linux/ethtool.h
index c6ec1111ffa3..898bce1b08b0 100644
--- a/uapi/linux/ethtool.h
+++ b/uapi/linux/ethtool.h
@@ -231,7 +231,7 @@ enum tunable_id {
 	ETHTOOL_PFC_PREVENTION_TOUT, /* timeout in msecs */
 	/*
 	 * Add your fresh new tunable attribute above and remember to update
-	 * tunable_strings[] in net/core/ethtool.c
+	 * tunable_strings[] in net/ethtool/common.c
 	 */
 	__ETHTOOL_TUNABLE_COUNT,
 };
@@ -295,7 +295,7 @@ enum phy_tunable_id {
 	ETHTOOL_PHY_EDPD,
 	/*
 	 * Add your fresh new phy tunable attribute above and remember to update
-	 * phy_tunable_strings[] in net/core/ethtool.c
+	 * phy_tunable_strings[] in net/ethtool/common.c
 	 */
 	__ETHTOOL_PHY_TUNABLE_COUNT,
 };
@@ -672,6 +672,7 @@ enum ethtool_link_ext_substate_cable_issue {
  * @ETH_SS_STATS_ETH_MAC: names of IEEE 802.3 MAC statistics
  * @ETH_SS_STATS_ETH_CTRL: names of IEEE 802.3 MAC Control statistics
  * @ETH_SS_STATS_RMON: names of RMON statistics
+ * @ETH_SS_STATS_XDP: names of XDP statistics
  *
  * @ETH_SS_COUNT: number of defined string sets
  */
@@ -697,6 +698,7 @@ enum ethtool_stringset {
 	ETH_SS_STATS_ETH_MAC,
 	ETH_SS_STATS_ETH_CTRL,
 	ETH_SS_STATS_RMON,
+	ETH_SS_STATS_XDP,
 
 	/* add new constants above here */
 	ETH_SS_COUNT
diff --git a/uapi/linux/ethtool_netlink.h b/uapi/linux/ethtool_netlink.h
index 4653c4c79972..acb1e93084ac 100644
--- a/uapi/linux/ethtool_netlink.h
+++ b/uapi/linux/ethtool_netlink.h
@@ -46,6 +46,7 @@ enum {
 	ETHTOOL_MSG_FEC_SET,
 	ETHTOOL_MSG_MODULE_EEPROM_GET,
 	ETHTOOL_MSG_STATS_GET,
+	ETHTOOL_MSG_PHC_VCLOCKS_GET,
 
 	/* add new constants above here */
 	__ETHTOOL_MSG_USER_CNT,
@@ -88,6 +89,7 @@ enum {
 	ETHTOOL_MSG_FEC_NTF,
 	ETHTOOL_MSG_MODULE_EEPROM_GET_REPLY,
 	ETHTOOL_MSG_STATS_GET_REPLY,
+	ETHTOOL_MSG_PHC_VCLOCKS_GET_REPLY,
 
 	/* add new constants above here */
 	__ETHTOOL_MSG_KERNEL_CNT,
@@ -440,6 +442,19 @@ enum {
 	ETHTOOL_A_TSINFO_MAX = (__ETHTOOL_A_TSINFO_CNT - 1)
 };
 
+/* PHC VCLOCKS */
+
+enum {
+	ETHTOOL_A_PHC_VCLOCKS_UNSPEC,
+	ETHTOOL_A_PHC_VCLOCKS_HEADER,			/* nest - _A_HEADER_* */
+	ETHTOOL_A_PHC_VCLOCKS_NUM,			/* u32 */
+	ETHTOOL_A_PHC_VCLOCKS_INDEX,			/* array, s32 */
+
+	/* add new constants above here */
+	__ETHTOOL_A_PHC_VCLOCKS_CNT,
+	ETHTOOL_A_PHC_VCLOCKS_MAX = (__ETHTOOL_A_PHC_VCLOCKS_CNT - 1)
+};
+
 /* CABLE TEST */
 
 enum {
@@ -675,7 +690,7 @@ enum {
 	ETHTOOL_A_MODULE_EEPROM_PAGE,			/* u8 */
 	ETHTOOL_A_MODULE_EEPROM_BANK,			/* u8 */
 	ETHTOOL_A_MODULE_EEPROM_I2C_ADDRESS,		/* u8 */
-	ETHTOOL_A_MODULE_EEPROM_DATA,			/* nested */
+	ETHTOOL_A_MODULE_EEPROM_DATA,			/* binary */
 
 	__ETHTOOL_A_MODULE_EEPROM_CNT,
 	ETHTOOL_A_MODULE_EEPROM_MAX = (__ETHTOOL_A_MODULE_EEPROM_CNT - 1)
@@ -701,6 +716,7 @@ enum {
 	ETHTOOL_STATS_ETH_MAC,
 	ETHTOOL_STATS_ETH_CTRL,
 	ETHTOOL_STATS_RMON,
+	ETHTOOL_STATS_XDP,
 
 	/* add new constants above here */
 	__ETHTOOL_STATS_CNT
@@ -722,6 +738,8 @@ enum {
 	ETHTOOL_A_STATS_GRP_HIST_BKT_HI,	/* u32 */
 	ETHTOOL_A_STATS_GRP_HIST_VAL,		/* u64 */
 
+	ETHTOOL_A_STATS_GRP_STAT_BLOCK,		/* nest */
+
 	/* add new constants above here */
 	__ETHTOOL_A_STATS_GRP_CNT,
 	ETHTOOL_A_STATS_GRP_MAX = (__ETHTOOL_A_STATS_CNT - 1)
@@ -816,6 +834,37 @@ enum {
 	ETHTOOL_A_STATS_RMON_MAX = (__ETHTOOL_A_STATS_RMON_CNT - 1)
 };
 
+enum {
+	/* Number of frames passed to bpf_prog_run_xdp() */
+	ETHTOOL_A_STATS_XDP_PACKETS,
+	/* Number o general XDP errors if driver counts them together */
+	ETHTOOL_A_STATS_XDP_ERRORS,
+	/* Number of %XDP_ABORTED returns */
+	ETHTOOL_A_STATS_XDP_ABORTED,
+	/* Number of %XDP_DROP returns */
+	ETHTOOL_A_STATS_XDP_DROP,
+	/* Number of returns of unallowed values (i.e. not XDP_*) */
+	ETHTOOL_A_STATS_XDP_INVALID,
+	/* Number of %XDP_PASS returns */
+	ETHTOOL_A_STATS_XDP_PASS,
+	/* Number of successfully performed %XDP_REDIRECT requests */
+	ETHTOOL_A_STATS_XDP_REDIRECT,
+	/* Number of failed %XDP_REDIRECT requests */
+	ETHTOOL_A_STATS_XDP_REDIRECT_ERRORS,
+	/* Number of successfully performed %XDP_TX requests */
+	ETHTOOL_A_STATS_XDP_TX,
+	/* Number of failed %XDP_TX requests */
+	ETHTOOL_A_STATS_XDP_TX_ERRORS,
+	/* Number of xdp_frames successfully transmitted via .ndo_xdp_xmit() */
+	ETHTOOL_A_STATS_XDP_XMIT,
+	/* Number of frames dropped from .ndo_xdp_xmit() */
+	ETHTOOL_A_STATS_XDP_XMIT_DROPS,
+
+	/* Add new constants above here */
+	__ETHTOOL_A_STATS_XDP_CNT,
+	ETHTOOL_A_STATS_XDP_MAX = (__ETHTOOL_A_STATS_XDP_CNT - 1)
+};
+
 /* generic netlink info */
 #define ETHTOOL_GENL_NAME "ethtool"
 #define ETHTOOL_GENL_VERSION 1
diff --git a/uapi/linux/if_link.h b/uapi/linux/if_link.h
index 0e81707a9637..fb2ecf403a16 100644
--- a/uapi/linux/if_link.h
+++ b/uapi/linux/if_link.h
@@ -341,6 +341,13 @@ enum {
 	IFLA_ALT_IFNAME, /* Alternative ifname */
 	IFLA_PERM_ADDRESS,
 	IFLA_PROTO_DOWN_REASON,
+
+	/* device (sysfs) name as parent, used instead
+	 * of IFLA_LINK where there's no parent netdev
+	 */
+	IFLA_PARENT_DEV_NAME,
+	IFLA_PARENT_DEV_BUS_NAME,
+
 	__IFLA_MAX
 };
 
@@ -846,6 +853,7 @@ enum {
 	IFLA_BOND_AD_ACTOR_SYSTEM,
 	IFLA_BOND_TLB_DYNAMIC_LB,
 	IFLA_BOND_PEER_NOTIF_DELAY,
+	IFLA_BOND_AD_LACP_ACTIVE,
 	__IFLA_BOND_MAX,
 };
 
@@ -1234,6 +1242,8 @@ enum {
 #define RMNET_FLAGS_INGRESS_MAP_COMMANDS          (1U << 1)
 #define RMNET_FLAGS_INGRESS_MAP_CKSUMV4           (1U << 2)
 #define RMNET_FLAGS_EGRESS_MAP_CKSUMV4            (1U << 3)
+#define RMNET_FLAGS_INGRESS_MAP_CKSUMV5           (1U << 4)
+#define RMNET_FLAGS_EGRESS_MAP_CKSUMV5            (1U << 5)
 
 enum {
 	IFLA_RMNET_UNSPEC,
@@ -1249,4 +1259,14 @@ struct ifla_rmnet_flags {
 	__u32	mask;
 };
 
+/* MCTP section */
+
+enum {
+	IFLA_MCTP_UNSPEC,
+	IFLA_MCTP_NET,
+	__IFLA_MCTP_MAX,
+};
+
+#define IFLA_MCTP_MAX (__IFLA_MCTP_MAX - 1)
+
 #endif /* _LINUX_IF_LINK_H */
diff --git a/uapi/linux/net_tstamp.h b/uapi/linux/net_tstamp.h
index 7ed0b3d1c00a..fcc61c73a666 100644
--- a/uapi/linux/net_tstamp.h
+++ b/uapi/linux/net_tstamp.h
@@ -13,7 +13,7 @@
 #include <linux/types.h>
 #include <linux/socket.h>   /* for SO_TIMESTAMPING */
 
-/* SO_TIMESTAMPING gets an integer bit field comprised of these values */
+/* SO_TIMESTAMPING flags */
 enum {
 	SOF_TIMESTAMPING_TX_HARDWARE = (1<<0),
 	SOF_TIMESTAMPING_TX_SOFTWARE = (1<<1),
@@ -30,8 +30,9 @@ enum {
 	SOF_TIMESTAMPING_OPT_STATS = (1<<12),
 	SOF_TIMESTAMPING_OPT_PKTINFO = (1<<13),
 	SOF_TIMESTAMPING_OPT_TX_SWHW = (1<<14),
+	SOF_TIMESTAMPING_BIND_PHC = (1 << 15),
 
-	SOF_TIMESTAMPING_LAST = SOF_TIMESTAMPING_OPT_TX_SWHW,
+	SOF_TIMESTAMPING_LAST = SOF_TIMESTAMPING_BIND_PHC,
 	SOF_TIMESTAMPING_MASK = (SOF_TIMESTAMPING_LAST - 1) |
 				 SOF_TIMESTAMPING_LAST
 };
@@ -46,6 +47,18 @@ enum {
 					 SOF_TIMESTAMPING_TX_SCHED | \
 					 SOF_TIMESTAMPING_TX_ACK)
 
+/**
+ * struct so_timestamping - SO_TIMESTAMPING parameter
+ *
+ * @flags:	SO_TIMESTAMPING flags
+ * @bind_phc:	Index of PTP virtual clock bound to sock. This is available
+ *		if flag SOF_TIMESTAMPING_BIND_PHC is set.
+ */
+struct so_timestamping {
+	int flags;
+	int bind_phc;
+};
+
 /**
  * struct hwtstamp_config - %SIOCGHWTSTAMP and %SIOCSHWTSTAMP parameter
  *
diff --git a/uapi/linux/netlink.h b/uapi/linux/netlink.h
index 5024c5435749..e83e2e300130 100644
--- a/uapi/linux/netlink.h
+++ b/uapi/linux/netlink.h
@@ -91,9 +91,10 @@ struct nlmsghdr {
 #define NLMSG_HDRLEN	 ((int) NLMSG_ALIGN(sizeof(struct nlmsghdr)))
 #define NLMSG_LENGTH(len) ((len) + NLMSG_HDRLEN)
 #define NLMSG_SPACE(len) NLMSG_ALIGN(NLMSG_LENGTH(len))
-#define NLMSG_DATA(nlh)  ((void*)(((char*)nlh) + NLMSG_LENGTH(0)))
+#define NLMSG_DATA(nlh)  ((void *)(((char *)nlh) + NLMSG_HDRLEN))
 #define NLMSG_NEXT(nlh,len)	 ((len) -= NLMSG_ALIGN((nlh)->nlmsg_len), \
-				  (struct nlmsghdr*)(((char*)(nlh)) + NLMSG_ALIGN((nlh)->nlmsg_len)))
+				  (struct nlmsghdr *)(((char *)(nlh)) + \
+				  NLMSG_ALIGN((nlh)->nlmsg_len)))
 #define NLMSG_OK(nlh,len) ((len) >= (int)sizeof(struct nlmsghdr) && \
 			   (nlh)->nlmsg_len >= sizeof(struct nlmsghdr) && \
 			   (nlh)->nlmsg_len <= (len))
-- 
2.31.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH ethtool-next 2/5] stats: factor out one stat field printing
  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 ` Alexander Lobakin
  2021-08-03 16:51 ` [PATCH ethtool-next 3/5] stats: add support for per-channel statistics [blocks] Alexander Lobakin
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Alexander Lobakin @ 2021-08-03 16:51 UTC (permalink / raw)
  To: Michal Kubecek
  Cc: David S. Miller, Jakub Kicinski, Alexander Lobakin,
	Jesse Brandeburg, Lukasz Czapnik, Marcin Kubiak, Michal Kubiak,
	Michal Swiatkowski, Jonathan Corbet, Netanel Belgazal,
	Arthur Kiyanovski, Guy Tzalik, Saeed Bishara, Ioana Ciornei,
	Claudiu Manoil, Thomas Petazzoni, Marcin Wojtas, Russell King,
	Edward Cree, Martin Habets, Michael S. Tsirkin, Jason Wang,
	Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
	John Fastabend, Andrii Nakryiko, Martin KaFai Lau, Song Liu,
	Yonghong Song, KP Singh, Shay Agroskin, Sameeh Jubran,
	Alexander Duyck, Danielle Ratson, Ido Schimmel, Andrew Lunn,
	Vladyslav Tarasiuk, Arnd Bergmann, Andrew Morton, Jian Shen,
	Petr Vorel, Dan Murphy, Yangbo Lu, Zheng Yongjun,
	Heiner Kallweit, YueHaibing, Johannes Berg, netdev, linux-doc,
	linux-kernel, virtualization, bpf

Move the code that takes one stat field nlattr, validates and prints
it in either stdout or JSON, into a separate function.
It will later be reused by per-channel statistics printing.

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

diff --git a/netlink/stats.c b/netlink/stats.c
index 9f609a4ec550..9d950b77d656 100644
--- a/netlink/stats.c
+++ b/netlink/stats.c
@@ -87,6 +87,36 @@ err_close_rmon:
 	return 1;
 }
 
+static int parse_stat(const struct nlattr *attr, const char *grp_name,
+		      const struct stringset *stat_str)
+{
+	const struct nlattr *stat;
+	unsigned long long val;
+	const char *name;
+	unsigned int s;
+	int ret;
+
+	stat = mnl_attr_get_payload(attr);
+	ret = mnl_attr_validate(stat, MNL_TYPE_U64);
+	if (ret) {
+		fprintf(stderr, "invalid kernel response - bad statistic entry\n");
+		return 1;
+	}
+
+	s = mnl_attr_get_type(stat);
+	name = get_string(stat_str, s);
+	if (!name || !name[0])
+		return 0;
+
+	if (!is_json_context())
+		fprintf(stdout, "%s-%s: ", grp_name, name);
+
+	val = mnl_attr_get_u64(stat);
+	print_u64(PRINT_ANY, name, "%llu\n", val);
+
+	return 0;
+}
+
 static int parse_grp(struct nl_context *nlctx, const struct nlattr *grp,
 		     const struct stringset *std_str)
 {
@@ -94,10 +124,9 @@ static int parse_grp(struct nl_context *nlctx, const struct nlattr *grp,
 	DECLARE_ATTR_TB_INFO(tb);
 	bool hist_rx = false, hist_tx = false;
 	const struct stringset *stat_str;
-	const struct nlattr *attr, *stat;
-	const char *std_name, *name;
-	unsigned int ss_id, id, s;
-	unsigned long long val;
+	const struct nlattr *attr;
+	unsigned int ss_id, id;
+	const char *std_name;
 	int ret;
 
 	ret = mnl_attr_parse_nested(grp, attr_cb, &tb_info);
@@ -131,22 +160,8 @@ static int parse_grp(struct nl_context *nlctx, const struct nlattr *grp,
 			continue;
 		}
 
-		stat = mnl_attr_get_payload(attr);
-		ret = mnl_attr_validate(stat, MNL_TYPE_U64);
-		if (ret) {
-			fprintf(stderr, "invalid kernel response - bad statistic entry\n");
+		if (parse_stat(attr, NULL, std_name, stat_str))
 			goto err_close_grp;
-		}
-		s = mnl_attr_get_type(stat);
-		name = get_string(stat_str, s);
-		if (!name || !name[0])
-			continue;
-
-		if (!is_json_context())
-			fprintf(stdout, "%s-%s: ", std_name, name);
-
-		val = mnl_attr_get_u64(stat);
-		print_u64(PRINT_ANY, name, "%llu\n", val);
 	}
 
 	if (hist_rx)
-- 
2.31.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH ethtool-next 3/5] stats: add support for per-channel statistics [blocks]
  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
  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
  4 siblings, 0 replies; 6+ messages in thread
From: Alexander Lobakin @ 2021-08-03 16:51 UTC (permalink / raw)
  To: Michal Kubecek
  Cc: David S. Miller, Jakub Kicinski, Alexander Lobakin,
	Jesse Brandeburg, Lukasz Czapnik, Marcin Kubiak, Michal Kubiak,
	Michal Swiatkowski, Jonathan Corbet, Netanel Belgazal,
	Arthur Kiyanovski, Guy Tzalik, Saeed Bishara, Ioana Ciornei,
	Claudiu Manoil, Thomas Petazzoni, Marcin Wojtas, Russell King,
	Edward Cree, Martin Habets, Michael S. Tsirkin, Jason Wang,
	Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
	John Fastabend, Andrii Nakryiko, Martin KaFai Lau, Song Liu,
	Yonghong Song, KP Singh, Shay Agroskin, Sameeh Jubran,
	Alexander Duyck, Danielle Ratson, Ido Schimmel, Andrew Lunn,
	Vladyslav Tarasiuk, Arnd Bergmann, Andrew Morton, Jian Shen,
	Petr Vorel, Dan Murphy, Yangbo Lu, Zheng Yongjun,
	Heiner Kallweit, YueHaibing, Johannes Berg, netdev, linux-doc,
	linux-kernel, virtualization, bpf

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH ethtool-next 4/5] man: fix typo for "rmon" standard stat type
  2021-08-03 16:51 [PATCH ethtool-next 0/5] stats: add support for per-channel and XDP standard stats Alexander Lobakin
                   ` (2 preceding siblings ...)
  2021-08-03 16:51 ` [PATCH ethtool-next 3/5] stats: add support for per-channel statistics [blocks] Alexander Lobakin
@ 2021-08-03 16:51 ` Alexander Lobakin
  2021-08-03 16:51 ` [PATCH ethtool-next 5/5] man: mention XDP standard statistics in help and man page Alexander Lobakin
  4 siblings, 0 replies; 6+ messages in thread
From: Alexander Lobakin @ 2021-08-03 16:51 UTC (permalink / raw)
  To: Michal Kubecek
  Cc: David S. Miller, Jakub Kicinski, Alexander Lobakin,
	Jesse Brandeburg, Lukasz Czapnik, Marcin Kubiak, Michal Kubiak,
	Michal Swiatkowski, Jonathan Corbet, Netanel Belgazal,
	Arthur Kiyanovski, Guy Tzalik, Saeed Bishara, Ioana Ciornei,
	Claudiu Manoil, Thomas Petazzoni, Marcin Wojtas, Russell King,
	Edward Cree, Martin Habets, Michael S. Tsirkin, Jason Wang,
	Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
	John Fastabend, Andrii Nakryiko, Martin KaFai Lau, Song Liu,
	Yonghong Song, KP Singh, Shay Agroskin, Sameeh Jubran,
	Alexander Duyck, Danielle Ratson, Ido Schimmel, Andrew Lunn,
	Vladyslav Tarasiuk, Arnd Bergmann, Andrew Morton, Jian Shen,
	Petr Vorel, Dan Murphy, Yangbo Lu, Zheng Yongjun,
	Heiner Kallweit, YueHaibing, Johannes Berg, netdev, linux-doc,
	linux-kernel, virtualization, bpf

Due to ".RN" instead of ".RB", "[rmon]" string was always being
omitted from the SYNOPSIS part.

Fixes: f8d2bc2ccd8b ("netlink: add support for standard stats")
Signed-off-by: Alexander Lobakin <alexandr.lobakin@intel.com>
Reviewed-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
---
 ethtool.8.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ethtool.8.in b/ethtool.8.in
index f83d6d17ae41..6b7761849fca 100644
--- a/ethtool.8.in
+++ b/ethtool.8.in
@@ -244,7 +244,7 @@ ethtool \- query or control network driver and hardware settings
 .RB [\fBeth\-phy\fP]
 .RB [\fBeth\-mac\fP]
 .RB [\fBeth\-ctrl\fP]
-.RN [\fBrmon\fP]
+.RB [\fBrmon\fP]
 .RB ]
 .HP
 .B ethtool \-\-phy\-statistics
-- 
2.31.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH ethtool-next 5/5] man: mention XDP standard statistics in help and man page
  2021-08-03 16:51 [PATCH ethtool-next 0/5] stats: add support for per-channel and XDP standard stats Alexander Lobakin
                   ` (3 preceding siblings ...)
  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 ` Alexander Lobakin
  4 siblings, 0 replies; 6+ messages in thread
From: Alexander Lobakin @ 2021-08-03 16:51 UTC (permalink / raw)
  To: Michal Kubecek
  Cc: David S. Miller, Jakub Kicinski, Alexander Lobakin,
	Jesse Brandeburg, Lukasz Czapnik, Marcin Kubiak, Michal Kubiak,
	Michal Swiatkowski, Jonathan Corbet, Netanel Belgazal,
	Arthur Kiyanovski, Guy Tzalik, Saeed Bishara, Ioana Ciornei,
	Claudiu Manoil, Thomas Petazzoni, Marcin Wojtas, Russell King,
	Edward Cree, Martin Habets, Michael S. Tsirkin, Jason Wang,
	Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
	John Fastabend, Andrii Nakryiko, Martin KaFai Lau, Song Liu,
	Yonghong Song, KP Singh, Shay Agroskin, Sameeh Jubran,
	Alexander Duyck, Danielle Ratson, Ido Schimmel, Andrew Lunn,
	Vladyslav Tarasiuk, Arnd Bergmann, Andrew Morton, Jian Shen,
	Petr Vorel, Dan Murphy, Yangbo Lu, Zheng Yongjun,
	Heiner Kallweit, YueHaibing, Johannes Berg, netdev, linux-doc,
	linux-kernel, virtualization, bpf

"xdp" is a new type of standard statistics landed in with Linux
commit a9428aaed122 ("ethtool, stats: introduce standard XDP statistics").
Mention it in the help text and the man page source.

Signed-off-by: Alexander Lobakin <alexandr.lobakin@intel.com>
Reviewed-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
---
 ethtool.8.in | 3 ++-
 ethtool.c    | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/ethtool.8.in b/ethtool.8.in
index 6b7761849fca..7db0adebbdcf 100644
--- a/ethtool.8.in
+++ b/ethtool.8.in
@@ -245,6 +245,7 @@ ethtool \- query or control network driver and hardware settings
 .RB [\fBeth\-mac\fP]
 .RB [\fBeth\-ctrl\fP]
 .RB [\fBrmon\fP]
+.RB [\fBxdp\fP]
 .RB ]
 .HP
 .B ethtool \-\-phy\-statistics
@@ -673,7 +674,7 @@ naming of NIC- and driver-specific statistics across vendors.
 .B \fB\-\-all\-groups
 .E
 .TP
-.B \fB\-\-groups [\fBeth\-phy\fP] [\fBeth\-mac\fP] [\fBeth\-ctrl\fP] [\fBrmon\fP]
+.B \fB\-\-groups [\fBeth\-phy\fP] [\fBeth\-mac\fP] [\fBeth\-ctrl\fP] [\fBrmon\fP] [\fBxdp\fP]
 Request groups of standard device statistics.
 .RE
 .TP
diff --git a/ethtool.c b/ethtool.c
index 33a0a492cb15..c1f1279bd9f0 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -5776,7 +5776,7 @@ static const struct option args[] = {
 		.nlchk	= nl_gstats_chk,
 		.nlfunc	= nl_gstats,
 		.help	= "Show adapter statistics",
-		.xhelp	= "               [ --all-groups | --groups [eth-phy] [eth-mac] [eth-ctrl] [rmon] ]\n"
+		.xhelp	= "               [ --all-groups | --groups [eth-phy] [eth-mac] [eth-ctrl] [rmon] [xdp] ]\n"
 	},
 	{
 		.opts	= "--phy-statistics",
-- 
2.31.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-08-03 16:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH ethtool-next 3/5] stats: add support for per-channel statistics [blocks] Alexander Lobakin
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

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).