qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Tanish Desai <tanishdesai37@gmail.com>
To: Stefan Hajnoczi <stefanha@redhat.com>
Cc: qemu-devel@nongnu.org, Mads Ynddal <mads@ynddal.dk>,
	 Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [PATCH v2 2/3] tracetool: introduce generate_unconditional
Date: Tue, 24 Jun 2025 23:07:34 +0530	[thread overview]
Message-ID: <CAH_Y1jd9CSUZB502Vj4tYFXEsqymAGVJQ93TZ5oEZF726KGHKw@mail.gmail.com> (raw)
In-Reply-To: <20250624143701.GA5519@fedora>

[-- Attachment #1: Type: text/plain, Size: 3386 bytes --]

> 1. nocheck isn't necessary anymore. The body of nocheck could be inlined
>   here instead to simplify the generated code.
Yes I agree.I will remove nocheck and inline the body of nocheck in
trace-foo
> 2. "if (%(cond)s) {" is only useful for backends that implement
>   .generate(). For example, if only the dtrace backend is enabled then
>   "if (trace_event_get_state(...)) {}" will be emitted unnecessarily.
Yes, we should remove unnecessary if (trace_event_get_state(...)){}
blocks.

But It is difficult because backend.generate() calls
_run_function("generate_%s", event, group) which in turn loops on all
backends.Format can't call generate for individual backends.I will need
to make this map in scripts/tracetool/backend/__init__.py:_run_function().(I
think this
will not be a good thing to do).

possible fix would be to create in scripts/tracetool/backend/__init__.py
def is_conditional(self, cond_check):
    self._run_function("generate_%s_conditional", cond_check)
now cond_check will be passed to all backends and backend's will have
def is_h_conditional(cond_check):
    cond_check = cond_check or True

Finally if cond_check==True in h.py I will generate "if
(trace_event_get_state(...)) {"
else not. As the same condition is re-used this solution would work well.
Since h.py only handles reused/shared logic, it's safe to assume consistent
conditions.
If a new backend requires a different condition, it's better handled
directly in backend/*.py.


On Tue, Jun 24, 2025 at 8:07 PM Stefan Hajnoczi <stefanha@redhat.com> wrote:

> On Fri, Jun 20, 2025 at 02:37:19PM +0000, Tanish Desai wrote:
> > 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)
>
> Two thoughts:
>
> 1. nocheck isn't necessary anymore. The body of nocheck could be inlined
>    here instead to simplify the generated code.
>
> 2. "if (%(cond)s) {" is only useful for backends that implement
>    .generate(). For example, if only the dtrace backend is enabled then
>    "if (trace_event_get_state(...)) {}" will be emitted unnecessarily.
>
> Maybe backends should have a .condition() interface so that
> scripts/tracetool/format/h.py:generate() can first collect a dict[cond]
> -> backend. Then it iterates over the map, calling backend.generate()
> within "if (%(cond)s) { ... }". That way only the conditions that are
> actually needed are generated and multiple backends that have the same
> condition will share the same if statement.
>
> Stefan
>

[-- Attachment #2: Type: text/html, Size: 5263 bytes --]

  reply	other threads:[~2025-06-24 17:38 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-20 14:37 [PATCH v2 0/3] tracetool: cleanup "if(true)" check from trace_foo() Tanish Desai
2025-06-20 14:37 ` [PATCH v2 1/3] tracetool: removed the unused vcpu property Tanish Desai
2025-06-20 16:12   ` Alex Bennée
2025-06-20 16:27     ` Tanish Desai
2025-06-20 14:37 ` [PATCH v2 2/3] tracetool: introduce generate_unconditional Tanish Desai
2025-06-24 14:37   ` Stefan Hajnoczi
2025-06-24 17:37     ` Tanish Desai [this message]
2025-06-24 19:03       ` Stefan Hajnoczi
2025-06-25 12:30         ` [PATCH v3] tracetool: generates conitional checks when needed Tanish Desai
2025-06-26 18:43           ` Stefan Hajnoczi
2025-06-26 19:30             ` Tanish Desai
2025-06-20 14:37 ` [PATCH v2 3/3] tracetool: remove redundant event_get_state checks Tanish Desai
2025-06-24 14:26   ` Stefan Hajnoczi
2025-06-20 14:38 ` [PATCH v2 0/3] tracetool: cleanup "if(true)" check from trace_foo() Tanish Desai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAH_Y1jd9CSUZB502Vj4tYFXEsqymAGVJQ93TZ5oEZF726KGHKw@mail.gmail.com \
    --to=tanishdesai37@gmail.com \
    --cc=mads@ynddal.dk \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).