From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40960) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bX91M-0006Ko-Ph for qemu-devel@nongnu.org; Tue, 09 Aug 2016 11:32:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bX91K-0005ex-3p for qemu-devel@nongnu.org; Tue, 09 Aug 2016 11:32:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54806) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bX91J-0005ek-RT for qemu-devel@nongnu.org; Tue, 09 Aug 2016 11:32:46 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 75B423BEC1 for ; Tue, 9 Aug 2016 15:32:45 +0000 (UTC) From: "Daniel P. Berrange" Date: Tue, 9 Aug 2016 16:31:37 +0100 Message-Id: <1470756748-18933-10-git-send-email-berrange@redhat.com> In-Reply-To: <1470756748-18933-1-git-send-email-berrange@redhat.com> References: <1470756748-18933-1-git-send-email-berrange@redhat.com> Subject: [Qemu-devel] [PATCH for-2.8 v1 09/60] trace: remove use of TRACE_VCPU_EVENT_COUNT in cpu.h List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , "Daniel P. Berrange" 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 --- 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