instrument: Let the user wrap/override specific event tracing routines
v3 cover instrument: Let the user wrap/override specific event tracing routines
TODO: Operations 'instr_load' and 'instr_unload' are not thread safe.
(qemu_cpu_kick?)
TODO: Do cmdline actions have to be implemented on top of QMP routines?
TODO: HMP and QMP interfaces only accept one argument to "instr-load".
TODO: Replace programmatic 'InstrLoadError' in favour of QAPI's 'InstrLoadCode'?
(harder to find using code navigation tools, as it's auto-generated; but provides a single point to manage the enumeration values, which is less error-prone)
The whole set of patch series is available at:
https://projects.gso.ac.upc.edu/projects/qemu-dbi
Adds the "instrument" event property to declare which tracing events in QEMU must be instrumentable. Still, in case the user only wants to wrap around the tracing events, the original tracing implementation is accessible through the appropriate routines.
The instrumentation can be performed either through a dynamically-loaded library or through user-provided code that is compiled into QEMU itself (useful when instrumenting high-frequency events, as the fast-path of the instrumentation can be inlined into QEMU).
As a side-effect this series adds an API for the instrumentation code to have some basic interaction with QEMU.
See the documentation added in the first patch for more information.
---
Changes in v3:
* Rename QAPI 'input' primitive to 'include' (Eric Blake).
* Use 'error_setg' instead of 'errot_set' (Eric Blake).
* Added copyright and fixed docs on "instrument/qapi-schema.json" (Eric Blake).
* Rename internal 'args' variable in "qapi-commands.py" to 'args_'.
* Rename argument 'iargs' in QAPI command 'instr-load' to 'args', and make it optional (Eric Blake).
* Fixed loop in 'qmp_instr_laod'.
* Revamped QAPI commands "instr-load" and "instr-unload" to use a proper return value.
* Fixed QMP arguments for "instr-load".
* Added 'instr_type' and 'instr_active'.
* Use 'instr_type' instead of CONFIG_TRACE_INSTRUMENT* whenever possible.
* Change QAPI interfaces to appear as if providing support for multiple libraries (Eric Blake).
* Reimplemented HMP commands on top of QMP commands.
Changes in v2:
* Rebased on latest master (e2ec3f9).
* Added "libqemutools.a".
* Have 'tracetool' forbid certain event argument names.
* Fixed title in path for "linux-headers" include path (Peter Maydell).
* Small fixes to qapi/qmp (Eric Blake).
* Have 'qi_init' accept a list of strings as arguments (Eric Blake)
Lluís Vilanova (24):
instrument: Add documentation
trace: [simple] Do not include "trace/simple.h" in generated tracer headers
trace: Let the user specify her own trace-events file
tracetool: Use method 'Event.api' to get the name of public routines
trace: Minimize inclusions of "qemu-common.h" to avoid inclusion loops
instrument: [none] Add null instrumentation
system: [linux] Use absolute include path for linux-headers
instrument: [static] Call statically linked user-provided routines
build: Add variable 'tools-obj-y' for tool-only files
instrument: [dynamic] Call dynamically linked user-provided routines
qapi: Add a primitive to include other files from a QAPI schema file
qapi: [trivial] Set the input root directory when parsing QAPI files
qapi: [trivial] Allow user to use 'args' as an argument name
instrument: Add internal control interface
instrument: [qmp, qapi] Add control interface
instrument: [hmp] Add control interface
Let makefiles add entries to the set of target architecture objects
instrument: Add commandline options to start with an instrumentation library
instrument: Add client-side API to enumerate events
instrument: Add client-side API to control tracing state of events
instrument: Add client-side API to control event instrumentation
build: Fix installation of target-dependant files
instrument: Install headers for dynamic instrumentation clients
trace: Do not use the word 'new' in event arguments
.gitignore | 4 Makefile | 57 +++ Makefile.objs | 9 Makefile.target | 7 bsd-user/main.c | 22 + bsd-user/syscall.c | 5 configure | 96 +++++ docs/instrumentation.txt | 496 +++++++++++++++++++++++++++ docs/tracing.txt | 9 hmp-commands.hx | 42 ++ hw/virtio/virtio.c | 1 include/trace.h | 2 instrument/Makefile.objs | 87 +++++ instrument/api-control.c | 14 + instrument/api-trace.c | 14 + instrument/cmdline.c | 91 +++++ instrument/cmdline.h | 52 +++ instrument/control-internal.h | 40 ++ instrument/control.c | 226 ++++++++++++ instrument/control.h | 152 ++++++++ instrument/hmp.c | 79 ++++ instrument/hmp.h | 21 + instrument/qapi-schema.json | 150 ++++++++ instrument/qemu-instr/control-internal.h | 69 ++++ instrument/qemu-instr/control.h | 199 +++++++++++ instrument/qemu-instr/trace-internal.h | 32 ++ instrument/qemu-instr/trace.h | 91 +++++ instrument/qemu-instr/visibility-internal.h | 94 +++++ instrument/qmp.c | 78 ++++ libcacard/Makefile | 4 linux-user/main.c | 31 ++ linux-user/syscall.c | 4 monitor.c | 5 qapi-schema.json | 2 qemu-options.hx | 18 + qmp-commands.hx | 71 ++++ qmp.c | 4 rules.mak | 3 scripts/qapi-commands.py | 18 + scripts/qapi-types.py | 10 - scripts/qapi-visit.py | 10 - scripts/qapi.py | 12 + scripts/tracetool.py | 14 + scripts/tracetool/__init__.py | 44 ++ scripts/tracetool/backend/dtrace.py | 6 scripts/tracetool/backend/instr_dynamic.py | 93 +++++ scripts/tracetool/backend/instr_none.py | 44 ++ scripts/tracetool/backend/instr_static.py | 82 ++++ scripts/tracetool/backend/simple.py | 13 - scripts/tracetool/backend/stderr.py | 5 scripts/tracetool/backend/ust.py | 8 scripts/tracetool/format/api_c.py | 24 + scripts/tracetool/format/api_events_h.py | 56 +++ scripts/tracetool/format/api_h.py | 39 ++ scripts/tracetool/format/events_c.py | 42 ++ scripts/tracetool/format/h.py | 15 + scripts/tracetool/format/qemu_h.py | 68 ++++ trace-events | 8 trace/Makefile.objs | 10 - trace/control-internal.h | 4 trace/control.c | 4 trace/control.h | 9 trace/default.c | 4 trace/event-internal.h | 17 + trace/simple.c | 6 trace/simple.h | 1 trace/stderr.c | 4 vl.c | 41 ++ 68 files changed, 3016 insertions(+), 76 deletions(-) create mode 100644 docs/instrumentation.txt create mode 100644 instrument/Makefile.objs create mode 100644 instrument/api-control.c create mode 100644 instrument/api-trace.c create mode 100644 instrument/cmdline.c create mode 100644 instrument/cmdline.h create mode 100644 instrument/control-internal.h create mode 100644 instrument/control.c create mode 100644 instrument/control.h create mode 100644 instrument/hmp.c create mode 100644 instrument/hmp.h create mode 100644 instrument/qapi-schema.json create mode 100644 instrument/qemu-instr/control-internal.h create mode 100644 instrument/qemu-instr/control.h create mode 100644 instrument/qemu-instr/trace-internal.h create mode 100644 instrument/qemu-instr/trace.h create mode 100644 instrument/qemu-instr/visibility-internal.h create mode 100644 instrument/qmp.c create mode 100644 scripts/tracetool/backend/instr_dynamic.py create mode 100644 scripts/tracetool/backend/instr_none.py create mode 100644 scripts/tracetool/backend/instr_static.py create mode 100644 scripts/tracetool/format/api_c.py create mode 100644 scripts/tracetool/format/api_events_h.py create mode 100644 scripts/tracetool/format/api_h.py create mode 100644 scripts/tracetool/format/qemu_h.py
To: [email protected]
Cc: Stefan Hajnoczi <[email protected]>
Cc: Eric Blake <[email protected]>
PATCH v3 1/24 instrument: Add documentation
--- docs/instrumentation.txt | 496 ++++++++++++++++++++++++++++++++++++++++++++++ docs/tracing.txt | 9 + 2 files changed, 505 insertions(+) create mode 100644 docs/instrumentation.txt
docs/instrumentation.txt new file +496 -0
@@ -0,0 +1,496 @@ += Trace instrumentation = + +== Introduction == + +This document describes how the events provided by the tracing infrastructure +(described in the document "tracing.txt") can be extended with user-provided +code. + +Instrumentation comes in two (three) flavours; dynamic and static (and none at +all). Both provide means for you to associate code to specific tracing events +that have the "instrument" property in the "trace-events" file. + +As opposed to using tracing backends that can dynamically load user-defined code +into the tracing events (e.g., "dtrace"), trace instrumentation provides a +well-defined API for the user-provided code to interact with QEMU. + +In the case of dynamic instrumentation, you can load and unload a shared object +(a dynamic library) to establish your instrumentation callbacks. This mechanism +provides a trade-off between performance and the simplicity of reusing the same +QEMU binary for different instrumentation scenarios. + +In the case of static instrumentation, you must provide a static library that is +compiled directly into QEMU. This mechanism can provide better performance, at +the expense of having to recompile QEMU for each different instrumentation +scenario. + + + +== Selecting the events to instrument == + +You must declare which events to instrument before compiling QEMU. + +This can be done by adding the "instrument" property (and removing the "disable" +property, if any) in the events listed in the "trace-events" file. + +In order to avoid modifying the QEMU sources, you can simply create a new +trace-events file with your modifications: + + cp /path/to/qemu-source/trace-events /tmp/trace-events + sed -i -e "s/qemu_vmalloc(/instrument qemu_vmalloc(/g" /tmp/trace-events + +Note: You must remove the "disable" property (if any) if you want to add the +"instrument" property of an event, as these are mutually exclusive. + + +== Pre-defined instrumentation callbacks == + +If you are using dynamic auto-instrumentation (see 'QI_CTRL_INSTR_AUTO' below) +or static instrumentation, your callbacks must follow a specific naming scheme: +'qi_event_${event}'. + +Two other default callbacks are provided by QEMU: + +* 'qi_event_${event}_nop' + + Does nothing. + + This is the default callback for all instrumentable events when using dynamic + instrumentation. + +* 'qi_event_${event}_trace' + + Call QEMU's tracing backend. That is, trace the event using whatever tracing + backend QEMU has been configured with. + + See document "tracing.txt" to learn more about tracing events with QEMU (e.g., + write events into a file or print them on the screen). + +All these callbacks are declared in the "qemu-instr/events.h" header. + + +== Dynamic instrumentation == + +Dynamic instrumentation is based on dynamically loadable libraries that can be +loaded and unloaded from QEMU at any point in time. This also includes an API to +dynamically set the per-event tracing instrumentation callback at any point in +time. + +Being able to load and unload an instrumentation library provides a comfortable +mechanism to test multiple instrumentation approaches without having to +recompile or restart QEMU between instrumentation tests. + +Note: By default, events are set to use the 'qi_event_${event}_nop' callback. + + +=== Example === + +1. Select the events to instrument in file "trace-events" (see above). + +2. Build QEMU with dynamic trace intrumentation: + + mkdir -p /tmp/qemu-build + cd /tmp/qemu-build + /path/to/qemu-source/configure \ + --with-trace-events=/tmp/trace-events \ + --with-trace-instrument=dynamic \ + --enable-trace-backend=stderr \ + --prefix=/tmp/qemu-install + make + make install + +3. Create the "Makefile" to build the instrumentation library: + + mkdir -p /tmp/my-dinstrument + + cat > /tmp/my-dinstrument/Makefile <<EOF + QEMU_PATH=/tmp/qemu-install/ + + CFLAGS += -O3 + CFLAGS += -Werror -Wall + CFLAGS += -I$(QEMU_PATH)/include + + all: libtrace-instrument.la + + libtrace-instrument.la: instrument.lo + libtool --mode=link --tag=CC $(CC) -module -rpath /usr/local/lib -o $@ $^ + + %.lo: %.c + libtool --mode=compile --tag=CC $(CC) $(CFLAGS) -c $^ + + clean: + $(RM) -f *.o *.so *.lo + $(RM) -Rf .libs + EOF + +4. Create the necessary source code files to implement your event instrumentation: + + cat > /tmp/my-dinstrument/instrument.c <<EOF + #include <stdio.h> + #include <assert.h> + + /* get event declarations */ + #include <qemu-instr/events.h> + + /* enumerate events and manipulate their instrumentation callbacks */ + #include <qemu-instr/control.h> + + /* manipulate the dynamic tracing state of events */ + #include <qemu-instr/trace.h> + + /* define instrumentation callbacks during event execution: + * qi_event_${event} + */ + + /* called every time QEMU traces event 'qemu_vmalloc' */ + void qi_event_qemu_vmalloc(size_t size, void *ptr) + { + fprintf(stderr, "qemu_vmalloc! [instrument]\n"); + + /* call the original tracing routine */ + qi_event_qemu_vmalloc_trace(size, ptr); + + /* disable instrumentation and tracing after 10 calls */ + static int c = 0; + if (c++ > 10) { + QIEvent *ev = qi_ctrl_event_id(QI_EVENT_QEMU_VMALLOC); + qi_ctrl_event_set(ev, QI_CTRL_INSTR_NOP); + qi_trace_event_set_state_dynamic(ev, false); + } + } + + + + /* mandatory initialization callback */ + void qi_init(int argc, const char *argv) + { + int i; + fprintf(stderr, "init!\n"); + fprintf(stderr, " argc :: %d\n", argc); + for (i = 0; i < argc; i++) { + fprintf(stderr, " -> %s\n", argv[i]); + } + + /* iterate on all trace events */ + QIEvent *ev = NULL; + while ((ev = qi_ctrl_event_pattern("*", ev)) != NULL) { + + /* auto-instrument all events instrumentable at execution time */ + if (qi_ctrl_event_is_available(ev)) { + + printf("[exec] instrumenting '%s'\n", + qi_ctrl_event_get_name(ev)); + + /* auto-detect instrumentation routines */ + bool instrumented = qi_ctrl_event_set(ev, QI_CTRL_INSTR_AUTO); + assert(instrumented); + + /* activate tracing for that event + * (otherwise qi_event_${event}_trace does nothing when using + * the 'stderr' backend) + */ + qi_trace_event_set_state_dynamic(ev, true); + } + } + } + + /* mandatory finalization callback */ + void qi_fini(void) + { + fprintf(stderr, "fini!\n"); + + /* ensure all tracing is disabled */ + QIEvent *ev = NULL; + while ((ev = qi_ctrl_event_pattern("*", ev)) != NULL) { + qi_trace_event_set_state_dynamic(ev, false); + } + + /* instrumentation callbacks are automatically reset by QEMU */ + } + EOF + +5. Compile the instrumentation library: + + make -C /tmp/my-dinstrument + +6. Start QEMU with the instrumentation library: + + /tmp/qemu-install/bin/qemu-system-x86_64 \ + -instr file=/tmp/my-dinstrument/.libs/libtrace-instrument.so + + +Alternatively, you can explicitly set which events and with which callback you +want to instrument them: + + /* ... */ + void qi_init(int argc, const char *argv) + { + int i; + fprintf(stderr, "init!\n"); + fprintf(stderr, " argc :: %d\n", argc); + for (i = 0; i < argc; i++) { + fprintf(stderr, " -> %s\n", argv[i]); + } + + QIEvent *ev; + bool instrumented; + + /* NOTE: the callbacks can be pointers to arbitrary routines; + * there's no need to follow the 'qi_event_${event}' naming + * scheme if you're not using QI_CTRL_INSTR_AUTO. + */ + + ev = qi_ctrl_event_id(QI_EVENT_QEMU_VMALLOC); + assert(ev); + printf("[exec] instrumenting '%s'\n", + qi_ctrl_event_get_name(ev)); + instrumented = qi_ctrl_event_set(ev, execute_qemu_vmalloc); + assert(instrumented); + qi_trace_event_set_state_dynamic(ev, true); + } + /* ... */ + + + +== Static instrumentation == + +Static instrumentation relies on you providing a directory that QEMU will +compile on to produce a static library. The instrumentation library is compiled +during the compilation of QEMU's target-dependant code, and the directory you +provided will be present on the include path. This static library will then be +linked into QEMU itself. + +This mechanism allows you to inline your own instrumentation code into the QEMU +tracing routines. This requires the (partial) recompilation of QEMU whenever the +instrumentation analysis code changes, and is thus intended for +performance-critical event instrumentation analysis. + +For this reason, you can prototype your analysis using dynamic instrumentation +before moving to static instrumentation. + + +=== Example === + +1. Select the events to instrument in file "trace-events" (see above). + +2. Create the "Makefile" to build the instrumentation library: + + mkdir -p /tmp/my-sinstrument + + cat > /tmp/my-sinstrument/Makefile <<EOF + include $(BUILD_DIR)/config-host.mak + include $(BUILD_DIR)/$(TARGET_DIR)../config-target.mak + include $(SRC_PATH)/rules.mak + + vpath %.c /tmp/my-sinstrument + + libtrace-instrument.a: CFLAGS += -I$(SRC_PATH)/instrument + libtrace-instrument.a: CFLAGS += -I$(BUILD_DIR)/instrument + libtrace-instrument.a: instrument.o + + # Include automatically generated dependency files + -include $(wildcard *.d) + EOF + +3. Create the necessary source code files to implement the event instrumentation. + + The same code on the dynamic instrumentation example can be used, eliminating + calls to 'qi_ctrl_event_set'. + + See below for a description on how to reuse the same code to work with both + instrumentation types. + +4. Build QEMU with static trace intrumentation: + + mkdir -p /tmp/qemu-build + cd /tmp/qemu-build + /path/to/qemu-source/configure \ + --with-trace-events=/tmp/trace-events \ + --with-trace-instrument=static \ + --with-trace-instrument-path=/tmp/my-sinstrument \ + --enable-trace-backend=stderr \ + --prefix=/tmp/qemu-install + make + make install + + +=== Performance optimizations === + +You can create a few header files in the user-provided instrumentation path +('--with-trace-instrument-path') to further optimize static instrumentation: + +* "events-pre.h" + + Included before the code of the in-QEMU and tracing backend-specific header + ("trace.h"). + + This header can contain per-event defines to allow the user to provide an + inlined version of the instrumentation routine (see "events-post.h"): + + #define QI_EVENT_${EVENT}_INLINE 1 + + Example: + + #ifndef EVENTS_PRE_H + #define EVENTS_PRE_H + + #define QI_EVENT_QEMU_VMALLOC_INLINE 1 + + #endif /* EVENTS_PRE_H */ + +* "events-post.h" + + Included after the code of the in-QEMU and tracing backend-specific header + ("trace.h"). + + This header can contain arbitrary user-provided code that will be inlined into + all QEMU files using tracing events. This includes inlined versions of the + instrumentation routines. + + For example, inlining the fast-path of the instrumentation code: + + #ifndef EVENTS_POST_H + #define EVENTS_POST_H + + #include <qemu-instr/events.h> + + // file residing in "/tmp/my-sinstrument/my-header.h", + // which declares 'my_trace_qemu_vmalloc_slow' + #include "my-header.h" + + + // requires "#define QI_EVENT_QEMU_VMALLOC_INLINE 1" in "events-pre.h" + static inline void qi_event_qemu_vmalloc(size_t size, void *ptr) + { + if (/* ... performance-critical condition ... */) { + /* ... performance-critical code ... */ + } else { + my_trace_qemu_vmalloc_slow(size, ptr); + } + } + + #endif /* EVENTS_POST_H */ + +Note: All these headers are completely optional, and will only be used if they +exist at compile time. + + + +== Loading and unloading instrumentation libraries == + +QEMU starts with all instrumentation callbacks set to their default value, which +corresponds to a call to 'qi_event_${event}_nop'. + +To load a dynamic instrumentation library, the user can either use the "-instr" +command line argument, or the "instr-load" command available in the QEMU +monitor, QAPI and QMP. + +Once loaded, QEMU will call the 'qi_init' routine in the instrumentation library. + +To unload a dynamic instrumentation library, the user can use the "instr-unload" +command. + +When unloading, QEMU will call the 'qi_fini' routine in the instrumentation +library, and immediately after restore all the instrumentation callbacks to +their default value. + +In the case of static instrumentation, the commands "instr-load" and +"instr-unload" are not available, and thus the instrumentation library is +already loaded when QEMU starts, and is unloaded when QEMU exits. + + + +== Instrumentation API == + +Both dynamic and static trace instrumentation libraries can interact with QEMU +using the API provided in the headers found under the "qemu-instr" directory +(installed alongside QEMU). + + +=== Event enumeration === + +Events can be obtained either by identifier or by name. Identifiers are values +of the enumeration 'QIEventID' and follow the naming scheme 'QI_EVENT_${EVENT}' +(e.g., 'QI_EVENT_QEMU_VMALLOC' for the "qemu_vmalloc" event). + +Identifiers, together with defines indicating if an event is enabled at +compile-time ('QI_EVENT_${EVENT}_ENABLED') are located in the +"qemu-instr/events-list.h" header. + +The interface to obtain and enumerate these events is located in the +"qemu-instr/control.h" header. + + +=== Event tracing === + +You can interact with the state of QEMU's event tracing backend (see document +"tracing.txt") through the API in the "qemu-instr/trace.h" header. + + +=== Event instrumentation === + +You can control the instrumentation callbacks of events through the API in the +"qemu-instr/control.h" header. + + +=== Instrumentation type discrimination === + +The same source code for an instrumentation library can result in different code +depending on the current instrumentation type (either dynamic or static): + +* "qemu-instr/config.h" + + The define QI_TYPE_CONFIG_STATIC (QI_TYPE_CONFIG_DYNAMIC) will be available + and set to 1 if QEMU has been compiled with static (dynamic) instrumentation. + +* "qemu-instr/control.h" + + Routine 'qi_ctrl_type' can be used to discriminate if dynamic instrumentation + is available. + + Similarly, routine 'qi_ctrl_event_is_available' indicates whether the given + event is available for instrumentation (both static and dynamic). + +With this, you can ensure the same code will work under both instrumentation +types. + +Example initialization: + + #if defined(QI_TYPE_CONFIG_DYNAMIC) + #include "events-post.h" + #endif + + void qi_init(int argc, const char *argv) + { + int i; + fprintf(stderr, "init!\n"); + fprintf(stderr, " argc :: %d\n", argc); + for (i = 0; i < argc; i++) { + fprintf(stderr, " -> %s\n", argv[i]); + } + + QIEvent *ev = NULL; + while ((ev = qi_ctrl_event_pattern("*", ev)) != NULL) { + + if (qi_ctrl_event_is_available(ev)) { + + /* changing the callback will fail during static instrumentation */ + if (qi_ctrl_type() == QI_TYPE_DYNAMIC) { + bool instrumented = qi_ctrl_event_set(ev, QI_CTRL_INSTR_AUTO); + assert(instrumented); + } + + qi_trace_event_set_state_dynamic(ev, true); + } + } + } + +Example "events-post.h": + + #if defined(QI_TYPE_CONFIG_STATIC) + static inline + #endif + void qi_event_qemu_vmalloc(size_t size, void *ptr) + { + /* ... */ + }
docs/tracing.txt +9 -0
@@ -255,3 +255,12 @@ guard such computations and avoid its compilation when the event is disabled: You can check both if the event has been disabled and is dynamically enabled at the same time using the 'trace_event_get_state' routine (see header "trace/control.h" for more information). + +=== "instrument" === + +When compiling QEMU with trace instrumentation enabled, the "instrument" +property lets you provide your own implementation for that trace event. This +implementation can override and/or wrap the backend-specific tracing code +(regardless of the tracing backend). + +See the document "instrumentation.txt" for more information.
PATCH v3 2/24 trace: [simple] Do not include "trace/simple.h" in generated tracer headers
In reply to Lluís VilanovaThe header is not necessary, given that the simple backend does not define any inlined tracing routines.
--- scripts/tracetool/backend/simple.py | 5 +---- trace/simple.c | 2 ++ 2 files changed, 3 insertions(+), 4 deletions(-)
scripts/tracetool/backend/simple.py +1 -4
@@ -6,7 +6,7 @@ Simple built-in backend. """ __author__ = "Lluís Vilanova <[email protected]>" -__copyright__ = "Copyright 2012, Lluís Vilanova <[email protected]>" +__copyright__ = "Copyright 2012-2013, Lluís Vilanova <[email protected]>" __license__ = "GPL version 2 or (at your option) any later version" __maintainer__ = "Stefan Hajnoczi"
@@ -93,9 +93,6 @@ def c(events): def h(events): - out('#include "trace/simple.h"', - '') - for event in events: out('void trace_%(name)s(%(args)s);', name = event.name,
trace/simple.c +2 -0
@@ -8,6 +8,8 @@* */ +#include "trace/simple.h" +#include <stdlib.h> #include <stdint.h> #include <stdio.h>
PATCH v3 3/24 trace: Let the user specify her own trace-events file
In reply to Lluís VilanovaWith this option the user can perform multiple builds of QEMU with different tracing event properties.
--- Makefile.target | 2 +- configure | 19 +++++++++++++++++++ trace/Makefile.objs | 10 +++++----- 3 files changed, 25 insertions(+), 6 deletions(-)
Makefile.target +1 -1
@@ -47,7 +47,7 @@ else TARGET_TYPE=system endif -$(QEMU_PROG).stp: $(SRC_PATH)/trace-events +$(QEMU_PROG).stp: $(TRACE_EVENTS) $(call quiet-command,$(TRACETOOL) \ --format=stap \ --backend=$(TRACE_BACKEND) \
configure +19 -0
@@ -221,6 +221,7 @@ blobs="yes" pkgversion="" pie="" zero_malloc="" +trace_events=`dirname $0`/trace-events trace_backend="nop" trace_file="trace" spice=""
@@ -639,6 +640,8 @@ for opt do ;; --target-list=*) target_list="$optarg" ;; + --with-trace-events=*) trace_events="$optarg" + ;; --enable-trace-backend=*) trace_backend="$optarg" ;; --with-trace-file=*) trace_file="$optarg"
@@ -1158,6 +1161,7 @@ echo " --enable-docs enable documentation build" echo " --disable-docs disable documentation build" echo " --disable-vhost-net disable vhost-net acceleration support" echo " --enable-vhost-net enable vhost-net acceleration support" +echo " --with-trace-events=PATH file with tracing events description (default: $trace_events)" echo " --enable-trace-backend=B Set trace backend" echo " Available backends:" $($python "$source_path"/scripts/tracetool.py --list-backends) echo " --with-trace-file=NAME Full PATH,NAME of file to store traces"
@@ -3009,6 +3013,18 @@ if compile_prog "" "" ; then fi ########################################## +# check if trace-events file exists + +if test ! -f "$trace_events"; then + echo + echo "Error: the given trace-events file does not exist" + echo + exit 1 +else + trace_events=`readlink -f "$trace_events"` +fi + +########################################## # check if trace backend exists $python "$source_path/scripts/tracetool.py" "--backend=$trace_backend" --check-backend > /dev/null 2> /dev/null
@@ -3418,6 +3434,7 @@ echo "sigev_thread_id $sigev_thread_id" echo "uuid support $uuid" echo "libcap-ng support $cap_ng" echo "vhost-net support $vhost_net" +echo "Trace events $trace_events" echo "Trace backend $trace_backend" echo "Trace output file $trace_file-<pid>" echo "spice support $spice ($spice_protocol_version/$spice_server_version)"
@@ -3810,6 +3827,8 @@ bsd) ;; esac +echo "TRACE_EVENTS=$trace_events" >> $config_host_mak + # use default implementation for tracing backend-specific routines trace_default=yes echo "TRACE_BACKEND=$trace_backend" >> $config_host_mak
trace/Makefile.objs +5 -5
@@ -4,7 +4,7 @@ # Auto-generated event descriptions $(obj)/generated-events.h: $(obj)/generated-events.h-timestamp -$(obj)/generated-events.h-timestamp: $(SRC_PATH)/trace-events +$(obj)/generated-events.h-timestamp: $(TRACE_EVENTS) $(call quiet-command,$(TRACETOOL) \ --format=events-h \ --backend=events \
@@ -12,7 +12,7 @@ $(obj)/generated-events.h-timestamp: $(SRC_PATH)/trace-events @cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp,%,$@) $(obj)/generated-events.c: $(obj)/generated-events.c-timestamp $(BUILD_DIR)/config-host.mak -$(obj)/generated-events.c-timestamp: $(SRC_PATH)/trace-events +$(obj)/generated-events.c-timestamp: $(TRACE_EVENTS) $(call quiet-command,$(TRACETOOL) \ --format=events-c \ --backend=events \
@@ -27,7 +27,7 @@ util-obj-y += generated-events.o $(obj)/generated-tracers.h: $(obj)/generated-tracers.h-timestamp @cmp -s $< $@ || cp $< $@ -$(obj)/generated-tracers.h-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak +$(obj)/generated-tracers.h-timestamp: $(TRACE_EVENTS) $(BUILD_DIR)/config-host.mak $(call quiet-command,$(TRACETOOL) \ --format=h \ --backend=$(TRACE_BACKEND) \
@@ -39,7 +39,7 @@ $(obj)/generated-tracers.h-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/conf ifneq ($(TRACE_BACKEND),dtrace) $(obj)/generated-tracers.c: $(obj)/generated-tracers.c-timestamp @cmp -s $< $@ || cp $< $@ -$(obj)/generated-tracers.c-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak +$(obj)/generated-tracers.c-timestamp: $(TRACE_EVENTS) $(BUILD_DIR)/config-host.mak $(call quiet-command,$(TRACETOOL) \ --format=c \ --backend=$(TRACE_BACKEND) \
@@ -57,7 +57,7 @@ endif # rule file. So we use '.dtrace' instead ifeq ($(TRACE_BACKEND),dtrace) $(obj)/generated-tracers.dtrace: $(obj)/generated-tracers.dtrace-timestamp -$(obj)/generated-tracers.dtrace-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak +$(obj)/generated-tracers.dtrace-timestamp: $(TRACE_EVENTS) $(BUILD_DIR)/config-host.mak $(call quiet-command,$(TRACETOOL) \ --format=d \ --backend=$(TRACE_BACKEND) \
PATCH v3 4/24 tracetool: Use method 'Event.api' to get the name of public routines
In reply to Lluís VilanovaThis ensures proper naming across tracing backends, even when someone overrides the value without backends knowing it.
--- scripts/tracetool/__init__.py | 10 +++++++++- scripts/tracetool/backend/dtrace.py | 6 +++--- scripts/tracetool/backend/simple.py | 8 ++++---- scripts/tracetool/backend/stderr.py | 5 +++-- scripts/tracetool/backend/ust.py | 8 +++++--- scripts/tracetool/format/h.py | 6 +++--- 6 files changed, 27 insertions(+), 16 deletions(-)
scripts/tracetool/__init__.py +9 -1
@@ -6,7 +6,7 @@ Machinery for generating tracing-related intermediate files. """ __author__ = "Lluís Vilanova <[email protected]>" -__copyright__ = "Copyright 2012, Lluís Vilanova <[email protected]>" +__copyright__ = "Copyright 2012-2013, Lluís Vilanova <[email protected]>" __license__ = "GPL version 2 or (at your option) any later version" __maintainer__ = "Stefan Hajnoczi"
@@ -173,6 +173,14 @@ class Event(object): self.args, self.fmt) + + QEMU_TRACE = "trace_%(name)s" + + def api(self, fmt = None): + if fmt is None: + fmt = Event.QEMU_TRACE + return fmt % { "name" : self.name } + def _read_events(fobj): res = [] for line in fobj:
scripts/tracetool/backend/dtrace.py +3 -3
@@ -6,7 +6,7 @@ DTrace/SystemTAP backend. """ __author__ = "Lluís Vilanova <[email protected]>" -__copyright__ = "Copyright 2012, Lluís Vilanova <[email protected]>" +__copyright__ = "Copyright 2012-2013, Lluís Vilanova <[email protected]>" __license__ = "GPL version 2 or (at your option) any later version" __maintainer__ = "Stefan Hajnoczi"
@@ -44,10 +44,10 @@ def h(events): '') for e in events: - out('static inline void trace_%(name)s(%(args)s) {', + out('static inline void %(api)s(%(args)s) {', ' QEMU_%(uppername)s(%(argnames)s);', '}', - name = e.name, + api = e.api(), args = e.args, uppername = e.name.upper(), argnames = ", ".join(e.args.names()),
scripts/tracetool/backend/simple.py +4 -4
@@ -34,10 +34,10 @@ def c(events): ) for num, event in enumerate(events): - out('void trace_%(name)s(%(args)s)', + out('void %(api)s(%(args)s)', '{', ' TraceBufferRecord rec;', - name = event.name, + api = event.api(), args = event.args, ) sizes = []
@@ -94,7 +94,7 @@ def c(events): def h(events): for event in events: - out('void trace_%(name)s(%(args)s);', - name = event.name, + out('void %(api)s(%(args)s);', + api = event.api(), args = event.args, )
scripts/tracetool/backend/stderr.py +3 -2
@@ -6,7 +6,7 @@ Stderr built-in backend. """ __author__ = "Lluís Vilanova <[email protected]>" -__copyright__ = "Copyright 2012, Lluís Vilanova <[email protected]>" +__copyright__ = "Copyright 2012-2013, Lluís Vilanova <[email protected]>" __license__ = "GPL version 2 or (at your option) any later version" __maintainer__ = "Stefan Hajnoczi"
@@ -33,13 +33,14 @@ def h(events): if len(e.args) > 0: argnames = ", " + argnames - out('static inline void trace_%(name)s(%(args)s)', + out('static inline void %(api)s(%(args)s)', '{', ' bool _state = trace_event_get_state(%(event_id)s);', ' if (_state) {', ' fprintf(stderr, "%(name)s " %(fmt)s "\\n" %(argnames)s);', ' }', '}', + api = e.api(), name = e.name, args = e.args, event_id = "TRACE_" + e.name.upper(),
scripts/tracetool/backend/ust.py +5 -3
@@ -6,7 +6,7 @@ LTTng User Space Tracing backend. """ __author__ = "Lluís Vilanova <[email protected]>" -__copyright__ = "Copyright 2012, Lluís Vilanova <[email protected]>" +__copyright__ = "Copyright 2012-2013, Lluís Vilanova <[email protected]>" __license__ = "GPL version 2 or (at your option) any later version" __maintainer__ = "Stefan Hajnoczi"
@@ -78,7 +78,8 @@ def h(events): for e in events: if len(e.args) > 0: out('DECLARE_TRACE(ust_%(name)s, TP_PROTO(%(args)s), TP_ARGS(%(argnames)s));', - '#define trace_%(name)s trace_ust_%(name)s', + '#define %(api)s trace_ust_%(name)s', + api = e.api(), name = e.name, args = e.args, argnames = ", ".join(e.args.names()),
@@ -86,7 +87,8 @@ def h(events): else: out('_DECLARE_TRACEPOINT_NOARGS(ust_%(name)s);', - '#define trace_%(name)s trace_ust_%(name)s', + '#define %(api)s trace_ust_%(name)s', + api = e.api(), name = e.name, )
scripts/tracetool/format/h.py +3 -3
@@ -6,7 +6,7 @@ Generate .h file. """ __author__ = "Lluís Vilanova <[email protected]>" -__copyright__ = "Copyright 2012, Lluís Vilanova <[email protected]>" +__copyright__ = "Copyright 2012-2013, Lluís Vilanova <[email protected]>" __license__ = "GPL version 2 or (at your option) any later version" __maintainer__ = "Stefan Hajnoczi"
@@ -30,9 +30,9 @@ def end(events): def nop(events): for e in events: out('', - 'static inline void trace_%(name)s(%(args)s)', + 'static inline void %(api)s(%(args)s)', '{', '}', - name = e.name, + api = e.api(), args = e.args, )
PATCH v3 5/24 trace: Minimize inclusions of "qemu-common.h" to avoid inclusion loops
In reply to Lluís VilanovaThis problem arises in the following patches.
--- hw/virtio/virtio.c | 1 + monitor.c | 4 +++- scripts/tracetool/format/h.py | 9 ++++++++- trace/control-internal.h | 4 +++- trace/control.c | 4 +++- trace/control.h | 9 +++++++-- trace/default.c | 4 +++- trace/simple.c | 4 +++- trace/simple.h | 1 + trace/stderr.c | 4 +++- 10 files changed, 35 insertions(+), 9 deletions(-)
hw/virtio/virtio.c +1 -0
@@ -14,6 +14,7 @@#include <inttypes.h> #include "trace.h" +#include "qemu-common.h" #include "qemu/error-report.h" #include "hw/virtio/virtio.h" #include "qemu/atomic.h"
monitor.c +3 -1
@@ -22,6 +22,9 @@* THE SOFTWARE. */ #include <dirent.h> +#define TRACE__CONTROL__USE__TRACE_PRINT_EVENTS +#include "trace/control.h" +#undef TRACE__CONTROL__USE__TRACE_PRINT_EVENTS#include "hw/hw.h" #include "monitor/qdev.h" #include "hw/usb.h"
@@ -59,7 +62,6 @@#include "qemu/osdep.h" #include "cpu.h" #include "trace.h" -#include "trace/control.h" #ifdef CONFIG_TRACE_SIMPLE #include "trace/simple.h" #endif
scripts/tracetool/format/h.py +8 -1
@@ -22,7 +22,14 @@ def begin(events): '#ifndef TRACE__GENERATED_TRACERS_H', '#define TRACE__GENERATED_TRACERS_H', '', - '#include "qemu-common.h"') + '/* Do not directly include "qemu-common.h" to avoid circular dependencies */', + '#include <stdint.h>', + '#include <inttypes.h>', + '#include <stdbool.h>', + '#include <stddef.h>', + '#include <unistd.h>', + '', + ) def end(events): out('#endif /* TRACE__GENERATED_TRACERS_H */')
trace/control-internal.h +3 -1
@@ -1,7 +1,7 @@/* * Interface for configuring and controlling the state of tracing events. * -* Copyright (C) 2011-2012 Lluís Vilanova <[email protected]> +* Copyright (C) 2011-2013 Lluís Vilanova <[email protected]> * * This work is licensed under the terms of the GNU GPL, version 2 or later. * See the COPYING file in the top-level directory.
@@ -11,6 +11,8 @@#define TRACE__CONTROL_INTERNAL_H #include <string.h> +#include <assert.h> +#include <stddef.h> extern TraceEvent trace_events[];
trace/control.c +3 -1
@@ -1,7 +1,7 @@/* * Interface for configuring and controlling the state of tracing events. * -* Copyright (C) 2011-2012 Lluís Vilanova <[email protected]> +* Copyright (C) 2011-2013 Lluís Vilanova <[email protected]> * * This work is licensed under the terms of the GNU GPL, version 2 or later. * See the COPYING file in the top-level directory.
@@ -9,6 +9,8 @@#include "trace/control.h" +#include "qemu-common.h" +TraceEvent *trace_event_name (const char *name) {
trace/control.h +7 -2
@@ -1,7 +1,7 @@/* * Interface for configuring and controlling the state of tracing events. * -* Copyright (C) 2011-2012 Lluís Vilanova <[email protected]> +* Copyright (C) 2011-2013 Lluís Vilanova <[email protected]> * * This work is licensed under the terms of the GNU GPL, version 2 or later. * See the COPYING file in the top-level directory.
@@ -10,7 +10,6 @@#ifndef TRACE__CONTROL_H #define TRACE__CONTROL_H -#include "qemu-common.h" #include "trace/generated-events.h"
@@ -155,6 +154,10 @@ void trace_event_set_state_dynamic_backend(TraceEvent *ev, bool state); +#if defined(TRACE__CONTROL__USE__TRACE_PRINT_EVENTS ) +/* Minimize inclusions of "qemu-common.h" to avoid circular dependencies */ +#include "qemu-common.h" +/** * trace_print_events: *
@@ -164,6 +167,8 @@ void trace_event_set_state_dynamic_backend(TraceEvent *ev, bool state);*/ void trace_print_events (FILE *stream,fprintf_function stream_printf); +#endif /* defined(TRACE__CONTROL__USE__TRACE_PRINT_EVENTS) */ +/** * trace_backend_init: * @events: Name of file with events to be enabled at startup; may be NULL.
trace/default.c +3 -1
@@ -1,13 +1,15 @@/* * Default implementation for backend initialization from commandline. * -* Copyright (C) 2011-2012 Lluís Vilanova <[email protected]> +* Copyright (C) 2011-2013 Lluís Vilanova <[email protected]> * * This work is licensed under the terms of the GNU GPL, version 2. See * the COPYING file in the top-level directory. */ +#define TRACE__CONTROL__USE__TRACE_PRINT_EVENTS #include "trace/control.h" +#undef TRACE__CONTROL__USE__TRACE_PRINT_EVENTSvoid trace_print_events (FILE *stream,fprintf_function stream_printf)
trace/simple.c +3 -1
@@ -19,8 +19,10 @@#include <pthread.h> #endif #include "qemu/timer.h" -#include "trace.h" +#define TRACE__CONTROL__USE__TRACE_PRINT_EVENTS #include "trace/control.h" +#undef TRACE__CONTROL__USE__TRACE_PRINT_EVENTS +#include "trace.h" /** Trace file header event ID */ #define HEADER_EVENT_ID (~(uint64_t)0)/* avoids conflicting with TraceEventIDs */
trace/simple.h +1 -0
@@ -16,6 +16,7 @@#include <stdio.h> #include "trace/generated-events.h" +#include "qemu-common.h" void st_print_trace_file_status (FILE *stream,fprintf_function stream_printf);
trace/stderr.c +3 -1
@@ -1,5 +1,7 @@ -#include "trace.h" +#define TRACE__CONTROL__USE__TRACE_PRINT_EVENTS #include "trace/control.h" +#undef TRACE__CONTROL__USE__TRACE_PRINT_EVENTS +#include "trace.h" void trace_print_events (FILE *stream,fprintf_function stream_printf)
PATCH v3 6/24 instrument: [none] Add null instrumentation
In reply to Lluís VilanovaSplits the QEMU-side tracing interface into different layers (in order of nested invocation):
* trace_*
The interface used by QEMU code to signal traceable/instrumentable events (now generated according to the selected instrumentation type).
* qi_event_*
The interface provided by the user's instrumentation code (for which QEMU provides default implementations depending on the instrumentation type).
* qi_event_*_trace / qi_event_*_nop
The interface provided by QEMU to the user's instrumentation code to invoke the tracing backend. The nop variant simply does nothing.
* trace_*_backend
The interface provided by the tracing backend in QEMU. Originally exposed as 'trace_*' routines.
The 'none' instrumentation type (this one) skips through the qi_* layers and directly calls 'trace_*_backend' from the 'trace_*' routines (providing the original tracing behaviour).
--- .gitignore | 2 + Makefile | 3 + configure | 31 ++++++++++++++ include/trace.h | 2 - instrument/Makefile.objs | 24 +++++++++++ scripts/tracetool/__init__.py | 9 +++- scripts/tracetool/backend/instr_none.py | 41 +++++++++++++++++++ scripts/tracetool/format/api_h.py | 39 ++++++++++++++++++ scripts/tracetool/format/qemu_h.py | 68 +++++++++++++++++++++++++++++++ 9 files changed, 216 insertions(+), 3 deletions(-) create mode 100644 instrument/Makefile.objs create mode 100644 scripts/tracetool/backend/instr_none.py create mode 100644 scripts/tracetool/format/api_h.py create mode 100644 scripts/tracetool/format/qemu_h.py
.gitignore +2 -0
@@ -10,6 +10,8 @@ trace/generated-tracers.dtrace trace/generated-events.h trace/generated-events.c libcacard/trace/generated-tracers.c +instrument/generated-tracers.h +instrument/qemu-instr/events.h *-timestamp *-softmmu *-darwin-user
Makefile +3 -0
@@ -35,6 +35,9 @@ GENERATED_HEADERS = config-host.h qemu-options.def GENERATED_HEADERS += qmp-commands.h qapi-types.h qapi-visit.h GENERATED_SOURCES += qmp-marshal.c qapi-types.c qapi-visit.c +GENERATED_HEADERS += instrument/generated-tracers.h +GENERATED_HEADERS += instrument/qemu-instr/events.h + GENERATED_HEADERS += trace/generated-events.h GENERATED_SOURCES += trace/generated-events.c
configure +31 -0
@@ -224,6 +224,7 @@ zero_malloc="" trace_events=`dirname $0`/trace-events trace_backend="nop" trace_file="trace" +trace_instrument="none" spice="" rbd="" smartcard_nss=""
@@ -646,6 +647,8 @@ for opt do ;; --with-trace-file=*) trace_file="$optarg" ;; + --with-trace-instrument=*) trace_instrument="$optarg" + ;; --enable-gprof) gprof="yes" ;; --enable-gcov) gcov="yes"
@@ -1166,6 +1169,8 @@ echo " --enable-trace-backend=B Set trace backend" echo " Available backends:" $($python "$source_path"/scripts/tracetool.py --list-backends) echo " --with-trace-file=NAME Full PATH,NAME of file to store traces" echo " Default:trace-<pid>" +echo " --with-trace-instrument=TYPE" +echo " Trace instrumentation type (none; default: $trace_instrument)" echo " --disable-spice disable spice" echo " --enable-spice enable spice" echo " --enable-rbd enable building the rados block device (rbd)"
@@ -3062,6 +3067,15 @@ if test "$trace_backend" = "dtrace"; then fi ########################################## +# Check instrumentation type +case "$trace_instrument" in +none) ;; +*) echo "Error: invalid trace instrumentation type: $trace_instrument" + exit 1 + ;; +esac + +########################################## # __sync_fetch_and_and requires at least -march=i486. Many toolchains # use i686 as default anyway, but for those that don't, an explicit # specification is necessary
@@ -3437,6 +3451,7 @@ echo "vhost-net support $vhost_net" echo "Trace events $trace_events" echo "Trace backend $trace_backend" echo "Trace output file $trace_file-<pid>" +echo "Trace instrument $trace_instrument" echo "spice support $spice ($spice_protocol_version/$spice_server_version)" echo "rbd support $rbd" echo "xfsctl support $xfs"
@@ -3859,6 +3874,22 @@ if test "$trace_default" = "yes"; then echo "CONFIG_TRACE_DEFAULT=y" >> $config_host_mak fi +########################################## +# trace instrumentation +config_qi=instrument/qemu-instr/config.h +mkdir -p `dirname $config_qi` +echo "/* Automatically generated by configure - do not modify */" > $config_qi + +echo "TRACE_INSTRUMENT_BACKEND=instr-$trace_instrument" >> $config_host_mak + +if test "$trace_instrument" = "none"; then + echo "#define QI_TYPE_CONFIG_NONE 1" >> $config_qi + echo "CONFIG_TRACE_INSTRUMENT_NONE=y" >> $config_host_mak +else + echo "CONFIG_TRACE_INSTRUMENT=y" >> $config_host_mak +fi +########################################## + echo "TOOLS=$tools" >> $config_host_mak echo "ROMS=$roms" >> $config_host_mak echo "MAKE=$make" >> $config_host_mak
include/trace.h +1 -1
@@ -1,6 +1,6 @@#ifndef TRACE_H #define TRACE_H -#include "trace/generated-tracers.h" +#include "instrument/generated-tracers.h" #endif /* TRACE_H */
instrument/Makefile.objs new file +24 -0
@@ -0,0 +1,24 @@ +# -*- mode: makefile -*- + +###################################################################### +# QEMU trace->instrument interface + +$(obj)/generated-tracers.h: $(obj)/generated-tracers.h-timestamp +$(obj)/generated-tracers.h-timestamp: $(TRACE_EVENTS) $(BUILD_DIR)/config-host.mak + $(call quiet-command,$(TRACETOOL) \ + --format=qemu-h \ + --backend=$(TRACE_INSTRUMENT_BACKEND) \ + < $< > $@," GEN $(patsubst %-timestamp,%,$@)") + @cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp,%,$@) + + +###################################################################### +# User interface + +$(obj)/qemu-instr/events.h: $(obj)/qemu-instr/events.h-timestamp +$(obj)/qemu-instr/events.h-timestamp: $(TRACE_EVENTS) $(BUILD_DIR)/config-host.mak + $(call quiet-command,$(TRACETOOL) \ + --format=api-h \ + --backend=$(TRACE_INSTRUMENT_BACKEND) \ + < $< > $@," GEN $(patsubst %-timestamp,%,$@)") + @cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp,%,$@)
scripts/tracetool/__init__.py +7 -2
@@ -122,7 +122,7 @@ class Event(object): _CRE = re.compile("((?P<props>.*)\s+)?(?P<name>[^(\s]+)\((?P<args>[^)]*)\)\s*(?P<fmt>\".*)?") - _VALID_PROPS = set(["disable"]) + _VALID_PROPS = set(["disable", "instrument"]) def __init__(self, name, props, fmt, args): """
@@ -146,6 +146,9 @@ class Event(object): if len(unknown_props) > 0: raise ValueError("Unknown properties: %s" % ", ".join(unknown_props)) + if "instrument" in self.properties and "disable" in self.properties: + raise ValueError("Cannot instrument a disabled event: %s" % self.name) + @staticmethod def build(line_str): """Build an Event instance from a string.
@@ -175,10 +178,12 @@ class Event(object): QEMU_TRACE = "trace_%(name)s" + QEMU_TRACE_BACKEND = "trace_%(name)s_backend" + QI_TRACE_INSTRUMENT = "qi_event_%(name)s" def api(self, fmt = None): if fmt is None: - fmt = Event.QEMU_TRACE + fmt = Event.QEMU_TRACE_BACKEND return fmt % { "name" : self.name } def _read_events(fobj):
scripts/tracetool/backend/instr_none.py new file +41 -0
41 lines not on this page · raw message
scripts/tracetool/format/api_h.py new file +39 -0
@@ -0,0 +1,39 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +Generate .h for trace instrumentation clients. +""" + +__author__ = "Lluís Vilanova <[email protected]>" +__copyright__ = "Copyright 2012-2013, Lluís Vilanova <[email protected]>" +__license__ = "GPL version 2 or (at your option) any later version" + +__maintainer__ = "Stefan Hajnoczi" +__email__ = "[email protected]" + + +from tracetool import out + + +def begin(events): + out('/* This file is autogenerated by tracetool, do not edit. */', + '', + '#ifndef QI__EVENTS_H', + '#define QI__EVENTS_H', + '', + '#ifdef __cplusplus', + 'extern "C" {', + '#endif', + '', + '#include <stdint.h>', + '', + ) + +def end(events): + out('#ifdef __cplusplus', + '}', + '#endif', + '', + '#endif /* QI__EVENTS_H */', + )
scripts/tracetool/format/qemu_h.py new file +68 -0
68 lines not on this page · raw message
PATCH v3 7/24 system: [linux] Use absolute include path for linux-headers
In reply to Lluís VilanovaLets the include directive work regardless of the current directory.
This is needed for code compiled in directories deeper than one level from the build root.
--- Makefile.target | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile.target +1 -1
@@ -7,7 +7,7 @@ include $(SRC_PATH)/rules.mak $(call set-vpath, $(SRC_PATH)) ifdef CONFIG_LINUX -QEMU_CFLAGS += -I../linux-headers +QEMU_CFLAGS += -I$(BUILD_DIR)/linux-headers endif QEMU_CFLAGS += -I.. -I$(SRC_PATH)/target-$(TARGET_BASE_ARCH) -DNEED_CPU_H
PATCH v3 8/24 instrument: [static] Call statically linked user-provided routines
In reply to Lluís VilanovaCompiles a user-provided static library during QEMU compilation.
This library must provide the implementation of the 'qi_event_*' routines.
--- Makefile.target | 2 + configure | 42 +++++++++++++++- instrument/Makefile.objs | 27 ++++++++++ scripts/tracetool.py | 14 ++++- scripts/tracetool/__init__.py | 10 +++- scripts/tracetool/backend/instr_static.py | 76 +++++++++++++++++++++++++++++ 6 files changed, 165 insertions(+), 6 deletions(-) create mode 100644 scripts/tracetool/backend/instr_static.py
Makefile.target +2 -0
@@ -149,6 +149,8 @@ include $(SRC_PATH)/Makefile.objs all-obj-y = $(obj-y) all-obj-y += $(addprefix ../, $(common-obj-y)) +all-obj-y += $(LIBTRACE_INSTRUMENT) + ifdef QEMU_PROGW # The linker builds a windows executable. Make also a console executable. $(QEMU_PROGW): $(all-obj-y) ../libqemuutil.a ../libqemustub.a
configure +40 -2
90 lines not on this page · raw message
instrument/Makefile.objs +27 -0
@@ -8,9 +8,15 @@ $(obj)/generated-tracers.h-timestamp: $(TRACE_EVENTS) $(BUILD_DIR)/config-host.m $(call quiet-command,$(TRACETOOL) \ --format=qemu-h \ --backend=$(TRACE_INSTRUMENT_BACKEND) \ + $(TRACETOOL_INSTR_STATIC) \ < $< > $@," GEN $(patsubst %-timestamp,%,$@)") @cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp,%,$@) +ifdef CONFIG_TRACE_INSTRUMENT_STATIC +# Rebuild to check for user headers +.PHONY: $(obj)/generated-tracers.h-timestamp +endif + ###################################################################### # User interface
@@ -20,5 +26,26 @@ $(obj)/qemu-instr/events.h-timestamp: $(TRACE_EVENTS) $(BUILD_DIR)/config-host.m $(call quiet-command,$(TRACETOOL) \ --format=api-h \ --backend=$(TRACE_INSTRUMENT_BACKEND) \ + $(TRACETOOL_INSTR_STATIC) \ < $< > $@," GEN $(patsubst %-timestamp,%,$@)") @cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp,%,$@) + + +###################################################################### +# User code (static instrumentation) + +ifdef CONFIG_TRACE_INSTRUMENT_STATIC +LIBTRACE_INSTRUMENT = libtrace-instrument/libtrace-instrument.a + +.PHONY: force +force: + +_libinstrument_cflags = $(subst libtrace-instrument,.,$(subst libtrace-instrument/,.,$(1))) +$(LIBTRACE_INSTRUMENT): QEMU_CFLAGS += -I$(BUILD_DIR)/ +$(LIBTRACE_INSTRUMENT): VPATH = $(TRACE_INSTRUMENT_PATH) +$(LIBTRACE_INSTRUMENT): $(dir $(LIBTRACE_INSTRUMENT))/Makefile force + $(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C $(dir $@) \ + QEMU_CFLAGS="$(call _libinstrument_cflags,$(QEMU_CFLAGS))" \ + TARGET_DIR=$(TARGET_DIR)$(dir $@)/ VPATH=$(VPATH) \ + SRC_PATH=$(SRC_PATH) V="$(V)" $(notdir $@)) +endif
scripts/tracetool.py +11 -3
@@ -6,7 +6,7 @@ Command-line wrapper for the tracetool machinery. """ __author__ = "Lluís Vilanova <[email protected]>" -__copyright__ = "Copyright 2012, Lluís Vilanova <[email protected]>" +__copyright__ = "Copyright 2012-2013, Lluís Vilanova <[email protected]>" __license__ = "GPL version 2 or (at your option) any later version" __maintainer__ = "Stefan Hajnoczi"
@@ -48,7 +48,10 @@ Options: --target-type <type> QEMU emulator target type ('system' or 'user'). --target-arch <arch> QEMU emulator target arch. --probe-prefix <prefix> Prefix for dtrace probe names - (default: qemu-<target-type>-<target-arch>).\ + (default: qemu-<target-type>-<target-arch>). + --instr-static--path <path> + Path to directory containing static instrumentation + library.\ """ % { "script" : _SCRIPT, "backends" : backend_descr,
@@ -67,6 +70,7 @@ def main(args): long_opts = [ "backend=", "format=", "help", "list-backends", "check-backend" ] long_opts += [ "binary=", "target-type=", "target-arch=", "probe-prefix=" ] + long_opts += [ "instr-static-path=" ] try: opts, args = getopt.getopt(args[1:], "", long_opts)
@@ -80,6 +84,7 @@ def main(args): target_type = None target_arch = None probe_prefix = None + instr_static_path = None for opt, arg in opts: if opt == "--help": error_opt()
@@ -104,6 +109,8 @@ def main(args): target_arch = arg elif opt == '--probe-prefix': probe_prefix = arg + elif opt == '--instr-static-path': + instr_static_path = arg else: error_opt("unhandled option: %s" % opt)
@@ -130,7 +137,8 @@ def main(args): try: tracetool.generate(sys.stdin, arg_format, arg_backend, - binary = binary, probe_prefix = probe_prefix) + binary = binary, probe_prefix = probe_prefix, + instr_static_path = instr_static_path) except tracetool.TracetoolError, e: error_opt(str(e))
scripts/tracetool/__init__.py +9 -1
@@ -180,6 +180,8 @@ class Event(object): QEMU_TRACE = "trace_%(name)s" QEMU_TRACE_BACKEND = "trace_%(name)s_backend" QI_TRACE_INSTRUMENT = "qi_event_%(name)s" + QI_TRACE_NOP = "qi_event_%(name)s_nop" + QI_TRACE_BACKEND = "qi_event_%(name)s_trace" def api(self, fmt = None): if fmt is None:
@@ -229,7 +231,8 @@ def try_import(mod_name, attr_name = None, attr_default = None): def generate(fevents, format, backend, - binary = None, probe_prefix = None): + binary = None, probe_prefix = None, + instr_static_path = None): """Generate the output for the given (format, backend) pair. Parameters
@@ -244,6 +247,8 @@ def generate(fevents, format, backend, See tracetool.backend.dtrace.BINARY. probe_prefix : str or None See tracetool.backend.dtrace.PROBEPREFIX. + instr_static_path : str or None + See tracetool.backend.instr_static.PATH. """ # fix strange python error (UnboundLocalError tracetool) import tracetool
@@ -270,6 +275,9 @@ def generate(fevents, format, backend, tracetool.backend.dtrace.BINARY = binary tracetool.backend.dtrace.PROBEPREFIX = probe_prefix + import tracetool.backend.instr_static + tracetool.backend.instr_static.PATH = instr_static_path + events = _read_events(fevents) if backend == "nop":
scripts/tracetool/backend/instr_static.py new file +76 -0
76 lines not on this page · raw message
PATCH v3 9/24 build: Add variable 'tools-obj-y' for tool-only files
In reply to Lluís Vilanova--- Makefile | 11 ++++++----- libcacard/Makefile | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-)
Makefile +6 -5
@@ -171,18 +171,19 @@ Makefile: $(version-obj-y) libqemustub.a: $(stub-obj-y) libqemuutil.a: $(util-obj-y) +libqemutools.a: $(tools-obj-y) ###################################################################### qemu-img.o: qemu-img-cmds.h -qemu-img$(EXESUF): qemu-img.o $(block-obj-y) libqemuutil.a libqemustub.a -qemu-nbd$(EXESUF): qemu-nbd.o $(block-obj-y) libqemuutil.a libqemustub.a -qemu-io$(EXESUF): qemu-io.o cmd.o $(block-obj-y) libqemuutil.a libqemustub.a +qemu-img$(EXESUF): qemu-img.o $(block-obj-y) libqemuutil.a libqemustub.a libqemutools.a +qemu-nbd$(EXESUF): qemu-nbd.o $(block-obj-y) libqemuutil.a libqemustub.a libqemutools.a +qemu-io$(EXESUF): qemu-io.o cmd.o $(block-obj-y) libqemuutil.a libqemustub.a libqemutools.a qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o -fsdev/virtfs-proxy-helper$(EXESUF): fsdev/virtfs-proxy-helper.o fsdev/virtio-9p-marshal.o libqemuutil.a libqemustub.a +fsdev/virtfs-proxy-helper$(EXESUF): fsdev/virtfs-proxy-helper.o fsdev/virtio-9p-marshal.o libqemuutil.a libqemustub.a libqemutools.a fsdev/virtfs-proxy-helper$(EXESUF): LIBS += -lcap qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx
@@ -218,7 +219,7 @@ $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-commands.py $(qapi-py) QGALIB_GEN=$(addprefix qga/qapi-generated/, qga-qapi-types.h qga-qapi-visit.h qga-qmp-commands.h) $(qga-obj-y) qemu-ga.o: $(QGALIB_GEN) -qemu-ga$(EXESUF): $(qga-obj-y) libqemuutil.a libqemustub.a +qemu-ga$(EXESUF): $(qga-obj-y) libqemuutil.a libqemustub.a libqemutools.a $(call LINK, $^) clean:
libcacard/Makefile +1 -1
@@ -16,7 +16,7 @@ $(libcacard-obj-y): | $(libcacard-lobj-y) all: libcacard.la libcacard.pc -vscclient$(EXESUF): libcacard/vscclient.o libcacard.la +vscclient$(EXESUF): libcacard/vscclient.o libcacard.la libqemutools.a $(call LINK,$^) #########################################################################
PATCH v3 10/24 instrument: [dynamic] Call dynamically linked user-provided routines
In reply to Lluís VilanovaProvides a mechanism to dynamically change the routine invoked by 'trace_*'.
--- .gitignore | 1 Makefile | 4 + Makefile.objs | 6 ++ configure | 8 ++- instrument/Makefile.objs | 11 ++++ libcacard/Makefile | 2 - scripts/tracetool/__init__.py | 1 scripts/tracetool/backend/instr_dynamic.py | 87 ++++++++++++++++++++++++++++ scripts/tracetool/format/api_c.py | 24 ++++++++ scripts/tracetool/format/events_c.py | 36 +++++++++++- trace/event-internal.h | 12 ++++ 11 files changed, 186 insertions(+), 6 deletions(-) create mode 100644 scripts/tracetool/backend/instr_dynamic.py create mode 100644 scripts/tracetool/format/api_c.py
.gitignore +1 -0
@@ -11,6 +11,7 @@ trace/generated-events.h trace/generated-events.c libcacard/trace/generated-tracers.c instrument/generated-tracers.h +instrument/generated-tracers.c instrument/qemu-instr/events.h *-timestamp *-softmmu
Makefile +4 -0
@@ -36,6 +36,9 @@ GENERATED_HEADERS += qmp-commands.h qapi-types.h qapi-visit.h GENERATED_SOURCES += qmp-marshal.c qapi-types.c qapi-visit.c GENERATED_HEADERS += instrument/generated-tracers.h +ifdef CONFIG_TRACE_INSTRUMENT_DYNAMIC +GENERATED_SOURCES += instrument/generated-tracers.c +endif GENERATED_HEADERS += instrument/qemu-instr/events.h GENERATED_HEADERS += trace/generated-events.h
@@ -234,6 +237,7 @@ clean: @# May not be present in GENERATED_HEADERS rm -f trace/generated-tracers-dtrace.dtrace* rm -f trace/generated-tracers-dtrace.h* + rm -f instrument/generated-tracers.c* rm -f $(foreach f,$(GENERATED_HEADERS),$(f) $(f)-timestamp) rm -f $(foreach f,$(GENERATED_SOURCES),$(f) $(f)-timestamp) rm -rf qapi-generated
Makefile.objs +6 -0
@@ -91,6 +91,11 @@ common-obj-y += qom/ common-obj-y += disas/ ###################################################################### +# instrumentation + +tools-obj-y += instrument/ + +###################################################################### # guest agent # FIXME: a few definitions from qapi-types.o/qapi-visit.o are needed
@@ -108,5 +113,6 @@ nested-vars += \ util-obj-y \ qga-obj-y \ block-obj-y \ + tools-obj-y \ common-obj-y dummy := $(call unnest-vars)
configure +6 -2
@@ -1173,7 +1173,7 @@ echo " Available backends:" $($python "$source_path"/s echo " --with-trace-file=NAME Full PATH,NAME of file to store traces" echo " Default:trace-<pid>" echo " --with-trace-instrument=TYPE" -echo " Trace instrumentation type (none static; default: $trace_instrument)" +echo " Trace instrumentation type (none static dynamic; default: $trace_instrument)" echo " --with-trace-instrument-path=PATH" echo " Directory to build user-provided static trace event instrumentation library" echo " --disable-spice disable spice"
@@ -3074,7 +3074,7 @@ fi ########################################## # Check instrumentation type case "$trace_instrument" in -none|static) ;; +none|static|dynamic) ;; *) echo "Error: invalid trace instrumentation type: $trace_instrument" exit 1 ;;
@@ -3922,6 +3922,10 @@ if test "$trace_instrument" = "static"; then echo "TRACETOOL_INSTR_STATIC=--instr-static-path \"\$(TRACE_INSTRUMENT_PATH)\"" >> $config_host_mak QEMU_CFLAGS="-I\"$trace_instrument_path\" $QEMU_CFLAGS" fi +if test "$trace_instrument" = "dynamic"; then + echo "#define QI_TYPE_CONFIG_DYNAMIC 1" >> $config_qi + echo "CONFIG_TRACE_INSTRUMENT_DYNAMIC=y" >> $config_host_mak +fi ########################################## echo "TOOLS=$tools" >> $config_host_mak
instrument/Makefile.objs +11 -0
@@ -17,6 +17,17 @@ ifdef CONFIG_TRACE_INSTRUMENT_STATIC .PHONY: $(obj)/generated-tracers.h-timestamp endif +$(obj)/generated-tracers.c: $(obj)/generated-tracers.c-timestamp +$(obj)/generated-tracers.c-timestamp: $(TRACE_EVENTS) $(BUILD_DIR)/config-host.mak + $(call quiet-command,$(TRACETOOL) \ + --format=api-c \ + --backend=$(TRACE_INSTRUMENT_BACKEND) \ + < $< > $@," GEN $(patsubst %-timestamp,%,$@)") + @cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp,%,$@) + +tools-obj-$(CONFIG_TRACE_INSTRUMENT_DYNAMIC) += generated-tracers.o +target-obj-$(CONFIG_TRACE_INSTRUMENT_DYNAMIC) += generated-tracers.o + ###################################################################### # User interface
libcacard/Makefile +1 -1
@@ -7,7 +7,7 @@ libcacard-obj-y = $(stub-obj-y) $(libcacard-y) libcacard-obj-y += util/osdep.o util/cutils.o util/qemu-timer-common.o util/error.o libcacard-obj-$(CONFIG_WIN32) += util/oslib-win32.o util/qemu-thread-win32.o libcacard-obj-$(CONFIG_POSIX) += util/oslib-posix.o util/qemu-thread-posix.o -libcacard-obj-y += $(filter trace/%, $(util-obj-y)) +libcacard-obj-y += $(filter trace/%, $(util-obj-y)) $(filter instrument/%, $(util-obj-y)) libcacard-lobj-y=$(patsubst %.o,%.lo,$(libcacard-obj-y))
scripts/tracetool/__init__.py +1 -0
@@ -182,6 +182,7 @@ class Event(object): QI_TRACE_INSTRUMENT = "qi_event_%(name)s" QI_TRACE_NOP = "qi_event_%(name)s_nop" QI_TRACE_BACKEND = "qi_event_%(name)s_trace" + QI_TRACE_CB = QI_TRACE_NOP def api(self, fmt = None): if fmt is None:
scripts/tracetool/backend/instr_dynamic.py new file +87 -0
87 lines not on this page · raw message
scripts/tracetool/format/api_c.py new file +24 -0
@@ -0,0 +1,24 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +Generate .c for trace instrumentation clients. +""" + +__author__ = "Lluís Vilanova <[email protected]>" +__copyright__ = "Copyright 2012-2013, Lluís Vilanova <[email protected]>" +__license__ = "GPL version 2 or (at your option) any later version" + +__maintainer__ = "Stefan Hajnoczi" +__email__ = "[email protected]" + + +from tracetool import out + + +def begin(events): + out('/* This file is autogenerated by tracetool, do not edit. */', + '', + '#include <stdlib.h>', + '', + )
scripts/tracetool/format/events_c.py +34 -2
@@ -6,7 +6,7 @@ Generate .c for event description. """ __author__ = "Lluís Vilanova <[email protected]>" -__copyright__ = "Copyright 2012, Lluís Vilanova <[email protected]>" +__copyright__ = "Copyright 2012-2013, Lluís Vilanova <[email protected]>" __license__ = "GPL version 2 or (at your option) any later version" __maintainer__ = "Stefan Hajnoczi"
@@ -19,17 +19,49 @@ from tracetool import out def begin(events): out('/* This file is autogenerated by tracetool, do not edit. */', '', + '#include "config-host.h"', '#include "trace.h"', '#include "trace/generated-events.h"', '#include "trace/control.h"', '', ) + # declarations + out('#if defined(CONFIG_TRACE_INSTRUMENT_DYNAMIC)') + for e in events: + if "instrument" in e.properties: + out('void %(nop)s(%(args)s);', + 'void %(backend)s(%(args)s);', + nop = e.api(e.QI_TRACE_NOP), + backend = e.api(e.QI_TRACE_BACKEND), + args = e.args, + ) + out('#endif', + '', + ) + + # event state out('TraceEvent trace_events[TRACE_EVENT_COUNT] = {') for e in events: - out(' { .id = %(id)s, .name = \"%(name)s\", .sstate = %(sstate)s, .dstate = 0 },', + cb = cb_nop = cb_backend = "NULL" + + if "instrument" in e.properties: + cb = "&%s_cb" % e.api(e.QI_TRACE_INSTRUMENT) + cb_nop = e.api(e.QI_TRACE_NOP) + cb_backend = e.api(e.QI_TRACE_BACKEND) + + out(' { .id = %(id)s, .name = \"%(name)s\", .sstate = %(sstate)s, .dstate = 0,', + '#if defined(CONFIG_TRACE_INSTRUMENT_DYNAMIC)', + ' .instr_cb = %(cb)s,', + ' .instr_cb_nop = %(cb_nop)s,', + ' .instr_cb_backend = %(cb_backend)s,', + '#endif', + ' },', id = "TRACE_" + e.name.upper(), + cb = cb, + cb_nop = cb_nop, + cb_backend = cb_backend, name = e.name, sstate = "TRACE_%s_ENABLED" % e.name.upper(), )
trace/event-internal.h +11 -1
@@ -1,7 +1,7 @@/* * Interface for configuring and controlling the state of tracing events. * -* Copyright (C) 2012 Lluís Vilanova <[email protected]> +* Copyright (C) 2012-2013 Lluís Vilanova <[email protected]> * * This work is licensed under the terms of the GNU GPL, version 2 or later. * See the COPYING file in the top-level directory.
@@ -11,6 +11,7 @@#define TRACE__EVENT_INTERNAL_H #include "trace/generated-events.h" +#include "config-host.h" /**
@@ -19,6 +20,9 @@* @name: Event name. * @sstate: Static tracing state. * @dstate: Dynamic tracing state. +* @instr_cb: Instrumentation callback pointer. +* @instr_cb_nop: Instrumentation callback pointer to no-operation. +* @instr_cb_backend: Instrumentation callback pointer to tracing backend. * * Opaque generic description of a tracing event. */
@@ -27,6 +31,12 @@ typedef struct TraceEvent {const char * name;const bool sstate;bool dstate; + +#if defined(CONFIG_TRACE_INSTRUMENT_DYNAMIC ) +void **instr_cb; +void *instr_cb_nop; +void *instr_cb_backend; +#endif } TraceEvent;
PATCH v3 11/24 qapi: Add a primitive to include other files from a QAPI schema file
In reply to Lluís VilanovaAdds the "include(...)" primitive to the syntax of QAPI schema files.
--- scripts/qapi-commands.py | 10 +++++++--- scripts/qapi-types.py | 10 +++++++--- scripts/qapi-visit.py | 10 +++++++--- scripts/qapi.py | 12 +++++++++++- 4 files changed, 32 insertions(+), 10 deletions(-)
scripts/qapi-commands.py +7 -3
@@ -386,13 +386,15 @@ def gen_command_def_prologue(prefix="", proxy=False): try: - opts, args = getopt.gnu_getopt(sys.argv[1:], "chp:o:m", + opts, args = getopt.gnu_getopt(sys.argv[1:], "chp:i:o:m", ["source", "header", "prefix=", - "output-dir=", "type=", "middle"]) + "input-dir=", "output-dir=", + "type=", "middle"]) except getopt.GetoptError, err: print str(err) sys.exit(1) +input_dir = "" output_dir = "" prefix = "" dispatch_type = "sync"
@@ -406,6 +408,8 @@ do_h = False for o, a in opts: if o in ("-p", "--prefix"): prefix = a + elif o in ("-i", "--input-dir"): + input_dir = a elif o in ("-o", "--output-dir"): output_dir = a + "/" elif o in ("-t", "--type"):
@@ -437,7 +441,7 @@ except os.error, e: if e.errno != errno.EEXIST: raise -exprs = parse_schema(sys.stdin) +exprs = parse_schema(sys.stdin, input_dir) commands = filter(lambda expr: expr.has_key('command'), exprs) commands = filter(lambda expr: not expr.has_key('gen'), commands)
scripts/qapi-types.py +7 -3
@@ -184,13 +184,15 @@ void qapi_free_%(type)s(%(c_type)s obj) try: - opts, args = getopt.gnu_getopt(sys.argv[1:], "chp:o:", - ["source", "header", "prefix=", "output-dir="]) + opts, args = getopt.gnu_getopt(sys.argv[1:], "chp:i:o:", + ["source", "header", "prefix=", + "input-dir=", "output-dir="]) except getopt.GetoptError, err: print str(err) sys.exit(1) output_dir = "" +input_dir = "" prefix = "" c_file = 'qapi-types.c' h_file = 'qapi-types.h'
@@ -201,6 +203,8 @@ do_h = False for o, a in opts: if o in ("-p", "--prefix"): prefix = a + elif o in ("-i", "--input-dir"): + input_dir = a elif o in ("-o", "--output-dir"): output_dir = a + "/" elif o in ("-c", "--source"):
@@ -279,7 +283,7 @@ fdecl.write(mcgen(''' ''', guard=guardname(h_file))) -exprs = parse_schema(sys.stdin) +exprs = parse_schema(sys.stdin, input_dir) exprs = filter(lambda expr: not expr.has_key('gen'), exprs) for expr in exprs:
scripts/qapi-visit.py +7 -3
@@ -235,12 +235,14 @@ void visit_type_%(name)s(Visitor *m, %(name)s * obj, const char *name, Error **e name=name) try: - opts, args = getopt.gnu_getopt(sys.argv[1:], "chp:o:", - ["source", "header", "prefix=", "output-dir="]) + opts, args = getopt.gnu_getopt(sys.argv[1:], "chp:i:o:", + ["source", "header", "prefix=", + "input-dir=", "output-dir="]) except getopt.GetoptError, err: print str(err) sys.exit(1) +input_dir = "" output_dir = "" prefix = "" c_file = 'qapi-visit.c'
@@ -252,6 +254,8 @@ do_h = False for o, a in opts: if o in ("-p", "--prefix"): prefix = a + elif o in ("-i", "--input-dir"): + input_dir = a elif o in ("-o", "--output-dir"): output_dir = a + "/" elif o in ("-c", "--source"):
@@ -327,7 +331,7 @@ fdecl.write(mcgen(''' ''', prefix=prefix, guard=guardname(h_file))) -exprs = parse_schema(sys.stdin) +exprs = parse_schema(sys.stdin, input_dir) for expr in exprs: if expr.has_key('type'):
scripts/qapi.py +11 -1
@@ -9,8 +9,12 @@ # This work is licensed under the terms of the GNU GPLv2. # See the COPYING.LIB file in the top-level directory. +import os +import re from ordereddict import OrderedDict +include_cre = re.compile("\s*include\(\"([^\"]*)\"\)") + def tokenize(data): while len(data): ch = data[0]
@@ -72,7 +76,7 @@ def parse(tokens): def evaluate(string): return parse(map(lambda x: x, tokenize(string)))[0] -def parse_schema(fp): +def parse_schema(fp, input_dir): exprs = [] expr = '' expr_eval = None
@@ -81,6 +85,12 @@ def parse_schema(fp): if line.startswith('#') or line == '\n': continue + line_file = include_cre.match(line) + if line_file is not None: + path = os.sep.join([input_dir, line_file.group(1)]) + exprs += parse_schema(file(path), input_dir) + continue + if line.startswith(' '): expr += line elif expr:
PATCH v3 12/24 qapi: [trivial] Set the input root directory when parsing QAPI files
In reply to Lluís Vilanova--- Makefile | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
Makefile +9 -3
@@ -211,13 +211,19 @@ $(SRC_PATH)/qga/qapi-schema.json $(SRC_PATH)/scripts/qapi-commands.py $(qapi-py) qapi-types.c qapi-types.h :\ $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-types.py $(qapi-py) - $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py $(gen-out-type) -o "." < $<, " GEN $@") + $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py \ + $(gen-out-type) -o "." -i "$(SRC_PATH)" \ + < $<, " GEN $@") qapi-visit.c qapi-visit.h :\ $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-visit.py $(qapi-py) - $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py $(gen-out-type) -o "." < $<, " GEN $@") + $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py \ + $(gen-out-type) -o "." -i "$(SRC_PATH)" \ + < $<, " GEN $@") qmp-commands.h qmp-marshal.c :\ $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-commands.py $(qapi-py) - $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py $(gen-out-type) -m -o "." < $<, " GEN $@") + $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py \ + $(gen-out-type) -m -o "." -i "$(SRC_PATH)" \ + < $<, " GEN $@") QGALIB_GEN=$(addprefix qga/qapi-generated/, qga-qapi-types.h qga-qapi-visit.h qga-qmp-commands.h) $(qga-obj-y) qemu-ga.o: $(QGALIB_GEN)
PATCH v3 13/24 qapi: [trivial] Allow user to use 'args' as an argument name
In reply to Lluís Vilanova--- scripts/qapi-commands.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
scripts/qapi-commands.py +4 -4
@@ -207,7 +207,7 @@ def gen_marshal_input_decl(name, args, ret_type, middle_mode): if middle_mode: return 'int qmp_marshal_input_%s(Monitor *mon, const QDict *qdict, QObject **ret)' % c_fun(name) else: - return 'static void qmp_marshal_input_%s(QDict *args, QObject **ret, Error **errp)' % c_fun(name) + return 'static void qmp_marshal_input_%s(QDict *args_, QObject **ret, Error **errp)' % c_fun(name)
@@ -224,7 +224,7 @@ def gen_marshal_input(name, args, ret_type, middle_mode): ret += mcgen(''' Error *local_err = NULL; Error **errp = &local_err; - QDict *args = (QDict *)qdict; + QDict *args_ = (QDict *)qdict; ''') if ret_type:
@@ -247,10 +247,10 @@ def gen_marshal_input(name, args, ret_type, middle_mode): ''', visitor_input_containers_decl=gen_visitor_input_containers_decl(args), visitor_input_vars_decl=gen_visitor_input_vars_decl(args), - visitor_input_block=gen_visitor_input_block(args, "QOBJECT(args)")) + visitor_input_block=gen_visitor_input_block(args, "QOBJECT(args_)")) else: ret += mcgen(''' - (void)args; + (void)args_; ''') ret += mcgen('''
PATCH v3 14/24 instrument: Add internal control interface
In reply to Lluís VilanovaThis interface provides two sets of operations:
* Loading/unloading a trace instrumentation library.
* Controls the instrumentation callbacks of the tracing events.
Note that in the case of static instrumentation, the library is not loaded/unloaded, but is still properly (de)initialized when QEMU starts and exits.
--- Makefile.objs | 2 configure | 3 instrument/Makefile.objs | 6 + instrument/control-internal.h | 40 +++++ instrument/control.c | 226 ++++++++++++++++++++++++++++ instrument/control.h | 148 ++++++++++++++++++ instrument/qapi-schema.json | 26 +++ qapi-schema.json | 2 rules.mak | 3 scripts/tracetool/backend/instr_dynamic.py | 3 scripts/tracetool/backend/instr_static.py | 3 scripts/tracetool/format/events_c.py | 6 + trace/event-internal.h | 5 + 13 files changed, 473 insertions(+) create mode 100644 instrument/control-internal.h create mode 100644 instrument/control.c create mode 100644 instrument/control.h create mode 100644 instrument/qapi-schema.json
Makefile.objs +2 -0
@@ -94,6 +94,7 @@ common-obj-y += disas/ # instrumentation tools-obj-y += instrument/ +target-obj-y += instrument/ ###################################################################### # guest agent
@@ -114,5 +115,6 @@ nested-vars += \ qga-obj-y \ block-obj-y \ tools-obj-y \ + target-obj-y \ common-obj-y dummy := $(call unnest-vars)
configure +3 -0
@@ -3925,7 +3925,10 @@ fi if test "$trace_instrument" = "dynamic"; then echo "#define QI_TYPE_CONFIG_DYNAMIC 1" >> $config_qi echo "CONFIG_TRACE_INSTRUMENT_DYNAMIC=y" >> $config_host_mak + libs_qga="-ldl $libs_qga" fi +# code requiring it is always compiled-in +LIBS="-ldl $LIBS" ########################################## echo "TOOLS=$tools" >> $config_host_mak
instrument/Makefile.objs +6 -0
@@ -60,3 +60,9 @@ $(LIBTRACE_INSTRUMENT): $(dir $(LIBTRACE_INSTRUMENT))/Makefile force TARGET_DIR=$(TARGET_DIR)$(dir $@)/ VPATH=$(VPATH) \ SRC_PATH=$(SRC_PATH) V="$(V)" $(notdir $@)) endif + + +###################################################################### +# Control code + +target-obj-y += control.o
instrument/control-internal.h new file +40 -0
@@ -0,0 +1,40 @@ +/* +* Interface for controlling dynamic trace instrumentation. +* +* Copyright (C) 2012-2013 Lluís Vilanova <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef INSTRUMENT__CONTROL_INTERNAL_H +#define INSTRUMENT__CONTROL_INTERNAL_H + +#include <assert.h> +#include <stdlib.h> + +#include "config-host.h" + + +static inline InstrType instr_type (void ) +{ +#if defined(CONFIG_TRACE_INSTRUMENT_DYNAMIC ) +return INSTR_TYPE_DYNAMIC ; +#elif defined(CONFIG_TRACE_INSTRUMENT_STATE ) +return INSTR_TYPE_STATIC ; +#else +return INSTR_TYPE_NONE ; +#endif +} + +static inline bool instr_event_available (TraceEvent *ev) +{ +assert (ev !=NULL ); +#if defined(CONFIG_TRACE_INSTRUMENT ) +return ev->instr; +#else +return false; +#endif +} + +#endif /* INSTRUMENT__CONTROL_INTERNAL_H */
instrument/control.c new file +226 -0
226 lines not on this page · raw message
instrument/control.h new file +148 -0
148 lines not on this page · raw message
instrument/qapi-schema.json new file +26 -0
@@ -0,0 +1,26 @@ +# *-*- Mode: Python -*-* +# +# QAPI trace instrumentation control commands. +# +# Copyright (C) 2012-2013 Lluís Vilanova <[email protected]> +# +# This work is licensed under the terms of the GNU GPL, version 2 or later. +# See the COPYING file in the top-level directory. + +## +# @InstrType +# +# Instrumentation type supported by the system. +# +# @None: No instrumentation support. +# +# @Static: Static instrumentation support. +# +# @Dynamic: Dynamic instrumentation support. +# +# Warning: Keep in sync with #QIType. +# +# Since: 1.5 +## +{ 'enum': 'InstrType', + 'data': [ 'None', 'Static', 'Dynamic' ] }
qapi-schema.json +2 -0
@@ -3513,3 +3513,5 @@ '*asl_compiler_rev': 'uint32', '*file': 'str', '*data': 'str' }} + +include("instrument/qapi-schema.json")
rules.mak +3 -0
@@ -51,6 +51,9 @@ endif %.o: %.dtrace $(call quiet-command,dtrace -o $@ -G -s $<, " GEN $(TARGET_DIR)$@") +ifdef CONFIG_TRACE_INSTRUMENT_DYNAMIC +%$(EXESUF): LDFLAGS+=-rdynamic +endif %$(EXESUF): %.o $(call LINK,$^)
scripts/tracetool/backend/instr_dynamic.py +3 -0
@@ -40,6 +40,9 @@ def qemu_h(events): def api_h(events): out('#include <qemu-instr/visibility-internal.h>', '', + 'QI_VPUBLIC void qi_init(int argc, const char **argv);', + 'QI_VPUBLIC void qi_fini(void);', + '', ) for e in events:
scripts/tracetool/backend/instr_static.py +3 -0
@@ -46,6 +46,9 @@ def qemu_h(events): def api_h(events): out('#include "trace/generated-tracers.h"', '', + 'void qi_init(int argc, const char **argv);', + 'void qi_fini(void);', + '', ) for e in events:
scripts/tracetool/format/events_c.py +6 -0
@@ -44,14 +44,19 @@ def begin(events): out('TraceEvent trace_events[TRACE_EVENT_COUNT] = {') for e in events: + instr = "false" cb = cb_nop = cb_backend = "NULL" if "instrument" in e.properties: + instr = "true" cb = "&%s_cb" % e.api(e.QI_TRACE_INSTRUMENT) cb_nop = e.api(e.QI_TRACE_NOP) cb_backend = e.api(e.QI_TRACE_BACKEND) out(' { .id = %(id)s, .name = \"%(name)s\", .sstate = %(sstate)s, .dstate = 0,', + '#if !defined(CONFIG_TRACE_INSTRUMENT_NONE)', + ' .instr = %(instr)s,', + '#endif', '#if defined(CONFIG_TRACE_INSTRUMENT_DYNAMIC)', ' .instr_cb = %(cb)s,', ' .instr_cb_nop = %(cb_nop)s,',
@@ -59,6 +64,7 @@ def begin(events): '#endif', ' },', id = "TRACE_" + e.name.upper(), + instr = instr, cb = cb, cb_nop = cb_nop, cb_backend = cb_backend,
trace/event-internal.h +5 -0
@@ -20,6 +20,7 @@* @name: Event name. * @sstate: Static tracing state. * @dstate: Dynamic tracing state. +* @instr: Whether the event is instrumentable. * @instr_cb: Instrumentation callback pointer. * @instr_cb_nop: Instrumentation callback pointer to no-operation. * @instr_cb_backend: Instrumentation callback pointer to tracing backend.
@@ -32,6 +33,10 @@ typedef struct TraceEvent {const bool sstate;bool dstate; +#if defined(CONFIG_TRACE_INSTRUMENT ) +const bool instr; +#endif +#if defined(CONFIG_TRACE_INSTRUMENT_DYNAMIC )void **instr_cb;void *instr_cb_nop;
PATCH v3 15/24 instrument: [qmp, qapi] Add control interface
In reply to Lluís VilanovaAdd QMP commands to control (un)loading of dynamic instrumentation library.
--- instrument/Makefile.objs | 2 + instrument/control.h | 4 + instrument/qapi-schema.json | 124 +++++++++++++++++++++++++++++++++++++++++++ instrument/qmp.c | 78 +++++++++++++++++++++++++++ qmp-commands.hx | 71 +++++++++++++++++++++++++ qmp.c | 4 + 6 files changed, 283 insertions(+) create mode 100644 instrument/qmp.c
instrument/Makefile.objs +2 -0
@@ -66,3 +66,5 @@ endif # Control code target-obj-y += control.o + +common-obj-$(CONFIG_SOFTMMU) += qmp.o
instrument/control.h +4 -0
@@ -21,6 +21,8 @@* @INSTR_LOAD_ERROR: Error with libdl (see dlerror). * * Error codes for instr_load(). +* +* Warning: Keep in sync with #InstrLoadCode */ typedef enum { INSTR_LOAD_OK,
@@ -36,6 +38,8 @@ typedef enum {* @INSTR_UNLOAD_ERROR: Error with libdl (see dlerror). * * Error codes for instr_unload(). +* +* Warning: Keep in sync with #InstrUnloadCode */ typedef enum { INSTR_UNLOAD_OK,
instrument/qapi-schema.json +124 -0
127 lines not on this page · raw message
instrument/qmp.c new file +78 -0
78 lines not on this page · raw message
qmp-commands.hx +71 -0
77 lines not on this page · raw message
qmp.c +4 -0
@@ -24,6 +24,10 @@#include "hw/qdev.h" #include "sysemu/blockdev.h" #include "qom/qom-qobject.h" +#if defined(TRACE_INSTRUMENT_DYNAMIC ) +#include "instrument/qi-qmp-commands.h" +#endif +NameInfo *qmp_query_name (Error **errp) {
PATCH v3 16/24 instrument: [hmp] Add control interface
In reply to Lluís VilanovaAdd HMP commands to control (un)loading of dynamic instrumentation library.
--- Makefile.objs | 1 + hmp-commands.hx | 42 ++++++++++++++++++++++++ instrument/Makefile.objs | 1 + instrument/hmp.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++ instrument/hmp.h | 21 ++++++++++++ monitor.c | 1 + 6 files changed, 145 insertions(+) create mode 100644 instrument/hmp.c create mode 100644 instrument/hmp.h
Makefile.objs +1 -0
@@ -95,6 +95,7 @@ common-obj-y += disas/ tools-obj-y += instrument/ target-obj-y += instrument/ +common-obj-y += instrument/ ###################################################################### # guest agent
hmp-commands.hx +42 -0
48 lines not on this page · raw message
instrument/Makefile.objs +1 -0
@@ -68,3 +68,4 @@ endif target-obj-y += control.o common-obj-$(CONFIG_SOFTMMU) += qmp.o +common-obj-$(CONFIG_SOFTMMU) += hmp.o
instrument/hmp.c new file +79 -0
79 lines not on this page · raw message
instrument/hmp.h new file +21 -0
@@ -0,0 +1,21 @@ +/* +* HMP interface for dynamic trace instrumentation control commands. +* +* Copyright (C) 2012-2013 Lluís Vilanova <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef INSTRUMENT__HMP_H +#define INSTRUMENT__HMP_H + +#include "qemu-common.h" +#include "qapi/qmp/qdict.h" + + +void hmp_instr_query (Monitor *mon,const QDict *qdict); +void hmp_instr_load (Monitor *mon,const QDict *qdict); +void hmp_instr_unload (Monitor *mon,const QDict *qdict); + +#endif /* INSTRUMENT__HMP_H */
monitor.c +1 -0
@@ -69,6 +69,7 @@#include "exec/memory.h" #include "qmp-commands.h" #include "hmp.h" +#include "instrument/hmp.h" #include "qemu/thread.h" /* for pic/irq_info */
PATCH v3 17/24 Let makefiles add entries to the set of target architecture objects
In reply to Lluís Vilanova--- Makefile.target | 1 + 1 file changed, 1 insertion(+)
Makefile.target +1 -0
@@ -149,6 +149,7 @@ include $(SRC_PATH)/Makefile.objs all-obj-y = $(obj-y) all-obj-y += $(addprefix ../, $(common-obj-y)) +all-obj-y += $(target-obj-y) all-obj-y += $(LIBTRACE_INSTRUMENT) ifdef QEMU_PROGW
PATCH v3 18/24 instrument: Add commandline options to start with an instrumentation library
In reply to Lluís VilanovaAdd commandline options to control initial loading of dynamic instrumentation library.
--- bsd-user/main.c | 22 +++++++++++ bsd-user/syscall.c | 5 +++ instrument/Makefile.objs | 2 + instrument/cmdline.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++ instrument/cmdline.h | 52 ++++++++++++++++++++++++++ linux-user/main.c | 31 ++++++++++++++++ linux-user/syscall.c | 4 ++ qemu-options.hx | 18 +++++++++ vl.c | 41 +++++++++++++++++++++ 9 files changed, 266 insertions(+) create mode 100644 instrument/cmdline.c create mode 100644 instrument/cmdline.h
bsd-user/main.c +22 -0
@@ -33,6 +33,9 @@#include "tcg.h" #include "qemu/timer.h" #include "qemu/envlist.h" +#include "instrument/cmdline.h" +#include "instrument/control.h" +int singlestep;#if defined(CONFIG_USE_GUEST_BASE )
@@ -688,6 +691,15 @@ static void usage(void)#endif "-bsd type select emulated BSD type FreeBSD/NetBSD/OpenBSD (default)\n" "\n" +#if defined(CONFIG_TRACE_INSTRUMENT ) + "Tracing options:\n" +#if defined(CONFIG_TRACE_INSTRUMENT_DYNAMIC ) +"-instr path load a dynamic trace instrumentation library\n" +#endif +"-instr-arg string\n" +" argument to trace instrumentation library (can be given multiple times)\n" + "\n" +#endif "Debug options:\n" "-d item1[,...] enable logging of specified items\n" " (use '-d help' for a list of log items)\n"
@@ -743,6 +755,9 @@ int main(int argc, char **argv)char **target_environ, **wrk;envlist_t *envlist =NULL ; bsd_type = target_openbsd; +char *instrument_path =NULL ; +int instrument_argc =0 ; +char **instrument_argv =NULL ;if (argc <=1 )usage ();
@@ -852,6 +867,10 @@ int main(int argc, char **argv) singlestep =1 ; }else if (!strcmp (r,"strace" )) { do_strace =1 ; + }else if (instr_type () ==INSTR_TYPE_DYNAMIC && !strcmp (r,"instr" )) { + instrument_path = argv[optind++]; + }else if (instr_type () !=INSTR_TYPE_NONE && !strcmp (r,"instr-arg" )) { +instr_parse_args (argv[optind++], &instrument_argc, &instrument_argv); }else {usage ();
@@ -1135,6 +1154,9 @@ int main(int argc, char **argv)gdbserver_start (gdbstub_port);gdb_handlesig (env,0 ); } + +instr_init (instrument_path, instrument_argc, instrument_argv); +cpu_loop (env);/* never exits */ return 0 ;
bsd-user/syscall.c +5 -0
@@ -35,6 +35,8 @@#include "qemu.h" #include "qemu-common.h" +#include "instrument/cmdline.h" +//#define DEBUG
@@ -334,6 +336,7 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1,_mcleanup ();#endif gdb_exit (cpu_env, arg1); +instr_fini ();/* XXX: should free thread stack and CPU env */ _exit (arg1); ret =0 ;/* avoid warning */
@@ -429,6 +432,7 @@ abi_long do_netbsd_syscall(void *cpu_env, int num, abi_long arg1,_mcleanup ();#endif gdb_exit (cpu_env, arg1); +instr_fini ();/* XXX: should free thread stack and CPU env */ _exit (arg1); ret =0 ;/* avoid warning */
@@ -501,6 +505,7 @@ abi_long do_openbsd_syscall(void *cpu_env, int num, abi_long arg1,_mcleanup ();#endif gdb_exit (cpu_env, arg1); +instr_fini ();/* XXX: should free thread stack and CPU env */ _exit (arg1); ret =0 ;/* avoid warning */
instrument/Makefile.objs +2 -0
@@ -65,6 +65,8 @@ endif ###################################################################### # Control code +target-obj-y += cmdline.o + target-obj-y += control.o common-obj-$(CONFIG_SOFTMMU) += qmp.o
instrument/cmdline.c new file +91 -0
91 lines not on this page · raw message
instrument/cmdline.h new file +52 -0
52 lines not on this page · raw message
linux-user/main.c +31 -0
@@ -34,6 +34,9 @@#include "qemu/timer.h" #include "qemu/envlist.h" #include "elf.h" +#include "instrument/cmdline.h" +#include "instrument/control.h" +char *exec_path;
@@ -3327,6 +3330,23 @@ static void handle_arg_reserved_va(const char *arg) }#endif +static const char *instrument_path; +#if defined(CONFIG_TRACE_INSTRUMENT_DYNAMIC ) +static void handle_arg_instrument (const char *arg) +{ + instrument_path = arg; +} +#endif + +static int instrument_argc =0 ; +static const char **instrument_argv =NULL ; +#if defined(CONFIG_TRACE_INSTRUMENT ) +static void handle_arg_instrument_arg (const char *arg) +{ +instr_parse_args (arg, &instrument_argc, &instrument_argv); +} +#endif +static void handle_arg_singlestep (const char *arg) { singlestep =1 ;
@@ -3378,6 +3398,14 @@ static const struct qemu_argument arg_table[] = { {"R", "QEMU_RESERVED_VA", true, handle_arg_reserved_va, "size", "reserve 'size' bytes for guest virtual address space"}, #endif +#if defined(CONFIG_TRACE_INSTRUMENT_DYNAMIC) + {"instr", "QEMU_INSTR", true, handle_arg_instrument, + "path", "load a dynamic trace instrumentation library"}, +#endif +#if defined(CONFIG_TRACE_INSTRUMENT) + {"instr-arg", "QEMU_INSTR_ARGS", true, handle_arg_instrument_arg, + "string", "argument to trace instrumentation library (can be given multiple times)"}, +#endif {"d", "QEMU_LOG", true, handle_arg_log, "item[,...]", "enable logging of specified items " "(use '-d help' for a list of items)"},
@@ -4071,6 +4099,9 @@ int main(int argc, char **argv, char **envp) }gdb_handlesig (env,0 ); } + +instr_init (instrument_path, instrument_argc, instrument_argv); +cpu_loop (env);/* never exits */ return 0 ;
linux-user/syscall.c +4 -0
@@ -109,6 +109,8 @@ int __clone2(int (*fn)(void *), void *child_stack_base,#include "cpu-uname.h" #include "qemu.h" +#include "instrument/cmdline.h" +#if defined(CONFIG_USE_NPTL )#define CLONE_NPTL_FLAGS2 (CLONE_SETTLS | \
@@ -5248,6 +5250,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,_mcleanup ();#endif gdb_exit (cpu_env, arg1); +instr_fini ();_exit (arg1); ret =0 ;/* avoid warning */ break ;
@@ -7028,6 +7031,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,_mcleanup ();#endif gdb_exit (cpu_env, arg1); +instr_fini (); ret =get_errno (exit_group (arg1));break ;#endif
qemu-options.hx +18 -0
@@ -3021,6 +3021,24 @@ the @var{simple} tracing backend. @end table ETEXI +DEF("instr", HAS_ARG, QEMU_OPTION_instr, + "-instr file=<file>[,arg=<string>]\n" + " load an instrumentation library\n", + QEMU_ARCH_ALL) +STEXI +@item -instr file=@var{file}[,arg=@var{string}] +@findex -instr + +Load a dynamic trace instrumentation library. + +@table @option +@item file=@var{file} +Load the given dynamic trace instrumentation library. +@item arg=@var{string} +String argument passed as to the library's @code{qi_init} routine (can be given multiple times). +@end table +ETEXI + HXCOMM Internal use DEF("qtest", HAS_ARG, QEMU_OPTION_qtest, "", QEMU_ARCH_ALL) DEF("qtest-log", HAS_ARG, QEMU_OPTION_qtest_log, "", QEMU_ARCH_ALL)
vl.c +41 -0
77 lines not on this page · raw message
PATCH v3 19/24 instrument: Add client-side API to enumerate events
In reply to Lluís Vilanova--- .gitignore | 1 Makefile | 1 configure | 1 instrument/Makefile.objs | 13 +++ instrument/api-control.c | 14 +++ instrument/qemu-instr/control-internal.h | 53 ++++++++++++ instrument/qemu-instr/control.h | 124 +++++++++++++++++++++++++++ instrument/qemu-instr/visibility-internal.h | 94 ++++++++++++++++++++ scripts/tracetool/backend/instr_dynamic.py | 3 + scripts/tracetool/backend/instr_none.py | 3 + scripts/tracetool/backend/instr_static.py | 3 + scripts/tracetool/format/api_events_h.py | 56 ++++++++++++ 12 files changed, 366 insertions(+) create mode 100644 instrument/api-control.c create mode 100644 instrument/qemu-instr/control-internal.h create mode 100644 instrument/qemu-instr/control.h create mode 100644 instrument/qemu-instr/visibility-internal.h create mode 100644 scripts/tracetool/format/api_events_h.py
.gitignore +1 -0
@@ -13,6 +13,7 @@ libcacard/trace/generated-tracers.c instrument/generated-tracers.h instrument/generated-tracers.c instrument/qemu-instr/events.h +instrument/qemu-instr/events-list.h *-timestamp *-softmmu *-darwin-user
Makefile +1 -0
@@ -40,6 +40,7 @@ ifdef CONFIG_TRACE_INSTRUMENT_DYNAMIC GENERATED_SOURCES += instrument/generated-tracers.c endif GENERATED_HEADERS += instrument/qemu-instr/events.h +GENERATED_HEADERS += instrument/qemu-instr/events-list.h GENERATED_HEADERS += trace/generated-events.h GENERATED_SOURCES += trace/generated-events.c
configure +1 -0
@@ -301,6 +301,7 @@ QEMU_CFLAGS="-fno-strict-aliasing $QEMU_CFLAGS" QEMU_CFLAGS="-Wall -Wundef -Wwrite-strings -Wmissing-prototypes $QEMU_CFLAGS" QEMU_CFLAGS="-Wstrict-prototypes -Wredundant-decls $QEMU_CFLAGS" QEMU_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE $QEMU_CFLAGS" +QEMU_CFLAGS="-DBUILDING_QEMU $QEMU_CFLAGS" QEMU_INCLUDES="-I. -I\$(SRC_PATH) -I\$(SRC_PATH)/include" if test "$debug_info" = "yes"; then CFLAGS="-g $CFLAGS"
instrument/Makefile.objs +13 -0
@@ -41,6 +41,15 @@ $(obj)/qemu-instr/events.h-timestamp: $(TRACE_EVENTS) $(BUILD_DIR)/config-host.m < $< > $@," GEN $(patsubst %-timestamp,%,$@)") @cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp,%,$@) +$(obj)/qemu-instr/events-list.h: $(obj)/qemu-instr/events-list.h-timestamp +$(obj)/qemu-instr/events-list.h-timestamp: $(TRACE_EVENTS) $(BUILD_DIR)/config-host.mak + $(call quiet-command,$(TRACETOOL) \ + --format=api-events-h \ + --backend=$(TRACE_INSTRUMENT_BACKEND) \ + $(TRACETOOL_INSTR_STATIC) \ + < $< > $@," GEN $(patsubst %-timestamp,%,$@)") + @cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp,%,$@) + ###################################################################### # User code (static instrumentation)
@@ -71,3 +80,7 @@ target-obj-y += control.o common-obj-$(CONFIG_SOFTMMU) += qmp.o common-obj-$(CONFIG_SOFTMMU) += hmp.o + +target-obj-y += api-control.o + +QEMU_CFLAGS += -I$(BUILD_DIR)/instrument -I$(SRC_PATH)/instrument
instrument/api-control.c new file +14 -0
@@ -0,0 +1,14 @@ +/* +* Interface for controlling the state of events. +* +* Copyright (C) 2012-2013 Lluís Vilanova <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include "instrument/qemu-instr/control.h" + +#if defined(QI_TYPE_CONFIG_DYNAMIC ) +#include "instrument/qemu-instr/control-internal.h" +#endif
instrument/qemu-instr/control-internal.h new file +53 -0
53 lines not on this page · raw message
instrument/qemu-instr/control.h new file +124 -0
124 lines not on this page · raw message
instrument/qemu-instr/visibility-internal.h new file +94 -0
94 lines not on this page · raw message
scripts/tracetool/backend/instr_dynamic.py +3 -0
@@ -88,3 +88,6 @@ def api_c(events): args = e.args, argnames = ", ".join(e.args.names()), ) + +def api_events_h(events): + pass
scripts/tracetool/backend/instr_none.py +3 -0
@@ -39,3 +39,6 @@ def api_h(events): qemu_backend = e.api(e.QEMU_TRACE_BACKEND), argnames = ", ".join(e.args.names()), ) + +def api_events_h(events): + pass
scripts/tracetool/backend/instr_static.py +3 -0
@@ -77,3 +77,6 @@ def api_h(events): argnames = ", ".join(e.args.names()), upper_name = e.name.upper(), ) + +def api_events_h(events): + pass
scripts/tracetool/format/api_events_h.py new file +56 -0
56 lines not on this page · raw message
PATCH v3 20/24 instrument: Add client-side API to control tracing state of events
In reply to Lluís Vilanova--- instrument/Makefile.objs | 1 instrument/api-trace.c | 14 +++++ instrument/qemu-instr/trace-internal.h | 32 +++++++++++ instrument/qemu-instr/trace.h | 91 ++++++++++++++++++++++++++++++++ 4 files changed, 138 insertions(+) create mode 100644 instrument/api-trace.c create mode 100644 instrument/qemu-instr/trace-internal.h create mode 100644 instrument/qemu-instr/trace.h
instrument/Makefile.objs +1 -0
@@ -82,5 +82,6 @@ common-obj-$(CONFIG_SOFTMMU) += qmp.o common-obj-$(CONFIG_SOFTMMU) += hmp.o target-obj-y += api-control.o +target-obj-y += api-trace.o QEMU_CFLAGS += -I$(BUILD_DIR)/instrument -I$(SRC_PATH)/instrument
instrument/api-trace.c new file +14 -0
@@ -0,0 +1,14 @@ +/* +* Interface for controlling the tracing state of events. +* +* Copyright (C) 2012-2013 Lluís Vilanova <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include "instrument/qemu-instr/trace.h" + +#if defined(QI_TYPE_CONFIG_DYNAMIC ) +#include "instrument/qemu-instr/trace-internal.h" +#endif
instrument/qemu-instr/trace-internal.h new file +32 -0
@@ -0,0 +1,32 @@ +/* +* Interface for controlling the tracing state of events. +* +* Copyright (C) 2012-2013 Lluís Vilanova <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef QI__TRACE_INTERNAL_H +#define QI__TRACE_INTERNAL_H + +#include "trace/control.h" + + +QI_IDEF bool qi_trace_event_get_state_static(QIEvent *ev) +{ +return trace_event_get_state_static ((TraceEvent *)ev); +} + +QI_IDEF bool qi_trace_event_get_state_dynamic(QIEvent *ev) +{ +return trace_event_get_state_dynamic ((TraceEvent *)ev); +} + +QI_IDEF void qi_trace_event_set_state_dynamic(QIEvent *ev, bool state) +{ +assert (qi_trace_event_get_state_static (ev)); +return trace_event_set_state_dynamic ((TraceEvent *)ev, state); +} + +#endif /* QI__TRACE_INTERNAL_H */
instrument/qemu-instr/trace.h new file +91 -0
91 lines not on this page · raw message
PATCH v3 21/24 instrument: Add client-side API to control event instrumentation
In reply to Lluís Vilanova--- instrument/qemu-instr/control-internal.h | 16 ++++++ instrument/qemu-instr/control.h | 75 ++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+)
instrument/qemu-instr/control-internal.h +16 -0
@@ -11,6 +11,7 @@#define QI__CONTROL_INTERNAL_H #include "trace/control.h" +#include "instrument/control.h" QI_IDEF QIEvent* qi_ctrl_event_id(QIEventID id)
@@ -38,6 +39,16 @@ QI_IDEF QIEventID qi_ctrl_event_count(void)return (QIEventID )trace_event_count (); } +QI_IDEF QIType qi_ctrl_type(void) +{ +return instr_type (); +} + +QI_IDEF bool qi_ctrl_event_is_available(QIEvent *ev) +{ +return instr_event_available ((TraceEvent *)ev); +} + QI_IDEF QIEventID qi_ctrl_event_get_id(QIEvent *ev)
@@ -50,4 +61,9 @@ QI_IDEF const char * qi_ctrl_event_get_name(QIEvent *ev)return trace_event_get_name ((TraceEvent *)ev); } +QI_IDEF bool qi_ctrl_event_set(QIEvent *ev, void *cb) +{ +return instr_event_set ((TraceEvent *)ev, cb); +} +#endif /* QI__CONTROL_INTERNAL_H */
instrument/qemu-instr/control.h +75 -0
87 lines not on this page · raw message
PATCH v3 22/24 build: Fix installation of target-dependant files
In reply to Lluís VilanovaPass all the relevant sub-directory make variables.
---
Cc: Anthony Liguori <[email protected]>
Cc: Paul Brook <[email protected]>
--- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
@@ -346,7 +346,7 @@ endif $(INSTALL_DATA) $(SRC_PATH)/pc-bios/keymaps/$$x "$(DESTDIR)$(qemu_datadir)/keymaps"; \ done for d in $(TARGET_DIRS); do \ - $(MAKE) -C $$d $@ || exit 1 ; \ + $(MAKE) $(SUBDIR_MAKEFLAGS) TARGET_DIR=$$d/ -C $$d $@ || exit 1 ; \ done # various test targets
PATCH v3 23/24 instrument: Install headers for dynamic instrumentation clients
In reply to Lluís Vilanova--- Makefile | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-)
Makefile +23 -1
@@ -324,7 +324,29 @@ install-confdir: install-sysconfig: install-datadir install-confdir $(INSTALL_DATA) $(SRC_PATH)/sysconfigs/target/target-x86_64.conf "$(DESTDIR)$(qemu_confdir)" -install: all $(if $(BUILD_DOCS),install-doc) install-sysconfig install-datadir +install_instrument_find=$(shell find $(1)/instrument/qemu-instr -type f -name \*.h) + +install-instrument: INSTALL_FILES =$(call install_instrument_find,$(SRC_PATH)) +install-instrument: INSTALL_FILES+=$(call install_instrument_find,$(BUILD_DIR)) +install-instrument: INSTALL_DIRS:=$(dir $(INSTALL_FILES)) +install-instrument: INSTALL_DIRS:=$(patsubst $(SRC_PATH)/instrument/%,$(DESTDIR)$(includedir)/%,$(INSTALL_DIRS)) +install-instrument: INSTALL_DIRS:=$(patsubst $(BUILD_DIR)/instrument/%,$(DESTDIR)$(includedir)/%,$(INSTALL_DIRS)) +install-instrument: INSTALL_DIRS:=$(sort $(INSTALL_DIRS)) +install-instrument: + @for d in $(INSTALL_DIRS); do \ + echo "$(INSTALL_DIR) \"$$d\""; \ + $(INSTALL_DIR) "$$d"; \ + done + @for f in $(INSTALL_FILES); do \ + echo "$(INSTALL_DATA) \"$$f\" \"$(DESTDIR)$(includedir)/qemu-instr/$${f##*qemu-instr/}\""; \ + $(INSTALL_DATA) "$$f" "$(DESTDIR)$(includedir)/qemu-instr/$${f##*qemu-instr/}"; \ + done + +ifdef CONFIG_TRACE_INSTRUMENT_DYNAMIC +INSTALL_INSTRUMENT=install-instrument +endif + +install: all $(if $(BUILD_DOCS),install-doc) install-sysconfig install-datadir $(INSTALL_INSTRUMENT) $(INSTALL_DIR) "$(DESTDIR)$(bindir)" ifneq ($(TOOLS),) $(INSTALL_PROG) $(STRIP_OPT) $(TOOLS) "$(DESTDIR)$(bindir)"
PATCH v3 24/24 trace: Do not use the word 'new' in event arguments
In reply to Lluís VilanovaThis lets instrumentation clients in C++ use the auto-generated headers.
--- scripts/tracetool/__init__.py | 16 +++++++++++++++- trace-events | 8 ++++---- 2 files changed, 19 insertions(+), 5 deletions(-)
scripts/tracetool/__init__.py +15 -1
@@ -40,6 +40,14 @@ def out(*lines, **kwargs): sys.stdout.writelines("\n".join(lines) + "\n") +FORBIDDEN = [ "new" ] + +class ForbiddenArgumentError (Exception): + def __init__ (self, name): + self.name = name + def __str__ (self): + return "Cannot use forbidden argument name: %s" % self.name + class Arguments: """Event arguments description."""
@@ -74,6 +82,9 @@ class Arguments: else: arg_type, identifier = arg.rsplit(None, 1) + if identifier in FORBIDDEN: + raise ForbiddenArgumentError(identifier) + res.append((arg_type, identifier)) return Arguments(res)
@@ -165,7 +176,10 @@ class Event(object): name = groups["name"] props = groups["props"].split() fmt = groups["fmt"] - args = Arguments.build(groups["args"]) + try: + args = Arguments.build(groups["args"]) + except ForbiddenArgumentError as e: + error("Error: event '%s' uses forbidden argument name '%s'" % (name, e.name)) return Event(name, props, fmt, args)
trace-events +4 -4
@@ -187,7 +187,7 @@ hd_geometry_guess(void *bs, uint32_t cyls, uint32_t heads, uint32_t secs, int tr # hw/jazz-led.c jazz_led_read(uint64_t addr, uint8_t val) "read addr=0x%"PRIx64": 0x%x" -jazz_led_write(uint64_t addr, uint8_t new) "write addr=0x%"PRIx64": 0x%x" +jazz_led_write(uint64_t addr, uint8_t new_) "write addr=0x%"PRIx64": 0x%x" # hw/lance.c lance_mem_readw(uint64_t addr, uint32_t ret) "addr=%"PRIx64"val=0x%04x"
@@ -285,10 +285,10 @@ usb_port_release(int bus, const char *port) "bus %d, port %s" usb_ehci_reset(void) "=== RESET ===" usb_ehci_opreg_read(uint32_t addr, const char *str, uint32_t val) "rd mmio %04x [%s] = %x" usb_ehci_opreg_write(uint32_t addr, const char *str, uint32_t val) "wr mmio %04x [%s] = %x" -usb_ehci_opreg_change(uint32_t addr, const char *str, uint32_t new, uint32_t old) "ch mmio %04x [%s] = %x (old: %x)" +usb_ehci_opreg_change(uint32_t addr, const char *str, uint32_t new_, uint32_t old) "ch mmio %04x [%s] = %x (old: %x)" usb_ehci_portsc_read(uint32_t addr, uint32_t port, uint32_t val) "rd mmio %04x [port %d] = %x" usb_ehci_portsc_write(uint32_t addr, uint32_t port, uint32_t val) "wr mmio %04x [port %d] = %x" -usb_ehci_portsc_change(uint32_t addr, uint32_t port, uint32_t new, uint32_t old) "ch mmio %04x [port %d] = %x (old: %x)" +usb_ehci_portsc_change(uint32_t addr, uint32_t port, uint32_t new_, uint32_t old) "ch mmio %04x [port %d] = %x (old: %x)" usb_ehci_usbsts(const char *sts, int state) "usbsts %s %d" usb_ehci_state(const char *schedule, const char *state) "%s schedule %s" usb_ehci_qh_ptrs(void *q, uint32_t addr, uint32_t nxt, uint32_t c_qtd, uint32_t n_qtd, uint32_t a_qtd) "q %p - QH @ %08x: next %08x qtds %08x,%08x,%08x"
@@ -530,7 +530,7 @@ qed_aio_write_main(void *s, void *acb, int ret, uint64_t offset, size_t len) "s # hw/g364fb.c g364fb_read(uint64_t addr, uint32_t val) "read addr=0x%"PRIx64": 0x%x" -g364fb_write(uint64_t addr, uint32_t new) "write addr=0x%"PRIx64": 0x%x" +g364fb_write(uint64_t addr, uint32_t val) "write addr=0x%"PRIx64": 0x%x" # hw/grlib_gptimer.c grlib_gptimer_enable(int id, uint32_t count) "timer:%d set count 0x%x and run"
Quoted 26 lines · Lluís Vilanova
TODO: Operations '
instr_load' and 'instr_unload' are not thread safe.(qemu_cpu_kick?)TODO: Do cmdline actions have to be implemented on top of QMP routines?
TODO: HMP and QMP interfaces only accept one argument to "instr-load".
TODO: Replace programmatic 'InstrLoadError' in favour of QAPI's 'InstrLoadCode'?
(harder to find using code navigation tools, as it's auto-generated; but provides a single point to manage the enumeration values, which is less error-prone)The whole set of patch series is available at:
https://projects.gso.ac.upc.edu/projects/qemu-dbiAdds the "instrument" event property to declare which tracing events in QEMU must be instrumentable. Still, in case the user only wants to wrap around the tracing events, the original tracing implementation is accessible through the appropriate routines.
The instrumentation can be performed either through a dynamically-loaded library or through user-provided code that is compiled into QEMU itself (useful when instrumenting high-frequency events, as the fast-path of the instrumentation can be inlined into QEMU).
Quoted 7 lines
As a side-effect this series adds an API for the instrumentation code to have some basic interaction with QEMU.
See the documentation added in the first patch for more information.
Signed-off-by Lluís Vilanova <[email protected]>---
If I understand correctly this series allows trace events to be exported as a shared library API. It can be used with instrumentation libraries (shared objects), which avoids rebuilding QEMU for each instrumentation set.
I'm skeptical of the effort required to do this (and maintain it) when it's easy to keep several git branches - one for each instrumentation set - and rebuild.
Trace events are not an API. They are not stable. Therefore these dynamic instrumentation libraries would be broken when QEMU changes.
Maybe I don't understand the application well enough to see the benefit?
Stefan
Quoted 40 lines · Stefan Hajnoczi
Quoted 26 lines · Lluís Vilanova
TODO: Operations '
instr_load' and 'instr_unload' are not thread safe. (qemu_cpu_kick?)TODO: Do cmdline actions have to be implemented on top of QMP routines?
TODO: HMP and QMP interfaces only accept one argument to "instr-load".
TODO: Replace programmatic 'InstrLoadError' in favour of QAPI's 'InstrLoadCode'? (harder to find using code navigation tools, as it's auto-generated; but provides a single point to manage the enumeration values, which is less error-prone)
The whole set of patch series is available at:
https://projects.gso.ac.upc.edu/projects/qemu-dbiAdds the "instrument" event property to declare which tracing events in QEMU must be instrumentable. Still, in case the user only wants to wrap around the tracing events, the original tracing implementation is accessible through the appropriate routines.
The instrumentation can be performed either through a dynamically-loaded library or through user-provided code that is compiled into QEMU itself (useful when instrumenting high-frequency events, as the fast-path of the instrumentation can be inlined into QEMU).
Quoted 7 lines
As a side-effect this series adds an API for the instrumentation code to have some basic interaction with QEMU.
See the documentation added in the first patch for more information.
Signed-off-by Lluís Vilanova <[email protected]>---
If I understand correctly this series allows trace events to be exported as a shared library API. It can be used with instrumentation libraries (shared objects), which avoids rebuilding QEMU for each instrumentation set.
Quoted 8 lines
I'm skeptical of the effort required to do this (and maintain it) when it's easy to keep several git branches - one for each instrumentation set - and rebuild.
Trace events are not an API. They are not stable. Therefore these dynamic instrumentation libraries would be broken when QEMU changes.
Maybe I don't understand the application well enough to see the benefit?
True, changing QEMU's tracing events will break the instrumentation libraries, and the user should be completely aware of that, given that the library is actually instrumenting specific tracing events (not just some well-established API). You can think of this as yet another tracing backend, with the ability to interact with QEMU.
The actually interesting part is in the following series (which are also publicly available on the url of the cover), which adds some generic tracing events that should not change between versions, and can thus be safely assumed. Such events are related to the guest code, including (but not limited to) guest memory accesses or instruction execution. As we discussed in some very old try at this, what all of this provides is the ability to instrument guest code for all architectures supported by QEMU.
In fact, the ability to instrument all tracing events could be seen as just a side-effect of the implementation; but one that can come in handy in certain cases when developing ad-hoc trace analyses.
Does this make more sense now?
Lluis
Quoted 65 lines · Lluís Vilanova
Quoted 40 lines · Stefan Hajnoczi
Quoted 26 lines · Lluís Vilanova
TODO: Operations '
instr_load' and 'instr_unload' are not thread safe. (qemu_cpu_kick?)TODO: Do cmdline actions have to be implemented on top of QMP routines?
TODO: HMP and QMP interfaces only accept one argument to "instr-load".
TODO: Replace programmatic 'InstrLoadError' in favour of QAPI's 'InstrLoadCode'? (harder to find using code navigation tools, as it's auto-generated; but provides a single point to manage the enumeration values, which is less error-prone)
The whole set of patch series is available at:
https://projects.gso.ac.upc.edu/projects/qemu-dbiAdds the "instrument" event property to declare which tracing events in QEMU must be instrumentable. Still, in case the user only wants to wrap around the tracing events, the original tracing implementation is accessible through the appropriate routines.
The instrumentation can be performed either through a dynamically-loaded library or through user-provided code that is compiled into QEMU itself (useful when instrumenting high-frequency events, as the fast-path of the instrumentation can be inlined into QEMU).
Quoted 7 lines
As a side-effect this series adds an API for the instrumentation code to have some basic interaction with QEMU.
See the documentation added in the first patch for more information.
Signed-off-by Lluís Vilanova <[email protected]>---
If I understand correctly this series allows trace events to be exported as a shared library API. It can be used with instrumentation libraries (shared objects), which avoids rebuilding QEMU for each instrumentation set.
Quoted 8 lines
I'm skeptical of the effort required to do this (and maintain it) when it's easy to keep several git branches - one for each instrumentation set - and rebuild.
Trace events are not an API. They are not stable. Therefore these dynamic instrumentation libraries would be broken when QEMU changes.
Maybe I don't understand the application well enough to see the benefit?
True, changing QEMU's tracing events will break the instrumentation libraries, and the user should be completely aware of that, given that the library is actually instrumenting specific tracing events (not just some well-established API). You can think of this as yet another tracing backend, with the ability to interact with QEMU.
The actually interesting part is in the following series (which are also publicly available on the url of the cover), which adds some generic tracing events that should not change between versions, and can thus be safely assumed. Such events are related to the guest code, including (but not limited to) guest memory accesses or instruction execution. As we discussed in some very old try at this, what all of this provides is the ability to instrument guest code for all architectures supported by QEMU.
Quoted 5 lines
In fact, the ability to instrument all tracing events could be seen as just a side-effect of the implementation; but one that can come in handy in certain cases when developing ad-hoc trace analyses.
Does this make more sense now?
Thanks for explaining.
People doing this level of instrumentation probably need to do QEMU hacking anyway for deep analysis, perhaps pausing and resuming the guest, checking other guest RAM locations, grabbing device state, maybe snapshotting the guest.
Is it worth building and maintain a stable API? It means that folks working on TCG, for example, do not have the freedom to change/delete trace events. They are now stuck maintaining trace event semantics no matter how TCG will evolve in the future.
It would be nice to make TCG multi-threaded soon. How will instrumentation libraries handle this? Existing ones probably won't, they'll break unless QEMU restricts itself back to single-threaded mode.
Given that the group of users for this feature is so small while the burden of supporting this is rather large, it seems like writing instrumentation code straight in a QEMU source tree is the most powerful and viable solution.
Basically I think putting a stable API in place here isn't going to fly. In terms of the tracing subsystem I don't mind, but I think it's a question for the larger QEMU community.
Stefan
Quoted 7 lines · Stefan Hajnoczi
On Wed, Apr 24, 2013 at 02:17:22PM +0200, Lluís Vilanova wrote:
Thanks for explaining.People doing this level of instrumentation probably need to do QEMU hacking anyway for deep analysis, perhaps pausing and resuming the guest, checking other guest RAM locations, grabbing device state, maybe snapshotting the guest.
Some of these are already (or could easily be) available through QAPI, so there's no need to "re-expose" them.
Quoted 4 lines
Is it worth building and maintain a stable API? It means that folks working on TCG, for example, do not have the freedom to change/delete trace events. They are now stuck maintaining trace event semantics no matter how TCG will evolve in the future.
Well, the events added in future series (this one just adds the infrastructure) are generic enough that TCG should just care about signalling, for example, when an instruction/bbl starts. As this is in no way tied to the actual TCG primitives, the internals are free to change.
What's probably less appropriate is exposing functions to generate TCG code to the instrumentation libraries. This is what I added in one of my series, as it allows the writing of highly-perfomant instrumentation routines, but I understand it is undesirable (still, the library can just say "call this function I wrote when the event happens", aka call a helper).
Quoted 3 lines
It would be nice to make TCG multi-threaded soon. How will instrumentation libraries handle this? Existing ones probably won't, they'll break unless QEMU restricts itself back to single-threaded mode.
The only problem here is changing the dynamic callback of an event and flushing the generated TCG code when a library is unloaded. That's the reason of one of my TODO's at the top of this series, as I didn't dive enough into QEMU to handle that.
Quoted 4 lines
Given that the group of users for this feature is so small while the burden of supporting this is rather large, it seems like writing instrumentation code straight in a QEMU source tree is the most powerful and viable solution.
Well, the tracing event instrumentation support itself is quite generic and should be maintainable, and can enormously simplify the task for others to use it in the future.
Quoted 1 line
From my repository, the first three series (including this one) handle the
infrastructure, which is mostly based on providing tracetool backends.
The 4th one adds some very generic events (vbbl_{before,after}, vinst_{before,after}, vmem) that should have no ties to the TCG implementation.
The 5th one adds the backdoor we discussed long ago, which lets the guest code interact with the instrumentation library, so that they can coordinate (AFAIR, Blue said that could come in handy during tests, for example).
The next ones probably are more controversial, as they start adding new interfaces available to the instrumentation libraries (as well as some extra events).
Quoted 3 lines
Basically I think putting a stable API in place here isn't going to fly. In terms of the tracing subsystem I don't mind, but I think it's a question for the larger QEMU community.
What are you referring to as an API? The tracing events and their signatures?
Lluis
Signature · 4 lines
"And it's much the same thing with knowledge, for whenever you learn something new, the whole world becomes that much richer." -- The Princess of Pure Reason, as told by Norton Juster in The Phantom Tollbooth
Re: [Qemu-devel] [PATCH v3 14/24] instrument: Add internal control interface
In reply to Lluís VilanovaQuoted 9 lines · Lluís Vilanova
This interface provides two sets of operations:
* Loading/unloading a trace instrumentation library.
* Controls the instrumentation callbacks of the tracing events.
Note that in the case of static instrumentation, the library is not loaded/unloaded, but is still properly (de)initialized when QEMU starts and exits.
I don't know if the series in general will be accepted, but if so, here's some interface things to think about:
Quoted 11 lines
+++
b/instrument/qapi-schema.jsoninstrument/qapi-schema.json new file +9
-0@@ -0,0 +1,26 @@ +# *-*- Mode: Python -*-* +# +# QAPI trace instrumentation control commands. +# +# Copyright (C) 2012-2013 Lluís Vilanova <[email protected]> +# +# This work is licensed under the terms of the GNU GPL, version 2 or later. +# See the COPYING file in the top-level directory. +
instrument/qapi-schema.json line 19
Quoted 10 lines
instrument/qapi-schema.json new file +10
-0+## +# @InstrType +# +# Instrumentation type supported by the system. +# +# @None: No instrumentation support. +# +# @Static: Static instrumentation support. +# +# @Dynamic: Dynamic instrumentation support.
Generally, QMP enums are lower case (s/None/none/, and so forth).
Review line 21
Quoted 2 lines
(quoted diff) +2
-0+# +# Warning: Keep in sync with #QIType.
If we had the hypothetical tool that converted .json into end-user documentation, this sort of comment does not belong in the end-user document. Do we need to invent a syntax for development-only comments within .json files for things that are useful during qemu development? Or is it just better to move the comment to instead be in the C file that declares the enum, reminding any developer that modifies the enum to also modify the QMP type that reflects it? (We went with the latter approach in the recent query-command-line-options, putting the reminder comment to keep QMP and C in sync only in the C file.)
Review line 23
Quoted 2 lines
(quoted diff) +2
-0+# +# Since: 1.5
This missed 1.5; it will need to be 1.6 now.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 12 lines · Lluís Vilanova
Quoted 5 lines · Stefan Hajnoczi
On Wed, Apr 24, 2013 at 02:17:22PM +0200, Lluís Vilanova wrote:
Given that the group of users for this feature is so small while the burden of supporting this is rather large, it seems like writing instrumentation code straight in a QEMU source tree is the most powerful and viable solution.Well, the tracing event instrumentation support itself is quite generic and should be maintainable, and can enormously simplify the task for others to use it in the future.
Quoted 5 lines
From my repository, the first three series (including this one) handle the infrastructure, which is mostly based on providing tracetool backends.
The 4th one adds some very generic events (vbbl_{before,after}, vinst_{before,after}, vmem) that should have no ties to the TCG implementation.
They would be affected by things like real TCG vcpu threads (parallel translation and execution) because now trace events will be invoked simultaneously from multiple threads. Or heterogenous cores in QEMU (ARM + DSP) where previously you could assume there is one target architecture.
Quoted 7 lines
The 5th one adds the backdoor we discussed long ago, which lets the guest code interact with the instrumentation library, so that they can coordinate (AFAIR, Blue said that could come in handy during tests, for example).
The next ones probably are more controversial, as they start adding new interfaces available to the instrumentation libraries (as well as some extra events).
I don't think this effort is maintainable.
The API would be great if QEMU was heavily focussed on instrumentation and simulation research. It allows interesting analysis without diving into the internals of QEMU.
The problem is it touches everything in QEMU because you should be able to instrument everything. Who is going to maintain an API of this scope?
The QEMU community has two large groups: TCG for emulation and KVM for virtualization. The API doesn't offer them anything so they will not keep it in mind when making changes.
This is why I think it makes more sense to focus on specific tools that don't try to introduce stable APIs. i.e. a tool for instruction tracing in TCG.
Advanced users will have to modify the QEMU source.
Quoted 5 lines
Quoted 3 lines
Basically I think putting a stable API in place here isn't going to fly. In terms of the tracing subsystem I don't mind, but I think it's a question for the larger QEMU community.
What are you referring to as an API? The tracing events and their signatures?
The interface that dynamic instrumentation libraries use to interact with QEMU. That means "stable" tracing events plus any operations that libraries can perform (stop/stop vcpu, peek/poke memory, dirty bitmaps, MMU, interrupts, etc).
Stefan
Re: [Qemu-devel] [PATCH v3 14/24] instrument: Add internal control interface
In reply to Lluís VilanovaIl 21/04/2013 21:12, Lluís Vilanova ha scritto:
Makefile.objs common-obj-y += disas/ · line 98
Quoted 10 lines
Makefile.objs +1
-0@@ -94,6 +94,7 @@ common-obj-y += disas/ # instrumentation tools-obj-y += instrument/ +target-obj-y += instrument/
Why does instrument/ have to be compiled once per target?
If you can compile it just once, then libqemuutil.a and util-obj-y will do.
Paolo
Re: [Qemu-devel] [PATCH v3 07/24] system: [linux] Use absolute include path for linux-headers
In reply to Lluís VilanovaIl 21/04/2013 21:12, Lluís Vilanova ha scritto:
Quoted 15 lines
Lets the include directive work regardless of the current directory.
This is needed for code compiled in directories deeper than one level from the build root.
Signed-off-by Lluís Vilanova <[email protected]>--- Makefile.target | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Makefile.target +0
-0
Makefile.target include $(SRC_PATH)/rules.mak · line 12
Quoted 7 lines
Makefile.target +1
-1@@ -7,7 +7,7 @@ include $(SRC_PATH)/rules.mak $(call set-vpath, $(SRC_PATH)) ifdef CONFIG_LINUX -QEMU_CFLAGS += -I../linux-headers +QEMU_CFLAGS += -I$(BUILD_DIR)/linux-headers endif QEMU_CFLAGS += -I.. -I$(SRC_PATH)/target-$(TARGET_BASE_ARCH) -DNEED_CPU_H
I am not sure why this is needed. The .. here is the path from foo-softmmu/ to the build root. QEMU's build system is only one-level recursive, something like foo-softmmu/hw/virtio/virtio.c is compiled from foo-softmmu/ (whose Makefile is Makefile.target) and thus the path needs to be relative from foo-softmmu/. It need not be relative to foo-softmmu/hw/virtio.
Paolo
Re: [Qemu-devel] [PATCH v3 03/24] trace: Let the user specify her own trace-events file
In reply to Lluís VilanovaIl 21/04/2013 21:11, Lluís Vilanova ha scritto:
Quoted 2 lines
With this option the user can perform multiple builds of QEMU with different tracing event properties.
I don't understand why this is useful? If it is just to add/remove "disable" here and there, surely the user should be using git and different branches?
Paolo
Quoted 137 lines
Signed-off-by Lluís Vilanova <[email protected]>--- Makefile.target | 2 +- configure | 19 +++++++++++++++++++ trace/Makefile.objs | 10 +++++----- 3 files changed, 25 insertions(+), 6 deletions(-)Makefile.target +1
-1@@ -47,7 +47,7 @@ else TARGET_TYPE=system endif -$(QEMU_PROG).stp: $(SRC_PATH)/trace-events +$(QEMU_PROG).stp: $(TRACE_EVENTS) $(call quiet-command,$(TRACETOOL) \ --format=stap \ --backend=$(TRACE_BACKEND) \configure +19
-0@@ -221,6 +221,7 @@ blobs="yes" pkgversion="" pie="" zero_malloc="" +trace_events=`dirname $0`/trace-events trace_backend="nop" trace_file="trace" spice=""@@ -639,6 +640,8 @@ for opt do ;; --target-list=*) target_list="$optarg" ;; + --with-trace-events=*) trace_events="$optarg" + ;; --enable-trace-backend=*) trace_backend="$optarg" ;; --with-trace-file=*) trace_file="$optarg"@@ -1158,6 +1161,7 @@ echo " --enable-docs enable documentation build" echo " --disable-docs disable documentation build" echo " --disable-vhost-net disable vhost-net acceleration support" echo " --enable-vhost-net enable vhost-net acceleration support" +echo " --with-trace-events=PATH file with tracing events description (default: $trace_events)" echo " --enable-trace-backend=B Set trace backend" echo " Available backends:" $($python "$source_path"/scripts/tracetool.py --list-backends) echo " --with-trace-file=NAME Full PATH,NAME of file to store traces"@@ -3009,6 +3013,18 @@ if compile_prog "" "" ; then fi ########################################## +# check if trace-events file exists + +if test ! -f "$trace_events"; then + echo + echo "Error: the given trace-events file does not exist" + echo + exit 1 +else + trace_events=`readlink -f "$trace_events"` +fi + +########################################## # check if trace backend exists $python "$source_path/scripts/tracetool.py" "--backend=$trace_backend" --check-backend > /dev/null 2> /dev/null@@ -3418,6 +3434,7 @@ echo "sigev_thread_id $sigev_thread_id" echo "uuid support $uuid" echo "libcap-ng support $cap_ng" echo "vhost-net support $vhost_net" +echo "Trace events $trace_events" echo "Trace backend $trace_backend" echo "Trace output file $trace_file-<pid>" echo "spice support $spice ($spice_protocol_version/$spice_server_version)"@@ -3810,6 +3827,8 @@ bsd) ;; esac +echo "TRACE_EVENTS=$trace_events" >> $config_host_mak + # use default implementation for tracing backend-specific routines trace_default=yes echo "TRACE_BACKEND=$trace_backend" >> $config_host_maktrace/Makefile.objs +5
-5@@ -4,7 +4,7 @@ # Auto-generated event descriptions $(obj)/generated-events.h: $(obj)/generated-events.h-timestamp -$(obj)/generated-events.h-timestamp: $(SRC_PATH)/trace-events +$(obj)/generated-events.h-timestamp: $(TRACE_EVENTS) $(call quiet-command,$(TRACETOOL) \ --format=events-h \ --backend=events \@@ -12,7 +12,7 @@ $(obj)/generated-events.h-timestamp: $(SRC_PATH)/trace-events @cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp,%,$@) $(obj)/generated-events.c: $(obj)/generated-events.c-timestamp $(BUILD_DIR)/config-host.mak -$(obj)/generated-events.c-timestamp: $(SRC_PATH)/trace-events +$(obj)/generated-events.c-timestamp: $(TRACE_EVENTS) $(call quiet-command,$(TRACETOOL) \ --format=events-c \ --backend=events \@@ -27,7 +27,7 @@ util-obj-y += generated-events.o $(obj)/generated-tracers.h: $(obj)/generated-tracers.h-timestamp @cmp -s $< $@ || cp $< $@ -$(obj)/generated-tracers.h-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak +$(obj)/generated-tracers.h-timestamp: $(TRACE_EVENTS) $(BUILD_DIR)/config-host.mak $(call quiet-command,$(TRACETOOL) \ --format=h \ --backend=$(TRACE_BACKEND) \@@ -39,7 +39,7 @@ $(obj)/generated-tracers.h-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/conf ifneq ($(TRACE_BACKEND),dtrace) $(obj)/generated-tracers.c: $(obj)/generated-tracers.c-timestamp @cmp -s $< $@ || cp $< $@ -$(obj)/generated-tracers.c-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak +$(obj)/generated-tracers.c-timestamp: $(TRACE_EVENTS) $(BUILD_DIR)/config-host.mak $(call quiet-command,$(TRACETOOL) \ --format=c \ --backend=$(TRACE_BACKEND) \@@ -57,7 +57,7 @@ endif # rule file. So we use '.dtrace' instead ifeq ($(TRACE_BACKEND),dtrace) $(obj)/generated-tracers.dtrace: $(obj)/generated-tracers.dtrace-timestamp -$(obj)/generated-tracers.dtrace-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak +$(obj)/generated-tracers.dtrace-timestamp: $(TRACE_EVENTS) $(BUILD_DIR)/config-host.mak $(call quiet-command,$(TRACETOOL) \ --format=d \ --backend=$(TRACE_BACKEND) \
Re: [Qemu-devel] [PATCH v3 05/24] trace: Minimize inclusions of "qemu-common.h" to avoid inclusion loops
In reply to Lluís VilanovaIl 21/04/2013 21:11, Lluís Vilanova ha scritto:
Quoted 1 line
This problem arises in the following patches.
Removing inclusions of qemu-common.h from .h files is definitely useful.
However, the TRACE__CONTROL__USE__TRACE_PRINT_EVENTS is really hideous. :) Just make inclusion of qemu-common.h mandatory before inclusion of trace/control.h.
Paolo
Quoted 134 lines
Signed-off-by Lluís Vilanova <[email protected]>--- hw/virtio/virtio.c | 1 + monitor.c | 4 +++- scripts/tracetool/format/h.py | 9 ++++++++- trace/control-internal.h | 4 +++- trace/control.c | 4 +++- trace/control.h | 9 +++++++-- trace/default.c | 4 +++- trace/simple.c | 4 +++- trace/simple.h | 1 + trace/stderr.c | 4 +++- 10 files changed, 35 insertions(+), 9 deletions(-)hw/virtio/virtio.c +1
-0@@ -14,6 +14,7 @@#include <inttypes.h> #include "trace.h" +#include "qemu-common.h" #include "qemu/error-report.h" #include "hw/virtio/virtio.h" #include "qemu/atomic.h" monitor.c +3
-1@@ -22,6 +22,9 @@* THE SOFTWARE. */ #include <dirent.h> +#define TRACE__CONTROL__USE__TRACE_PRINT_EVENTS +#include "trace/control.h" +#undef TRACE__CONTROL__USE__TRACE_PRINT_EVENTS#include "hw/hw.h" #include "monitor/qdev.h" #include "hw/usb.h" @@ -59,7 +62,6 @@#include "qemu/osdep.h" #include "cpu.h" #include "trace.h" -#include "trace/control.h" #ifdef CONFIG_TRACE_SIMPLE #include "trace/simple.h" #endif scripts/tracetool/format/h.py +8
-1@@ -22,7 +22,14 @@ def begin(events): '#ifndef TRACE__GENERATED_TRACERS_H', '#define TRACE__GENERATED_TRACERS_H', '', - '#include "qemu-common.h"') + '/* Do not directly include "qemu-common.h" to avoid circular dependencies */', + '#include <stdint.h>', + '#include <inttypes.h>', + '#include <stdbool.h>', + '#include <stddef.h>', + '#include <unistd.h>', + '', + ) def end(events): out('#endif /* TRACE__GENERATED_TRACERS_H */')trace/control-internal.h +3
-1@@ -1,7 +1,7 @@/* * Interface for configuring and controlling the state of tracing events. * -* Copyright (C) 2011-2012 Lluís Vilanova <[email protected]> +* Copyright (C) 2011-2013 Lluís Vilanova <[email protected]> * * This work is licensed under the terms of the GNU GPL, version 2 or later. * See the COPYING file in the top-level directory. @@ -11,6 +11,8 @@#define TRACE__CONTROL_INTERNAL_H #include <string.h> +#include <assert.h> +#include <stddef.h> extern TraceEvent trace_events[];trace/control.c +3
-1@@ -1,7 +1,7 @@/* * Interface for configuring and controlling the state of tracing events. * -* Copyright (C) 2011-2012 Lluís Vilanova <[email protected]> +* Copyright (C) 2011-2013 Lluís Vilanova <[email protected]> * * This work is licensed under the terms of the GNU GPL, version 2 or later. * See the COPYING file in the top-level directory. @@ -9,6 +9,8 @@#include "trace/control.h" +#include "qemu-common.h" +TraceEvent *trace_event_name (const char *name) {trace/control.h +1
-2@@ -1,7 +1,7 @@/* * Interface for configuring and controlling the state of tracing events. * -* Copyright (C) 2011-2012 Lluís Vilanova <[email protected]> +* Copyright (C) 2011-2013 Lluís Vilanova <[email protected]> * * This work is licensed under the terms of the GNU GPL, version 2 or later. * See the COPYING file in the top-level directory. @@ -10,7 +10,6 @@#ifndef TRACE__CONTROL_H #define TRACE__CONTROL_H -#include "qemu-common.h" #include "trace/generated-events.h"
trace/control.h void trace_event_set_state_dynamic_backend(TraceEvent *ev, bool state); · line 159
Quoted 6 lines
trace/control.h +3
-0@@ -155,6 +154,10 @@ void trace_event_set_state_dynamic_backend(TraceEvent *ev, bool state); +#if defined(TRACE__CONTROL__USE__TRACE_PRINT_EVENTS ) +/* Minimize inclusions of "qemu-common.h" to avoid circular dependencies */ +#include "qemu-common.h"
Can you just include this from the C files instead?
Quoted 77 lines
trace/control.h +2
-0/** * trace_print_events: * @@ -164,6 +167,8 @@ void trace_event_set_state_dynamic_backend(TraceEvent *ev, bool state);*/ void trace_print_events (FILE *stream,fprintf_function stream_printf); +#endif /* defined(TRACE__CONTROL__USE__TRACE_PRINT_EVENTS) */ +/** * trace_backend_init: * @events: Name of file with events to be enabled at startup; may be NULL. trace/default.c +3
-1@@ -1,13 +1,15 @@/* * Default implementation for backend initialization from commandline. * -* Copyright (C) 2011-2012 Lluís Vilanova <[email protected]> +* Copyright (C) 2011-2013 Lluís Vilanova <[email protected]> * * This work is licensed under the terms of the GNU GPL, version 2. See * the COPYING file in the top-level directory. */ +#define TRACE__CONTROL__USE__TRACE_PRINT_EVENTS #include "trace/control.h" +#undef TRACE__CONTROL__USE__TRACE_PRINT_EVENTSvoid trace_print_events (FILE *stream,fprintf_function stream_printf)trace/simple.c +3
-1@@ -19,8 +19,10 @@#include <pthread.h> #endif #include "qemu/timer.h" -#include "trace.h" +#define TRACE__CONTROL__USE__TRACE_PRINT_EVENTS #include "trace/control.h" +#undef TRACE__CONTROL__USE__TRACE_PRINT_EVENTS +#include "trace.h" /** Trace file header event ID */ #define HEADER_EVENT_ID (~(uint64_t)0)/* avoids conflicting with TraceEventIDs */ trace/simple.h +1
-0@@ -16,6 +16,7 @@#include <stdio.h> #include "trace/generated-events.h" +#include "qemu-common.h" void st_print_trace_file_status (FILE *stream,fprintf_function stream_printf);trace/stderr.c +3
-1@@ -1,5 +1,7 @@ -#include "trace.h" +#define TRACE__CONTROL__USE__TRACE_PRINT_EVENTS #include "trace/control.h" +#undef TRACE__CONTROL__USE__TRACE_PRINT_EVENTS +#include "trace.h" void trace_print_events (FILE *stream,fprintf_function stream_printf)
Re: [Qemu-devel] [PATCH v3 22/24] build: Fix installation of target-dependant files
In reply to Lluís VilanovaIl 21/04/2013 21:13, Lluís Vilanova ha scritto:
Quoted 18 lines
Pass all the relevant sub-directory make variables.
Signed-off-by Lluís Vilanova <[email protected]>---
Cc: Anthony Liguori <[email protected]>
Cc: Paul Brook <[email protected]>--- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Makefile +0
-0
Makefile endif · line 352
Quoted 8 lines
Makefile +1
-1@@ -346,7 +346,7 @@ endif $(INSTALL_DATA) $(SRC_PATH)/pc-bios/keymaps/$$x "$(DESTDIR)$(qemu_datadir)/keymaps"; \ done for d in $(TARGET_DIRS); do \ - $(MAKE) -C $$d $@ || exit 1 ; \ + $(MAKE) $(SUBDIR_MAKEFLAGS) TARGET_DIR=$$d/ -C $$d $@ || exit 1 ; \ done # various test targets
Please resubmit this separately too, it is a worthwhile cleanup.
Paolo
Re: [Qemu-devel] [PATCH v3 14/24] instrument: Add internal control interface
In reply to Paolo BonziniQuoted 8 lines · Paolo Bonzini
Il 21/04/2013 21:12, Lluís Vilanova ha scritto:
Quoted 7 lines
Makefile.objs +0
-0@@ -94,6 +94,7 @@ common-obj-y += disas/ # instrumentation
Quoted 7 lines
Quoted 3 lines
tools-obj-y += instrument/
+target-obj-y += instrument/Why does instrument/ have to be compiled once per target?
If you can compile it just once, then libqemuutil.a and util-obj-y will do.
It looks like that after some re-merges, the patch was placed too early in the series. This is necessary later for files like instrument/cmdline.c and instrument/api-control.c (patch 18).
Lluis
Signature · 4 lines
"And it's much the same thing with knowledge, for whenever you learn something new, the whole world becomes that much richer." -- The Princess of Pure Reason, as told by Norton Juster in The Phantom Tollbooth
Re: [Qemu-devel] [PATCH v3 22/24] build: Fix installation of target-dependant files
In reply to Paolo BonziniQuoted 6 lines · Paolo Bonzini
Il 21/04/2013 21:13, Lluís Vilanova ha scritto:
Quoted 3 lines
Pass all the relevant sub-directory make variables.
Signed-off-by Lluís Vilanova <[email protected]>Please resubmit this separately too, it is a worthwhile cleanup.
...if you're going to resubmit anyway, you might fix the typo in the commit message: "dependent" ends -ent.
thanks
-- PMM
Re: [Qemu-devel] [PATCH v3 14/24] instrument: Add internal control interface
In reply to Lluís VilanovaIl 26/04/2013 17:25, Lluís Vilanova ha scritto:
Quoted 16 lines
Quoted 13 lines · Paolo Bonzini
Il 21/04/2013 21:12, Lluís Vilanova ha scritto:
Quoted 10 lines
Makefile.objs +0
-0@@ -94,6 +94,7 @@ common-obj-y += disas/ # instrumentationtools-obj-y += instrument/
+target-obj-y += instrument/Why does instrument/ have to be compiled once per target?
Quoted 5 lines
Quoted 1 line
If you can compile it just once, then libqemuutil.a and util-obj-y will do.
It looks like that after some re-merges, the patch was placed too early in the series. This is necessary later for files like
instrument/cmdline.candinstrument/api-control.c(patch 18).
The point of using a static library is exactly to leave out files automatically if they are not used. Just put it into libqemuutil.a, and tools will not pick it up.
Paolo
Re: [Qemu-devel] [PATCH v3 03/24] trace: Let the user specify her own trace-events file
In reply to Paolo BonziniQuoted 7 lines · Paolo Bonzini
Il 21/04/2013 21:11, Lluís Vilanova ha scritto:
Quoted 2 lines
With this option the user can perform multiple builds of QEMU with different tracing event properties.
I don't understand why this is useful? If it is just to add/remove "disable" here and there, surely the user should be using git and different branches?
Well, you can create multiple build directories that use a different trace-events file. As you have to explicitly add the "instrument" keyword on events, I found it handy to have builds with different sorts of events.
Lluis
Signature · 4 lines
"And it's much the same thing with knowledge, for whenever you learn something new, the whole world becomes that much richer." -- The Princess of Pure Reason, as told by Norton Juster in The Phantom Tollbooth
Quoted 16 lines · Stefan Hajnoczi
Quoted 15 lines · Lluís Vilanova
Quoted 5 lines · Stefan Hajnoczi
On Wed, Apr 24, 2013 at 02:17:22PM +0200, Lluís Vilanova wrote:
Given that the group of users for this feature is so small while the burden of supporting this is rather large, it seems like writing instrumentation code straight in a QEMU source tree is the most powerful and viable solution.Well, the tracing event instrumentation support itself is quite generic and should be maintainable, and can enormously simplify the task for others to use it in the future.
From my repository, the first three series (including this one) handle the infrastructure, which is mostly based on providing tracetool backends.
Quoted 8 lines
Quoted 2 lines
The 4th one adds some very generic events (vbbl_{before,after}, vinst_{before,after}, vmem) that should have no ties to the TCG implementation.
They would be affected by things like real TCG vcpu threads (parallel translation and execution) because now trace events will be invoked simultaneously from multiple threads. Or heterogenous cores in QEMU (ARM + DSP) where previously you could assume there is one target architecture.
Yes, my assumption was that the library is invoked on the vCPU's thread, so everything is performed on its context. For other non-guest tracing events, you need to know what's going on in QEMU, and that's why events are not instrumentable by default.
What I didn't yet get to implement is to safely unload an instrumentation library or change the callback for an event (e.g., ensure it is performed exclusively).
As for the heterogeneous case, I thought it was still far, so I didn't give it much thought. Most of the code in the base infrastructure is oblivious to the target. Once you need that, the affected target-specific routines would need to be defined using something similar to the current function pointers in CPUState when having a heterogeneous QEMU.
Quoted 14 lines
Quoted 7 lines
The 5th one adds the backdoor we discussed long ago, which lets the guest code interact with the instrumentation library, so that they can coordinate (AFAIR, Blue said that could come in handy during tests, for example).
The next ones probably are more controversial, as they start adding new interfaces available to the instrumentation libraries (as well as some extra events).
I don't think this effort is maintainable.
The API would be great if QEMU was heavily focussed on instrumentation and simulation research. It allows interesting analysis without diving into the internals of QEMU.
Quoted 7 lines
The problem is it touches everything in QEMU because you should be able to instrument everything. Who is going to maintain an API of this scope?
The QEMU community has two large groups: TCG for emulation and KVM for virtualization. The API doesn't offer them anything so they will not keep it in mind when making changes.
Ok, my bad. After the initial discussions that took place long ago I understood there actually was some interest in having such functionality, although not with all the public APIs I added.
I have no problem in maintaining a separate branch for certain events and interfaces (some of which are currently quite crude and hackish in the final series), as long as the bases are upstream (e.g., instrumentation infrastructure, and the most basic abstract guest events).
Quoted 3 lines
This is why I think it makes more sense to focus on specific tools that don't try to introduce stable APIs. i.e. a tool for instruction tracing in TCG.
I'm not sure what you mean by such a tool. What some patches do is, for example, call "trace_vbbl_begin" at the beginning of the main loop of "gen_intermediate_code_internal" of each target. The user does not instrument calls to actual TCG routines (which know near to nothing about the guest semantics), but only the "vbbl_begin" event.
In fact, while looking at all the targets I thought about unifying code by merging code generation of all targets using a single common header implementing the main loop, with callbacks to target-specific code. But I thought that would be too invasive to the project.
I agree that all the public API could become a burden for a project only interested in functional emulation and virtualization, but as I said I think the most basic parts of it could be landed, already providing a powerful infrastructure where further extension is up to the user.
Quoted 6 lines
Advanced users will have to modify the QEMU source.
Quoted 4 lines
Quoted 3 lines
Basically I think putting a stable API in place here isn't going to fly. In terms of the tracing subsystem I don't mind, but I think it's a question for the larger QEMU community.
Quoted 6 lines
Quoted 1 line
What are you referring to as an API? The tracing events and their signatures?
The interface that dynamic instrumentation libraries use to interact with QEMU. That means "stable" tracing events plus any operations that libraries can perform (stop/stop vcpu, peek/poke memory, dirty bitmaps, MMU, interrupts, etc).
Not all events require being "stable", just a few that I established as "abstract" and relate to some very generic guest state (which in their most basic form can be boiled down to 5). As for the rest of the API and more controversial events, as I said I have no problem in maintaining a separate branch.
Thanks,
Lluis
Signature · 4 lines
"And it's much the same thing with knowledge, for whenever you learn something new, the whole world becomes that much richer." -- The Princess of Pure Reason, as told by Norton Juster in The Phantom Tollbooth
Quoted 16 lines · Lluís Vilanova
Quoted 7 lines · Stefan Hajnoczi
On Fri, Apr 26, 2013 at 02:15:46PM +0200, Lluís Vilanova wrote:
Advanced users will have to modify the QEMU source.Quoted 4 lines
Quoted 3 lines
Basically I think putting a stable API in place here isn't going to fly. In terms of the tracing subsystem I don't mind, but I think it's a question for the larger QEMU community.
Quoted 6 lines
Quoted 1 line
What are you referring to as an API? The tracing events and their signatures?
The interface that dynamic instrumentation libraries use to interact with QEMU. That means "stable" tracing events plus any operations that libraries can perform (stop/stop vcpu, peek/poke memory, dirty bitmaps, MMU, interrupts, etc).
Quoted 5 lines
Not all events require being "stable", just a few that I established as "abstract" and relate to some very generic guest state (which in their most basic form can be boiled down to 5). As for the rest of the API and more controversial events, as I said I have no problem in maintaining a separate branch.
Can you split the work into two patch series:
1. Target-independent TCG events (e.g. vbbl_begin)
2. "custom" trace backend that links custom C trace event handler functions - but without dynamic libraries or stable API.
It loses the dynamic library and stable API features but would be easy to merge.
Stefan
Quoted 23 lines · Stefan Hajnoczi
Quoted 16 lines · Lluís Vilanova
Quoted 7 lines · Stefan Hajnoczi
On Fri, Apr 26, 2013 at 02:15:46PM +0200, Lluís Vilanova wrote:
Advanced users will have to modify the QEMU source.Quoted 4 lines
Quoted 3 lines
Basically I think putting a stable API in place here isn't going to fly. In terms of the tracing subsystem I don't mind, but I think it's a question for the larger QEMU community.
Quoted 6 lines
Quoted 1 line
What are you referring to as an API? The tracing events and their signatures?
The interface that dynamic instrumentation libraries use to interact with QEMU. That means "stable" tracing events plus any operations that libraries can perform (stop/stop vcpu, peek/poke memory, dirty bitmaps, MMU, interrupts, etc).
Quoted 5 lines
Not all events require being "stable", just a few that I established as "abstract" and relate to some very generic guest state (which in their most basic form can be boiled down to 5). As for the rest of the API and more controversial events, as I said I have no problem in maintaining a separate branch.
Quoted 7 lines
Can you split the work into two patch series:
1. Target-independent TCG events (e.g.vbbl_begin)
2. "custom" trace backend that links custom C trace event handler functions - but without dynamic libraries or stable API.It loses the dynamic library and stable API features but would be easy to merge.
Yes, I was thinking about sending a mail along those lines too. This basically entails two series (2nd and 4th in my current branch):
* Support for tracing events at TCG code generation time (basically auto-generating per-event TCG helpers - trace_<event>_tcg -, which call the actual tracing event - trace_<event> -).
* The events themselves (calls to trace_<event>_tcg).
I can then maintain instrumentation support and its public API on a separate branch.
Still, I'm not sure when I'll have time for this, as it will require moving a few patches among the series I have now (and readjusting their contents).
Thanks,
Lluis
Signature · 4 lines
"And it's much the same thing with knowledge, for whenever you learn something new, the whole world becomes that much richer." -- The Princess of Pure Reason, as told by Norton Juster in The Phantom Tollbooth