From: "Lluís Vilanova" <vilanova@ac.upc.edu>
To: Stefan Hajnoczi <stefanha@gmail.com>
Cc: "Eduardo Habkost" <ehabkost@redhat.com>,
"Riku Voipio" <riku.voipio@iki.fi>,
qemu-devel@nongnu.org, "Blue Swirl" <blauwirbel@gmail.com>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Andreas Färber" <afaerber@suse.de>
Subject: Re: [Qemu-devel] [PATCH 4/6] trace: Add per-vCPU tracing states for events with the 'vcpu' property
Date: Thu, 09 Jun 2016 16:17:11 +0200 [thread overview]
Message-ID: <871t4630rc.fsf@fimbulvetr.bsc.es> (raw)
In-Reply-To: <20160609120756.GA15369@stefanha-x1.localdomain> (Stefan Hajnoczi's message of "Thu, 9 Jun 2016 13:07:56 +0100")
Stefan Hajnoczi writes:
> On Thu, Feb 25, 2016 at 04:03:06PM +0100, Lluís Vilanova wrote:
> @@ -332,6 +334,16 @@ struct CPUState {
>> struct KVMState *kvm_state;
>> struct kvm_run *kvm_run;
>>
>> +#define TRACE_VCPU_DSTATE_TYPE uint32_t
>> + TRACE_VCPU_DSTATE_TYPE trace_dstate;
> Please use typedef instead of #define.
>> + /*
>> + * Ensure 'trace_dstate' can encode event states as a bitmask. This limits
>> + * the number of events with the 'vcpu' property and *without* the
>> + * 'disabled' property.
>> + */
>> + bool too_many_vcpu_events[
>> + TRACE_VCPU_EVENT_COUNT > sizeof(TRACE_VCPU_DSTATE_TYPE)*8 ? -1 : 0];
> Why limit ourselves to a scalar when "qemu/bitops.h" and "qemu/bitmap.h"
> provide functions for arbitrary length bitmaps?
> See DECLARE_BITMAP(), set_bit(), clear_bit(), test_bit().
Oh, I wasn't aware of the bitmap functions. Nice catch.
>> @@ -61,7 +69,7 @@ static inline bool trace_event_get_state_static(TraceEvent *ev)
>> static inline bool trace_event_get_state_dynamic_by_id(TraceEventID id)
>> {
>> /* it's on fast path, avoid consistency checks (asserts) */
>> - return unlikely(trace_events_enabled_count) && trace_events_dstate[id];
>> + return unlikely(trace_events_enabled_count) && (trace_events_dstate[id] > 0);
> typeof(trace_events_dstate[0]) is size_t, so trace_events_dstate[id] > 0
> is equivalent to trace_events_dstate[id] (due to unsigned). Why change
> this line?
Sorry, I have a tendency to make this type of checks explicit when the types are
not boolean (for a maybe-false sense of future-proofing). I can leave it as it
was if it bothers you.
>> +void trace_event_set_state_dynamic(TraceEvent *ev, bool state)
>> +{
>> + CPUState *cpu;
>> + assert(ev != NULL);
>> + assert(trace_event_get_state_static(ev));
>> + if (trace_event_get_cpu_id(ev) != trace_event_cpu_count()) {
>> + CPU_FOREACH(cpu) {
>> + trace_event_set_cpu_state_dynamic(cpu, ev, state);
>> + }
>> + } else {
>> + TraceEventID id = trace_event_get_id(ev);
>> + trace_events_enabled_count += state - trace_events_dstate[id];
>> + trace_events_dstate[id] = state;
>> + }
>> +}
> I find it a little confusing to use different semantics for
> trace_events_dstate[] elements depending on trace_event_get_cpu_id(ev)
> != trace_event_cpu_count(). In other words, it either acts as a vcpu
> enabled counter or as an enable/disable flag.
> That said, it's nice to preserve the non-cpu_id case since it was
> written by Paolo as a performance optimization. Changing it could
> introduce a regression so I think your approach is okay.
Yes, it's a bit messy. I'll add some proper documentation about how this is
interpreted.
>> +
>> +void trace_event_set_cpu_state_dynamic(CPUState *cpu,
>> + TraceEvent *ev, bool state)
>> +{
>> + TraceEventID id;
>> + TraceEventVCPUID cpu_id;
>> + TRACE_VCPU_DSTATE_TYPE bit;
>> + bool state_pre;
>> + assert(cpu != NULL);
>> + assert(ev != NULL);
>> + assert(trace_event_get_state_static(ev));
>> + assert(trace_event_get_cpu_id(ev) != trace_event_cpu_count());
>> + id = trace_event_get_id(ev);
>> + cpu_id = trace_event_get_cpu_id(ev);
>> + bit = ((TRACE_VCPU_DSTATE_TYPE)1) << cpu_id;
>> + state_pre = cpu->trace_dstate & bit;
>> + if ((state_pre == 0) != (state == 0)) {
> Simpler expression:
> if (state_pre != state)
>> @@ -21,7 +21,10 @@
>> #include "qemu/error-report.h"
>>
>> int trace_events_enabled_count;
>> -bool trace_events_dstate[TRACE_EVENT_COUNT];
>> +/* With the 'vcpu' property, counts how many vCPUs have it enabled. */
>> +size_t trace_events_dstate[TRACE_EVENT_COUNT];
> The number of cpus has type int (see CPUState *qemu_get_cpu(int index)).
> Why did you choose size_t?
It just sounds proper to me to use size_t, since the state can never be negative
(it's either interpreted as a boolean or as an unsigned counter, depending on
the "vcpu" property).
Thanks,
Lluis
next prev parent reply other threads:[~2016-06-09 14:17 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-25 15:02 [Qemu-devel] [PATCH0/6] trace: Per-vCPU tracing states Lluís Vilanova
2016-02-25 15:02 ` [Qemu-devel] [PATCH 1/6] trace: Identify events with the 'vcpu' property Lluís Vilanova
2016-06-09 12:11 ` Stefan Hajnoczi
2016-02-25 15:02 ` [Qemu-devel] [PATCH 2/6] disas: Remove unused macro '_' Lluís Vilanova
2016-06-09 8:18 ` Stefan Hajnoczi
2016-06-09 10:34 ` Lluís Vilanova
2016-02-25 15:03 ` [Qemu-devel] [PATCH 3/6] [trivial] trace: Cosmetic changes on fast-path tracing Lluís Vilanova
2016-06-09 12:11 ` Stefan Hajnoczi
2016-06-13 9:04 ` Paolo Bonzini
2016-06-13 13:39 ` Lluís Vilanova
2016-02-25 15:03 ` [Qemu-devel] [PATCH 4/6] trace: Add per-vCPU tracing states for events with the 'vcpu' property Lluís Vilanova
2016-06-09 12:07 ` Stefan Hajnoczi
2016-06-09 14:17 ` Lluís Vilanova [this message]
2016-06-10 16:25 ` Stefan Hajnoczi
2016-06-10 17:52 ` Lluís Vilanova
2016-06-13 8:38 ` Paolo Bonzini
2016-06-13 12:17 ` Lluís Vilanova
2016-06-13 9:13 ` Paolo Bonzini
2016-06-13 12:15 ` Lluís Vilanova
2016-06-13 14:08 ` Paolo Bonzini
2016-06-13 16:39 ` Lluís Vilanova
2016-06-14 8:39 ` Stefan Hajnoczi
2016-06-14 9:13 ` Paolo Bonzini
2016-06-14 12:17 ` Lluís Vilanova
2016-06-13 14:38 ` Lluís Vilanova
2016-02-25 15:03 ` [Qemu-devel] [PATCH 5/6] trace: Conditionally trace events based on their per-vCPU state Lluís Vilanova
2016-06-09 12:09 ` Stefan Hajnoczi
2016-02-25 15:03 ` [Qemu-devel] [PATCH 6/6] trace: Add QAPI/QMP interfaces to query and control per-vCPU tracing state Lluís Vilanova
2016-06-09 12:10 ` Stefan Hajnoczi
2016-03-07 19:35 ` [Qemu-devel] [PATCH0/6] trace: Per-vCPU tracing states Lluís Vilanova
2016-06-01 12:14 ` Lluís Vilanova
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=871t4630rc.fsf@fimbulvetr.bsc.es \
--to=vilanova@ac.upc.edu \
--cc=afaerber@suse.de \
--cc=blauwirbel@gmail.com \
--cc=ehabkost@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=riku.voipio@iki.fi \
--cc=stefanha@gmail.com \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.