vdpa: Add support for reading vdpa device statistics
Subsystems (2)
PATCH 1/1 vdpa: Add support for reading vdpa device statistics
Read statistics of a vdpa device. The specific data is a received as a pair of attribute name and attribute value.
Examples:
1. Read statistics for the virtqueue at index 1
$ vdpa dev vstats show vdpa-a qidx 1 vdpa-a: vdpa-a: queue_type tx received_desc 321812 completed_desc 321812
2. Read statistics for the virtqueue at index 16
$ vdpa dev vstats show vdpa-a qidx 16 vdpa-a: queue_type control_vq received_desc 17 completed_desc 17
3. Read statisitics for the virtqueue at index 0 with json output
$ vdpa -j dev vstats show vdpa-a qidx 0
{"vstats":{"vdpa-a":{"queue_type":"rx","received_desc":114855,"completed_desc":114617}}}4. Read statistics for the virtqueue at index 0 with preety json output
$ vdpa -jp dev vstats show vdpa-a qidx 0
vdpa -jp dev vstats show vdpa-a qidx 0
{
"vstats": {
"vdpa-a": {
"queue_type": "rx",
"received_desc": 114855,
"completed_desc": 114617
}
}
}--- vdpa/include/uapi/linux/vdpa.h | 6 ++ vdpa/vdpa.c | 156 +++++++++++++++++++++++++++++++++ 2 files changed, 162 insertions(+)
vdpa/include/uapi/linux/vdpa.h +6 -0
@@ -18,6 +18,7 @@ enum vdpa_command {VDPA_CMD_DEV_DEL ,VDPA_CMD_DEV_GET ,/* can dump */ VDPA_CMD_DEV_CONFIG_GET ,/* can dump */ + VDPA_CMD_DEV_STATS_GET, }; enum vdpa_attr {
@@ -46,6 +47,11 @@ enum vdpa_attr {VDPA_ATTR_DEV_NEGOTIATED_FEATURES ,/* u64 */ VDPA_ATTR_DEV_MGMTDEV_MAX_VQS ,/* u32 */ VDPA_ATTR_DEV_SUPPORTED_FEATURES ,/* u64 */ + +VDPA_ATTR_DEV_QUEUE_INDEX ,/* u32 */ +VDPA_ATTR_DEV_VENDOR_ATTR_NAME ,/* string */ +VDPA_ATTR_DEV_VENDOR_ATTR_VALUE ,/* u64 */ +/* new attributes must be added above here */ VDPA_ATTR_MAX, };
vdpa/vdpa.c +156 -0
210 lines not on this page · raw message
Signature · 1 line
2.35.1
Quoted 14 lines · Eli Cohen
vdpa/include/uapi/linux/vdpa.h +1
-0@@ -18,6 +18,7 @@ enum vdpa_command {VDPA_CMD_DEV_DEL ,VDPA_CMD_DEV_GET ,/* can dump */ VDPA_CMD_DEV_CONFIG_GET ,/* can dump */ + VDPA_CMD_DEV_STATS_GET, }; enum vdpa_attr {@@ -46,6 +47,11 @@ enum vdpa_attr { VDPA_ATTR_DEV_NEGOTIATED_FEATURES, /* u64 */
vdpa/include/uapi/linux/vdpa.h enum vdpa_attr { · line 57
Quoted 10 lines
vdpa/include/uapi/linux/vdpa.h +5
-0VDPA_ATTR_DEV_MGMTDEV_MAX_VQS ,/* u32 */ VDPA_ATTR_DEV_SUPPORTED_FEATURES ,/* u64 */ + +VDPA_ATTR_DEV_QUEUE_INDEX ,/* u32 */ +VDPA_ATTR_DEV_VENDOR_ATTR_NAME ,/* string */ +VDPA_ATTR_DEV_VENDOR_ATTR_VALUE ,/* u64 */ +/* new attributes must be added above here */ VDPA_ATTR_MAX, };
no reference to the kernel patch, so I have no idea if this uapi has been committed to a kernel tree.
Quoted 27 lines
From: David Ahern <[email protected]>
Sent: Thursday, June 9, 2022 6:11 PM
To: Eli Cohen <[email protected]>; [email protected]; [email protected]; [email protected]; si- [email protected]; [email protected]
Subject: Re: [PATCH] vdpa: Add support for reading vdpa device statisticsQuoted 20 lines · Eli Cohen
vdpa/include/uapi/linux/vdpa.h +5
-0@@ -18,6 +18,7 @@ enum vdpa_command {VDPA_CMD_DEV_DEL ,VDPA_CMD_DEV_GET ,/* can dump */ VDPA_CMD_DEV_CONFIG_GET ,/* can dump */ + VDPA_CMD_DEV_STATS_GET, }; enum vdpa_attr {@@ -46,6 +47,11 @@ enum vdpa_attr {VDPA_ATTR_DEV_NEGOTIATED_FEATURES ,/* u64 */ VDPA_ATTR_DEV_MGMTDEV_MAX_VQS ,/* u32 */ VDPA_ATTR_DEV_SUPPORTED_FEATURES ,/* u64 */ + +VDPA_ATTR_DEV_QUEUE_INDEX ,/* u32 */ +VDPA_ATTR_DEV_VENDOR_ATTR_NAME ,/* string */ + VDPA_ATTR_DEV_VENDOR_ATTR_VALUE, /* u64 */
Quoted 8 lines
vdpa/include/uapi/linux/vdpa.h enum vdpa_attr { · line 57
Quoted 4 lines
vdpa/include/uapi/linux/vdpa.h +1
-0+/* new attributes must be added above here */ VDPA_ATTR_MAX, };no reference to the kernel patch, so I have no idea if this uapi has been committed to a kernel tree.
It has been merged upstream:
commit 13b00b135665c92065a27c0c39dd97e0f380bd4f
Author: Eli Cohen <[email protected]> Date: Wed May 18 16:38:00 2022 +0300
vdpa: Add support for querying vendor statistics
I am not sure what's the convention for reporting such reference.
In any case, I can repost the patch if you could let me know how I should write that reference.
Quoted 7 lines · Eli Cohen
Quoted 4 lines
no reference to the kernel patch, so I have no idea if this uapi has been committed to a kernel tree.
It has been merged upstream:
Quoted 9 lines
commit
13b00b135665c92065a27c0c39dd97e0f380bd4fAuthor: Eli Cohen <[email protected]> Date: Wed May 18 16:38:00 2022 +0300vdpa: Add support for querying vendor statistics
I am not sure what's the convention for reporting such reference.
In any case, I can repost the patch if you could let me know how I should write that reference.
you can add it as a comment after the '---'; let's me check on the upstream uapi status.
vdpa/vdpa.c static int vdpa_argv_parse(struct vdpa *vdpa, int argc, char **argv, · line 323
Quoted 9 lines · Eli Cohen
vdpa/vdpa.c +1
-0@@ -304,6 +320,14 @@ static int vdpa_argv_parse(struct vdpa *vdpa, int argc, char **argv,NEXT_ARG_FWD (); o_found |=VDPA_OPT_MAX_VQP ; + }else if ((matches (*argv,"qidx" ) ==0 ) && (o_optional &VDPA_OPT_QUEUE_INDEX )) {
above line should be wrapped.
Also, please convert all new matches() to strcmp; we are not taking any new users of matches() api.
Quoted 49 lines
vdpa/vdpa.c +35
-0+NEXT_ARG_FWD (); + err =vdpa_argv_u32 (vdpa, argc, argv, &opts->queue_idx); +if (err) +return err; + +NEXT_ARG_FWD (); + o_found |=VDPA_OPT_QUEUE_INDEX ; }else {fprintf (stderr,"Unknown option \"%s\"\n" , *argv);return -EINVAL ;@@ -594,6 +618,7 @@ static void cmd_dev_help(void)fprintf (stderr," [ max_vqp MAX_VQ_PAIRS ]\n" );fprintf (stderr," vdpa dev del DEV\n" );fprintf (stderr,"Usage: vdpa dev config COMMAND [ OPTIONS ]\n" ); +fprintf (stderr,"Usage: vdpa dev vstats COMMAND\n" ); }static const char *device_type_name (uint32_t type)@@ -819,6 +844,135 @@ static int cmd_dev_config(struct vdpa *vdpa, int argc, char **argv)return -ENOENT ; } +#define MAX_KEY_LEN 200 +/* 5 bytes for format */ +#define MAX_FMT_LEN (MAX_KEY_LEN + 5 + 1) + +static void pr_out_dev_net_vstats (const struct nlmsghdr *nlh) +{ +const char *name =NULL ; +uint64_t features =0 ; +char fmt[MAX_FMT_LEN ]; +uint16_t max_vqp =0 ; +bool is_ctrl = false; +struct nlattr *attr; +uint16_t qidx =0 ; +uint64_t v64; + +mnl_attr_for_each (attr, nlh,sizeof (struct genlmsghdr )) { +switch (attr->nla_type) { +case VDPA_ATTR_DEV_NET_CFG_MAX_VQP : + max_vqp =mnl_attr_get_u16 (attr); +break ; +case VDPA_ATTR_DEV_NEGOTIATED_FEATURES : + features =mnl_attr_get_u64 (attr); +break ; +case VDPA_ATTR_DEV_QUEUE_INDEX : + qidx =mnl_attr_get_u16 (attr); + is_ctrl = features &BIT (VIRTIO_NET_F_CTRL_VQ ) && qidx ==2 * max_vqp; +if (!is_ctrl) {
vdpa/vdpa.c static int cmd_dev_config(struct vdpa *vdpa, int argc, char **argv) · line 883
Quoted 10 lines
vdpa/vdpa.c +10
-0+if (qidx &1 ) +print_string (PRINT_ANY ,"queue_type" ,"queue_type %s " , +"tx" ); +else +print_string (PRINT_ANY ,"queue_type" ,"queue_type %s " , +"rx" ); + }else { +print_string (PRINT_ANY ,"queue_type" ,"queue_type %s " , +"control_vq" ); + }
the above should be in a helper function to keep line lengths at a reasonable size.