perf tools: Reference count map_groups objects
authorArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 25 Mar 2014 18:26:44 +0000 (15:26 -0300)
committerJiri Olsa <jolsa@kernel.org>
Mon, 28 Apr 2014 11:43:26 +0000 (13:43 +0200)
We will share it among threads in the same process.
Adding map_groups__get/map_groups__put interface for that.

Signed-off-by: Arnaldo Carvalho de Melo <acme@kernel.org>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1397490723-1992-4-git-send-email-jolsa@redhat.com
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
tools/perf/util/map.c
tools/perf/util/map.h
tools/perf/util/thread.c

index ae4c5e12debdc76bcf1345e90faf9d2616e46a31..ba5f5c0c838bcface37ec62c37f6728db098269f 100644 (file)
@@ -323,6 +323,7 @@ void map_groups__init(struct map_groups *mg)
                INIT_LIST_HEAD(&mg->removed_maps[i]);
        }
        mg->machine = NULL;
+       mg->refcnt = 1;
 }
 
 static void maps__delete(struct rb_root *maps)
@@ -374,6 +375,12 @@ void map_groups__delete(struct map_groups *mg)
        free(mg);
 }
 
+void map_groups__put(struct map_groups *mg)
+{
+       if (--mg->refcnt == 0)
+               map_groups__delete(mg);
+}
+
 void map_groups__flush(struct map_groups *mg)
 {
        int type;
index 1073e2d8b79740fb4a1c9656b9cc4058b5c84299..d6445b27d672b48cc9b95ab68b9ae92bfdab44c6 100644 (file)
@@ -59,11 +59,20 @@ struct map_groups {
        struct rb_root   maps[MAP__NR_TYPES];
        struct list_head removed_maps[MAP__NR_TYPES];
        struct machine   *machine;
+       int              refcnt;
 };
 
 struct map_groups *map_groups__new(void);
 void map_groups__delete(struct map_groups *mg);
 
+static inline struct map_groups *map_groups__get(struct map_groups *mg)
+{
+       ++mg->refcnt;
+       return mg;
+}
+
+void map_groups__put(struct map_groups *mg);
+
 static inline struct kmap *map__kmap(struct map *map)
 {
        return (struct kmap *)(map + 1);
index dc51d1632e92a4664225cac3e87ac6c1f0a825b7..b501848a8424cc2483232cba02520f5a95c8d140 100644 (file)
@@ -50,7 +50,7 @@ void thread__delete(struct thread *thread)
 {
        struct comm *comm, *tmp;
 
-       map_groups__delete(thread->mg);
+       map_groups__put(thread->mg);
        thread->mg = NULL;
        list_for_each_entry_safe(comm, tmp, &thread->comm_list, list) {
                list_del(&comm->list);