Patchwork [v1,2/4] trace-gen: auto-generate TCG helper routines for tracing

login
register
mail settings
Submitter =?utf-8?Q?Llu=C3=ADs?=
Date Nov. 3, 2010, 8:02 p.m.
Message ID <20101103200249.6599.63024.stgit@ginnungagap.bsc.es>
Download mbox | patch
Permalink /patch/70065/
State New
Headers show

Comments

=?utf-8?Q?Llu=C3=ADs?= - Nov. 3, 2010, 8:02 p.m.
Auto-generates file "trace-helper.h" to provide TCG helpers and "trace-helper.c"
to proxy these helpers onto trace event routines.

Only trace events with the 'gen' property are affected.

Signed-off-by: LluĂ­s Vilanova <vilanova@ac.upc.edu>
---
 .gitignore      |    2 +
 Makefile        |   15 ++++++++
 Makefile.target |    5 +--
 trace-events    |    5 +++
 tracetool       |   98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 5 files changed, 120 insertions(+), 5 deletions(-)

Patch

diff --git a/.gitignore b/.gitignore
index e4a351d..758f457 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,6 +4,8 @@  config-host.*
 config-target.*
 trace.h
 trace.c
+trace-helper.h
+trace-helper.c
 *-timestamp
 *-softmmu
 *-darwin-user
diff --git a/Makefile b/Makefile
index 1886317..5975926 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@ 
 # Makefile for QEMU.
 
-GENERATED_HEADERS = config-host.h trace.h
+GENERATED_HEADERS = config-host.h trace.h trace-helper.h trace-helper.c
 
 ifneq ($(wildcard config-host.mak),)
 # Put the all: rule here so that config-host.mak can contain dependencies.
@@ -118,6 +118,18 @@  trace.c-timestamp: $(SRC_PATH)/trace-events config-host.mak
 
 trace.o: trace.c $(GENERATED_HEADERS)
 
+trace-helper.h: trace-helper.h-timestamp
+trace-helper.h-timestamp: $(SRC_PATH)/trace-events config-host.mak
+	$(call quiet-command,sh $(SRC_PATH)/tracetool $(TRACETOOL_EXTRA) --helper --$(TRACE_BACKEND) -h < $< > $@,"  GEN   trace-helper.h")
+	@cmp -s $@ trace-helper.h || cp $@ trace-helper.h
+
+trace-helper.c: trace-helper.c-timestamp
+trace-helper.c-timestamp: $(SRC_PATH)/trace-events config-host.mak
+	$(call quiet-command,sh $(SRC_PATH)/tracetool $(TRACETOOL_EXTRA) --helper --$(TRACE_BACKEND) -c < $< > $@,"  GEN   trace-helper.c")
+	@cmp -s $@ trace-helper.c || cp $@ trace-helper.c
+
+trace-helper.o: trace-helper.c $(GENERATED_HEADERS)
+
 simpletrace.o: simpletrace.c $(GENERATED_HEADERS)
 
 version.o: $(SRC_PATH)/version.rc config-host.mak
@@ -154,6 +166,7 @@  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
 	rm -f qemu-img-cmds.h
 	rm -f trace.c trace.h trace.c-timestamp trace.h-timestamp
+	rm -f trace-helper.c trace-helper.h trace-helper.h-timestamp trace-helper.c-timestamp
 	$(MAKE) -C tests clean
 	for d in $(ALL_SUBDIRS) libhw32 libhw64 libuser libdis libdis-user; do \
 	if test -d $$d; then $(MAKE) -C $$d $@ || exit 1; fi; \
diff --git a/Makefile.target b/Makefile.target
index 90867e7..c7e26e2 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -378,9 +378,8 @@  endif
 
 $(QEMU_PROG)-prepare: $(GENERATED_HEADERS) $(LIBBACKDOOR_LIB) $(LIBINSTRUMENT_LIB) $(QEMU_PROG)
 
-$(QEMU_PROG): $(obj-y) $(obj-$(TARGET_BASE_ARCH)-y) $(LIBBACKDOOR_LIB) $(LIBINSTRUMENT_LIB)
-	$(call LINK,$(obj-y) $(obj-$(TARGET_BASE_ARCH)-y)) $(LIBBACKDOOR_LIB) $(LIBINSTRUMENT_LIB)
-
+$(QEMU_PROG): trace-helper.o $(obj-y) $(obj-$(TARGET_BASE_ARCH)-y) $(LIBBACKDOOR_LIB) $(LIBINSTRUMENT_LIB)
+	$(call LINK,trace-helper.o $(obj-y) $(obj-$(TARGET_BASE_ARCH)-y)) $(LIBBACKDOOR_LIB) $(LIBINSTRUMENT_LIB)
 
 gdbstub-xml.c: $(TARGET_XML_FILES) $(SRC_PATH)/feature_to_c.sh
 	$(call quiet-command,rm -f $@ && $(SHELL) $(SRC_PATH)/feature_to_c.sh $@ $(TARGET_XML_FILES),"  GEN   $(TARGET_DIR)$@")
