net: phy: Maintain MDIO device and bus statistics
Subsystems (3)
PATCH v2 1/1 net: phy: Maintain MDIO device and bus statistics
We maintain global statistics for an entire MDIO bus, as well as broken down, per MDIO bus address statistics. Given that it is possible for MDIO devices such as switches to access MDIO bus addressies for which there is not a mdio_device instance created (therefore not a a corresponding device directory in sysfs either), we also maintain per-address statistics under the statistics folder. The layout looks like this:
/sys/class/mdio_bus/../statistics/
transfers
errrors
writes
reads
transfers_<addr>
errors_<addr>
writes_<addr>
reads_<addr>
When a mdio_device instance is registered, a statistics/ folder is created with the tranfers, errors, writes and reads attributes which point to the appropriate MDIO bus statistics structure.
Statistics are 64-bit unsigned quantities and maintained through the u64_stats_sync.h helper functions.
---
Changes in v2:
- tracked per MDIO address statististics in separate attributes
- global statistics sum all per MDIO address statistics instead of requiring another stats structure
Documentation/ABI/testing/sysfs-bus-mdio | 63 +++++++ drivers/net/phy/mdio_bus.c | 226 ++++++++++++++++++++++- include/linux/phy.h | 10 + 3 files changed, 297 insertions(+), 2 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-bus-mdio
Documentation/ABI/testing/sysfs-bus-mdio new file +63 -0
@@ -0,0 +1,63 @@ +What: /sys/bus/mdio_bus/devices/.../statistics/ +Date: January 2020 +KernelVersion: 5.6 +Contact: [email protected] +Description: + This folder contains statistics about global and per + MDIO bus address statistics. + +What: /sys/bus/mdio_bus/devices/.../statistics/transfers +Date: January 2020 +KernelVersion: 5.6 +Contact: [email protected] +Description: + Total number of transfers for this MDIO bus. + +What: /sys/bus/mdio_bus/devices/.../statistics/errors +Date: January 2020 +KernelVersion: 5.6 +Contact: [email protected] +Description: + Total number of transfer errors for this MDIO bus. + +What: /sys/bus/mdio_bus/devices/.../statistics/writes +Date: January 2020 +KernelVersion: 5.6 +Contact: [email protected] +Description: + Total number of write transactions for this MDIO bus. + +What: /sys/bus/mdio_bus/devices/.../statistics/reads +Date: January 2020 +KernelVersion: 5.6 +Contact: [email protected] +Description: + Total number of read transactions for this MDIO bus. + +What: /sys/bus/mdio_bus/devices/.../statistics/transfers_<addr> +Date: January 2020 +KernelVersion: 5.6 +Contact: [email protected] +Description: + Total number of transfers for this MDIO bus address. + +What: /sys/bus/mdio_bus/devices/.../statistics/errors_<addr> +Date: January 2020 +KernelVersion: 5.6 +Contact: [email protected] +Description: + Total number of transfer errors for this MDIO bus address. + +What: /sys/bus/mdio_bus/devices/.../statistics/writes_<addr> +Date: January 2020 +KernelVersion: 5.6 +Contact: [email protected] +Description: + Total number of write transactions for this MDIO bus address. + +What: /sys/bus/mdio_bus/devices/.../statistics/reads_<addr> +Date: January 2020 +KernelVersion: 5.6 +Contact: [email protected] +Description: + Total number of read transactions for this MDIO bus address.
drivers/net/phy/mdio_bus.c +224 -2
268 lines not on this page · raw message
include/linux/phy.h +10 -0
@@ -22,6 +22,7 @@#include <linux/timer.h> #include <linux/workqueue.h> #include <linux/mod_devicetable.h> +#include <linux/u64_stats_sync.h> #include <linux/atomic.h>
@@ -212,6 +213,14 @@ struct sfp_bus;struct sfp_upstream_ops ;struct sk_buff ; +struct mdio_bus_stats { +struct u64_stats_sync syncp; +u64_stats_t transfers; +u64_stats_t errors; +u64_stats_t writes; +u64_stats_t reads; +}; +/* * The Bus class for PHYs. Devices which provide access to * PHYs should register using this structure
@@ -224,6 +233,7 @@ struct mii_bus {int (*read)(struct mii_bus *bus,int addr,int regnum);int (*write)(struct mii_bus *bus,int addr,int regnum,u16 val);int (*reset)(struct mii_bus *bus); +struct mdio_bus_stats stats[PHY_MAX_ADDR ];/* * A lock to ensure that only one thing can read/write
Signature · 1 line
2.17.1
Quoted 22 lines · Florian Fainelli
We maintain global statistics for an entire MDIO bus, as well as broken down, per MDIO bus address statistics. Given that it is possible for MDIO devices such as switches to access MDIO bus addressies for which there is not a
mdio_deviceinstance created (therefore not a a corresponding device directory in sysfs either), we also maintain per-address statistics under the statistics folder. The layout looks like this:
/sys/class/mdio_bus/../statistics/
transfers
errrors
writes
reads
transfers_<addr>
errors_<addr>
writes_<addr>
reads_<addr>When a
mdio_deviceinstance is registered, a statistics/ folder is created with the tranfers, errors, writes and reads attributes which point to the appropriate MDIO bus statistics structure.
Quoted 8 lines
Statistics are 64-bit unsigned quantities and maintained through the
u64_stats_sync.hhelper functions.Signed-off-by Florian Fainelli <[email protected]>---
Changes in v2:- tracked per MDIO address statististics in separate attributes
Hi Florian
This is much better. Here is an MDIO bus with a Marvel MV88E6390
andrew@zii-devel-c-bidi:/sys/class/mdio_bus/0.1/statistics$ awk ' { print FILENAME " " $0 } ' transfers_? transfers_?? transfers
transfers_0 93
transfers_1 80
transfers_2 80
transfers_3 80
transfers_4 102
transfers_5 18
transfers_6 7
transfers_7 7
transfers_8 7
transfers_9 7
transfers_10 82
transfers_11 0
transfers_12 0
transfers_13 0
transfers_14 0
transfers_15 0
transfers_16 0
transfers_17 0
transfers_18 0
transfers_19 0
transfers_20 0
transfers_21 0
transfers_22 0
transfers_23 0
transfers_24 0
transfers_25 0
transfers_26 0
transfers_27 288
transfers_28 3328
transfers_29 0
transfers_30 0
transfers_31 0
transfers 4179As you can see, there are transfers on a number of addresses.
I've not looked at the code yet, but i can give:
I will review the code soon.
Andrew
Andrew Lunn
maintainerdrivers/net/phy/mdio_bus.c static void mdiobus_release(struct device *d) · line 324
Quoted 8 lines
drivers/net/phy/mdio_bus.c +8
-0+#define MDIO_BUS_STATS_ADDR_ATTR (field, addr, file) \ +static ssize_t mdio_bus_##field##_##addr##_show(struct device *dev, \ + struct device_attribute *attr, \ + char *buf) \ +{ \ + struct mii_bus *bus = to_mii_bus(dev); \ + return mdio_bus_stats_##field##_show(&bus->stats[addr], buf); \ +} \
Hi Florian
Lots of Macro magic here. But it is reasonably understandable. However, the compiler is maybe not doing the best of jobs:
00000064 l F .text 00000030 mdio_bus_reads_31_show 00000094 l F .text 00000030 mdio_bus_reads_30_show 000000c4 l F .text 00000030 mdio_bus_reads_29_show 000000f4 l F .text 00000030 mdio_bus_reads_28_show 00000124 l F .text 00000030 mdio_bus_reads_27_show 00000154 l F .text 00000030 mdio_bus_reads_26_show 00000184 l F .text 00000030 mdio_bus_reads_25_show 000001b4 l F .text 00000034 mdio_bus_reads_24_show 000001e8 l F .text 00000034 mdio_bus_reads_23_show 0000021c l F .text 00000034 mdio_bus_reads_22_show 00000250 l F .text 00000034 mdio_bus_reads_21_show 00000284 l F .text 00000034 mdio_bus_reads_20_show 000002b8 l F .text 00000034 mdio_bus_reads_19_show 000002ec l F .text 00000034 mdio_bus_reads_18_show 00000320 l F .text 00000034 mdio_bus_reads_17_show 00000354 l F .text 00000034 mdio_bus_reads_16_show 00000388 l F .text 00000034 mdio_bus_reads_15_show 000003bc l F .text 00000034 mdio_bus_reads_14_show 000003f0 l F .text 00000034 mdio_bus_reads_13_show 00000424 l F .text 00000034 mdio_bus_reads_12_show 00000458 l F .text 00000034 mdio_bus_reads_11_show 0000048c l F .text 00000034 mdio_bus_reads_10_show 000004c0 l F .text 00000034 mdio_bus_reads_9_show 000004f4 l F .text 00000034 mdio_bus_reads_8_show 00000528 l F .text 00000034 mdio_bus_reads_7_show 0000055c l F .text 00000034 mdio_bus_reads_6_show 00000590 l F .text 00000034 mdio_bus_reads_5_show 000005c4 l F .text 00000034 mdio_bus_reads_4_show 000005f8 l F .text 00000034 mdio_bus_reads_3_show 0000062c l F .text 00000034 mdio_bus_reads_2_show 00000660 l F .text 00000034 mdio_bus_reads_1_show 00000694 l F .text 00000034 mdio_bus_reads_0_show
It appears to be inlining everything, so end up with lots of functions, and they are not tiny.
I'm wondering if we can get ride of this per address reads/write/transfer function. Could you stuff the addr into var of struct dev_ext_attribute?
https://elixir.bootlin.com/linux/latest/source/include/linux/device.h#L813
Andrew
Hi Andrew,
Quoted 47 lines · Andrew Lunn
drivers/net/phy/mdio_bus.c static void mdiobus_release(struct device *d) · line 324
Quoted 8 lines
drivers/net/phy/mdio_bus.c +8
-0+#define MDIO_BUS_STATS_ADDR_ATTR (field, addr, file) \ +static ssize_t mdio_bus_##field##_##addr##_show(struct device *dev, \ + struct device_attribute *attr, \ + char *buf) \ +{ \ + struct mii_bus *bus = to_mii_bus(dev); \ + return mdio_bus_stats_##field##_show(&bus->stats[addr], buf); \ +} \Hi Florian
Lots of Macro magic here. But it is reasonably understandable. However, the compiler is maybe not doing the best of jobs:
00000064 l F .text 00000030 mdio_bus_reads_31_show 00000094 l F .text 00000030 mdio_bus_reads_30_show 000000c4 l F .text 00000030 mdio_bus_reads_29_show 000000f4 l F .text 00000030 mdio_bus_reads_28_show 00000124 l F .text 00000030 mdio_bus_reads_27_show 00000154 l F .text 00000030 mdio_bus_reads_26_show 00000184 l F .text 00000030 mdio_bus_reads_25_show 000001b4 l F .text 00000034 mdio_bus_reads_24_show 000001e8 l F .text 00000034 mdio_bus_reads_23_show 0000021c l F .text 00000034 mdio_bus_reads_22_show 00000250 l F .text 00000034 mdio_bus_reads_21_show 00000284 l F .text 00000034 mdio_bus_reads_20_show 000002b8 l F .text 00000034 mdio_bus_reads_19_show 000002ec l F .text 00000034 mdio_bus_reads_18_show 00000320 l F .text 00000034 mdio_bus_reads_17_show 00000354 l F .text 00000034 mdio_bus_reads_16_show 00000388 l F .text 00000034 mdio_bus_reads_15_show 000003bc l F .text 00000034 mdio_bus_reads_14_show 000003f0 l F .text 00000034 mdio_bus_reads_13_show 00000424 l F .text 00000034 mdio_bus_reads_12_show 00000458 l F .text 00000034 mdio_bus_reads_11_show 0000048c l F .text 00000034 mdio_bus_reads_10_show 000004c0 l F .text 00000034 mdio_bus_reads_9_show 000004f4 l F .text 00000034 mdio_bus_reads_8_show 00000528 l F .text 00000034 mdio_bus_reads_7_show 0000055c l F .text 00000034 mdio_bus_reads_6_show 00000590 l F .text 00000034 mdio_bus_reads_5_show 000005c4 l F .text 00000034 mdio_bus_reads_4_show 000005f8 l F .text 00000034 mdio_bus_reads_3_show 0000062c l F .text 00000034 mdio_bus_reads_2_show 00000660 l F .text 00000034 mdio_bus_reads_1_show 00000694 l F .text 00000034 mdio_bus_reads_0_show
Quoted 6 lines
It appears to be inlining everything, so end up with lots of functions, and they are not tiny.
I'm wondering if we can get ride of this per address reads/write/transfer function. Could you stuff the addr into var of struct
dev_ext_attribute?
That is a great suggestion, thanks! This should reduce the number of those _show functions, expect v3 soon.
Signature · 1 line
Florian