Re: [PATCH 19/20] perf tools: Reference count struct thread

From: Arnaldo Carvalho de Melo
Date: Tue Mar 03 2015 - 08:57:35 EST


Em Tue, Mar 03, 2015 at 10:42:14PM +0900, Namhyung Kim escreveu:
> On Tue, Mar 03, 2015 at 12:26:08AM -0300, Arnaldo Carvalho de Melo wrote:
> > +++ b/tools/perf/util/thread.c
> > @@ -82,6 +82,20 @@ void thread__delete(struct thread *thread)

> > +struct thread *thread__get(struct thread *thread)
> > +{
> > + ++thread->refcnt;
> > + return thread;
> > +}

> > +void thread__put(struct thread *thread)
> > +{
> > + if (thread && --thread->refcnt == 0) {
> > + list_del_init(&thread->node);
> > + thread__delete(thread);
> > + }
> > +}

> I think we need to protect refcnt from concurrent accesses from
> multiple threads. Not to mention my multi-thread work, perf top
> already uses two threads.

Sure

> For perf top case, hist_entry__new() will be called from main thread
> and hist_entry__delete() might be called from display thread.

Reference counting is a step in that direction, as to if the integer
inc/dec is enough or is already surrounded by existing serialization
needs to be checked.

- Arnaldo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/