netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/2] net: collect tstats automatically
@ 2024-02-28 11:31 Breno Leitao
  2024-02-28 11:31 ` [PATCH net-next 1/2] net: get stats64 if device if driver is configured Breno Leitao
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Breno Leitao @ 2024-02-28 11:31 UTC (permalink / raw)
  To: kuba, davem, pabeni, edumazet; +Cc: netdev, linux-kernel, horms, dsahern

The commit 34d21de99cea9 ("net: Move {l,t,d}stats allocation to core and
convert veth & vrf") added a field in struct_netdevice, which tells what
type of statistics the driver supports.

That field is used primarily to allocate stats structures automatically,
but, it also could leveraged to simplify the drivers even further, such
as, if the driver relies in the default stats collection, then it
doesn't need to assign to .ndo_get_stats64. That means that drivers only
assign functions to .ndo_get_stats64 if they are using something
special.

I started to move some of these drivers[1][2][3] to use the core
allocation, and with this change in, I just need to touch the driver
once, and be able to simplify the whole stats allocation and collection
for generic case.

There are 44 devices today that could benefit from this simplification.

	# grep -r .ndo_get_stats64 | grep dev_get_tstats64 | wc -l
	44

As of today, netnext only has the `sit` driver fully ported to core
stats allocation, hence the second patch.

Links:
[1] https://lore.kernel.org/all/20240227182338.2739884-1-leitao@debian.org/
[2] https://lore.kernel.org/all/20240222144117.1370101-1-leitao@debian.org/
[3] https://lore.kernel.org/all/20240223115839.3572852-1-leitao@debian.org/

Breno Leitao (2):
  net: get stats64 if device if driver is configured
  net: sit: Do not set .ndo_get_stats64

 net/core/dev.c | 2 ++
 net/ipv6/sit.c | 1 -
 2 files changed, 2 insertions(+), 1 deletion(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH net-next 1/2] net: get stats64 if device if driver is configured
  2024-02-28 11:31 [PATCH net-next 0/2] net: collect tstats automatically Breno Leitao
@ 2024-02-28 11:31 ` Breno Leitao
  2024-02-28 14:34   ` Simon Horman
  2024-02-28 11:31 ` [PATCH net-next 2/2] net: sit: Do not set .ndo_get_stats64 Breno Leitao
  2024-02-29 12:00 ` [PATCH net-next 0/2] net: collect tstats automatically patchwork-bot+netdevbpf
  2 siblings, 1 reply; 6+ messages in thread
From: Breno Leitao @ 2024-02-28 11:31 UTC (permalink / raw)
  To: kuba, davem, pabeni, edumazet
  Cc: netdev, linux-kernel, horms, dsahern, Jiri Pirko, Daniel Borkmann,
	Lorenzo Bianconi, Coco Li

If the network driver is relying in the net core to do stats allocation,
then we want to dev_get_tstats64() instead of netdev_stats_to_stats64(),
since there are per-cpu stats that needs to be taken in consideration.

This will also simplify the drivers in regard to statistics. Once the
driver sets NETDEV_PCPU_STAT_TSTATS, it doesn't not need to allocate the
stacks, neither it needs to set `.ndo_get_stats64 = dev_get_tstats64`
for the generic stats collection function anymore.

Signed-off-by: Breno Leitao <leitao@debian.org>
---
 net/core/dev.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/core/dev.c b/net/core/dev.c
index 275fd5259a4a..3577620e39bd 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -10701,6 +10701,8 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
 		ops->ndo_get_stats64(dev, storage);
 	} else if (ops->ndo_get_stats) {
 		netdev_stats_to_stats64(storage, ops->ndo_get_stats(dev));
+	} else if (dev->pcpu_stat_type == NETDEV_PCPU_STAT_TSTATS) {
+		dev_get_tstats64(dev, storage);
 	} else {
 		netdev_stats_to_stats64(storage, &dev->stats);
 	}
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net-next 2/2] net: sit: Do not set .ndo_get_stats64
  2024-02-28 11:31 [PATCH net-next 0/2] net: collect tstats automatically Breno Leitao
  2024-02-28 11:31 ` [PATCH net-next 1/2] net: get stats64 if device if driver is configured Breno Leitao
@ 2024-02-28 11:31 ` Breno Leitao
  2024-02-28 14:34   ` Simon Horman
  2024-02-29 12:00 ` [PATCH net-next 0/2] net: collect tstats automatically patchwork-bot+netdevbpf
  2 siblings, 1 reply; 6+ messages in thread
From: Breno Leitao @ 2024-02-28 11:31 UTC (permalink / raw)
  To: kuba, davem, pabeni, edumazet, David Ahern; +Cc: netdev, linux-kernel, horms

If the driver is using the network core allocation mechanism, by setting
NETDEV_PCPU_STAT_TSTATS, as this driver is, then, it doesn't need to set
the dev_get_tstats64() generic .ndo_get_stats64 function pointer. Since
the network core calls it automatically, and .ndo_get_stats64 should
only be set if the driver needs special treatment.

This simplifies the driver, since all the generic statistics is now
handled by core.

Signed-off-by: Breno Leitao <leitao@debian.org>
---
 net/ipv6/sit.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
index 5ad01480854d..655c9b1a19b8 100644
--- a/net/ipv6/sit.c
+++ b/net/ipv6/sit.c
@@ -1398,7 +1398,6 @@ static const struct net_device_ops ipip6_netdev_ops = {
 	.ndo_uninit	= ipip6_tunnel_uninit,
 	.ndo_start_xmit	= sit_tunnel_xmit,
 	.ndo_siocdevprivate = ipip6_tunnel_siocdevprivate,
-	.ndo_get_stats64 = dev_get_tstats64,
 	.ndo_get_iflink = ip_tunnel_get_iflink,
 	.ndo_tunnel_ctl = ipip6_tunnel_ctl,
 };
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next 1/2] net: get stats64 if device if driver is configured
  2024-02-28 11:31 ` [PATCH net-next 1/2] net: get stats64 if device if driver is configured Breno Leitao
