* [PATCH] virtio_net: Use u64_stats_fetch_begin() for stats fetch
@ 2024-06-19 2:55 Li RongQing
2024-06-19 7:42 ` Heng Qi
` (5 more replies)
0 siblings, 6 replies; 9+ messages in thread
From: Li RongQing @ 2024-06-19 2:55 UTC (permalink / raw)
To: mst, jasowang, xuanzhuo, eperezma, hengqi, virtualization, netdev
Cc: Li RongQing
This place is fetching the stats, so u64_stats_fetch_begin
and u64_stats_fetch_retry should be used
Fixes: 6208799553a8 ("virtio-net: support rx netdim")
Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
drivers/net/virtio_net.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 61a57d1..b669e73 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -2332,16 +2332,18 @@ static void virtnet_poll_cleantx(struct receive_queue *rq)
static void virtnet_rx_dim_update(struct virtnet_info *vi, struct receive_queue *rq)
{
struct dim_sample cur_sample = {};
+ unsigned int start;
if (!rq->packets_in_napi)
return;
- u64_stats_update_begin(&rq->stats.syncp);
- dim_update_sample(rq->calls,
- u64_stats_read(&rq->stats.packets),
- u64_stats_read(&rq->stats.bytes),
- &cur_sample);
- u64_stats_update_end(&rq->stats.syncp);
+ do {
+ start = u64_stats_fetch_begin(&rq->stats.syncp);
+ dim_update_sample(rq->calls,
+ u64_stats_read(&rq->stats.packets),
+ u64_stats_read(&rq->stats.bytes),
+ &cur_sample);
+ } while (u64_stats_fetch_retry(&rq->stats.syncp, start));
net_dim(&rq->dim, cur_sample);
rq->packets_in_napi = 0;
--
2.9.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] virtio_net: Use u64_stats_fetch_begin() for stats fetch
2024-06-19 2:55 [PATCH] virtio_net: Use u64_stats_fetch_begin() for stats fetch Li RongQing
@ 2024-06-19 7:42 ` Heng Qi
2024-06-19 8:06 ` Jiri Pirko
` (4 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Heng Qi @ 2024-06-19 7:42 UTC (permalink / raw)
To: Li RongQing
Cc: Li RongQing, mst, jasowang, xuanzhuo, eperezma, virtualization,
netdev
On Wed, 19 Jun 2024 10:55:29 +0800, Li RongQing <lirongqing@baidu.com> wrote:
> This place is fetching the stats, so u64_stats_fetch_begin
> and u64_stats_fetch_retry should be used
Reviewed-by: Heng Qi <hengqi@linux.alibaba.com>
Thanks!
>
> Fixes: 6208799553a8 ("virtio-net: support rx netdim")
> Signed-off-by: Li RongQing <lirongqing@baidu.com>
> ---
> drivers/net/virtio_net.c | 14 ++++++++------
> 1 file changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index 61a57d1..b669e73 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -2332,16 +2332,18 @@ static void virtnet_poll_cleantx(struct receive_queue *rq)
> static void virtnet_rx_dim_update(struct virtnet_info *vi, struct receive_queue *rq)
> {
> struct dim_sample cur_sample = {};
> + unsigned int start;
>
> if (!rq->packets_in_napi)
> return;
>
> - u64_stats_update_begin(&rq->stats.syncp);
> - dim_update_sample(rq->calls,
> - u64_stats_read(&rq->stats.packets),
> - u64_stats_read(&rq->stats.bytes),
> - &cur_sample);
> - u64_stats_update_end(&rq->stats.syncp);
> + do {
> + start = u64_stats_fetch_begin(&rq->stats.syncp);
> + dim_update_sample(rq->calls,
> + u64_stats_read(&rq->stats.packets),
> + u64_stats_read(&rq->stats.bytes),
> + &cur_sample);
> + } while (u64_stats_fetch_retry(&rq->stats.syncp, start));
>
> net_dim(&rq->dim, cur_sample);
> rq->packets_in_napi = 0;
> --
> 2.9.4
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] virtio_net: Use u64_stats_fetch_begin() for stats fetch
2024-06-19 2:55 [PATCH] virtio_net: Use u64_stats_fetch_begin() for stats fetch Li RongQing
2024-06-19 7:42 ` Heng Qi
@ 2024-06-19 8:06 ` Jiri Pirko
2024-06-19 8:34 ` Michael S. Tsirkin
` (3 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Jiri Pirko @ 2024-06-19 8:06 UTC (permalink / raw)
To: Li RongQing
Cc: mst, jasowang, xuanzhuo, eperezma, hengqi, virtualization, netdev
Wed, Jun 19, 2024 at 04:55:29AM CEST, lirongqing@baidu.com wrote:
>This place is fetching the stats, so u64_stats_fetch_begin
>and u64_stats_fetch_retry should be used
>
>Fixes: 6208799553a8 ("virtio-net: support rx netdim")
>Signed-off-by: Li RongQing <lirongqing@baidu.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] virtio_net: Use u64_stats_fetch_begin() for stats fetch
2024-06-19 2:55 [PATCH] virtio_net: Use u64_stats_fetch_begin() for stats fetch Li RongQing
2024-06-19 7:42 ` Heng Qi
2024-06-19 8:06 ` Jiri Pirko
@ 2024-06-19 8:34 ` Michael S. Tsirkin
2024-06-20 0:33 ` Jason Wang
` (2 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Michael S. Tsirkin @ 2024-06-19 8:34 UTC (permalink / raw)
To: Li RongQing; +Cc: jasowang, xuanzhuo, eperezma, hengqi, virtualization, netdev
On Wed, Jun 19, 2024 at 10:55:29AM +0800, Li RongQing wrote:
> This place is fetching the stats, so u64_stats_fetch_begin
> and u64_stats_fetch_retry should be used
>
> Fixes: 6208799553a8 ("virtio-net: support rx netdim")
> Signed-off-by: Li RongQing <lirongqing@baidu.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
> ---
> drivers/net/virtio_net.c | 14 ++++++++------
> 1 file changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index 61a57d1..b669e73 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -2332,16 +2332,18 @@ static void virtnet_poll_cleantx(struct receive_queue *rq)
> static void virtnet_rx_dim_update(struct virtnet_info *vi, struct receive_queue *rq)
> {
> struct dim_sample cur_sample = {};
> + unsigned int start;
>
> if (!rq->packets_in_napi)
> return;
>
> - u64_stats_update_begin(&rq->stats.syncp);
> - dim_update_sample(rq->calls,
> - u64_stats_read(&rq->stats.packets),
> - u64_stats_read(&rq->stats.bytes),
> - &cur_sample);
> - u64_stats_update_end(&rq->stats.syncp);
> + do {
> + start = u64_stats_fetch_begin(&rq->stats.syncp);
> + dim_update_sample(rq->calls,
> + u64_stats_read(&rq->stats.packets),
> + u64_stats_read(&rq->stats.bytes),
> + &cur_sample);
> + } while (u64_stats_fetch_retry(&rq->stats.syncp, start));
>
> net_dim(&rq->dim, cur_sample);
> rq->packets_in_napi = 0;
> --
> 2.9.4
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] virtio_net: Use u64_stats_fetch_begin() for stats fetch
2024-06-19 2:55 [PATCH] virtio_net: Use u64_stats_fetch_begin() for stats fetch Li RongQing
` (2 preceding siblings ...)
2024-06-19 8:34 ` Michael S. Tsirkin
@ 2024-06-20 0:33 ` Jason Wang
2024-06-20 14:09 ` Jakub Kicinski
2024-07-09 12:45 ` Michael S. Tsirkin
5 siblings, 0 replies; 9+ messages in thread
From: Jason Wang @ 2024-06-20 0:33 UTC (permalink / raw)
To: Li RongQing; +Cc: mst, xuanzhuo, eperezma, hengqi, virtualization, netdev
On Wed, Jun 19, 2024 at 10:56 AM Li RongQing <lirongqing@baidu.com> wrote:
>
> This place is fetching the stats, so u64_stats_fetch_begin
> and u64_stats_fetch_retry should be used
>
> Fixes: 6208799553a8 ("virtio-net: support rx netdim")
> Signed-off-by: Li RongQing <lirongqing@baidu.com>
Acked-by: Jason Wang <jasowang@redhat.com>
Thanks
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] virtio_net: Use u64_stats_fetch_begin() for stats fetch
2024-06-19 2:55 [PATCH] virtio_net: Use u64_stats_fetch_begin() for stats fetch Li RongQing
` (3 preceding siblings ...)
2024-06-20 0:33 ` Jason Wang
@ 2024-06-20 14:09 ` Jakub Kicinski
2024-06-20 15:52 ` Michael S. Tsirkin
2024-06-21 6:20 ` [????] " Li,Rongqing
2024-07-09 12:45 ` Michael S. Tsirkin
5 siblings, 2 replies; 9+ messages in thread
From: Jakub Kicinski @ 2024-06-20 14:09 UTC (permalink / raw)
To: Li RongQing
Cc: mst, jasowang, xuanzhuo, eperezma, hengqi, virtualization, netdev
On Wed, 19 Jun 2024 10:55:29 +0800 Li RongQing wrote:
> This place is fetching the stats, so u64_stats_fetch_begin
> and u64_stats_fetch_retry should be used
>
> Fixes: 6208799553a8 ("virtio-net: support rx netdim")
> Signed-off-by: Li RongQing <lirongqing@baidu.com>
> ---
> drivers/net/virtio_net.c | 14 ++++++++------
> 1 file changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index 61a57d1..b669e73 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -2332,16 +2332,18 @@ static void virtnet_poll_cleantx(struct receive_queue *rq)
> static void virtnet_rx_dim_update(struct virtnet_info *vi, struct receive_queue *rq)
> {
> struct dim_sample cur_sample = {};
> + unsigned int start;
>
> if (!rq->packets_in_napi)
> return;
>
> - u64_stats_update_begin(&rq->stats.syncp);
> - dim_update_sample(rq->calls,
> - u64_stats_read(&rq->stats.packets),
> - u64_stats_read(&rq->stats.bytes),
> - &cur_sample);
> - u64_stats_update_end(&rq->stats.syncp);
> + do {
> + start = u64_stats_fetch_begin(&rq->stats.syncp);
> + dim_update_sample(rq->calls,
> + u64_stats_read(&rq->stats.packets),
> + u64_stats_read(&rq->stats.bytes),
> + &cur_sample);
> + } while (u64_stats_fetch_retry(&rq->stats.syncp, start));
Did you by any chance use an automated tool of any sort to find this
issue or generate the fix?
I don't think this is actually necessary here, you're in the same
context as the updater of the stats, you don't need any protection.
You can remove u64_stats_update_begin() / end() (in net-next, there's
no bug).
I won't comment on implications of calling dim_update_sample() in
a loop.
Please make sure you answer my "did you use a tool" question, I'm
really curious.
--
pw-bot: cr
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] virtio_net: Use u64_stats_fetch_begin() for stats fetch
2024-06-20 14:09 ` Jakub Kicinski
@ 2024-06-20 15:52 ` Michael S. Tsirkin
2024-06-21 6:20 ` [????] " Li,Rongqing
1 sibling, 0 replies; 9+ messages in thread
From: Michael S. Tsirkin @ 2024-06-20 15:52 UTC (permalink / raw)
To: Jakub Kicinski
Cc: Li RongQing, jasowang, xuanzhuo, eperezma, hengqi, virtualization,
netdev
On Thu, Jun 20, 2024 at 07:09:08AM -0700, Jakub Kicinski wrote:
> On Wed, 19 Jun 2024 10:55:29 +0800 Li RongQing wrote:
> > This place is fetching the stats, so u64_stats_fetch_begin
> > and u64_stats_fetch_retry should be used
> >
> > Fixes: 6208799553a8 ("virtio-net: support rx netdim")
> > Signed-off-by: Li RongQing <lirongqing@baidu.com>
> > ---
> > drivers/net/virtio_net.c | 14 ++++++++------
> > 1 file changed, 8 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> > index 61a57d1..b669e73 100644
> > --- a/drivers/net/virtio_net.c
> > +++ b/drivers/net/virtio_net.c
> > @@ -2332,16 +2332,18 @@ static void virtnet_poll_cleantx(struct receive_queue *rq)
> > static void virtnet_rx_dim_update(struct virtnet_info *vi, struct receive_queue *rq)
> > {
> > struct dim_sample cur_sample = {};
> > + unsigned int start;
> >
> > if (!rq->packets_in_napi)
> > return;
> >
> > - u64_stats_update_begin(&rq->stats.syncp);
> > - dim_update_sample(rq->calls,
> > - u64_stats_read(&rq->stats.packets),
> > - u64_stats_read(&rq->stats.bytes),
> > - &cur_sample);
> > - u64_stats_update_end(&rq->stats.syncp);
> > + do {
> > + start = u64_stats_fetch_begin(&rq->stats.syncp);
> > + dim_update_sample(rq->calls,
> > + u64_stats_read(&rq->stats.packets),
> > + u64_stats_read(&rq->stats.bytes),
> > + &cur_sample);
> > + } while (u64_stats_fetch_retry(&rq->stats.syncp, start));
>
> Did you by any chance use an automated tool of any sort to find this
> issue or generate the fix?
>
> I don't think this is actually necessary here, you're in the same
> context as the updater of the stats, you don't need any protection.
> You can remove u64_stats_update_begin() / end() (in net-next, there's
> no bug).
>
> I won't comment on implications of calling dim_update_sample() in
> a loop.
I didn't realize there are any - it seems to be idempotent, no?
> Please make sure you answer my "did you use a tool" question, I'm
> really curious.
> --
> pw-bot: cr
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: [????] Re: [PATCH] virtio_net: Use u64_stats_fetch_begin() for stats fetch
2024-06-20 14:09 ` Jakub Kicinski
2024-06-20 15:52 ` Michael S. Tsirkin
@ 2024-06-21 6:20 ` Li,Rongqing
1 sibling, 0 replies; 9+ messages in thread
From: Li,Rongqing @ 2024-06-21 6:20 UTC (permalink / raw)
To: Jakub Kicinski
Cc: mst@redhat.com, jasowang@redhat.com, xuanzhuo@linux.alibaba.com,
eperezma@redhat.com, hengqi@linux.alibaba.com,
virtualization@lists.linux.dev, netdev@vger.kernel.org
> Did you by any chance use an automated tool of any sort to find this issue or
> generate the fix?
>
> I don't think this is actually necessary here, you're in the same context as the
> updater of the stats, you don't need any protection.
> You can remove u64_stats_update_begin() / end() (in net-next, there's no bug).
>
> I won't comment on implications of calling dim_update_sample() in a loop.
>
> Please make sure you answer my "did you use a tool" question, I'm really
> curious.
I have no tool, I find this when I investigating a DIM related issue.
Thanks
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] virtio_net: Use u64_stats_fetch_begin() for stats fetch
2024-06-19 2:55 [PATCH] virtio_net: Use u64_stats_fetch_begin() for stats fetch Li RongQing
` (4 preceding siblings ...)
2024-06-20 14:09 ` Jakub Kicinski
@ 2024-07-09 12:45 ` Michael S. Tsirkin
5 siblings, 0 replies; 9+ messages in thread
From: Michael S. Tsirkin @ 2024-07-09 12:45 UTC (permalink / raw)
To: Li RongQing; +Cc: jasowang, xuanzhuo, eperezma, hengqi, virtualization, netdev
On Wed, Jun 19, 2024 at 10:55:29AM +0800, Li RongQing wrote:
> This place is fetching the stats, so u64_stats_fetch_begin
> and u64_stats_fetch_retry should be used
>
> Fixes: 6208799553a8 ("virtio-net: support rx netdim")
> Signed-off-by: Li RongQing <lirongqing@baidu.com>
So I dropped this from my tree, if you think it's
still necessary, pls resubmit to net-next.
Thanks!
> ---
> drivers/net/virtio_net.c | 14 ++++++++------
> 1 file changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index 61a57d1..b669e73 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -2332,16 +2332,18 @@ static void virtnet_poll_cleantx(struct receive_queue *rq)
> static void virtnet_rx_dim_update(struct virtnet_info *vi, struct receive_queue *rq)
> {
> struct dim_sample cur_sample = {};
> + unsigned int start;
>
> if (!rq->packets_in_napi)
> return;
>
> - u64_stats_update_begin(&rq->stats.syncp);
> - dim_update_sample(rq->calls,
> - u64_stats_read(&rq->stats.packets),
> - u64_stats_read(&rq->stats.bytes),
> - &cur_sample);
> - u64_stats_update_end(&rq->stats.syncp);
> + do {
> + start = u64_stats_fetch_begin(&rq->stats.syncp);
> + dim_update_sample(rq->calls,
> + u64_stats_read(&rq->stats.packets),
> + u64_stats_read(&rq->stats.bytes),
> + &cur_sample);
> + } while (u64_stats_fetch_retry(&rq->stats.syncp, start));
>
> net_dim(&rq->dim, cur_sample);
> rq->packets_in_napi = 0;
> --
> 2.9.4
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2024-07-09 12:45 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-19 2:55 [PATCH] virtio_net: Use u64_stats_fetch_begin() for stats fetch Li RongQing
2024-06-19 7:42 ` Heng Qi
2024-06-19 8:06 ` Jiri Pirko
2024-06-19 8:34 ` Michael S. Tsirkin
2024-06-20 0:33 ` Jason Wang
2024-06-20 14:09 ` Jakub Kicinski
2024-06-20 15:52 ` Michael S. Tsirkin
2024-06-21 6:20 ` [????] " Li,Rongqing
2024-07-09 12:45 ` Michael S. Tsirkin
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).