linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 1/2] net/vsockmon: Leverage core stats allocator
@ 2024-02-23 11:58 Breno Leitao
  2024-02-23 11:58 ` [PATCH net-next 2/2] net/vsockmon: Do not set zeroed statistics Breno Leitao
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Breno Leitao @ 2024-02-23 11:58 UTC (permalink / raw)
  To: kuba, davem, pabeni, edumazet, Stefano Garzarella
  Cc: netdev, linux-kernel, horms, open list:VM SOCKETS (AF_VSOCK)

With commit 34d21de99cea9 ("net: Move {l,t,d}stats allocation to core and
convert veth & vrf"), stats allocation could be done on net core
instead of this driver.

With this new approach, the driver doesn't have to bother with error
handling (allocation failure checking, making sure free happens in the
right spot, etc). This is core responsibility now.

Remove the allocation in the vsockmon driver and leverage the network
core allocation instead.

Signed-off-by: Breno Leitao <leitao@debian.org>
---
 drivers/net/vsockmon.c | 16 +---------------
 1 file changed, 1 insertion(+), 15 deletions(-)

diff --git a/drivers/net/vsockmon.c b/drivers/net/vsockmon.c
index b1bb1b04b664..a0b4dca36baf 100644
--- a/drivers/net/vsockmon.c
+++ b/drivers/net/vsockmon.c
@@ -13,19 +13,6 @@
 #define DEFAULT_MTU (VIRTIO_VSOCK_MAX_PKT_BUF_SIZE + \
 		     sizeof(struct af_vsockmon_hdr))
 
-static int vsockmon_dev_init(struct net_device *dev)
-{
-	dev->lstats = netdev_alloc_pcpu_stats(struct pcpu_lstats);
-	if (!dev->lstats)
-		return -ENOMEM;
-	return 0;
-}
-
-static void vsockmon_dev_uninit(struct net_device *dev)
-{
-	free_percpu(dev->lstats);
-}
-
 struct vsockmon {
 	struct vsock_tap vt;
 };
@@ -79,8 +66,6 @@ static int vsockmon_change_mtu(struct net_device *dev, int new_mtu)
 }
 
 static const struct net_device_ops vsockmon_ops = {
-	.ndo_init = vsockmon_dev_init,
-	.ndo_uninit = vsockmon_dev_uninit,
 	.ndo_open = vsockmon_open,
 	.ndo_stop = vsockmon_close,
 	.ndo_start_xmit = vsockmon_xmit,
@@ -112,6 +97,7 @@ static void vsockmon_setup(struct net_device *dev)
 	dev->flags = IFF_NOARP;
 
 	dev->mtu = DEFAULT_MTU;
+	dev->pcpu_stat_type = NETDEV_PCPU_STAT_LSTATS;
 }
 
 static struct rtnl_link_ops vsockmon_link_ops __read_mostly = {
-- 
2.39.3


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

* [PATCH net-next 2/2] net/vsockmon: Do not set zeroed statistics
  2024-02-23 11:58 [PATCH net-next 1/2] net/vsockmon: Leverage core stats allocator Breno Leitao
@ 2024-02-23 11:58 ` Breno Leitao
  2024-02-23 13:08   ` Eric Dumazet
                     ` (2 more replies)
  2024-02-23 13:09 ` [PATCH net-next 1/2] net/vsockmon: Leverage core stats allocator Eric Dumazet
                   ` (2 subsequent siblings)
  3 siblings, 3 replies; 8+ messages in thread
From: Breno Leitao @ 2024-02-23 11:58 UTC (permalink / raw)
  To: kuba, davem, pabeni, edumazet, Stefano Garzarella
  Cc: netdev, linux-kernel, horms, open list:VM SOCKETS (AF_VSOCK)

Do not set rtnl_link_stats64 fields to zero, since they are zeroed
before ops->ndo_get_stats64 is called in core dev_get_stats() function.

Signed-off-by: Breno Leitao <leitao@debian.org>
---
 drivers/net/vsockmon.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/net/vsockmon.c b/drivers/net/vsockmon.c
index a0b4dca36baf..a1ba5169ed5d 100644
--- a/drivers/net/vsockmon.c
+++ b/drivers/net/vsockmon.c
@@ -46,9 +46,6 @@ static void
 vsockmon_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
 {
 	dev_lstats_read(dev, &stats->rx_packets, &stats->rx_bytes);
-
-	stats->tx_packets = 0;
-	stats->tx_bytes = 0;
 }
 
 static int vsockmon_is_valid_mtu(int new_mtu)
