Skip to content

Commit 38f01d8

Browse files
olsajiriacmel
authored andcommitted
libperf: Add perf_cpu_map__get()/perf_cpu_map__put()
Moving the following functions: cpu_map__get() cpu_map__put() to libperf with following names: perf_cpu_map__get() perf_cpu_map__put() Committer notes: Added fixes for arm/arm64 Signed-off-by: Jiri Olsa <jolsa@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Alexey Budankov <alexey.budankov@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Michael Petlan <mpetlan@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/20190721112506.12306-31-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 397721e commit 38f01d8

33 files changed

Lines changed: 78 additions & 75 deletions

‎tools/perf/arch/arm/util/cs-etm.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ static int cs_etm_set_option(struct auxtrace_record *itr,
181181

182182
err = 0;
183183
out:
184-
cpu_map__put(online_cpus);
184+
perf_cpu_map__put(online_cpus);
185185
return err;
186186
}
187187

@@ -517,7 +517,7 @@ cs_etm_info_priv_size(struct auxtrace_record *itr __maybe_unused,
517517
}
518518
}
519519

520-
cpu_map__put(online_cpus);
520+
perf_cpu_map__put(online_cpus);
521521

522522
return (CS_ETM_HEADER_SIZE +
523523
(etmv4 * CS_ETMV4_PRIV_SIZE) +
@@ -679,7 +679,7 @@ static int cs_etm_info_fill(struct auxtrace_record *itr,
679679
if (cpu_map__has(cpu_map, i))
680680
cs_etm_get_metadata(i, &offset, itr, info);
681681

682-
cpu_map__put(online_cpus);
682+
perf_cpu_map__put(online_cpus);
683683

684684
return 0;
685685
}

‎tools/perf/arch/arm64/util/header.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ char *get_cpuid_str(struct perf_pmu *pmu)
2727
return NULL;
2828

2929
/* read midr from list of cpus mapped to this pmu */
30-
cpus = cpu_map__get(pmu->cpus);
30+
cpus = perf_cpu_map__get(pmu->cpus);
3131
for (cpu = 0; cpu < cpus->nr; cpu++) {
3232
scnprintf(path, PATH_MAX, "%s/devices/system/cpu/cpu%d"MIDR,
3333
sysfs, cpus->map[cpu]);
@@ -60,6 +60,6 @@ char *get_cpuid_str(struct perf_pmu *pmu)
6060
buf = NULL;
6161
}
6262

63-
cpu_map__put(cpus);
63+
perf_cpu_map__put(cpus);
6464
return buf;
6565
}

‎tools/perf/builtin-ftrace.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ static int reset_tracing_cpu(void)
206206
int ret;
207207

208208
ret = set_tracing_cpumask(cpumap);
209-
cpu_map__put(cpumap);
209+
perf_cpu_map__put(cpumap);
210210
return ret;
211211
}
212212

‎tools/perf/builtin-stat.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -933,8 +933,8 @@ static int perf_stat_init_aggr_mode(void)
933933

934934
static void perf_stat__exit_aggr_mode(void)
935935
{
936-
cpu_map__put(stat_config.aggr_map);
937-
cpu_map__put(stat_config.cpus_aggr_map);
936+
perf_cpu_map__put(stat_config.aggr_map);
937+
perf_cpu_map__put(stat_config.cpus_aggr_map);
938938
stat_config.aggr_map = NULL;
939939
stat_config.cpus_aggr_map = NULL;
940940
}

‎tools/perf/lib/cpumap.c‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include <stdlib.h>
44
#include <linux/refcount.h>
55
#include <internal/cpumap.h>
6+
#include <asm/bug.h>
7+
#include <stdio.h>
68

