net/core: Export dev_core_stats_rx_dropped_inc sets
Subsystems (2)
PATCH 1/1 net/core: Export dev_core_stats_rx_dropped_inc sets
Although there is a kfree_skb_reason() helper function that can be used to find the reason for dropped packets, but most callers didn't increase one of rx_dropped, tx_dropped, rx_nohandler and rx_otherhost_dropped.
For the users, people are more concerned about why the dropped in ifconfig is increasing. So we can export dev_core_stats_rx_dropped_inc sets, which users would trace them know why rx_dropped is increasing.
Export dev_core_stats_{rx_dropped, tx_dropped, rx_nohandler, rx_otherhost_dropped}_inc for trace. Also, move dev_core_stats() and netdev_core_stats_alloc() in dev.c, because they are not called externally.
--- include/linux/netdevice.h | 32 +++++--------------------------- net/core/dev.c | 30 ++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 29 deletions(-)
include/linux/netdevice.h +5 -27
@@ -3954,6 +3954,11 @@ int dev_forward_skb_nomtu(struct net_device *dev, struct sk_buff *skb);bool is_skb_forwardable (const struct net_device *dev,const struct sk_buff *skb); +void dev_core_stats_rx_dropped_inc (struct net_device *dev); +void dev_core_stats_tx_dropped_inc (struct net_device *dev); +void dev_core_stats_rx_nohandler_inc (struct net_device *dev); +void dev_core_stats_rx_otherhost_dropped_inc (struct net_device *dev); + static __always_inline bool __is_skb_forwardable(const struct net_device *dev,const struct sk_buff *skb,const bool check_mtu)
@@ -3980,33 +3985,6 @@ static __always_inline bool __is_skb_forwardable(const struct net_device *dev,return false; } -struct net_device_core_stats __percpu *netdev_core_stats_alloc (struct net_device *dev); - -static inline struct net_device_core_stats __percpu *dev_core_stats (struct net_device *dev) -{ -/* This READ_ONCE() pairs with the write in netdev_core_stats_alloc() */ -struct net_device_core_stats __percpu *p =READ_ONCE (dev->core_stats); - -if (likely (p)) -return p; - -return netdev_core_stats_alloc (dev); -} - -#define DEV_CORE_STATS_INC (FIELD ) \ -static inline void dev_core_stats_##FIELD##_inc(struct net_device *dev) \ -{ \ - struct net_device_core_stats __percpu *p; \ - \ - p = dev_core_stats(dev); \ - if (p) \ - this_cpu_inc(p->FIELD); \ -} -DEV_CORE_STATS_INC(rx_dropped) -DEV_CORE_STATS_INC(tx_dropped) -DEV_CORE_STATS_INC(rx_nohandler) -DEV_CORE_STATS_INC(rx_otherhost_dropped) - static __always_inline int ____dev_forward_skb(struct net_device *dev,struct sk_buff *skb,const bool check_mtu)
net/core/dev.c +28 -2
@@ -10475,7 +10475,7 @@ void netdev_stats_to_stats64(struct rtnl_link_stats64 *stats64, }EXPORT_SYMBOL (netdev_stats_to_stats64); -struct net_device_core_stats __percpu *netdev_core_stats_alloc (struct net_device *dev) +static struct net_device_core_stats __percpu *netdev_core_stats_alloc (struct net_device *dev) {struct net_device_core_stats __percpu *p;
@@ -10488,7 +10488,33 @@ struct net_device_core_stats __percpu *netdev_core_stats_alloc(struct net_device/* This READ_ONCE() pairs with the cmpxchg() above */ return READ_ONCE (dev->core_stats); } -EXPORT_SYMBOL (netdev_core_stats_alloc); + +static inline struct net_device_core_stats __percpu *dev_core_stats (struct net_device *dev) +{ +/* This READ_ONCE() pairs with the write in netdev_core_stats_alloc() */ +struct net_device_core_stats __percpu *p =READ_ONCE (dev->core_stats); + +if (likely (p)) +return p; + +return netdev_core_stats_alloc (dev); +} + +#define DEV_CORE_STATS_INC (FIELD ) \ +void dev_core_stats_##FIELD##_inc(struct net_device *dev) \ +{ \ + struct net_device_core_stats __percpu *p; \ + \ + p = dev_core_stats(dev); \ + if (p) \ + this_cpu_inc(p->FIELD); \ +} \ +EXPORT_SYMBOL(dev_core_stats_##FIELD##_inc) + +DEV_CORE_STATS_INC (rx_dropped); +DEV_CORE_STATS_INC (tx_dropped); +DEV_CORE_STATS_INC (rx_nohandler); +DEV_CORE_STATS_INC (rx_otherhost_dropped);/** * dev_get_stats - get network device statistics
Signature · 1 line
2.25.1
Quoted 9 lines · On Mon, 11 Sep 2023 16:20:16 +0800 Yajun Deng <[email protected]> wrote:
Although there is a
kfree_skb_reason()helper function that can be used to find the reason for dropped packets, but most callers didn't increase one ofrx_dropped,tx_dropped,rx_nohandlerandrx_otherhost_dropped.For the users, people are more concerned about why the dropped in ifconfig is increasing. So we can export
dev_core_stats_rx_dropped_incsets, which users would trace them know whyrx_droppedis increasing.
ifconfig has been frozen for over 10 years, and is deprecated so there is no point in catering to legacy api's. There are better API's such as ethtool and netlink that can provide more info.
Quoted 16 lines · Stephen Hemminger
Quoted 11 lines · On Mon, 11 Sep 2023 16:20:16 +0800 Yajun Deng <[email protected]> wrote:
Although there is a
kfree_skb_reason()helper function that can be
used to find the reason for dropped packets, but most callers didn't increase one ofrx_dropped,tx_dropped,rx_nohandlerandrx_otherhost_dropped.For the users, people are more concerned about why the dropped in ifconfig is increasing. So we can export
dev_core_stats_rx_dropped_incsets, which users would trace them know whyrx_droppedis increasing.
Quoted 4 lines
ifconfig has been frozen for over 10 years, and is deprecated so there is no point in catering to legacy api's. There are better API's such as ethtool and netlink that can provide more info.
Yes, ifconfig is deprecated. but the dropped in ifconfig and ip is the same. We're more concerned about the reason for dropped packets.
ip, ethtool and netlink couldn't show the reason.
Quoted 9 lines · Yajun Deng
Although there is a
kfree_skb_reason()helper function that can be used to find the reason for dropped packets, but most callers didn't increase one ofrx_dropped,tx_dropped,rx_nohandlerandrx_otherhost_dropped.For the users, people are more concerned about why the dropped in ifconfig is increasing. So we can export
dev_core_stats_rx_dropped_incsets, which users would trace them know whyrx_droppedis increasing.
Quoted 6 lines
Export dev_core_stats_{rx_dropped,
tx_dropped,rx_nohandler, rx_otherhost_dropped}_inc for trace. Also, movedev_core_stats()andnetdev_core_stats_alloc()indev.c, because they are not called externally.Signed-off-by Yajun Deng <[email protected]>
Okay, but it seems you forgot to say which tree was targeted by this patch.
Documentation/process/maintainer-netdev.rst
I would guess net-next, but patch authors are supposed to be explicit.
Quoted 69 lines
--- include/linux/netdevice.h | 32 +++++--------------------------- net/core/dev.c | 30 ++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 29 deletions(-)include/linux/netdevice.h +5
-27@@ -3954,6 +3954,11 @@ int dev_forward_skb_nomtu(struct net_device *dev, struct sk_buff *skb);bool is_skb_forwardable (const struct net_device *dev,const struct sk_buff *skb); +void dev_core_stats_rx_dropped_inc (struct net_device *dev); +void dev_core_stats_tx_dropped_inc (struct net_device *dev); +void dev_core_stats_rx_nohandler_inc (struct net_device *dev); +void dev_core_stats_rx_otherhost_dropped_inc (struct net_device *dev); + static __always_inline bool __is_skb_forwardable(const struct net_device *dev,const struct sk_buff *skb,const bool check_mtu)@@ -3980,33 +3985,6 @@ static __always_inline bool __is_skb_forwardable(const struct net_device *dev,return false; } -struct net_device_core_stats __percpu *netdev_core_stats_alloc (struct net_device *dev); - -static inline struct net_device_core_stats __percpu *dev_core_stats (struct net_device *dev) -{ -/* This READ_ONCE() pairs with the write in netdev_core_stats_alloc() */ -struct net_device_core_stats __percpu *p =READ_ONCE (dev->core_stats); - -if (likely (p)) -return p; - -return netdev_core_stats_alloc (dev); -} - -#define DEV_CORE_STATS_INC (FIELD ) \ -static inline void dev_core_stats_##FIELD##_inc(struct net_device *dev) \ -{ \ - struct net_device_core_stats __percpu *p; \ - \ - p = dev_core_stats(dev); \ - if (p) \ - this_cpu_inc(p->FIELD); \ -} -DEV_CORE_STATS_INC(rx_dropped) -DEV_CORE_STATS_INC(tx_dropped) -DEV_CORE_STATS_INC(rx_nohandler) -DEV_CORE_STATS_INC(rx_otherhost_dropped) - static __always_inline int ____dev_forward_skb(struct net_device *dev,struct sk_buff *skb,const bool check_mtu)net/core/dev.c +1
-1@@ -10475,7 +10475,7 @@ void netdev_stats_to_stats64(struct rtnl_link_stats64 *stats64, }EXPORT_SYMBOL (netdev_stats_to_stats64); -struct net_device_core_stats __percpu *netdev_core_stats_alloc (struct net_device *dev) +static struct net_device_core_stats __percpu *netdev_core_stats_alloc (struct net_device *dev) {struct net_device_core_stats __percpu *p;
net/core/dev.c struct net_device_core_stats __percpu *netdev_core_stats_alloc(struct net_device · line 10492
Quoted 6 lines
net/core/dev.c +2
-1@@ -10488,7 +10488,33 @@ struct net_device_core_stats __percpu *netdev_core_stats_alloc(struct net_device/* This READ_ONCE() pairs with the cmpxchg() above */ return READ_ONCE (dev->core_stats); } -EXPORT_SYMBOL (netdev_core_stats_alloc); + +static inline struct net_device_core_stats __percpu *dev_core_stats (struct net_device *dev)
Please remove this inline attritbute. Consider using __cold instead.
Quoted 15 lines
net/core/dev.c +15
-0+{ +/* This READ_ONCE() pairs with the write in netdev_core_stats_alloc() */ +struct net_device_core_stats __percpu *p =READ_ONCE (dev->core_stats); + +if (likely (p)) +return p; + +return netdev_core_stats_alloc (dev); +} + +#define DEV_CORE_STATS_INC (FIELD ) \ +void dev_core_stats_##FIELD##_inc(struct net_device *dev) \ +{ \ + struct net_device_core_stats __percpu *p; \ + \
net/core/dev.c struct net_device_core_stats __percpu *netdev_core_stats_alloc(struct net_device · line 10517
Quoted 10 lines
net/core/dev.c +10
-0+ p =dev_core_stats (dev); \ +if (p) \ +this_cpu_inc (p->FIELD); \ +} \ +EXPORT_SYMBOL(dev_core_stats_##FIELD##_inc) + +DEV_CORE_STATS_INC (rx_dropped); +DEV_CORE_STATS_INC (tx_dropped); +DEV_CORE_STATS_INC (rx_nohandler); +DEV_CORE_STATS_INC (rx_otherhost_dropped);
#undef DEV_CORE_STATS_INC
Quoted 6 lines
net/core/dev.c +0
-1/** * dev_get_stats - get network device statistics -- 2.25.1
From: Eric Dumazet <[email protected]>
Date: Tue, 12 Sep 2023 06:23:24 +0200
Quoted 5 lines · Yajun Deng
Quoted 4 lines
Although there is a
kfree_skb_reason()helper function that can be used to find the reason for dropped packets, but most callers didn't increase one ofrx_dropped,tx_dropped,rx_nohandlerandrx_otherhost_dropped.
[...]
Quoted 7 lines
Quoted 7 lines
EXPORT_SYMBOL(netdev_stats_to_stats64);net/core/dev.c +1
-1-struct net_device_core_stats __percpu *netdev_core_stats_alloc (struct net_device *dev) +static struct net_device_core_stats __percpu *netdev_core_stats_alloc (struct net_device *dev) {struct net_device_core_stats __percpu *p;
Quoted 9 lines
net/core/dev.c struct net_device_core_stats __percpu *netdev_core_stats_alloc(struct net_device · line 10492
Quoted 7 lines
net/core/dev.c +2
-1@@ -10488,7 +10488,33 @@ struct net_device_core_stats __percpu *netdev_core_stats_alloc(struct net_device/* This READ_ONCE() pairs with the cmpxchg() above */ return READ_ONCE (dev->core_stats); } -EXPORT_SYMBOL (netdev_core_stats_alloc); + +static inline struct net_device_core_stats __percpu *dev_core_stats (struct net_device *dev)Please remove this inline attritbute. Consider using
__coldinstead.
__cold? O_o I thought the author's inlining it as it's a couple locs/intstructions, while the compilers would most likely keep it non-inlined as it's referenced 4 times. __cold will for sure keep it standalone and place it in .text.cold, i.e. far away from the call sites. I realize dev_core_stats_*() aren't called frequently, but why making only one small helper cold rather than all of them then?
Quoted 10 lines
net/core/dev.c struct net_device_core_stats __percpu *netdev_core_stats_alloc(struct net_device · line 10501
Quoted 10 lines
net/core/dev.c +9
-0+{ +/* This READ_ONCE() pairs with the write in netdev_core_stats_alloc() */ +struct net_device_core_stats __percpu *p =READ_ONCE (dev->core_stats); + +if (likely (p)) +return p; + +return netdev_core_stats_alloc (dev); +}
[...]
Thanks,
Olek
Quoted 29 lines · Alexander Lobakin
From: Eric Dumazet <[email protected]>
Date: Tue, 12 Sep 2023 06:23:24 +0200Quoted 5 lines · Yajun Deng
Quoted 4 lines
Although there is a
kfree_skb_reason()helper function that can be used to find the reason for dropped packets, but most callers didn't increase one ofrx_dropped,tx_dropped,rx_nohandlerandrx_otherhost_dropped.[...]
Quoted 7 lines
Quoted 7 lines
EXPORT_SYMBOL(netdev_stats_to_stats64);net/core/dev.c +1
-1-struct net_device_core_stats __percpu *netdev_core_stats_alloc (struct net_device *dev) +static struct net_device_core_stats __percpu *netdev_core_stats_alloc (struct net_device *dev) {struct net_device_core_stats __percpu *p;Quoted 9 lines
net/core/dev.c struct net_device_core_stats __percpu *netdev_core_stats_alloc(struct net_device · line 10492
Quoted 7 lines
net/core/dev.c +2
-1@@ -10488,7 +10488,33 @@ struct net_device_core_stats __percpu *netdev_core_stats_alloc(struct net_device/* This READ_ONCE() pairs with the cmpxchg() above */ return READ_ONCE (dev->core_stats); } -EXPORT_SYMBOL (netdev_core_stats_alloc); + +static inline struct net_device_core_stats __percpu *dev_core_stats (struct net_device *dev)Please remove this inline attritbute. Consider using
__coldinstead.
Quoted 7 lines
__cold?O_oI thought the author's inlining it as it's a couple locs/intstructions, while the compilers would most likely keep it non-inlined as it's referenced 4 times.__coldwill for sure keep it standalone and place it in .text.cold, i.e. far away from the call sites. I realize dev_core_stats_*() aren't called frequently, but why making only one small helper cold rather than all of them then?
This helper is used at least one time per netdevice lifetime. This is definitely cold.
Forcing an inline makes no sense, this would duplicate the code four times, for absolutely no gain.
Quoted 15 lines
Quoted 10 lines
net/core/dev.c struct net_device_core_stats __percpu *netdev_core_stats_alloc(struct net_device · line 10501
Quoted 10 lines
net/core/dev.c +9
-0+{ +/* This READ_ONCE() pairs with the write in netdev_core_stats_alloc() */ +struct net_device_core_stats __percpu *p =READ_ONCE (dev->core_stats); + +if (likely (p)) +return p; + +return netdev_core_stats_alloc (dev); +}[...]
Thanks,
Olek
From: Yajun Deng <[email protected]>
Date: Mon, 11 Sep 2023 16:20:16 +0800
Quoted 3 lines
Although there is a
kfree_skb_reason()helper function that can be used to find the reason for dropped packets, but most callers didn't increase one ofrx_dropped,tx_dropped,rx_nohandlerandrx_otherhost_dropped.
[...]
Quoted 35 lines
net/core/dev.c +18
-2@@ -10475,7 +10475,7 @@ void netdev_stats_to_stats64(struct rtnl_link_stats64 *stats64, }EXPORT_SYMBOL (netdev_stats_to_stats64); -struct net_device_core_stats __percpu *netdev_core_stats_alloc (struct net_device *dev) +static struct net_device_core_stats __percpu *netdev_core_stats_alloc (struct net_device *dev) {struct net_device_core_stats __percpu *p;@@ -10488,7 +10488,33 @@ struct net_device_core_stats __percpu *netdev_core_stats_alloc(struct net_device/* This READ_ONCE() pairs with the cmpxchg() above */ return READ_ONCE (dev->core_stats); } -EXPORT_SYMBOL (netdev_core_stats_alloc); + +static inline struct net_device_core_stats __percpu *dev_core_stats (struct net_device *dev) +{ +/* This READ_ONCE() pairs with the write in netdev_core_stats_alloc() */ +struct net_device_core_stats __percpu *p =READ_ONCE (dev->core_stats); + +if (likely (p)) +return p; + +return netdev_core_stats_alloc (dev); +} + +#define DEV_CORE_STATS_INC (FIELD ) \ +void dev_core_stats_##FIELD##_inc(struct net_device *dev) \ +{ \ + struct net_device_core_stats __percpu *p; \ + \
net/core/dev.c struct net_device_core_stats __percpu *netdev_core_stats_alloc(struct net_device · line 10517
Quoted 10 lines
net/core/dev.c +10
-0+ p =dev_core_stats (dev); \ +if (p) \ +this_cpu_inc (p->FIELD); \ +} \ +EXPORT_SYMBOL(dev_core_stats_##FIELD##_inc) + +DEV_CORE_STATS_INC (rx_dropped); +DEV_CORE_STATS_INC (tx_dropped); +DEV_CORE_STATS_INC (rx_nohandler); +DEV_CORE_STATS_INC (rx_otherhost_dropped);
I realize you need to have an external function to be able to trace it, but why don't you make it just 1 function instead of 4+ (will only be increasing)?
Define 1 function
void dev_core_stats_inc(struct net_device *dev, u32 offset)
{
struct net_device_core_stats __percpu *p;
p = dev_core_stats(dev);
if (p)
this_cpu_inc(*(unsigned long *)(void *)p + offset);
}EXPORT_SYMBOL_GPL(dev_core_stats_inc); // Why not GPL BTW?
And then build inlines:
#define DEV_CORE_STATS_INC(FIELD) \
static inline void \
dev_core_stats_##FIELD##_inc(struct net_device *dev) \
{ \
dev_core_stats_inc(dev, \
offsetof(struct net_device_core_stats, FIELD)); \
}DEV_CORE_STATS_INC(rx_dropped);
...
OR even just make them macros
#define __DEV_CORE_STATS_INC(dev, field) \ dev_core_stats_inc(dev, \ offsetof(struct net_device_core_stats, field))
#define dev_core_stats_rx_dropped_inc(dev) \
__DEV_CORE_STATS_INC(dev, rx_dropped)
...
Just don't copy that awful Thunderbird's line wrap and don't assume this code builds and works and that is something finished/polished.
You'll be able to trace functions and you'll be able to understand which counter has been incremented by checking the second argument, i.e. the field offset (IIRC tracing shows you arguments).
And that way you wouldn't geometrically increase the number of symbol exports and deal with its consequences.
net/core/dev.c struct net_device_core_stats __percpu *netdev_core_stats_alloc(struct net_device · line 10520
Quoted 3 lines
net/core/dev.c +0
-0/** * dev_get_stats - get network device statistics
Thanks,
Olek
From: Eric Dumazet <[email protected]>
Date: Tue, 12 Sep 2023 18:04:44 +0200
Quoted 39 lines
Quoted 29 lines · Alexander Lobakin
From: Eric Dumazet <[email protected]>
Date: Tue, 12 Sep 2023 06:23:24 +0200Quoted 5 lines · Yajun Deng
Quoted 4 lines
Although there is a
kfree_skb_reason()helper function that can be used to find the reason for dropped packets, but most callers didn't increase one ofrx_dropped,tx_dropped,rx_nohandlerandrx_otherhost_dropped.[...]
Quoted 7 lines
Quoted 7 lines
EXPORT_SYMBOL(netdev_stats_to_stats64);net/core/dev.c +1
-1-struct net_device_core_stats __percpu *netdev_core_stats_alloc (struct net_device *dev) +static struct net_device_core_stats __percpu *netdev_core_stats_alloc (struct net_device *dev) {struct net_device_core_stats __percpu *p;Quoted 9 lines
net/core/dev.c struct net_device_core_stats __percpu *netdev_core_stats_alloc(struct net_device · line 10492
Quoted 7 lines
net/core/dev.c +2
-1@@ -10488,7 +10488,33 @@ struct net_device_core_stats __percpu *netdev_core_stats_alloc(struct net_device/* This READ_ONCE() pairs with the cmpxchg() above */ return READ_ONCE (dev->core_stats); } -EXPORT_SYMBOL (netdev_core_stats_alloc); + +static inline struct net_device_core_stats __percpu *dev_core_stats (struct net_device *dev)Please remove this inline attritbute. Consider using
__coldinstead.Quoted 7 lines
__cold?O_oI thought the author's inlining it as it's a couple locs/intstructions, while the compilers would most likely keep it non-inlined as it's referenced 4 times.__coldwill for sure keep it standalone and place it in .text.cold, i.e. far away from the call sites. I realize dev_core_stats_*() aren't called frequently, but why making only one small helper cold rather than all of them then?
Quoted 2 lines
This helper is used at least one time per netdevice lifetime. This is definitely cold.
But then each dev_stats_*_inc() (not cold) has to call it from a completely different piece of .text far from their. I either don't understand the idea or dunno. Why not make them cold as well then?
Quoted 2 lines
Forcing an inline makes no sense, this would duplicate the code four times, for absolutely no gain.
I'd love to see bloat-o-meter numbers, I suspect we're talking about 20-30 bytes.
Quoted 14 lines
Quoted 14 lines
Quoted 11 lines
Quoted 11 lines
net/core/dev.c +9
-0+{ +/* This READ_ONCE() pairs with the write in netdev_core_stats_alloc() */ +struct net_device_core_stats __percpu *p =READ_ONCE (dev->core_stats); + +if (likely (p)) +return p; + +return netdev_core_stats_alloc (dev); +}[...]
Quoted 2 lines
Quoted 2 lines
Thanks,
Olek
Thanks,
Olek
Quoted 43 lines · Alexander Lobakin
From: Eric Dumazet <[email protected]>
Date: Tue, 12 Sep 2023 18:04:44 +0200Quoted 39 lines
Quoted 36 lines · Alexander Lobakin
From: Eric Dumazet <[email protected]>
Date: Tue, 12 Sep 2023 06:23:24 +0200Quoted 5 lines · Yajun Deng
Quoted 4 lines
Although there is a
kfree_skb_reason()helper function that can be used to find the reason for dropped packets, but most callers didn't increase one ofrx_dropped,tx_dropped,rx_nohandlerandrx_otherhost_dropped.[...]
Quoted 7 lines
Quoted 7 lines
EXPORT_SYMBOL(netdev_stats_to_stats64);net/core/dev.c +1
-1-struct net_device_core_stats __percpu *netdev_core_stats_alloc (struct net_device *dev) +static struct net_device_core_stats __percpu *netdev_core_stats_alloc (struct net_device *dev) {struct net_device_core_stats __percpu *p;Quoted 9 lines
net/core/dev.c struct net_device_core_stats __percpu *netdev_core_stats_alloc(struct net_device · line 10492
Quoted 7 lines
net/core/dev.c +2
-1@@ -10488,7 +10488,33 @@ struct net_device_core_stats __percpu *netdev_core_stats_alloc(struct net_device/* This READ_ONCE() pairs with the cmpxchg() above */ return READ_ONCE (dev->core_stats); } -EXPORT_SYMBOL (netdev_core_stats_alloc); + +static inline struct net_device_core_stats __percpu *dev_core_stats (struct net_device *dev)Please remove this inline attritbute. Consider using
__coldinstead.
__cold?O_oI thought the author's inlining it as it's a couple locs/intstructions, while the compilers would most likely keep it non-inlined as it's referenced 4 times.__coldwill for sure keep it standalone and place it in .text.cold, i.e. far away from the call sites. I realize dev_core_stats_*() aren't called frequently, but why making only one small helper cold rather than all of them then?
Quoted 7 lines
Quoted 2 lines
This helper is used at least one time per netdevice lifetime. This is definitely cold.
But then each dev_stats_*_inc() (not cold) has to call it from a completely different piece of .text far from their. I either don't understand the idea or dunno. Why not make them cold as well then?
The __cold attribute is only applied to the helper _allocating_ the memory, once.
Not on the functions actually incrementing the stats.
There are situations where they can be called thousands/millions of times per second (incast flood).
If this situation happens, the _allocation_ still happens once.
Quoted 25 lines
Quoted 2 lines
Forcing an inline makes no sense, this would duplicate the code four times, for absolutely no gain.
I'd love to see bloat-o-meter numbers, I suspect we're talking about 20-30 bytes.
Quoted 14 lines
Quoted 14 lines
Quoted 11 lines
Quoted 11 lines
net/core/dev.c +9
-0+{ +/* This READ_ONCE() pairs with the write in netdev_core_stats_alloc() */ +struct net_device_core_stats __percpu *p =READ_ONCE (dev->core_stats); + +if (likely (p)) +return p; + +return netdev_core_stats_alloc (dev); +}[...]
Quoted 2 lines
Quoted 2 lines
Thanks,
OlekThanks,
Olek
From: Eric Dumazet <[email protected]>
Date: Tue, 12 Sep 2023 19:28:50 +0200
Quoted 48 lines
Quoted 46 lines · Alexander Lobakin
From: Eric Dumazet <[email protected]>
Date: Tue, 12 Sep 2023 18:04:44 +0200Quoted 41 lines
Quoted 29 lines · Alexander Lobakin
From: Eric Dumazet <[email protected]>
Date: Tue, 12 Sep 2023 06:23:24 +0200Quoted 5 lines · Yajun Deng
Quoted 4 lines
Although there is a
kfree_skb_reason()helper function that can be used to find the reason for dropped packets, but most callers didn't increase one ofrx_dropped,tx_dropped,rx_nohandlerandrx_otherhost_dropped.[...]
Quoted 7 lines
Quoted 7 lines
EXPORT_SYMBOL(netdev_stats_to_stats64);net/core/dev.c +1
-1-struct net_device_core_stats __percpu *netdev_core_stats_alloc (struct net_device *dev) +static struct net_device_core_stats __percpu *netdev_core_stats_alloc (struct net_device *dev) {struct net_device_core_stats __percpu *p;Quoted 9 lines
net/core/dev.c struct net_device_core_stats __percpu *netdev_core_stats_alloc(struct net_device · line 10492
Quoted 7 lines
net/core/dev.c +2
-1@@ -10488,7 +10488,33 @@ struct net_device_core_stats __percpu *netdev_core_stats_alloc(struct net_device/* This READ_ONCE() pairs with the cmpxchg() above */ return READ_ONCE (dev->core_stats); } -EXPORT_SYMBOL (netdev_core_stats_alloc); + +static inline struct net_device_core_stats __percpu *dev_core_stats (struct net_device *dev)Please remove this inline attritbute. Consider using
__coldinstead.Quoted 7 lines
__cold?O_oI thought the author's inlining it as it's a couple locs/intstructions, while the compilers would most likely keep it non-inlined as it's referenced 4 times.__coldwill for sure keep it standalone and place it in .text.cold, i.e. far away from the call sites. I realize dev_core_stats_*() aren't called frequently, but why making only one small helper cold rather than all of them then?This helper is used at least one time per netdevice lifetime. This is definitely cold.
Quoted 7 lines
Quoted 4 lines
But then each dev_stats_*_inc() (not cold) has to call it from a completely different piece of .text far from their. I either don't understand the idea or dunno. Why not make them cold as well then?
The
__coldattribute is only applied to the helper _allocating_ the memory, once.
Then it should be applied to netdev_core_stats_alloc(), not dev_core_stats(). The latter only dereferences the already existing pointer or calls the former, which actually does the allocation. That's why I don't get why make one if/else non-inline or even cold.
Quoted 6 lines
Not on the functions actually incrementing the stats.
There are situations where they can be called thousands/millions of times per second (incast flood).
If this situation happens, the _allocation_ still happens once.
Correct, but dev_core_stats() will be called the same millions of times per second, see above. It's called unconditionally each increment.
So seems like I got the idea of .cold correctly, but you were referring to the wrong function.
Quoted 23 lines
Quoted 23 lines
Quoted 5 lines
Forcing an inline makes no sense, this would duplicate the code four times, for absolutely no gain.
I'd love to see bloat-o-meter numbers, I suspect we're talking about 20-30 bytes.
Quoted 14 lines
Quoted 14 lines
Quoted 11 lines
Quoted 11 lines
net/core/dev.c +9
-0+{ +/* This READ_ONCE() pairs with the write in netdev_core_stats_alloc() */ +struct net_device_core_stats __percpu *p =READ_ONCE (dev->core_stats); + +if (likely (p)) +return p; + +return netdev_core_stats_alloc (dev); +}[...]
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Thanks,
OlekThanks,
Olek
Thanks,
Olek
Quoted 57 lines · Alexander Lobakin
From: Eric Dumazet <[email protected]>
Date: Tue, 12 Sep 2023 19:28:50 +0200Quoted 53 lines
Quoted 50 lines · Alexander Lobakin
From: Eric Dumazet <[email protected]>
Date: Tue, 12 Sep 2023 18:04:44 +0200Quoted 39 lines
Quoted 29 lines · Alexander Lobakin
From: Eric Dumazet <[email protected]>
Date: Tue, 12 Sep 2023 06:23:24 +0200Quoted 5 lines · Yajun Deng
Quoted 4 lines
Although there is a
kfree_skb_reason()helper function that can be used to find the reason for dropped packets, but most callers didn't increase one ofrx_dropped,tx_dropped,rx_nohandlerandrx_otherhost_dropped.[...]
Quoted 7 lines
Quoted 7 lines
EXPORT_SYMBOL(netdev_stats_to_stats64);(quoted diff) +1
-1-struct net_device_core_stats __percpu *netdev_core_stats_alloc(struct net_device *dev) +static struct net_device_core_stats __percpu *netdev_core_stats_alloc(struct net_device *dev) { struct net_device_core_stats __percpu *p;Quoted 9 lines
Review struct net_device_core_stats __percpu *netdev_core_stats_alloc(struct net_device · line 10492
Quoted 7 lines
(quoted diff) +2
-1@@ -10488,7 +10488,33 @@ struct net_device_core_stats __percpu *netdev_core_stats_alloc(struct net_device /* This READ_ONCE() pairs with the cmpxchg() above */ return READ_ONCE(dev->core_stats); } -EXPORT_SYMBOL(netdev_core_stats_alloc); + +static inline struct net_device_core_stats __percpu *dev_core_stats(struct net_device *dev)Please remove this inline attritbute. Consider using
__coldinstead.Quoted 7 lines
__cold?O_oI thought the author's inlining it as it's a couple locs/intstructions, while the compilers would most likely keep it non-inlined as it's referenced 4 times.__coldwill for sure keep it standalone and place it in .text.cold, i.e. far away from the call sites. I realize dev_core_stats_*() aren't called frequently, but why making only one small helper cold rather than all of them then?Quoted 2 lines
This helper is used at least one time per netdevice lifetime. This is definitely cold.
But then each dev_stats_*_inc() (not cold) has to call it from a completely different piece of .text far from their. I either don't understand the idea or dunno. Why not make them cold as well then?
Quoted 7 lines
Quoted 2 lines
The
__coldattribute is only applied to the helper _allocating_ the memory, once.Then it should be applied to
netdev_core_stats_alloc(), notdev_core_stats(). The latter only dereferences the already existing pointer or calls the former, which actually does the allocation. That's why I don't get why make one if/else non-inline or even cold.
Sure, this was what was suggested (perhaps not _very_ precisely, but the general idea was pretty clear).
v2 seems ok, right ?
It seems we are all on the same page.
+static __cold struct net_device_core_stats __percpu *dev_core_stats(struct net_device *dev)
+{
+ /* This READ_ONCE() pairs with the write in netdev_core_stats_alloc() */
+ struct net_device_core_stats __percpu *p = READ_ONCE(dev->core_stats);
+
+ if (likely(p))
+ return p;
+
+ return netdev_core_stats_alloc(dev);
+}
+
+#define DEV_CORE_STATS_INC(FIELD) \
+void dev_core_stats_##FIELD##_inc(struct net_device *dev) \
+{ \
+ struct net_device_core_stats __percpu *p; \
+ \
+ p = dev_core_stats(dev); \
+ if (p) \
+ this_cpu_inc(p->FIELD); \
+} \+EXPORT_SYMBOL(dev_core_stats_##FIELD##_inc)
Quoted 18 lines · Eric Dumazet
Sure, this was what was suggested (perhaps not _very_ precisely, but the general idea was pretty clear).
v2 seems ok, right ?It seems we are all on the same page.
+static
__coldstructnet_device_core_stats__percpu*dev_core_stats(structnet_device*dev)(quoted diff) +10
-0+{ + /* This READ_ONCE() pairs with the write in netdev_core_stats_alloc() */ + struct net_device_core_stats __percpu *p = READ_ONCE(dev->core_stats); + + if (likely(p)) + return p; + + return netdev_core_stats_alloc(dev); +} +
Review
Quoted 10 lines
(quoted diff) +10
-0+#define DEV_CORE_STATS_INC(FIELD) \ +void dev_core_stats_##FIELD##_inc(struct net_device *dev) \ +{ \ + struct net_device_core_stats __percpu *p; \ + \ + p = dev_core_stats(dev); \ + if (p) \ + this_cpu_inc(p->FIELD); \ +} \ +EXPORT_SYMBOL(dev_core_stats_##FIELD##_inc)
Oh well, I just read the patch, and it seems wrong indeed.
netdev_core_stats_alloc() is the one that can be cold.
Quoted 32 lines · Eric Dumazet
Quoted 18 lines · Eric Dumazet
Sure, this was what was suggested (perhaps not _very_ precisely, but the general idea was pretty clear).
v2 seems ok, right ?It seems we are all on the same page.
+static
__coldstructnet_device_core_stats__percpu*dev_core_stats(structnet_device*dev)(quoted diff) +10
-0+{ + /* This READ_ONCE() pairs with the write in netdev_core_stats_alloc() */ + struct net_device_core_stats __percpu *p = READ_ONCE(dev->core_stats); + + if (likely(p)) + return p; + + return netdev_core_stats_alloc(dev); +} +Review
Quoted 10 lines
(quoted diff) +10
-0+#define DEV_CORE_STATS_INC(FIELD) \ +void dev_core_stats_##FIELD##_inc(struct net_device *dev) \ +{ \ + struct net_device_core_stats __percpu *p; \ + \ + p = dev_core_stats(dev); \ + if (p) \ + this_cpu_inc(p->FIELD); \ +} \ +EXPORT_SYMBOL(dev_core_stats_##FIELD##_inc)Oh well, I just read the patch, and it seems wrong indeed.
Quoted 1 line
netdev_core_stats_alloc()is the one that can be cold.
Okay, I would add __cold to netdev_core_stats_alloc() in v3.
Olek suggest that define a new dev_core_stats_inc() function.
I hope to see the suggestion in another reply.
From: Yajun Deng <[email protected]>
Date: Wed, 13 Sep 2023 10:08:08 +0800
Quoted 4 lines · Alexander Lobakin
Quoted 2 lines
From: Yajun Deng <[email protected]>
Date: Mon, 11 Sep 2023 16:20:16 +0800
[...]
Quoted 7 lines
Quoted 1 line
EXPORT_SYMBOL_GPL(dev_core_stats_inc); // Why not GPL BTW?This may be a better option.
Just because
EXPORT_SYMBOL(netdev_core_stats_alloc)before, but I think
EXPORT_SYMBOL_GPLis better.
Ah I see. BTW, if you will still define increment functions as externals, there will be no reason to export netdev_core_stats_alloc() or even make it non-static at all.
Quoted 21 lines
Quoted 19 lines
And then build inlines:
#define
DEV_CORE_STATS_INC(FIELD)\
static inline void \
dev_core_stats_##FIELD##_inc(structnet_device*dev) \{ \ dev_core_stats_inc(dev, \ offsetof(struct net_device_core_stats, FIELD)); \ }
DEV_CORE_STATS_INC(rx_dropped);
...OR even just make them macros
#define __DEV_CORE_STATS_INC(dev, field) \ dev_core_stats_inc(dev, \ offsetof(struct net_device_core_stats, field))
Quoted 5 lines
Quoted 3 lines
#define
dev_core_stats_rx_dropped_inc(dev)\
__DEV_CORE_STATS_INC(dev, rx_dropped)
...I would like the former. Keep it the same as before.
By "the former" you mean to build static inlines or externals? Seems like the first one, but I got confused by your "the same as before" :D
Quoted 11 lines
Quoted 10 lines
Just don't copy that awful Thunderbird's line wrap and don't assume this code builds and works and that is something finished/polished.
You'll be able to trace functions and you'll be able to understand which counter has been incremented by checking the second argument, i.e. the field offset (IIRC tracing shows you arguments).
And that way you wouldn't geometrically increase the number of symbol exports and deal with its consequences.I agree that.
Ok, after this one I guess you meant "I'd like to use your approach with static inlines".
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
/**
*dev_get_stats- get network device statisticsThanks,
Olek
Thanks,
Olek
Quoted 49 lines · Alexander Lobakin
From: Yajun Deng <[email protected]>
Date: Wed, 13 Sep 2023 10:08:08 +0800Quoted 3 lines · Alexander Lobakin
Quoted 2 lines
From: Yajun Deng <[email protected]>
Date: Mon, 11 Sep 2023 16:20:16 +0800[...]
Quoted 6 lines
Quoted 1 line
EXPORT_SYMBOL_GPL(dev_core_stats_inc); // Why not GPL BTW?This may be a better option.
Just because
EXPORT_SYMBOL(netdev_core_stats_alloc)before, but I think
EXPORT_SYMBOL_GPLis better.Ah I see. BTW, if you will still define increment functions as externals, there will be no reason to export
netdev_core_stats_alloc()or even make it non-static at all.Quoted 16 lines
Quoted 16 lines
And then build inlines:
#define
DEV_CORE_STATS_INC(FIELD)\
static inline void \
dev_core_stats_##FIELD##_inc(structnet_device*dev) \{ \ dev_core_stats_inc(dev, \ offsetof(struct net_device_core_stats, FIELD)); \ }
DEV_CORE_STATS_INC(rx_dropped);
...OR even just make them macros
Quoted 8 lines
Quoted 7 lines
#define __DEV_CORE_STATS_INC(dev, field) \ dev_core_stats_inc(dev, \ offsetof(struct net_device_core_stats, field))#define
dev_core_stats_rx_dropped_inc(dev)\
__DEV_CORE_STATS_INC(dev, rx_dropped)
...I would like the former. Keep it the same as before.
By "the former" you mean to build static inlines or externals? Seems like the first one, but I got confused by your "the same as before" :D
Quoted 4 lines
Quoted 4 lines
Just don't copy that awful Thunderbird's line wrap and don't assume this code builds and works and that is something finished/polished.
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
You'll be able to trace functions and you'll be able to understand which counter has been incremented by checking the second argument, i.e. the field offset (IIRC tracing shows you arguments).
And that way you wouldn't geometrically increase the number of symbol exports and deal with its consequences.I agree that.
Ok, after this one I guess you meant "I'd like to use your approach with static inlines".
Finally, I give up this approach.
The new function dev_core_stats_inc() didn't called by external modules directly.
So EXPORT_SYMBOL_GPL(dev_core_stats_inc) can be removed by anyone.
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
/**
*dev_get_stats- get network device statisticsThanks,
OlekThanks,
Olek
From: Yajun Deng <[email protected]>
Date: Thu, 14 Sep 2023 10:44:14 +0800
Quoted 58 lines · Alexander Lobakin
Quoted 56 lines
From: Yajun Deng <[email protected]>
Date: Wed, 13 Sep 2023 10:08:08 +0800Quoted 3 lines · Alexander Lobakin
Quoted 2 lines
From: Yajun Deng <[email protected]>
Date: Mon, 11 Sep 2023 16:20:16 +0800[...]
Quoted 6 lines
Quoted 1 line
EXPORT_SYMBOL_GPL(dev_core_stats_inc); // Why not GPL BTW?This may be a better option.
Just because
EXPORT_SYMBOL(netdev_core_stats_alloc)before, but I think
EXPORT_SYMBOL_GPLis better.Ah I see. BTW, if you will still define increment functions as externals, there will be no reason to export
netdev_core_stats_alloc()or even make it non-static at all.Quoted 16 lines
Quoted 15 lines
And then build inlines:
#define DEV_CORE_STATS_INC(FIELD) \
static inline void \
dev_core_stats_##FIELD##_inc(structnet_device*dev) \
{ \
dev_core_stats_inc(dev, \
offsetof(struct net_device_core_stats, FIELD)); \
}
DEV_CORE_STATS_INC(rx_dropped);
...OR even just make them macros
Quoted 8 lines
Quoted 7 lines
#define
__DEV_CORE_STATS_INC(dev, field)\
dev_core_stats_inc(dev, \
offsetof(struct net_device_core_stats, field))#define dev_core_stats_rx_dropped_inc(dev) \
__DEV_CORE_STATS_INC(dev,rx_dropped)
...I would like the former. Keep it the same as before.
By "the former" you mean to build static inlines or externals? Seems like the first one, but I got confused by your "the same as before" :D
Quoted 11 lines
Quoted 11 lines
Just don't copy that awful Thunderbird's line wrap and don't assume this
code builds and works and that is something finished/polished.You'll be able to trace functions and you'll be able to understand which
counter has been incremented by checking the second argument, i.e. the field offset (IIRC tracing shows you arguments).
And that way you wouldn't geometrically increase the number of symbol exports and deal with its consequences.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
I agree that.
Ok, after this one I guess you meant "I'd like to use your approach with static inlines".
Finally, I give up this approach.
The new function
dev_core_stats_inc()didn't called by external modules directly.
If it's called via an inline or macro or whatever, it still needs to be exported.
Double-check that modpost doesn't complain on allmodconfig build.
Quoted 2 lines
So
EXPORT_SYMBOL_GPL(dev_core_stats_inc)can be removed by anyone.
That doesn't mean it won't be needed tomorrow.
And I don't feel like it's a good excuse to define 1 external function per counter instead of 1 external + static inlines for the rest. It's not only about the exports.
Esp. given that I wrote almost the whole code needed for it to work in one of my previous replies.
If you don't want to do that, I could take it over xD
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
/**
* dev_get_stats - get network device statisticsThanks,
OlekThanks,
Olek
Thanks,
Olek