Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755267AbbKRGrd (ORCPT ); Wed, 18 Nov 2015 01:47:33 -0500 Received: from mail9.hitachi.co.jp ([133.145.228.44]:39788 "EHLO mail9.hitachi.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754945AbbKRGra (ORCPT ); Wed, 18 Nov 2015 01:47:30 -0500 X-AuditID: 85900ec0-9d7c9b9000001a57-95-564c1efffb83 Subject: [PATCH perf/core 09/13] perf: Make dso to use refcnt for debug From: Masami Hiramatsu To: Arnaldo Carvalho de Melo Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Adrian Hunter , Ingo Molnar , Namhyung Kim , Jiri Olsa Date: Wed, 18 Nov 2015 15:40:29 +0900 Message-ID: <20151118064029.30709.91699.stgit@localhost.localdomain> In-Reply-To: <20151118064009.30709.74354.stgit@localhost.localdomain> References: <20151118064009.30709.74354.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Brightmail-Tracker: AAAAAA== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1730 Lines: 65 Make 'dso' object to use refcnt interface for debug. This can find refcnt related memory leaks on dsos. E.g. ---- # ./perf probe vfs_read Added new event: probe:vfs_read (on vfs_read) You can now use it in all perf tools, such as: perf record -e probe:vfs_read -aR sleep 1 REFCNT: BUG: Unreclaimed objects found. REFCNT: Total 75 objects are not reclaimed. To see all backtraces, rerun with -v option ---- Signed-off-by: Masami Hiramatsu --- tools/perf/util/dso.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c index 7c0c083..28ad06a 100644 --- a/tools/perf/util/dso.c +++ b/tools/perf/util/dso.c @@ -1049,7 +1049,7 @@ struct dso *dso__new(const char *name) INIT_LIST_HEAD(&dso->node); INIT_LIST_HEAD(&dso->data.open_entry); pthread_mutex_init(&dso->lock, NULL); - atomic_set(&dso->refcnt, 1); + refcnt__init(dso, refcnt); } return dso; @@ -1081,19 +1081,20 @@ void dso__delete(struct dso *dso) dso__free_a2l(dso); zfree(&dso->symsrc_filename); pthread_mutex_destroy(&dso->lock); + refcnt__exit(dso, refcnt); free(dso); } struct dso *dso__get(struct dso *dso) { if (dso) - atomic_inc(&dso->refcnt); + refcnt__get(dso, refcnt); return dso; } void dso__put(struct dso *dso) { - if (dso && atomic_dec_and_test(&dso->refcnt)) + if (dso && refcnt__put(dso, refcnt)) dso__delete(dso); } -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/