Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753492AbbLICWb (ORCPT ); Tue, 8 Dec 2015 21:22:31 -0500 Received: from mail7.hitachi.co.jp ([133.145.228.42]:42860 "EHLO mail7.hitachi.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753283AbbLICTK (ORCPT ); Tue, 8 Dec 2015 21:19:10 -0500 X-AuditID: 85900ec0-9ebcbb9000001a57-b8-56678f9ad1e6 Subject: [PATCH perf/core 13/22] perf: Make perf_mmap to use refcnt for debug From: Masami Hiramatsu To: Arnaldo Carvalho de Melo Cc: Peter Zijlstra , Adrian Hunter , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Ingo Molnar , Namhyung Kim , Jiri Olsa Date: Wed, 09 Dec 2015 11:11:16 +0900 Message-ID: <20151209021116.10245.15749.stgit@localhost.localdomain> In-Reply-To: <20151209021047.10245.8918.stgit@localhost.localdomain> References: <20151209021047.10245.8918.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: 2136 Lines: 60 Make 'perf_mmap' object to use refcnt interface for debug. This can find refcnt related memory leaks. Signed-off-by: Masami Hiramatsu --- tools/perf/util/evlist.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index d1b6c20..0637603 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -15,6 +15,7 @@ #include "evlist.h" #include "evsel.h" #include "debug.h" +#include "refcnt.h" #include #include "parse-events.h" @@ -769,14 +770,14 @@ static bool perf_mmap__empty(struct perf_mmap *md) static void perf_evlist__mmap_get(struct perf_evlist *evlist, int idx) { - atomic_inc(&evlist->mmap[idx].refcnt); + refcnt__get(&evlist->mmap[idx], refcnt); } static void perf_evlist__mmap_put(struct perf_evlist *evlist, int idx) { BUG_ON(atomic_read(&evlist->mmap[idx].refcnt) == 0); - if (atomic_dec_and_test(&evlist->mmap[idx].refcnt)) + if (refcnt__put(&evlist->mmap[idx], refcnt)) __perf_evlist__munmap(evlist, idx); } @@ -827,6 +828,7 @@ static void __perf_evlist__munmap(struct perf_evlist *evlist, int idx) if (evlist->mmap[idx].base != NULL) { munmap(evlist->mmap[idx].base, evlist->mmap_len); evlist->mmap[idx].base = NULL; + refcnt__exit(&evlist->mmap[idx], refcnt); atomic_set(&evlist->mmap[idx].refcnt, 0); } auxtrace_mmap__munmap(&evlist->mmap[idx].auxtrace_mmap); @@ -876,7 +878,7 @@ static int __perf_evlist__mmap(struct perf_evlist *evlist, int idx, * evlist layer can't just drop it when filtering events in * perf_evlist__filter_pollfd(). */ - atomic_set(&evlist->mmap[idx].refcnt, 2); + refcnt__init_as(&evlist->mmap[idx], refcnt, 2, "perf_mmap"); evlist->mmap[idx].prev = 0; evlist->mmap[idx].mask = mp->mask; evlist->mmap[idx].base = mmap(NULL, evlist->mmap_len, mp->prot, -- 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/