Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 38f01d8d authored by Jiri Olsa's avatar Jiri Olsa Committed by Arnaldo Carvalho de Melo
Browse files

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: default avatarJiri 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: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 397721e0
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -181,7 +181,7 @@ static int cs_etm_set_option(struct auxtrace_record *itr,

	err = 0;
out:
	cpu_map__put(online_cpus);
	perf_cpu_map__put(online_cpus);
	return err;
}

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

	cpu_map__put(online_cpus);
	perf_cpu_map__put(online_cpus);

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

	cpu_map__put(online_cpus);
	perf_cpu_map__put(online_cpus);

	return 0;
}
+2 −2
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ char *get_cpuid_str(struct perf_pmu *pmu)
		return NULL;

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

	cpu_map__put(cpus);
	perf_cpu_map__put(cpus);
	return buf;
}
+1 −1
Original line number Diff line number Diff line
@@ -206,7 +206,7 @@ static int reset_tracing_cpu(void)
	int ret;

	ret = set_tracing_cpumask(cpumap);
	cpu_map__put(cpumap);
	perf_cpu_map__put(cpumap);
	return ret;
}

+2 −2
Original line number Diff line number Diff line
@@ -933,8 +933,8 @@ static int perf_stat_init_aggr_mode(void)

static void perf_stat__exit_aggr_mode(void)
{
	cpu_map__put(stat_config.aggr_map);
	cpu_map__put(stat_config.cpus_aggr_map);
	perf_cpu_map__put(stat_config.aggr_map);
	perf_cpu_map__put(stat_config.cpus_aggr_map);
	stat_config.aggr_map = NULL;
	stat_config.cpus_aggr_map = NULL;
}
+24 −0
Original line number Diff line number Diff line
@@ -3,6 +3,8 @@
#include <stdlib.h>
#include <linux/refcount.h>
#include <internal/cpumap.h>
#include <asm/bug.h>
#include <stdio.h>

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

	return cpus;
}

static void cpu_map__delete(struct perf_cpu_map *map)
{
	if (map) {
		WARN_ONCE(refcount_read(&map->refcnt) != 0,
			  "cpu_map refcnt unbalanced\n");
		free(map);
	}
}

struct perf_cpu_map *perf_cpu_map__get(struct perf_cpu_map *map)
{
	if (map)
		refcount_inc(&map->refcnt);
	return map;
}

void perf_cpu_map__put(struct perf_cpu_map *map)
{
	if (map && refcount_dec_and_test(&map->refcnt))
		cpu_map__delete(map);
}
Loading