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

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

perf tools: Add reference counting for cpu_map object



Adding refference counting for cpu_map object, so it could be easily
shared among other objects.

Using cpu_map__put instead cpu_map__delete and making cpu_map__delete
static.

Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1435012588-9007-4-git-send-email-jolsa@kernel.org


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 4cc97614
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -545,7 +545,7 @@ static int do_test_code_reading(bool try_kcore)
	if (evlist) {
		perf_evlist__delete(evlist);
	} else {
		cpu_map__delete(cpus);
		cpu_map__put(cpus);
		thread_map__delete(threads);
	}
	machines__destroy_kernel_maps(&machines);
+1 −1
Original line number Diff line number Diff line
@@ -144,7 +144,7 @@ int test__keep_tracking(void)
		perf_evlist__disable(evlist);
		perf_evlist__delete(evlist);
	} else {
		cpu_map__delete(cpus);
		cpu_map__put(cpus);
		thread_map__delete(threads);
	}

+1 −1
Original line number Diff line number Diff line
@@ -140,7 +140,7 @@ int test__basic_mmap(void)
	cpus	= NULL;
	threads = NULL;
out_free_cpus:
	cpu_map__delete(cpus);
	cpu_map__put(cpus);
out_free_threads:
	thread_map__delete(threads);
	return err;
+1 −1
Original line number Diff line number Diff line
@@ -560,7 +560,7 @@ int test__switch_tracking(void)
		perf_evlist__disable(evlist);
		perf_evlist__delete(evlist);
	} else {
		cpu_map__delete(cpus);
		cpu_map__put(cpus);
		thread_map__delete(threads);
	}

+24 −2
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include "asm/bug.h"

static struct cpu_map *cpu_map__default_new(void)
{
@@ -22,6 +23,7 @@ static struct cpu_map *cpu_map__default_new(void)
			cpus->map[i] = i;

		cpus->nr = nr_cpus;
		atomic_set(&cpus->refcnt, 1);
	}

	return cpus;
@@ -35,6 +37,7 @@ static struct cpu_map *cpu_map__trim_new(int nr_cpus, int *tmp_cpus)
	if (cpus != NULL) {
		cpus->nr = nr_cpus;
		memcpy(cpus->map, tmp_cpus, payload_size);
		atomic_set(&cpus->refcnt, 1);
	}

	return cpus;
@@ -194,15 +197,33 @@ struct cpu_map *cpu_map__dummy_new(void)
	if (cpus != NULL) {
		cpus->nr = 1;
		cpus->map[0] = -1;
		atomic_set(&cpus->refcnt, 1);
	}

	return cpus;
}

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

struct cpu_map *cpu_map__get(struct cpu_map *map)
{
	if (map)
		atomic_inc(&map->refcnt);
	return map;
}

void cpu_map__put(struct cpu_map *map)
{
	if (map && atomic_dec_and_test(&map->refcnt))
		cpu_map__delete(map);
}

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,
	/* ensure we process id in increasing order */
	qsort(c->map, c->nr, sizeof(int), cmp_ids);

	atomic_set(&cpus->refcnt, 1);
	*res = c;
	return 0;
}
Loading