From: "Lluís Vilanova" <vilanova@ac.upc.edu>
To: Stefan Hajnoczi <stefanha@redhat.com>
Cc: "Stefan Hajnoczi" <stefanha@gmail.com>,
"Eduardo Habkost" <ehabkost@redhat.com>,
"Riku Voipio" <riku.voipio@iki.fi>,
qemu-devel@nongnu.org, "Blue Swirl" <blauwirbel@gmail.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: Fri, 10 Jun 2016 19:52:16 +0200 [thread overview]
Message-ID: <87bn39j5in.fsf@fimbulvetr.bsc.es> (raw)
In-Reply-To: <20160610162524.GF3855@stefanha-x1.localdomain> (Stefan Hajnoczi's message of "Fri, 10 Jun 2016 17:25:24 +0100")
Stefan Hajnoczi writes:
> On Thu, Jun 09, 2016 at 04:17:11PM +0200, Lluís Vilanova wrote:
>> >> @@ -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.
> When reviewing patches I try to understand each change. When I don't
> see a reason for a change I need to ask.
> In general it's easier to leave code as-is unless there is a need to
> change it. But there are no hard rules :).
I'll refrain from pushing my manias into QEMU :)
[...]
>> > 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).
> If you feel strongly about it, feel free to keep it. Alternative
> reasoning about the type:
> int is the CPU index type used in qemu_get_cpu(). It is guaranteed to
> be large enough for the vcpu count. IMO there's no need to select a new
> type, but there's more...
> size_t is larger than necessary on 64-bit machines and has an impact on
> the CPU cache performance that Paolo's optimization takes advantage of
> (if you trigger adjacent trace event IDs they will probably already be
> in cache).
> size_t made me have to think hard when reading the "int += bool -
> size_t" statement for updating trace_events_enabled_count.
> If int is used then it's clear that int = (int)bool - int will be one of
> [-1, 0, +1].
> But with size_t you have to starting wondering whether the type coercion
> is portable and works as expected:
> int = (int)((size_t)bool - size_t);
> In "6.3.1.3 Signed and unsigned integers" the C99 standard says:
> [If] the new type is signed and the value cannot be represented in
> it; either the result is implementation-defined or an
> implementation-defined signal is raised.
> The size_t -> int conversion is therefore implementation-defined. This
> is not portable although QEMU probably does it in many places.
> So for these reasons, I think int is the natural choice.
Fair point. But now I feel tempted to change both trace_events_dstate and
trace_events_enabled_count into unsigned int... it burns me when I see signed
types used only on their positives by design.
But don't worry, I'll change trace_events_dstate into int :)
Thanks!
Lluis
next prev parent reply other threads:[~2016-06-10 17:52 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
2016-06-10 16:25 ` Stefan Hajnoczi
2016-06-10 17:52 ` Lluís Vilanova [this message]
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=87bn39j5in.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.