diff --git a/trace-events b/trace-events
index 3b91a1c..4a89d97 100644
--- a/trace-events
+++ b/trace-events
@@ -38,6 +38,11 @@ 
 #   is identified by the '--with-instrument' configure option).
 #   The original backend-specific function is still available under the name
 #   'trace_##name##_backend'.
+#
+# - gen
+#   Provide trace events suitable for using during TCG code generation.
+#   Generates TCG function helpers reachable through 'helper_trace_gen_##name'
+#   which proxy their calls onto 'trace_##name'.
 
 # qemu-malloc.c
 disable qemu_malloc(size_t size, void *ptr) "size %zu ptr %p"
diff --git a/tracetool b/tracetool
index 3172259..588f442 100755
--- a/tracetool
+++ b/tracetool
@@ -234,6 +234,38 @@  native_type()
 ################################################################################
 ### Backend code
 
+### nil -- H
+begin_h_nil()
+{
+    return
+}
+
+line_h_nil()
+{
+    return
+}
+
+end_h_nil()
+{
+    return
+}
+
+### nil -- C
+begin_c_nil()
+{
+    return
+}
+
+line_c_nil()
+{
+    return
+}
+
+end_c_nil()
+{
+    return
+}
+
 ### nop -- H
 begin_h_nop()
 {
@@ -507,6 +539,69 @@  line_c_regular()
     return
 }
 
+### Helper -- H
+traceto_h_helper()
+{
+    echo "/* This file is autogenerated by tracetool, do not edit. */"
+    convert h $1 nil
+}
+
+helper_h_type()
+{
+    case "$1" in
+        "void *"|"TCGv_ptr")   echo "ptr";;
+        "uint32_t"|"TCGv_i64") echo "i32";;
+        "uint64_t"|"TCGv_i32") echo "i64";;
+        *)                     echo "i64";;
+    esac
+}
+
+line_h_helper()
+{
+    local gen
+    gen=$(get_property "$1" "gen")
+    [ "$gen" = "1" ] || return
+
+    local name argc argtypes
+    name=$(get_event_name "$1")
+    argc=$(get_argc "$1")
+    argtypes=$(get_argtypes "$1" helper_h_type)
+    echo "DEF_HELPER_$argc(trace_proxy_$name, void, $argtypes)"
+}
+
+### Helper -- C
+traceto_c_helper()
+{
+    cat <<EOF
+/* This file is autogenerated by tracetool, do not edit. */
+#include "trace.h"
+#include "helper.h"
+EOF
+    convert c $1 nil
+}
+
+line_c_helper()
+{
+    local gen
+    gen=$(get_property "$1" "gen")
+    [ "$gen" = "1" ] || return
+
+    local name api args argtypes_native argnames values
+    name=$(get_event_name "$1")
+    api=$(get_api_name "$1")
+    args=$(get_args "$1" native_type)
+    argtypes_native=$(get_argtypes "$1" native_type)
+    argnames=$(get_argnames "$1")
+    values=$(zip_lists "$argtypes_native" "$argnames" "(%s)%s")
+
+    cat <<EOF
+void helper_trace_proxy_$name($args)
+{
+    $api($values);
+}
+EOF
+}
+
 ################################################################################
 ### Generic code
 
@@ -551,6 +646,7 @@  Flags:
 
 Frontends:
   --regular     Regular frontend
+  --helper      Helper proxies
 
 Backends:
   --nop         Tracing disabled
@@ -567,7 +663,7 @@  EOF
 while [ $# -gt 0 ]; do
     case $1 in
         "--instrument") enable_instrument="1" ;;
-        "--regular") frontend="${1#--}" ;;
+        "--regular"|"--helper") frontend="${1#--}" ;;
         "--nop"|"--simple"|"--ust") backend="${1#--}" ;;
         "-h"|"-c") output="${1#-}" ;;
         "--check-backend") check=1 ;; # used by ./configure to test for backend