From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56358) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zm35z-0004cz-3t for qemu-devel@nongnu.org; Tue, 13 Oct 2015 13:10:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zm35w-0000cI-AS for qemu-devel@nongnu.org; Tue, 13 Oct 2015 13:10:39 -0400 Received: from roura.ac.upc.es ([147.83.33.10]:55442) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zm35v-0000cA-Mp for qemu-devel@nongnu.org; Tue, 13 Oct 2015 13:10:36 -0400 From: =?utf-8?b?TGx1w61z?= Vilanova Date: Tue, 13 Oct 2015 19:10:33 +0200 Message-Id: <20151013171032.21325.61781.stgit@localhost> In-Reply-To: <20151013171020.21325.27626.stgit@localhost> References: <20151013171020.21325.27626.stgit@localhost> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCHv12/8] trace: Add 'vcpu' event property List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , Stefan Hajnoczi This property identifies events that trace vCPU-specific information. It adds an implicit "CPUState*" argument that identifies the vCPU raising= this event. TCG translation events have an additional "TCGv_cpu" implicit argu= ment that is later used as the "CPUState*" argument at execution time. Signed-off-by: Llu=C3=ADs Vilanova --- docs/tracing.txt | 30 ++++++++++++++++++++++++= ++++++ scripts/tracetool/__init__.py | 24 ++++++++++++++++++++++-- scripts/tracetool/format/h.py | 4 +++- scripts/tracetool/format/tcg_h.py | 13 ++++++++++--- scripts/tracetool/format/ust_events_c.py | 4 +++- 5 files changed, 68 insertions(+), 7 deletions(-) diff --git a/docs/tracing.txt b/docs/tracing.txt index 7117c5e..f0dba3d 100644 --- a/docs/tracing.txt +++ b/docs/tracing.txt @@ -347,3 +347,33 @@ This will immediately call: and will generate the TCG code to call: =20 void trace_foo(uint8_t a1, uint32_t a2); + +=3D=3D=3D "vcpu" =3D=3D=3D + +Identifies events that trace vCPU-specific information. The property add= s a +"CPUState*" argument that identifies the vCPU raising the event. If used +together with the "tcg" property, it adds a second "TCGv_cpu" argument t= hat +identifies the vCPU when guest code is executed. + +The following example events: + + foo(uint32_t a) "a=3D%x" + vcpu bar(uint32_t a) "cpu=3D%p a=3D%x" + tcg vcpu baz(uint32_t a) "cpu=3D%p a=3D%x", "cpu=3D%p a=3D%x" + +Can be used as: + + #include "trace-tcg.h" + =20 + CPUArchState *env; + TCGv_ptr cpu_env; + =20 + void some_disassembly_func(...) + { + /* trace emitted at this point */ + trace_foo(0xcafe); + /* trace emitted at this point */ + trace_bar(ENV_GET_CPU(env), 0xcafe); + /* trace emitted at this point (env) and when guest code is exec= uted (cpu_env) */ + trace_baz_tcg(ENV_GET_CPU(env), cpu_env, 0xcafe); + } diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.p= y index 181675f..b75c66d 100644 --- a/scripts/tracetool/__init__.py +++ b/scripts/tracetool/__init__.py @@ -6,7 +6,7 @@ Machinery for generating tracing-related intermediate fil= es. """ =20 __author__ =3D "Llu=C3=ADs Vilanova " -__copyright__ =3D "Copyright 2012-2014, Llu=C3=ADs Vilanova " +__copyright__ =3D "Copyright 2012-2015, Llu=C3=ADs Vilanova " __license__ =3D "GPL version 2 or (at your option) any later version" =20 __maintainer__ =3D "Stefan Hajnoczi" @@ -146,7 +146,7 @@ class Event(object): "(?:(?:(?P\".+),)?\s*(?P\".+))?" "\s*") =20 - _VALID_PROPS =3D set(["disable", "tcg", "tcg-trans", "tcg-exec"]) + _VALID_PROPS =3D set(["disable", "tcg", "tcg-trans", "tcg-exec", "vc= pu"]) =20 def __init__(self, name, props, fmt, args, orig=3DNone): """ @@ -215,6 +215,19 @@ class Event(object): if "tcg" in props and isinstance(fmt, str): raise ValueError("Events with 'tcg' property must have two f= ormats") =20 + # add implicit arguments when using the 'vcpu' property + if "vcpu" in props: + assert "tcg-trans" not in props and "tcg-exec" not in props + # events with 'tcg-trans' and 'tcg-exec' are auto-generated,= they + # have already been transformed + if "tcg" in props: + types =3D ["TCGv_cpu"] + args.types() + names =3D ["_tcg_cpu"] + args.names() + else: + types =3D ["CPUState *"] + args.types() + names =3D ["_cpu"] + args.names() + args =3D Arguments(zip(types, names)) + return Event(name, props, fmt, args) =20 def __repr__(self): @@ -270,6 +283,7 @@ def _read_events(fobj): event_trans.name +=3D "_trans" event_trans.properties +=3D ["tcg-trans"] event_trans.fmt =3D event.fmt[0] + # ignore TCG arguments args_trans =3D [] for atrans, aorig in zip( event_trans.transform(tracetool.transform.TCG_2_HOST= ).args, @@ -279,6 +293,12 @@ def _read_events(fobj): event_trans.args =3D Arguments(args_trans) event_trans =3D event_trans.copy() =20 + # trace the vCPU performing the translation + if "vcpu" in event_trans.properties: + event_trans.args =3D Arguments(zip( + ["CPUState *"] + list(event_trans.args.types()), + ["_cpu"] + list(event_trans.args.names()))) + event_exec =3D event.copy() event_exec.name +=3D "_exec" event_exec.properties +=3D ["tcg-exec"] diff --git a/scripts/tracetool/format/h.py b/scripts/tracetool/format/h.p= y index 9b39430..4bdb48f 100644 --- a/scripts/tracetool/format/h.py +++ b/scripts/tracetool/format/h.py @@ -6,7 +6,7 @@ trace/generated-tracers.h """ =20 __author__ =3D "Llu=C3=ADs Vilanova " -__copyright__ =3D "Copyright 2012-2014, Llu=C3=ADs Vilanova " +__copyright__ =3D "Copyright 2012-2015, Llu=C3=ADs Vilanova " __license__ =3D "GPL version 2 or (at your option) any later version" =20 __maintainer__ =3D "Stefan Hajnoczi" @@ -23,6 +23,8 @@ def generate(events, backend): '#define TRACE__GENERATED_TRACERS_H', '', '#include "qemu-common.h"', + '', + 'typedef struct CPUState CPUState;', '') =20 backend.generate_begin(events) diff --git a/scripts/tracetool/format/tcg_h.py b/scripts/tracetool/format= /tcg_h.py index f676b66..222002c 100644 --- a/scripts/tracetool/format/tcg_h.py +++ b/scripts/tracetool/format/tcg_h.py @@ -6,14 +6,14 @@ Generate .h file for TCG code generation. """ =20 __author__ =3D "Llu=C3=ADs Vilanova " -__copyright__ =3D "Copyright 2012-2014, Llu=C3=ADs Vilanova " +__copyright__ =3D "Copyright 2012-2015, Llu=C3=ADs Vilanova " __license__ =3D "GPL version 2 or (at your option) any later version" =20 __maintainer__ =3D "Stefan Hajnoczi" __email__ =3D "stefanha@linux.vnet.ibm.com" =20 =20 -from tracetool import out +from tracetool import out, Arguments =20 =20 def generate(events, backend): @@ -38,10 +38,17 @@ def generate(events, backend): # get the original event definition e =3D e.original.original =20 + if "vcpu" in e.properties: + args_api =3D Arguments(zip( + ["CPUState *"] + e.args.types(), + ["_cpu"] + e.args.names())) + else: + args_api =3D e.args + out('static inline void %(name_tcg)s(%(args)s)', '{', name_tcg=3De.api(e.QEMU_TRACE_TCG), - args=3De.args) + args=3Dargs_api) =20 if "disable" not in e.properties: out(' %(name_trans)s(%(argnames_trans)s);', diff --git a/scripts/tracetool/format/ust_events_c.py b/scripts/tracetool= /format/ust_events_c.py index bc97093..92064f0 100644 --- a/scripts/tracetool/format/ust_events_c.py +++ b/scripts/tracetool/format/ust_events_c.py @@ -6,7 +6,7 @@ trace/generated-ust.c """ =20 __author__ =3D "Mohamad Gebai " -__copyright__ =3D "Copyright 2012, Mohamad Gebai " +__copyright__ =3D "Copyright 2012, 2015, Mohamad Gebai " __license__ =3D "GPL version 2 or (at your option) any later version" =20 __maintainer__ =3D "Stefan Hajnoczi" @@ -30,4 +30,6 @@ def generate(events, backend): ' */', '#pragma GCC diagnostic ignored "-Wredundant-decls"', '', + 'typedef struct CPUState CPUState;', + '', '#include "generated-ust-provider.h"')