From nobody Sat May 4 14:01:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15012342200891000.6219561423956; Fri, 28 Jul 2017 02:30:20 -0700 (PDT) Received: from localhost ([::1]:47036 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1db1b7-0006jO-0t for importer@patchew.org; Fri, 28 Jul 2017 05:30:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32993) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1db1SC-00077Z-BS for qemu-devel@nongnu.org; Fri, 28 Jul 2017 05:21:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1db1SB-00075e-B6 for qemu-devel@nongnu.org; Fri, 28 Jul 2017 05:21:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44488) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1db1SB-00074e-21 for qemu-devel@nongnu.org; Fri, 28 Jul 2017 05:21:03 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DFE0E18310C; Fri, 28 Jul 2017 09:21:01 +0000 (UTC) Received: from localhost (ovpn-117-150.ams2.redhat.com [10.36.117.150]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8BC9E53CE9; Fri, 28 Jul 2017 09:20:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com DFE0E18310C Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=stefanha@redhat.com From: Stefan Hajnoczi To: Date: Fri, 28 Jul 2017 10:20:52 +0100 Message-Id: <20170728092053.10122-2-stefanha@redhat.com> In-Reply-To: <20170728092053.10122-1-stefanha@redhat.com> References: <20170728092053.10122-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 28 Jul 2017 09:21:02 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 1/2] trace: add TRACE__BACKEND_DSTATE() 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: "Denis V. Lunev" , =?UTF-8?q?Llu=C3=ADs=20Vilanova?= , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" QEMU keeps track of trace event enabled/disabled state and provides monitor commands to inspect and modify the "dstate". SystemTap and LTTng UST maintain independent enabled/disabled states for each trace event. Introduce a new per-event macro that combines backend-specific dstate like this: #define TRACE_MY_EVENT_BACKEND_DSTATE() ( \ QEMU_MY_EVENT_ENABLED() || /* SystemTap */ \ tracepoint_enabled(qemu, my_event) /* LTTng UST */ || \ false) This will be used to extend trace_event_get_state() in the next patch. Signed-off-by: Stefan Hajnoczi Reviewed-by: Denis V. Lunev --- scripts/tracetool/__init__.py | 1 + scripts/tracetool/backend/__init__.py | 3 +++ scripts/tracetool/backend/dtrace.py | 12 ++++++++++++ scripts/tracetool/backend/ust.py | 5 +++++ scripts/tracetool/format/h.py | 10 ++++++++++ 5 files changed, 31 insertions(+) diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py index d4c204a472..0670ec17d5 100644 --- a/scripts/tracetool/__init__.py +++ b/scripts/tracetool/__init__.py @@ -271,6 +271,7 @@ class Event(object): QEMU_TRACE_NOCHECK =3D "_nocheck__" + QEMU_TRACE QEMU_TRACE_TCG =3D QEMU_TRACE + "_tcg" QEMU_DSTATE =3D "_TRACE_%(NAME)s_DSTATE" + QEMU_BACKEND_DSTATE =3D "TRACE_%(NAME)s_BACKEND_DSTATE" QEMU_EVENT =3D "_TRACE_%(NAME)s_EVENT" =20 def api(self, fmt=3DNone): diff --git a/scripts/tracetool/backend/__init__.py b/scripts/tracetool/back= end/__init__.py index f735a259c0..259c6a6531 100644 --- a/scripts/tracetool/backend/__init__.py +++ b/scripts/tracetool/backend/__init__.py @@ -119,5 +119,8 @@ class Wrapper: def generate(self, event, group): self._run_function("generate_%s", event, group) =20 + def generate_backend_dstate(self, event, group): + self._run_function("generate_%s_backend_dstate", event, group) + def generate_end(self, events, group): self._run_function("generate_%s_end", events, group) diff --git a/scripts/tracetool/backend/dtrace.py b/scripts/tracetool/backen= d/dtrace.py index c6812b70a2..17f902cc62 100644 --- a/scripts/tracetool/backend/dtrace.py +++ b/scripts/tracetool/backend/dtrace.py @@ -44,8 +44,20 @@ def generate_h_begin(events, group): out('#include "%s"' % header, '') =20 + # SystemTap defines __ENABLED() but other DTrace + # implementations might not. + for e in events: + out('#ifndef QEMU_%(uppername)s_ENABLED', + '#define QEMU_%(uppername)s_ENABLED() false', + '#endif', + uppername=3De.name.upper()) =20 def generate_h(event, group): out(' QEMU_%(uppername)s(%(argnames)s);', uppername=3Devent.name.upper(), argnames=3D", ".join(event.args.names())) + + +def generate_h_backend_dstate(event, group): + out(' QEMU_%(uppername)s_ENABLED() || \\', + uppername=3Devent.name.upper()) diff --git a/scripts/tracetool/backend/ust.py b/scripts/tracetool/backend/u= st.py index 2adaf548d5..412592b8e0 100644 --- a/scripts/tracetool/backend/ust.py +++ b/scripts/tracetool/backend/ust.py @@ -38,3 +38,8 @@ def generate_h(event, group): out(' tracepoint(qemu, %(name)s%(tp_args)s);', name=3Devent.name, tp_args=3Dargnames) + + +def generate_h_backend_dstate(event, group): + out(' tracepoint_enabled(qemu, %(name)s) || \\', + name=3Devent.name) diff --git a/scripts/tracetool/format/h.py b/scripts/tracetool/format/h.py index aecf249d66..e06f0f27c5 100644 --- a/scripts/tracetool/format/h.py +++ b/scripts/tracetool/format/h.py @@ -49,6 +49,16 @@ def generate(events, backend, group): backend.generate_begin(events, group) =20 for e in events: + # tracer-specific dstate + out('', + '#define %(api)s() ( \\', + api=3De.api(e.QEMU_BACKEND_DSTATE)) + + if "disable" not in e.properties: + backend.generate_backend_dstate(e, group) + + out(' false)') + # tracer without checks out('', 'static inline void %(api)s(%(args)s)', --=20 2.13.3 From nobody Sat May 4 14:01:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1501234284606866.163323265345; Fri, 28 Jul 2017 02:31:24 -0700 (PDT) Received: from localhost ([::1]:47044 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1db1cB-000813-3p for importer@patchew.org; Fri, 28 Jul 2017 05:31:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33012) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1db1SE-00078z-H7 for qemu-devel@nongnu.org; Fri, 28 Jul 2017 05:21:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1db1SD-00076n-AI for qemu-devel@nongnu.org; Fri, 28 Jul 2017 05:21:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58440) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1db1SD-00076I-06 for qemu-devel@nongnu.org; Fri, 28 Jul 2017 05:21:05 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EAA2E7036E; Fri, 28 Jul 2017 09:21:03 +0000 (UTC) Received: from localhost (ovpn-117-150.ams2.redhat.com [10.36.117.150]) by smtp.corp.redhat.com (Postfix) with ESMTP id 44AA160BF1; Fri, 28 Jul 2017 09:21:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com EAA2E7036E Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=stefanha@redhat.com From: Stefan Hajnoczi To: Date: Fri, 28 Jul 2017 10:20:53 +0100 Message-Id: <20170728092053.10122-3-stefanha@redhat.com> In-Reply-To: <20170728092053.10122-1-stefanha@redhat.com> References: <20170728092053.10122-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 28 Jul 2017 09:21:04 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 2/2] trace: check backend dstate in trace_event_get_state() 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: "Denis V. Lunev" , =?UTF-8?q?Llu=C3=ADs=20Vilanova?= , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Code that checks dstate is unaware of SystemTap and LTTng UST dstate, so the following trace event will not fire when solely enabled by SystemTap or LTTng UST: if (trace_event_get_state(TRACE_MY_EVENT)) { str =3D g_strdup_printf("Expensive string to generate ...", ...); trace_my_event(str); g_free(str); } Most users of trace_event_get_state() want to know both QEMU and backend dstate for the event. Update the macro to include backend dstate. Introduce trace_event_get_state_qemu() for those callers who really only want QEMU dstate. This includes the trace backends (like 'log') which should only trigger when event are enabled via QEMU. Signed-off-by: Stefan Hajnoczi Reviewed-by: Denis V. Lunev --- trace/control.h | 20 ++++++++++++++++++-- scripts/tracetool/backend/ftrace.py | 2 +- scripts/tracetool/backend/log.py | 3 ++- scripts/tracetool/backend/simple.py | 2 +- scripts/tracetool/backend/syslog.py | 3 ++- 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/trace/control.h b/trace/control.h index b931824d60..b996c34c08 100644 --- a/trace/control.h +++ b/trace/control.h @@ -93,16 +93,32 @@ static bool trace_event_is_vcpu(TraceEvent *ev); static const char * trace_event_get_name(TraceEvent *ev); =20 /** + * trace_event_get_state_qemu: + * @id: Event identifier name. + * + * Get the tracing state of an event, both static and the QEMU dynamic sta= te. + * Note that some backends maintain their own dynamic state, use + * trace_event_get_state() instead if you wish to include it. + * + * If the event has the disabled property, the check will have no performa= nce + * impact. + */ +#define trace_event_get_state_qemu(id) \ + ((id ##_ENABLED) && trace_event_get_state_dynamic_by_id(id)) + +/** * trace_event_get_state: * @id: Event identifier name. * - * Get the tracing state of an event (both static and dynamic). + * Get the tracing state of an event (both static and dynamic). Both QEMU= and + * backend-specific dynamic state are included. * * If the event has the disabled property, the check will have no performa= nce * impact. */ #define trace_event_get_state(id) \ - ((id ##_ENABLED) && trace_event_get_state_dynamic_by_id(id)) + ((id ##_ENABLED) && (trace_event_get_state_dynamic_by_id(id) || \ + id ##_BACKEND_DSTATE())) =20 /** * trace_event_get_vcpu_state: diff --git a/scripts/tracetool/backend/ftrace.py b/scripts/tracetool/backen= d/ftrace.py index dd0eda4441..fba637b376 100644 --- a/scripts/tracetool/backend/ftrace.py +++ b/scripts/tracetool/backend/ftrace.py @@ -33,7 +33,7 @@ def generate_h(event, group): ' char ftrace_buf[MAX_TRACE_STRLEN];', ' int unused __attribute__ ((unused));', ' int trlen;', - ' if (trace_event_get_state(%(event_id)s)) {', + ' if (trace_event_get_state_qemu(%(event_id)s)) {', ' trlen =3D snprintf(ftrace_buf, MAX_TRACE_STRLEN,', ' "%(name)s " %(fmt)s "\\n" %(argnames= )s);', ' trlen =3D MIN(trlen, MAX_TRACE_STRLEN - 1);', diff --git a/scripts/tracetool/backend/log.py b/scripts/tracetool/backend/l= og.py index 54f0a69886..4562b9d12d 100644 --- a/scripts/tracetool/backend/log.py +++ b/scripts/tracetool/backend/log.py @@ -33,7 +33,8 @@ def generate_h(event, group): # already checked on the generic format code cond =3D "true" else: - cond =3D "trace_event_get_state(%s)" % ("TRACE_" + event.name.uppe= r()) + cond =3D "trace_event_get_state_qemu(%s)" % \ + ("TRACE_" + event.name.upper()) =20 out(' if (%(cond)s) {', ' struct timeval _now;', diff --git a/scripts/tracetool/backend/simple.py b/scripts/tracetool/backen= d/simple.py index f983670ee1..a39bbdc5c6 100644 --- a/scripts/tracetool/backend/simple.py +++ b/scripts/tracetool/backend/simple.py @@ -73,7 +73,7 @@ def generate_c(event, group): # already checked on the generic format code cond =3D "true" else: - cond =3D "trace_event_get_state(%s)" % event_id + cond =3D "trace_event_get_state_qemu(%s)" % event_id =20 out('', ' if (!%(cond)s) {', diff --git a/scripts/tracetool/backend/syslog.py b/scripts/tracetool/backen= d/syslog.py index 1ce627f0fc..3ee07bf7fd 100644 --- a/scripts/tracetool/backend/syslog.py +++ b/scripts/tracetool/backend/syslog.py @@ -33,7 +33,8 @@ def generate_h(event, group): # already checked on the generic format code cond =3D "true" else: - cond =3D "trace_event_get_state(%s)" % ("TRACE_" + event.name.uppe= r()) + cond =3D "trace_event_get_state_qemu(%s)" % \ + ("TRACE_" + event.name.upper()) =20 out(' if (%(cond)s) {', ' syslog(LOG_INFO, "%(name)s " %(fmt)s %(argnames)s);', --=20 2.13.3