diff mbox

[PATCHv12/8] trace: Add 'vcpu' event property

Message ID 20151013171032.21325.61781.stgit@localhost
State New
Headers show

Commit Message

Lluís Vilanova Oct. 13, 2015, 5:10 p.m. UTC
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 argument
that is later used as the "CPUState*" argument at execution time.

Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
---
 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(-)

Comments

Stefan Hajnoczi Oct. 16, 2015, 9:16 a.m. UTC | #1
On Tue, Oct 13, 2015 at 07:10:33PM +0200, Lluís Vilanova wrote:
> diff --git a/scripts/tracetool/format/h.py b/scripts/tracetool/format/h.py
> index 9b39430..4bdb48f 100644
> --- a/scripts/tracetool/format/h.py
> +++ b/scripts/tracetool/format/h.py
> @@ -6,7 +6,7 @@ trace/generated-tracers.h
>  """
>  
>  __author__     = "Lluís Vilanova <vilanova@ac.upc.edu>"
> -__copyright__  = "Copyright 2012-2014, Lluís Vilanova <vilanova@ac.upc.edu>"
> +__copyright__  = "Copyright 2012-2015, Lluís Vilanova <vilanova@ac.upc.edu>"
>  __license__    = "GPL version 2 or (at your option) any later version"
>  
>  __maintainer__ = "Stefan Hajnoczi"
> @@ -23,6 +23,8 @@ def generate(events, backend):
>          '#define TRACE__GENERATED_TRACERS_H',
>          '',
>          '#include "qemu-common.h"',
> +        '',
> +        'typedef struct CPUState CPUState;',

Here...

> 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
>  """
>  
>  __author__     = "Mohamad Gebai <mohamad.gebai@polymtl.ca>"
> -__copyright__  = "Copyright 2012, Mohamad Gebai <mohamad.gebai@polymtl.ca>"
> +__copyright__  = "Copyright 2012, 2015, Mohamad Gebai <mohamad.gebai@polymtl.ca>"
>  __license__    = "GPL version 2 or (at your option) any later version"
>  
>  __maintainer__ = "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"')

...and here is okay but please generate a comment so it's clear why this
needs to be defined.
Lluís Vilanova Oct. 16, 2015, 3:45 p.m. UTC | #2
Stefan Hajnoczi writes:

> On Tue, Oct 13, 2015 at 07:10:33PM +0200, Lluís Vilanova wrote:
>> diff --git a/scripts/tracetool/format/h.py b/scripts/tracetool/format/h.py
>> index 9b39430..4bdb48f 100644
>> --- a/scripts/tracetool/format/h.py
>> +++ b/scripts/tracetool/format/h.py
>> @@ -6,7 +6,7 @@ trace/generated-tracers.h
>> """
>> 
>> __author__     = "Lluís Vilanova <vilanova@ac.upc.edu>"
>> -__copyright__ = "Copyright 2012-2014, Lluís Vilanova <vilanova@ac.upc.edu>"
>> +__copyright__  = "Copyright 2012-2015, Lluís Vilanova <vilanova@ac.upc.edu>"
>> __license__    = "GPL version 2 or (at your option) any later version"
>> 
>> __maintainer__ = "Stefan Hajnoczi"
>> @@ -23,6 +23,8 @@ def generate(events, backend):
>> '#define TRACE__GENERATED_TRACERS_H',
>> '',
>> '#include "qemu-common.h"',
>> +        '',
>> +        'typedef struct CPUState CPUState;',

> Here...

>> 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
>> """
>> 
>> __author__     = "Mohamad Gebai <mohamad.gebai@polymtl.ca>"
>> -__copyright__  = "Copyright 2012, Mohamad Gebai <mohamad.gebai@polymtl.ca>"
>> +__copyright__  = "Copyright 2012, 2015, Mohamad Gebai <mohamad.gebai@polymtl.ca>"
>> __license__    = "GPL version 2 or (at your option) any later version"
>> 
>> __maintainer__ = "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"')

> ...and here is okay but please generate a comment so it's clear why this
> needs to be defined.

Will do.

Thanks,
  Lluis
diff mbox

Patch

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:
 
     void trace_foo(uint8_t a1, uint32_t a2);
