* [PATCH 1/3] tracetool: removed the unused vcpu property
2025-06-16 20:12 [PATCH 0/3] tracetool:cleanup "if(true)" check from trace_foo() Tanish Desai
@ 2025-06-16 20:12 ` Tanish Desai
2025-06-17 14:07 ` Stefan Hajnoczi
2025-06-17 19:43 ` [PATCH 1/3] " Alex Bennée
2025-06-16 20:12 ` [PATCH 2/3] tracetool: introduce generate_unconditional Tanish Desai
` (2 subsequent siblings)
3 siblings, 2 replies; 10+ messages in thread
From: Tanish Desai @ 2025-06-16 20:12 UTC (permalink / raw)
To: qemu-devel
Cc: Lluís Vilanova, Paolo Bonzini, Mads Ynddal, Stefan Hajnoczi,
Tanish Desai
The vcpu property is no longer used in these backends. Removing it avoids
unnecessary checks and simplifies the code generation for these trace backends.
Signed-off-by: Tanish Desai <tanishdesai37@gmail.com>
---
scripts/tracetool/backend/log.py | 6 +-----
scripts/tracetool/backend/simple.py | 6 +-----
scripts/tracetool/backend/syslog.py | 6 +-----
3 files changed, 3 insertions(+), 15 deletions(-)
diff --git a/scripts/tracetool/backend/log.py b/scripts/tracetool/backend/log.py
index de27b7e62e..f24acad74c 100644
--- a/scripts/tracetool/backend/log.py
+++ b/scripts/tracetool/backend/log.py
@@ -31,11 +31,7 @@ def generate_h(event, group):
if len(event.args) > 0:
argnames = ", " + argnames
- if "vcpu" in event.properties:
- # already checked on the generic format code
- cond = "true"
- else:
- cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper())
+ cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper())
out(' if (%(cond)s && qemu_loglevel_mask(LOG_TRACE)) {',
' if (message_with_timestamp) {',
diff --git a/scripts/tracetool/backend/simple.py b/scripts/tracetool/backend/simple.py
index 2688d4b64b..7c84c06b20 100644
--- a/scripts/tracetool/backend/simple.py
+++ b/scripts/tracetool/backend/simple.py
@@ -37,11 +37,7 @@ def generate_h_begin(events, group):
def generate_h(event, group):
event_id = 'TRACE_' + event.name.upper()
- if "vcpu" in event.properties:
- # already checked on the generic format code
- cond = "true"
- else:
- cond = "trace_event_get_state(%s)" % event_id
+ cond = "trace_event_get_state(%s)" % event_id
out(' if (%(cond)s) {',
' _simple_%(api)s(%(args)s);',
' }',
diff --git a/scripts/tracetool/backend/syslog.py b/scripts/tracetool/backend/syslog.py
index 012970f6cc..6fdc1142fb 100644
--- a/scripts/tracetool/backend/syslog.py
+++ b/scripts/tracetool/backend/syslog.py
@@ -30,11 +30,7 @@ def generate_h(event, group):
if len(event.args) > 0:
argnames = ", " + argnames
- if "vcpu" in event.properties:
- # already checked on the generic format code
- cond = "true"
- else:
- cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper())
+ cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper())
out(' if (%(cond)s) {',
'#line %(event_lineno)d "%(event_filename)s"',
--
2.34.1
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH 1/3] tracetool: removed the unused vcpu property
2025-06-16 20:12 ` [PATCH 1/3] tracetool: removed the unused vcpu property Tanish Desai
@ 2025-06-17 14:07 ` Stefan Hajnoczi
2025-06-17 18:36 ` [PATCH v2] " Tanish Desai
2025-06-17 19:43 ` [PATCH 1/3] " Alex Bennée
1 sibling, 1 reply; 10+ messages in thread
From: Stefan Hajnoczi @ 2025-06-17 14:07 UTC (permalink / raw)
To: Tanish Desai; +Cc: qemu-devel, Lluís Vilanova, Paolo Bonzini, Mads Ynddal
[-- Attachment #1: Type: text/plain, Size: 668 bytes --]
On Mon, Jun 16, 2025 at 08:12:20PM +0000, Tanish Desai wrote:
> The vcpu property is no longer used in these backends. Removing it avoids
> unnecessary checks and simplifies the code generation for these trace backends.
>
> Signed-off-by: Tanish Desai <tanishdesai37@gmail.com>
> ---
> scripts/tracetool/backend/log.py | 6 +-----
> scripts/tracetool/backend/simple.py | 6 +-----
> scripts/tracetool/backend/syslog.py | 6 +-----
> 3 files changed, 3 insertions(+), 15 deletions(-)
Please also remove "vcpu" from scripts/tracetool/__init__.py:Event:
_VALID_PROPS = set(["disable", "vcpu"])
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2] tracetool: removed the unused vcpu property
2025-06-17 14:07 ` Stefan Hajnoczi
@ 2025-06-17 18:36 ` Tanish Desai
0 siblings, 0 replies; 10+ messages in thread
From: Tanish Desai @ 2025-06-17 18:36 UTC (permalink / raw)
To: qemu-devel; +Cc: pbonzini, mads, stefanha, Tanish Desai
The vcpu property is no longer used in these backends. Removing it avoids
unnecessary checks and simplifies the code generation for these trace backends.
Signed-off-by: Tanish Desai <tanishdesai37@gmail.com>
---
scripts/tracetool/__init__.py | 6 +++---
scripts/tracetool/backend/log.py | 6 +-----
scripts/tracetool/backend/simple.py | 6 +-----
scripts/tracetool/backend/syslog.py | 6 +-----
4 files changed, 6 insertions(+), 18 deletions(-)
diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py
index bc03238c0f..e86c898a1e 100644
--- a/scripts/tracetool/__init__.py
+++ b/scripts/tracetool/__init__.py
@@ -216,9 +216,9 @@ class Event(object):
r"\s*"
r"(?:(?:(?P<fmt_trans>\".+),)?\s*(?P<fmt>\".+))?"
r"\s*")
-
- _VALID_PROPS = set(["disable", "vcpu"])
-
+
+ _VALID_PROPS = set(["disable"])
+
def __init__(self, name, props, fmt, args, lineno, filename, orig=None,
event_trans=None, event_exec=None):
"""
diff --git a/scripts/tracetool/backend/log.py b/scripts/tracetool/backend/log.py
index de27b7e62e..f24acad74c 100644
--- a/scripts/tracetool/backend/log.py
+++ b/scripts/tracetool/backend/log.py
@@ -31,11 +31,7 @@ def generate_h(event, group):
if len(event.args) > 0:
argnames = ", " + argnames
- if "vcpu" in event.properties:
- # already checked on the generic format code
- cond = "true"
- else:
- cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper())
+ cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper())
out(' if (%(cond)s && qemu_loglevel_mask(LOG_TRACE)) {',
' if (message_with_timestamp) {',
diff --git a/scripts/tracetool/backend/simple.py b/scripts/tracetool/backend/simple.py
index 2688d4b64b..7c84c06b20 100644
--- a/scripts/tracetool/backend/simple.py
+++ b/scripts/tracetool/backend/simple.py
@@ -37,11 +37,7 @@ def generate_h_begin(events, group):
def generate_h(event, group):
event_id = 'TRACE_' + event.name.upper()
- if "vcpu" in event.properties:
- # already checked on the generic format code
- cond = "true"
- else:
- cond = "trace_event_get_state(%s)" % event_id
+ cond = "trace_event_get_state(%s)" % event_id
out(' if (%(cond)s) {',
' _simple_%(api)s(%(args)s);',
' }',
diff --git a/scripts/tracetool/backend/syslog.py b/scripts/tracetool/backend/syslog.py
index 012970f6cc..6fdc1142fb 100644
--- a/scripts/tracetool/backend/syslog.py
+++ b/scripts/tracetool/backend/syslog.py
@@ -30,11 +30,7 @@ def generate_h(event, group):
if len(event.args) > 0:
argnames = ", " + argnames
- if "vcpu" in event.properties:
- # already checked on the generic format code
- cond = "true"
- else:
- cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper())
+ cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper())
out(' if (%(cond)s) {',
'#line %(event_lineno)d "%(event_filename)s"',
--
2.34.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 1/3] tracetool: removed the unused vcpu property
2025-06-16 20:12 ` [PATCH 1/3] tracetool: removed the unused vcpu property Tanish Desai
2025-06-17 14:07 ` Stefan Hajnoczi
@ 2025-06-17 19:43 ` Alex Bennée
1 sibling, 0 replies; 10+ messages in thread
From: Alex Bennée @ 2025-06-17 19:43 UTC (permalink / raw)
To: Tanish Desai
Cc: qemu-devel, Lluís Vilanova, Paolo Bonzini, Mads Ynddal,
Stefan Hajnoczi
Tanish Desai <tanishdesai37@gmail.com> writes:
> The vcpu property is no longer used in these backends. Removing it avoids
> unnecessary checks and simplifies the code generation for these trace backends.
>
> Signed-off-by: Tanish Desai <tanishdesai37@gmail.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 2/3] tracetool: introduce generate_unconditional
2025-06-16 20:12 [PATCH 0/3] tracetool:cleanup "if(true)" check from trace_foo() Tanish Desai
2025-06-16 20:12 ` [PATCH 1/3] tracetool: removed the unused vcpu property Tanish Desai
@ 2025-06-16 20:12 ` Tanish Desai
2025-06-17 22:42 ` Alex Bennée
2025-06-16 20:12 ` [PATCH 3/3] tracetool: remove redundant event_get_state checks Tanish Desai
2025-06-17 14:09 ` [PATCH 0/3] tracetool:cleanup "if(true)" check from trace_foo() Stefan Hajnoczi
3 siblings, 1 reply; 10+ messages in thread
From: Tanish Desai @ 2025-06-16 20:12 UTC (permalink / raw)
To: qemu-devel
Cc: Lluís Vilanova, Paolo Bonzini, Mads Ynddal, Stefan Hajnoczi,
Tanish Desai
This patch separates the generation logic of trace_foo() for the UST and DTrace backends from other backends.
The motivation is to remove the unnecessary if (true) in the _no_check function, as UST and DTrace do not require a trace_event_get_state check without introducing a seperate function it is very difficult to generate code which keeps them out of unified if condition.
With this separation, we can safely move the trace_event_get_state check into trace_foo for the other backends only, keeping UST/DTrace generation paths clean.
A new generate_h_unconditional function has been introduced for UST and DTrace. It behaves similarly to generate_h, but is defined only in UST and DTrace backends. This ensures that generate_h is used by the other backends, while UST/DTrace selectively use generate_h_unconditional.
Signed-off-by: Tanish Desai <tanishdesai37@gmail.com>
---
scripts/tracetool/backend/__init__.py | 3 +++
scripts/tracetool/backend/dtrace.py | 3 ++-
scripts/tracetool/backend/ust.py | 2 +-
scripts/tracetool/format/h.py | 10 +++++++---
4 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/scripts/tracetool/backend/__init__.py b/scripts/tracetool/backend/__init__.py
index 7bfcc86cc5..c4456a5efd 100644
--- a/scripts/tracetool/backend/__init__.py
+++ b/scripts/tracetool/backend/__init__.py
@@ -118,6 +118,9 @@ def generate_begin(self, events, group):
def generate(self, event, group):
self._run_function("generate_%s", event, group)
+ def generate_unconditional(self, event, group):
+ self._run_function("generate_%s_unconditional", event, group)
+
def generate_backend_dstate(self, event, group):
self._run_function("generate_%s_backend_dstate", event, group)
diff --git a/scripts/tracetool/backend/dtrace.py b/scripts/tracetool/backend/dtrace.py
index e17edc9b9d..171b7e09ed 100644
--- a/scripts/tracetool/backend/dtrace.py
+++ b/scripts/tracetool/backend/dtrace.py
@@ -61,7 +61,8 @@ def generate_h_begin(events, group):
'#endif',
uppername=e.name.upper())
-def generate_h(event, group):
+
+def generate_h_unconditional(event, group):
out(' QEMU_%(uppername)s(%(argnames)s);',
uppername=event.name.upper(),
argnames=", ".join(event.args.names()))
diff --git a/scripts/tracetool/backend/ust.py b/scripts/tracetool/backend/ust.py
index c857516f21..1564b490ec 100644
--- a/scripts/tracetool/backend/ust.py
+++ b/scripts/tracetool/backend/ust.py
@@ -30,7 +30,7 @@ def generate_h_begin(events, group):
'')
-def generate_h(event, group):
+def generate_h_unconditional(event, group):
argnames = ", ".join(event.args.names())
if len(event.args) > 0:
argnames = ", " + argnames
diff --git a/scripts/tracetool/format/h.py b/scripts/tracetool/format/h.py
index ea126b07ea..89d54b9aff 100644
--- a/scripts/tracetool/format/h.py
+++ b/scripts/tracetool/format/h.py
@@ -76,13 +76,17 @@ def generate(events, backend, group):
out('',
'static inline void %(api)s(%(args)s)',
'{',
- ' if (%(cond)s) {',
+ api=e.api(),
+ args=e.args)
+
+ if "disable" not in e.properties:
+ backend.generate_unconditional(e, group)
+
+ out(' if (%(cond)s) {',
' %(api_nocheck)s(%(names)s);',
' }',
'}',
- api=e.api(),
api_nocheck=e.api(e.QEMU_TRACE_NOCHECK),
- args=e.args,
names=", ".join(e.args.names()),
cond=cond)
--
2.34.1
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH 2/3] tracetool: introduce generate_unconditional
2025-06-16 20:12 ` [PATCH 2/3] tracetool: introduce generate_unconditional Tanish Desai
@ 2025-06-17 22:42 ` Alex Bennée
2025-06-18 16:23 ` Tanish Desai
0 siblings, 1 reply; 10+ messages in thread
From: Alex Bennée @ 2025-06-17 22:42 UTC (permalink / raw)
To: Tanish Desai
Cc: qemu-devel, Lluís Vilanova, Paolo Bonzini, Mads Ynddal,
Stefan Hajnoczi
Tanish Desai <tanishdesai37@gmail.com> writes:
> This patch separates the generation logic of trace_foo() for the UST and DTrace backends from other backends.
> The motivation is to remove the unnecessary if (true) in the _no_check function, as UST and DTrace do not require a trace_event_get_state check without introducing a seperate function it is very difficult to generate code which keeps them out of unified if condition.
> With this separation, we can safely move the trace_event_get_state check into trace_foo for the other backends only, keeping UST/DTrace generation paths clean.
> A new generate_h_unconditional function has been introduced for UST
> and DTrace. It behaves similarly to generate_h, but is defined only in
> UST and DTrace backends. This ensures that generate_h is used by the
> other backends, while UST/DTrace selectively use
> generate_h_unconditional.
Please fix the word wrap on the commit at 78 chars.
>
> Signed-off-by: Tanish Desai <tanishdesai37@gmail.com>
> ---
> scripts/tracetool/backend/__init__.py | 3 +++
> scripts/tracetool/backend/dtrace.py | 3 ++-
> scripts/tracetool/backend/ust.py | 2 +-
> scripts/tracetool/format/h.py | 10 +++++++---
> 4 files changed, 13 insertions(+), 5 deletions(-)
>
> diff --git a/scripts/tracetool/backend/__init__.py b/scripts/tracetool/backend/__init__.py
> index 7bfcc86cc5..c4456a5efd 100644
> --- a/scripts/tracetool/backend/__init__.py
> +++ b/scripts/tracetool/backend/__init__.py
> @@ -118,6 +118,9 @@ def generate_begin(self, events, group):
> def generate(self, event, group):
> self._run_function("generate_%s", event, group)
>
> + def generate_unconditional(self, event, group):
> + self._run_function("generate_%s_unconditional", event, group)
> +
> def generate_backend_dstate(self, event, group):
> self._run_function("generate_%s_backend_dstate", event, group)
>
> diff --git a/scripts/tracetool/backend/dtrace.py b/scripts/tracetool/backend/dtrace.py
> index e17edc9b9d..171b7e09ed 100644
> --- a/scripts/tracetool/backend/dtrace.py
> +++ b/scripts/tracetool/backend/dtrace.py
> @@ -61,7 +61,8 @@ def generate_h_begin(events, group):
> '#endif',
> uppername=e.name.upper())
>
> -def generate_h(event, group):
> +
stray newline
> +def generate_h_unconditional(event, group):
> out(' QEMU_%(uppername)s(%(argnames)s);',
> uppername=event.name.upper(),
> argnames=", ".join(event.args.names()))
> diff --git a/scripts/tracetool/backend/ust.py b/scripts/tracetool/backend/ust.py
> index c857516f21..1564b490ec 100644
> --- a/scripts/tracetool/backend/ust.py
> +++ b/scripts/tracetool/backend/ust.py
> @@ -30,7 +30,7 @@ def generate_h_begin(events, group):
> '')
>
>
> -def generate_h(event, group):
> +def generate_h_unconditional(event, group):
> argnames = ", ".join(event.args.names())
> if len(event.args) > 0:
> argnames = ", " + argnames
> diff --git a/scripts/tracetool/format/h.py b/scripts/tracetool/format/h.py
> index ea126b07ea..89d54b9aff 100644
> --- a/scripts/tracetool/format/h.py
> +++ b/scripts/tracetool/format/h.py
> @@ -76,13 +76,17 @@ def generate(events, backend, group):
> out('',
> 'static inline void %(api)s(%(args)s)',
> '{',
> - ' if (%(cond)s) {',
> + api=e.api(),
> + args=e.args)
> +
> + if "disable" not in e.properties:
> + backend.generate_unconditional(e, group)
> +
> + out(' if (%(cond)s) {',
> ' %(api_nocheck)s(%(names)s);',
> ' }',
> '}',
> - api=e.api(),
> api_nocheck=e.api(e.QEMU_TRACE_NOCHECK),
> - args=e.args,
> names=", ".join(e.args.names()),
> cond=cond)
Otherwise:
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH 2/3] tracetool: introduce generate_unconditional
2025-06-17 22:42 ` Alex Bennée
@ 2025-06-18 16:23 ` Tanish Desai
0 siblings, 0 replies; 10+ messages in thread
From: Tanish Desai @ 2025-06-18 16:23 UTC (permalink / raw)
To: Alex Bennée
Cc: qemu-devel, Lluís Vilanova, Paolo Bonzini, Mads Ynddal,
Stefan Hajnoczi
[-- Attachment #1: Type: text/plain, Size: 4546 bytes --]
> Please fix the word wrap on the commit at 78 chars.
I will send v2 with this fix
> stray newline
In tracetool/backend, every function is followed by two newline characters.
On Wed, Jun 18, 2025 at 4:12 AM Alex Bennée <alex.bennee@linaro.org> wrote:
> Tanish Desai <tanishdesai37@gmail.com> writes:
>
> > This patch separates the generation logic of trace_foo() for the UST and
> DTrace backends from other backends.
> > The motivation is to remove the unnecessary if (true) in the _no_check
> function, as UST and DTrace do not require a trace_event_get_state check
> without introducing a seperate function it is very difficult to generate
> code which keeps them out of unified if condition.
> > With this separation, we can safely move the trace_event_get_state check
> into trace_foo for the other backends only, keeping UST/DTrace generation
> paths clean.
> > A new generate_h_unconditional function has been introduced for UST
> > and DTrace. It behaves similarly to generate_h, but is defined only in
> > UST and DTrace backends. This ensures that generate_h is used by the
> > other backends, while UST/DTrace selectively use
> > generate_h_unconditional.
>
> Please fix the word wrap on the commit at 78 chars.
>
> >
> > Signed-off-by: Tanish Desai <tanishdesai37@gmail.com>
> > ---
> > scripts/tracetool/backend/__init__.py | 3 +++
> > scripts/tracetool/backend/dtrace.py | 3 ++-
> > scripts/tracetool/backend/ust.py | 2 +-
> > scripts/tracetool/format/h.py | 10 +++++++---
> > 4 files changed, 13 insertions(+), 5 deletions(-)
> >
> > diff --git a/scripts/tracetool/backend/__init__.py
> b/scripts/tracetool/backend/__init__.py
> > index 7bfcc86cc5..c4456a5efd 100644
> > --- a/scripts/tracetool/backend/__init__.py
> > +++ b/scripts/tracetool/backend/__init__.py
> > @@ -118,6 +118,9 @@ def generate_begin(self, events, group):
> > def generate(self, event, group):
> > self._run_function("generate_%s", event, group)
> >
> > + def generate_unconditional(self, event, group):
> > + self._run_function("generate_%s_unconditional", event, group)
> > +
> > def generate_backend_dstate(self, event, group):
> > self._run_function("generate_%s_backend_dstate", event, group)
> >
> > diff --git a/scripts/tracetool/backend/dtrace.py
> b/scripts/tracetool/backend/dtrace.py
> > index e17edc9b9d..171b7e09ed 100644
> > --- a/scripts/tracetool/backend/dtrace.py
> > +++ b/scripts/tracetool/backend/dtrace.py
> > @@ -61,7 +61,8 @@ def generate_h_begin(events, group):
> > '#endif',
> > uppername=e.name.upper())
> >
> > -def generate_h(event, group):
> > +
>
> stray newline
>
> > +def generate_h_unconditional(event, group):
> > out(' QEMU_%(uppername)s(%(argnames)s);',
> > uppername=event.name.upper(),
> > argnames=", ".join(event.args.names()))
> > diff --git a/scripts/tracetool/backend/ust.py
> b/scripts/tracetool/backend/ust.py
> > index c857516f21..1564b490ec 100644
> > --- a/scripts/tracetool/backend/ust.py
> > +++ b/scripts/tracetool/backend/ust.py
> > @@ -30,7 +30,7 @@ def generate_h_begin(events, group):
> > '')
> >
> >
> > -def generate_h(event, group):
> > +def generate_h_unconditional(event, group):
> > argnames = ", ".join(event.args.names())
> > if len(event.args) > 0:
> > argnames = ", " + argnames
> > diff --git a/scripts/tracetool/format/h.py
> b/scripts/tracetool/format/h.py
> > index ea126b07ea..89d54b9aff 100644
> > --- a/scripts/tracetool/format/h.py
> > +++ b/scripts/tracetool/format/h.py
> > @@ -76,13 +76,17 @@ def generate(events, backend, group):
> > out('',
> > 'static inline void %(api)s(%(args)s)',
> > '{',
> > - ' if (%(cond)s) {',
> > + api=e.api(),
> > + args=e.args)
> > +
> > + if "disable" not in e.properties:
> > + backend.generate_unconditional(e, group)
> > +
> > + out(' if (%(cond)s) {',
> > ' %(api_nocheck)s(%(names)s);',
> > ' }',
> > '}',
> > - api=e.api(),
> > api_nocheck=e.api(e.QEMU_TRACE_NOCHECK),
> > - args=e.args,
> > names=", ".join(e.args.names()),
> > cond=cond)
>
> Otherwise:
>
> Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
>
>
> --
> Alex Bennée
> Virtualisation Tech Lead @ Linaro
>
[-- Attachment #2: Type: text/html, Size: 5958 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 3/3] tracetool: remove redundant event_get_state checks
2025-06-16 20:12 [PATCH 0/3] tracetool:cleanup "if(true)" check from trace_foo() Tanish Desai
2025-06-16 20:12 ` [PATCH 1/3] tracetool: removed the unused vcpu property Tanish Desai
2025-06-16 20:12 ` [PATCH 2/3] tracetool: introduce generate_unconditional Tanish Desai
@ 2025-06-16 20:12 ` Tanish Desai
2025-06-17 14:09 ` [PATCH 0/3] tracetool:cleanup "if(true)" check from trace_foo() Stefan Hajnoczi
3 siblings, 0 replies; 10+ messages in thread
From: Tanish Desai @ 2025-06-16 20:12 UTC (permalink / raw)
To: qemu-devel
Cc: Lluís Vilanova, Paolo Bonzini, Mads Ynddal, Stefan Hajnoczi,
Tanish Desai
Moved trace_event_get_state check from _no_check_trace_foo to trace_foo, and removed
if (true) checks. The _no_check_trace_foo now only emits backend-specific core
logic, avoiding trace event conditionals entirely.
This brings conditional logic in format/h.py, reducing duplication across
backends and simplifying their code generation. It also removes one conditional
branch instruction from the fast path (trace_foo), improving runtime performance slightly(for some old compiler).
---
scripts/tracetool/backend/ftrace.py | 3 ---
scripts/tracetool/backend/log.py | 5 +----
scripts/tracetool/backend/simple.py | 7 +------
scripts/tracetool/backend/syslog.py | 7 +------
scripts/tracetool/format/h.py | 3 ++-
5 files changed, 5 insertions(+), 20 deletions(-)
diff --git a/scripts/tracetool/backend/ftrace.py b/scripts/tracetool/backend/ftrace.py
index baed2ae61c..2d6d608add 100644
--- a/scripts/tracetool/backend/ftrace.py
+++ b/scripts/tracetool/backend/ftrace.py
@@ -34,18 +34,15 @@ 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)) {',
'#line %(event_lineno)d "%(event_filename)s"',
' trlen = snprintf(ftrace_buf, MAX_TRACE_STRLEN,',
' "%(name)s " %(fmt)s "\\n" %(argnames)s);',
'#line %(out_next_lineno)d "%(out_filename)s"',
' trlen = MIN(trlen, MAX_TRACE_STRLEN - 1);',
' unused = write(trace_marker_fd, ftrace_buf, trlen);',
- ' }',
' }',
name=event.name,
args=event.args,
- event_id="TRACE_" + event.name.upper(),
event_lineno=event.lineno,
event_filename=os.path.relpath(event.filename),
fmt=event.fmt.rstrip("\n"),
diff --git a/scripts/tracetool/backend/log.py b/scripts/tracetool/backend/log.py
index f24acad74c..35a3aeee55 100644
--- a/scripts/tracetool/backend/log.py
+++ b/scripts/tracetool/backend/log.py
@@ -31,9 +31,7 @@ def generate_h(event, group):
if len(event.args) > 0:
argnames = ", " + argnames
- cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper())
-
- out(' if (%(cond)s && qemu_loglevel_mask(LOG_TRACE)) {',
+ out(' if (qemu_loglevel_mask(LOG_TRACE)) {',
' if (message_with_timestamp) {',
' struct timeval _now;',
' gettimeofday(&_now, NULL);',
@@ -49,7 +47,6 @@ def generate_h(event, group):
'#line %(out_next_lineno)d "%(out_filename)s"',
' }',
' }',
- cond=cond,
event_lineno=event.lineno,
event_filename=os.path.relpath(event.filename),
name=event.name,
diff --git a/scripts/tracetool/backend/simple.py b/scripts/tracetool/backend/simple.py
index 7c84c06b20..ce8036f5da 100644
--- a/scripts/tracetool/backend/simple.py
+++ b/scripts/tracetool/backend/simple.py
@@ -36,13 +36,8 @@ def generate_h_begin(events, group):
def generate_h(event, group):
- event_id = 'TRACE_' + event.name.upper()
- cond = "trace_event_get_state(%s)" % event_id
- out(' if (%(cond)s) {',
- ' _simple_%(api)s(%(args)s);',
- ' }',
+ out(' _simple_%(api)s(%(args)s);',
api=event.api(),
- cond=cond,
args=", ".join(event.args.names()))
diff --git a/scripts/tracetool/backend/syslog.py b/scripts/tracetool/backend/syslog.py
index 6fdc1142fb..f84cec641c 100644
--- a/scripts/tracetool/backend/syslog.py
+++ b/scripts/tracetool/backend/syslog.py
@@ -30,14 +30,9 @@ def generate_h(event, group):
if len(event.args) > 0:
argnames = ", " + argnames
- cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper())
-
- out(' if (%(cond)s) {',
- '#line %(event_lineno)d "%(event_filename)s"',
+ out('#line %(event_lineno)d "%(event_filename)s"',
' syslog(LOG_INFO, "%(name)s " %(fmt)s %(argnames)s);',
'#line %(out_next_lineno)d "%(out_filename)s"',
- ' }',
- cond=cond,
event_lineno=event.lineno,
event_filename=os.path.relpath(event.filename),
name=event.name,
diff --git a/scripts/tracetool/format/h.py b/scripts/tracetool/format/h.py
index 89d54b9aff..7bbe6d3148 100644
--- a/scripts/tracetool/format/h.py
+++ b/scripts/tracetool/format/h.py
@@ -71,7 +71,8 @@ def generate(events, backend, group):
out('}')
- cond = "true"
+ event_id = 'TRACE_' + e.name.upper()
+ cond = "trace_event_get_state(%s)" % event_id
out('',
'static inline void %(api)s(%(args)s)',
--
2.34.1
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH 0/3] tracetool:cleanup "if(true)" check from trace_foo()
2025-06-16 20:12 [PATCH 0/3] tracetool:cleanup "if(true)" check from trace_foo() Tanish Desai
` (2 preceding siblings ...)
2025-06-16 20:12 ` [PATCH 3/3] tracetool: remove redundant event_get_state checks Tanish Desai
@ 2025-06-17 14:09 ` Stefan Hajnoczi
3 siblings, 0 replies; 10+ messages in thread
From: Stefan Hajnoczi @ 2025-06-17 14:09 UTC (permalink / raw)
To: Tanish Desai
Cc: qemu-devel, Lluís Vilanova, Paolo Bonzini, Mads Ynddal,
Alex Bennée
[-- Attachment #1: Type: text/plain, Size: 1381 bytes --]
On Mon, Jun 16, 2025 at 08:12:19PM +0000, Tanish Desai wrote:
> This series of patch aims to removes the leftover if (true) condition from trace_foo, a remnant from the TCG tracing feature removal.
> It replaces it with a proper trace_event_get_state(...) check where necessary(for log/simple/syslog and ftrace backend).
> Additionally, this change centralizes the generation of trace_event_get_state(...) calls into format/h.py,
> eliminating redundant code across individual backends.
> This cleanup results in more consistent and less repetitive backend code.
CCing Alex Bennée, who authored commit 126d4123c50a ("tracing: excise
the tcg related from tracetool").
>
> Tanish Desai (3):
> tracetool: removed the unused vcpu property
> tracetool: introduce generate_unconditional
> tracetool: remove redundant event_get_state checks
>
> scripts/tracetool/backend/__init__.py | 3 +++
> scripts/tracetool/backend/dtrace.py | 3 ++-
> scripts/tracetool/backend/ftrace.py | 3 ---
> scripts/tracetool/backend/log.py | 9 +--------
> scripts/tracetool/backend/simple.py | 11 +----------
> scripts/tracetool/backend/syslog.py | 11 +----------
> scripts/tracetool/backend/ust.py | 2 +-
> scripts/tracetool/format/h.py | 13 +++++++++----
> 8 files changed, 18 insertions(+), 37 deletions(-)
>
> --
> 2.34.1
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread