[PATCH 21/33] vhost-user: make trace events more readable

Vladimir Sementsov-Ogievskiy posted 33 patches 3 months ago
Maintainers: "Michael S. Tsirkin" <mst@redhat.com>, Stefano Garzarella <sgarzare@redhat.com>, "Gonglei (Arei)" <arei.gonglei@huawei.com>, Zhenwei Pi <pizhenwei@bytedance.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>, Raphael Norwitz <raphael@enfabrica.net>, Jason Wang <jasowang@redhat.com>, Fam Zheng <fam@euphon.net>, "Alex Bennée" <alex.bennee@linaro.org>, "Daniel P. Berrangé" <berrange@redhat.com>, Peter Xu <peterx@redhat.com>, Fabiano Rosas <farosas@suse.de>, Eric Blake <eblake@redhat.com>, Markus Armbruster <armbru@redhat.com>, Thomas Huth <thuth@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Laurent Vivier <lvivier@redhat.com>
There is a newer version of this series
[PATCH 21/33] vhost-user: make trace events more readable
Posted by Vladimir Sementsov-Ogievskiy 3 months ago
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
---
 hw/virtio/trace-events |  4 +-
 hw/virtio/vhost-user.c | 94 +++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 94 insertions(+), 4 deletions(-)

diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events
index 76f0d458b2..e5142c27f9 100644
--- a/hw/virtio/trace-events
+++ b/hw/virtio/trace-events
@@ -25,8 +25,8 @@ vhost_user_set_mem_table_withfd(int index, const char *name, uint64_t memory_siz
 vhost_user_postcopy_waker(const char *rb, uint64_t rb_offset) "%s + 0x%"PRIx64
 vhost_user_postcopy_waker_found(uint64_t client_addr) "0x%"PRIx64
 vhost_user_postcopy_waker_nomatch(const char *rb, uint64_t rb_offset) "%s + 0x%"PRIx64
-vhost_user_read(uint32_t req, uint32_t flags) "req:%d flags:0x%"PRIx32""
-vhost_user_write(uint32_t req, uint32_t flags) "req:%d flags:0x%"PRIx32""
+vhost_user_read(uint32_t req, const char *req_name, uint32_t flags) "req:%d (%s) flags:0x%"PRIx32""
+vhost_user_write(uint32_t req, const char *req_name, uint32_t flags) "req:%d (%s) flags:0x%"PRIx32""
 vhost_user_create_notifier(int idx, void *n) "idx:%d n:%p"
 
 # vhost-vdpa.c
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index fe9d91348d..3979582975 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -119,6 +119,94 @@ typedef enum VhostUserBackendRequest {
     VHOST_USER_BACKEND_MAX
 }  VhostUserBackendRequest;
 
+static const char *vhost_req_name(VhostUserRequest req)
+{
+    switch (req) {
+    case VHOST_USER_NONE:
+        return "NONE";
+    case VHOST_USER_GET_FEATURES:
+        return "GET_FEATURES";
+    case VHOST_USER_SET_FEATURES:
+        return "SET_FEATURES";
+    case VHOST_USER_SET_OWNER:
+        return "SET_OWNER";
+    case VHOST_USER_RESET_OWNER:
+        return "RESET_OWNER";
+    case VHOST_USER_SET_MEM_TABLE:
+        return "SET_MEM_TABLE";
+    case VHOST_USER_SET_LOG_BASE:
+        return "SET_LOG_BASE";
+    case VHOST_USER_SET_LOG_FD:
+        return "SET_LOG_FD";
+    case VHOST_USER_SET_VRING_NUM:
+        return "SET_VRING_NUM";
+    case VHOST_USER_SET_VRING_ADDR:
+        return "SET_VRING_ADDR";
+    case VHOST_USER_SET_VRING_BASE:
+        return "SET_VRING_BASE";
+    case VHOST_USER_GET_VRING_BASE:
+        return "GET_VRING_BASE";
+    case VHOST_USER_SET_VRING_KICK:
+        return "SET_VRING_KICK";
+    case VHOST_USER_SET_VRING_CALL:
+        return "SET_VRING_CALL";
+    case VHOST_USER_SET_VRING_ERR:
+        return "SET_VRING_ERR";
+    case VHOST_USER_GET_PROTOCOL_FEATURES:
+        return "GET_PROTOCOL_FEATURES";
+    case VHOST_USER_SET_PROTOCOL_FEATURES:
+        return "SET_PROTOCOL_FEATURES";
+    case VHOST_USER_GET_QUEUE_NUM:
+        return "GET_QUEUE_NUM";
+    case VHOST_USER_SET_VRING_ENABLE:
+        return "SET_VRING_ENABLE";
+    case VHOST_USER_SEND_RARP:
+        return "SEND_RARP";
+    case VHOST_USER_NET_SET_MTU:
+        return "NET_SET_MTU";
+    case VHOST_USER_SET_BACKEND_REQ_FD:
+        return "SET_BACKEND_REQ_FD";
+    case VHOST_USER_IOTLB_MSG:
+        return "IOTLB_MSG";
+    case VHOST_USER_SET_VRING_ENDIAN:
+        return "SET_VRING_ENDIAN";
+    case VHOST_USER_GET_CONFIG:
+        return "GET_CONFIG";
+    case VHOST_USER_SET_CONFIG:
+        return "SET_CONFIG";
+    case VHOST_USER_CREATE_CRYPTO_SESSION:
+        return "CREATE_CRYPTO_SESSION";
+    case VHOST_USER_CLOSE_CRYPTO_SESSION:
+        return "CLOSE_CRYPTO_SESSION";
+    case VHOST_USER_POSTCOPY_ADVISE:
+        return "POSTCOPY_ADVISE";
+    case VHOST_USER_POSTCOPY_LISTEN:
+        return "POSTCOPY_LISTEN";
+    case VHOST_USER_POSTCOPY_END:
+        return "POSTCOPY_END";
+    case VHOST_USER_GET_INFLIGHT_FD:
+        return "GET_INFLIGHT_FD";
+    case VHOST_USER_SET_INFLIGHT_FD:
+        return "SET_INFLIGHT_FD";
+    case VHOST_USER_GPU_SET_SOCKET:
+        return "GPU_SET_SOCKET";
+    case VHOST_USER_RESET_DEVICE:
+        return "RESET_DEVICE";
+    case VHOST_USER_GET_MAX_MEM_SLOTS:
+        return "GET_MAX_MEM_SLOTS";
+    case VHOST_USER_ADD_MEM_REG:
+        return "ADD_MEM_REG";
+    case VHOST_USER_REM_MEM_REG:
+        return "REM_MEM_REG";
+    case VHOST_USER_SET_STATUS:
+        return "SET_STATUS";
+    case VHOST_USER_GET_STATUS:
+        return "GET_STATUS";
+    default:
+        return "<unknown>";
+    }
+}
+
 typedef struct VhostUserMemoryRegion {
     uint64_t guest_phys_addr;
     uint64_t memory_size;
@@ -310,7 +398,8 @@ static int vhost_user_read_header(struct vhost_dev *dev, VhostUserMsg *msg)
         return -EPROTO;
     }
 
-    trace_vhost_user_read(msg->hdr.request, msg->hdr.flags);
+    trace_vhost_user_read(msg->hdr.request,
+                          vhost_req_name(msg->hdr.request), msg->hdr.flags);
 
     return 0;
 }