@ 2024-02-28 14:34   ` Simon Horman
  0 siblings, 0 replies; 6+ messages in thread
From: Simon Horman @ 2024-02-28 14:34 UTC (permalink / raw)
  To: Breno Leitao
  Cc: kuba, davem, pabeni, edumazet, netdev, linux-kernel, dsahern,
	Jiri Pirko, Daniel Borkmann, Lorenzo Bianconi, Coco Li

On Wed, Feb 28, 2024 at 03:31:21AM -0800, Breno Leitao wrote:
> If the network driver is relying in the net core to do stats allocation,
> then we want to dev_get_tstats64() instead of netdev_stats_to_stats64(),
> since there are per-cpu stats that needs to be taken in consideration.
> 
> This will also simplify the drivers in regard to statistics. Once the
> driver sets NETDEV_PCPU_STAT_TSTATS, it doesn't not need to allocate the
> stacks, neither it needs to set `.ndo_get_stats64 = dev_get_tstats64`
> for the generic stats collection function anymore.
> 
> Signed-off-by: Breno Leitao <leitao@debian.org>

Reviewed-by: Simon Horman <horms@kernel.org>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next 2/2] net: sit: Do not set .ndo_get_stats64
  2024-02-28 11:31 ` [PATCH net-next 2/2] net: sit: Do not set .ndo_get_stats64 Breno Leitao
@ 2024-02-28 14:34   ` Simon Horman
  0 siblings, 0 replies; 6+ messages in thread
From: Simon Horman @ 2024-02-28 14:34 UTC (permalink / raw)
  To: Breno Leitao
  Cc: kuba, davem, pabeni, edumazet, David Ahern, netdev, linux-kernel

On Wed, Feb 28, 2024 at 03:31:22AM -0800, Breno Leitao wrote:
> If the driver is using the network core allocation mechanism, by setting
> NETDEV_PCPU_STAT_TSTATS, as this driver is, then, it doesn't need to set
> the dev_get_tstats64() generic .ndo_get_stats64 function pointer. Since
> the network core calls it automatically, and .ndo_get_stats64 should
> only be set if the driver needs special treatment.
> 
> This simplifies the driver, since all the generic statistics is now
> handled by core.
> 
> Signed-off-by: Breno Leitao <leitao@debian.org>

Reviewed-by: Simon Horman <horms@kernel.org>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next 0/2] net: collect tstats automatically
  2024-02-28 11:31 [PATCH net-next 0/2] net: collect tstats automatically Breno Leitao
  2024-02-28 11:31 ` [PATCH net-next 1/2] net: get stats64 if device if driver is configured Breno Leitao
  2024-02-28 11:31 ` [PATCH net-next 2/2] net: sit: Do not set .ndo_get_stats64 Breno Leitao
@ 2024-02-29 12:00 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-02-29 12:00 UTC (permalink / raw)
  To: Breno Leitao
  Cc: kuba, davem, pabeni, edumazet, netdev, linux-kernel, horms,
	dsahern

Hello:

This series was applied to netdev/net-next.git (main)
by Paolo Abeni <pabeni@redhat.com>:

On Wed, 28 Feb 2024 03:31:20 -0800 you wrote:
> The commit 34d21de99cea9 ("net: Move {l,t,d}stats allocation to core and
> convert veth & vrf") added a field in struct_netdevice, which tells what
> type of statistics the driver supports.
> 
> That field is used primarily to allocate stats structures automatically,
> but, it also could leveraged to simplify the drivers even further, such
> as, if the driver relies in the default stats collection, then it
> doesn't need to assign to .ndo_get_stats64. That means that drivers only
> assign functions to .ndo_get_stats64 if they are using something
> special.
> 
> [...]

Here is the summary with links:
  - [net-next,1/2] net: get stats64 if device if driver is configured
    https://git.kernel.org/netdev/net-next/c/3e2f544dd8a3
  - [net-next,2/2] net: sit: Do not set .ndo_get_stats64
    https://git.kernel.org/netdev/net-next/c/fa0cd9021369

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] 6+ messages in thread

end of thread, other threads:[~2024-02-29 12:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-28 11:31 [PATCH net-next 0/2] net: collect tstats automatically Breno Leitao
2024-02-28 11:31 ` [PATCH net-next 1/2] net: get stats64 if device if driver is configured Breno Leitao
2024-02-28 14:34   ` Simon Horman
2024-02-28 11:31 ` [PATCH net-next 2/2] net: sit: Do not set .ndo_get_stats64 Breno Leitao
2024-02-28 14:34   ` Simon Horman
2024-02-29 12:00 ` [PATCH net-next 0/2] net: collect tstats automatically 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;
as well as URLs for NNTP newsgroup(s).