* [PATCH net-next 0/8] net: phy: improve stats handling in mdio_bus.c
@ 2026-02-27 22:04 Heiner Kallweit
2026-02-27 22:05 ` [PATCH net-next 1/8] net: mdio: extend struct mdio_bus_stat_attr instead of using dev_ext_attribute Heiner Kallweit
` (8 more replies)
0 siblings, 9 replies; 12+ messages in thread
From: Heiner Kallweit @ 2026-02-27 22:04 UTC (permalink / raw)
To: Andrew Lunn, Andrew Lunn, Russell King - ARM Linux, Paolo Abeni,
Eric Dumazet, David Miller, Jakub Kicinski
Cc: netdev@vger.kernel.org
Improve stats handling in mdio_bus.c.
Heiner Kallweit (8):
net: mdio: extend struct mdio_bus_stat_attr instead of using
dev_ext_attribute
net: mdio: use macro __ATTR to simplify the code
net: phy: consider that mdio_bus_device_stat_field_show doesn't use
member address
net: phy: avoid extra casting in mdio_bus_get_stat
net: mdio: constify attributes and attribute arrays
net: mdio: use macro __ATTRIBUTE_GROUPS
net: phy: inline helper mdio_bus_get_global_stat
net: phy: improve mdiobus_stats_acct
drivers/net/phy/mdio_bus.c | 124 ++++++++++++++-----------------------
1 file changed, 46 insertions(+), 78 deletions(-)
--
2.53.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH net-next 1/8] net: mdio: extend struct mdio_bus_stat_attr instead of using dev_ext_attribute
2026-02-27 22:04 [PATCH net-next 0/8] net: phy: improve stats handling in mdio_bus.c Heiner Kallweit
@ 2026-02-27 22:05 ` Heiner Kallweit
2026-02-27 22:06 ` [PATCH net-next 2/8] net: mdio: use macro __ATTR to simplify the code Heiner Kallweit
` (7 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Heiner Kallweit @ 2026-02-27 22:05 UTC (permalink / raw)
To: Andrew Lunn, Andrew Lunn, Russell King - ARM Linux, Paolo Abeni,
Eric Dumazet, David Miller, Jakub Kicinski
Cc: netdev@vger.kernel.org
Currently the var member of struct dev_ext_attribute is used in a very
ugly way. Extend struct mdio_bus_stat_attr instead, what allows to
simplify the code and also slightly reduces memory footprint.
Note: Member addr is renamed to avoid a conflict in macro
MDIO_BUS_STATS_ADDR_ATTR_DECL.
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
drivers/net/phy/mdio_bus.c | 45 +++++++++++++++++---------------------
1 file changed, 20 insertions(+), 25 deletions(-)
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index afdf1ad6c0e..4fe9859369b 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -124,10 +124,16 @@ static void mdiobus_release(struct device *d)
}
struct mdio_bus_stat_attr {
- int addr;
+ struct device_attribute attr;
+ int address;
unsigned int field_offset;
};
+static struct mdio_bus_stat_attr *to_sattr(struct device_attribute *attr)
+{
+ return container_of(attr, struct mdio_bus_stat_attr, attr);
+}
+
static u64 mdio_bus_get_stat(struct mdio_bus_stats *s, unsigned int offset)
{
const char *p = (const char *)s + offset;
@@ -157,18 +163,14 @@ static ssize_t mdio_bus_stat_field_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
+ struct mdio_bus_stat_attr *sattr = to_sattr(attr);
struct mii_bus *bus = to_mii_bus(dev);
- struct mdio_bus_stat_attr *sattr;
- struct dev_ext_attribute *eattr;
u64 val;
- eattr = container_of(attr, struct dev_ext_attribute, attr);
- sattr = eattr->var;
-
- if (sattr->addr < 0)
+ if (sattr->address < 0)
val = mdio_bus_get_global_stat(bus, sattr->field_offset);
else
- val = mdio_bus_get_stat(&bus->stats[sattr->addr],
+ val = mdio_bus_get_stat(&bus->stats[sattr->address],
sattr->field_offset);
return sysfs_emit(buf, "%llu\n", val);
@@ -178,37 +180,31 @@ static ssize_t mdio_bus_device_stat_field_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
+ struct mdio_bus_stat_attr *sattr = to_sattr(attr);
struct mdio_device *mdiodev = to_mdio_device(dev);
struct mii_bus *bus = mdiodev->bus;
- struct mdio_bus_stat_attr *sattr;
- struct dev_ext_attribute *eattr;
int addr = mdiodev->addr;
u64 val;
- eattr = container_of(attr, struct dev_ext_attribute, attr);
- sattr = eattr->var;
-
val = mdio_bus_get_stat(&bus->stats[addr], sattr->field_offset);
return sysfs_emit(buf, "%llu\n", val);
}
#define MDIO_BUS_STATS_ATTR_DECL(field, file) \
-static struct dev_ext_attribute dev_attr_mdio_bus_##field = { \
+static struct mdio_bus_stat_attr dev_attr_mdio_bus_##field = { \
.attr = { .attr = { .name = file, .mode = 0444 }, \
.show = mdio_bus_stat_field_show, \
}, \
- .var = &((struct mdio_bus_stat_attr) { \
- -1, offsetof(struct mdio_bus_stats, field) \
- }), \
+ .address = -1, \
+ .field_offset = offsetof(struct mdio_bus_stats, field), \
}; \
-static struct dev_ext_attribute dev_attr_mdio_bus_device_##field = { \
+static struct mdio_bus_stat_attr dev_attr_mdio_bus_device_##field = { \
.attr = { .attr = { .name = file, .mode = 0444 }, \
.show = mdio_bus_device_stat_field_show, \
}, \
- .var = &((struct mdio_bus_stat_attr) { \
- -1, offsetof(struct mdio_bus_stats, field) \
- }), \
+ .address = -1, \
+ .field_offset = offsetof(struct mdio_bus_stats, field), \
};
#define MDIO_BUS_STATS_ATTR(field) \
@@ -220,13 +216,12 @@ MDIO_BUS_STATS_ATTR(writes);
MDIO_BUS_STATS_ATTR(reads);
#define MDIO_BUS_STATS_ADDR_ATTR_DECL(field, addr, file) \
-static struct dev_ext_attribute dev_attr_mdio_bus_addr_##field##_##addr = { \
+static struct mdio_bus_stat_attr dev_attr_mdio_bus_addr_##field##_##addr = { \
.attr = { .attr = { .name = file, .mode = 0444 }, \
.show = mdio_bus_stat_field_show, \
}, \
- .var = &((struct mdio_bus_stat_attr) { \
- addr, offsetof(struct mdio_bus_stats, field) \
- }), \
+ .address = addr, \
+ .field_offset = offsetof(struct mdio_bus_stats, field), \
}
#define MDIO_BUS_STATS_ADDR_ATTR(field, addr) \
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH net-next 2/8] net: mdio: use macro __ATTR to simplify the code
2026-02-27 22:04 [PATCH net-next 0/8] net: phy: improve stats handling in mdio_bus.c Heiner Kallweit
2026-02-27 22:05 ` [PATCH net-next 1/8] net: mdio: extend struct mdio_bus_stat_attr instead of using dev_ext_attribute Heiner Kallweit
@ 2026-02-27 22:06 ` Heiner Kallweit
2026-02-27 22:07 ` [PATCH net-next 3/8] net: phy: consider that mdio_bus_device_stat_field_show doesn't use member address Heiner Kallweit
` (6 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Heiner Kallweit @ 2026-02-27 22:06 UTC (permalink / raw)
To: Andrew Lunn, Andrew Lunn, Russell King - ARM Linux, Paolo Abeni,
Eric Dumazet, David Miller, Jakub Kicinski
Cc: netdev@vger.kernel.org
Use macro __ATTR to simplify the code. Note that __ATTR can't be used
in MDIO_BUS_STATS_ADDR_ATTR_DECL because the included stringification
would conflict with how argument file is passed.
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
drivers/net/phy/mdio_bus.c | 15 ++++-----------
1 file changed, 4 insertions(+), 11 deletions(-)
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 4fe9859369b..0c0cf7a7296 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -191,24 +191,17 @@ static ssize_t mdio_bus_device_stat_field_show(struct device *dev,
return sysfs_emit(buf, "%llu\n", val);
}
-#define MDIO_BUS_STATS_ATTR_DECL(field, file) \
+#define MDIO_BUS_STATS_ATTR(field) \
static struct mdio_bus_stat_attr dev_attr_mdio_bus_##field = { \
- .attr = { .attr = { .name = file, .mode = 0444 }, \
- .show = mdio_bus_stat_field_show, \
- }, \
+ .attr = __ATTR(field, 0444, mdio_bus_stat_field_show, NULL), \
.address = -1, \
.field_offset = offsetof(struct mdio_bus_stats, field), \
}; \
static struct mdio_bus_stat_attr dev_attr_mdio_bus_device_##field = { \
- .attr = { .attr = { .name = file, .mode = 0444 }, \
- .show = mdio_bus_device_stat_field_show, \
- }, \
+ .attr = __ATTR(field, 0444, mdio_bus_device_stat_field_show, NULL), \
.address = -1, \
.field_offset = offsetof(struct mdio_bus_stats, field), \
-};
-
-#define MDIO_BUS_STATS_ATTR(field) \
- MDIO_BUS_STATS_ATTR_DECL(field, __stringify(field))
+}
MDIO_BUS_STATS_ATTR(transfers);
MDIO_BUS_STATS_ATTR(errors);
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH net-next 3/8] net: phy: consider that mdio_bus_device_stat_field_show doesn't use member address
2026-02-27 22:04 [PATCH net-next 0/8] net: phy: improve stats handling in mdio_bus.c Heiner Kallweit
2026-02-27 22:05 ` [PATCH net-next 1/8] net: mdio: extend struct mdio_bus_stat_attr instead of using dev_ext_attribute Heiner Kallweit
2026-02-27 22:06 ` [PATCH net-next 2/8] net: mdio: use macro __ATTR to simplify the code Heiner Kallweit
@ 2026-02-27 22:07 ` Heiner Kallweit
2026-02-27 22:07 ` [PATCH net-next 4/8] net: phy: avoid extra casting in mdio_bus_get_stat Heiner Kallweit
` (5 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Heiner Kallweit @ 2026-02-27 22:07 UTC (permalink / raw)
To: Andrew Lunn, Andrew Lunn, Russell King - ARM Linux, Paolo Abeni,
Eric Dumazet, David Miller, Jakub Kicinski
Cc: netdev@vger.kernel.org
mdio_bus_device_stat_field_show() doesn't use the address member,
so we don't have to initialize it.
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
drivers/net/phy/mdio_bus.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 0c0cf7a7296..f189e9fbcbd 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -199,7 +199,6 @@ static struct mdio_bus_stat_attr dev_attr_mdio_bus_##field = { \
}; \
static struct mdio_bus_stat_attr dev_attr_mdio_bus_device_##field = { \
.attr = __ATTR(field, 0444, mdio_bus_device_stat_field_show, NULL), \
- .address = -1, \
.field_offset = offsetof(struct mdio_bus_stats, field), \
}
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH net-next 4/8] net: phy: avoid extra casting in mdio_bus_get_stat
2026-02-27 22:04 [PATCH net-next 0/8] net: phy: improve stats handling in mdio_bus.c Heiner Kallweit
` (2 preceding siblings ...)
2026-02-27 22:07 ` [PATCH net-next 3/8] net: phy: consider that mdio_bus_device_stat_field_show doesn't use member address Heiner Kallweit
@ 2026-02-27 22:07 ` Heiner Kallweit
2026-02-27 22:08 ` [PATCH net-next 5/8] net: mdio: constify attributes and attribute arrays Heiner Kallweit
` (4 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Heiner Kallweit @ 2026-02-27 22:07 UTC (permalink / raw)
To: Andrew Lunn, Andrew Lunn, Russell King - ARM Linux, Paolo Abeni,
Eric Dumazet, David Miller, Jakub Kicinski
Cc: netdev@vger.kernel.org
Using void * instead of char * allows to remove one cast.
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
drivers/net/phy/mdio_bus.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index f189e9fbcbd..fb2bcc69c8d 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -136,13 +136,13 @@ static struct mdio_bus_stat_attr *to_sattr(struct device_attribute *attr)
static u64 mdio_bus_get_stat(struct mdio_bus_stats *s, unsigned int offset)
{
- const char *p = (const char *)s + offset;
+ const u64_stats_t *stats = (const void *)s + offset;
unsigned int start;
u64 val = 0;
do {
start = u64_stats_fetch_begin(&s->syncp);
- val = u64_stats_read((const u64_stats_t *)p);
+ val = u64_stats_read(stats);
} while (u64_stats_fetch_retry(&s->syncp, start));
return val;
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH net-next 5/8] net: mdio: constify attributes and attribute arrays
2026-02-27 22:04 [PATCH net-next 0/8] net: phy: improve stats handling in mdio_bus.c Heiner Kallweit
` (3 preceding siblings ...)
2026-02-27 22:07 ` [PATCH net-next 4/8] net: phy: avoid extra casting in mdio_bus_get_stat Heiner Kallweit
@ 2026-02-27 22:08 ` Heiner Kallweit
2026-02-27 22:09 ` [PATCH net-next 6/8] net: mdio: use macro __ATTRIBUTE_GROUPS Heiner Kallweit
` (3 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Heiner Kallweit @ 2026-02-27 22:08 UTC (permalink / raw)
To: Andrew Lunn, Andrew Lunn, Russell King - ARM Linux, Paolo Abeni,
Eric Dumazet, David Miller, Jakub Kicinski
Cc: netdev@vger.kernel.org
Constify attributes and attribute arrays, using new member attrs_const
of struct attribute_group.
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
drivers/net/phy/mdio_bus.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index fb2bcc69c8d..750b9165086 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -192,12 +192,12 @@ static ssize_t mdio_bus_device_stat_field_show(struct device *dev,
}
#define MDIO_BUS_STATS_ATTR(field) \
-static struct mdio_bus_stat_attr dev_attr_mdio_bus_##field = { \
+static const struct mdio_bus_stat_attr dev_attr_mdio_bus_##field = { \
.attr = __ATTR(field, 0444, mdio_bus_stat_field_show, NULL), \
.address = -1, \
.field_offset = offsetof(struct mdio_bus_stats, field), \
}; \
-static struct mdio_bus_stat_attr dev_attr_mdio_bus_device_##field = { \
+static const struct mdio_bus_stat_attr dev_attr_mdio_bus_device_##field = { \
.attr = __ATTR(field, 0444, mdio_bus_device_stat_field_show, NULL), \
.field_offset = offsetof(struct mdio_bus_stats, field), \
}
@@ -208,7 +208,8 @@ MDIO_BUS_STATS_ATTR(writes);
MDIO_BUS_STATS_ATTR(reads);
#define MDIO_BUS_STATS_ADDR_ATTR_DECL(field, addr, file) \
-static struct mdio_bus_stat_attr dev_attr_mdio_bus_addr_##field##_##addr = { \
+static const struct mdio_bus_stat_attr \
+dev_attr_mdio_bus_addr_##field##_##addr = { \
.attr = { .attr = { .name = file, .mode = 0444 }, \
.show = mdio_bus_stat_field_show, \
}, \
@@ -265,7 +266,7 @@ MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(31);
&dev_attr_mdio_bus_addr_writes_##addr.attr.attr, \
&dev_attr_mdio_bus_addr_reads_##addr.attr.attr \
-static struct attribute *mdio_bus_statistics_attrs[] = {
+static const struct attribute *const mdio_bus_statistics_attrs[] = {
&dev_attr_mdio_bus_transfers.attr.attr,
&dev_attr_mdio_bus_errors.attr.attr,
&dev_attr_mdio_bus_writes.attr.attr,
@@ -306,8 +307,8 @@ static struct attribute *mdio_bus_statistics_attrs[] = {
};
static const struct attribute_group mdio_bus_statistics_group = {
- .name = "statistics",
- .attrs = mdio_bus_statistics_attrs,
+ .name = "statistics",
+ .attrs_const = mdio_bus_statistics_attrs,
};
static const struct attribute_group *mdio_bus_groups[] = {
@@ -973,7 +974,7 @@ static int mdio_uevent(const struct device *dev, struct kobj_uevent_env *env)
return 0;
}
-static struct attribute *mdio_bus_device_statistics_attrs[] = {
+static const struct attribute *const mdio_bus_device_statistics_attrs[] = {
&dev_attr_mdio_bus_device_transfers.attr.attr,
&dev_attr_mdio_bus_device_errors.attr.attr,
&dev_attr_mdio_bus_device_writes.attr.attr,
@@ -982,8 +983,8 @@ static struct attribute *mdio_bus_device_statistics_attrs[] = {
};
static const struct attribute_group mdio_bus_device_statistics_group = {
- .name = "statistics",
- .attrs = mdio_bus_device_statistics_attrs,
+ .name = "statistics",
+ .attrs_const = mdio_bus_device_statistics_attrs,
};
static const struct attribute_group *mdio_bus_dev_groups[] = {
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH net-next 6/8] net: mdio: use macro __ATTRIBUTE_GROUPS
2026-02-27 22:04 [PATCH net-next 0/8] net: phy: improve stats handling in mdio_bus.c Heiner Kallweit
` (4 preceding siblings ...)
2026-02-27 22:08 ` [PATCH net-next 5/8] net: mdio: constify attributes and attribute arrays Heiner Kallweit
@ 2026-02-27 22:09 ` Heiner Kallweit
2026-02-27 22:10 ` [PATCH net-next 7/8] net: phy: inline helper mdio_bus_get_global_stat Heiner Kallweit
` (2 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Heiner Kallweit @ 2026-02-27 22:09 UTC (permalink / raw)
To: Andrew Lunn, Andrew Lunn, Russell King - ARM Linux, Paolo Abeni,
Eric Dumazet, David Miller, Jakub Kicinski
Cc: netdev@vger.kernel.org
Use macro __ATTRIBUTE_GROUPS() to simplify the code.
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
drivers/net/phy/mdio_bus.c | 16 ++++------------
1 file changed, 4 insertions(+), 12 deletions(-)
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 750b9165086..0e2820ab8cb 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -310,16 +310,12 @@ static const struct attribute_group mdio_bus_statistics_group = {
.name = "statistics",
.attrs_const = mdio_bus_statistics_attrs,
};
-
-static const struct attribute_group *mdio_bus_groups[] = {
- &mdio_bus_statistics_group,
- NULL,
-};
+__ATTRIBUTE_GROUPS(mdio_bus_statistics);
const struct class mdio_bus_class = {
.name = "mdio_bus",
.dev_release = mdiobus_release,
- .dev_groups = mdio_bus_groups,
+ .dev_groups = mdio_bus_statistics_groups,
};
EXPORT_SYMBOL_GPL(mdio_bus_class);
@@ -986,15 +982,11 @@ static const struct attribute_group mdio_bus_device_statistics_group = {
.name = "statistics",
.attrs_const = mdio_bus_device_statistics_attrs,
};
-
-static const struct attribute_group *mdio_bus_dev_groups[] = {
- &mdio_bus_device_statistics_group,
- NULL,
-};
+__ATTRIBUTE_GROUPS(mdio_bus_device_statistics);
const struct bus_type mdio_bus_type = {
.name = "mdio_bus",
- .dev_groups = mdio_bus_dev_groups,
+ .dev_groups = mdio_bus_device_statistics_groups,
.match = mdio_bus_match,
.uevent = mdio_uevent,
};
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH net-next 7/8] net: phy: inline helper mdio_bus_get_global_stat
2026-02-27 22:04 [PATCH net-next 0/8] net: phy: improve stats handling in mdio_bus.c Heiner Kallweit
` (5 preceding siblings ...)
2026-02-27 22:09 ` [PATCH net-next 6/8] net: mdio: use macro __ATTRIBUTE_GROUPS Heiner Kallweit
@ 2026-02-27 22:10 ` Heiner Kallweit
2026-02-27 22:11 ` [PATCH net-next 8/8] net: phy: improve mdiobus_stats_acct Heiner Kallweit
2026-03-03 12:30 ` [PATCH net-next 0/8] net: phy: improve stats handling in mdio_bus.c patchwork-bot+netdevbpf
8 siblings, 0 replies; 12+ messages in thread
From: Heiner Kallweit @ 2026-02-27 22:10 UTC (permalink / raw)
To: Andrew Lunn, Andrew Lunn, Russell King - ARM Linux, Paolo Abeni,
Eric Dumazet, David Miller, Jakub Kicinski
Cc: netdev@vger.kernel.org
mdio_bus_get_global_stat() has only one user. Inline it to simplify
the code.
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
drivers/net/phy/mdio_bus.c | 23 ++++++++---------------
1 file changed, 8 insertions(+), 15 deletions(-)
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 0e2820ab8cb..48c0447e6a8 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -148,30 +148,23 @@ static u64 mdio_bus_get_stat(struct mdio_bus_stats *s, unsigned int offset)
return val;
}
-static u64 mdio_bus_get_global_stat(struct mii_bus *bus, unsigned int offset)
-{
- unsigned int i;
- u64 val = 0;
-
- for (i = 0; i < PHY_MAX_ADDR; i++)
- val += mdio_bus_get_stat(&bus->stats[i], offset);
-
- return val;
-}
-
static ssize_t mdio_bus_stat_field_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct mdio_bus_stat_attr *sattr = to_sattr(attr);
struct mii_bus *bus = to_mii_bus(dev);
- u64 val;
+ u64 val = 0;
- if (sattr->address < 0)
- val = mdio_bus_get_global_stat(bus, sattr->field_offset);
- else
+ if (sattr->address < 0) {
+ /* get global stats */
+ for (int i = 0; i < PHY_MAX_ADDR; i++)
+ val += mdio_bus_get_stat(&bus->stats[i],
+ sattr->field_offset);
+ } else {
val = mdio_bus_get_stat(&bus->stats[sattr->address],
sattr->field_offset);
+ }
return sysfs_emit(buf, "%llu\n", val);
}
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH net-next 8/8] net: phy: improve mdiobus_stats_acct
2026-02-27 22:04 [PATCH net-next 0/8] net: phy: improve stats handling in mdio_bus.c Heiner Kallweit
` (6 preceding siblings ...)
2026-02-27 22:10 ` [PATCH net-next 7/8] net: phy: inline helper mdio_bus_get_global_stat Heiner Kallweit
@ 2026-02-27 22:11 ` Heiner Kallweit
2026-03-05 8:31 ` Marek Szyprowski
2026-03-03 12:30 ` [PATCH net-next 0/8] net: phy: improve stats handling in mdio_bus.c patchwork-bot+netdevbpf
8 siblings, 1 reply; 12+ messages in thread
From: Heiner Kallweit @ 2026-02-27 22:11 UTC (permalink / raw)
To: Andrew Lunn, Andrew Lunn, Russell King - ARM Linux, Paolo Abeni,
Eric Dumazet, David Miller, Jakub Kicinski
Cc: netdev@vger.kernel.org
- Remove duplicated preempt disable. Disabling preemption has been added
to functions like u64_stats_update_begin() in the meantime.
- Simplify branch structure
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
drivers/net/phy/mdio_bus.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 48c0447e6a8..b32a369cd25 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -358,22 +358,17 @@ EXPORT_SYMBOL(of_mdio_find_bus);
static void mdiobus_stats_acct(struct mdio_bus_stats *stats, bool op, int ret)
{
- preempt_disable();
u64_stats_update_begin(&stats->syncp);
u64_stats_inc(&stats->transfers);
- if (ret < 0) {
+ if (ret < 0)
u64_stats_inc(&stats->errors);
- goto out;
- }
-
- if (op)
+ else if (op)
u64_stats_inc(&stats->reads);
else
u64_stats_inc(&stats->writes);
-out:
+
u64_stats_update_end(&stats->syncp);
- preempt_enable();
}
/**
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH net-next 0/8] net: phy: improve stats handling in mdio_bus.c
2026-02-27 22:04 [PATCH net-next 0/8] net: phy: improve stats handling in mdio_bus.c Heiner Kallweit
` (7 preceding siblings ...)
2026-02-27 22:11 ` [PATCH net-next 8/8] net: phy: improve mdiobus_stats_acct Heiner Kallweit
@ 2026-03-03 12:30 ` patchwork-bot+netdevbpf
8 siblings, 0 replies; 12+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-03-03 12:30 UTC (permalink / raw)
To: Heiner Kallweit
Cc: andrew, andrew+netdev, linux, pabeni, edumazet, davem, kuba,
netdev
Hello:
This series was applied to netdev/net-next.git (main)
by Paolo Abeni <pabeni@redhat.com>:
On Fri, 27 Feb 2026 23:04:20 +0100 you wrote:
> Improve stats handling in mdio_bus.c.
>
> Heiner Kallweit (8):
> net: mdio: extend struct mdio_bus_stat_attr instead of using
> dev_ext_attribute
> net: mdio: use macro __ATTR to simplify the code
> net: phy: consider that mdio_bus_device_stat_field_show doesn't use
> member address
> net: phy: avoid extra casting in mdio_bus_get_stat
> net: mdio: constify attributes and attribute arrays
> net: mdio: use macro __ATTRIBUTE_GROUPS
> net: phy: inline helper mdio_bus_get_global_stat
> net: phy: improve mdiobus_stats_acct
>
> [...]
Here is the summary with links:
- [net-next,1/8] net: mdio: extend struct mdio_bus_stat_attr instead of using dev_ext_attribute
https://git.kernel.org/netdev/net-next/c/5c494f404a3f
- [net-next,2/8] net: mdio: use macro __ATTR to simplify the code
https://git.kernel.org/netdev/net-next/c/807d8addc3ec
- [net-next,3/8] net: phy: consider that mdio_bus_device_stat_field_show doesn't use member address
https://git.kernel.org/netdev/net-next/c/8068acaff125
- [net-next,4/8] net: phy: avoid extra casting in mdio_bus_get_stat
https://git.kernel.org/netdev/net-next/c/c599649d05a0
- [net-next,5/8] net: mdio: constify attributes and attribute arrays
https://git.kernel.org/netdev/net-next/c/a4c08b701559
- [net-next,6/8] net: mdio: use macro __ATTRIBUTE_GROUPS
https://git.kernel.org/netdev/net-next/c/8e0bdf30be75
- [net-next,7/8] net: phy: inline helper mdio_bus_get_global_stat
https://git.kernel.org/netdev/net-next/c/7f97ca5f9858
- [net-next,8/8] net: phy: improve mdiobus_stats_acct
https://git.kernel.org/netdev/net-next/c/1afccc5a201e
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH net-next 8/8] net: phy: improve mdiobus_stats_acct
2026-02-27 22:11 ` [PATCH net-next 8/8] net: phy: improve mdiobus_stats_acct Heiner Kallweit
@ 2026-03-05 8:31 ` Marek Szyprowski
2026-03-05 9:57 ` Heiner Kallweit
0 siblings, 1 reply; 12+ messages in thread
From: Marek Szyprowski @ 2026-03-05 8:31 UTC (permalink / raw)
To: Heiner Kallweit, Andrew Lunn, Andrew Lunn,
Russell King - ARM Linux, Paolo Abeni, Eric Dumazet, David Miller,
Jakub Kicinski
Cc: netdev@vger.kernel.org
On 27.02.2026 23:11, Heiner Kallweit wrote:
> - Remove duplicated preempt disable. Disabling preemption has been added
> to functions like u64_stats_update_begin() in the meantime.
> - Simplify branch structure
>
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
This patch has been merged to yesterday's linux-next as commit
1afccc5a201e ("net: phy: improve mdiobus_stats_acct"). In my tests I
found that it introduces the following warning on 32bit machines with
USB ethernet adapters, so the preempt disable was there for a good reason:
------------[ cut here ]------------
WARNING: ./include/linux/u64_stats_sync.h:171 at
mdiobus_stats_acct+0x288/0x2b4, CPU#0: kworker/0:3/50
Loading compiled-in X.509 certificates
Modules linked in:
CPU: 0 UID: 0 PID: 50 Comm: kworker/0:3 Not tainted
7.0.0-rc2-next-20260304 #12283 PREEMPT
Hardware name: Samsung Exynos (Flattened Device Tree)
Workqueue: usb_hub_wq hub_event
Call trace:
unwind_backtrace from show_stack+0x10/0x14
show_stack from dump_stack_lvl+0x68/0x88
dump_stack_lvl from __warn+0x94/0x210
__warn from warn_slowpath_fmt+0x1b0/0x1bc
warn_slowpath_fmt from mdiobus_stats_acct+0x288/0x2b4
mdiobus_stats_acct from __mdiobus_read+0x84/0xf0
__mdiobus_read from mdiobus_read+0x30/0x44
mdiobus_read from get_phy_device+0xac/0x140
get_phy_device from mdiobus_scan+0x24/0x104
mdiobus_scan from __mdiobus_register+0x21c/0x478
__mdiobus_register from smsc95xx_bind+0x3f4/0x5f0
smsc95xx_bind from usbnet_probe+0x330/0x928
usbnet_probe from usb_probe_interface+0xec/0x318
usb_probe_interface from really_probe+0xe0/0x424
really_probe from __driver_probe_device+0x9c/0x1f4
__driver_probe_device from driver_probe_device+0x30/0xc0
driver_probe_device from __device_attach_driver+0xa8/0x140
__device_attach_driver from bus_for_each_drv+0x84/0xdc
bus_for_each_drv from __device_attach+0xb0/0x214
__device_attach from device_initial_probe+0x3c/0x48
device_initial_probe from bus_probe_device+0x24/0x80
bus_probe_device from device_add+0x5c0/0x810
device_add from usb_set_configuration+0x4e4/0x974
usb_set_configuration from usb_generic_driver_probe+0x3c/0x78
usb_generic_driver_probe from usb_probe_device+0x4c/0x14c
usb_probe_device from really_probe+0xe0/0x424
really_probe from __driver_probe_device+0x9c/0x1f4
__driver_probe_device from driver_probe_device+0x30/0xc0
driver_probe_device from __device_attach_driver+0xa8/0x140
__device_attach_driver from bus_for_each_drv+0x84/0xdc
bus_for_each_drv from __device_attach+0xb0/0x214
__device_attach from device_initial_probe+0x3c/0x48
device_initial_probe from bus_probe_device+0x24/0x80
bus_probe_device from device_add+0x5c0/0x810
device_add from usb_new_device+0x23c/0x4f8
usb_new_device from hub_event+0x11dc/0x1ca4
hub_event from process_one_work+0x24c/0x7b8
process_one_work from worker_thread+0x1b8/0x3bc
worker_thread from kthread+0x128/0x168
kthread from ret_from_fork+0x14/0x28
Exception stack(0xf0a15fb0 to 0xf0a15ff8)
...
irq event stamp: 5711
hardirqs last enabled at (5911): [<c01c6c54>]
console_flush_one_record+0x424/0x570
hardirqs last disabled at (5943): [<c013ce4c>] handle_softirqs+0x53c/0x5c0
softirqs last enabled at (5944): [<c013cc3c>] handle_softirqs+0x32c/0x5c0
softirqs last disabled at (6157): [<c013d07c>] __irq_exit_rcu+0x144/0x1f0
---[ end trace 0000000000000000 ]---
> ---
> drivers/net/phy/mdio_bus.c | 11 +++--------
> 1 file changed, 3 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
> index 48c0447e6a8..b32a369cd25 100644
> --- a/drivers/net/phy/mdio_bus.c
> +++ b/drivers/net/phy/mdio_bus.c
> @@ -358,22 +358,17 @@ EXPORT_SYMBOL(of_mdio_find_bus);
>
> static void mdiobus_stats_acct(struct mdio_bus_stats *stats, bool op, int ret)
> {
> - preempt_disable();
> u64_stats_update_begin(&stats->syncp);
>
> u64_stats_inc(&stats->transfers);
> - if (ret < 0) {
> + if (ret < 0)
> u64_stats_inc(&stats->errors);
> - goto out;
> - }
> -
> - if (op)
> + else if (op)
> u64_stats_inc(&stats->reads);
> else
> u64_stats_inc(&stats->writes);
> -out:
> +
> u64_stats_update_end(&stats->syncp);
> - preempt_enable();
> }
>
> /**
Best regards
--
Marek Szyprowski, PhD
Samsung R&D Institute Poland
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH net-next 8/8] net: phy: improve mdiobus_stats_acct
2026-03-05 8:31 ` Marek Szyprowski
@ 2026-03-05 9:57 ` Heiner Kallweit
0 siblings, 0 replies; 12+ messages in thread
From: Heiner Kallweit @ 2026-03-05 9:57 UTC (permalink / raw)
To: Marek Szyprowski, Andrew Lunn, Andrew Lunn,
Russell King - ARM Linux, Paolo Abeni, Eric Dumazet, David Miller,
Jakub Kicinski
Cc: netdev@vger.kernel.org
On 05.03.2026 09:31, Marek Szyprowski wrote:
> On 27.02.2026 23:11, Heiner Kallweit wrote:
>> - Remove duplicated preempt disable. Disabling preemption has been added
>> to functions like u64_stats_update_begin() in the meantime.
>> - Simplify branch structure
>>
>> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
>
> This patch has been merged to yesterday's linux-next as commit
> 1afccc5a201e ("net: phy: improve mdiobus_stats_acct"). In my tests I
> found that it introduces the following warning on 32bit machines with
> USB ethernet adapters, so the preempt disable was there for a good reason:
>
Thanks for the report. Indeed, on non-PREEMPT_RT systems it's still needed.
I'll send a revert.
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2026-03-05 9:57 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-27 22:04 [PATCH net-next 0/8] net: phy: improve stats handling in mdio_bus.c Heiner Kallweit
2026-02-27 22:05 ` [PATCH net-next 1/8] net: mdio: extend struct mdio_bus_stat_attr instead of using dev_ext_attribute Heiner Kallweit
2026-02-27 22:06 ` [PATCH net-next 2/8] net: mdio: use macro __ATTR to simplify the code Heiner Kallweit
2026-02-27 22:07 ` [PATCH net-next 3/8] net: phy: consider that mdio_bus_device_stat_field_show doesn't use member address Heiner Kallweit
2026-02-27 22:07 ` [PATCH net-next 4/8] net: phy: avoid extra casting in mdio_bus_get_stat Heiner Kallweit
2026-02-27 22:08 ` [PATCH net-next 5/8] net: mdio: constify attributes and attribute arrays Heiner Kallweit
2026-02-27 22:09 ` [PATCH net-next 6/8] net: mdio: use macro __ATTRIBUTE_GROUPS Heiner Kallweit
2026-02-27 22:10 ` [PATCH net-next 7/8] net: phy: inline helper mdio_bus_get_global_stat Heiner Kallweit
2026-02-27 22:11 ` [PATCH net-next 8/8] net: phy: improve mdiobus_stats_acct Heiner Kallweit
2026-03-05 8:31 ` Marek Szyprowski
2026-03-05 9:57 ` Heiner Kallweit
2026-03-03 12:30 ` [PATCH net-next 0/8] net: phy: improve stats handling in mdio_bus.c patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox