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

perf maps: Use a pointer for kmaps



struct maps is reference counted, using a pointer is more idiomatic.

Committer notes:

Delay:

   maps = machine__kernel_maps(&vmlinux);

To after:

  machine__init(&vmlinux, "", HOST_KERNEL_ID);

To avoid this on f34:

  In file included from /var/home/acme/git/perf/tools/perf/util/build-id.h:10,
                   from /var/home/acme/git/perf/tools/perf/util/dso.h:13,
                   from tests/vmlinux-kallsyms.c:8:
  In function ‘machine__kernel_maps’,
      inlined from ‘test__vmlinux_matches_kallsyms’ at tests/vmlinux-kallsyms.c:122:22:
  /var/home/acme/git/perf/tools/perf/util/machine.h:86:23: error: ‘vmlinux.kmaps’ is used uninitialized [-Werror=uninitialized]
     86 |         return machine->kmaps;
        |                ~~~~~~~^~~~~~~
  tests/vmlinux-kallsyms.c: In function ‘test__vmlinux_matches_kallsyms’:
  tests/vmlinux-kallsyms.c:121:34: note: ‘vmlinux’ declared here
    121 |         struct machine kallsyms, vmlinux;
        |                                  ^~~~~~~
  cc1: all warnings being treated as errors

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: André Almeida <andrealmeid@collabora.com>
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: James Clark <james.clark@arm.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.garry@huawei.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: http://lore.kernel.org/lkml/20220211103415.2737789-6-irogers@google.com


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent e8eaadf4
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -18,7 +18,7 @@ int perf_event__synthesize_extra_kmaps(struct perf_tool *tool,
{
{
	int rc = 0;
	int rc = 0;
	struct map *pos;
	struct map *pos;
	struct maps *kmaps = &machine->kmaps;
	struct maps *kmaps = machine__kernel_maps(machine);
	union perf_event *event = zalloc(sizeof(event->mmap) +
	union perf_event *event = zalloc(sizeof(event->mmap) +
					 machine->id_hdr_size);
					 machine->id_hdr_size);


+5 −3
Original line number Original line Diff line number Diff line
@@ -119,7 +119,7 @@ static int test__vmlinux_matches_kallsyms(struct test_suite *test __maybe_unused
	struct symbol *sym;
	struct symbol *sym;
	struct map *kallsyms_map, *vmlinux_map, *map;
	struct map *kallsyms_map, *vmlinux_map, *map;
	struct machine kallsyms, vmlinux;
	struct machine kallsyms, vmlinux;
	struct maps *maps = machine__kernel_maps(&vmlinux);
	struct maps *maps;
	u64 mem_start, mem_end;
	u64 mem_start, mem_end;
	bool header_printed;
	bool header_printed;


@@ -132,6 +132,8 @@ static int test__vmlinux_matches_kallsyms(struct test_suite *test __maybe_unused
	machine__init(&kallsyms, "", HOST_KERNEL_ID);
	machine__init(&kallsyms, "", HOST_KERNEL_ID);
	machine__init(&vmlinux, "", HOST_KERNEL_ID);
	machine__init(&vmlinux, "", HOST_KERNEL_ID);


	maps = machine__kernel_maps(&vmlinux);

	/*
	/*
	 * Step 2:
	 * Step 2:
	 *
	 *
@@ -293,7 +295,7 @@ static int test__vmlinux_matches_kallsyms(struct test_suite *test __maybe_unused
		 * so use the short name, less descriptive but the same ("[kernel]" in
		 * so use the short name, less descriptive but the same ("[kernel]" in
		 * both cases.
		 * both cases.
		 */
		 */
		pair = maps__find_by_name(&kallsyms.kmaps, (map->dso->kernel ?
		pair = maps__find_by_name(kallsyms.kmaps, (map->dso->kernel ?
								map->dso->short_name :
								map->dso->short_name :
								map->dso->name));
								map->dso->name));
		if (pair) {
		if (pair) {
@@ -315,7 +317,7 @@ static int test__vmlinux_matches_kallsyms(struct test_suite *test __maybe_unused
		mem_start = vmlinux_map->unmap_ip(vmlinux_map, map->start);
		mem_start = vmlinux_map->unmap_ip(vmlinux_map, map->start);
		mem_end = vmlinux_map->unmap_ip(vmlinux_map, map->end);
		mem_end = vmlinux_map->unmap_ip(vmlinux_map, map->end);


		pair = maps__find(&kallsyms.kmaps, mem_start);
		pair = maps__find(kallsyms.kmaps, mem_start);
		if (pair == NULL || pair->priv)
		if (pair == NULL || pair->priv)
			continue;
			continue;


+1 −1
Original line number Original line Diff line number Diff line
@@ -105,7 +105,7 @@ static int machine__process_bpf_event_load(struct machine *machine,
	for (i = 0; i < info_linear->info.nr_jited_ksyms; i++) {
	for (i = 0; i < info_linear->info.nr_jited_ksyms; i++) {
		u64 *addrs = (u64 *)(uintptr_t)(info_linear->info.jited_ksyms);
		u64 *addrs = (u64 *)(uintptr_t)(info_linear->info.jited_ksyms);
		u64 addr = addrs[i];
		u64 addr = addrs[i];
		struct map *map = maps__find(&machine->kmaps, addr);
		struct map *map = maps__find(machine__kernel_maps(machine), addr);


		if (map) {
		if (map) {
			map->dso->binary_type = DSO_BINARY_TYPE__BPF_PROG_INFO;
			map->dso->binary_type = DSO_BINARY_TYPE__BPF_PROG_INFO;
+1 −1
Original line number Original line Diff line number Diff line
@@ -1119,7 +1119,7 @@ int fill_callchain_info(struct addr_location *al, struct callchain_cursor_node *
			goto out;
			goto out;
	}
	}


	if (al->maps == &al->maps->machine->kmaps) {
	if (al->maps == machine__kernel_maps(al->maps->machine)) {
		if (machine__is_host(al->maps->machine)) {
		if (machine__is_host(al->maps->machine)) {
			al->cpumode = PERF_RECORD_MISC_KERNEL;
			al->cpumode = PERF_RECORD_MISC_KERNEL;
			al->level = 'k';
			al->level = 'k';
+3 −3
Original line number Original line Diff line number Diff line
@@ -484,7 +484,7 @@ size_t perf_event__fprintf_text_poke(union perf_event *event, struct machine *ma
	if (machine) {
	if (machine) {
		struct addr_location al;
		struct addr_location al;


		al.map = maps__find(&machine->kmaps, tp->addr);
		al.map = maps__find(machine__kernel_maps(machine), tp->addr);
		if (al.map && map__load(al.map) >= 0) {
		if (al.map && map__load(al.map) >= 0) {
			al.addr = al.map->map_ip(al.map, tp->addr);
			al.addr = al.map->map_ip(al.map, tp->addr);
			al.sym = map__find_symbol(al.map, al.addr);
			al.sym = map__find_symbol(al.map, al.addr);
@@ -587,13 +587,13 @@ struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,


	if (cpumode == PERF_RECORD_MISC_KERNEL && perf_host) {
	if (cpumode == PERF_RECORD_MISC_KERNEL && perf_host) {
		al->level = 'k';
		al->level = 'k';
		al->maps = maps = &machine->kmaps;
		al->maps = maps = machine__kernel_maps(machine);
		load_map = true;
		load_map = true;
	} else if (cpumode == PERF_RECORD_MISC_USER && perf_host) {
	} else if (cpumode == PERF_RECORD_MISC_USER && perf_host) {
		al->level = '.';
		al->level = '.';
	} else if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL && perf_guest) {
	} else if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL && perf_guest) {
		al->level = 'g';
		al->level = 'g';
		al->maps = maps = &machine->kmaps;
		al->maps = maps = machine__kernel_maps(machine);
		load_map = true;
		load_map = true;
	} else if (cpumode == PERF_RECORD_MISC_GUEST_USER && perf_guest) {
	} else if (cpumode == PERF_RECORD_MISC_GUEST_USER && perf_guest) {
		al->level = 'u';
		al->level = 'u';
Loading