2010-03-26 06:59:00 +08: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-23 06:37:02 +08:00
|
|
|
#include <inttypes.h>
|
2010-05-20 23:15:33 +08:00
|
|
|
#include "build-id.h"
|
2012-02-10 09:10:17 +08:00
|
|
|
#include "util.h"
|
2010-07-21 01:42:52 +08:00
|
|
|
#include "debug.h"
|
2009-05-29 01:55:04 +08:00
|
|
|
#include "symbol.h"
|
2010-03-26 06:59:00 +08:00
|
|
|
#include "strlist.h"
|
2009-05-29 01:55:04 +08:00
|
|
|
|
|
|
|
#include <elf.h>
|
2009-11-19 06:20:52 +08:00
|
|
|
#include <limits.h>
|
2009-10-02 14:29:58 +08:00
|
|
|
#include <sys/utsname.h>
|
2009-08-05 20:05:16 +08:00
|
|
|
|
2010-12-22 11:08:36 +08:00
|
|
|
#ifndef KSYM_NAME_LEN
|
2011-10-20 15:43:26 +08:00
|
|
|
#define KSYM_NAME_LEN 256
|
2010-12-22 11:08:36 +08:00
|
|
|
#endif
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
static int dso__load_kernel_sym(struct dso *dso, struct map *map,
|
2010-02-04 02:52:00 +08:00
|
|
|
symbol_filter_t filter);
|
2011-03-31 21:56:28 +08:00
|
|
|
static int dso__load_guest_kernel_sym(struct dso *dso, struct map *map,
|
2010-04-19 13:32:50 +08:00
|
|
|
symbol_filter_t filter);
|
2009-11-24 02:39:10 +08:00
|
|
|
static int vmlinux_path__nr_entries;
|
|
|
|
static char **vmlinux_path;
|
2009-10-02 14:29:58 +08:00
|
|
|
|
2009-12-16 06:04:39 +08:00
|
|
|
struct symbol_conf symbol_conf = {
|
2009-12-16 06:04:42 +08:00
|
|
|
.exclude_other = true,
|
2009-11-24 22:05:15 +08:00
|
|
|
.use_modules = true,
|
|
|
|
.try_vmlinux_path = true,
|
2011-05-17 23:32:07 +08:00
|
|
|
.annotate_src = true,
|
2010-12-10 04:27:07 +08:00
|
|
|
.symfs = "",
|
2009-11-24 22:05:15 +08:00
|
|
|
};
|
|
|
|
|
2012-07-22 20:14:32 +08: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,
|
|
|
|
DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE,
|
|
|
|
DSO_BINARY_TYPE__NOT_FOUND,
|
|
|
|
};
|
|
|
|
|
2012-08-01 20:47:57 +08:00
|
|
|
#define DSO_BINARY_TYPE__SYMTAB_CNT ARRAY_SIZE(binary_type_symtab)
|
2012-07-22 20:14:32 +08:00
|
|
|
|
2010-01-05 02:19:27 +08:00
|
|
|
bool symbol_type__is_a(char symbol_type, enum map_type map_type)
|
2009-12-12 00:50:37 +08:00
|
|
|
{
|
2011-08-24 14:40:16 +08:00
|
|
|
symbol_type = toupper(symbol_type);
|
|
|
|
|
2009-12-12 00:50:37 +08: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-12 00:50:39 +08:00
|
|
|
case MAP__VARIABLE:
|
2011-08-24 14:40:16 +08:00
|
|
|
return symbol_type == 'D';
|
2009-12-12 00:50:37 +08:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-24 14:40:17 +08:00
|
|
|
static int prefix_underscores_count(const char *str)
|
|
|
|
{
|
|
|
|
const char *tail = str;
|
|
|
|
|
|
|
|
while (*tail == '_')
|
|
|
|
tail++;
|
|
|
|
|
|
|
|
return tail - str;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SYMBOL_A 0
|
|
|
|
#define SYMBOL_B 1
|
|
|
|
|
|
|
|
static int choose_best_symbol(struct symbol *syma, struct symbol *symb)
|
|
|
|
{
|
|
|
|
s64 a;
|
|
|
|
s64 b;
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
|
|
|
/* If all else fails, choose the symbol with the longest name */
|
|
|
|
if (strlen(syma->name) >= strlen(symb->name))
|
|
|
|
return SYMBOL_A;
|
|
|
|
else
|
|
|
|
return SYMBOL_B;
|
|
|
|
}
|
|
|
|
|
2012-08-06 12:41:20 +08:00
|
|
|
void symbols__fixup_duplicate(struct rb_root *symbols)
|
2011-08-24 14:40:17 +08: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);
|
|
|
|
goto again;
|
|
|
|
} else {
|
|
|
|
nd = rb_next(&curr->rb_node);
|
|
|
|
rb_erase(&curr->rb_node, symbols);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-06 12:41:20 +08:00
|
|
|
void symbols__fixup_end(struct rb_root *symbols)
|
2009-10-06 01:26:17 +08:00
|
|
|
{
|
2011-03-31 21:56:28 +08:00
|
|
|
struct rb_node *nd, *prevnd = rb_first(symbols);
|
2009-10-08 00:48:56 +08:00
|
|
|
struct symbol *curr, *prev;
|
2009-10-06 01:26:17 +08:00
|
|
|
|
|
|
|
if (prevnd == NULL)
|
|
|
|
return;
|
|
|
|
|
2009-10-08 00:48:56 +08:00
|
|
|
curr = rb_entry(prevnd, struct symbol, rb_node);
|
|
|
|
|
2009-10-06 01:26:17 +08:00
|
|
|
for (nd = rb_next(prevnd); nd; nd = rb_next(nd)) {
|
2009-10-08 00:48:56 +08:00
|
|
|
prev = curr;
|
|
|
|
curr = rb_entry(nd, struct symbol, rb_node);
|
2009-10-06 01:26:17 +08:00
|
|
|
|
2010-12-22 11:08:36 +08:00
|
|
|
if (prev->end == prev->start && prev->end != curr->start)
|
2009-10-06 01:26:17 +08:00
|
|
|
prev->end = curr->start - 1;
|
|
|
|
}
|
2009-10-08 00:48:56 +08:00
|
|
|
|
|
|
|
/* Last entry */
|
|
|
|
if (curr->end == curr->start)
|
|
|
|
curr->end = roundup(curr->start, 4096);
|
2009-10-06 01:26:17 +08:00
|
|
|
}
|
|
|
|
|
2012-08-06 12:41:20 +08:00
|
|
|
void __map_groups__fixup_end(struct map_groups *mg, enum map_type type)
|
2009-10-06 01:26:17 +08:00
|
|
|
{
|
|
|
|
struct map *prev, *curr;
|
2011-03-31 21:56:28 +08:00
|
|
|
struct rb_node *nd, *prevnd = rb_first(&mg->maps[type]);
|
2009-10-06 01:26:17 +08:00
|
|
|
|
|
|
|
if (prevnd == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
curr = rb_entry(prevnd, struct map, rb_node);
|
|
|
|
|
|
|
|
for (nd = rb_next(prevnd); nd; nd = rb_next(nd)) {
|
|
|
|
prev = curr;
|
|
|
|
curr = rb_entry(nd, struct map, rb_node);
|
|
|
|
prev->end = curr->start - 1;
|
2009-10-08 00:48:56 +08:00
|
|
|
}
|
2009-11-22 00:31:24 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We still haven't the actual symbols, so guess the
|
|
|
|
* last map final address.
|
|
|
|
*/
|
2010-11-25 12:12:53 +08:00
|
|
|
curr->end = ~0ULL;
|
2009-10-06 01:26:17 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
static void map_groups__fixup_end(struct map_groups *mg)
|
2009-11-28 02:29:19 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < MAP__NR_TYPES; ++i)
|
2011-03-31 21:56:28 +08:00
|
|
|
__map_groups__fixup_end(mg, i);
|
2009-11-28 02:29:19 +08:00
|
|
|
}
|
|
|
|
|
2012-08-06 12:41:20 +08:00
|
|
|
struct symbol *symbol__new(u64 start, u64 len, u8 binding, const char *name)
|
2009-05-29 01:55:04 +08:00
|
|
|
{
|
2009-05-29 01:55:13 +08:00
|
|
|
size_t namelen = strlen(name) + 1;
|
2011-03-31 21:56:28 +08: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 21:48:52 +08:00
|
|
|
return NULL;
|
|
|
|
|
2009-12-16 06:04:39 +08:00
|
|
|
if (symbol_conf.priv_size)
|
2011-03-31 21:56:28 +08:00
|
|
|
sym = ((void *)sym) + symbol_conf.priv_size;
|
2009-10-21 00:25:40 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
sym->start = start;
|
|
|
|
sym->end = len ? start + len - 1 : start;
|
|
|
|
sym->binding = binding;
|
|
|
|
sym->namelen = namelen - 1;
|
2009-10-21 00:25:40 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
pr_debug4("%s: %s %#" PRIx64 "-%#" PRIx64 "\n",
|
|
|
|
__func__, name, start, sym->end);
|
|
|
|
memcpy(sym->name, name, namelen);
|
2009-05-29 01:55:04 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
return sym;
|
2009-05-29 01:55:04 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
void symbol__delete(struct symbol *sym)
|
2009-05-29 01:55:04 +08:00
|
|
|
{
|
2011-03-31 21:56:28 +08:00
|
|
|
free(((void *)sym) - symbol_conf.priv_size);
|
2009-05-29 01:55:04 +08:00
|
|
|
}
|
|
|
|
|
2012-10-28 05:18:32 +08:00
|
|
|
size_t symbol__fprintf(struct symbol *sym, FILE *fp)
|
2009-05-29 01:55:04 +08:00
|
|
|
{
|
2011-01-23 06:37:02 +08:00
|
|
|
return fprintf(fp, " %" PRIx64 "-%" PRIx64 " %c %s\n",
|
2011-03-31 21:56:28 +08:00
|
|
|
sym->start, sym->end,
|
|
|
|
sym->binding == STB_GLOBAL ? 'g' :
|
|
|
|
sym->binding == STB_LOCAL ? 'l' : 'w',
|
|
|
|
sym->name);
|
2009-05-29 01:55:04 +08:00
|
|
|
}
|
|
|
|
|
2012-01-30 12:43:15 +08:00
|
|
|
size_t symbol__fprintf_symname_offs(const struct symbol *sym,
|
|
|
|
const struct addr_location *al, FILE *fp)
|
2012-01-30 12:42:57 +08:00
|
|
|
{
|
2012-01-30 12:43:15 +08:00
|
|
|
unsigned long offset;
|
|
|
|
size_t length;
|
|
|
|
|
|
|
|
if (sym && sym->name) {
|
|
|
|
length = fprintf(fp, "%s", sym->name);
|
|
|
|
if (al) {
|
|
|
|
offset = al->addr - sym->start;
|
|
|
|
length += fprintf(fp, "+0x%lx", offset);
|
|
|
|
}
|
|
|
|
return length;
|
|
|
|
} else
|
|
|
|
return fprintf(fp, "[unknown]");
|
|
|
|
}
|
2012-01-30 12:42:57 +08:00
|
|
|
|
2012-01-30 12:43:15 +08:00
|
|
|
size_t symbol__fprintf_symname(const struct symbol *sym, FILE *fp)
|
|
|
|
{
|
|
|
|
return symbol__fprintf_symname_offs(sym, NULL, fp);
|
2012-01-30 12:42:57 +08:00
|
|
|
}
|
|
|
|
|
2012-10-28 05:18:32 +08:00
|
|
|
void symbols__delete(struct rb_root *symbols)
|
2009-05-29 01:55:04 +08:00
|
|
|
{
|
|
|
|
struct symbol *pos;
|
2011-03-31 21:56:28 +08:00
|
|
|
struct rb_node *next = rb_first(symbols);
|
2009-05-29 01:55:04 +08:00
|
|
|
|
|
|
|
while (next) {
|
|
|
|
pos = rb_entry(next, struct symbol, rb_node);
|
|
|
|
next = rb_next(&pos->rb_node);
|
2011-03-31 21:56:28 +08:00
|
|
|
rb_erase(&pos->rb_node, symbols);
|
2009-10-31 02:28:24 +08:00
|
|
|
symbol__delete(pos);
|
2009-05-29 01:55:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-06 12:41:20 +08:00
|
|
|
void symbols__insert(struct rb_root *symbols, struct symbol *sym)
|
2009-05-29 01:55:04 +08:00
|
|
|
{
|
2011-03-31 21:56:28 +08:00
|
|
|
struct rb_node **p = &symbols->rb_node;
|
2009-05-29 01:55:04 +08: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 20:21:42 +08:00
|
|
|
const u64 ip = sym->start;
|
2009-05-29 01:55:04 +08: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 21:56:28 +08:00
|
|
|
rb_insert_color(&sym->rb_node, symbols);
|
2009-05-29 01:55:04 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
static struct symbol *symbols__find(struct rb_root *symbols, u64 ip)
|
2009-05-29 01:55:04 +08:00
|
|
|
{
|
|
|
|
struct rb_node *n;
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
if (symbols == NULL)
|
2009-05-29 01:55:04 +08:00
|
|
|
return NULL;
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
n = symbols->rb_node;
|
2009-05-29 01:55:04 +08:00
|
|
|
|
|
|
|
while (n) {
|
|
|
|
struct symbol *s = rb_entry(n, struct symbol, rb_node);
|
|
|
|
|
|
|
|
if (ip < s->start)
|
|
|
|
n = n->rb_left;
|
|
|
|
else if (ip > s->end)
|
|
|
|
n = n->rb_right;
|
|
|
|
else
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
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-12 04:50:22 +08:00
|
|
|
struct symbol_name_rb_node {
|
|
|
|
struct rb_node rb_node;
|
|
|
|
struct symbol sym;
|
|
|
|
};
|
|
|
|
|
2011-03-31 21:56:28 +08: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-12 04:50:22 +08:00
|
|
|
{
|
2011-03-31 21:56:28 +08: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-12 04:50:22 +08:00
|
|
|
struct rb_node *parent = NULL;
|
2010-11-24 00:38:18 +08: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-12 04:50:22 +08: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 21:56:28 +08: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-12 04:50:22 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08: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-12 04:50:22 +08: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 21:56:28 +08: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-12 04:50:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08: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-12 04:50:22 +08:00
|
|
|
{
|
|
|
|
struct rb_node *n;
|
|
|
|
|
2011-03-31 21:56:28 +08: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-12 04:50:22 +08:00
|
|
|
return NULL;
|
|
|
|
|
2011-03-31 21:56:28 +08: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-12 04:50:22 +08:00
|
|
|
|
|
|
|
while (n) {
|
|
|
|
struct symbol_name_rb_node *s;
|
|
|
|
int cmp;
|
|
|
|
|
|
|
|
s = rb_entry(n, struct symbol_name_rb_node, rb_node);
|
|
|
|
cmp = strcmp(name, s->sym.name);
|
|
|
|
|
|
|
|
if (cmp < 0)
|
|
|
|
n = n->rb_left;
|
|
|
|
else if (cmp > 0)
|
|
|
|
n = n->rb_right;
|
|
|
|
else
|
|
|
|
return &s->sym;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08: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-12 04:50:22 +08:00
|
|
|
enum map_type type, u64 addr)
|
2009-11-24 23:01:52 +08:00
|
|
|
{
|
2011-03-31 21:56:28 +08:00
|
|
|
return symbols__find(&dso->symbols[type], addr);
|
2009-11-24 23:01:52 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08: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-12 04:50:22 +08:00
|
|
|
const char *name)
|
|
|
|
{
|
2011-03-31 21:56:28 +08: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-12 04:50:22 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08: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-12 04:50:22 +08:00
|
|
|
{
|
2011-03-31 21:56:28 +08: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-12 04:50:22 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
size_t dso__fprintf_symbols_by_name(struct dso *dso,
|
|
|
|
enum map_type type, FILE *fp)
|
2010-08-25 21:43:29 +08:00
|
|
|
{
|
|
|
|
size_t ret = 0;
|
|
|
|
struct rb_node *nd;
|
|
|
|
struct symbol_name_rb_node *pos;
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
for (nd = rb_first(&dso->symbol_names[type]); nd; nd = rb_next(nd)) {
|
2010-08-25 21:43:29 +08:00
|
|
|
pos = rb_entry(nd, struct symbol_name_rb_node, rb_node);
|
|
|
|
fprintf(fp, "%s\n", pos->sym.name);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-01-15 04:30:06 +08:00
|
|
|
int kallsyms__parse(const char *filename, void *arg,
|
|
|
|
int (*process_symbol)(void *arg, const char *name,
|
2012-08-11 06:22:48 +08:00
|
|
|
char type, u64 start))
|
2009-05-29 01:55:04 +08:00
|
|
|
{
|
|
|
|
char *line = NULL;
|
|
|
|
size_t n;
|
2010-12-22 11:08:36 +08:00
|
|
|
int err = -1;
|
2010-01-15 04:30:06 +08:00
|
|
|
FILE *file = fopen(filename, "r");
|
2009-05-29 01:55:04 +08:00
|
|
|
|
|
|
|
if (file == NULL)
|
|
|
|
goto out_failure;
|
|
|
|
|
2010-12-22 11:08:36 +08:00
|
|
|
err = 0;
|
|
|
|
|
2009-05-29 01:55:04 +08:00
|
|
|
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 20:21:42 +08:00
|
|
|
u64 start;
|
2009-05-29 01:55:04 +08:00
|
|
|
int line_len, len;
|
|
|
|
char symbol_type;
|
2009-10-08 00:48:56 +08:00
|
|
|
char *symbol_name;
|
2009-05-29 01:55:04 +08:00
|
|
|
|
|
|
|
line_len = getline(&line, &n, file);
|
2010-04-19 13:32:50 +08:00
|
|
|
if (line_len < 0 || !line)
|
2009-05-29 01:55:04 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
line[--line_len] = '\0'; /* \n */
|
|
|
|
|
2009-06-02 04:50:19 +08:00
|
|
|
len = hex2u64(line, &start);
|
2009-05-29 01:55:04 +08:00
|
|
|
|
|
|
|
len++;
|
|
|
|
if (len + 2 >= line_len)
|
|
|
|
continue;
|
|
|
|
|
2011-08-24 14:40:16 +08:00
|
|
|
symbol_type = line[len];
|
2010-12-22 11:08:36 +08:00
|
|
|
len += 2;
|
|
|
|
symbol_name = line + len;
|
|
|
|
len = line_len - len;
|
2010-01-05 02:19:26 +08:00
|
|
|
|
2010-12-22 11:08:36 +08:00
|
|
|
if (len >= KSYM_NAME_LEN) {
|
|
|
|
err = -1;
|
2010-01-05 02:19:26 +08:00
|
|
|
break;
|
2010-12-22 11:08:36 +08:00
|
|
|
}
|
|
|
|
|
2011-08-24 14:40:15 +08:00
|
|
|
err = process_symbol(arg, symbol_name,
|
2012-08-11 06:22:48 +08:00
|
|
|
symbol_type, start);
|
2011-08-24 14:40:15 +08:00
|
|
|
if (err)
|
|
|
|
break;
|
2009-10-08 00:48:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
free(line);
|
|
|
|
fclose(file);
|
2010-01-05 02:19:26 +08:00
|
|
|
return err;
|
2009-10-08 00:48:56 +08:00
|
|
|
|
|
|
|
out_failure:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-01-05 02:19:26 +08:00
|
|
|
struct process_kallsyms_args {
|
|
|
|
struct map *map;
|
|
|
|
struct dso *dso;
|
|
|
|
};
|
|
|
|
|
2010-08-05 23:59:47 +08:00
|
|
|
static u8 kallsyms2elf_type(char type)
|
|
|
|
{
|
|
|
|
if (type == 'W')
|
|
|
|
return STB_WEAK;
|
|
|
|
|
|
|
|
return isupper(type) ? STB_GLOBAL : STB_LOCAL;
|
|
|
|
}
|
|
|
|
|
2010-01-05 02:19:26 +08:00
|
|
|
static int map__process_kallsym_symbol(void *arg, const char *name,
|
2012-08-11 06:22:48 +08:00
|
|
|
char type, u64 start)
|
2010-01-05 02:19:26 +08: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-11 06:22:48 +08: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-05 02:19:26 +08: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 13:32:50 +08:00
|
|
|
|
2010-01-05 02:19:26 +08: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 21:56:28 +08:00
|
|
|
static int dso__load_all_kallsyms(struct dso *dso, const char *filename,
|
2010-01-15 04:30:06 +08:00
|
|
|
struct map *map)
|
2010-01-05 02:19:26 +08:00
|
|
|
{
|
2011-03-31 21:56:28 +08:00
|
|
|
struct process_kallsyms_args args = { .map = map, .dso = dso, };
|
2010-01-15 04:30:06 +08:00
|
|
|
return kallsyms__parse(filename, &args, map__process_kallsym_symbol);
|
2010-01-05 02:19:26 +08:00
|
|
|
}
|
|
|
|
|
2009-10-08 00:48:56 +08: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.
|
|
|
|
*/
|
2011-03-31 21:56:28 +08:00
|
|
|
static int dso__split_kallsyms(struct dso *dso, struct map *map,
|
2010-02-04 02:52:00 +08:00
|
|
|
symbol_filter_t filter)
|
2009-10-08 00:48:56 +08:00
|
|
|
{
|
2010-02-04 02:52:00 +08:00
|
|
|
struct map_groups *kmaps = map__kmap(map)->kmaps;
|
2010-04-28 08:17:50 +08:00
|
|
|
struct machine *machine = kmaps->machine;
|
2009-11-28 02:29:18 +08:00
|
|
|
struct map *curr_map = map;
|
2009-10-08 00:48:56 +08:00
|
|
|
struct symbol *pos;
|
2010-11-29 22:44:15 +08:00
|
|
|
int count = 0, moved = 0;
|
2011-03-31 21:56:28 +08:00
|
|
|
struct rb_root *root = &dso->symbols[map->type];
|
2009-11-28 02:29:18 +08:00
|
|
|
struct rb_node *next = rb_first(root);
|
2009-10-08 00:48:56 +08:00
|
|
|
int kernel_range = 0;
|
|
|
|
|
|
|
|
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-16 06:04:39 +08:00
|
|
|
if (!symbol_conf.use_modules)
|
2009-11-28 02:29:21 +08:00
|
|
|
goto discard_symbol;
|
|
|
|
|
2009-10-08 00:48:56 +08: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 23:22:17 +08:00
|
|
|
if (strcmp(curr_map->dso->short_name, module)) {
|
2010-04-19 13:32:50 +08:00
|
|
|
if (curr_map != map &&
|
2011-03-31 21:56:28 +08:00
|
|
|
dso->kernel == DSO_TYPE_GUEST_KERNEL &&
|
2010-04-28 08:17:50 +08:00
|
|
|
machine__is_default_guest(machine)) {
|
2010-04-19 13:32:50 +08: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-28 02:29:18 +08:00
|
|
|
if (curr_map == NULL) {
|
2010-05-18 04:57:59 +08: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 23:22:17 +08:00
|
|
|
"inconsistency while looking "
|
2010-04-19 13:32:50 +08:00
|
|
|
"for \"%s\" module!\n",
|
2010-04-28 08:17:50 +08:00
|
|
|
machine->root_dir, module);
|
2010-04-19 13:32:50 +08:00
|
|
|
curr_map = map;
|
|
|
|
goto discard_symbol;
|
2009-10-06 01:26:17 +08: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 23:22:17 +08:00
|
|
|
|
2010-04-19 13:32:50 +08:00
|
|
|
if (curr_map->dso->loaded &&
|
2010-04-28 08:17:50 +08: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 23:22:17 +08:00
|
|
|
goto discard_symbol;
|
2009-10-06 01:26:17 +08:00
|
|
|
}
|
2009-10-08 00:48:56 +08:00
|
|
|
/*
|
|
|
|
* So that we look just like we get from .ko files,
|
|
|
|
* i.e. not prelinked, relative to map->start.
|
|
|
|
*/
|
2009-11-28 02:29:18 +08: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-08 00:48:56 +08:00
|
|
|
char dso_name[PATH_MAX];
|
2011-03-31 21:56:28 +08:00
|
|
|
struct dso *ndso;
|
2009-10-08 00:48:56 +08:00
|
|
|
|
2010-11-29 22:44:15 +08:00
|
|
|
if (count == 0) {
|
|
|
|
curr_map = map;
|
|
|
|
goto filter_symbol;
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
if (dso->kernel == DSO_TYPE_GUEST_KERNEL)
|
2010-04-19 13:32:50 +08: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-08 00:48:56 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
ndso = dso__new(dso_name);
|
|
|
|
if (ndso == NULL)
|
2009-10-08 00:48:56 +08:00
|
|
|
return -1;
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
ndso->kernel = dso->kernel;
|
2010-04-19 13:32:50 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
curr_map = map__new2(pos->start, ndso, map->type);
|
2010-02-25 11:00:51 +08:00
|
|
|
if (curr_map == NULL) {
|
2011-03-31 21:56:28 +08:00
|
|
|
dso__delete(ndso);
|
2009-10-08 00:48:56 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2009-05-29 01:55:04 +08:00
|
|
|
|
2009-11-28 02:29:18 +08:00
|
|
|
curr_map->map_ip = curr_map->unmap_ip = identity__map_ip;
|
2010-02-04 02:52:00 +08:00
|
|
|
map_groups__insert(kmaps, curr_map);
|
2009-10-08 00:48:56 +08:00
|
|
|
++kernel_range;
|
|
|
|
}
|
2010-11-29 22:44:15 +08:00
|
|
|
filter_symbol:
|
2009-11-28 02:29:18 +08:00
|
|
|
if (filter && filter(curr_map, pos)) {
|
2009-11-28 02:29:21 +08:00
|
|
|
discard_symbol: rb_erase(&pos->rb_node, root);
|
2009-10-31 02:28:24 +08:00
|
|
|
symbol__delete(pos);
|
2009-10-08 00:48:56 +08:00
|
|
|
} else {
|
2009-11-28 02:29:18 +08:00
|
|
|
if (curr_map != map) {
|
|
|
|
rb_erase(&pos->rb_node, root);
|
|
|
|
symbols__insert(&curr_map->dso->symbols[curr_map->type], pos);
|
2010-11-29 22:44:15 +08:00
|
|
|
++moved;
|
|
|
|
} else
|
|
|
|
++count;
|
2009-07-02 14:05:58 +08:00
|
|
|
}
|
2009-05-29 01:55:04 +08:00
|
|
|
}
|
|
|
|
|
2010-04-19 13:32:50 +08:00
|
|
|
if (curr_map != map &&
|
2011-03-31 21:56:28 +08:00
|
|
|
dso->kernel == DSO_TYPE_GUEST_KERNEL &&
|
2010-04-28 08:17:50 +08:00
|
|
|
machine__is_default_guest(kmaps->machine)) {
|
2010-04-19 13:32:50 +08:00
|
|
|
dso__set_loaded(curr_map->dso, curr_map->type);
|
|
|
|
}
|
|
|
|
|
2010-11-29 22:44:15 +08:00
|
|
|
return count + moved;
|
2009-10-08 00:48:56 +08:00
|
|
|
}
|
2009-05-29 01:55:04 +08:00
|
|
|
|
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 20:53:51 +08:00
|
|
|
static bool symbol__restricted_filename(const char *filename,
|
|
|
|
const char *restricted_filename)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
int dso__load_kallsyms(struct dso *dso, const char *filename,
|
2010-02-04 02:52:00 +08:00
|
|
|
struct map *map, symbol_filter_t filter)
|
2009-10-08 00:48:56 +08:00
|
|
|
{
|
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 20:53:51 +08:00
|
|
|
if (symbol__restricted_filename(filename, "/proc/kallsyms"))
|
|
|
|
return -1;
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
if (dso__load_all_kallsyms(dso, filename, map) < 0)
|
2009-10-08 00:48:56 +08:00
|
|
|
return -1;
|
|
|
|
|
2011-08-24 14:40:17 +08:00
|
|
|
symbols__fixup_duplicate(&dso->symbols[map->type]);
|
2011-08-24 14:40:15 +08:00
|
|
|
symbols__fixup_end(&dso->symbols[map->type]);
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
if (dso->kernel == DSO_TYPE_GUEST_KERNEL)
|
2012-07-22 20:14:32 +08:00
|
|
|
dso->symtab_type = DSO_BINARY_TYPE__GUEST_KALLSYMS;
|
2010-04-19 13:32:50 +08:00
|
|
|
else
|
2012-07-22 20:14:32 +08:00
|
|
|
dso->symtab_type = DSO_BINARY_TYPE__KALLSYMS;
|
2009-10-08 00:48:56 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
return dso__split_kallsyms(dso, map, filter);
|
2009-10-06 01:26:17 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
static int dso__load_perf_map(struct dso *dso, struct map *map,
|
2009-10-22 03:34:06 +08:00
|
|
|
symbol_filter_t filter)
|
2009-06-09 02:12:48 +08:00
|
|
|
{
|
|
|
|
char *line = NULL;
|
|
|
|
size_t n;
|
|
|
|
FILE *file;
|
|
|
|
int nr_syms = 0;
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
file = fopen(dso->long_name, "r");
|
2009-06-09 02:12:48 +08: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 20:21:42 +08:00
|
|
|
u64 start, size;
|
2009-06-09 02:12:48 +08: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 23:59:47 +08:00
|
|
|
sym = symbol__new(start, size, STB_GLOBAL, line + len);
|
2009-06-09 02:12:48 +08:00
|
|
|
|
|
|
|
if (sym == NULL)
|
|
|
|
goto out_delete_line;
|
|
|
|
|
2009-10-02 14:29:58 +08:00
|
|
|
if (filter && filter(map, sym))
|
2009-10-31 02:28:24 +08:00
|
|
|
symbol__delete(sym);
|
2009-06-09 02:12:48 +08:00
|
|
|
else {
|
2011-03-31 21:56:28 +08:00
|
|
|
symbols__insert(&dso->symbols[map->type], sym);
|
2009-06-09 02:12:48 +08:00
|
|
|
nr_syms++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(line);
|
|
|
|
fclose(file);
|
|
|
|
|
|
|
|
return nr_syms;
|
|
|
|
|
|
|
|
out_delete_line:
|
|
|
|
free(line);
|
|
|
|
out_failure:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter)
|
2009-05-29 01:55:04 +08:00
|
|
|
{
|
2009-11-21 06:51:27 +08:00
|
|
|
char *name;
|
2009-05-29 01:55:04 +08:00
|
|
|
int ret = -1;
|
2012-07-22 20:14:32 +08:00
|
|
|
u_int i;
|
2010-04-28 08:17:50 +08:00
|
|
|
struct machine *machine;
|
2012-07-22 20:14:32 +08:00
|
|
|
char *root_dir = (char *) "";
|
2012-08-11 06:23:02 +08:00
|
|
|
int ss_pos = 0;
|
|
|
|
struct symsrc ss_[2];
|
|
|
|
struct symsrc *syms_ss = NULL, *runtime_ss = NULL;
|
2009-05-29 01:55:04 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
dso__set_loaded(dso, map->type);
|
2009-10-29 07:51:21 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
if (dso->kernel == DSO_TYPE_KERNEL)
|
|
|
|
return dso__load_kernel_sym(dso, map, filter);
|
|
|
|
else if (dso->kernel == DSO_TYPE_GUEST_KERNEL)
|
|
|
|
return dso__load_guest_kernel_sym(dso, map, filter);
|
2010-04-19 13:32:50 +08:00
|
|
|
|
2010-04-28 08:17:50 +08:00
|
|
|
if (map->groups && map->groups->machine)
|
|
|
|
machine = map->groups->machine;
|
2010-04-19 13:32:50 +08:00
|
|
|
else
|
2010-04-28 08:17:50 +08:00
|
|
|
machine = NULL;
|
2009-11-21 06:51:27 +08:00
|
|
|
|
2012-07-22 20:14:32 +08:00
|
|
|
name = malloc(PATH_MAX);
|
2009-05-29 01:55:04 +08:00
|
|
|
if (!name)
|
|
|
|
return -1;
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
dso->adjust_symbols = 0;
|
2009-06-30 22:43:17 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
if (strncmp(dso->name, "/tmp/perf-", 10) == 0) {
|
2011-08-10 03:54:18 +08:00
|
|
|
struct stat st;
|
|
|
|
|
2011-08-12 04:55:37 +08:00
|
|
|
if (lstat(dso->name, &st) < 0)
|
2011-08-10 03:54:18 +08:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (st.st_uid && (st.st_uid != geteuid())) {
|
|
|
|
pr_warning("File %s not owned by current user or root, "
|
|
|
|
"ignoring it.\n", dso->name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
ret = dso__load_perf_map(dso, map, filter);
|
2012-07-22 20:14:32 +08:00
|
|
|
dso->symtab_type = ret > 0 ? DSO_BINARY_TYPE__JAVA_JIT :
|
|
|
|
DSO_BINARY_TYPE__NOT_FOUND;
|
2009-08-07 01:43:17 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-07-22 20:14:32 +08:00
|
|
|
if (machine)
|
|
|
|
root_dir = machine->root_dir;
|
|
|
|
|
2010-07-30 20:50:09 +08:00
|
|
|
/* Iterate over candidate debug images.
|
2012-08-11 06:23:02 +08:00
|
|
|
* Keep track of "interesting" ones (those which have a symtab, dynsym,
|
|
|
|
* and/or opd section) for processing.
|
2010-07-30 20:50:09 +08:00
|
|
|
*/
|
2012-07-22 20:14:32 +08:00
|
|
|
for (i = 0; i < DSO_BINARY_TYPE__SYMTAB_CNT; i++) {
|
2012-08-11 06:23:02 +08:00
|
|
|
struct symsrc *ss = &ss_[ss_pos];
|
|
|
|
bool next_slot = false;
|
2010-07-30 20:50:09 +08:00
|
|
|
|
2012-08-11 06:22:58 +08:00
|
|
|
enum dso_binary_type symtab_type = binary_type_symtab[i];
|
2010-12-10 04:27:07 +08:00
|
|
|
|
2012-08-11 06:22:58 +08:00
|
|
|
if (dso__binary_type_file(dso, symtab_type,
|
2012-07-22 20:14:32 +08:00
|
|
|
root_dir, name, PATH_MAX))
|
|
|
|
continue;
|
2010-07-30 20:50:09 +08:00
|
|
|
|
|
|
|
/* Name is now the name of the next image to try */
|
2012-08-11 06:23:02 +08:00
|
|
|
if (symsrc__init(ss, dso, name, symtab_type) < 0)
|
2010-07-30 20:50:09 +08:00
|
|
|
continue;
|
2009-05-29 01:55:04 +08:00
|
|
|
|
2012-08-11 06:23:02 +08:00
|
|
|
if (!syms_ss && symsrc__has_symtab(ss)) {
|
|
|
|
syms_ss = ss;
|
|
|
|
next_slot = true;
|
2012-08-11 06:23:00 +08:00
|
|
|
}
|
|
|
|
|
2012-08-11 06:23:02 +08:00
|
|
|
if (!runtime_ss && symsrc__possibly_runtime(ss)) {
|
|
|
|
runtime_ss = ss;
|
|
|
|
next_slot = true;
|
2012-08-11 06:22:59 +08:00
|
|
|
}
|
2009-05-29 01:55:04 +08:00
|
|
|
|
2012-08-11 06:23:02 +08:00
|
|
|
if (next_slot) {
|
|
|
|
ss_pos++;
|
2012-04-18 21:46:58 +08:00
|
|
|
|
2012-08-11 06:23:02 +08:00
|
|
|
if (syms_ss && runtime_ss)
|
|
|
|
break;
|
2010-07-30 20:50:09 +08:00
|
|
|
}
|
2012-08-11 06:23:02 +08: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 23:18:36 +08:00
|
|
|
}
|
2010-07-30 20:50:09 +08:00
|
|
|
|
2012-08-11 06:23:02 +08: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;
|
|
|
|
|
|
|
|
if (syms_ss)
|
|
|
|
ret = dso__load_sym(dso, map, syms_ss, runtime_ss, filter, 0);
|
|
|
|
else
|
|
|
|
ret = -1;
|
|
|
|
|
2012-08-19 23:47:14 +08:00
|
|
|
if (ret > 0) {
|
2012-08-11 06:23:02 +08:00
|
|
|
int nr_plt;
|
|
|
|
|
|
|
|
nr_plt = dso__synthesize_plt_symbols(dso, runtime_ss, map, filter);
|
|
|
|
if (nr_plt > 0)
|
|
|
|
ret += nr_plt;
|
2011-03-23 02:42:14 +08:00
|
|
|
}
|
|
|
|
|
2012-08-11 06:23:02 +08:00
|
|
|
for (; ss_pos > 0; ss_pos--)
|
|
|
|
symsrc__destroy(&ss_[ss_pos - 1]);
|
|
|
|
out_free:
|
2009-05-29 01:55:04 +08:00
|
|
|
free(name);
|
2011-03-31 21:56:28 +08:00
|
|
|
if (ret < 0 && strstr(dso->name, " (deleted)") != NULL)
|
2009-08-12 04:04:36 +08:00
|
|
|
return 0;
|
2009-05-29 01:55:04 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08: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-12 04:50:22 +08:00
|
|
|
enum map_type type, const char *name)
|
2009-10-02 14:29:58 +08:00
|
|
|
{
|
|
|
|
struct rb_node *nd;
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
for (nd = rb_first(&mg->maps[type]); nd; nd = rb_next(nd)) {
|
2009-10-02 14:29:58 +08:00
|
|
|
struct map *map = rb_entry(nd, struct map, rb_node);
|
|
|
|
|
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 23:22:17 +08:00
|
|
|
if (map->dso && strcmp(map->dso->short_name, name) == 0)
|
2009-10-02 14:29:58 +08:00
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
static int map_groups__set_modules_path_dir(struct map_groups *mg,
|
2010-04-19 13:32:50 +08:00
|
|
|
const char *dir_name)
|
2009-07-02 14:08:36 +08:00
|
|
|
{
|
2009-10-02 14:29:58 +08:00
|
|
|
struct dirent *dent;
|
2010-03-26 06:59:00 +08:00
|
|
|
DIR *dir = opendir(dir_name);
|
2010-06-24 15:04:02 +08:00
|
|
|
int ret = 0;
|
2009-07-02 14:08:36 +08:00
|
|
|
|
2009-10-02 14:29:58 +08:00
|
|
|
if (!dir) {
|
2010-03-26 06:59:00 +08:00
|
|
|
pr_debug("%s: cannot open %s dir\n", __func__, dir_name);
|
2009-10-02 14:29:58 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2009-07-02 14:08:36 +08:00
|
|
|
|
2009-10-02 14:29:58 +08:00
|
|
|
while ((dent = readdir(dir)) != NULL) {
|
|
|
|
char path[PATH_MAX];
|
2010-04-19 13:32:50 +08:00
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
/*sshfs might return bad dent->d_type, so we have to stat*/
|
2011-12-12 23:16:51 +08:00
|
|
|
snprintf(path, sizeof(path), "%s/%s", dir_name, dent->d_name);
|
2010-04-19 13:32:50 +08:00
|
|
|
if (stat(path, &st))
|
|
|
|
continue;
|
2009-10-02 14:29:58 +08:00
|
|
|
|
2010-04-19 13:32:50 +08:00
|
|
|
if (S_ISDIR(st.st_mode)) {
|
2009-10-02 14:29:58 +08:00
|
|
|
if (!strcmp(dent->d_name, ".") ||
|
|
|
|
!strcmp(dent->d_name, ".."))
|
|
|
|
continue;
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
ret = map_groups__set_modules_path_dir(mg, path);
|
2010-06-24 15:04:02 +08:00
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
2009-10-02 14:29:58 +08:00
|
|
|
} else {
|
|
|
|
char *dot = strrchr(dent->d_name, '.'),
|
|
|
|
dso_name[PATH_MAX];
|
|
|
|
struct map *map;
|
2009-11-18 01:40:53 +08:00
|
|
|
char *long_name;
|
2009-10-02 14:29:58 +08:00
|
|
|
|
|
|
|
if (dot == NULL || strcmp(dot, ".ko"))
|
|
|
|
continue;
|
|
|
|
snprintf(dso_name, sizeof(dso_name), "[%.*s]",
|
|
|
|
(int)(dot - dent->d_name), dent->d_name);
|
|
|
|
|
2009-10-06 01:26:18 +08:00
|
|
|
strxfrchar(dso_name, '-', '_');
|
2011-03-31 21:56:28 +08:00
|
|
|
map = map_groups__find_by_name(mg, MAP__FUNCTION,
|
|
|
|
dso_name);
|
2009-10-02 14:29:58 +08:00
|
|
|
if (map == NULL)
|
|
|
|
continue;
|
|
|
|
|
2009-11-18 01:40:53 +08:00
|
|
|
long_name = strdup(path);
|
2010-06-24 15:04:02 +08:00
|
|
|
if (long_name == NULL) {
|
|
|
|
ret = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
2009-11-18 01:40:53 +08:00
|
|
|
dso__set_long_name(map->dso, long_name);
|
2010-07-30 02:11:30 +08:00
|
|
|
map->dso->lname_alloc = 1;
|
2010-04-19 13:32:50 +08:00
|
|
|
dso__kernel_module_get_build_id(map->dso, "");
|
2009-10-02 14:29:58 +08:00
|
|
|
}
|
|
|
|
}
|
2009-07-02 14:08:36 +08:00
|
|
|
|
2010-06-24 15:04:02 +08:00
|
|
|
out:
|
2009-10-02 14:29:58 +08:00
|
|
|
closedir(dir);
|
2010-06-24 15:04:02 +08:00
|
|
|
return ret;
|
2009-10-02 14:29:58 +08:00
|
|
|
}
|
2009-07-02 14:08:36 +08:00
|
|
|
|
2010-04-19 13:32:50 +08:00
|
|
|
static char *get_kernel_version(const char *root_dir)
|
2009-10-02 14:29:58 +08:00
|
|
|
{
|
2010-04-19 13:32:50 +08:00
|
|
|
char version[PATH_MAX];
|
|
|
|
FILE *file;
|
|
|
|
char *name, *tmp;
|
|
|
|
const char *prefix = "Linux version ";
|
|
|
|
|
|
|
|
sprintf(version, "%s/proc/version", root_dir);
|
|
|
|
file = fopen(version, "r");
|
|
|
|
if (!file)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
version[0] = '\0';
|
|
|
|
tmp = fgets(version, sizeof(version), file);
|
|
|
|
fclose(file);
|
|
|
|
|
|
|
|
name = strstr(version, prefix);
|
|
|
|
if (!name)
|
|
|
|
return NULL;
|
|
|
|
name += strlen(prefix);
|
|
|
|
tmp = strchr(name, ' ');
|
|
|
|
if (tmp)
|
|
|
|
*tmp = '\0';
|
|
|
|
|
|
|
|
return strdup(name);
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
static int machine__set_modules_path(struct machine *machine)
|
2010-04-19 13:32:50 +08:00
|
|
|
{
|
|
|
|
char *version;
|
2009-10-02 14:29:58 +08:00
|
|
|
char modules_path[PATH_MAX];
|
2009-07-02 14:08:36 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
version = get_kernel_version(machine->root_dir);
|
2010-04-19 13:32:50 +08:00
|
|
|
if (!version)
|
2009-10-02 14:29:58 +08:00
|
|
|
return -1;
|
2009-07-02 14:08:36 +08:00
|
|
|
|
2010-04-19 13:32:50 +08:00
|
|
|
snprintf(modules_path, sizeof(modules_path), "%s/lib/modules/%s/kernel",
|
2011-03-31 21:56:28 +08:00
|
|
|
machine->root_dir, version);
|
2010-04-19 13:32:50 +08:00
|
|
|
free(version);
|
2009-07-02 14:08:36 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
return map_groups__set_modules_path_dir(&machine->kmaps, modules_path);
|
2009-07-02 14:08:36 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
struct map *machine__new_module(struct machine *machine, u64 start,
|
2010-04-28 08:20:43 +08:00
|
|
|
const char *filename)
|
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 23:22:17 +08:00
|
|
|
{
|
|
|
|
struct map *map;
|
2011-03-31 21:56:28 +08:00
|
|
|
struct dso *dso = __dsos__findnew(&machine->kernel_dsos, filename);
|
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 23:22:17 +08:00
|
|
|
|
|
|
|
if (dso == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
map = map__new2(start, dso, MAP__FUNCTION);
|
|
|
|
if (map == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
if (machine__is_host(machine))
|
2012-07-22 20:14:32 +08:00
|
|
|
dso->symtab_type = DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE;
|
2010-04-19 13:32:50 +08:00
|
|
|
else
|
2012-07-22 20:14:32 +08:00
|
|
|
dso->symtab_type = DSO_BINARY_TYPE__GUEST_KMODULE;
|
2011-03-31 21:56:28 +08:00
|
|
|
map_groups__insert(&machine->kmaps, 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 23:22:17 +08:00
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
static int machine__create_modules(struct machine *machine)
|
2009-10-02 14:29:58 +08:00
|
|
|
{
|
|
|
|
char *line = NULL;
|
|
|
|
size_t n;
|
2010-04-19 13:32:50 +08:00
|
|
|
FILE *file;
|
2009-10-02 14:29:58 +08:00
|
|
|
struct map *map;
|
2010-04-19 13:32:50 +08:00
|
|
|
const char *modules;
|
|
|
|
char path[PATH_MAX];
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
if (machine__is_default_guest(machine))
|
2010-04-19 13:32:50 +08:00
|
|
|
modules = symbol_conf.default_guest_modules;
|
|
|
|
else {
|
2011-03-31 21:56:28 +08:00
|
|
|
sprintf(path, "%s/proc/modules", machine->root_dir);
|
2010-04-19 13:32:50 +08:00
|
|
|
modules = path;
|
|
|
|
}
|
2009-07-02 14:08:36 +08:00
|
|
|
|
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 20:53:51 +08:00
|
|
|
if (symbol__restricted_filename(path, "/proc/modules"))
|
|
|
|
return -1;
|
|
|
|
|
2010-04-19 13:32:50 +08:00
|
|
|
file = fopen(modules, "r");
|
2009-10-02 14:29:58 +08:00
|
|
|
if (file == NULL)
|
|
|
|
return -1;
|
2009-07-02 14:08:36 +08:00
|
|
|
|
2009-10-02 14:29:58 +08:00
|
|
|
while (!feof(file)) {
|
|
|
|
char name[PATH_MAX];
|
|
|
|
u64 start;
|
|
|
|
char *sep;
|
|
|
|
int line_len;
|
2009-07-02 14:08:36 +08:00
|
|
|
|
2009-10-02 14:29:58 +08:00
|
|
|
line_len = getline(&line, &n, file);
|
|
|
|
if (line_len < 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!line)
|
|
|
|
goto out_failure;
|
|
|
|
|
|
|
|
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';
|
|
|
|
|
|
|
|
snprintf(name, sizeof(name), "[%s]", line);
|
2011-03-31 21:56:28 +08:00
|
|
|
map = machine__new_module(machine, start, name);
|
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 23:22:17 +08:00
|
|
|
if (map == NULL)
|
2009-10-02 14:29:58 +08:00
|
|
|
goto out_delete_line;
|
2011-03-31 21:56:28 +08:00
|
|
|
dso__kernel_module_get_build_id(map->dso, machine->root_dir);
|
2009-07-02 14:08:36 +08:00
|
|
|
}
|
2009-10-02 14:29:58 +08:00
|
|
|
|
|
|
|
free(line);
|
|
|
|
fclose(file);
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
return machine__set_modules_path(machine);
|
2009-10-02 14:29:58 +08:00
|
|
|
|
|
|
|
out_delete_line:
|
|
|
|
free(line);
|
|
|
|
out_failure:
|
|
|
|
return -1;
|
2009-07-02 14:08:36 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
int dso__load_vmlinux(struct dso *dso, struct map *map,
|
2010-12-10 21:06:03 +08:00
|
|
|
const char *vmlinux, symbol_filter_t filter)
|
2009-05-29 01:55:04 +08:00
|
|
|
{
|
2012-08-11 06:22:57 +08:00
|
|
|
int err = -1;
|
|
|
|
struct symsrc ss;
|
2010-12-10 04:27:07 +08:00
|
|
|
char symfs_vmlinux[PATH_MAX];
|
2012-08-11 06:22:58 +08:00
|
|
|
enum dso_binary_type symtab_type;
|
2009-05-29 01:55:04 +08:00
|
|
|
|
2011-03-01 00:54:38 +08:00
|
|
|
snprintf(symfs_vmlinux, sizeof(symfs_vmlinux), "%s%s",
|
2010-12-10 04:27:07 +08:00
|
|
|
symbol_conf.symfs, vmlinux);
|
2009-05-29 01:55:04 +08:00
|
|
|
|
2012-08-11 06:22:56 +08:00
|
|
|
if (dso->kernel == DSO_TYPE_GUEST_KERNEL)
|
2012-08-11 06:22:58 +08:00
|
|
|
symtab_type = DSO_BINARY_TYPE__GUEST_VMLINUX;
|
2012-08-11 06:22:56 +08:00
|
|
|
else
|
2012-08-11 06:22:58 +08:00
|
|
|
symtab_type = DSO_BINARY_TYPE__VMLINUX;
|
2012-08-11 06:22:56 +08:00
|
|
|
|
2012-08-11 06:22:58 +08:00
|
|
|
if (symsrc__init(&ss, dso, symfs_vmlinux, symtab_type))
|
2012-08-11 06:22:57 +08:00
|
|
|
return -1;
|
|
|
|
|
2012-08-11 06:23:01 +08:00
|
|
|
err = dso__load_sym(dso, map, &ss, &ss, filter, 0);
|
2012-08-11 06:22:57 +08:00
|
|
|
symsrc__destroy(&ss);
|
2009-05-29 01:55:04 +08:00
|
|
|
|
2012-08-11 06:22:54 +08:00
|
|
|
if (err > 0) {
|
|
|
|
dso__set_long_name(dso, (char *)vmlinux);
|
|
|
|
dso__set_loaded(dso, map->type);
|
2010-12-10 04:27:07 +08:00
|
|
|
pr_debug("Using %s for symbols\n", symfs_vmlinux);
|
2012-08-11 06:22:54 +08:00
|
|
|
}
|
2010-02-23 03:15:39 +08:00
|
|
|
|
2009-05-29 01:55:04 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
int dso__load_vmlinux_path(struct dso *dso, struct map *map,
|
2010-02-04 02:52:00 +08:00
|
|
|
symbol_filter_t filter)
|
2010-01-28 07:05:50 +08:00
|
|
|
{
|
|
|
|
int i, err = 0;
|
2010-05-27 00:26:02 +08:00
|
|
|
char *filename;
|
2010-01-28 07:05:50 +08:00
|
|
|
|
|
|
|
pr_debug("Looking at the vmlinux_path (%d entries long)\n",
|
2010-05-27 00:26:02 +08:00
|
|
|
vmlinux_path__nr_entries + 1);
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
filename = dso__build_id_filename(dso, NULL, 0);
|
2010-05-27 00:26:02 +08:00
|
|
|
if (filename != NULL) {
|
2011-03-31 21:56:28 +08:00
|
|
|
err = dso__load_vmlinux(dso, map, filename, filter);
|
2012-08-11 06:22:52 +08:00
|
|
|
if (err > 0)
|
2010-05-27 00:26:02 +08:00
|
|
|
goto out;
|
|
|
|
free(filename);
|
|
|
|
}
|
2010-01-28 07:05:50 +08:00
|
|
|
|
|
|
|
for (i = 0; i < vmlinux_path__nr_entries; ++i) {
|
2011-03-31 21:56:28 +08:00
|
|
|
err = dso__load_vmlinux(dso, map, vmlinux_path[i], filter);
|
2010-01-28 07:05:50 +08:00
|
|
|
if (err > 0) {
|
2011-03-31 21:56:28 +08:00
|
|
|
dso__set_long_name(dso, strdup(vmlinux_path[i]));
|
2010-01-28 07:05:50 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-05-27 00:26:02 +08:00
|
|
|
out:
|
2010-01-28 07:05:50 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
static int dso__load_kernel_sym(struct dso *dso, struct map *map,
|
2010-02-04 02:52:00 +08:00
|
|
|
symbol_filter_t filter)
|
2009-05-29 01:55:19 +08:00
|
|
|
{
|
2009-11-24 02:39:10 +08:00
|
|
|
int err;
|
2010-01-15 04:30:06 +08:00
|
|
|
const char *kallsyms_filename = NULL;
|
|
|
|
char *kallsyms_allocated_filename = NULL;
|
2010-01-19 20:36:14 +08:00
|
|
|
/*
|
2010-12-08 10:39:46 +08: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 20:36:14 +08: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 10:39:46 +08:00
|
|
|
if (symbol_conf.kallsyms_name != NULL) {
|
|
|
|
kallsyms_filename = symbol_conf.kallsyms_name;
|
|
|
|
goto do_kallsyms;
|
|
|
|
}
|
|
|
|
|
2010-01-19 20:36:14 +08:00
|
|
|
if (symbol_conf.vmlinux_name != NULL) {
|
2011-03-31 21:56:28 +08:00
|
|
|
err = dso__load_vmlinux(dso, map,
|
2010-01-19 20:36:14 +08:00
|
|
|
symbol_conf.vmlinux_name, filter);
|
2010-06-04 05:35:55 +08:00
|
|
|
if (err > 0) {
|
2011-03-31 21:56:28 +08:00
|
|
|
dso__set_long_name(dso,
|
2010-06-04 05:35:55 +08:00
|
|
|
strdup(symbol_conf.vmlinux_name));
|
|
|
|
goto out_fixup;
|
|
|
|
}
|
|
|
|
return err;
|
2010-01-19 20:36:14 +08:00
|
|
|
}
|
2009-11-24 02:39:10 +08:00
|
|
|
|
|
|
|
if (vmlinux_path != NULL) {
|
2011-03-31 21:56:28 +08:00
|
|
|
err = dso__load_vmlinux_path(dso, map, filter);
|
2010-01-28 07:05:50 +08:00
|
|
|
if (err > 0)
|
|
|
|
goto out_fixup;
|
2009-11-24 02:39:10 +08:00
|
|
|
}
|
|
|
|
|
2010-12-10 04:27:07 +08:00
|
|
|
/* do not try local files if a symfs was given */
|
|
|
|
if (symbol_conf.symfs[0] != 0)
|
|
|
|
return -1;
|
|
|
|
|
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 23:22:17 +08:00
|
|
|
/*
|
|
|
|
* Say the kernel DSO was created when processing the build-id header table,
|
|
|
|
* we have a build-id, so check if it is the same as the running kernel,
|
|
|
|
* using it if it is.
|
|
|
|
*/
|
2011-03-31 21:56:28 +08:00
|
|
|
if (dso->has_build_id) {
|
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 23:22:17 +08:00
|
|
|
u8 kallsyms_build_id[BUILD_ID_SIZE];
|
2010-01-15 04:30:06 +08:00
|
|
|
char sbuild_id[BUILD_ID_SIZE * 2 + 1];
|
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 23:22:17 +08:00
|
|
|
|
|
|
|
if (sysfs__read_build_id("/sys/kernel/notes", kallsyms_build_id,
|
2010-01-15 04:30:05 +08:00
|
|
|
sizeof(kallsyms_build_id)) == 0) {
|
2011-03-31 21:56:28 +08:00
|
|
|
if (dso__build_id_equal(dso, kallsyms_build_id)) {
|
2010-01-15 04:30:06 +08:00
|
|
|
kallsyms_filename = "/proc/kallsyms";
|
2010-01-15 04:30:05 +08:00
|
|
|
goto do_kallsyms;
|
2010-01-15 04:30:06 +08:00
|
|
|
}
|
2010-01-15 04:30:05 +08:00
|
|
|
}
|
2010-01-19 20:36:14 +08:00
|
|
|
/*
|
|
|
|
* Now look if we have it on the build-id cache in
|
|
|
|
* $HOME/.debug/[kernel.kallsyms].
|
|
|
|
*/
|
2011-03-31 21:56:28 +08:00
|
|
|
build_id__sprintf(dso->build_id, sizeof(dso->build_id),
|
2010-01-15 04:30:06 +08:00
|
|
|
sbuild_id);
|
|
|
|
|
|
|
|
if (asprintf(&kallsyms_allocated_filename,
|
|
|
|
"%s/.debug/[kernel.kallsyms]/%s",
|
2010-02-23 03:15:39 +08:00
|
|
|
getenv("HOME"), sbuild_id) == -1) {
|
|
|
|
pr_err("Not enough memory for kallsyms file lookup\n");
|
2010-01-19 20:36:14 +08:00
|
|
|
return -1;
|
2010-02-23 03:15:39 +08:00
|
|
|
}
|
2010-01-19 20:36:14 +08:00
|
|
|
|
2010-01-23 00:35:02 +08:00
|
|
|
kallsyms_filename = kallsyms_allocated_filename;
|
|
|
|
|
2010-01-19 20:36:14 +08:00
|
|
|
if (access(kallsyms_filename, F_OK)) {
|
2010-02-23 03:15:39 +08:00
|
|
|
pr_err("No kallsyms or vmlinux with build-id %s "
|
|
|
|
"was found\n", sbuild_id);
|
2010-01-15 04:30:06 +08:00
|
|
|
free(kallsyms_allocated_filename);
|
2010-01-19 20:36:14 +08:00
|
|
|
return -1;
|
2010-01-15 04:30:06 +08:00
|
|
|
}
|
2010-01-19 20:36:14 +08:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Last resort, if we don't have a build-id and couldn't find
|
|
|
|
* any vmlinux file, try the running kernel kallsyms table.
|
|
|
|
*/
|
2010-01-15 04:30:06 +08:00
|
|
|
kallsyms_filename = "/proc/kallsyms";
|
|
|
|
}
|
2009-10-02 14:29:58 +08:00
|
|
|
|
2009-11-24 02:39:10 +08:00
|
|
|
do_kallsyms:
|
2011-03-31 21:56:28 +08:00
|
|
|
err = dso__load_kallsyms(dso, kallsyms_filename, map, filter);
|
2010-02-23 03:15:39 +08:00
|
|
|
if (err > 0)
|
|
|
|
pr_debug("Using %s for symbols\n", kallsyms_filename);
|
2010-01-19 20:36:14 +08:00
|
|
|
free(kallsyms_allocated_filename);
|
2009-10-02 14:29:58 +08:00
|
|
|
|
|
|
|
if (err > 0) {
|
2012-08-11 06:22:53 +08:00
|
|
|
dso__set_long_name(dso, strdup("[kernel.kallsyms]"));
|
2009-11-24 02:39:10 +08:00
|
|
|
out_fixup:
|
2009-11-28 02:29:17 +08:00
|
|
|
map__fixup_start(map);
|
|
|
|
map__fixup_end(map);
|
2009-10-02 14:29:58 +08:00
|
|
|
}
|
2009-08-07 01:43:17 +08:00
|
|
|
|
2009-05-29 01:55:19 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
static int dso__load_guest_kernel_sym(struct dso *dso, struct map *map,
|
|
|
|
symbol_filter_t filter)
|
2010-04-19 13:32:50 +08:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
const char *kallsyms_filename = NULL;
|
2010-04-28 08:17:50 +08:00
|
|
|
struct machine *machine;
|
2010-04-19 13:32:50 +08: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 08:17:50 +08:00
|
|
|
machine = map->groups->machine;
|
2010-04-19 13:32:50 +08:00
|
|
|
|
2010-04-28 08:17:50 +08:00
|
|
|
if (machine__is_default_guest(machine)) {
|
2010-04-19 13:32:50 +08: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 21:56:28 +08:00
|
|
|
err = dso__load_vmlinux(dso, map,
|
2010-04-19 13:32:50 +08:00
|
|
|
symbol_conf.default_guest_vmlinux_name, filter);
|
|
|
|
goto out_try_fixup;
|
|
|
|
}
|
|
|
|
|
|
|
|
kallsyms_filename = symbol_conf.default_guest_kallsyms;
|
|
|
|
if (!kallsyms_filename)
|
|
|
|
return -1;
|
|
|
|
} else {
|
2010-04-28 08:17:50 +08:00
|
|
|
sprintf(path, "%s/proc/kallsyms", machine->root_dir);
|
2010-04-19 13:32:50 +08:00
|
|
|
kallsyms_filename = path;
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
err = dso__load_kallsyms(dso, kallsyms_filename, map, filter);
|
2010-04-19 13:32:50 +08:00
|
|
|
if (err > 0)
|
|
|
|
pr_debug("Using %s for symbols\n", kallsyms_filename);
|
|
|
|
|
|
|
|
out_try_fixup:
|
|
|
|
if (err > 0) {
|
|
|
|
if (kallsyms_filename != NULL) {
|
2010-04-28 08:19:05 +08:00
|
|
|
machine__mmap_name(machine, path, sizeof(path));
|
2011-03-31 21:56:28 +08:00
|
|
|
dso__set_long_name(dso, strdup(path));
|
2010-04-19 13:32:50 +08:00
|
|
|
}
|
|
|
|
map__fixup_start(map);
|
|
|
|
map__fixup_end(map);
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
2009-08-12 16:03:49 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
size_t machines__fprintf_dsos(struct rb_root *machines, FILE *fp)
|
2009-11-28 02:29:14 +08:00
|
|
|
{
|
2010-04-19 13:32:50 +08:00
|
|
|
struct rb_node *nd;
|
2010-04-28 08:22:44 +08:00
|
|
|
size_t ret = 0;
|
2010-04-19 13:32:50 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
for (nd = rb_first(machines); nd; nd = rb_next(nd)) {
|
2010-04-28 08:17:50 +08:00
|
|
|
struct machine *pos = rb_entry(nd, struct machine, rb_node);
|
2010-04-28 08:22:44 +08:00
|
|
|
ret += __dsos__fprintf(&pos->kernel_dsos, fp);
|
|
|
|
ret += __dsos__fprintf(&pos->user_dsos, fp);
|
2010-04-19 13:32:50 +08:00
|
|
|
}
|
2010-04-28 08:22:44 +08:00
|
|
|
|
|
|
|
return ret;
|
2009-11-28 02:29:14 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
size_t machine__fprintf_dsos_buildid(struct machine *machine, FILE *fp,
|
|
|
|
bool with_hits)
|
2010-05-20 00:41:23 +08:00
|
|
|
{
|
2011-03-31 21:56:28 +08:00
|
|
|
return __dsos__fprintf_buildid(&machine->kernel_dsos, fp, with_hits) +
|
|
|
|
__dsos__fprintf_buildid(&machine->user_dsos, fp, with_hits);
|
2010-05-20 00:41:23 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
size_t machines__fprintf_dsos_buildid(struct rb_root *machines,
|
|
|
|
FILE *fp, bool with_hits)
|
2009-11-28 02:29:14 +08:00
|
|
|
{
|
2010-04-19 13:32:50 +08:00
|
|
|
struct rb_node *nd;
|
|
|
|
size_t ret = 0;
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
for (nd = rb_first(machines); nd; nd = rb_next(nd)) {
|
2010-04-28 08:17:50 +08:00
|
|
|
struct machine *pos = rb_entry(nd, struct machine, rb_node);
|
2010-05-20 00:41:23 +08:00
|
|
|
ret += machine__fprintf_dsos_buildid(pos, fp, with_hits);
|
2010-04-19 13:32:50 +08:00
|
|
|
}
|
|
|
|
return ret;
|
2009-11-28 02:29:14 +08:00
|
|
|
}
|
|
|
|
|
2011-06-02 03:43:46 +08:00
|
|
|
static struct dso *machine__get_kernel(struct machine *machine)
|
2009-08-12 16:03:49 +08:00
|
|
|
{
|
2010-04-19 13:32:50 +08:00
|
|
|
const char *vmlinux_name = NULL;
|
|
|
|
struct dso *kernel;
|
2009-08-12 16:03:49 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
if (machine__is_host(machine)) {
|
2010-04-19 13:32:50 +08:00
|
|
|
vmlinux_name = symbol_conf.vmlinux_name;
|
2011-06-02 03:43:46 +08:00
|
|
|
if (!vmlinux_name)
|
|
|
|
vmlinux_name = "[kernel.kallsyms]";
|
|
|
|
|
|
|
|
kernel = dso__kernel_findnew(machine, vmlinux_name,
|
|
|
|
"[kernel]",
|
|
|
|
DSO_TYPE_KERNEL);
|
2010-04-19 13:32:50 +08:00
|
|
|
} else {
|
2011-06-02 03:43:46 +08:00
|
|
|
char bf[PATH_MAX];
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
if (machine__is_default_guest(machine))
|
2010-04-19 13:32:50 +08:00
|
|
|
vmlinux_name = symbol_conf.default_guest_vmlinux_name;
|
2011-06-02 03:43:46 +08:00
|
|
|
if (!vmlinux_name)
|
|
|
|
vmlinux_name = machine__mmap_name(machine, bf,
|
|
|
|
sizeof(bf));
|
|
|
|
|
|
|
|
kernel = dso__kernel_findnew(machine, vmlinux_name,
|
|
|
|
"[guest.kernel]",
|
|
|
|
DSO_TYPE_GUEST_KERNEL);
|
2010-02-04 02:52:02 +08:00
|
|
|
}
|
2009-08-12 16:03:49 +08:00
|
|
|
|
2011-06-02 03:43:46 +08:00
|
|
|
if (kernel != NULL && (!kernel->has_build_id))
|
2011-03-31 21:56:28 +08:00
|
|
|
dso__read_running_kernel_build_id(kernel, machine);
|
2011-06-02 03:43:46 +08:00
|
|
|
|
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-12 00:50:39 +08:00
|
|
|
return kernel;
|
|
|
|
}
|
|
|
|
|
2010-11-25 19:27:25 +08:00
|
|
|
struct process_args {
|
|
|
|
u64 start;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int symbol__in_kernel(void *arg, const char *name,
|
2012-09-11 06:15:03 +08:00
|
|
|
char type __maybe_unused, u64 start)
|
2010-11-25 19:27:25 +08:00
|
|
|
{
|
|
|
|
struct process_args *args = arg;
|
|
|
|
|
|
|
|
if (strchr(name, '['))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
args->start = start;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Figure out the start address of kernel map from /proc/kallsyms */
|
|
|
|
static u64 machine__get_kernel_start_addr(struct machine *machine)
|
|
|
|
{
|
|
|
|
const char *filename;
|
|
|
|
char path[PATH_MAX];
|
|
|
|
struct process_args args;
|
|
|
|
|
|
|
|
if (machine__is_host(machine)) {
|
|
|
|
filename = "/proc/kallsyms";
|
|
|
|
} else {
|
|
|
|
if (machine__is_default_guest(machine))
|
|
|
|
filename = (char *)symbol_conf.default_guest_kallsyms;
|
|
|
|
else {
|
|
|
|
sprintf(path, "%s/proc/kallsyms", machine->root_dir);
|
|
|
|
filename = path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 20:53:51 +08:00
|
|
|
if (symbol__restricted_filename(filename, "/proc/kallsyms"))
|
|
|
|
return 0;
|
|
|
|
|
2010-11-25 19:27:25 +08:00
|
|
|
if (kallsyms__parse(filename, &args, symbol__in_kernel) <= 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return args.start;
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel)
|
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-12 00:50:39 +08:00
|
|
|
{
|
2010-01-05 02:19:29 +08:00
|
|
|
enum map_type type;
|
2011-03-31 21:56:28 +08:00
|
|
|
u64 start = machine__get_kernel_start_addr(machine);
|
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-12 00:50:39 +08:00
|
|
|
|
2010-01-05 02:19:29 +08:00
|
|
|
for (type = 0; type < MAP__NR_TYPES; ++type) {
|
2010-02-04 02:52:00 +08:00
|
|
|
struct kmap *kmap;
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
machine->vmlinux_maps[type] = map__new2(start, kernel, type);
|
|
|
|
if (machine->vmlinux_maps[type] == NULL)
|
2010-01-05 02:19:29 +08:00
|
|
|
return -1;
|
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-12 00:50:39 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
machine->vmlinux_maps[type]->map_ip =
|
|
|
|
machine->vmlinux_maps[type]->unmap_ip =
|
|
|
|
identity__map_ip;
|
|
|
|
kmap = map__kmap(machine->vmlinux_maps[type]);
|
|
|
|
kmap->kmaps = &machine->kmaps;
|
|
|
|
map_groups__insert(&machine->kmaps,
|
|
|
|
machine->vmlinux_maps[type]);
|
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-12 00:50:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2009-11-19 06:20:53 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
void machine__destroy_kernel_maps(struct machine *machine)
|
perf session: Free the ref_reloc_sym memory at the right place
Which is at perf_session__destroy_kernel_maps, counterpart to the
perf_session__create_kernel_maps where the kmap structure is located, just
after the vmlinux_maps.
Make it also check if the kernel maps were actually created, which may not
be the case if, for instance, perf_session__new can't complete due to
permission problems in, for instance, a 'perf report' case, when a
segfault will take place, that is how this was noticed.
The problem was introduced in d65a458, thus post .35.
This also adds code to release guest machines as them are also created
in perf_session__create_kernel_maps, so should be deleted on this newly
introduced counterpart, perf_session__destroy_kernel_maps.
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-08-03 05:18:28 +08:00
|
|
|
{
|
|
|
|
enum map_type type;
|
|
|
|
|
|
|
|
for (type = 0; type < MAP__NR_TYPES; ++type) {
|
|
|
|
struct kmap *kmap;
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
if (machine->vmlinux_maps[type] == NULL)
|
perf session: Free the ref_reloc_sym memory at the right place
Which is at perf_session__destroy_kernel_maps, counterpart to the
perf_session__create_kernel_maps where the kmap structure is located, just
after the vmlinux_maps.
Make it also check if the kernel maps were actually created, which may not
be the case if, for instance, perf_session__new can't complete due to
permission problems in, for instance, a 'perf report' case, when a
segfault will take place, that is how this was noticed.
The problem was introduced in d65a458, thus post .35.
This also adds code to release guest machines as them are also created
in perf_session__create_kernel_maps, so should be deleted on this newly
introduced counterpart, perf_session__destroy_kernel_maps.
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-08-03 05:18:28 +08:00
|
|
|
continue;
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
kmap = map__kmap(machine->vmlinux_maps[type]);
|
|
|
|
map_groups__remove(&machine->kmaps,
|
|
|
|
machine->vmlinux_maps[type]);
|
perf session: Free the ref_reloc_sym memory at the right place
Which is at perf_session__destroy_kernel_maps, counterpart to the
perf_session__create_kernel_maps where the kmap structure is located, just
after the vmlinux_maps.
Make it also check if the kernel maps were actually created, which may not
be the case if, for instance, perf_session__new can't complete due to
permission problems in, for instance, a 'perf report' case, when a
segfault will take place, that is how this was noticed.
The problem was introduced in d65a458, thus post .35.
This also adds code to release guest machines as them are also created
in perf_session__create_kernel_maps, so should be deleted on this newly
introduced counterpart, perf_session__destroy_kernel_maps.
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-08-03 05:18:28 +08:00
|
|
|
if (kmap->ref_reloc_sym) {
|
|
|
|
/*
|
|
|
|
* ref_reloc_sym is shared among all maps, so free just
|
|
|
|
* on one of them.
|
|
|
|
*/
|
|
|
|
if (type == MAP__FUNCTION) {
|
|
|
|
free((char *)kmap->ref_reloc_sym->name);
|
|
|
|
kmap->ref_reloc_sym->name = NULL;
|
|
|
|
free(kmap->ref_reloc_sym);
|
|
|
|
}
|
|
|
|
kmap->ref_reloc_sym = NULL;
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
map__delete(machine->vmlinux_maps[type]);
|
|
|
|
machine->vmlinux_maps[type] = NULL;
|
perf session: Free the ref_reloc_sym memory at the right place
Which is at perf_session__destroy_kernel_maps, counterpart to the
perf_session__create_kernel_maps where the kmap structure is located, just
after the vmlinux_maps.
Make it also check if the kernel maps were actually created, which may not
be the case if, for instance, perf_session__new can't complete due to
permission problems in, for instance, a 'perf report' case, when a
segfault will take place, that is how this was noticed.
The problem was introduced in d65a458, thus post .35.
This also adds code to release guest machines as them are also created
in perf_session__create_kernel_maps, so should be deleted on this newly
introduced counterpart, perf_session__destroy_kernel_maps.
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-08-03 05:18:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
int machine__create_kernel_maps(struct machine *machine)
|
2010-04-30 02:25:23 +08:00
|
|
|
{
|
2011-06-02 03:43:46 +08:00
|
|
|
struct dso *kernel = machine__get_kernel(machine);
|
2010-04-30 02:25:23 +08:00
|
|
|
|
|
|
|
if (kernel == NULL ||
|
2011-03-31 21:56:28 +08:00
|
|
|
__machine__create_kernel_maps(machine, kernel) < 0)
|
2010-04-30 02:25:23 +08:00
|
|
|
return -1;
|
|
|
|
|
2012-07-21 07:25:46 +08:00
|
|
|
if (symbol_conf.use_modules && machine__create_modules(machine) < 0) {
|
|
|
|
if (machine__is_host(machine))
|
|
|
|
pr_debug("Problems creating module maps, "
|
|
|
|
"continuing anyway...\n");
|
|
|
|
else
|
|
|
|
pr_debug("Problems creating module maps for guest %d, "
|
|
|
|
"continuing anyway...\n", machine->pid);
|
|
|
|
}
|
|
|
|
|
2010-04-30 02:25:23 +08:00
|
|
|
/*
|
|
|
|
* Now that we have all the maps created, just set the ->end of them:
|
|
|
|
*/
|
2011-03-31 21:56:28 +08:00
|
|
|
map_groups__fixup_end(&machine->kmaps);
|
2010-04-30 02:25:23 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-11-24 02:39:10 +08:00
|
|
|
static void vmlinux_path__exit(void)
|
|
|
|
{
|
|
|
|
while (--vmlinux_path__nr_entries >= 0) {
|
|
|
|
free(vmlinux_path[vmlinux_path__nr_entries]);
|
|
|
|
vmlinux_path[vmlinux_path__nr_entries] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(vmlinux_path);
|
|
|
|
vmlinux_path = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vmlinux_path__init(void)
|
|
|
|
{
|
|
|
|
struct utsname uts;
|
|
|
|
char bf[PATH_MAX];
|
|
|
|
|
|
|
|
vmlinux_path = malloc(sizeof(char *) * 5);
|
|
|
|
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-10 04:27:07 +08:00
|
|
|
|
|
|
|
/* only try running kernel version if no symfs was given */
|
|
|
|
if (symbol_conf.symfs[0] != 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (uname(&uts) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2009-11-24 02:39:10 +08:00
|
|
|
snprintf(bf, sizeof(bf), "/boot/vmlinux-%s", uts.release);
|
|
|
|
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), "/lib/modules/%s/build/vmlinux", uts.release);
|
|
|
|
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",
|
|
|
|
uts.release);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp)
|
2010-03-15 22:46:58 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
size_t printed = 0;
|
2011-03-31 21:56:28 +08:00
|
|
|
struct dso *kdso = machine->vmlinux_maps[MAP__FUNCTION]->dso;
|
2010-05-27 00:26:02 +08:00
|
|
|
|
|
|
|
if (kdso->has_build_id) {
|
|
|
|
char filename[PATH_MAX];
|
|
|
|
if (dso__build_id_filename(kdso, filename, sizeof(filename)))
|
|
|
|
printed += fprintf(fp, "[0] %s\n", filename);
|
|
|
|
}
|
2010-03-15 22:46:58 +08:00
|
|
|
|
|
|
|
for (i = 0; i < vmlinux_path__nr_entries; ++i)
|
2010-05-27 00:26:02 +08:00
|
|
|
printed += fprintf(fp, "[%d] %s\n",
|
|
|
|
i + kdso->has_build_id, vmlinux_path[i]);
|
2010-03-15 22:46:58 +08:00
|
|
|
|
|
|
|
return printed;
|
|
|
|
}
|
|
|
|
|
2009-12-16 06:04:40 +08:00
|
|
|
static int setup_list(struct strlist **list, const char *list_str,
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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 20:53:51 +08: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;
|
|
|
|
}
|
|
|
|
|
2009-12-16 06:04:39 +08:00
|
|
|
int symbol__init(void)
|
2009-11-19 06:20:53 +08:00
|
|
|
{
|
2010-12-10 04:27:07 +08:00
|
|
|
const char *symfs;
|
|
|
|
|
2010-09-10 00:30:59 +08:00
|
|
|
if (symbol_conf.initialized)
|
|
|
|
return 0;
|
|
|
|
|
2012-09-11 06:15:01 +08:00
|
|
|
symbol_conf.priv_size = PERF_ALIGN(symbol_conf.priv_size, sizeof(u64));
|
2011-03-30 01:18:39 +08:00
|
|
|
|
2012-08-06 12:41:19 +08:00
|
|
|
symbol__elf_init();
|
|
|
|
|
2009-12-16 06:04:39 +08:00
|
|
|
if (symbol_conf.sort_by_name)
|
|
|
|
symbol_conf.priv_size += (sizeof(struct symbol_name_rb_node) -
|
|
|
|
sizeof(struct symbol));
|
2009-11-24 22:05:15 +08:00
|
|
|
|
2009-12-16 06:04:39 +08:00
|
|
|
if (symbol_conf.try_vmlinux_path && vmlinux_path__init() < 0)
|
2009-11-19 06:20:53 +08:00
|
|
|
return -1;
|
|
|
|
|
2009-12-16 06:04:41 +08: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-16 06:04:40 +08: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;
|
|
|
|
|
|
|
|
if (setup_list(&symbol_conf.sym_list,
|
|
|
|
symbol_conf.sym_list_str, "symbol") < 0)
|
|
|
|
goto out_free_comm_list;
|
|
|
|
|
2010-12-10 04:27:07 +08: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 20:53:51 +08:00
|
|
|
symbol_conf.kptr_restrict = symbol__read_kptr_restrict();
|
|
|
|
|
2010-09-10 00:30:59 +08: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-14 05:50:29 +08:00
|
|
|
return 0;
|
2009-12-16 06:04:40 +08:00
|
|
|
|
|
|
|
out_free_comm_list:
|
|
|
|
strlist__delete(symbol_conf.comm_list);
|
2011-12-12 23:16:52 +08:00
|
|
|
out_free_dso_list:
|
|
|
|
strlist__delete(symbol_conf.dso_list);
|
2009-12-16 06:04:40 +08: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-14 05:50:29 +08:00
|
|
|
}
|
|
|
|
|
2010-07-31 05:31:28 +08:00
|
|
|
void symbol__exit(void)
|
|
|
|
{
|
2010-09-10 00:30:59 +08:00
|
|
|
if (!symbol_conf.initialized)
|
|
|
|
return;
|
2010-07-31 05:31:28 +08:00
|
|
|
strlist__delete(symbol_conf.sym_list);
|
|
|
|
strlist__delete(symbol_conf.dso_list);
|
|
|
|
strlist__delete(symbol_conf.comm_list);
|
|
|
|
vmlinux_path__exit();
|
|
|
|
symbol_conf.sym_list = symbol_conf.dso_list = symbol_conf.comm_list = NULL;
|
2010-09-10 00:30:59 +08:00
|
|
|
symbol_conf.initialized = false;
|
2010-07-31 05:31:28 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
int machines__create_kernel_maps(struct rb_root *machines, pid_t pid)
|
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-14 05:50:29 +08:00
|
|
|
{
|
2011-03-31 21:56:28 +08:00
|
|
|
struct machine *machine = machines__findnew(machines, pid);
|
2010-02-04 02:52:00 +08:00
|
|
|
|
2010-04-28 08:17:50 +08:00
|
|
|
if (machine == NULL)
|
2010-04-19 13:32:50 +08:00
|
|
|
return -1;
|
2009-11-24 02:39:10 +08:00
|
|
|
|
2010-04-30 02:25:23 +08:00
|
|
|
return machine__create_kernel_maps(machine);
|
2009-08-12 16:03:49 +08:00
|
|
|
}
|
2010-03-26 06:59:00 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
int machines__create_guest_kernel_maps(struct rb_root *machines)
|
2010-04-19 13:32:50 +08:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
struct dirent **namelist = NULL;
|
|
|
|
int i, items = 0;
|
|
|
|
char path[PATH_MAX];
|
|
|
|
pid_t pid;
|
2012-07-30 10:54:35 +08:00
|
|
|
char *endp;
|
2010-04-19 13:32:50 +08:00
|
|
|
|
|
|
|
if (symbol_conf.default_guest_vmlinux_name ||
|
|
|
|
symbol_conf.default_guest_modules ||
|
|
|
|
symbol_conf.default_guest_kallsyms) {
|
2011-03-31 21:56:28 +08:00
|
|
|
machines__create_kernel_maps(machines, DEFAULT_GUEST_KERNEL_ID);
|
2010-04-19 13:32:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (symbol_conf.guestmount) {
|
|
|
|
items = scandir(symbol_conf.guestmount, &namelist, NULL, NULL);
|
|
|
|
if (items <= 0)
|
|
|
|
return -ENOENT;
|
|
|
|
for (i = 0; i < items; i++) {
|
|
|
|
if (!isdigit(namelist[i]->d_name[0])) {
|
|
|
|
/* Filter out . and .. */
|
|
|
|
continue;
|
|
|
|
}
|
2012-07-30 10:54:35 +08:00
|
|
|
pid = (pid_t)strtol(namelist[i]->d_name, &endp, 10);
|
|
|
|
if ((*endp != '\0') ||
|
|
|
|
(endp == namelist[i]->d_name) ||
|
|
|
|
(errno == ERANGE)) {
|
|
|
|
pr_debug("invalid directory (%s). Skipping.\n",
|
|
|
|
namelist[i]->d_name);
|
|
|
|
continue;
|
|
|
|
}
|
2010-04-19 13:32:50 +08:00
|
|
|
sprintf(path, "%s/%s/proc/kallsyms",
|
|
|
|
symbol_conf.guestmount,
|
|
|
|
namelist[i]->d_name);
|
|
|
|
ret = access(path, R_OK);
|
|
|
|
if (ret) {
|
|
|
|
pr_debug("Can't access file %s\n", path);
|
|
|
|
goto failure;
|
|
|
|
}
|
2011-03-31 21:56:28 +08:00
|
|
|
machines__create_kernel_maps(machines, pid);
|
2010-04-19 13:32:50 +08:00
|
|
|
}
|
|
|
|
failure:
|
|
|
|
free(namelist);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2010-04-30 02:25:23 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
void machines__destroy_guest_kernel_maps(struct rb_root *machines)
|
perf session: Free the ref_reloc_sym memory at the right place
Which is at perf_session__destroy_kernel_maps, counterpart to the
perf_session__create_kernel_maps where the kmap structure is located, just
after the vmlinux_maps.
Make it also check if the kernel maps were actually created, which may not
be the case if, for instance, perf_session__new can't complete due to
permission problems in, for instance, a 'perf report' case, when a
segfault will take place, that is how this was noticed.
The problem was introduced in d65a458, thus post .35.
This also adds code to release guest machines as them are also created
in perf_session__create_kernel_maps, so should be deleted on this newly
introduced counterpart, perf_session__destroy_kernel_maps.
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-08-03 05:18:28 +08:00
|
|
|
{
|
2011-03-31 21:56:28 +08:00
|
|
|
struct rb_node *next = rb_first(machines);
|
perf session: Free the ref_reloc_sym memory at the right place
Which is at perf_session__destroy_kernel_maps, counterpart to the
perf_session__create_kernel_maps where the kmap structure is located, just
after the vmlinux_maps.
Make it also check if the kernel maps were actually created, which may not
be the case if, for instance, perf_session__new can't complete due to
permission problems in, for instance, a 'perf report' case, when a
segfault will take place, that is how this was noticed.
The problem was introduced in d65a458, thus post .35.
This also adds code to release guest machines as them are also created
in perf_session__create_kernel_maps, so should be deleted on this newly
introduced counterpart, perf_session__destroy_kernel_maps.
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-08-03 05:18:28 +08:00
|
|
|
|
|
|
|
while (next) {
|
|
|
|
struct machine *pos = rb_entry(next, struct machine, rb_node);
|
|
|
|
|
|
|
|
next = rb_next(&pos->rb_node);
|
2011-03-31 21:56:28 +08:00
|
|
|
rb_erase(&pos->rb_node, machines);
|
perf session: Free the ref_reloc_sym memory at the right place
Which is at perf_session__destroy_kernel_maps, counterpart to the
perf_session__create_kernel_maps where the kmap structure is located, just
after the vmlinux_maps.
Make it also check if the kernel maps were actually created, which may not
be the case if, for instance, perf_session__new can't complete due to
permission problems in, for instance, a 'perf report' case, when a
segfault will take place, that is how this was noticed.
The problem was introduced in d65a458, thus post .35.
This also adds code to release guest machines as them are also created
in perf_session__create_kernel_maps, so should be deleted on this newly
introduced counterpart, perf_session__destroy_kernel_maps.
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-08-03 05:18:28 +08:00
|
|
|
machine__delete(pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
int machine__load_kallsyms(struct machine *machine, const char *filename,
|
2010-04-30 02:25:23 +08:00
|
|
|
enum map_type type, symbol_filter_t filter)
|
|
|
|
{
|
2011-03-31 21:56:28 +08:00
|
|
|
struct map *map = machine->vmlinux_maps[type];
|
2010-04-30 02:25:23 +08:00
|
|
|
int ret = dso__load_kallsyms(map->dso, filename, map, filter);
|
|
|
|
|
|
|
|
if (ret > 0) {
|
|
|
|
dso__set_loaded(map->dso, type);
|
|
|
|
/*
|
|
|
|
* Since /proc/kallsyms will have multiple sessions for the
|
|
|
|
* kernel, with modules between them, fixup the end of all
|
|
|
|
* sections.
|
|
|
|
*/
|
2011-03-31 21:56:28 +08:00
|
|
|
__map_groups__fixup_end(&machine->kmaps, type);
|
2010-04-30 02:25:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
int machine__load_vmlinux_path(struct machine *machine, enum map_type type,
|
2010-04-30 02:25:23 +08:00
|
|
|
symbol_filter_t filter)
|
|
|
|
{
|
2011-03-31 21:56:28 +08:00
|
|
|
struct map *map = machine->vmlinux_maps[type];
|
2010-04-30 02:25:23 +08:00
|
|
|
int ret = dso__load_vmlinux_path(map->dso, map, filter);
|
|
|
|
|
|
|
|
if (ret > 0) {
|
|
|
|
dso__set_loaded(map->dso, type);
|
|
|
|
map__reloc_vmlinux(map);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|