From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752995AbbEJHKc (ORCPT ); Sun, 10 May 2015 03:10:32 -0400 Received: from terminus.zytor.com ([198.137.202.10]:44907 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752205AbbEJHK2 (ORCPT ); Sun, 10 May 2015 03:10:28 -0400 Date: Sun, 10 May 2015 00:10:12 -0700 From: tip-bot for Arnaldo Carvalho de Melo Message-ID: Cc: hpa@zytor.com, mingo@kernel.org, fweisbec@gmail.com, tglx@linutronix.de, linux-kernel@vger.kernel.org, dsahern@gmail.com, jolsa@redhat.com, eranian@google.com, dzickus@redhat.com, namhyung@kernel.org, adrian.hunter@intel.com, acme@redhat.com, bp@suse.de Reply-To: tglx@linutronix.de, dsahern@gmail.com, linux-kernel@vger.kernel.org, mingo@kernel.org, hpa@zytor.com, fweisbec@gmail.com, acme@redhat.com, bp@suse.de, jolsa@redhat.com, adrian.hunter@intel.com, dzickus@redhat.com, namhyung@kernel.org, eranian@google.com To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf tools: Use atomic_t to implement thread__{get,put} refcnt Git-Commit-ID: e1ed3a5b87ed6759e16ec93f16aae83d2cc77ca2 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: e1ed3a5b87ed6759e16ec93f16aae83d2cc77ca2 Gitweb: http://git.kernel.org/tip/e1ed3a5b87ed6759e16ec93f16aae83d2cc77ca2 Author: Arnaldo Carvalho de Melo AuthorDate: Tue, 7 Apr 2015 11:59:50 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 8 May 2015 16:16:23 -0300 perf tools: Use atomic_t to implement thread__{get,put} refcnt Fixing bugs in 'perf top' where the used thread unsafe 'struct thread' refcount implementation was falling apart because we really use two threads. Acked-by: David Ahern Cc: Adrian Hunter Cc: Borislav Petkov Cc: Don Zickus Cc: Frederic Weisbecker Cc: Jiri Olsa Cc: Namhyung Kim Cc: Stephane Eranian Link: http://lkml.kernel.org/n/tip-hil2hol294u5ntcuof4jhmn6@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/thread.c | 6 +++--- tools/perf/util/thread.h | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c index 1c8fbc9..1b26552 100644 --- a/tools/perf/util/thread.c +++ b/tools/perf/util/thread.c @@ -53,7 +53,7 @@ struct thread *thread__new(pid_t pid, pid_t tid) goto err_thread; list_add(&comm->list, &thread->comm_list); - + atomic_set(&thread->refcnt, 0); } return thread; @@ -84,13 +84,13 @@ void thread__delete(struct thread *thread) struct thread *thread__get(struct thread *thread) { - ++thread->refcnt; + atomic_inc(&thread->refcnt); return thread; } void thread__put(struct thread *thread) { - if (thread && --thread->refcnt == 0) { + if (thread && atomic_dec_and_test(&thread->refcnt)) { list_del_init(&thread->node); thread__delete(thread); } diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h index 9b8a54d..f33c48c 100644 --- a/tools/perf/util/thread.h +++ b/tools/perf/util/thread.h @@ -1,6 +1,7 @@ #ifndef __PERF_THREAD_H #define __PERF_THREAD_H +#include #include #include #include @@ -21,7 +22,7 @@ struct thread { pid_t tid; pid_t ppid; int cpu; - int refcnt; + atomic_t refcnt; char shortname[3]; bool comm_set; bool dead; /* if set thread has exited */