qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH for-2.8 v1 09/60] trace: remove use of TRACE_VCPU_EV


From: Daniel P. Berrange
Subject: [Qemu-devel] [PATCH for-2.8 v1 09/60] trace: remove use of TRACE_VCPU_EVENT_COUNT in cpu.h
Date: Tue, 9 Aug 2016 16:31:37 +0100

The CPUState struct has a bitmap tracking which VCPU
events are currently active. This is indexed based on
the event ID values, and sized according the maximum
TraceEventVCPUID enum value. Since there will the
possibility of having multiple event groups, the
indexes will potentially overlap.

Rather than creating a more complex 2 dimensional
data structure in CPUState, make an assumption that
all the per-VCPU events will be defined in the same
event group. Do a sanity check for this assumption
when registering event groups.

In addition, rather than using the TRACE_VCPU_EVENT_COUNT
constant, which requires pulling in the enourmous trace
events header, define a fixed bitmap size, which allows
for 32 events. This will suffice for the immediate future
and can be easily raised later if needed.

With this change, the cpu.h file no longer has a direct
dependancy on the generate events header file.

Signed-off-by: Daniel P. Berrange <address@hidden>
---
 include/qom/cpu.h | 10 ++++++++--
 qom/cpu.c         |  2 +-
 trace/control.c   | 15 +++++++++++++++
 trace/control.h   |  1 +
 4 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index ce0c406..6e39cf7 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -27,7 +27,6 @@
 #include "qemu/bitmap.h"
 #include "qemu/queue.h"
 #include "qemu/thread.h"
-#include "trace/generated-events.h"
 
 typedef int (*WriteCoreDumpFunction)(const void *buf, size_t size,
                                      void *opaque);
@@ -240,6 +239,13 @@ struct qemu_work_item {
     bool free;
 };
 
+
+/* Keep this a multiple of 8, or better yet a multiple
+ * of the platform word size, since the struct
+ * will be padded out to that regardless.
+ */
+#define TRACE_MAX_VCPU_EVENT 32
+
 /**
  * CPUState:
  * @cpu_index: CPU index (informative).
@@ -351,7 +357,7 @@ struct CPUState {
     struct kvm_run *kvm_run;
 
     /* Used for events with 'vcpu' and *without* the 'disabled' properties */
-    DECLARE_BITMAP(trace_dstate, TRACE_VCPU_EVENT_COUNT);
+    DECLARE_BITMAP(trace_dstate, TRACE_MAX_VCPU_EVENT);
 
     /* 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 2553247..8b5280a 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -345,7 +345,7 @@ static void cpu_common_initfn(Object *obj)
     qemu_mutex_init(&cpu->work_mutex);
     QTAILQ_INIT(&cpu->breakpoints);
     QTAILQ_INIT(&cpu->watchpoints);
-    bitmap_zero(cpu->trace_dstate, TRACE_VCPU_EVENT_COUNT);
+    bitmap_zero(cpu->trace_dstate, TRACE_MAX_VCPU_EVENT);
 }
 
 static void cpu_common_finalize(Object *obj)
diff --git a/trace/control.c b/trace/control.c
index 4847a51..d0aa075 100644
--- a/trace/control.c
+++ b/trace/control.c
@@ -31,6 +31,7 @@ typedef struct TraceEventGroup {
     size_t nevents;
 } TraceEventGroup;
 
+static bool have_vcpu_events;
 static TraceEventGroup *event_groups;
 static size_t nevent_groups;
 
@@ -67,6 +68,20 @@ QemuOptsList qemu_trace_opts = {
 void trace_event_register_group(TraceEvent *events,
                                 size_t nevents)
 {
+    size_t nvcpuevents = 0;
+    for (size_t i = 0; i < nevents; i++) {
+        if (events[i].vcpu_id != TRACE_VCPU_EVENT_COUNT) {
+            nvcpuevents++;
+        }
+    }
+
+    if (nvcpuevents) {
+        /* We only support 1 group having vcpu events */
+        assert(!have_vcpu_events);
+        assert(nvcpuevents < TRACE_MAX_VCPU_EVENT);
+        have_vcpu_events = true;
+    }
+
     event_groups = g_renew(TraceEventGroup, event_groups, nevent_groups + 1);
     event_groups[nevent_groups].events = events;
     event_groups[nevent_groups].nevents = nevents;
diff --git a/trace/control.h b/trace/control.h
index 81471ad..c9ea2f6 100644
--- a/trace/control.h
+++ b/trace/control.h
@@ -19,6 +19,7 @@ typedef struct TraceEventIter {
     const char *pattern;
 } TraceEventIter;
 
+
 /**
  * TraceEventID:
  *
-- 
2.7.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]