perf tools: Use struct extra_kernel_map in machine__process_kernel_mmap_event
Using struct extra_kernel_map in machine__process_kernel_mmap_event, to pass mmap details. This way we can used single function for all 3 mmap versions. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Acked-by: Ian Rogers <irogers@google.com> Acked-by: Namhyung Kim <namhyung@kernel.org> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Alexey Budankov <alexey.budankov@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Michael Petlan <mpetlan@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Song Liu <songliubraving@fb.com> Cc: Stephane Eranian <eranian@google.com> Link: http://lore.kernel.org/lkml/20201126170026.2619053-12-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
af21c579c8
commit
031f112f8d
|
@ -1581,32 +1581,25 @@ static bool machine__uses_kcore(struct machine *machine)
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool perf_event__is_extra_kernel_mmap(struct machine *machine,
|
static bool perf_event__is_extra_kernel_mmap(struct machine *machine,
|
||||||
union perf_event *event)
|
struct extra_kernel_map *xm)
|
||||||
{
|
{
|
||||||
return machine__is(machine, "x86_64") &&
|
return machine__is(machine, "x86_64") &&
|
||||||
is_entry_trampoline(event->mmap.filename);
|
is_entry_trampoline(xm->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int machine__process_extra_kernel_map(struct machine *machine,
|
static int machine__process_extra_kernel_map(struct machine *machine,
|
||||||
union perf_event *event)
|
struct extra_kernel_map *xm)
|
||||||
{
|
{
|
||||||
struct dso *kernel = machine__kernel_dso(machine);
|
struct dso *kernel = machine__kernel_dso(machine);
|
||||||
struct extra_kernel_map xm = {
|
|
||||||
.start = event->mmap.start,
|
|
||||||
.end = event->mmap.start + event->mmap.len,
|
|
||||||
.pgoff = event->mmap.pgoff,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (kernel == NULL)
|
if (kernel == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
strlcpy(xm.name, event->mmap.filename, KMAP_NAME_LEN);
|
return machine__create_extra_kernel_map(machine, kernel, xm);
|
||||||
|
|
||||||
return machine__create_extra_kernel_map(machine, kernel, &xm);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int machine__process_kernel_mmap_event(struct machine *machine,
|
static int machine__process_kernel_mmap_event(struct machine *machine,
|
||||||
union perf_event *event)
|
struct extra_kernel_map *xm)
|
||||||
{
|
{
|
||||||
struct map *map;
|
struct map *map;
|
||||||
enum dso_space_type dso_space;
|
enum dso_space_type dso_space;
|
||||||
|
@ -1621,20 +1614,18 @@ static int machine__process_kernel_mmap_event(struct machine *machine,
|
||||||
else
|
else
|
||||||
dso_space = DSO_SPACE__KERNEL_GUEST;
|
dso_space = DSO_SPACE__KERNEL_GUEST;
|
||||||
|
|
||||||
is_kernel_mmap = memcmp(event->mmap.filename,
|
is_kernel_mmap = memcmp(xm->name, machine->mmap_name,
|
||||||
machine->mmap_name,
|
|
||||||
strlen(machine->mmap_name) - 1) == 0;
|
strlen(machine->mmap_name) - 1) == 0;
|
||||||
if (event->mmap.filename[0] == '/' ||
|
if (xm->name[0] == '/' ||
|
||||||
(!is_kernel_mmap && event->mmap.filename[0] == '[')) {
|
(!is_kernel_mmap && xm->name[0] == '[')) {
|
||||||
map = machine__addnew_module_map(machine, event->mmap.start,
|
map = machine__addnew_module_map(machine, xm->start,
|
||||||
event->mmap.filename);
|
xm->name);
|
||||||
if (map == NULL)
|
if (map == NULL)
|
||||||
goto out_problem;
|
goto out_problem;
|
||||||
|
|
||||||
map->end = map->start + event->mmap.len;
|
map->end = map->start + xm->end - xm->start;
|
||||||
} else if (is_kernel_mmap) {
|
} else if (is_kernel_mmap) {
|
||||||
const char *symbol_name = (event->mmap.filename +
|
const char *symbol_name = (xm->name + strlen(machine->mmap_name));
|
||||||
strlen(machine->mmap_name));
|
|
||||||
/*
|
/*
|
||||||
* Should be there already, from the build-id table in
|
* Should be there already, from the build-id table in
|
||||||
* the header.
|
* the header.
|
||||||
|
@ -1688,18 +1679,17 @@ static int machine__process_kernel_mmap_event(struct machine *machine,
|
||||||
if (strstr(kernel->long_name, "vmlinux"))
|
if (strstr(kernel->long_name, "vmlinux"))
|
||||||
dso__set_short_name(kernel, "[kernel.vmlinux]", false);
|
dso__set_short_name(kernel, "[kernel.vmlinux]", false);
|
||||||
|
|
||||||
machine__update_kernel_mmap(machine, event->mmap.start,
|
machine__update_kernel_mmap(machine, xm->start, xm->end);
|
||||||
event->mmap.start + event->mmap.len);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Avoid using a zero address (kptr_restrict) for the ref reloc
|
* Avoid using a zero address (kptr_restrict) for the ref reloc
|
||||||
* symbol. Effectively having zero here means that at record
|
* symbol. Effectively having zero here means that at record
|
||||||
* time /proc/sys/kernel/kptr_restrict was non zero.
|
* time /proc/sys/kernel/kptr_restrict was non zero.
|
||||||
*/
|
*/
|
||||||
if (event->mmap.pgoff != 0) {
|
if (xm->pgoff != 0) {
|
||||||
map__set_kallsyms_ref_reloc_sym(machine->vmlinux_map,
|
map__set_kallsyms_ref_reloc_sym(machine->vmlinux_map,
|
||||||
symbol_name,
|
symbol_name,
|
||||||
event->mmap.pgoff);
|
xm->pgoff);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (machine__is_default_guest(machine)) {
|
if (machine__is_default_guest(machine)) {
|
||||||
|
@ -1708,8 +1698,8 @@ static int machine__process_kernel_mmap_event(struct machine *machine,
|
||||||
*/
|
*/
|
||||||
dso__load(kernel, machine__kernel_map(machine));
|
dso__load(kernel, machine__kernel_map(machine));
|
||||||
}
|
}
|
||||||
} else if (perf_event__is_extra_kernel_mmap(machine, event)) {
|
} else if (perf_event__is_extra_kernel_mmap(machine, xm)) {
|
||||||
return machine__process_extra_kernel_map(machine, event);
|
return machine__process_extra_kernel_map(machine, xm);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
out_problem:
|
out_problem:
|
||||||
|
@ -1735,7 +1725,14 @@ int machine__process_mmap2_event(struct machine *machine,
|
||||||
|
|
||||||
if (sample->cpumode == PERF_RECORD_MISC_GUEST_KERNEL ||
|
if (sample->cpumode == PERF_RECORD_MISC_GUEST_KERNEL ||
|
||||||
sample->cpumode == PERF_RECORD_MISC_KERNEL) {
|
sample->cpumode == PERF_RECORD_MISC_KERNEL) {
|
||||||
ret = machine__process_kernel_mmap_event(machine, event);
|
struct extra_kernel_map xm = {
|
||||||
|
.start = event->mmap2.start,
|
||||||
|
.end = event->mmap2.start + event->mmap2.len,
|
||||||
|
.pgoff = event->mmap2.pgoff,
|
||||||
|
};
|
||||||
|
|
||||||
|
strlcpy(xm.name, event->mmap2.filename, KMAP_NAME_LEN);
|
||||||
|
ret = machine__process_kernel_mmap_event(machine, &xm);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto out_problem;
|
goto out_problem;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1785,7 +1782,14 @@ int machine__process_mmap_event(struct machine *machine, union perf_event *event
|
||||||
|
|
||||||
if (sample->cpumode == PERF_RECORD_MISC_GUEST_KERNEL ||
|
if (sample->cpumode == PERF_RECORD_MISC_GUEST_KERNEL ||
|
||||||
sample->cpumode == PERF_RECORD_MISC_KERNEL) {
|
sample->cpumode == PERF_RECORD_MISC_KERNEL) {
|
||||||
ret = machine__process_kernel_mmap_event(machine, event);
|
struct extra_kernel_map xm = {
|
||||||
|
.start = event->mmap.start,
|
||||||
|
.end = event->mmap.start + event->mmap.len,
|
||||||
|
.pgoff = event->mmap.pgoff,
|
||||||
|
};
|
||||||
|
|
||||||
|
strlcpy(xm.name, event->mmap.filename, KMAP_NAME_LEN);
|
||||||
|
ret = machine__process_kernel_mmap_event(machine, &xm);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto out_problem;
|
goto out_problem;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue