diff mbox series

[net-next] net: tn40xx: add per queue netdev-genl stats support

Message ID 20240706064324.137574-1-fujita.tomonori@gmail.com (mailing list archive)
State Accepted
Commit 6c2a4c2f70e5b6c9c57d6d8adc893c55ba318613
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: tn40xx: add per queue netdev-genl stats support | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 816 this patch: 816
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang success Errors and warnings before: 821 this patch: 821
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 821 this patch: 821
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 85 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-07-08--15-00 (tests: 694)

Commit Message

FUJITA Tomonori July 6, 2024, 6:43 a.m. UTC
Add support for the netdev-genl per queue stats API.

./tools/net/ynl/cli.py --spec Documentation/netlink/specs/netdev.yaml \
--dump qstats-get --json '{"scope":"queue"}'
[{'ifindex': 4,
  'queue-id': 0,
  'queue-type': 'rx',
  'rx-alloc-fail': 0,
  'rx-bytes': 266613,
  'rx-packets': 3325},
 {'ifindex': 4,
  'queue-id': 0,
  'queue-type': 'tx',
  'tx-bytes': 142823367,
  'tx-packets': 2387}]

Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
---
 drivers/net/ethernet/tehuti/tn40.c | 54 ++++++++++++++++++++++++++++--
 drivers/net/ethernet/tehuti/tn40.h |  1 +
 2 files changed, 53 insertions(+), 2 deletions(-)


base-commit: 2f5e6395714d0ee53c150da38b25975fe37755c2

Comments

Jakub Kicinski July 9, 2024, 3:18 a.m. UTC | #1
On Sat,  6 Jul 2024 15:43:24 +0900 FUJITA Tomonori wrote:
> Add support for the netdev-genl per queue stats API.
> 
> ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/netdev.yaml \
> --dump qstats-get --json '{"scope":"queue"}'
> [{'ifindex': 4,
>   'queue-id': 0,
>   'queue-type': 'rx',
>   'rx-alloc-fail': 0,
>   'rx-bytes': 266613,
>   'rx-packets': 3325},
>  {'ifindex': 4,
>   'queue-id': 0,
>   'queue-type': 'tx',
>   'tx-bytes': 142823367,
>   'tx-packets': 2387}]
> 
> Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>

Reviewed-by: Jakub Kicinski <kuba@kernel.org>
patchwork-bot+netdevbpf@kernel.org July 9, 2024, 11:30 a.m. UTC | #2
Hello:

This patch was applied to netdev/net-next.git (main)
by Paolo Abeni <pabeni@redhat.com>:

On Sat,  6 Jul 2024 15:43:24 +0900 you wrote:
> Add support for the netdev-genl per queue stats API.
> 
> ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/netdev.yaml \
> --dump qstats-get --json '{"scope":"queue"}'
> [{'ifindex': 4,
>   'queue-id': 0,
>   'queue-type': 'rx',
>   'rx-alloc-fail': 0,
>   'rx-bytes': 266613,
>   'rx-packets': 3325},
>  {'ifindex': 4,
>   'queue-id': 0,
>   'queue-type': 'tx',
>   'tx-bytes': 142823367,
>   'tx-packets': 2387}]
> 
> [...]

Here is the summary with links:
  - [net-next] net: tn40xx: add per queue netdev-genl stats support
    https://git.kernel.org/netdev/net-next/c/6c2a4c2f70e5

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/tehuti/tn40.c b/drivers/net/ethernet/tehuti/tn40.c
index 565b72537efa..259bdac24cf2 100644
--- a/drivers/net/ethernet/tehuti/tn40.c
+++ b/drivers/net/ethernet/tehuti/tn40.c
@@ -10,6 +10,7 @@ 
 #include <linux/pci.h>
 #include <linux/phylink.h>
 #include <linux/vmalloc.h>
