From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756769AbbCCN5c (ORCPT ); Tue, 3 Mar 2015 08:57:32 -0500 Received: from mail.kernel.org ([198.145.29.136]:47107 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756756AbbCCN5a (ORCPT ); Tue, 3 Mar 2015 08:57:30 -0500 Date: Tue, 3 Mar 2015 10:57:25 -0300 From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , linux-kernel@vger.kernel.org, Adrian Hunter , Borislav Petkov , David Ahern , Don Zickus , Frederic Weisbecker , Jiri Olsa , Stephane Eranian Subject: Re: [PATCH 19/20] perf tools: Reference count struct thread Message-ID: <20150303135725.GE5187@kernel.org> References: <1425353169-21436-1-git-send-email-acme@kernel.org> <1425353169-21436-20-git-send-email-acme@kernel.org> <20150303134214.GB27046@danjae> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150303134214.GB27046@danjae> X-Url: http://acmel.wordpress.com 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 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