trace: Per-vCPU tracing states
v2 cover trace: Per-vCPU tracing states
NOTE: This series completes the framework for guest code tracing. Next series
will add actual events.
Provides per-vCPU dynamic controls of the tracing state of events tied to a specific virtual CPU.
Events with the "vcpu" property are identified as being tied to a particular virtual CPU, like executing an instruction. The state of such events can be controlled idependently; this is specially useful to, for example, trace memory access events of a process executing on a specific virtual CPU.
This event property plays in combination with the "tcg" property to avoid generating a call to the execution-time event tracer when a vCPU is not actively tracing such event (i.e., avoids adding tracing overheads).
Virtual CPUs tracing the same set of events use the same physical translation cache, improving their reuse. The system has 2^N physical translation caches, where "N" is the number of TCG events with the "vcpu" property. Every vCPU has a bitmap with the states of these events, which can be controlled separately, and uses it to select its physical translation cache. At translation time, QEMU generates the code to trace an event at execution time only if the event is enabled.
Changes in v2
=============
* Rebase on 5522a84.
* Improve patch descriptions.
* Refactor code generation into a separate patch.
* Fix forward declarations (Stefan Hajnoczi & Eduardo Habkost).
* Fix "since" tags in QAPI interface (Eric Blake).
* Unify QAPI/QMP interface with an optional 'vcpu' argument (Eric Blake).
* Fix QMP+GTK header workaround (Stefan Hajnoczi).
---
Lluís Vilanova (10):
trace: Add support for vCPU pointers in trace events
trace: Add 'vcpu' event property
trace: [tcg] Identify events with the 'vcpu' property
exec: [tcg] Refactor flush of per-CPU virtual TB cache
exec: [ŧcg] Use multiple physical TB caches
exec: [tcg] Track which vCPU is performing translation and execution [trivial] Track when QEMU has finished initialization
disas: Remove unused macro '_'
trace: [tcg] Add per-vCPU tracing states for events with the 'vcpu' property
trace: [tcg] Generate TCG code to trace guest events on a per-vCPU basis
Makefile.objs | 3 - bsd-user/main.c | 1 cpu-exec.c | 17 +++ cputlb.c | 2 disas/i386.c | 2 docs/tracing.txt | 40 ++++++++ include/disas/bfd.h | 1 include/exec/exec-all.h | 16 +++ include/qemu-common.h | 3 + include/qemu/typedefs.h | 1 include/qom/cpu.h | 10 ++ linux-user/main.c | 1 monitor.c | 4 - qapi/trace.json | 16 ++- qemu-common.c | 14 +++ qmp-commands.hx | 17 +++ qom/cpu.c | 21 ++++ scripts/tracetool/__init__.py | 24 ++++- scripts/tracetool/format/events_c.py | 11 ++ scripts/tracetool/format/events_h.py | 14 ++- scripts/tracetool/format/h.py | 4 + scripts/tracetool/format/tcg_h.py | 21 +++- scripts/tracetool/format/tcg_helper_c.py | 11 ++ scripts/tracetool/format/ust_events_c.py | 3 - scripts/tracetool/transform.py | 9 ++ stubs/Makefile.objs | 1 stubs/qemu-common-stub.c | 21 ++++ target-alpha/translate.c | 3 - target-arm/translate.c | 3 - target-arm/translate.h | 2 target-cris/translate.c | 3 - target-cris/translate_v10.c | 1 target-i386/translate.c | 3 - target-lm32/translate.c | 3 - target-m68k/translate.c | 3 - target-microblaze/translate.c | 3 - target-mips/translate.c | 3 - target-moxie/translate.c | 3 - target-openrisc/translate.c | 3 - target-ppc/translate.c | 3 - target-s390x/translate.c | 3 - target-sh4/translate.c | 3 - target-sparc/translate.c | 6 + target-tilegx/translate.c | 3 - target-tricore/translate.c | 3 - target-unicore32/translate.c | 3 - target-xtensa/translate.c | 3 - tcg/tcg-op.h | 2 tcg/tcg.h | 10 ++ trace/Makefile.objs | 2 trace/control-internal.h | 21 +++- trace/control-stub.c | 29 ++++++ trace/control-target.c | 69 +++++++++++++ trace/control.h | 64 ++++++++++++ trace/event-internal.h | 6 + trace/qmp.c | 139 ++++++++++++++++++++++----- translate-all.c | 156 ++++++++++++++++++++++++++---- translate-all.h | 49 +++++++++ vl.c | 2 59 files changed, 788 insertions(+), 109 deletions(-) create mode 100644 qemu-common.c create mode 100644 stubs/qemu-common-stub.c create mode 100644 trace/control-stub.c create mode 100644 trace/control-target.c
To: [email protected]
Cc: Stefan Hajnoczi <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: Eric Blake <[email protected]>
PATCH v2 1/10 trace: Add support for vCPU pointers in trace events
The tracing infrastructure later needs to differentiate between regular pointers and pointers to vCPUs.
Also changes all targets to use the new 'TCGv_cpu' type instead of the generic 'TCGv_ptr'. As of now, the change is merely cosmetic ('TCGv_cpu' translates into 'TCGv_ptr'), but that could change in the future to enforce the difference.
--- include/qemu/typedefs.h | 1 + scripts/tracetool/transform.py | 9 ++++++++- target-alpha/translate.c | 2 +- target-arm/translate.c | 2 +- target-arm/translate.h | 2 +- target-cris/translate.c | 2 +- target-i386/translate.c | 2 +- target-lm32/translate.c | 2 +- target-m68k/translate.c | 2 +- target-microblaze/translate.c | 2 +- target-mips/translate.c | 2 +- target-moxie/translate.c | 2 +- target-openrisc/translate.c | 2 +- target-ppc/translate.c | 2 +- target-s390x/translate.c | 2 +- target-sh4/translate.c | 2 +- target-sparc/translate.c | 5 +++-- target-tilegx/translate.c | 2 +- target-tricore/translate.c | 2 +- target-unicore32/translate.c | 2 +- target-xtensa/translate.c | 2 +- tcg/tcg-op.h | 2 -- tcg/tcg.h | 6 ++++++ trace/control.h | 3 ++- 24 files changed, 38 insertions(+), 24 deletions(-)
include/qemu/typedefs.h +1 -0
@@ -19,6 +19,7 @@ typedef struct BusState BusState;typedef struct CharDriverState CharDriverState ;typedef struct CompatProperty CompatProperty ;typedef struct CPUAddressSpace CPUAddressSpace ; +typedef struct CPUState CPUState ;typedef struct DeviceState DeviceState ;typedef struct DeviceListener DeviceListener ;typedef struct DisplayChangeListener DisplayChangeListener ;
scripts/tracetool/transform.py +8 -1
@@ -6,7 +6,7 @@ Type-transformation rules. """ __author__ = "Lluís Vilanova <[email protected]>" -__copyright__ = "Copyright 2012-2014, Lluís Vilanova <[email protected]>" +__copyright__ = "Copyright 2012-2015, Lluís Vilanova <[email protected]>" __license__ = "GPL version 2 or (at your option) any later version" __maintainer__ = "Stefan Hajnoczi"
@@ -74,6 +74,7 @@ TCG_2_HOST = { "TCGv_i32": "uint32_t", "TCGv_i64": "uint64_t", "TCGv_ptr": "void *", + "TCGv_cpu": "CPUState *", None: _tcg_2_host, }
@@ -98,6 +99,7 @@ HOST_2_TCG = { "uint32_t": "TCGv_i32", "uint64_t": "TCGv_i64", "void *" : "TCGv_ptr", + "CPUState *": "TCGv_cpu", None: _host_2_tcg, }
@@ -115,6 +117,8 @@ TCG_2_TCG_HELPER_DEF = { "TCGv_i32": "uint32_t", "TCGv_i64": "uint64_t", "TCGv_ptr": "void *", + "TCGv_cpu": "void *", + "CPUState *": "void *", None: _tcg_2_helper_def, }
@@ -130,6 +134,7 @@ TCG_2_TCG_HELPER_DECL = { "TCGv_ptr": "ptr", "TCGv_i32": "i32", "TCGv_i64": "i64", + "TCGv_cpu": "ptr", None: _tcg_2_tcg_helper_decl_error, }
@@ -146,6 +151,7 @@ HOST_2_TCG_TMP_NEW = { "uint32_t": "tcg_const_i32", "uint64_t": "tcg_const_i64", "void *" : "tcg_const_ptr", + "CPUState *": "tcg_const_ptr", None: _host_2_tcg_tmp_new, }
@@ -162,5 +168,6 @@ HOST_2_TCG_TMP_FREE = { "uint32_t": "tcg_temp_free_i32", "uint64_t": "tcg_temp_free_i64", "void *" : "tcg_temp_free_ptr", + "CPUState *": "tcg_temp_free_ptr", None: _host_2_tcg_tmp_free, }
target-alpha/translate.c +1 -1
@@ -91,7 +91,7 @@ typedef enum { } ExitStatus;/* global register indexes */ -static TCGv_ptr cpu_env; +static TCGv_cpu cpu_env;static TCGv cpu_std_ir[31 ];static TCGv cpu_fir[31 ];static TCGv cpu_pc;
target-arm/translate.c +1 -1
@@ -59,7 +59,7 @@#define IS_USER (s) (s->user)#endif -TCGv_ptr cpu_env; +TCGv_cpu cpu_env;/* We reuse the same 64-bit temporaries for efficiency. */ static TCGv_i64 cpu_V0, cpu_V1, cpu_M0;static TCGv_i32 cpu_R[16 ];
target-arm/translate.h +1 -1
@@ -70,7 +70,7 @@ typedef struct DisasCompare { } DisasCompare;/* Share the TCG temporaries common between 32 and 64 bit modes. */ -extern TCGv_ptr cpu_env; +extern TCGv_cpu cpu_env;extern TCGv_i32 cpu_NF, cpu_ZF, cpu_CF, cpu_VF;extern TCGv_i64 cpu_exclusive_addr;extern TCGv_i64 cpu_exclusive_val;
target-cris/translate.c +1 -1
@@ -58,7 +58,7 @@#define CC_MASK_NZVC 0xf#define CC_MASK_RNZV 0x10e -static TCGv_ptr cpu_env; +static TCGv_cpu cpu_env;static TCGv cpu_R[16 ];static TCGv cpu_PR[16 ];static TCGv cc_x;
target-i386/translate.c +1 -1
@@ -62,7 +62,7 @@//#define MACRO_TEST 1 /* global register indexes */ -static TCGv_ptr cpu_env; +static TCGv_cpu cpu_env;static TCGv cpu_A0;static TCGv cpu_cc_dst, cpu_cc_src, cpu_cc_src2, cpu_cc_srcT;static TCGv_i32 cpu_cc_op;
target-lm32/translate.c +1 -1
@@ -42,7 +42,7 @@#define MEM_INDEX 0 -static TCGv_ptr cpu_env; +static TCGv_cpu cpu_env;static TCGv cpu_R[32 ];static TCGv cpu_pc;static TCGv cpu_ie;
target-m68k/translate.c +1 -1
@@ -48,7 +48,7 @@static TCGv_i32 cpu_halted;static TCGv_i32 cpu_exception_index; -static TCGv_ptr cpu_env; +static TCGv_cpu cpu_env;static char cpu_reg_names[3 *8 *3 +5 *4 ];static TCGv cpu_dregs[8 ];
target-microblaze/translate.c +1 -1
@@ -44,7 +44,7 @@ (((src) >> start) & ((1 << (end - start + 1)) - 1))static TCGv env_debug; -static TCGv_ptr cpu_env; +static TCGv_cpu cpu_env;static TCGv cpu_R[32 ];static TCGv cpu_SR[18 ];static TCGv env_imm;
target-mips/translate.c +1 -1
@@ -1351,7 +1351,7 @@ enum { };/* global register indices */ -static TCGv_ptr cpu_env; +static TCGv_cpu cpu_env;static TCGv cpu_gpr[32 ], cpu_PC;static TCGv cpu_HI[MIPS_DSP_ACC ], cpu_LO[MIPS_DSP_ACC ];static TCGv cpu_dspctrl, btarget, bcond;
target-moxie/translate.c +1 -1
@@ -59,7 +59,7 @@ enum {static TCGv cpu_pc;static TCGv cpu_gregs[16 ]; -static TCGv_ptr cpu_env; +static TCGv_cpu cpu_env;static TCGv cc_a, cc_b;#include "exec/gen-icount.h"
target-openrisc/translate.c +1 -1
@@ -52,7 +52,7 @@ typedef struct DisasContext {uint32_t delayed_branch; } DisasContext; -static TCGv_ptr cpu_env; +static TCGv_cpu cpu_env;static TCGv cpu_sr;static TCGv cpu_R[32 ];static TCGv cpu_pc;
target-ppc/translate.c +1 -1
@@ -47,7 +47,7 @@/* Code translation helpers */ /* global register indexes */ -static TCGv_ptr cpu_env; +static TCGv_cpu cpu_env;static char cpu_reg_names[10 *3 +22 *4 /* GPR */ +10 *4 +22 *5 /* SPE GPRh */ + 10*4 + 22*5 /* FPR */
target-s390x/translate.c +1 -1
@@ -36,7 +36,7 @@#include "exec/cpu_ldst.h" /* global register indexes */ -static TCGv_ptr cpu_env; +static TCGv_cpu cpu_env;#include "exec/gen-icount.h" #include "exec/helper-proto.h"
target-sh4/translate.c +1 -1
@@ -59,7 +59,7 @@ enum { };/* global register indexes */ -static TCGv_ptr cpu_env; +static TCGv_cpu cpu_env;static TCGv cpu_gregs[24 ];static TCGv cpu_sr, cpu_sr_m, cpu_sr_q, cpu_sr_t;static TCGv cpu_pc, cpu_ssr, cpu_spc, cpu_gbr;
target-sparc/translate.c +3 -2
@@ -42,7 +42,8 @@according to jump_pc[T2] */ /* global register indexes */ -static TCGv_ptr cpu_env, cpu_regwptr; +static TCGv_cpu cpu_env; +static TCGv_ptr cpu_regwptr;static TCGv cpu_cc_src, cpu_cc_src2, cpu_cc_dst;static TCGv_i32 cpu_cc_op;static TCGv_i32 cpu_psr;
@@ -2294,7 +2295,7 @@ static void gen_fmovq(DisasContext *dc, DisasCompare *cmp, int rd, int rs) }#ifndef CONFIG_USER_ONLY -static inline void gen_load_trap_state_at_tl (TCGv_ptr r_tsptr,TCGv_ptr cpu_env) +static inline void gen_load_trap_state_at_tl (TCGv_ptr r_tsptr,TCGv_cpu cpu_env) {TCGv_i32 r_tl =tcg_temp_new_i32 ();
target-tilegx/translate.c +1 -1
@@ -30,7 +30,7 @@#define FMT64X "%016" PRIx64 -static TCGv_ptr cpu_env; +static TCGv_cpu cpu_env;static TCGv cpu_pc;static TCGv cpu_regs[TILEGX_R_COUNT ];
target-tricore/translate.c +1 -1
@@ -45,7 +45,7 @@ static TCGv cpu_PSW_SV;static TCGv cpu_PSW_AV;static TCGv cpu_PSW_SAV;/* CPU env */ -static TCGv_ptr cpu_env; +static TCGv_cpu cpu_env;#include "exec/gen-icount.h"
target-unicore32/translate.c +1 -1
@@ -51,7 +51,7 @@ typedef struct DisasContext {conditional executions state has been updated. */ #define DISAS_SYSCALL 5 -static TCGv_ptr cpu_env; +static TCGv_cpu cpu_env;static TCGv_i32 cpu_R[32 ];/* FIXME: These should be removed. */
target-xtensa/translate.c +1 -1
@@ -73,7 +73,7 @@ typedef struct DisasContext {unsigned cpenable; } DisasContext; -static TCGv_ptr cpu_env; +static TCGv_cpu cpu_env;static TCGv_i32 cpu_pc;static TCGv_i32 cpu_R[16 ];static TCGv_i32 cpu_FR[16 ];
tcg/tcg-op.h +0 -2
@@ -756,7 +756,6 @@ static inline void tcg_gen_exit_tb(uintptr_t val)void tcg_gen_goto_tb (unsigned idx);#if TARGET_LONG_BITS ==32 -#define TCGv TCGv_i32#define tcg_temp_new () tcg_temp_new_i32()#define tcg_global_reg_new tcg_global_reg_new_i32#define tcg_global_mem_new tcg_global_mem_new_i32
@@ -768,7 +767,6 @@ void tcg_gen_goto_tb(unsigned idx);#define tcg_gen_qemu_ld_tl tcg_gen_qemu_ld_i32#define tcg_gen_qemu_st_tl tcg_gen_qemu_st_i32#else -#define TCGv TCGv_i64#define tcg_temp_new () tcg_temp_new_i64()#define tcg_global_reg_new tcg_global_reg_new_i64#define tcg_global_mem_new tcg_global_mem_new_i64
tcg/tcg.h +6 -0
@@ -308,6 +308,12 @@ typedef tcg_target_ulong TCGArg;typedef struct TCGv_i32_d *TCGv_i32 ;typedef struct TCGv_i64_d *TCGv_i64 ;typedef struct TCGv_ptr_d *TCGv_ptr ; +typedef TCGv_ptr TCGv_cpu ; +#if TARGET_LONG_BITS ==32 +typedef TCGv_i32 TCGv ; +#else /* TARGET_LONG_BITS == 64 */ +typedef TCGv_i64 TCGv ; +#endif static inline TCGv_i32 QEMU_ARTIFICIAL MAKE_TCGV_I32(intptr_t i) {
trace/control.h +2 -1
@@ -1,7 +1,7 @@/* * Interface for configuring and controlling the state of tracing events. * -* Copyright (C) 2011-2014 Lluís Vilanova <[email protected]> +* Copyright (C) 2011-2015 Lluís Vilanova <[email protected]> * * This work is licensed under the terms of the GNU GPL, version 2 or later. * See the COPYING file in the top-level directory.
@@ -11,6 +11,7 @@#define TRACE__CONTROL_H #include "qemu-common.h" +#include "qemu/typedefs.h" #include "trace/generated-events.h"
PATCH v2 2/10 trace: Add 'vcpu' event property
In reply to Lluís VilanovaThis 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.
--- 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 | 3 ++ 5 files changed, 76 insertions(+), 7 deletions(-)
docs/tracing.txt +40 -0
@@ -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
scripts/tracetool/__init__.py +22 -2
@@ -6,7 +6,7 @@ Machinery for generating tracing-related intermediate files. """ __author__ = "Lluís Vilanova <[email protected]>" -__copyright__ = "Copyright 2012-2014, Lluís Vilanova <[email protected]>" +__copyright__ = "Copyright 2012-2015, Lluís Vilanova <[email protected]>" __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"]
scripts/tracetool/format/h.py +2 -1
@@ -6,7 +6,7 @@ trace/generated-tracers.h """ __author__ = "Lluís Vilanova <[email protected]>" -__copyright__ = "Copyright 2012-2014, Lluís Vilanova <[email protected]>" +__copyright__ = "Copyright 2012-2015, Lluís Vilanova <[email protected]>" __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)
scripts/tracetool/format/tcg_h.py +10 -3
@@ -6,14 +6,14 @@ Generate .h file for TCG code generation. """ __author__ = "Lluís Vilanova <[email protected]>" -__copyright__ = "Copyright 2012-2014, Lluís Vilanova <[email protected]>" +__copyright__ = "Copyright 2012-2015, Lluís Vilanova <[email protected]>" __license__ = "GPL version 2 or (at your option) any later version" __maintainer__ = "Stefan Hajnoczi" __email__ = "[email protected]" -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);',
scripts/tracetool/format/ust_events_c.py +2 -1
@@ -6,7 +6,7 @@ trace/generated-ust.c """ __author__ = "Mohamad Gebai <[email protected]>" -__copyright__ = "Copyright 2012, Mohamad Gebai <[email protected]>" +__copyright__ = "Copyright 2012, 2015, Mohamad Gebai <[email protected]>" __license__ = "GPL version 2 or (at your option) any later version" __maintainer__ = "Stefan Hajnoczi"
@@ -30,4 +30,5 @@ def generate(events, backend): ' */', '#pragma GCC diagnostic ignored "-Wredundant-decls"', '', + '#include "qemu/typedefs.h"', '#include "generated-ust-provider.h"')
PATCH v2 3/10 trace: [tcg] Identify events with the 'vcpu' property
In reply to Lluís VilanovaA separate ID space ('TRACE_CPU_*') is used in attribute 'cpu_id' that only contains events with the 'vcpu' property.
These are later used to select the appropriate physical TB cache based on what events are active.
--- qapi/trace.json | 5 +++-- scripts/tracetool/format/events_c.py | 11 +++++++++-- scripts/tracetool/format/events_h.py | 14 ++++++++++++-- trace/control-internal.h | 8 +++++++- trace/control.h | 7 +++++++ trace/event-internal.h | 4 +++- trace/qmp.c | 3 ++- 7 files changed, 43 insertions(+), 9 deletions(-)
qapi/trace.json +3 -2
@@ -1,6 +1,6 @@ # -*- mode: python -*- # -# Copyright (C) 2011-2014 Lluís Vilanova <[email protected]> +# Copyright (C) 2011-2015 Lluís Vilanova <[email protected]> # # This work is licensed under the terms of the GNU GPL, version 2 or later. # See the COPYING file in the top-level directory.
@@ -29,11 +29,12 @@ # # @name: Event name. # @state: Tracing state. +# @vcpu: Whether this is a per-vCPU event (since 2.5). # # Since 2.2 ## { 'struct': 'TraceEventInfo', - 'data': {'name': 'str', 'state': 'TraceEventState'} } + 'data': {'name': 'str', 'state': 'TraceEventState', 'vcpu': 'bool'} } ## # @trace-event-get-state:
scripts/tracetool/format/events_c.py +9 -2
@@ -6,7 +6,7 @@ trace/generated-events.c """ __author__ = "Lluís Vilanova <[email protected]>" -__copyright__ = "Copyright 2012-2014, Lluís Vilanova <[email protected]>" +__copyright__ = "Copyright 2012-2015, Lluís Vilanova <[email protected]>" __license__ = "GPL version 2 or (at your option) any later version" __maintainer__ = "Stefan Hajnoczi"
@@ -27,8 +27,15 @@ def generate(events, backend): out('TraceEvent trace_events[TRACE_EVENT_COUNT] = {') for e in events: - out(' { .id = %(id)s, .name = \"%(name)s\", .sstate = %(sstate)s, .dstate = 0 },', + if "vcpu" in e.properties and "tcg-exec" in e.properties: + vcpu_id = "TRACE_CPU_" + e.name.upper() + else: + vcpu_id = "TRACE_CPU_EVENT_COUNT" + out(' { .id = %(id)s, .cpu_id = %(vcpu_id)s,' + ' .name = \"%(name)s\",' + ' .sstate = %(sstate)s, .dstate = 0 },', id = "TRACE_" + e.name.upper(), + vcpu_id = vcpu_id, name = e.name, sstate = "TRACE_%s_ENABLED" % e.name.upper())
scripts/tracetool/format/events_h.py +12 -2
@@ -6,7 +6,7 @@ trace/generated-events.h """ __author__ = "Lluís Vilanova <[email protected]>" -__copyright__ = "Copyright 2012-2014, Lluís Vilanova <[email protected]>" +__copyright__ = "Copyright 2012-2015, Lluís Vilanova <[email protected]>" __license__ = "GPL version 2 or (at your option) any later version" __maintainer__ = "Stefan Hajnoczi"
@@ -34,13 +34,23 @@ def generate(events, backend): out(' TRACE_EVENT_COUNT', '} TraceEventID;') + # per-vCPU event identifiers + out('typedef enum {') + + for e in events: + if "vcpu" in e.properties and "tcg-exec" in e.properties: + out(' TRACE_CPU_%s,' % e.name.upper()) + + out(' TRACE_CPU_EVENT_COUNT', + '} TraceEventCPUID;') + # static state for e in events: if 'disable' in e.properties: enabled = 0 else: enabled = 1 - if "tcg-trans" in e.properties: + if "tcg-exec" in e.properties: # a single define for the two "sub-events" out('#define TRACE_%(name)s_ENABLED %(enabled)d', name=e.original.original.name.upper(),
trace/control-internal.h +7 -1
@@ -1,7 +1,7 @@/* * Interface for configuring and controlling the state of tracing events. * -* Copyright (C) 2011-2014 Lluís Vilanova <[email protected]> +* Copyright (C) 2011-2015 Lluís Vilanova <[email protected]> * * This work is licensed under the terms of the GNU GPL, version 2 or later. * See the COPYING file in the top-level directory.
@@ -39,6 +39,12 @@ static inline TraceEventID trace_event_get_id(TraceEvent *ev)return ev->id; } +static inline TraceEventCPUID trace_event_get_cpu_id (TraceEvent *ev) +{ +assert (ev !=NULL ); +return ev->cpu_id; +} +static inline const char *trace_event_get_name (TraceEvent *ev) {assert (ev !=NULL );
trace/control.h +7 -0
@@ -87,6 +87,13 @@ static TraceEventID trace_event_count(void);static TraceEventID trace_event_get_id (TraceEvent *ev);/** +* trace_event_get_cpu_id: +* +* Get the per-vCPU identifier of an event. +*/ +static TraceEventCPUID trace_event_get_cpu_id (TraceEvent *ev); + +/** * trace_event_get_name: * * Get the name of an event.
trace/event-internal.h +3 -1
@@ -1,7 +1,7 @@/* * Interface for configuring and controlling the state of tracing events. * -* Copyright (C) 2012 Lluís Vilanova <[email protected]> +* Copyright (C) 2012-2015 Lluís Vilanova <[email protected]> * * This work is licensed under the terms of the GNU GPL, version 2 or later. * See the COPYING file in the top-level directory.
@@ -16,6 +16,7 @@/** * TraceEvent: * @id: Unique event identifier. +* @cpu_id: Unique per-vCPU event identifier. * @name: Event name. * @sstate: Static tracing state. * @dstate: Dynamic tracing state.
@@ -24,6 +25,7 @@*/ typedef struct TraceEvent { TraceEventID id; + TraceEventCPUID cpu_id; const char * name; const bool sstate; bool dstate;
trace/qmp.c +2 -1
@@ -1,7 +1,7 @@/* * QMP commands for tracing events. * -* Copyright (C) 2014 Lluís Vilanova <[email protected]> +* Copyright (C) 2014-2015 Lluís Vilanova <[email protected]> * * This work is licensed under the terms of the GNU GPL, version 2 or later. * See the COPYING file in the top-level directory.
@@ -22,6 +22,7 @@ TraceEventInfoList *qmp_trace_event_get_state(const char *name, Error **errp)while ((ev =trace_event_pattern (name, ev)) !=NULL ) {TraceEventInfoList *elem =g_new (TraceEventInfoList,1 ); elem->value =g_new (TraceEventInfo,1 ); + elem->value->vcpu =trace_event_get_cpu_id (ev) !=TRACE_CPU_EVENT_COUNT ; elem->value->name =g_strdup (trace_event_get_name (ev));if (!trace_event_get_state_static (ev)) { elem->value->state =TRACE_EVENT_STATE_UNAVAILABLE ;
Re: [Qemu-devel] [PATCH v2 03/10] trace: [tcg] Identify events with the 'vcpu' property
Quoted 19 lines · Lluís Vilanova
A separate ID space ('TRACE_CPU_*') is used in attribute '
cpu_id' that only contains events with the 'vcpu' property.These are later used to select the appropriate physical TB cache based on what events are active.
Signed-off-by Lluís Vilanova <[email protected]>---
+++
b/qapi/trace.jsonqapi/trace.json +1
-1@@ -1,6 +1,6 @@ # -*- mode: python -*- # -# Copyright (C) 2011-2014 Lluís Vilanova <[email protected]> +# Copyright (C) 2011-2015 Lluís Vilanova <[email protected]> # # This work is licensed under the terms of the GNU GPL, version 2 or later. # See the COPYING file in the top-level directory.
qapi/trace.json line 32
Quoted 4 lines
qapi/trace.json +1
-0@@ -29,11 +29,12 @@ # # @name: Event name. # @state: Tracing state. +# @vcpu: Whether this is a per-vCPU event (since 2.5).
You've missed 2.5 hard freeze; this will need to be 2.6.
Also, I note that patch 9/10 touches the same line again to make it optional; why not just have it be optional in the beginning, to reduce churn within the series?
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH v2 4/10 exec: [tcg] Refactor flush of per-CPU virtual TB cache
In reply to Lluís VilanovaThe function is reused in later patches.
--- cputlb.c | 2 +- include/exec/exec-all.h | 6 ++++++ translate-all.c | 7 ++++++- 3 files changed, 13 insertions(+), 2 deletions(-)
cputlb.c +1 -1
@@ -61,7 +61,7 @@ void tlb_flush(CPUState *cpu, int flush_global)memset (env->tlb_table,-1 ,sizeof (env->tlb_table));memset (env->tlb_v_table,-1 ,sizeof (env->tlb_v_table)); -memset (cpu->tb_jmp_cache,0 ,sizeof (cpu->tb_jmp_cache)); +tb_flush_jmp_cache_all (cpu); env->vtlb_index =0 ; env->tlb_flush_addr =-1 ;
include/exec/exec-all.h +6 -0
@@ -238,6 +238,12 @@ struct TBContext { };void tb_free (TranslationBlock *tb); +/** +* tb_flush_jmp_cache_all: +* +* Flush the virtual translation block cache. +*/ +void tb_flush_jmp_cache_all (CPUState *env);void tb_flush (CPUState *cpu);void tb_phys_invalidate (TranslationBlock *tb,tb_page_addr_t page_addr);
translate-all.c +6 -1
@@ -846,7 +846,7 @@ void tb_flush(CPUState *cpu) tcg_ctx.tb_ctx.nb_tbs =0 ;CPU_FOREACH (cpu) { -memset (cpu->tb_jmp_cache,0 ,sizeof (cpu->tb_jmp_cache)); +tb_flush_jmp_cache_all (cpu); }memset (tcg_ctx.tb_ctx.tb_phys_hash,0 ,sizeof (tcg_ctx.tb_ctx.tb_phys_hash));
@@ -1586,6 +1586,11 @@ void tb_check_watchpoint(CPUState *cpu) } } +void tb_flush_jmp_cache_all (CPUState *cpu) +{ +memset (cpu->tb_jmp_cache,0 ,sizeof (cpu->tb_jmp_cache)); +} +#ifndef CONFIG_USER_ONLY /* in deterministic execution mode, instructions doing device I/Os must be at the end of the TB */
PATCH v2 5/10 exec: [ŧcg] Use multiple physical TB caches
In reply to Lluís VilanovaThe physical translation block cache is split into as many caches as wanted, and the virtual TB cache on each guest CPU uses a (potentially) different physical TB cache.
This is later exploited to support different tracing event states on a per-vCPU basis.
--- cpu-exec.c | 17 +++++ include/exec/exec-all.h | 10 +++ include/qom/cpu.h | 5 ++ qom/cpu.c | 9 +++ translate-all.c | 146 +++++++++++++++++++++++++++++++++++++++++------ translate-all.h | 49 ++++++++++++++++ 6 files changed, 214 insertions(+), 22 deletions(-)
cpu-exec.c +14 -3
@@ -27,6 +27,7 @@#include "exec/address-spaces.h" #include "qemu/rcu.h" #include "exec/tb-hash.h" +#include "translate-all.h" #if defined(TARGET_I386 ) && !defined(CONFIG_USER_ONLY )#include "hw/i386/apic.h" #endif
@@ -224,7 +225,7 @@ static TranslationBlock *tb_find_physical(CPUState *cpu, phys_pc =get_page_addr_code (env, pc); phys_page1 = phys_pc &TARGET_PAGE_MASK ; h =tb_phys_hash_func (phys_pc); - ptb1 = &tcg_ctx.tb_ctx.tb_phys_hash[h]; + ptb1 = &tcg_ctx.tb_ctx.tb_phys_hash[cpu->tb_phys_idx][h];for (;;) { tb = *ptb1;if (!tb) {
@@ -253,8 +254,8 @@ static TranslationBlock *tb_find_physical(CPUState *cpu,/* Move the TB to the head of the list */ *ptb1 = tb->phys_hash_next; - tb->phys_hash_next = tcg_ctx.tb_ctx.tb_phys_hash[h]; - tcg_ctx.tb_ctx.tb_phys_hash[h] = tb; + tb->phys_hash_next = tcg_ctx.tb_ctx.tb_phys_hash[cpu->tb_phys_idx][h]; + tcg_ctx.tb_ctx.tb_phys_hash[cpu->tb_phys_idx][h] = tb;return tb; }
@@ -488,6 +489,16 @@ int cpu_exec(CPUState *cpu) cpu->exception_index =EXCP_INTERRUPT ;cpu_loop_exit (cpu); } +if (unlikely (tcg_ctx.tb_ctx.tb_phys_hash_size_req != + tcg_ctx.tb_ctx.tb_phys_hash_size)) { +if (tb_caches_apply () <0 ) { + next_tb =0 ; + } + } +if (unlikely (cpu->tb_phys_idx != cpu->tb_phys_idx_req)) { +cpu_tb_cache_apply (cpu); + next_tb =0 ; + }tb_lock (); tb =tb_find_fast (cpu);/* Note: we do it here to avoid a gcc bug on Mac OS X when
include/exec/exec-all.h +9 -1
@@ -177,6 +177,10 @@ static inline void tlb_flush_by_mmuidx(CPUState *cpu, ...)#define USE_DIRECT_JUMP #endif +/** +* TranslationBlock: +* @phys_idx: Index of physical TB cache where this TB has been allocated. +*/ struct TranslationBlock {target_ulong pc;/* simulated PC corresponding to this block (EIP + CS base) */ target_ulong cs_base;/* CS base for this block */
@@ -216,6 +220,8 @@ struct TranslationBlock {jmp_first */ struct TranslationBlock *jmp_next[2 ];struct TranslationBlock *jmp_first; + +unsigned int phys_idx; };#include "qemu/thread.h"
@@ -225,7 +231,9 @@ typedef struct TBContext TBContext;struct TBContext {TranslationBlock *tbs; -TranslationBlock *tb_phys_hash[CODE_GEN_PHYS_HASH_SIZE ]; +TranslationBlock ***tb_phys_hash; +size_t tb_phys_hash_size; +size_t tb_phys_hash_size_req;int nb_tbs;/* any access to the tbs or the page table must use this lock */ QemuMutex tb_lock;
include/qom/cpu.h +5 -0
@@ -250,6 +250,8 @@ struct kvm_run;* @kvm_fd: vCPU file descriptor for KVM. * @work_mutex: Lock to prevent multiple access to queued_work_*. * @queued_work_first: First asynchronous work pending. +* @tb_phys_idx: Index of current phsyical TB cache. +* @tb_phys_idx_req: Index of requested phsyical TB cache. * * State of one CPU core or thread. */
@@ -314,6 +316,9 @@ struct CPUState {struct KVMState *kvm_state;struct kvm_run *kvm_run; +unsigned int tb_phys_idx; +unsigned int tb_phys_idx_req; +/* TODO Move common fields from CPUArchState here. */ int cpu_index;/* used by alpha TCG */ uint32_t halted;/* used by alpha, cris, ppc TCG */
qom/cpu.c +9 -0
@@ -363,6 +363,14 @@ static void cpu_class_init(ObjectClass *klass, void *data) dc->cannot_instantiate_with_device_add_yet = true; } +static void cpu_init (Object *obj) +{ +CPUState *cpu =CPU (obj); + + cpu->tb_phys_idx =0 ; + cpu->tb_phys_idx_req =0 ; +} +static const TypeInfo cpu_type_info = { .name =TYPE_CPU , .parent =TYPE_DEVICE ,
@@ -372,6 +380,7 @@ static const TypeInfo cpu_type_info = { .abstract = true, .class_size = sizeof(CPUClass), .class_init = cpu_class_init, + .instance_init = cpu_init, };static void cpu_register_types (void )
translate-all.c +128 -18
208 lines not on this page · raw message
translate-all.h +49 -0
55 lines not on this page · raw message
Re: [Qemu-devel] [PATCH v2 05/10] exec: [ŧcg] Use multiple physical TB caches
On Tue, Nov 24, 2015 at 06:09:14PM +0100, Lluís Vilanova wrote:
Commit message uses 'LATIN SMALL LETTER T WITH STROKE' (U+0167) instead of regular 't' character :).
Re: [Qemu-devel] [PATCH v2 05/10] exec: [ŧcg] Use multiple physical TB caches
Quoted 3 lines · Stefan Hajnoczi
On Tue, Nov 24, 2015 at 06:09:14PM +0100, Lluís Vilanova wrote:
Commit message uses 'LATIN SMALL LETTER T WITH STROKE' (U+0167) instead of regular 't' character :).
Woops! Thanks :)
PATCH v2 6/10 exec: [tcg] Track which vCPU is performing translation and execution
In reply to Lluís VilanovaInformation is tracked inside the TCGContext structure, and later used by tracing events with the 'tcg' and 'vcpu' properties.
The 'cpu' field is used to check tracing of translation-time events ("*_trans"). The 'tcg_env' field is used to pass it to execution-time events ("*_exec").
--- target-alpha/translate.c | 1 + target-arm/translate.c | 1 + target-cris/translate.c | 1 + target-cris/translate_v10.c | 1 + target-i386/translate.c | 1 + target-lm32/translate.c | 1 + target-m68k/translate.c | 1 + target-microblaze/translate.c | 1 + target-mips/translate.c | 1 + target-moxie/translate.c | 1 + target-openrisc/translate.c | 1 + target-ppc/translate.c | 1 + target-s390x/translate.c | 1 + target-sh4/translate.c | 1 + target-sparc/translate.c | 1 + target-tilegx/translate.c | 1 + target-tricore/translate.c | 1 + target-unicore32/translate.c | 1 + target-xtensa/translate.c | 1 + tcg/tcg.h | 4 ++++ translate-all.c | 2 ++ 21 files changed, 25 insertions(+)
target-alpha/translate.c +1 -0
@@ -148,6 +148,7 @@ void alpha_translate_init(void) done_init =1 ; cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); + tcg_ctx.tcg_env = cpu_env;for (i =0 ; i <31 ; i++) { cpu_std_ir[i] = tcg_global_mem_new_i64(TCG_AREG0,
target-arm/translate.c +1 -0
@@ -87,6 +87,7 @@ void arm_translate_init(void)int i; cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); + tcg_ctx.tcg_env = cpu_env;for (i =0 ; i <16 ; i++) { cpu_R[i] = tcg_global_mem_new_i32(TCG_AREG0,
target-cris/translate.c +1 -0
@@ -3360,6 +3360,7 @@ void cris_initialize_tcg(void)int i; cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); + tcg_ctx.tcg_env = cpu_env; cc_x =tcg_global_mem_new (TCG_AREG0 , offsetof(CPUCRISState , cc_x),"cc_x" ); cc_src = tcg_global_mem_new(TCG_AREG0,
target-cris/translate_v10.c +1 -0
@@ -1249,6 +1249,7 @@ void cris_initialize_crisv10_tcg(void)int i; cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); + tcg_ctx.tcg_env = cpu_env; cc_x =tcg_global_mem_new (TCG_AREG0 , offsetof(CPUCRISState , cc_x),"cc_x" ); cc_src = tcg_global_mem_new(TCG_AREG0,
target-i386/translate.c +1 -0
@@ -7863,6 +7863,7 @@ void optimize_flags_init(void)int i; cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); + tcg_ctx.tcg_env = cpu_env; cpu_cc_op =tcg_global_mem_new_i32 (TCG_AREG0 , offsetof(CPUX86State , cc_op),"cc_op" ); cpu_cc_dst = tcg_global_mem_new(TCG_AREG0, offsetof(CPUX86State, cc_dst),
target-lm32/translate.c +1 -0
@@ -1189,6 +1189,7 @@ void lm32_translate_init(void)int i; cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); + tcg_ctx.tcg_env = cpu_env;for (i =0 ; i <ARRAY_SIZE (cpu_R); i++) { cpu_R[i] = tcg_global_mem_new(TCG_AREG0,
target-m68k/translate.c +1 -0
@@ -91,6 +91,7 @@ void m68k_tcg_init(void) "EXCEPTION"); cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); + tcg_ctx.tcg_env = cpu_env; p = cpu_reg_names;for (i =0 ; i <8 ; i++) {
target-microblaze/translate.c +1 -0
@@ -1867,6 +1867,7 @@ void mb_tcg_init(void)int i; cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); + tcg_ctx.tcg_env = cpu_env; env_debug = tcg_global_mem_new(TCG_AREG0, offsetof(CPUMBState, debug),
target-mips/translate.c +1 -0
@@ -19818,6 +19818,7 @@ void mips_tcg_init(void)return ; cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); + tcg_ctx.tcg_env = cpu_env;TCGV_UNUSED (cpu_gpr[0 ]);for (i =1 ; i <32 ; i++) cpu_gpr[i] = tcg_global_mem_new(TCG_AREG0,
target-moxie/translate.c +1 -0
@@ -109,6 +109,7 @@ void moxie_translate_init(void)return ; } cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); + tcg_ctx.tcg_env = cpu_env; cpu_pc =tcg_global_mem_new_i32 (TCG_AREG0 , offsetof(CPUMoxieState , pc),"$pc" );for (i =0 ; i <16 ; i++)
target-openrisc/translate.c +1 -0
@@ -77,6 +77,7 @@ void openrisc_translate_init(void)int i; cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); + tcg_ctx.tcg_env = cpu_env; cpu_sr =tcg_global_mem_new (TCG_AREG0 , offsetof(CPUOpenRISCState , sr),"sr" ); env_flags = tcg_global_mem_new_i32(TCG_AREG0,
target-ppc/translate.c +1 -0
@@ -85,6 +85,7 @@ void ppc_translate_init(void)return ; cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); + tcg_ctx.tcg_env = cpu_env; p = cpu_reg_names; cpu_reg_names_size =sizeof (cpu_reg_names);
target-s390x/translate.c +1 -0
@@ -166,6 +166,7 @@ void s390x_translate_init(void)int i; cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); + tcg_ctx.tcg_env = cpu_env; psw_addr =tcg_global_mem_new_i64 (TCG_AREG0 , offsetof(CPUS390XState, psw.addr),"psw_addr" );
target-sh4/translate.c +1 -0
@@ -98,6 +98,7 @@ void sh4_translate_init(void)return ; cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); + tcg_ctx.tcg_env = cpu_env;for (i =0 ; i <24 ; i++) cpu_gregs[i] = tcg_global_mem_new_i32(TCG_AREG0,
target-sparc/translate.c +1 -0
@@ -5344,6 +5344,7 @@ void gen_intermediate_code_init(CPUSPARCState *env) inited =1 ; cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); + tcg_ctx.tcg_env = cpu_env; cpu_regwptr =tcg_global_mem_new_ptr (TCG_AREG0 , offsetof(CPUSPARCState , regwptr),"regwptr" );
target-tilegx/translate.c +1 -0
@@ -2440,6 +2440,7 @@ void tilegx_tcg_init(void)int i; cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); + tcg_ctx.tcg_env = cpu_env; cpu_pc =tcg_global_mem_new_i64 (TCG_AREG0 , offsetof(CPUTLGState , pc),"pc" );for (i =0 ; i <TILEGX_R_COUNT ; i++) { cpu_regs[i] = tcg_global_mem_new_i64(TCG_AREG0,
target-tricore/translate.c +1 -0
@@ -8366,6 +8366,7 @@ void tricore_tcg_init(void)return ; } cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); + tcg_ctx.tcg_env = cpu_env;/* reg init */ for (i =0 ; i <16 ; i++) { cpu_gpr_a[i] = tcg_global_mem_new(TCG_AREG0,
target-unicore32/translate.c +1 -0
@@ -72,6 +72,7 @@ void uc32_translate_init(void)int i; cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); + tcg_ctx.tcg_env = cpu_env;for (i =0 ; i <32 ; i++) { cpu_R[i] = tcg_global_mem_new_i32(TCG_AREG0,
target-xtensa/translate.c +1 -0
@@ -217,6 +217,7 @@ void xtensa_translate_init(void)int i; cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); + tcg_ctx.tcg_env = cpu_env; cpu_pc =tcg_global_mem_new_i32 (TCG_AREG0 , offsetof(CPUXtensaState , pc),"pc" );
tcg/tcg.h +4 -0
@@ -572,6 +572,10 @@ struct TCGContext {TBContext tb_ctx; +/* Track which vCPU triggers events */ +CPUState *cpu;/* *_trans */ +TCGv_cpu tcg_env;/* *_exec */ +/* The TCGBackendData structure is private to tcg-target.c. */ struct TCGBackendData *be;
translate-all.c +2 -0
@@ -1205,6 +1205,8 @@ TranslationBlock *tb_gen_code(CPUState *cpu, ti =profile_getclock ();#endif + tcg_ctx.cpu =ENV_GET_CPU (env); +tcg_func_start (&tcg_ctx);gen_intermediate_code (env, tb);
PATCH v2 7/10 Track when QEMU has finished initialization
In reply to Lluís VilanovaLater used to synchronize per-vCPU state of events enabled from command line.
--- Makefile.objs | 2 +- bsd-user/main.c | 1 + include/qemu-common.h | 3 +++ linux-user/main.c | 1 + qemu-common.c | 14 ++++++++++++++ stubs/Makefile.objs | 1 + stubs/qemu-common-stub.c | 21 +++++++++++++++++++++ vl.c | 2 ++ 8 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 qemu-common.c create mode 100644 stubs/qemu-common-stub.c
Makefile.objs +1 -1
@@ -2,7 +2,7 @@ # Common libraries for tools and emulators stub-obj-y = stubs/ util-obj-y = util/ qobject/ qapi/ -util-obj-y += qmp-introspect.o qapi-types.o qapi-visit.o qapi-event.o +util-obj-y += qmp-introspect.o qapi-types.o qapi-visit.o qapi-event.o qemu-common.o ####################################################################### # block-obj-y is code used by both qemu system emulation and qemu-img
bsd-user/main.c +1 -0
@@ -1121,6 +1121,7 @@ int main(int argc, char **argv)gdbserver_start (gdbstub_port);gdb_handlesig (cpu,0 ); } + qemu_initialized = true;cpu_loop (env);/* never exits */ return 0 ;
include/qemu-common.h +3 -0
@@ -35,6 +35,9 @@# error Unknown pointer size#endif +/* Whether the system has finished initializing */ +extern bool qemu_initialized; +void cpu_ticks_init (void );/* icount */
linux-user/main.c +1 -0
@@ -4663,6 +4663,7 @@ int main(int argc, char **argv, char **envp) }gdb_handlesig (cpu,0 ); } + qemu_initialized = true;cpu_loop (env);/* never exits */ return 0 ;
qemu-common.c new file +14 -0
@@ -0,0 +1,14 @@ +/* +* Common symbol definitions for all tools and targets. +* +* Copyright (C) 2011-2015 Lluís Vilanova <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include "qemu-common.h" + + +/* Whether QEMU has been initialized. */ +bool qemu_initialized;
stubs/Makefile.objs +1 -0
@@ -38,3 +38,4 @@ stub-obj-y += qmp_pc_dimm_device_list.o stub-obj-y += target-monitor-defs.o stub-obj-y += target-get-monitor-def.o stub-obj-y += vhost.o +stub-obj-y += qemu-common-stub.o
stubs/qemu-common-stub.c new file +21 -0
@@ -0,0 +1,21 @@ +/* +* Common symbol definitions for all tools and targets. +* +* Copyright (C) 2011-2015 Lluís Vilanova <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include "qemu-common.h" +#include <qemu/module.h> + + +static void do_qemu_initialized_init (void ) +{ +/* Tools always consider QEMU as inited */ + qemu_initialized = true; +} + +/* Block is always inited on both tools (and targets) */ +block_init (do_qemu_initialized_init);
vl.c +2 -0
@@ -4681,6 +4681,8 @@ int main(int argc, char **argv, char **envp) } } + qemu_initialized = true; +main_loop ();replay_disable_events ();
PATCH v2 8/10 disas: Remove unused macro '_'
In reply to Lluís VilanovaEliminates a future compilation error when UI code includes the tracing headers (indirectly pulling "disas/bfd.h" through "qom/cpu.h") and GLib's i18n '_' macro.
--- disas/i386.c | 2 +- include/disas/bfd.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-)
disas/i386.c +1 -1
@@ -3406,7 +3406,7 @@ static const struct dis386 three_byte_table[][256] = { } }; -#define INTERNAL_DISASSEMBLER_ERROR _("<internal disassembler error>") +#define INTERNAL_DISASSEMBLER_ERROR "<internal disassembler error>"static void ckprefix (void )
include/disas/bfd.h +0 -1
@@ -477,7 +477,6 @@ int generic_symbol_at_address(bfd_vma, struct disassemble_info *); (INFO ).disassembler_options =NULL , \ (INFO).insn_info_valid = 0 -#define _ (x) x#define ATTRIBUTE_UNUSED __attribute__((unused))/* from libbfd */
PATCH v2 9/10 trace: [tcg] Add per-vCPU tracing states for events with the 'vcpu' property
In reply to Lluís VilanovaEach event with the 'vcpu' property gets a per-vCPU dynamic tracing state.
The set of enabled events with the 'vcpu' and 'tcg' properties is used to select a per-vCPU physical TB cache. The number of events with both properties is used to select the number of physical TB caches, and a bitmap of the identifiers of such enabled events is used to select a physical TB cache.
--- Makefile.objs | 1 include/qom/cpu.h | 5 + monitor.c | 4 - qapi/trace.json | 13 ++- qmp-commands.hx | 17 +++- qom/cpu.c | 12 +++ scripts/tracetool/format/h.py | 1 scripts/tracetool/format/tcg_helper_c.py | 11 ++ trace/Makefile.objs | 2 trace/control-internal.h | 13 ++- trace/control-stub.c | 29 ++++++ trace/control-target.c | 69 +++++++++++++++ trace/control.h | 54 ++++++++++++ trace/event-internal.h | 2 trace/qmp.c | 138 +++++++++++++++++++++++++----- translate-all.c | 1 16 files changed, 330 insertions(+), 42 deletions(-) create mode 100644 trace/control-stub.c create mode 100644 trace/control-target.c
Makefile.objs +1 -0
@@ -98,6 +98,7 @@ version-lobj-$(CONFIG_WIN32) += $(BUILD_DIR)/version.lo # tracing util-obj-y += trace/ target-obj-y += trace/ +stub-obj-y += trace/ ###################################################################### # guest agent
include/qom/cpu.h +5 -0
@@ -29,6 +29,7 @@#include "qemu/queue.h" #include "qemu/thread.h" #include "qemu/typedefs.h" +#include "trace/generated-events.h" typedef int (*WriteCoreDumpFunction )(const void *buf,size_t size,void *opaque);
@@ -319,6 +320,10 @@ struct CPUState {unsigned int tb_phys_idx;unsigned int tb_phys_idx_req; +/* Ensure 'tb_phys_idx' can encode event states as a bitmask */ +bool too_many_tcg_vcpu_events[ +TRACE_CPU_EVENT_COUNT >sizeof (unsigned int )*8 ?-1 :0 ]; +/* TODO Move common fields from CPUArchState here. */ int cpu_index;/* used by alpha TCG */ uint32_t halted;/* used by alpha, cris, ppc TCG */
monitor.c +2 -2
@@ -888,7 +888,7 @@ static void hmp_trace_event(Monitor *mon, const QDict *qdict)bool new_state =qdict_get_bool (qdict,"option" );Error *local_err =NULL ; -qmp_trace_event_set_state (tp_name, new_state, true, true, &local_err); +qmp_trace_event_set_state (tp_name, new_state, true, true, false,0 , &local_err);if (local_err) {error_report_err (local_err); }
@@ -1047,7 +1047,7 @@ static void hmp_info_cpustats(Monitor *mon, const QDict *qdict)static void hmp_info_trace_events (Monitor *mon,const QDict *qdict) { -TraceEventInfoList *events =qmp_trace_event_get_state ("*" ,NULL ); +TraceEventInfoList *events =qmp_trace_event_get_state ("*" , false,0 ,NULL );TraceEventInfoList *elem;for (elem = events; elem !=NULL ; elem = elem->next) {
qapi/trace.json +10 -3
@@ -29,7 +29,7 @@ # # @name: Event name. # @state: Tracing state. -# @vcpu: Whether this is a per-vCPU event (since 2.5). +# @vcpu: #optional Whether this is a per-vCPU event (since 2.5). # # Since 2.2 ##
@@ -42,13 +42,18 @@ # Query the state of events. # # @name: Event name pattern (case-sensitive glob). +# @vcpu: #optional The vCPU to check (any by default; since 2.5). # # Returns: a list of @TraceEventInfo for the matching events # +# For any event without the "vcpu" property: +# - If @name is a pattern and @vcpu is set, events are ignored. +# - If @name is not a pattern and @vcpu is set, an error is raised. +# # Since 2.2 ## { 'command': 'trace-event-get-state', - 'data': {'name': 'str'}, + 'data': {'name': 'str', '*vcpu': 'int'}, 'returns': ['TraceEventInfo'] } ##
@@ -59,8 +64,10 @@ # @name: Event name pattern (case-sensitive glob). # @enable: Whether to enable tracing. # @ignore-unavailable: #optional Do not match unavailable events with @name. +# @vcpu: The vCPU to act upon (all by default; since 2.5). # # Since 2.2 ## { 'command': 'trace-event-set-state', - 'data': {'name': 'str', 'enable': 'bool', '*ignore-unavailable': 'bool'} } + 'data': {'name': 'str', 'enable': 'bool', '*ignore-unavailable': 'bool', + '*vcpu': 'int'} }
qmp-commands.hx +14 -3
@@ -4510,7 +4510,7 @@ EQMP { .name = "trace-event-get-state", - .args_type = "name:s", + .args_type = "name:s,vcpu:i?", .mhandler.cmd_new = qmp_marshal_trace_event_get_state, },
@@ -4520,6 +4520,11 @@ trace-event-get-state Query the state of events. +Arguments: + +- "name": Event name pattern (json-string). +- "vcpu": Specific vCPU to query, any vCPU by default (json-int, optional). + Example: -> { "execute": "trace-event-get-state", "arguments": { "name": "qemu_memalign" } }
@@ -4528,7 +4533,7 @@ EQMP { .name = "trace-event-set-state", - .args_type = "name:s,enable:b,ignore-unavailable:b?", + .args_type = "name:s,enable:b,ignore-unavailable:b?,vcpu:i?", .mhandler.cmd_new = qmp_marshal_trace_event_set_state, },
@@ -4538,6 +4543,13 @@ trace-event-set-state Set the state of events. +Arguments: + +- "name": Event name pattern (json-string). +- "enable": Whether to enable or disable the event (json-bool). +- "ignore-unavailable": Whether to ignore errors for events that cannot be changed (json-bool, optional). +- "vcpu": Specific vCPU to set, all vCPUs by default (json-int, optional). + Example: -> { "execute": "trace-event-set-state", "arguments": { "name": "qemu_memalign", "enable": "true" } }
@@ -4606,7 +4618,6 @@ Move mouse pointer to absolute coordinates (20000, 400). { "type": "abs", "data" : { "axis": "X", "value" : 20000 } }, { "type": "abs", "data" : { "axis": "Y", "value" : 400 } } ] } } <- { "return": {} } - EQMP {
qom/cpu.c +12 -0
@@ -25,6 +25,7 @@#include "qemu/log.h" #include "qemu/error-report.h" #include "sysemu/sysemu.h" +#include "trace/control.h" bool cpu_exists (int64_t id) {
@@ -227,6 +228,17 @@ void cpu_dump_statistics(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf,void cpu_reset (CPUState *cpu) {CPUClass *klass =CPU_GET_CLASS (cpu); +TraceEvent *ev =NULL ; + +if (!qemu_initialized) { +/* trace enabled events on all initial vCPUs */ +while ((ev =trace_event_pattern ("*" , ev)) !=NULL ) { +if (trace_event_get_cpu_id (ev) !=TRACE_CPU_EVENT_COUNT && +trace_event_get_state_dynamic (ev)) { +trace_event_set_state_dynamic (ev, true); + } + } + }if (klass->reset !=NULL ) { (*klass->reset)(cpu);
scripts/tracetool/format/h.py +1 -0
@@ -36,6 +36,7 @@ def generate(events, backend): args=e.args) if "disable" not in e.properties: + # NOTE: See note on 'trace_event_set_cpu_state()'. backend.generate(e) out('}')
scripts/tracetool/format/tcg_helper_c.py +8 -3
@@ -6,7 +6,7 @@ Generate trace/generated-helpers.c. """ __author__ = "Lluís Vilanova <[email protected]>" -__copyright__ = "Copyright 2012-2014, Lluís Vilanova <[email protected]>" +__copyright__ = "Copyright 2012-2015, Lluís Vilanova <[email protected]>" __license__ = "GPL version 2 or (at your option) any later version" __maintainer__ = "Stefan Hajnoczi"
@@ -36,8 +36,13 @@ def generate(events, backend): # tracetool.generate always transforms types to host e_args = e.original.args - values = ["(%s)%s" % (t, n) - for t, n in e.args.transform(TCG_2_TCG_HELPER_DEF)] + values = [] + for (t_old, n), (t_new, _) in zip( + e.args, e.args.transform(TCG_2_TCG_HELPER_DEF)): + if t_old == "CPUState *": + values.append("ENV_GET_CPU((CPUArchState*)%s)" % n) + else: + values.append("(%s)%s" % (t_new, n)) out('void %(name_tcg)s(%(args)s)', '{',
trace/Makefile.objs +2 -0
@@ -144,4 +144,6 @@ util-obj-$(CONFIG_TRACE_SIMPLE) += simple.o generated-tracers.o util-obj-$(CONFIG_TRACE_FTRACE) += ftrace.o util-obj-$(CONFIG_TRACE_UST) += generated-ust.o util-obj-y += control.o +target-obj-y += control-target.o +stub-obj-y += control-stub.o util-obj-y += qmp.o
trace/control-internal.h +9 -4
@@ -12,6 +12,9 @@#include <string.h> +#include "qemu-common.h" +#include "qom/cpu.h" +extern TraceEvent trace_events[];
@@ -60,14 +63,16 @@ static inline bool trace_event_get_state_static(TraceEvent *ev)static inline bool trace_event_get_state_dynamic (TraceEvent *ev) {assert (ev !=NULL ); -return ev->dstate; +/* no need to iterate over vCPUs, since the global dynamic state is always set */ +return ev->dstate >0 ; } -static inline void trace_event_set_state_dynamic (TraceEvent *ev,bool state) +static inline bool trace_event_get_cpu_state_dynamic (CPUState *cpu, +TraceEvent *ev) { +assert (cpu !=NULL );assert (ev !=NULL ); -assert (trace_event_get_state_static (ev)); - ev->dstate = state; +return cpu->tb_phys_idx & (((unsigned long )1 ) << ev->cpu_id); }#endif /* TRACE__CONTROL_INTERNAL_H */
trace/control-stub.c new file +29 -0
@@ -0,0 +1,29 @@ +/* +* Interface for configuring and controlling the state of tracing events. +* +* Copyright (C) 2014-2015 Lluís Vilanova <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include "trace/control.h" + + +void trace_init_vcpu_tb_caches (void ) +{ +} + +void trace_event_set_state_dynamic (TraceEvent *ev,bool state) +{ +assert (ev !=NULL ); +assert (trace_event_get_state_static (ev)); + ev->dstate = state; +} + +void trace_event_set_cpu_state_dynamic (CPUState *cpu, +TraceEvent *ev,bool state) +{ +/* should never be called on non-target binaries */ +abort (); +}
trace/control-target.c new file +69 -0
69 lines not on this page · raw message
trace/control.h +53 -1
88 lines not on this page · raw message
trace/event-internal.h +1 -1
@@ -28,7 +28,7 @@ typedef struct TraceEvent {TraceEventCPUID cpu_id;const char * name;const bool sstate; -bool dstate; +size_t dstate; } TraceEvent;
trace/qmp.c +113 -25
177 lines not on this page · raw message
translate-all.c +1 -0
@@ -179,6 +179,7 @@ void cpu_gen_init(void) tcg_ctx.tb_ctx.tb_phys_hash_size_req =1 ; tcg_ctx.tb_ctx.tb_phys_hash =NULL ;tb_caches_apply (); +trace_init_vcpu_tb_caches (); }/* Encode VAL as a signed leb128 sequence at P.
Re: [Qemu-devel] [PATCH v2 09/10] trace: [tcg] Add per-vCPU tracing states for events with the 'vcpu' property
Quoted 13 lines · Lluís Vilanova
Each event with the 'vcpu' property gets a per-vCPU dynamic tracing state.
The set of enabled events with the 'vcpu' and 'tcg' properties is used to select a per-vCPU physical TB cache. The number of events with both properties is used to select the number of physical TB caches, and a bitmap of the identifiers of such enabled events is used to select a physical TB cache.
Signed-off-by Lluís Vilanova <[email protected]>---
+++
b/qapi/trace.json
qapi/trace.json line 35
Quoted 8 lines
qapi/trace.json +1
-1@@ -29,7 +29,7 @@ # # @name: Event name. # @state: Tracing state. -# @vcpu: Whether this is a per-vCPU event (since 2.5). +# @vcpu: #optional Whether this is a per-vCPU event (since 2.5). # # Since 2.2 ##
Spurious hunk? It looks like vcpu is always present on output, and that it is only...
qapi/trace.json line 45
Quoted 5 lines
qapi/trace.json +1
-0@@ -42,13 +42,18 @@ # Query the state of events. # # @name: Event name pattern (case-sensitive glob). +# @vcpu: #optional The vCPU to check (any by default; since 2.5).
...the new input place where it is optional.
2.6.
Quoted 16 lines
qapi/trace.json +5
-1# # Returns: a list of @TraceEventInfo for the matching events # +# For any event without the "vcpu" property: +# - If @name is a pattern and @vcpu is set, events are ignored. +# - If @name is not a pattern and @vcpu is set, an error is raised. +# # Since 2.2 ## { 'command': 'trace-event-get-state', - 'data': {'name': 'str'}, + 'data': {'name': 'str', '*vcpu': 'int'}, 'returns': ['TraceEventInfo'] } ##
qapi/trace.json line 67
Quoted 4 lines
qapi/trace.json +1
-0@@ -59,8 +64,10 @@ # @name: Event name pattern (case-sensitive glob). # @enable: Whether to enable tracing. # @ignore-unavailable: #optional Do not match unavailable events with @name. +# @vcpu: The vCPU to act upon (all by default; since 2.5).
2.6
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v2 09/10] trace: [tcg] Add per-vCPU tracing states for events with the 'vcpu' property
Quoted 26 lines · Eric Blake
Quoted 13 lines · Lluís Vilanova
Each event with the 'vcpu' property gets a per-vCPU dynamic tracing state.
The set of enabled events with the 'vcpu' and 'tcg' properties is used to select a per-vCPU physical TB cache. The number of events with both properties is used to select the number of physical TB caches, and a bitmap of the identifiers of such enabled events is used to select a physical TB cache.
Signed-off-by Lluís Vilanova <[email protected]>---
+++
b/qapi/trace.jsonqapi/trace.json line 35
Quoted 8 lines
qapi/trace.json +1
-1@@ -29,7 +29,7 @@ # # @name: Event name. # @state: Tracing state. -# @vcpu: Whether this is a per-vCPU event (since 2.5). +# @vcpu: #optional Whether this is a per-vCPU event (since 2.5). # # Since 2.2 ##Spurious hunk? It looks like vcpu is always present on output, and that it is only...
Quoted 7 lines
qapi/trace.json line 45
Quoted 5 lines
qapi/trace.json +1
-0@@ -42,13 +42,18 @@ # Query the state of events. # # @name: Event name pattern (case-sensitive glob). +# @vcpu: #optional The vCPU to check (any by default; since 2.5)....the new input place where it is optional.
Whoops! Misplaced tag, thanks.
Quoted 1 line
2.6.
Done.
Thanks,
Lluis
Signature · 4 lines
"And it's much the same thing with knowledge, for whenever you learn something new, the whole world becomes that much richer." -- The Princess of Pure Reason, as told by Norton Juster in The Phantom Tollbooth
Re: [Qemu-devel] [PATCH v2 09/10] trace: [tcg] Add per-vCPU tracing states for events with the 'vcpu' property
In reply to Lluís Vilanovainclude/qom/cpu.h struct CPUState { · line 325
Quoted 3 lines · Lluís Vilanova
include/qom/cpu.h +3
-0+/* Ensure 'tb_phys_idx' can encode event states as a bitmask */ +bool too_many_tcg_vcpu_events[ +TRACE_CPU_EVENT_COUNT >sizeof (unsigned int )*8 ?-1 :0 ];
There is a limit of 32 vcpu tcg events? That seems low but as long as not too many users of this feature are merged it will work...
qom/cpu.c void cpu_dump_statistics(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf, · line 233
Quoted 7 lines
qom/cpu.c +3
-0@@ -227,6 +228,17 @@ void cpu_dump_statistics(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf,void cpu_reset (CPUState *cpu) {CPUClass *klass =CPU_GET_CLASS (cpu); +TraceEvent *ev =NULL ; + +if (!qemu_initialized) {
Is there a cleaner place to do this without introducing the qemu_initialized global?
I guess the problem is that tracing itself is initialized before the vcpus are set up. Is qemu_add_machine_init_done_notifier() sufficient for this purpose?
Re: [Qemu-devel] [PATCH v2 09/10] trace: [tcg] Add per-vCPU tracing states for events with the 'vcpu' property
Quoted 7 lines · Stefan Hajnoczi
include/qom/cpu.h struct CPUState { · line 325
Quoted 3 lines · Lluís Vilanova
include/qom/cpu.h +3
-0+/* Ensure 'tb_phys_idx' can encode event states as a bitmask */ +bool too_many_tcg_vcpu_events[ +TRACE_CPU_EVENT_COUNT >sizeof (unsigned int )*8 ?-1 :0 ];There is a limit of 32 vcpu tcg events? That seems low but as long as not too many users of this feature are merged it will work...
Well, 'tb_phys_idx' and 'tb_phys_idx_req' (just above this line) are 'unsigned int'. They could be changed to a 64-bit index if necessary, but more than that would require a more complex physical TB cache selection.
Fortunately, this is going to be catched at compilation time, making it safe against crashing QEMU because of too many events of this type.
Quoted 11 lines
qom/cpu.c void cpu_dump_statistics(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf, · line 233
Quoted 7 lines
qom/cpu.c +3
-0@@ -227,6 +228,17 @@ void cpu_dump_statistics(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf,void cpu_reset (CPUState *cpu) {CPUClass *klass =CPU_GET_CLASS (cpu); +TraceEvent *ev =NULL ; + +if (!qemu_initialized) {Is there a cleaner place to do this without introducing the
qemu_initializedglobal?
Quoted 3 lines
I guess the problem is that tracing itself is initialized before the vcpus are set up. Is
qemu_add_machine_init_done_notifier()sufficient for this purpose?
Right, tracing must be initialized early, while vCPUs do so much later. Also, the hook I took for initialization is also called by regular vCPU resets and hotplugs. The problem with machine_init is that it only works in full-system (softmmu) mode, so it would require a separate initialization call for the user mode variants (e.g., linux-user).
It would be much cleaner to add a trace post-initialization routine right before main_loop/cpu_loop (doing the per-vCPU tracing state initialization). I'll re-check the code to see if there was any other condition that made me take 'cpu_reset' instead.
Thanks,
Lluis
Re: [Qemu-devel] [PATCH v2 09/10] trace: [tcg] Add per-vCPU tracing states for events with the 'vcpu' property
Quoted 24 lines · Lluís Vilanova
Quoted 12 lines · Stefan Hajnoczi
qom/cpu.c void cpu_dump_statistics(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf, · line 233
Quoted 7 lines · Lluís Vilanova
qom/cpu.c +3
-0@@ -227,6 +228,17 @@ void cpu_dump_statistics(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf,void cpu_reset (CPUState *cpu) {CPUClass *klass =CPU_GET_CLASS (cpu); +TraceEvent *ev =NULL ; + +if (!qemu_initialized) {Is there a cleaner place to do this without introducing the
qemu_initializedglobal?Quoted 3 lines
I guess the problem is that tracing itself is initialized before the vcpus are set up. Is
qemu_add_machine_init_done_notifier()sufficient for this purpose?Right, tracing must be initialized early, while vCPUs do so much later. Also, the hook I took for initialization is also called by regular vCPU resets and hotplugs. The problem with
machine_initis that it only works in full-system (softmmu) mode, so it would require a separate initialization call for the user mode variants (e.g., linux-user).
Quoted 4 lines
It would be much cleaner to add a trace post-initialization routine right before main_loop/cpu_loop (doing the per-vCPU tracing state initialization). I'll re-check the code to see if there was any other condition that made me take '
cpu_reset' instead.
Okay, great.
Stefan
PATCH v2 10/10 trace: [tcg] Generate TCG code to trace guest events on a per-vCPU basis
In reply to Lluís VilanovaEvents with the 'tcg' and 'vcpu' properties will:
* Trace the translation-time event ('*_trans').
* Generate TCG code to call a function that traces the execution-time event ('*_exec') iff the event is enabled for that vCPU.
--- scripts/tracetool/format/tcg_h.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
scripts/tracetool/format/tcg_h.py +6 -2
@@ -32,7 +32,7 @@ def generate(events, backend): for e in events: # just keep one of them - if "tcg-trans" not in e.properties: + if "tcg-exec" not in e.properties: continue # get the original event definition
@@ -52,7 +52,11 @@ def generate(events, backend): if "disable" not in e.properties: out(' %(name_trans)s(%(argnames_trans)s);', - ' gen_helper_%(name_exec)s(%(argnames_exec)s);', + ' if (%(cond)s) {', + ' gen_helper_%(name_exec)s(%(argnames_exec)s);', + ' }', + cond='trace_event_get_cpu_state(_cpu, TRACE_%s)' % e.event_exec.name.upper() + if "vcpu" in e.properties else "true", name_trans=e.event_trans.api(e.QEMU_TRACE), name_exec=e.event_exec.api(e.QEMU_TRACE), argnames_trans=", ".join(e.event_trans.args.names()),
Quoted 117 lines · Lluís Vilanova
NOTE: This series completes the framework for guest code tracing. Next series
will add actual events.Provides per-vCPU dynamic controls of the tracing state of events tied to a specific virtual CPU.
Events with the "vcpu" property are identified as being tied to a particular virtual CPU, like executing an instruction. The state of such events can be controlled idependently; this is specially useful to, for example, trace memory access events of a process executing on a specific virtual CPU.
This event property plays in combination with the "tcg" property to avoid generating a call to the execution-time event tracer when a vCPU is not actively tracing such event (i.e., avoids adding tracing overheads).
Virtual CPUs tracing the same set of events use the same physical translation cache, improving their reuse. The system has 2^N physical translation caches, where "N" is the number of TCG events with the "vcpu" property. Every vCPU has a bitmap with the states of these events, which can be controlled separately, and uses it to select its physical translation cache. At translation time, QEMU generates the code to trace an event at execution time only if the event is enabled.
Changes in v2
=============* Rebase on 5522a84.
* Improve patch descriptions.
* Refactor code generation into a separate patch.
* Fix forward declarations (Stefan Hajnoczi & Eduardo Habkost).
* Fix "since" tags in QAPI interface (Eric Blake).
* Unify QAPI/QMP interface with an optional 'vcpu' argument (Eric Blake).
* Fix QMP+GTK header workaround (Stefan Hajnoczi).Signed-off-by Lluís Vilanova <[email protected]>---
Lluís Vilanova (10):
trace: Add support for vCPU pointers in trace events
trace: Add 'vcpu' event property
trace: [tcg] Identify events with the 'vcpu' property
exec: [tcg] Refactor flush of per-CPU virtual TB cache
exec: [ŧcg] Use multiple physical TB caches
exec: [tcg] Track which vCPU is performing translation and execution [trivial] Track when QEMU has finished initialization
disas: Remove unused macro '_'
trace: [tcg] Add per-vCPU tracing states for events with the 'vcpu' property
trace: [tcg] Generate TCG code to trace guest events on a per-vCPU basisMakefile.objs | 3 - bsd-user/main.c | 1 cpu-exec.c | 17 +++ cputlb.c | 2 disas/i386.c | 2 docs/tracing.txt | 40 ++++++++ include/disas/bfd.h | 1 include/exec/exec-all.h | 16 +++ include/qemu-common.h | 3 + include/qemu/typedefs.h | 1 include/qom/cpu.h | 10 ++ linux-user/main.c | 1 monitor.c | 4 - qapi/trace.json | 16 ++- qemu-common.c | 14 +++ qmp-commands.hx | 17 +++ qom/cpu.c | 21 ++++ scripts/tracetool/__init__.py | 24 ++++- scripts/tracetool/format/events_c.py | 11 ++ scripts/tracetool/format/events_h.py | 14 ++- scripts/tracetool/format/h.py | 4 + scripts/tracetool/format/tcg_h.py | 21 +++- scripts/tracetool/format/tcg_helper_c.py | 11 ++ scripts/tracetool/format/ust_events_c.py | 3 - scripts/tracetool/transform.py | 9 ++ stubs/Makefile.objs | 1 stubs/qemu-common-stub.c | 21 ++++ target-alpha/translate.c | 3 - target-arm/translate.c | 3 - target-arm/translate.h | 2 target-cris/translate.c | 3 - target-cris/translate_v10.c | 1 target-i386/translate.c | 3 - target-lm32/translate.c | 3 - target-m68k/translate.c | 3 - target-microblaze/translate.c | 3 - target-mips/translate.c | 3 - target-moxie/translate.c | 3 - target-openrisc/translate.c | 3 - target-ppc/translate.c | 3 - target-s390x/translate.c | 3 - target-sh4/translate.c | 3 - target-sparc/translate.c | 6 + target-tilegx/translate.c | 3 - target-tricore/translate.c | 3 - target-unicore32/translate.c | 3 - target-xtensa/translate.c | 3 - tcg/tcg-op.h | 2 tcg/tcg.h | 10 ++ trace/Makefile.objs | 2 trace/control-internal.h | 21 +++- trace/control-stub.c | 29 ++++++ trace/control-target.c | 69 +++++++++++++ trace/control.h | 64 ++++++++++++ trace/event-internal.h | 6 + trace/qmp.c | 139 ++++++++++++++++++++++----- translate-all.c | 156 ++++++++++++++++++++++++++---- translate-all.h | 49 +++++++++ vl.c | 2 59 files changed, 788 insertions(+), 109 deletions(-) create mode 100644 qemu-common.c create mode 100644 stubs/qemu-common-stub.c create mode 100644 trace/control-stub.c create mode 100644 trace/control-target.c
Quoted 4 lines
To: [email protected]
Cc: Stefan Hajnoczi <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: Eric Blake <[email protected]>
I left comments on individual patches.
There hasn't been any review from TCG folks yet. I have CCed Peter Maydell and Richard Henderson to review the TCG changes.
Stefan