Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tools: Use atomic.h for the map_groups refcount

Now that we have atomic.h, we should convert all of the existing
refcounts to use it.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-onm5u3pioba1hqqhjs8on03e@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+12 -10
+6 -6
tools/perf/tests/thread-mg-share.c
··· 43 43 leader && t1 && t2 && t3 && other); 44 44 45 45 mg = leader->mg; 46 - TEST_ASSERT_EQUAL("wrong refcnt", mg->refcnt, 4); 46 + TEST_ASSERT_EQUAL("wrong refcnt", atomic_read(&mg->refcnt), 4); 47 47 48 48 /* test the map groups pointer is shared */ 49 49 TEST_ASSERT_VAL("map groups don't match", mg == t1->mg); ··· 71 71 machine__remove_thread(machine, other_leader); 72 72 73 73 other_mg = other->mg; 74 - TEST_ASSERT_EQUAL("wrong refcnt", other_mg->refcnt, 2); 74 + TEST_ASSERT_EQUAL("wrong refcnt", atomic_read(&other_mg->refcnt), 2); 75 75 76 76 TEST_ASSERT_VAL("map groups don't match", other_mg == other_leader->mg); 77 77 78 78 /* release thread group */ 79 79 thread__put(leader); 80 - TEST_ASSERT_EQUAL("wrong refcnt", mg->refcnt, 3); 80 + TEST_ASSERT_EQUAL("wrong refcnt", atomic_read(&mg->refcnt), 3); 81 81 82 82 thread__put(t1); 83 - TEST_ASSERT_EQUAL("wrong refcnt", mg->refcnt, 2); 83 + TEST_ASSERT_EQUAL("wrong refcnt", atomic_read(&mg->refcnt), 2); 84 84 85 85 thread__put(t2); 86 - TEST_ASSERT_EQUAL("wrong refcnt", mg->refcnt, 1); 86 + TEST_ASSERT_EQUAL("wrong refcnt", atomic_read(&mg->refcnt), 1); 87 87 88 88 thread__put(t3); 89 89 90 90 /* release other group */ 91 91 thread__put(other_leader); 92 - TEST_ASSERT_EQUAL("wrong refcnt", other_mg->refcnt, 1); 92 + TEST_ASSERT_EQUAL("wrong refcnt", atomic_read(&other_mg->refcnt), 1); 93 93 94 94 thread__put(other); 95 95
+2 -2
tools/perf/util/map.c
··· 426 426 INIT_LIST_HEAD(&mg->removed_maps[i]); 427 427 } 428 428 mg->machine = machine; 429 - mg->refcnt = 1; 429 + atomic_set(&mg->refcnt, 1); 430 430 } 431 431 432 432 static void maps__delete(struct rb_root *maps) ··· 494 494 495 495 void map_groups__put(struct map_groups *mg) 496 496 { 497 - if (--mg->refcnt == 0) 497 + if (mg && atomic_dec_and_test(&mg->refcnt)) 498 498 map_groups__delete(mg); 499 499 } 500 500
+4 -2
tools/perf/util/map.h
··· 1 1 #ifndef __PERF_MAP_H 2 2 #define __PERF_MAP_H 3 3 4 + #include <linux/atomic.h> 4 5 #include <linux/compiler.h> 5 6 #include <linux/list.h> 6 7 #include <linux/rbtree.h> ··· 62 61 struct rb_root maps[MAP__NR_TYPES]; 63 62 struct list_head removed_maps[MAP__NR_TYPES]; 64 63 struct machine *machine; 65 - int refcnt; 64 + atomic_t refcnt; 66 65 }; 67 66 68 67 struct map_groups *map_groups__new(struct machine *machine); ··· 71 70 72 71 static inline struct map_groups *map_groups__get(struct map_groups *mg) 73 72 { 74 - ++mg->refcnt; 73 + if (mg) 74 + atomic_inc(&mg->refcnt); 75 75 return mg; 76 76 } 77 77