linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com>
To: Jiri Olsa <jolsa@redhat.com>
Cc: David Ahern <dsahern@gmail.com>, Jiri Olsa <jolsa@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Stephane Eranian <eranian@google.com>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [BUG] segfault in perf-top -- thread refcnt
Date: Mon, 30 Mar 2015 10:22:26 -0300	[thread overview]
Message-ID: <20150330132226.GD24063@kernel.org> (raw)
In-Reply-To: <20150330114907.GH1413@krava>

Em Mon, Mar 30, 2015 at 01:49:07PM +0200, Jiri Olsa escreveu:
> On Mon, Mar 30, 2015 at 01:21:08PM +0200, Jiri Olsa wrote:
> > > looks like race among __machine__findnew_thread and thread__put
> > > over the machine->threads rb_tree insert/removal

> > > is there a reason why thread__put does not erase itself from machine->threads?
 
> that was the reason.. we do this separately.. not in thread__put..
> is there a reason for this? ;-)
 
> testing attached patch..
 
>  void thread__put(struct thread *thread)
>  {
>  	if (thread && --thread->refcnt == 0) {
> +		struct machine *machine = thread->machine;
> +
>  		list_del_init(&thread->node);
> +
> +		pthread_mutex_lock(&machine->threads_lock);
> +		rb_erase(&thread->rb_node, &machine->threads);
> +		pthread_mutex_unlock(&machine->threads_lock);
> +
>  		thread__delete(thread);

You can't do that, look at the definition of struct thread:

struct thread {
        union {
                struct rb_node   rb_node;
                struct list_head node;
        };

I.e. a thread can't be at the same time in the rbtree (live threads) and
on the list (dead threads).

When the thread dies (PERF_RECORD_EXIT) we transition it from the live
threads rb_tree to the dead_threads list, where it will wait till the
last hist_entry holding a reference to it to call thread__put(), when we
will want to remove it _only_ from the dead_threads _list_.

- Arnaldo

  parent reply	other threads:[~2015-03-30 13:22 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-27 17:31 [BUG] segfault in perf-top -- thread refcnt David Ahern
2015-03-27 19:51 ` Arnaldo Carvalho de Melo
2015-03-27 20:11 ` Arnaldo Carvalho de Melo
2015-03-27 20:13   ` David Ahern
2015-03-30  8:07     ` Jiri Olsa
2015-03-30 10:22       ` Jiri Olsa
2015-03-30 11:21         ` Jiri Olsa
2015-03-30 11:49           ` Jiri Olsa
2015-03-30 12:48             ` Namhyung Kim
2015-03-30 12:56               ` Jiri Olsa
2015-03-30 13:06                 ` Namhyung Kim
2015-03-30 14:02                   ` Arnaldo Carvalho de Melo
2015-03-31  0:15                     ` Namhyung Kim
2015-03-30 13:07                 ` Arnaldo Carvalho de Melo
2015-03-30 13:20                   ` Jiri Olsa
2015-03-30 13:59                     ` Arnaldo Carvalho de Melo
2015-03-30 14:58               ` Arnaldo Carvalho de Melo
2015-03-30 15:13                 ` Arnaldo Carvalho de Melo
2015-03-31  0:27                   ` Namhyung Kim
2015-03-31  0:46                     ` Arnaldo Carvalho de Melo
2015-03-31  7:21                       ` Namhyung Kim
2015-03-30 13:22             ` Arnaldo Carvalho de Melo [this message]
2015-03-30 13:09         ` Arnaldo Carvalho de Melo
2015-03-30 13:17         ` Arnaldo Carvalho de Melo

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=20150330132226.GD24063@kernel.org \
    --to=arnaldo.melo@gmail.com \
    --cc=dsahern@gmail.com \
    --cc=eranian@google.com \
    --cc=jolsa@kernel.org \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.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).