+#include <net/netdev_queues.h>
 #include <net/page_pool/helpers.h>
 
 #include "tn40.h"
@@ -378,6 +379,7 @@  static int tn40_rx_receive(struct tn40_priv *priv, int budget)
 		if (!skb) {
 			u64_stats_update_begin(&priv->syncp);
 			priv->stats.rx_dropped++;
+			priv->alloc_fail++;
 			u64_stats_update_end(&priv->syncp);
 			tn40_recycle_rx_buffer(priv, rxdd);
 			break;
@@ -1580,8 +1582,55 @@  static int tn40_ethtool_get_link_ksettings(struct net_device *ndev,
 }
 
 static const struct ethtool_ops tn40_ethtool_ops = {
-	.get_link		= ethtool_op_get_link,
-	.get_link_ksettings	= tn40_ethtool_get_link_ksettings,
+	.get_link = ethtool_op_get_link,
+	.get_link_ksettings = tn40_ethtool_get_link_ksettings,
+};
+
+static void tn40_get_queue_stats_rx(struct net_device *ndev, int idx,
+				    struct netdev_queue_stats_rx *stats)
+{
+	struct tn40_priv *priv = netdev_priv(ndev);
+	unsigned int start;
+
+	do {
+		start = u64_stats_fetch_begin(&priv->syncp);
+
+		stats->packets = priv->stats.rx_packets;
+		stats->bytes = priv->stats.rx_bytes;
+		stats->alloc_fail = priv->alloc_fail;
+	} while (u64_stats_fetch_retry(&priv->syncp, start));
+}
+
+static void tn40_get_queue_stats_tx(struct net_device *ndev, int idx,
+				    struct netdev_queue_stats_tx *stats)
+{
+	struct tn40_priv *priv = netdev_priv(ndev);
+	unsigned int start;
+
+	do {
+		start = u64_stats_fetch_begin(&priv->syncp);
+
+		stats->packets = priv->stats.tx_packets;
+		stats->bytes = priv->stats.tx_bytes;
+	} while (u64_stats_fetch_retry(&priv->syncp, start));
+}
+
+static void tn40_get_base_stats(struct net_device *ndev,
+				struct netdev_queue_stats_rx *rx,
+				struct netdev_queue_stats_tx *tx)
+{
+	rx->packets = 0;
+	rx->bytes = 0;
+	rx->alloc_fail = 0;
+
+	tx->packets = 0;
+	tx->bytes = 0;
+}
+
+static const struct netdev_stat_ops tn40_stat_ops = {
+	.get_queue_stats_rx = tn40_get_queue_stats_rx,
+	.get_queue_stats_tx = tn40_get_queue_stats_tx,
+	.get_base_stats = tn40_get_base_stats,
 };
 
 static int tn40_priv_init(struct tn40_priv *priv)
@@ -1613,6 +1662,7 @@  static struct net_device *tn40_netdev_alloc(struct pci_dev *pdev)
 		return NULL;
 	ndev->netdev_ops = &tn40_netdev_ops;
 	ndev->ethtool_ops = &tn40_ethtool_ops;
+	ndev->stat_ops = &tn40_stat_ops;
 	ndev->tx_queue_len = TN40_NDEV_TXQ_LEN;
 	ndev->mem_start = pci_resource_start(pdev, 0);
 	ndev->mem_end = pci_resource_end(pdev, 0);
diff --git a/drivers/net/ethernet/tehuti/tn40.h b/drivers/net/ethernet/tehuti/tn40.h
index 10368264f7b7..490781fe5120 100644
--- a/drivers/net/ethernet/tehuti/tn40.h
+++ b/drivers/net/ethernet/tehuti/tn40.h
@@ -123,6 +123,7 @@  struct tn40_priv {
 
 	int stats_flag;
 	struct rtnl_link_stats64 stats;
+	u64 alloc_fail;
 	struct u64_stats_sync syncp;
 
 	u8 txd_size;