[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v6 11/22] instrument: Track vCPUs
From: |
Lluís Vilanova |
Subject: |
[Qemu-devel] [PATCH v6 11/22] instrument: Track vCPUs |
Date: |
Wed, 13 Sep 2017 13:38:05 +0300 |
User-agent: |
StGit/0.18 |
Keep a translation between instrumentation's QICPU and CPUState objects to avoid
exposing QEMU's internals to instrumentation clients.
Signed-off-by: Lluís Vilanova <address@hidden>
---
cpus-common.c | 9 +++++++++
instrument/control.c | 23 +++++++++++++++++++++++
instrument/control.h | 36 ++++++++++++++++++++++++++++++++++++
instrument/control.inc.h | 23 +++++++++++++++++++++++
4 files changed, 91 insertions(+)
diff --git a/cpus-common.c b/cpus-common.c
index 59f751ecf9..ec5f46cc3d 100644
--- a/cpus-common.c
+++ b/cpus-common.c
@@ -22,6 +22,9 @@
#include "exec/cpu-common.h"
#include "qom/cpu.h"
#include "sysemu/cpus.h"
+#if defined(CONFIG_INSTRUMENT)
+#include "instrument/control.h"
+#endif
static QemuMutex qemu_cpu_list_lock;
static QemuCond exclusive_cond;
@@ -84,6 +87,9 @@ void cpu_list_add(CPUState *cpu)
} else {
assert(!cpu_index_auto_assigned);
}
+#if defined(CONFIG_INSTRUMENT)
+ instr_cpu_add(cpu);
+#endif
QTAILQ_INSERT_TAIL(&cpus, cpu, node);
qemu_mutex_unlock(&qemu_cpu_list_lock);
@@ -102,6 +108,9 @@ void cpu_list_remove(CPUState *cpu)
assert(!(cpu_index_auto_assigned && cpu != QTAILQ_LAST(&cpus, CPUTailQ)));
QTAILQ_REMOVE(&cpus, cpu, node);
+#if defined(CONFIG_INSTRUMENT)
+ instr_cpu_remove(cpu);
+#endif
cpu->cpu_index = UNASSIGNED_CPU_INDEX;
qemu_mutex_unlock(&qemu_cpu_list_lock);
}
diff --git a/instrument/control.c b/instrument/control.c
index 3630d6b3be..8cf2b4f967 100644
--- a/instrument/control.c
+++ b/instrument/control.c
@@ -13,10 +13,33 @@
#include "instrument/load.h"
#include "instrument/qemu-instr/control.h"
#include "qemu/compiler.h"
+#include "qom/cpu.h"
+
__thread InstrState instr_cur_state;
+unsigned int instr_cpus_count;
+CPUState **instr_cpus;
+
+void instr_cpu_add(CPUState *vcpu)
+{
+ unsigned int idx = vcpu->cpu_index;
+ if (idx >= instr_cpus_count) {
+ instr_cpus_count = idx + 1;
+ instr_cpus = realloc(instr_cpus,
+ sizeof(*instr_cpus) * instr_cpus_count);
+ }
+ instr_cpus[idx] = vcpu;
+}
+
+void instr_cpu_remove(CPUState *vcpu)
+{
+ unsigned int idx = vcpu->cpu_index;
+ instr_cpus[idx] = NULL;
+}
+
+
qi_fini_fn instr_event__fini_fn;
void *instr_event__fini_data;
diff --git a/instrument/control.h b/instrument/control.h
index f2b085f69b..57cea07fa7 100644
--- a/instrument/control.h
+++ b/instrument/control.h
@@ -10,6 +10,42 @@
#ifndef INSTRUMENT__CONTROL_H
#define INSTRUMENT__CONTROL_H
+#include "qemu/typedefs.h"
+#include "instrument/qemu-instr/types.h"
+
+
+/**
+ * instr_cpu_add:
+ *
+ * Make @vcpu available to instrumentation clients.
+ *
+ * Precondition: cpu_list_lock().
+ */
+void instr_cpu_add(CPUState *vcpu);
+
+/**
+ * instr_cpu_remove:
+ *
+ * Make @vcpu unavailable to instrumentation clients.
+ *
+ * Precondition: cpu_list_lock().
+ */
+void instr_cpu_remove(CPUState *vcpu);
+
+/**
+ * instr_cpu_to_qicpu:
+ *
+ * Get the #QICPU corresponding to the given #CPUState.
+ */
+static inline QICPU instr_cpu_to_qicpu(CPUState *vcpu);
+
+/**
+ * instr_cpu_from_qicpu:
+ *
+ * Get the #CPUState corresponding to the given #QICPU.
+ */
+static inline CPUState *instr_cpu_from_qicpu(QICPU vcpu);
+
/**
* InstrState:
diff --git a/instrument/control.inc.h b/instrument/control.inc.h
index 0f649f4caa..45daae7d1d 100644
--- a/instrument/control.inc.h
+++ b/instrument/control.inc.h
@@ -7,9 +7,32 @@
* See the COPYING file in the top-level directory.
*/
+#include "qemu/osdep.h"
#include "qemu/atomic.h"
#include "qemu/compiler.h"
+#include "qom/cpu.h"
#include <stdbool.h>
+#include <stdint.h>
+
+
+extern unsigned int instr_cpus_count;
+extern CPUState **instr_cpus;
+
+static inline QICPU instr_cpu_to_qicpu(CPUState *vcpu)
+{
+ uintptr_t idx = vcpu->cpu_index;
+ return (QICPU)idx;
+}
+
+static inline CPUState *instr_cpu_from_qicpu(QICPU vcpu)
+{
+ unsigned int idx = (uintptr_t)vcpu;
+ if (idx >= instr_cpus_count) {
+ return NULL;
+ } else {
+ return instr_cpus[idx];
+ }
+}
extern __thread InstrState instr_cur_state;
- [Qemu-devel] [PATCH v6 01/22] instrument: Add documentation, (continued)
- [Qemu-devel] [PATCH v6 01/22] instrument: Add documentation, Lluís Vilanova, 2017/09/13
- [Qemu-devel] [PATCH v6 02/22] instrument: Add configure-time flag, Lluís Vilanova, 2017/09/13
- [Qemu-devel] [PATCH v6 03/22] instrument: Add generic library loader, Lluís Vilanova, 2017/09/13
- [Qemu-devel] [PATCH v6 04/22] instrument: [linux-user] Add command line library loader, Lluís Vilanova, 2017/09/13
- [Qemu-devel] [PATCH v6 05/22] instrument: [bsd-user] Add command line library loader, Lluís Vilanova, 2017/09/13
- [Qemu-devel] [PATCH v6 06/22] instrument: [softmmu] Add command line library loader, Lluís Vilanova, 2017/09/13
- [Qemu-devel] [PATCH v6 07/22] instrument: [qapi] Add library loader, Lluís Vilanova, 2017/09/13
- [Qemu-devel] [PATCH v6 08/22] instrument: [hmp] Add library loader, Lluís Vilanova, 2017/09/13
- [Qemu-devel] [PATCH v6 09/22] instrument: Add basic control interface, Lluís Vilanova, 2017/09/13
- [Qemu-devel] [PATCH v6 10/22] instrument: Add support for tracing events, Lluís Vilanova, 2017/09/13
- [Qemu-devel] [PATCH v6 11/22] instrument: Track vCPUs,
Lluís Vilanova <=
- [Qemu-devel] [PATCH v6 12/22] instrument: Add event 'guest_cpu_enter', Lluís Vilanova, 2017/09/13
- [Qemu-devel] [PATCH v6 13/22] instrument: Support synchronous modification of vCPU state, Lluís Vilanova, 2017/09/13
- [Qemu-devel] [PATCH v6 14/22] exec: Add function to synchronously flush TB on a stopped vCPU, Lluís Vilanova, 2017/09/13
- [Qemu-devel] [PATCH v6 15/22] instrument: Add event 'guest_cpu_exit', Lluís Vilanova, 2017/09/13
- [Qemu-devel] [PATCH v6 16/22] instrument: Add event 'guest_cpu_reset', Lluís Vilanova, 2017/09/13
- [Qemu-devel] [PATCH v6 17/22] trace: Introduce a proper structure to describe memory accesses, Lluís Vilanova, 2017/09/13
- [Qemu-devel] [PATCH v6 18/22] instrument: Add event 'guest_mem_before_trans', Lluís Vilanova, 2017/09/13
- [Qemu-devel] [PATCH v6 19/22] instrument: Add event 'guest_mem_before_exec', Lluís Vilanova, 2017/09/13
- [Qemu-devel] [PATCH v6 20/22] instrument: Add event 'guest_user_syscall', Lluís Vilanova, 2017/09/13
- [Qemu-devel] [PATCH v6 21/22] instrument: Add event 'guest_user_syscall_ret', Lluís Vilanova, 2017/09/13