Commit ff583dc4 authored by Ian Rogers's avatar Ian Rogers Committed by Arnaldo Carvalho de Melo
Browse files

perf maps: Remove rb_node from struct map



struct map is reference counted, having it also be a node in an
red-black tree complicates the reference counting. Switch to having a
map_rb_node which is a red-block tree node but points at the reference
counted struct map. This reference is responsible for a single reference
count.

Committer notes:

Fixed up tools/perf/util/unwind-libunwind-local.c to use map_rb_node as
well.

Signed-off-by: default avatarIan Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Darren Hart <dvhart@infradead.org>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Dmitriy Vyukov <dvyukov@google.com>
Cc: Eric Dumazet <edumazet@google.com>
Cc: German Gomez <german.gomez@arm.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Miaoqian Lin <linmq006@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Shunsuke Nakamura <nakamura.shun@fujitsu.com>
Cc: Song Liu <song@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Stephen Brennan <stephen.s.brennan@oracle.com>
Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Yury Norov <yury.norov@gmail.com>
Link: https://lore.kernel.org/r/20230320212248.1175731-2-irogers@google.com


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 83720209
Loading
Loading
Loading
Loading
+7 −6
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ int perf_event__synthesize_extra_kmaps(struct perf_tool *tool,
				       struct machine *machine)
{
	int rc = 0;
	struct map *pos;
	struct map_rb_node *pos;
	struct maps *kmaps = machine__kernel_maps(machine);
	union perf_event *event = zalloc(sizeof(event->mmap) +
					 machine->id_hdr_size);
@@ -33,11 +33,12 @@ int perf_event__synthesize_extra_kmaps(struct perf_tool *tool,
	maps__for_each_entry(kmaps, pos) {
		struct kmap *kmap;
		size_t size;
		struct map *map = pos->map;

		if (!__map__is_extra_kernel_map(pos))
		if (!__map__is_extra_kernel_map(map))
			continue;

		kmap = map__kmap(pos);
		kmap = map__kmap(map);

		size = sizeof(event->mmap) - sizeof(event->mmap.filename) +
		       PERF_ALIGN(strlen(kmap->name) + 1, sizeof(u64)) +
@@ -58,9 +59,9 @@ int perf_event__synthesize_extra_kmaps(struct perf_tool *tool,

		event->mmap.header.size = size;

		event->mmap.start = pos->start;
		event->mmap.len   = pos->end - pos->start;
		event->mmap.pgoff = pos->pgoff;
		event->mmap.start = map->start;
		event->mmap.len   = map->end - map->start;
		event->mmap.pgoff = map->pgoff;
		event->mmap.pid   = machine->pid;

		strlcpy(event->mmap.filename, kmap->name, PATH_MAX);
+4 −2
Original line number Diff line number Diff line
@@ -844,9 +844,11 @@ static struct task *tasks_list(struct task *task, struct machine *machine)
static size_t maps__fprintf_task(struct maps *maps, int indent, FILE *fp)
{
	size_t printed = 0;
	struct map *map;
	struct map_rb_node *rb_node;

	maps__for_each_entry(maps, rb_node) {
		struct map *map = rb_node->map;

	maps__for_each_entry(maps, map) {
		printed += fprintf(fp, "%*s  %" PRIx64 "-%" PRIx64 " %c%c%c%c %08" PRIx64 " %" PRIu64 " %s\n",
				   indent, "", map->start, map->end,
				   map->prot & PROT_READ ? 'r' : '-',
+5 −3
Original line number Diff line number Diff line
@@ -15,10 +15,12 @@ struct map_def {

static int check_maps(struct map_def *merged, unsigned int size, struct maps *maps)
{
	struct map *map;
	struct map_rb_node *rb_node;
	unsigned int i = 0;

	maps__for_each_entry(maps, map) {
	maps__for_each_entry(maps, rb_node) {
		struct map *map = rb_node->map;

		if (i > 0)
			TEST_ASSERT_VAL("less maps expected", (map && i < size) || (!map && i == size));

@@ -74,7 +76,7 @@ static int test__maps__merge_in(struct test_suite *t __maybe_unused, int subtest

		map->start = bpf_progs[i].start;
		map->end   = bpf_progs[i].end;
		maps__insert(maps, map);
		TEST_ASSERT_VAL("failed to insert map", maps__insert(maps, map) == 0);
		map__put(map);
	}

+10 −7
Original line number Diff line number Diff line
@@ -118,7 +118,8 @@ static int test__vmlinux_matches_kallsyms(struct test_suite *test __maybe_unused
	int err = TEST_FAIL;
	struct rb_node *nd;
	struct symbol *sym;
	struct map *kallsyms_map, *vmlinux_map, *map;
	struct map *kallsyms_map, *vmlinux_map;
	struct map_rb_node *rb_node;
	struct machine kallsyms, vmlinux;
	struct maps *maps;
	u64 mem_start, mem_end;
@@ -290,15 +291,15 @@ static int test__vmlinux_matches_kallsyms(struct test_suite *test __maybe_unused

	header_printed = false;

	maps__for_each_entry(maps, map) {
		struct map *
	maps__for_each_entry(maps, rb_node) {
		struct map *map = rb_node->map;
		/*
		 * If it is the kernel, kallsyms is always "[kernel.kallsyms]", while
		 * the kernel will have the path for the vmlinux file being used,
		 * so use the short name, less descriptive but the same ("[kernel]" in
		 * both cases.
		 */
		pair = maps__find_by_name(kallsyms.kmaps, (map->dso->kernel ?
		struct map *pair = maps__find_by_name(kallsyms.kmaps, (map->dso->kernel ?
								map->dso->short_name :
								map->dso->name));
		if (pair) {
@@ -314,8 +315,8 @@ static int test__vmlinux_matches_kallsyms(struct test_suite *test __maybe_unused

	header_printed = false;

	maps__for_each_entry(maps, map) {
		struct map *pair;
	maps__for_each_entry(maps, rb_node) {
		struct map *pair, *map = rb_node->map;

		mem_start = vmlinux_map->unmap_ip(vmlinux_map, map->start);
		mem_end = vmlinux_map->unmap_ip(vmlinux_map, map->end);
@@ -344,7 +345,9 @@ static int test__vmlinux_matches_kallsyms(struct test_suite *test __maybe_unused

	maps = machine__kernel_maps(&kallsyms);

	maps__for_each_entry(maps, map) {
	maps__for_each_entry(maps, rb_node) {
		struct map *map = rb_node->map;

		if (!map->priv) {
			if (!header_printed) {
				pr_info("WARN: Maps only in kallsyms:\n");
+1 −1
Original line number Diff line number Diff line
@@ -284,7 +284,7 @@ int lock_contention_read(struct lock_contention *con)
	}

	/* make sure it loads the kernel map */
	map__load(maps__first(machine->kmaps));
	map__load(maps__first(machine->kmaps)->map);

	prev_key = NULL;
	while (!bpf_map_get_next_key(fd, prev_key, &key)) {
Loading