* [PATCH net-next] net: virtio: unify code to init stats
@ 2024-06-20 7:44 Michael S. Tsirkin
2024-06-20 8:15 ` Xuan Zhuo
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Michael S. Tsirkin @ 2024-06-20 7:44 UTC (permalink / raw)
To: linux-kernel
Cc: Jason Wang, Xuan Zhuo, Eugenio Pérez, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, virtualization, netdev,
Jiri Pirko
Moving initialization of stats structure into
__free_old_xmit reduces the code size slightly.
It also makes it clearer that this function shouldn't
be called multiple times on the same stats struct.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
Especially important now that Jiri's patch for BQL has been merged.
Lightly tested.
drivers/net/virtio_net.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 283b34d50296..c2ce8de340f7 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -383,6 +383,8 @@ static void __free_old_xmit(struct send_queue *sq, bool in_napi,
unsigned int len;
void *ptr;
+ stats->bytes = stats->packets = 0;
+
while ((ptr = virtqueue_get_buf(sq->vq, &len)) != NULL) {
++stats->packets;
@@ -828,7 +830,7 @@ static void virtnet_rq_unmap_free_buf(struct virtqueue *vq, void *buf)
static void free_old_xmit(struct send_queue *sq, bool in_napi)
{
- struct virtnet_sq_free_stats stats = {0};
+ struct virtnet_sq_free_stats stats;
__free_old_xmit(sq, in_napi, &stats);
@@ -979,7 +981,7 @@ static int virtnet_xdp_xmit(struct net_device *dev,
int n, struct xdp_frame **frames, u32 flags)
{
struct virtnet_info *vi = netdev_priv(dev);
- struct virtnet_sq_free_stats stats = {0};
+ struct virtnet_sq_free_stats stats;
struct receive_queue *rq = vi->rq;
struct bpf_prog *xdp_prog;
struct send_queue *sq;
--
MST
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net-next] net: virtio: unify code to init stats
2024-06-20 7:44 [PATCH net-next] net: virtio: unify code to init stats Michael S. Tsirkin
@ 2024-06-20 8:15 ` Xuan Zhuo
2024-06-20 8:34 ` Heng Qi
2024-06-22 0:33 ` Jakub Kicinski
2 siblings, 0 replies; 4+ messages in thread
From: Xuan Zhuo @ 2024-06-20 8:15 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: Jason Wang, Eugenio Pérez, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, virtualization, netdev, Jiri Pirko,
linux-kernel
On Thu, 20 Jun 2024 03:44:53 -0400, "Michael S. Tsirkin" <mst@redhat.com> wrote:
> Moving initialization of stats structure into
> __free_old_xmit reduces the code size slightly.
> It also makes it clearer that this function shouldn't
> be called multiple times on the same stats struct.
>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> ---
>
> Especially important now that Jiri's patch for BQL has been merged.
> Lightly tested.
>
> drivers/net/virtio_net.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index 283b34d50296..c2ce8de340f7 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -383,6 +383,8 @@ static void __free_old_xmit(struct send_queue *sq, bool in_napi,
> unsigned int len;
> void *ptr;
>
> + stats->bytes = stats->packets = 0;
> +
> while ((ptr = virtqueue_get_buf(sq->vq, &len)) != NULL) {
> ++stats->packets;
>
> @@ -828,7 +830,7 @@ static void virtnet_rq_unmap_free_buf(struct virtqueue *vq, void *buf)
>
> static void free_old_xmit(struct send_queue *sq, bool in_napi)
> {
> - struct virtnet_sq_free_stats stats = {0};
> + struct virtnet_sq_free_stats stats;
>
> __free_old_xmit(sq, in_napi, &stats);
>
> @@ -979,7 +981,7 @@ static int virtnet_xdp_xmit(struct net_device *dev,
> int n, struct xdp_frame **frames, u32 flags)
> {
> struct virtnet_info *vi = netdev_priv(dev);
> - struct virtnet_sq_free_stats stats = {0};
> + struct virtnet_sq_free_stats stats;
> struct receive_queue *rq = vi->rq;
> struct bpf_prog *xdp_prog;
> struct send_queue *sq;
> --
> MST
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net-next] net: virtio: unify code to init stats
2024-06-20 7:44 [PATCH net-next] net: virtio: unify code to init stats Michael S. Tsirkin
2024-06-20 8:15 ` Xuan Zhuo
@ 2024-06-20 8:34 ` Heng Qi
2024-06-22 0:33 ` Jakub Kicinski
2 siblings, 0 replies; 4+ messages in thread
From: Heng Qi @ 2024-06-20 8:34 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: Jason Wang, Xuan Zhuo, Eugenio Pérez, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, virtualization, netdev,
Jiri Pirko, linux-kernel
在 2024/6/20 下午3:44, Michael S. Tsirkin 写道:
> Moving initialization of stats structure into
> __free_old_xmit reduces the code size slightly.
> It also makes it clearer that this function shouldn't
> be called multiple times on the same stats struct.
>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>
> Especially important now that Jiri's patch for BQL has been merged.
> Lightly tested.
>
> drivers/net/virtio_net.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index 283b34d50296..c2ce8de340f7 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -383,6 +383,8 @@ static void __free_old_xmit(struct send_queue *sq, bool in_napi,
> unsigned int len;
> void *ptr;
>
> + stats->bytes = stats->packets = 0;
> +
> while ((ptr = virtqueue_get_buf(sq->vq, &len)) != NULL) {
> ++stats->packets;
>
> @@ -828,7 +830,7 @@ static void virtnet_rq_unmap_free_buf(struct virtqueue *vq, void *buf)
>
> static void free_old_xmit(struct send_queue *sq, bool in_napi)
> {
> - struct virtnet_sq_free_stats stats = {0};
> + struct virtnet_sq_free_stats stats;
>
> __free_old_xmit(sq, in_napi, &stats);
>
> @@ -979,7 +981,7 @@ static int virtnet_xdp_xmit(struct net_device *dev,
> int n, struct xdp_frame **frames, u32 flags)
> {
> struct virtnet_info *vi = netdev_priv(dev);
> - struct virtnet_sq_free_stats stats = {0};
> + struct virtnet_sq_free_stats stats;
> struct receive_queue *rq = vi->rq;
> struct bpf_prog *xdp_prog;
> struct send_queue *sq;
Reviewed-by: Heng Qi <hengqi@linux.alibaba.com>
Thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net-next] net: virtio: unify code to init stats
2024-06-20 7:44 [PATCH net-next] net: virtio: unify code to init stats Michael S. Tsirkin
2024-06-20 8:15 ` Xuan Zhuo
2024-06-20 8:34 ` Heng Qi
@ 2024-06-22 0:33 ` Jakub Kicinski
2 siblings, 0 replies; 4+ messages in thread
From: Jakub Kicinski @ 2024-06-22 0:33 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: linux-kernel, Jason Wang, Xuan Zhuo, Eugenio Pérez,
David S. Miller, Eric Dumazet, Paolo Abeni, virtualization,
netdev, Jiri Pirko
On Thu, 20 Jun 2024 03:44:53 -0400 Michael S. Tsirkin wrote:
> Moving initialization of stats structure into
> __free_old_xmit reduces the code size slightly.
> It also makes it clearer that this function shouldn't
> be called multiple times on the same stats struct.
>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Hm, doesn't apply?
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-06-22 0:33 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-20 7:44 [PATCH net-next] net: virtio: unify code to init stats Michael S. Tsirkin
2024-06-20 8:15 ` Xuan Zhuo
2024-06-20 8:34 ` Heng Qi
2024-06-22 0:33 ` Jakub Kicinski
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).