From: Heng Qi <hengqi@linux.alibaba.com>
To: netdev@vger.kernel.org, virtualization@lists.linux.dev
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
Jason Wang <jasowang@redhat.com>,
Xuan Zhuo <xuanzhuo@linux.alibaba.com>,
Eric Dumazet <edumazet@google.com>,
"David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Subject: [PATCH net-next 2/2] virtio_net: get init coalesce value when probe
Date: Tue, 23 Apr 2024 16:42:26 +0800 [thread overview]
Message-ID: <20240423084226.25440-3-hengqi@linux.alibaba.com> (raw)
In-Reply-To: <20240423084226.25440-1-hengqi@linux.alibaba.com>
Currently, virtio-net lacks a way to obtain the default coalesce
values of the device during the probe phase. That is, the device
may have default experience values, but the user uses "ethtool -c"
to query that the values are still 0.
Therefore, we reuse VIRTIO_NET_CTRL_NOTF_COAL_VQ_GET to complete the goal.
Signed-off-by: Heng Qi <hengqi@linux.alibaba.com>
---
drivers/net/virtio_net.c | 68 +++++++++++++++++++++++++++++++++++-----
1 file changed, 61 insertions(+), 7 deletions(-)
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 3bc9b1e621db..fe0c15819dd3 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -4623,6 +4623,46 @@ static int virtnet_validate(struct virtio_device *vdev)
return 0;
}
+static int virtnet_get_coal_init_value(struct virtnet_info *vi,
+ u16 _vqn, bool is_tx)
+{
+ struct virtio_net_ctrl_coal *coal = &vi->ctrl->coal_vq.coal;
+ __le16 *vqn = &vi->ctrl->coal_vq.vqn;
+ struct scatterlist sgs_in, sgs_out;
+ u32 usecs, pkts, i;
+ bool ret;
+
+ *vqn = cpu_to_le16(_vqn);
+
+ sg_init_one(&sgs_out, vqn, sizeof(*vqn));
+ sg_init_one(&sgs_in, coal, sizeof(*coal));
+ ret = virtnet_send_command_reply(vi, VIRTIO_NET_CTRL_NOTF_COAL,
+ VIRTIO_NET_CTRL_NOTF_COAL_VQ_GET,
+ &sgs_out, &sgs_in);
+ if (!ret)
+ return ret;
+
+ usecs = le32_to_cpu(coal->max_usecs);
+ pkts = le32_to_cpu(coal->max_packets);
+ if (is_tx) {
+ vi->intr_coal_tx.max_usecs = usecs;
+ vi->intr_coal_tx.max_packets = pkts;
+ for (i = 0; i < vi->max_queue_pairs; i++) {
+ vi->sq[i].intr_coal.max_usecs = usecs;
+ vi->sq[i].intr_coal.max_packets = pkts;
+ }
+ } else {
+ vi->intr_coal_rx.max_usecs = usecs;
+ vi->intr_coal_rx.max_packets = pkts;
+ for (i = 0; i < vi->max_queue_pairs; i++) {
+ vi->rq[i].intr_coal.max_usecs = usecs;
+ vi->rq[i].intr_coal.max_packets = pkts;
+ }
+ }
+
+ return 0;
+}
+
static bool virtnet_check_guest_gso(const struct virtnet_info *vi)
{
return virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_TSO4) ||
@@ -4885,13 +4925,6 @@ static int virtnet_probe(struct virtio_device *vdev)
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;
@@ -4926,6 +4959,27 @@ static int virtnet_probe(struct virtio_device *vdev)
virtio_device_ready(vdev);
+ 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;
+
+ /* The loop exits if the default value from any
+ * queue is successfully read.
+ */
+ for (i = 0; i < vi->max_queue_pairs; i++) {
+ err = virtnet_get_coal_init_value(vi, rxq2vq(i), false);
+ if (!err)
+ break;
+ }
+ for (i = 0; i < vi->max_queue_pairs; i++) {
+ err = virtnet_get_coal_init_value(vi, txq2vq(i), true);
+ if (!err)
+ break;
+ }
+ }
+
_virtnet_set_queues(vi, vi->curr_queue_pairs);
/* a random MAC address has been assigned, notify the device.
--
2.32.0.3.g01195cf9f
prev parent reply other threads:[~2024-04-23 8:42 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-23 8:42 [PATCH net-next 0/2] virtio_net: support getting initial value of irq coalesce Heng Qi
2024-04-23 8:42 ` [PATCH net-next 1/2] virtio_net: virtnet_send_command supports command-specific-result Heng Qi
2024-04-23 10:17 ` Jiri Pirko
2024-04-23 11:03 ` Heng Qi
2024-04-23 8:42 ` Heng Qi [this message]
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=20240423084226.25440-3-hengqi@linux.alibaba.com \
--to=hengqi@linux.alibaba.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=jasowang@redhat.com \
--cc=kuba@kernel.org \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=virtualization@lists.linux.dev \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox