linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Bryton Lee <brytonlee01@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>,
	linux-kernel@vger.kernel.org, Namhyung Kim <namhyung@kernel.org>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Andi Kleen <andi@firstfloor.org>, David Ahern <dsahern@gmail.com>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Jiri Olsa <jolsa@redhat.com>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Stephane Eranian <eranian@google.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: Re: [PATCH 13/18] perf symbols: Protect dso cache tree using dso->lock
Date: Fri, 29 Jul 2016 12:09:01 -0300	[thread overview]
Message-ID: <20160729150901.GA26514@kernel.org> (raw)
In-Reply-To: <CAC2pzGf6-b9grQBo=aedqM_OsYfcSaDmXoCEvmYfBsbcO5CrwQ@mail.gmail.com>

Em Fri, Jul 29, 2016 at 08:56:32PM +0800, Bryton Lee escreveu:
> Sorry for disturb you! maybe my question isn't  a good question, but I
> do want to know what situation made dwarf callchain unwind process
> concurrently, can you guys give a example to elaborate on that. thank
> you very much!

IIRC that was for things like 'perf top --call-graph dwarf', where there
are two threads, one traversing a set of histograms to present them on
the screen and another creating another set of histograms from events it
reads from the perf mmap, Jiri?

- Arnaldo
 
> On Mon, May 18, 2015 at 11:50 PM, Arnaldo Carvalho de Melo
> <acme@kernel.org> wrote:
> > From: Namhyung Kim <namhyung@kernel.org>
> >
> > The dso cache is accessed during dwarf callchain unwind and it might be
> > processed concurrently.  Protect it under dso->lock.
> >
> > Note that it doesn't protect dso_cache__find().  I think it's safe to
> > access to the cache tree without the lock since we don't delete nodes.
> >
> > It it missed an existing node due to rotation, it'll find it during
> > dso_cache__insert() anyway.
> >
> > Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> > Cc: Adrian Hunter <adrian.hunter@intel.com>
> > Cc: Andi Kleen <andi@firstfloor.org>
> > Cc: David Ahern <dsahern@gmail.com>
> > Cc: Frederic Weisbecker <fweisbec@gmail.com>
> > Cc: Jiri Olsa <jolsa@redhat.com>
> > Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
> > Cc: Stephane Eranian <eranian@google.com>
> > Link: http://lkml.kernel.org/r/1431909055-21442-27-git-send-email-namhyung@kernel.org
> > Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> > ---
> >  tools/perf/util/dso.c | 34 +++++++++++++++++++++++++++-------
> >  1 file changed, 27 insertions(+), 7 deletions(-)
> >
> > diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
> > index 482d6024ef13..666e1db44541 100644
> > --- a/tools/perf/util/dso.c
> > +++ b/tools/perf/util/dso.c
> > @@ -495,10 +495,12 @@ bool dso__data_status_seen(struct dso *dso, enum dso_data_status_seen by)
> >  }
> >
> >  static void
> > -dso_cache__free(struct rb_root *root)
> > +dso_cache__free(struct dso *dso)
> >  {
> > +       struct rb_root *root = &dso->data.cache;
> >         struct rb_node *next = rb_first(root);
> >
> > +       pthread_mutex_lock(&dso->lock);
> >         while (next) {
> >                 struct dso_cache *cache;
> >
> > @@ -507,10 +509,12 @@ dso_cache__free(struct rb_root *root)
> >                 rb_erase(&cache->rb_node, root);
> >                 free(cache);
> >         }
> > +       pthread_mutex_unlock(&dso->lock);
> >  }
> >
> > -static struct dso_cache *dso_cache__find(const struct rb_root *root, u64 offset)
> > +static struct dso_cache *dso_cache__find(struct dso *dso, u64 offset)
> >  {
> > +       const struct rb_root *root = &dso->data.cache;
> >         struct rb_node * const *p = &root->rb_node;
> >         const struct rb_node *parent = NULL;
> >         struct dso_cache *cache;
> > @@ -529,17 +533,20 @@ static struct dso_cache *dso_cache__find(const struct rb_root *root, u64 offset)
> >                 else
> >                         return cache;
> >         }
> > +
> >         return NULL;
> >  }
> >
> > -static void
> > -dso_cache__insert(struct rb_root *root, struct dso_cache *new)
> > +static struct dso_cache *
> > +dso_cache__insert(struct dso *dso, struct dso_cache *new)
> >  {
> > +       struct rb_root *root = &dso->data.cache;
> >         struct rb_node **p = &root->rb_node;
> >         struct rb_node *parent = NULL;
> >         struct dso_cache *cache;
> >         u64 offset = new->offset;
> >
> > +       pthread_mutex_lock(&dso->lock);
> >         while (*p != NULL) {
> >                 u64 end;
> >
> > @@ -551,10 +558,17 @@ dso_cache__insert(struct rb_root *root, struct dso_cache *new)
> >                         p = &(*p)->rb_left;
> >                 else if (offset >= end)
> >                         p = &(*p)->rb_right;
> > +               else
> > +                       goto out;
> >         }
> >
> >         rb_link_node(&new->rb_node, parent, p);
> >         rb_insert_color(&new->rb_node, root);
> > +
> > +       cache = NULL;
> > +out:
> > +       pthread_mutex_unlock(&dso->lock);
> > +       return cache;
> >  }
> >
> >  static ssize_t
> > @@ -572,6 +586,7 @@ static ssize_t
> >  dso_cache__read(struct dso *dso, u64 offset, u8 *data, ssize_t size)
> >  {
> >         struct dso_cache *cache;
> > +       struct dso_cache *old;
> >         ssize_t ret;
> >
> >         do {
> > @@ -591,7 +606,12 @@ dso_cache__read(struct dso *dso, u64 offset, u8 *data, ssize_t size)
> >
> >                 cache->offset = cache_offset;
> >                 cache->size   = ret;
> > -               dso_cache__insert(&dso->data.cache, cache);
> > +               old = dso_cache__insert(dso, cache);
> > +               if (old) {
> > +                       /* we lose the race */
> > +                       free(cache);
> > +                       cache = old;
> > +               }
> >
> >                 ret = dso_cache__memcpy(cache, offset, data, size);
> >
> > @@ -608,7 +628,7 @@ static ssize_t dso_cache_read(struct dso *dso, u64 offset,
> >  {
> >         struct dso_cache *cache;
> >
> > -       cache = dso_cache__find(&dso->data.cache, offset);
> > +       cache = dso_cache__find(dso, offset);
> >         if (cache)
> >                 return dso_cache__memcpy(cache, offset, data, size);
> >         else
> > @@ -964,7 +984,7 @@ void dso__delete(struct dso *dso)
> >
> >         dso__data_close(dso);
> >         auxtrace_cache__free(dso->auxtrace_cache);
> > -       dso_cache__free(&dso->data.cache);
> > +       dso_cache__free(dso);
> >         dso__free_a2l(dso);
> >         zfree(&dso->symsrc_filename);
> >         pthread_mutex_destroy(&dso->lock);
> > --
> > 2.1.0
> >
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > Please read the FAQ at  http://www.tux.org/lkml/
> 
> 
> 
> -- 
> Best Regards
> 
> Bryton.Lee

  reply	other threads:[~2016-07-29 15:09 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-18 15:50 [GIT PULL 00/18] perf/core improvements and fixes Arnaldo Carvalho de Melo
2015-05-18 15:50 ` [PATCH 01/18] perf tools: Use atomic.h for the map_groups refcount Arnaldo Carvalho de Melo
2015-05-18 15:50 ` [PATCH 02/18] perf machine: Stop accessing atomic_t::counter directly Arnaldo Carvalho de Melo
2015-05-18 15:50 ` [PATCH 03/18] perf evlist: Use atomic.h for the perf_mmap refcount Arnaldo Carvalho de Melo
2015-05-18 15:50 ` [PATCH 04/18] perf cgroup: Use atomic.h for refcounting Arnaldo Carvalho de Melo
2015-05-18 15:50 ` [PATCH 05/18] perf tools: Fix dwarf-aux.c compilation on i386 Arnaldo Carvalho de Melo
2015-05-18 15:50 ` [PATCH 06/18] perf tools: Fix "Command" sort_entry's cmp and collapse function Arnaldo Carvalho de Melo
2015-05-18 15:50 ` [PATCH 07/18] perf probe: Load map before glob matching Arnaldo Carvalho de Melo
2015-05-18 15:50 ` [PATCH 08/18] tools include: add __aligned_u64 to types.h Arnaldo Carvalho de Melo
2015-05-18 15:50 ` [PATCH 09/18] perf tools: Elliminate alignment holes Arnaldo Carvalho de Melo
2015-05-18 15:50 ` [PATCH 10/18] perf tools: Add rm_rf() utility function Arnaldo Carvalho de Melo
2015-05-18 15:50 ` [PATCH 11/18] perf tools: Introduce copyfile_offset() function Arnaldo Carvalho de Melo
2015-05-18 15:50 ` [PATCH 12/18] perf symbols: Protect dso symbol loading using a mutex Arnaldo Carvalho de Melo
2015-05-18 15:50 ` [PATCH 13/18] perf symbols: Protect dso cache tree using dso->lock Arnaldo Carvalho de Melo
2016-07-29 12:56   ` Bryton Lee
2016-07-29 15:09     ` Arnaldo Carvalho de Melo [this message]
2015-05-18 15:50 ` [PATCH 14/18] perf tools: Protect dso cache fd with a mutex Arnaldo Carvalho de Melo
2015-05-18 15:50 ` [PATCH 15/18] perf tools: Set vmlinux_path__nr_entries to 0 in vmlinux_path__exit Arnaldo Carvalho de Melo
2015-05-18 15:50 ` [PATCH 16/18] tools lib traceevent: Install libtraceevent.a into libdir Arnaldo Carvalho de Melo
2015-05-18 15:50 ` [PATCH 17/18] tools build: Change FEATURE_TESTS and FEATURE_DISPLAY to weak binding Arnaldo Carvalho de Melo
2015-05-18 15:50 ` [PATCH 18/18] perf bench numa: Share sched_getcpu() __weak def with cloexec.c Arnaldo Carvalho de Melo
2015-05-20 11:25 ` [GIT PULL 00/18] perf/core improvements and fixes Ingo Molnar

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=20160729150901.GA26514@kernel.org \
    --to=acme@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=andi@firstfloor.org \
    --cc=brytonlee01@gmail.com \
    --cc=dsahern@gmail.com \
    --cc=eranian@google.com \
    --cc=fweisbec@gmail.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    /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).