Skip to content

Commit

Permalink
perf record: Get ref_reloc_sym from kernel map
Browse files Browse the repository at this point in the history
Now that ref_reloc_sym is set up when the kernel map is created,
'perf record' does not need to pass the symbol names to
perf_event__synthesize_kernel_mmap() which can read the values needed
from ref_reloc_sym directly.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Tested-by: Jiri Olsa <jolsa@redhat.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1391004884-10334-6-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Adrian Hunter authored and Arnaldo Carvalho de Melo committed Jan 31, 2014
1 parent 5512cf2 commit 0ae617b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 30 deletions.
10 changes: 2 additions & 8 deletions tools/perf/builtin-record.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,7 @@ static void perf_event__synthesize_guest_os(struct machine *machine, void *data)
* have no _text sometimes.
*/
err = perf_event__synthesize_kernel_mmap(tool, process_synthesized_event,
machine, "_text");
if (err < 0)
err = perf_event__synthesize_kernel_mmap(tool, process_synthesized_event,
machine, "_stext");
machine);
if (err < 0)
pr_err("Couldn't record guest kernel [%d]'s reference"
" relocation symbol.\n", machine->pid);
Expand Down Expand Up @@ -457,10 +454,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
}

err = perf_event__synthesize_kernel_mmap(tool, process_synthesized_event,
machine, "_text");
if (err < 0)
err = perf_event__synthesize_kernel_mmap(tool, process_synthesized_event,
machine, "_stext");
machine);
if (err < 0)
pr_err("Couldn't record kernel reference relocation symbol\n"
"Symbol resolution may be skewed if relocation was used (e.g. kexec).\n"
Expand Down
26 changes: 6 additions & 20 deletions tools/perf/util/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,15 +483,13 @@ u64 kallsyms__get_function_start(const char *kallsyms_filename,

int perf_event__synthesize_kernel_mmap(struct perf_tool *tool,
perf_event__handler_t process,
struct machine *machine,
const char *symbol_name)
struct machine *machine)
{
size_t size;
const char *filename, *mmap_name;
char path[PATH_MAX];
const char *mmap_name;
char name_buff[PATH_MAX];
struct map *map;
u64 start;
struct kmap *kmap;
int err;
/*
* We should get this from /sys/kernel/sections/.text, but till that is
Expand All @@ -513,31 +511,19 @@ int perf_event__synthesize_kernel_mmap(struct perf_tool *tool,
* see kernel/perf_event.c __perf_event_mmap
*/
event->header.misc = PERF_RECORD_MISC_KERNEL;
filename = "/proc/kallsyms";
} else {
event->header.misc = PERF_RECORD_MISC_GUEST_KERNEL;
if (machine__is_default_guest(machine))
filename = (char *) symbol_conf.default_guest_kallsyms;
else {
sprintf(path, "%s/proc/kallsyms", machine->root_dir);
filename = path;
}
}

start = kallsyms__get_function_start(filename, symbol_name);
if (!start) {
free(event);
return -ENOENT;
}

map = machine->vmlinux_maps[MAP__FUNCTION];
kmap = map__kmap(map);
size = snprintf(event->mmap.filename, sizeof(event->mmap.filename),
"%s%s", mmap_name, symbol_name) + 1;
"%s%s", mmap_name, kmap->ref_reloc_sym->name) + 1;
size = PERF_ALIGN(size, sizeof(u64));
event->mmap.header.type = PERF_RECORD_MMAP;
event->mmap.header.size = (sizeof(event->mmap) -
(sizeof(event->mmap.filename) - size) + machine->id_hdr_size);
event->mmap.pgoff = start;
event->mmap.pgoff = kmap->ref_reloc_sym->addr;
event->mmap.start = map->start;
event->mmap.len = map->end - event->mmap.start;
event->mmap.pid = machine->pid;
Expand Down
3 changes: 1 addition & 2 deletions tools/perf/util/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,7 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
struct machine *machine, bool mmap_data);
int perf_event__synthesize_kernel_mmap(struct perf_tool *tool,
perf_event__handler_t process,
struct machine *machine,
const char *symbol_name);
struct machine *machine);

int perf_event__synthesize_modules(struct perf_tool *tool,
perf_event__handler_t process,
Expand Down

0 comments on commit 0ae617b

Please sign in to comment.