From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48862) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bkHeh-0002NS-BE for qemu-devel@nongnu.org; Wed, 14 Sep 2016 17:23:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bkHee-00007q-IR for qemu-devel@nongnu.org; Wed, 14 Sep 2016 17:23:42 -0400 Received: from roura.ac.upc.edu ([147.83.33.10]:51969 helo=roura.ac.upc.es) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bkHee-00007O-2z for qemu-devel@nongnu.org; Wed, 14 Sep 2016 17:23:40 -0400 From: =?utf-8?b?TGx1w61z?= Vilanova Date: Wed, 14 Sep 2016 23:23:38 +0200 Message-Id: <147388821876.17002.6684458103246806554.stgit@fimbulvetr.bsc.es> In-Reply-To: <147388819720.17002.17020698136656908126.stgit@fimbulvetr.bsc.es> References: <147388819720.17002.17020698136656908126.stgit@fimbulvetr.bsc.es> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH 4/4] trace: [tcg] Do not generate TCG code to trace dinamically-disabled events List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Eric Blake , Eduardo Habkost , Stefan Hajnoczi If an event is dynamically disabled, the TCG code that calls the execution-time tracer is not generated. Removes the overheads of execution-time tracers for dynamically disabled events. As a bonus, also avoids checking the event state when the execution-time tracer is called from TCG-generated code (since otherwise TCG would simply not call it). Signed-off-by: Llu=C3=ADs Vilanova --- scripts/tracetool/backend/dtrace.py | 2 +- scripts/tracetool/backend/ftrace.py | 20 ++++++++++---------- scripts/tracetool/backend/log.py | 16 ++++++++-------- scripts/tracetool/backend/simple.py | 2 +- scripts/tracetool/backend/syslog.py | 6 +++--- scripts/tracetool/backend/ust.py | 2 +- scripts/tracetool/format/h.py | 23 +++++++++++++++++------ scripts/tracetool/format/tcg_h.py | 20 +++++++++++++++++--- scripts/tracetool/format/tcg_helper_c.py | 3 ++- 9 files changed, 60 insertions(+), 34 deletions(-) diff --git a/scripts/tracetool/backend/dtrace.py b/scripts/tracetool/back= end/dtrace.py index ab9ecfa..20242f2 100644 --- a/scripts/tracetool/backend/dtrace.py +++ b/scripts/tracetool/backend/dtrace.py @@ -41,6 +41,6 @@ def generate_h_begin(events): =20 =20 def generate_h(event): - out(' QEMU_%(uppername)s(%(argnames)s);', + out(' QEMU_%(uppername)s(%(argnames)s);', uppername=3Devent.name.upper(), argnames=3D", ".join(event.args.names())) diff --git a/scripts/tracetool/backend/ftrace.py b/scripts/tracetool/back= end/ftrace.py index 80dcf30..d798c71 100644 --- a/scripts/tracetool/backend/ftrace.py +++ b/scripts/tracetool/backend/ftrace.py @@ -30,17 +30,17 @@ def generate_h(event): if len(event.args) > 0: argnames =3D ", " + argnames =20 - out(' {', - ' char ftrace_buf[MAX_TRACE_STRLEN];', - ' int unused __attribute__ ((unused));', - ' int trlen;', - ' if (trace_event_get_state(%(event_id)s)) {', - ' trlen =3D snprintf(ftrace_buf, MAX_TRACE_STRLEN= ,', - ' "%(name)s " %(fmt)s "\\n" %(ar= gnames)s);', - ' trlen =3D MIN(trlen, MAX_TRACE_STRLEN - 1);', - ' unused =3D write(trace_marker_fd, ftrace_buf, t= rlen);', - ' }', + out(' {', + ' char ftrace_buf[MAX_TRACE_STRLEN];', + ' int unused __attribute__ ((unused));', + ' int trlen;', + ' if (trace_event_get_state(%(event_id)s)) {', + ' trlen =3D snprintf(ftrace_buf, MAX_TRACE_STRLEN,', + ' "%(name)s " %(fmt)s "\\n" %(argnam= es)s);', + ' trlen =3D MIN(trlen, MAX_TRACE_STRLEN - 1);', + ' unused =3D write(trace_marker_fd, ftrace_buf, trlen= );', ' }', + ' }', name=3Devent.name, args=3Devent.args, event_id=3D"TRACE_" + event.name.upper(), diff --git a/scripts/tracetool/backend/log.py b/scripts/tracetool/backend= /log.py index b3ff064..6818147 100644 --- a/scripts/tracetool/backend/log.py +++ b/scripts/tracetool/backend/log.py @@ -36,14 +36,14 @@ def generate_h(event): else: cond =3D "trace_event_get_state(%s)" % ("TRACE_" + event.name.up= per()) =20 - out(' if (%(cond)s) {', - ' struct timeval _now;', - ' gettimeofday(&_now, NULL);', - ' qemu_log_mask(LOG_TRACE, "%%d@%%zd.%%06zd:%(name)s = " %(fmt)s "\\n",', - ' getpid(),', - ' (size_t)_now.tv_sec, (size_t)_now.tv_= usec', - ' %(argnames)s);', - ' }', + out(' if (%(cond)s) {', + ' struct timeval _now;', + ' gettimeofday(&_now, NULL);', + ' qemu_log_mask(LOG_TRACE, "%%d@%%zd.%%06zd:%(name)s " %(= fmt)s "\\n",', + ' getpid(),', + ' (size_t)_now.tv_sec, (size_t)_now.tv_usec= ', + ' %(argnames)s);', + ' }', cond=3Dcond, name=3Devent.name, fmt=3Devent.fmt.rstrip("\n"), diff --git a/scripts/tracetool/backend/simple.py b/scripts/tracetool/back= end/simple.py index 1bccada..4acf23f 100644 --- a/scripts/tracetool/backend/simple.py +++ b/scripts/tracetool/backend/simple.py @@ -36,7 +36,7 @@ def generate_h_begin(events): =20 =20 def generate_h(event): - out(' _simple_%(api)s(%(args)s);', + out(' _simple_%(api)s(%(args)s);', api=3Devent.api(), args=3D", ".join(event.args.names())) =20 diff --git a/scripts/tracetool/backend/syslog.py b/scripts/tracetool/back= end/syslog.py index 89019bc..b355121 100644 --- a/scripts/tracetool/backend/syslog.py +++ b/scripts/tracetool/backend/syslog.py @@ -36,9 +36,9 @@ def generate_h(event): else: cond =3D "trace_event_get_state(%s)" % ("TRACE_" + event.name.up= per()) =20 - out(' if (%(cond)s) {', - ' syslog(LOG_INFO, "%(name)s " %(fmt)s %(argnames)s);= ', - ' }', + out(' if (%(cond)s) {', + ' syslog(LOG_INFO, "%(name)s " %(fmt)s %(argnames)s);', + ' }', cond=3Dcond, name=3Devent.name, fmt=3Devent.fmt.rstrip("\n"), diff --git a/scripts/tracetool/backend/ust.py b/scripts/tracetool/backend= /ust.py index ed4c227..88d13e2 100644 --- a/scripts/tracetool/backend/ust.py +++ b/scripts/tracetool/backend/ust.py @@ -30,6 +30,6 @@ def generate_h(event): if len(event.args) > 0: argnames =3D ", " + argnames =20 - out(' tracepoint(qemu, %(name)s%(tp_args)s);', + out(' tracepoint(qemu, %(name)s%(tp_args)s);', name=3Devent.name, tp_args=3Dargnames) diff --git a/scripts/tracetool/format/h.py b/scripts/tracetool/format/h.p= y index 3763e9a..99fcbc0 100644 --- a/scripts/tracetool/format/h.py +++ b/scripts/tracetool/format/h.py @@ -29,6 +29,19 @@ def generate(events, backend): backend.generate_begin(events) =20 for e in events: + # tracer without checks + out('', + 'static inline void __nocheck__%(api)s(%(args)s)', + '{', + api=3De.api(), + args=3De.args) + + if "disable" not in e.properties: + backend.generate(e) + + out('}') + + # tracer wrapper with checks (per-vCPU tracing) if "vcpu" in e.properties: trace_cpu =3D next(iter(e.args))[1] cond =3D "trace_event_get_vcpu_state(%(cpu)s,"\ @@ -44,16 +57,14 @@ def generate(events, backend): 'static inline void %(api)s(%(args)s)', '{', ' if (%(cond)s) {', + ' __nocheck__%(api)s(%(names)s);', + ' }', + '}', api=3De.api(), args=3De.args, + names=3D", ".join(e.args.names()), cond=3Dcond) =20 - if "disable" not in e.properties: - backend.generate(e) - - out(' }', - '}') - backend.generate_end(events) =20 out('#endif /* TRACE__GENERATED_TRACERS_H */') diff --git a/scripts/tracetool/format/tcg_h.py b/scripts/tracetool/format= /tcg_h.py index e2331f2..fb2503a 100644 --- a/scripts/tracetool/format/tcg_h.py +++ b/scripts/tracetool/format/tcg_h.py @@ -41,7 +41,7 @@ def generate(events, backend): =20 for e in events: # just keep one of them - if "tcg-trans" not in e.properties: + if "tcg-exec" not in e.properties: continue =20 out('static inline void %(name_tcg)s(%(args)s)', @@ -53,12 +53,26 @@ def generate(events, backend): args_trans =3D e.original.event_trans.args args_exec =3D tracetool.vcpu.transform_args( "tcg_helper_c", e.original.event_exec, "wrapper") + if "vcpu" in e.properties: + trace_cpu =3D e.args.names()[0] + cond =3D "trace_event_get_vcpu_state(%(cpu)s,"\ + " TRACE_%(id)s,"\ + " TRACE_VCPU_%(id)s)"\ + % dict( + cpu=3Dtrace_cpu, + id=3De.original.event_exec.name.upper()) + else: + cond =3D "true" + out(' %(name_trans)s(%(argnames_trans)s);', - ' gen_helper_%(name_exec)s(%(argnames_exec)s);', + ' if (%(cond)s) {', + ' gen_helper_%(name_exec)s(%(argnames_exec)s);', + ' }', name_trans=3De.original.event_trans.api(e.QEMU_TRACE), name_exec=3De.original.event_exec.api(e.QEMU_TRACE), argnames_trans=3D", ".join(args_trans.names()), - argnames_exec=3D", ".join(args_exec.names())) + argnames_exec=3D", ".join(args_exec.names()), + cond=3Dcond) =20 out('}') =20 diff --git a/scripts/tracetool/format/tcg_helper_c.py b/scripts/tracetool= /format/tcg_helper_c.py index e3485b7..f9adb3c 100644 --- a/scripts/tracetool/format/tcg_helper_c.py +++ b/scripts/tracetool/format/tcg_helper_c.py @@ -66,7 +66,8 @@ def generate(events, backend): =20 out('void %(name_tcg)s(%(args_api)s)', '{', - ' %(name)s(%(args_call)s);', + # NOTE: the check was already performed at TCG-generation ti= me + ' __nocheck__%(name)s(%(args_call)s);', '}', name_tcg=3D"helper_%s_proxy" % e.api(), name=3De.api(),