From patchwork Tue Aug 23 08:58:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Llu=C3=ADs_Vilanova?= X-Patchwork-Id: 9295273 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 2033660574 for ; Tue, 23 Aug 2016 09:02:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0E554281A7 for ; Tue, 23 Aug 2016 09:02:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 02F24288B3; Tue, 23 Aug 2016 09:02:34 +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 8B05F28210 for ; Tue, 23 Aug 2016 09:02:30 +0000 (UTC) Received: from localhost ([::1]:45360 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bc7bJ-0002Ap-Q2 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 23 Aug 2016 05:02:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50320) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bc7Y3-0008KU-By for qemu-devel@nongnu.org; Tue, 23 Aug 2016 04:59:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bc7Xw-0001dM-NU for qemu-devel@nongnu.org; Tue, 23 Aug 2016 04:59:06 -0400 Received: from roura.ac.upc.es ([147.83.33.10]:59013) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bc7Xw-0001dF-Bp for qemu-devel@nongnu.org; Tue, 23 Aug 2016 04:59:00 -0400 Received: from gw-3.ac.upc.es (gw-3.ac.upc.es [147.83.30.9]) by roura.ac.upc.es (8.13.8/8.13.8) with ESMTP id u7N8wxDv001846; Tue, 23 Aug 2016 10:58:59 +0200 Received: from localhost (159.red-2-136-134.dynamicip.rima-tde.net [2.136.134.159]) by gw-3.ac.upc.es (Postfix) with ESMTPSA id 1C4801F5; Tue, 23 Aug 2016 10:58:59 +0200 (CEST) From: =?utf-8?b?TGx1w61z?= Vilanova To: qemu-devel@nongnu.org Date: Tue, 23 Aug 2016 10:58:58 +0200 Message-Id: <147194273830.26836.5875729707953474838.stgit@fimbulvetr.bsc.es> X-Mailer: git-send-email 2.8.1 In-Reply-To: <147194272549.26836.14148280533962401765.stgit@fimbulvetr.bsc.es> References: <147194272549.26836.14148280533962401765.stgit@fimbulvetr.bsc.es> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-MIME-Autoconverted: from 8bit to quoted-printable by roura.ac.upc.es id u7N8wxDv001846 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 147.83.33.10 Subject: [Qemu-devel] [PATCH v5 2/2] 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: Paolo Bonzini , Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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; + } + } } }