From patchwork Fri Jan 29 16:29:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Llu=C3=ADs_Vilanova?= X-Patchwork-Id: 8164841 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id BEB979F9A0 for ; Fri, 29 Jan 2016 16:30:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DA9AD20154 for ; Fri, 29 Jan 2016 16:30:09 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C544F2010B for ; Fri, 29 Jan 2016 16:30:08 +0000 (UTC) Received: from localhost ([::1]:35139 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aPBvz-0006CY-TE for patchwork-qemu-devel@patchwork.kernel.org; Fri, 29 Jan 2016 11:30:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58761) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aPBvn-00067a-El for qemu-devel@nongnu.org; Fri, 29 Jan 2016 11:29:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aPBvk-0005aM-64 for qemu-devel@nongnu.org; Fri, 29 Jan 2016 11:29:55 -0500 Received: from roura.ac.upc.edu ([147.83.33.10]:33797 helo=roura.ac.upc.es) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aPBvj-0005aD-PV for qemu-devel@nongnu.org; Fri, 29 Jan 2016 11:29:52 -0500 Received: from gw-2.ac.upc.es (gw-2.ac.upc.es [147.83.30.8]) by roura.ac.upc.es (8.13.8/8.13.8) with ESMTP id u0TGToaB023398; Fri, 29 Jan 2016 17:29:50 +0100 Received: from localhost (unknown [84.88.51.85]) by gw-2.ac.upc.es (Postfix) with ESMTPSA id 7E95DA6; Fri, 29 Jan 2016 17:29:50 +0100 (CET) From: =?utf-8?b?TGx1w61z?= Vilanova To: qemu-devel@nongnu.org Date: Fri, 29 Jan 2016 17:29:50 +0100 Message-Id: <145408499001.24960.16314543684862819544.stgit@localhost> X-Mailer: git-send-email 2.7.0.rc3 In-Reply-To: <145408497756.24960.12454249118563529425.stgit@localhost> References: <145408497756.24960.12454249118563529425.stgit@localhost> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-MIME-Autoconverted: from 8bit to quoted-printable by roura.ac.upc.es id u0TGToaB023398 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 147.83.33.10 Cc: Stefan Hajnoczi , Eduardo Habkost , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH v5 2/2] trace: Add 'vcpu' event property to trace guest vCPU X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This property identifies events that trace vCPU-specific information. It adds a "CPUState*" argument to events with the property, identifying the vCPU raising the event. TCG translation events also have a "TCGv_cpu" implicit argument that is later used as the "CPUState*" argument at execution time. Signed-off-by: Lluís Vilanova --- docs/tracing.txt | 40 ++++++++++++++++++++++++++++++ scripts/tracetool/__init__.py | 24 +++++++++++++++++- scripts/tracetool/format/h.py | 3 ++ scripts/tracetool/format/tcg_h.py | 13 ++++++++-- scripts/tracetool/format/ust_events_c.py | 1 + 5 files changed, 75 insertions(+), 6 deletions(-) diff --git a/docs/tracing.txt b/docs/tracing.txt index 3853a6a..ade39e0 100644 --- a/docs/tracing.txt +++ b/docs/tracing.txt @@ -347,3 +347,43 @@ 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(0xd1); + /* trace emitted at this point */ + trace_bar(ENV_GET_CPU(env), 0xd2); + /* trace emitted at this point (env) and when guest code is executed (cpu_env) */ + trace_baz_tcg(ENV_GET_CPU(env), cpu_env, 0xd3); + } + +If we assume code is translated by the vCPU with address 0xc1 and executed by +the vCPU with address 0xc2, this would be an example output: + + // at guest code translation + foo a=0xd1 + bar cpu=0xc1 a=0xd2 + baz_trans cpu=0xc1 a=0xd3 + // at guest code execution + baz_exec cpu=0xc2 a=0xd3 diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py index 181675f..41feb23 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 " -__copyright__ = "Copyright 2012-2014, Lluís Vilanova " +__copyright__ = "Copyright 2012-2016, Lluís Vilanova " __license__ = "GPL version 2 or (at your option) any later version" __maintainer__ = "Stefan Hajnoczi" @@ -146,7 +146,7 @@ class Event(object): "(?:(?:(?P\".+),)?\s*(?P\".+))?" "\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..2bd68a2 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 " -__copyright__ = "Copyright 2012-2014, Lluís Vilanova " +__copyright__ = "Copyright 2012-2016, Lluís Vilanova " __license__ = "GPL version 2 or (at your option) any later version" __maintainer__ = "Stefan Hajnoczi" @@ -23,6 +23,7 @@ def generate(events, backend): '#define TRACE__GENERATED_TRACERS_H', '', '#include "qemu-common.h"', + '#include "qemu/typedefs.h"', '') backend.generate_begin(events) diff --git a/scripts/tracetool/format/tcg_h.py b/scripts/tracetool/format/tcg_h.py index f676b66..acaa963 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 " -__copyright__ = "Copyright 2012-2014, Lluís Vilanova " +__copyright__ = "Copyright 2012-2016, Lluís Vilanova " __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..ecb1f23 100644 --- a/scripts/tracetool/format/ust_events_c.py +++ b/scripts/tracetool/format/ust_events_c.py @@ -30,4 +30,5 @@ def generate(events, backend): ' */', '#pragma GCC diagnostic ignored "-Wredundant-decls"', '', + '#include "qemu/typedefs.h"', '#include "generated-ust-provider.h"')