Received: from eggs.gnu.org ([208.118.235.92]:34897) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UTzgQ-0007rZ-L6 for qemu-devel@nongnu.org; Sun, 21 Apr 2013 15:12:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UTzgO-0001kX-8S for qemu-devel@nongnu.org; Sun, 21 Apr 2013 15:12:18 -0400 Received: from roura.ac.upc.es ([147.83.33.10]:33185) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UTzgN-0001kN-RL for qemu-devel@nongnu.org; Sun, 21 Apr 2013 15:12:16 -0400 Received: from gw.ac.upc.edu (gw.ac.upc.es [147.83.30.3]) by roura.ac.upc.es (8.13.8/8.13.8) with ESMTP id r3LJCFEV001794 for ; Sun, 21 Apr 2013 21:12:15 +0200 Received: from localhost (unknown [84.88.51.85]) by gw.ac.upc.edu (Postfix) with ESMTP id 1B7646B01A4 for ; Sun, 21 Apr 2013 21:12:15 +0200 (CEST) From: =?utf-8?b?TGx1w61z?= Vilanova Date: Sun, 21 Apr 2013 21:12:14 +0200 Message-Id: <20130421191214.8947.46714.stgit@fimbulvetr.bsc.es> In-Reply-To: <20130421191129.8947.77964.stgit@fimbulvetr.bsc.es> References: <20130421191129.8947.77964.stgit@fimbulvetr.bsc.es> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v3 08/24] instrument: [static] Call statically linked user-provided routines List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Compiles a user-provided static library during QEMU compilation. This library must provide the implementation of the 'qi_event_*' routines. Signed-off-by: Llu=C3=ADs Vilanova --- 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 diff --git a/Makefile.target b/Makefile.target index 2f9675a..114fc39 100644 --- a/Makefile.target +++ b/Makefile.target @@ -149,6 +149,8 @@ include $(SRC_PATH)/Makefile.objs all-obj-y =3D $(obj-y) all-obj-y +=3D $(addprefix ../, $(common-obj-y)) =20 +all-obj-y +=3D $(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 diff --git a/configure b/configure index 2cddce4..0eafd5a 100755 --- a/configure +++ b/configure @@ -225,6 +225,7 @@ trace_events=3D`dirname $0`/trace-events trace_backend=3D"nop" trace_file=3D"trace" trace_instrument=3D"none" +trace_instrument_path=3D"" spice=3D"" rbd=3D"" smartcard_nss=3D"" @@ -649,6 +650,8 @@ for opt do ;; --with-trace-instrument=3D*) trace_instrument=3D"$optarg" ;; + --with-trace-instrument-path=3D*) trace_instrument_path=3D"$optarg" + ;; --enable-gprof) gprof=3D"yes" ;; --enable-gcov) gcov=3D"yes" @@ -1170,7 +1173,9 @@ echo " Available backends= :" $($python "$source_path"/s echo " --with-trace-file=3DNAME Full PATH,NAME of file to store trace= s" echo " Default:trace-" echo " --with-trace-instrument=3DTYPE" -echo " Trace instrumentation type (none; defau= lt: $trace_instrument)" +echo " Trace instrumentation type (none static= ; default: $trace_instrument)" +echo " --with-trace-instrument-path=3DPATH" +echo " Directory to build user-provided static= trace event instrumentation library" echo " --disable-spice disable spice" echo " --enable-spice enable spice" echo " --enable-rbd enable building the rados block device = (rbd)" @@ -3069,13 +3074,32 @@ fi ########################################## # Check instrumentation type case "$trace_instrument" in -none) ;; +none|static) ;; *) echo "Error: invalid trace instrumentation type: $trace_instrum= ent" exit 1 ;; esac =20 ########################################## +# check for a valid directory for static trace instrumentation +if test "$trace_instrument" =3D "static" -a -z "$trace_instrument_path";= then + echo "Error: must provide '--with-trace-instrument-path' when using = static trace instrumentation" + exit 1 +fi +if test "$trace_instrument" !=3D "static" -a -n "$trace_instrument_path"= ; then + echo "Error: cannot provide '--with-trace-instrument-path' when not = using static trace instrumentation" + exit 1 +fi +if test "$trace_instrument" =3D "static" -a ! -f "$trace_instrument_path= /Makefile"; then + echo + echo "Error: cannot make into '$trace_instrument_path'" + echo "Please choose a directory where I can run 'make'" + echo + exit 1 +fi +trace_instrument_path=3D`readlink -f "$trace_instrument_path"` + +########################################## # __sync_fetch_and_and requires at least -march=3Di486. Many toolchains # use i686 as default anyway, but for those that don't, an explicit # specification is necessary @@ -3452,6 +3476,9 @@ echo "Trace events $trace_events" echo "Trace backend $trace_backend" echo "Trace output file $trace_file-" echo "Trace instrument $trace_instrument" +if test -n "$trace_instrument_path"; then +echo "Static instrument $trace_instrument_path" +fi echo "spice support $spice ($spice_protocol_version/$spice_server_ve= rsion)" echo "rbd support $rbd" echo "xfsctl support $xfs" @@ -3888,6 +3915,13 @@ if test "$trace_instrument" =3D "none"; then else echo "CONFIG_TRACE_INSTRUMENT=3Dy" >> $config_host_mak fi +if test "$trace_instrument" =3D "static"; then + echo "#define QI_TYPE_CONFIG_STATIC 1" >> $config_qi + echo "CONFIG_TRACE_INSTRUMENT_STATIC=3Dy" >> $config_host_mak + echo "TRACE_INSTRUMENT_PATH=3D\"$trace_instrument_path\"" >> $config= _host_mak + echo "TRACETOOL_INSTR_STATIC=3D--instr-static-path \"\$(TRACE_INSTRU= MENT_PATH)\"" >> $config_host_mak + QEMU_CFLAGS=3D"-I\"$trace_instrument_path\" $QEMU_CFLAGS" +fi ########################################## =20 echo "TOOLS=3D$tools" >> $config_host_mak @@ -4150,6 +4184,10 @@ if [ "$TARGET_BASE_ARCH" =3D "" ]; then fi =20 symlink "$source_path/Makefile.target" "$target_dir/Makefile" +if test -n "$trace_instrument_path"; then + mkdir -p $target_dir/libtrace-instrument + symlink $trace_instrument_path/Makefile $target_dir/libtrace-instrum= ent/Makefile +fi =20 upper() { echo "$@"| LC_ALL=3DC tr '[a-z]' '[A-Z]' diff --git a/instrument/Makefile.objs b/instrument/Makefile.objs index 9c5d5dc..4102b59 100644 --- a/instrument/Makefile.objs +++ b/instrument/Makefile.objs @@ -8,9 +8,15 @@ $(obj)/generated-tracers.h-timestamp: $(TRACE_EVENTS) $(= BUILD_DIR)/config-host.m $(call quiet-command,$(TRACETOOL) \ --format=3Dqemu-h \ --backend=3D$(TRACE_INSTRUMENT_BACKEND) \ + $(TRACETOOL_INSTR_STATIC) \ < $< > $@," GEN $(patsubst %-timestamp,%,$@)") @cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp= ,%,$@) =20 +ifdef CONFIG_TRACE_INSTRUMENT_STATIC +# Rebuild to check for user headers +.PHONY: $(obj)/generated-tracers.h-timestamp +endif + =20 ###################################################################### # User interface @@ -20,5 +26,26 @@ $(obj)/qemu-instr/events.h-timestamp: $(TRACE_EVENTS) = $(BUILD_DIR)/config-host.m $(call quiet-command,$(TRACETOOL) \ --format=3Dapi-h \ --backend=3D$(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 =3D libtrace-instrument/libtrace-instrument.a + +.PHONY: force +force: + +_libinstrument_cflags =3D $(subst libtrace-instrument,.,$(subst libtrace= -instrument/,.,$(1))) +$(LIBTRACE_INSTRUMENT): QEMU_CFLAGS +=3D -I$(BUILD_DIR)/ +$(LIBTRACE_INSTRUMENT): VPATH =3D $(TRACE_INSTRUMENT_PATH) +$(LIBTRACE_INSTRUMENT): $(dir $(LIBTRACE_INSTRUMENT))/Makefile force + $(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C $(dir $@) \ + QEMU_CFLAGS=3D"$(call _libinstrument_cflags,$(QEMU_CFLAGS))" \ + TARGET_DIR=3D$(TARGET_DIR)$(dir $@)/ VPATH=3D$(VPATH) \ + SRC_PATH=3D$(SRC_PATH) V=3D"$(V)" $(notdir $@)) +endif diff --git a/scripts/tracetool.py b/scripts/tracetool.py index a79ec0f..52d2cf4 100755 --- a/scripts/tracetool.py +++ b/scripts/tracetool.py @@ -6,7 +6,7 @@ Command-line wrapper for the tracetool machinery. """ =20 __author__ =3D "Llu=C3=ADs Vilanova " -__copyright__ =3D "Copyright 2012, Llu=C3=ADs Vilanova " +__copyright__ =3D "Copyright 2012-2013, Llu=C3=ADs Vilanova " __license__ =3D "GPL version 2 or (at your option) any later version" =20 __maintainer__ =3D "Stefan Hajnoczi" @@ -48,7 +48,10 @@ Options: --target-type QEMU emulator target type ('system' or 'use= r'). --target-arch QEMU emulator target arch. --probe-prefix Prefix for dtrace probe names - (default: qemu--)= .\ + (default: qemu--). + --instr-static--path + Path to directory containing static instrum= entation + library.\ """ % { "script" : _SCRIPT, "backends" : backend_descr, @@ -67,6 +70,7 @@ def main(args): =20 long_opts =3D [ "backend=3D", "format=3D", "help", "list-backends",= "check-backend" ] long_opts +=3D [ "binary=3D", "target-type=3D", "target-arch=3D", "p= robe-prefix=3D" ] + long_opts +=3D [ "instr-static-path=3D" ] =20 try: opts, args =3D getopt.getopt(args[1:], "", long_opts) @@ -80,6 +84,7 @@ def main(args): target_type =3D None target_arch =3D None probe_prefix =3D None + instr_static_path =3D None for opt, arg in opts: if opt =3D=3D "--help": error_opt() @@ -104,6 +109,8 @@ def main(args): target_arch =3D arg elif opt =3D=3D '--probe-prefix': probe_prefix =3D arg + elif opt =3D=3D '--instr-static-path': + instr_static_path =3D arg =20 else: error_opt("unhandled option: %s" % opt) @@ -130,7 +137,8 @@ def main(args): =20 try: tracetool.generate(sys.stdin, arg_format, arg_backend, - binary =3D binary, probe_prefix =3D probe_pre= fix) + binary =3D binary, probe_prefix =3D probe_pre= fix, + instr_static_path =3D instr_static_path) except tracetool.TracetoolError, e: error_opt(str(e)) =20 diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.p= y index f849e39..5406a2b 100644 --- a/scripts/tracetool/__init__.py +++ b/scripts/tracetool/__init__.py @@ -180,6 +180,8 @@ class Event(object): QEMU_TRACE =3D "trace_%(name)s" QEMU_TRACE_BACKEND =3D "trace_%(name)s_backend" QI_TRACE_INSTRUMENT =3D "qi_event_%(name)s" + QI_TRACE_NOP =3D "qi_event_%(name)s_nop" + QI_TRACE_BACKEND =3D "qi_event_%(name)s_trace" =20 def api(self, fmt =3D None): if fmt is None: @@ -229,7 +231,8 @@ def try_import(mod_name, attr_name =3D None, attr_def= ault =3D None): =20 =20 def generate(fevents, format, backend, - binary =3D None, probe_prefix =3D None): + binary =3D None, probe_prefix =3D None, + instr_static_path =3D None): """Generate the output for the given (format, backend) pair. =20 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 =3D binary tracetool.backend.dtrace.PROBEPREFIX =3D probe_prefix =20 + import tracetool.backend.instr_static + tracetool.backend.instr_static.PATH =3D instr_static_path + events =3D _read_events(fevents) =20 if backend =3D=3D "nop": diff --git a/scripts/tracetool/backend/instr_static.py b/scripts/tracetoo= l/backend/instr_static.py new file mode 100644 index 0000000..b010596 --- /dev/null +++ b/scripts/tracetool/backend/instr_static.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +Static instrumentation proxy. +""" + +__author__ =3D "Llu=C3=ADs Vilanova " +__copyright__ =3D "Copyright 2012-2013, Llu=C3=ADs Vilanova " +__license__ =3D "GPL version 2 or (at your option) any later version" + +__maintainer__ =3D "Stefan Hajnoczi" +__email__ =3D "stefanha@linux.vnet.ibm.com" + + +import os + +from tracetool import out +import tracetool.format.qemu_h + + +PATH =3D None + +def _path(): + if PATH is None: + raise ValueError("you must set PATH") + return PATH + + +def qemu_h(events): + if _path() and os.path.exists(os.sep.join([_path(), "events-pre.h"])= ): + out('#include "events-pre.h"', + '', + ) + + out('#include "instrument/qemu-instr/events.h"', + '', + ) + tracetool.format.qemu_h.process_common(events) + + if _path() and os.path.exists(os.sep.join([_path(), "events-post.h"]= )): + out('#include "events-post.h"', + '', + ) + +def api_h(events): + out('#include "trace/generated-tracers.h"', + '', + ) + + for e in events: + if "instrument" not in e.properties: + continue + + out('#if defined(QI_EVENT_%(upper_name)s_INLINE)', + 'static', + '#endif', + 'void %(qi)s(%(args)s);', + '', + 'static inline void %(qi_nop)s(%(args)s)', + '{', + '}', + '', + 'static inline void %(qi_backend)s(%(args)s)', + '{', + ' %(qemu_backend)s(%(argnames)s);', + '}', + '', + qi =3D e.api(e.QI_TRACE_INSTRUMENT), + qi_nop =3D e.api(e.QI_TRACE_NOP), + qi_backend =3D e.api(e.QI_TRACE_BACKEND), + qemu_backend =3D e.api(e.QEMU_TRACE_BACKEND), + args =3D e.args, + argnames =3D ", ".join(e.args.names()), + upper_name =3D e.name.upper(), + )