diff mbox series

[net-next,1/6] virtio_net: introduce device stats feature and structures

Message ID 20231222033021.20649-2-xuanzhuo@linux.alibaba.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series virtio-net: support device stats | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/apply fail Patch does not apply to net-next

Commit Message

Xuan Zhuo Dec. 22, 2023, 3:30 a.m. UTC
The virtio-net device stats spec:

https://github.com/oasis-tcs/virtio-spec/commit/42f389989823039724f95bbbd243291ab0064f82

This commit introduces the relative feature and structures.

Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
---
 include/uapi/linux/virtio_net.h | 137 ++++++++++++++++++++++++++++++++
 1 file changed, 137 insertions(+)

Comments

kernel test robot Dec. 23, 2023, 5:55 p.m. UTC | #1
Hi Xuan,

kernel test robot noticed the following build errors:

[auto build test ERROR on mst-vhost/linux-next]
[also build test ERROR on linus/master v6.7-rc6 next-20231222]
[cannot apply to net-next/main horms-ipvs/master]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Xuan-Zhuo/virtio_net-introduce-device-stats-feature-and-structures/20231222-175505
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost.git linux-next
patch link:    https://lore.kernel.org/r/20231222033021.20649-2-xuanzhuo%40linux.alibaba.com
patch subject: [PATCH net-next 1/6] virtio_net: introduce device stats feature and structures
config: x86_64-buildonly-randconfig-002-20231223 (https://download.01.org/0day-ci/archive/20231224/202312240125.00z3nxGY-lkp@intel.com/config)
compiler: clang version 16.0.4 (https://github.com/llvm/llvm-project.git ae42196bc493ffe877a7e3dff8be32035dea4d07)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231224/202312240125.00z3nxGY-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202312240125.00z3nxGY-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from <built-in>:1:
>> ./usr/include/linux/virtio_net.h:454:2: error: unknown type name 'u8'
           u8 type;
           ^
   ./usr/include/linux/virtio_net.h:455:2: error: unknown type name 'u8'
           u8 reserved;
           ^
   2 errors generated.
Zhu Yanjun Dec. 24, 2023, 8:40 a.m. UTC | #2
在 2023/12/24 1:55, kernel test robot 写道:
> Hi Xuan,
> 
> kernel test robot noticed the following build errors:
> 
> [auto build test ERROR on mst-vhost/linux-next]
> [also build test ERROR on linus/master v6.7-rc6 next-20231222]
> [cannot apply to net-next/main horms-ipvs/master]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch#_base_tree_information]
> 
> url:    https://github.com/intel-lab-lkp/linux/commits/Xuan-Zhuo/virtio_net-introduce-device-stats-feature-and-structures/20231222-175505
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost.git linux-next
> patch link:    https://lore.kernel.org/r/20231222033021.20649-2-xuanzhuo%40linux.alibaba.com
> patch subject: [PATCH net-next 1/6] virtio_net: introduce device stats feature and structures
> config: x86_64-buildonly-randconfig-002-20231223 (https://download.01.org/0day-ci/archive/20231224/202312240125.00z3nxGY-lkp@intel.com/config)
> compiler: clang version 16.0.4 (https://github.com/llvm/llvm-project.git ae42196bc493ffe877a7e3dff8be32035dea4d07)
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231224/202312240125.00z3nxGY-lkp@intel.com/reproduce)
> 
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202312240125.00z3nxGY-lkp@intel.com/
> 
> All errors (new ones prefixed by >>):
> 
>     In file included from <built-in>:1:
>>> ./usr/include/linux/virtio_net.h:454:2: error: unknown type name 'u8'
>             u8 type;
>             ^
>     ./usr/include/linux/virtio_net.h:455:2: error: unknown type name 'u8'
>             u8 reserved;
I can reproduce this problem.
Replacing u8 as __u8 can fix this problem.
Not sure whether __u8 is correct to the whole patches.

Zhu Yanjun

>             ^
>     2 errors generated.
>
Zhu Yanjun Dec. 25, 2023, 8:01 a.m. UTC | #3
在 2023/12/22 11:30, Xuan Zhuo 写道:
> The virtio-net device stats spec:
> 
> https://github.com/oasis-tcs/virtio-spec/commit/42f389989823039724f95bbbd243291ab0064f82
> 
> This commit introduces the relative feature and structures.

Hi, Xuan

After applying this patch series, withe ethtool version 6.5,
I got the following NIC statistics. But I do not find the statistics 
mentioned in this patch series.
Do I miss something?

"
NIC statistics:
      rx_packets: 3434812669
      rx_bytes: 5168475253690
      rx_drops: 0
      rx_xdp_packets: 0
      rx_xdp_tx: 0
      rx_xdp_redirects: 0
      rx_xdp_drops: 0
      rx_kicks: 57179891
      tx_packets: 187694230
      tx_bytes: 12423799040
      tx_xdp_tx: 0
      tx_xdp_tx_drops: 0
      tx_kicks: 187694230
      tx_timeouts: 0
      rx_queue_0_packets: 866027381
      rx_queue_0_bytes: 1302726908150
      rx_queue_0_drops: 0
      rx_queue_0_xdp_packets: 0
      rx_queue_0_xdp_tx: 0
      rx_queue_0_xdp_redirects: 0
      rx_queue_0_xdp_drops: 0
      rx_queue_0_kicks: 14567691
      rx_queue_1_packets: 856758801
      rx_queue_1_bytes: 1289899049042
      rx_queue_1_drops: 0
      rx_queue_1_xdp_packets: 0
      rx_queue_1_xdp_tx: 0
      rx_queue_1_xdp_redirects: 0
      rx_queue_1_xdp_drops: 0
      rx_queue_1_kicks: 14265201
      rx_queue_2_packets: 839291053
      rx_queue_2_bytes: 1261620863886
      rx_queue_2_drops: 0
      rx_queue_2_xdp_packets: 0
      rx_queue_2_xdp_tx: 0
      rx_queue_2_xdp_redirects: 0
      rx_queue_2_xdp_drops: 0
      rx_queue_2_kicks: 13857653
      rx_queue_3_packets: 872735434
      rx_queue_3_bytes: 1314228432612
      rx_queue_3_drops: 0
      rx_queue_3_xdp_packets: 0
      rx_queue_3_xdp_tx: 0
      rx_queue_3_xdp_redirects: 0
      rx_queue_3_xdp_drops: 0
      rx_queue_3_kicks: 14489346
      tx_queue_0_packets: 75723
      tx_queue_0_bytes: 4999030
      tx_queue_0_xdp_tx: 0
      tx_queue_0_xdp_tx_drops: 0
      tx_queue_0_kicks: 75723
      tx_queue_0_timeouts: 0
      tx_queue_1_packets: 62262921
      tx_queue_1_bytes: 4134803914
      tx_queue_1_xdp_tx: 0
      tx_queue_1_xdp_tx_drops: 0
      tx_queue_1_kicks: 62262921
      tx_queue_1_timeouts: 0
      tx_queue_2_packets: 83
      tx_queue_2_bytes: 5478
      tx_queue_2_xdp_tx: 0
      tx_queue_2_xdp_tx_drops: 0
      tx_queue_2_kicks: 83
      tx_queue_2_timeouts: 0
      tx_queue_3_packets: 125355503
      tx_queue_3_bytes: 8283990618
      tx_queue_3_xdp_tx: 0
      tx_queue_3_xdp_tx_drops: 0
      tx_queue_3_kicks: 125355503
      tx_queue_3_timeouts: 0
"

> 
> Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> ---
>   include/uapi/linux/virtio_net.h | 137 ++++++++++++++++++++++++++++++++
>   1 file changed, 137 insertions(+)
> 
> diff --git a/include/uapi/linux/virtio_net.h b/include/uapi/linux/virtio_net.h
> index cc65ef0f3c3e..129e0871d28f 100644
> --- a/include/uapi/linux/virtio_net.h
> +++ b/include/uapi/linux/virtio_net.h
> @@ -56,6 +56,7 @@
>   #define VIRTIO_NET_F_MQ	22	/* Device supports Receive Flow
>   					 * Steering */
>   #define VIRTIO_NET_F_CTRL_MAC_ADDR 23	/* Set MAC address */
> +#define VIRTIO_NET_F_DEVICE_STATS 50	/* Device can provide device-level statistics. */
>   #define VIRTIO_NET_F_VQ_NOTF_COAL 52	/* Device supports virtqueue notification coalescing */
>   #define VIRTIO_NET_F_NOTF_COAL	53	/* Device supports notifications coalescing */
>   #define VIRTIO_NET_F_GUEST_USO4	54	/* Guest can handle USOv4 in. */
> @@ -406,4 +407,140 @@ struct  virtio_net_ctrl_coal_vq {
>   	struct virtio_net_ctrl_coal coal;
>   };
>   
> +/*
> + * Device Statistics
> + */
> +#define VIRTIO_NET_CTRL_STATS         8
> +#define VIRTIO_NET_CTRL_STATS_QUERY   0
> +#define VIRTIO_NET_CTRL_STATS_GET     1
> +
> +struct virtio_net_stats_capabilities {
> +
> +#define VIRTIO_NET_STATS_TYPE_CVQ       (1L << 32)
> +
> +#define VIRTIO_NET_STATS_TYPE_RX_BASIC  (1 << 0)
> +#define VIRTIO_NET_STATS_TYPE_RX_CSUM   (1 << 1)
> +#define VIRTIO_NET_STATS_TYPE_RX_GSO    (1 << 2)
> +#define VIRTIO_NET_STATS_TYPE_RX_SPEED  (1 << 3)
> +
> +#define VIRTIO_NET_STATS_TYPE_TX_BASIC  (1 << 16)
> +#define VIRTIO_NET_STATS_TYPE_TX_CSUM   (1 << 17)
> +#define VIRTIO_NET_STATS_TYPE_TX_GSO    (1 << 18)
> +#define VIRTIO_NET_STATS_TYPE_TX_SPEED  (1 << 19)
> +
> +	__le64 supported_stats_types[1];
> +};
> +
> +struct virtio_net_ctrl_queue_stats {
> +	struct {
> +		__le16 vq_index;
> +		__le16 reserved[3];
> +		__le64 types_bitmap[1];
> +	} stats[1];
> +};
> +
> +struct virtio_net_stats_reply_hdr {
> +#define VIRTIO_NET_STATS_TYPE_REPLY_CVQ       32
> +
> +#define VIRTIO_NET_STATS_TYPE_REPLY_RX_BASIC  0
> +#define VIRTIO_NET_STATS_TYPE_REPLY_RX_CSUM   1
> +#define VIRTIO_NET_STATS_TYPE_REPLY_RX_GSO    2
> +#define VIRTIO_NET_STATS_TYPE_REPLY_RX_SPEED  3
> +
> +#define VIRTIO_NET_STATS_TYPE_REPLY_TX_BASIC  16
> +#define VIRTIO_NET_STATS_TYPE_REPLY_TX_CSUM   17
> +#define VIRTIO_NET_STATS_TYPE_REPLY_TX_GSO    18
> +#define VIRTIO_NET_STATS_TYPE_REPLY_TX_SPEED  19
> +	u8 type;
> +	u8 reserved;
> +	__le16 vq_index;
> +	__le16 reserved1;
> +	__le16 size;
> +};
> +
> +struct virtio_net_stats_cvq {
> +	struct virtio_net_stats_reply_hdr hdr;
> +
> +	__le64 command_num;
> +	__le64 ok_num;
> +};
> +
> +struct virtio_net_stats_rx_basic {
> +	struct virtio_net_stats_reply_hdr hdr;
> +
> +	__le64 rx_notifications;
> +
> +	__le64 rx_packets;
> +	__le64 rx_bytes;
> +
> +	__le64 rx_interrupts;
> +
> +	__le64 rx_drops;
> +	__le64 rx_drop_overruns;
> +};
> +
> +struct virtio_net_stats_tx_basic {
> +	struct virtio_net_stats_reply_hdr hdr;
> +
> +	__le64 tx_notifications;
> +
> +	__le64 tx_packets;
> +	__le64 tx_bytes;
> +
> +	__le64 tx_interrupts;
> +
> +	__le64 tx_drops;
> +	__le64 tx_drop_malformed;
> +};
> +
> +struct virtio_net_stats_rx_csum {
> +	struct virtio_net_stats_reply_hdr hdr;
> +
> +	__le64 rx_csum_valid;
> +	__le64 rx_needs_csum;
> +	__le64 rx_csum_none;
> +	__le64 rx_csum_bad;
> +};
> +
> +struct virtio_net_stats_tx_csum {
> +	struct virtio_net_stats_reply_hdr hdr;
> +
> +	__le64 tx_csum_none;
> +	__le64 tx_needs_csum;
> +};
> +
> +struct virtio_net_stats_rx_gso {
> +	struct virtio_net_stats_reply_hdr hdr;
> +
> +	__le64 rx_gso_packets;
> +	__le64 rx_gso_bytes;
> +	__le64 rx_gso_packets_coalesced;
> +	__le64 rx_gso_bytes_coalesced;
> +};
> +
> +struct virtio_net_stats_tx_gso {
> +	struct virtio_net_stats_reply_hdr hdr;
> +
> +	__le64 tx_gso_packets;
> +	__le64 tx_gso_bytes;
> +	__le64 tx_gso_segments;
> +	__le64 tx_gso_segments_bytes;
> +	__le64 tx_gso_packets_noseg;
> +	__le64 tx_gso_bytes_noseg;
> +};
> +
> +struct virtio_net_stats_rx_speed {
> +	struct virtio_net_stats_reply_hdr hdr;
> +
> +	__le64 rx_packets_allowance_exceeded;
> +	__le64 rx_bytes_allowance_exceeded;
> +};
> +
> +struct virtio_net_stats_tx_speed {
> +	struct virtio_net_stats_reply_hdr hdr;
> +
> +	__le64 tx_packets_allowance_exceeded;
> +	__le64 tx_bytes_allowance_exceeded;
> +};
> +
>   #endif /* _UAPI_LINUX_VIRTIO_NET_H */
Xuan Zhuo Dec. 26, 2023, 6:17 a.m. UTC | #4
On Mon, 25 Dec 2023 16:01:39 +0800, Zhu Yanjun <yanjun.zhu@linux.dev> wrote:
> 在 2023/12/22 11:30, Xuan Zhuo 写道:
> > The virtio-net device stats spec:
> >
> > https://github.com/oasis-tcs/virtio-spec/commit/42f389989823039724f95bbbd243291ab0064f82
> >
> > This commit introduces the relative feature and structures.
>
> Hi, Xuan
>
> After applying this patch series, withe ethtool version 6.5,
> I got the following NIC statistics. But I do not find the statistics
> mentioned in this patch series.
> Do I miss something?

This needs the new virtio-net feature VIRTIO_NET_F_DEVICE_STATS.
You need to update the hypervisor. But the qemu may not support this.

Thanks.



>
> "
> NIC statistics:
>       rx_packets: 3434812669
>       rx_bytes: 5168475253690
>       rx_drops: 0
>       rx_xdp_packets: 0
>       rx_xdp_tx: 0
>       rx_xdp_redirects: 0
>       rx_xdp_drops: 0
>       rx_kicks: 57179891
>       tx_packets: 187694230
>       tx_bytes: 12423799040
>       tx_xdp_tx: 0
>       tx_xdp_tx_drops: 0
>       tx_kicks: 187694230
>       tx_timeouts: 0
>       rx_queue_0_packets: 866027381
>       rx_queue_0_bytes: 1302726908150
>       rx_queue_0_drops: 0
>       rx_queue_0_xdp_packets: 0
>       rx_queue_0_xdp_tx: 0
>       rx_queue_0_xdp_redirects: 0
>       rx_queue_0_xdp_drops: 0
>       rx_queue_0_kicks: 14567691
>       rx_queue_1_packets: 856758801
>       rx_queue_1_bytes: 1289899049042
>       rx_queue_1_drops: 0
>       rx_queue_1_xdp_packets: 0
>       rx_queue_1_xdp_tx: 0
>       rx_queue_1_xdp_redirects: 0
>       rx_queue_1_xdp_drops: 0
>       rx_queue_1_kicks: 14265201
>       rx_queue_2_packets: 839291053
>       rx_queue_2_bytes: 1261620863886
>       rx_queue_2_drops: 0
>       rx_queue_2_xdp_packets: 0
>       rx_queue_2_xdp_tx: 0
>       rx_queue_2_xdp_redirects: 0
>       rx_queue_2_xdp_drops: 0
>       rx_queue_2_kicks: 13857653
>       rx_queue_3_packets: 872735434
>       rx_queue_3_bytes: 1314228432612
>       rx_queue_3_drops: 0
>       rx_queue_3_xdp_packets: 0
>       rx_queue_3_xdp_tx: 0
>       rx_queue_3_xdp_redirects: 0
>       rx_queue_3_xdp_drops: 0
>       rx_queue_3_kicks: 14489346
>       tx_queue_0_packets: 75723
>       tx_queue_0_bytes: 4999030
>       tx_queue_0_xdp_tx: 0
>       tx_queue_0_xdp_tx_drops: 0
>       tx_queue_0_kicks: 75723
>       tx_queue_0_timeouts: 0
>       tx_queue_1_packets: 62262921
>       tx_queue_1_bytes: 4134803914
>       tx_queue_1_xdp_tx: 0
>       tx_queue_1_xdp_tx_drops: 0
>       tx_queue_1_kicks: 62262921
>       tx_queue_1_timeouts: 0
>       tx_queue_2_packets: 83
>       tx_queue_2_bytes: 5478
>       tx_queue_2_xdp_tx: 0
>       tx_queue_2_xdp_tx_drops: 0
>       tx_queue_2_kicks: 83
>       tx_queue_2_timeouts: 0
>       tx_queue_3_packets: 125355503
>       tx_queue_3_bytes: 8283990618
>       tx_queue_3_xdp_tx: 0
>       tx_queue_3_xdp_tx_drops: 0
>       tx_queue_3_kicks: 125355503
>       tx_queue_3_timeouts: 0
> "
>
> >
> > Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> > ---
> >   include/uapi/linux/virtio_net.h | 137 ++++++++++++++++++++++++++++++++
> >   1 file changed, 137 insertions(+)
> >
> > diff --git a/include/uapi/linux/virtio_net.h b/include/uapi/linux/virtio_net.h
> > index cc65ef0f3c3e..129e0871d28f 100644
> > --- a/include/uapi/linux/virtio_net.h
> > +++ b/include/uapi/linux/virtio_net.h
> > @@ -56,6 +56,7 @@
> >   #define VIRTIO_NET_F_MQ	22	/* Device supports Receive Flow
> >   					 * Steering */
> >   #define VIRTIO_NET_F_CTRL_MAC_ADDR 23	/* Set MAC address */
> > +#define VIRTIO_NET_F_DEVICE_STATS 50	/* Device can provide device-level statistics. */
> >   #define VIRTIO_NET_F_VQ_NOTF_COAL 52	/* Device supports virtqueue notification coalescing */
> >   #define VIRTIO_NET_F_NOTF_COAL	53	/* Device supports notifications coalescing */
> >   #define VIRTIO_NET_F_GUEST_USO4	54	/* Guest can handle USOv4 in. */
> > @@ -406,4 +407,140 @@ struct  virtio_net_ctrl_coal_vq {
> >   	struct virtio_net_ctrl_coal coal;
> >   };
> >
> > +/*
> > + * Device Statistics
> > + */
> > +#define VIRTIO_NET_CTRL_STATS         8
> > +#define VIRTIO_NET_CTRL_STATS_QUERY   0
> > +#define VIRTIO_NET_CTRL_STATS_GET     1
> > +
> > +struct virtio_net_stats_capabilities {
> > +
> > +#define VIRTIO_NET_STATS_TYPE_CVQ       (1L << 32)
> > +
> > +#define VIRTIO_NET_STATS_TYPE_RX_BASIC  (1 << 0)
> > +#define VIRTIO_NET_STATS_TYPE_RX_CSUM   (1 << 1)
> > +#define VIRTIO_NET_STATS_TYPE_RX_GSO    (1 << 2)
> > +#define VIRTIO_NET_STATS_TYPE_RX_SPEED  (1 << 3)
> > +
> > +#define VIRTIO_NET_STATS_TYPE_TX_BASIC  (1 << 16)
> > +#define VIRTIO_NET_STATS_TYPE_TX_CSUM   (1 << 17)
> > +#define VIRTIO_NET_STATS_TYPE_TX_GSO    (1 << 18)
> > +#define VIRTIO_NET_STATS_TYPE_TX_SPEED  (1 << 19)
> > +
> > +	__le64 supported_stats_types[1];
> > +};
> > +
> > +struct virtio_net_ctrl_queue_stats {
> > +	struct {
> > +		__le16 vq_index;
> > +		__le16 reserved[3];
> > +		__le64 types_bitmap[1];
> > +	} stats[1];
> > +};
> > +
> > +struct virtio_net_stats_reply_hdr {
> > +#define VIRTIO_NET_STATS_TYPE_REPLY_CVQ       32
> > +
> > +#define VIRTIO_NET_STATS_TYPE_REPLY_RX_BASIC  0
> > +#define VIRTIO_NET_STATS_TYPE_REPLY_RX_CSUM   1
> > +#define VIRTIO_NET_STATS_TYPE_REPLY_RX_GSO    2
> > +#define VIRTIO_NET_STATS_TYPE_REPLY_RX_SPEED  3
> > +
> > +#define VIRTIO_NET_STATS_TYPE_REPLY_TX_BASIC  16
> > +#define VIRTIO_NET_STATS_TYPE_REPLY_TX_CSUM   17
> > +#define VIRTIO_NET_STATS_TYPE_REPLY_TX_GSO    18
> > +#define VIRTIO_NET_STATS_TYPE_REPLY_TX_SPEED  19
> > +	u8 type;
> > +	u8 reserved;
> > +	__le16 vq_index;
> > +	__le16 reserved1;
> > +	__le16 size;
> > +};
> > +
> > +struct virtio_net_stats_cvq {
> > +	struct virtio_net_stats_reply_hdr hdr;
> > +
> > +	__le64 command_num;
> > +	__le64 ok_num;
> > +};
> > +
> > +struct virtio_net_stats_rx_basic {
> > +	struct virtio_net_stats_reply_hdr hdr;
> > +
> > +	__le64 rx_notifications;
> > +
> > +	__le64 rx_packets;
> > +	__le64 rx_bytes;
> > +
> > +	__le64 rx_interrupts;
> > +
> > +	__le64 rx_drops;
> > +	__le64 rx_drop_overruns;
> > +};
> > +
> > +struct virtio_net_stats_tx_basic {
> > +	struct virtio_net_stats_reply_hdr hdr;
> > +
> > +	__le64 tx_notifications;
> > +
> > +	__le64 tx_packets;
> > +	__le64 tx_bytes;
> > +
> > +	__le64 tx_interrupts;
> > +
> > +	__le64 tx_drops;
> > +	__le64 tx_drop_malformed;
> > +};
> > +
> > +struct virtio_net_stats_rx_csum {
> > +	struct virtio_net_stats_reply_hdr hdr;
> > +
> > +	__le64 rx_csum_valid;
> > +	__le64 rx_needs_csum;
> > +	__le64 rx_csum_none;
> > +	__le64 rx_csum_bad;
> > +};
> > +
> > +struct virtio_net_stats_tx_csum {
> > +	struct virtio_net_stats_reply_hdr hdr;
> > +
> > +	__le64 tx_csum_none;
> > +	__le64 tx_needs_csum;
> > +};
> > +
> > +struct virtio_net_stats_rx_gso {
> > +	struct virtio_net_stats_reply_hdr hdr;
> > +
> > +	__le64 rx_gso_packets;
> > +	__le64 rx_gso_bytes;
> > +	__le64 rx_gso_packets_coalesced;
> > +	__le64 rx_gso_bytes_coalesced;
> > +};
> > +
> > +struct virtio_net_stats_tx_gso {
> > +	struct virtio_net_stats_reply_hdr hdr;
> > +
> > +	__le64 tx_gso_packets;
> > +	__le64 tx_gso_bytes;
> > +	__le64 tx_gso_segments;
> > +	__le64 tx_gso_segments_bytes;
> > +	__le64 tx_gso_packets_noseg;
> > +	__le64 tx_gso_bytes_noseg;
> > +};
> > +
> > +struct virtio_net_stats_rx_speed {
> > +	struct virtio_net_stats_reply_hdr hdr;
> > +
> > +	__le64 rx_packets_allowance_exceeded;
> > +	__le64 rx_bytes_allowance_exceeded;
> > +};
> > +
> > +struct virtio_net_stats_tx_speed {
> > +	struct virtio_net_stats_reply_hdr hdr;
> > +
> > +	__le64 tx_packets_allowance_exceeded;
> > +	__le64 tx_bytes_allowance_exceeded;
> > +};
> > +
> >   #endif /* _UAPI_LINUX_VIRTIO_NET_H */
>
Michael S. Tsirkin Dec. 26, 2023, 8:58 a.m. UTC | #5
On Tue, Dec 26, 2023 at 02:17:43PM +0800, Xuan Zhuo wrote:
> On Mon, 25 Dec 2023 16:01:39 +0800, Zhu Yanjun <yanjun.zhu@linux.dev> wrote:
> > 在 2023/12/22 11:30, Xuan Zhuo 写道:
> > > The virtio-net device stats spec:
> > >
> > > https://github.com/oasis-tcs/virtio-spec/commit/42f389989823039724f95bbbd243291ab0064f82
> > >
> > > This commit introduces the relative feature and structures.
> >
> > Hi, Xuan
> >
> > After applying this patch series, withe ethtool version 6.5,
> > I got the following NIC statistics. But I do not find the statistics
> > mentioned in this patch series.
> > Do I miss something?
> 
> This needs the new virtio-net feature VIRTIO_NET_F_DEVICE_STATS.
> You need to update the hypervisor. But the qemu may not support this.
> 
> Thanks.

Why not? Can you add this to QEMU?


> 
> 
> >
> > "
> > NIC statistics:
> >       rx_packets: 3434812669
> >       rx_bytes: 5168475253690
> >       rx_drops: 0
> >       rx_xdp_packets: 0
> >       rx_xdp_tx: 0
> >       rx_xdp_redirects: 0
> >       rx_xdp_drops: 0
> >       rx_kicks: 57179891
> >       tx_packets: 187694230
> >       tx_bytes: 12423799040
> >       tx_xdp_tx: 0
> >       tx_xdp_tx_drops: 0
> >       tx_kicks: 187694230
> >       tx_timeouts: 0
> >       rx_queue_0_packets: 866027381
> >       rx_queue_0_bytes: 1302726908150
> >       rx_queue_0_drops: 0
> >       rx_queue_0_xdp_packets: 0
> >       rx_queue_0_xdp_tx: 0
> >       rx_queue_0_xdp_redirects: 0
> >       rx_queue_0_xdp_drops: 0
> >       rx_queue_0_kicks: 14567691
> >       rx_queue_1_packets: 856758801
> >       rx_queue_1_bytes: 1289899049042
> >       rx_queue_1_drops: 0
> >       rx_queue_1_xdp_packets: 0
> >       rx_queue_1_xdp_tx: 0
> >       rx_queue_1_xdp_redirects: 0
> >       rx_queue_1_xdp_drops: 0
> >       rx_queue_1_kicks: 14265201
> >       rx_queue_2_packets: 839291053
> >       rx_queue_2_bytes: 1261620863886
> >       rx_queue_2_drops: 0
> >       rx_queue_2_xdp_packets: 0
> >       rx_queue_2_xdp_tx: 0
> >       rx_queue_2_xdp_redirects: 0
> >       rx_queue_2_xdp_drops: 0
> >       rx_queue_2_kicks: 13857653
> >       rx_queue_3_packets: 872735434
> >       rx_queue_3_bytes: 1314228432612
> >       rx_queue_3_drops: 0
> >       rx_queue_3_xdp_packets: 0
> >       rx_queue_3_xdp_tx: 0
> >       rx_queue_3_xdp_redirects: 0
> >       rx_queue_3_xdp_drops: 0
> >       rx_queue_3_kicks: 14489346
> >       tx_queue_0_packets: 75723
> >       tx_queue_0_bytes: 4999030
> >       tx_queue_0_xdp_tx: 0
> >       tx_queue_0_xdp_tx_drops: 0
> >       tx_queue_0_kicks: 75723
> >       tx_queue_0_timeouts: 0
> >       tx_queue_1_packets: 62262921
> >       tx_queue_1_bytes: 4134803914
> >       tx_queue_1_xdp_tx: 0
> >       tx_queue_1_xdp_tx_drops: 0
> >       tx_queue_1_kicks: 62262921
> >       tx_queue_1_timeouts: 0
> >       tx_queue_2_packets: 83
> >       tx_queue_2_bytes: 5478
> >       tx_queue_2_xdp_tx: 0
> >       tx_queue_2_xdp_tx_drops: 0
> >       tx_queue_2_kicks: 83
> >       tx_queue_2_timeouts: 0
> >       tx_queue_3_packets: 125355503
> >       tx_queue_3_bytes: 8283990618
> >       tx_queue_3_xdp_tx: 0
> >       tx_queue_3_xdp_tx_drops: 0
> >       tx_queue_3_kicks: 125355503
> >       tx_queue_3_timeouts: 0
> > "
> >
> > >
> > > Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> > > ---
> > >   include/uapi/linux/virtio_net.h | 137 ++++++++++++++++++++++++++++++++
> > >   1 file changed, 137 insertions(+)
> > >
> > > diff --git a/include/uapi/linux/virtio_net.h b/include/uapi/linux/virtio_net.h
> > > index cc65ef0f3c3e..129e0871d28f 100644
> > > --- a/include/uapi/linux/virtio_net.h
> > > +++ b/include/uapi/linux/virtio_net.h
> > > @@ -56,6 +56,7 @@
> > >   #define VIRTIO_NET_F_MQ	22	/* Device supports Receive Flow
> > >   					 * Steering */
> > >   #define VIRTIO_NET_F_CTRL_MAC_ADDR 23	/* Set MAC address */
> > > +#define VIRTIO_NET_F_DEVICE_STATS 50	/* Device can provide device-level statistics. */
> > >   #define VIRTIO_NET_F_VQ_NOTF_COAL 52	/* Device supports virtqueue notification coalescing */
> > >   #define VIRTIO_NET_F_NOTF_COAL	53	/* Device supports notifications coalescing */
> > >   #define VIRTIO_NET_F_GUEST_USO4	54	/* Guest can handle USOv4 in. */
> > > @@ -406,4 +407,140 @@ struct  virtio_net_ctrl_coal_vq {
> > >   	struct virtio_net_ctrl_coal coal;
> > >   };
> > >
> > > +/*
> > > + * Device Statistics
> > > + */
> > > +#define VIRTIO_NET_CTRL_STATS         8
> > > +#define VIRTIO_NET_CTRL_STATS_QUERY   0
> > > +#define VIRTIO_NET_CTRL_STATS_GET     1
> > > +
> > > +struct virtio_net_stats_capabilities {
> > > +
> > > +#define VIRTIO_NET_STATS_TYPE_CVQ       (1L << 32)
> > > +
> > > +#define VIRTIO_NET_STATS_TYPE_RX_BASIC  (1 << 0)
> > > +#define VIRTIO_NET_STATS_TYPE_RX_CSUM   (1 << 1)
> > > +#define VIRTIO_NET_STATS_TYPE_RX_GSO    (1 << 2)
> > > +#define VIRTIO_NET_STATS_TYPE_RX_SPEED  (1 << 3)
> > > +
> > > +#define VIRTIO_NET_STATS_TYPE_TX_BASIC  (1 << 16)
> > > +#define VIRTIO_NET_STATS_TYPE_TX_CSUM   (1 << 17)
> > > +#define VIRTIO_NET_STATS_TYPE_TX_GSO    (1 << 18)
> > > +#define VIRTIO_NET_STATS_TYPE_TX_SPEED  (1 << 19)
> > > +
> > > +	__le64 supported_stats_types[1];
> > > +};
> > > +
> > > +struct virtio_net_ctrl_queue_stats {
> > > +	struct {
> > > +		__le16 vq_index;
> > > +		__le16 reserved[3];
> > > +		__le64 types_bitmap[1];
> > > +	} stats[1];
> > > +};
> > > +
> > > +struct virtio_net_stats_reply_hdr {
> > > +#define VIRTIO_NET_STATS_TYPE_REPLY_CVQ       32
> > > +
> > > +#define VIRTIO_NET_STATS_TYPE_REPLY_RX_BASIC  0
> > > +#define VIRTIO_NET_STATS_TYPE_REPLY_RX_CSUM   1
> > > +#define VIRTIO_NET_STATS_TYPE_REPLY_RX_GSO    2
> > > +#define VIRTIO_NET_STATS_TYPE_REPLY_RX_SPEED  3
> > > +
> > > +#define VIRTIO_NET_STATS_TYPE_REPLY_TX_BASIC  16
> > > +#define VIRTIO_NET_STATS_TYPE_REPLY_TX_CSUM   17
> > > +#define VIRTIO_NET_STATS_TYPE_REPLY_TX_GSO    18
> > > +#define VIRTIO_NET_STATS_TYPE_REPLY_TX_SPEED  19
> > > +	u8 type;
> > > +	u8 reserved;
> > > +	__le16 vq_index;
> > > +	__le16 reserved1;
> > > +	__le16 size;
> > > +};
> > > +
> > > +struct virtio_net_stats_cvq {
> > > +	struct virtio_net_stats_reply_hdr hdr;
> > > +
> > > +	__le64 command_num;
> > > +	__le64 ok_num;
> > > +};
> > > +
> > > +struct virtio_net_stats_rx_basic {
> > > +	struct virtio_net_stats_reply_hdr hdr;
> > > +
> > > +	__le64 rx_notifications;
> > > +
> > > +	__le64 rx_packets;
> > > +	__le64 rx_bytes;
> > > +
> > > +	__le64 rx_interrupts;
> > > +
> > > +	__le64 rx_drops;
> > > +	__le64 rx_drop_overruns;
> > > +};
> > > +
> > > +struct virtio_net_stats_tx_basic {
> > > +	struct virtio_net_stats_reply_hdr hdr;
> > > +
> > > +	__le64 tx_notifications;
> > > +
> > > +	__le64 tx_packets;
> > > +	__le64 tx_bytes;
> > > +
> > > +	__le64 tx_interrupts;
> > > +
> > > +	__le64 tx_drops;
> > > +	__le64 tx_drop_malformed;
> > > +};
> > > +
> > > +struct virtio_net_stats_rx_csum {
> > > +	struct virtio_net_stats_reply_hdr hdr;
> > > +
> > > +	__le64 rx_csum_valid;
> > > +	__le64 rx_needs_csum;
> > > +	__le64 rx_csum_none;
> > > +	__le64 rx_csum_bad;
> > > +};
> > > +
> > > +struct virtio_net_stats_tx_csum {
> > > +	struct virtio_net_stats_reply_hdr hdr;
> > > +
> > > +	__le64 tx_csum_none;
> > > +	__le64 tx_needs_csum;
> > > +};
> > > +
> > > +struct virtio_net_stats_rx_gso {
> > > +	struct virtio_net_stats_reply_hdr hdr;
> > > +
> > > +	__le64 rx_gso_packets;
> > > +	__le64 rx_gso_bytes;
> > > +	__le64 rx_gso_packets_coalesced;
> > > +	__le64 rx_gso_bytes_coalesced;
> > > +};
> > > +
> > > +struct virtio_net_stats_tx_gso {
> > > +	struct virtio_net_stats_reply_hdr hdr;
> > > +
> > > +	__le64 tx_gso_packets;
> > > +	__le64 tx_gso_bytes;
> > > +	__le64 tx_gso_segments;
> > > +	__le64 tx_gso_segments_bytes;
> > > +	__le64 tx_gso_packets_noseg;
> > > +	__le64 tx_gso_bytes_noseg;
> > > +};
> > > +
> > > +struct virtio_net_stats_rx_speed {
> > > +	struct virtio_net_stats_reply_hdr hdr;
> > > +
> > > +	__le64 rx_packets_allowance_exceeded;
> > > +	__le64 rx_bytes_allowance_exceeded;
> > > +};
> > > +
> > > +struct virtio_net_stats_tx_speed {
> > > +	struct virtio_net_stats_reply_hdr hdr;
> > > +
> > > +	__le64 tx_packets_allowance_exceeded;
> > > +	__le64 tx_bytes_allowance_exceeded;
> > > +};
> > > +
> > >   #endif /* _UAPI_LINUX_VIRTIO_NET_H */
> >
Xuan Zhuo Dec. 26, 2023, 9 a.m. UTC | #6
On Tue, 26 Dec 2023 03:58:37 -0500, "Michael S. Tsirkin" <mst@redhat.com> wrote:
> On Tue, Dec 26, 2023 at 02:17:43PM +0800, Xuan Zhuo wrote:
> > On Mon, 25 Dec 2023 16:01:39 +0800, Zhu Yanjun <yanjun.zhu@linux.dev> wrote:
> > > 在 2023/12/22 11:30, Xuan Zhuo 写道:
> > > > The virtio-net device stats spec:
> > > >
> > > > https://github.com/oasis-tcs/virtio-spec/commit/42f389989823039724f95bbbd243291ab0064f82
> > > >
> > > > This commit introduces the relative feature and structures.
> > >
> > > Hi, Xuan
> > >
> > > After applying this patch series, withe ethtool version 6.5,
> > > I got the following NIC statistics. But I do not find the statistics
> > > mentioned in this patch series.
> > > Do I miss something?
> >
> > This needs the new virtio-net feature VIRTIO_NET_F_DEVICE_STATS.
> > You need to update the hypervisor. But the qemu may not support this.
> >
> > Thanks.
>
> Why not? Can you add this to QEMU?


Yes. It is in my list.

But in my plan, I want the kernel to support this firstly.

Thanks.


>
>
> >
> >
> > >
> > > "
> > > NIC statistics:
> > >       rx_packets: 3434812669
> > >       rx_bytes: 5168475253690
> > >       rx_drops: 0
> > >       rx_xdp_packets: 0
> > >       rx_xdp_tx: 0
> > >       rx_xdp_redirects: 0
> > >       rx_xdp_drops: 0
> > >       rx_kicks: 57179891
> > >       tx_packets: 187694230
> > >       tx_bytes: 12423799040
> > >       tx_xdp_tx: 0
> > >       tx_xdp_tx_drops: 0
> > >       tx_kicks: 187694230
> > >       tx_timeouts: 0
> > >       rx_queue_0_packets: 866027381
> > >       rx_queue_0_bytes: 1302726908150
> > >       rx_queue_0_drops: 0
> > >       rx_queue_0_xdp_packets: 0
> > >       rx_queue_0_xdp_tx: 0
> > >       rx_queue_0_xdp_redirects: 0
> > >       rx_queue_0_xdp_drops: 0
> > >       rx_queue_0_kicks: 14567691
> > >       rx_queue_1_packets: 856758801
> > >       rx_queue_1_bytes: 1289899049042
> > >       rx_queue_1_drops: 0
> > >       rx_queue_1_xdp_packets: 0
> > >       rx_queue_1_xdp_tx: 0
> > >       rx_queue_1_xdp_redirects: 0
> > >       rx_queue_1_xdp_drops: 0
> > >       rx_queue_1_kicks: 14265201
> > >       rx_queue_2_packets: 839291053
> > >       rx_queue_2_bytes: 1261620863886
> > >       rx_queue_2_drops: 0
> > >       rx_queue_2_xdp_packets: 0
> > >       rx_queue_2_xdp_tx: 0
> > >       rx_queue_2_xdp_redirects: 0
> > >       rx_queue_2_xdp_drops: 0
> > >       rx_queue_2_kicks: 13857653
> > >       rx_queue_3_packets: 872735434
> > >       rx_queue_3_bytes: 1314228432612
> > >       rx_queue_3_drops: 0
> > >       rx_queue_3_xdp_packets: 0
> > >       rx_queue_3_xdp_tx: 0
> > >       rx_queue_3_xdp_redirects: 0
> > >       rx_queue_3_xdp_drops: 0
> > >       rx_queue_3_kicks: 14489346
> > >       tx_queue_0_packets: 75723
> > >       tx_queue_0_bytes: 4999030
> > >       tx_queue_0_xdp_tx: 0
> > >       tx_queue_0_xdp_tx_drops: 0
> > >       tx_queue_0_kicks: 75723
> > >       tx_queue_0_timeouts: 0
> > >       tx_queue_1_packets: 62262921
> > >       tx_queue_1_bytes: 4134803914
> > >       tx_queue_1_xdp_tx: 0
> > >       tx_queue_1_xdp_tx_drops: 0
> > >       tx_queue_1_kicks: 62262921
> > >       tx_queue_1_timeouts: 0
> > >       tx_queue_2_packets: 83
> > >       tx_queue_2_bytes: 5478
> > >       tx_queue_2_xdp_tx: 0
> > >       tx_queue_2_xdp_tx_drops: 0
> > >       tx_queue_2_kicks: 83
> > >       tx_queue_2_timeouts: 0
> > >       tx_queue_3_packets: 125355503
> > >       tx_queue_3_bytes: 8283990618
> > >       tx_queue_3_xdp_tx: 0
> > >       tx_queue_3_xdp_tx_drops: 0
> > >       tx_queue_3_kicks: 125355503
> > >       tx_queue_3_timeouts: 0
> > > "
> > >
> > > >
> > > > Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> > > > ---
> > > >   include/uapi/linux/virtio_net.h | 137 ++++++++++++++++++++++++++++++++
> > > >   1 file changed, 137 insertions(+)
> > > >
> > > > diff --git a/include/uapi/linux/virtio_net.h b/include/uapi/linux/virtio_net.h
> > > > index cc65ef0f3c3e..129e0871d28f 100644
> > > > --- a/include/uapi/linux/virtio_net.h
> > > > +++ b/include/uapi/linux/virtio_net.h
> > > > @@ -56,6 +56,7 @@
> > > >   #define VIRTIO_NET_F_MQ	22	/* Device supports Receive Flow
> > > >   					 * Steering */
> > > >   #define VIRTIO_NET_F_CTRL_MAC_ADDR 23	/* Set MAC address */
> > > > +#define VIRTIO_NET_F_DEVICE_STATS 50	/* Device can provide device-level statistics. */
> > > >   #define VIRTIO_NET_F_VQ_NOTF_COAL 52	/* Device supports virtqueue notification coalescing */
> > > >   #define VIRTIO_NET_F_NOTF_COAL	53	/* Device supports notifications coalescing */
> > > >   #define VIRTIO_NET_F_GUEST_USO4	54	/* Guest can handle USOv4 in. */
> > > > @@ -406,4 +407,140 @@ struct  virtio_net_ctrl_coal_vq {
> > > >   	struct virtio_net_ctrl_coal coal;
> > > >   };
> > > >
> > > > +/*
> > > > + * Device Statistics
> > > > + */
> > > > +#define VIRTIO_NET_CTRL_STATS         8
> > > > +#define VIRTIO_NET_CTRL_STATS_QUERY   0
> > > > +#define VIRTIO_NET_CTRL_STATS_GET     1
> > > > +
> > > > +struct virtio_net_stats_capabilities {
> > > > +
> > > > +#define VIRTIO_NET_STATS_TYPE_CVQ       (1L << 32)
> > > > +
> > > > +#define VIRTIO_NET_STATS_TYPE_RX_BASIC  (1 << 0)
> > > > +#define VIRTIO_NET_STATS_TYPE_RX_CSUM   (1 << 1)
> > > > +#define VIRTIO_NET_STATS_TYPE_RX_GSO    (1 << 2)
> > > > +#define VIRTIO_NET_STATS_TYPE_RX_SPEED  (1 << 3)
> > > > +
> > > > +#define VIRTIO_NET_STATS_TYPE_TX_BASIC  (1 << 16)
> > > > +#define VIRTIO_NET_STATS_TYPE_TX_CSUM   (1 << 17)
> > > > +#define VIRTIO_NET_STATS_TYPE_TX_GSO    (1 << 18)
> > > > +#define VIRTIO_NET_STATS_TYPE_TX_SPEED  (1 << 19)
> > > > +
> > > > +	__le64 supported_stats_types[1];
> > > > +};
> > > > +
> > > > +struct virtio_net_ctrl_queue_stats {
> > > > +	struct {
> > > > +		__le16 vq_index;
> > > > +		__le16 reserved[3];
> > > > +		__le64 types_bitmap[1];
> > > > +	} stats[1];
> > > > +};
> > > > +
> > > > +struct virtio_net_stats_reply_hdr {
> > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_CVQ       32
> > > > +
> > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_RX_BASIC  0
> > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_RX_CSUM   1
> > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_RX_GSO    2
> > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_RX_SPEED  3
> > > > +
> > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_TX_BASIC  16
> > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_TX_CSUM   17
> > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_TX_GSO    18
> > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_TX_SPEED  19
> > > > +	u8 type;
> > > > +	u8 reserved;
> > > > +	__le16 vq_index;
> > > > +	__le16 reserved1;
> > > > +	__le16 size;
> > > > +};
> > > > +
> > > > +struct virtio_net_stats_cvq {
> > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > +
> > > > +	__le64 command_num;
> > > > +	__le64 ok_num;
> > > > +};
> > > > +
> > > > +struct virtio_net_stats_rx_basic {
> > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > +
> > > > +	__le64 rx_notifications;
> > > > +
> > > > +	__le64 rx_packets;
> > > > +	__le64 rx_bytes;
> > > > +
> > > > +	__le64 rx_interrupts;
> > > > +
> > > > +	__le64 rx_drops;
> > > > +	__le64 rx_drop_overruns;
> > > > +};
> > > > +
> > > > +struct virtio_net_stats_tx_basic {
> > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > +
> > > > +	__le64 tx_notifications;
> > > > +
> > > > +	__le64 tx_packets;
> > > > +	__le64 tx_bytes;
> > > > +
> > > > +	__le64 tx_interrupts;
> > > > +
> > > > +	__le64 tx_drops;
> > > > +	__le64 tx_drop_malformed;
> > > > +};
> > > > +
> > > > +struct virtio_net_stats_rx_csum {
> > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > +
> > > > +	__le64 rx_csum_valid;
> > > > +	__le64 rx_needs_csum;
> > > > +	__le64 rx_csum_none;
> > > > +	__le64 rx_csum_bad;
> > > > +};
> > > > +
> > > > +struct virtio_net_stats_tx_csum {
> > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > +
> > > > +	__le64 tx_csum_none;
> > > > +	__le64 tx_needs_csum;
> > > > +};
> > > > +
> > > > +struct virtio_net_stats_rx_gso {
> > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > +
> > > > +	__le64 rx_gso_packets;
> > > > +	__le64 rx_gso_bytes;
> > > > +	__le64 rx_gso_packets_coalesced;
> > > > +	__le64 rx_gso_bytes_coalesced;
> > > > +};
> > > > +
> > > > +struct virtio_net_stats_tx_gso {
> > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > +
> > > > +	__le64 tx_gso_packets;
> > > > +	__le64 tx_gso_bytes;
> > > > +	__le64 tx_gso_segments;
> > > > +	__le64 tx_gso_segments_bytes;
> > > > +	__le64 tx_gso_packets_noseg;
> > > > +	__le64 tx_gso_bytes_noseg;
> > > > +};
> > > > +
> > > > +struct virtio_net_stats_rx_speed {
> > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > +
> > > > +	__le64 rx_packets_allowance_exceeded;
> > > > +	__le64 rx_bytes_allowance_exceeded;
> > > > +};
> > > > +
> > > > +struct virtio_net_stats_tx_speed {
> > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > +
> > > > +	__le64 tx_packets_allowance_exceeded;
> > > > +	__le64 tx_bytes_allowance_exceeded;
> > > > +};
> > > > +
> > > >   #endif /* _UAPI_LINUX_VIRTIO_NET_H */
> > >
>
>
Michael S. Tsirkin Dec. 26, 2023, 9:08 a.m. UTC | #7
On Tue, Dec 26, 2023 at 05:00:25PM +0800, Xuan Zhuo wrote:
> On Tue, 26 Dec 2023 03:58:37 -0500, "Michael S. Tsirkin" <mst@redhat.com> wrote:
> > On Tue, Dec 26, 2023 at 02:17:43PM +0800, Xuan Zhuo wrote:
> > > On Mon, 25 Dec 2023 16:01:39 +0800, Zhu Yanjun <yanjun.zhu@linux.dev> wrote:
> > > > 在 2023/12/22 11:30, Xuan Zhuo 写道:
> > > > > The virtio-net device stats spec:
> > > > >
> > > > > https://github.com/oasis-tcs/virtio-spec/commit/42f389989823039724f95bbbd243291ab0064f82
> > > > >
> > > > > This commit introduces the relative feature and structures.
> > > >
> > > > Hi, Xuan
> > > >
> > > > After applying this patch series, withe ethtool version 6.5,
> > > > I got the following NIC statistics. But I do not find the statistics
> > > > mentioned in this patch series.
> > > > Do I miss something?
> > >
> > > This needs the new virtio-net feature VIRTIO_NET_F_DEVICE_STATS.
> > > You need to update the hypervisor. But the qemu may not support this.
> > >
> > > Thanks.
> >
> > Why not? Can you add this to QEMU?
> 
> 
> Yes. It is in my list.
> 
> But in my plan, I want the kernel to support this firstly.
> 
> Thanks.

QEMU support would mean it's much better tested.
How did you test this one?

> 
> >
> >
> > >
> > >
> > > >
> > > > "
> > > > NIC statistics:
> > > >       rx_packets: 3434812669
> > > >       rx_bytes: 5168475253690
> > > >       rx_drops: 0
> > > >       rx_xdp_packets: 0
> > > >       rx_xdp_tx: 0
> > > >       rx_xdp_redirects: 0
> > > >       rx_xdp_drops: 0
> > > >       rx_kicks: 57179891
> > > >       tx_packets: 187694230
> > > >       tx_bytes: 12423799040
> > > >       tx_xdp_tx: 0
> > > >       tx_xdp_tx_drops: 0
> > > >       tx_kicks: 187694230
> > > >       tx_timeouts: 0
> > > >       rx_queue_0_packets: 866027381
> > > >       rx_queue_0_bytes: 1302726908150
> > > >       rx_queue_0_drops: 0
> > > >       rx_queue_0_xdp_packets: 0
> > > >       rx_queue_0_xdp_tx: 0
> > > >       rx_queue_0_xdp_redirects: 0
> > > >       rx_queue_0_xdp_drops: 0
> > > >       rx_queue_0_kicks: 14567691
> > > >       rx_queue_1_packets: 856758801
> > > >       rx_queue_1_bytes: 1289899049042
> > > >       rx_queue_1_drops: 0
> > > >       rx_queue_1_xdp_packets: 0
> > > >       rx_queue_1_xdp_tx: 0
> > > >       rx_queue_1_xdp_redirects: 0
> > > >       rx_queue_1_xdp_drops: 0
> > > >       rx_queue_1_kicks: 14265201
> > > >       rx_queue_2_packets: 839291053
> > > >       rx_queue_2_bytes: 1261620863886
> > > >       rx_queue_2_drops: 0
> > > >       rx_queue_2_xdp_packets: 0
> > > >       rx_queue_2_xdp_tx: 0
> > > >       rx_queue_2_xdp_redirects: 0
> > > >       rx_queue_2_xdp_drops: 0
> > > >       rx_queue_2_kicks: 13857653
> > > >       rx_queue_3_packets: 872735434
> > > >       rx_queue_3_bytes: 1314228432612
> > > >       rx_queue_3_drops: 0
> > > >       rx_queue_3_xdp_packets: 0
> > > >       rx_queue_3_xdp_tx: 0
> > > >       rx_queue_3_xdp_redirects: 0
> > > >       rx_queue_3_xdp_drops: 0
> > > >       rx_queue_3_kicks: 14489346
> > > >       tx_queue_0_packets: 75723
> > > >       tx_queue_0_bytes: 4999030
> > > >       tx_queue_0_xdp_tx: 0
> > > >       tx_queue_0_xdp_tx_drops: 0
> > > >       tx_queue_0_kicks: 75723
> > > >       tx_queue_0_timeouts: 0
> > > >       tx_queue_1_packets: 62262921
> > > >       tx_queue_1_bytes: 4134803914
> > > >       tx_queue_1_xdp_tx: 0
> > > >       tx_queue_1_xdp_tx_drops: 0
> > > >       tx_queue_1_kicks: 62262921
> > > >       tx_queue_1_timeouts: 0
> > > >       tx_queue_2_packets: 83
> > > >       tx_queue_2_bytes: 5478
> > > >       tx_queue_2_xdp_tx: 0
> > > >       tx_queue_2_xdp_tx_drops: 0
> > > >       tx_queue_2_kicks: 83
> > > >       tx_queue_2_timeouts: 0
> > > >       tx_queue_3_packets: 125355503
> > > >       tx_queue_3_bytes: 8283990618
> > > >       tx_queue_3_xdp_tx: 0
> > > >       tx_queue_3_xdp_tx_drops: 0
> > > >       tx_queue_3_kicks: 125355503
> > > >       tx_queue_3_timeouts: 0
> > > > "
> > > >
> > > > >
> > > > > Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> > > > > ---
> > > > >   include/uapi/linux/virtio_net.h | 137 ++++++++++++++++++++++++++++++++
> > > > >   1 file changed, 137 insertions(+)
> > > > >
> > > > > diff --git a/include/uapi/linux/virtio_net.h b/include/uapi/linux/virtio_net.h
> > > > > index cc65ef0f3c3e..129e0871d28f 100644
> > > > > --- a/include/uapi/linux/virtio_net.h
> > > > > +++ b/include/uapi/linux/virtio_net.h
> > > > > @@ -56,6 +56,7 @@
> > > > >   #define VIRTIO_NET_F_MQ	22	/* Device supports Receive Flow
> > > > >   					 * Steering */
> > > > >   #define VIRTIO_NET_F_CTRL_MAC_ADDR 23	/* Set MAC address */
> > > > > +#define VIRTIO_NET_F_DEVICE_STATS 50	/* Device can provide device-level statistics. */
> > > > >   #define VIRTIO_NET_F_VQ_NOTF_COAL 52	/* Device supports virtqueue notification coalescing */
> > > > >   #define VIRTIO_NET_F_NOTF_COAL	53	/* Device supports notifications coalescing */
> > > > >   #define VIRTIO_NET_F_GUEST_USO4	54	/* Guest can handle USOv4 in. */
> > > > > @@ -406,4 +407,140 @@ struct  virtio_net_ctrl_coal_vq {
> > > > >   	struct virtio_net_ctrl_coal coal;
> > > > >   };
> > > > >
> > > > > +/*
> > > > > + * Device Statistics
> > > > > + */
> > > > > +#define VIRTIO_NET_CTRL_STATS         8
> > > > > +#define VIRTIO_NET_CTRL_STATS_QUERY   0
> > > > > +#define VIRTIO_NET_CTRL_STATS_GET     1
> > > > > +
> > > > > +struct virtio_net_stats_capabilities {
> > > > > +
> > > > > +#define VIRTIO_NET_STATS_TYPE_CVQ       (1L << 32)
> > > > > +
> > > > > +#define VIRTIO_NET_STATS_TYPE_RX_BASIC  (1 << 0)
> > > > > +#define VIRTIO_NET_STATS_TYPE_RX_CSUM   (1 << 1)
> > > > > +#define VIRTIO_NET_STATS_TYPE_RX_GSO    (1 << 2)
> > > > > +#define VIRTIO_NET_STATS_TYPE_RX_SPEED  (1 << 3)
> > > > > +
> > > > > +#define VIRTIO_NET_STATS_TYPE_TX_BASIC  (1 << 16)
> > > > > +#define VIRTIO_NET_STATS_TYPE_TX_CSUM   (1 << 17)
> > > > > +#define VIRTIO_NET_STATS_TYPE_TX_GSO    (1 << 18)
> > > > > +#define VIRTIO_NET_STATS_TYPE_TX_SPEED  (1 << 19)
> > > > > +
> > > > > +	__le64 supported_stats_types[1];
> > > > > +};
> > > > > +
> > > > > +struct virtio_net_ctrl_queue_stats {
> > > > > +	struct {
> > > > > +		__le16 vq_index;
> > > > > +		__le16 reserved[3];
> > > > > +		__le64 types_bitmap[1];
> > > > > +	} stats[1];
> > > > > +};
> > > > > +
> > > > > +struct virtio_net_stats_reply_hdr {
> > > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_CVQ       32
> > > > > +
> > > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_RX_BASIC  0
> > > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_RX_CSUM   1
> > > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_RX_GSO    2
> > > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_RX_SPEED  3
> > > > > +
> > > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_TX_BASIC  16
> > > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_TX_CSUM   17
> > > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_TX_GSO    18
> > > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_TX_SPEED  19
> > > > > +	u8 type;
> > > > > +	u8 reserved;
> > > > > +	__le16 vq_index;
> > > > > +	__le16 reserved1;
> > > > > +	__le16 size;
> > > > > +};
> > > > > +
> > > > > +struct virtio_net_stats_cvq {
> > > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > > +
> > > > > +	__le64 command_num;
> > > > > +	__le64 ok_num;
> > > > > +};
> > > > > +
> > > > > +struct virtio_net_stats_rx_basic {
> > > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > > +
> > > > > +	__le64 rx_notifications;
> > > > > +
> > > > > +	__le64 rx_packets;
> > > > > +	__le64 rx_bytes;
> > > > > +
> > > > > +	__le64 rx_interrupts;
> > > > > +
> > > > > +	__le64 rx_drops;
> > > > > +	__le64 rx_drop_overruns;
> > > > > +};
> > > > > +
> > > > > +struct virtio_net_stats_tx_basic {
> > > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > > +
> > > > > +	__le64 tx_notifications;
> > > > > +
> > > > > +	__le64 tx_packets;
> > > > > +	__le64 tx_bytes;
> > > > > +
> > > > > +	__le64 tx_interrupts;
> > > > > +
> > > > > +	__le64 tx_drops;
> > > > > +	__le64 tx_drop_malformed;
> > > > > +};
> > > > > +
> > > > > +struct virtio_net_stats_rx_csum {
> > > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > > +
> > > > > +	__le64 rx_csum_valid;
> > > > > +	__le64 rx_needs_csum;
> > > > > +	__le64 rx_csum_none;
> > > > > +	__le64 rx_csum_bad;
> > > > > +};
> > > > > +
> > > > > +struct virtio_net_stats_tx_csum {
> > > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > > +
> > > > > +	__le64 tx_csum_none;
> > > > > +	__le64 tx_needs_csum;
> > > > > +};
> > > > > +
> > > > > +struct virtio_net_stats_rx_gso {
> > > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > > +
> > > > > +	__le64 rx_gso_packets;
> > > > > +	__le64 rx_gso_bytes;
> > > > > +	__le64 rx_gso_packets_coalesced;
> > > > > +	__le64 rx_gso_bytes_coalesced;
> > > > > +};
> > > > > +
> > > > > +struct virtio_net_stats_tx_gso {
> > > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > > +
> > > > > +	__le64 tx_gso_packets;
> > > > > +	__le64 tx_gso_bytes;
> > > > > +	__le64 tx_gso_segments;
> > > > > +	__le64 tx_gso_segments_bytes;
> > > > > +	__le64 tx_gso_packets_noseg;
> > > > > +	__le64 tx_gso_bytes_noseg;
> > > > > +};
> > > > > +
> > > > > +struct virtio_net_stats_rx_speed {
> > > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > > +
> > > > > +	__le64 rx_packets_allowance_exceeded;
> > > > > +	__le64 rx_bytes_allowance_exceeded;
> > > > > +};
> > > > > +
> > > > > +struct virtio_net_stats_tx_speed {
> > > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > > +
> > > > > +	__le64 tx_packets_allowance_exceeded;
> > > > > +	__le64 tx_bytes_allowance_exceeded;
> > > > > +};
> > > > > +
> > > > >   #endif /* _UAPI_LINUX_VIRTIO_NET_H */
> > > >
> >
> >
Xuan Zhuo Dec. 26, 2023, 9:09 a.m. UTC | #8
On Tue, 26 Dec 2023 04:08:01 -0500, "Michael S. Tsirkin" <mst@redhat.com> wrote:
> On Tue, Dec 26, 2023 at 05:00:25PM +0800, Xuan Zhuo wrote:
> > On Tue, 26 Dec 2023 03:58:37 -0500, "Michael S. Tsirkin" <mst@redhat.com> wrote:
> > > On Tue, Dec 26, 2023 at 02:17:43PM +0800, Xuan Zhuo wrote:
> > > > On Mon, 25 Dec 2023 16:01:39 +0800, Zhu Yanjun <yanjun.zhu@linux.dev> wrote:
> > > > > 在 2023/12/22 11:30, Xuan Zhuo 写道:
> > > > > > The virtio-net device stats spec:
> > > > > >
> > > > > > https://github.com/oasis-tcs/virtio-spec/commit/42f389989823039724f95bbbd243291ab0064f82
> > > > > >
> > > > > > This commit introduces the relative feature and structures.
> > > > >
> > > > > Hi, Xuan
> > > > >
> > > > > After applying this patch series, withe ethtool version 6.5,
> > > > > I got the following NIC statistics. But I do not find the statistics
> > > > > mentioned in this patch series.
> > > > > Do I miss something?
> > > >
> > > > This needs the new virtio-net feature VIRTIO_NET_F_DEVICE_STATS.
> > > > You need to update the hypervisor. But the qemu may not support this.
> > > >
> > > > Thanks.
> > >
> > > Why not? Can you add this to QEMU?
> >
> >
> > Yes. It is in my list.
> >
> > But in my plan, I want the kernel to support this firstly.
> >
> > Thanks.
>
> QEMU support would mean it's much better tested.
> How did you test this one?

With our DPU.

Thanks.


>
> >
> > >
> > >
> > > >
> > > >
> > > > >
> > > > > "
> > > > > NIC statistics:
> > > > >       rx_packets: 3434812669
> > > > >       rx_bytes: 5168475253690
> > > > >       rx_drops: 0
> > > > >       rx_xdp_packets: 0
> > > > >       rx_xdp_tx: 0
> > > > >       rx_xdp_redirects: 0
> > > > >       rx_xdp_drops: 0
> > > > >       rx_kicks: 57179891
> > > > >       tx_packets: 187694230
> > > > >       tx_bytes: 12423799040
> > > > >       tx_xdp_tx: 0
> > > > >       tx_xdp_tx_drops: 0
> > > > >       tx_kicks: 187694230
> > > > >       tx_timeouts: 0
> > > > >       rx_queue_0_packets: 866027381
> > > > >       rx_queue_0_bytes: 1302726908150
> > > > >       rx_queue_0_drops: 0
> > > > >       rx_queue_0_xdp_packets: 0
> > > > >       rx_queue_0_xdp_tx: 0
> > > > >       rx_queue_0_xdp_redirects: 0
> > > > >       rx_queue_0_xdp_drops: 0
> > > > >       rx_queue_0_kicks: 14567691
> > > > >       rx_queue_1_packets: 856758801
> > > > >       rx_queue_1_bytes: 1289899049042
> > > > >       rx_queue_1_drops: 0
> > > > >       rx_queue_1_xdp_packets: 0
> > > > >       rx_queue_1_xdp_tx: 0
> > > > >       rx_queue_1_xdp_redirects: 0
> > > > >       rx_queue_1_xdp_drops: 0
> > > > >       rx_queue_1_kicks: 14265201
> > > > >       rx_queue_2_packets: 839291053
> > > > >       rx_queue_2_bytes: 1261620863886
> > > > >       rx_queue_2_drops: 0
> > > > >       rx_queue_2_xdp_packets: 0
> > > > >       rx_queue_2_xdp_tx: 0
> > > > >       rx_queue_2_xdp_redirects: 0
> > > > >       rx_queue_2_xdp_drops: 0
> > > > >       rx_queue_2_kicks: 13857653
> > > > >       rx_queue_3_packets: 872735434
> > > > >       rx_queue_3_bytes: 1314228432612
> > > > >       rx_queue_3_drops: 0
> > > > >       rx_queue_3_xdp_packets: 0
> > > > >       rx_queue_3_xdp_tx: 0
> > > > >       rx_queue_3_xdp_redirects: 0
> > > > >       rx_queue_3_xdp_drops: 0
> > > > >       rx_queue_3_kicks: 14489346
> > > > >       tx_queue_0_packets: 75723
> > > > >       tx_queue_0_bytes: 4999030
> > > > >       tx_queue_0_xdp_tx: 0
> > > > >       tx_queue_0_xdp_tx_drops: 0
> > > > >       tx_queue_0_kicks: 75723
> > > > >       tx_queue_0_timeouts: 0
> > > > >       tx_queue_1_packets: 62262921
> > > > >       tx_queue_1_bytes: 4134803914
> > > > >       tx_queue_1_xdp_tx: 0
> > > > >       tx_queue_1_xdp_tx_drops: 0
> > > > >       tx_queue_1_kicks: 62262921
> > > > >       tx_queue_1_timeouts: 0
> > > > >       tx_queue_2_packets: 83
> > > > >       tx_queue_2_bytes: 5478
> > > > >       tx_queue_2_xdp_tx: 0
> > > > >       tx_queue_2_xdp_tx_drops: 0
> > > > >       tx_queue_2_kicks: 83
> > > > >       tx_queue_2_timeouts: 0
> > > > >       tx_queue_3_packets: 125355503
> > > > >       tx_queue_3_bytes: 8283990618
> > > > >       tx_queue_3_xdp_tx: 0
> > > > >       tx_queue_3_xdp_tx_drops: 0
> > > > >       tx_queue_3_kicks: 125355503
> > > > >       tx_queue_3_timeouts: 0
> > > > > "
> > > > >
> > > > > >
> > > > > > Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> > > > > > ---
> > > > > >   include/uapi/linux/virtio_net.h | 137 ++++++++++++++++++++++++++++++++
> > > > > >   1 file changed, 137 insertions(+)
> > > > > >
> > > > > > diff --git a/include/uapi/linux/virtio_net.h b/include/uapi/linux/virtio_net.h
> > > > > > index cc65ef0f3c3e..129e0871d28f 100644
> > > > > > --- a/include/uapi/linux/virtio_net.h
> > > > > > +++ b/include/uapi/linux/virtio_net.h
> > > > > > @@ -56,6 +56,7 @@
> > > > > >   #define VIRTIO_NET_F_MQ	22	/* Device supports Receive Flow
> > > > > >   					 * Steering */
> > > > > >   #define VIRTIO_NET_F_CTRL_MAC_ADDR 23	/* Set MAC address */
> > > > > > +#define VIRTIO_NET_F_DEVICE_STATS 50	/* Device can provide device-level statistics. */
> > > > > >   #define VIRTIO_NET_F_VQ_NOTF_COAL 52	/* Device supports virtqueue notification coalescing */
> > > > > >   #define VIRTIO_NET_F_NOTF_COAL	53	/* Device supports notifications coalescing */
> > > > > >   #define VIRTIO_NET_F_GUEST_USO4	54	/* Guest can handle USOv4 in. */
> > > > > > @@ -406,4 +407,140 @@ struct  virtio_net_ctrl_coal_vq {
> > > > > >   	struct virtio_net_ctrl_coal coal;
> > > > > >   };
> > > > > >
> > > > > > +/*
> > > > > > + * Device Statistics
> > > > > > + */
> > > > > > +#define VIRTIO_NET_CTRL_STATS         8
> > > > > > +#define VIRTIO_NET_CTRL_STATS_QUERY   0
> > > > > > +#define VIRTIO_NET_CTRL_STATS_GET     1
> > > > > > +
> > > > > > +struct virtio_net_stats_capabilities {
> > > > > > +
> > > > > > +#define VIRTIO_NET_STATS_TYPE_CVQ       (1L << 32)
> > > > > > +
> > > > > > +#define VIRTIO_NET_STATS_TYPE_RX_BASIC  (1 << 0)
> > > > > > +#define VIRTIO_NET_STATS_TYPE_RX_CSUM   (1 << 1)
> > > > > > +#define VIRTIO_NET_STATS_TYPE_RX_GSO    (1 << 2)
> > > > > > +#define VIRTIO_NET_STATS_TYPE_RX_SPEED  (1 << 3)
> > > > > > +
> > > > > > +#define VIRTIO_NET_STATS_TYPE_TX_BASIC  (1 << 16)
> > > > > > +#define VIRTIO_NET_STATS_TYPE_TX_CSUM   (1 << 17)
> > > > > > +#define VIRTIO_NET_STATS_TYPE_TX_GSO    (1 << 18)
> > > > > > +#define VIRTIO_NET_STATS_TYPE_TX_SPEED  (1 << 19)
> > > > > > +
> > > > > > +	__le64 supported_stats_types[1];
> > > > > > +};
> > > > > > +
> > > > > > +struct virtio_net_ctrl_queue_stats {
> > > > > > +	struct {
> > > > > > +		__le16 vq_index;
> > > > > > +		__le16 reserved[3];
> > > > > > +		__le64 types_bitmap[1];
> > > > > > +	} stats[1];
> > > > > > +};
> > > > > > +
> > > > > > +struct virtio_net_stats_reply_hdr {
> > > > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_CVQ       32
> > > > > > +
> > > > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_RX_BASIC  0
> > > > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_RX_CSUM   1
> > > > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_RX_GSO    2
> > > > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_RX_SPEED  3
> > > > > > +
> > > > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_TX_BASIC  16
> > > > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_TX_CSUM   17
> > > > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_TX_GSO    18
> > > > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_TX_SPEED  19
> > > > > > +	u8 type;
> > > > > > +	u8 reserved;
> > > > > > +	__le16 vq_index;
> > > > > > +	__le16 reserved1;
> > > > > > +	__le16 size;
> > > > > > +};
> > > > > > +
> > > > > > +struct virtio_net_stats_cvq {
> > > > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > > > +
> > > > > > +	__le64 command_num;
> > > > > > +	__le64 ok_num;
> > > > > > +};
> > > > > > +
> > > > > > +struct virtio_net_stats_rx_basic {
> > > > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > > > +
> > > > > > +	__le64 rx_notifications;
> > > > > > +
> > > > > > +	__le64 rx_packets;
> > > > > > +	__le64 rx_bytes;
> > > > > > +
> > > > > > +	__le64 rx_interrupts;
> > > > > > +
> > > > > > +	__le64 rx_drops;
> > > > > > +	__le64 rx_drop_overruns;
> > > > > > +};
> > > > > > +
> > > > > > +struct virtio_net_stats_tx_basic {
> > > > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > > > +
> > > > > > +	__le64 tx_notifications;
> > > > > > +
> > > > > > +	__le64 tx_packets;
> > > > > > +	__le64 tx_bytes;
> > > > > > +
> > > > > > +	__le64 tx_interrupts;
> > > > > > +
> > > > > > +	__le64 tx_drops;
> > > > > > +	__le64 tx_drop_malformed;
> > > > > > +};
> > > > > > +
> > > > > > +struct virtio_net_stats_rx_csum {
> > > > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > > > +
> > > > > > +	__le64 rx_csum_valid;
> > > > > > +	__le64 rx_needs_csum;
> > > > > > +	__le64 rx_csum_none;
> > > > > > +	__le64 rx_csum_bad;
> > > > > > +};
> > > > > > +
> > > > > > +struct virtio_net_stats_tx_csum {
> > > > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > > > +
> > > > > > +	__le64 tx_csum_none;
> > > > > > +	__le64 tx_needs_csum;
> > > > > > +};
> > > > > > +
> > > > > > +struct virtio_net_stats_rx_gso {
> > > > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > > > +
> > > > > > +	__le64 rx_gso_packets;
> > > > > > +	__le64 rx_gso_bytes;
> > > > > > +	__le64 rx_gso_packets_coalesced;
> > > > > > +	__le64 rx_gso_bytes_coalesced;
> > > > > > +};
> > > > > > +
> > > > > > +struct virtio_net_stats_tx_gso {
> > > > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > > > +
> > > > > > +	__le64 tx_gso_packets;
> > > > > > +	__le64 tx_gso_bytes;
> > > > > > +	__le64 tx_gso_segments;
> > > > > > +	__le64 tx_gso_segments_bytes;
> > > > > > +	__le64 tx_gso_packets_noseg;
> > > > > > +	__le64 tx_gso_bytes_noseg;
> > > > > > +};
> > > > > > +
> > > > > > +struct virtio_net_stats_rx_speed {
> > > > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > > > +
> > > > > > +	__le64 rx_packets_allowance_exceeded;
> > > > > > +	__le64 rx_bytes_allowance_exceeded;
> > > > > > +};
> > > > > > +
> > > > > > +struct virtio_net_stats_tx_speed {
> > > > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > > > +
> > > > > > +	__le64 tx_packets_allowance_exceeded;
> > > > > > +	__le64 tx_bytes_allowance_exceeded;
> > > > > > +};
> > > > > > +
> > > > > >   #endif /* _UAPI_LINUX_VIRTIO_NET_H */
> > > > >
> > >
> > >
>
Michael S. Tsirkin Dec. 26, 2023, 9:19 a.m. UTC | #9
On Tue, Dec 26, 2023 at 05:09:21PM +0800, Xuan Zhuo wrote:
> On Tue, 26 Dec 2023 04:08:01 -0500, "Michael S. Tsirkin" <mst@redhat.com> wrote:
> > On Tue, Dec 26, 2023 at 05:00:25PM +0800, Xuan Zhuo wrote:
> > > On Tue, 26 Dec 2023 03:58:37 -0500, "Michael S. Tsirkin" <mst@redhat.com> wrote:
> > > > On Tue, Dec 26, 2023 at 02:17:43PM +0800, Xuan Zhuo wrote:
> > > > > On Mon, 25 Dec 2023 16:01:39 +0800, Zhu Yanjun <yanjun.zhu@linux.dev> wrote:
> > > > > > 在 2023/12/22 11:30, Xuan Zhuo 写道:
> > > > > > > The virtio-net device stats spec:
> > > > > > >
> > > > > > > https://github.com/oasis-tcs/virtio-spec/commit/42f389989823039724f95bbbd243291ab0064f82
> > > > > > >
> > > > > > > This commit introduces the relative feature and structures.
> > > > > >
> > > > > > Hi, Xuan
> > > > > >
> > > > > > After applying this patch series, withe ethtool version 6.5,
> > > > > > I got the following NIC statistics. But I do not find the statistics
> > > > > > mentioned in this patch series.
> > > > > > Do I miss something?
> > > > >
> > > > > This needs the new virtio-net feature VIRTIO_NET_F_DEVICE_STATS.
> > > > > You need to update the hypervisor. But the qemu may not support this.
> > > > >
> > > > > Thanks.
> > > >
> > > > Why not? Can you add this to QEMU?
> > >
> > >
> > > Yes. It is in my list.
> > >
> > > But in my plan, I want the kernel to support this firstly.
> > >
> > > Thanks.
> >
> > QEMU support would mean it's much better tested.
> > How did you test this one?
> 
> With our DPU.
> 
> Thanks.
> 

Well if QEMU support is there then Zhu Yanjun here can test it.


> >
> > >
> > > >
> > > >
> > > > >
> > > > >
> > > > > >
> > > > > > "
> > > > > > NIC statistics:
> > > > > >       rx_packets: 3434812669
> > > > > >       rx_bytes: 5168475253690
> > > > > >       rx_drops: 0
> > > > > >       rx_xdp_packets: 0
> > > > > >       rx_xdp_tx: 0
> > > > > >       rx_xdp_redirects: 0
> > > > > >       rx_xdp_drops: 0
> > > > > >       rx_kicks: 57179891
> > > > > >       tx_packets: 187694230
> > > > > >       tx_bytes: 12423799040
> > > > > >       tx_xdp_tx: 0
> > > > > >       tx_xdp_tx_drops: 0
> > > > > >       tx_kicks: 187694230
> > > > > >       tx_timeouts: 0
> > > > > >       rx_queue_0_packets: 866027381
> > > > > >       rx_queue_0_bytes: 1302726908150
> > > > > >       rx_queue_0_drops: 0
> > > > > >       rx_queue_0_xdp_packets: 0
> > > > > >       rx_queue_0_xdp_tx: 0
> > > > > >       rx_queue_0_xdp_redirects: 0
> > > > > >       rx_queue_0_xdp_drops: 0
> > > > > >       rx_queue_0_kicks: 14567691
> > > > > >       rx_queue_1_packets: 856758801
> > > > > >       rx_queue_1_bytes: 1289899049042
> > > > > >       rx_queue_1_drops: 0
> > > > > >       rx_queue_1_xdp_packets: 0
> > > > > >       rx_queue_1_xdp_tx: 0
> > > > > >       rx_queue_1_xdp_redirects: 0
> > > > > >       rx_queue_1_xdp_drops: 0
> > > > > >       rx_queue_1_kicks: 14265201
> > > > > >       rx_queue_2_packets: 839291053
> > > > > >       rx_queue_2_bytes: 1261620863886
> > > > > >       rx_queue_2_drops: 0
> > > > > >       rx_queue_2_xdp_packets: 0
> > > > > >       rx_queue_2_xdp_tx: 0
> > > > > >       rx_queue_2_xdp_redirects: 0
> > > > > >       rx_queue_2_xdp_drops: 0
> > > > > >       rx_queue_2_kicks: 13857653
> > > > > >       rx_queue_3_packets: 872735434
> > > > > >       rx_queue_3_bytes: 1314228432612
> > > > > >       rx_queue_3_drops: 0
> > > > > >       rx_queue_3_xdp_packets: 0
> > > > > >       rx_queue_3_xdp_tx: 0
> > > > > >       rx_queue_3_xdp_redirects: 0
> > > > > >       rx_queue_3_xdp_drops: 0
> > > > > >       rx_queue_3_kicks: 14489346
> > > > > >       tx_queue_0_packets: 75723
> > > > > >       tx_queue_0_bytes: 4999030
> > > > > >       tx_queue_0_xdp_tx: 0
> > > > > >       tx_queue_0_xdp_tx_drops: 0
> > > > > >       tx_queue_0_kicks: 75723
> > > > > >       tx_queue_0_timeouts: 0
> > > > > >       tx_queue_1_packets: 62262921
> > > > > >       tx_queue_1_bytes: 4134803914
> > > > > >       tx_queue_1_xdp_tx: 0
> > > > > >       tx_queue_1_xdp_tx_drops: 0
> > > > > >       tx_queue_1_kicks: 62262921
> > > > > >       tx_queue_1_timeouts: 0
> > > > > >       tx_queue_2_packets: 83
> > > > > >       tx_queue_2_bytes: 5478
> > > > > >       tx_queue_2_xdp_tx: 0
> > > > > >       tx_queue_2_xdp_tx_drops: 0
> > > > > >       tx_queue_2_kicks: 83
> > > > > >       tx_queue_2_timeouts: 0
> > > > > >       tx_queue_3_packets: 125355503
> > > > > >       tx_queue_3_bytes: 8283990618
> > > > > >       tx_queue_3_xdp_tx: 0
> > > > > >       tx_queue_3_xdp_tx_drops: 0
> > > > > >       tx_queue_3_kicks: 125355503
> > > > > >       tx_queue_3_timeouts: 0
> > > > > > "
> > > > > >
> > > > > > >
> > > > > > > Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> > > > > > > ---
> > > > > > >   include/uapi/linux/virtio_net.h | 137 ++++++++++++++++++++++++++++++++
> > > > > > >   1 file changed, 137 insertions(+)
> > > > > > >
> > > > > > > diff --git a/include/uapi/linux/virtio_net.h b/include/uapi/linux/virtio_net.h
> > > > > > > index cc65ef0f3c3e..129e0871d28f 100644
> > > > > > > --- a/include/uapi/linux/virtio_net.h
> > > > > > > +++ b/include/uapi/linux/virtio_net.h
> > > > > > > @@ -56,6 +56,7 @@
> > > > > > >   #define VIRTIO_NET_F_MQ	22	/* Device supports Receive Flow
> > > > > > >   					 * Steering */
> > > > > > >   #define VIRTIO_NET_F_CTRL_MAC_ADDR 23	/* Set MAC address */
> > > > > > > +#define VIRTIO_NET_F_DEVICE_STATS 50	/* Device can provide device-level statistics. */
> > > > > > >   #define VIRTIO_NET_F_VQ_NOTF_COAL 52	/* Device supports virtqueue notification coalescing */
> > > > > > >   #define VIRTIO_NET_F_NOTF_COAL	53	/* Device supports notifications coalescing */
> > > > > > >   #define VIRTIO_NET_F_GUEST_USO4	54	/* Guest can handle USOv4 in. */
> > > > > > > @@ -406,4 +407,140 @@ struct  virtio_net_ctrl_coal_vq {
> > > > > > >   	struct virtio_net_ctrl_coal coal;
> > > > > > >   };
> > > > > > >
> > > > > > > +/*
> > > > > > > + * Device Statistics
> > > > > > > + */
> > > > > > > +#define VIRTIO_NET_CTRL_STATS         8
> > > > > > > +#define VIRTIO_NET_CTRL_STATS_QUERY   0
> > > > > > > +#define VIRTIO_NET_CTRL_STATS_GET     1
> > > > > > > +
> > > > > > > +struct virtio_net_stats_capabilities {
> > > > > > > +
> > > > > > > +#define VIRTIO_NET_STATS_TYPE_CVQ       (1L << 32)
> > > > > > > +
> > > > > > > +#define VIRTIO_NET_STATS_TYPE_RX_BASIC  (1 << 0)
> > > > > > > +#define VIRTIO_NET_STATS_TYPE_RX_CSUM   (1 << 1)
> > > > > > > +#define VIRTIO_NET_STATS_TYPE_RX_GSO    (1 << 2)
> > > > > > > +#define VIRTIO_NET_STATS_TYPE_RX_SPEED  (1 << 3)
> > > > > > > +
> > > > > > > +#define VIRTIO_NET_STATS_TYPE_TX_BASIC  (1 << 16)
> > > > > > > +#define VIRTIO_NET_STATS_TYPE_TX_CSUM   (1 << 17)
> > > > > > > +#define VIRTIO_NET_STATS_TYPE_TX_GSO    (1 << 18)
> > > > > > > +#define VIRTIO_NET_STATS_TYPE_TX_SPEED  (1 << 19)
> > > > > > > +
> > > > > > > +	__le64 supported_stats_types[1];
> > > > > > > +};
> > > > > > > +
> > > > > > > +struct virtio_net_ctrl_queue_stats {
> > > > > > > +	struct {
> > > > > > > +		__le16 vq_index;
> > > > > > > +		__le16 reserved[3];
> > > > > > > +		__le64 types_bitmap[1];
> > > > > > > +	} stats[1];
> > > > > > > +};
> > > > > > > +
> > > > > > > +struct virtio_net_stats_reply_hdr {
> > > > > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_CVQ       32
> > > > > > > +
> > > > > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_RX_BASIC  0
> > > > > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_RX_CSUM   1
> > > > > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_RX_GSO    2
> > > > > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_RX_SPEED  3
> > > > > > > +
> > > > > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_TX_BASIC  16
> > > > > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_TX_CSUM   17
> > > > > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_TX_GSO    18
> > > > > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_TX_SPEED  19
> > > > > > > +	u8 type;
> > > > > > > +	u8 reserved;
> > > > > > > +	__le16 vq_index;
> > > > > > > +	__le16 reserved1;
> > > > > > > +	__le16 size;
> > > > > > > +};
> > > > > > > +
> > > > > > > +struct virtio_net_stats_cvq {
> > > > > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > > > > +
> > > > > > > +	__le64 command_num;
> > > > > > > +	__le64 ok_num;
> > > > > > > +};
> > > > > > > +
> > > > > > > +struct virtio_net_stats_rx_basic {
> > > > > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > > > > +
> > > > > > > +	__le64 rx_notifications;
> > > > > > > +
> > > > > > > +	__le64 rx_packets;
> > > > > > > +	__le64 rx_bytes;
> > > > > > > +
> > > > > > > +	__le64 rx_interrupts;
> > > > > > > +
> > > > > > > +	__le64 rx_drops;
> > > > > > > +	__le64 rx_drop_overruns;
> > > > > > > +};
> > > > > > > +
> > > > > > > +struct virtio_net_stats_tx_basic {
> > > > > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > > > > +
> > > > > > > +	__le64 tx_notifications;
> > > > > > > +
> > > > > > > +	__le64 tx_packets;
> > > > > > > +	__le64 tx_bytes;
> > > > > > > +
> > > > > > > +	__le64 tx_interrupts;
> > > > > > > +
> > > > > > > +	__le64 tx_drops;
> > > > > > > +	__le64 tx_drop_malformed;
> > > > > > > +};
> > > > > > > +
> > > > > > > +struct virtio_net_stats_rx_csum {
> > > > > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > > > > +
> > > > > > > +	__le64 rx_csum_valid;
> > > > > > > +	__le64 rx_needs_csum;
> > > > > > > +	__le64 rx_csum_none;
> > > > > > > +	__le64 rx_csum_bad;
> > > > > > > +};
> > > > > > > +
> > > > > > > +struct virtio_net_stats_tx_csum {
> > > > > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > > > > +
> > > > > > > +	__le64 tx_csum_none;
> > > > > > > +	__le64 tx_needs_csum;
> > > > > > > +};
> > > > > > > +
> > > > > > > +struct virtio_net_stats_rx_gso {
> > > > > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > > > > +
> > > > > > > +	__le64 rx_gso_packets;
> > > > > > > +	__le64 rx_gso_bytes;
> > > > > > > +	__le64 rx_gso_packets_coalesced;
> > > > > > > +	__le64 rx_gso_bytes_coalesced;
> > > > > > > +};
> > > > > > > +
> > > > > > > +struct virtio_net_stats_tx_gso {
> > > > > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > > > > +
> > > > > > > +	__le64 tx_gso_packets;
> > > > > > > +	__le64 tx_gso_bytes;
> > > > > > > +	__le64 tx_gso_segments;
> > > > > > > +	__le64 tx_gso_segments_bytes;
> > > > > > > +	__le64 tx_gso_packets_noseg;
> > > > > > > +	__le64 tx_gso_bytes_noseg;
> > > > > > > +};
> > > > > > > +
> > > > > > > +struct virtio_net_stats_rx_speed {
> > > > > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > > > > +
> > > > > > > +	__le64 rx_packets_allowance_exceeded;
> > > > > > > +	__le64 rx_bytes_allowance_exceeded;
> > > > > > > +};
> > > > > > > +
> > > > > > > +struct virtio_net_stats_tx_speed {
> > > > > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > > > > +
> > > > > > > +	__le64 tx_packets_allowance_exceeded;
> > > > > > > +	__le64 tx_bytes_allowance_exceeded;
> > > > > > > +};
> > > > > > > +
> > > > > > >   #endif /* _UAPI_LINUX_VIRTIO_NET_H */
> > > > > >
> > > >
> > > >
> >
Xuan Zhuo Dec. 26, 2023, 9:24 a.m. UTC | #10
On Tue, 26 Dec 2023 04:19:26 -0500, "Michael S. Tsirkin" <mst@redhat.com> wrote:
> On Tue, Dec 26, 2023 at 05:09:21PM +0800, Xuan Zhuo wrote:
> > On Tue, 26 Dec 2023 04:08:01 -0500, "Michael S. Tsirkin" <mst@redhat.com> wrote:
> > > On Tue, Dec 26, 2023 at 05:00:25PM +0800, Xuan Zhuo wrote:
> > > > On Tue, 26 Dec 2023 03:58:37 -0500, "Michael S. Tsirkin" <mst@redhat.com> wrote:
> > > > > On Tue, Dec 26, 2023 at 02:17:43PM +0800, Xuan Zhuo wrote:
> > > > > > On Mon, 25 Dec 2023 16:01:39 +0800, Zhu Yanjun <yanjun.zhu@linux.dev> wrote:
> > > > > > > 在 2023/12/22 11:30, Xuan Zhuo 写道:
> > > > > > > > The virtio-net device stats spec:
> > > > > > > >
> > > > > > > > https://github.com/oasis-tcs/virtio-spec/commit/42f389989823039724f95bbbd243291ab0064f82
> > > > > > > >
> > > > > > > > This commit introduces the relative feature and structures.
> > > > > > >
> > > > > > > Hi, Xuan
> > > > > > >
> > > > > > > After applying this patch series, withe ethtool version 6.5,
> > > > > > > I got the following NIC statistics. But I do not find the statistics
> > > > > > > mentioned in this patch series.
> > > > > > > Do I miss something?
> > > > > >
> > > > > > This needs the new virtio-net feature VIRTIO_NET_F_DEVICE_STATS.
> > > > > > You need to update the hypervisor. But the qemu may not support this.
> > > > > >
> > > > > > Thanks.
> > > > >
> > > > > Why not? Can you add this to QEMU?
> > > >
> > > >
> > > > Yes. It is in my list.
> > > >
> > > > But in my plan, I want the kernel to support this firstly.
> > > >
> > > > Thanks.
> > >
> > > QEMU support would mean it's much better tested.
> > > How did you test this one?
> >
> > With our DPU.
> >
> > Thanks.
> >
>
> Well if QEMU support is there then Zhu Yanjun here can test it.

Yes.

But for me, the priority of the qemu implement is low.
I must do this one by one.

Thanks.


>
>
> > >
> > > >
> > > > >
> > > > >
> > > > > >
> > > > > >
> > > > > > >
> > > > > > > "
> > > > > > > NIC statistics:
> > > > > > >       rx_packets: 3434812669
> > > > > > >       rx_bytes: 5168475253690
> > > > > > >       rx_drops: 0
> > > > > > >       rx_xdp_packets: 0
> > > > > > >       rx_xdp_tx: 0
> > > > > > >       rx_xdp_redirects: 0
> > > > > > >       rx_xdp_drops: 0
> > > > > > >       rx_kicks: 57179891
> > > > > > >       tx_packets: 187694230
> > > > > > >       tx_bytes: 12423799040
> > > > > > >       tx_xdp_tx: 0
> > > > > > >       tx_xdp_tx_drops: 0
> > > > > > >       tx_kicks: 187694230
> > > > > > >       tx_timeouts: 0
> > > > > > >       rx_queue_0_packets: 866027381
> > > > > > >       rx_queue_0_bytes: 1302726908150
> > > > > > >       rx_queue_0_drops: 0
> > > > > > >       rx_queue_0_xdp_packets: 0
> > > > > > >       rx_queue_0_xdp_tx: 0
> > > > > > >       rx_queue_0_xdp_redirects: 0
> > > > > > >       rx_queue_0_xdp_drops: 0
> > > > > > >       rx_queue_0_kicks: 14567691
> > > > > > >       rx_queue_1_packets: 856758801
> > > > > > >       rx_queue_1_bytes: 1289899049042
> > > > > > >       rx_queue_1_drops: 0
> > > > > > >       rx_queue_1_xdp_packets: 0
> > > > > > >       rx_queue_1_xdp_tx: 0
> > > > > > >       rx_queue_1_xdp_redirects: 0
> > > > > > >       rx_queue_1_xdp_drops: 0
> > > > > > >       rx_queue_1_kicks: 14265201
> > > > > > >       rx_queue_2_packets: 839291053
> > > > > > >       rx_queue_2_bytes: 1261620863886
> > > > > > >       rx_queue_2_drops: 0
> > > > > > >       rx_queue_2_xdp_packets: 0
> > > > > > >       rx_queue_2_xdp_tx: 0
> > > > > > >       rx_queue_2_xdp_redirects: 0
> > > > > > >       rx_queue_2_xdp_drops: 0
> > > > > > >       rx_queue_2_kicks: 13857653
> > > > > > >       rx_queue_3_packets: 872735434
> > > > > > >       rx_queue_3_bytes: 1314228432612
> > > > > > >       rx_queue_3_drops: 0
> > > > > > >       rx_queue_3_xdp_packets: 0
> > > > > > >       rx_queue_3_xdp_tx: 0
> > > > > > >       rx_queue_3_xdp_redirects: 0
> > > > > > >       rx_queue_3_xdp_drops: 0
> > > > > > >       rx_queue_3_kicks: 14489346
> > > > > > >       tx_queue_0_packets: 75723
> > > > > > >       tx_queue_0_bytes: 4999030
> > > > > > >       tx_queue_0_xdp_tx: 0
> > > > > > >       tx_queue_0_xdp_tx_drops: 0
> > > > > > >       tx_queue_0_kicks: 75723
> > > > > > >       tx_queue_0_timeouts: 0
> > > > > > >       tx_queue_1_packets: 62262921
> > > > > > >       tx_queue_1_bytes: 4134803914
> > > > > > >       tx_queue_1_xdp_tx: 0
> > > > > > >       tx_queue_1_xdp_tx_drops: 0
> > > > > > >       tx_queue_1_kicks: 62262921
> > > > > > >       tx_queue_1_timeouts: 0
> > > > > > >       tx_queue_2_packets: 83
> > > > > > >       tx_queue_2_bytes: 5478
> > > > > > >       tx_queue_2_xdp_tx: 0
> > > > > > >       tx_queue_2_xdp_tx_drops: 0
> > > > > > >       tx_queue_2_kicks: 83
> > > > > > >       tx_queue_2_timeouts: 0
> > > > > > >       tx_queue_3_packets: 125355503
> > > > > > >       tx_queue_3_bytes: 8283990618
> > > > > > >       tx_queue_3_xdp_tx: 0
> > > > > > >       tx_queue_3_xdp_tx_drops: 0
> > > > > > >       tx_queue_3_kicks: 125355503
> > > > > > >       tx_queue_3_timeouts: 0
> > > > > > > "
> > > > > > >
> > > > > > > >
> > > > > > > > Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> > > > > > > > ---
> > > > > > > >   include/uapi/linux/virtio_net.h | 137 ++++++++++++++++++++++++++++++++
> > > > > > > >   1 file changed, 137 insertions(+)
> > > > > > > >
> > > > > > > > diff --git a/include/uapi/linux/virtio_net.h b/include/uapi/linux/virtio_net.h
> > > > > > > > index cc65ef0f3c3e..129e0871d28f 100644
> > > > > > > > --- a/include/uapi/linux/virtio_net.h
> > > > > > > > +++ b/include/uapi/linux/virtio_net.h
> > > > > > > > @@ -56,6 +56,7 @@
> > > > > > > >   #define VIRTIO_NET_F_MQ	22	/* Device supports Receive Flow
> > > > > > > >   					 * Steering */
> > > > > > > >   #define VIRTIO_NET_F_CTRL_MAC_ADDR 23	/* Set MAC address */
> > > > > > > > +#define VIRTIO_NET_F_DEVICE_STATS 50	/* Device can provide device-level statistics. */
> > > > > > > >   #define VIRTIO_NET_F_VQ_NOTF_COAL 52	/* Device supports virtqueue notification coalescing */
> > > > > > > >   #define VIRTIO_NET_F_NOTF_COAL	53	/* Device supports notifications coalescing */
> > > > > > > >   #define VIRTIO_NET_F_GUEST_USO4	54	/* Guest can handle USOv4 in. */
> > > > > > > > @@ -406,4 +407,140 @@ struct  virtio_net_ctrl_coal_vq {
> > > > > > > >   	struct virtio_net_ctrl_coal coal;
> > > > > > > >   };
> > > > > > > >
> > > > > > > > +/*
> > > > > > > > + * Device Statistics
> > > > > > > > + */
> > > > > > > > +#define VIRTIO_NET_CTRL_STATS         8
> > > > > > > > +#define VIRTIO_NET_CTRL_STATS_QUERY   0
> > > > > > > > +#define VIRTIO_NET_CTRL_STATS_GET     1
> > > > > > > > +
> > > > > > > > +struct virtio_net_stats_capabilities {
> > > > > > > > +
> > > > > > > > +#define VIRTIO_NET_STATS_TYPE_CVQ       (1L << 32)
> > > > > > > > +
> > > > > > > > +#define VIRTIO_NET_STATS_TYPE_RX_BASIC  (1 << 0)
> > > > > > > > +#define VIRTIO_NET_STATS_TYPE_RX_CSUM   (1 << 1)
> > > > > > > > +#define VIRTIO_NET_STATS_TYPE_RX_GSO    (1 << 2)
> > > > > > > > +#define VIRTIO_NET_STATS_TYPE_RX_SPEED  (1 << 3)
> > > > > > > > +
> > > > > > > > +#define VIRTIO_NET_STATS_TYPE_TX_BASIC  (1 << 16)
> > > > > > > > +#define VIRTIO_NET_STATS_TYPE_TX_CSUM   (1 << 17)
> > > > > > > > +#define VIRTIO_NET_STATS_TYPE_TX_GSO    (1 << 18)
> > > > > > > > +#define VIRTIO_NET_STATS_TYPE_TX_SPEED  (1 << 19)
> > > > > > > > +
> > > > > > > > +	__le64 supported_stats_types[1];
> > > > > > > > +};
> > > > > > > > +
> > > > > > > > +struct virtio_net_ctrl_queue_stats {
> > > > > > > > +	struct {
> > > > > > > > +		__le16 vq_index;
> > > > > > > > +		__le16 reserved[3];
> > > > > > > > +		__le64 types_bitmap[1];
> > > > > > > > +	} stats[1];
> > > > > > > > +};
> > > > > > > > +
> > > > > > > > +struct virtio_net_stats_reply_hdr {
> > > > > > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_CVQ       32
> > > > > > > > +
> > > > > > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_RX_BASIC  0
> > > > > > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_RX_CSUM   1
> > > > > > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_RX_GSO    2
> > > > > > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_RX_SPEED  3
> > > > > > > > +
> > > > > > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_TX_BASIC  16
> > > > > > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_TX_CSUM   17
> > > > > > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_TX_GSO    18
> > > > > > > > +#define VIRTIO_NET_STATS_TYPE_REPLY_TX_SPEED  19
> > > > > > > > +	u8 type;
> > > > > > > > +	u8 reserved;
> > > > > > > > +	__le16 vq_index;
> > > > > > > > +	__le16 reserved1;
> > > > > > > > +	__le16 size;
> > > > > > > > +};
> > > > > > > > +
> > > > > > > > +struct virtio_net_stats_cvq {
> > > > > > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > > > > > +
> > > > > > > > +	__le64 command_num;
> > > > > > > > +	__le64 ok_num;
> > > > > > > > +};
> > > > > > > > +
> > > > > > > > +struct virtio_net_stats_rx_basic {
> > > > > > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > > > > > +
> > > > > > > > +	__le64 rx_notifications;
> > > > > > > > +
> > > > > > > > +	__le64 rx_packets;
> > > > > > > > +	__le64 rx_bytes;
> > > > > > > > +
> > > > > > > > +	__le64 rx_interrupts;
> > > > > > > > +
> > > > > > > > +	__le64 rx_drops;
> > > > > > > > +	__le64 rx_drop_overruns;
> > > > > > > > +};
> > > > > > > > +
> > > > > > > > +struct virtio_net_stats_tx_basic {
> > > > > > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > > > > > +
> > > > > > > > +	__le64 tx_notifications;
> > > > > > > > +
> > > > > > > > +	__le64 tx_packets;
> > > > > > > > +	__le64 tx_bytes;
> > > > > > > > +
> > > > > > > > +	__le64 tx_interrupts;
> > > > > > > > +
> > > > > > > > +	__le64 tx_drops;
> > > > > > > > +	__le64 tx_drop_malformed;
> > > > > > > > +};
> > > > > > > > +
> > > > > > > > +struct virtio_net_stats_rx_csum {
> > > > > > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > > > > > +
> > > > > > > > +	__le64 rx_csum_valid;
> > > > > > > > +	__le64 rx_needs_csum;
> > > > > > > > +	__le64 rx_csum_none;
> > > > > > > > +	__le64 rx_csum_bad;
> > > > > > > > +};
> > > > > > > > +
> > > > > > > > +struct virtio_net_stats_tx_csum {
> > > > > > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > > > > > +
> > > > > > > > +	__le64 tx_csum_none;
> > > > > > > > +	__le64 tx_needs_csum;
> > > > > > > > +};
> > > > > > > > +
> > > > > > > > +struct virtio_net_stats_rx_gso {
> > > > > > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > > > > > +
> > > > > > > > +	__le64 rx_gso_packets;
> > > > > > > > +	__le64 rx_gso_bytes;
> > > > > > > > +	__le64 rx_gso_packets_coalesced;
> > > > > > > > +	__le64 rx_gso_bytes_coalesced;
> > > > > > > > +};
> > > > > > > > +
> > > > > > > > +struct virtio_net_stats_tx_gso {
> > > > > > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > > > > > +
> > > > > > > > +	__le64 tx_gso_packets;
> > > > > > > > +	__le64 tx_gso_bytes;
> > > > > > > > +	__le64 tx_gso_segments;
> > > > > > > > +	__le64 tx_gso_segments_bytes;
> > > > > > > > +	__le64 tx_gso_packets_noseg;
> > > > > > > > +	__le64 tx_gso_bytes_noseg;
> > > > > > > > +};
> > > > > > > > +
> > > > > > > > +struct virtio_net_stats_rx_speed {
> > > > > > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > > > > > +
> > > > > > > > +	__le64 rx_packets_allowance_exceeded;
> > > > > > > > +	__le64 rx_bytes_allowance_exceeded;
> > > > > > > > +};
> > > > > > > > +
> > > > > > > > +struct virtio_net_stats_tx_speed {
> > > > > > > > +	struct virtio_net_stats_reply_hdr hdr;
> > > > > > > > +
> > > > > > > > +	__le64 tx_packets_allowance_exceeded;
> > > > > > > > +	__le64 tx_bytes_allowance_exceeded;
> > > > > > > > +};
> > > > > > > > +
> > > > > > > >   #endif /* _UAPI_LINUX_VIRTIO_NET_H */
> > > > > > >
> > > > >
> > > > >
> > >
>
diff mbox series

Patch

diff --git a/include/uapi/linux/virtio_net.h b/include/uapi/linux/virtio_net.h
index cc65ef0f3c3e..129e0871d28f 100644
--- a/include/uapi/linux/virtio_net.h
+++ b/include/uapi/linux/virtio_net.h
@@ -56,6 +56,7 @@ 
 #define VIRTIO_NET_F_MQ	22	/* Device supports Receive Flow
 					 * Steering */
 #define VIRTIO_NET_F_CTRL_MAC_ADDR 23	/* Set MAC address */
+#define VIRTIO_NET_F_DEVICE_STATS 50	/* Device can provide device-level statistics. */
 #define VIRTIO_NET_F_VQ_NOTF_COAL 52	/* Device supports virtqueue notification coalescing */
 #define VIRTIO_NET_F_NOTF_COAL	53	/* Device supports notifications coalescing */
 #define VIRTIO_NET_F_GUEST_USO4	54	/* Guest can handle USOv4 in. */
@@ -406,4 +407,140 @@  struct  virtio_net_ctrl_coal_vq {
 	struct virtio_net_ctrl_coal coal;
 };
 
+/*
+ * Device Statistics
+ */
+#define VIRTIO_NET_CTRL_STATS         8
+#define VIRTIO_NET_CTRL_STATS_QUERY   0
+#define VIRTIO_NET_CTRL_STATS_GET     1
+
+struct virtio_net_stats_capabilities {
+
+#define VIRTIO_NET_STATS_TYPE_CVQ       (1L << 32)
+
+#define VIRTIO_NET_STATS_TYPE_RX_BASIC  (1 << 0)
+#define VIRTIO_NET_STATS_TYPE_RX_CSUM   (1 << 1)
+#define VIRTIO_NET_STATS_TYPE_RX_GSO    (1 << 2)
+#define VIRTIO_NET_STATS_TYPE_RX_SPEED  (1 << 3)
+
+#define VIRTIO_NET_STATS_TYPE_TX_BASIC  (1 << 16)
+#define VIRTIO_NET_STATS_TYPE_TX_CSUM   (1 << 17)
+#define VIRTIO_NET_STATS_TYPE_TX_GSO    (1 << 18)
+#define VIRTIO_NET_STATS_TYPE_TX_SPEED  (1 << 19)
+
+	__le64 supported_stats_types[1];
+};
+
+struct virtio_net_ctrl_queue_stats {
+	struct {
+		__le16 vq_index;
+		__le16 reserved[3];
+		__le64 types_bitmap[1];
+	} stats[1];
+};
+
+struct virtio_net_stats_reply_hdr {
+#define VIRTIO_NET_STATS_TYPE_REPLY_CVQ       32
+
+#define VIRTIO_NET_STATS_TYPE_REPLY_RX_BASIC  0
+#define VIRTIO_NET_STATS_TYPE_REPLY_RX_CSUM   1
+#define VIRTIO_NET_STATS_TYPE_REPLY_RX_GSO    2
+#define VIRTIO_NET_STATS_TYPE_REPLY_RX_SPEED  3
+
+#define VIRTIO_NET_STATS_TYPE_REPLY_TX_BASIC  16
+#define VIRTIO_NET_STATS_TYPE_REPLY_TX_CSUM   17
+#define VIRTIO_NET_STATS_TYPE_REPLY_TX_GSO    18
+#define VIRTIO_NET_STATS_TYPE_REPLY_TX_SPEED  19
+	u8 type;
+	u8 reserved;
+	__le16 vq_index;
+	__le16 reserved1;
+	__le16 size;
+};
+
+struct virtio_net_stats_cvq {
+	struct virtio_net_stats_reply_hdr hdr;
+
+	__le64 command_num;
+	__le64 ok_num;
+};
+
+struct virtio_net_stats_rx_basic {
+	struct virtio_net_stats_reply_hdr hdr;
+
+	__le64 rx_notifications;
+
+	__le64 rx_packets;
+	__le64 rx_bytes;
+
+	__le64 rx_interrupts;
+
+	__le64 rx_drops;
+	__le64 rx_drop_overruns;
+};
+
+struct virtio_net_stats_tx_basic {
+	struct virtio_net_stats_reply_hdr hdr;
+
+	__le64 tx_notifications;
+
+	__le64 tx_packets;
+	__le64 tx_bytes;
+
+	__le64 tx_interrupts;
+
+	__le64 tx_drops;
+	__le64 tx_drop_malformed;
+};
+
+struct virtio_net_stats_rx_csum {
+	struct virtio_net_stats_reply_hdr hdr;
+
+	__le64 rx_csum_valid;
+	__le64 rx_needs_csum;
+	__le64 rx_csum_none;
+	__le64 rx_csum_bad;
+};
+
+struct virtio_net_stats_tx_csum {
+	struct virtio_net_stats_reply_hdr hdr;
+
+	__le64 tx_csum_none;
+	__le64 tx_needs_csum;
+};
+
+struct virtio_net_stats_rx_gso {
+	struct virtio_net_stats_reply_hdr hdr;
+
+	__le64 rx_gso_packets;
+	__le64 rx_gso_bytes;
+	__le64 rx_gso_packets_coalesced;
+	__le64 rx_gso_bytes_coalesced;
+};
+
+struct virtio_net_stats_tx_gso {
+	struct virtio_net_stats_reply_hdr hdr;
+
+	__le64 tx_gso_packets;
+	__le64 tx_gso_bytes;
+	__le64 tx_gso_segments;
+	__le64 tx_gso_segments_bytes;
+	__le64 tx_gso_packets_noseg;
+	__le64 tx_gso_bytes_noseg;
+};
+
+struct virtio_net_stats_rx_speed {
+	struct virtio_net_stats_reply_hdr hdr;
+
+	__le64 rx_packets_allowance_exceeded;
+	__le64 rx_bytes_allowance_exceeded;
+};
+
+struct virtio_net_stats_tx_speed {
+	struct virtio_net_stats_reply_hdr hdr;
+
+	__le64 tx_packets_allowance_exceeded;
+	__le64 tx_bytes_allowance_exceeded;
+};
+
 #endif /* _UAPI_LINUX_VIRTIO_NET_H */