@@ -430,7 +519,8 @@ static int vhost_user_write(struct vhost_dev *dev, VhostUserMsg *msg,
         return ret < 0 ? -saved_errno : -EIO;
     }
 
-    trace_vhost_user_write(msg->hdr.request, msg->hdr.flags);
+    trace_vhost_user_write(msg->hdr.request,
+                          vhost_req_name(msg->hdr.request), msg->hdr.flags);
 
     return 0;
 }
-- 
2.48.1
Re: [PATCH 21/33] vhost-user: make trace events more readable
Posted by Raphael Norwitz 1 month ago
Reviewed-by: Raphael Norwitz <raphael.s.norwitz@gmail.com>

On Wed, Aug 13, 2025 at 12:57 PM Vladimir Sementsov-Ogievskiy
<vsementsov@yandex-team.ru> wrote:
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
> ---
>  hw/virtio/trace-events |  4 +-
>  hw/virtio/vhost-user.c | 94 +++++++++++++++++++++++++++++++++++++++++-
>  2 files changed, 94 insertions(+), 4 deletions(-)
>
> diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events
> index 76f0d458b2..e5142c27f9 100644
> --- a/hw/virtio/trace-events
> +++ b/hw/virtio/trace-events
> @@ -25,8 +25,8 @@ vhost_user_set_mem_table_withfd(int index, const char *name, uint64_t memory_siz
>  vhost_user_postcopy_waker(const char *rb, uint64_t rb_offset) "%s + 0x%"PRIx64
>  vhost_user_postcopy_waker_found(uint64_t client_addr) "0x%"PRIx64
>  vhost_user_postcopy_waker_nomatch(const char *rb, uint64_t rb_offset) "%s + 0x%"PRIx64
> -vhost_user_read(uint32_t req, uint32_t flags) "req:%d flags:0x%"PRIx32""
> -vhost_user_write(uint32_t req, uint32_t flags) "req:%d flags:0x%"PRIx32""
> +vhost_user_read(uint32_t req, const char *req_name, uint32_t flags) "req:%d (%s) flags:0x%"PRIx32""
> +vhost_user_write(uint32_t req, const char *req_name, uint32_t flags) "req:%d (%s) flags:0x%"PRIx32""
>  vhost_user_create_notifier(int idx, void *n) "idx:%d n:%p"
>
>  # vhost-vdpa.c
> diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
> index fe9d91348d..3979582975 100644
> --- a/hw/virtio/vhost-user.c
> +++ b/hw/virtio/vhost-user.c
> @@ -119,6 +119,94 @@ typedef enum VhostUserBackendRequest {
>      VHOST_USER_BACKEND_MAX
>  }  VhostUserBackendRequest;
>
> +static const char *vhost_req_name(VhostUserRequest req)
> +{
> +    switch (req) {
> +    case VHOST_USER_NONE:
> +        return "NONE";
> +    case VHOST_USER_GET_FEATURES:
> +        return "GET_FEATURES";
> +    case VHOST_USER_SET_FEATURES:
> +        return "SET_FEATURES";
> +    case VHOST_USER_SET_OWNER:
> +        return "SET_OWNER";
> +    case VHOST_USER_RESET_OWNER:
> +        return "RESET_OWNER";
> +    case VHOST_USER_SET_MEM_TABLE:
> +        return "SET_MEM_TABLE";
> +    case VHOST_USER_SET_LOG_BASE:
> +        return "SET_LOG_BASE";
> +    case VHOST_USER_SET_LOG_FD:
> +        return "SET_LOG_FD";
> +    case VHOST_USER_SET_VRING_NUM:
> +        return "SET_VRING_NUM";
> +    case VHOST_USER_SET_VRING_ADDR:
> +        return "SET_VRING_ADDR";
> +    case VHOST_USER_SET_VRING_BASE:
> +        return "SET_VRING_BASE";
> +    case VHOST_USER_GET_VRING_BASE:
> +        return "GET_VRING_BASE";
> +    case VHOST_USER_SET_VRING_KICK:
> +        return "SET_VRING_KICK";
> +    case VHOST_USER_SET_VRING_CALL:
> +        return "SET_VRING_CALL";
> +    case VHOST_USER_SET_VRING_ERR:
> +        return "SET_VRING_ERR";
> +    case VHOST_USER_GET_PROTOCOL_FEATURES:
> +        return "GET_PROTOCOL_FEATURES";
> +    case VHOST_USER_SET_PROTOCOL_FEATURES:
> +        return "SET_PROTOCOL_FEATURES";
> +    case VHOST_USER_GET_QUEUE_NUM:
> +        return "GET_QUEUE_NUM";
> +    case VHOST_USER_SET_VRING_ENABLE:
> +        return "SET_VRING_ENABLE";
> +    case VHOST_USER_SEND_RARP:
> +        return "SEND_RARP";
> +    case VHOST_USER_NET_SET_MTU:
> +        return "NET_SET_MTU";
> +    case VHOST_USER_SET_BACKEND_REQ_FD:
> +        return "SET_BACKEND_REQ_FD";
> +    case VHOST_USER_IOTLB_MSG:
> +        return "IOTLB_MSG";
> +    case VHOST_USER_SET_VRING_ENDIAN:
> +        return "SET_VRING_ENDIAN";
> +    case VHOST_USER_GET_CONFIG:
> +        return "GET_CONFIG";
> +    case VHOST_USER_SET_CONFIG:
> +        return "SET_CONFIG";
> +    case VHOST_USER_CREATE_CRYPTO_SESSION:
> +        return "CREATE_CRYPTO_SESSION";
> +    case VHOST_USER_CLOSE_CRYPTO_SESSION:
> +        return "CLOSE_CRYPTO_SESSION";
> +    case VHOST_USER_POSTCOPY_ADVISE:
> +        return "POSTCOPY_ADVISE";
> +    case VHOST_USER_POSTCOPY_LISTEN:
> +        return "POSTCOPY_LISTEN";
> +    case VHOST_USER_POSTCOPY_END:
> +        return "POSTCOPY_END";
> +    case VHOST_USER_GET_INFLIGHT_FD:
> +        return "GET_INFLIGHT_FD";
> +    case VHOST_USER_SET_INFLIGHT_FD:
> +        return "SET_INFLIGHT_FD";
> +    case VHOST_USER_GPU_SET_SOCKET:
> +        return "GPU_SET_SOCKET";
> +    case VHOST_USER_RESET_DEVICE:
> +        return "RESET_DEVICE";
> +    case VHOST_USER_GET_MAX_MEM_SLOTS:
> +        return "GET_MAX_MEM_SLOTS";
> +    case VHOST_USER_ADD_MEM_REG:
> +        return "ADD_MEM_REG";
> +    case VHOST_USER_REM_MEM_REG:
> +        return "REM_MEM_REG";
> +    case VHOST_USER_SET_STATUS:
> +        return "SET_STATUS";
> +    case VHOST_USER_GET_STATUS:
> +        return "GET_STATUS";
> +    default:
> +        return "<unknown>";
> +    }
> +}
> +
>  typedef struct VhostUserMemoryRegion {
>      uint64_t guest_phys_addr;
>      uint64_t memory_size;
> @@ -310,7 +398,8 @@ static int vhost_user_read_header(struct vhost_dev *dev, VhostUserMsg *msg)
>          return -EPROTO;
>      }
>
> -    trace_vhost_user_read(msg->hdr.request, msg->hdr.flags);
> +    trace_vhost_user_read(msg->hdr.request,
> +                          vhost_req_name(msg->hdr.request), msg->hdr.flags);
>
>      return 0;
>  }
> @@ -430,7 +519,8 @@ static int vhost_user_write(struct vhost_dev *dev, VhostUserMsg *msg,
>          return ret < 0 ? -saved_errno : -EIO;
>      }
>
> -    trace_vhost_user_write(msg->hdr.request, msg->hdr.flags);
> +    trace_vhost_user_write(msg->hdr.request,
> +                          vhost_req_name(msg->hdr.request), msg->hdr.flags);
>
>      return 0;
>  }
> --
> 2.48.1
>
>
Re: [PATCH 21/33] vhost-user: make trace events more readable
Posted by Philippe Mathieu-Daudé 3 months ago
On 13/8/25 18:48, Vladimir Sementsov-Ogievskiy wrote:
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
> ---
>   hw/virtio/trace-events |  4 +-
>   hw/virtio/vhost-user.c | 94 +++++++++++++++++++++++++++++++++++++++++-
>   2 files changed, 94 insertions(+), 4 deletions(-)


> @@ -430,7 +519,8 @@ static int vhost_user_write(struct vhost_dev *dev, VhostUserMsg *msg,
>           return ret < 0 ? -saved_errno : -EIO;
>       }
>   
> -    trace_vhost_user_write(msg->hdr.request, msg->hdr.flags);
> +    trace_vhost_user_write(msg->hdr.request,
> +                          vhost_req_name(msg->hdr.request), msg->hdr.flags);

Mis-indent ;)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>

>   
>       return 0;
>   }