net: tighten the definition of interface statistics
Subsystems (3)
Jakub Kicinski
maintainerPATCH 1/1 net: tighten the definition of interface statistics
This patch is born out of an investigation into which IEEE statistics correspond to which struct rtnl_link_stats64 members. Turns out that there seems to be reasonable consensus on the matter, among many drivers. To save others the time (and it took more time than I'm comfortable admitting) I'm adding comments referring to IEEE attributes to struct rtnl_link_stats64.
Up until now we had two forms of documentation for stats - in Documentation/ABI/testing/sysfs-class-net-statistics and the comments on struct rtnl_link_stats64 itself. While the former is very cautious in defining the expected behavior, the latter feel quite dated and may not be easy to understand for modern day driver author (e.g. rx_over_errors). At the same time modern systems are far more complex and once obvious definitions lost their clarity. For example
- does rx_packet count at the MAC layer (aFramesReceivedOK)? packets processed correctly by hardware? received by the driver? or maybe received by the stack?
I tried to clarify the expectations, further clarifications from others are very welcome.
The part hardest to untangle is rx_over_errors vs rx_fifo_errors vs rx_missed_errors. After much deliberation I concluded that for modern HW only two of the counters will make sense. The distinction between internal FIFO overflow and packets dropped due to back-pressure from the host is likely too implementation (driver and device) specific to expose in the standard stats.
Now - which two of those counters we select to use is anyone's pick:
sysfs documentation suggests rx_over_errors counts packets which did not fit into buffers due to MTU being too small, which I reused. There don't seem to be many modern drivers using it (well, CAN drivers seem to love this statistic).
Of the remaining two I picked rx_missed_errors to report device drops. bnxt reports it and it's folded into "drop"s in procfs (while rx_fifo_errors is an error, and modern devices usually receive the frame OK, they just can't admit it into the pipeline).
Of the drivers I looked at only AMD Lance-like and NS8390-like use all three of these counters. rx_missed_errors counts missed frames, rx_over_errors counts overflow events, and rx_fifo_errors counts frames which were truncated because they didn't fit into buffers. This suggests that rx_fifo_errors may be the correct stat for truncated packets, but I'd think a FIFO stat counting truncated packets would be very confusing to a modern reader.
--- Documentation/networking/index.rst | 1 + Documentation/networking/statistics.rst | 123 +++++++++++++++ include/uapi/linux/if_link.h | 198 ++++++++++++++++++++++-- 3 files changed, 305 insertions(+), 17 deletions(-) create mode 100644 Documentation/networking/statistics.rst
Documentation/networking/index.rst +1 -0
@@ -93,6 +93,7 @@ Linux Networking Documentation sctp secid seg6-sysctl + statistics strparser switchdev tc-actions-env-rules
Documentation/networking/statistics.rst new file +123 -0
123 lines not on this page · raw message
include/uapi/linux/if_link.h +181 -17
215 lines not on this page · raw message
Signature · 1 line
2.26.2
Documentation/networking/statistics.rst line 112
Quoted 4 lines · Jakub Kicinski
Documentation/networking/statistics.rst new file +4
-0+Drivers should report all statistics which have a matching member in +:c:type:`struct rtnl_link_stats64 <rtnl_link_stats64>` exclusively +via `.ndo_get_stats64`. Reporting such standard stats via ethtool +or debugfs will not be accepted.
Should existing drivers that currently duplicate standard stats in the ethtool list be revised also?
Quoted 4 lines
+ * @rx_packets: Number of good packets received by the interface.
+ * For hardware interfaces counts all good packets seen by the host, + * including packets which host had to drop at various stages of processing + * (even in the driver).
This is perhaps a bit ambiguous. I think you mean to say packets received from the device, but I could also interpret the above to mean received by the device if 'host' is read to be the whole physical machine (ie. including NIC hardware) instead of the part that is apart from the NIC from the NIC's perspective.
Quoted 2 lines
+ * @rx_bytes: Number of good incoming bytes, corresponding to @rx_packets.
+ * @tx_bytes: Number of good incoming bytes, corresponding to @tx_packets.
Including or excluding FCS?
Quoted 3 lines
+ * For Ethernet devices this counter may be equivalent to:
+ *
+ * - 30.3.1.1.21 aMulticastFramesReceivedOK
You mention the IEEE standard in your commit message, but I don't think this document properly cites what you are referring to here? It might be an idea to say "IEEE 30.3.1.1.21 aMulticastFramesReceivedOK" here and provide an appropriate citation reference at the end, or perhaps a link.
Regards,
Edwin Peer
Jakub Kicinski
maintainerQuoted 8 lines · On Thu, 3 Sep 2020 09:29:22 -0700 Edwin Peer wrote:
Documentation/networking/statistics.rst line 112
Quoted 4 lines · Jakub Kicinski
Documentation/networking/statistics.rst new file +4
-0+Drivers should report all statistics which have a matching member in +:c:type:`struct rtnl_link_stats64 <rtnl_link_stats64>` exclusively +via `.ndo_get_stats64`. Reporting such standard stats via ethtool +or debugfs will not be accepted.Should existing drivers that currently duplicate standard stats in the ethtool list be revised also?
That's probably considered uAPI land. I've removed the stats from the nfp awhile back, and nobody complained, but I'm thinking to leave the decision to individual maintainers.
Funnily enough number of 10G and 40G drivers report tx_heartbeat_errors in their ethtool stats (always as 0). Explainer what the statistic counts for a contemporary reader:
http://www.ethermanage.com/ethernet/sqe/sqe.html
Quoted 9 lines
Quoted 4 lines
+ * @rx_packets: Number of good packets received by the interface.
+ * For hardware interfaces counts all good packets seen by the host, + * including packets which host had to drop at various stages of processing + * (even in the driver).This is perhaps a bit ambiguous. I think you mean to say packets received from the device, but I could also interpret the above to mean received by the device if 'host' is read to be the whole physical machine (ie. including NIC hardware) instead of the part that is apart from the NIC from the NIC's perspective.
How about:
For hardware interfaces counts all good packets received from the device by the host, including packets which host had to drop...
Quoted 4 lines
Quoted 2 lines
+ * @rx_bytes: Number of good incoming bytes, corresponding to @rx_packets.
+ * @tx_bytes: Number of good incoming bytes, corresponding to @tx_packets.Including or excluding FCS?
Good point, no FCS is probably a reasonable expectation.
I'm not sure what to say about pad. I'm tempted to also mention that for tx we shouldn't count pad, no? (IOW Ethernet Frame - FCS - pad)
Quoted 8 lines
Quoted 3 lines
+ * For Ethernet devices this counter may be equivalent to:
+ *
+ * - 30.3.1.1.21 aMulticastFramesReceivedOKYou mention the IEEE standard in your commit message, but I don't think this document properly cites what you are referring to here? It might be an idea to say "IEEE 30.3.1.1.21 aMulticastFramesReceivedOK" here and provide an appropriate citation reference at the end, or perhaps a link.
How about I replace Ethernet with IEEE 802.3:
For IEEE 802.3 devices this counter may be equivalent to:
- 30.3.1.1.21 aMulticastFramesReceivedOK
Quoted 38 lines · Jakub Kicinski
Quoted 8 lines · On Thu, 3 Sep 2020 09:29:22 -0700 Edwin Peer wrote:
Documentation/networking/statistics.rst line 112
Quoted 4 lines · Jakub Kicinski
Documentation/networking/statistics.rst new file +4
-0+Drivers should report all statistics which have a matching member in +:c:type:`struct rtnl_link_stats64 <rtnl_link_stats64>` exclusively +via `.ndo_get_stats64`. Reporting such standard stats via ethtool +or debugfs will not be accepted.Should existing drivers that currently duplicate standard stats in the ethtool list be revised also?
That's probably considered uAPI land. I've removed the stats from the nfp awhile back, and nobody complained, but I'm thinking to leave the decision to individual maintainers.
Funnily enough number of 10G and 40G drivers report
tx_heartbeat_errorsin their ethtool stats (always as 0). Explainer what the statistic counts for a contemporary reader:http://www.ethermanage.com/ethernet/sqe/sqe.html
Quoted 9 lines
Quoted 4 lines
+ * @rx_packets: Number of good packets received by the interface.
+ * For hardware interfaces counts all good packets seen by the host, + * including packets which host had to drop at various stages of processing + * (even in the driver).This is perhaps a bit ambiguous. I think you mean to say packets received from the device, but I could also interpret the above to mean received by the device if 'host' is read to be the whole physical machine (ie. including NIC hardware) instead of the part that is apart from the NIC from the NIC's perspective.
How about:
For hardware interfaces counts all good packets received from the device by the host, including packets which host had to drop...
Quoted 3 lines
Quoted 2 lines
+ * @rx_bytes: Number of good incoming bytes, corresponding to @rx_packets.
+ * @tx_bytes: Number of good incoming bytes, corresponding to @tx_packets.
Quoted 6 lines
Quoted 1 line
Including or excluding FCS?
Good point, no FCS is probably a reasonable expectation.
I'm not sure what to say about pad. I'm tempted to also mention that for tx we shouldn't count pad, no? (IOW Ethernet Frame - FCS - pad)
It depends I would say, if the driver needed to add padding in order to get the frame to be transmitted because the Ethernet MAC cannot pad automatically then it would seem natural to count the added padding. If you implement BQL that is what you will be reporting because that how much travels on the wire. What do you think?
Quoted 16 lines
Quoted 9 lines
Quoted 4 lines
+ * For Ethernet devices this counter may be equivalent to:
+ *
+ * - 30.3.1.1.21 aMulticastFramesReceivedOKYou mention the IEEE standard in your commit message, but I don't think this document properly cites what you are referring to here? It might be an idea to say "IEEE 30.3.1.1.21 aMulticastFramesReceivedOK" here and provide an appropriate citation reference at the end, or perhaps a link.
How about I replace Ethernet with IEEE 802.3:
For IEEE 802.3 devices this counter may be equivalent to:
- 30.3.1.1.21 aMulticastFramesReceivedOK
Signature · 1 line
Florian
Jakub Kicinski
maintainerQuoted 5 lines · On Thu, 3 Sep 2020 13:48:39 -0700 Florian Fainelli wrote:
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines
+ * @rx_bytes: Number of good incoming bytes, corresponding to @rx_packets.
+ * @tx_bytes: Number of good incoming bytes, corresponding to @tx_packets.Including or excluding FCS?
Quoted 8 lines
Quoted 4 lines
Good point, no FCS is probably a reasonable expectation.
I'm not sure what to say about pad. I'm tempted to also mention that for tx we shouldn't count pad, no? (IOW Ethernet Frame - FCS - pad)
It depends I would say, if the driver needed to add padding in order to get the frame to be transmitted because the Ethernet MAC cannot pad automatically then it would seem natural to count the added padding.
Ack, I was actually hoping "modern" devices don't need this, but I was wrong :S Looks like bnxt is padding. And Intel devices pad on RX, which NFP used to do as well, until I removed it. Any idea why do people do this?
Quoted 2 lines
If you implement BQL that is what you will be reporting because that how much travels on the wire. What do you think?
No strong preference. I'm not very concerned about BQL, it doesn't account for other "realities" of wire transmission anyway. And I thought it would be nice for interface stats to match Qdisc stats. Plus feels strange putting burden on devices which do things "right".
But unless we count pad on TX we'd have an asymmetry where we expect pad on RX but not TX. So I think you're right. Let's suggest to count pad both ways (for Ethernet, at least).
Quoted 5 lines · Jakub Kicinski
Documentation/networking/statistics.rst new file +0
-0
...
Documentation/networking/statistics.rst line 65
Quoted 10 lines
Documentation/networking/statistics.rst new file +10
-0+ +sysfs +----- + +Each device directory in sysfs contains a `statistics` directory (e.g. +`/sys/class/net/lo/statistics/`) with files corresponding to +members of :c:type:`struct rtnl_link_stats64 <rtnl_link_stats64>`. + +This simple interface is convenient especially in constrained/embedded +environments without access to tools. However, it's sightly inefficient
sightly seems like the wrong word. Did you mean 'highly inefficient'?
Quoted 13 lines
Documentation/networking/statistics.rst new file +13
-0+when reading multiple stats as it internally performs a full dump of +:c:type:`struct rtnl_link_stats64 <rtnl_link_stats64>` +and reports only the stat corresponding to the accessed file. + +Sysfs files are documented in +`Documentation/ABI/testing/sysfs-class-net-statistics`. + + +netlink +------- + +`rtnetlink` (`NETLINK_ROUTE`) is the preferred method of accessing +:c:type:`struct rtnl_link_stats64 <rtnl_link_stats64>` stats.
Documentation/networking/statistics.rst line 88
Quoted 10 lines
Documentation/networking/statistics.rst new file +10
-0+ +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). + +ethtool +------- + +Ethtool IOCTL interface allows drivers to report implementation +specific statistics.
an example here would be helpful. e.g., I use ethool -S primarily for per queue stats which show more details than the other APIs which show aggregated stats.
Quoted 5 lines
include/uapi/linux/if_link.h +0
-0
include/uapi/linux/if_link.h struct rtnl_link_stats { · line 47
Quoted 9 lines
include/uapi/linux/if_link.h +5
-1@@ -40,26 +40,191 @@ struct rtnl_link_stats {__u32 rx_nohandler;/* dropped, no handler found */ }; -/* The main device statistics structure */ +/** +* struct rtnl_link_stats64 - The main device statistics structure. +* +* @rx_packets: Number of good packets received by the interface. +* For hardware interfaces counts all good packets seen by the host,> + * including packets which host had to drop at various stages of
processing
include/uapi/linux/if_link.h struct rtnl_link_stats { · line 57
Quoted 9 lines
include/uapi/linux/if_link.h +9
-0+* (even in the driver). +* +* @tx_packets: Number of packets successfully transmitted. +* For hardware interfaces counts packets which host was able to successfully +* hand over to the device, which does not necessarily mean that packets +* had been successfully transmitted out of the device, only that device +* acknowledged it copied them out of host memory. +* +* @rx_bytes: Number of good incoming bytes, corresponding to @rx_packets.
s/incoming/received/?
include/uapi/linux/if_link.h struct rtnl_link_stats { · line 58
Quoted 2 lines
include/uapi/linux/if_link.h +2
-0+* +* @tx_bytes: Number of good incoming bytes, corresponding to @tx_packets.
s/incoming/transmitted/
Thanks for taking the time to work on this; I'm sure you spent a LOT of hours going through all of the drivers and APIs.
Jakub Kicinski
maintainerQuoted 12 lines · On Thu, 3 Sep 2020 16:40:54 -0600 David Ahern wrote:
Documentation/networking/statistics.rst line 65
Quoted 9 lines · Jakub Kicinski
Documentation/networking/statistics.rst new file +9
-0+sysfs +----- + +Each device directory in sysfs contains a `statistics` directory (e.g. +`/sys/class/net/lo/statistics/`) with files corresponding to +members of :c:type:`struct rtnl_link_stats64 <rtnl_link_stats64>`. + +This simple interface is convenient especially in constrained/embedded +environments without access to tools. However, it's sightly inefficientsightly seems like the wrong word. Did you mean 'highly inefficient'?
Indeed, I'll drop the "slightly". Hopefully the info below is clear enough for users to understand what's happening.
Quoted 19 lines
Quoted 19 lines
Documentation/networking/statistics.rst new file +19
-0+when reading multiple stats as it internally performs a full dump of +:c:type:`struct rtnl_link_stats64 <rtnl_link_stats64>` +and reports only the stat corresponding to the accessed file. + +Sysfs files are documented in +`Documentation/ABI/testing/sysfs-class-net-statistics`. + + +netlink +------- + +`rtnetlink` (`NETLINK_ROUTE`) is the preferred method of accessing +:c:type:`struct rtnl_link_stats64 <rtnl_link_stats64>` stats. + +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). + +ethtool
Quoted 8 lines
Documentation/networking/statistics.rst line 88
Quoted 4 lines
+-------
Documentation/networking/statistics.rst new file +3
-0+ +Ethtool IOCTL interface allows drivers to report implementation +specific statistics.an example here would be helpful. e.g., I use
ethool -Sprimarily for per queue stats which show more details than the other APIs which show aggregated stats.
I'll mention the queue stats here.
Quoted 27 lines
Quoted 14 lines
include/uapi/linux/if_link.h +5
-1@@ -40,26 +40,191 @@ struct rtnl_link_stats {__u32 rx_nohandler;/* dropped, no handler found */ }; -/* The main device statistics structure */ +/** +* struct rtnl_link_stats64 - The main device statistics structure. +* +* @rx_packets: Number of good packets received by the interface. +* For hardware interfaces counts all good packets seen by the host, include/uapi/linux/if_link.h struct rtnl_link_stats { · line 57
Quoted 10 lines
include/uapi/linux/if_link.h +10
-0+* including packets which host had to drop at various stages of processing +* (even in the driver). +* +* @tx_packets: Number of packets successfully transmitted. +* For hardware interfaces counts packets which host was able to successfully +* hand over to the device, which does not necessarily mean that packets +* had been successfully transmitted out of the device, only that device +* acknowledged it copied them out of host memory. +* +* @rx_bytes: Number of good incoming bytes, corresponding to @rx_packets. s/incoming/received/?
Quoted 4 lines
include/uapi/linux/if_link.h struct rtnl_link_stats { · line 59
Quoted 2 lines
include/uapi/linux/if_link.h +2
-0+* +* @tx_bytes: Number of good incoming bytes, corresponding to @tx_packets. s/incoming/transmitted/
:o I wonder where I got those from.
Quoted 2 lines
Thanks for taking the time to work on this; I'm sure you spent a LOT of hours going through all of the drivers and APIs.
And "dusty datasheets" :)
Jakub Kicinski
maintainerQuoted 7 lines · On Thu, 3 Sep 2020 16:02:28 -0700 Jakub Kicinski wrote:
Quoted 4 lines
Documentation/networking/statistics.rst line 65
Quoted 2 lines
Documentation/networking/statistics.rst new file +2
-0+This simple interface is convenient especially in constrained/embedded +environments without access to tools. However, it's sightly inefficientsightly seems like the wrong word. Did you mean 'highly inefficient'?
Indeed, I'll drop the "slightly". Hopefully the info below is clear enough for users to understand what's happening.
Ah, I realized now I was missing the 'l'. Anyway, I dropped the word, it didn't add much.