79
struct perf_cpu_map *perf_cpu_map__dummy_new(void)
810
{
@@ -16,3 +18,25 @@ struct perf_cpu_map *perf_cpu_map__dummy_new(void)
1618

1719
return cpus;
1820
}
21+
22+
static void cpu_map__delete(struct perf_cpu_map *map)
23+
{
24+
if (map) {
25+
WARN_ONCE(refcount_read(&map->refcnt) != 0,
26+
"cpu_map refcnt unbalanced\n");
27+
free(map);
28+
}
29+
}
30+
31+
struct perf_cpu_map *perf_cpu_map__get(struct perf_cpu_map *map)
32+
{
33+
if (map)
34+
refcount_inc(&map->refcnt);
35+
return map;
36+
}
37+
38+
void perf_cpu_map__put(struct perf_cpu_map *map)
39+
{
40+
if (map && refcount_dec_and_test(&map->refcnt))
41+
cpu_map__delete(map);
42+
}

‎tools/perf/lib/include/perf/cpumap.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@
77
struct perf_cpu_map;
88

99
LIBPERF_API struct perf_cpu_map *perf_cpu_map__dummy_new(void);
10+
LIBPERF_API struct perf_cpu_map *perf_cpu_map__get(struct perf_cpu_map *map);
11+
LIBPERF_API void perf_cpu_map__put(struct perf_cpu_map *map);
1012

1113
#endif /* __LIBPERF_CPUMAP_H */

‎tools/perf/lib/libperf.map‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ LIBPERF_0.0.1 {
22
global:
33
libperf_set_print;
44
perf_cpu_map__dummy_new;
5+
perf_cpu_map__get;
6+
perf_cpu_map__put;
57
local:
68
*;
79
};

‎tools/perf/tests/bitmap.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static unsigned long *get_bitmap(const char *str, int nbits)
2121
}
2222

2323
if (map)
24-
cpu_map__put(map);
24+
perf_cpu_map__put(map);
2525
return bm;
2626
}
2727

‎tools/perf/tests/code-reading.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ static int do_test_code_reading(bool try_kcore)
655655
* and will be freed by following perf_evlist__set_maps
656656
* call. Getting refference to keep them alive.
657657
*/
658-
cpu_map__get(cpus);
658+
perf_cpu_map__get(cpus);
659659
thread_map__get(threads);
660660
perf_evlist__set_maps(evlist, NULL, NULL);
661661
evlist__delete(evlist);
@@ -705,7 +705,7 @@ static int do_test_code_reading(bool try_kcore)
705705
if (evlist) {
706706
evlist__delete(evlist);
707707
} else {
708-
cpu_map__put(cpus);
708+
perf_cpu_map__put(cpus);
709709
thread_map__put(threads);
710710
}
711711
machine__delete_threads(machine);

‎tools/perf/tests/cpumap.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static int process_event_mask(struct perf_tool *tool __maybe_unused,
3939
TEST_ASSERT_VAL("wrong cpu", map->map[i] == i);
4040
}
4141

42-
cpu_map__put(map);
42+
perf_cpu_map__put(map);
4343
return 0;
4444
}
4545

@@ -68,7 +68,7 @@ static int process_event_cpus(struct perf_tool *tool __maybe_unused,
6868
TEST_ASSERT_VAL("wrong cpu", map->map[0] == 1);
6969
TEST_ASSERT_VAL("wrong cpu", map->map[1] == 256);
7070
TEST_ASSERT_VAL("wrong refcnt", refcount_read(&map->refcnt) == 1);
71-
cpu_map__put(map);
71+
perf_cpu_map__put(map);
7272
return 0;
7373
}
7474

@@ -83,15 +83,15 @@ int test__cpu_map_synthesize(struct test *test __maybe_unused, int subtest __may
8383
TEST_ASSERT_VAL("failed to synthesize map",
8484
!perf_event__synthesize_cpu_map(NULL, cpus, process_event_mask, NULL));
8585

86-
cpu_map__put(cpus);
86+
perf_cpu_map__put(cpus);
8787

8888
/* This one is better stores in cpu values. */
8989
cpus = cpu_map__new("1,256");
9090

9191
TEST_ASSERT_VAL("failed to synthesize map",
9292
!perf_event__synthesize_cpu_map(NULL, cpus, process_event_cpus, NULL));
9393

94-
cpu_map__put(cpus);
94+
perf_cpu_map__put(cpus);
9595
return 0;
9696
}
9797

0 commit comments

Comments
 (0)