All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrange" <berrange@redhat.com>
To: "Lluís Vilanova" <vilanova@ac.upc.edu>
Cc: qemu-devel@nongnu.org, Luiz Capitulino <lcapitulino@redhat.com>,
	Eric Blake <eblake@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v3 1/6] hypertrace: Add documentation
Date: Wed, 28 Sep 2016 14:14:52 +0100	[thread overview]
Message-ID: <20160928131452.GC15510@redhat.com> (raw)
In-Reply-To: <147506793596.18187.14194318363118441846.stgit@fimbulvetr.bsc.es>

On Wed, Sep 28, 2016 at 03:05:36PM +0200, Lluís Vilanova wrote:
> Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
> ---
>  docs/hypertrace.txt |  232 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  docs/tracing.txt    |    3 +
>  2 files changed, 235 insertions(+)
>  create mode 100644 docs/hypertrace.txt

> +== Quick guide ==
> +
> +This shows an example of using the hypertrace channel to trace the guest memory
> +accesses only in a specific guest code region, which is identified by calls to
> +the hypertrace channel.
> +
> +We are going to trace memory accesses to disk using QEMU's "log" backend, and
> +will use QEMU's "dtrace" (SystemTap) backend to ensure memory accesses are only
> +traced in the guest code region of interest. The first time the guest code
> +invokes the hypertrace channel, we will start tracing the
> +"guest_mem_before_exec" event using dtrace, and then will disable it the second
> +time around.
> +
> +Tracing is done with "log" because it is more efficient than using "dtrace" in
> +high-volume events like memory accesses. If the event rate is low, you can
> +ignore the "log" backend and simply use "dtrace"'s printf, while still using the
> +hypertrace events to identify guest semantics.
> +
> +1. Set the tracing backends and number of arguments for the hypertrace events:
> +
> +    mkdir /tmp/qemu-build
> +    cd /tmp/qemu-build
> +    /path/to/qemu-source/configure              \
> +        --enable-trace-backends=dtrace,log      \
> +        --with-hypertrace-args=4                \
> +        --prefix=/tmp/qemu-install
> +    make -j install
> +
> +2. Enable the event "guest_mem_before_exec":
> +
> +    sed -i -e 's/disable vcpu tcg guest_mem_before/vcpu tcg guest_mem_before/g' /path/to/qemu-source/trace-events
> +
> +3. Compile the guest support code:
> +
> +    make -C /tmp/qemu-build/x86_64-linux-user/hypertrace/guest/user
> +    make -C /tmp/qemu-build/x86_64-softmmu/hypertrace/guest/user
> +    make -C /tmp/qemu-build/x86_64-softmmu/hypertrace/guest/linux-module
> +
> +   If you need to cross-compile the guest library, set the 'CC' variable:
> +
> +    make -C /tmp/qemu-build/mipsel-linux-user/hypertrace/guest/user CC=mipsel-gnu-linux-gcc
> +
> +3. Create a guest application using "qemu-hypertrace.h" to interact with the
> +   hypertrace channel:
> +
> +    cat > /tmp/my-hypertrace.c <<\EOF
> +    #include <stdio.h>
> +    #include <errno.h>
> +    #include <stdlib.h>
> +    #include <string.h>
> +    #include <qemu-hypertrace.h>
> +    
> +    
> +    int main(int argc, char **argv)
> +    {
> +        char *base = NULL;
> +        if (argc > 1) {
> +            base = argv[1];
> +        }
> +    
> +        /* In 'user' mode this path must be the same we will use to start QEMU. */
> +        if (qemu_hypertrace_init(base) != 0) {
> +            perror("error: qemu_hypertrace_init");
> +            abort();
> +        }
> +    
> +        /* Set additional event arguments */
> +        uint64_t client  = 0;

IIUC, 'client' is the field that the host uses to distinguish
between different guest applications or different guest threads.

How are applications expected to assign themselves a unique
value for this field ? 

It feels that life would be easier if you made this field be
128-bits instead of 64-bit, as then you could encode a UUID
in it, making it much easier to guarnatee uniqueness without
having to have a central authority.

> +        uint64_t *data = qemu_hypertrace_data(client);
> +        data[0] = 0xcafe;
> +        data[1] = 0xdead;
> +        data[2] = 0xbeef;
> +    
> +        /* Emit event to start tracing */
> +        qemu_hypertrace(client, 1);
> +
> +        /* Computation in between */
> +        printf("Some computation...\n");
> +
> +        /* Emit event to stop tracing */
> +        qemu_hypertrace(client, 0);
> +    }
> +    EOF
> +
> +    gcc -o /tmp/my-hypertrace-user /tmp/my-hypertrace.c                                    \
> +        /tmp/qemu-build/x86_64-linux-user/hypertrace/guest/user/libqemu-hypertrace-guest.a \
> +        -I/tmp/qemu-install/include -lpthread
> +
> +    gcc -o /tmp/my-hypertrace-softmmu /tmp/my-hypertrace.c                              \
> +        /tmp/qemu-build/x86_64-softmmu/hypertrace/guest/user/libqemu-hypertrace-guest.a \
> +        -I/tmp/qemu-install/include -lpthread

Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://entangle-photo.org       -o-    http://search.cpan.org/~danberr/ :|

  reply	other threads:[~2016-09-28 13:15 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-28 13:05 [Qemu-devel] [PATCH v3 0/6] hypertrace: Lightweight guest-to-QEMU trace channel Lluís Vilanova
2016-09-28 13:05 ` [Qemu-devel] [PATCH v3 1/6] hypertrace: Add documentation Lluís Vilanova
2016-09-28 13:14   ` Daniel P. Berrange [this message]
2016-09-30 15:03     ` Lluís Vilanova
2016-09-28 13:05 ` [Qemu-devel] [PATCH v3 2/6] hypertrace: Add tracing event "guest_hypertrace" Lluís Vilanova
2016-09-28 13:05 ` [Qemu-devel] [PATCH v3 3/6] hypertrace: [*-user] Add QEMU-side proxy to "guest_hypertrace" event Lluís Vilanova
2016-09-28 13:05 ` [Qemu-devel] [PATCH v3 4/6] hypertrace: [softmmu] " Lluís Vilanova
2016-09-28 13:05 ` [Qemu-devel] [PATCH v3 5/6] hypertrace: Add guest-side user-level library Lluís Vilanova
2016-09-28 13:06 ` [Qemu-devel] [PATCH v3 6/6] hypertrace: Add guest-side Linux module Lluís Vilanova
2016-09-28 13:56 ` [Qemu-devel] [PATCH v3 0/6] hypertrace: Lightweight guest-to-QEMU trace channel no-reply

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=20160928131452.GC15510@redhat.com \
    --to=berrange@redhat.com \
    --cc=eblake@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=vilanova@ac.upc.edu \
    /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.