netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH ethtool-next v3] netlink: tsinfo: add statistics support
@ 2024-05-08  4:24 Rahul Rameshbabu
  2024-05-20  0:10 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Rahul Rameshbabu @ 2024-05-08  4:24 UTC (permalink / raw)
  To: netdev
  Cc: cjubran, cratiu, davem, edumazet, gal, jacob.e.keller, kuba,
	mkubecek, pabeni, rrameshbabu, saeedm, tariqt, vadim.fedorenko,
	wintera

If stats flag is present, report back statistics for tsinfo if the netlink
response body contains statistics information.

Link: https://lore.kernel.org/netdev/20240403212931.128541-1-rrameshbabu@nvidia.com/
Signed-off-by: Rahul Rameshbabu <rrameshbabu@nvidia.com>
Reviewed-by: Carolina Jubran <cjubran@nvidia.com>
Reviewed-by: Cosmin Ratiu <cratiu@nvidia.com>
---

Notes:
    Changes:
    
      v1->v2:
        - Refactored logic based on a suggestion from Jakub Kicinski
          <kuba@kernel.org>.
      v2->v3:
        - Dropped previous uapi header update by rebasing the next branch with
          the latest changes.
    
    Links:
    
      - https://lore.kernel.org/netdev/20240417203836.113377-1-rrameshbabu@nvidia.com/
      - https://lore.kernel.org/netdev/20240416203723.104062-1-rrameshbabu@nvidia.com/

 netlink/tsinfo.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 64 insertions(+), 1 deletion(-)

diff --git a/netlink/tsinfo.c b/netlink/tsinfo.c
index c6571ff..4df4141 100644
--- a/netlink/tsinfo.c
+++ b/netlink/tsinfo.c
@@ -5,6 +5,7 @@
  */
 
 #include <errno.h>
+#include <inttypes.h>
 #include <string.h>
 #include <stdio.h>
 
@@ -15,6 +16,60 @@
 
 /* TSINFO_GET */
 
+static int tsinfo_show_stats(const struct nlattr *nest)
+{
+	const struct nlattr *tb[ETHTOOL_A_TS_STAT_MAX + 1] = {};
+	DECLARE_ATTR_TB_INFO(tb);
+	static const struct {
+		unsigned int attr;
+		char *name;
+	} stats[] = {
+		{ ETHTOOL_A_TS_STAT_TX_PKTS, "tx_pkts" },
+		{ ETHTOOL_A_TS_STAT_TX_LOST, "tx_lost" },
+		{ ETHTOOL_A_TS_STAT_TX_ERR, "tx_err" },
+	};
+	bool header = false;
+	unsigned int i;
+	__u64 val;
+	int ret;
+
+	ret = mnl_attr_parse_nested(nest, attr_cb, &tb_info);
+	if (ret < 0)
+		return ret;
+
+	open_json_object("statistics");
+	for (i = 0; i < ARRAY_SIZE(stats); i++) {
+		char fmt[64];
+
+		if (!tb[stats[i].attr])
+			continue;
+
+		if (!header && !is_json_context()) {
+			printf("Statistics:\n");
+			header = true;
+		}
+
+		if (!mnl_attr_validate(tb[stats[i].attr], MNL_TYPE_U32)) {
+			val = mnl_attr_get_u32(tb[stats[i].attr]);
+		} else if (!mnl_attr_validate(tb[stats[i].attr], MNL_TYPE_U64)) {
+			val = mnl_attr_get_u64(tb[stats[i].attr]);
+		} else {
+			fprintf(stderr, "malformed netlink message (statistic)\n");
+			goto err_close_stats;
+		}
+
+		snprintf(fmt, sizeof(fmt), "  %s: %%" PRIu64 "\n", stats[i].name);
+		print_u64(PRINT_ANY, stats[i].name, fmt, val);
+	}
+	close_json_object();
+
+	return 0;
+
+err_close_stats:
+	close_json_object();
+	return -1;
+}
+
 static void tsinfo_dump_cb(unsigned int idx, const char *name, bool val,
 			   void *data __maybe_unused)
 {
@@ -99,6 +154,12 @@ int tsinfo_reply_cb(const struct nlmsghdr *nlhdr, void *data)
 	if (ret < 0)
 		return err_ret;
 
+	if (tb[ETHTOOL_A_TSINFO_STATS]) {
+		ret = tsinfo_show_stats(tb[ETHTOOL_A_TSINFO_STATS]);
+		if (ret < 0)
+			return err_ret;
+	}
+
 	return MNL_CB_OK;
 }
 
@@ -106,6 +167,7 @@ int nl_tsinfo(struct cmd_context *ctx)
 {
 	struct nl_context *nlctx = ctx->nlctx;
 	struct nl_socket *nlsk = nlctx->ethnl_socket;
+	u32 flags;
 	int ret;
 
 	if (netlink_cmd_check(ctx, ETHTOOL_MSG_TSINFO_GET, true))
@@ -116,8 +178,9 @@ int nl_tsinfo(struct cmd_context *ctx)
 		return 1;
 	}
 
+	flags = get_stats_flag(nlctx, ETHTOOL_MSG_TSINFO_GET, ETHTOOL_A_TSINFO_HEADER);
 	ret = nlsock_prep_get_request(nlsk, ETHTOOL_MSG_TSINFO_GET,
-				      ETHTOOL_A_TSINFO_HEADER, 0);
+				      ETHTOOL_A_TSINFO_HEADER, flags);
 	if (ret < 0)
 		return ret;
 	return nlsock_send_get_request(nlsk, tsinfo_reply_cb);
-- 
2.42.0


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

* Re: [PATCH ethtool-next v3] netlink: tsinfo: add statistics support
  2024-05-08  4:24 [PATCH ethtool-next v3] netlink: tsinfo: add statistics support Rahul Rameshbabu
@ 2024-05-20  0:10 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-05-20  0:10 UTC (permalink / raw)
  To: Rahul Rameshbabu
  Cc: netdev, cjubran, cratiu, davem, edumazet, gal, jacob.e.keller,
	kuba, mkubecek, pabeni, saeedm, tariqt, vadim.fedorenko, wintera

Hello:

This patch was applied to ethtool/ethtool.git (next)
by Michal Kubecek <mkubecek@suse.cz>:

On Tue,  7 May 2024 21:24:12 -0700 you wrote:
> If stats flag is present, report back statistics for tsinfo if the netlink
> response body contains statistics information.
> 
> Link: https://lore.kernel.org/netdev/20240403212931.128541-1-rrameshbabu@nvidia.com/
> Signed-off-by: Rahul Rameshbabu <rrameshbabu@nvidia.com>
> Reviewed-by: Carolina Jubran <cjubran@nvidia.com>
> Reviewed-by: Cosmin Ratiu <cratiu@nvidia.com>
> 
> [...]

Here is the summary with links:
  - [ethtool-next,v3] netlink: tsinfo: add statistics support
    https://git.kernel.org/pub/scm/network/ethtool/ethtool.git/commit/?id=edf00bab748b

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2024-05-20  0:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-08  4:24 [PATCH ethtool-next v3] netlink: tsinfo: add statistics support Rahul Rameshbabu
2024-05-20  0:10 ` patchwork-bot+netdevbpf

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