All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Cc: jasowang@redhat.com, qemu-devel@nongnu.org, leiyang@redhat.com,
	steven.sistare@oracle.com, yc-core@yandex-team.ru,
	peterx@redhat.com, mst@redhat.com, farosas@suse.de,
	eblake@redhat.com, armbru@redhat.com, thuth@redhat.com,
	philmd@linaro.org
Subject: Re: [PATCH v2 1/8] net/tap: add some trace points
Date: Wed, 3 Sep 2025 16:11:37 +0200	[thread overview]
Message-ID: <aLhLvIts2vVl63Xr@redhat.com> (raw)
In-Reply-To: <20250903133706.1177633-2-vsementsov@yandex-team.ru>

On Wed, Sep 03, 2025 at 04:36:58PM +0300, Vladimir Sementsov-Ogievskiy wrote:
> Add trace points to simplify debugging migration.
> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
> ---
>  net/tap.c        | 58 ++++++++++++++++++++++++++++++++++++++++++++++++
>  net/trace-events |  7 ++++++
>  2 files changed, 65 insertions(+)
> 
> diff --git a/net/tap.c b/net/tap.c
> index 2530627a9a..224fb37310 100644
> --- a/net/tap.c
> +++ b/net/tap.c
> @@ -43,6 +43,7 @@
>  #include "qemu/main-loop.h"
>  #include "qemu/sockets.h"
>  #include "hw/virtio/vhost.h"
> +#include "trace.h"
>  
>  #include "net/tap.h"
>  
> @@ -148,6 +149,9 @@ static ssize_t tap_receive_iov(NetClientState *nc, const struct iovec *iov,
>      g_autofree struct iovec *iov_copy = NULL;
>      struct virtio_net_hdr hdr = { };
>  
> +    trace_tap_receive_iov(s->using_vnet_hdr, s->host_vnet_hdr_len, iovcnt,
> +                          iov->iov_len);
> +
>      if (s->host_vnet_hdr_len && !s->using_vnet_hdr) {
>          iov_copy = g_new(struct iovec, iovcnt + 1);
>          iov_copy[0].iov_base = &hdr;
> @@ -183,6 +187,49 @@ static void tap_send_completed(NetClientState *nc, ssize_t len)
>      tap_read_poll(s, true);
>  }
>  
> +static char *tap_dump_packet(const uint8_t *buf, int size)
> +{
> +    int i, j;
> +    char hex_line[80];  /* Enough space for hex pairs + spaces */
> +    char ascii_line[17]; /* 16 + 1 for null terminator */
> +    GString *dump_str = g_string_new(NULL);
> +
> +    g_string_append_printf(dump_str, "Packet dump (%d bytes):\n", size);

It occurrs to me that this ability to dump a buffer is likely useful for
other areas of QEMU. How about moving this to somewhere in util/ and
renaming it to something like "dump_buffer".

You can drop the 'Packet dump' prefix, and bytes count, as you can
include that info in the trace-events format string instead.

> +
> +    for (i = 0; i < size; i += 16) {
> +        memset(hex_line, 0, sizeof(hex_line));
> +        memset(ascii_line, 0, sizeof(ascii_line));
> +
> +        /* Build hex line in groups of 2 bytes (4 hex chars) */
> +        int hex_pos = 0;
> +        for (j = 0; j < 16 && (i + j) < size; j += 2) {
> +            if (i + j + 1 < size) {
> +                /* Two bytes available */
> +                hex_pos += snprintf(hex_line + hex_pos,
> +                                    sizeof(hex_line) - hex_pos,
> +                                    "%02x%02x ", buf[i + j], buf[i + j + 1]);
> +            } else {
> +                /* Only one byte left */
> +                hex_pos += snprintf(hex_line + hex_pos,
> +                                    sizeof(hex_line) - hex_pos,
> +                                    "%02x   ", buf[i + j]);
> +            }
> +        }
> +
> +        /* Build ASCII line */
> +        for (j = 0; j < 16 && (i + j) < size; j++) {
> +            uint8_t byte = buf[i + j];
> +            ascii_line[j] = (byte >= 32 && byte <= 126) ? byte : '.';
> +        }
> +
> +        /* Add the line in tcpdump-like format */
> +        g_string_append_printf(dump_str, "\t0x%04x:  %-40s %s\n",
> +                               i, hex_line, ascii_line);
> +    }
> +
> +    return g_string_free(dump_str, false);
> +}

> diff --git a/net/trace-events b/net/trace-events
> index cda960f42b..b51427f539 100644
> --- a/net/trace-events
> +++ b/net/trace-events
> @@ -29,3 +29,10 @@ vhost_vdpa_set_address_space_id(void *v, unsigned vq_group, unsigned asid_num) "
>  vhost_vdpa_net_load_cmd(void *s, uint8_t class, uint8_t cmd, int data_num, int data_size) "vdpa state: %p class: %u cmd: %u sg_num: %d size: %d"
>  vhost_vdpa_net_load_cmd_retval(void *s, uint8_t class, uint8_t cmd, int r) "vdpa state: %p class: %u cmd: %u retval: %d"
>  vhost_vdpa_net_load_mq(void *s, int ncurqps) "vdpa state: %p current_qpairs: %d"
> +
> +# tap.c
> +tap_receive_iov(bool using_vnet_hdr, uint32_t host_vnet_hdr_len, int iovcnt, size_t iov_len) "using_vnet_hdr:%d host_vnet_hdr_len:%u iovcnt:%d iov_len:%zu"
> +tap_send_packet(bool using_vnet_hdr, uint32_t host_vnet_hdr_len, int size) "using_vnet_hdr:%d host_vnet_hdr_len:%u size:%d"
> +tap_enable(void) "tap enabled"
> +tap_disable(void) "tap disabled"
> +tap_packet_dump(const char *dump_str) "%s"

This could be 

     tap_packet_dump(size_t bytes, const char *dump_str) "Package dump (%zu bytes) %s"

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



  reply	other threads:[~2025-09-03 14:13 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-03 13:36 [PATCH v2 0/8] virtio-net: live-TAP local migration Vladimir Sementsov-Ogievskiy
2025-09-03 13:36 ` [PATCH v2 1/8] net/tap: add some trace points Vladimir Sementsov-Ogievskiy
2025-09-03 14:11   ` Daniel P. Berrangé [this message]
2025-09-03 14:26     ` Vladimir Sementsov-Ogievskiy
2025-09-05 12:33     ` Vladimir Sementsov-Ogievskiy
2025-09-03 13:36 ` [PATCH v2 2/8] net/tap: keep exit notifier only when downscript set Vladimir Sementsov-Ogievskiy
2025-09-03 13:37 ` [PATCH v2 3/8] net/tap: refactor net_tap_setup_vhost() Vladimir Sementsov-Ogievskiy
2025-09-03 13:37 ` [PATCH v2 4/8] qapi: add interface for local TAP migration Vladimir Sementsov-Ogievskiy
2025-09-10  6:28   ` Markus Armbruster
2025-09-10 10:29     ` Vladimir Sementsov-Ogievskiy
2025-09-03 13:37 ` [PATCH v2 5/8] net/tap: implement interfaces for local migration Vladimir Sementsov-Ogievskiy
2025-09-03 14:34   ` Daniel P. Berrangé
2025-09-03 15:31     ` Vladimir Sementsov-Ogievskiy
2025-09-03 16:09       ` Steven Sistare
2025-09-04  7:41         ` Vladimir Sementsov-Ogievskiy
2025-09-05 10:14           ` Vladimir Sementsov-Ogievskiy
2025-09-05 12:23             ` Steven Sistare
2025-09-03 13:37 ` [PATCH v2 6/8] virtio-net: support local tap migration Vladimir Sementsov-Ogievskiy
2025-09-03 13:37 ` [PATCH v2 7/8] test/functional: exec_command_and_wait_for_pattern: add vm arg Vladimir Sementsov-Ogievskiy
2025-09-03 13:37 ` [PATCH v2 8/8] tests/functional: add test_x86_64_tap_fd_migration Vladimir Sementsov-Ogievskiy
2025-09-03 14:47   ` Daniel P. Berrangé
2025-09-03 15:14     ` Vladimir Sementsov-Ogievskiy
2025-09-03 15:19       ` Daniel P. Berrangé
2025-09-03 15:24         ` Vladimir Sementsov-Ogievskiy
2025-09-04 14:42 ` [PATCH v2 0/8] virtio-net: live-TAP local migration Lei Yang
2025-09-04 15:05   ` Vladimir Sementsov-Ogievskiy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aLhLvIts2vVl63Xr@redhat.com \
    --to=berrange@redhat.com \
    --cc=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=farosas@suse.de \
    --cc=jasowang@redhat.com \
    --cc=leiyang@redhat.com \
    --cc=mst@redhat.com \
    --cc=peterx@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=steven.sistare@oracle.com \
    --cc=thuth@redhat.com \
    --cc=vsementsov@yandex-team.ru \
    --cc=yc-core@yandex-team.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.