Skip to contentSkip to conversation

stats: add support for per-channel and XDP standard stats

PATCH New Alexander Lobakin 1 participant 6 messages Aug 3, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover stats: add support for per-channel and XDP standard stats

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/[email protected]

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(-)
Signature · 1 line
2.31.1
#1 lore raw

PATCH 1/5 sync UAPI header copies

+ 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")

---
 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(-)
uapi/linux/ethtool.h +4 -2
index c6ec1111ffa3..898bce1b08b0 100644
@@ -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
uapi/linux/ethtool_netlink.h +50 -1

93 lines not on this page · raw message

uapi/linux/if_link.h +20 -0
index 0e81707a9637..fb2ecf403a16 100644
@@ -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 */
uapi/linux/net_tstamp.h +15 -2
index 7ed0b3d1c00a..fcc61c73a666 100644
@@ -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
  *
uapi/linux/netlink.h +3 -2
index 5024c5435749..e83e2e300130 100644
@@ -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))
Signature · 1 line
2.31.1
#2 lore raw

PATCH 2/5 stats: factor out one stat field printing

In reply to Alexander Lobakin

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.

---
 netlink/stats.c | 53 +++++++++++++++++++++++++++++++------------------
 1 file changed, 34 insertions(+), 19 deletions(-)
netlink/stats.c +34 -19
index 9f609a4ec550..9d950b77d656 100644
@@ -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)
Signature · 1 line
2.31.1
#3 lore raw

PATCH 3/5 stats: add support for per-channel statistics [blocks]

In reply to Alexander Lobakin

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.

---
 netlink/stats.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 63 insertions(+), 4 deletions(-)
netlink/stats.c +63 -4
index 9d950b77d656..36a9dad97f15 100644
@@ -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();
 
Signature · 1 line
2.31.1
#4 lore raw

PATCH 4/5 man: fix typo for "rmon" standard stat type

In reply to Alexander Lobakin

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

Fixes f8d2bc2ccd8b ("netlink: add support for standard stats")
---
 ethtool.8.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
ethtool.8.in +1 -1
index f83d6d17ae41..6b7761849fca 100644
@@ -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
Signature · 1 line
2.31.1
#5 lore raw

PATCH 5/5 man: mention XDP standard statistics in help and man page

In reply to Alexander Lobakin

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

---
 ethtool.8.in | 3 ++-
 ethtool.c    | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)
ethtool.8.in +2 -1
index 6b7761849fca..7db0adebbdcf 100644
@@ -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
ethtool.c +1 -1
index 33a0a492cb15..c1f1279bd9f0 100644
@@ -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",
Signature · 1 line
2.31.1