2010-03-25 22:59:00 +00:00
|
|
|
#include <dirent.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
2011-01-22 22:37:02 +00:00
|
|
|
#include <inttypes.h>
|
2010-05-20 15:15:33 +00:00
|
|
|
#include "build-id.h"
|
2012-02-10 01:10:17 +00:00
|
|
|
#include "util.h"
|
2010-07-20 17:42:52 +00:00
|
|
|
#include "debug.h"
|
2012-11-09 14:32:52 +00:00
|
|
|
#include "machine.h"
|
2009-05-28 17:55:04 +00:00
|
|
|
#include "symbol.h"
|
2010-03-25 22:59:00 +00:00
|
|
|
#include "strlist.h"
|
2015-03-24 15:52:41 +00:00
|
|
|
#include "intlist.h"
|
2014-08-12 06:40:45 +00:00
|
|
|
#include "header.h"
|
2009-05-28 17:55:04 +00:00
|
|
|
|
|
|
|
#include <elf.h>
|
2009-11-18 22:20:52 +00:00
|
|
|
#include <limits.h>
|
2013-12-11 12:15:00 +00:00
|
|
|
#include <symbol/kallsyms.h>
|
2009-10-02 06:29:58 +00:00
|
|
|
#include <sys/utsname.h>
|
2009-08-05 12:05:16 +00:00
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
static int dso__load_kernel_sym(struct dso *dso, struct map *map,
|
2010-02-03 18:52:00 +00:00
|
|
|
symbol_filter_t filter);
|
2011-03-31 13:56:28 +00:00
|
|
|
static int dso__load_guest_kernel_sym(struct dso *dso, struct map *map,
|
2010-04-19 05:32:50 +00:00
|
|
|
symbol_filter_t filter);
|
2012-12-07 20:39:39 +00:00
|
|
|
int vmlinux_path__nr_entries;
|
|
|
|
char **vmlinux_path;
|
2009-10-02 06:29:58 +00:00
|
|
|
|
2009-12-15 22:04:39 +00:00
|
|
|
struct symbol_conf symbol_conf = {
|
2013-12-24 07:19:25 +00:00
|
|
|
.use_modules = true,
|
|
|
|
.try_vmlinux_path = true,
|
|
|
|
.annotate_src = true,
|
|
|
|
.demangle = true,
|
2014-09-13 04:15:05 +00:00
|
|
|
.demangle_kernel = false,
|
2013-12-24 07:19:25 +00:00
|
|
|
.cumulate_callchain = true,
|
2014-06-27 16:26:58 +00:00
|
|
|
.show_hist_headers = true,
|
2013-12-24 07:19:25 +00:00
|
|
|
.symfs = "",
|
2009-11-24 14:05:15 +00:00
|
|
|
};
|
|
|
|
|
2012-07-22 12:14:32 +00:00
|
|
|
static enum dso_binary_type binary_type_symtab[] = {
|
|
|
|
DSO_BINARY_TYPE__KALLSYMS,
|
|
|
|
DSO_BINARY_TYPE__GUEST_KALLSYMS,
|
|
|
|
DSO_BINARY_TYPE__JAVA_JIT,
|
|
|
|
DSO_BINARY_TYPE__DEBUGLINK,
|
|
|
|
DSO_BINARY_TYPE__BUILD_ID_CACHE,
|
|
|
|
DSO_BINARY_TYPE__FEDORA_DEBUGINFO,
|
|
|
|
DSO_BINARY_TYPE__UBUNTU_DEBUGINFO,
|
|
|
|
DSO_BINARY_TYPE__BUILDID_DEBUGINFO,
|
|
|
|
DSO_BINARY_TYPE__SYSTEM_PATH_DSO,
|
|
|
|
DSO_BINARY_TYPE__GUEST_KMODULE,
|
2014-11-04 01:14:27 +00:00
|
|
|
DSO_BINARY_TYPE__GUEST_KMODULE_COMP,
|
2012-07-22 12:14:32 +00:00
|
|
|
DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE,
|
2014-11-04 01:14:27 +00:00
|
|
|
DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP,
|
2013-09-18 13:56:14 +00:00
|
|
|
DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO,
|
2012-07-22 12:14:32 +00:00
|
|
|
DSO_BINARY_TYPE__NOT_FOUND,
|
|
|
|
};
|
|
|
|
|
2012-08-01 12:47:57 +00:00
|
|
|
#define DSO_BINARY_TYPE__SYMTAB_CNT ARRAY_SIZE(binary_type_symtab)
|
2012-07-22 12:14:32 +00:00
|
|
|
|
2010-01-04 18:19:27 +00:00
|
|
|
bool symbol_type__is_a(char symbol_type, enum map_type map_type)
|
2009-12-11 16:50:37 +00:00
|
|
|
{
|
2011-08-24 06:40:16 +00:00
|
|
|
symbol_type = toupper(symbol_type);
|
|
|
|
|
2009-12-11 16:50:37 +00:00
|
|
|
switch (map_type) {
|
|
|
|
case MAP__FUNCTION:
|
|
|
|
return symbol_type == 'T' || symbol_type == 'W';
|
perf symbols: Add support for 'variable' symtabs
Example:
{
u64 addr = strtoull(sym_filter, NULL, 16);
struct map *map = map_groups__find(kmaps, MAP__VARIABLE, addr);
if (map == NULL)
pr_err("couldn't find map!\n");
else {
struct symbol *sym = map__find_symbol(map, addr, NULL);
if (sym == NULL)
pr_err("couldn't find addr!\n");
else
pr_info("addr %#Lx is in %s global var\n", addr, sym->name);
}
exit(0);
}
Added just after symbol__init() call in 'perf top', then:
{
u64 addr = strtoull(sym_filter, NULL, 16);
struct map *map = map_groups__find(kmaps, MAP__VARIABLE, addr);
if (map == NULL)
pr_err("couldn't find map!\n");
else {
struct symbol *sym = map__find_symbol(map, addr, NULL);
if (sym == NULL)
pr_err("couldn't find addr!\n");
else
pr_info("addr %#Lx is in %s global var\n", addr, sym->name);
}
exit(0);
}
[root@doppio linux-2.6-tip]# grep ' [dD] ' /proc/kallsyms | grep ' sched'
ffffffff817827d8 d sched_nr_latency
ffffffff81782ce0 d sched_domains_mutex
ffffffff8178c070 d schedstr.22423
ffffffff817909a0 d sched_register_mutex
ffffffff81823490 d sched_feat_names
ffffffff81823558 d scheduler_running
ffffffff818235b8 d sched_clock_running
ffffffff818235bc D sched_clock_stable
ffffffff81824f00 d sched_switch_trace
[root@doppio linux-2.6-tip]# perf top -s 0xffffffff817827d9
addr 0xffffffff817827d9 is in sched_nr_latency global var
[root@doppio linux-2.6-tip]# perf top -s ffffffff81782ce0
addr 0xffffffff81782ce0 is in sched_domains_mutex global var
[root@doppio linux-2.6-tip]#
[root@doppio linux-2.6-tip]# perf top -s ffffffff81782ce0 --vmlinux OFF
The file OFF cannot be used, trying to use /proc/kallsyms...addr 0xffffffff81782ce0 is in sched_domains_mutex global var
[root@doppio linux-2.6-tip]# perf top -s ffffffff818235bc --vmlinux OFF
The file OFF cannot be used, trying to use /proc/kallsyms...addr 0xffffffff818235bc is in sched_clock_stable global var
[root@doppio linux-2.6-tip]#
So it works with both /proc/kallsyms and with ELF symtabs, either
the one on the vmlinux explicitely passed via --vmlinux or in one
in the vmlinux_path that matches the buildid for the running kernel
or the one found in the buildid header section in a perf.data file.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260550239-5372-4-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-11 16:50:39 +00:00
|
|
|
case MAP__VARIABLE:
|
2011-08-24 06:40:16 +00:00
|
|
|
return symbol_type == 'D';
|
2009-12-11 16:50:37 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-24 06:40:17 +00:00
|
|
|
static int prefix_underscores_count(const char *str)
|
|
|
|
{
|
|
|
|
const char *tail = str;
|
|
|
|
|
|
|
|
while (*tail == '_')
|
|
|
|
tail++;
|
|
|
|
|
|
|
|
return tail - str;
|
|
|
|
}
|
|
|
|
|
2015-04-28 12:05:36 +00:00
|
|
|
int __weak arch__choose_best_symbol(struct symbol *syma,
|
|
|
|
struct symbol *symb __maybe_unused)
|
|
|
|
{
|
|
|
|
/* Avoid "SyS" kernel syscall aliases */
|
|
|
|
if (strlen(syma->name) >= 3 && !strncmp(syma->name, "SyS", 3))
|
|
|
|
return SYMBOL_B;
|
|
|
|
if (strlen(syma->name) >= 10 && !strncmp(syma->name, "compat_SyS", 10))
|
|
|
|
return SYMBOL_B;
|
|
|
|
|
|
|
|
return SYMBOL_A;
|
|
|
|
}
|
2011-08-24 06:40:17 +00:00
|
|
|
|
|
|
|
static int choose_best_symbol(struct symbol *syma, struct symbol *symb)
|
|
|
|
{
|
|
|
|
s64 a;
|
|
|
|
s64 b;
|
2013-08-07 11:38:49 +00:00
|
|
|
size_t na, nb;
|
2011-08-24 06:40:17 +00:00
|
|
|
|
|
|
|
/* Prefer a symbol with non zero length */
|
|
|
|
a = syma->end - syma->start;
|
|
|
|
b = symb->end - symb->start;
|
|
|
|
if ((b == 0) && (a > 0))
|
|
|
|
return SYMBOL_A;
|
|
|
|
else if ((a == 0) && (b > 0))
|
|
|
|
return SYMBOL_B;
|
|
|
|
|
|
|
|
/* Prefer a non weak symbol over a weak one */
|
|
|
|
a = syma->binding == STB_WEAK;
|
|
|
|
b = symb->binding == STB_WEAK;
|
|
|
|
if (b && !a)
|
|
|
|
return SYMBOL_A;
|
|
|
|
if (a && !b)
|
|
|
|
return SYMBOL_B;
|
|
|
|
|
|
|
|
/* Prefer a global symbol over a non global one */
|
|
|
|
a = syma->binding == STB_GLOBAL;
|
|
|
|
b = symb->binding == STB_GLOBAL;
|
|
|
|
if (a && !b)
|
|
|
|
return SYMBOL_A;
|
|
|
|
if (b && !a)
|
|
|
|
return SYMBOL_B;
|
|
|
|
|
|
|
|
/* Prefer a symbol with less underscores */
|
|
|
|
a = prefix_underscores_count(syma->name);
|
|
|
|
b = prefix_underscores_count(symb->name);
|
|
|
|
if (b > a)
|
|
|
|
return SYMBOL_A;
|
|
|
|
else if (a > b)
|
|
|
|
return SYMBOL_B;
|
|
|
|
|
2013-08-07 11:38:49 +00:00
|
|
|
/* Choose the symbol with the longest name */
|
|
|
|
na = strlen(syma->name);
|
|
|
|
nb = strlen(symb->name);
|
|
|
|
if (na > nb)
|
2011-08-24 06:40:17 +00:00
|
|
|
return SYMBOL_A;
|
2013-08-07 11:38:49 +00:00
|
|
|
else if (na < nb)
|
2011-08-24 06:40:17 +00:00
|
|
|
return SYMBOL_B;
|
2013-08-07 11:38:49 +00:00
|
|
|
|
2015-04-28 12:05:36 +00:00
|
|
|
return arch__choose_best_symbol(syma, symb);
|
2011-08-24 06:40:17 +00:00
|
|
|
}
|
|
|
|
|
2012-08-06 04:41:20 +00:00
|
|
|
void symbols__fixup_duplicate(struct rb_root *symbols)
|
2011-08-24 06:40:17 +00:00
|
|
|
{
|
|
|
|
struct rb_node *nd;
|
|
|
|
struct symbol *curr, *next;
|
|
|
|
|
|
|
|
nd = rb_first(symbols);
|
|
|
|
|
|
|
|
while (nd) {
|
|
|
|
curr = rb_entry(nd, struct symbol, rb_node);
|
|
|
|
again:
|
|
|
|
nd = rb_next(&curr->rb_node);
|
|
|
|
next = rb_entry(nd, struct symbol, rb_node);
|
|
|
|
|
|
|
|
if (!nd)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (curr->start != next->start)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (choose_best_symbol(curr, next) == SYMBOL_A) {
|
|
|
|
rb_erase(&next->rb_node, symbols);
|
2013-10-11 00:27:59 +00:00
|
|
|
symbol__delete(next);
|
2011-08-24 06:40:17 +00:00
|
|
|
goto again;
|
|
|
|
} else {
|
|
|
|
nd = rb_next(&curr->rb_node);
|
|
|
|
rb_erase(&curr->rb_node, symbols);
|
2013-10-11 00:27:59 +00:00
|
|
|
symbol__delete(curr);
|
2011-08-24 06:40:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-06 04:41:20 +00:00
|
|
|
void symbols__fixup_end(struct rb_root *symbols)
|
2009-10-05 17:26:17 +00:00
|
|
|
{
|
2011-03-31 13:56:28 +00:00
|
|
|
struct rb_node *nd, *prevnd = rb_first(symbols);
|
2009-10-07 16:48:56 +00:00
|
|
|
struct symbol *curr, *prev;
|
2009-10-05 17:26:17 +00:00
|
|
|
|
|
|
|
if (prevnd == NULL)
|
|
|
|
return;
|
|
|
|
|
2009-10-07 16:48:56 +00:00
|
|
|
curr = rb_entry(prevnd, struct symbol, rb_node);
|
|
|
|
|
2009-10-05 17:26:17 +00:00
|
|
|
for (nd = rb_next(prevnd); nd; nd = rb_next(nd)) {
|
2009-10-07 16:48:56 +00:00
|
|
|
prev = curr;
|
|
|
|
curr = rb_entry(nd, struct symbol, rb_node);
|
2009-10-05 17:26:17 +00:00
|
|
|
|
2010-12-22 03:08:36 +00:00
|
|
|
if (prev->end == prev->start && prev->end != curr->start)
|
2014-10-14 20:19:44 +00:00
|
|
|
prev->end = curr->start;
|
2009-10-05 17:26:17 +00:00
|
|
|
}
|
2009-10-07 16:48:56 +00:00
|
|
|
|
|
|
|
/* Last entry */
|
|
|
|
if (curr->end == curr->start)
|
|
|
|
curr->end = roundup(curr->start, 4096);
|
2009-10-05 17:26:17 +00:00
|
|
|
}
|
|
|
|
|
2012-08-06 04:41:20 +00:00
|
|
|
void __map_groups__fixup_end(struct map_groups *mg, enum map_type type)
|
2009-10-05 17:26:17 +00:00
|
|
|
{
|
2015-05-22 15:58:53 +00:00
|
|
|
struct maps *maps = &mg->maps[type];
|
2015-05-22 14:52:22 +00:00
|
|
|
struct map *next, *curr;
|
2009-10-05 17:26:17 +00:00
|
|
|
|
2015-05-22 16:45:24 +00:00
|
|
|
pthread_rwlock_wrlock(&maps->lock);
|
|
|
|
|
2015-05-22 14:52:22 +00:00
|
|
|
curr = maps__first(maps);
|
|
|
|
if (curr == NULL)
|
2015-05-22 16:45:24 +00:00
|
|
|
goto out_unlock;
|
2009-10-05 17:26:17 +00:00
|
|
|
|
2015-05-22 14:52:22 +00:00
|
|
|
for (next = map__next(curr); next; next = map__next(curr)) {
|
|
|
|
curr->end = next->start;
|
|
|
|
curr = next;
|
2009-10-07 16:48:56 +00:00
|
|
|
}
|
2009-11-21 16:31:24 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We still haven't the actual symbols, so guess the
|
|
|
|
* last map final address.
|
|
|
|
*/
|
2010-11-25 04:12:53 +00:00
|
|
|
curr->end = ~0ULL;
|
2015-05-22 16:45:24 +00:00
|
|
|
|
|
|
|
out_unlock:
|
|
|
|
pthread_rwlock_unlock(&maps->lock);
|
2009-10-05 17:26:17 +00:00
|
|
|
}
|
|
|
|
|
2012-08-06 04:41:20 +00:00
|
|
|
struct symbol *symbol__new(u64 start, u64 len, u8 binding, const char *name)
|
2009-05-28 17:55:04 +00:00
|
|
|
{
|
2009-05-28 17:55:13 +00:00
|
|
|
size_t namelen = strlen(name) + 1;
|
2011-03-31 13:56:28 +00:00
|
|
|
struct symbol *sym = calloc(1, (symbol_conf.priv_size +
|
|
|
|
sizeof(*sym) + namelen));
|
|
|
|
if (sym == NULL)
|
perf_counter tools: Add 'perf annotate' feature
Add new perf sub-command to display annotated source code:
$ perf annotate decode_tree_entry
------------------------------------------------
Percent | Source code & Disassembly of /home/mingo/git/git
------------------------------------------------
:
: /home/mingo/git/git: file format elf64-x86-64
:
:
: Disassembly of section .text:
:
: 00000000004a0da0 <decode_tree_entry>:
: *modep = mode;
: return str;
: }
:
: static void decode_tree_entry(struct tree_desc *desc, const char *buf, unsigned long size)
: {
3.82 : 4a0da0: 41 54 push %r12
: const char *path;
: unsigned int mode, len;
:
: if (size < 24 || buf[size - 21])
0.17 : 4a0da2: 48 83 fa 17 cmp $0x17,%rdx
: *modep = mode;
: return str;
: }
:
: static void decode_tree_entry(struct tree_desc *desc, const char *buf, unsigned long size)
: {
0.00 : 4a0da6: 49 89 fc mov %rdi,%r12
0.00 : 4a0da9: 55 push %rbp
3.37 : 4a0daa: 53 push %rbx
: const char *path;
: unsigned int mode, len;
:
: if (size < 24 || buf[size - 21])
0.08 : 4a0dab: 76 73 jbe 4a0e20 <decode_tree_entry+0x80>
0.00 : 4a0dad: 80 7c 16 eb 00 cmpb $0x0,-0x15(%rsi,%rdx,1)
3.48 : 4a0db2: 75 6c jne 4a0e20 <decode_tree_entry+0x80>
: static const char *get_mode(const char *str, unsigned int *modep)
: {
: unsigned char c;
: unsigned int mode = 0;
:
: if (*str == ' ')
1.94 : 4a0db4: 0f b6 06 movzbl (%rsi),%eax
0.39 : 4a0db7: 3c 20 cmp $0x20,%al
0.00 : 4a0db9: 74 65 je 4a0e20 <decode_tree_entry+0x80>
: return NULL;
:
: while ((c = *str++) != ' ') {
0.06 : 4a0dbb: 89 c2 mov %eax,%edx
: if (c < '0' || c > '7')
1.99 : 4a0dbd: 31 ed xor %ebp,%ebp
: unsigned int mode = 0;
:
: if (*str == ' ')
: return NULL;
:
: while ((c = *str++) != ' ') {
1.74 : 4a0dbf: 48 8d 5e 01 lea 0x1(%rsi),%rbx
: if (c < '0' || c > '7')
0.00 : 4a0dc3: 8d 42 d0 lea -0x30(%rdx),%eax
0.17 : 4a0dc6: 3c 07 cmp $0x7,%al
0.00 : 4a0dc8: 76 0d jbe 4a0dd7 <decode_tree_entry+0x37>
0.00 : 4a0dca: eb 54 jmp 4a0e20 <decode_tree_entry+0x80>
0.00 : 4a0dcc: 0f 1f 40 00 nopl 0x0(%rax)
16.57 : 4a0dd0: 8d 42 d0 lea -0x30(%rdx),%eax
0.14 : 4a0dd3: 3c 07 cmp $0x7,%al
0.00 : 4a0dd5: 77 49 ja 4a0e20 <decode_tree_entry+0x80>
: return NULL;
: mode = (mode << 3) + (c - '0');
3.12 : 4a0dd7: 0f b6 c2 movzbl %dl,%eax
: unsigned int mode = 0;
:
: if (*str == ' ')
: return NULL;
:
: while ((c = *str++) != ' ') {
0.00 : 4a0dda: 0f b6 13 movzbl (%rbx),%edx
16.74 : 4a0ddd: 48 83 c3 01 add $0x1,%rbx
: if (c < '0' || c > '7')
: return NULL;
: mode = (mode << 3) + (c - '0');
The first column is the percentage of samples that arrived on that
particular line - relative to the total cost of the function.
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <new-submission>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-06-06 13:48:52 +00:00
|
|
|
return NULL;
|
|
|
|
|
2009-12-15 22:04:39 +00:00
|
|
|
if (symbol_conf.priv_size)
|
2011-03-31 13:56:28 +00:00
|
|
|
sym = ((void *)sym) + symbol_conf.priv_size;
|
2009-10-20 16:25:40 +00:00
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
sym->start = start;
|
2014-10-14 20:19:44 +00:00
|
|
|
sym->end = len ? start + len : start;
|
2011-03-31 13:56:28 +00:00
|
|
|
sym->binding = binding;
|
|
|
|
sym->namelen = namelen - 1;
|
2009-10-20 16:25:40 +00:00
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
pr_debug4("%s: %s %#" PRIx64 "-%#" PRIx64 "\n",
|
|
|
|
__func__, name, start, sym->end);
|
|
|
|
memcpy(sym->name, name, namelen);
|
2009-05-28 17:55:04 +00:00
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
return sym;
|
2009-05-28 17:55:04 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
void symbol__delete(struct symbol *sym)
|
2009-05-28 17:55:04 +00:00
|
|
|
{
|
2011-03-31 13:56:28 +00:00
|
|
|
free(((void *)sym) - symbol_conf.priv_size);
|
2009-05-28 17:55:04 +00:00
|
|
|
}
|
|
|
|
|
2012-10-27 21:18:32 +00:00
|
|
|
size_t symbol__fprintf(struct symbol *sym, FILE *fp)
|
2009-05-28 17:55:04 +00:00
|
|
|
{
|
2011-01-22 22:37:02 +00:00
|
|
|
return fprintf(fp, " %" PRIx64 "-%" PRIx64 " %c %s\n",
|
2011-03-31 13:56:28 +00:00
|
|
|
sym->start, sym->end,
|
|
|
|
sym->binding == STB_GLOBAL ? 'g' :
|
|
|
|
sym->binding == STB_LOCAL ? 'l' : 'w',
|
|
|
|
sym->name);
|
2009-05-28 17:55:04 +00:00
|
|
|
}
|
|
|
|
|
2012-01-30 04:43:15 +00:00
|
|
|
size_t symbol__fprintf_symname_offs(const struct symbol *sym,
|
|
|
|
const struct addr_location *al, FILE *fp)
|
2012-01-30 04:42:57 +00:00
|
|
|
{
|
2012-01-30 04:43:15 +00:00
|
|
|
unsigned long offset;
|
|
|
|
size_t length;
|
|
|
|
|
|
|
|
if (sym && sym->name) {
|
|
|
|
length = fprintf(fp, "%s", sym->name);
|
|
|
|
if (al) {
|
2013-07-28 15:48:32 +00:00
|
|
|
if (al->addr < sym->end)
|
|
|
|
offset = al->addr - sym->start;
|
|
|
|
else
|
|
|
|
offset = al->addr - al->map->start - sym->start;
|
2012-01-30 04:43:15 +00:00
|
|
|
length += fprintf(fp, "+0x%lx", offset);
|
|
|
|
}
|
|
|
|
return length;
|
|
|
|
} else
|
|
|
|
return fprintf(fp, "[unknown]");
|
|
|
|
}
|
2012-01-30 04:42:57 +00:00
|
|
|
|
2012-01-30 04:43:15 +00:00
|
|
|
size_t symbol__fprintf_symname(const struct symbol *sym, FILE *fp)
|
|
|
|
{
|
|
|
|
return symbol__fprintf_symname_offs(sym, NULL, fp);
|
2012-01-30 04:42:57 +00:00
|
|
|
}
|
|
|
|
|
2012-10-27 21:18:32 +00:00
|
|
|
void symbols__delete(struct rb_root *symbols)
|
2009-05-28 17:55:04 +00:00
|
|
|
{
|
|
|
|
struct symbol *pos;
|
2011-03-31 13:56:28 +00:00
|
|
|
struct rb_node *next = rb_first(symbols);
|
2009-05-28 17:55:04 +00:00
|
|
|
|
|
|
|
while (next) {
|
|
|
|
pos = rb_entry(next, struct symbol, rb_node);
|
|
|
|
next = rb_next(&pos->rb_node);
|
2011-03-31 13:56:28 +00:00
|
|
|
rb_erase(&pos->rb_node, symbols);
|
2009-10-30 18:28:24 +00:00
|
|
|
symbol__delete(pos);
|
2009-05-28 17:55:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-06 04:41:20 +00:00
|
|
|
void symbols__insert(struct rb_root *symbols, struct symbol *sym)
|
2009-05-28 17:55:04 +00:00
|
|
|
{
|
2011-03-31 13:56:28 +00:00
|
|
|
struct rb_node **p = &symbols->rb_node;
|
2009-05-28 17:55:04 +00:00
|
|
|
struct rb_node *parent = NULL;
|
perf_counter tools: Define and use our own u64, s64 etc. definitions
On 64-bit powerpc, __u64 is defined to be unsigned long rather than
unsigned long long. This causes compiler warnings every time we
print a __u64 value with %Lx.
Rather than changing __u64, we define our own u64 to be unsigned long
long on all architectures, and similarly s64 as signed long long.
For consistency we also define u32, s32, u16, s16, u8 and s8. These
definitions are put in a new header, types.h, because these definitions
are needed in util/string.h and util/symbol.h.
The main change here is the mechanical change of __[us]{64,32,16,8}
to remove the "__". The other changes are:
* Create types.h
* Include types.h in perf.h, util/string.h and util/symbol.h
* Add types.h to the LIB_H definition in Makefile
* Added (u64) casts in process_overflow_event() and print_sym_table()
to kill two remaining warnings.
Signed-off-by: Paul Mackerras <paulus@samba.org>
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: benh@kernel.crashing.org
LKML-Reference: <19003.33494.495844.956580@cargo.ozlabs.ibm.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-06-19 12:21:42 +00:00
|
|
|
const u64 ip = sym->start;
|
2009-05-28 17:55:04 +00:00
|
|
|
struct symbol *s;
|
|
|
|
|
|
|
|
while (*p != NULL) {
|
|
|
|
parent = *p;
|
|
|
|
s = rb_entry(parent, struct symbol, rb_node);
|
|
|
|
if (ip < s->start)
|
|
|
|
p = &(*p)->rb_left;
|
|
|
|
else
|
|
|
|
p = &(*p)->rb_right;
|
|
|
|
}
|
|
|
|
rb_link_node(&sym->rb_node, parent, p);
|
2011-03-31 13:56:28 +00:00
|
|
|
rb_insert_color(&sym->rb_node, symbols);
|
2009-05-28 17:55:04 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
static struct symbol *symbols__find(struct rb_root *symbols, u64 ip)
|
2009-05-28 17:55:04 +00:00
|
|
|
{
|
|
|
|
struct rb_node *n;
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
if (symbols == NULL)
|
2009-05-28 17:55:04 +00:00
|
|
|
return NULL;
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
n = symbols->rb_node;
|
2009-05-28 17:55:04 +00:00
|
|
|
|
|
|
|
while (n) {
|
|
|
|
struct symbol *s = rb_entry(n, struct symbol, rb_node);
|
|
|
|
|
|
|
|
if (ip < s->start)
|
|
|
|
n = n->rb_left;
|
2014-10-14 20:19:44 +00:00
|
|
|
else if (ip >= s->end)
|
2009-05-28 17:55:04 +00:00
|
|
|
n = n->rb_right;
|
|
|
|
else
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-08-07 11:38:51 +00:00
|
|
|
static struct symbol *symbols__first(struct rb_root *symbols)
|
|
|
|
{
|
|
|
|
struct rb_node *n = rb_first(symbols);
|
|
|
|
|
|
|
|
if (n)
|
|
|
|
return rb_entry(n, struct symbol, rb_node);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-07-14 10:02:50 +00:00
|
|
|
static struct symbol *symbols__next(struct symbol *sym)
|
|
|
|
{
|
|
|
|
struct rb_node *n = rb_next(&sym->rb_node);
|
|
|
|
|
|
|
|
if (n)
|
|
|
|
return rb_entry(n, struct symbol, rb_node);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-11 20:50:22 +00:00
|
|
|
struct symbol_name_rb_node {
|
|
|
|
struct rb_node rb_node;
|
|
|
|
struct symbol sym;
|
|
|
|
};
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
static void symbols__insert_by_name(struct rb_root *symbols, struct symbol *sym)
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-11 20:50:22 +00:00
|
|
|
{
|
2011-03-31 13:56:28 +00:00
|
|
|
struct rb_node **p = &symbols->rb_node;
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-11 20:50:22 +00:00
|
|
|
struct rb_node *parent = NULL;
|
2010-11-23 16:38:18 +00:00
|
|
|
struct symbol_name_rb_node *symn, *s;
|
|
|
|
|
|
|
|
symn = container_of(sym, struct symbol_name_rb_node, sym);
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-11 20:50:22 +00:00
|
|
|
|
|
|
|
while (*p != NULL) {
|
|
|
|
parent = *p;
|
|
|
|
s = rb_entry(parent, struct symbol_name_rb_node, rb_node);
|
|
|
|
if (strcmp(sym->name, s->sym.name) < 0)
|
|
|
|
p = &(*p)->rb_left;
|
|
|
|
else
|
|
|
|
p = &(*p)->rb_right;
|
|
|
|
}
|
|
|
|
rb_link_node(&symn->rb_node, parent, p);
|
2011-03-31 13:56:28 +00:00
|
|
|
rb_insert_color(&symn->rb_node, symbols);
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-11 20:50:22 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
static void symbols__sort_by_name(struct rb_root *symbols,
|
|
|
|
struct rb_root *source)
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-11 20:50:22 +00:00
|
|
|
{
|
|
|
|
struct rb_node *nd;
|
|
|
|
|
|
|
|
for (nd = rb_first(source); nd; nd = rb_next(nd)) {
|
|
|
|
struct symbol *pos = rb_entry(nd, struct symbol, rb_node);
|
2011-03-31 13:56:28 +00:00
|
|
|
symbols__insert_by_name(symbols, pos);
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-11 20:50:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
static struct symbol *symbols__find_by_name(struct rb_root *symbols,
|
|
|
|
const char *name)
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-11 20:50:22 +00:00
|
|
|
{
|
|
|
|
struct rb_node *n;
|
2015-05-26 14:41:37 +00:00
|
|
|
struct symbol_name_rb_node *s = NULL;
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-11 20:50:22 +00:00
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
if (symbols == NULL)
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-11 20:50:22 +00:00
|
|
|
return NULL;
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
n = symbols->rb_node;
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-11 20:50:22 +00:00
|
|
|
|
|
|
|
while (n) {
|
|
|
|
int cmp;
|
|
|
|
|
|
|
|
s = rb_entry(n, struct symbol_name_rb_node, rb_node);
|
2015-04-28 12:05:37 +00:00
|
|
|
cmp = arch__compare_symbol_names(name, s->sym.name);
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-11 20:50:22 +00:00
|
|
|
|
|
|
|
if (cmp < 0)
|
|
|
|
n = n->rb_left;
|
|
|
|
else if (cmp > 0)
|
|
|
|
n = n->rb_right;
|
|
|
|
else
|
2015-01-16 18:31:28 +00:00
|
|
|
break;
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-11 20:50:22 +00:00
|
|
|
}
|
|
|
|
|
2015-01-16 18:31:28 +00:00
|
|
|
if (n == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* return first symbol that has same name (if any) */
|
|
|
|
for (n = rb_prev(n); n; n = rb_prev(n)) {
|
|
|
|
struct symbol_name_rb_node *tmp;
|
|
|
|
|
|
|
|
tmp = rb_entry(n, struct symbol_name_rb_node, rb_node);
|
2015-04-28 12:05:37 +00:00
|
|
|
if (arch__compare_symbol_names(tmp->sym.name, s->sym.name))
|
2015-01-16 18:31:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
s = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return &s->sym;
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-11 20:50:22 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
struct symbol *dso__find_symbol(struct dso *dso,
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-11 20:50:22 +00:00
|
|
|
enum map_type type, u64 addr)
|
2009-11-24 15:01:52 +00:00
|
|
|
{
|
2011-03-31 13:56:28 +00:00
|
|
|
return symbols__find(&dso->symbols[type], addr);
|
2009-11-24 15:01:52 +00:00
|
|
|
}
|
|
|
|
|
2014-07-14 10:02:50 +00:00
|
|
|
struct symbol *dso__first_symbol(struct dso *dso, enum map_type type)
|
2013-08-07 11:38:51 +00:00
|
|
|
{
|
|
|
|
return symbols__first(&dso->symbols[type]);
|
2014-07-14 10:02:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct symbol *dso__next_symbol(struct symbol *sym)
|
|
|
|
{
|
|
|
|
return symbols__next(sym);
|
2013-08-07 11:38:51 +00:00
|
|
|
}
|
|
|
|
|
2015-01-16 18:39:53 +00:00
|
|
|
struct symbol *symbol__next_by_name(struct symbol *sym)
|
|
|
|
{
|
|
|
|
struct symbol_name_rb_node *s = container_of(sym, struct symbol_name_rb_node, sym);
|
|
|
|
struct rb_node *n = rb_next(&s->rb_node);
|
|
|
|
|
|
|
|
return n ? &rb_entry(n, struct symbol_name_rb_node, rb_node)->sym : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Teturns first symbol that matched with @name.
|
|
|
|
*/
|
2011-03-31 13:56:28 +00:00
|
|
|
struct symbol *dso__find_symbol_by_name(struct dso *dso, enum map_type type,
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-11 20:50:22 +00:00
|
|
|
const char *name)
|
|
|
|
{
|
2011-03-31 13:56:28 +00:00
|
|
|
return symbols__find_by_name(&dso->symbol_names[type], name);
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-11 20:50:22 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
void dso__sort_by_name(struct dso *dso, enum map_type type)
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-11 20:50:22 +00:00
|
|
|
{
|
2011-03-31 13:56:28 +00:00
|
|
|
dso__set_sorted_by_name(dso, type);
|
|
|
|
return symbols__sort_by_name(&dso->symbol_names[type],
|
|
|
|
&dso->symbols[type]);
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-11 20:50:22 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
size_t dso__fprintf_symbols_by_name(struct dso *dso,
|
|
|
|
enum map_type type, FILE *fp)
|
2010-08-25 13:43:29 +00:00
|
|
|
{
|
|
|
|
size_t ret = 0;
|
|
|
|
struct rb_node *nd;
|
|
|
|
struct symbol_name_rb_node *pos;
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
for (nd = rb_first(&dso->symbol_names[type]); nd; nd = rb_next(nd)) {
|
2010-08-25 13:43:29 +00:00
|
|
|
pos = rb_entry(nd, struct symbol_name_rb_node, rb_node);
|
|
|
|
fprintf(fp, "%s\n", pos->sym.name);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-10-08 08:45:48 +00:00
|
|
|
int modules__parse(const char *filename, void *arg,
|
|
|
|
int (*process_module)(void *arg, const char *name,
|
|
|
|
u64 start))
|
|
|
|
{
|
|
|
|
char *line = NULL;
|
|
|
|
size_t n;
|
|
|
|
FILE *file;
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
file = fopen(filename, "r");
|
|
|
|
if (file == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
char name[PATH_MAX];
|
|
|
|
u64 start;
|
|
|
|
char *sep;
|
|
|
|
ssize_t line_len;
|
|
|
|
|
|
|
|
line_len = getline(&line, &n, file);
|
|
|
|
if (line_len < 0) {
|
|
|
|
if (feof(file))
|
|
|
|
break;
|
|
|
|
err = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!line) {
|
|
|
|
err = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
line[--line_len] = '\0'; /* \n */
|
|
|
|
|
|
|
|
sep = strrchr(line, 'x');
|
|
|
|
if (sep == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
hex2u64(sep + 1, &start);
|
|
|
|
|
|
|
|
sep = strchr(line, ' ');
|
|
|
|
if (sep == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
*sep = '\0';
|
|
|
|
|
|
|
|
scnprintf(name, sizeof(name), "[%s]", line);
|
|
|
|
|
|
|
|
err = process_module(arg, name, start);
|
|
|
|
if (err)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
free(line);
|
|
|
|
fclose(file);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2010-01-04 18:19:26 +00:00
|
|
|
struct process_kallsyms_args {
|
|
|
|
struct map *map;
|
|
|
|
struct dso *dso;
|
|
|
|
};
|
|
|
|
|
2014-08-08 21:00:39 +00:00
|
|
|
/*
|
|
|
|
* These are symbols in the kernel image, so make sure that
|
|
|
|
* sym is from a kernel DSO.
|
|
|
|
*/
|
2013-11-18 20:32:45 +00:00
|
|
|
bool symbol__is_idle(struct symbol *sym)
|
|
|
|
{
|
|
|
|
const char * const idle_symbols[] = {
|
|
|
|
"cpu_idle",
|
2014-08-08 21:02:41 +00:00
|
|
|
"cpu_startup_entry",
|
2013-11-18 20:32:45 +00:00
|
|
|
"intel_idle",
|
|
|
|
"default_idle",
|
|
|
|
"native_safe_halt",
|
|
|
|
"enter_idle",
|
|
|
|
"exit_idle",
|
|
|
|
"mwait_idle",
|
|
|
|
"mwait_idle_with_hints",
|
|
|
|
"poll_idle",
|
|
|
|
"ppc64_runlatch_off",
|
|
|
|
"pseries_dedicated_idle_sleep",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!sym)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (i = 0; idle_symbols[i]; i++) {
|
|
|
|
if (!strcmp(idle_symbols[i], sym->name))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-01-04 18:19:26 +00:00
|
|
|
static int map__process_kallsym_symbol(void *arg, const char *name,
|
2012-08-10 22:22:48 +00:00
|
|
|
char type, u64 start)
|
2010-01-04 18:19:26 +00:00
|
|
|
{
|
|
|
|
struct symbol *sym;
|
|
|
|
struct process_kallsyms_args *a = arg;
|
|
|
|
struct rb_root *root = &a->dso->symbols[a->map->type];
|
|
|
|
|
|
|
|
if (!symbol_type__is_a(type, a->map->type))
|
|
|
|
return 0;
|
|
|
|
|
2012-08-10 22:22:48 +00:00
|
|
|
/*
|
|
|
|
* module symbols are not sorted so we add all
|
|
|
|
* symbols, setting length to 0, and rely on
|
|
|
|
* symbols__fixup_end() to fix it up.
|
|
|
|
*/
|
|
|
|
sym = symbol__new(start, 0, kallsyms2elf_type(type), name);
|
2010-01-04 18:19:26 +00:00
|
|
|
if (sym == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
/*
|
|
|
|
* We will pass the symbols to the filter later, in
|
|
|
|
* map__split_kallsyms, when we have split the maps per module
|
|
|
|
*/
|
|
|
|
symbols__insert(root, sym);
|
2010-04-19 05:32:50 +00:00
|
|
|
|
2010-01-04 18:19:26 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Loads the function entries in /proc/kallsyms into kernel_map->dso,
|
|
|
|
* so that we can in the next step set the symbol ->end address and then
|
|
|
|
* call kernel_maps__split_kallsyms.
|
|
|
|
*/
|
2011-03-31 13:56:28 +00:00
|
|
|
static int dso__load_all_kallsyms(struct dso *dso, const char *filename,
|
2010-01-14 20:30:06 +00:00
|
|
|
struct map *map)
|
2010-01-04 18:19:26 +00:00
|
|
|
{
|
2011-03-31 13:56:28 +00:00
|
|
|
struct process_kallsyms_args args = { .map = map, .dso = dso, };
|
2010-01-14 20:30:06 +00:00
|
|
|
return kallsyms__parse(filename, &args, map__process_kallsym_symbol);
|
2010-01-04 18:19:26 +00:00
|
|
|
}
|
|
|
|
|
2013-08-07 11:38:51 +00:00
|
|
|
static int dso__split_kallsyms_for_kcore(struct dso *dso, struct map *map,
|
|
|
|
symbol_filter_t filter)
|
|
|
|
{
|
2015-04-07 08:22:45 +00:00
|
|
|
struct map_groups *kmaps = map__kmaps(map);
|
2013-08-07 11:38:51 +00:00
|
|
|
struct map *curr_map;
|
|
|
|
struct symbol *pos;
|
|
|
|
int count = 0, moved = 0;
|
|
|
|
struct rb_root *root = &dso->symbols[map->type];
|
|
|
|
struct rb_node *next = rb_first(root);
|
|
|
|
|
2015-04-07 08:22:45 +00:00
|
|
|
if (!kmaps)
|
|
|
|
return -1;
|
|
|
|
|
2013-08-07 11:38:51 +00:00
|
|
|
while (next) {
|
|
|
|
char *module;
|
|
|
|
|
|
|
|
pos = rb_entry(next, struct symbol, rb_node);
|
|
|
|
next = rb_next(&pos->rb_node);
|
|
|
|
|
|
|
|
module = strchr(pos->name, '\t');
|
|
|
|
if (module)
|
|
|
|
*module = '\0';
|
|
|
|
|
|
|
|
curr_map = map_groups__find(kmaps, map->type, pos->start);
|
|
|
|
|
|
|
|
if (!curr_map || (filter && filter(curr_map, pos))) {
|
2015-05-25 18:30:09 +00:00
|
|
|
rb_erase_init(&pos->rb_node, root);
|
2013-08-07 11:38:51 +00:00
|
|
|
symbol__delete(pos);
|
|
|
|
} else {
|
|
|
|
pos->start -= curr_map->start - curr_map->pgoff;
|
|
|
|
if (pos->end)
|
|
|
|
pos->end -= curr_map->start - curr_map->pgoff;
|
|
|
|
if (curr_map != map) {
|
2015-05-25 18:30:09 +00:00
|
|
|
rb_erase_init(&pos->rb_node, root);
|
2013-08-07 11:38:51 +00:00
|
|
|
symbols__insert(
|
|
|
|
&curr_map->dso->symbols[curr_map->type],
|
|
|
|
pos);
|
|
|
|
++moved;
|
|
|
|
} else {
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Symbols have been adjusted */
|
|
|
|
dso->adjust_symbols = 1;
|
|
|
|
|
|
|
|
return count + moved;
|
|
|
|
}
|
|
|
|
|
2009-10-07 16:48:56 +00:00
|
|
|
/*
|
|
|
|
* Split the symbols into maps, making sure there are no overlaps, i.e. the
|
|
|
|
* kernel range is broken in several maps, named [kernel].N, as we don't have
|
|
|
|
* the original ELF section names vmlinux have.
|
|
|
|
*/
|
2014-01-29 14:14:43 +00:00
|
|
|
static int dso__split_kallsyms(struct dso *dso, struct map *map, u64 delta,
|
2010-02-03 18:52:00 +00:00
|
|
|
symbol_filter_t filter)
|
2009-10-07 16:48:56 +00:00
|
|
|
{
|
2015-04-07 08:22:45 +00:00
|
|
|
struct map_groups *kmaps = map__kmaps(map);
|
|
|
|
struct machine *machine;
|
2009-11-27 18:29:18 +00:00
|
|
|
struct map *curr_map = map;
|
2009-10-07 16:48:56 +00:00
|
|
|
struct symbol *pos;
|
2014-12-17 20:24:45 +00:00
|
|
|
int count = 0, moved = 0;
|
2011-03-31 13:56:28 +00:00
|
|
|
struct rb_root *root = &dso->symbols[map->type];
|
2009-11-27 18:29:18 +00:00
|
|
|
struct rb_node *next = rb_first(root);
|
2009-10-07 16:48:56 +00:00
|
|
|
int kernel_range = 0;
|
|
|
|
|
2015-04-07 08:22:45 +00:00
|
|
|
if (!kmaps)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
machine = kmaps->machine;
|
|
|
|
|
2009-10-07 16:48:56 +00:00
|
|
|
while (next) {
|
|
|
|
char *module;
|
|
|
|
|
|
|
|
pos = rb_entry(next, struct symbol, rb_node);
|
|
|
|
next = rb_next(&pos->rb_node);
|
|
|
|
|
|
|
|
module = strchr(pos->name, '\t');
|
|
|
|
if (module) {
|
2009-12-15 22:04:39 +00:00
|
|
|
if (!symbol_conf.use_modules)
|
2009-11-27 18:29:21 +00:00
|
|
|
goto discard_symbol;
|
|
|
|
|
2009-10-07 16:48:56 +00:00
|
|
|
*module++ = '\0';
|
|
|
|
|
perf tools: Encode kernel module mappings in perf.data
We were always looking at the running machine /proc/modules,
even when processing a perf.data file, which only makes sense
when we're doing 'perf record' and 'perf report' on the same
machine, and in close sucession, or if we don't use modules at
all, right Peter? ;-)
Now, at 'perf record' time we read /proc/modules, find the long
path for modules, and put them as PERF_MMAP events, just like we
did to encode the reloc reference symbol for vmlinux. Talking
about that now it is encoded in .pgoff, so that we can use
.{start,len} to store the address boundaries for the kernel so
that when we reconstruct the kmaps tree we can do lookups right
away, without having to fixup the end of the kernel maps like we
did in the past (and now only in perf record).
One more step in the 'perf archive' direction when we'll finally
be able to collect data in one machine and analyse in another.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1263396139-4798-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-13 15:22:17 +00:00
|
|
|
if (strcmp(curr_map->dso->short_name, module)) {
|
2010-04-19 05:32:50 +00:00
|
|
|
if (curr_map != map &&
|
2011-03-31 13:56:28 +00:00
|
|
|
dso->kernel == DSO_TYPE_GUEST_KERNEL &&
|
2010-04-28 00:17:50 +00:00
|
|
|
machine__is_default_guest(machine)) {
|
2010-04-19 05:32:50 +00:00
|
|
|
/*
|
|
|
|
* We assume all symbols of a module are
|
|
|
|
* continuous in * kallsyms, so curr_map
|
|
|
|
* points to a module and all its
|
|
|
|
* symbols are in its kmap. Mark it as
|
|
|
|
* loaded.
|
|
|
|
*/
|
|
|
|
dso__set_loaded(curr_map->dso,
|
|
|
|
curr_map->type);
|
|
|
|
}
|
|
|
|
|
|
|
|
curr_map = map_groups__find_by_name(kmaps,
|
|
|
|
map->type, module);
|
2009-11-27 18:29:18 +00:00
|
|
|
if (curr_map == NULL) {
|
2010-05-17 20:57:59 +00:00
|
|
|
pr_debug("%s/proc/{kallsyms,modules} "
|
perf tools: Encode kernel module mappings in perf.data
We were always looking at the running machine /proc/modules,
even when processing a perf.data file, which only makes sense
when we're doing 'perf record' and 'perf report' on the same
machine, and in close sucession, or if we don't use modules at
all, right Peter? ;-)
Now, at 'perf record' time we read /proc/modules, find the long
path for modules, and put them as PERF_MMAP events, just like we
did to encode the reloc reference symbol for vmlinux. Talking
about that now it is encoded in .pgoff, so that we can use
.{start,len} to store the address boundaries for the kernel so
that when we reconstruct the kmaps tree we can do lookups right
away, without having to fixup the end of the kernel maps like we
did in the past (and now only in perf record).
One more step in the 'perf archive' direction when we'll finally
be able to collect data in one machine and analyse in another.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1263396139-4798-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-13 15:22:17 +00:00
|
|
|
"inconsistency while looking "
|
2010-04-19 05:32:50 +00:00
|
|
|
"for \"%s\" module!\n",
|
2010-04-28 00:17:50 +00:00
|
|
|
machine->root_dir, module);
|
2010-04-19 05:32:50 +00:00
|
|
|
curr_map = map;
|
|
|
|
goto discard_symbol;
|
2009-10-05 17:26:17 +00:00
|
|
|
}
|
perf tools: Encode kernel module mappings in perf.data
We were always looking at the running machine /proc/modules,
even when processing a perf.data file, which only makes sense
when we're doing 'perf record' and 'perf report' on the same
machine, and in close sucession, or if we don't use modules at
all, right Peter? ;-)
Now, at 'perf record' time we read /proc/modules, find the long
path for modules, and put them as PERF_MMAP events, just like we
did to encode the reloc reference symbol for vmlinux. Talking
about that now it is encoded in .pgoff, so that we can use
.{start,len} to store the address boundaries for the kernel so
that when we reconstruct the kmaps tree we can do lookups right
away, without having to fixup the end of the kernel maps like we
did in the past (and now only in perf record).
One more step in the 'perf archive' direction when we'll finally
be able to collect data in one machine and analyse in another.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1263396139-4798-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-13 15:22:17 +00:00
|
|
|
|
2010-04-19 05:32:50 +00:00
|
|
|
if (curr_map->dso->loaded &&
|
2010-04-28 00:17:50 +00:00
|
|
|
!machine__is_default_guest(machine))
|
perf tools: Encode kernel module mappings in perf.data
We were always looking at the running machine /proc/modules,
even when processing a perf.data file, which only makes sense
when we're doing 'perf record' and 'perf report' on the same
machine, and in close sucession, or if we don't use modules at
all, right Peter? ;-)
Now, at 'perf record' time we read /proc/modules, find the long
path for modules, and put them as PERF_MMAP events, just like we
did to encode the reloc reference symbol for vmlinux. Talking
about that now it is encoded in .pgoff, so that we can use
.{start,len} to store the address boundaries for the kernel so
that when we reconstruct the kmaps tree we can do lookups right
away, without having to fixup the end of the kernel maps like we
did in the past (and now only in perf record).
One more step in the 'perf archive' direction when we'll finally
be able to collect data in one machine and analyse in another.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1263396139-4798-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-13 15:22:17 +00:00
|
|
|
goto discard_symbol;
|
2009-10-05 17:26:17 +00:00
|
|
|
}
|
2009-10-07 16:48:56 +00:00
|
|
|
/*
|
|
|
|
* So that we look just like we get from .ko files,
|
|
|
|
* i.e. not prelinked, relative to map->start.
|
|
|
|
*/
|
2009-11-27 18:29:18 +00:00
|
|
|
pos->start = curr_map->map_ip(curr_map, pos->start);
|
|
|
|
pos->end = curr_map->map_ip(curr_map, pos->end);
|
|
|
|
} else if (curr_map != map) {
|
2009-10-07 16:48:56 +00:00
|
|
|
char dso_name[PATH_MAX];
|
2011-03-31 13:56:28 +00:00
|
|
|
struct dso *ndso;
|
2009-10-07 16:48:56 +00:00
|
|
|
|
2014-01-29 14:14:43 +00:00
|
|
|
if (delta) {
|
|
|
|
/* Kernel was relocated at boot time */
|
|
|
|
pos->start -= delta;
|
|
|
|
pos->end -= delta;
|
|
|
|
}
|
|
|
|
|
2010-11-29 14:44:15 +00:00
|
|
|
if (count == 0) {
|
|
|
|
curr_map = map;
|
|
|
|
goto filter_symbol;
|
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
if (dso->kernel == DSO_TYPE_GUEST_KERNEL)
|
2010-04-19 05:32:50 +00:00
|
|
|
snprintf(dso_name, sizeof(dso_name),
|
|
|
|
"[guest.kernel].%d",
|
|
|
|
kernel_range++);
|
|
|
|
else
|
|
|
|
snprintf(dso_name, sizeof(dso_name),
|
|
|
|
"[kernel].%d",
|
|
|
|
kernel_range++);
|
2009-10-07 16:48:56 +00:00
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
ndso = dso__new(dso_name);
|
|
|
|
if (ndso == NULL)
|
2009-10-07 16:48:56 +00:00
|
|
|
return -1;
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
ndso->kernel = dso->kernel;
|
2010-04-19 05:32:50 +00:00
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
curr_map = map__new2(pos->start, ndso, map->type);
|
2010-02-25 03:00:51 +00:00
|
|
|
if (curr_map == NULL) {
|
2011-03-31 13:56:28 +00:00
|
|
|
dso__delete(ndso);
|
2009-10-07 16:48:56 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-05-28 17:55:04 +00:00
|
|
|
|
2009-11-27 18:29:18 +00:00
|
|
|
curr_map->map_ip = curr_map->unmap_ip = identity__map_ip;
|
2010-02-03 18:52:00 +00:00
|
|
|
map_groups__insert(kmaps, curr_map);
|
2009-10-07 16:48:56 +00:00
|
|
|
++kernel_range;
|
2014-01-29 14:14:43 +00:00
|
|
|
} else if (delta) {
|
|
|
|
/* Kernel was relocated at boot time */
|
|
|
|
pos->start -= delta;
|
|
|
|
pos->end -= delta;
|
2009-10-07 16:48:56 +00:00
|
|
|
}
|
2010-11-29 14:44:15 +00:00
|
|
|
filter_symbol:
|
2009-11-27 18:29:18 +00:00
|
|
|
if (filter && filter(curr_map, pos)) {
|
2009-11-27 18:29:21 +00:00
|
|
|
discard_symbol: rb_erase(&pos->rb_node, root);
|
2009-10-30 18:28:24 +00:00
|
|
|
symbol__delete(pos);
|
2009-10-07 16:48:56 +00:00
|
|
|
} else {
|
2009-11-27 18:29:18 +00:00
|
|
|
if (curr_map != map) {
|
|
|
|
rb_erase(&pos->rb_node, root);
|
|
|
|
symbols__insert(&curr_map->dso->symbols[curr_map->type], pos);
|
2010-11-29 14:44:15 +00:00
|
|
|
++moved;
|
|
|
|
} else
|
|
|
|
++count;
|
2009-07-02 06:05:58 +00:00
|
|
|
}
|
2009-05-28 17:55:04 +00:00
|
|
|
}
|
|
|
|
|
2010-04-19 05:32:50 +00:00
|
|
|
if (curr_map != map &&
|
2011-03-31 13:56:28 +00:00
|
|
|
dso->kernel == DSO_TYPE_GUEST_KERNEL &&
|
2010-04-28 00:17:50 +00:00
|
|
|
machine__is_default_guest(kmaps->machine)) {
|
2010-04-19 05:32:50 +00:00
|
|
|
dso__set_loaded(curr_map->dso, curr_map->type);
|
|
|
|
}
|
|
|
|
|
2010-11-29 14:44:15 +00:00
|
|
|
return count + moved;
|
2009-10-07 16:48:56 +00:00
|
|
|
}
|
2009-05-28 17:55:04 +00:00
|
|
|
|
2012-12-07 20:39:39 +00:00
|
|
|
bool symbol__restricted_filename(const char *filename,
|
|
|
|
const char *restricted_filename)
|
perf symbols: Handle /proc/sys/kernel/kptr_restrict
Perf uses /proc/modules to figure out where kernel modules are loaded.
With the advent of kptr_restrict, non root users get zeroes for all module
start addresses.
So check if kptr_restrict is non zero and don't generate the syntethic
PERF_RECORD_MMAP events for them.
Warn the user about it in perf record and in perf report.
In perf report the reference relocation symbol being zero means that
kptr_restrict was set, thus /proc/kallsyms has only zeroed addresses, so don't
use it to fixup symbol addresses when using a valid kallsyms (in the buildid
cache) or vmlinux (in the vmlinux path) build-id located automatically or
specified by the user.
Provide an explanation about it in 'perf report' if kernel samples were taken,
checking if a suitable vmlinux or kallsyms was found/specified.
Restricted /proc/kallsyms don't go to the buildid cache anymore.
Example:
[acme@emilia ~]$ perf record -F 100000 sleep 1
WARNING: Kernel address maps (/proc/{kallsyms,modules}) are restricted, check
/proc/sys/kernel/kptr_restrict.
Samples in kernel functions may not be resolved if a suitable vmlinux file is
not found in the buildid cache or in the vmlinux path.
Samples in kernel modules won't be resolved at all.
If some relocation was applied (e.g. kexec) symbols may be misresolved even
with a suitable vmlinux or kallsyms file.
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.005 MB perf.data (~231 samples) ]
[acme@emilia ~]$
[acme@emilia ~]$ perf report --stdio
Kernel address maps (/proc/{kallsyms,modules}) were restricted,
check /proc/sys/kernel/kptr_restrict before running 'perf record'.
If some relocation was applied (e.g. kexec) symbols may be misresolved.
Samples in kernel modules can't be resolved as well.
# Events: 13 cycles
#
# Overhead Command Shared Object Symbol
# ........ ....... ................. .....................
#
20.24% sleep [kernel.kallsyms] [k] page_fault
20.04% sleep [kernel.kallsyms] [k] filemap_fault
19.78% sleep [kernel.kallsyms] [k] __lru_cache_add
19.69% sleep ld-2.12.so [.] memcpy
14.71% sleep [kernel.kallsyms] [k] dput
4.70% sleep [kernel.kallsyms] [k] flush_signal_handlers
0.73% sleep [kernel.kallsyms] [k] perf_event_comm
0.11% sleep [kernel.kallsyms] [k] native_write_msr_safe
#
# (For a higher level overview, try: perf report --sort comm,dso)
#
[acme@emilia ~]$
This is because it found a suitable vmlinux (build-id checked) in
/lib/modules/2.6.39-rc7+/build/vmlinux (use -v in perf report to see the long
file name).
If we remove that file from the vmlinux path:
[root@emilia ~]# mv /lib/modules/2.6.39-rc7+/build/vmlinux \
/lib/modules/2.6.39-rc7+/build/vmlinux.OFF
[acme@emilia ~]$ perf report --stdio
[kernel.kallsyms] with build id 57298cdbe0131f6871667ec0eaab4804dcf6f562
not found, continuing without symbols
Kernel address maps (/proc/{kallsyms,modules}) were restricted, check
/proc/sys/kernel/kptr_restrict before running 'perf record'.
As no suitable kallsyms nor vmlinux was found, kernel samples can't be
resolved.
Samples in kernel modules can't be resolved as well.
# Events: 13 cycles
#
# Overhead Command Shared Object Symbol
# ........ ....... ................. ......
#
80.31% sleep [kernel.kallsyms] [k] 0xffffffff8103425a
19.69% sleep ld-2.12.so [.] memcpy
#
# (For a higher level overview, try: perf report --sort comm,dso)
#
[acme@emilia ~]$
Reported-by: Stephane Eranian <eranian@google.com>
Suggested-by: David Miller <davem@davemloft.net>
Cc: Dave Jones <davej@redhat.com>
Cc: David Miller <davem@davemloft.net>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Kees Cook <kees.cook@canonical.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
Link: http://lkml.kernel.org/n/tip-mt512joaxxbhhp1odop04yit@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2011-05-26 12:53:51 +00:00
|
|
|
{
|
|
|
|
bool restricted = false;
|
|
|
|
|
|
|
|
if (symbol_conf.kptr_restrict) {
|
|
|
|
char *r = realpath(filename, NULL);
|
|
|
|
|
|
|
|
if (r != NULL) {
|
|
|
|
restricted = strcmp(r, restricted_filename) == 0;
|
|
|
|
free(r);
|
|
|
|
return restricted;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return restricted;
|
|
|
|
}
|
|
|
|
|
2013-10-09 12:01:11 +00:00
|
|
|
struct module_info {
|
|
|
|
struct rb_node rb_node;
|
|
|
|
char *name;
|
|
|
|
u64 start;
|
2013-08-07 11:38:51 +00:00
|
|
|
};
|
|
|
|
|
2013-10-09 12:01:11 +00:00
|
|
|
static void add_module(struct module_info *mi, struct rb_root *modules)
|
2013-08-07 11:38:51 +00:00
|
|
|
{
|
2013-10-09 12:01:11 +00:00
|
|
|
struct rb_node **p = &modules->rb_node;
|
|
|
|
struct rb_node *parent = NULL;
|
|
|
|
struct module_info *m;
|
2013-08-07 11:38:51 +00:00
|
|
|
|
2013-10-09 12:01:11 +00:00
|
|
|
while (*p != NULL) {
|
|
|
|
parent = *p;
|
|
|
|
m = rb_entry(parent, struct module_info, rb_node);
|
|
|
|
if (strcmp(mi->name, m->name) < 0)
|
|
|
|
p = &(*p)->rb_left;
|
|
|
|
else
|
|
|
|
p = &(*p)->rb_right;
|
|
|
|
}
|
|
|
|
rb_link_node(&mi->rb_node, parent, p);
|
|
|
|
rb_insert_color(&mi->rb_node, modules);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void delete_modules(struct rb_root *modules)
|
|
|
|
{
|
|
|
|
struct module_info *mi;
|
|
|
|
struct rb_node *next = rb_first(modules);
|
|
|
|
|
|
|
|
while (next) {
|
|
|
|
mi = rb_entry(next, struct module_info, rb_node);
|
|
|
|
next = rb_next(&mi->rb_node);
|
|
|
|
rb_erase(&mi->rb_node, modules);
|
2013-12-27 19:55:14 +00:00
|
|
|
zfree(&mi->name);
|
2013-10-09 12:01:11 +00:00
|
|
|
free(mi);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct module_info *find_module(const char *name,
|
|
|
|
struct rb_root *modules)
|
|
|
|
{
|
|
|
|
struct rb_node *n = modules->rb_node;
|
|
|
|
|
|
|
|
while (n) {
|
|
|
|
struct module_info *m;
|
|
|
|
int cmp;
|
|
|
|
|
|
|
|
m = rb_entry(n, struct module_info, rb_node);
|
|
|
|
cmp = strcmp(name, m->name);
|
|
|
|
if (cmp < 0)
|
|
|
|
n = n->rb_left;
|
|
|
|
else if (cmp > 0)
|
|
|
|
n = n->rb_right;
|
|
|
|
else
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __read_proc_modules(void *arg, const char *name, u64 start)
|
|
|
|
{
|
|
|
|
struct rb_root *modules = arg;
|
|
|
|
struct module_info *mi;
|
|
|
|
|
|
|
|
mi = zalloc(sizeof(struct module_info));
|
|
|
|
if (!mi)
|
2013-08-07 11:38:51 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2013-10-09 12:01:11 +00:00
|
|
|
mi->name = strdup(name);
|
|
|
|
mi->start = start;
|
2013-08-07 11:38:51 +00:00
|
|
|
|
2013-10-09 12:01:11 +00:00
|
|
|
if (!mi->name) {
|
|
|
|
free(mi);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
add_module(mi, modules);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int read_proc_modules(const char *filename, struct rb_root *modules)
|
|
|
|
{
|
|
|
|
if (symbol__restricted_filename(filename, "/proc/modules"))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (modules__parse(filename, modules, __read_proc_modules)) {
|
|
|
|
delete_modules(modules);
|
|
|
|
return -1;
|
|
|
|
}
|
2013-08-07 11:38:51 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-10-14 13:57:29 +00:00
|
|
|
int compare_proc_modules(const char *from, const char *to)
|
|
|
|
{
|
|
|
|
struct rb_root from_modules = RB_ROOT;
|
|
|
|
struct rb_root to_modules = RB_ROOT;
|
|
|
|
struct rb_node *from_node, *to_node;
|
|
|
|
struct module_info *from_m, *to_m;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
if (read_proc_modules(from, &from_modules))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (read_proc_modules(to, &to_modules))
|
|
|
|
goto out_delete_from;
|
|
|
|
|
|
|
|
from_node = rb_first(&from_modules);
|
|
|
|
to_node = rb_first(&to_modules);
|
|
|
|
while (from_node) {
|
|
|
|
if (!to_node)
|
|
|
|
break;
|
|
|
|
|
|
|
|
from_m = rb_entry(from_node, struct module_info, rb_node);
|
|
|
|
to_m = rb_entry(to_node, struct module_info, rb_node);
|
|
|
|
|
|
|
|
if (from_m->start != to_m->start ||
|
|
|
|
strcmp(from_m->name, to_m->name))
|
|
|
|
break;
|
|
|
|
|
|
|
|
from_node = rb_next(from_node);
|
|
|
|
to_node = rb_next(to_node);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!from_node && !to_node)
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
delete_modules(&to_modules);
|
|
|
|
out_delete_from:
|
|
|
|
delete_modules(&from_modules);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-10-09 12:01:11 +00:00
|
|
|
static int do_validate_kcore_modules(const char *filename, struct map *map,
|
|
|
|
struct map_groups *kmaps)
|
|
|
|
{
|
|
|
|
struct rb_root modules = RB_ROOT;
|
|
|
|
struct map *old_map;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = read_proc_modules(filename, &modules);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
old_map = map_groups__first(kmaps, map->type);
|
|
|
|
while (old_map) {
|
|
|
|
struct map *next = map_groups__next(old_map);
|
|
|
|
struct module_info *mi;
|
|
|
|
|
|
|
|
if (old_map == map || old_map->start == map->start) {
|
|
|
|
/* The kernel map */
|
|
|
|
old_map = next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Module must be in memory at the same address */
|
|
|
|
mi = find_module(old_map->dso->short_name, &modules);
|
|
|
|
if (!mi || mi->start != old_map->start) {
|
|
|
|
err = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
old_map = next;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
delete_modules(&modules);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2013-08-07 11:38:51 +00:00
|
|
|
/*
|
2013-10-09 12:01:11 +00:00
|
|
|
* If kallsyms is referenced by name then we look for filename in the same
|
2013-08-07 11:38:51 +00:00
|
|
|
* directory.
|
|
|
|
*/
|
2013-10-09 12:01:11 +00:00
|
|
|
static bool filename_from_kallsyms_filename(char *filename,
|
|
|
|
const char *base_name,
|
|
|
|
const char *kallsyms_filename)
|
2013-08-07 11:38:51 +00:00
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
|
2013-10-09 12:01:11 +00:00
|
|
|
strcpy(filename, kallsyms_filename);
|
|
|
|
name = strrchr(filename, '/');
|
2013-08-07 11:38:51 +00:00
|
|
|
if (!name)
|
|
|
|
return false;
|
|
|
|
|
2013-10-09 12:01:11 +00:00
|
|
|
name += 1;
|
|
|
|
|
|
|
|
if (!strcmp(name, "kallsyms")) {
|
|
|
|
strcpy(name, base_name);
|
2013-08-07 11:38:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-10-09 12:01:11 +00:00
|
|
|
static int validate_kcore_modules(const char *kallsyms_filename,
|
|
|
|
struct map *map)
|
|
|
|
{
|
2015-04-07 08:22:45 +00:00
|
|
|
struct map_groups *kmaps = map__kmaps(map);
|
2013-10-09 12:01:11 +00:00
|
|
|
char modules_filename[PATH_MAX];
|
|
|
|
|
2015-04-07 08:22:45 +00:00
|
|
|
if (!kmaps)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2013-10-09 12:01:11 +00:00
|
|
|
if (!filename_from_kallsyms_filename(modules_filename, "modules",
|
|
|
|
kallsyms_filename))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (do_validate_kcore_modules(modules_filename, map, kmaps))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-01-29 14:14:41 +00:00
|
|
|
static int validate_kcore_addresses(const char *kallsyms_filename,
|
|
|
|
struct map *map)
|
|
|
|
{
|
|
|
|
struct kmap *kmap = map__kmap(map);
|
|
|
|
|
2015-04-07 08:22:45 +00:00
|
|
|
if (!kmap)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2014-01-29 14:14:41 +00:00
|
|
|
if (kmap->ref_reloc_sym && kmap->ref_reloc_sym->name) {
|
|
|
|
u64 start;
|
|
|
|
|
|
|
|
start = kallsyms__get_function_start(kallsyms_filename,
|
|
|
|
kmap->ref_reloc_sym->name);
|
|
|
|
if (start != kmap->ref_reloc_sym->addr)
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return validate_kcore_modules(kallsyms_filename, map);
|
|
|
|
}
|
|
|
|
|
2013-10-09 12:01:11 +00:00
|
|
|
struct kcore_mapfn_data {
|
|
|
|
struct dso *dso;
|
|
|
|
enum map_type type;
|
|
|
|
struct list_head maps;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int kcore_mapfn(u64 start, u64 len, u64 pgoff, void *data)
|
|
|
|
{
|
|
|
|
struct kcore_mapfn_data *md = data;
|
|
|
|
struct map *map;
|
|
|
|
|
|
|
|
map = map__new2(start, md->dso, md->type);
|
|
|
|
if (map == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
map->end = map->start + len;
|
|
|
|
map->pgoff = pgoff;
|
|
|
|
|
|
|
|
list_add(&map->node, &md->maps);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-08-07 11:38:51 +00:00
|
|
|
static int dso__load_kcore(struct dso *dso, struct map *map,
|
|
|
|
const char *kallsyms_filename)
|
|
|
|
{
|
2015-04-07 08:22:45 +00:00
|
|
|
struct map_groups *kmaps = map__kmaps(map);
|
|
|
|
struct machine *machine;
|
2013-08-07 11:38:51 +00:00
|
|
|
struct kcore_mapfn_data md;
|
|
|
|
struct map *old_map, *new_map, *replacement_map = NULL;
|
|
|
|
bool is_64_bit;
|
|
|
|
int err, fd;
|
|
|
|
char kcore_filename[PATH_MAX];
|
|
|
|
struct symbol *sym;
|
|
|
|
|
2015-04-07 08:22:45 +00:00
|
|
|
if (!kmaps)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
machine = kmaps->machine;
|
|
|
|
|
2013-08-07 11:38:51 +00:00
|
|
|
/* This function requires that the map is the kernel map */
|
|
|
|
if (map != machine->vmlinux_maps[map->type])
|
|
|
|
return -EINVAL;
|
|
|
|
|
2013-10-09 12:01:11 +00:00
|
|
|
if (!filename_from_kallsyms_filename(kcore_filename, "kcore",
|
|
|
|
kallsyms_filename))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2014-01-29 14:14:41 +00:00
|
|
|
/* Modules and kernel must be present at their original addresses */
|
|
|
|
if (validate_kcore_addresses(kallsyms_filename, map))
|
2013-08-07 11:38:51 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
md.dso = dso;
|
|
|
|
md.type = map->type;
|
|
|
|
INIT_LIST_HEAD(&md.maps);
|
|
|
|
|
|
|
|
fd = open(kcore_filename, O_RDONLY);
|
|
|
|
if (fd < 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* Read new maps into temporary lists */
|
|
|
|
err = file__read_maps(fd, md.type == MAP__FUNCTION, kcore_mapfn, &md,
|
|
|
|
&is_64_bit);
|
|
|
|
if (err)
|
|
|
|
goto out_err;
|
2014-07-14 10:02:41 +00:00
|
|
|
dso->is_64_bit = is_64_bit;
|
2013-08-07 11:38:51 +00:00
|
|
|
|
|
|
|
if (list_empty(&md.maps)) {
|
|
|
|
err = -EINVAL;
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove old maps */
|
|
|
|
old_map = map_groups__first(kmaps, map->type);
|
|
|
|
while (old_map) {
|
|
|
|
struct map *next = map_groups__next(old_map);
|
|
|
|
|
|
|
|
if (old_map != map)
|
|
|
|
map_groups__remove(kmaps, old_map);
|
|
|
|
old_map = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find the kernel map using the first symbol */
|
|
|
|
sym = dso__first_symbol(dso, map->type);
|
|
|
|
list_for_each_entry(new_map, &md.maps, node) {
|
|
|
|
if (sym && sym->start >= new_map->start &&
|
|
|
|
sym->start < new_map->end) {
|
|
|
|
replacement_map = new_map;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!replacement_map)
|
|
|
|
replacement_map = list_entry(md.maps.next, struct map, node);
|
|
|
|
|
|
|
|
/* Add new maps */
|
|
|
|
while (!list_empty(&md.maps)) {
|
|
|
|
new_map = list_entry(md.maps.next, struct map, node);
|
2015-05-25 18:30:09 +00:00
|
|
|
list_del_init(&new_map->node);
|
2013-08-07 11:38:51 +00:00
|
|
|
if (new_map == replacement_map) {
|
|
|
|
map->start = new_map->start;
|
|
|
|
map->end = new_map->end;
|
|
|
|
map->pgoff = new_map->pgoff;
|
|
|
|
map->map_ip = new_map->map_ip;
|
|
|
|
map->unmap_ip = new_map->unmap_ip;
|
|
|
|
map__delete(new_map);
|
|
|
|
/* Ensure maps are correctly ordered */
|
|
|
|
map_groups__remove(kmaps, map);
|
|
|
|
map_groups__insert(kmaps, map);
|
|
|
|
} else {
|
|
|
|
map_groups__insert(kmaps, new_map);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the data type and long name so that kcore can be read via
|
|
|
|
* dso__data_read_addr().
|
|
|
|
*/
|
|
|
|
if (dso->kernel == DSO_TYPE_GUEST_KERNEL)
|
2013-12-17 19:14:07 +00:00
|
|
|
dso->binary_type = DSO_BINARY_TYPE__GUEST_KCORE;
|
2013-08-07 11:38:51 +00:00
|
|
|
else
|
2013-12-17 19:14:07 +00:00
|
|
|
dso->binary_type = DSO_BINARY_TYPE__KCORE;
|
2013-12-10 18:08:44 +00:00
|
|
|
dso__set_long_name(dso, strdup(kcore_filename), true);
|
2013-08-07 11:38:51 +00:00
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
if (map->type == MAP__FUNCTION)
|
|
|
|
pr_debug("Using %s for kernel object code\n", kcore_filename);
|
|
|
|
else
|
|
|
|
pr_debug("Using %s for kernel data\n", kcore_filename);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_err:
|
|
|
|
while (!list_empty(&md.maps)) {
|
|
|
|
map = list_entry(md.maps.next, struct map, node);
|
2015-05-25 18:30:09 +00:00
|
|
|
list_del_init(&map->node);
|
2013-08-07 11:38:51 +00:00
|
|
|
map__delete(map);
|
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2014-01-29 14:14:43 +00:00
|
|
|
/*
|
|
|
|
* If the kernel is relocated at boot time, kallsyms won't match. Compute the
|
|
|
|
* delta based on the relocation reference symbol.
|
|
|
|
*/
|
|
|
|
static int kallsyms__delta(struct map *map, const char *filename, u64 *delta)
|
|
|
|
{
|
|
|
|
struct kmap *kmap = map__kmap(map);
|
|
|
|
u64 addr;
|
|
|
|
|
2015-04-07 08:22:45 +00:00
|
|
|
if (!kmap)
|
|
|
|
return -1;
|
|
|
|
|
2014-01-29 14:14:43 +00:00
|
|
|
if (!kmap->ref_reloc_sym || !kmap->ref_reloc_sym->name)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
addr = kallsyms__get_function_start(filename,
|
|
|
|
kmap->ref_reloc_sym->name);
|
|
|
|
if (!addr)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
*delta = addr - kmap->ref_reloc_sym->addr;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
int dso__load_kallsyms(struct dso *dso, const char *filename,
|
2010-02-03 18:52:00 +00:00
|
|
|
struct map *map, symbol_filter_t filter)
|
2009-10-07 16:48:56 +00:00
|
|
|
{
|
2014-01-29 14:14:43 +00:00
|
|
|
u64 delta = 0;
|
|
|
|
|
perf symbols: Handle /proc/sys/kernel/kptr_restrict
Perf uses /proc/modules to figure out where kernel modules are loaded.
With the advent of kptr_restrict, non root users get zeroes for all module
start addresses.
So check if kptr_restrict is non zero and don't generate the syntethic
PERF_RECORD_MMAP events for them.
Warn the user about it in perf record and in perf report.
In perf report the reference relocation symbol being zero means that
kptr_restrict was set, thus /proc/kallsyms has only zeroed addresses, so don't
use it to fixup symbol addresses when using a valid kallsyms (in the buildid
cache) or vmlinux (in the vmlinux path) build-id located automatically or
specified by the user.
Provide an explanation about it in 'perf report' if kernel samples were taken,
checking if a suitable vmlinux or kallsyms was found/specified.
Restricted /proc/kallsyms don't go to the buildid cache anymore.
Example:
[acme@emilia ~]$ perf record -F 100000 sleep 1
WARNING: Kernel address maps (/proc/{kallsyms,modules}) are restricted, check
/proc/sys/kernel/kptr_restrict.
Samples in kernel functions may not be resolved if a suitable vmlinux file is
not found in the buildid cache or in the vmlinux path.
Samples in kernel modules won't be resolved at all.
If some relocation was applied (e.g. kexec) symbols may be misresolved even
with a suitable vmlinux or kallsyms file.
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.005 MB perf.data (~231 samples) ]
[acme@emilia ~]$
[acme@emilia ~]$ perf report --stdio
Kernel address maps (/proc/{kallsyms,modules}) were restricted,
check /proc/sys/kernel/kptr_restrict before running 'perf record'.
If some relocation was applied (e.g. kexec) symbols may be misresolved.
Samples in kernel modules can't be resolved as well.
# Events: 13 cycles
#
# Overhead Command Shared Object Symbol
# ........ ....... ................. .....................
#
20.24% sleep [kernel.kallsyms] [k] page_fault
20.04% sleep [kernel.kallsyms] [k] filemap_fault
19.78% sleep [kernel.kallsyms] [k] __lru_cache_add
19.69% sleep ld-2.12.so [.] memcpy
14.71% sleep [kernel.kallsyms] [k] dput
4.70% sleep [kernel.kallsyms] [k] flush_signal_handlers
0.73% sleep [kernel.kallsyms] [k] perf_event_comm
0.11% sleep [kernel.kallsyms] [k] native_write_msr_safe
#
# (For a higher level overview, try: perf report --sort comm,dso)
#
[acme@emilia ~]$
This is because it found a suitable vmlinux (build-id checked) in
/lib/modules/2.6.39-rc7+/build/vmlinux (use -v in perf report to see the long
file name).
If we remove that file from the vmlinux path:
[root@emilia ~]# mv /lib/modules/2.6.39-rc7+/build/vmlinux \
/lib/modules/2.6.39-rc7+/build/vmlinux.OFF
[acme@emilia ~]$ perf report --stdio
[kernel.kallsyms] with build id 57298cdbe0131f6871667ec0eaab4804dcf6f562
not found, continuing without symbols
Kernel address maps (/proc/{kallsyms,modules}) were restricted, check
/proc/sys/kernel/kptr_restrict before running 'perf record'.
As no suitable kallsyms nor vmlinux was found, kernel samples can't be
resolved.
Samples in kernel modules can't be resolved as well.
# Events: 13 cycles
#
# Overhead Command Shared Object Symbol
# ........ ....... ................. ......
#
80.31% sleep [kernel.kallsyms] [k] 0xffffffff8103425a
19.69% sleep ld-2.12.so [.] memcpy
#
# (For a higher level overview, try: perf report --sort comm,dso)
#
[acme@emilia ~]$
Reported-by: Stephane Eranian <eranian@google.com>
Suggested-by: David Miller <davem@davemloft.net>
Cc: Dave Jones <davej@redhat.com>
Cc: David Miller <davem@davemloft.net>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Kees Cook <kees.cook@canonical.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
Link: http://lkml.kernel.org/n/tip-mt512joaxxbhhp1odop04yit@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2011-05-26 12:53:51 +00:00
|
|
|
if (symbol__restricted_filename(filename, "/proc/kallsyms"))
|
|
|
|
return -1;
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
if (dso__load_all_kallsyms(dso, filename, map) < 0)
|
2009-10-07 16:48:56 +00:00
|
|
|
return -1;
|
|
|
|
|
2014-01-29 14:14:43 +00:00
|
|
|
if (kallsyms__delta(map, filename, &delta))
|
|
|
|
return -1;
|
|
|
|
|
2011-08-24 06:40:17 +00:00
|
|
|
symbols__fixup_duplicate(&dso->symbols[map->type]);
|
2011-08-24 06:40:15 +00:00
|
|
|
symbols__fixup_end(&dso->symbols[map->type]);
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
if (dso->kernel == DSO_TYPE_GUEST_KERNEL)
|
2012-07-22 12:14:32 +00:00
|
|
|
dso->symtab_type = DSO_BINARY_TYPE__GUEST_KALLSYMS;
|
2010-04-19 05:32:50 +00:00
|
|
|
else
|
2012-07-22 12:14:32 +00:00
|
|
|
dso->symtab_type = DSO_BINARY_TYPE__KALLSYMS;
|
2009-10-07 16:48:56 +00:00
|
|
|
|
2013-08-07 11:38:51 +00:00
|
|
|
if (!dso__load_kcore(dso, map, filename))
|
|
|
|
return dso__split_kallsyms_for_kcore(dso, map, filter);
|
|
|
|
else
|
2014-01-29 14:14:43 +00:00
|
|
|
return dso__split_kallsyms(dso, map, delta, filter);
|
2009-10-05 17:26:17 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
static int dso__load_perf_map(struct dso *dso, struct map *map,
|
2009-10-21 19:34:06 +00:00
|
|
|
symbol_filter_t filter)
|
2009-06-08 18:12:48 +00:00
|
|
|
{
|
|
|
|
char *line = NULL;
|
|
|
|
size_t n;
|
|
|
|
FILE *file;
|
|
|
|
int nr_syms = 0;
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
file = fopen(dso->long_name, "r");
|
2009-06-08 18:12:48 +00:00
|
|
|
if (file == NULL)
|
|
|
|
goto out_failure;
|
|
|
|
|
|
|
|
while (!feof(file)) {
|
perf_counter tools: Define and use our own u64, s64 etc. definitions
On 64-bit powerpc, __u64 is defined to be unsigned long rather than
unsigned long long. This causes compiler warnings every time we
print a __u64 value with %Lx.
Rather than changing __u64, we define our own u64 to be unsigned long
long on all architectures, and similarly s64 as signed long long.
For consistency we also define u32, s32, u16, s16, u8 and s8. These
definitions are put in a new header, types.h, because these definitions
are needed in util/string.h and util/symbol.h.
The main change here is the mechanical change of __[us]{64,32,16,8}
to remove the "__". The other changes are:
* Create types.h
* Include types.h in perf.h, util/string.h and util/symbol.h
* Add types.h to the LIB_H definition in Makefile
* Added (u64) casts in process_overflow_event() and print_sym_table()
to kill two remaining warnings.
Signed-off-by: Paul Mackerras <paulus@samba.org>
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: benh@kernel.crashing.org
LKML-Reference: <19003.33494.495844.956580@cargo.ozlabs.ibm.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-06-19 12:21:42 +00:00
|
|
|
u64 start, size;
|
2009-06-08 18:12:48 +00:00
|
|
|
struct symbol *sym;
|
|
|
|
int line_len, len;
|
|
|
|
|
|
|
|
line_len = getline(&line, &n, file);
|
|
|
|
if (line_len < 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!line)
|
|
|
|
goto out_failure;
|
|
|
|
|
|
|
|
line[--line_len] = '\0'; /* \n */
|
|
|
|
|
|
|
|
len = hex2u64(line, &start);
|
|
|
|
|
|
|
|
len++;
|
|
|
|
if (len + 2 >= line_len)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
len += hex2u64(line + len, &size);
|
|
|
|
|
|
|
|
len++;
|
|
|
|
if (len + 2 >= line_len)
|
|
|
|
continue;
|
|
|
|
|
2010-08-05 15:59:47 +00:00
|
|
|
sym = symbol__new(start, size, STB_GLOBAL, line + len);
|
2009-06-08 18:12:48 +00:00
|
|
|
|
|
|
|
if (sym == NULL)
|
|
|
|
goto out_delete_line;
|
|
|
|
|
2009-10-02 06:29:58 +00:00
|
|
|
if (filter && filter(map, sym))
|
2009-10-30 18:28:24 +00:00
|
|
|
symbol__delete(sym);
|
2009-06-08 18:12:48 +00:00
|
|
|
else {
|
2011-03-31 13:56:28 +00:00
|
|
|
symbols__insert(&dso->symbols[map->type], sym);
|
2009-06-08 18:12:48 +00:00
|
|
|
nr_syms++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(line);
|
|
|
|
fclose(file);
|
|
|
|
|
|
|
|
return nr_syms;
|
|
|
|
|
|
|
|
out_delete_line:
|
|
|
|
free(line);
|
|
|
|
out_failure:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-02-20 01:32:56 +00:00
|
|
|
static bool dso__is_compatible_symtab_type(struct dso *dso, bool kmod,
|
|
|
|
enum dso_binary_type type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case DSO_BINARY_TYPE__JAVA_JIT:
|
|
|
|
case DSO_BINARY_TYPE__DEBUGLINK:
|
|
|
|
case DSO_BINARY_TYPE__SYSTEM_PATH_DSO:
|
|
|
|
case DSO_BINARY_TYPE__FEDORA_DEBUGINFO:
|
|
|
|
case DSO_BINARY_TYPE__UBUNTU_DEBUGINFO:
|
|
|
|
case DSO_BINARY_TYPE__BUILDID_DEBUGINFO:
|
|
|
|
case DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO:
|
|
|
|
return !kmod && dso->kernel == DSO_TYPE_USER;
|
|
|
|
|
|
|
|
case DSO_BINARY_TYPE__KALLSYMS:
|
|
|
|
case DSO_BINARY_TYPE__VMLINUX:
|
|
|
|
case DSO_BINARY_TYPE__KCORE:
|
|
|
|
return dso->kernel == DSO_TYPE_KERNEL;
|
|
|
|
|
|
|
|
case DSO_BINARY_TYPE__GUEST_KALLSYMS:
|
|
|
|
case DSO_BINARY_TYPE__GUEST_VMLINUX:
|
|
|
|
case DSO_BINARY_TYPE__GUEST_KCORE:
|
|
|
|
return dso->kernel == DSO_TYPE_GUEST_KERNEL;
|
|
|
|
|
|
|
|
case DSO_BINARY_TYPE__GUEST_KMODULE:
|
2014-11-04 01:14:27 +00:00
|
|
|
case DSO_BINARY_TYPE__GUEST_KMODULE_COMP:
|
2014-02-20 01:32:56 +00:00
|
|
|
case DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE:
|
2014-11-04 01:14:27 +00:00
|
|
|
case DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP:
|
2014-02-20 01:32:56 +00:00
|
|
|
/*
|
|
|
|
* kernel modules know their symtab type - it's set when
|
|
|
|
* creating a module dso in machine__new_module().
|
|
|
|
*/
|
|
|
|
return kmod && dso->symtab_type == type;
|
|
|
|
|
|
|
|
case DSO_BINARY_TYPE__BUILD_ID_CACHE:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case DSO_BINARY_TYPE__NOT_FOUND:
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter)
|
2009-05-28 17:55:04 +00:00
|
|
|
{
|
2009-11-20 22:51:27 +00:00
|
|
|
char *name;
|
2009-05-28 17:55:04 +00:00
|
|
|
int ret = -1;
|
2012-07-22 12:14:32 +00:00
|
|
|
u_int i;
|
2010-04-28 00:17:50 +00:00
|
|
|
struct machine *machine;
|
2012-07-22 12:14:32 +00:00
|
|
|
char *root_dir = (char *) "";
|
2012-08-10 22:23:02 +00:00
|
|
|
int ss_pos = 0;
|
|
|
|
struct symsrc ss_[2];
|
|
|
|
struct symsrc *syms_ss = NULL, *runtime_ss = NULL;
|
2014-02-20 01:32:56 +00:00
|
|
|
bool kmod;
|
2009-05-28 17:55:04 +00:00
|
|
|
|
2015-05-18 00:30:40 +00:00
|
|
|
pthread_mutex_lock(&dso->lock);
|
|
|
|
|
|
|
|
/* check again under the dso->lock */
|
|
|
|
if (dso__loaded(dso, map->type)) {
|
|
|
|
ret = 1;
|
|
|
|
goto out;
|
|
|
|
}
|
2009-10-28 23:51:21 +00:00
|
|
|
|
2015-05-18 00:30:40 +00:00
|
|
|
if (dso->kernel) {
|
|
|
|
if (dso->kernel == DSO_TYPE_KERNEL)
|
|
|
|
ret = dso__load_kernel_sym(dso, map, filter);
|
|
|
|
else if (dso->kernel == DSO_TYPE_GUEST_KERNEL)
|
|
|
|
ret = dso__load_guest_kernel_sym(dso, map, filter);
|
|
|
|
|
|
|
|
goto out;
|
|
|
|
}
|
2010-04-19 05:32:50 +00:00
|
|
|
|
2010-04-28 00:17:50 +00:00
|
|
|
if (map->groups && map->groups->machine)
|
|
|
|
machine = map->groups->machine;
|
2010-04-19 05:32:50 +00:00
|
|
|
else
|
2010-04-28 00:17:50 +00:00
|
|
|
machine = NULL;
|
2009-11-20 22:51:27 +00:00
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
dso->adjust_symbols = 0;
|
2009-06-30 14:43:17 +00:00
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
if (strncmp(dso->name, "/tmp/perf-", 10) == 0) {
|
2011-08-09 19:54:18 +00:00
|
|
|
struct stat st;
|
|
|
|
|
2011-08-11 20:55:37 +00:00
|
|
|
if (lstat(dso->name, &st) < 0)
|
2015-05-18 00:30:40 +00:00
|
|
|
goto out;
|
2011-08-09 19:54:18 +00:00
|
|
|
|
|
|
|
if (st.st_uid && (st.st_uid != geteuid())) {
|
|
|
|
pr_warning("File %s not owned by current user or root, "
|
|
|
|
"ignoring it.\n", dso->name);
|
2015-05-18 00:30:40 +00:00
|
|
|
goto out;
|
2011-08-09 19:54:18 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
ret = dso__load_perf_map(dso, map, filter);
|
2012-07-22 12:14:32 +00:00
|
|
|
dso->symtab_type = ret > 0 ? DSO_BINARY_TYPE__JAVA_JIT :
|
|
|
|
DSO_BINARY_TYPE__NOT_FOUND;
|
2015-05-18 00:30:40 +00:00
|
|
|
goto out;
|
2009-08-06 17:43:17 +00:00
|
|
|
}
|
|
|
|
|
2012-07-22 12:14:32 +00:00
|
|
|
if (machine)
|
|
|
|
root_dir = machine->root_dir;
|
|
|
|
|
2013-01-14 17:46:47 +00:00
|
|
|
name = malloc(PATH_MAX);
|
|
|
|
if (!name)
|
2015-05-18 00:30:40 +00:00
|
|
|
goto out;
|
2013-01-14 17:46:47 +00:00
|
|
|
|
2014-02-20 01:32:56 +00:00
|
|
|
kmod = dso->symtab_type == DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE ||
|
2014-11-04 01:14:27 +00:00
|
|
|
dso->symtab_type == DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP ||
|
|
|
|
dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE ||
|
|
|
|
dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE_COMP;
|
2014-02-20 01:32:56 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Iterate over candidate debug images.
|
2012-08-10 22:23:02 +00:00
|
|
|
* Keep track of "interesting" ones (those which have a symtab, dynsym,
|
|
|
|
* and/or opd section) for processing.
|
2010-07-30 12:50:09 +00:00
|
|
|
*/
|
2012-07-22 12:14:32 +00:00
|
|
|
for (i = 0; i < DSO_BINARY_TYPE__SYMTAB_CNT; i++) {
|
2012-08-10 22:23:02 +00:00
|
|
|
struct symsrc *ss = &ss_[ss_pos];
|
|
|
|
bool next_slot = false;
|
2010-07-30 12:50:09 +00:00
|
|
|
|
2012-08-10 22:22:58 +00:00
|
|
|
enum dso_binary_type symtab_type = binary_type_symtab[i];
|
2010-12-09 20:27:07 +00:00
|
|
|
|
2014-02-20 01:32:56 +00:00
|
|
|
if (!dso__is_compatible_symtab_type(dso, kmod, symtab_type))
|
|
|
|
continue;
|
|
|
|
|
2013-12-16 20:03:18 +00:00
|
|
|
if (dso__read_binary_type_filename(dso, symtab_type,
|
|
|
|
root_dir, name, PATH_MAX))
|
2012-07-22 12:14:32 +00:00
|
|
|
continue;
|
2010-07-30 12:50:09 +00:00
|
|
|
|
|
|
|
/* Name is now the name of the next image to try */
|
2012-08-10 22:23:02 +00:00
|
|
|
if (symsrc__init(ss, dso, name, symtab_type) < 0)
|
2010-07-30 12:50:09 +00:00
|
|
|
continue;
|
2009-05-28 17:55:04 +00:00
|
|
|
|
2012-08-10 22:23:02 +00:00
|
|
|
if (!syms_ss && symsrc__has_symtab(ss)) {
|
|
|
|
syms_ss = ss;
|
|
|
|
next_slot = true;
|
2013-12-03 07:23:08 +00:00
|
|
|
if (!dso->symsrc_filename)
|
|
|
|
dso->symsrc_filename = strdup(name);
|
2012-08-10 22:23:00 +00:00
|
|
|
}
|
|
|
|
|
2012-08-10 22:23:02 +00:00
|
|
|
if (!runtime_ss && symsrc__possibly_runtime(ss)) {
|
|
|
|
runtime_ss = ss;
|
|
|
|
next_slot = true;
|
2012-08-10 22:22:59 +00:00
|
|
|
}
|
2009-05-28 17:55:04 +00:00
|
|
|
|
2012-08-10 22:23:02 +00:00
|
|
|
if (next_slot) {
|
|
|
|
ss_pos++;
|
2012-04-18 13:46:58 +00:00
|
|
|
|
2012-08-10 22:23:02 +00:00
|
|
|
if (syms_ss && runtime_ss)
|
|
|
|
break;
|
2014-02-20 01:32:54 +00:00
|
|
|
} else {
|
|
|
|
symsrc__destroy(ss);
|
2010-07-30 12:50:09 +00:00
|
|
|
}
|
2012-08-10 22:23:02 +00:00
|
|
|
|
perf_counter tools: PLT info is stripped in -debuginfo packages
So we need to get the richer .symtab from the debuginfo
packages but the PLT info from the original DSO where we have
just the leaner .dynsym symtab.
Example:
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > before
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > after
| [acme@doppio pahole]$ diff -U1 before after
| --- before 2009-07-11 11:04:22.688595741 -0300
| +++ after 2009-07-11 11:04:33.380595676 -0300
| @@ -80,3 +80,2 @@
| 0.07% pahole ./build/pahole [.] pahole_stealer
| - 0.06% pahole /usr/lib64/libdw-0.141.so [.] 0x00000000007140
| 0.06% pahole /usr/lib64/libdw-0.141.so [.] __libdw_getabbrev
| @@ -91,2 +90,3 @@
| 0.06% pahole [kernel] [k] free_hot_cold_page
| + 0.06% pahole /usr/lib64/libdw-0.141.so [.] tfind@plt
| 0.05% pahole ./build/libdwarves.so.1.0.0 [.] ftype__add_parameter
| @@ -242,2 +242,3 @@
| 0.01% pahole [kernel] [k] account_group_user_time
| + 0.01% pahole /usr/lib64/libdw-0.141.so [.] strlen@plt
| 0.01% pahole ./build/pahole [.] strcmp@plt
| [acme@doppio pahole]$
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <1247325517-12272-4-git-send-email-acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-07-11 15:18:36 +00:00
|
|
|
}
|
2010-07-30 12:50:09 +00:00
|
|
|
|
2012-08-10 22:23:02 +00:00
|
|
|
if (!runtime_ss && !syms_ss)
|
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
if (runtime_ss && !syms_ss) {
|
|
|
|
syms_ss = runtime_ss;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We'll have to hope for the best */
|
|
|
|
if (!runtime_ss && syms_ss)
|
|
|
|
runtime_ss = syms_ss;
|
|
|
|
|
2014-02-20 01:32:56 +00:00
|
|
|
if (syms_ss)
|
|
|
|
ret = dso__load_sym(dso, map, syms_ss, runtime_ss, filter, kmod);
|
|
|
|
else
|
2012-08-10 22:23:02 +00:00
|
|
|
ret = -1;
|
|
|
|
|
2012-08-19 15:47:14 +00:00
|
|
|
if (ret > 0) {
|
2012-08-10 22:23:02 +00:00
|
|
|
int nr_plt;
|
|
|
|
|
|
|
|
nr_plt = dso__synthesize_plt_symbols(dso, runtime_ss, map, filter);
|
|
|
|
if (nr_plt > 0)
|
|
|
|
ret += nr_plt;
|
2011-03-22 18:42:14 +00:00
|
|
|
}
|
|
|
|
|
2012-08-10 22:23:02 +00:00
|
|
|
for (; ss_pos > 0; ss_pos--)
|
|
|
|
symsrc__destroy(&ss_[ss_pos - 1]);
|
|
|
|
out_free:
|
2009-05-28 17:55:04 +00:00
|
|
|
free(name);
|
2011-03-31 13:56:28 +00:00
|
|
|
if (ret < 0 && strstr(dso->name, " (deleted)") != NULL)
|
2015-05-18 00:30:40 +00:00
|
|
|
ret = 0;
|
|
|
|
out:
|
|
|
|
dso__set_loaded(dso, map->type);
|
|
|
|
pthread_mutex_unlock(&dso->lock);
|
|
|
|
|
2009-05-28 17:55:04 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
struct map *map_groups__find_by_name(struct map_groups *mg,
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-11 20:50:22 +00:00
|
|
|
enum map_type type, const char *name)
|
2009-10-02 06:29:58 +00:00
|
|
|
{
|
2015-05-22 15:58:53 +00:00
|
|
|
struct maps *maps = &mg->maps[type];
|
2015-05-22 14:52:22 +00:00
|
|
|
struct map *map;
|
2009-10-02 06:29:58 +00:00
|
|
|
|
2015-05-22 16:45:24 +00:00
|
|
|
pthread_rwlock_rdlock(&maps->lock);
|
|
|
|
|
2015-05-22 14:52:22 +00:00
|
|
|
for (map = maps__first(maps); map; map = map__next(map)) {
|
perf tools: Encode kernel module mappings in perf.data
We were always looking at the running machine /proc/modules,
even when processing a perf.data file, which only makes sense
when we're doing 'perf record' and 'perf report' on the same
machine, and in close sucession, or if we don't use modules at
all, right Peter? ;-)
Now, at 'perf record' time we read /proc/modules, find the long
path for modules, and put them as PERF_MMAP events, just like we
did to encode the reloc reference symbol for vmlinux. Talking
about that now it is encoded in .pgoff, so that we can use
.{start,len} to store the address boundaries for the kernel so
that when we reconstruct the kmaps tree we can do lookups right
away, without having to fixup the end of the kernel maps like we
did in the past (and now only in perf record).
One more step in the 'perf archive' direction when we'll finally
be able to collect data in one machine and analyse in another.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1263396139-4798-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-13 15:22:17 +00:00
|
|
|
if (map->dso && strcmp(map->dso->short_name, name) == 0)
|
2015-05-22 16:45:24 +00:00
|
|
|
goto out_unlock;
|
2009-10-02 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
2015-05-22 16:45:24 +00:00
|
|
|
map = NULL;
|
|
|
|
|
|
|
|
out_unlock:
|
|
|
|
pthread_rwlock_unlock(&maps->lock);
|
|
|
|
return map;
|
2009-10-02 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
int dso__load_vmlinux(struct dso *dso, struct map *map,
|
2013-12-10 14:58:52 +00:00
|
|
|
const char *vmlinux, bool vmlinux_allocated,
|
|
|
|
symbol_filter_t filter)
|
2009-05-28 17:55:04 +00:00
|
|
|
{
|
2012-08-10 22:22:57 +00:00
|
|
|
int err = -1;
|
|
|
|
struct symsrc ss;
|
2010-12-09 20:27:07 +00:00
|
|
|
char symfs_vmlinux[PATH_MAX];
|
2012-08-10 22:22:58 +00:00
|
|
|
enum dso_binary_type symtab_type;
|
2009-05-28 17:55:04 +00:00
|
|
|
|
2013-07-17 08:08:15 +00:00
|
|
|
if (vmlinux[0] == '/')
|
|
|
|
snprintf(symfs_vmlinux, sizeof(symfs_vmlinux), "%s", vmlinux);
|
|
|
|
else
|
2014-07-29 13:21:58 +00:00
|
|
|
symbol__join_symfs(symfs_vmlinux, vmlinux);
|
2009-05-28 17:55:04 +00:00
|
|
|
|
2012-08-10 22:22:56 +00:00
|
|
|
if (dso->kernel == DSO_TYPE_GUEST_KERNEL)
|
2012-08-10 22:22:58 +00:00
|
|
|
symtab_type = DSO_BINARY_TYPE__GUEST_VMLINUX;
|
2012-08-10 22:22:56 +00:00
|
|
|
else
|
2012-08-10 22:22:58 +00:00
|
|
|
symtab_type = DSO_BINARY_TYPE__VMLINUX;
|
2012-08-10 22:22:56 +00:00
|
|
|
|
2012-08-10 22:22:58 +00:00
|
|
|
if (symsrc__init(&ss, dso, symfs_vmlinux, symtab_type))
|
2012-08-10 22:22:57 +00:00
|
|
|
return -1;
|
|
|
|
|
2012-08-10 22:23:01 +00:00
|
|
|
err = dso__load_sym(dso, map, &ss, &ss, filter, 0);
|
2012-08-10 22:22:57 +00:00
|
|
|
symsrc__destroy(&ss);
|
2009-05-28 17:55:04 +00:00
|
|
|
|
2012-08-10 22:22:54 +00:00
|
|
|
if (err > 0) {
|
2013-08-07 11:38:47 +00:00
|
|
|
if (dso->kernel == DSO_TYPE_GUEST_KERNEL)
|
2013-12-17 19:14:07 +00:00
|
|
|
dso->binary_type = DSO_BINARY_TYPE__GUEST_VMLINUX;
|
2013-08-07 11:38:47 +00:00
|
|
|
else
|
2013-12-17 19:14:07 +00:00
|
|
|
dso->binary_type = DSO_BINARY_TYPE__VMLINUX;
|
2013-12-10 18:19:23 +00:00
|
|
|
dso__set_long_name(dso, vmlinux, vmlinux_allocated);
|
2012-08-10 22:22:54 +00:00
|
|
|
dso__set_loaded(dso, map->type);
|
2010-12-09 20:27:07 +00:00
|
|
|
pr_debug("Using %s for symbols\n", symfs_vmlinux);
|
2012-08-10 22:22:54 +00:00
|
|
|
}
|
2010-02-22 19:15:39 +00:00
|
|
|
|
2009-05-28 17:55:04 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
int dso__load_vmlinux_path(struct dso *dso, struct map *map,
|
2010-02-03 18:52:00 +00:00
|
|
|
symbol_filter_t filter)
|
2010-01-27 23:05:50 +00:00
|
|
|
{
|
|
|
|
int i, err = 0;
|
2014-11-04 01:14:32 +00:00
|
|
|
char *filename = NULL;
|
2010-01-27 23:05:50 +00:00
|
|
|
|
2014-11-04 01:14:32 +00:00
|
|
|
if (!symbol_conf.ignore_vmlinux_buildid)
|
|
|
|
filename = dso__build_id_filename(dso, NULL, 0);
|
2010-05-26 16:26:02 +00:00
|
|
|
if (filename != NULL) {
|
2013-12-10 14:58:52 +00:00
|
|
|
err = dso__load_vmlinux(dso, map, filename, true, filter);
|
|
|
|
if (err > 0)
|
2010-05-26 16:26:02 +00:00
|
|
|
goto out;
|
|
|
|
free(filename);
|
|
|
|
}
|
2010-01-27 23:05:50 +00:00
|
|
|
|
2014-11-04 01:14:32 +00:00
|
|
|
pr_debug("Looking at the vmlinux_path (%d entries long)\n",
|
|
|
|
vmlinux_path__nr_entries + 1);
|
|
|
|
|
2010-01-27 23:05:50 +00:00
|
|
|
for (i = 0; i < vmlinux_path__nr_entries; ++i) {
|
2013-12-10 14:58:52 +00:00
|
|
|
err = dso__load_vmlinux(dso, map, vmlinux_path[i], false, filter);
|
|
|
|
if (err > 0)
|
2010-01-27 23:05:50 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-05-26 16:26:02 +00:00
|
|
|
out:
|
2010-01-27 23:05:50 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2013-10-14 10:43:43 +00:00
|
|
|
static int find_matching_kcore(struct map *map, char *dir, size_t dir_sz)
|
|
|
|
{
|
|
|
|
char kallsyms_filename[PATH_MAX];
|
|
|
|
struct dirent *dent;
|
|
|
|
int ret = -1;
|
|
|
|
DIR *d;
|
|
|
|
|
|
|
|
d = opendir(dir);
|
|
|
|
if (!d)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
dent = readdir(d);
|
|
|
|
if (!dent)
|
|
|
|
break;
|
|
|
|
if (dent->d_type != DT_DIR)
|
|
|
|
continue;
|
|
|
|
scnprintf(kallsyms_filename, sizeof(kallsyms_filename),
|
|
|
|
"%s/%s/kallsyms", dir, dent->d_name);
|
2014-01-29 14:14:41 +00:00
|
|
|
if (!validate_kcore_addresses(kallsyms_filename, map)) {
|
2013-10-14 10:43:43 +00:00
|
|
|
strlcpy(dir, kallsyms_filename, dir_sz);
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
closedir(d);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *dso__find_kallsyms(struct dso *dso, struct map *map)
|
|
|
|
{
|
|
|
|
u8 host_build_id[BUILD_ID_SIZE];
|
|
|
|
char sbuild_id[BUILD_ID_SIZE * 2 + 1];
|
|
|
|
bool is_host = false;
|
|
|
|
char path[PATH_MAX];
|
|
|
|
|
|
|
|
if (!dso->has_build_id) {
|
|
|
|
/*
|
|
|
|
* Last resort, if we don't have a build-id and couldn't find
|
|
|
|
* any vmlinux file, try the running kernel kallsyms table.
|
|
|
|
*/
|
|
|
|
goto proc_kallsyms;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sysfs__read_build_id("/sys/kernel/notes", host_build_id,
|
|
|
|
sizeof(host_build_id)) == 0)
|
|
|
|
is_host = dso__build_id_equal(dso, host_build_id);
|
|
|
|
|
|
|
|
build_id__sprintf(dso->build_id, sizeof(dso->build_id), sbuild_id);
|
|
|
|
|
2013-11-26 13:19:24 +00:00
|
|
|
scnprintf(path, sizeof(path), "%s/[kernel.kcore]/%s", buildid_dir,
|
|
|
|
sbuild_id);
|
|
|
|
|
2013-10-14 10:43:43 +00:00
|
|
|
/* Use /proc/kallsyms if possible */
|
|
|
|
if (is_host) {
|
|
|
|
DIR *d;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
/* If no cached kcore go with /proc/kallsyms */
|
|
|
|
d = opendir(path);
|
|
|
|
if (!d)
|
|
|
|
goto proc_kallsyms;
|
|
|
|
closedir(d);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do not check the build-id cache, until we know we cannot use
|
|
|
|
* /proc/kcore.
|
|
|
|
*/
|
|
|
|
fd = open("/proc/kcore", O_RDONLY);
|
|
|
|
if (fd != -1) {
|
|
|
|
close(fd);
|
|
|
|
/* If module maps match go with /proc/kallsyms */
|
2014-01-29 14:14:41 +00:00
|
|
|
if (!validate_kcore_addresses("/proc/kallsyms", map))
|
2013-10-14 10:43:43 +00:00
|
|
|
goto proc_kallsyms;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find kallsyms in build-id cache with kcore */
|
|
|
|
if (!find_matching_kcore(map, path, sizeof(path)))
|
|
|
|
return strdup(path);
|
|
|
|
|
|
|
|
goto proc_kallsyms;
|
|
|
|
}
|
|
|
|
|
2013-11-26 13:19:24 +00:00
|
|
|
/* Find kallsyms in build-id cache with kcore */
|
|
|
|
if (!find_matching_kcore(map, path, sizeof(path)))
|
|
|
|
return strdup(path);
|
|
|
|
|
2013-10-14 10:43:43 +00:00
|
|
|
scnprintf(path, sizeof(path), "%s/[kernel.kallsyms]/%s",
|
|
|
|
buildid_dir, sbuild_id);
|
|
|
|
|
|
|
|
if (access(path, F_OK)) {
|
|
|
|
pr_err("No kallsyms or vmlinux with build-id %s was found\n",
|
|
|
|
sbuild_id);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return strdup(path);
|
|
|
|
|
|
|
|
proc_kallsyms:
|
|
|
|
return strdup("/proc/kallsyms");
|
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
static int dso__load_kernel_sym(struct dso *dso, struct map *map,
|
2010-02-03 18:52:00 +00:00
|
|
|
symbol_filter_t filter)
|
2009-05-28 17:55:19 +00:00
|
|
|
{
|
2009-11-23 18:39:10 +00:00
|
|
|
int err;
|
2010-01-14 20:30:06 +00:00
|
|
|
const char *kallsyms_filename = NULL;
|
|
|
|
char *kallsyms_allocated_filename = NULL;
|
2010-01-19 12:36:14 +00:00
|
|
|
/*
|
2010-12-08 02:39:46 +00:00
|
|
|
* Step 1: if the user specified a kallsyms or vmlinux filename, use
|
|
|
|
* it and only it, reporting errors to the user if it cannot be used.
|
2010-01-19 12:36:14 +00:00
|
|
|
*
|
|
|
|
* For instance, try to analyse an ARM perf.data file _without_ a
|
|
|
|
* build-id, or if the user specifies the wrong path to the right
|
|
|
|
* vmlinux file, obviously we can't fallback to another vmlinux (a
|
|
|
|
* x86_86 one, on the machine where analysis is being performed, say),
|
|
|
|
* or worse, /proc/kallsyms.
|
|
|
|
*
|
|
|
|
* If the specified file _has_ a build-id and there is a build-id
|
|
|
|
* section in the perf.data file, we will still do the expected
|
|
|
|
* validation in dso__load_vmlinux and will bail out if they don't
|
|
|
|
* match.
|
|
|
|
*/
|
2010-12-08 02:39:46 +00:00
|
|
|
if (symbol_conf.kallsyms_name != NULL) {
|
|
|
|
kallsyms_filename = symbol_conf.kallsyms_name;
|
|
|
|
goto do_kallsyms;
|
|
|
|
}
|
|
|
|
|
2013-09-14 08:32:59 +00:00
|
|
|
if (!symbol_conf.ignore_vmlinux && symbol_conf.vmlinux_name != NULL) {
|
2013-12-10 14:58:52 +00:00
|
|
|
return dso__load_vmlinux(dso, map, symbol_conf.vmlinux_name,
|
|
|
|
false, filter);
|
2010-01-19 12:36:14 +00:00
|
|
|
}
|
2009-11-23 18:39:10 +00:00
|
|
|
|
2013-09-14 08:32:59 +00:00
|
|
|
if (!symbol_conf.ignore_vmlinux && vmlinux_path != NULL) {
|
2011-03-31 13:56:28 +00:00
|
|
|
err = dso__load_vmlinux_path(dso, map, filter);
|
2010-01-27 23:05:50 +00:00
|
|
|
if (err > 0)
|
2013-08-07 11:38:47 +00:00
|
|
|
return err;
|
2009-11-23 18:39:10 +00:00
|
|
|
}
|
|
|
|
|
2010-12-09 20:27:07 +00:00
|
|
|
/* do not try local files if a symfs was given */
|
|
|
|
if (symbol_conf.symfs[0] != 0)
|
|
|
|
return -1;
|
|
|
|
|
2013-10-14 10:43:43 +00:00
|
|
|
kallsyms_allocated_filename = dso__find_kallsyms(dso, map);
|
|
|
|
if (!kallsyms_allocated_filename)
|
|
|
|
return -1;
|
2010-01-22 16:35:02 +00:00
|
|
|
|
2013-10-14 10:43:43 +00:00
|
|
|
kallsyms_filename = kallsyms_allocated_filename;
|
2009-10-02 06:29:58 +00:00
|
|
|
|
2009-11-23 18:39:10 +00:00
|
|
|
do_kallsyms:
|
2011-03-31 13:56:28 +00:00
|
|
|
err = dso__load_kallsyms(dso, kallsyms_filename, map, filter);
|
2010-02-22 19:15:39 +00:00
|
|
|
if (err > 0)
|
|
|
|
pr_debug("Using %s for symbols\n", kallsyms_filename);
|
2010-01-19 12:36:14 +00:00
|
|
|
free(kallsyms_allocated_filename);
|
2009-10-02 06:29:58 +00:00
|
|
|
|
2013-08-07 11:38:51 +00:00
|
|
|
if (err > 0 && !dso__is_kcore(dso)) {
|
2014-07-14 10:02:43 +00:00
|
|
|
dso->binary_type = DSO_BINARY_TYPE__KALLSYMS;
|
2013-12-10 18:19:23 +00:00
|
|
|
dso__set_long_name(dso, "[kernel.kallsyms]", false);
|
2009-11-27 18:29:17 +00:00
|
|
|
map__fixup_start(map);
|
|
|
|
map__fixup_end(map);
|
2009-10-02 06:29:58 +00:00
|
|
|
}
|
2009-08-06 17:43:17 +00:00
|
|
|
|
2009-05-28 17:55:19 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
static int dso__load_guest_kernel_sym(struct dso *dso, struct map *map,
|
|
|
|
symbol_filter_t filter)
|
2010-04-19 05:32:50 +00:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
const char *kallsyms_filename = NULL;
|
2010-04-28 00:17:50 +00:00
|
|
|
struct machine *machine;
|
2010-04-19 05:32:50 +00:00
|
|
|
char path[PATH_MAX];
|
|
|
|
|
|
|
|
if (!map->groups) {
|
|
|
|
pr_debug("Guest kernel map hasn't the point to groups\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2010-04-28 00:17:50 +00:00
|
|
|
machine = map->groups->machine;
|
2010-04-19 05:32:50 +00:00
|
|
|
|
2010-04-28 00:17:50 +00:00
|
|
|
if (machine__is_default_guest(machine)) {
|
2010-04-19 05:32:50 +00:00
|
|
|
/*
|
|
|
|
* if the user specified a vmlinux filename, use it and only
|
|
|
|
* it, reporting errors to the user if it cannot be used.
|
|
|
|
* Or use file guest_kallsyms inputted by user on commandline
|
|
|
|
*/
|
|
|
|
if (symbol_conf.default_guest_vmlinux_name != NULL) {
|
2011-03-31 13:56:28 +00:00
|
|
|
err = dso__load_vmlinux(dso, map,
|
2013-12-10 14:58:52 +00:00
|
|
|
symbol_conf.default_guest_vmlinux_name,
|
|
|
|
false, filter);
|
2013-08-07 11:38:47 +00:00
|
|
|
return err;
|
2010-04-19 05:32:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
kallsyms_filename = symbol_conf.default_guest_kallsyms;
|
|
|
|
if (!kallsyms_filename)
|
|
|
|
return -1;
|
|
|
|
} else {
|
2010-04-28 00:17:50 +00:00
|
|
|
sprintf(path, "%s/proc/kallsyms", machine->root_dir);
|
2010-04-19 05:32:50 +00:00
|
|
|
kallsyms_filename = path;
|
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
err = dso__load_kallsyms(dso, kallsyms_filename, map, filter);
|
2013-08-07 11:38:51 +00:00
|
|
|
if (err > 0)
|
2013-08-07 11:38:47 +00:00
|
|
|
pr_debug("Using %s for symbols\n", kallsyms_filename);
|
2013-08-07 11:38:51 +00:00
|
|
|
if (err > 0 && !dso__is_kcore(dso)) {
|
2014-07-14 10:02:43 +00:00
|
|
|
dso->binary_type = DSO_BINARY_TYPE__GUEST_KALLSYMS;
|
2013-08-07 11:38:47 +00:00
|
|
|
machine__mmap_name(machine, path, sizeof(path));
|
2013-12-10 18:08:44 +00:00
|
|
|
dso__set_long_name(dso, strdup(path), true);
|
2010-04-19 05:32:50 +00:00
|
|
|
map__fixup_start(map);
|
|
|
|
map__fixup_end(map);
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
2009-08-12 08:03:49 +00:00
|
|
|
|
2009-11-23 18:39:10 +00:00
|
|
|
static void vmlinux_path__exit(void)
|
|
|
|
{
|
2013-12-26 20:41:15 +00:00
|
|
|
while (--vmlinux_path__nr_entries >= 0)
|
|
|
|
zfree(&vmlinux_path[vmlinux_path__nr_entries]);
|
2015-05-17 10:56:27 +00:00
|
|
|
vmlinux_path__nr_entries = 0;
|
2009-11-23 18:39:10 +00:00
|
|
|
|
2013-12-26 20:41:15 +00:00
|
|
|
zfree(&vmlinux_path);
|
2009-11-23 18:39:10 +00:00
|
|
|
}
|
|
|
|
|
2014-08-12 06:40:45 +00:00
|
|
|
static int vmlinux_path__init(struct perf_session_env *env)
|
2009-11-23 18:39:10 +00:00
|
|
|
{
|
|
|
|
struct utsname uts;
|
|
|
|
char bf[PATH_MAX];
|
2014-08-12 06:40:45 +00:00
|
|
|
char *kernel_version;
|
2009-11-23 18:39:10 +00:00
|
|
|
|
2014-09-15 19:57:56 +00:00
|
|
|
vmlinux_path = malloc(sizeof(char *) * 6);
|
2009-11-23 18:39:10 +00:00
|
|
|
if (vmlinux_path == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
vmlinux_path[vmlinux_path__nr_entries] = strdup("vmlinux");
|
|
|
|
if (vmlinux_path[vmlinux_path__nr_entries] == NULL)
|
|
|
|
goto out_fail;
|
|
|
|
++vmlinux_path__nr_entries;
|
|
|
|
vmlinux_path[vmlinux_path__nr_entries] = strdup("/boot/vmlinux");
|
|
|
|
if (vmlinux_path[vmlinux_path__nr_entries] == NULL)
|
|
|
|
goto out_fail;
|
|
|
|
++vmlinux_path__nr_entries;
|
2010-12-09 20:27:07 +00:00
|
|
|
|
2014-08-12 06:40:45 +00:00
|
|
|
/* only try kernel version if no symfs was given */
|
2010-12-09 20:27:07 +00:00
|
|
|
if (symbol_conf.symfs[0] != 0)
|
|
|
|
return 0;
|
|
|
|
|
2014-08-12 06:40:45 +00:00
|
|
|
if (env) {
|
|
|
|
kernel_version = env->os_release;
|
|
|
|
} else {
|
|
|
|
if (uname(&uts) < 0)
|
|
|
|
goto out_fail;
|
|
|
|
|
|
|
|
kernel_version = uts.release;
|
|
|
|
}
|
2010-12-09 20:27:07 +00:00
|
|
|
|
2014-08-12 06:40:45 +00:00
|
|
|
snprintf(bf, sizeof(bf), "/boot/vmlinux-%s", kernel_version);
|
2009-11-23 18:39:10 +00:00
|
|
|
vmlinux_path[vmlinux_path__nr_entries] = strdup(bf);
|
|
|
|
if (vmlinux_path[vmlinux_path__nr_entries] == NULL)
|
|
|
|
goto out_fail;
|
|
|
|
++vmlinux_path__nr_entries;
|
2014-09-15 19:57:56 +00:00
|
|
|
snprintf(bf, sizeof(bf), "/usr/lib/debug/boot/vmlinux-%s",
|
|
|
|
kernel_version);
|
|
|
|
vmlinux_path[vmlinux_path__nr_entries] = strdup(bf);
|
|
|
|
if (vmlinux_path[vmlinux_path__nr_entries] == NULL)
|
|
|
|
goto out_fail;
|
|
|
|
++vmlinux_path__nr_entries;
|
2014-08-12 06:40:45 +00:00
|
|
|
snprintf(bf, sizeof(bf), "/lib/modules/%s/build/vmlinux", kernel_version);
|
2009-11-23 18:39:10 +00:00
|
|
|
vmlinux_path[vmlinux_path__nr_entries] = strdup(bf);
|
|
|
|
if (vmlinux_path[vmlinux_path__nr_entries] == NULL)
|
|
|
|
goto out_fail;
|
|
|
|
++vmlinux_path__nr_entries;
|
|
|
|
snprintf(bf, sizeof(bf), "/usr/lib/debug/lib/modules/%s/vmlinux",
|
2014-08-12 06:40:45 +00:00
|
|
|
kernel_version);
|
2009-11-23 18:39:10 +00:00
|
|
|
vmlinux_path[vmlinux_path__nr_entries] = strdup(bf);
|
|
|
|
if (vmlinux_path[vmlinux_path__nr_entries] == NULL)
|
|
|
|
goto out_fail;
|
|
|
|
++vmlinux_path__nr_entries;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_fail:
|
|
|
|
vmlinux_path__exit();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-11-18 20:32:48 +00:00
|
|
|
int setup_list(struct strlist **list, const char *list_str,
|
2009-12-15 22:04:40 +00:00
|
|
|
const char *list_name)
|
|
|
|
{
|
|
|
|
if (list_str == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
*list = strlist__new(true, list_str);
|
|
|
|
if (!*list) {
|
|
|
|
pr_err("problems parsing %s list\n", list_name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-24 15:52:41 +00:00
|
|
|
int setup_intlist(struct intlist **list, const char *list_str,
|
|
|
|
const char *list_name)
|
|
|
|
{
|
|
|
|
if (list_str == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
*list = intlist__new(list_str);
|
|
|
|
if (!*list) {
|
|
|
|
pr_err("problems parsing %s list\n", list_name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
perf symbols: Handle /proc/sys/kernel/kptr_restrict
Perf uses /proc/modules to figure out where kernel modules are loaded.
With the advent of kptr_restrict, non root users get zeroes for all module
start addresses.
So check if kptr_restrict is non zero and don't generate the syntethic
PERF_RECORD_MMAP events for them.
Warn the user about it in perf record and in perf report.
In perf report the reference relocation symbol being zero means that
kptr_restrict was set, thus /proc/kallsyms has only zeroed addresses, so don't
use it to fixup symbol addresses when using a valid kallsyms (in the buildid
cache) or vmlinux (in the vmlinux path) build-id located automatically or
specified by the user.
Provide an explanation about it in 'perf report' if kernel samples were taken,
checking if a suitable vmlinux or kallsyms was found/specified.
Restricted /proc/kallsyms don't go to the buildid cache anymore.
Example:
[acme@emilia ~]$ perf record -F 100000 sleep 1
WARNING: Kernel address maps (/proc/{kallsyms,modules}) are restricted, check
/proc/sys/kernel/kptr_restrict.
Samples in kernel functions may not be resolved if a suitable vmlinux file is
not found in the buildid cache or in the vmlinux path.
Samples in kernel modules won't be resolved at all.
If some relocation was applied (e.g. kexec) symbols may be misresolved even
with a suitable vmlinux or kallsyms file.
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.005 MB perf.data (~231 samples) ]
[acme@emilia ~]$
[acme@emilia ~]$ perf report --stdio
Kernel address maps (/proc/{kallsyms,modules}) were restricted,
check /proc/sys/kernel/kptr_restrict before running 'perf record'.
If some relocation was applied (e.g. kexec) symbols may be misresolved.
Samples in kernel modules can't be resolved as well.
# Events: 13 cycles
#
# Overhead Command Shared Object Symbol
# ........ ....... ................. .....................
#
20.24% sleep [kernel.kallsyms] [k] page_fault
20.04% sleep [kernel.kallsyms] [k] filemap_fault
19.78% sleep [kernel.kallsyms] [k] __lru_cache_add
19.69% sleep ld-2.12.so [.] memcpy
14.71% sleep [kernel.kallsyms] [k] dput
4.70% sleep [kernel.kallsyms] [k] flush_signal_handlers
0.73% sleep [kernel.kallsyms] [k] perf_event_comm
0.11% sleep [kernel.kallsyms] [k] native_write_msr_safe
#
# (For a higher level overview, try: perf report --sort comm,dso)
#
[acme@emilia ~]$
This is because it found a suitable vmlinux (build-id checked) in
/lib/modules/2.6.39-rc7+/build/vmlinux (use -v in perf report to see the long
file name).
If we remove that file from the vmlinux path:
[root@emilia ~]# mv /lib/modules/2.6.39-rc7+/build/vmlinux \
/lib/modules/2.6.39-rc7+/build/vmlinux.OFF
[acme@emilia ~]$ perf report --stdio
[kernel.kallsyms] with build id 57298cdbe0131f6871667ec0eaab4804dcf6f562
not found, continuing without symbols
Kernel address maps (/proc/{kallsyms,modules}) were restricted, check
/proc/sys/kernel/kptr_restrict before running 'perf record'.
As no suitable kallsyms nor vmlinux was found, kernel samples can't be
resolved.
Samples in kernel modules can't be resolved as well.
# Events: 13 cycles
#
# Overhead Command Shared Object Symbol
# ........ ....... ................. ......
#
80.31% sleep [kernel.kallsyms] [k] 0xffffffff8103425a
19.69% sleep ld-2.12.so [.] memcpy
#
# (For a higher level overview, try: perf report --sort comm,dso)
#
[acme@emilia ~]$
Reported-by: Stephane Eranian <eranian@google.com>
Suggested-by: David Miller <davem@davemloft.net>
Cc: Dave Jones <davej@redhat.com>
Cc: David Miller <davem@davemloft.net>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Kees Cook <kees.cook@canonical.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
Link: http://lkml.kernel.org/n/tip-mt512joaxxbhhp1odop04yit@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2011-05-26 12:53:51 +00:00
|
|
|
static bool symbol__read_kptr_restrict(void)
|
|
|
|
{
|
|
|
|
bool value = false;
|
|
|
|
|
|
|
|
if (geteuid() != 0) {
|
|
|
|
FILE *fp = fopen("/proc/sys/kernel/kptr_restrict", "r");
|
|
|
|
if (fp != NULL) {
|
|
|
|
char line[8];
|
|
|
|
|
|
|
|
if (fgets(line, sizeof(line), fp) != NULL)
|
|
|
|
value = atoi(line) != 0;
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2014-08-12 06:40:45 +00:00
|
|
|
int symbol__init(struct perf_session_env *env)
|
2009-11-18 22:20:53 +00:00
|
|
|
{
|
2010-12-09 20:27:07 +00:00
|
|
|
const char *symfs;
|
|
|
|
|
2010-09-09 16:30:59 +00:00
|
|
|
if (symbol_conf.initialized)
|
|
|
|
return 0;
|
|
|
|
|
2012-09-10 22:15:01 +00:00
|
|
|
symbol_conf.priv_size = PERF_ALIGN(symbol_conf.priv_size, sizeof(u64));
|
2011-03-29 17:18:39 +00:00
|
|
|
|
2012-08-06 04:41:19 +00:00
|
|
|
symbol__elf_init();
|
|
|
|
|
2009-12-15 22:04:39 +00:00
|
|
|
if (symbol_conf.sort_by_name)
|
|
|
|
symbol_conf.priv_size += (sizeof(struct symbol_name_rb_node) -
|
|
|
|
sizeof(struct symbol));
|
2009-11-24 14:05:15 +00:00
|
|
|
|
2014-08-12 06:40:45 +00:00
|
|
|
if (symbol_conf.try_vmlinux_path && vmlinux_path__init(env) < 0)
|
2009-11-18 22:20:53 +00:00
|
|
|
return -1;
|
|
|
|
|
2009-12-15 22:04:41 +00:00
|
|
|
if (symbol_conf.field_sep && *symbol_conf.field_sep == '.') {
|
|
|
|
pr_err("'.' is the only non valid --field-separator argument\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-12-15 22:04:40 +00:00
|
|
|
if (setup_list(&symbol_conf.dso_list,
|
|
|
|
symbol_conf.dso_list_str, "dso") < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (setup_list(&symbol_conf.comm_list,
|
|
|
|
symbol_conf.comm_list_str, "comm") < 0)
|
|
|
|
goto out_free_dso_list;
|
|
|
|
|
2015-03-24 15:52:41 +00:00
|
|
|
if (setup_intlist(&symbol_conf.pid_list,
|
|
|
|
symbol_conf.pid_list_str, "pid") < 0)
|
|
|
|
goto out_free_comm_list;
|
|
|
|
|
|
|
|
if (setup_intlist(&symbol_conf.tid_list,
|
|
|
|
symbol_conf.tid_list_str, "tid") < 0)
|
|
|
|
goto out_free_pid_list;
|
|
|
|
|
2009-12-15 22:04:40 +00:00
|
|
|
if (setup_list(&symbol_conf.sym_list,
|
|
|
|
symbol_conf.sym_list_str, "symbol") < 0)
|
2015-03-24 15:52:41 +00:00
|
|
|
goto out_free_tid_list;
|
2009-12-15 22:04:40 +00:00
|
|
|
|
2010-12-09 20:27:07 +00:00
|
|
|
/*
|
|
|
|
* A path to symbols of "/" is identical to ""
|
|
|
|
* reset here for simplicity.
|
|
|
|
*/
|
|
|
|
symfs = realpath(symbol_conf.symfs, NULL);
|
|
|
|
if (symfs == NULL)
|
|
|
|
symfs = symbol_conf.symfs;
|
|
|
|
if (strcmp(symfs, "/") == 0)
|
|
|
|
symbol_conf.symfs = "";
|
|
|
|
if (symfs != symbol_conf.symfs)
|
|
|
|
free((void *)symfs);
|
|
|
|
|
perf symbols: Handle /proc/sys/kernel/kptr_restrict
Perf uses /proc/modules to figure out where kernel modules are loaded.
With the advent of kptr_restrict, non root users get zeroes for all module
start addresses.
So check if kptr_restrict is non zero and don't generate the syntethic
PERF_RECORD_MMAP events for them.
Warn the user about it in perf record and in perf report.
In perf report the reference relocation symbol being zero means that
kptr_restrict was set, thus /proc/kallsyms has only zeroed addresses, so don't
use it to fixup symbol addresses when using a valid kallsyms (in the buildid
cache) or vmlinux (in the vmlinux path) build-id located automatically or
specified by the user.
Provide an explanation about it in 'perf report' if kernel samples were taken,
checking if a suitable vmlinux or kallsyms was found/specified.
Restricted /proc/kallsyms don't go to the buildid cache anymore.
Example:
[acme@emilia ~]$ perf record -F 100000 sleep 1
WARNING: Kernel address maps (/proc/{kallsyms,modules}) are restricted, check
/proc/sys/kernel/kptr_restrict.
Samples in kernel functions may not be resolved if a suitable vmlinux file is
not found in the buildid cache or in the vmlinux path.
Samples in kernel modules won't be resolved at all.
If some relocation was applied (e.g. kexec) symbols may be misresolved even
with a suitable vmlinux or kallsyms file.
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.005 MB perf.data (~231 samples) ]
[acme@emilia ~]$
[acme@emilia ~]$ perf report --stdio
Kernel address maps (/proc/{kallsyms,modules}) were restricted,
check /proc/sys/kernel/kptr_restrict before running 'perf record'.
If some relocation was applied (e.g. kexec) symbols may be misresolved.
Samples in kernel modules can't be resolved as well.
# Events: 13 cycles
#
# Overhead Command Shared Object Symbol
# ........ ....... ................. .....................
#
20.24% sleep [kernel.kallsyms] [k] page_fault
20.04% sleep [kernel.kallsyms] [k] filemap_fault
19.78% sleep [kernel.kallsyms] [k] __lru_cache_add
19.69% sleep ld-2.12.so [.] memcpy
14.71% sleep [kernel.kallsyms] [k] dput
4.70% sleep [kernel.kallsyms] [k] flush_signal_handlers
0.73% sleep [kernel.kallsyms] [k] perf_event_comm
0.11% sleep [kernel.kallsyms] [k] native_write_msr_safe
#
# (For a higher level overview, try: perf report --sort comm,dso)
#
[acme@emilia ~]$
This is because it found a suitable vmlinux (build-id checked) in
/lib/modules/2.6.39-rc7+/build/vmlinux (use -v in perf report to see the long
file name).
If we remove that file from the vmlinux path:
[root@emilia ~]# mv /lib/modules/2.6.39-rc7+/build/vmlinux \
/lib/modules/2.6.39-rc7+/build/vmlinux.OFF
[acme@emilia ~]$ perf report --stdio
[kernel.kallsyms] with build id 57298cdbe0131f6871667ec0eaab4804dcf6f562
not found, continuing without symbols
Kernel address maps (/proc/{kallsyms,modules}) were restricted, check
/proc/sys/kernel/kptr_restrict before running 'perf record'.
As no suitable kallsyms nor vmlinux was found, kernel samples can't be
resolved.
Samples in kernel modules can't be resolved as well.
# Events: 13 cycles
#
# Overhead Command Shared Object Symbol
# ........ ....... ................. ......
#
80.31% sleep [kernel.kallsyms] [k] 0xffffffff8103425a
19.69% sleep ld-2.12.so [.] memcpy
#
# (For a higher level overview, try: perf report --sort comm,dso)
#
[acme@emilia ~]$
Reported-by: Stephane Eranian <eranian@google.com>
Suggested-by: David Miller <davem@davemloft.net>
Cc: Dave Jones <davej@redhat.com>
Cc: David Miller <davem@davemloft.net>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Kees Cook <kees.cook@canonical.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
Link: http://lkml.kernel.org/n/tip-mt512joaxxbhhp1odop04yit@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2011-05-26 12:53:51 +00:00
|
|
|
symbol_conf.kptr_restrict = symbol__read_kptr_restrict();
|
|
|
|
|
2010-09-09 16:30:59 +00:00
|
|
|
symbol_conf.initialized = true;
|
perf session: Move kmaps to perf_session
There is still some more work to do to disentangle map creation
from DSO loading, but this happens only for the kernel, and for
the early adopters of perf diff, where this disentanglement
matters most, we'll be testing different kernels, so no problem
here.
Further clarification: right now we create the kernel maps for
the various modules and discontiguous kernel text maps when
loading the DSO, we should do it as a two step process, first
creating the maps, for multiple mappings with the same DSO
store, then doing the dso load just once, for the first hit on
one of the maps sharing this DSO backing store.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260741029-4430-6-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-13 21:50:29 +00:00
|
|
|
return 0;
|
2009-12-15 22:04:40 +00:00
|
|
|
|
2015-03-24 15:52:41 +00:00
|
|
|
out_free_tid_list:
|
|
|
|
intlist__delete(symbol_conf.tid_list);
|
|
|
|
out_free_pid_list:
|
|
|
|
intlist__delete(symbol_conf.pid_list);
|
2009-12-15 22:04:40 +00:00
|
|
|
out_free_comm_list:
|
|
|
|
strlist__delete(symbol_conf.comm_list);
|
2011-12-12 15:16:52 +00:00
|
|
|
out_free_dso_list:
|
|
|
|
strlist__delete(symbol_conf.dso_list);
|
2009-12-15 22:04:40 +00:00
|
|
|
return -1;
|
perf session: Move kmaps to perf_session
There is still some more work to do to disentangle map creation
from DSO loading, but this happens only for the kernel, and for
the early adopters of perf diff, where this disentanglement
matters most, we'll be testing different kernels, so no problem
here.
Further clarification: right now we create the kernel maps for
the various modules and discontiguous kernel text maps when
loading the DSO, we should do it as a two step process, first
creating the maps, for multiple mappings with the same DSO
store, then doing the dso load just once, for the first hit on
one of the maps sharing this DSO backing store.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260741029-4430-6-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-13 21:50:29 +00:00
|
|
|
}
|
|
|
|
|
2010-07-30 21:31:28 +00:00
|
|
|
void symbol__exit(void)
|
|
|
|
{
|
2010-09-09 16:30:59 +00:00
|
|
|
if (!symbol_conf.initialized)
|
|
|
|
return;
|
2010-07-30 21:31:28 +00:00
|
|
|
strlist__delete(symbol_conf.sym_list);
|
|
|
|
strlist__delete(symbol_conf.dso_list);
|
|
|
|
strlist__delete(symbol_conf.comm_list);
|
2015-03-24 15:52:41 +00:00
|
|
|
intlist__delete(symbol_conf.tid_list);
|
|
|
|
intlist__delete(symbol_conf.pid_list);
|
2010-07-30 21:31:28 +00:00
|
|
|
vmlinux_path__exit();
|
|
|
|
symbol_conf.sym_list = symbol_conf.dso_list = symbol_conf.comm_list = NULL;
|
2010-09-09 16:30:59 +00:00
|
|
|
symbol_conf.initialized = false;
|
2010-07-30 21:31:28 +00:00
|
|
|
}
|