[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 1/7] trace: Allocate cpu->trace_dstate in place
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [PULL 1/7] trace: Allocate cpu->trace_dstate in place |
Date: |
Mon, 17 Jul 2017 13:11:21 +0100 |
From: Lluís Vilanova <address@hidden>
There's little point in dynamically allocating the bitmap if we
know at compile-time the max number of events we want to support.
Thus, make room in the struct for the bitmap, which will make things
easier later: this paves the way for upcoming changes, in which
we'll use a u32 to fully capture cpu->trace_dstate.
This change also increases performance by saving a dereference and
improving locality--note that this is important since upcoming work
makes reading this bitmap fairly common.
Signed-off-by: Emilio G. Cota <address@hidden>
Reviewed-by: Lluís Vilanova <address@hidden>
Signed-off-by: Lluís Vilanova <address@hidden>
Message-id: address@hidden
Signed-off-by: Stefan Hajnoczi <address@hidden>
---
include/qom/cpu.h | 9 +++------
qom/cpu.c | 8 --------
trace/control.c | 9 ++++++++-
3 files changed, 11 insertions(+), 15 deletions(-)
diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index 04c31e6..5f188d4 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -259,6 +259,7 @@ typedef void (*run_on_cpu_func)(CPUState *cpu,
run_on_cpu_data data);
struct qemu_work_item;
#define CPU_UNSET_NUMA_NODE_ID -1
+#define CPU_TRACE_DSTATE_MAX_EVENTS 32
/**
* CPUState:
@@ -370,12 +371,8 @@ struct CPUState {
struct KVMState *kvm_state;
struct kvm_run *kvm_run;
- /*
- * Used for events with 'vcpu' and *without* the 'disabled' properties.
- * Dynamically allocated based on bitmap requried to hold up to
- * trace_get_vcpu_event_count() entries.
- */
- unsigned long *trace_dstate;
+ /* Used for events with 'vcpu' and *without* the 'disabled' properties */
+ DECLARE_BITMAP(trace_dstate, CPU_TRACE_DSTATE_MAX_EVENTS);
/* TODO Move common fields from CPUArchState here. */
int cpu_index; /* used by alpha TCG */
diff --git a/qom/cpu.c b/qom/cpu.c
index a39ff6c..4f38db0 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -380,7 +380,6 @@ static void cpu_common_unrealizefn(DeviceState *dev, Error
**errp)
static void cpu_common_initfn(Object *obj)
{
- uint32_t count;
CPUState *cpu = CPU(obj);
CPUClass *cc = CPU_GET_CLASS(obj);
@@ -395,18 +394,11 @@ static void cpu_common_initfn(Object *obj)
QTAILQ_INIT(&cpu->breakpoints);
QTAILQ_INIT(&cpu->watchpoints);
- count = trace_get_vcpu_event_count();
- if (count) {
- cpu->trace_dstate = bitmap_new(count);
- }
-
cpu_exec_initfn(cpu);
}
static void cpu_common_finalize(Object *obj)
{
- CPUState *cpu = CPU(obj);
- g_free(cpu->trace_dstate);
}
static int64_t cpu_common_get_arch_id(CPUState *cpu)
diff --git a/trace/control.c b/trace/control.c
index f5fb11d..82d8989 100644
--- a/trace/control.c
+++ b/trace/control.c
@@ -65,8 +65,15 @@ void trace_event_register_group(TraceEvent **events)
size_t i;
for (i = 0; events[i] != NULL; i++) {
events[i]->id = next_id++;
- if (events[i]->vcpu_id != TRACE_VCPU_EVENT_NONE) {
+ if (events[i]->vcpu_id == TRACE_VCPU_EVENT_NONE) {
+ continue;
+ }
+
+ if (likely(next_vcpu_id < CPU_TRACE_DSTATE_MAX_EVENTS)) {
events[i]->vcpu_id = next_vcpu_id++;
+ } else {
+ error_report("WARNING: too many vcpu trace events; dropping '%s'",
+ events[i]->name);
}
}
event_groups = g_renew(TraceEventGroup, event_groups, nevent_groups + 1);
--
2.9.4
- [Qemu-devel] [PULL 0/7] Tracing patches, Stefan Hajnoczi, 2017/07/17
- [Qemu-devel] [PULL 1/7] trace: Allocate cpu->trace_dstate in place,
Stefan Hajnoczi <=
- [Qemu-devel] [PULL 2/7] trace: [tcg] Delay changes to dynamic state when translating, Stefan Hajnoczi, 2017/07/17
- [Qemu-devel] [PULL 3/7] exec: [tcg] Use different TBs according to the vCPU's dynamic tracing state, Stefan Hajnoczi, 2017/07/17
- [Qemu-devel] [PULL 4/7] trace: [tcg] Do not generate TCG code to trace dynamically-disabled events, Stefan Hajnoczi, 2017/07/17
- [Qemu-devel] [PULL 5/7] trace: [tcg, trivial] Re-align generated code, Stefan Hajnoczi, 2017/07/17
- [Qemu-devel] [PULL 7/7] trace: update old trace events in docs, Stefan Hajnoczi, 2017/07/17
- [Qemu-devel] [PULL 6/7] trace: [trivial] Statically enable all guest events, Stefan Hajnoczi, 2017/07/17
- Re: [Qemu-devel] [PULL 0/7] Tracing patches, Peter Maydell, 2017/07/18