From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753979AbbCaAV7 (ORCPT ); Mon, 30 Mar 2015 20:21:59 -0400 Received: from lgeamrelo04.lge.com ([156.147.1.127]:44108 "EHLO lgeamrelo04.lge.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753524AbbCaAV4 (ORCPT ); Mon, 30 Mar 2015 20:21:56 -0400 X-Original-SENDERIP: 10.177.220.203 X-Original-MAILFROM: namhyung@kernel.org Date: Tue, 31 Mar 2015 09:15:15 +0900 From: Namhyung Kim To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , David Ahern , Jiri Olsa , Stephane Eranian , LKML Subject: Re: [BUG] segfault in perf-top -- thread refcnt Message-ID: <20150331001515.GD32033@sejong> References: <20150327201126.GM21510@kernel.org> <5515B9E6.5020007@gmail.com> <20150330080737.GD1413@krava> <20150330102220.GE1413@krava> <20150330112108.GG1413@krava> <20150330114907.GH1413@krava> <20150330124852.GA4507@danjae.kornet> <20150330125631.GI1413@krava> <20150330140239.GB32560@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20150330140239.GB32560@kernel.org> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Arnaldo, On Mon, Mar 30, 2015 at 11:02:39AM -0300, Arnaldo Carvalho de Melo wrote: > Em Mon, Mar 30, 2015 at 10:06:35PM +0900, Namhyung Kim escreveu: > > On Mon, Mar 30, 2015 at 9:56 PM, Jiri Olsa wrote: > > > On Mon, Mar 30, 2015 at 09:48:52PM +0900, Namhyung Kim wrote: > > >> > @@ -380,10 +381,13 @@ static struct thread *__machine__findnew_thread(struct machine *machine, > > >> > if (!create) > > >> > return NULL; > > >> > > > >> > - th = thread__new(pid, tid); > > >> > + th = thread__new(machine, pid, tid); > > >> > if (th != NULL) { > > >> > + > > >> > + pthread_mutex_lock(&machine->threads_lock); > > >> > rb_link_node(&th->rb_node, parent, p); > > >> > rb_insert_color(&th->rb_node, &machine->threads); > > >> > + pthread_mutex_unlock(&machine->threads_lock); > > >> > > >> I think you also need to protect the rb tree traversal above. > > > > > > yep, I already have another version.. but it blows on another place ;-) > > > > > >> > > >> But this makes every sample processing grabs and releases the lock so > > >> might cause high overhead. It can be a problem if such processing is > > >> done parallelly like my multi-thread work. :-/ > > > > > > yep.. perhaps instead of more locking we need to find a way where > > > only single thread do the update on hists/threads > > > > Agreed. > > > > AFAIK the reason we do ref-counting is to cleanup dead/exited thread > > for live session like perf top. In that case we can somehow mark > > to-be-deleted thread and kill it in a safe time/place.. > > Humm, you mean have another list node in struct threads and add threads > to another dead_threads like list, i.e. one that is _really_ dead as no > more refcounts point to it, and then amortize the costs of removing it > from the rb_tree by removing multiple threads instead of just one? Yes, I really want to avoid any overhead on the fastpath. Instead of refcnt, how about marking and deleting dead threads by the perf top's display thread unless it's not a selected one? Thanks, Namhyung