diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/perf/tests/code-reading.c | 2 | ||||
| -rw-r--r-- | tools/perf/tests/keep-tracking.c | 2 | ||||
| -rw-r--r-- | tools/perf/tests/mmap-basic.c | 2 | ||||
| -rw-r--r-- | tools/perf/tests/switch-tracking.c | 2 | ||||
| -rw-r--r-- | tools/perf/util/cpumap.c | 26 | ||||
| -rw-r--r-- | tools/perf/util/cpumap.h | 6 | ||||
| -rw-r--r-- | tools/perf/util/evlist.c | 4 | ||||
| -rw-r--r-- | tools/perf/util/evsel.c | 1 | ||||
| -rw-r--r-- | tools/perf/util/parse-events.c | 5 | ||||
| -rw-r--r-- | tools/perf/util/python.c | 2 | ||||
| -rw-r--r-- | tools/perf/util/record.c | 4 | ||||
| -rw-r--r-- | tools/perf/util/session.c | 2 | ||||
| -rw-r--r-- | tools/perf/util/svghelper.c | 2 |
13 files changed, 45 insertions, 15 deletions
diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c index 22f8a00446e1..6b3250f54240 100644 --- a/tools/perf/tests/code-reading.c +++ b/tools/perf/tests/code-reading.c | |||
| @@ -545,7 +545,7 @@ out_err: | |||
| 545 | if (evlist) { | 545 | if (evlist) { |
| 546 | perf_evlist__delete(evlist); | 546 | perf_evlist__delete(evlist); |
| 547 | } else { | 547 | } else { |
| 548 | cpu_map__delete(cpus); | 548 | cpu_map__put(cpus); |
| 549 | thread_map__delete(threads); | 549 | thread_map__delete(threads); |
| 550 | } | 550 | } |
| 551 | machines__destroy_kernel_maps(&machines); | 551 | machines__destroy_kernel_maps(&machines); |
diff --git a/tools/perf/tests/keep-tracking.c b/tools/perf/tests/keep-tracking.c index 5b171d1e338b..a330235cefc0 100644 --- a/tools/perf/tests/keep-tracking.c +++ b/tools/perf/tests/keep-tracking.c | |||
| @@ -144,7 +144,7 @@ out_err: | |||
| 144 | perf_evlist__disable(evlist); | 144 | perf_evlist__disable(evlist); |
| 145 | perf_evlist__delete(evlist); | 145 | perf_evlist__delete(evlist); |
| 146 | } else { | 146 | } else { |
| 147 | cpu_map__delete(cpus); | 147 | cpu_map__put(cpus); |
| 148 | thread_map__delete(threads); | 148 | thread_map__delete(threads); |
| 149 | } | 149 | } |
| 150 | 150 | ||
diff --git a/tools/perf/tests/mmap-basic.c b/tools/perf/tests/mmap-basic.c index 5855cf471210..5a9ef5833452 100644 --- a/tools/perf/tests/mmap-basic.c +++ b/tools/perf/tests/mmap-basic.c | |||
| @@ -140,7 +140,7 @@ out_delete_evlist: | |||
| 140 | cpus = NULL; | 140 | cpus = NULL; |
| 141 | threads = NULL; | 141 | threads = NULL; |
| 142 | out_free_cpus: | 142 | out_free_cpus: |
| 143 | cpu_map__delete(cpus); | 143 | cpu_map__put(cpus); |
| 144 | out_free_threads: | 144 | out_free_threads: |
| 145 | thread_map__delete(threads); | 145 | thread_map__delete(threads); |
| 146 | return err; | 146 | return err; |
diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-tracking.c index 0d31403ea593..1b06122beb76 100644 --- a/tools/perf/tests/switch-tracking.c +++ b/tools/perf/tests/switch-tracking.c | |||
| @@ -560,7 +560,7 @@ out: | |||
| 560 | perf_evlist__disable(evlist); | 560 | perf_evlist__disable(evlist); |
| 561 | perf_evlist__delete(evlist); | 561 | perf_evlist__delete(evlist); |
| 562 | } else { | 562 | } else { |
| 563 | cpu_map__delete(cpus); | 563 | cpu_map__put(cpus); |
| 564 | thread_map__delete(threads); | 564 | thread_map__delete(threads); |
| 565 | } | 565 | } |
| 566 | 566 | ||
diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index c4e55b71010c..3667e2123e5b 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #include <assert.h> | 5 | #include <assert.h> |
| 6 | #include <stdio.h> | 6 | #include <stdio.h> |
| 7 | #include <stdlib.h> | 7 | #include <stdlib.h> |
| 8 | #include "asm/bug.h" | ||
| 8 | 9 | ||
| 9 | static struct cpu_map *cpu_map__default_new(void) | 10 | static struct cpu_map *cpu_map__default_new(void) |
| 10 | { | 11 | { |
| @@ -22,6 +23,7 @@ static struct cpu_map *cpu_map__default_new(void) | |||
| 22 | cpus->map[i] = i; | 23 | cpus->map[i] = i; |
| 23 | 24 | ||
| 24 | cpus->nr = nr_cpus; | 25 | cpus->nr = nr_cpus; |
| 26 | atomic_set(&cpus->refcnt, 1); | ||
| 25 | } | 27 | } |
| 26 | 28 | ||
| 27 | return cpus; | 29 | return cpus; |
| @@ -35,6 +37,7 @@ static struct cpu_map *cpu_map__trim_new(int nr_cpus, int *tmp_cpus) | |||
| 35 | if (cpus != NULL) { | 37 | if (cpus != NULL) { |
| 36 | cpus->nr = nr_cpus; | 38 | cpus->nr = nr_cpus; |
| 37 | memcpy(cpus->map, tmp_cpus, payload_size); | 39 | memcpy(cpus->map, tmp_cpus, payload_size); |
| 40 | atomic_set(&cpus->refcnt, 1); | ||
| 38 | } | 41 | } |
| 39 | 42 | ||
| 40 | return cpus; | 43 | return cpus; |
| @@ -194,14 +197,32 @@ struct cpu_map *cpu_map__dummy_new(void) | |||
| 194 | if (cpus != NULL) { | 197 | if (cpus != NULL) { |
| 195 | cpus->nr = 1; | 198 | cpus->nr = 1; |
| 196 | cpus->map[0] = -1; | 199 | cpus->map[0] = -1; |
| 200 | atomic_set(&cpus->refcnt, 1); | ||
| 197 | } | 201 | } |
| 198 | 202 | ||
| 199 | return cpus; | 203 | return cpus; |
| 200 | } | 204 | } |
| 201 | 205 | ||
| 202 | void cpu_map__delete(struct cpu_map *map) | 206 | static void cpu_map__delete(struct cpu_map *map) |
| 203 | { | 207 | { |
| 204 | free(map); | 208 | if (map) { |
| 209 | WARN_ONCE(atomic_read(&map->refcnt) != 0, | ||
| 210 | "cpu_map refcnt unbalanced\n"); | ||
| 211 | free(map); | ||
| 212 | } | ||
| 213 | } | ||
| 214 | |||
| 215 | struct cpu_map *cpu_map__get(struct cpu_map *map) | ||
| 216 | { | ||
| 217 | if (map) | ||
| 218 | atomic_inc(&map->refcnt); | ||
| 219 | return map; | ||
| 220 | } | ||
| 221 | |||
| 222 | void cpu_map__put(struct cpu_map *map) | ||
| 223 | { | ||
| 224 | if (map && atomic_dec_and_test(&map->refcnt)) | ||
| 225 | cpu_map__delete(map); | ||
| 205 | } | 226 | } |
| 206 | 227 | ||
| 207 | int cpu_map__get_socket(struct cpu_map *map, int idx) | 228 | int cpu_map__get_socket(struct cpu_map *map, int idx) |
| @@ -263,6 +284,7 @@ static int cpu_map__build_map(struct cpu_map *cpus, struct cpu_map **res, | |||
| 263 | /* ensure we process id in increasing order */ | 284 | /* ensure we process id in increasing order */ |
| 264 | qsort(c->map, c->nr, sizeof(int), cmp_ids); | 285 | qsort(c->map, c->nr, sizeof(int), cmp_ids); |
| 265 | 286 | ||
| 287 | atomic_set(&cpus->refcnt, 1); | ||
| 266 | *res = c; | 288 | *res = c; |
| 267 | return 0; | 289 | return 0; |
| 268 | } | 290 | } |
diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index 61a654849002..0af9cecb4c51 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h | |||
| @@ -3,18 +3,19 @@ | |||
| 3 | 3 | ||
| 4 | #include <stdio.h> | 4 | #include <stdio.h> |
| 5 | #include <stdbool.h> | 5 | #include <stdbool.h> |
| 6 | #include <linux/atomic.h> | ||
| 6 | 7 | ||
| 7 | #include "perf.h" | 8 | #include "perf.h" |
| 8 | #include "util/debug.h" | 9 | #include "util/debug.h" |
| 9 | 10 | ||
| 10 | struct cpu_map { | 11 | struct cpu_map { |
| 12 | atomic_t refcnt; | ||
| 11 | int nr; | 13 | int nr; |
| 12 | int map[]; | 14 | int map[]; |
| 13 | }; | 15 | }; |
| 14 | 16 | ||
| 15 | struct cpu_map *cpu_map__new(const char *cpu_list); | 17 | struct cpu_map *cpu_map__new(const char *cpu_list); |
| 16 | struct cpu_map *cpu_map__dummy_new(void); | 18 | struct cpu_map *cpu_map__dummy_new(void); |
| 17 | void cpu_map__delete(struct cpu_map *map); | ||
| 18 | struct cpu_map *cpu_map__read(FILE *file); | 19 | struct cpu_map *cpu_map__read(FILE *file); |
| 19 | size_t cpu_map__fprintf(struct cpu_map *map, FILE *fp); | 20 | size_t cpu_map__fprintf(struct cpu_map *map, FILE *fp); |
| 20 | int cpu_map__get_socket(struct cpu_map *map, int idx); | 21 | int cpu_map__get_socket(struct cpu_map *map, int idx); |
| @@ -22,6 +23,9 @@ int cpu_map__get_core(struct cpu_map *map, int idx); | |||
| 22 | int cpu_map__build_socket_map(struct cpu_map *cpus, struct cpu_map **sockp); | 23 | int cpu_map__build_socket_map(struct cpu_map *cpus, struct cpu_map **sockp); |
| 23 | int cpu_map__build_core_map(struct cpu_map *cpus, struct cpu_map **corep); | 24 | int cpu_map__build_core_map(struct cpu_map *cpus, struct cpu_map **corep); |
| 24 | 25 | ||
| 26 | struct cpu_map *cpu_map__get(struct cpu_map *map); | ||
| 27 | void cpu_map__put(struct cpu_map *map); | ||
| 28 | |||
| 25 | static inline int cpu_map__socket(struct cpu_map *sock, int s) | 29 | static inline int cpu_map__socket(struct cpu_map *sock, int s) |
| 26 | { | 30 | { |
| 27 | if (!sock || s > sock->nr || s < 0) | 31 | if (!sock || s > sock->nr || s < 0) |
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index d29df901be3e..59498f7b3e9b 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c | |||
| @@ -114,7 +114,7 @@ void perf_evlist__delete(struct perf_evlist *evlist) | |||
| 114 | { | 114 | { |
| 115 | perf_evlist__munmap(evlist); | 115 | perf_evlist__munmap(evlist); |
| 116 | perf_evlist__close(evlist); | 116 | perf_evlist__close(evlist); |
| 117 | cpu_map__delete(evlist->cpus); | 117 | cpu_map__put(evlist->cpus); |
| 118 | thread_map__delete(evlist->threads); | 118 | thread_map__delete(evlist->threads); |
| 119 | evlist->cpus = NULL; | 119 | evlist->cpus = NULL; |
| 120 | evlist->threads = NULL; | 120 | evlist->threads = NULL; |
| @@ -1353,7 +1353,7 @@ static int perf_evlist__create_syswide_maps(struct perf_evlist *evlist) | |||
| 1353 | out: | 1353 | out: |
| 1354 | return err; | 1354 | return err; |
| 1355 | out_free_cpus: | 1355 | out_free_cpus: |
