From patchwork Fri Aug 11 06:55:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heng Qi X-Patchwork-Id: 13350172 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF1371865 for ; Fri, 11 Aug 2023 06:55:20 +0000 (UTC) Received: from out30-113.freemail.mail.aliyun.com (out30-113.freemail.mail.aliyun.com [115.124.30.113]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A31E92717 for ; Thu, 10 Aug 2023 23:55:18 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R351e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046056;MF=hengqi@linux.alibaba.com;NM=1;PH=DS;RN=13;SR=0;TI=SMTPD_---0VpWGJDH_1691736914; Received: from localhost(mailfrom:hengqi@linux.alibaba.com fp:SMTPD_---0VpWGJDH_1691736914) by smtp.aliyun-inc.com; Fri, 11 Aug 2023 14:55:15 +0800 From: Heng Qi To: "Michael S . Tsirkin" , Jason Wang , netdev@vger.kernel.org, virtualization@lists.linux-foundation.org Cc: "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Xuan Zhuo Subject: [PATCH net-next 1/8] virtio-net: initially change the value of tx-frames Date: Fri, 11 Aug 2023 14:55:05 +0800 Message-Id: <20230811065512.22190-2-hengqi@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230811065512.22190-1-hengqi@linux.alibaba.com> References: <20230811065512.22190-1-hengqi@linux.alibaba.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org Background: 1. Commit 0c465be183c7 ("virtio_net: ethtool tx napi configuration") uses tx-frames to toggle napi_tx (0 off and 1 on) if notification coalescing is not supported. 2. Commit 31c03aef9bc2 ("virtio_net: enable napi_tx by default") enables napi_tx for all txqs by default. Status: When virtio-net supports notification coalescing, after initialization, tx-frames is 0 and napi_tx is true. Problem: 1. When the user only wants to set rx coalescing params using ethtool -C eth0 rx-usecs 10, or ethtool -Q eth0 queue_mask 0x1 -C rx-usecs 10, these cmds will carry tx-frames as 0, causing the napi_tx switching condition is satisfied. Then the user gets: netlink error: Device or resource busy. The same happens when trying to set rx-frames, adaptive_{rx, tx}. 2. When notification coalescing is not supported, switching napi_tx is a way to achieve coalescing. But now coalescing is supported, we don't need tx-frames to toggle napi_tx anymore. 3. The value of supported tx-frames cannot be set arbitrarily. When setting 0 and non-zero value, if the device is up, the user will always get EBUSY warning. Not intuitive. Result: When notification coalescing feature is negotiated, initially change the value of tx-frames to be consistent with napi_tx. Reported-by: Xiaoming Zhao Signed-off-by: Heng Qi --- drivers/net/virtio_net.c | 42 +++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 82f9b899b938..3b254f778e7e 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -4376,13 +4376,6 @@ static int virtnet_probe(struct virtio_device *vdev) dev->xdp_features |= NETDEV_XDP_ACT_RX_SG; } - if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_NOTF_COAL)) { - vi->intr_coal_rx.max_usecs = 0; - vi->intr_coal_tx.max_usecs = 0; - vi->intr_coal_tx.max_packets = 0; - vi->intr_coal_rx.max_packets = 0; - } - if (virtio_has_feature(vdev, VIRTIO_NET_F_HASH_REPORT)) vi->has_rss_hash_report = true; @@ -4457,6 +4450,41 @@ static int virtnet_probe(struct virtio_device *vdev) if (err) goto free; + if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_NOTF_COAL)) { + vi->intr_coal_rx.max_usecs = 0; + vi->intr_coal_tx.max_usecs = 0; + vi->intr_coal_rx.max_packets = 0; + + /* Why is this needed? + * If without this setting, consider that when VIRTIO_NET_F_NOTF_COAL is + * negotiated and napi_tx is initially true: when the user sets non tx-frames + * parameters, such as the following cmd or others, + * ethtool -C eth0 rx-usecs 10. + * Then + * 1. ethtool_set_coalesce() first calls virtnet_get_coalesce() to get + * the last parameters except rx-usecs. If tx-frames has never been set before, + * virtnet_get_coalesce() returns with tx-frames=0 in the parameters. + * 2. virtnet_set_coalesce() is then called, according to 1: + * ec->tx_max_coalesced_frames=0. Now napi_tx switching condition is met. + * 3. If the device is up, the user setting fails: + * "netlink error: Device or resource busy" + * This is not intuitive. Therefore, we keep napi_tx state consistent with + * tx-frames when VIRTIO_NET_F_NOTF_COAL is negotiated. This behavior is + * compatible with before. + */ + if (vi->sq[0].napi.weight) + vi->intr_coal_tx.max_packets = 1; + else + vi->intr_coal_tx.max_packets = 0; + } + + if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_VQ_NOTF_COAL)) { + /* The reason is the same as VIRTIO_NET_F_NOTF_COAL. */ + for (i = 0; i < vi->max_queue_pairs; i++) + if (vi->sq[i].napi.weight) + vi->sq[i].intr_coal.max_packets = 1; + } + #ifdef CONFIG_SYSFS if (vi->mergeable_rx_bufs) dev->sysfs_rx_queue_group = &virtio_net_mrg_rx_group; From patchwork Fri Aug 11 06:55:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heng Qi X-Patchwork-Id: 13350174 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A882B4406 for ; Fri, 11 Aug 2023 06:55:23 +0000 (UTC) Received: from out30-98.freemail.mail.aliyun.com (out30-98.freemail.mail.aliyun.com [115.124.30.98]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7D991FCF for ; Thu, 10 Aug 2023 23:55:22 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R111e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045168;MF=hengqi@linux.alibaba.com;NM=1;PH=DS;RN=14;SR=0;TI=SMTPD_---0VpWD-9a_1691736915; Received: from localhost(mailfrom:hengqi@linux.alibaba.com fp:SMTPD_---0VpWD-9a_1691736915) by smtp.aliyun-inc.com; Fri, 11 Aug 2023 14:55:16 +0800 From: Heng Qi To: "Michael S . Tsirkin" , Jason Wang , netdev@vger.kernel.org, virtualization@lists.linux-foundation.org Cc: "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Xuan Zhuo , Gavin Li Subject: [PATCH net-next 2/8] virtio-net: fix mismatch of getting txq tx-frames param Date: Fri, 11 Aug 2023 14:55:06 +0800 Message-Id: <20230811065512.22190-3-hengqi@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230811065512.22190-1-hengqi@linux.alibaba.com> References: <20230811065512.22190-1-hengqi@linux.alibaba.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org Now virtio-net allows switching napi_tx for each txq. Therefore, we get the corresponding tx-frames for virtnet_get_per_queue_coalesce(). Note: in virtnet_get_coalesce(), since different txqs may have different napi_tx values, the value of txq[0] is used as a representative. Fixes: 394bd87764b6 ("virtio_net: support per queue interrupt coalesce command") Cc: Gavin Li Signed-off-by: Heng Qi --- drivers/net/virtio_net.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 3b254f778e7e..b1b4038f06e3 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -3379,7 +3379,7 @@ static int virtnet_get_per_queue_coalesce(struct net_device *dev, } else { ec->rx_max_coalesced_frames = 1; - if (vi->sq[0].napi.weight) + if (vi->sq[queue].napi.weight) ec->tx_max_coalesced_frames = 1; } From patchwork Fri Aug 11 06:55:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heng Qi X-Patchwork-Id: 13350173 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 61F1720F3 for ; Fri, 11 Aug 2023 06:55:23 +0000 (UTC) Received: from out30-98.freemail.mail.aliyun.com (out30-98.freemail.mail.aliyun.com [115.124.30.98]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6FA5E7E for ; Thu, 10 Aug 2023 23:55:21 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R941e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046051;MF=hengqi@linux.alibaba.com;NM=1;PH=DS;RN=13;SR=0;TI=SMTPD_---0VpWHlIZ_1691736917; Received: from localhost(mailfrom:hengqi@linux.alibaba.com fp:SMTPD_---0VpWHlIZ_1691736917) by smtp.aliyun-inc.com; Fri, 11 Aug 2023 14:55:17 +0800 From: Heng Qi To: "Michael S . Tsirkin" , Jason Wang , netdev@vger.kernel.org, virtualization@lists.linux-foundation.org Cc: "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Xuan Zhuo Subject: [PATCH net-next 3/8] virtio-net: returns whether napi is complete Date: Fri, 11 Aug 2023 14:55:07 +0800 Message-Id: <20230811065512.22190-4-hengqi@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230811065512.22190-1-hengqi@linux.alibaba.com> References: <20230811065512.22190-1-hengqi@linux.alibaba.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org rx netdim needs to count the traffic during a complete napi process, and start updating and comparing samples to make decisions after the napi ends. Let virtqueue_napi_complete() return true if napi is done, otherwise vice versa. Signed-off-by: Heng Qi --- drivers/net/virtio_net.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index b1b4038f06e3..8f61783fd895 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -415,7 +415,7 @@ static void virtqueue_napi_schedule(struct napi_struct *napi, } } -static void virtqueue_napi_complete(struct napi_struct *napi, +static bool virtqueue_napi_complete(struct napi_struct *napi, struct virtqueue *vq, int processed) { int opaque; @@ -424,9 +424,13 @@ static void virtqueue_napi_complete(struct napi_struct *napi, if (napi_complete_done(napi, processed)) { if (unlikely(virtqueue_poll(vq, opaque))) virtqueue_napi_schedule(napi, vq); + else + return true; } else { virtqueue_disable_cb(vq); } + + return false; } static void skb_xmit_done(struct virtqueue *vq) From patchwork Fri Aug 11 06:55:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heng Qi X-Patchwork-Id: 13350175 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B3F25230 for ; Fri, 11 Aug 2023 06:55:24 +0000 (UTC) Received: from out30-98.freemail.mail.aliyun.com (out30-98.freemail.mail.aliyun.com [115.124.30.98]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CFF1E7E for ; Thu, 10 Aug 2023 23:55:23 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R651e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046050;MF=hengqi@linux.alibaba.com;NM=1;PH=DS;RN=13;SR=0;TI=SMTPD_---0VpWHlJ2_1691736918; Received: from localhost(mailfrom:hengqi@linux.alibaba.com fp:SMTPD_---0VpWHlJ2_1691736918) by smtp.aliyun-inc.com; Fri, 11 Aug 2023 14:55:19 +0800 From: Heng Qi To: "Michael S . Tsirkin" , Jason Wang , netdev@vger.kernel.org, virtualization@lists.linux-foundation.org Cc: "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Xuan Zhuo Subject: [PATCH net-next 4/8] virtio-net: separate rx/tx coalescing moderation cmds Date: Fri, 11 Aug 2023 14:55:08 +0800 Message-Id: <20230811065512.22190-5-hengqi@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230811065512.22190-1-hengqi@linux.alibaba.com> References: <20230811065512.22190-1-hengqi@linux.alibaba.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org This patch separates the rx and tx global coalescing moderation commands to support netdim switches in subsequent patches. Signed-off-by: Heng Qi --- drivers/net/virtio_net.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 8f61783fd895..9d97b20f5da7 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -3159,10 +3159,10 @@ static int virtnet_get_link_ksettings(struct net_device *dev, return 0; } -static int virtnet_send_notf_coal_cmds(struct virtnet_info *vi, - struct ethtool_coalesce *ec) +static int virtnet_send_tx_notf_coal_cmds(struct virtnet_info *vi, + struct ethtool_coalesce *ec) { - struct scatterlist sgs_tx, sgs_rx; + struct scatterlist sgs_tx; vi->ctrl->coal_tx.tx_usecs = cpu_to_le32(ec->tx_coalesce_usecs); vi->ctrl->coal_tx.tx_max_packets = cpu_to_le32(ec->tx_max_coalesced_frames); @@ -3177,6 +3177,14 @@ static int virtnet_send_notf_coal_cmds(struct virtnet_info *vi, vi->intr_coal_tx.max_usecs = ec->tx_coalesce_usecs; vi->intr_coal_tx.max_packets = ec->tx_max_coalesced_frames; + return 0; +} + +static int virtnet_send_rx_notf_coal_cmds(struct virtnet_info *vi, + struct ethtool_coalesce *ec) +{ + struct scatterlist sgs_rx; + vi->ctrl->coal_rx.rx_usecs = cpu_to_le32(ec->rx_coalesce_usecs); vi->ctrl->coal_rx.rx_max_packets = cpu_to_le32(ec->rx_max_coalesced_frames); sg_init_one(&sgs_rx, &vi->ctrl->coal_rx, sizeof(vi->ctrl->coal_rx)); @@ -3193,6 +3201,22 @@ static int virtnet_send_notf_coal_cmds(struct virtnet_info *vi, return 0; } +static int virtnet_send_notf_coal_cmds(struct virtnet_info *vi, + struct ethtool_coalesce *ec) +{ + int err; + + err = virtnet_send_tx_notf_coal_cmds(vi, ec); + if (err) + return err; + + err = virtnet_send_rx_notf_coal_cmds(vi, ec); + if (err) + return err; + + return 0; +} + static int virtnet_send_ctrl_coal_vq_cmd(struct virtnet_info *vi, u16 vqn, u32 max_usecs, u32 max_packets) { From patchwork Fri Aug 11 06:55:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heng Qi X-Patchwork-Id: 13350176 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A05EE5230 for ; Fri, 11 Aug 2023 06:55:25 +0000 (UTC) Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89CC626B2 for ; Thu, 10 Aug 2023 23:55:24 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R791e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045170;MF=hengqi@linux.alibaba.com;NM=1;PH=DS;RN=13;SR=0;TI=SMTPD_---0VpWEtCm_1691736919; Received: from localhost(mailfrom:hengqi@linux.alibaba.com fp:SMTPD_---0VpWEtCm_1691736919) by smtp.aliyun-inc.com; Fri, 11 Aug 2023 14:55:20 +0800 From: Heng Qi To: "Michael S . Tsirkin" , Jason Wang , netdev@vger.kernel.org, virtualization@lists.linux-foundation.org Cc: "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Xuan Zhuo Subject: [PATCH net-next 5/8] virtio-net: extract virtqueue coalescig cmd for reuse Date: Fri, 11 Aug 2023 14:55:09 +0800 Message-Id: <20230811065512.22190-6-hengqi@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230811065512.22190-1-hengqi@linux.alibaba.com> References: <20230811065512.22190-1-hengqi@linux.alibaba.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org Extract commands to set virtqueue coalescing parameters for reuse by ethtool -Q and netdim. Signed-off-by: Heng Qi --- drivers/net/virtio_net.c | 54 +++++++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 9d97b20f5da7..0318113bd8c2 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -3235,6 +3235,42 @@ static int virtnet_send_ctrl_coal_vq_cmd(struct virtnet_info *vi, return 0; } +static int virtnet_send_tx_notf_coal_vq_cmd(struct virtnet_info *vi, + u16 queue, u32 max_usecs, + u32 max_packets) +{ + int err; + + err = virtnet_send_ctrl_coal_vq_cmd(vi, txq2vq(queue), + max_usecs, max_packets); + if (err) + return err; + + /* Save parameters */ + vi->sq[queue].intr_coal.max_usecs = max_usecs; + vi->sq[queue].intr_coal.max_packets = max_packets; + + return 0; +} + +static int virtnet_send_rx_notf_coal_vq_cmd(struct virtnet_info *vi, + u16 queue, u32 max_usecs, + u32 max_packets) +{ + int err; + + err = virtnet_send_ctrl_coal_vq_cmd(vi, rxq2vq(queue), + max_usecs, max_packets); + if (err) + return err; + + /* Save parameters */ + vi->rq[queue].intr_coal.max_usecs = max_usecs; + vi->rq[queue].intr_coal.max_packets = max_packets; + + return 0; +} + static int virtnet_send_notf_coal_vq_cmds(struct virtnet_info *vi, struct ethtool_coalesce *ec, u16 queue) @@ -3242,25 +3278,19 @@ static int virtnet_send_notf_coal_vq_cmds(struct virtnet_info *vi, int err; if (ec->rx_coalesce_usecs || ec->rx_max_coalesced_frames) { - err = virtnet_send_ctrl_coal_vq_cmd(vi, rxq2vq(queue), - ec->rx_coalesce_usecs, - ec->rx_max_coalesced_frames); + err = virtnet_send_rx_notf_coal_vq_cmd(vi, queue, + ec->rx_coalesce_usecs, + ec->rx_max_coalesced_frames); if (err) return err; - /* Save parameters */ - vi->rq[queue].intr_coal.max_usecs = ec->rx_coalesce_usecs; - vi->rq[queue].intr_coal.max_packets = ec->rx_max_coalesced_frames; } if (ec->tx_coalesce_usecs || ec->tx_max_coalesced_frames) { - err = virtnet_send_ctrl_coal_vq_cmd(vi, txq2vq(queue), - ec->tx_coalesce_usecs, - ec->tx_max_coalesced_frames); + err = virtnet_send_tx_notf_coal_vq_cmd(vi, queue, + ec->tx_coalesce_usecs, + ec->tx_max_coalesced_frames); if (err) return err; - /* Save parameters */ - vi->sq[queue].intr_coal.max_usecs = ec->tx_coalesce_usecs; - vi->sq[queue].intr_coal.max_packets = ec->tx_max_coalesced_frames; } return 0; From patchwork Fri Aug 11 06:55:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heng Qi X-Patchwork-Id: 13350177 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 00D741872 for ; Fri, 11 Aug 2023 06:55:27 +0000 (UTC) Received: from out30-100.freemail.mail.aliyun.com (out30-100.freemail.mail.aliyun.com [115.124.30.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4E702127 for ; Thu, 10 Aug 2023 23:55:25 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R141e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046050;MF=hengqi@linux.alibaba.com;NM=1;PH=DS;RN=13;SR=0;TI=SMTPD_---0VpWEtDE_1691736920; Received: from localhost(mailfrom:hengqi@linux.alibaba.com fp:SMTPD_---0VpWEtDE_1691736920) by smtp.aliyun-inc.com; Fri, 11 Aug 2023 14:55:21 +0800 From: Heng Qi To: "Michael S . Tsirkin" , Jason Wang , netdev@vger.kernel.org, virtualization@lists.linux-foundation.org Cc: "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Xuan Zhuo Subject: [PATCH net-next 6/8] virtio-net: support rx netdim Date: Fri, 11 Aug 2023 14:55:10 +0800 Message-Id: <20230811065512.22190-7-hengqi@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230811065512.22190-1-hengqi@linux.alibaba.com> References: <20230811065512.22190-1-hengqi@linux.alibaba.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org By comparing the traffic information in the complete napi processes, let the virtio-net driver automatically adjust the coalescing moderation parameters of each receive queue. Signed-off-by: Heng Qi --- drivers/net/virtio_net.c | 124 +++++++++++++++++++++++++++++++++------ 1 file changed, 106 insertions(+), 18 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 0318113bd8c2..3fb801a7a785 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -168,8 +169,17 @@ struct receive_queue { struct virtnet_rq_stats stats; + /* The number of rx notifications */ + u16 calls; + + /* Is dynamic interrupt moderation enabled? */ + bool dim_enabled; + struct virtnet_interrupt_coalesce intr_coal; + /* Dynamic Iterrupt Moderation */ + struct dim dim; + /* Chain pages by the private ptr. */ struct page *pages; @@ -1927,6 +1937,7 @@ static void skb_recv_done(struct virtqueue *rvq) struct virtnet_info *vi = rvq->vdev->priv; struct receive_queue *rq = &vi->rq[vq2rxq(rvq)]; + rq->calls++; virtqueue_napi_schedule(&rq->napi, rvq); } @@ -2064,6 +2075,21 @@ static void virtnet_poll_cleantx(struct receive_queue *rq) } } +static void virtnet_rx_dim_work(struct work_struct *work); + +static void virtnet_rx_dim_update(struct virtnet_info *vi, struct receive_queue *rq) +{ + struct virtnet_rq_stats *stats = &rq->stats; + struct dim_sample cur_sample = {}; + + u64_stats_update_begin(&rq->stats.syncp); + dim_update_sample(rq->calls, stats->packets, + stats->bytes, &cur_sample); + u64_stats_update_end(&rq->stats.syncp); + + net_dim(&rq->dim, cur_sample); +} + static int virtnet_poll(struct napi_struct *napi, int budget) { struct receive_queue *rq = @@ -2072,6 +2098,7 @@ static int virtnet_poll(struct napi_struct *napi, int budget) struct send_queue *sq; unsigned int received; unsigned int xdp_xmit = 0; + bool napi_complete; virtnet_poll_cleantx(rq); @@ -2081,8 +2108,11 @@ static int virtnet_poll(struct napi_struct *napi, int budget) xdp_do_flush(); /* Out of packets? */ - if (received < budget) - virtqueue_napi_complete(napi, rq->vq, received); + if (received < budget) { + napi_complete = virtqueue_napi_complete(napi, rq->vq, received); + if (napi_complete && rq->dim_enabled) + virtnet_rx_dim_update(vi, rq); + } if (xdp_xmit & VIRTIO_XDP_TX) { sq = virtnet_xdp_get_sq(vi); @@ -2102,6 +2132,7 @@ static void virtnet_disable_queue_pair(struct virtnet_info *vi, int qp_index) virtnet_napi_tx_disable(&vi->sq[qp_index].napi); napi_disable(&vi->rq[qp_index].napi); xdp_rxq_info_unreg(&vi->rq[qp_index].xdp_rxq); + cancel_work_sync(&vi->rq[qp_index].dim.work); } static int virtnet_enable_queue_pair(struct virtnet_info *vi, int qp_index) @@ -2119,6 +2150,9 @@ static int virtnet_enable_queue_pair(struct virtnet_info *vi, int qp_index) if (err < 0) goto err_xdp_reg_mem_model; + INIT_WORK(&vi->rq[qp_index].dim.work, virtnet_rx_dim_work); + vi->rq[qp_index].dim.mode = DIM_CQ_PERIOD_MODE_START_FROM_EQE; + virtnet_napi_enable(vi->rq[qp_index].vq, &vi->rq[qp_index].napi); virtnet_napi_tx_enable(vi, vi->sq[qp_index].vq, &vi->sq[qp_index].napi); @@ -3183,20 +3217,37 @@ static int virtnet_send_tx_notf_coal_cmds(struct virtnet_info *vi, static int virtnet_send_rx_notf_coal_cmds(struct virtnet_info *vi, struct ethtool_coalesce *ec) { + bool rx_ctrl_dim_on = !!ec->use_adaptive_rx_coalesce; struct scatterlist sgs_rx; + int i; - vi->ctrl->coal_rx.rx_usecs = cpu_to_le32(ec->rx_coalesce_usecs); - vi->ctrl->coal_rx.rx_max_packets = cpu_to_le32(ec->rx_max_coalesced_frames); - sg_init_one(&sgs_rx, &vi->ctrl->coal_rx, sizeof(vi->ctrl->coal_rx)); - - if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_NOTF_COAL, - VIRTIO_NET_CTRL_NOTF_COAL_RX_SET, - &sgs_rx)) + if (rx_ctrl_dim_on && (ec->rx_coalesce_usecs != vi->intr_coal_rx.max_usecs || + ec->rx_max_coalesced_frames != vi->intr_coal_rx.max_packets)) return -EINVAL; - /* Save parameters */ - vi->intr_coal_rx.max_usecs = ec->rx_coalesce_usecs; - vi->intr_coal_rx.max_packets = ec->rx_max_coalesced_frames; + if (rx_ctrl_dim_on) { + if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_VQ_NOTF_COAL)) + for (i = 0; i < vi->max_queue_pairs; i++) + vi->rq[i].dim_enabled = true; + else + return -EOPNOTSUPP; + } else { + for (i = 0; i < vi->max_queue_pairs; i++) + vi->rq[i].dim_enabled = false; + + vi->ctrl->coal_rx.rx_usecs = cpu_to_le32(ec->rx_coalesce_usecs); + vi->ctrl->coal_rx.rx_max_packets = cpu_to_le32(ec->rx_max_coalesced_frames); + sg_init_one(&sgs_rx, &vi->ctrl->coal_rx, sizeof(vi->ctrl->coal_rx)); + + if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_NOTF_COAL, + VIRTIO_NET_CTRL_NOTF_COAL_RX_SET, + &sgs_rx)) + return -EINVAL; + + /* Save parameters */ + vi->intr_coal_rx.max_usecs = ec->rx_coalesce_usecs; + vi->intr_coal_rx.max_packets = ec->rx_max_coalesced_frames; + } return 0; } @@ -3275,14 +3326,28 @@ static int virtnet_send_notf_coal_vq_cmds(struct virtnet_info *vi, struct ethtool_coalesce *ec, u16 queue) { + bool rx_ctrl_dim_on; + u32 max_usecs, max_packets; int err; if (ec->rx_coalesce_usecs || ec->rx_max_coalesced_frames) { - err = virtnet_send_rx_notf_coal_vq_cmd(vi, queue, - ec->rx_coalesce_usecs, - ec->rx_max_coalesced_frames); - if (err) - return err; + rx_ctrl_dim_on = !!ec->use_adaptive_rx_coalesce; + max_usecs = vi->rq[queue].intr_coal.max_usecs; + max_packets = vi->rq[queue].intr_coal.max_packets; + if (rx_ctrl_dim_on && (ec->rx_coalesce_usecs != max_usecs || + ec->rx_max_coalesced_frames != max_packets)) + return -EINVAL; + + if (rx_ctrl_dim_on) { + vi->rq[queue].dim_enabled = true; + } else { + vi->rq[queue].dim_enabled = false; + err = virtnet_send_rx_notf_coal_vq_cmd(vi, queue, + ec->rx_coalesce_usecs, + ec->rx_max_coalesced_frames); + if (err) + return err; + } } if (ec->tx_coalesce_usecs || ec->tx_max_coalesced_frames) { @@ -3296,6 +3361,27 @@ static int virtnet_send_notf_coal_vq_cmds(struct virtnet_info *vi, return 0; } +static void virtnet_rx_dim_work(struct work_struct *work) +{ + struct dim *dim = container_of(work, struct dim, work); + struct receive_queue *rq = container_of(dim, + struct receive_queue, dim); + struct virtnet_info *vi = rq->vq->vdev->priv; + struct net_device *dev = vi->dev; + struct dim_cq_moder update_moder; + int qnum = rq - vi->rq, err; + + update_moder = net_dim_get_rx_moderation(dim->mode, dim->profile_ix); + err = virtnet_send_rx_notf_coal_vq_cmd(vi, qnum, + update_moder.usec, + update_moder.pkts); + if (err) + pr_debug("%s: Failed to send dim parameters on rxq%d\n", + dev->name, (int)(rq - vi->rq)); + + dim->state = DIM_START_MEASURE; +} + static int virtnet_coal_params_supported(struct ethtool_coalesce *ec) { /* usecs coalescing is supported only if VIRTIO_NET_F_NOTF_COAL @@ -3377,6 +3463,7 @@ static int virtnet_get_coalesce(struct net_device *dev, ec->tx_coalesce_usecs = vi->intr_coal_tx.max_usecs; ec->tx_max_coalesced_frames = vi->intr_coal_tx.max_packets; ec->rx_max_coalesced_frames = vi->intr_coal_rx.max_packets; + ec->use_adaptive_rx_coalesce = vi->rq[0].dim_enabled; } else { ec->rx_max_coalesced_frames = 1; @@ -3434,6 +3521,7 @@ static int virtnet_get_per_queue_coalesce(struct net_device *dev, ec->tx_coalesce_usecs = vi->sq[queue].intr_coal.max_usecs; ec->tx_max_coalesced_frames = vi->sq[queue].intr_coal.max_packets; ec->rx_max_coalesced_frames = vi->rq[queue].intr_coal.max_packets; + ec->use_adaptive_rx_coalesce = vi->rq[queue].dim_enabled; } else { ec->rx_max_coalesced_frames = 1; @@ -3559,7 +3647,7 @@ static int virtnet_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info) static const struct ethtool_ops virtnet_ethtool_ops = { .supported_coalesce_params = ETHTOOL_COALESCE_MAX_FRAMES | - ETHTOOL_COALESCE_USECS, + ETHTOOL_COALESCE_USECS | ETHTOOL_COALESCE_USE_ADAPTIVE_RX, .get_drvinfo = virtnet_get_drvinfo, .get_link = ethtool_op_get_link, .get_ringparam = virtnet_get_ringparam, From patchwork Fri Aug 11 06:55:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heng Qi X-Patchwork-Id: 13350179 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A3EA65675 for ; Fri, 11 Aug 2023 06:55:29 +0000 (UTC) Received: from out30-133.freemail.mail.aliyun.com (out30-133.freemail.mail.aliyun.com [115.124.30.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63FA31FCF for ; Thu, 10 Aug 2023 23:55:28 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R151e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046056;MF=hengqi@linux.alibaba.com;NM=1;PH=DS;RN=13;SR=0;TI=SMTPD_---0VpWDMKx_1691736922; Received: from localhost(mailfrom:hengqi@linux.alibaba.com fp:SMTPD_---0VpWDMKx_1691736922) by smtp.aliyun-inc.com; Fri, 11 Aug 2023 14:55:22 +0800 From: Heng Qi To: "Michael S . Tsirkin" , Jason Wang , netdev@vger.kernel.org, virtualization@lists.linux-foundation.org Cc: "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Xuan Zhuo Subject: [PATCH net-next 7/8] virtio-net: support tx netdim Date: Fri, 11 Aug 2023 14:55:11 +0800 Message-Id: <20230811065512.22190-8-hengqi@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230811065512.22190-1-hengqi@linux.alibaba.com> References: <20230811065512.22190-1-hengqi@linux.alibaba.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org Similar to rx netdim, this patch supports adaptive tx coalescing moderation for the virtio-net driver. Signed-off-by: Heng Qi --- drivers/net/virtio_net.c | 128 +++++++++++++++++++++++++++++++++------ 1 file changed, 108 insertions(+), 20 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 3fb801a7a785..df7705ca05f0 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -147,8 +147,17 @@ struct send_queue { struct virtnet_sq_stats stats; + /* The number of tx notifications */ + u16 calls; + + /* Is dynamic interrupt moderation enabled? */ + bool dim_enabled; + struct virtnet_interrupt_coalesce intr_coal; + /* Dynamic Iterrupt Moderation */ + struct dim dim; + struct napi_struct napi; /* Record whether sq is in reset state. */ @@ -443,19 +452,40 @@ static bool virtqueue_napi_complete(struct napi_struct *napi, return false; } +static void virtnet_tx_dim_work(struct work_struct *work); + +static void virtnet_tx_dim_update(struct virtnet_info *vi, struct send_queue *sq) +{ + struct virtnet_sq_stats *stats = &sq->stats; + struct dim_sample cur_sample = {}; + + u64_stats_update_begin(&sq->stats.syncp); + dim_update_sample(sq->calls, stats->packets, + stats->bytes, &cur_sample); + u64_stats_update_end(&sq->stats.syncp); + + net_dim(&sq->dim, cur_sample); +} + static void skb_xmit_done(struct virtqueue *vq) { struct virtnet_info *vi = vq->vdev->priv; - struct napi_struct *napi = &vi->sq[vq2txq(vq)].napi; + struct send_queue *sq = &vi->sq[vq2txq(vq)]; + struct napi_struct *napi = &sq->napi; + + sq->calls++; /* Suppress further interrupts. */ virtqueue_disable_cb(vq); - if (napi->weight) + if (napi->weight) { virtqueue_napi_schedule(napi, vq); - else + } else { + if (sq->dim_enabled) + virtnet_tx_dim_update(vi, sq); /* We were probably waiting for more output buffers. */ netif_wake_subqueue(vi->dev, vq2txq(vq)); + } } #define MRG_CTX_HEADER_SHIFT 22 @@ -2133,6 +2163,7 @@ static void virtnet_disable_queue_pair(struct virtnet_info *vi, int qp_index) napi_disable(&vi->rq[qp_index].napi); xdp_rxq_info_unreg(&vi->rq[qp_index].xdp_rxq); cancel_work_sync(&vi->rq[qp_index].dim.work); + cancel_work_sync(&vi->sq[qp_index].dim.work); } static int virtnet_enable_queue_pair(struct virtnet_info *vi, int qp_index) @@ -2152,6 +2183,8 @@ static int virtnet_enable_queue_pair(struct virtnet_info *vi, int qp_index) INIT_WORK(&vi->rq[qp_index].dim.work, virtnet_rx_dim_work); vi->rq[qp_index].dim.mode = DIM_CQ_PERIOD_MODE_START_FROM_EQE; + INIT_WORK(&vi->sq[qp_index].dim.work, virtnet_tx_dim_work); + vi->sq[qp_index].dim.mode = DIM_CQ_PERIOD_MODE_START_FROM_EQE; virtnet_napi_enable(vi->rq[qp_index].vq, &vi->rq[qp_index].napi); virtnet_napi_tx_enable(vi, vi->sq[qp_index].vq, &vi->sq[qp_index].napi); @@ -2232,6 +2265,9 @@ static int virtnet_poll_tx(struct napi_struct *napi, int budget) __netif_tx_unlock(txq); __napi_schedule(napi); } + } else { + if (sq->dim_enabled) + virtnet_tx_dim_update(vi, sq); } } @@ -3196,20 +3232,37 @@ static int virtnet_get_link_ksettings(struct net_device *dev, static int virtnet_send_tx_notf_coal_cmds(struct virtnet_info *vi, struct ethtool_coalesce *ec) { + bool tx_ctrl_dim_on = !!ec->use_adaptive_tx_coalesce; struct scatterlist sgs_tx; + int i; - vi->ctrl->coal_tx.tx_usecs = cpu_to_le32(ec->tx_coalesce_usecs); - vi->ctrl->coal_tx.tx_max_packets = cpu_to_le32(ec->tx_max_coalesced_frames); - sg_init_one(&sgs_tx, &vi->ctrl->coal_tx, sizeof(vi->ctrl->coal_tx)); - - if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_NOTF_COAL, - VIRTIO_NET_CTRL_NOTF_COAL_TX_SET, - &sgs_tx)) + if (tx_ctrl_dim_on && (ec->tx_coalesce_usecs != vi->intr_coal_tx.max_usecs || + ec->tx_max_coalesced_frames != vi->intr_coal_tx.max_packets)) return -EINVAL; - /* Save parameters */ - vi->intr_coal_tx.max_usecs = ec->tx_coalesce_usecs; - vi->intr_coal_tx.max_packets = ec->tx_max_coalesced_frames; + if (tx_ctrl_dim_on) { + if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_VQ_NOTF_COAL)) + for (i = 0; i < vi->max_queue_pairs; i++) + vi->sq[i].dim_enabled = true; + else + return -EOPNOTSUPP; + } else { + for (i = 0; i < vi->max_queue_pairs; i++) + vi->sq[i].dim_enabled = false; + + vi->ctrl->coal_tx.tx_usecs = cpu_to_le32(ec->tx_coalesce_usecs); + vi->ctrl->coal_tx.tx_max_packets = cpu_to_le32(ec->tx_max_coalesced_frames); + sg_init_one(&sgs_tx, &vi->ctrl->coal_tx, sizeof(vi->ctrl->coal_tx)); + + if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_NOTF_COAL, + VIRTIO_NET_CTRL_NOTF_COAL_TX_SET, + &sgs_tx)) + return -EINVAL; + + /* Save parameters */ + vi->intr_coal_tx.max_usecs = ec->tx_coalesce_usecs; + vi->intr_coal_tx.max_packets = ec->tx_max_coalesced_frames; + } return 0; } @@ -3304,6 +3357,27 @@ static int virtnet_send_tx_notf_coal_vq_cmd(struct virtnet_info *vi, return 0; } +static void virtnet_tx_dim_work(struct work_struct *work) +{ + struct dim *dim = container_of(work, struct dim, work); + struct send_queue *sq = container_of(dim, + struct send_queue, dim); + struct virtnet_info *vi = sq->vq->vdev->priv; + struct net_device *dev = vi->dev; + struct dim_cq_moder update_moder; + int qnum = sq - vi->sq, err; + + update_moder = net_dim_get_tx_moderation(dim->mode, dim->profile_ix); + err = virtnet_send_tx_notf_coal_vq_cmd(vi, qnum, + update_moder.usec, + update_moder.pkts); + if (err) + pr_debug("%s: Failed to send dim parameters on txq%d\n", + dev->name, (int)(sq - vi->sq)); + + dim->state = DIM_START_MEASURE; +} + static int virtnet_send_rx_notf_coal_vq_cmd(struct virtnet_info *vi, u16 queue, u32 max_usecs, u32 max_packets) @@ -3326,7 +3400,7 @@ static int virtnet_send_notf_coal_vq_cmds(struct virtnet_info *vi, struct ethtool_coalesce *ec, u16 queue) { - bool rx_ctrl_dim_on; + bool rx_ctrl_dim_on, tx_ctrl_dim_on; u32 max_usecs, max_packets; int err; @@ -3351,11 +3425,23 @@ static int virtnet_send_notf_coal_vq_cmds(struct virtnet_info *vi, } if (ec->tx_coalesce_usecs || ec->tx_max_coalesced_frames) { - err = virtnet_send_tx_notf_coal_vq_cmd(vi, queue, - ec->tx_coalesce_usecs, - ec->tx_max_coalesced_frames); - if (err) - return err; + tx_ctrl_dim_on = !!ec->use_adaptive_tx_coalesce; + max_usecs = vi->sq[queue].intr_coal.max_usecs; + max_packets = vi->sq[queue].intr_coal.max_packets; + if (tx_ctrl_dim_on && (ec->tx_coalesce_usecs != max_usecs || + ec->tx_max_coalesced_frames != max_packets)) + return -EINVAL; + + if (tx_ctrl_dim_on) { + vi->sq[queue].dim_enabled = true; + } else { + vi->sq[queue].dim_enabled = false; + err = virtnet_send_tx_notf_coal_vq_cmd(vi, queue, + ec->tx_coalesce_usecs, + ec->tx_max_coalesced_frames); + if (err) + return err; + } } return 0; @@ -3464,6 +3550,7 @@ static int virtnet_get_coalesce(struct net_device *dev, ec->tx_max_coalesced_frames = vi->intr_coal_tx.max_packets; ec->rx_max_coalesced_frames = vi->intr_coal_rx.max_packets; ec->use_adaptive_rx_coalesce = vi->rq[0].dim_enabled; + ec->use_adaptive_tx_coalesce = vi->sq[0].dim_enabled; } else { ec->rx_max_coalesced_frames = 1; @@ -3522,6 +3609,7 @@ static int virtnet_get_per_queue_coalesce(struct net_device *dev, ec->tx_max_coalesced_frames = vi->sq[queue].intr_coal.max_packets; ec->rx_max_coalesced_frames = vi->rq[queue].intr_coal.max_packets; ec->use_adaptive_rx_coalesce = vi->rq[queue].dim_enabled; + ec->use_adaptive_tx_coalesce = vi->sq[queue].dim_enabled; } else { ec->rx_max_coalesced_frames = 1; @@ -3647,7 +3735,7 @@ static int virtnet_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info) static const struct ethtool_ops virtnet_ethtool_ops = { .supported_coalesce_params = ETHTOOL_COALESCE_MAX_FRAMES | - ETHTOOL_COALESCE_USECS | ETHTOOL_COALESCE_USE_ADAPTIVE_RX, + ETHTOOL_COALESCE_USECS | ETHTOOL_COALESCE_USE_ADAPTIVE, .get_drvinfo = virtnet_get_drvinfo, .get_link = ethtool_op_get_link, .get_ringparam = virtnet_get_ringparam, From patchwork Fri Aug 11 06:55:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heng Qi X-Patchwork-Id: 13350178 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DBE1353BA for ; Fri, 11 Aug 2023 06:55:28 +0000 (UTC) Received: from out30-112.freemail.mail.aliyun.com (out30-112.freemail.mail.aliyun.com [115.124.30.112]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9619E7E for ; Thu, 10 Aug 2023 23:55:27 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R171e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046050;MF=hengqi@linux.alibaba.com;NM=1;PH=DS;RN=13;SR=0;TI=SMTPD_---0VpWGJHw_1691736923; Received: from localhost(mailfrom:hengqi@linux.alibaba.com fp:SMTPD_---0VpWGJHw_1691736923) by smtp.aliyun-inc.com; Fri, 11 Aug 2023 14:55:24 +0800 From: Heng Qi To: "Michael S . Tsirkin" , Jason Wang , netdev@vger.kernel.org, virtualization@lists.linux-foundation.org Cc: "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Xuan Zhuo Subject: [PATCH net-next 8/8] virtio-net: a tiny comment update Date: Fri, 11 Aug 2023 14:55:12 +0800 Message-Id: <20230811065512.22190-9-hengqi@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230811065512.22190-1-hengqi@linux.alibaba.com> References: <20230811065512.22190-1-hengqi@linux.alibaba.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org Update a comment because virtio-net now supports both VIRTIO_NET_F_NOTF_COAL and VIRTIO_NET_F_VQ_NOTF_COAL. Signed-off-by: Heng Qi --- drivers/net/virtio_net.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index df7705ca05f0..6d07e496924f 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -3471,7 +3471,7 @@ static void virtnet_rx_dim_work(struct work_struct *work) static int virtnet_coal_params_supported(struct ethtool_coalesce *ec) { /* usecs coalescing is supported only if VIRTIO_NET_F_NOTF_COAL - * feature is negotiated. + * or VIRTIO_NET_F_VQ_NOTF_COAL feature is negotiated. */ if (ec->rx_coalesce_usecs || ec->tx_coalesce_usecs) return -EOPNOTSUPP;