From: "Michael S. Tsirkin" <mst@redhat.com>
To: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Cc: Jakub Kicinski <kuba@kernel.org>,
virtualization@lists.linux-foundation.org,
"David S. Miller" <davem@davemloft.net>,
netdev@vger.kernel.org
Subject: Re: [PATCH] virtio: Introduce a new kick interface virtqueue_kick_try()
Date: Tue, 19 Oct 2021 06:37:00 -0400 [thread overview]
Message-ID: <20211019063009-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <1634631199.0198228-1-xuanzhuo@linux.alibaba.com>
On Tue, Oct 19, 2021 at 04:13:19PM +0800, Xuan Zhuo wrote:
> On Mon, 31 May 2021 14:34:16 +0800, Jason Wang <jasowang@redhat.com> wrote:
> >
> > ÔÚ 2021/5/19 ÏÂÎç7:47, Xuan Zhuo дµÀ:
> > > Unlike virtqueue_kick(), virtqueue_kick_try() returns true only when the
> > > kick is successful. In virtio-net, we want to count the number of kicks.
> > > So we need an interface that can perceive whether the kick is actually
> > > executed.
> > >
> > > Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> >
> >
> > Acked-by: Jason Wang <jasowang@redhat.com>
>
> Hi, this patch seems to have not been merged, is there something wrong with me?
>
> Thanks.
The commit log does not make it clear, but this is just
code refactoring. Pls make it clearer in the log.
Also, if we add a new API like this as a cleanup,
it needs to be documented much better.
> >
> > Thanks
> >
> >
> > > ---
> > > drivers/net/virtio_net.c | 8 ++++----
> > > drivers/virtio/virtio_ring.c | 20 ++++++++++++++++++++
> > > include/linux/virtio.h | 2 ++
> > > 3 files changed, 26 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> > > index 9b6a4a875c55..167697030cb6 100644
> > > --- a/drivers/net/virtio_net.c
> > > +++ b/drivers/net/virtio_net.c
> > > @@ -617,7 +617,7 @@ static int virtnet_xdp_xmit(struct net_device *dev,
> > > ret = nxmit;
> > >
> > > if (flags & XDP_XMIT_FLUSH) {
> > > - if (virtqueue_kick_prepare(sq->vq) && virtqueue_notify(sq->vq))
> > > + if (virtqueue_kick_try(sq->vq))
> > > kicks = 1;
> > > }
> > > out:
> > > @@ -1325,7 +1325,7 @@ static bool try_fill_recv(struct virtnet_info *vi, struct receive_queue *rq,
> > > if (err)
> > > break;
> > > } while (rq->vq->num_free);
> > > - if (virtqueue_kick_prepare(rq->vq) && virtqueue_notify(rq->vq)) {
> > > + if (virtqueue_kick_try(rq->vq)) {
> > > unsigned long flags;
> > >
> > > flags = u64_stats_update_begin_irqsave(&rq->stats.syncp);
> > > @@ -1533,7 +1533,7 @@ static int virtnet_poll(struct napi_struct *napi, int budget)
> > >
> > > if (xdp_xmit & VIRTIO_XDP_TX) {
> > > sq = virtnet_xdp_get_sq(vi);
> > > - if (virtqueue_kick_prepare(sq->vq) && virtqueue_notify(sq->vq)) {
> > > + if (virtqueue_kick_try(sq->vq)) {
> > > u64_stats_update_begin(&sq->stats.syncp);
> > > sq->stats.kicks++;
> > > u64_stats_update_end(&sq->stats.syncp);
> > > @@ -1710,7 +1710,7 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)
> > > }
> > >
> > > if (kick || netif_xmit_stopped(txq)) {
> > > - if (virtqueue_kick_prepare(sq->vq) && virtqueue_notify(sq->vq)) {
> > > + if (virtqueue_kick_try(sq->vq)) {
> > > u64_stats_update_begin(&sq->stats.syncp);
> > > sq->stats.kicks++;
> > > u64_stats_update_end(&sq->stats.syncp);
> > > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> > > index 71e16b53e9c1..1462be756875 100644
> > > --- a/drivers/virtio/virtio_ring.c
> > > +++ b/drivers/virtio/virtio_ring.c
> > > @@ -1874,6 +1874,26 @@ bool virtqueue_kick(struct virtqueue *vq)
> > > }
> > > EXPORT_SYMBOL_GPL(virtqueue_kick);
> > >
> > > +/**
> > > + * virtqueue_kick_try - try update after add_buf
> > > + * @vq: the struct virtqueue
> > > + *
> > > + * After one or more virtqueue_add_* calls, invoke this to kick
> > > + * the other side.
> > > + *
> > > + * Caller must ensure we don't call this with other virtqueue
> > > + * operations at the same time (except where noted).
> > > + *
> > > + * Returns true if kick success, otherwise false.
on a successful kick?
> > > + */
I don't really understand what this is doing, the comment
doesn't seem to explain. Try implies it might fail to update.
virtqueue_kick seems to be documented the same:
* Returns false if kick failed, otherwise true.
> > > +bool virtqueue_kick_try(struct virtqueue *vq)
> > > +{
> > > + if (virtqueue_kick_prepare(vq) && virtqueue_notify(vq))
> > > + return true;
> > > + return false;
> > > +}
> > > +EXPORT_SYMBOL_GPL(virtqueue_kick_try);
> > > +
> > > /**
> > > * virtqueue_get_buf - get the next used buffer
> > > * @_vq: the struct virtqueue we're talking about.
> > > diff --git a/include/linux/virtio.h b/include/linux/virtio.h
> > > index b1894e0323fa..45cd6a0af24d 100644
> > > --- a/include/linux/virtio.h
> > > +++ b/include/linux/virtio.h
> > > @@ -59,6 +59,8 @@ int virtqueue_add_sgs(struct virtqueue *vq,
> > >
> > > bool virtqueue_kick(struct virtqueue *vq);
> > >
> > > +bool virtqueue_kick_try(struct virtqueue *vq);
> > > +
> > > bool virtqueue_kick_prepare(struct virtqueue *vq);
> > >
> > > bool virtqueue_notify(struct virtqueue *vq);
> >
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
WARNING: multiple messages have this Message-ID (diff)
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Cc: Jason Wang <jasowang@redhat.com>,
"David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
netdev@vger.kernel.org,
virtualization@lists.linux-foundation.org
Subject: Re: [PATCH] virtio: Introduce a new kick interface virtqueue_kick_try()
Date: Tue, 19 Oct 2021 06:37:00 -0400 [thread overview]
Message-ID: <20211019063009-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <1634631199.0198228-1-xuanzhuo@linux.alibaba.com>
On Tue, Oct 19, 2021 at 04:13:19PM +0800, Xuan Zhuo wrote:
> On Mon, 31 May 2021 14:34:16 +0800, Jason Wang <jasowang@redhat.com> wrote:
> >
> > ÔÚ 2021/5/19 ÏÂÎç7:47, Xuan Zhuo дµÀ:
> > > Unlike virtqueue_kick(), virtqueue_kick_try() returns true only when the
> > > kick is successful. In virtio-net, we want to count the number of kicks.
> > > So we need an interface that can perceive whether the kick is actually
> > > executed.
> > >
> > > Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> >
> >
> > Acked-by: Jason Wang <jasowang@redhat.com>
>
> Hi, this patch seems to have not been merged, is there something wrong with me?
>
> Thanks.
The commit log does not make it clear, but this is just
code refactoring. Pls make it clearer in the log.
Also, if we add a new API like this as a cleanup,
it needs to be documented much better.
> >
> > Thanks
> >
> >
> > > ---
> > > drivers/net/virtio_net.c | 8 ++++----
> > > drivers/virtio/virtio_ring.c | 20 ++++++++++++++++++++
> > > include/linux/virtio.h | 2 ++
> > > 3 files changed, 26 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> > > index 9b6a4a875c55..167697030cb6 100644
> > > --- a/drivers/net/virtio_net.c
> > > +++ b/drivers/net/virtio_net.c
> > > @@ -617,7 +617,7 @@ static int virtnet_xdp_xmit(struct net_device *dev,
> > > ret = nxmit;
> > >
> > > if (flags & XDP_XMIT_FLUSH) {
> > > - if (virtqueue_kick_prepare(sq->vq) && virtqueue_notify(sq->vq))
> > > + if (virtqueue_kick_try(sq->vq))
> > > kicks = 1;
> > > }
> > > out:
> > > @@ -1325,7 +1325,7 @@ static bool try_fill_recv(struct virtnet_info *vi, struct receive_queue *rq,
> > > if (err)
> > > break;
> > > } while (rq->vq->num_free);
> > > - if (virtqueue_kick_prepare(rq->vq) && virtqueue_notify(rq->vq)) {
> > > + if (virtqueue_kick_try(rq->vq)) {
> > > unsigned long flags;
> > >
> > > flags = u64_stats_update_begin_irqsave(&rq->stats.syncp);
> > > @@ -1533,7 +1533,7 @@ static int virtnet_poll(struct napi_struct *napi, int budget)
> > >
> > > if (xdp_xmit & VIRTIO_XDP_TX) {
> > > sq = virtnet_xdp_get_sq(vi);
> > > - if (virtqueue_kick_prepare(sq->vq) && virtqueue_notify(sq->vq)) {
> > > + if (virtqueue_kick_try(sq->vq)) {
> > > u64_stats_update_begin(&sq->stats.syncp);
> > > sq->stats.kicks++;
> > > u64_stats_update_end(&sq->stats.syncp);
> > > @@ -1710,7 +1710,7 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)
> > > }
> > >
> > > if (kick || netif_xmit_stopped(txq)) {
> > > - if (virtqueue_kick_prepare(sq->vq) && virtqueue_notify(sq->vq)) {
> > > + if (virtqueue_kick_try(sq->vq)) {
> > > u64_stats_update_begin(&sq->stats.syncp);
> > > sq->stats.kicks++;
> > > u64_stats_update_end(&sq->stats.syncp);
> > > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> > > index 71e16b53e9c1..1462be756875 100644
> > > --- a/drivers/virtio/virtio_ring.c
> > > +++ b/drivers/virtio/virtio_ring.c
> > > @@ -1874,6 +1874,26 @@ bool virtqueue_kick(struct virtqueue *vq)
> > > }
> > > EXPORT_SYMBOL_GPL(virtqueue_kick);
> > >
> > > +/**
> > > + * virtqueue_kick_try - try update after add_buf
> > > + * @vq: the struct virtqueue
> > > + *
> > > + * After one or more virtqueue_add_* calls, invoke this to kick
> > > + * the other side.
> > > + *
> > > + * Caller must ensure we don't call this with other virtqueue
> > > + * operations at the same time (except where noted).
> > > + *
> > > + * Returns true if kick success, otherwise false.
on a successful kick?
> > > + */
I don't really understand what this is doing, the comment
doesn't seem to explain. Try implies it might fail to update.
virtqueue_kick seems to be documented the same:
* Returns false if kick failed, otherwise true.
> > > +bool virtqueue_kick_try(struct virtqueue *vq)
> > > +{
> > > + if (virtqueue_kick_prepare(vq) && virtqueue_notify(vq))
> > > + return true;
> > > + return false;
> > > +}
> > > +EXPORT_SYMBOL_GPL(virtqueue_kick_try);
> > > +
> > > /**
> > > * virtqueue_get_buf - get the next used buffer
> > > * @_vq: the struct virtqueue we're talking about.
> > > diff --git a/include/linux/virtio.h b/include/linux/virtio.h
> > > index b1894e0323fa..45cd6a0af24d 100644
> > > --- a/include/linux/virtio.h
> > > +++ b/include/linux/virtio.h
> > > @@ -59,6 +59,8 @@ int virtqueue_add_sgs(struct virtqueue *vq,
> > >
> > > bool virtqueue_kick(struct virtqueue *vq);
> > >
> > > +bool virtqueue_kick_try(struct virtqueue *vq);
> > > +
> > > bool virtqueue_kick_prepare(struct virtqueue *vq);
> > >
> > > bool virtqueue_notify(struct virtqueue *vq);
> >
next prev parent reply other threads:[~2021-10-19 10:39 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-19 11:47 [PATCH] virtio: Introduce a new kick interface virtqueue_kick_try() Xuan Zhuo
2021-05-19 11:47 ` Xuan Zhuo
2021-05-19 12:44 ` Michael S. Tsirkin
2021-05-19 12:44 ` Michael S. Tsirkin
2021-05-19 13:14 ` Xuan Zhuo
2021-05-31 6:34 ` Jason Wang
2021-05-31 6:34 ` Jason Wang
2021-10-19 8:13 ` Xuan Zhuo
2021-10-19 10:37 ` Michael S. Tsirkin [this message]
2021-10-19 10:37 ` Michael S. Tsirkin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211019063009-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=davem@davemloft.net \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=virtualization@lists.linux-foundation.org \
--cc=xuanzhuo@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.