From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47615) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1baILN-0001VE-8j for qemu-devel@nongnu.org; Thu, 18 Aug 2016 04:06:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1baILI-0008Eh-Hv for qemu-devel@nongnu.org; Thu, 18 Aug 2016 04:06:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50948) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1baILI-0008Ed-9u for qemu-devel@nongnu.org; Thu, 18 Aug 2016 04:06:24 -0400 Date: Thu, 18 Aug 2016 09:06:20 +0100 From: "Daniel P. Berrange" Message-ID: <20160818080620.GD13050@redhat.com> Reply-To: "Daniel P. Berrange" References: <147101601558.15723.5286973980439276800.stgit@fimbulvetr.bsc.es> <147101602639.15723.14773982987486773596.stgit@fimbulvetr.bsc.es> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <147101602639.15723.14773982987486773596.stgit@fimbulvetr.bsc.es> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v4 2/2] trace: Avoid implicit bool->integer conversions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?utf-8?B?TGx1w61z?= Vilanova Cc: qemu-devel@nongnu.org, Paolo Bonzini , Stefan Hajnoczi On Fri, Aug 12, 2016 at 05:33:46PM +0200, Llu=C3=ADs Vilanova wrote: > An explicit if/else is clearer than arithmetic assuming #true is 1, > while the compiler should be able to generate just as optimal code. >=20 > Signed-off-by: Llu=C3=ADs Vilanova > --- > stubs/trace-control.c | 17 +++++++++++++++-- > trace/control-target.c | 31 ++++++++++++++++++++++++++----- > 2 files changed, 41 insertions(+), 7 deletions(-) Reviewed-by: Daniel P. Berrange >=20 > diff --git a/stubs/trace-control.c b/stubs/trace-control.c > index 3740c38..2dfcd9f 100644 > --- a/stubs/trace-control.c > +++ b/stubs/trace-control.c > @@ -19,10 +19,23 @@ void trace_event_set_state_dynamic_init(TraceEvent = *ev, bool state) > void trace_event_set_state_dynamic(TraceEvent *ev, bool state) > { > TraceEventID id; > + bool state_pre; > assert(trace_event_get_state_static(ev)); > id =3D trace_event_get_id(ev); > - trace_events_enabled_count +=3D state - trace_events_dstate[id]; > - trace_events_dstate[id] =3D state; > + /* > + * We ignore the "vcpu" property here, since there's no target cod= e. Then > + * dstate can only be 1 or 0. > + */ > + state_pre =3D trace_events_dstate[id]; > + if (state_pre !=3D state) { > + if (state) { > + trace_events_enabled_count++; > + trace_events_dstate[id] =3D 1; > + } else { > + trace_events_enabled_count--; > + trace_events_dstate[id] =3D 0; > + } > + } > } > =20 > void trace_event_set_vcpu_state_dynamic(CPUState *vcpu, > diff --git a/trace/control-target.c b/trace/control-target.c > index 4ee3733..72081e2 100644 > --- a/trace/control-target.c > +++ b/trace/control-target.c > @@ -16,10 +16,22 @@ > void trace_event_set_state_dynamic_init(TraceEvent *ev, bool state) > { > TraceEventID id =3D trace_event_get_id(ev); > + bool state_pre; > assert(trace_event_get_state_static(ev)); > - /* Ignore "vcpu" property, since no vCPUs have been created yet */ > - trace_events_enabled_count +=3D state - trace_events_dstate[id]; > - trace_events_dstate[id] =3D state; > + /* > + * We ignore the "vcpu" property here, since no vCPUs have been cr= eated > + * yet. Then dstate can only be 1 or 0. > + */ > + state_pre =3D trace_events_dstate[id]; > + if (state_pre !=3D state) { > + if (state) { > + trace_events_enabled_count++; > + trace_events_dstate[id] =3D 1; > + } else { > + trace_events_enabled_count--; > + trace_events_dstate[id] =3D 0; > + } > + } > } > =20 > void trace_event_set_state_dynamic(TraceEvent *ev, bool state) > @@ -31,9 +43,18 @@ void trace_event_set_state_dynamic(TraceEvent *ev, b= ool state) > trace_event_set_vcpu_state_dynamic(vcpu, ev, state); > } > } else { > + /* Without the "vcpu" property, dstate can only be 1 or 0 */ > TraceEventID id =3D trace_event_get_id(ev); > - trace_events_enabled_count +=3D state - trace_events_dstate[id= ]; > - trace_events_dstate[id] =3D state; > + bool state_pre =3D trace_events_dstate[id]; > + if (state_pre !=3D state) { > + if (state) { > + trace_events_enabled_count++; > + trace_events_dstate[id] =3D 1; > + } else { > + trace_events_enabled_count--; > + trace_events_dstate[id] =3D 0; > + } > + } > } > } > =20 >=20 Regards, Daniel --=20 |: http://berrange.com -o- http://www.flickr.com/photos/dberrange= / :| |: http://libvirt.org -o- http://virt-manager.or= g :| |: http://autobuild.org -o- http://search.cpan.org/~danberr= / :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vn= c :|