From patchwork Wed May 19 11:47:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xuan Zhuo X-Patchwork-Id: 12267057 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44F0DC433ED for ; Wed, 19 May 2021 11:48:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1D34B611BD for ; Wed, 19 May 2021 11:48:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243918AbhESLtU (ORCPT ); Wed, 19 May 2021 07:49:20 -0400 Received: from out30-131.freemail.mail.aliyun.com ([115.124.30.131]:40388 "EHLO out30-131.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235384AbhESLtT (ORCPT ); Wed, 19 May 2021 07:49:19 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R931e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04400;MF=xuanzhuo@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0UZPQget_1621424877; Received: from localhost(mailfrom:xuanzhuo@linux.alibaba.com fp:SMTPD_---0UZPQget_1621424877) by smtp.aliyun-inc.com(127.0.0.1); Wed, 19 May 2021 19:47:57 +0800 From: Xuan Zhuo To: virtualization@lists.linux-foundation.org Cc: "Michael S. Tsirkin" , Jason Wang , "David S. Miller" , Jakub Kicinski , netdev@vger.kernel.org Subject: [PATCH] virtio: Introduce a new kick interface virtqueue_kick_try() Date: Wed, 19 May 2021 19:47:57 +0800 Message-Id: <20210519114757.6143-1-xuanzhuo@linux.alibaba.com> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org 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 Acked-by: Jason Wang --- 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. + */ +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);