Skip to content

Commit 1fb87b8

Browse files
olsajiriacmel
authored andcommitted
perf machine: Don't search for active kernel start in __machine__create_kernel_maps
We should not search for the kernel start address in __machine__create_kernel_maps(), because it's being used in the 'report' code path, where we are interested in kernel MMAP data address (the one recorded via 'perf record', possibly on another machine, or an older or newer kernel on the same machine where analysis is being performed) instead of in current kernel address. The __machine__create_kernel_maps() function serves purely for creating the machines kernel maps and setting up the kmap group. The report code path then sets the address based on the data from kernel MMAP event in the machine__set_kernel_mmap() function. The kallsyms search address logic is used for test code, that calls machine__create_kernel_maps() to get current maps and calls machine__get_running_kernel_start() to get kernel starting address. Use machine__set_kernel_mmap() to set the kernel maps start address and moving map_groups__fixup_end to be call when all maps are in place. Also make __machine__create_kernel_maps static, because there's no external user. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/20180215122635.24029-7-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 05db6ff commit 1fb87b8

File tree

2 files changed

+26
-30
lines changed

2 files changed

+26
-30
lines changed

tools/perf/util/machine.c

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -856,13 +856,10 @@ static int machine__get_running_kernel_start(struct machine *machine,
856856
return 0;
857857
}
858858

859-
int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel)
859+
static int
860+
__machine__create_kernel_maps(struct machine *machine, struct dso *kernel)
860861
{
861862
int type;
862-
u64 start = 0;
863-
864-
if (machine__get_running_kernel_start(machine, NULL, &start))
865-
return -1;
866863

867864
/* In case of renewal the kernel map, destroy previous one */
868865
machine__destroy_kernel_maps(machine);
@@ -871,7 +868,7 @@ int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel)
871868
struct kmap *kmap;
872869
struct map *map;
873870

874-
machine->vmlinux_maps[type] = map__new2(start, kernel, type);
871+
machine->vmlinux_maps[type] = map__new2(0, kernel, type);
875872
if (machine->vmlinux_maps[type] == NULL)
876873
return -1;
877874

@@ -1222,6 +1219,24 @@ static int machine__create_modules(struct machine *machine)
12221219
return 0;
12231220
}
12241221

1222+
static void machine__set_kernel_mmap(struct machine *machine,
1223+
u64 start, u64 end)
1224+
{
1225+
int i;
1226+
1227+
for (i = 0; i < MAP__NR_TYPES; i++) {
1228+
machine->vmlinux_maps[i]->start = start;
1229+
machine->vmlinux_maps[i]->end = end;
1230+
1231+
/*
1232+
* Be a bit paranoid here, some perf.data file came with
1233+
* a zero sized synthesized MMAP event for the kernel.
1234+
*/
1235+
if (machine->vmlinux_maps[i]->end == 0)
1236+
machine->vmlinux_maps[i]->end = ~0ULL;
1237+
}
1238+
}
1239+
12251240
int machine__create_kernel_maps(struct machine *machine)
12261241
{
12271242
struct dso *kernel = machine__get_kernel(machine);
@@ -1246,40 +1261,22 @@ int machine__create_kernel_maps(struct machine *machine)
12461261
"continuing anyway...\n", machine->pid);
12471262
}
12481263

1249-
/*
1250-
* Now that we have all the maps created, just set the ->end of them:
1251-
*/
1252-
map_groups__fixup_end(&machine->kmaps);
1253-
12541264
if (!machine__get_running_kernel_start(machine, &name, &addr)) {
12551265
if (name &&
12561266
maps__set_kallsyms_ref_reloc_sym(machine->vmlinux_maps, name, addr)) {
12571267
machine__destroy_kernel_maps(machine);
12581268
return -1;
12591269
}
1270+
machine__set_kernel_mmap(machine, addr, 0);
12601271
}
12611272

1273+
/*
1274+
* Now that we have all the maps created, just set the ->end of them:
1275+
*/
1276+
map_groups__fixup_end(&machine->kmaps);
12621277
return 0;
12631278
}
12641279

1265-
static void machine__set_kernel_mmap(struct machine *machine,
1266-
u64 start, u64 end)
1267-
{
1268-
int i;
1269-
1270-
for (i = 0; i < MAP__NR_TYPES; i++) {
1271-
machine->vmlinux_maps[i]->start = start;
1272-
machine->vmlinux_maps[i]->end = end;
1273-
1274-
/*
1275-
* Be a bit paranoid here, some perf.data file came with
1276-
* a zero sized synthesized MMAP event for the kernel.
1277-
*/
1278-
if (machine->vmlinux_maps[i]->end == 0)
1279-
machine->vmlinux_maps[i]->end = ~0ULL;
1280-
}
1281-
}
1282-
12831280
static bool machine__uses_kcore(struct machine *machine)
12841281
{
12851282
struct dso *dso;

tools/perf/util/machine.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ size_t machines__fprintf_dsos_buildid(struct machines *machines, FILE *fp,
238238
bool (skip)(struct dso *dso, int parm), int parm);
239239

240240
void machine__destroy_kernel_maps(struct machine *machine);
241-
int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel);
242241
int machine__create_kernel_maps(struct machine *machine);
243242

244243
int machines__create_kernel_maps(struct machines *machines, pid_t pid);

0 commit comments

Comments
 (0)