trace-tcg: Allow tracing guest events in TCG-generated code
cover trace-tcg: Allow tracing guest events in TCG-generated code
Adds the basic ability to specify which events in the "trace-events" may be used to trace guest activity in the TCG code.
Such events generate an extra set of tracing functions that can be called during TCG code generation and will automatically redirect a call to the appropriate backend-dependant tracing functions when the guest code is executed.
The extra routines and files generated by tracetool are:
* trace-tcg-helper.h
Included on all "${target}/helper.h" headers.Declares a 'trace_${name}_proxy' TCG helper using the 'DEF_HELPER_*' macros for each TCG-aware event.
Defines a 'gen_helper_trace_${name}' that ends up calling
'gen_helper_trace_${name}_proxy'.In order to provide a more streamlined interface, this routine can take a mix of tracing-supported types and TCG types. In order to do this, it automatically casts the arguments and allocates them into the appropriate TCG types, calls 'gen_helper_trace_${name}_proxy' and frees the temporary TCG values it has allocated.
* trace-tcg-helper.c
Defines a 'trace_${name}_proxy' TCG helper for each TCG-aware event. This
helper will immediately call 'trace_${name}' with all the necessary argument
type casts to match the signature of the callee.NOTE: This patch series has been stripped out of all trace instrumentation
features, and is thus applicable on top of QEMU 1.0
---
Lluís Vilanova (10):
trace: [doc] Document event properties on a separate section
trace-tcg: Add documentation
Trivial changes to eliminate auto-generated files [m68k,s390,xtensa] Move helpers.h to helper.h
trace: [tracetool] Common functions to manage event arguments
trace: [tracetool] Add 'get_api_name' to construct the name of tracing routines
trace-tcg: [tracetool] Allow TCG types in trace event declarations
trace-tcg: [tracetool] Declare TCG tracing helper routines
trace-tcg: [tracetool] Define TCG tracing helper routines
trace-tcg: [all] Include TCG-tracing helpers
.gitignore | 2 Makefile | 11 + Makefile.objs | 17 ++ Makefile.target | 2 def-helper.h | 9 + docs/tracing.txt | 62 +++++- scripts/simpletrace.py | 2 scripts/tracetool | 449 +++++++++++++++++++++++++++++++++++++++++--- target-alpha/helper.h | 2 target-arm/helper.h | 2 target-cris/helper.h | 2 target-i386/helper.h | 2 target-lm32/helper.h | 2 target-m68k/helper.c | 2 target-m68k/helper.h | 56 +++++ target-m68k/helpers.h | 54 ----- target-m68k/op_helper.c | 2 target-m68k/translate.c | 6 - target-microblaze/helper.h | 2 target-mips/helper.h | 2 target-ppc/helper.h | 2 target-s390x/helper.h | 154 +++++++++++++++ target-s390x/helpers.h | 152 --------------- target-s390x/op_helper.c | 2 target-s390x/translate.c | 4 target-sh4/helper.h | 2 target-sparc/helper.h | 2 target-unicore32/helper.h | 2 target-xtensa/helper.h | 34 +++ target-xtensa/helpers.h | 32 --- target-xtensa/op_helper.c | 2 target-xtensa/translate.c | 6 - xtensa-semi.c | 2 33 files changed, 796 insertions(+), 288 deletions(-) create mode 100644 target-m68k/helper.h delete mode 100644 target-m68k/helpers.h create mode 100644 target-s390x/helper.h delete mode 100644 target-s390x/helpers.h create mode 100644 target-xtensa/helper.h delete mode 100644 target-xtensa/helpers.h
PATCH 1/10 trace: [doc] Document event properties on a separate section
--- docs/tracing.txt | 22 ++++++++++++++++------ 1 files changed, 16 insertions(+), 6 deletions(-)
docs/tracing.txt +16 -6
@@ -98,12 +98,6 @@ respectively. This ensures portability between 32- and 64-bit platforms. 4. Name trace events after their function. If there are multiple trace events in one function, append a unique distinguisher at the end of the name. -5. If specific trace events are going to be called a huge number of times, this - might have a noticeable performance impact even when the trace events are - programmatically disabled. In this case you should declare the trace event - with the "disable" property, which will effectively disable it at compile - time (using the "nop" backend). - == Generic interface and monitor commands == You can programmatically query and control the dynamic state of trace events
@@ -234,3 +228,19 @@ probes: --target-type system \ --target-arch x86_64 \ <trace-events >qemu.stp + +== Trace event properties == + +Each event in the "trace-events" file can be prefixed with a space-separated +list of zero or more of the following event properties. + +=== "disable" === + +If a specific trace event is going to be invoked a huge number of times, this +might have a noticeable performance impact even when the event is +programmatically disabled. + +In this case you should declare such event with the "disable" property. This +will effectively disable the event at compile time (by using the "nop" backend), +thus having no performance impact at all on regular builds (i.e., unless you +edit the "trace-events" file).
Re: [Qemu-devel] [PATCH 01/10] trace: [doc] Document event properties on a separate section
This series must be updated to apply on top of the patch recently accepted by Stefan into the tracing tree [1].
[1] http://lists.gnu.org/archive/html/qemu-devel/2011-12/msg00763.html
Lluis
Quoted 42 lines · Lluís Vilanova
Signed-off-by Lluís Vilanova <[email protected]>--- docs/tracing.txt | 22 ++++++++++++++++------ 1 files changed, 16 insertions(+), 6 deletions(-)docs/tracing.txt +16
-6@@ -98,12 +98,6 @@ respectively. This ensures portability between 32- and 64-bit platforms. 4. Name trace events after their function. If there are multiple trace events in one function, append a unique distinguisher at the end of the name. -5. If specific trace events are going to be called a huge number of times, this - might have a noticeable performance impact even when the trace events are - programmatically disabled. In this case you should declare the trace event - with the "disable" property, which will effectively disable it at compile - time (using the "nop" backend). - == Generic interface and monitor commands == You can programmatically query and control the dynamic state of trace events@@ -234,3 +228,19 @@ probes: --target-type system \ --target-arch x86_64 \ <trace-events >qemu.stp + +== Trace event properties == + +Each event in the "trace-events" file can be prefixed with a space-separated +list of zero or more of the following event properties. + +=== "disable" === + +If a specific trace event is going to be invoked a huge number of times, this +might have a noticeable performance impact even when the event is +programmatically disabled. + +In this case you should declare such event with the "disable" property. This +will effectively disable the event at compile time (by using the "nop" backend), +thus having no performance impact at all on regular builds (i.e., unless you +edit the "trace-events" file).
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
PATCH 2/10 trace-tcg: Add documentation
In reply to Lluís Vilanova--- docs/tracing.txt | 40 ++++++++++++++++++++++++++++++++++++++++ 1 files changed, 40 insertions(+), 0 deletions(-)
docs/tracing.txt +40 -0
@@ -244,3 +244,43 @@ In this case you should declare such event with the "disable" property. This will effectively disable the event at compile time (by using the "nop" backend), thus having no performance impact at all on regular builds (i.e., unless you edit the "trace-events" file). + +=== "tcg" === + +Code from the guest generated by TCG can be traced by defining an event with the +"tcg" event property. + +In addition to the regular "trace_<eventname>" routine in the "trace.h" header, +events with the "tcg" property will also provide the TCG helper routine +"gen_helper_trace_<eventname>". This routine can be called during TCG code +generation as any other TCG helper to automatically generate TCG code to call +"trace_<eventname>" during TCG code execution. + +The notable difference is that these events can be declared in the +"trace-events" file with both basic types as well as TCG types. The +"gen_helper_trace_<eventname>" routine will transparently take care of turning +any non-TCG argument into a TCG value. + +For example, the event: + + tcg foo(uint8_t a1, TCGv_i32 a2) "a1=%d a2=%d" + +Can be invoked from TCG code as: + + uint8_t a1 = ...; + TCGv_i32 a2 = ...; + gen_helper_trace_foo(a1, a2); + +And the intermediate boilerplate code will take care of generating the TCG code +to call: + + void trace_foo(uint8_t a1, uint32_t a2); + +=== "tcg-vcpu" === + +Events with the "tcg" property will generate code helpers with the +"TCG_CALL_CONST" flag (see "tcg/README" and "tcg/tcg.h"), which produces faster +code that is unable to reliably access the state of the vCPU. + +Using the "tcg-vcpu" property will generate a slower TCG helper that will be +able to reliably get and set values from the vCPU.
PATCH 3/10 Trivial changes to eliminate auto-generated files
In reply to Lluís Vilanova--- Makefile | 11 ++++++++--- 1 files changed, 8 insertions(+), 3 deletions(-)
Makefile +8 -3
@@ -3,10 +3,14 @@ # Always point to the root of the build tree (needs GNU make). BUILD_DIR=$(CURDIR) -GENERATED_HEADERS = config-host.h trace.h qemu-options.def +GENERATED_HEADERS = config-host.h qemu-options.def + +GENERATED_HEADERS += trace.h ifeq ($(TRACE_BACKEND),dtrace) GENERATED_HEADERS += trace-dtrace.h endif +GENERATED_SOURCES += trace.c + GENERATED_HEADERS += qmp-commands.h qapi-types.h qapi-visit.h GENERATED_SOURCES += qmp-marshal.c qapi-types.c qapi-visit.c
@@ -226,10 +230,11 @@ clean: rm -f slirp/*.o slirp/*.d audio/*.o audio/*.d block/*.o block/*.d net/*.o net/*.d fsdev/*.o fsdev/*.d ui/*.o ui/*.d qapi/*.o qapi/*.d qga/*.o qga/*.d rm -f qemu-img-cmds.h rm -f trace/*.o trace/*.d - rm -f trace.c trace.h trace.c-timestamp trace.h-timestamp rm -f trace-dtrace.dtrace trace-dtrace.dtrace-timestamp + @# May not be present in GENERATED_HEADERS rm -f trace-dtrace.h trace-dtrace.h-timestamp - rm -f $(GENERATED_SOURCES) + rm -f $(foreach f,$(GENERATED_HEADERS) $(foreach h,$(GENERATED_HEADERS),$(h)-timestamp),$(f) */$(f)) + rm -f $(foreach f,$(GENERATED_SOURCES) $(foreach h,$(GENERATED_SOURCES),$(h)-timestamp),$(f) */$(f)) rm -rf $(qapi-dir) $(MAKE) -C tests clean for d in $(ALL_SUBDIRS) $(QEMULIBS) libcacard; do \
PATCH 4/10 Move helpers.h to helper.h
In reply to Lluís VilanovaThis provides a consistent file naming scheme across all targets.
--- target-m68k/helper.c | 2 - target-m68k/helper.h | 54 ++++++++++++++++ target-m68k/helpers.h | 54 ---------------- target-m68k/op_helper.c | 2 - target-m68k/translate.c | 6 +- target-s390x/helper.h | 152 +++++++++++++++++++++++++++++++++++++++++++++ target-s390x/helpers.h | 152 --------------------------------------------- target-s390x/op_helper.c | 2 - target-s390x/translate.c | 4 + target-xtensa/helper.h | 32 +++++++++ target-xtensa/helpers.h | 32 --------- target-xtensa/op_helper.c | 2 - target-xtensa/translate.c | 6 +- xtensa-semi.c | 2 - 14 files changed, 251 insertions(+), 251 deletions(-) create mode 100644 target-m68k/helper.h delete mode 100644 target-m68k/helpers.h create mode 100644 target-s390x/helper.h delete mode 100644 target-s390x/helpers.h create mode 100644 target-xtensa/helper.h delete mode 100644 target-xtensa/helpers.h
target-m68k/helper.c +1 -1
@@ -26,7 +26,7 @@#include "qemu-common.h" #include "gdbstub.h" -#include "helpers.h" +#include "helper.h" #define SIGNBIT (1u << 31)
target-m68k/helper.h new file +54 -0
54 lines not on this page · raw message
target-m68k/helpers.h deleted +0 -54
54 lines not on this page · raw message
target-m68k/op_helper.c +1 -1
@@ -18,7 +18,7 @@*/ #include "cpu.h" #include "dyngen-exec.h" -#include "helpers.h" +#include "helper.h" #if defined(CONFIG_USER_ONLY )
target-m68k/translate.c +3 -3
@@ -29,9 +29,9 @@#include "tcg-op.h" #include "qemu-log.h" -#include "helpers.h" +#include "helper.h" #define GEN_HELPER 1 -#include "helpers.h" +#include "helper.h" //#define DEBUG_DISPATCH 1
@@ -110,7 +110,7 @@ void m68k_tcg_init(void) store_dummy =tcg_global_mem_new (TCG_AREG0 ,-8 ,"NULL" );#define GEN_HELPER 2 -#include "helpers.h" +#include "helper.h" }static inline void qemu_assert (int cond,const char *msg)
target-s390x/helper.h new file +152 -0
152 lines not on this page · raw message
target-s390x/helpers.h deleted +0 -152
152 lines not on this page · raw message
target-s390x/op_helper.c +1 -1
@@ -21,7 +21,7 @@#include "cpu.h" #include "dyngen-exec.h" #include "host-utils.h" -#include "helpers.h" +#include "helper.h" #include <string.h> #include "kvm.h" #include "qemu-timer.h"
target-s390x/translate.c +2 -2
@@ -43,9 +43,9 @@static TCGv_ptr cpu_env;#include "gen-icount.h" -#include "helpers.h" +#include "helper.h" #define GEN_HELPER 1 -#include "helpers.h" +#include "helper.h" typedef struct DisasContext DisasContext ;struct DisasContext {
target-xtensa/helper.h new file +32 -0
@@ -0,0 +1,32 @@ +#include "def-helper.h" + +DEF_HELPER_1(exception, void, i32) +DEF_HELPER_2(exception_cause, void, i32, i32) +DEF_HELPER_3(exception_cause_vaddr, void, i32, i32, i32) +DEF_HELPER_1(nsa, i32, i32) +DEF_HELPER_1(nsau, i32, i32) +DEF_HELPER_1(wsr_windowbase, void, i32) +DEF_HELPER_3(entry, void, i32, i32, i32) +DEF_HELPER_1(retw, i32, i32) +DEF_HELPER_1(rotw, void, i32) +DEF_HELPER_2(window_check, void, i32, i32) +DEF_HELPER_0(restore_owb, void) +DEF_HELPER_1(movsp, void, i32) +DEF_HELPER_1(wsr_lbeg, void, i32) +DEF_HELPER_1(wsr_lend, void, i32) +DEF_HELPER_1(simcall, void, env) +DEF_HELPER_0(dump_state, void) + +DEF_HELPER_2(waiti, void, i32, i32) +DEF_HELPER_2(timer_irq, void, i32, i32) +DEF_HELPER_1(advance_ccount, void, i32) +DEF_HELPER_1(check_interrupts, void, env) + +DEF_HELPER_1(wsr_rasid, void, i32) +DEF_HELPER_2(rtlb0, i32, i32, i32) +DEF_HELPER_2(rtlb1, i32, i32, i32) +DEF_HELPER_2(itlb, void, i32, i32) +DEF_HELPER_2(ptlb, i32, i32, i32) +DEF_HELPER_3(wtlb, void, i32, i32, i32) + +#include "def-helper.h"
target-xtensa/helpers.h deleted +0 -32
@@ -1,32 +0,0 @@ -#include "def-helper.h" - -DEF_HELPER_1(exception, void, i32) -DEF_HELPER_2(exception_cause, void, i32, i32) -DEF_HELPER_3(exception_cause_vaddr, void, i32, i32, i32) -DEF_HELPER_1(nsa, i32, i32) -DEF_HELPER_1(nsau, i32, i32) -DEF_HELPER_1(wsr_windowbase, void, i32) -DEF_HELPER_3(entry, void, i32, i32, i32) -DEF_HELPER_1(retw, i32, i32) -DEF_HELPER_1(rotw, void, i32) -DEF_HELPER_2(window_check, void, i32, i32) -DEF_HELPER_0(restore_owb, void) -DEF_HELPER_1(movsp, void, i32) -DEF_HELPER_1(wsr_lbeg, void, i32) -DEF_HELPER_1(wsr_lend, void, i32) -DEF_HELPER_1(simcall, void, env) -DEF_HELPER_0(dump_state, void) - -DEF_HELPER_2(waiti, void, i32, i32) -DEF_HELPER_2(timer_irq, void, i32, i32) -DEF_HELPER_1(advance_ccount, void, i32) -DEF_HELPER_1(check_interrupts, void, env) - -DEF_HELPER_1(wsr_rasid, void, i32) -DEF_HELPER_2(rtlb0, i32, i32, i32) -DEF_HELPER_2(rtlb1, i32, i32, i32) -DEF_HELPER_2(itlb, void, i32, i32) -DEF_HELPER_2(ptlb, i32, i32, i32) -DEF_HELPER_3(wtlb, void, i32, i32, i32) - -#include "def-helper.h"
target-xtensa/op_helper.c +1 -1
@@ -27,7 +27,7 @@#include "cpu.h" #include "dyngen-exec.h" -#include "helpers.h" +#include "helper.h" #include "host-utils.h" static void do_unaligned_access(target_ulong addr, int is_write, int is_user,
target-xtensa/translate.c +3 -3
@@ -37,9 +37,9 @@#include "qemu-log.h" #include "sysemu.h" -#include "helpers.h" +#include "helper.h" #define GEN_HELPER 1 -#include "helpers.h" +#include "helper.h" typedef struct DisasContext { const XtensaConfig *config;
@@ -169,7 +169,7 @@ void xtensa_translate_init(void) } }#define GEN_HELPER 2 -#include "helpers.h" +#include "helper.h" }static inline bool option_bits_enabled (DisasContext *dc,uint64_t opt)
xtensa-semi.c +1 -1
@@ -31,7 +31,7 @@#include <stddef.h> #include "cpu.h" #include "dyngen-exec.h" -#include "helpers.h" +#include "helper.h" #include "qemu-log.h" enum {
PATCH 5/10 trace: [tracetool] Common functions to manage event arguments
In reply to Lluís VilanovaThis adds:
* zip_lists: Pair elements from two lists.
* get_argtypes: Get the list of types of the arguments; can optionally transform the types in the process.
The function 'get_args' is modified to use a combination of 'get_argnames', 'get_argtypes', 'zip_lists' and, optionally, use the type transformation capabilities of 'get_argtypes'.
--- scripts/tracetool | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 116 insertions(+), 1 deletions(-)
scripts/tracetool +116 -1
@@ -74,15 +74,130 @@ has_property() return 1 } +# Convenience function to pair elements from two comma-separated lists of equal +# size. +# 1: first list +# 2: second list +# 3: printf format for each pair of elements (optional, default: "%s %s, ") +zip_lists() +{ + [ -n "$1" -a -n "$2" ] || return + + local format + format=$3 + [ -n "$format" ] || format="%s %s, " + + local i elem accum + i=1 + accum="" + for elem in $1; do + if [ "$elem" = "${elem%,}" ]; then + accum="$accum $elem" + else + accum="$accum ${elem%,}" + eval __elem_$i=\"$accum\" + i=$(($i + 1)) + accum="" + fi + done + eval __elem_$i=\"$accum\" + + local tmp res + accum="" + res="" + i=1 + for elem in $2; do + if [ "$elem" = "${elem%,}" ]; then + accum="$accum $elem" + else + accum="$accum ${elem%,}" + eval tmp=\$__elem_$i + tmp=$(printf "$format" "$tmp" "$accum") + res="$res$tmp" + i=$(($i + 1)) + accum="" + fi + done + eval tmp=\$__elem_$i + tmp=$(printf "$format" "$tmp" "$accum") + res="$res$tmp" + res="${res%, }" + echo $res +} + # Get the argument list of a trace event, including types and names +# 1: event name +# 2: passed as the second argument to 'get_argtypes' (optional) get_args() { local args args=${1#*\(} args=${args%%\)*} - echo "$args" + + if [ -z "$2" -o "$args" = "void" ]; then + echo "$args" + else + local argtypes argnames res + argtypes=$(get_argtypes "$1" $2) + argnames=$(get_argnames "$1" ",") + res=$(zip_lists "$argtypes" "$argnames") + echo "${res#, }" + fi } +# Get the argument type list of a trace event +# 1: event name +# 2: function to translate each of the types (optional, default: nil_type) +get_argtypes() +{ + local translate field type res + + translate=$2 + [ -n "$translate" ] || translate=nil_type + + res="" + type="" + for field in $(get_args "$1"); do + if [ "${field%,}" != "${field}" ]; then + # it's a name, but can have a star in it + [ "${field#\*}" = "$field" ] || type="${type}*" + # trim spaces + type="${type## }" + type="${type%% }" + # translate + type=$($translate "$type") + res="$res$type, " + type="" + else + # types can have spaces + type="$type $field" + fi + done + + # remove the accumulated name + field="${type##* }" + type="${type% *}" + + # trim spaces + type="${type## }" + type="${type%% }" + + # it's a name, but can have a star in it + [ "${field#\*}" = "$field" ] || type="${type}*" + # translate + type=$($translate "$type") + res="$res$type" + + echo $res +} + +# No-op type translator for get_argtypes +nil_type() +{ + echo "$1" +} + + # Get the argument name list of a trace event get_argnames() {
PATCH 6/10 trace: [tracetool] Add 'get_api_name' to construct the name of tracing routines
In reply to Lluís VilanovaAll backends now use 'get_api_name' to build the name of the routines that are used by QEMU code when invoking trace points. This is built based on the value of 'get_api_name_fmt_default'.
The old 'get_name' is still available to refer to the name of an event.
This ensures proper naming across tracing backends.
--- scripts/tracetool | 40 ++++++++++++++++++++++++++++------------ 1 files changed, 28 insertions(+), 12 deletions(-)
scripts/tracetool +28 -12
@@ -57,6 +57,19 @@ get_name() echo "${name##* }" } +get_api_name_fmt_default="trace_%s" + +# Get the tracepoint name of a trace event (the name of the function QEMU uses) +# The result is 'printf "$fmt" $name', where 'fmt' is +# 'get_api_name_fmt_default'. +get_api_name() +{ + local name fmt + name=$(get_name "$1") + fmt="$get_api_name_fmt_default" + printf "$fmt" "$name" +} + # Get the given property of a trace event # 1: trace-events line # 2: property name
@@ -248,13 +261,13 @@ linetoh_begin_nop() linetoh_nop() { - local name args - name=$(get_name "$1") + local api args + api=$(get_api_name "$1") args=$(get_args "$1") # Define an empty function for the trace event cat <<EOF -static inline void trace_$name($args) +static inline void ${api}($args) { } EOF
@@ -300,8 +313,8 @@ cast_args_to_uint64_t() linetoh_simple() { - local name args argc trace_args - name=$(get_name "$1") + local api args argc trace_args + api=$(get_api_name "$1") args=$(get_args "$1") argc=$(get_argc "$1")
@@ -312,7 +325,7 @@ linetoh_simple() fi cat <<EOF -static inline void trace_$name($args) +static inline void ${api}($args) { trace$argc($trace_args); }
@@ -372,8 +385,9 @@ EOF linetoh_stderr() { - local name args argnames argc fmt + local name api args argnames argc fmt name=$(get_name "$1") + api=$(get_api_name "$1") args=$(get_args "$1") argnames=$(get_argnames "$1" ",") argc=$(get_argc "$1")
@@ -384,7 +398,7 @@ linetoh_stderr() fi cat <<EOF -static inline void trace_$name($args) +static inline void ${api}($args) { if (trace_list[$stderr_event_num].state != 0) { fprintf(stderr, "$name " $fmt "\n" $argnames);
@@ -448,14 +462,15 @@ linetoh_begin_ust() linetoh_ust() { - local name args argnames + local name api args argnames name=$(get_name "$1") + api=$(get_api_name "$1") args=$(get_args "$1") argnames=$(get_argnames "$1", ",") cat <<EOF DECLARE_TRACE(ust_$name, TP_PROTO($args), TP_ARGS($argnames)); -#define trace_$name trace_ust_$name +#define ${api} trace_ust_$name EOF }
@@ -520,8 +535,9 @@ EOF linetoh_dtrace() { - local name args argnames nameupper + local name api args argnames nameupper name=$(get_name "$1") + api=$(get_api_name "$1") args=$(get_args "$1") argnames=$(get_argnames "$1", ",")
@@ -529,7 +545,7 @@ linetoh_dtrace() # Define an empty function for the trace event cat <<EOF -static inline void trace_$name($args) { +static inline void ${api}($args) { if (QEMU_${nameupper}_ENABLED()) { QEMU_${nameupper}($argnames); }
PATCH 7/10 trace-tcg: [tracetool] Allow TCG types in trace event declarations
In reply to Lluís VilanovaWhen found, TCG types are translated into the host native types when declaring and defining the tracing routines in "trace.h" and "trace.c".
--- scripts/tracetool | 31 +++++++++++++++++++++++-------- 1 files changed, 23 insertions(+), 8 deletions(-)
scripts/tracetool +23 -8
@@ -210,6 +210,21 @@ nil_type() echo "$1" } +# Native type translator for get_argtypes +# (e.g., TCGv_i32 -> uint32_t) +host_type() +{ + case "$1" in + "TCGv_i32") echo "uint32_t" ;; + "TCGv_i64") echo "uint64_t" ;; + "TCGv_ptr") echo "void *" ;; + # force a fixed-size type in trace.{h,c} + # (ideally would use a host-specific type) + "TCGv") echo "uint64_t" ;; + *) echo "$1" ;; + esac +} + # Get the argument name list of a trace event get_argnames()
@@ -263,7 +278,7 @@ linetoh_nop() { local api args api=$(get_api_name "$1") - args=$(get_args "$1") + args=$(get_args "$1" host_type) # Define an empty function for the trace event cat <<EOF
@@ -315,7 +330,7 @@ linetoh_simple() { local api args argc trace_args api=$(get_api_name "$1") - args=$(get_args "$1") + args=$(get_args "$1" host_type) argc=$(get_argc "$1") trace_args="$simple_event_num"
@@ -388,7 +403,7 @@ linetoh_stderr() local name api args argnames argc fmt name=$(get_name "$1") api=$(get_api_name "$1") - args=$(get_args "$1") + args=$(get_args "$1" host_type) argnames=$(get_argnames "$1" ",") argc=$(get_argc "$1") fmt=$(get_fmt "$1")
@@ -465,7 +480,7 @@ linetoh_ust() local name api args argnames name=$(get_name "$1") api=$(get_api_name "$1") - args=$(get_args "$1") + args=$(get_args "$1" host_type) argnames=$(get_argnames "$1", ",") cat <<EOF
@@ -492,7 +507,7 @@ linetoc_ust() { local name args argnames fmt name=$(get_name "$1") - args=$(get_args "$1") + args=$(get_args "$1" host_type) argnames=$(get_argnames "$1", ",") [ -z "$argnames" ] || argnames=", $argnames" fmt=$(get_fmt "$1")
@@ -538,7 +553,7 @@ linetoh_dtrace() local name api args argnames nameupper name=$(get_name "$1") api=$(get_api_name "$1") - args=$(get_args "$1") + args=$(get_args "$1" host_type) argnames=$(get_argnames "$1", ",") nameupper=`echo $name | tr '[:lower:]' '[:upper:]'`
@@ -585,7 +600,7 @@ linetod_dtrace() { local name args name=$(get_name "$1") - args=$(get_args "$1") + args=$(get_args "$1" host_type) # DTrace provider syntax expects foo() for empty # params, not foo(void)
@@ -615,7 +630,7 @@ linetostap_dtrace() { local i arg name args arglist name=$(get_name "$1") - args=$(get_args "$1") + args=$(get_args "$1" host_type) arglist=$(get_argnames "$1", "") # Define prototype for probe arguments
PATCH 8/10 trace-tcg: [tracetool] Declare TCG tracing helper routines
In reply to Lluís VilanovaGenerate the necessary TCG helper declarations for tracing events in guest code.
--- .gitignore | 1 Makefile | 2 Makefile.objs | 9 ++ def-helper.h | 9 ++ scripts/simpletrace.py | 2 scripts/tracetool | 202 ++++++++++++++++++++++++++++++++++++++++++++++-- 6 files changed, 214 insertions(+), 11 deletions(-)
.gitignore +1 -0
@@ -6,6 +6,7 @@ trace.h trace.c trace-dtrace.h trace-dtrace.dtrace +trace-tcg-helper.h *-timestamp *-softmmu *-darwin-user
Makefile +1 -1
@@ -5,7 +5,7 @@ BUILD_DIR=$(CURDIR) GENERATED_HEADERS = config-host.h qemu-options.def -GENERATED_HEADERS += trace.h +GENERATED_HEADERS += trace.h trace-tcg-helper.h ifeq ($(TRACE_BACKEND),dtrace) GENERATED_HEADERS += trace-dtrace.h endif
Makefile.objs +9 -0
@@ -398,6 +398,15 @@ trace-obj-y += $(addprefix trace/, $(trace-nested-y)) $(trace-obj-y): $(GENERATED_HEADERS) ###################################################################### +# trace tcg + +trace-tcg-helper.h-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak + $(call quiet-command,sh $(SRC_PATH)/scripts/tracetool $(TRACETOOL_EXTRA) --tcg --tcg-h < $< > $@," GEN $(TARGET_DIR)trace-tcg-helper.h") + @cmp -s $@ trace-tcg-helper.h || cp $@ trace-tcg-helper.h + +trace-tcg-helper.h: trace-tcg-helper.h-timestamp + +###################################################################### # smartcard libcacard-y = cac.o event.o vcard.o vreader.o vcard_emul_nss.o vcard_emul_type.o card_7816.o
def-helper.h +9 -0
@@ -13,6 +13,11 @@helper.c, defining: GEN_HELPER 1 to produce op generation functions (gen_helper_*) GEN_HELPER 2 to do runtime registration helper functions. + +After including this header the GEN_HELPER_MACRO will have the following +values: +1 : op generation functions were produced (GEN_HELPER was 1) +-1 : otherwise */ #ifndef DEF_HELPER_H
@@ -142,6 +147,7 @@ dh_ctype(ret) HELPER(name) (dh_ctype(t1), dh_ctype(t2), dh_ctype(t3), \#undef GEN_HELPER#define GEN_HELPER -1 +#define GEN_HELPER_CODE -1#elif GEN_HELPER ==1 /* Gen functions. */
@@ -205,6 +211,7 @@ static inline void glue(gen_helper_, name)(dh_retvar_decl(ret) dh_arg_decl(t1, 1#undef GEN_HELPER#define GEN_HELPER -1 +#define GEN_HELPER_CODE 1#elif GEN_HELPER ==2 /* Register helpers. */
@@ -226,6 +233,7 @@ DEF_HELPER_FLAGS_0(name, flags, ret)#undef GEN_HELPER#define GEN_HELPER -1 +#define GEN_HELPER_CODE -1#elif GEN_HELPER ==-1 /* Undefine macros. */
@@ -236,5 +244,6 @@ DEF_HELPER_FLAGS_0(name, flags, ret)#undef DEF_HELPER_FLAGS_3#undef DEF_HELPER_FLAGS_4#undef GEN_HELPER +#undef GEN_HELPER_CODE#endif
scripts/simpletrace.py +1 -1
@@ -20,7 +20,7 @@ dropped_event_id = 0xfffffffffffffffe trace_fmt = '=QQQQQQQQ' trace_len = struct.calcsize(trace_fmt) -event_re = re.compile(r'(disable\s+)?([a-zA-Z0-9_]+)\(([^)]*)\).*') +event_re = re.compile(r'(disable\s+|tcg\s+|tcg-vcpu\s+)*([a-zA-Z0-9_]+)\(([^)]*)\).*') def parse_events(fobj): """Parse a trace-events file into {event_num: (name, arg1, ...)}."""
scripts/tracetool +193 -9
250 lines not on this page · raw message
PATCH 9/10 trace-tcg: [tracetool] Define TCG tracing helper routines
In reply to Lluís VilanovaGenerate the necessary TCG helper routines for tracing events in guest code.
--- .gitignore | 1 + Makefile | 2 +- Makefile.objs | 8 +++++++ Makefile.target | 2 ++ scripts/tracetool | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 77 insertions(+), 1 deletions(-)
.gitignore +1 -0
@@ -7,6 +7,7 @@ trace.c trace-dtrace.h trace-dtrace.dtrace trace-tcg-helper.h +trace-tcg-helper.c *-timestamp *-softmmu *-darwin-user
Makefile +1 -1
@@ -9,7 +9,7 @@ GENERATED_HEADERS += trace.h trace-tcg-helper.h ifeq ($(TRACE_BACKEND),dtrace) GENERATED_HEADERS += trace-dtrace.h endif -GENERATED_SOURCES += trace.c +GENERATED_SOURCES += trace.c trace-tcg-helper.c GENERATED_HEADERS += qmp-commands.h qapi-types.h qapi-visit.h GENERATED_SOURCES += qmp-marshal.c qapi-types.c qapi-visit.c
Makefile.objs +8 -0
@@ -406,6 +406,14 @@ trace-tcg-helper.h-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host. trace-tcg-helper.h: trace-tcg-helper.h-timestamp +trace-tcg-helper.c-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak + $(call quiet-command,sh $(SRC_PATH)/scripts/tracetool $(TRACETOOL_EXTRA) --tcg --tcg-c < $< > $@," GEN $(TARGET_DIR)trace-tcg-helper.c") + @cmp -s $@ trace-tcg-helper.c || cp $@ trace-tcg-helper.c + +trace-tcg-helper.c: trace-tcg-helper.c-timestamp + +trace-tcg-helper.o: trace-tcg-helper.c $(GENERATED_HEADERS) + ###################################################################### # smartcard
Makefile.target +2 -0
@@ -90,6 +90,8 @@ libobj-$(CONFIG_TCI_DIS) += tci-dis.o tci-dis.o: QEMU_CFLAGS += -I$(SRC_PATH)/tcg -I$(SRC_PATH)/tcg/tci +libobj-y += trace-tcg-helper.o + $(libobj-y): $(GENERATED_HEADERS) # libqemu
scripts/tracetool +65 -0
95 lines not on this page · raw message
PATCH 10/10 trace-tcg: [all] Include TCG-tracing helpers
In reply to Lluís Vilanova--- target-alpha/helper.h | 2 ++ target-arm/helper.h | 2 ++ target-cris/helper.h | 2 ++ target-i386/helper.h | 2 ++ target-lm32/helper.h | 2 ++ target-m68k/helper.h | 2 ++ target-microblaze/helper.h | 2 ++ target-mips/helper.h | 2 ++ target-ppc/helper.h | 2 ++ target-s390x/helper.h | 2 ++ target-sh4/helper.h | 2 ++ target-sparc/helper.h | 2 ++ target-unicore32/helper.h | 2 ++ target-xtensa/helper.h | 2 ++ 14 files changed, 28 insertions(+), 0 deletions(-)
target-alpha/helper.h +2 -0
@@ -120,4 +120,6 @@ DEF_HELPER_FLAGS_0(get_time, TCG_CALL_CONST, i64) DEF_HELPER_FLAGS_1(set_alarm, TCG_CALL_CONST, void, i64)#endif +#include "trace-tcg-helper.h" +#include "def-helper.h"
target-arm/helper.h +2 -0
@@ -472,4 +472,6 @@ DEF_HELPER_3(neon_qzip8, void, env, i32, i32) DEF_HELPER_3(neon_qzip16, void, env, i32, i32) DEF_HELPER_3(neon_qzip32, void, env, i32, i32) +#include "trace-tcg-helper.h" +#include "def-helper.h"
target-cris/helper.h +2 -0
@@ -23,4 +23,6 @@ DEF_HELPER_FLAGS_2(evaluate_flags_move_2, TCG_CALL_PURE, i32, i32, i32) DEF_HELPER_0(evaluate_flags, void) DEF_HELPER_0(top_evaluate_flags, void) +#include "trace-tcg-helper.h" +#include "def-helper.h"
target-i386/helper.h +2 -0
@@ -217,4 +217,6 @@ DEF_HELPER_2(rclq, tl, tl, tl) DEF_HELPER_2(rcrq, tl, tl, tl)#endif +#include "trace-tcg-helper.h" +#include "def-helper.h"
target-lm32/helper.h +2 -0
@@ -11,4 +11,6 @@ DEF_HELPER_0(rcsr_ip, i32) DEF_HELPER_0(rcsr_jtx, i32) DEF_HELPER_0(rcsr_jrx, i32) +#include "trace-tcg-helper.h" +#include "def-helper.h"
target-m68k/helper.h +2 -0
@@ -51,4 +51,6 @@ DEF_HELPER_3(set_mac_extu, void, env, i32, i32) DEF_HELPER_2(flush_flags, void, env, i32) DEF_HELPER_1(raise_exception, void, i32) +#include "trace-tcg-helper.h" +#include "def-helper.h"
target-microblaze/helper.h +2 -0
@@ -36,4 +36,6 @@ DEF_HELPER_4(memalign, void, i32, i32, i32, i32) DEF_HELPER_2(get, i32, i32, i32) DEF_HELPER_3(put, void, i32, i32, i32) +#include "trace-tcg-helper.h" +#include "def-helper.h"
target-mips/helper.h +2 -0
@@ -297,4 +297,6 @@ DEF_HELPER_0(rdhwr_ccres, tl) DEF_HELPER_1(pmon, void, int) DEF_HELPER_0(wait, void) +#include "trace-tcg-helper.h" +#include "def-helper.h"
target-ppc/helper.h +2 -0
@@ -408,4 +408,6 @@ DEF_HELPER_2(store_601_batl, void, i32, tl) DEF_HELPER_2(store_601_batu, void, i32, tl)#endif +#include "trace-tcg-helper.h" +#include "def-helper.h"
target-s390x/helper.h +2 -0
@@ -149,4 +149,6 @@ DEF_HELPER_2(cksm, void, i32, i32)DEF_HELPER_FLAGS_4 (calc_cc,TCG_CALL_PURE |TCG_CALL_CONST , i32, i32, i64, i64, i64) +#include "trace-tcg-helper.h" +#include "def-helper.h"
target-sh4/helper.h +2 -0
@@ -51,4 +51,6 @@ DEF_HELPER_1(ftrc_DT, i32, f64) DEF_HELPER_2(fipr, void, i32, i32) DEF_HELPER_1(ftrv, void, i32) +#include "trace-tcg-helper.h" +#include "def-helper.h"
target-sparc/helper.h +2 -0
@@ -167,4 +167,6 @@ VIS_CMPHELPER(cmpne);DEF_HELPER_1 (compute_psr, void, env);DEF_HELPER_1 (compute_C_icc, i32, env); +#include "trace-tcg-helper.h" +#include "def-helper.h"
target-unicore32/helper.h +2 -0
@@ -67,4 +67,6 @@ DEF_HELPER_2(ucf64_si2df, f64, f32, env) DEF_HELPER_2(ucf64_sf2si, f32, f32, env) DEF_HELPER_2(ucf64_df2si, f32, f64, env) +#include "trace-tcg-helper.h" +#include "def-helper.h"
target-xtensa/helper.h +2 -0
@@ -29,4 +29,6 @@ DEF_HELPER_2(itlb, void, i32, i32) DEF_HELPER_2(ptlb, i32, i32, i32) DEF_HELPER_3(wtlb, void, i32, i32, i32) +#include "trace-tcg-helper.h" +#include "def-helper.h"