Skip to contentSkip to conversation

netdev: add per-queue statistics

PATCH Superseded Jakub Kicinski 4 participants 10 messages Feb 29, 2024 – Mar 6, 2024

Subsystems (5)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

v2 cover netdev: add per-queue statistics

Hi!

Per queue stats keep coming up, so it's about time someone laid the foundation. This series adds the uAPI, a handful of stats and a sample support for bnxt. It's not very comprehensive in terms of stat types or driver support. The expectation is that the support will grow organically. If we have the basic pieces in place it will be easy for reviewers to request new stats, or use of the API in place of ethtool -S.

See patch 3 for sample output.

v2:
- un-wrap short lines
- s/stats/qstats/
v1: https://lore.kernel.org/all/[email protected]/
- rename projection -> scope
- turn projection/scope into flags
- remove the "netdev" scope since it's always implied
rfc: https://lore.kernel.org/all/[email protected]/

Jakub Kicinski (3):
netdev: add per-queue statistics
netdev: add queue stat for alloc failures
eth: bnxt: support per-queue statistics

 Documentation/netlink/specs/netdev.yaml   |  91 +++++++++
 Documentation/networking/statistics.rst   |  15 ++
 drivers/net/ethernet/broadcom/bnxt/bnxt.c |  63 +++++++
 include/linux/netdevice.h                 |   3 +
 include/net/netdev_queues.h               |  56 ++++++
 include/uapi/linux/netdev.h               |  20 ++
 net/core/netdev-genl-gen.c                |  12 ++
 net/core/netdev-genl-gen.h                |   2 +
 net/core/netdev-genl.c                    | 217 ++++++++++++++++++++++
 tools/include/uapi/linux/netdev.h         |  20 ++
 10 files changed, 499 insertions(+)
Signature · 1 line
2.43.2
author maintainer
#1 lore raw

PATCH v2 1/3 netdev: add per-queue statistics

The ethtool-nl family does a good job exposing various protocol related and IEEE/IETF statistics which used to get dumped under ethtool -S, with creative names. Queue stats don't have a netlink API, yet, and remain a lion's share of ethtool -S output for new drivers. Not only is that bad because the names differ driver to driver but it's also bug-prone. Intuitively drivers try to report only the stats for active queues, but querying ethtool stats involves multiple system calls, and the number of stats is read separately from the stats themselves. Worse still when user space asks for values of the stats, it doesn't inform the kernel how big the buffer is. If number of stats increases in the meantime kernel will overflow user buffer.

Add a netlink API for dumping queue stats. Queue information is exposed via the netdev-genl family, so add the stats there. Support per-queue and sum-for-device dumps. Latter will be useful when subsequent patches add more interesting common stats than just bytes and packets.

The API does not currently distinguish between HW and SW stats. The expectation is that the source of the stats will either not matter much (good packets) or be obvious (skb alloc errors).

---
 Documentation/netlink/specs/netdev.yaml |  84 +++++++++
 Documentation/networking/statistics.rst |  15 ++
 include/linux/netdevice.h               |   3 +
 include/net/netdev_queues.h             |  54 ++++++
 include/uapi/linux/netdev.h             |  19 +++
 net/core/netdev-genl-gen.c              |  12 ++
 net/core/netdev-genl-gen.h              |   2 +
 net/core/netdev-genl.c                  | 216 ++++++++++++++++++++++++
 tools/include/uapi/linux/netdev.h       |  19 +++
 9 files changed, 424 insertions(+)
Documentation/netlink/specs/netdev.yaml +84 -0
index 3addac970680..a1e48c3c84c9 100644
@@ -74,6 +74,10 @@ name: netdev
     name: queue-type
     type: enum
     entries: [ rx, tx ]
+  -
+    name: qstats-scope
+    type: flags
+    entries: [ queue ]
 
 attribute-sets:
   -
@@ -265,6 +269,66 @@ name: netdev
         doc: ID of the NAPI instance which services this queue.
         type: u32
 
