From 7de422834447b635fefe3a7a250e3b581ce4ae6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Tue, 13 Dec 2016 01:17:59 +0300 Subject: [PATCH 1/4] trace-events: spelling fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marc-André Lureau Message-id: 20161212221759.28949-1-marcandre.lureau@redhat.com Signed-off-by: Stefan Hajnoczi --- trace-events | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trace-events b/trace-events index 1181486454..2c66780706 100644 --- a/trace-events +++ b/trace-events @@ -53,7 +53,7 @@ qemu_system_shutdown_request(void) "" qemu_system_powerdown_request(void) "" # spice-qemu-char.c -spice_vmc_write(ssize_t out, int len) "spice wrottn %zd of requested %d" +spice_vmc_write(ssize_t out, int len) "spice wrote %zd of requested %d" spice_vmc_read(int bytes, int len) "spice read %d of requested %d" spice_vmc_register_interface(void *scd) "spice vmc registered interface %p" spice_vmc_unregister_interface(void *scd) "spice vmc unregistered interface %p" From fff895dfdbe41965f7b0430e3d9e8b7bd8fc8eda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs=20Vilanova?= Date: Mon, 26 Dec 2016 22:24:35 +0100 Subject: [PATCH 2/4] trace: Lock vCPU list when initializing dynamic tracing state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes potential corruption when a vCPU is hot-(un)plugged while initializing the current one. Signed-off-by: Lluís Vilanova Message-id: 148278747515.1404.6538173443841279200.stgit@fimbulvetr.bsc.es Signed-off-by: Stefan Hajnoczi --- trace/control-target.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/trace/control-target.c b/trace/control-target.c index 7ebf6e0bcb..e2e138a3f0 100644 --- a/trace/control-target.c +++ b/trace/control-target.c @@ -79,7 +79,7 @@ void trace_event_set_vcpu_state_dynamic(CPUState *vcpu, } } -static bool adding_first_cpu(void) +static bool adding_first_cpu1(void) { CPUState *cpu; size_t count = 0; @@ -92,6 +92,15 @@ static bool adding_first_cpu(void) return true; } +static bool adding_first_cpu(void) +{ + bool res; + cpu_list_lock(); + res = adding_first_cpu1(); + cpu_list_unlock(); + return res; +} + void trace_init_vcpu(CPUState *vcpu) { TraceEventIter iter; From 82e95ec847757c1a2b6accf0e8312925ada3dca8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs=20Vilanova?= Date: Mon, 26 Dec 2016 22:24:40 +0100 Subject: [PATCH 3/4] trace: Fix dynamic event state on vCPU hot-unplug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We need to disable per-vCPU events on a vCPU that is hot-unplugged to keep the dynamic event state global counters consistent. Signed-off-by: Lluís Vilanova Message-id: 148278748055.1404.1570530281528619895.stgit@fimbulvetr.bsc.es Signed-off-by: Stefan Hajnoczi --- qom/cpu.c | 2 ++ trace/control.c | 16 ++++++++++++++++ trace/control.h | 8 ++++++++ 3 files changed, 26 insertions(+) diff --git a/qom/cpu.c b/qom/cpu.c index 03d9190f8c..93e41056d9 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -348,6 +348,8 @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp) static void cpu_common_unrealizefn(DeviceState *dev, Error **errp) { CPUState *cpu = CPU(dev); + /* NOTE: latest generic point before the cpu is fully unrealized */ + trace_fini_vcpu(cpu); cpu_exec_unrealizefn(cpu); } diff --git a/trace/control.c b/trace/control.c index 1a7bee6ddc..cb79bb17ec 100644 --- a/trace/control.c +++ b/trace/control.c @@ -259,6 +259,22 @@ void trace_init_file(const char *file) #endif } +void trace_fini_vcpu(CPUState *vcpu) +{ + TraceEventIter iter; + TraceEvent *ev; + + trace_event_iter_init(&iter, NULL); + while ((ev = trace_event_iter_next(&iter)) != NULL) { + if (trace_event_is_vcpu(ev) && + trace_event_get_state_static(ev) && + trace_event_get_vcpu_state_dynamic(vcpu, ev)) { + /* must disable to affect the global counter */ + trace_event_set_vcpu_state_dynamic(vcpu, ev, false); + } + } +} + bool trace_init_backends(void) { #ifdef CONFIG_TRACE_SIMPLE diff --git a/trace/control.h b/trace/control.h index ccaeac8552..4ea53e2986 100644 --- a/trace/control.h +++ b/trace/control.h @@ -201,6 +201,14 @@ void trace_init_file(const char *file); */ void trace_init_vcpu(CPUState *vcpu); +/** + * trace_fini_vcpu: + * @vcpu: Removed vCPU. + * + * Disable dynamic event state for a hot-unplugged vCPU. + */ +void trace_fini_vcpu(CPUState *vcpu); + /** * trace_list_events: * From a47e87151e785977d34e7b726495e7781860ca9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs=20Vilanova?= Date: Mon, 26 Dec 2016 22:24:46 +0100 Subject: [PATCH 4/4] trace: Add event "guest_cpu_exit" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signals the hot-unplugging of a virtual (guest) CPU. Signed-off-by: Lluís Vilanova Message-id: 148278748597.1404.10546320797997984932.stgit@fimbulvetr.bsc.es Signed-off-by: Stefan Hajnoczi --- trace-events | 6 ++++++ trace/control.c | 3 +++ 2 files changed, 9 insertions(+) diff --git a/trace-events b/trace-events index 2c66780706..839a9d0fba 100644 --- a/trace-events +++ b/trace-events @@ -141,6 +141,12 @@ memory_region_ram_device_write(int cpu_index, void *mr, uint64_t addr, uint64_t # Targets: all vcpu guest_cpu_enter(void) +# Hot-unplug a virtual (guest) CPU +# +# Mode: user, softmmu +# Targets: all +vcpu guest_cpu_exit(void) + # Reset the state of a virtual (guest) CPU # # Mode: user, softmmu diff --git a/trace/control.c b/trace/control.c index cb79bb17ec..56a2632584 100644 --- a/trace/control.c +++ b/trace/control.c @@ -26,6 +26,7 @@ #include "qemu/error-report.h" #include "qemu/config-file.h" #include "monitor/monitor.h" +#include "trace.h" int trace_events_enabled_count; @@ -264,6 +265,8 @@ void trace_fini_vcpu(CPUState *vcpu) TraceEventIter iter; TraceEvent *ev; + trace_guest_cpu_exit(vcpu); + trace_event_iter_init(&iter, NULL); while ((ev = trace_event_iter_next(&iter)) != NULL) { if (trace_event_is_vcpu(ev) &&