From patchwork Thu Feb 25 15:03:06 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: 8424341 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 78D90C0553 for ; Thu, 25 Feb 2016 15:06:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A59662034C for ; Thu, 25 Feb 2016 15:06:23 +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 56B562028D for ; Thu, 25 Feb 2016 15:06:22 +0000 (UTC) Received: from localhost ([::1]:43831 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aYxUj-00059S-MJ for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Feb 2016 10:06:21 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36941) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aYxRv-0000Yh-P5 for qemu-devel@nongnu.org; Thu, 25 Feb 2016 10:03:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aYxRp-0008VA-Mm for qemu-devel@nongnu.org; Thu, 25 Feb 2016 10:03:27 -0500 Received: from roura.ac.upc.edu ([147.83.33.10]:37976 helo=roura.ac.upc.es) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aYxRp-0008V1-0n for qemu-devel@nongnu.org; Thu, 25 Feb 2016 10:03:21 -0500 Received: from gw-3.ac.upc.es (gw-3.ac.upc.es [147.83.30.9]) by roura.ac.upc.es (8.13.8/8.13.8) with ESMTP id u1PF37qp030995; Thu, 25 Feb 2016 16:03:07 +0100 Received: from localhost (unknown [84.88.51.85]) by gw-3.ac.upc.es (Postfix) with ESMTPSA id CE45F1F3; Thu, 25 Feb 2016 16:03:06 +0100 (CET) From: =?utf-8?b?TGx1w61z?= Vilanova To: qemu-devel@nongnu.org Date: Thu, 25 Feb 2016 16:03:06 +0100 Message-Id: <145641258612.30097.7127731954660712163.stgit@localhost> X-Mailer: git-send-email 2.7.0 In-Reply-To: <145641255678.30097.2919142707547689749.stgit@localhost> References: <145641255678.30097.2919142707547689749.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 u1PF37qp030995 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 147.83.33.10 Cc: Eduardo Habkost , Riku Voipio , Blue Swirl , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [Qemu-devel] [PATCH 4/6] trace: Add per-vCPU tracing states for events with the 'vcpu' property 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=-1.9 required=5.0 tests=BAYES_00, 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 Each vCPU gets a 'trace_dstate' bitmap to control the per-vCPU dynamic tracing state of events with the 'vcpu' property. Signed-off-by: Lluís Vilanova --- Makefile.objs | 1 + bsd-user/main.c | 2 + include/qom/cpu.h | 12 ++++++++ linux-user/main.c | 2 + qom/cpu.c | 1 + trace/Makefile.objs | 26 ++++++++++++++++++ trace/control-internal.h | 35 ++++++++++++++++++++---- trace/control-stub.c | 29 ++++++++++++++++++++ trace/control-target.c | 58 +++++++++++++++++++++++++++++++++++++++ trace/control.c | 25 ++++++++++++++++- trace/control.h | 68 +++++++++++++++++++++++++++++++++++++++++++++- vl.c | 1 + 12 files changed, 251 insertions(+), 9 deletions(-) create mode 100644 trace/control-stub.c create mode 100644 trace/control-target.c diff --git a/Makefile.objs b/Makefile.objs index fbcaa74..402efb3 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -103,6 +103,7 @@ version-lobj-$(CONFIG_WIN32) += $(BUILD_DIR)/version.lo # tracing util-obj-y += trace/ target-obj-y += trace/ +stub-obj-y += trace/ ###################################################################### # guest agent diff --git a/bsd-user/main.c b/bsd-user/main.c index 287ec1d..79d2ad0 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -25,6 +25,7 @@ /* For tb_lock */ #include "cpu.h" #include "tcg.h" +#include "trace/control.h" #include "qemu/timer.h" #include "qemu/envlist.h" #include "exec/log.h" @@ -1116,6 +1117,7 @@ int main(int argc, char **argv) gdbserver_start (gdbstub_port); gdb_handlesig(cpu, 0); } + trace_init_vcpu_events(); cpu_loop(env); /* never exits */ return 0; diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 1df7cb4..7e19be3 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -28,6 +28,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); @@ -266,6 +267,7 @@ 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. + * @trace_dstate: Dynamic tracing state of events for this vCPU. * * State of one CPU core or thread. */ @@ -332,6 +334,16 @@ struct CPUState { struct KVMState *kvm_state; struct kvm_run *kvm_run; +#define TRACE_VCPU_DSTATE_TYPE uint32_t + TRACE_VCPU_DSTATE_TYPE trace_dstate; + /* + * Ensure 'trace_dstate' can encode event states as a bitmask. This limits + * the number of events with the 'vcpu' property and *without* the + * 'disabled' property. + */ + bool too_many_vcpu_events[ + TRACE_VCPU_EVENT_COUNT > sizeof(TRACE_VCPU_DSTATE_TYPE)*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 */ diff --git a/linux-user/main.c b/linux-user/main.c index e719a2d..13ce851 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -25,6 +25,7 @@ #include "qemu-common.h" #include "cpu.h" #include "tcg.h" +#include "trace/control.h" #include "qemu/timer.h" #include "qemu/envlist.h" #include "elf.h" @@ -4650,6 +4651,7 @@ int main(int argc, char **argv, char **envp) } gdb_handlesig(cpu, 0); } + trace_init_vcpu_events(); cpu_loop(env); /* never exits */ return 0; diff --git a/qom/cpu.c b/qom/cpu.c index c45d0bb..7363776 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -330,6 +330,7 @@ static void cpu_common_initfn(Object *obj) qemu_mutex_init(&cpu->work_mutex); QTAILQ_INIT(&cpu->breakpoints); QTAILQ_INIT(&cpu->watchpoints); + cpu->trace_dstate = 0; } static void cpu_common_finalize(Object *obj) diff --git a/trace/Makefile.objs b/trace/Makefile.objs index 5145b34..902d47b 100644 --- a/trace/Makefile.objs +++ b/trace/Makefile.objs @@ -12,6 +12,8 @@ tracetool-y += $(shell find $(SRC_PATH)/scripts/tracetool -name "*.py") # Auto-generated event descriptions for LTTng ust code ifeq ($(findstring ust,$(TRACE_BACKENDS)),ust) + +ifndef MAKEFILE_GUARD_TRACE $(obj)/generated-ust-provider.h: $(obj)/generated-ust-provider.h-timestamp @cmp $< $@ >/dev/null 2>&1 || cp $< $@ $(obj)/generated-ust-provider.h-timestamp: $(SRC_PATH)/trace-events $(tracetool-y) @@ -30,11 +32,14 @@ $(obj)/generated-ust.c-timestamp: $(SRC_PATH)/trace-events $(tracetool-y) $(obj)/generated-events.h: $(obj)/generated-ust-provider.h $(obj)/generated-events.c: $(obj)/generated-ust.c +endif # MAKEFILE_GUARD_TRACE + endif ###################################################################### # Auto-generated event descriptions +ifndef MAKEFILE_GUARD_TRACE $(obj)/generated-events.h: $(obj)/generated-events.h-timestamp @cmp $< $@ >/dev/null 2>&1 || cp $< $@ $(obj)/generated-events.h-timestamp: $(SRC_PATH)/trace-events $(tracetool-y) @@ -50,6 +55,7 @@ $(obj)/generated-events.c-timestamp: $(SRC_PATH)/trace-events $(tracetool-y) --format=events-c \ --backends=$(TRACE_BACKENDS) \ < $< > $@," GEN $(patsubst %-timestamp,%,$@)") +endif # MAKEFILE_GUARD_TRACE util-obj-y += generated-events.o @@ -60,6 +66,7 @@ util-obj-y += generated-events.o ################################################## # Execution level +ifndef MAKEFILE_GUARD_TRACE $(obj)/generated-tracers.h: $(obj)/generated-tracers.h-timestamp @cmp -s $< $@ || cp $< $@ $(obj)/generated-tracers.h-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak $(tracetool-y) @@ -67,10 +74,12 @@ $(obj)/generated-tracers.h-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/conf --format=h \ --backends=$(TRACE_BACKENDS) \ < $< > $@," GEN $(patsubst %-timestamp,%,$@)") +endif # MAKEFILE_GUARD_TRACE ############################## # non-DTrace +ifndef MAKEFILE_GUARD_TRACE $(obj)/generated-tracers.c: $(obj)/generated-tracers.c-timestamp @cmp -s $< $@ || cp $< $@ $(obj)/generated-tracers.c-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak $(tracetool-y) @@ -80,6 +89,7 @@ $(obj)/generated-tracers.c-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/conf < $< > $@," GEN $(patsubst %-timestamp,%,$@)") $(obj)/generated-tracers.o: $(obj)/generated-tracers.c $(obj)/generated-tracers.h +endif # MAKEFILE_GUARD_TRACE ############################## # DTrace @@ -88,6 +98,8 @@ $(obj)/generated-tracers.o: $(obj)/generated-tracers.c $(obj)/generated-tracers. # but that gets picked up by QEMU's Makefile as an external dependency # rule file. So we use '.dtrace' instead ifeq ($(findstring dtrace,$(TRACE_BACKENDS)),dtrace) + +ifndef MAKEFILE_GUARD_TRACE $(obj)/generated-tracers-dtrace.dtrace: $(obj)/generated-tracers-dtrace.dtrace-timestamp @cmp $< $@ >/dev/null 2>&1 || cp $< $@ $(obj)/generated-tracers-dtrace.dtrace-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak $(tracetool-y) @@ -100,6 +112,7 @@ $(obj)/generated-tracers-dtrace.h: $(obj)/generated-tracers-dtrace.dtrace $(call quiet-command,dtrace -o $@ -h -s $<, " GEN $@") $(obj)/generated-tracers-dtrace.o: $(obj)/generated-tracers-dtrace.dtrace +endif # MAKEFILE_GUARD_TRACE util-obj-y += generated-tracers-dtrace.o endif @@ -107,6 +120,7 @@ endif ################################################## # Translation level +ifndef MAKEFILE_GUARD_TRACE $(obj)/generated-helpers-wrappers.h: $(obj)/generated-helpers-wrappers.h-timestamp @cmp $< $@ >/dev/null 2>&1 || cp $< $@ $(obj)/generated-helpers-wrappers.h-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak $(tracetool-y) @@ -132,10 +146,12 @@ $(obj)/generated-helpers.c-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/conf < $< > $@," GEN $(patsubst %-timestamp,%,$@)") $(obj)/generated-helpers.o: $(obj)/generated-helpers.c +endif # MAKEFILE_GUARD_TRACE target-obj-y += generated-helpers.o +ifndef MAKEFILE_GUARD_TRACE $(obj)/generated-tcg-tracers.h: $(obj)/generated-tcg-tracers.h-timestamp @cmp $< $@ >/dev/null 2>&1 || cp $< $@ $(obj)/generated-tcg-tracers.h-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak $(tracetool-y) @@ -143,6 +159,7 @@ $(obj)/generated-tcg-tracers.h-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/ --format=tcg-h \ --backend=$(TRACE_BACKENDS) \ < $< > $@," GEN $(patsubst %-timestamp,%,$@)") +endif # MAKEFILE_GUARD_TRACE ###################################################################### @@ -152,4 +169,13 @@ 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 + + +###################################################################### +# Avoid rule overrides when included from multiple top-level variables +ifndef MAKEFILE_GUARD_TRACE +MAKEFILE_GUARD_TRACE = 1 +endif diff --git a/trace/control-internal.h b/trace/control-internal.h index d1f99e3..2189063 100644 --- a/trace/control-internal.h +++ b/trace/control-internal.h @@ -10,10 +10,13 @@ #ifndef TRACE__CONTROL_INTERNAL_H #define TRACE__CONTROL_INTERNAL_H +#include /* size_t */ + +#include "qom/cpu.h" extern TraceEvent trace_events[]; -extern bool trace_events_dstate[]; +extern size_t trace_events_dstate[]; extern int trace_events_enabled_count; @@ -22,6 +25,11 @@ static inline TraceEventID trace_event_count(void) return TRACE_EVENT_COUNT; } +static inline TraceEventVCPUID trace_event_cpu_count(void) +{ + return TRACE_VCPU_EVENT_COUNT; +} + static inline TraceEvent *trace_event_id(TraceEventID id) { assert(id < trace_event_count()); @@ -61,7 +69,7 @@ static inline bool trace_event_get_state_static(TraceEvent *ev) static inline bool trace_event_get_state_dynamic_by_id(TraceEventID id) { /* it's on fast path, avoid consistency checks (asserts) */ - return unlikely(trace_events_enabled_count) && trace_events_dstate[id]; + return unlikely(trace_events_enabled_count) && (trace_events_dstate[id] > 0); } static inline bool trace_event_get_state_dynamic(TraceEvent *ev) @@ -73,13 +81,28 @@ static inline bool trace_event_get_state_dynamic(TraceEvent *ev) return trace_event_get_state_dynamic_by_id(id); } -static inline void trace_event_set_state_dynamic(TraceEvent *ev, bool state) +static inline bool trace_event_get_cpu_state_dynamic_by_cpu_id(CPUState *cpu, + TraceEventVCPUID id) +{ + /* it's on fast path, avoid consistency checks (asserts) */ + if (unlikely(trace_events_enabled_count)) { + TRACE_VCPU_DSTATE_TYPE bit = ((TRACE_VCPU_DSTATE_TYPE)1) << id; + return cpu->trace_dstate & bit; + } else { + return false; + } +} + +static inline bool trace_event_get_cpu_state_dynamic(CPUState *cpu, + TraceEvent *ev) { - int id = trace_event_get_id(ev); + TraceEventVCPUID id; + assert(cpu != NULL); assert(ev != NULL); assert(trace_event_get_state_static(ev)); - trace_events_enabled_count += state - trace_events_dstate[id]; - trace_events_dstate[id] = state; + assert(trace_event_get_cpu_id(ev) != trace_event_cpu_count()); + id = trace_event_get_cpu_id(ev); + return trace_event_get_cpu_state_dynamic_by_cpu_id(cpu, id); } #endif /* TRACE__CONTROL_INTERNAL_H */ diff --git a/trace/control-stub.c b/trace/control-stub.c new file mode 100644 index 0000000..858b13e --- /dev/null +++ b/trace/control-stub.c @@ -0,0 +1,29 @@ +/* + * Interface for configuring and controlling the state of tracing events. + * + * Copyright (C) 2014-2016 Lluís Vilanova + * + * 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/osdep.h" +#include "trace/control.h" + + +void trace_event_set_state_dynamic(TraceEvent *ev, bool state) +{ + TraceEventID id; + assert(ev != NULL); + assert(trace_event_get_state_static(ev)); + id = trace_event_get_id(ev); + trace_events_enabled_count += state - trace_events_dstate[id]; + trace_events_dstate[id] = state; +} + +void trace_event_set_cpu_state_dynamic(CPUState *cpu, + TraceEvent *ev, bool state) +{ + /* should never be called on non-target binaries */ + abort(); +} diff --git a/trace/control-target.c b/trace/control-target.c new file mode 100644 index 0000000..5ae672e --- /dev/null +++ b/trace/control-target.c @@ -0,0 +1,58 @@ +/* + * Interface for configuring and controlling the state of tracing events. + * + * Copyright (C) 2014-2016 Lluís Vilanova + * + * 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/osdep.h" +#include "cpu.h" +#include "trace/control.h" +#include "translate-all.h" + + +void trace_event_set_state_dynamic(TraceEvent *ev, bool state) +{ + CPUState *cpu; + assert(ev != NULL); + assert(trace_event_get_state_static(ev)); + if (trace_event_get_cpu_id(ev) != trace_event_cpu_count()) { + CPU_FOREACH(cpu) { + trace_event_set_cpu_state_dynamic(cpu, ev, state); + } + } else { + TraceEventID id = trace_event_get_id(ev); + trace_events_enabled_count += state - trace_events_dstate[id]; + trace_events_dstate[id] = state; + } +} + +void trace_event_set_cpu_state_dynamic(CPUState *cpu, + TraceEvent *ev, bool state) +{ + TraceEventID id; + TraceEventVCPUID cpu_id; + TRACE_VCPU_DSTATE_TYPE bit; + bool state_pre; + assert(cpu != NULL); + assert(ev != NULL); + assert(trace_event_get_state_static(ev)); + assert(trace_event_get_cpu_id(ev) != trace_event_cpu_count()); + id = trace_event_get_id(ev); + cpu_id = trace_event_get_cpu_id(ev); + bit = ((TRACE_VCPU_DSTATE_TYPE)1) << cpu_id; + state_pre = cpu->trace_dstate & bit; + if ((state_pre == 0) != (state == 0)) { + if (state) { + trace_events_enabled_count++; + cpu->trace_dstate |= bit; + trace_events_dstate[id]++; + } else { + trace_events_enabled_count--; + cpu->trace_dstate &= ~bit; + trace_events_dstate[id]--; + } + } +} diff --git a/trace/control.c b/trace/control.c index 20d3370..501dc29 100644 --- a/trace/control.c +++ b/trace/control.c @@ -1,7 +1,7 @@ /* * Interface for configuring and controlling the state of tracing events. * - * Copyright (C) 2011-2014 Lluís Vilanova + * Copyright (C) 2011-2016 Lluís Vilanova * * This work is licensed under the terms of the GNU GPL, version 2 or later. * See the COPYING file in the top-level directory. @@ -21,7 +21,10 @@ #include "qemu/error-report.h" int trace_events_enabled_count; -bool trace_events_dstate[TRACE_EVENT_COUNT]; +/* With the 'vcpu' property, counts how many vCPUs have it enabled. */ +size_t trace_events_dstate[TRACE_EVENT_COUNT]; +/* Marks events for late vCPU state init */ +static bool trace_events_dstate_init[TRACE_EVENT_COUNT]; TraceEvent *trace_event_name(const char *name) { @@ -110,7 +113,10 @@ static void do_trace_enable_events(const char *line_buf) TraceEvent *ev = NULL; while ((ev = trace_event_pattern(line_ptr, ev)) != NULL) { if (trace_event_get_state_static(ev)) { + /* start tracing */ trace_event_set_state_dynamic(ev, enable); + /* mark for late vCPU init */ + trace_events_dstate_init[ev->id] = true; } } } else { @@ -122,7 +128,10 @@ static void do_trace_enable_events(const char *line_buf) error_report("WARNING: trace event '%s' is not traceable", line_ptr); } else { + /* start tracing */ trace_event_set_state_dynamic(ev, enable); + /* mark for late vCPU init */ + trace_events_dstate_init[ev->id] = true; } } } @@ -212,3 +221,15 @@ bool trace_init_backends(void) return true; } + +void trace_init_vcpu_events(void) +{ + TraceEvent *ev = NULL; + while ((ev = trace_event_pattern("*", ev)) != NULL) { + if (trace_event_get_cpu_id(ev) != trace_event_cpu_count() && + trace_event_get_state_static(ev) && + trace_events_dstate_init[ev->id]) { + trace_event_set_state_dynamic(ev, true); + } + } +} diff --git a/trace/control.h b/trace/control.h index f014e11..fb7d18e 100644 --- a/trace/control.h +++ b/trace/control.h @@ -77,6 +77,13 @@ static bool trace_event_is_pattern(const char *str); */ static TraceEventID trace_event_count(void); +/** + * trace_event_cpu_count: + * + * Return the number of events with the 'vcpu' property. + */ +static TraceEventVCPUID trace_event_cpu_count(void); + /** @@ -118,6 +125,23 @@ static const char * trace_event_get_name(TraceEvent *ev); ((id ##_ENABLED) && trace_event_get_state_dynamic_by_id(id)) /** + * trace_event_get_cpu_state: + * @cpu: Target vCPU. + * @id: Event identifier (TraceEventID). + * @cpu_id: Per-vCPU event identifier (TraceEventVCPUID). + * + * Get the tracing state of an event (both static and dynamic) for the given + * vCPU. + * + * If the event has the disabled property, the check will have no performance + * impact. + * + * As a down side, you must always use an immediate #TraceEventID value. + */ +#define trace_event_get_cpu_state(cpu, id, cpu_id) \ + ((id ##_ENABLED) && trace_event_get_cpu_state_dynamic_by_cpu_id(cpu, cpu_id)) + +/** * trace_event_get_state_static: * @id: Event identifier. * @@ -132,10 +156,19 @@ static bool trace_event_get_state_static(TraceEvent *ev); * trace_event_get_state_dynamic: * * Get the dynamic tracing state of an event. + * + * If the event has the 'vcpu' property, gets the OR'ed state of all vCPUs. */ static bool trace_event_get_state_dynamic(TraceEvent *ev); /** + * trace_event_get_cpu_state_dynamic: + * + * Get the dynamic tracing state of an event for the given vCPU. + */ +static bool trace_event_get_cpu_state_dynamic(CPUState *cpu, TraceEvent *ev); + +/** * trace_event_set_state: * * Set the tracing state of an event (only if possible). @@ -149,13 +182,38 @@ static bool trace_event_get_state_dynamic(TraceEvent *ev); } while (0) /** + * trace_event_set_cpu_state: + * + * Set the tracing state of an event for the given vCPU (only if not disabled). + */ +#define trace_event_set_cpu_state(cpu, id, state) \ + do { \ + if ((id ##_ENABLED)) { \ + TraceEvent *_e = trace_event_id(id); \ + trace_event_set_cpu_state_dynamic(cpu, _e, state); \ + } \ + } while (0) + +/** * trace_event_set_state_dynamic: * * Set the dynamic tracing state of an event. * + * If the event has the 'vcpu' property, sets the state on all vCPUs. + * * Pre-condition: trace_event_get_state_static(ev) == true */ -static void trace_event_set_state_dynamic(TraceEvent *ev, bool state); +void trace_event_set_state_dynamic(TraceEvent *ev, bool state); + +/** + * trace_event_set_cpu_state_dynamic: + * + * Set the dynamic tracing state of an event for the given vCPU. + * + * Pre-condition: trace_event_get_cpu_state_static(ev) == true + */ +void trace_event_set_cpu_state_dynamic(CPUState *cpu, + TraceEvent *ev, bool state); @@ -208,6 +266,14 @@ void trace_list_events(void); */ void trace_enable_events(const char *line_buf); +/** + * trace_init_vcpu_events: + * + * Re-synchronize initial event state with vCPUs (which can be created after + * trace_init_events()). + */ +void trace_init_vcpu_events(void); + #include "trace/control-internal.h" diff --git a/vl.c b/vl.c index adeddd9..7a1d7f6 100644 --- a/vl.c +++ b/vl.c @@ -4642,6 +4642,7 @@ int main(int argc, char **argv, char **envp) os_setup_post(); + trace_init_vcpu_events(); main_loop(); replay_disable_events();