-- 
2.39.3


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

* Re: [PATCH net-next 2/2] net/vsockmon: Do not set zeroed statistics
  2024-02-23 11:58 ` [PATCH net-next 2/2] net/vsockmon: Do not set zeroed statistics Breno Leitao
@ 2024-02-23 13:08   ` Eric Dumazet
  2024-02-26  8:31   ` Stefano Garzarella
  2024-02-26  9:27   ` Jason Xing
  2 siblings, 0 replies; 8+ messages in thread
From: Eric Dumazet @ 2024-02-23 13:08 UTC (permalink / raw)
  To: Breno Leitao
  Cc: kuba, davem, pabeni, Stefano Garzarella, netdev, linux-kernel,
	horms, open list:VM SOCKETS (AF_VSOCK)

On Fri, Feb 23, 2024 at 12:58 PM Breno Leitao <leitao@debian.org> wrote:
>
> Do not set rtnl_link_stats64 fields to zero, since they are zeroed
> before ops->ndo_get_stats64 is called in core dev_get_stats() function.
>
> Signed-off-by: Breno Leitao <leitao@debian.org>

Reviewed-by: Eric Dumazet <edumazet@google.com>

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

* Re: [PATCH net-next 1/2] net/vsockmon: Leverage core stats allocator
  2024-02-23 11:58 [PATCH net-next 1/2] net/vsockmon: Leverage core stats allocator Breno Leitao
  2024-02-23 11:58 ` [PATCH net-next 2/2] net/vsockmon: Do not set zeroed statistics Breno Leitao
@ 2024-02-23 13:09 ` Eric Dumazet
  2024-02-26  8:27 ` Stefano Garzarella
  2024-02-27  3:20 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 8+ messages in thread
From: Eric Dumazet @ 2024-02-23 13:09 UTC (permalink / raw)
  To: Breno Leitao
  Cc: kuba, davem, pabeni, Stefano Garzarella, netdev, linux-kernel,
	horms, open list:VM SOCKETS (AF_VSOCK)

On Fri, Feb 23, 2024 at 12:58 PM Breno Leitao <leitao@debian.org> wrote:
>
> With commit 34d21de99cea9 ("net: Move {l,t,d}stats allocation to core and
> convert veth & vrf"), stats allocation could be done on net core
> instead of this driver.
>
> With this new approach, the driver doesn't have to bother with error
> handling (allocation failure checking, making sure free happens in the
> right spot, etc). This is core responsibility now.
>
> Remove the allocation in the vsockmon driver and leverage the network
> core allocation instead.
>
> Signed-off-by: Breno Leitao <leitao@debian.org>

Reviewed-by: Eric Dumazet <edumazet@google.com>

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

* Re: [PATCH net-next 1/2] net/vsockmon: Leverage core stats allocator
  2024-02-23 11:58 [PATCH net-next 1/2] net/vsockmon: Leverage core stats allocator Breno Leitao
  2024-02-23 11:58 ` [PATCH net-next 2/2] net/vsockmon: Do not set zeroed statistics Breno Leitao
  2024-02-23 13:09 ` [PATCH net-next 1/2] net/vsockmon: Leverage core stats allocator Eric Dumazet
@ 2024-02-26  8:27 ` Stefano Garzarella
  2024-02-27  3:20 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 8+ messages in thread
From: Stefano Garzarella @ 2024-02-26  8:27 UTC (permalink / raw)
  To: Breno Leitao
  Cc: kuba, davem, pabeni, edumazet, netdev, linux-kernel, horms,
	open list:VM SOCKETS (AF_VSOCK)

