@@ -124,3 +124,12 @@ SYM_PUBLIC void qi_event_set_guest_cpu_enter(void (*fn)(QICPU vcpu))
ERROR_IF(!instr_get_state(), "called outside instrumentation");
instr_set_event(guest_cpu_enter, fn);
}
+
+
+void (*instr_event__guest_cpu_exit)(QICPU vcpu);
+
+SYM_PUBLIC void qi_event_set_guest_cpu_exit(void (*fn)(QICPU vcpu))
+{
+ ERROR_IF(!instr_get_state(), "called outside instrumentation");
+ instr_set_event(guest_cpu_exit, fn);
+}
@@ -36,6 +36,9 @@ extern void *instr_event__fini_data;
extern void (*instr_event__guest_cpu_enter)(QICPU vcpu);
static inline void instr_guest_cpu_enter(CPUState *vcpu);
+extern void (*instr_event__guest_cpu_exit)(QICPU vcpu);
+static inline void instr_guest_cpu_exit(CPUState *vcpu);
+
#include "instrument/events.inc.h"
@@ -20,3 +20,14 @@ static inline void instr_guest_cpu_enter(CPUState *vcpu)
instr_set_state(INSTR_STATE_DISABLE);
}
}
+
+static inline void instr_guest_cpu_exit(CPUState *vcpu)
+{
+ void (*cb)(QICPU vcpu) = instr_get_event(guest_cpu_exit);
+ if (cb) {
+ QICPU vcpu_ = instr_cpu_to_qicpu(vcpu);
+ instr_set_state(INSTR_STATE_ENABLE);
+ (*cb)(vcpu_);
+ instr_set_state(INSTR_STATE_DISABLE);
+ }
+}
@@ -11,7 +11,9 @@
#include "qemu-common.h"
#include <dlfcn.h>
+#include "cpu.h"
#include "exec/cpu-common.h"
+#include "exec/exec-all.h"
#include "instrument/control.h"
#include "instrument/events.h"
#include "instrument/load.h"
@@ -127,6 +129,13 @@ out:
return res;
}
+
+static void instr_unload__cb(CPUState *cpu, void *data)
+{
+ tb_flush_sync(cpu);
+ instr_guest_cpu_exit(cpu);
+}
+
InstrUnloadError instr_unload(const char *id)
{
InstrUnloadError res;
@@ -139,6 +148,10 @@ InstrUnloadError instr_unload(const char *id)
goto out;
}
+ InstrCPUStop info;
+ cpu_list_lock();
+ instr_cpu_stop_all_begin(&info, instr_unload__cb, NULL);
+
qi_fini_fn fini_fn = instr_get_event(fini_fn);
if (fini_fn) {
void *fini_data = instr_get_event(fini_data);
@@ -147,6 +160,10 @@ InstrUnloadError instr_unload(const char *id)
instr_set_event(fini_fn, NULL);
instr_set_event(guest_cpu_enter, NULL);
+ instr_set_event(guest_cpu_exit, NULL);
+
+ instr_cpu_stop_all_end(&info);
+ cpu_list_unlock();
/* this should never fail */
if (dlclose(handle->dlhandle) < 0) {
@@ -85,6 +85,17 @@ void qi_set_fini(qi_fini_fn fn, void *data);
*/
void qi_event_set_guest_cpu_enter(void (*fn)(QICPU vcpu));
+/*
+ * Hot-unplug a virtual (guest) CPU.
+ *
+ * Also triggered on each CPU when an instrumentation library is unloaded.
+ *
+ * Mode: user, softmmu
+ * Targets: all
+ * Time: exec
+ */
+void qi_event_set_guest_cpu_exit(void (*fn)(QICPU vcpu));
+
#ifdef __cplusplus
}
#endif
@@ -47,3 +47,4 @@ void qmp_instr_unload(const char *id, Error **errp)
__thread InstrState instr_cur_state;
void (*instr_event__guest_cpu_enter)(QICPU *vcpu);
+void (*instr_event__guest_cpu_exit)(QICPU *vcpu);
@@ -1,13 +1,14 @@
/*
* Interface for configuring and controlling the state of tracing events.
*
- * Copyright (C) 2011-2016 Lluís Vilanova <vilanova@ac.upc.edu>
+ * Copyright (C) 2011-2017 Lluís Vilanova <vilanova@ac.upc.edu>
*
* 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 "instrument/events.h"
#include "trace/control.h"
#include "qemu/help_option.h"
#ifdef CONFIG_TRACE_SIMPLE
@@ -272,6 +273,7 @@ void trace_fini_vcpu(CPUState *vcpu)
TraceEventIter iter;
TraceEvent *ev;
+ instr_guest_cpu_exit(vcpu);
trace_guest_cpu_exit(vcpu);
trace_event_iter_init(&iter, NULL);
Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu> --- instrument/control.c | 9 +++++++++ instrument/events.h | 3 +++ instrument/events.inc.h | 11 +++++++++++ instrument/load.c | 17 +++++++++++++++++ instrument/qemu-instr/control.h | 11 +++++++++++ stubs/instrument.c | 1 + trace/control.c | 4 +++- 7 files changed, 55 insertions(+), 1 deletion(-)