From patchwork Mon Sep 5 19:42:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 9315135 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0DBFB6075E for ; Mon, 5 Sep 2016 19:56:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F4011288B8 for ; Mon, 5 Sep 2016 19:56:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E8EBD288D9; Mon, 5 Sep 2016 19:56:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7A3BC288B8 for ; Mon, 5 Sep 2016 19:56:52 +0000 (UTC) Received: from localhost ([::1]:56786 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bh00h-0004Tb-JH for patchwork-qemu-devel@patchwork.kernel.org; Mon, 05 Sep 2016 15:56:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57543) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bgzos-0003Wb-43 for qemu-devel@nongnu.org; Mon, 05 Sep 2016 15:44:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bgzor-0002EY-3K for qemu-devel@nongnu.org; Mon, 05 Sep 2016 15:44:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52734) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bgzoq-0002EN-RK for qemu-devel@nongnu.org; Mon, 05 Sep 2016 15:44:37 -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 417BA4E4C6; Mon, 5 Sep 2016 19:44:36 +0000 (UTC) Received: from localhost (ovpn-112-28.ams2.redhat.com [10.36.112.28]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u85JiY9w001456; Mon, 5 Sep 2016 15:44:35 -0400 From: Stefan Hajnoczi To: Date: Mon, 5 Sep 2016 15:42:49 -0400 Message-Id: <1473104569-6973-4-git-send-email-stefanha@redhat.com> In-Reply-To: <1473104569-6973-1-git-send-email-stefanha@redhat.com> References: <1473104569-6973-1-git-send-email-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 05 Sep 2016 19:44:36 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 3/3] trace: Avoid implicit bool->integer conversions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?UTF-8?q?Llu=C3=ADs=20Vilanova?= , Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Lluís Vilanova An explicit if/else is clearer than arithmetic assuming #true is 1, while the compiler should be able to generate just as optimal code. Signed-off-by: Lluís Vilanova Message-id: 147194273830.26836.5875729707953474838.stgit@fimbulvetr.bsc.es Signed-off-by: Stefan Hajnoczi --- stubs/trace-control.c | 17 +++++++++++++++-- trace/control-target.c | 31 ++++++++++++++++++++++++++----- 2 files changed, 41 insertions(+), 7 deletions(-) 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 = trace_event_get_id(ev); - trace_events_enabled_count += state - trace_events_dstate[id]; - trace_events_dstate[id] = state; + /* + * We ignore the "vcpu" property here, since there's no target code. Then + * dstate can only be 1 or 0. + */ + state_pre = trace_events_dstate[id]; + if (state_pre != state) { + if (state) { + trace_events_enabled_count++; + trace_events_dstate[id] = 1; + } else { + trace_events_enabled_count--; + trace_events_dstate[id] = 0; + } + } } 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 = 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 += state - trace_events_dstate[id]; - trace_events_dstate[id] = state; + /* + * We ignore the "vcpu" property here, since no vCPUs have been created + * yet. Then dstate can only be 1 or 0. + */ + state_pre = trace_events_dstate[id]; + if (state_pre != state) { + if (state) { + trace_events_enabled_count++; + trace_events_dstate[id] = 1; + } else { + trace_events_enabled_count--; + trace_events_dstate[id] = 0; + } + } } void trace_event_set_state_dynamic(TraceEvent *ev, bool state) @@ -31,9 +43,18 @@ void trace_event_set_state_dynamic(TraceEvent *ev, bool state) trace_event_set_vcpu_state_dynamic(vcpu, ev, state); } } else { + /* Without the "vcpu" property, dstate can only be 1 or 0 */ TraceEventID id = trace_event_get_id(ev); - trace_events_enabled_count += state - trace_events_dstate[id]; - trace_events_dstate[id] = state; + bool state_pre = trace_events_dstate[id]; + if (state_pre != state) { + if (state) { + trace_events_enabled_count++; + trace_events_dstate[id] = 1; + } else { + trace_events_enabled_count--; + trace_events_dstate[id] = 0; + } + } } }