+
+=== "vcpu" ===
+
+Identifies events that trace vCPU-specific information. The property adds a
+"CPUState*" argument that identifies the vCPU raising the event. If used
+together with the "tcg" property, it adds a second "TCGv_cpu" argument that
+identifies the vCPU when guest code is executed.
+
+The following example events:
+
+    foo(uint32_t a) "a=%x"
+    vcpu bar(uint32_t a) "cpu=%p a=%x"
+    tcg vcpu baz(uint32_t a) "cpu=%p a=%x", "cpu=%p a=%x"
+
+Can be used as:
+
+    #include "trace-tcg.h"
+    
+    CPUArchState *env;
+    TCGv_ptr cpu_env;
+    
+    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 executed (cpu_env) */
+        trace_baz_tcg(ENV_GET_CPU(env), cpu_env, 0xcafe);
+    }
diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py
index 181675f..b75c66d 100644
--- a/scripts/tracetool/__init__.py
+++ b/scripts/tracetool/__init__.py
@@ -6,7 +6,7 @@  Machinery for generating tracing-related intermediate files.
 """
 
 __author__     = "Lluís Vilanova <vilanova@ac.upc.edu>"
-__copyright__  = "Copyright 2012-2014, Lluís Vilanova <vilanova@ac.upc.edu>"
+__copyright__  = "Copyright 2012-2015, Lluís Vilanova <vilanova@ac.upc.edu>"
 __license__    = "GPL version 2 or (at your option) any later version"
 
 __maintainer__ = "Stefan Hajnoczi"
@@ -146,7 +146,7 @@  class Event(object):
                       "(?:(?:(?P<fmt_trans>\".+),)?\s*(?P<fmt>\".+))?"
                       "\s*")
 
-    _VALID_PROPS = set(["disable", "tcg", "tcg-trans", "tcg-exec"])
+    _VALID_PROPS = set(["disable", "tcg", "tcg-trans", "tcg-exec", "vcpu"])
 
     def __init__(self, name, props, fmt, args, orig=None):
         """
@@ -215,6 +215,19 @@  class Event(object):
         if "tcg" in props and isinstance(fmt, str):
             raise ValueError("Events with 'tcg' property must have two formats")
 
+        # 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 = ["TCGv_cpu"] + args.types()
+                names = ["_tcg_cpu"] + args.names()
+            else:
+                types = ["CPUState *"] + args.types()
+                names = ["_cpu"] + args.names()
+            args = Arguments(zip(types, names))
+
         return Event(name, props, fmt, args)
 
     def __repr__(self):
@@ -270,6 +283,7 @@  def _read_events(fobj):
             event_trans.name += "_trans"
             event_trans.properties += ["tcg-trans"]
             event_trans.fmt = event.fmt[0]
+            # ignore TCG arguments
             args_trans = []
             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 = Arguments(args_trans)
             event_trans = event_trans.copy()
 
+            # trace the vCPU performing the translation
+            if "vcpu" in event_trans.properties:
+                event_trans.args = Arguments(zip(
+                    ["CPUState *"] + list(event_trans.args.types()),
+                    ["_cpu"] + list(event_trans.args.names())))
+
             event_exec = event.copy()
             event_exec.name += "_exec"
             event_exec.properties += ["tcg-exec"]
diff --git a/scripts/tracetool/format/h.py b/scripts/tracetool/format/h.py
index 9b39430..4bdb48f 100644
--- a/scripts/tracetool/format/h.py
+++ b/scripts/tracetool/format/h.py
@@ -6,7 +6,7 @@  trace/generated-tracers.h
 """
 
 __author__     = "Lluís Vilanova <vilanova@ac.upc.edu>"
-__copyright__  = "Copyright 2012-2014, Lluís Vilanova <vilanova@ac.upc.edu>"
+__copyright__  = "Copyright 2012-2015, Lluís Vilanova <vilanova@ac.upc.edu>"
 __license__    = "GPL version 2 or (at your option) any later version"
 
 __maintainer__ = "Stefan Hajnoczi"
@@ -23,6 +23,8 @@  def generate(events, backend):
         '#define TRACE__GENERATED_TRACERS_H',
         '',
         '#include "qemu-common.h"',
+        '',
+        'typedef struct CPUState CPUState;',
         '')
 
     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.
 """
 
 __author__     = "Lluís Vilanova <vilanova@ac.upc.edu>"
-__copyright__  = "Copyright 2012-2014, Lluís Vilanova <vilanova@ac.upc.edu>"
+__copyright__  = "Copyright 2012-2015, Lluís Vilanova <vilanova@ac.upc.edu>"
 __license__    = "GPL version 2 or (at your option) any later version"
 
 __maintainer__ = "Stefan Hajnoczi"
 __email__      = "stefanha@linux.vnet.ibm.com"
 
 
-from tracetool import out
+from tracetool import out, Arguments
 
 
 def generate(events, backend):
@@ -38,10 +38,17 @@  def generate(events, backend):
         # get the original event definition
         e = e.original.original
 
+        if "vcpu" in e.properties:
+            args_api = Arguments(zip(
+                ["CPUState *"] + e.args.types(),
+                ["_cpu"] + e.args.names()))
+        else:
+            args_api = e.args
+
         out('static inline void %(name_tcg)s(%(args)s)',
             '{',
             name_tcg=e.api(e.QEMU_TRACE_TCG),
-            args=e.args)
+            args=args_api)
 
         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
 """
 
 __author__     = "Mohamad Gebai <mohamad.gebai@polymtl.ca>"
-__copyright__  = "Copyright 2012, Mohamad Gebai <mohamad.gebai@polymtl.ca>"
+__copyright__  = "Copyright 2012, 2015, Mohamad Gebai <mohamad.gebai@polymtl.ca>"
 __license__    = "GPL version 2 or (at your option) any later version"
 
 __maintainer__ = "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"')