On Fri, Feb 23, 2024 at 03:58:37AM -0800, Breno Leitao wrote:
>With commit 34d21de99cea9 ("net: Move {l,t,d}stats allocation to core and
>convert veth & vrf"), stats allocation could be done on net core
>instead of this driver.
>
>With this new approach, the driver doesn't have to bother with error
>handling (allocation failure checking, making sure free happens in the
>right spot, etc). This is core responsibility now.
>
>Remove the allocation in the vsockmon driver and leverage the network
>core allocation instead.
>
>Signed-off-by: Breno Leitao <leitao@debian.org>
>---
> drivers/net/vsockmon.c | 16 +---------------
> 1 file changed, 1 insertion(+), 15 deletions(-)

Thanks for this patch!

Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>

>
>diff --git a/drivers/net/vsockmon.c b/drivers/net/vsockmon.c
>index b1bb1b04b664..a0b4dca36baf 100644
>--- a/drivers/net/vsockmon.c
>+++ b/drivers/net/vsockmon.c
>@@ -13,19 +13,6 @@
> #define DEFAULT_MTU (VIRTIO_VSOCK_MAX_PKT_BUF_SIZE + \
> 		     sizeof(struct af_vsockmon_hdr))
>
>-static int vsockmon_dev_init(struct net_device *dev)
>-{
>-	dev->lstats = netdev_alloc_pcpu_stats(struct pcpu_lstats);
>-	if (!dev->lstats)
>-		return -ENOMEM;
>-	return 0;
>-}
>-
>-static void vsockmon_dev_uninit(struct net_device *dev)
>-{
>-	free_percpu(dev->lstats);
>-}
>-
> struct vsockmon {
> 	struct vsock_tap vt;
> };
>@@ -79,8 +66,6 @@ static int vsockmon_change_mtu(struct net_device *dev, int new_mtu)
> }
>
> static const struct net_device_ops vsockmon_ops = {
>-	.ndo_init = vsockmon_dev_init,
>-	.ndo_uninit = vsockmon_dev_uninit,
> 	.ndo_open = vsockmon_open,
> 	.ndo_stop = vsockmon_close,
> 	.ndo_start_xmit = vsockmon_xmit,
>@@ -112,6 +97,7 @@ static void vsockmon_setup(struct net_device *dev)
> 	dev->flags = IFF_NOARP;
>
> 	dev->mtu = DEFAULT_MTU;
>+	dev->pcpu_stat_type = NETDEV_PCPU_STAT_LSTATS;
> }
>
> static struct rtnl_link_ops vsockmon_link_ops __read_mostly = {
>-- 
>2.39.3
>


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

* Re: [PATCH net-next 2/2] net/vsockmon: Do not set zeroed statistics
  2024-02-23 11:58 ` [PATCH net-next 2/2] net/vsockmon: Do not set zeroed statistics Breno Leitao
  2024-02-23 13:08   ` Eric Dumazet
@ 2024-02-26  8:31   ` Stefano Garzarella
  2024-02-26  9:27   ` Jason Xing
  2 siblings, 0 replies; 8+ messages in thread
From: Stefano Garzarella @ 2024-02-26  8:31 UTC (permalink / raw)
  To: Breno Leitao
  Cc: kuba, davem, pabeni, edumazet, netdev, linux-kernel, horms,
	open list:VM SOCKETS (AF_VSOCK)

On Fri, Feb 23, 2024 at 03:58:38AM -0800, Breno Leitao wrote:
>Do not set rtnl_link_stats64 fields to zero, since they are zeroed
>before ops->ndo_get_stats64 is called in core dev_get_stats() function.
>
>Signed-off-by: Breno Leitao <leitao@debian.org>
>---
> drivers/net/vsockmon.c | 3 ---
> 1 file changed, 3 deletions(-)

Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>

>
>diff --git a/drivers/net/vsockmon.c b/drivers/net/vsockmon.c
>index a0b4dca36baf..a1ba5169ed5d 100644
>--- a/drivers/net/vsockmon.c
>+++ b/drivers/net/vsockmon.c
>@@ -46,9 +46,6 @@ static void
> vsockmon_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
> {
> 	dev_lstats_read(dev, &stats->rx_packets, &stats->rx_bytes);
>-
>-	stats->tx_packets = 0;
>-	stats->tx_bytes = 0;
> }
>
> static int vsockmon_is_valid_mtu(int new_mtu)
>-- 
>2.39.3
>


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

* Re: [PATCH net-next 2/2] net/vsockmon: Do not set zeroed statistics
  2024-02-23 11:58 ` [PATCH net-next 2/2] net/vsockmon: Do not set zeroed statistics Breno Leitao
  2024-02-23 13:08   ` Eric Dumazet
  2024-02-26  8:31   ` Stefano Garzarella
@ 2024-02-26  9:27   ` Jason Xing
  2 siblings, 0 replies; 8+ messages in thread
From: Jason Xing @ 2024-02-26  9:27 UTC (permalink / raw)
  To: Breno Leitao
  Cc: kuba, davem, pabeni, edumazet, Stefano Garzarella, netdev,
	linux-kernel, horms, open list:VM SOCKETS (AF_VSOCK)

On Fri, Feb 23, 2024 at 7:59 PM Breno Leitao <leitao@debian.org> wrote:
>
> Do not set rtnl_link_stats64 fields to zero, since they are zeroed
> before ops->ndo_get_stats64 is called in core dev_get_stats() function.
>
> Signed-off-by: Breno Leitao <leitao@debian.org>

Reviewed-by: Jason Xing <kerneljasonxing@gmail.com>

Another similar codes that also can be changed later go like this:

diff --git a/drivers/net/nlmon.c b/drivers/net/nlmon.c
index 5e19a6839dea..9b205b152734 100644
--- a/drivers/net/nlmon.c
+++ b/drivers/net/nlmon.c
@@ -56,10 +56,8 @@ nlmon_get_stats64(struct net_device *dev, struct
rtnl_link_stats64 *stats)
        dev_lstats_read(dev, &packets, &bytes);

        stats->rx_packets = packets;
-       stats->tx_packets = 0;

        stats->rx_bytes = bytes;
-       stats->tx_bytes = 0;
 }

 static u32 always_on(struct net_device *dev)

