All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrange" <berrange@redhat.com>
To: qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v2 4/6] trace: remove global 'uint16 dstate[]' array
Date: Thu, 15 Sep 2016 10:11:12 +0100	[thread overview]
Message-ID: <20160915091112.GE26068@redhat.com> (raw)
In-Reply-To: <87fup2w0na.fsf@fimbulvetr.bsc.es>

On Thu, Sep 15, 2016 at 12:56:57AM +0200, Lluís Vilanova wrote:
> Daniel P Berrange writes:
> 
> > Instead of having a global dstate array, declare a single
> > 'uint16 TRACE_${EVENT_NAME}_DSTATE' variable for each
> > trace event. Record a pointer to this variable in the
> > TraceEvent struct too.
> 
> > By turning trace_event_get_state_dynamic_by_id into a
> > macro, this still hits the fast path, and cache affinity
> > is ensured by declaring all the uint16 vars adjacent to
> > each other.
> 
> > Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
> > ---
> >  scripts/tracetool/format/events_c.py |  6 +++++-
> >  scripts/tracetool/format/events_h.py |  3 +++
> >  stubs/trace-control.c                |  9 ++++-----
> >  trace/control-internal.h             | 14 ++++----------
> >  trace/control-target.c               | 20 ++++++++------------
> >  trace/control.c                      | 11 ++---------
> >  trace/event-internal.h               |  6 ++++++
> >  7 files changed, 32 insertions(+), 37 deletions(-)
> 
> > diff --git a/scripts/tracetool/format/events_c.py b/scripts/tracetool/format/events_c.py
> > index 4012063..a2f457f 100644
> > --- a/scripts/tracetool/format/events_c.py
> > +++ b/scripts/tracetool/format/events_c.py
> > @@ -25,6 +25,9 @@ def generate(events, backend):
> >          '#include "trace/control.h"',
> >          '')
>  
> > +    for e in events:
> > +        out('uint16_t TRACE_%s_DSTATE;' % e.name.upper())
> > +
> >      out('TraceEvent trace_events[TRACE_EVENT_COUNT] = {')
>  
> >      for e in events:
> 
> I would emit an "obviously non-public" variable name, like
> ___TRACE_%s_dstate. The "TRACE_%s" is only necesary for consistency with the
> "public name" and macro trickery on the fast path.
> 
> To make naming consistency easier to track, you can use Event.api(), which needs
> only a small extension ("scripts/tracetool/__init__.py"):
> 
>     QEMU_TRACE               = "trace_%(name)s"
>     QEMU_TRACE_TCG           = QEMU_TRACE + "_tcg"
> 
>     QEMU_DSTATE              = "___TRACE_%(NAME)s_dstate"
> 
>     def api(self, fmt=None):
>         if fmt is None:
>             fmt = Event.QEMU_TRACE
>         return fmt % {"name": self.name, "NAME": self.name.upper()}
> 
> Then change all the places where you generate the dstate symbol name to
> something like:
> 
>     out('uint16_t ' + e.api(e.QEMU_DSTATE)) + ';')

Ah interesting, I hadn't noticed the Event.api() method.

> > @@ -54,18 +53,13 @@ static inline bool trace_event_get_state_static(TraceEvent *ev)
> >      return ev->sstate;
> >  }
>  
> > -static inline bool trace_event_get_state_dynamic_by_id(TraceEventID id)
> > -{
> > -    /* it's on fast path, avoid consistency checks (asserts) */
> > -    return unlikely(trace_events_enabled_count) && trace_events_dstate[id];
> > -}
> > +/* it's on fast path, avoid consistency checks (asserts) */
> > +#define trace_event_get_state_dynamic_by_id(id) \
> > +    (unlikely(trace_events_enabled_count) && id ## _DSTATE)
>  
> >  static inline bool trace_event_get_state_dynamic(TraceEvent *ev)
> >  {
> > -    TraceEventID id;
> > -    assert(trace_event_get_state_static(ev));
> > -    id = trace_event_get_id(ev);
> > -    return trace_event_get_state_dynamic_by_id(id);
> > +    return unlikely(trace_events_enabled_count) && *ev->dstate;
> 
> This one is not on the fast path, so there's no need for the first part of the
> AND (shouldn't hurt performance to keep it either).

Yep, I just figured it'd be nice to keep the two methods having the
same logic even if this second one isn't so performance critical.

Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

  reply	other threads:[~2016-09-15  9:11 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-14 17:08 [Qemu-devel] [PATCH v2 0/6] Prep changes for modular trace-events build Daniel P. Berrange
2016-09-14 17:08 ` [Qemu-devel] [PATCH v2 1/6] trace: add trace event iterator APIs Daniel P. Berrange
2016-09-14 21:53   ` Lluís Vilanova
2016-09-15  9:07     ` Daniel P. Berrange
2016-09-14 17:08 ` [Qemu-devel] [PATCH v2 2/6] trace: convert code to use event iterators Daniel P. Berrange
2016-09-14 22:16   ` Lluís Vilanova
2016-09-15  9:09     ` Daniel P. Berrange
2016-09-14 17:08 ` [Qemu-devel] [PATCH v2 3/6] trace: remove some now unused functions Daniel P. Berrange
2016-09-14 22:21   ` Lluís Vilanova
2016-09-14 17:08 ` [Qemu-devel] [PATCH v2 4/6] trace: remove global 'uint16 dstate[]' array Daniel P. Berrange
2016-09-14 22:56   ` Lluís Vilanova
2016-09-15  9:11     ` Daniel P. Berrange [this message]
2016-09-14 17:08 ` [Qemu-devel] [PATCH v2 5/6] trace: remove use of event ID enums from APIs Daniel P. Berrange
2016-09-14 23:26   ` Lluís Vilanova
2016-09-15  9:26     ` Daniel P. Berrange
2016-09-15 12:20       ` Lluís Vilanova
2016-09-15 12:29         ` Daniel P. Berrange
2016-09-14 17:08 ` [Qemu-devel] [PATCH v2 6/6] trace: use -1 instead of TRACE_VCPU_EVENT_COUNT as magic value Daniel P. Berrange
2016-09-14 23:12   ` Lluís Vilanova
2016-09-14 19:41 ` [Qemu-devel] [PATCH v2 0/6] Prep changes for modular trace-events build no-reply

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=20160915091112.GE26068@redhat.com \
    --to=berrange@redhat.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.