Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753280AbbLICTG (ORCPT ); Tue, 8 Dec 2015 21:19:06 -0500 Received: from mail9.hitachi.co.jp ([133.145.228.44]:50869 "EHLO mail9.hitachi.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753242AbbLICTB (ORCPT ); Tue, 8 Dec 2015 21:19:01 -0500 X-AuditID: 85900ec0-9f5ccb9000001a57-b4-56678f922ca3 Subject: [PATCH perf/core 09/22] perf: Make cpu_map 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:07 +0900 Message-ID: <20151209021107.10245.33413.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: 2776 Lines: 100 Make 'cpu_map' object to use refcnt interface for debug. This can find refcnt related memory leaks. Signed-off-by: Masami Hiramatsu --- tools/perf/util/cpumap.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index 10af1e7..cca94d3 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -23,7 +23,7 @@ static struct cpu_map *cpu_map__default_new(void) cpus->map[i] = i; cpus->nr = nr_cpus; - atomic_set(&cpus->refcnt, 1); + refcnt__init_as(cpus, refcnt, 1, "cpu_map"); } return cpus; @@ -37,7 +37,7 @@ static struct cpu_map *cpu_map__trim_new(int nr_cpus, int *tmp_cpus) if (cpus != NULL) { cpus->nr = nr_cpus; memcpy(cpus->map, tmp_cpus, payload_size); - atomic_set(&cpus->refcnt, 1); + refcnt__init_as(cpus, refcnt, 1, "cpu_map"); } return cpus; @@ -197,7 +197,7 @@ struct cpu_map *cpu_map__dummy_new(void) if (cpus != NULL) { cpus->nr = 1; cpus->map[0] = -1; - atomic_set(&cpus->refcnt, 1); + refcnt__init_as(cpus, refcnt, 1, "cpu_map"); } return cpus; @@ -214,32 +214,33 @@ struct cpu_map *cpu_map__empty_new(int nr) for (i = 0; i < nr; i++) cpus->map[i] = -1; - atomic_set(&cpus->refcnt, 1); + refcnt__init_as(cpus, refcnt, 1, "cpu_map"); } return cpus; } -static void cpu_map__delete(struct cpu_map *map) +static void cpu_map__delete(struct cpu_map *cpus) { - if (map) { - WARN_ONCE(atomic_read(&map->refcnt) != 0, + if (cpus) { + WARN_ONCE(atomic_read(&cpus->refcnt) != 0, "cpu_map refcnt unbalanced\n"); - free(map); + refcnt__exit(cpus, refcnt); + free(cpus); } } -struct cpu_map *cpu_map__get(struct cpu_map *map) +struct cpu_map *cpu_map__get(struct cpu_map *cpus) { - if (map) - atomic_inc(&map->refcnt); - return map; + if (cpus) + refcnt__get(cpus, refcnt); + return cpus; } -void cpu_map__put(struct cpu_map *map) +void cpu_map__put(struct cpu_map *cpus) { - if (map && atomic_dec_and_test(&map->refcnt)) - cpu_map__delete(map); + if (cpus && refcnt__put(cpus, refcnt)) + cpu_map__delete(cpus); } static int cpu__get_topology_int(int cpu, const char *name, int *value) @@ -302,7 +303,7 @@ int cpu_map__build_map(struct cpu_map *cpus, struct cpu_map **res, /* ensure we process id in increasing order */ qsort(c->map, c->nr, sizeof(int), cmp_ids); - atomic_set(&c->refcnt, 1); + refcnt__init_as(c, refcnt, 1, "cpu_map"); *res = c; return 0; } -- 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/