+  -
+    name: qstats
+    doc: |
+      Get device statistics, scoped to a device or a queue.
+      These statistics extend (and partially duplicate) statistics available
+      in struct rtnl_link_stats64.
+      Value of the `scope` attribute determines how statistics are
+      aggregated. When aggregated for the entire device the statistics
+      represent the total number of events since last explicit reset of
+      the device (i.e. not a reconfiguration like changing queue count).
+      When reported per-queue, however, the statistics may not add
+      up to the total number of events, will only be reported for currently
+      active objects, and will likely report the number of events since last
+      reconfiguration.
+    attributes:
+      -
+        name: ifindex
+        doc: ifindex of the netdevice to which stats belong.
+        type: u32
+        checks:
+          min: 1
+      -
+        name: queue-type
+        doc: Queue type as rx, tx, for queue-id.
+        type: u32
+        enum: queue-type
+      -
+        name: queue-id
+        doc: Queue ID, if stats are scoped to a single queue instance.
+        type: u32
+      -
+        name: scope
+        doc: |
+          What object type should be used to iterate over the stats.
+        type: uint
+        enum: qstats-scope
+      -
+        name: rx-packets
+        doc: |
+          Number of wire packets successfully received and passed to the stack.
+          For drivers supporting XDP, XDP is considered the first layer
+          of the stack, so packets consumed by XDP are still counted here.
+        type: uint
+        value: 8 # reserve some attr ids in case we need more metadata later
+      -
+        name: rx-bytes
+        doc: Successfully received bytes, see `rx-packets`.
+        type: uint
+      -
+        name: tx-packets
+        doc: |
+          Number of wire packets successfully sent. Packet is considered to be
+          successfully sent once it is in device memory (usually this means
+          the device has issued a DMA completion for the packet).
+        type: uint
+      -
+        name: tx-bytes
+        doc: Successfully sent bytes, see `tx-packets`.
+        type: uint
+
 operations:
   list:
     -
@@ -405,6 +469,26 @@ name: netdev
           attributes:
             - ifindex
         reply: *napi-get-op
+    -
+      name: qstats-get
+      doc: |
+        Get / dump fine grained statistics. Which statistics are reported
+        depends on the device and the driver, and whether the driver stores
+        software counters per-queue.
+      attribute-set: qstats
+      dump:
+        request:
+          attributes:
+            - scope
+        reply:
+          attributes:
+            - ifindex
+            - queue-type
+            - queue-id
+            - rx-packets
+            - rx-bytes
+            - tx-packets
+            - tx-bytes
 
 mcast-groups:
   list:
Documentation/networking/statistics.rst +15 -0
index 551b3cc29a41..75e017dfa825 100644
@@ -41,6 +41,15 @@ If `-s` is specified once the detailed errors won't be shown.
 
 `ip` supports JSON formatting via the `-j` option.
 
+Queue statistics
+~~~~~~~~~~~~~~~~
+
+Queue statistics are accessible via the netdev netlink family.
+
+Currently no widely distributed CLI exists to access those statistics.
+Kernel development tools (ynl) can be used to experiment with them,
+see `Documentation/userspace-api/netlink/intro-specs.rst`.
+
 Protocol-specific statistics
 ----------------------------
 
@@ -147,6 +156,12 @@ Statistics are reported both in the responses to link information
 requests (`RTM_GETLINK`) and statistic requests (`RTM_GETSTATS`,
 when `IFLA_STATS_LINK_64` bit is set in the `.filter_mask` of the request).
 
+netdev (netlink)
+~~~~~~~~~~~~~~~~
+
+`netdev` generic netlink family allows accessing page pool and per queue
+statistics.
+
 ethtool
 -------
 
include/linux/netdevice.h +3 -0
index 09023e44db4e..9e4dc83a92ab 100644
@@ -2039,6 +2039,7 @@ enum netdev_reg_state {
  *
  *	@sysfs_rx_queue_group:	Space for optional per-rx queue attributes
  *	@rtnl_link_ops:	Rtnl_link_ops
+ *	@stat_ops:	Optional ops for queue-aware statistics
  *
  *	@gso_max_size:	Maximum size of generic segmentation offload
  *	@tso_max_size:	Device (as in HW) limit on the max TSO request size
@@ -2419,6 +2420,8 @@ struct net_device {
 
 	const struct rtnl_link_ops *rtnl_link_ops;
 
+	const struct netdev_stat_ops *stat_ops;
+
 	/* for setting kernel sock attribute on TCP connection setup */
 #define GSO_MAX_SEGS		65535u
 #define GSO_LEGACY_MAX_SIZE	65536u
include/net/netdev_queues.h +54 -0

60 lines not on this page · raw message

include/uapi/linux/netdev.h +19 -0
index 93cb411adf72..639ffa04c172 100644
@@ -70,6 +70,10 @@ enum netdev_queue_type {
 	NETDEV_QUEUE_TYPE_TX,
 };
 
+enum netdev_qstats_scope {
+	NETDEV_QSTATS_SCOPE_QUEUE = 1,
+};
+
 enum {
 	NETDEV_A_DEV_IFINDEX = 1,
 	NETDEV_A_DEV_PAD,
@@ -132,6 +136,20 @@ enum {
 	NETDEV_A_QUEUE_MAX = (__NETDEV_A_QUEUE_MAX - 1)
 };
 
+enum {
+	NETDEV_A_QSTATS_IFINDEX = 1,
+	NETDEV_A_QSTATS_QUEUE_TYPE,
+	NETDEV_A_QSTATS_QUEUE_ID,
+	NETDEV_A_QSTATS_SCOPE,
+	NETDEV_A_QSTATS_RX_PACKETS = 8,
+	NETDEV_A_QSTATS_RX_BYTES,
+	NETDEV_A_QSTATS_TX_PACKETS,
+	NETDEV_A_QSTATS_TX_BYTES,
+
+	__NETDEV_A_QSTATS_MAX,
+	NETDEV_A_QSTATS_MAX = (__NETDEV_A_QSTATS_MAX - 1)
+};
+
 enum {
 	NETDEV_CMD_DEV_GET = 1,
 	NETDEV_CMD_DEV_ADD_NTF,
@@ -144,6 +162,7 @@ enum {
 	NETDEV_CMD_PAGE_POOL_STATS_GET,
 	NETDEV_CMD_QUEUE_GET,
 	NETDEV_CMD_NAPI_GET,
+	NETDEV_CMD_QSTATS_GET,
 
 	__NETDEV_CMD_MAX,
 	NETDEV_CMD_MAX = (__NETDEV_CMD_MAX - 1)
net/core/netdev-genl-gen.c +12 -0
index be7f2ebd61b2..8d8ace9ef87f 100644
@@ -68,6 +68,11 @@ static const struct nla_policy netdev_napi_get_dump_nl_policy[NETDEV_A_NAPI_IFIN
 	[NETDEV_A_NAPI_IFINDEX] = NLA_POLICY_MIN(NLA_U32, 1),
 };
 
+/* NETDEV_CMD_QSTATS_GET - dump */
+static const struct nla_policy netdev_qstats_get_nl_policy[NETDEV_A_QSTATS_SCOPE + 1] = {
+	[NETDEV_A_QSTATS_SCOPE] = NLA_POLICY_MASK(NLA_UINT, 0x1),
+};
+
 /* Ops table for netdev */
 static const struct genl_split_ops netdev_nl_ops[] = {
 	{
@@ -138,6 +143,13 @@ static const struct genl_split_ops netdev_nl_ops[] = {
 		.maxattr	= NETDEV_A_NAPI_IFINDEX,
 		.flags		= GENL_CMD_CAP_DUMP,
 	},
+	{
+		.cmd		= NETDEV_CMD_QSTATS_GET,
+		.dumpit		= netdev_nl_qstats_get_dumpit,
+		.policy		= netdev_qstats_get_nl_policy,
+		.maxattr	= NETDEV_A_QSTATS_SCOPE,
+		.flags		= GENL_CMD_CAP_DUMP,
+	},
 };
 
 static const struct genl_multicast_group netdev_nl_mcgrps[] = {
net/core/netdev-genl-gen.h +2 -0
index a47f2bcbe4fa..4db40fd5b4a9 100644
@@ -28,6 +28,8 @@ int netdev_nl_queue_get_dumpit(struct sk_buff *skb,
 			       struct netlink_callback *cb);
 int netdev_nl_napi_get_doit(struct sk_buff *skb, struct genl_info *info);
 int netdev_nl_napi_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb);
+int netdev_nl_qstats_get_dumpit(struct sk_buff *skb,
+				struct netlink_callback *cb);
 
 enum {
 	NETDEV_NLGRP_MGMT,
net/core/netdev-genl.c +216 -0

228 lines not on this page · raw message

tools/include/uapi/linux/netdev.h +19 -0
index 93cb411adf72..639ffa04c172 100644
@@ -70,6 +70,10 @@ enum netdev_queue_type {
 	NETDEV_QUEUE_TYPE_TX,
 };
 
+enum netdev_qstats_scope {
+	NETDEV_QSTATS_SCOPE_QUEUE = 1,
+};
+
 enum {
 	NETDEV_A_DEV_IFINDEX = 1,
 	NETDEV_A_DEV_PAD,
@@ -132,6 +136,20 @@ enum {
 	NETDEV_A_QUEUE_MAX = (__NETDEV_A_QUEUE_MAX - 1)
 };
 
+enum {
+	NETDEV_A_QSTATS_IFINDEX = 1,
+	NETDEV_A_QSTATS_QUEUE_TYPE,
+	NETDEV_A_QSTATS_QUEUE_ID,
+	NETDEV_A_QSTATS_SCOPE,
+	NETDEV_A_QSTATS_RX_PACKETS = 8,
+	NETDEV_A_QSTATS_RX_BYTES,
+	NETDEV_A_QSTATS_TX_PACKETS,
+	NETDEV_A_QSTATS_TX_BYTES,
+
+	__NETDEV_A_QSTATS_MAX,
+	NETDEV_A_QSTATS_MAX = (__NETDEV_A_QSTATS_MAX - 1)
+};
+
 enum {
 	NETDEV_CMD_DEV_GET = 1,
 	NETDEV_CMD_DEV_ADD_NTF,
@@ -144,6 +162,7 @@ enum {
 	NETDEV_CMD_PAGE_POOL_STATS_GET,
 	NETDEV_CMD_QUEUE_GET,
 	NETDEV_CMD_NAPI_GET,
+	NETDEV_CMD_QSTATS_GET,
 
 	__NETDEV_CMD_MAX,
 	NETDEV_CMD_MAX = (__NETDEV_CMD_MAX - 1)
Signature · 1 line
2.43.2
author maintainer
#2 lore raw

PATCH v2 2/3 netdev: add queue stat for alloc failures

In reply to Jakub Kicinski

Rx alloc failures are commonly counted by drivers. Support reporting those via netdev-genl queue stats.

---
 Documentation/netlink/specs/netdev.yaml | 7 +++++++
 include/net/netdev_queues.h             | 2 ++
 include/uapi/linux/netdev.h             | 1 +
 net/core/netdev-genl.c                  | 3 ++-
 tools/include/uapi/linux/netdev.h       | 1 +
 5 files changed, 13 insertions(+), 1 deletion(-)
Documentation/netlink/specs/netdev.yaml +7 -0
index a1e48c3c84c9..76352dbd2be4 100644
@@ -328,6 +328,13 @@ name: netdev
         name: tx-bytes
         doc: Successfully sent bytes, see `tx-packets`.
         type: uint
+      -
+        name: rx-alloc-fail
+        doc: |
+          Number of times skb or buffer allocation failed on the Rx datapath.
+          Allocation failure may, or may not result in a packet drop, depending
+          on driver implementation and whether system recovers quickly.
+        type: uint
 
 operations:
   list:
include/net/netdev_queues.h +2 -0
index d633347eeda5..1ec408585373 100644
@@ -4,9 +4,11 @@
 
 #include <linux/netdevice.h>
 
+/* See the netdev.yaml spec for definition of each statistic */
 struct netdev_queue_stats_rx {
 	u64 bytes;
 	u64 packets;
+	u64 alloc_fail;
 };
 
 struct netdev_queue_stats_tx {
include/uapi/linux/netdev.h +1 -0
index 639ffa04c172..bb65ee840cda 100644
@@ -145,6 +145,7 @@ enum {
 	NETDEV_A_QSTATS_RX_BYTES,
 	NETDEV_A_QSTATS_TX_PACKETS,
 	NETDEV_A_QSTATS_TX_BYTES,
+	NETDEV_A_QSTATS_RX_ALLOC_FAIL,
 
 	__NETDEV_A_QSTATS_MAX,
 	NETDEV_A_QSTATS_MAX = (__NETDEV_A_QSTATS_MAX - 1)
net/core/netdev-genl.c +2 -1
index 9369ef54d172..2eb45b7f5030 100644
@@ -497,7 +497,8 @@ static int
 netdev_nl_stats_write_rx(struct sk_buff *rsp, struct netdev_queue_stats_rx *rx)
 {
 	if (netdev_stat_put(rsp, NETDEV_A_QSTATS_RX_PACKETS, rx->packets) ||
-	    netdev_stat_put(rsp, NETDEV_A_QSTATS_RX_BYTES, rx->bytes))
+	    netdev_stat_put(rsp, NETDEV_A_QSTATS_RX_BYTES, rx->bytes) ||
+	    netdev_stat_put(rsp, NETDEV_A_QSTATS_RX_ALLOC_FAIL, rx->alloc_fail))
 		return -EMSGSIZE;
 	return 0;
 }
tools/include/uapi/linux/netdev.h +1 -0
index 639ffa04c172..bb65ee840cda 100644
@@ -145,6 +145,7 @@ enum {
 	NETDEV_A_QSTATS_RX_BYTES,
 	NETDEV_A_QSTATS_TX_PACKETS,
 	NETDEV_A_QSTATS_TX_BYTES,
+	NETDEV_A_QSTATS_RX_ALLOC_FAIL,
 
 	__NETDEV_A_QSTATS_MAX,
 	NETDEV_A_QSTATS_MAX = (__NETDEV_A_QSTATS_MAX - 1)
Signature · 1 line
2.43.2
author maintainer
#3 lore raw

PATCH v2 3/3 eth: bnxt: support per-queue statistics

In reply to Jakub Kicinski

Support per-queue statistics API in bnxt.

$ ethtool -S eth0
NIC statistics:
     [0]: rx_ucast_packets: 1418
     [0]: rx_mcast_packets: 178
     [0]: rx_bcast_packets: 0
     [0]: rx_discards: 0
     [0]: rx_errors: 0
     [0]: rx_ucast_bytes: 1141815
     [0]: rx_mcast_bytes: 16766
     [0]: rx_bcast_bytes: 0
     [0]: tx_ucast_packets: 1734
...
$ ./cli.py --spec netlink/specs/netdev.yaml \
   --dump qstats-get --json '{"scope": "queue"}'
[{'ifindex': 2,
  'queue-id': 0,
  'queue-type': 'rx',
  'rx-alloc-fail': 0,
  'rx-bytes': 1164931,
  'rx-packets': 1641},
...
 {'ifindex': 2,
  'queue-id': 0,
  'queue-type': 'tx',
  'tx-bytes': 631494,
  'tx-packets': 1771},
...

Reset the per queue counters:

$ ethtool -L eth0 combined 4

Inspect again:

$ ./cli.py --spec netlink/specs/netdev.yaml \
   --dump qstats-get --json '{"scope": "queue"}'
[{'ifindex': 2,
  'queue-id': 0,
  'queue-type': 'rx',
  'rx-alloc-fail': 0,
  'rx-bytes': 32397,
  'rx-packets': 145},
...
 {'ifindex': 2,
  'queue-id': 0,
  'queue-type': 'tx',
  'tx-bytes': 37481,
  'tx-packets': 196},
...
$ ethtool -S eth0 | head
NIC statistics:
     [0]: rx_ucast_packets: 174
     [0]: rx_mcast_packets: 3
     [0]: rx_bcast_packets: 0
     [0]: rx_discards: 0
     [0]: rx_errors: 0
     [0]: rx_ucast_bytes: 37151
     [0]: rx_mcast_bytes: 267
     [0]: rx_bcast_bytes: 0
     [0]: tx_ucast_packets: 267
...

Totals are still correct:

$ ./cli.py --spec netlink/specs/netdev.yaml --dump qstats-get
[{'ifindex': 2,
  'rx-alloc-fail': 0,
  'rx-bytes': 281949995,
  'rx-packets': 216524,
  'tx-bytes': 52694905,
  'tx-packets': 75546}]
$ ip -s link show dev eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
    link/ether 14:23:f2:61:05:40 brd ff:ff:ff:ff:ff:ff
    RX:  bytes packets errors dropped  missed   mcast
     282519546  218100      0       0       0     516
    TX:  bytes packets errors dropped carrier collsns
      53323054   77674      0       0       0       0
---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 63 +++++++++++++++++++++++
 1 file changed, 63 insertions(+)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +63 -0
index a15e6d31fc22..97abde27d5fe 100644
@@ -14523,6 +14523,68 @@ static const struct net_device_ops bnxt_netdev_ops = {
 	.ndo_bridge_setlink	= bnxt_bridge_setlink,
 };
 
+static void bnxt_get_queue_stats_rx(struct net_device *dev, int i,
+				    struct netdev_queue_stats_rx *stats)
+{
+	struct bnxt *bp = netdev_priv(dev);
+	struct bnxt_cp_ring_info *cpr;
+	u64 *sw;
+
+	cpr = &bp->bnapi[i]->cp_ring;
+	sw = cpr->stats.sw_stats;
+
+	stats->packets = 0;
+	stats->packets += BNXT_GET_RING_STATS64(sw, rx_ucast_pkts);
+	stats->packets += BNXT_GET_RING_STATS64(sw, rx_mcast_pkts);
+	stats->packets += BNXT_GET_RING_STATS64(sw, rx_bcast_pkts);
+
+	stats->bytes = 0;
+	stats->bytes += BNXT_GET_RING_STATS64(sw, rx_ucast_bytes);
+	stats->bytes += BNXT_GET_RING_STATS64(sw, rx_mcast_bytes);
+	stats->bytes += BNXT_GET_RING_STATS64(sw, rx_bcast_bytes);
+
+	stats->alloc_fail = cpr->sw_stats.rx.rx_oom_discards;
+}
+
+static void bnxt_get_queue_stats_tx(struct net_device *dev, int i,
+				    struct netdev_queue_stats_tx *stats)
+{
+	struct bnxt *bp = netdev_priv(dev);
+	u64 *sw;
+
+	sw = bp->bnapi[i]->cp_ring.stats.sw_stats;
+
+	stats->packets = 0;
+	stats->packets += BNXT_GET_RING_STATS64(sw, tx_ucast_pkts);
+	stats->packets += BNXT_GET_RING_STATS64(sw, tx_mcast_pkts);
+	stats->packets += BNXT_GET_RING_STATS64(sw, tx_bcast_pkts);
+
+	stats->bytes = 0;
+	stats->bytes += BNXT_GET_RING_STATS64(sw, tx_ucast_bytes);
+	stats->bytes += BNXT_GET_RING_STATS64(sw, tx_mcast_bytes);
+	stats->bytes += BNXT_GET_RING_STATS64(sw, tx_bcast_bytes);
+}
+
+static void bnxt_get_base_stats(struct net_device *dev,
+				struct netdev_queue_stats_rx *rx,
+				struct netdev_queue_stats_tx *tx)
+{
+	struct bnxt *bp = netdev_priv(dev);
+
+	rx->packets = bp->net_stats_prev.rx_packets;
+	rx->bytes = bp->net_stats_prev.rx_bytes;
+	rx->alloc_fail = bp->ring_err_stats_prev.rx_total_oom_discards;
+
+	tx->packets = bp->net_stats_prev.tx_packets;
+	tx->bytes = bp->net_stats_prev.tx_bytes;
+}
+
+static const struct netdev_stat_ops bnxt_stat_ops = {
+	.get_queue_stats_rx	= bnxt_get_queue_stats_rx,
+	.get_queue_stats_tx	= bnxt_get_queue_stats_tx,
+	.get_base_stats		= bnxt_get_base_stats,
+};
+
 static void bnxt_remove_one(struct pci_dev *pdev)
 {
 	struct net_device *dev = pci_get_drvdata(pdev);
@@ -14970,6 +15032,7 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 		goto init_err_free;
 
 	dev->netdev_ops = &bnxt_netdev_ops;
+	dev->stat_ops = &bnxt_stat_ops;
 	dev->watchdog_timeo = BNXT_TX_TIMEOUT;
 	dev->ethtool_ops = &bnxt_ethtool_ops;
 	pci_set_drvdata(pdev, dev);
Signature · 1 line
2.43.2
maintainer
#4 lore raw

Re: [PATCH net-next v2 3/3] eth: bnxt: support per-queue statistics

Quoted 15 lines · Jakub Kicinski

Support per-queue statistics API in bnxt.

$ ethtool -S eth0
NIC statistics:
     [0]: rx_ucast_packets: 1418
     [0]: rx_mcast_packets: 178
     [0]: rx_bcast_packets: 0
     [0]: rx_discards: 0
     [0]: rx_errors: 0
     [0]: rx_ucast_bytes: 1141815
     [0]: rx_mcast_bytes: 16766
     [0]: rx_bcast_bytes: 0
     [0]: tx_ucast_packets: 1734
...

drivers/net/ethernet/broadcom/bnxt/bnxt.c static const struct net_device_ops bnxt_netdev_ops = { · line 14555

Quoted 8 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +8 -0
+
+static void bnxt_get_queue_stats_tx(struct net_device *dev, int i,
+                                   struct netdev_queue_stats_tx *stats)
+{
+       struct bnxt *bp = netdev_priv(dev);
+       u64 *sw;
+
+       sw = bp->bnapi[i]->cp_ring.stats.sw_stats;

Sorry I missed this earlier. When we are in XDP mode, the first set of TX rings is generally hidden from the user. The standard TX rings don't start from index 0. They start from bp->tx_nr_rings_xdp. Should we adjust for that?

Quoted 12 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +12 -0
+
+       stats->packets = 0;
+       stats->packets += BNXT_GET_RING_STATS64(sw, tx_ucast_pkts);
+       stats->packets += BNXT_GET_RING_STATS64(sw, tx_mcast_pkts);
+       stats->packets += BNXT_GET_RING_STATS64(sw, tx_bcast_pkts);
+
+       stats->bytes = 0;
+       stats->bytes += BNXT_GET_RING_STATS64(sw, tx_ucast_bytes);
+       stats->bytes += BNXT_GET_RING_STATS64(sw, tx_mcast_bytes);
+       stats->bytes += BNXT_GET_RING_STATS64(sw, tx_bcast_bytes);
+}
+
author maintainer
#5 lore raw

Re: [PATCH net-next v2 3/3] eth: bnxt: support per-queue statistics

Quoted 4 lines · On Wed, 28 Feb 2024 19:40:01 -0800 Michael Chan wrote:
Quoted 4 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +4 -0
+static void bnxt_get_queue_stats_tx(struct net_device *dev, int i,
+                                   struct netdev_queue_stats_tx *stats)
+{
+       struct bnxt *bp = netdev_priv(dev);
Quoted 8 lines

drivers/net/ethernet/broadcom/bnxt/bnxt.c static const struct net_device_ops bnxt_netdev_ops = { · line 14555

Quoted 3 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +3 -0
+       u64 *sw;
+
+       sw = bp->bnapi[i]->cp_ring.stats.sw_stats;  

Sorry I missed this earlier. When we are in XDP mode, the first set of TX rings is generally hidden from the user. The standard TX rings don't start from index 0. They start from bp->tx_nr_rings_xdp. Should we adjust for that?

I feel like I made this mistake before already.. Will fix, thanks!

author maintainer
#6 lore raw

Re: [PATCH net-next v2 3/3] eth: bnxt: support per-queue statistics

In reply to Michael Chan
Quoted 4 lines · On Wed, 28 Feb 2024 19:40:01 -0800 Michael Chan wrote:
Quoted 4 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +4 -0
+static void bnxt_get_queue_stats_tx(struct net_device *dev, int i,
+                                   struct netdev_queue_stats_tx *stats)
+{
+       struct bnxt *bp = netdev_priv(dev);
Quoted 8 lines

drivers/net/ethernet/broadcom/bnxt/bnxt.c static const struct net_device_ops bnxt_netdev_ops = { · line 14555

Quoted 3 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +3 -0
+       u64 *sw;
+
+       sw = bp->bnapi[i]->cp_ring.stats.sw_stats;  

Sorry I missed this earlier. When we are in XDP mode, the first set of TX rings is generally hidden from the user. The standard TX rings don't start from index 0. They start from bp->tx_nr_rings_xdp. Should we adjust for that?

Hi Michael! Sorry for the delay, I was waiting for some related netlink bits to get merged to simplify the core parts.

Not sure what the most idiomatic way would be to translate the indexes.

Do you prefer:

	bnapi = &bp->tx_ring[bp->tx_ring_map[i]].bnapi;
	sw = bnapi->cp_ring.stats.sw_stats;

or simply:

	sw = bp->bnapi[i - bp->tx_nr_rings_xdp]->cp_ring.stats.sw_stats;

or something else?

maintainer
#7 lore raw

Re: [PATCH net-next v2 3/3] eth: bnxt: support per-queue statistics

Quoted 10 lines · Jakub Kicinski
Quoted 4 lines · On Wed, 28 Feb 2024 19:40:01 -0800 Michael Chan wrote:

Sorry I missed this earlier. When we are in XDP mode, the first set of TX rings is generally hidden from the user. The standard TX rings don't start from index 0. They start from bp->tx_nr_rings_xdp. Should we adjust for that?

Hi Michael! Sorry for the delay, I was waiting for some related netlink bits to get merged to simplify the core parts.

Quoted 6 lines

Not sure what the most idiomatic way would be to translate the indexes.

Do you prefer:

        bnapi = &bp->tx_ring[bp->tx_ring_map[i]].bnapi;
        sw = bnapi->cp_ring.stats.sw_stats;

The 2 methods are interchangeable but I think it is preferred to use bp->tx_ring_map[]. It's easier to change the underlying mapping scheme in the future if we use bp->tx_ring_map[].

Quoted 6 lines

or simply:

        sw = bp->bnapi[i - bp->tx_nr_rings_xdp]->cp_ring.stats.sw_stats;

or something else?

Acked-by on the v2 series
#8 lore raw
In reply to Jakub Kicinski
Quoted 12 lines · Jakub Kicinski

Hi!

Per queue stats keep coming up, so it's about time someone laid the foundation. This series adds the uAPI, a handful of stats and a sample support for bnxt. It's not very comprehensive in terms of stat types or driver support. The expectation is that the support will grow organically. If we have the basic pieces in place it will be easy for reviewers to request new stats, or use of the API in place of ethtool -S.

See patch 3 for sample output.

Quoted 8 lines

v2:
- un-wrap short lines
- s/stats/qstats/
v1: https://lore.kernel.org/all/[email protected]/
- rename projection -> scope
- turn projection/scope into flags
- remove the "netdev" scope since it's always implied
rfc: https://lore.kernel.org/all/[email protected]/

Reviewed-by on the v2 series
#9 lore raw
In reply to Jakub Kicinski
Quoted 12 lines · Jakub Kicinski

Hi!

Per queue stats keep coming up, so it's about time someone laid the foundation. This series adds the uAPI, a handful of stats and a sample support for bnxt. It's not very comprehensive in terms of stat types or driver support. The expectation is that the support will grow organically. If we have the basic pieces in place it will be easy for reviewers to request new stats, or use of the API in place of ethtool -S.

See patch 3 for sample output.

Quoted 9 lines

v2:
- un-wrap short lines
- s/stats/qstats/
v1: https://lore.kernel.org/all/[email protected]/
- rename projection -> scope
- turn projection/scope into flags
- remove the "netdev" scope since it's always implied
rfc: https://lore.kernel.org/all/[email protected]/

Quoted 17 lines

Jakub Kicinski (3):
netdev: add per-queue statistics
netdev: add queue stat for alloc failures
eth: bnxt: support per-queue statistics

  Documentation/netlink/specs/netdev.yaml   |  91 +++++++++
  Documentation/networking/statistics.rst   |  15 ++
  drivers/net/ethernet/broadcom/bnxt/bnxt.c |  63 +++++++
  include/linux/netdevice.h                 |   3 +
  include/net/netdev_queues.h               |  56 ++++++
  include/uapi/linux/netdev.h               |  20 ++
  net/core/netdev-genl-gen.c                |  12 ++
  net/core/netdev-genl-gen.h                |   2 +
  net/core/netdev-genl.c                    | 217 ++++++++++++++++++++++
  tools/include/uapi/linux/netdev.h         |  20 ++
  10 files changed, 499 insertions(+)