History

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

Jakub Kicinski committed 2 years ago

Commit ab63a231 parent e8bb2cc9 files · +421 −0Browse files

Showing the changes to tools/include/uapi/linux/netdev.h (1 of 9 files). Show all

Unified · Split

tools/include/uapi/linux/netdev.h+19−0
@@ -70,6 +70,10 @@ enum netdev_queue_type { · 69 unmodified lines
7070 NETDEV_QUEUE_TYPE_TX,
7171 };
7272
73+enum netdev_qstats_scope {
74+ NETDEV_QSTATS_SCOPE_QUEUE = 1,
75+};
76+
7377 enum {
7478 NETDEV_A_DEV_IFINDEX = 1,
7579 NETDEV_A_DEV_PAD,
@@ -132,6 +136,20 @@ enum { · 56 unmodified lines
132136 NETDEV_A_QUEUE_MAX = (__NETDEV_A_QUEUE_MAX - 1)
133137 };
134138
139+enum {
140+ NETDEV_A_QSTATS_IFINDEX = 1,
141+ NETDEV_A_QSTATS_QUEUE_TYPE,
142+ NETDEV_A_QSTATS_QUEUE_ID,
143+ NETDEV_A_QSTATS_SCOPE,
144+ NETDEV_A_QSTATS_RX_PACKETS = 8,
145+ NETDEV_A_QSTATS_RX_BYTES,
146+ NETDEV_A_QSTATS_TX_PACKETS,
147+ NETDEV_A_QSTATS_TX_BYTES,
148+
149+ __NETDEV_A_QSTATS_MAX,
150+ NETDEV_A_QSTATS_MAX = (__NETDEV_A_QSTATS_MAX - 1)
151+};
152+
135153 enum {
136154 NETDEV_CMD_DEV_GET = 1,
137155 NETDEV_CMD_DEV_ADD_NTF,
@@ -144,6 +162,7 @@ enum { · 6 unmodified lines
144162 NETDEV_CMD_PAGE_POOL_STATS_GET,
145163 NETDEV_CMD_QUEUE_GET,
146164 NETDEV_CMD_NAPI_GET,
165+ NETDEV_CMD_QSTATS_GET,
147166
148167 __NETDEV_CMD_MAX,
149168 NETDEV_CMD_MAX = (__NETDEV_CMD_MAX - 1)