From 2bfe11c8fac96db4f94abbe818fbc964a6744130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs=20Vilanova?= Date: Mon, 19 Sep 2016 14:55:07 +0200 Subject: trace: Properly initialize dynamic event states in hot-plugged vCPUs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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Ă­s Vilanova Message-id: 147428970768.15111.7664565956870423529.stgit@fimbulvetr.bsc.es Signed-off-by: Stefan Hajnoczi --- trace/control-target.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'trace/control-target.c') diff --git a/trace/control-target.c b/trace/control-target.c index 72081e2a34..3b7d99b44c 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 = 0; + CPU_FOREACH(cpu) { + count++; + if (count > 1) { + return false; + } + } + return true; +} + +void trace_init_vcpu(CPUState *vcpu) +{ + TraceEvent *ev = NULL; + + while ((ev = trace_event_pattern("*", ev)) != NULL) { + if (trace_event_is_vcpu(ev) && + trace_event_get_state_static(ev) && + trace_event_get_state_dynamic(ev)) { + TraceEventID id = trace_event_get_id(ev); + if (adding_first_cpu()) { + /* check preconditions */ + assert(trace_events_dstate[id] == 1); + /* disable early-init state ... */ + trace_events_dstate[id] = 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); + } + } + } +} -- cgit v1.2.3