virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Simon Horman <horms@kernel.org>
To: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Cc: netdev@vger.kernel.org, "Michael S. Tsirkin" <mst@redhat.com>,
	Jason Wang <jasowang@redhat.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	virtualization@lists.linux.dev
Subject: Re: [PATCH net-next 3/6] virtio_net: support device stats
Date: Wed, 3 Jan 2024 21:03:21 +0000	[thread overview]
Message-ID: <20240103210321.GD31813@kernel.org> (raw)
In-Reply-To: <20231222033021.20649-4-xuanzhuo@linux.alibaba.com>

On Fri, Dec 22, 2023 at 11:30:18AM +0800, Xuan Zhuo wrote:
> As the spec https://github.com/oasis-tcs/virtio-spec/commit/42f389989823039724f95bbbd243291ab0064f82
> 
> Virtio-net supports to get the stats from the device by ethtool -S <eth0>.
> 
> Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>

Hi Xuan Zhuo,

some minor feedback from my side relating to Sparse warnings.

...

> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c

...

> +static int virtnet_get_hw_stats(struct virtnet_info *vi,
> +				struct virtnet_stats_ctx *ctx)
> +{
> +	struct virtio_net_ctrl_queue_stats *req;
> +	struct virtio_net_stats_reply_hdr *hdr;
> +	struct scatterlist sgs_in, sgs_out;
> +	u32 num_rx, num_tx, num_cq, offset;
> +	int qnum, i, j,  qid, res_size;
> +	struct virtnet_stats_map *m;
> +	void *reply, *p;
> +	u64 bitmap;
> +	int ok;
> +	u64 *v;

...

> +	for (p = reply; p - reply < res_size; p += virtio16_to_cpu(vi->vdev, hdr->size)) {

The type of the second parameter of _virtio16_to_cpu() is __virtio16.
But the type of the size field of virtio_net_stats_reply_hdr is __le16.
This does not seem correct.

> +		hdr = p;
> +
> +		qid = virtio16_to_cpu(vi->vdev, hdr->vq_index);

Similarly, the vq_index field of virtio_net_stats_reply_hdr is also __le16.

...

> +		for (i = 0; i < ARRAY_SIZE(virtio_net_stats_map); ++i) {
> +			m = &virtio_net_stats_map[i];
> +
> +			if (m->flag & bitmap)
> +				offset += m->num;
> +
> +			if (hdr->type != m->type)
> +				continue;
> +
> +			for (j = 0; j < m->num; ++j) {
> +				v = p + m->desc[j].offset;
> +				ctx->data[offset + j] = virtio64_to_cpu(vi->vdev, *v);

Here the type of the second parameter of virtio64_to_cpu() is __virtio64.
But the type of *v is u64.

> +			}
> +
> +			break;
> +		}
> +	}
> +
> +	kfree(reply);
> +	return 0;
> +}
> +

...

> @@ -3183,11 +3497,35 @@ static void virtnet_get_strings(struct net_device *dev, u32 stringset, u8 *data)
>  static int virtnet_get_sset_count(struct net_device *dev, int sset)
>  {
>  	struct virtnet_info *vi = netdev_priv(dev);
> +	struct virtnet_stats_ctx ctx = {0};
> +	u32 pair_count;
>  
>  	switch (sset) {
>  	case ETH_SS_STATS:
> -		return vi->curr_queue_pairs * (VIRTNET_RQ_STATS_LEN +
> -					       VIRTNET_SQ_STATS_LEN);
> +		if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_DEVICE_STATS) &&
> +		    !vi->device_stats_cap) {
> +			struct scatterlist sg;
> +
> +			sg_init_one(&sg, &vi->ctrl->stats_cap, sizeof(vi->ctrl->stats_cap));
> +
> +			if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_STATS,
> +						  VIRTIO_NET_CTRL_STATS_QUERY,
> +						  NULL, &sg)) {
> +				dev_warn(&dev->dev, "Fail to get stats capability\n");
> +			} else {
> +				__le64 v;
> +
> +				v = vi->ctrl->stats_cap.supported_stats_types[0];
> +				vi->device_stats_cap = virtio64_to_cpu(vi->vdev, v);

Similarly, the type of v is __le64.

> +			}
> +		}
> +
> +		virtnet_stats_ctx_init(vi, &ctx, NULL);
> +
> +		pair_count = VIRTNET_RQ_STATS_LEN + VIRTNET_SQ_STATS_LEN;
> +		pair_count += ctx.num_rx + ctx.num_tx;
> +
> +		return ctx.num_cq + vi->curr_queue_pairs * pair_count;
>  	default:
>  		return -EOPNOTSUPP;
>  	}

...

  parent reply	other threads:[~2024-01-03 21:03 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-22  3:30 [PATCH net-next 0/6] virtio-net: support device stats Xuan Zhuo
2023-12-22  3:30 ` [PATCH net-next 1/6] virtio_net: introduce device stats feature and structures Xuan Zhuo
2023-12-23 17:55   ` kernel test robot
2023-12-24  8:40     ` Zhu Yanjun
2023-12-25  8:01   ` Zhu Yanjun
2023-12-26  6:17     ` Xuan Zhuo
2023-12-26  8:58       ` Michael S. Tsirkin
2023-12-26  9:00         ` Xuan Zhuo
2023-12-26  9:08           ` Michael S. Tsirkin
2023-12-26  9:09             ` Xuan Zhuo
2023-12-26  9:19               ` Michael S. Tsirkin
2023-12-26  9:24                 ` Xuan Zhuo
2023-12-22  3:30 ` [PATCH net-next 2/6] virtio_net: virtnet_send_command supports command-specific-result Xuan Zhuo
2023-12-22  3:30 ` [PATCH net-next 3/6] virtio_net: support device stats Xuan Zhuo
2023-12-23 17:03   ` kernel test robot
2023-12-23 17:23   ` kernel test robot
2023-12-24  8:55     ` Zhu Yanjun
2024-01-03 21:03   ` Simon Horman [this message]
2023-12-22  3:30 ` [PATCH net-next 4/6] virtio_net: stats map include driver stats Xuan Zhuo
2023-12-22  3:30 ` [PATCH net-next 5/6] virtio_net: add the total stats field Xuan Zhuo
2023-12-22  3:30 ` [PATCH net-next 6/6] virtio_net: rename stat tx_timeout to timeout Xuan Zhuo

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=20240103210321.GD31813@kernel.org \
    --to=horms@kernel.org \
    --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;
as well as URLs for NNTP newsgroup(s).