Received: from eggs.gnu.org ([2001:4830:134:3::10]:51088) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpMSH-0001EU-MA for qemu-devel@nongnu.org; Wed, 28 Sep 2016 17:31:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bpMSD-00051P-O9 for qemu-devel@nongnu.org; Wed, 28 Sep 2016 17:31:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53676) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpMSD-00051H-Ec for qemu-devel@nongnu.org; Wed, 28 Sep 2016 17:31:49 -0400 From: Stefan Hajnoczi Date: Wed, 28 Sep 2016 22:31:30 +0100 Message-Id: <1475098293-13262-6-git-send-email-stefanha@redhat.com> In-Reply-To: <1475098293-13262-1-git-send-email-stefanha@redhat.com> References: <1475098293-13262-1-git-send-email-stefanha@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 5/8] trace: Properly initialize dynamic event states in hot-plugged vCPUs List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , =?UTF-8?q?Llu=C3=ADs=20Vilanova?= , Stefan Hajnoczi From: Llu=C3=ADs Vilanova Every time a vCPU is hot-plugged, it will "inherit" its tracing state from the global state array. That is, if *any* existing vCPU has an event enabled, new vCPUs will have too. Signed-off-by: Llu=C3=ADs Vilanova Message-id: 147428970768.15111.7664565956870423529.stgit@fimbulvetr.bsc.e= s Signed-off-by: Stefan Hajnoczi --- bsd-user/main.c | 1 - linux-user/main.c | 1 - qom/cpu.c | 3 +++ stubs/trace-control.c | 6 ++++++ trace/control-target.c | 37 +++++++++++++++++++++++++++++++++++++ trace/control.c | 19 ------------------- trace/control.h | 19 ++++++++----------- vl.c | 1 - 8 files changed, 54 insertions(+), 33 deletions(-) diff --git a/bsd-user/main.c b/bsd-user/main.c index 0fb08e4..f58bb43 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -1133,7 +1133,6 @@ 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/linux-user/main.c b/linux-user/main.c index 8daebe0..424f2b6 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -4800,7 +4800,6 @@ 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 f783b5a..f87fffa 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -333,6 +333,9 @@ static void cpu_common_realizefn(DeviceState *dev, Er= ror **errp) cpu_synchronize_post_init(cpu); cpu_resume(cpu); } + + /* NOTE: latest generic point where the cpu is fully realized */ + trace_init_vcpu(cpu); } =20 static void cpu_common_initfn(Object *obj) diff --git a/stubs/trace-control.c b/stubs/trace-control.c index 2dfcd9f..f765a02 100644 --- a/stubs/trace-control.c +++ b/stubs/trace-control.c @@ -44,3 +44,9 @@ void trace_event_set_vcpu_state_dynamic(CPUState *vcpu, /* should never be called on non-target binaries */ abort(); } + +void trace_init_vcpu(CPUState *vcpu) +{ + /* should never be called on non-target binaries */ + abort(); +} diff --git a/trace/control-target.c b/trace/control-target.c index 72081e2..3b7d99b 100644 --- a/trace/control-target.c +++ b/trace/control-target.c @@ -81,3 +81,40 @@ void trace_event_set_vcpu_state_dynamic(CPUState *vcpu= , } } } + +static bool adding_first_cpu(void) +{ + CPUState *cpu; + size_t count =3D 0; + CPU_FOREACH(cpu) { + count++; + if (count > 1) { + return false; + } + } + return true; +} + +void trace_init_vcpu(CPUState *vcpu) +{ + TraceEvent *ev =3D NULL; + + while ((ev =3D trace_event_pattern("*", ev)) !=3D NULL) { + if (trace_event_is_vcpu(ev) && + trace_event_get_state_static(ev) && + trace_event_get_state_dynamic(ev)) { + TraceEventID id =3D trace_event_get_id(ev); + if (adding_first_cpu()) { + /* check preconditions */ + assert(trace_events_dstate[id] =3D=3D 1); + /* disable early-init state ... */ + trace_events_dstate[id] =3D 0; + trace_events_enabled_count--; + /* ... and properly re-enable */ + trace_event_set_vcpu_state_dynamic(vcpu, ev, true); + } else { + trace_event_set_vcpu_state_dynamic(vcpu, ev, true); + } + } + } +} diff --git a/trace/control.c b/trace/control.c index 05d85ac..10b3e9b 100644 --- a/trace/control.c +++ b/trace/control.c @@ -269,22 +269,3 @@ char *trace_opt_parse(const char *optarg) =20 return trace_file; } - -void trace_init_vcpu_events(void) -{ - TraceEvent *ev =3D NULL; - while ((ev =3D trace_event_pattern("*", ev)) !=3D NULL) { - if (trace_event_is_vcpu(ev) && - trace_event_get_state_static(ev) && - trace_event_get_state_dynamic(ev)) { - TraceEventID id =3D trace_event_get_id(ev); - /* check preconditions */ - assert(trace_events_dstate[id] =3D=3D 1); - /* disable early-init state ... */ - trace_events_dstate[id] =3D 0; - trace_events_enabled_count--; - /* ... and properly re-enable */ - trace_event_set_state_dynamic(ev, true); - } - } -} diff --git a/trace/control.h b/trace/control.h index 27a16fc..a22d112 100644 --- a/trace/control.h +++ b/trace/control.h @@ -239,6 +239,14 @@ bool trace_init_backends(void); void trace_init_file(const char *file); =20 /** + * trace_init_vcpu: + * @vcpu: Added vCPU. + * + * Set initial dynamic event state for a hot-plugged vCPU. + */ +void trace_init_vcpu(CPUState *vcpu); + +/** * trace_list_events: * * List all available events. @@ -269,17 +277,6 @@ extern QemuOptsList qemu_trace_opts; */ char *trace_opt_parse(const char *optarg); =20 -/** - * trace_init_vcpu_events: - * - * Re-synchronize initial event state with vCPUs (which can be created a= fter - * trace_init_events()). - * - * Precondition: event states won't be changed between trace_enable_even= ts() and - * trace_init_vcpu_events() (e.g., through QMP). - */ -void trace_init_vcpu_events(void); - =20 #include "trace/control-internal.h" =20 diff --git a/vl.c b/vl.c index eafda8d..04fc172 100644 --- a/vl.c +++ b/vl.c @@ -4658,7 +4658,6 @@ int main(int argc, char **argv, char **envp) =20 os_setup_post(); =20 - trace_init_vcpu_events(); main_loop(); replay_disable_events(); iothread_stop_all(); --=20 2.7.4