> ---
>  drivers/net/vsockmon.c | 3 ---
>  1 file changed, 3 deletions(-)
>
> diff --git a/drivers/net/vsockmon.c b/drivers/net/vsockmon.c
> index a0b4dca36baf..a1ba5169ed5d 100644
> --- a/drivers/net/vsockmon.c
> +++ b/drivers/net/vsockmon.c
> @@ -46,9 +46,6 @@ static void
>  vsockmon_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
>  {
>         dev_lstats_read(dev, &stats->rx_packets, &stats->rx_bytes);
> -
> -       stats->tx_packets = 0;
> -       stats->tx_bytes = 0;
>  }
>
>  static int vsockmon_is_valid_mtu(int new_mtu)
> --
> 2.39.3
>
>

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

* Re: [PATCH net-next 1/2] net/vsockmon: Leverage core stats allocator
  2024-02-23 11:58 [PATCH net-next 1/2] net/vsockmon: Leverage core stats allocator Breno Leitao
                   ` (2 preceding siblings ...)
  2024-02-26  8:27 ` Stefano Garzarella
@ 2024-02-27  3:20 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 8+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-02-27  3:20 UTC (permalink / raw)
  To: Breno Leitao
  Cc: kuba, davem, pabeni, edumazet, sgarzare, netdev, linux-kernel,
	horms, virtualization

Hello:

This series was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Fri, 23 Feb 2024 03:58:37 -0800 you wrote:
> With commit 34d21de99cea9 ("net: Move {l,t,d}stats allocation to core and
> convert veth & vrf"), stats allocation could be done on net core
> instead of this driver.
> 
> With this new approach, the driver doesn't have to bother with error
> handling (allocation failure checking, making sure free happens in the
> right spot, etc). This is core responsibility now.
> 
> [...]

Here is the summary with links:
  - [net-next,1/2] net/vsockmon: Leverage core stats allocator
    https://git.kernel.org/netdev/net-next/c/bcd53aff4d0c
  - [net-next,2/2] net/vsockmon: Do not set zeroed statistics
    https://git.kernel.org/netdev/net-next/c/3a25e212306c

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

end of thread, other threads:[~2024-02-27  3:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-23 11:58 [PATCH net-next 1/2] net/vsockmon: Leverage core stats allocator Breno Leitao
2024-02-23 11:58 ` [PATCH net-next 2/2] net/vsockmon: Do not set zeroed statistics Breno Leitao
2024-02-23 13:08   ` Eric Dumazet
2024-02-26  8:31   ` Stefano Garzarella
2024-02-26  9:27   ` Jason Xing
2024-02-23 13:09 ` [PATCH net-next 1/2] net/vsockmon: Leverage core stats allocator Eric Dumazet
2024-02-26  8:27 ` Stefano Garzarella
2024-02-27  3:20 ` 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).