License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 21:07:57 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2010-03-26 05:59:00 +07:00
|
|
|
#include <dirent.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2017-04-17 21:39:06 +07:00
|
|
|
#include <linux/kernel.h>
|
2010-03-26 05:59:00 +07:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
2011-01-23 05:37:02 +07:00
|
|
|
#include <inttypes.h>
|
2016-08-26 02:09:21 +07:00
|
|
|
#include "annotate.h"
|
2010-05-20 22:15:33 +07:00
|
|
|
#include "build-id.h"
|
2012-02-10 08:10:17 +07:00
|
|
|
#include "util.h"
|
2010-07-21 00:42:52 +07:00
|
|
|
#include "debug.h"
|
2012-11-09 21:32:52 +07:00
|
|
|
#include "machine.h"
|
2009-05-29 00:55:04 +07:00
|
|
|
#include "symbol.h"
|
2010-03-26 05:59:00 +07:00
|
|
|
#include "strlist.h"
|
2015-03-24 22:52:41 +07:00
|
|
|
#include "intlist.h"
|
2017-07-06 08:48:08 +07:00
|
|
|
#include "namespaces.h"
|
2014-08-12 13:40:45 +07:00
|
|
|
#include "header.h"
|
2017-04-18 21:33:48 +07:00
|
|
|
#include "path.h"
|
2017-04-18 02:10:49 +07:00
|
|
|
#include "sane_ctype.h"
|
2009-05-29 00:55:04 +07:00
|
|
|
|
|
|
|
#include <elf.h>
|
2009-11-19 05:20:52 +07:00
|
|
|
#include <limits.h>
|
2013-12-11 19:15:00 +07:00
|
|
|
#include <symbol/kallsyms.h>
|
2009-10-02 13:29:58 +07:00
|
|
|
#include <sys/utsname.h>
|
2009-08-05 19:05:16 +07:00
|
|
|
|
2016-09-02 05:25:52 +07:00
|
|
|
static int dso__load_kernel_sym(struct dso *dso, struct map *map);
|
|
|
|
static int dso__load_guest_kernel_sym(struct dso *dso, struct map *map);
|
2016-09-02 03:54:31 +07:00
|
|
|
static bool symbol__is_idle(const char *name);
|
|
|
|
|
2012-12-08 03:39:39 +07:00
|
|
|
int vmlinux_path__nr_entries;
|
|
|
|
char **vmlinux_path;
|
2009-10-02 13:29:58 +07:00
|
|
|
|
2009-12-16 05:04:39 +07:00
|
|
|
struct symbol_conf symbol_conf = {
|
2013-12-24 14:19:25 +07:00
|
|
|
.use_modules = true,
|
|
|
|
.try_vmlinux_path = true,
|
|
|
|
.annotate_src = true,
|
|
|
|
.demangle = true,
|
2014-09-13 11:15:05 +07:00
|
|
|
.demangle_kernel = false,
|
2013-12-24 14:19:25 +07:00
|
|
|
.cumulate_callchain = true,
|
2014-06-27 23:26:58 +07:00
|
|
|
.show_hist_headers = true,
|
2013-12-24 14:19:25 +07:00
|
|
|
.symfs = "",
|
2015-11-29 21:24:17 +07:00
|
|
|
.event_group = true,
|
2017-10-19 18:38:36 +07:00
|
|
|
.inline_name = true,
|
2009-11-24 21:05:15 +07:00
|
|
|
};
|
|
|
|
|
2012-07-22 19:14:32 +07: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,
|
2017-07-06 08:48:13 +07:00
|
|
|
DSO_BINARY_TYPE__BUILD_ID_CACHE_DEBUGINFO,
|
2012-07-22 19:14:32 +07:00
|
|
|
DSO_BINARY_TYPE__FEDORA_DEBUGINFO,
|
|
|
|
DSO_BINARY_TYPE__UBUNTU_DEBUGINFO,
|
|
|
|
DSO_BINARY_TYPE__BUILDID_DEBUGINFO,
|
|
|
|
DSO_BINARY_TYPE__SYSTEM_PATH_DSO,
|
|
|
|
DSO_BINARY_TYPE__GUEST_KMODULE,
|
2014-11-04 08:14:27 +07:00
|
|
|
DSO_BINARY_TYPE__GUEST_KMODULE_COMP,
|
2012-07-22 19:14:32 +07:00
|
|
|
DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE,
|
2014-11-04 08:14:27 +07:00
|
|
|
DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP,
|
2013-09-18 20:56:14 +07:00
|
|
|
DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO,
|
2012-07-22 19:14:32 +07:00
|
|
|
DSO_BINARY_TYPE__NOT_FOUND,
|
|
|
|
};
|
|
|
|
|
2012-08-01 19:47:57 +07:00
|
|
|
#define DSO_BINARY_TYPE__SYMTAB_CNT ARRAY_SIZE(binary_type_symtab)
|
2012-07-22 19:14:32 +07:00
|
|
|
|
2010-01-05 01:19:27 +07:00
|
|
|
bool symbol_type__is_a(char symbol_type, enum map_type map_type)
|
2009-12-11 23:50:37 +07:00
|
|
|
{
|
2011-08-24 13:40:16 +07:00
|
|
|
symbol_type = toupper(symbol_type);
|
|
|
|
|
2009-12-11 23:50:37 +07:00
|
|
|
switch (map_type) {
|
|
|
|
case MAP__FUNCTION:
|
|
|
|
return symbol_type == 'T' || symbol_type == 'W';
|
perf symbols: Add support for 'variable' symtabs
Example:
{
u64 addr = strtoull(sym_filter, NULL, 16);
struct map *map = map_groups__find(kmaps, MAP__VARIABLE, addr);
if (map == NULL)
pr_err("couldn't find map!\n");
else {
struct symbol *sym = map__find_symbol(map, addr, NULL);
if (sym == NULL)
pr_err("couldn't find addr!\n");
else
pr_info("addr %#Lx is in %s global var\n", addr, sym->name);
}
exit(0);
}
Added just after symbol__init() call in 'perf top', then:
{
u64 addr = strtoull(sym_filter, NULL, 16);
struct map *map = map_groups__find(kmaps, MAP__VARIABLE, addr);
if (map == NULL)
pr_err("couldn't find map!\n");
else {
struct symbol *sym = map__find_symbol(map, addr, NULL);
if (sym == NULL)
pr_err("couldn't find addr!\n");
else
pr_info("addr %#Lx is in %s global var\n", addr, sym->name);
}
exit(0);
}
[root@doppio linux-2.6-tip]# grep ' [dD] ' /proc/kallsyms | grep ' sched'
ffffffff817827d8 d sched_nr_latency
ffffffff81782ce0 d sched_domains_mutex
ffffffff8178c070 d schedstr.22423
ffffffff817909a0 d sched_register_mutex
ffffffff81823490 d sched_feat_names
ffffffff81823558 d scheduler_running
ffffffff818235b8 d sched_clock_running
ffffffff818235bc D sched_clock_stable
ffffffff81824f00 d sched_switch_trace
[root@doppio linux-2.6-tip]# perf top -s 0xffffffff817827d9
addr 0xffffffff817827d9 is in sched_nr_latency global var
[root@doppio linux-2.6-tip]# perf top -s ffffffff81782ce0
addr 0xffffffff81782ce0 is in sched_domains_mutex global var
[root@doppio linux-2.6-tip]#
[root@doppio linux-2.6-tip]# perf top -s ffffffff81782ce0 --vmlinux OFF
The file OFF cannot be used, trying to use /proc/kallsyms...addr 0xffffffff81782ce0 is in sched_domains_mutex global var
[root@doppio linux-2.6-tip]# perf top -s ffffffff818235bc --vmlinux OFF
The file OFF cannot be used, trying to use /proc/kallsyms...addr 0xffffffff818235bc is in sched_clock_stable global var
[root@doppio linux-2.6-tip]#
So it works with both /proc/kallsyms and with ELF symtabs, either
the one on the vmlinux explicitely passed via --vmlinux or in one
in the vmlinux_path that matches the buildid for the running kernel
or the one found in the buildid header section in a perf.data file.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260550239-5372-4-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-11 23:50:39 +07:00
|
|
|
case MAP__VARIABLE:
|
2011-08-24 13:40:16 +07:00
|
|
|
return symbol_type == 'D';
|
2009-12-11 23:50:37 +07:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-24 13:40:17 +07:00
|
|
|
static int prefix_underscores_count(const char *str)
|
|
|
|
{
|
|
|
|
const char *tail = str;
|
|
|
|
|
|
|
|
while (*tail == '_')
|
|
|
|
tail++;
|
|
|
|
|
|
|
|
return tail - str;
|
|
|
|
}
|
|
|
|
|
2017-12-08 23:28:12 +07:00
|
|
|
const char * __weak arch__normalize_symbol_name(const char *name)
|
|
|
|
{
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
perf symbols: Allow user probes on versioned symbols
Symbol versioning, as in glibc, results in symbols being defined as:
<real symbol>@[@]<version>
(Note that "@@" identifies a default symbol, if the symbol name is
repeated.)
perf is currently unable to deal with this, and is unable to create user
probes at such symbols:
--
$ nm /lib/powerpc64le-linux-gnu/libpthread.so.0 | grep pthread_create
0000000000008d30 t __pthread_create_2_1
0000000000008d30 T pthread_create@@GLIBC_2.17
$ /usr/bin/sudo perf probe -v -x /lib/powerpc64le-linux-gnu/libpthread.so.0 pthread_create
probe-definition(0): pthread_create
symbol:pthread_create file:(null) line:0 offset:0 return:0 lazy:(null)
0 arguments
Open Debuginfo file: /usr/lib/debug/lib/powerpc64le-linux-gnu/libpthread-2.19.so
Try to find probe point from debuginfo.
Probe point 'pthread_create' not found.
Error: Failed to add events. Reason: No such file or directory (Code: -2)
--
One is not able to specify the fully versioned symbol, either, due to
syntactic conflicts with other uses of "@" by perf:
--
$ /usr/bin/sudo perf probe -v -x /lib/powerpc64le-linux-gnu/libpthread.so.0 pthread_create@@GLIBC_2.17
probe-definition(0): pthread_create@@GLIBC_2.17
Semantic error :SRC@SRC is not allowed.
0 arguments
Error: Command Parse Error. Reason: Invalid argument (Code: -22)
--
This patch ignores versioning for default symbols, thus allowing probes to be
created for these symbols:
--
$ /usr/bin/sudo ./perf probe -x /lib/powerpc64le-linux-gnu/libpthread.so.0 pthread_create
Added new event:
probe_libpthread:pthread_create (on pthread_create in /lib/powerpc64le-linux-gnu/libpthread-2.19.so)
You can now use it in all perf tools, such as:
perf record -e probe_libpthread:pthread_create -aR sleep 1
$ /usr/bin/sudo ./perf record -e probe_libpthread:pthread_create -aR ./test 2
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.052 MB perf.data (2 samples) ]
$ /usr/bin/sudo ./perf script
test 2915 [000] 19124.260729: probe_libpthread:pthread_create: (3fff99248d38)
test 2916 [000] 19124.260962: probe_libpthread:pthread_create: (3fff99248d38)
$ /usr/bin/sudo ./perf probe --del=probe_libpthread:pthread_create
Removed event: probe_libpthread:pthread_create
--
Committer note:
Change the variable storing the result of strlen() to 'int', to fix the build
on debian:experimental-x-mipsel, fedora:24-x-ARC-uClibc, ubuntu:16.04-x-arm,
etc:
util/symbol.c: In function 'symbol__match_symbol_name':
util/symbol.c:422:11: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
if (len < versioning - name)
^
Signed-off-by: Paul A. Clarke <pc@us.ibm.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Link: http://lkml.kernel.org/r/c2b18d9c-17f8-9285-4868-f58b6359ccac@us.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2017-04-26 01:15:49 +07:00
|
|
|
int __weak arch__compare_symbol_names(const char *namea, const char *nameb)
|
|
|
|
{
|
|
|
|
return strcmp(namea, nameb);
|
|
|
|
}
|
|
|
|
|
|
|
|
int __weak arch__compare_symbol_names_n(const char *namea, const char *nameb,
|
|
|
|
unsigned int n)
|
|
|
|
{
|
|
|
|
return strncmp(namea, nameb, n);
|
|
|
|
}
|
|
|
|
|
2015-04-28 19:05:36 +07:00
|
|
|
int __weak arch__choose_best_symbol(struct symbol *syma,
|
|
|
|
struct symbol *symb __maybe_unused)
|
|
|
|
{
|
|
|
|
/* Avoid "SyS" kernel syscall aliases */
|
|
|
|
if (strlen(syma->name) >= 3 && !strncmp(syma->name, "SyS", 3))
|
|
|
|
return SYMBOL_B;
|
|
|
|
if (strlen(syma->name) >= 10 && !strncmp(syma->name, "compat_SyS", 10))
|
|
|
|
return SYMBOL_B;
|
|
|
|
|
|
|
|
return SYMBOL_A;
|
|
|
|
}
|
2011-08-24 13:40:17 +07:00
|
|
|
|
|
|
|
static int choose_best_symbol(struct symbol *syma, struct symbol *symb)
|
|
|
|
{
|
|
|
|
s64 a;
|
|
|
|
s64 b;
|
2013-08-07 18:38:49 +07:00
|
|
|
size_t na, nb;
|
2011-08-24 13:40:17 +07:00
|
|
|
|
|
|
|
/* Prefer a symbol with non zero length */
|
|
|
|
a = syma->end - syma->start;
|
|
|
|
b = symb->end - symb->start;
|
|
|
|
if ((b == 0) && (a > 0))
|
|
|
|
return SYMBOL_A;
|
|
|
|
else if ((a == 0) && (b > 0))
|
|
|
|
return SYMBOL_B;
|
|
|
|
|
|
|
|
/* Prefer a non weak symbol over a weak one */
|
|
|
|
a = syma->binding == STB_WEAK;
|
|
|
|
b = symb->binding == STB_WEAK;
|
|
|
|
if (b && !a)
|
|
|
|
return SYMBOL_A;
|
|
|
|
if (a && !b)
|
|
|
|
return SYMBOL_B;
|
|
|
|
|
|
|
|
/* Prefer a global symbol over a non global one */
|
|
|
|
a = syma->binding == STB_GLOBAL;
|
|
|
|
b = symb->binding == STB_GLOBAL;
|
|
|
|
if (a && !b)
|
|
|
|
return SYMBOL_A;
|
|
|
|
if (b && !a)
|
|
|
|
return SYMBOL_B;
|
|
|
|
|
|
|
|
/* Prefer a symbol with less underscores */
|
|
|
|
a = prefix_underscores_count(syma->name);
|
|
|
|
b = prefix_underscores_count(symb->name);
|
|
|
|
if (b > a)
|
|
|
|
return SYMBOL_A;
|
|
|
|
else if (a > b)
|
|
|
|
return SYMBOL_B;
|
|
|
|
|
2013-08-07 18:38:49 +07:00
|
|
|
/* Choose the symbol with the longest name */
|
|
|
|
na = strlen(syma->name);
|
|
|
|
nb = strlen(symb->name);
|
|
|
|
if (na > nb)
|
2011-08-24 13:40:17 +07:00
|
|
|
return SYMBOL_A;
|
2013-08-07 18:38:49 +07:00
|
|
|
else if (na < nb)
|
2011-08-24 13:40:17 +07:00
|
|
|
return SYMBOL_B;
|
2013-08-07 18:38:49 +07:00
|
|
|
|
2015-04-28 19:05:36 +07:00
|
|
|
return arch__choose_best_symbol(syma, symb);
|
2011-08-24 13:40:17 +07:00
|
|
|
}
|
|
|
|
|
2012-08-06 11:41:20 +07:00
|
|
|
void symbols__fixup_duplicate(struct rb_root *symbols)
|
2011-08-24 13:40:17 +07:00
|
|
|
{
|
|
|
|
struct rb_node *nd;
|
|
|
|
struct symbol *curr, *next;
|
|
|
|
|
2016-09-01 20:56:06 +07:00
|
|
|
if (symbol_conf.allow_aliases)
|
|
|
|
return;
|
|
|
|
|
2011-08-24 13:40:17 +07:00
|
|
|
nd = rb_first(symbols);
|
|
|
|
|
|
|
|
while (nd) {
|
|
|
|
curr = rb_entry(nd, struct symbol, rb_node);
|
|
|
|
again:
|
|
|
|
nd = rb_next(&curr->rb_node);
|
|
|
|
next = rb_entry(nd, struct symbol, rb_node);
|
|
|
|
|
|
|
|
if (!nd)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (curr->start != next->start)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (choose_best_symbol(curr, next) == SYMBOL_A) {
|
|
|
|
rb_erase(&next->rb_node, symbols);
|
2013-10-11 07:27:59 +07:00
|
|
|
symbol__delete(next);
|
2011-08-24 13:40:17 +07:00
|
|
|
goto again;
|
|
|
|
} else {
|
|
|
|
nd = rb_next(&curr->rb_node);
|
|
|
|
rb_erase(&curr->rb_node, symbols);
|
2013-10-11 07:27:59 +07:00
|
|
|
symbol__delete(curr);
|
2011-08-24 13:40:17 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-06 11:41:20 +07:00
|
|
|
void symbols__fixup_end(struct rb_root *symbols)
|
2009-10-06 00:26:17 +07:00
|
|
|
{
|
2011-03-31 20:56:28 +07:00
|
|
|
struct rb_node *nd, *prevnd = rb_first(symbols);
|
2009-10-07 23:48:56 +07:00
|
|
|
struct symbol *curr, *prev;
|
2009-10-06 00:26:17 +07:00
|
|
|
|
|
|
|
if (prevnd == NULL)
|
|
|
|
return;
|
|
|
|
|
2009-10-07 23:48:56 +07:00
|
|
|
curr = rb_entry(prevnd, struct symbol, rb_node);
|
|
|
|
|
2009-10-06 00:26:17 +07:00
|
|
|
for (nd = rb_next(prevnd); nd; nd = rb_next(nd)) {
|
2009-10-07 23:48:56 +07:00
|
|
|
prev = curr;
|
|
|
|
curr = rb_entry(nd, struct symbol, rb_node);
|
2009-10-06 00:26:17 +07:00
|
|
|
|
2010-12-22 10:08:36 +07:00
|
|
|
if (prev->end == prev->start && prev->end != curr->start)
|
2014-10-15 03:19:44 +07:00
|
|
|
prev->end = curr->start;
|
2009-10-06 00:26:17 +07:00
|
|
|
}
|
2009-10-07 23:48:56 +07:00
|
|
|
|
|
|
|
/* Last entry */
|
|
|
|
if (curr->end == curr->start)
|
perf symbols: Fix symbols__fixup_end heuristic for corner cases
The current symbols__fixup_end() heuristic for the last entry in the rb
tree is suboptimal as it leads to not being able to recognize the symbol
in the call graph in a couple of corner cases, for example:
i) If the symbol has a start address (f.e. exposed via kallsyms)
that is at a page boundary, then the roundup(curr->start, 4096)
for the last entry will result in curr->start == curr->end with
a symbol length of zero.
ii) If the symbol has a start address that is shortly before a page
boundary, then also here, curr->end - curr->start will just be
very few bytes, where it's unrealistic that we could perform a
match against.
Instead, change the heuristic to roundup(curr->start, 4096) + 4096, so
that we can catch such corner cases and have a better chance to find
that specific symbol. It's still just best effort as the real end of the
symbol is unknown to us (and could even be at a larger offset than the
current range), but better than the current situation.
Alexei reported that he recently run into case i) with a JITed eBPF
program (these are all page aligned) as the last symbol which wasn't
properly shown in the call graph (while other eBPF program symbols in
the rb tree were displayed correctly). Since this is a generic issue,
lets try to improve the heuristic a bit.
Reported-and-Tested-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Fixes: 2e538c4a1847 ("perf tools: Improve kernel/modules symbol lookup")
Link: http://lkml.kernel.org/r/bb5c80d27743be6f12afc68405f1956a330e1bc9.1489614365.git.daniel@iogearbox.net
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2017-03-16 04:53:37 +07:00
|
|
|
curr->end = roundup(curr->start, 4096) + 4096;
|
2009-10-06 00:26:17 +07:00
|
|
|
}
|
|
|
|
|
2012-08-06 11:41:20 +07:00
|
|
|
void __map_groups__fixup_end(struct map_groups *mg, enum map_type type)
|
2009-10-06 00:26:17 +07:00
|
|
|
{
|
2015-05-22 22:58:53 +07:00
|
|
|
struct maps *maps = &mg->maps[type];
|
2015-05-22 21:52:22 +07:00
|
|
|
struct map *next, *curr;
|
2009-10-06 00:26:17 +07:00
|
|
|
|
2017-04-04 23:15:04 +07:00
|
|
|
down_write(&maps->lock);
|
2015-05-22 23:45:24 +07:00
|
|
|
|
2015-05-22 21:52:22 +07:00
|
|
|
curr = maps__first(maps);
|
|
|
|
if (curr == NULL)
|
2015-05-22 23:45:24 +07:00
|
|
|
goto out_unlock;
|
2009-10-06 00:26:17 +07:00
|
|
|
|
2015-05-22 21:52:22 +07:00
|
|
|
for (next = map__next(curr); next; next = map__next(curr)) {
|
2017-08-03 20:49:02 +07:00
|
|
|
if (!curr->end)
|
|
|
|
curr->end = next->start;
|
2015-05-22 21:52:22 +07:00
|
|
|
curr = next;
|
2009-10-07 23:48:56 +07:00
|
|
|
}
|
2009-11-21 23:31:24 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We still haven't the actual symbols, so guess the
|
|
|
|
* last map final address.
|
|
|
|
*/
|
2017-08-03 20:49:02 +07:00
|
|
|
if (!curr->end)
|
|
|
|
curr->end = ~0ULL;
|
2015-05-22 23:45:24 +07:00
|
|
|
|
|
|
|
out_unlock:
|
2017-04-04 23:15:04 +07:00
|
|
|
up_write(&maps->lock);
|
2009-10-06 00:26:17 +07:00
|
|
|
}
|
|
|
|
|
2012-08-06 11:41:20 +07:00
|
|
|
struct symbol *symbol__new(u64 start, u64 len, u8 binding, const char *name)
|
2009-05-29 00:55:04 +07:00
|
|
|
{
|
2009-05-29 00:55:13 +07:00
|
|
|
size_t namelen = strlen(name) + 1;
|
2011-03-31 20:56:28 +07: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 20:48:52 +07:00
|
|
|
return NULL;
|
|
|
|
|
2016-08-26 02:09:21 +07:00
|
|
|
if (symbol_conf.priv_size) {
|
|
|
|
if (symbol_conf.init_annotation) {
|
|
|
|
struct annotation *notes = (void *)sym;
|
|
|
|
pthread_mutex_init(¬es->lock, NULL);
|
|
|
|
}
|
2011-03-31 20:56:28 +07:00
|
|
|
sym = ((void *)sym) + symbol_conf.priv_size;
|
2016-08-26 02:09:21 +07:00
|
|
|
}
|
2009-10-20 23:25:40 +07:00
|
|
|
|
2011-03-31 20:56:28 +07:00
|
|
|
sym->start = start;
|
2014-10-15 03:19:44 +07:00
|
|
|
sym->end = len ? start + len : start;
|
2011-03-31 20:56:28 +07:00
|
|
|
sym->binding = binding;
|
|
|
|
sym->namelen = namelen - 1;
|
2009-10-20 23:25:40 +07:00
|
|
|
|
2011-03-31 20:56:28 +07:00
|
|
|
pr_debug4("%s: %s %#" PRIx64 "-%#" PRIx64 "\n",
|
|
|
|
__func__, name, start, sym->end);
|
|
|
|
memcpy(sym->name, name, namelen);
|
2009-05-29 00:55:04 +07:00
|
|
|
|
2011-03-31 20:56:28 +07:00
|
|
|
return sym;
|
2009-05-29 00:55:04 +07:00
|
|
|
}
|
|
|
|
|
2011-03-31 20:56:28 +07:00
|
|
|
void symbol__delete(struct symbol *sym)
|
2009-05-29 00:55:04 +07:00
|
|
|
{
|
2011-03-31 20:56:28 +07:00
|
|
|
free(((void *)sym) - symbol_conf.priv_size);
|
2009-05-29 00:55:04 +07:00
|
|
|
}
|
|
|
|
|
2012-10-28 04:18:32 +07:00
|
|
|
void symbols__delete(struct rb_root *symbols)
|
2009-05-29 00:55:04 +07:00
|
|
|
{
|
|
|
|
struct symbol *pos;
|
2011-03-31 20:56:28 +07:00
|
|
|
struct rb_node *next = rb_first(symbols);
|
2009-05-29 00:55:04 +07:00
|
|
|
|
|
|
|
while (next) {
|
|
|
|
pos = rb_entry(next, struct symbol, rb_node);
|
|
|
|
next = rb_next(&pos->rb_node);
|
2011-03-31 20:56:28 +07:00
|
|
|
rb_erase(&pos->rb_node, symbols);
|
2009-10-31 01:28:24 +07:00
|
|
|
symbol__delete(pos);
|
2009-05-29 00:55:04 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-02 03:54:31 +07:00
|
|
|
void __symbols__insert(struct rb_root *symbols, struct symbol *sym, bool kernel)
|
2009-05-29 00:55:04 +07:00
|
|
|
{
|
2011-03-31 20:56:28 +07:00
|
|
|
struct rb_node **p = &symbols->rb_node;
|
2009-05-29 00:55:04 +07: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 19:21:42 +07:00
|
|
|
const u64 ip = sym->start;
|
2009-05-29 00:55:04 +07:00
|
|
|
struct symbol *s;
|
|
|
|
|
2016-09-02 03:54:31 +07:00
|
|
|
if (kernel) {
|
|
|
|
const char *name = sym->name;
|
|
|
|
/*
|
|
|
|
* ppc64 uses function descriptors and appends a '.' to the
|
|
|
|
* start of every instruction address. Remove it.
|
|
|
|
*/
|
|
|
|
if (name[0] == '.')
|
|
|
|
name++;
|
|
|
|
sym->idle = symbol__is_idle(name);
|
|
|
|
}
|
|
|
|
|
2009-05-29 00:55:04 +07:00
|
|
|
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 20:56:28 +07:00
|
|
|
rb_insert_color(&sym->rb_node, symbols);
|
2009-05-29 00:55:04 +07:00
|
|
|
}
|
|
|
|
|
2016-09-02 03:54:31 +07:00
|
|
|
void symbols__insert(struct rb_root *symbols, struct symbol *sym)
|
|
|
|
{
|
|
|
|
__symbols__insert(symbols, sym, false);
|
|
|
|
}
|
|
|
|
|
2011-03-31 20:56:28 +07:00
|
|
|
static struct symbol *symbols__find(struct rb_root *symbols, u64 ip)
|
2009-05-29 00:55:04 +07:00
|
|
|
{
|
|
|
|
struct rb_node *n;
|
|
|
|
|
2011-03-31 20:56:28 +07:00
|
|
|
if (symbols == NULL)
|
2009-05-29 00:55:04 +07:00
|
|
|
return NULL;
|
|
|
|
|
2011-03-31 20:56:28 +07:00
|
|
|
n = symbols->rb_node;
|
2009-05-29 00:55:04 +07:00
|
|
|
|
|
|
|
while (n) {
|
|
|
|
struct symbol *s = rb_entry(n, struct symbol, rb_node);
|
|
|
|
|
|
|
|
if (ip < s->start)
|
|
|
|
n = n->rb_left;
|
2016-05-07 16:16:59 +07:00
|
|
|
else if (ip > s->end || (ip == s->end && ip != s->start))
|
2009-05-29 00:55:04 +07:00
|
|
|
n = n->rb_right;
|
|
|
|
else
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-08-07 18:38:51 +07:00
|
|
|
static struct symbol *symbols__first(struct rb_root *symbols)
|
|
|
|
{
|
|
|
|
struct rb_node *n = rb_first(symbols);
|
|
|
|
|
|
|
|
if (n)
|
|
|
|
return rb_entry(n, struct symbol, rb_node);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-09-23 21:38:38 +07:00
|
|
|
static struct symbol *symbols__last(struct rb_root *symbols)
|
|
|
|
{
|
|
|
|
struct rb_node *n = rb_last(symbols);
|
|
|
|
|
|
|
|
if (n)
|
|
|
|
return rb_entry(n, struct symbol, rb_node);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-07-14 17:02:50 +07:00
|
|
|
static struct symbol *symbols__next(struct symbol *sym)
|
|
|
|
{
|
|
|
|
struct rb_node *n = rb_next(&sym->rb_node);
|
|
|
|
|
|
|
|
if (n)
|
|
|
|
return rb_entry(n, struct symbol, rb_node);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-03-31 20:56:28 +07: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 03:50:22 +07:00
|
|
|
{
|
2011-03-31 20:56:28 +07: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 03:50:22 +07:00
|
|
|
struct rb_node *parent = NULL;
|
2010-11-23 23:38:18 +07: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 03:50:22 +07: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 20:56:28 +07: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 03:50:22 +07:00
|
|
|
}
|
|
|
|
|
2011-03-31 20:56:28 +07: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 03:50:22 +07: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 20:56:28 +07: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 03:50:22 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
perf symbols: Allow user probes on versioned symbols
Symbol versioning, as in glibc, results in symbols being defined as:
<real symbol>@[@]<version>
(Note that "@@" identifies a default symbol, if the symbol name is
repeated.)
perf is currently unable to deal with this, and is unable to create user
probes at such symbols:
--
$ nm /lib/powerpc64le-linux-gnu/libpthread.so.0 | grep pthread_create
0000000000008d30 t __pthread_create_2_1
0000000000008d30 T pthread_create@@GLIBC_2.17
$ /usr/bin/sudo perf probe -v -x /lib/powerpc64le-linux-gnu/libpthread.so.0 pthread_create
probe-definition(0): pthread_create
symbol:pthread_create file:(null) line:0 offset:0 return:0 lazy:(null)
0 arguments
Open Debuginfo file: /usr/lib/debug/lib/powerpc64le-linux-gnu/libpthread-2.19.so
Try to find probe point from debuginfo.
Probe point 'pthread_create' not found.
Error: Failed to add events. Reason: No such file or directory (Code: -2)
--
One is not able to specify the fully versioned symbol, either, due to
syntactic conflicts with other uses of "@" by perf:
--
$ /usr/bin/sudo perf probe -v -x /lib/powerpc64le-linux-gnu/libpthread.so.0 pthread_create@@GLIBC_2.17
probe-definition(0): pthread_create@@GLIBC_2.17
Semantic error :SRC@SRC is not allowed.
0 arguments
Error: Command Parse Error. Reason: Invalid argument (Code: -22)
--
This patch ignores versioning for default symbols, thus allowing probes to be
created for these symbols:
--
$ /usr/bin/sudo ./perf probe -x /lib/powerpc64le-linux-gnu/libpthread.so.0 pthread_create
Added new event:
probe_libpthread:pthread_create (on pthread_create in /lib/powerpc64le-linux-gnu/libpthread-2.19.so)
You can now use it in all perf tools, such as:
perf record -e probe_libpthread:pthread_create -aR sleep 1
$ /usr/bin/sudo ./perf record -e probe_libpthread:pthread_create -aR ./test 2
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.052 MB perf.data (2 samples) ]
$ /usr/bin/sudo ./perf script
test 2915 [000] 19124.260729: probe_libpthread:pthread_create: (3fff99248d38)
test 2916 [000] 19124.260962: probe_libpthread:pthread_create: (3fff99248d38)
$ /usr/bin/sudo ./perf probe --del=probe_libpthread:pthread_create
Removed event: probe_libpthread:pthread_create
--
Committer note:
Change the variable storing the result of strlen() to 'int', to fix the build
on debian:experimental-x-mipsel, fedora:24-x-ARC-uClibc, ubuntu:16.04-x-arm,
etc:
util/symbol.c: In function 'symbol__match_symbol_name':
util/symbol.c:422:11: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
if (len < versioning - name)
^
Signed-off-by: Paul A. Clarke <pc@us.ibm.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Link: http://lkml.kernel.org/r/c2b18d9c-17f8-9285-4868-f58b6359ccac@us.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2017-04-26 01:15:49 +07:00
|
|
|
int symbol__match_symbol_name(const char *name, const char *str,
|
|
|
|
enum symbol_tag_include includes)
|
|
|
|
{
|
|
|
|
const char *versioning;
|
|
|
|
|
|
|
|
if (includes == SYMBOL_TAG_INCLUDE__DEFAULT_ONLY &&
|
|
|
|
(versioning = strstr(name, "@@"))) {
|
|
|
|
int len = strlen(str);
|
|
|
|
|
|
|
|
if (len < versioning - name)
|
|
|
|
len = versioning - name;
|
|
|
|
|
|
|
|
return arch__compare_symbol_names_n(name, str, len);
|
|
|
|
} else
|
|
|
|
return arch__compare_symbol_names(name, str);
|
|
|
|
}
|
|
|
|
|
2011-03-31 20:56:28 +07:00
|
|
|
static struct symbol *symbols__find_by_name(struct rb_root *symbols,
|
perf symbols: Allow user probes on versioned symbols
Symbol versioning, as in glibc, results in symbols being defined as:
<real symbol>@[@]<version>
(Note that "@@" identifies a default symbol, if the symbol name is
repeated.)
perf is currently unable to deal with this, and is unable to create user
probes at such symbols:
--
$ nm /lib/powerpc64le-linux-gnu/libpthread.so.0 | grep pthread_create
0000000000008d30 t __pthread_create_2_1
0000000000008d30 T pthread_create@@GLIBC_2.17
$ /usr/bin/sudo perf probe -v -x /lib/powerpc64le-linux-gnu/libpthread.so.0 pthread_create
probe-definition(0): pthread_create
symbol:pthread_create file:(null) line:0 offset:0 return:0 lazy:(null)
0 arguments
Open Debuginfo file: /usr/lib/debug/lib/powerpc64le-linux-gnu/libpthread-2.19.so
Try to find probe point from debuginfo.
Probe point 'pthread_create' not found.
Error: Failed to add events. Reason: No such file or directory (Code: -2)
--
One is not able to specify the fully versioned symbol, either, due to
syntactic conflicts with other uses of "@" by perf:
--
$ /usr/bin/sudo perf probe -v -x /lib/powerpc64le-linux-gnu/libpthread.so.0 pthread_create@@GLIBC_2.17
probe-definition(0): pthread_create@@GLIBC_2.17
Semantic error :SRC@SRC is not allowed.
0 arguments
Error: Command Parse Error. Reason: Invalid argument (Code: -22)
--
This patch ignores versioning for default symbols, thus allowing probes to be
created for these symbols:
--
$ /usr/bin/sudo ./perf probe -x /lib/powerpc64le-linux-gnu/libpthread.so.0 pthread_create
Added new event:
probe_libpthread:pthread_create (on pthread_create in /lib/powerpc64le-linux-gnu/libpthread-2.19.so)
You can now use it in all perf tools, such as:
perf record -e probe_libpthread:pthread_create -aR sleep 1
$ /usr/bin/sudo ./perf record -e probe_libpthread:pthread_create -aR ./test 2
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.052 MB perf.data (2 samples) ]
$ /usr/bin/sudo ./perf script
test 2915 [000] 19124.260729: probe_libpthread:pthread_create: (3fff99248d38)
test 2916 [000] 19124.260962: probe_libpthread:pthread_create: (3fff99248d38)
$ /usr/bin/sudo ./perf probe --del=probe_libpthread:pthread_create
Removed event: probe_libpthread:pthread_create
--
Committer note:
Change the variable storing the result of strlen() to 'int', to fix the build
on debian:experimental-x-mipsel, fedora:24-x-ARC-uClibc, ubuntu:16.04-x-arm,
etc:
util/symbol.c: In function 'symbol__match_symbol_name':
util/symbol.c:422:11: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
if (len < versioning - name)
^
Signed-off-by: Paul A. Clarke <pc@us.ibm.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Link: http://lkml.kernel.org/r/c2b18d9c-17f8-9285-4868-f58b6359ccac@us.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2017-04-26 01:15:49 +07:00
|
|
|
const char *name,
|
|
|
|
enum symbol_tag_include includes)
|
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 03:50:22 +07:00
|
|
|
{
|
|
|
|
struct rb_node *n;
|
2015-05-26 21:41:37 +07:00
|
|
|
struct symbol_name_rb_node *s = NULL;
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-12 03:50:22 +07:00
|
|
|
|
2011-03-31 20:56:28 +07: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 03:50:22 +07:00
|
|
|
return NULL;
|
|
|
|
|
2011-03-31 20:56:28 +07: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 03:50:22 +07:00
|
|
|
|
|
|
|
while (n) {
|
|
|
|
int cmp;
|
|
|
|
|
|
|
|
s = rb_entry(n, struct symbol_name_rb_node, rb_node);
|
perf symbols: Allow user probes on versioned symbols
Symbol versioning, as in glibc, results in symbols being defined as:
<real symbol>@[@]<version>
(Note that "@@" identifies a default symbol, if the symbol name is
repeated.)
perf is currently unable to deal with this, and is unable to create user
probes at such symbols:
--
$ nm /lib/powerpc64le-linux-gnu/libpthread.so.0 | grep pthread_create
0000000000008d30 t __pthread_create_2_1
0000000000008d30 T pthread_create@@GLIBC_2.17
$ /usr/bin/sudo perf probe -v -x /lib/powerpc64le-linux-gnu/libpthread.so.0 pthread_create
probe-definition(0): pthread_create
symbol:pthread_create file:(null) line:0 offset:0 return:0 lazy:(null)
0 arguments
Open Debuginfo file: /usr/lib/debug/lib/powerpc64le-linux-gnu/libpthread-2.19.so
Try to find probe point from debuginfo.
Probe point 'pthread_create' not found.
Error: Failed to add events. Reason: No such file or directory (Code: -2)
--
One is not able to specify the fully versioned symbol, either, due to
syntactic conflicts with other uses of "@" by perf:
--
$ /usr/bin/sudo perf probe -v -x /lib/powerpc64le-linux-gnu/libpthread.so.0 pthread_create@@GLIBC_2.17
probe-definition(0): pthread_create@@GLIBC_2.17
Semantic error :SRC@SRC is not allowed.
0 arguments
Error: Command Parse Error. Reason: Invalid argument (Code: -22)
--
This patch ignores versioning for default symbols, thus allowing probes to be
created for these symbols:
--
$ /usr/bin/sudo ./perf probe -x /lib/powerpc64le-linux-gnu/libpthread.so.0 pthread_create
Added new event:
probe_libpthread:pthread_create (on pthread_create in /lib/powerpc64le-linux-gnu/libpthread-2.19.so)
You can now use it in all perf tools, such as:
perf record -e probe_libpthread:pthread_create -aR sleep 1
$ /usr/bin/sudo ./perf record -e probe_libpthread:pthread_create -aR ./test 2
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.052 MB perf.data (2 samples) ]
$ /usr/bin/sudo ./perf script
test 2915 [000] 19124.260729: probe_libpthread:pthread_create: (3fff99248d38)
test 2916 [000] 19124.260962: probe_libpthread:pthread_create: (3fff99248d38)
$ /usr/bin/sudo ./perf probe --del=probe_libpthread:pthread_create
Removed event: probe_libpthread:pthread_create
--
Committer note:
Change the variable storing the result of strlen() to 'int', to fix the build
on debian:experimental-x-mipsel, fedora:24-x-ARC-uClibc, ubuntu:16.04-x-arm,
etc:
util/symbol.c: In function 'symbol__match_symbol_name':
util/symbol.c:422:11: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
if (len < versioning - name)
^
Signed-off-by: Paul A. Clarke <pc@us.ibm.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Link: http://lkml.kernel.org/r/c2b18d9c-17f8-9285-4868-f58b6359ccac@us.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2017-04-26 01:15:49 +07:00
|
|
|
cmp = symbol__match_symbol_name(s->sym.name, name, includes);
|
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 03:50:22 +07:00
|
|
|
|
perf symbols: Allow user probes on versioned symbols
Symbol versioning, as in glibc, results in symbols being defined as:
<real symbol>@[@]<version>
(Note that "@@" identifies a default symbol, if the symbol name is
repeated.)
perf is currently unable to deal with this, and is unable to create user
probes at such symbols:
--
$ nm /lib/powerpc64le-linux-gnu/libpthread.so.0 | grep pthread_create
0000000000008d30 t __pthread_create_2_1
0000000000008d30 T pthread_create@@GLIBC_2.17
$ /usr/bin/sudo perf probe -v -x /lib/powerpc64le-linux-gnu/libpthread.so.0 pthread_create
probe-definition(0): pthread_create
symbol:pthread_create file:(null) line:0 offset:0 return:0 lazy:(null)
0 arguments
Open Debuginfo file: /usr/lib/debug/lib/powerpc64le-linux-gnu/libpthread-2.19.so
Try to find probe point from debuginfo.
Probe point 'pthread_create' not found.
Error: Failed to add events. Reason: No such file or directory (Code: -2)
--
One is not able to specify the fully versioned symbol, either, due to
syntactic conflicts with other uses of "@" by perf:
--
$ /usr/bin/sudo perf probe -v -x /lib/powerpc64le-linux-gnu/libpthread.so.0 pthread_create@@GLIBC_2.17
probe-definition(0): pthread_create@@GLIBC_2.17
Semantic error :SRC@SRC is not allowed.
0 arguments
Error: Command Parse Error. Reason: Invalid argument (Code: -22)
--
This patch ignores versioning for default symbols, thus allowing probes to be
created for these symbols:
--
$ /usr/bin/sudo ./perf probe -x /lib/powerpc64le-linux-gnu/libpthread.so.0 pthread_create
Added new event:
probe_libpthread:pthread_create (on pthread_create in /lib/powerpc64le-linux-gnu/libpthread-2.19.so)
You can now use it in all perf tools, such as:
perf record -e probe_libpthread:pthread_create -aR sleep 1
$ /usr/bin/sudo ./perf record -e probe_libpthread:pthread_create -aR ./test 2
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.052 MB perf.data (2 samples) ]
$ /usr/bin/sudo ./perf script
test 2915 [000] 19124.260729: probe_libpthread:pthread_create: (3fff99248d38)
test 2916 [000] 19124.260962: probe_libpthread:pthread_create: (3fff99248d38)
$ /usr/bin/sudo ./perf probe --del=probe_libpthread:pthread_create
Removed event: probe_libpthread:pthread_create
--
Committer note:
Change the variable storing the result of strlen() to 'int', to fix the build
on debian:experimental-x-mipsel, fedora:24-x-ARC-uClibc, ubuntu:16.04-x-arm,
etc:
util/symbol.c: In function 'symbol__match_symbol_name':
util/symbol.c:422:11: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
if (len < versioning - name)
^
Signed-off-by: Paul A. Clarke <pc@us.ibm.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Link: http://lkml.kernel.org/r/c2b18d9c-17f8-9285-4868-f58b6359ccac@us.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2017-04-26 01:15:49 +07:00
|
|
|
if (cmp > 0)
|
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 03:50:22 +07:00
|
|
|
n = n->rb_left;
|
perf symbols: Allow user probes on versioned symbols
Symbol versioning, as in glibc, results in symbols being defined as:
<real symbol>@[@]<version>
(Note that "@@" identifies a default symbol, if the symbol name is
repeated.)
perf is currently unable to deal with this, and is unable to create user
probes at such symbols:
--
$ nm /lib/powerpc64le-linux-gnu/libpthread.so.0 | grep pthread_create
0000000000008d30 t __pthread_create_2_1
0000000000008d30 T pthread_create@@GLIBC_2.17
$ /usr/bin/sudo perf probe -v -x /lib/powerpc64le-linux-gnu/libpthread.so.0 pthread_create
probe-definition(0): pthread_create
symbol:pthread_create file:(null) line:0 offset:0 return:0 lazy:(null)
0 arguments
Open Debuginfo file: /usr/lib/debug/lib/powerpc64le-linux-gnu/libpthread-2.19.so
Try to find probe point from debuginfo.
Probe point 'pthread_create' not found.
Error: Failed to add events. Reason: No such file or directory (Code: -2)
--
One is not able to specify the fully versioned symbol, either, due to
syntactic conflicts with other uses of "@" by perf:
--
$ /usr/bin/sudo perf probe -v -x /lib/powerpc64le-linux-gnu/libpthread.so.0 pthread_create@@GLIBC_2.17
probe-definition(0): pthread_create@@GLIBC_2.17
Semantic error :SRC@SRC is not allowed.
0 arguments
Error: Command Parse Error. Reason: Invalid argument (Code: -22)
--
This patch ignores versioning for default symbols, thus allowing probes to be
created for these symbols:
--
$ /usr/bin/sudo ./perf probe -x /lib/powerpc64le-linux-gnu/libpthread.so.0 pthread_create
Added new event:
probe_libpthread:pthread_create (on pthread_create in /lib/powerpc64le-linux-gnu/libpthread-2.19.so)
You can now use it in all perf tools, such as:
perf record -e probe_libpthread:pthread_create -aR sleep 1
$ /usr/bin/sudo ./perf record -e probe_libpthread:pthread_create -aR ./test 2
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.052 MB perf.data (2 samples) ]
$ /usr/bin/sudo ./perf script
test 2915 [000] 19124.260729: probe_libpthread:pthread_create: (3fff99248d38)
test 2916 [000] 19124.260962: probe_libpthread:pthread_create: (3fff99248d38)
$ /usr/bin/sudo ./perf probe --del=probe_libpthread:pthread_create
Removed event: probe_libpthread:pthread_create
--
Committer note:
Change the variable storing the result of strlen() to 'int', to fix the build
on debian:experimental-x-mipsel, fedora:24-x-ARC-uClibc, ubuntu:16.04-x-arm,
etc:
util/symbol.c: In function 'symbol__match_symbol_name':
util/symbol.c:422:11: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
if (len < versioning - name)
^
Signed-off-by: Paul A. Clarke <pc@us.ibm.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Link: http://lkml.kernel.org/r/c2b18d9c-17f8-9285-4868-f58b6359ccac@us.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2017-04-26 01:15:49 +07:00
|
|
|
else if (cmp < 0)
|
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 03:50:22 +07:00
|
|
|
n = n->rb_right;
|
|
|
|
else
|
2015-01-17 01:31:28 +07:00
|
|
|
break;
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-12 03:50:22 +07:00
|
|
|
}
|
|
|
|
|
2015-01-17 01:31:28 +07:00
|
|
|
if (n == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
perf symbols: Allow user probes on versioned symbols
Symbol versioning, as in glibc, results in symbols being defined as:
<real symbol>@[@]<version>
(Note that "@@" identifies a default symbol, if the symbol name is
repeated.)
perf is currently unable to deal with this, and is unable to create user
probes at such symbols:
--
$ nm /lib/powerpc64le-linux-gnu/libpthread.so.0 | grep pthread_create
0000000000008d30 t __pthread_create_2_1
0000000000008d30 T pthread_create@@GLIBC_2.17
$ /usr/bin/sudo perf probe -v -x /lib/powerpc64le-linux-gnu/libpthread.so.0 pthread_create
probe-definition(0): pthread_create
symbol:pthread_create file:(null) line:0 offset:0 return:0 lazy:(null)
0 arguments
Open Debuginfo file: /usr/lib/debug/lib/powerpc64le-linux-gnu/libpthread-2.19.so
Try to find probe point from debuginfo.
Probe point 'pthread_create' not found.
Error: Failed to add events. Reason: No such file or directory (Code: -2)
--
One is not able to specify the fully versioned symbol, either, due to
syntactic conflicts with other uses of "@" by perf:
--
$ /usr/bin/sudo perf probe -v -x /lib/powerpc64le-linux-gnu/libpthread.so.0 pthread_create@@GLIBC_2.17
probe-definition(0): pthread_create@@GLIBC_2.17
Semantic error :SRC@SRC is not allowed.
0 arguments
Error: Command Parse Error. Reason: Invalid argument (Code: -22)
--
This patch ignores versioning for default symbols, thus allowing probes to be
created for these symbols:
--
$ /usr/bin/sudo ./perf probe -x /lib/powerpc64le-linux-gnu/libpthread.so.0 pthread_create
Added new event:
probe_libpthread:pthread_create (on pthread_create in /lib/powerpc64le-linux-gnu/libpthread-2.19.so)
You can now use it in all perf tools, such as:
perf record -e probe_libpthread:pthread_create -aR sleep 1
$ /usr/bin/sudo ./perf record -e probe_libpthread:pthread_create -aR ./test 2
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.052 MB perf.data (2 samples) ]
$ /usr/bin/sudo ./perf script
test 2915 [000] 19124.260729: probe_libpthread:pthread_create: (3fff99248d38)
test 2916 [000] 19124.260962: probe_libpthread:pthread_create: (3fff99248d38)
$ /usr/bin/sudo ./perf probe --del=probe_libpthread:pthread_create
Removed event: probe_libpthread:pthread_create
--
Committer note:
Change the variable storing the result of strlen() to 'int', to fix the build
on debian:experimental-x-mipsel, fedora:24-x-ARC-uClibc, ubuntu:16.04-x-arm,
etc:
util/symbol.c: In function 'symbol__match_symbol_name':
util/symbol.c:422:11: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
if (len < versioning - name)
^
Signed-off-by: Paul A. Clarke <pc@us.ibm.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Link: http://lkml.kernel.org/r/c2b18d9c-17f8-9285-4868-f58b6359ccac@us.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2017-04-26 01:15:49 +07:00
|
|
|
if (includes != SYMBOL_TAG_INCLUDE__DEFAULT_ONLY)
|
|
|
|
/* return first symbol that has same name (if any) */
|
|
|
|
for (n = rb_prev(n); n; n = rb_prev(n)) {
|
|
|
|
struct symbol_name_rb_node *tmp;
|
2015-01-17 01:31:28 +07:00
|
|
|
|
perf symbols: Allow user probes on versioned symbols
Symbol versioning, as in glibc, results in symbols being defined as:
<real symbol>@[@]<version>
(Note that "@@" identifies a default symbol, if the symbol name is
repeated.)
perf is currently unable to deal with this, and is unable to create user
probes at such symbols:
--
$ nm /lib/powerpc64le-linux-gnu/libpthread.so.0 | grep pthread_create
0000000000008d30 t __pthread_create_2_1
0000000000008d30 T pthread_create@@GLIBC_2.17
$ /usr/bin/sudo perf probe -v -x /lib/powerpc64le-linux-gnu/libpthread.so.0 pthread_create
probe-definition(0): pthread_create
symbol:pthread_create file:(null) line:0 offset:0 return:0 lazy:(null)
0 arguments
Open Debuginfo file: /usr/lib/debug/lib/powerpc64le-linux-gnu/libpthread-2.19.so
Try to find probe point from debuginfo.
Probe point 'pthread_create' not found.
Error: Failed to add events. Reason: No such file or directory (Code: -2)
--
One is not able to specify the fully versioned symbol, either, due to
syntactic conflicts with other uses of "@" by perf:
--
$ /usr/bin/sudo perf probe -v -x /lib/powerpc64le-linux-gnu/libpthread.so.0 pthread_create@@GLIBC_2.17
probe-definition(0): pthread_create@@GLIBC_2.17
Semantic error :SRC@SRC is not allowed.
0 arguments
Error: Command Parse Error. Reason: Invalid argument (Code: -22)
--
This patch ignores versioning for default symbols, thus allowing probes to be
created for these symbols:
--
$ /usr/bin/sudo ./perf probe -x /lib/powerpc64le-linux-gnu/libpthread.so.0 pthread_create
Added new event:
probe_libpthread:pthread_create (on pthread_create in /lib/powerpc64le-linux-gnu/libpthread-2.19.so)
You can now use it in all perf tools, such as:
perf record -e probe_libpthread:pthread_create -aR sleep 1
$ /usr/bin/sudo ./perf record -e probe_libpthread:pthread_create -aR ./test 2
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.052 MB perf.data (2 samples) ]
$ /usr/bin/sudo ./perf script
test 2915 [000] 19124.260729: probe_libpthread:pthread_create: (3fff99248d38)
test 2916 [000] 19124.260962: probe_libpthread:pthread_create: (3fff99248d38)
$ /usr/bin/sudo ./perf probe --del=probe_libpthread:pthread_create
Removed event: probe_libpthread:pthread_create
--
Committer note:
Change the variable storing the result of strlen() to 'int', to fix the build
on debian:experimental-x-mipsel, fedora:24-x-ARC-uClibc, ubuntu:16.04-x-arm,
etc:
util/symbol.c: In function 'symbol__match_symbol_name':
util/symbol.c:422:11: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
if (len < versioning - name)
^
Signed-off-by: Paul A. Clarke <pc@us.ibm.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Link: http://lkml.kernel.org/r/c2b18d9c-17f8-9285-4868-f58b6359ccac@us.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2017-04-26 01:15:49 +07:00
|
|
|
tmp = rb_entry(n, struct symbol_name_rb_node, rb_node);
|
|
|
|
if (arch__compare_symbol_names(tmp->sym.name, s->sym.name))
|
|
|
|
break;
|
2015-01-17 01:31:28 +07:00
|
|
|
|
perf symbols: Allow user probes on versioned symbols
Symbol versioning, as in glibc, results in symbols being defined as:
<real symbol>@[@]<version>
(Note that "@@" identifies a default symbol, if the symbol name is
repeated.)
perf is currently unable to deal with this, and is unable to create user
probes at such symbols:
--
$ nm /lib/powerpc64le-linux-gnu/libpthread.so.0 | grep pthread_create
0000000000008d30 t __pthread_create_2_1
0000000000008d30 T pthread_create@@GLIBC_2.17
$ /usr/bin/sudo perf probe -v -x /lib/powerpc64le-linux-gnu/libpthread.so.0 pthread_create
probe-definition(0): pthread_create
symbol:pthread_create file:(null) line:0 offset:0 return:0 lazy:(null)
0 arguments
Open Debuginfo file: /usr/lib/debug/lib/powerpc64le-linux-gnu/libpthread-2.19.so
Try to find probe point from debuginfo.
Probe point 'pthread_create' not found.
Error: Failed to add events. Reason: No such file or directory (Code: -2)
--
One is not able to specify the fully versioned symbol, either, due to
syntactic conflicts with other uses of "@" by perf:
--
$ /usr/bin/sudo perf probe -v -x /lib/powerpc64le-linux-gnu/libpthread.so.0 pthread_create@@GLIBC_2.17
probe-definition(0): pthread_create@@GLIBC_2.17
Semantic error :SRC@SRC is not allowed.
0 arguments
Error: Command Parse Error. Reason: Invalid argument (Code: -22)
--
This patch ignores versioning for default symbols, thus allowing probes to be
created for these symbols:
--
$ /usr/bin/sudo ./perf probe -x /lib/powerpc64le-linux-gnu/libpthread.so.0 pthread_create
Added new event:
probe_libpthread:pthread_create (on pthread_create in /lib/powerpc64le-linux-gnu/libpthread-2.19.so)
You can now use it in all perf tools, such as:
perf record -e probe_libpthread:pthread_create -aR sleep 1
$ /usr/bin/sudo ./perf record -e probe_libpthread:pthread_create -aR ./test 2
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.052 MB perf.data (2 samples) ]
$ /usr/bin/sudo ./perf script
test 2915 [000] 19124.260729: probe_libpthread:pthread_create: (3fff99248d38)
test 2916 [000] 19124.260962: probe_libpthread:pthread_create: (3fff99248d38)
$ /usr/bin/sudo ./perf probe --del=probe_libpthread:pthread_create
Removed event: probe_libpthread:pthread_create
--
Committer note:
Change the variable storing the result of strlen() to 'int', to fix the build
on debian:experimental-x-mipsel, fedora:24-x-ARC-uClibc, ubuntu:16.04-x-arm,
etc:
util/symbol.c: In function 'symbol__match_symbol_name':
util/symbol.c:422:11: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
if (len < versioning - name)
^
Signed-off-by: Paul A. Clarke <pc@us.ibm.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Link: http://lkml.kernel.org/r/c2b18d9c-17f8-9285-4868-f58b6359ccac@us.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2017-04-26 01:15:49 +07:00
|
|
|
s = tmp;
|
|
|
|
}
|
2015-01-17 01:31:28 +07:00
|
|
|
|
|
|
|
return &s->sym;
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-12 03:50:22 +07:00
|
|
|
}
|
|
|
|
|
2015-08-24 23:33:14 +07:00
|
|
|
void dso__reset_find_symbol_cache(struct dso *dso)
|
|
|
|
{
|
|
|
|
enum map_type type;
|
|
|
|
|
|
|
|
for (type = MAP__FUNCTION; type <= MAP__VARIABLE; ++type) {
|
|
|
|
dso->last_find_result[type].addr = 0;
|
|
|
|
dso->last_find_result[type].symbol = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-11 10:26:46 +07:00
|
|
|
void dso__insert_symbol(struct dso *dso, enum map_type type, struct symbol *sym)
|
|
|
|
{
|
2016-09-02 03:54:31 +07:00
|
|
|
__symbols__insert(&dso->symbols[type], sym, dso->kernel);
|
2016-05-11 10:26:46 +07:00
|
|
|
|
|
|
|
/* update the symbol cache if necessary */
|
|
|
|
if (dso->last_find_result[type].addr >= sym->start &&
|
|
|
|
(dso->last_find_result[type].addr < sym->end ||
|
|
|
|
sym->start == sym->end)) {
|
|
|
|
dso->last_find_result[type].symbol = sym;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-31 20:56:28 +07: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 03:50:22 +07:00
|
|
|
enum map_type type, u64 addr)
|
2009-11-24 22:01:52 +07:00
|
|
|
{
|
perf symbols: Accept symbols starting at address 0
That is the case of _text on s390, and we have some functions that return an
address, using address zero to report problems, oops.
This would lead the symbol loading routines to not use "_text" as the reference
relocation symbol, or the first symbol for the kernel, but use instead
"_stext", that is at the same address on x86_64 and others, but not on s390:
[acme@localhost perf-4.11.0-rc6]$ head -15 /proc/kallsyms
0000000000000000 T _text
0000000000000418 t iplstart
0000000000000800 T start
000000000000080a t .base
000000000000082e t .sk8x8
0000000000000834 t .gotr
0000000000000842 t .cmd
0000000000000846 t .parm
000000000000084a t .lowcase
0000000000010000 T startup
0000000000010010 T startup_kdump
0000000000010214 t startup_kdump_relocated
0000000000011000 T startup_continue
00000000000112a0 T _ehead
0000000000100000 T _stext
[acme@localhost perf-4.11.0-rc6]$
Which in turn would make 'perf test vmlinux' to fail because it wouldn't find
the symbols before "_stext" in kallsyms.
Fix it by using the return value only for errors and storing the
address, when the symbol is successfully found, in a provided pointer
arg.
Before this patch:
After:
[acme@localhost perf-4.11.0-rc6]$ tools/perf/perf test -v 1
1: vmlinux symtab matches kallsyms :
--- start ---
test child forked, pid 40693
Looking at the vmlinux_path (8 entries long)
Using /usr/lib/debug/lib/modules/3.10.0-654.el7.s390x/vmlinux for symbols
ERR : 0: _text not on kallsyms
ERR : 0x418: iplstart not on kallsyms
ERR : 0x800: start not on kallsyms
ERR : 0x80a: .base not on kallsyms
ERR : 0x82e: .sk8x8 not on kallsyms
ERR : 0x834: .gotr not on kallsyms
ERR : 0x842: .cmd not on kallsyms
ERR : 0x846: .parm not on kallsyms
ERR : 0x84a: .lowcase not on kallsyms
ERR : 0x10000: startup not on kallsyms
ERR : 0x10010: startup_kdump not on kallsyms
ERR : 0x10214: startup_kdump_relocated not on kallsyms
ERR : 0x11000: startup_continue not on kallsyms
ERR : 0x112a0: _ehead not on kallsyms
<SNIP warnings>
test child finished with -1
---- end ----
vmlinux symtab matches kallsyms: FAILED!
[acme@localhost perf-4.11.0-rc6]$
After:
[acme@localhost perf-4.11.0-rc6]$ tools/perf/perf test -v 1
1: vmlinux symtab matches kallsyms :
--- start ---
test child forked, pid 47160
<SNIP warnings>
test child finished with 0
---- end ----
vmlinux symtab matches kallsyms: Ok
[acme@localhost perf-4.11.0-rc6]$
Reported-by: Michael Petlan <mpetlan@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-9x9bwgd3btwdk1u51xie93fz@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2017-04-28 07:21:09 +07:00
|
|
|
if (dso->last_find_result[type].addr != addr || dso->last_find_result[type].symbol == NULL) {
|
2015-07-22 22:52:17 +07:00
|
|
|
dso->last_find_result[type].addr = addr;
|
|
|
|
dso->last_find_result[type].symbol = symbols__find(&dso->symbols[type], addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return dso->last_find_result[type].symbol;
|
2009-11-24 22:01:52 +07:00
|
|
|
}
|
|
|
|
|
2014-07-14 17:02:50 +07:00
|
|
|
struct symbol *dso__first_symbol(struct dso *dso, enum map_type type)
|
2013-08-07 18:38:51 +07:00
|
|
|
{
|
|
|
|
return symbols__first(&dso->symbols[type]);
|
2014-07-14 17:02:50 +07:00
|
|
|
}
|
|
|
|
|
2016-09-23 21:38:38 +07:00
|
|
|
struct symbol *dso__last_symbol(struct dso *dso, enum map_type type)
|
|
|
|
{
|
|
|
|
return symbols__last(&dso->symbols[type]);
|
|
|
|
}
|
|
|
|
|
2014-07-14 17:02:50 +07:00
|
|
|
struct symbol *dso__next_symbol(struct symbol *sym)
|
|
|
|
{
|
|
|
|
return symbols__next(sym);
|
2013-08-07 18:38:51 +07:00
|
|
|
}
|
|
|
|
|
2015-01-17 01:39:53 +07:00
|
|
|
struct symbol *symbol__next_by_name(struct symbol *sym)
|
|
|
|
{
|
|
|
|
struct symbol_name_rb_node *s = container_of(sym, struct symbol_name_rb_node, sym);
|
|
|
|
struct rb_node *n = rb_next(&s->rb_node);
|
|
|
|
|
|
|
|
return n ? &rb_entry(n, struct symbol_name_rb_node, rb_node)->sym : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Teturns first symbol that matched with @name.
|
|
|
|
*/
|
2011-03-31 20:56:28 +07: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 03:50:22 +07:00
|
|
|
const char *name)
|
|
|
|
{
|
perf symbols: Allow user probes on versioned symbols
Symbol versioning, as in glibc, results in symbols being defined as:
<real symbol>@[@]<version>
(Note that "@@" identifies a default symbol, if the symbol name is
repeated.)
perf is currently unable to deal with this, and is unable to create user
probes at such symbols:
--
$ nm /lib/powerpc64le-linux-gnu/libpthread.so.0 | grep pthread_create
0000000000008d30 t __pthread_create_2_1
0000000000008d30 T pthread_create@@GLIBC_2.17
$ /usr/bin/sudo perf probe -v -x /lib/powerpc64le-linux-gnu/libpthread.so.0 pthread_create
probe-definition(0): pthread_create
symbol:pthread_create file:(null) line:0 offset:0 return:0 lazy:(null)
0 arguments
Open Debuginfo file: /usr/lib/debug/lib/powerpc64le-linux-gnu/libpthread-2.19.so
Try to find probe point from debuginfo.
Probe point 'pthread_create' not found.
Error: Failed to add events. Reason: No such file or directory (Code: -2)
--
One is not able to specify the fully versioned symbol, either, due to
syntactic conflicts with other uses of "@" by perf:
--
$ /usr/bin/sudo perf probe -v -x /lib/powerpc64le-linux-gnu/libpthread.so.0 pthread_create@@GLIBC_2.17
probe-definition(0): pthread_create@@GLIBC_2.17
Semantic error :SRC@SRC is not allowed.
0 arguments
Error: Command Parse Error. Reason: Invalid argument (Code: -22)
--
This patch ignores versioning for default symbols, thus allowing probes to be
created for these symbols:
--
$ /usr/bin/sudo ./perf probe -x /lib/powerpc64le-linux-gnu/libpthread.so.0 pthread_create
Added new event:
probe_libpthread:pthread_create (on pthread_create in /lib/powerpc64le-linux-gnu/libpthread-2.19.so)
You can now use it in all perf tools, such as:
perf record -e probe_libpthread:pthread_create -aR sleep 1
$ /usr/bin/sudo ./perf record -e probe_libpthread:pthread_create -aR ./test 2
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.052 MB perf.data (2 samples) ]
$ /usr/bin/sudo ./perf script
test 2915 [000] 19124.260729: probe_libpthread:pthread_create: (3fff99248d38)
test 2916 [000] 19124.260962: probe_libpthread:pthread_create: (3fff99248d38)
$ /usr/bin/sudo ./perf probe --del=probe_libpthread:pthread_create
Removed event: probe_libpthread:pthread_create
--
Committer note:
Change the variable storing the result of strlen() to 'int', to fix the build
on debian:experimental-x-mipsel, fedora:24-x-ARC-uClibc, ubuntu:16.04-x-arm,
etc:
util/symbol.c: In function 'symbol__match_symbol_name':
util/symbol.c:422:11: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
if (len < versioning - name)
^
Signed-off-by: Paul A. Clarke <pc@us.ibm.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Link: http://lkml.kernel.org/r/c2b18d9c-17f8-9285-4868-f58b6359ccac@us.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2017-04-26 01:15:49 +07:00
|
|
|
struct symbol *s = symbols__find_by_name(&dso->symbol_names[type], name,
|
|
|
|
SYMBOL_TAG_INCLUDE__NONE);
|
|
|
|
if (!s)
|
|
|
|
s = symbols__find_by_name(&dso->symbol_names[type], name,
|
|
|
|
SYMBOL_TAG_INCLUDE__DEFAULT_ONLY);
|
|
|
|
return s;
|
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 03:50:22 +07:00
|
|
|
}
|
|
|
|
|
2011-03-31 20:56:28 +07: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 03:50:22 +07:00
|
|
|
{
|
2011-03-31 20:56:28 +07: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 03:50:22 +07:00
|
|
|
}
|
|
|
|
|
2013-10-08 15:45:48 +07:00
|
|
|
int modules__parse(const char *filename, void *arg,
|
|
|
|
int (*process_module)(void *arg, const char *name,
|
2017-08-03 20:49:02 +07:00
|
|
|
u64 start, u64 size))
|
2013-10-08 15:45:48 +07:00
|
|
|
{
|
|
|
|
char *line = NULL;
|
|
|
|
size_t n;
|
|
|
|
FILE *file;
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
file = fopen(filename, "r");
|
|
|
|
if (file == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
char name[PATH_MAX];
|
2017-08-03 20:49:02 +07:00
|
|
|
u64 start, size;
|
|
|
|
char *sep, *endptr;
|
2013-10-08 15:45:48 +07:00
|
|
|
ssize_t line_len;
|
|
|
|
|
|
|
|
line_len = getline(&line, &n, file);
|
|
|
|
if (line_len < 0) {
|
|
|
|
if (feof(file))
|
|
|
|
break;
|
|
|
|
err = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!line) {
|
|
|
|
err = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
line[--line_len] = '\0'; /* \n */
|
|
|
|
|
|
|
|
sep = strrchr(line, 'x');
|
|
|
|
if (sep == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
hex2u64(sep + 1, &start);
|
|
|
|
|
|
|
|
sep = strchr(line, ' ');
|
|
|
|
if (sep == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
*sep = '\0';
|
|
|
|
|
|
|
|
scnprintf(name, sizeof(name), "[%s]", line);
|
|
|
|
|
2017-08-03 20:49:02 +07:00
|
|
|
size = strtoul(sep + 1, &endptr, 0);
|
|
|
|
if (*endptr != ' ' && *endptr != '\t')
|
|
|
|
continue;
|
|
|
|
|
|
|
|
err = process_module(arg, name, start, size);
|
2013-10-08 15:45:48 +07:00
|
|
|
if (err)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
free(line);
|
|
|
|
fclose(file);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2010-01-05 01:19:26 +07:00
|
|
|
struct process_kallsyms_args {
|
|
|
|
struct map *map;
|
|
|
|
struct dso *dso;
|
|
|
|
};
|
|
|
|
|
2014-08-09 04:00:39 +07:00
|
|
|
/*
|
|
|
|
* These are symbols in the kernel image, so make sure that
|
|
|
|
* sym is from a kernel DSO.
|
|
|
|
*/
|
2016-09-02 03:54:31 +07:00
|
|
|
static bool symbol__is_idle(const char *name)
|
2013-11-19 03:32:45 +07:00
|
|
|
{
|
|
|
|
const char * const idle_symbols[] = {
|
|
|
|
"cpu_idle",
|
2014-08-09 04:02:41 +07:00
|
|
|
"cpu_startup_entry",
|
2013-11-19 03:32:45 +07:00
|
|
|
"intel_idle",
|
|
|
|
"default_idle",
|
|
|
|
"native_safe_halt",
|
|
|
|
"enter_idle",
|
|
|
|
"exit_idle",
|
|
|
|
"mwait_idle",
|
|
|
|
"mwait_idle_with_hints",
|
|
|
|
"poll_idle",
|
|
|
|
"ppc64_runlatch_off",
|
|
|
|
"pseries_dedicated_idle_sleep",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; idle_symbols[i]; i++) {
|
2016-09-02 03:54:31 +07:00
|
|
|
if (!strcmp(idle_symbols[i], name))
|
2013-11-19 03:32:45 +07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-01-05 01:19:26 +07:00
|
|
|
static int map__process_kallsym_symbol(void *arg, const char *name,
|
2012-08-11 05:22:48 +07:00
|
|
|
char type, u64 start)
|
2010-01-05 01:19:26 +07: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 05:22:48 +07: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.
|
|
|
|
*/
|
2015-09-30 22:42:07 +07:00
|
|
|
sym = symbol__new(start, 0, kallsyms2elf_binding(type), name);
|
2010-01-05 01:19:26 +07: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
|
|
|
|
*/
|
2016-09-02 03:54:31 +07:00
|
|
|
__symbols__insert(root, sym, !strchr(name, '['));
|
2010-04-19 12:32:50 +07:00
|
|
|
|
2010-01-05 01:19:26 +07: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 20:56:28 +07:00
|
|
|
static int dso__load_all_kallsyms(struct dso *dso, const char *filename,
|
2010-01-15 03:30:06 +07:00
|
|
|
struct map *map)
|
2010-01-05 01:19:26 +07:00
|
|
|
{
|
2011-03-31 20:56:28 +07:00
|
|
|
struct process_kallsyms_args args = { .map = map, .dso = dso, };
|
2010-01-15 03:30:06 +07:00
|
|
|
return kallsyms__parse(filename, &args, map__process_kallsym_symbol);
|
2010-01-05 01:19:26 +07:00
|
|
|
}
|
|
|
|
|
2016-09-02 05:25:52 +07:00
|
|
|
static int dso__split_kallsyms_for_kcore(struct dso *dso, struct map *map)
|
2013-08-07 18:38:51 +07:00
|
|
|
{
|
2015-04-07 15:22:45 +07:00
|
|
|
struct map_groups *kmaps = map__kmaps(map);
|
2013-08-07 18:38:51 +07:00
|
|
|
struct map *curr_map;
|
|
|
|
struct symbol *pos;
|
2015-11-06 20:59:29 +07:00
|
|
|
int count = 0;
|
|
|
|
struct rb_root old_root = dso->symbols[map->type];
|
2013-08-07 18:38:51 +07:00
|
|
|
struct rb_root *root = &dso->symbols[map->type];
|
|
|
|
struct rb_node *next = rb_first(root);
|
|
|
|
|
2015-04-07 15:22:45 +07:00
|
|
|
if (!kmaps)
|
|
|
|
return -1;
|
|
|
|
|
2015-11-06 20:59:29 +07:00
|
|
|
*root = RB_ROOT;
|
|
|
|
|
2013-08-07 18:38:51 +07:00
|
|
|
while (next) {
|
|
|
|
char *module;
|
|
|
|
|
|
|
|
pos = rb_entry(next, struct symbol, rb_node);
|
|
|
|
next = rb_next(&pos->rb_node);
|
|
|
|
|
2015-11-06 20:59:29 +07:00
|
|
|
rb_erase_init(&pos->rb_node, &old_root);
|
|
|
|
|
2013-08-07 18:38:51 +07:00
|
|
|
module = strchr(pos->name, '\t');
|
|
|
|
if (module)
|
|
|
|
*module = '\0';
|
|
|
|
|
|
|
|
curr_map = map_groups__find(kmaps, map->type, pos->start);
|
|
|
|
|
2016-09-02 05:25:52 +07:00
|
|
|
if (!curr_map) {
|
2013-08-07 18:38:51 +07:00
|
|
|
symbol__delete(pos);
|
2015-11-06 20:59:29 +07:00
|
|
|
continue;
|
2013-08-07 18:38:51 +07:00
|
|
|
}
|
2015-11-06 20:59:29 +07:00
|
|
|
|
|
|
|
pos->start -= curr_map->start - curr_map->pgoff;
|
|
|
|
if (pos->end)
|
|
|
|
pos->end -= curr_map->start - curr_map->pgoff;
|
|
|
|
symbols__insert(&curr_map->dso->symbols[curr_map->type], pos);
|
|
|
|
++count;
|
2013-08-07 18:38:51 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Symbols have been adjusted */
|
|
|
|
dso->adjust_symbols = 1;
|
|
|
|
|
2015-11-06 20:59:29 +07:00
|
|
|
return count;
|
2013-08-07 18:38:51 +07:00
|
|
|
}
|
|
|
|
|
2009-10-07 23:48:56 +07: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.
|
|
|
|
*/
|
2016-09-02 05:25:52 +07:00
|
|
|
static int dso__split_kallsyms(struct dso *dso, struct map *map, u64 delta)
|
2009-10-07 23:48:56 +07:00
|
|
|
{
|
2015-04-07 15:22:45 +07:00
|
|
|
struct map_groups *kmaps = map__kmaps(map);
|
|
|
|
struct machine *machine;
|
2009-11-28 01:29:18 +07:00
|
|
|
struct map *curr_map = map;
|
2009-10-07 23:48:56 +07:00
|
|
|
struct symbol *pos;
|
2014-12-18 03:24:45 +07:00
|
|
|
int count = 0, moved = 0;
|
2011-03-31 20:56:28 +07:00
|
|
|
struct rb_root *root = &dso->symbols[map->type];
|
2009-11-28 01:29:18 +07:00
|
|
|
struct rb_node *next = rb_first(root);
|
2009-10-07 23:48:56 +07:00
|
|
|
int kernel_range = 0;
|
|
|
|
|
2015-04-07 15:22:45 +07:00
|
|
|
if (!kmaps)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
machine = kmaps->machine;
|
|
|
|
|
2009-10-07 23:48:56 +07:00
|
|
|
while (next) {
|
|
|
|
char *module;
|
|
|
|
|
|
|
|
pos = rb_entry(next, struct symbol, rb_node);
|
|
|
|
next = rb_next(&pos->rb_node);
|
|
|
|
|
|
|
|
module = strchr(pos->name, '\t');
|
|
|
|
if (module) {
|
2009-12-16 05:04:39 +07:00
|
|
|
if (!symbol_conf.use_modules)
|
2009-11-28 01:29:21 +07:00
|
|
|
goto discard_symbol;
|
|
|
|
|
2009-10-07 23:48:56 +07: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 22:22:17 +07:00
|
|
|
if (strcmp(curr_map->dso->short_name, module)) {
|
2010-04-19 12:32:50 +07:00
|
|
|
if (curr_map != map &&
|
2011-03-31 20:56:28 +07:00
|
|
|
dso->kernel == DSO_TYPE_GUEST_KERNEL &&
|
2010-04-28 07:17:50 +07:00
|
|
|
machine__is_default_guest(machine)) {
|
2010-04-19 12:32:50 +07: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 01:29:18 +07:00
|
|
|
if (curr_map == NULL) {
|
2010-05-18 03:57:59 +07: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 22:22:17 +07:00
|
|
|
"inconsistency while looking "
|
2010-04-19 12:32:50 +07:00
|
|
|
"for \"%s\" module!\n",
|
2010-04-28 07:17:50 +07:00
|
|
|
machine->root_dir, module);
|
2010-04-19 12:32:50 +07:00
|
|
|
curr_map = map;
|
|
|
|
goto discard_symbol;
|
2009-10-06 00:26:17 +07: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 22:22:17 +07:00
|
|
|
|
2010-04-19 12:32:50 +07:00
|
|
|
if (curr_map->dso->loaded &&
|
2010-04-28 07:17:50 +07: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 22:22:17 +07:00
|
|
|
goto discard_symbol;
|
2009-10-06 00:26:17 +07:00
|
|
|
}
|
2009-10-07 23:48:56 +07:00
|
|
|
/*
|
|
|
|
* So that we look just like we get from .ko files,
|
|
|
|
* i.e. not prelinked, relative to map->start.
|
|
|
|
*/
|
2009-11-28 01:29:18 +07:00
|
|
|
pos->start = curr_map->map_ip(curr_map, pos->start);
|
|
|
|
pos->end = curr_map->map_ip(curr_map, pos->end);
|
|
|
|
} else if (curr_map != map) {
|
2009-10-07 23:48:56 +07:00
|
|
|
char dso_name[PATH_MAX];
|
2011-03-31 20:56:28 +07:00
|
|
|
struct dso *ndso;
|
2009-10-07 23:48:56 +07:00
|
|
|
|
2014-01-29 21:14:43 +07:00
|
|
|
if (delta) {
|
|
|
|
/* Kernel was relocated at boot time */
|
|
|
|
pos->start -= delta;
|
|
|
|
pos->end -= delta;
|
|
|
|
}
|
|
|
|
|
2010-11-29 21:44:15 +07:00
|
|
|
if (count == 0) {
|
|
|
|
curr_map = map;
|
2016-09-02 05:25:52 +07:00
|
|
|
goto add_symbol;
|
2010-11-29 21:44:15 +07:00
|
|
|
}
|
|
|
|
|
2011-03-31 20:56:28 +07:00
|
|
|
if (dso->kernel == DSO_TYPE_GUEST_KERNEL)
|
2010-04-19 12:32:50 +07:00
|
|
|
snprintf(dso_name, sizeof(dso_name),
|
|
|
|
"[guest.kernel].%d",
|
|
|
|
kernel_range++);
|
|
|
|
else
|
|
|
|
snprintf(dso_name, sizeof(dso_name),
|
|
|
|
"[kernel].%d",
|
|
|
|
kernel_range++);
|
2009-10-07 23:48:56 +07:00
|
|
|
|
2011-03-31 20:56:28 +07:00
|
|
|
ndso = dso__new(dso_name);
|
|
|
|
if (ndso == NULL)
|
2009-10-07 23:48:56 +07:00
|
|
|
return -1;
|
|
|
|
|
2011-03-31 20:56:28 +07:00
|
|
|
ndso->kernel = dso->kernel;
|
2010-04-19 12:32:50 +07:00
|
|
|
|
2011-03-31 20:56:28 +07:00
|
|
|
curr_map = map__new2(pos->start, ndso, map->type);
|
2010-02-25 10:00:51 +07:00
|
|
|
if (curr_map == NULL) {
|
2015-06-02 21:53:26 +07:00
|
|
|
dso__put(ndso);
|
2009-10-07 23:48:56 +07:00
|
|
|
return -1;
|
|
|
|
}
|
2009-05-29 00:55:04 +07:00
|
|
|
|
2009-11-28 01:29:18 +07:00
|
|
|
curr_map->map_ip = curr_map->unmap_ip = identity__map_ip;
|
2010-02-04 01:52:00 +07:00
|
|
|
map_groups__insert(kmaps, curr_map);
|
2009-10-07 23:48:56 +07:00
|
|
|
++kernel_range;
|
2014-01-29 21:14:43 +07:00
|
|
|
} else if (delta) {
|
|
|
|
/* Kernel was relocated at boot time */
|
|
|
|
pos->start -= delta;
|
|
|
|
pos->end -= delta;
|
2009-10-07 23:48:56 +07:00
|
|
|
}
|
2016-09-02 05:25:52 +07:00
|
|
|
add_symbol:
|
|
|
|
if (curr_map != map) {
|
|
|
|
rb_erase(&pos->rb_node, root);
|
|
|
|
symbols__insert(&curr_map->dso->symbols[curr_map->type], pos);
|
|
|
|
++moved;
|
|
|
|
} else
|
|
|
|
++count;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
discard_symbol:
|
|
|
|
rb_erase(&pos->rb_node, root);
|
|
|
|
symbol__delete(pos);
|
2009-05-29 00:55:04 +07:00
|
|
|
}
|
|
|
|
|
2010-04-19 12:32:50 +07:00
|
|
|
if (curr_map != map &&
|
2011-03-31 20:56:28 +07:00
|
|
|
dso->kernel == DSO_TYPE_GUEST_KERNEL &&
|
2010-04-28 07:17:50 +07:00
|
|
|
machine__is_default_guest(kmaps->machine)) {
|
2010-04-19 12:32:50 +07:00
|
|
|
dso__set_loaded(curr_map->dso, curr_map->type);
|
|
|
|
}
|
|
|
|
|
2010-11-29 21:44:15 +07:00
|
|
|
return count + moved;
|
2009-10-07 23:48:56 +07:00
|
|
|
}
|
2009-05-29 00:55:04 +07:00
|
|
|
|
2012-12-08 03:39:39 +07:00
|
|
|
bool symbol__restricted_filename(const char *filename,
|
|
|
|
const char *restricted_filename)
|
perf symbols: Handle /proc/sys/kernel/kptr_restrict
Perf uses /proc/modules to figure out where kernel modules are loaded.
With the advent of kptr_restrict, non root users get zeroes for all module
start addresses.
So check if kptr_restrict is non zero and don't generate the syntethic
PERF_RECORD_MMAP events for them.
Warn the user about it in perf record and in perf report.
In perf report the reference relocation symbol being zero means that
kptr_restrict was set, thus /proc/kallsyms has only zeroed addresses, so don't
use it to fixup symbol addresses when using a valid kallsyms (in the buildid
cache) or vmlinux (in the vmlinux path) build-id located automatically or
specified by the user.
Provide an explanation about it in 'perf report' if kernel samples were taken,
checking if a suitable vmlinux or kallsyms was found/specified.
Restricted /proc/kallsyms don't go to the buildid cache anymore.
Example:
[acme@emilia ~]$ perf record -F 100000 sleep 1
WARNING: Kernel address maps (/proc/{kallsyms,modules}) are restricted, check
/proc/sys/kernel/kptr_restrict.
Samples in kernel functions may not be resolved if a suitable vmlinux file is
not found in the buildid cache or in the vmlinux path.
Samples in kernel modules won't be resolved at all.
If some relocation was applied (e.g. kexec) symbols may be misresolved even
with a suitable vmlinux or kallsyms file.
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.005 MB perf.data (~231 samples) ]
[acme@emilia ~]$
[acme@emilia ~]$ perf report --stdio
Kernel address maps (/proc/{kallsyms,modules}) were restricted,
check /proc/sys/kernel/kptr_restrict before running 'perf record'.
If some relocation was applied (e.g. kexec) symbols may be misresolved.
Samples in kernel modules can't be resolved as well.
# Events: 13 cycles
#
# Overhead Command Shared Object Symbol
# ........ ....... ................. .....................
#
20.24% sleep [kernel.kallsyms] [k] page_fault
20.04% sleep [kernel.kallsyms] [k] filemap_fault
19.78% sleep [kernel.kallsyms] [k] __lru_cache_add
19.69% sleep ld-2.12.so [.] memcpy
14.71% sleep [kernel.kallsyms] [k] dput
4.70% sleep [kernel.kallsyms] [k] flush_signal_handlers
0.73% sleep [kernel.kallsyms] [k] perf_event_comm
0.11% sleep [kernel.kallsyms] [k] native_write_msr_safe
#
# (For a higher level overview, try: perf report --sort comm,dso)
#
[acme@emilia ~]$
This is because it found a suitable vmlinux (build-id checked) in
/lib/modules/2.6.39-rc7+/build/vmlinux (use -v in perf report to see the long
file name).
If we remove that file from the vmlinux path:
[root@emilia ~]# mv /lib/modules/2.6.39-rc7+/build/vmlinux \
/lib/modules/2.6.39-rc7+/build/vmlinux.OFF
[acme@emilia ~]$ perf report --stdio
[kernel.kallsyms] with build id 57298cdbe0131f6871667ec0eaab4804dcf6f562
not found, continuing without symbols
Kernel address maps (/proc/{kallsyms,modules}) were restricted, check
/proc/sys/kernel/kptr_restrict before running 'perf record'.
As no suitable kallsyms nor vmlinux was found, kernel samples can't be
resolved.
Samples in kernel modules can't be resolved as well.
# Events: 13 cycles
#
# Overhead Command Shared Object Symbol
# ........ ....... ................. ......
#
80.31% sleep [kernel.kallsyms] [k] 0xffffffff8103425a
19.69% sleep ld-2.12.so [.] memcpy
#
# (For a higher level overview, try: perf report --sort comm,dso)
#
[acme@emilia ~]$
Reported-by: Stephane Eranian <eranian@google.com>
Suggested-by: David Miller <davem@davemloft.net>
Cc: Dave Jones <davej@redhat.com>
Cc: David Miller <davem@davemloft.net>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Kees Cook <kees.cook@canonical.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
Link: http://lkml.kernel.org/n/tip-mt512joaxxbhhp1odop04yit@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2011-05-26 19:53:51 +07:00
|
|
|
{
|
|
|
|
bool restricted = false;
|
|
|
|
|
|
|
|
if (symbol_conf.kptr_restrict) {
|
|
|
|
char *r = realpath(filename, NULL);
|
|
|
|
|
|
|
|
if (r != NULL) {
|
|
|
|
restricted = strcmp(r, restricted_filename) == 0;
|
|
|
|
free(r);
|
|
|
|
return restricted;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return restricted;
|
|
|
|
}
|
|
|
|
|
2013-10-09 19:01:11 +07:00
|
|
|
struct module_info {
|
|
|
|
struct rb_node rb_node;
|
|
|
|
char *name;
|
|
|
|
u64 start;
|
2013-08-07 18:38:51 +07:00
|
|
|
};
|
|
|
|
|
2013-10-09 19:01:11 +07:00
|
|
|
static void add_module(struct module_info *mi, struct rb_root *modules)
|
2013-08-07 18:38:51 +07:00
|
|
|
{
|
2013-10-09 19:01:11 +07:00
|
|
|
struct rb_node **p = &modules->rb_node;
|
|
|
|
struct rb_node *parent = NULL;
|
|
|
|
struct module_info *m;
|
2013-08-07 18:38:51 +07:00
|
|
|
|
2013-10-09 19:01:11 +07:00
|
|
|
while (*p != NULL) {
|
|
|
|
parent = *p;
|
|
|
|
m = rb_entry(parent, struct module_info, rb_node);
|
|
|
|
if (strcmp(mi->name, m->name) < 0)
|
|
|
|
p = &(*p)->rb_left;
|
|
|
|
else
|
|
|
|
p = &(*p)->rb_right;
|
|
|
|
}
|
|
|
|
rb_link_node(&mi->rb_node, parent, p);
|
|
|
|
rb_insert_color(&mi->rb_node, modules);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void delete_modules(struct rb_root *modules)
|
|
|
|
{
|
|
|
|
struct module_info *mi;
|
|
|
|
struct rb_node *next = rb_first(modules);
|
|
|
|
|
|
|
|
while (next) {
|
|
|
|
mi = rb_entry(next, struct module_info, rb_node);
|
|
|
|
next = rb_next(&mi->rb_node);
|
|
|
|
rb_erase(&mi->rb_node, modules);
|
2013-12-28 02:55:14 +07:00
|
|
|
zfree(&mi->name);
|
2013-10-09 19:01:11 +07:00
|
|
|
free(mi);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct module_info *find_module(const char *name,
|
|
|
|
struct rb_root *modules)
|
|
|
|
{
|
|
|
|
struct rb_node *n = modules->rb_node;
|
|
|
|
|
|
|
|
while (n) {
|
|
|
|
struct module_info *m;
|
|
|
|
int cmp;
|
|
|
|
|
|
|
|
m = rb_entry(n, struct module_info, rb_node);
|
|
|
|
cmp = strcmp(name, m->name);
|
|
|
|
if (cmp < 0)
|
|
|
|
n = n->rb_left;
|
|
|
|
else if (cmp > 0)
|
|
|
|
n = n->rb_right;
|
|
|
|
else
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-08-03 20:49:02 +07:00
|
|
|
static int __read_proc_modules(void *arg, const char *name, u64 start,
|
|
|
|
u64 size __maybe_unused)
|
2013-10-09 19:01:11 +07:00
|
|
|
{
|
|
|
|
struct rb_root *modules = arg;
|
|
|
|
struct module_info *mi;
|
|
|
|
|
|
|
|
mi = zalloc(sizeof(struct module_info));
|
|
|
|
if (!mi)
|
2013-08-07 18:38:51 +07:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2013-10-09 19:01:11 +07:00
|
|
|
mi->name = strdup(name);
|
|
|
|
mi->start = start;
|
2013-08-07 18:38:51 +07:00
|
|
|
|
2013-10-09 19:01:11 +07:00
|
|
|
if (!mi->name) {
|
|
|
|
free(mi);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
add_module(mi, modules);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int read_proc_modules(const char *filename, struct rb_root *modules)
|
|
|
|
{
|
|
|
|
if (symbol__restricted_filename(filename, "/proc/modules"))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (modules__parse(filename, modules, __read_proc_modules)) {
|
|
|
|
delete_modules(modules);
|
|
|
|
return -1;
|
|
|
|
}
|
2013-08-07 18:38:51 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-10-14 20:57:29 +07:00
|
|
|
int compare_proc_modules(const char *from, const char *to)
|
|
|
|
{
|
|
|
|
struct rb_root from_modules = RB_ROOT;
|
|
|
|
struct rb_root to_modules = RB_ROOT;
|
|
|
|
struct rb_node *from_node, *to_node;
|
|
|
|
struct module_info *from_m, *to_m;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
if (read_proc_modules(from, &from_modules))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (read_proc_modules(to, &to_modules))
|
|
|
|
goto out_delete_from;
|
|
|
|
|
|
|
|
from_node = rb_first(&from_modules);
|
|
|
|
to_node = rb_first(&to_modules);
|
|
|
|
while (from_node) {
|
|
|
|
if (!to_node)
|
|
|
|
break;
|
|
|
|
|
|
|
|
from_m = rb_entry(from_node, struct module_info, rb_node);
|
|
|
|
to_m = rb_entry(to_node, struct module_info, rb_node);
|
|
|
|
|
|
|
|
if (from_m->start != to_m->start ||
|
|
|
|
strcmp(from_m->name, to_m->name))
|
|
|
|
break;
|
|
|
|
|
|
|
|
from_node = rb_next(from_node);
|
|
|
|
to_node = rb_next(to_node);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!from_node && !to_node)
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
delete_modules(&to_modules);
|
|
|
|
out_delete_from:
|
|
|
|
delete_modules(&from_modules);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-10-09 19:01:11 +07:00
|
|
|
static int do_validate_kcore_modules(const char *filename, struct map *map,
|
|
|
|
struct map_groups *kmaps)
|
|
|
|
{
|
|
|
|
struct rb_root modules = RB_ROOT;
|
|
|
|
struct map *old_map;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = read_proc_modules(filename, &modules);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
old_map = map_groups__first(kmaps, map->type);
|
|
|
|
while (old_map) {
|
|
|
|
struct map *next = map_groups__next(old_map);
|
|
|
|
struct module_info *mi;
|
|
|
|
|
|
|
|
if (old_map == map || old_map->start == map->start) {
|
|
|
|
/* The kernel map */
|
|
|
|
old_map = next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Module must be in memory at the same address */
|
|
|
|
mi = find_module(old_map->dso->short_name, &modules);
|
|
|
|
if (!mi || mi->start != old_map->start) {
|
|
|
|
err = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
old_map = next;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
delete_modules(&modules);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2013-08-07 18:38:51 +07:00
|
|
|
/*
|
2013-10-09 19:01:11 +07:00
|
|
|
* If kallsyms is referenced by name then we look for filename in the same
|
2013-08-07 18:38:51 +07:00
|
|
|
* directory.
|
|
|
|
*/
|
2013-10-09 19:01:11 +07:00
|
|
|
static bool filename_from_kallsyms_filename(char *filename,
|
|
|
|
const char *base_name,
|
|
|
|
const char *kallsyms_filename)
|
2013-08-07 18:38:51 +07:00
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
|
2013-10-09 19:01:11 +07:00
|
|
|
strcpy(filename, kallsyms_filename);
|
|
|
|
name = strrchr(filename, '/');
|
2013-08-07 18:38:51 +07:00
|
|
|
if (!name)
|
|
|
|
return false;
|
|
|
|
|
2013-10-09 19:01:11 +07:00
|
|
|
name += 1;
|
|
|
|
|
|
|
|
if (!strcmp(name, "kallsyms")) {
|
|
|
|
strcpy(name, base_name);
|
2013-08-07 18:38:51 +07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-10-09 19:01:11 +07:00
|
|
|
static int validate_kcore_modules(const char *kallsyms_filename,
|
|
|
|
struct map *map)
|
|
|
|
{
|
2015-04-07 15:22:45 +07:00
|
|
|
struct map_groups *kmaps = map__kmaps(map);
|
2013-10-09 19:01:11 +07:00
|
|
|
char modules_filename[PATH_MAX];
|
|
|
|
|
2015-04-07 15:22:45 +07:00
|
|
|
if (!kmaps)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2013-10-09 19:01:11 +07:00
|
|
|
if (!filename_from_kallsyms_filename(modules_filename, "modules",
|
|
|
|
kallsyms_filename))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (do_validate_kcore_modules(modules_filename, map, kmaps))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-01-29 21:14:41 +07:00
|
|
|
static int validate_kcore_addresses(const char *kallsyms_filename,
|
|
|
|
struct map *map)
|
|
|
|
{
|
|
|
|
struct kmap *kmap = map__kmap(map);
|
|
|
|
|
2015-04-07 15:22:45 +07:00
|
|
|
if (!kmap)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2014-01-29 21:14:41 +07:00
|
|
|
if (kmap->ref_reloc_sym && kmap->ref_reloc_sym->name) {
|
|
|
|
u64 start;
|
|
|
|
|
perf symbols: Accept symbols starting at address 0
That is the case of _text on s390, and we have some functions that return an
address, using address zero to report problems, oops.
This would lead the symbol loading routines to not use "_text" as the reference
relocation symbol, or the first symbol for the kernel, but use instead
"_stext", that is at the same address on x86_64 and others, but not on s390:
[acme@localhost perf-4.11.0-rc6]$ head -15 /proc/kallsyms
0000000000000000 T _text
0000000000000418 t iplstart
0000000000000800 T start
000000000000080a t .base
000000000000082e t .sk8x8
0000000000000834 t .gotr
0000000000000842 t .cmd
0000000000000846 t .parm
000000000000084a t .lowcase
0000000000010000 T startup
0000000000010010 T startup_kdump
0000000000010214 t startup_kdump_relocated
0000000000011000 T startup_continue
00000000000112a0 T _ehead
0000000000100000 T _stext
[acme@localhost perf-4.11.0-rc6]$
Which in turn would make 'perf test vmlinux' to fail because it wouldn't find
the symbols before "_stext" in kallsyms.
Fix it by using the return value only for errors and storing the
address, when the symbol is successfully found, in a provided pointer
arg.
Before this patch:
After:
[acme@localhost perf-4.11.0-rc6]$ tools/perf/perf test -v 1
1: vmlinux symtab matches kallsyms :
--- start ---
test child forked, pid 40693
Looking at the vmlinux_path (8 entries long)
Using /usr/lib/debug/lib/modules/3.10.0-654.el7.s390x/vmlinux for symbols
ERR : 0: _text not on kallsyms
ERR : 0x418: iplstart not on kallsyms
ERR : 0x800: start not on kallsyms
ERR : 0x80a: .base not on kallsyms
ERR : 0x82e: .sk8x8 not on kallsyms
ERR : 0x834: .gotr not on kallsyms
ERR : 0x842: .cmd not on kallsyms
ERR : 0x846: .parm not on kallsyms
ERR : 0x84a: .lowcase not on kallsyms
ERR : 0x10000: startup not on kallsyms
ERR : 0x10010: startup_kdump not on kallsyms
ERR : 0x10214: startup_kdump_relocated not on kallsyms
ERR : 0x11000: startup_continue not on kallsyms
ERR : 0x112a0: _ehead not on kallsyms
<SNIP warnings>
test child finished with -1
---- end ----
vmlinux symtab matches kallsyms: FAILED!
[acme@localhost perf-4.11.0-rc6]$
After:
[acme@localhost perf-4.11.0-rc6]$ tools/perf/perf test -v 1
1: vmlinux symtab matches kallsyms :
--- start ---
test child forked, pid 47160
<SNIP warnings>
test child finished with 0
---- end ----
vmlinux symtab matches kallsyms: Ok
[acme@localhost perf-4.11.0-rc6]$
Reported-by: Michael Petlan <mpetlan@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-9x9bwgd3btwdk1u51xie93fz@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2017-04-28 07:21:09 +07:00
|
|
|
if (kallsyms__get_function_start(kallsyms_filename,
|
|
|
|
kmap->ref_reloc_sym->name, &start))
|
|
|
|
return -ENOENT;
|
2014-01-29 21:14:41 +07:00
|
|
|
if (start != kmap->ref_reloc_sym->addr)
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return validate_kcore_modules(kallsyms_filename, map);
|
|
|
|
}
|
|
|
|
|
2013-10-09 19:01:11 +07:00
|
|
|
struct kcore_mapfn_data {
|
|
|
|
struct dso *dso;
|
|
|
|
enum map_type type;
|
|
|
|
struct list_head maps;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int kcore_mapfn(u64 start, u64 len, u64 pgoff, void *data)
|
|
|
|
{
|
|
|
|
struct kcore_mapfn_data *md = data;
|
|
|
|
struct map *map;
|
|
|
|
|
|
|
|
map = map__new2(start, md->dso, md->type);
|
|
|
|
if (map == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
map->end = map->start + len;
|
|
|
|
map->pgoff = pgoff;
|
|
|
|
|
|
|
|
list_add(&map->node, &md->maps);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-08-07 18:38:51 +07:00
|
|
|
static int dso__load_kcore(struct dso *dso, struct map *map,
|
|
|
|
const char *kallsyms_filename)
|
|
|
|
{
|
2015-04-07 15:22:45 +07:00
|
|
|
struct map_groups *kmaps = map__kmaps(map);
|
|
|
|
struct machine *machine;
|
2013-08-07 18:38:51 +07:00
|
|
|
struct kcore_mapfn_data md;
|
|
|
|
struct map *old_map, *new_map, *replacement_map = NULL;
|
|
|
|
bool is_64_bit;
|
|
|
|
int err, fd;
|
|
|
|
char kcore_filename[PATH_MAX];
|
|
|
|
struct symbol *sym;
|
|
|
|
|
2015-04-07 15:22:45 +07:00
|
|
|
if (!kmaps)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
machine = kmaps->machine;
|
|
|
|
|
2013-08-07 18:38:51 +07:00
|
|
|
/* This function requires that the map is the kernel map */
|
|
|
|
if (map != machine->vmlinux_maps[map->type])
|
|
|
|
return -EINVAL;
|
|
|
|
|
2013-10-09 19:01:11 +07:00
|
|
|
if (!filename_from_kallsyms_filename(kcore_filename, "kcore",
|
|
|
|
kallsyms_filename))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2014-01-29 21:14:41 +07:00
|
|
|
/* Modules and kernel must be present at their original addresses */
|
|
|
|
if (validate_kcore_addresses(kallsyms_filename, map))
|
2013-08-07 18:38:51 +07:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
md.dso = dso;
|
|
|
|
md.type = map->type;
|
|
|
|
INIT_LIST_HEAD(&md.maps);
|
|
|
|
|
|
|
|
fd = open(kcore_filename, O_RDONLY);
|
2015-06-19 15:57:33 +07:00
|
|
|
if (fd < 0) {
|
2015-08-20 17:07:40 +07:00
|
|
|
pr_debug("Failed to open %s. Note /proc/kcore requires CAP_SYS_RAWIO capability to access.\n",
|
|
|
|
kcore_filename);
|
2013-08-07 18:38:51 +07:00
|
|
|
return -EINVAL;
|
2015-06-19 15:57:33 +07:00
|
|
|
}
|
2013-08-07 18:38:51 +07:00
|
|
|
|
|
|
|
/* Read new maps into temporary lists */
|
|
|
|
err = file__read_maps(fd, md.type == MAP__FUNCTION, kcore_mapfn, &md,
|
|
|
|
&is_64_bit);
|
|
|
|
if (err)
|
|
|
|
goto out_err;
|
2014-07-14 17:02:41 +07:00
|
|
|
dso->is_64_bit = is_64_bit;
|
2013-08-07 18:38:51 +07:00
|
|
|
|
|
|
|
if (list_empty(&md.maps)) {
|
|
|
|
err = -EINVAL;
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove old maps */
|
|
|
|
old_map = map_groups__first(kmaps, map->type);
|
|
|
|
while (old_map) {
|
|
|
|
struct map *next = map_groups__next(old_map);
|
|
|
|
|
|
|
|
if (old_map != map)
|
|
|
|
map_groups__remove(kmaps, old_map);
|
|
|
|
old_map = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find the kernel map using the first symbol */
|
|
|
|
sym = dso__first_symbol(dso, map->type);
|
|
|
|
list_for_each_entry(new_map, &md.maps, node) {
|
|
|
|
if (sym && sym->start >= new_map->start &&
|
|
|
|
sym->start < new_map->end) {
|
|
|
|
replacement_map = new_map;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!replacement_map)
|
|
|
|
replacement_map = list_entry(md.maps.next, struct map, node);
|
|
|
|
|
|
|
|
/* Add new maps */
|
|
|
|
while (!list_empty(&md.maps)) {
|
|
|
|
new_map = list_entry(md.maps.next, struct map, node);
|
2015-05-26 01:30:09 +07:00
|
|
|
list_del_init(&new_map->node);
|
2013-08-07 18:38:51 +07:00
|
|
|
if (new_map == replacement_map) {
|
|
|
|
map->start = new_map->start;
|
|
|
|
map->end = new_map->end;
|
|
|
|
map->pgoff = new_map->pgoff;
|
|
|
|
map->map_ip = new_map->map_ip;
|
|
|
|
map->unmap_ip = new_map->unmap_ip;
|
|
|
|
/* Ensure maps are correctly ordered */
|
2015-05-26 02:59:56 +07:00
|
|
|
map__get(map);
|
2013-08-07 18:38:51 +07:00
|
|
|
map_groups__remove(kmaps, map);
|
|
|
|
map_groups__insert(kmaps, map);
|
2015-05-26 02:59:56 +07:00
|
|
|
map__put(map);
|
2013-08-07 18:38:51 +07:00
|
|
|
} else {
|
|
|
|
map_groups__insert(kmaps, new_map);
|
|
|
|
}
|
2015-05-26 02:59:56 +07:00
|
|
|
|
|
|
|
map__put(new_map);
|
2013-08-07 18:38:51 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the data type and long name so that kcore can be read via
|
|
|
|
* dso__data_read_addr().
|
|
|
|
*/
|
|
|
|
if (dso->kernel == DSO_TYPE_GUEST_KERNEL)
|
2013-12-18 02:14:07 +07:00
|
|
|
dso->binary_type = DSO_BINARY_TYPE__GUEST_KCORE;
|
2013-08-07 18:38:51 +07:00
|
|
|
else
|
2013-12-18 02:14:07 +07:00
|
|
|
dso->binary_type = DSO_BINARY_TYPE__KCORE;
|
2013-12-11 01:08:44 +07:00
|
|
|
dso__set_long_name(dso, strdup(kcore_filename), true);
|
2013-08-07 18:38:51 +07:00
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
if (map->type == MAP__FUNCTION)
|
|
|
|
pr_debug("Using %s for kernel object code\n", kcore_filename);
|
|
|
|
else
|
|
|
|
pr_debug("Using %s for kernel data\n", kcore_filename);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_err:
|
|
|
|
while (!list_empty(&md.maps)) {
|
|
|
|
map = list_entry(md.maps.next, struct map, node);
|
2015-05-26 01:30:09 +07:00
|
|
|
list_del_init(&map->node);
|
2015-05-26 02:59:56 +07:00
|
|
|
map__put(map);
|
2013-08-07 18:38:51 +07:00
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2014-01-29 21:14:43 +07:00
|
|
|
/*
|
|
|
|
* If the kernel is relocated at boot time, kallsyms won't match. Compute the
|
|
|
|
* delta based on the relocation reference symbol.
|
|
|
|
*/
|
|
|
|
static int kallsyms__delta(struct map *map, const char *filename, u64 *delta)
|
|
|
|
{
|
|
|
|
struct kmap *kmap = map__kmap(map);
|
|
|
|
u64 addr;
|
|
|
|
|
2015-04-07 15:22:45 +07:00
|
|
|
if (!kmap)
|
|
|
|
return -1;
|
|
|
|
|
2014-01-29 21:14:43 +07:00
|
|
|
if (!kmap->ref_reloc_sym || !kmap->ref_reloc_sym->name)
|
|
|
|
return 0;
|
|
|
|
|
perf symbols: Accept symbols starting at address 0
That is the case of _text on s390, and we have some functions that return an
address, using address zero to report problems, oops.
This would lead the symbol loading routines to not use "_text" as the reference
relocation symbol, or the first symbol for the kernel, but use instead
"_stext", that is at the same address on x86_64 and others, but not on s390:
[acme@localhost perf-4.11.0-rc6]$ head -15 /proc/kallsyms
0000000000000000 T _text
0000000000000418 t iplstart
0000000000000800 T start
000000000000080a t .base
000000000000082e t .sk8x8
0000000000000834 t .gotr
0000000000000842 t .cmd
0000000000000846 t .parm
000000000000084a t .lowcase
0000000000010000 T startup
0000000000010010 T startup_kdump
0000000000010214 t startup_kdump_relocated
0000000000011000 T startup_continue
00000000000112a0 T _ehead
0000000000100000 T _stext
[acme@localhost perf-4.11.0-rc6]$
Which in turn would make 'perf test vmlinux' to fail because it wouldn't find
the symbols before "_stext" in kallsyms.
Fix it by using the return value only for errors and storing the
address, when the symbol is successfully found, in a provided pointer
arg.
Before this patch:
After:
[acme@localhost perf-4.11.0-rc6]$ tools/perf/perf test -v 1
1: vmlinux symtab matches kallsyms :
--- start ---
test child forked, pid 40693
Looking at the vmlinux_path (8 entries long)
Using /usr/lib/debug/lib/modules/3.10.0-654.el7.s390x/vmlinux for symbols
ERR : 0: _text not on kallsyms
ERR : 0x418: iplstart not on kallsyms
ERR : 0x800: start not on kallsyms
ERR : 0x80a: .base not on kallsyms
ERR : 0x82e: .sk8x8 not on kallsyms
ERR : 0x834: .gotr not on kallsyms
ERR : 0x842: .cmd not on kallsyms
ERR : 0x846: .parm not on kallsyms
ERR : 0x84a: .lowcase not on kallsyms
ERR : 0x10000: startup not on kallsyms
ERR : 0x10010: startup_kdump not on kallsyms
ERR : 0x10214: startup_kdump_relocated not on kallsyms
ERR : 0x11000: startup_continue not on kallsyms
ERR : 0x112a0: _ehead not on kallsyms
<SNIP warnings>
test child finished with -1
---- end ----
vmlinux symtab matches kallsyms: FAILED!
[acme@localhost perf-4.11.0-rc6]$
After:
[acme@localhost perf-4.11.0-rc6]$ tools/perf/perf test -v 1
1: vmlinux symtab matches kallsyms :
--- start ---
test child forked, pid 47160
<SNIP warnings>
test child finished with 0
---- end ----
vmlinux symtab matches kallsyms: Ok
[acme@localhost perf-4.11.0-rc6]$
Reported-by: Michael Petlan <mpetlan@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-9x9bwgd3btwdk1u51xie93fz@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2017-04-28 07:21:09 +07:00
|
|
|
if (kallsyms__get_function_start(filename, kmap->ref_reloc_sym->name, &addr))
|
2014-01-29 21:14:43 +07:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
*delta = addr - kmap->ref_reloc_sym->addr;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-19 22:12:49 +07:00
|
|
|
int __dso__load_kallsyms(struct dso *dso, const char *filename,
|
2016-09-02 05:25:52 +07:00
|
|
|
struct map *map, bool no_kcore)
|
2009-10-07 23:48:56 +07:00
|
|
|
{
|
2014-01-29 21:14:43 +07:00
|
|
|
u64 delta = 0;
|
|
|
|
|
perf symbols: Handle /proc/sys/kernel/kptr_restrict
Perf uses /proc/modules to figure out where kernel modules are loaded.
With the advent of kptr_restrict, non root users get zeroes for all module
start addresses.
So check if kptr_restrict is non zero and don't generate the syntethic
PERF_RECORD_MMAP events for them.
Warn the user about it in perf record and in perf report.
In perf report the reference relocation symbol being zero means that
kptr_restrict was set, thus /proc/kallsyms has only zeroed addresses, so don't
use it to fixup symbol addresses when using a valid kallsyms (in the buildid
cache) or vmlinux (in the vmlinux path) build-id located automatically or
specified by the user.
Provide an explanation about it in 'perf report' if kernel samples were taken,
checking if a suitable vmlinux or kallsyms was found/specified.
Restricted /proc/kallsyms don't go to the buildid cache anymore.
Example:
[acme@emilia ~]$ perf record -F 100000 sleep 1
WARNING: Kernel address maps (/proc/{kallsyms,modules}) are restricted, check
/proc/sys/kernel/kptr_restrict.
Samples in kernel functions may not be resolved if a suitable vmlinux file is
not found in the buildid cache or in the vmlinux path.
Samples in kernel modules won't be resolved at all.
If some relocation was applied (e.g. kexec) symbols may be misresolved even
with a suitable vmlinux or kallsyms file.
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.005 MB perf.data (~231 samples) ]
[acme@emilia ~]$
[acme@emilia ~]$ perf report --stdio
Kernel address maps (/proc/{kallsyms,modules}) were restricted,
check /proc/sys/kernel/kptr_restrict before running 'perf record'.
If some relocation was applied (e.g. kexec) symbols may be misresolved.
Samples in kernel modules can't be resolved as well.
# Events: 13 cycles
#
# Overhead Command Shared Object Symbol
# ........ ....... ................. .....................
#
20.24% sleep [kernel.kallsyms] [k] page_fault
20.04% sleep [kernel.kallsyms] [k] filemap_fault
19.78% sleep [kernel.kallsyms] [k] __lru_cache_add
19.69% sleep ld-2.12.so [.] memcpy
14.71% sleep [kernel.kallsyms] [k] dput
4.70% sleep [kernel.kallsyms] [k] flush_signal_handlers
0.73% sleep [kernel.kallsyms] [k] perf_event_comm
0.11% sleep [kernel.kallsyms] [k] native_write_msr_safe
#
# (For a higher level overview, try: perf report --sort comm,dso)
#
[acme@emilia ~]$
This is because it found a suitable vmlinux (build-id checked) in
/lib/modules/2.6.39-rc7+/build/vmlinux (use -v in perf report to see the long
file name).
If we remove that file from the vmlinux path:
[root@emilia ~]# mv /lib/modules/2.6.39-rc7+/build/vmlinux \
/lib/modules/2.6.39-rc7+/build/vmlinux.OFF
[acme@emilia ~]$ perf report --stdio
[kernel.kallsyms] with build id 57298cdbe0131f6871667ec0eaab4804dcf6f562
not found, continuing without symbols
Kernel address maps (/proc/{kallsyms,modules}) were restricted, check
/proc/sys/kernel/kptr_restrict before running 'perf record'.
As no suitable kallsyms nor vmlinux was found, kernel samples can't be
resolved.
Samples in kernel modules can't be resolved as well.
# Events: 13 cycles
#
# Overhead Command Shared Object Symbol
# ........ ....... ................. ......
#
80.31% sleep [kernel.kallsyms] [k] 0xffffffff8103425a
19.69% sleep ld-2.12.so [.] memcpy
#
# (For a higher level overview, try: perf report --sort comm,dso)
#
[acme@emilia ~]$
Reported-by: Stephane Eranian <eranian@google.com>
Suggested-by: David Miller <davem@davemloft.net>
Cc: Dave Jones <davej@redhat.com>
Cc: David Miller <davem@davemloft.net>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Kees Cook <kees.cook@canonical.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
Link: http://lkml.kernel.org/n/tip-mt512joaxxbhhp1odop04yit@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2011-05-26 19:53:51 +07:00
|
|
|
if (symbol__restricted_filename(filename, "/proc/kallsyms"))
|
|
|
|
return -1;
|
|
|
|
|
2011-03-31 20:56:28 +07:00
|
|
|
if (dso__load_all_kallsyms(dso, filename, map) < 0)
|
2009-10-07 23:48:56 +07:00
|
|
|
return -1;
|
|
|
|
|
2014-01-29 21:14:43 +07:00
|
|
|
if (kallsyms__delta(map, filename, &delta))
|
|
|
|
return -1;
|
|
|
|
|
2011-08-24 13:40:15 +07:00
|
|
|
symbols__fixup_end(&dso->symbols[map->type]);
|
2016-09-01 21:00:23 +07:00
|
|
|
symbols__fixup_duplicate(&dso->symbols[map->type]);
|
2011-08-24 13:40:15 +07:00
|
|
|
|
2011-03-31 20:56:28 +07:00
|
|
|
if (dso->kernel == DSO_TYPE_GUEST_KERNEL)
|
2012-07-22 19:14:32 +07:00
|
|
|
dso->symtab_type = DSO_BINARY_TYPE__GUEST_KALLSYMS;
|
2010-04-19 12:32:50 +07:00
|
|
|
else
|
2012-07-22 19:14:32 +07:00
|
|
|
dso->symtab_type = DSO_BINARY_TYPE__KALLSYMS;
|
2009-10-07 23:48:56 +07:00
|
|
|
|
2016-04-19 22:12:49 +07:00
|
|
|
if (!no_kcore && !dso__load_kcore(dso, map, filename))
|
2016-09-02 05:25:52 +07:00
|
|
|
return dso__split_kallsyms_for_kcore(dso, map);
|
2013-08-07 18:38:51 +07:00
|
|
|
else
|
2016-09-02 05:25:52 +07:00
|
|
|
return dso__split_kallsyms(dso, map, delta);
|
2009-10-06 00:26:17 +07:00
|
|
|
}
|
|
|
|
|
2016-04-19 22:12:49 +07:00
|
|
|
int dso__load_kallsyms(struct dso *dso, const char *filename,
|
2016-09-02 05:25:52 +07:00
|
|
|
struct map *map)
|
2016-04-19 22:12:49 +07:00
|
|
|
{
|
2016-09-02 05:25:52 +07:00
|
|
|
return __dso__load_kallsyms(dso, filename, map, false);
|
2016-04-19 22:12:49 +07:00
|
|
|
}
|
|
|
|
|
2017-07-06 08:48:09 +07:00
|
|
|
static int dso__load_perf_map(const char *map_path, struct dso *dso,
|
|
|
|
struct map *map)
|
2009-06-09 01:12:48 +07:00
|
|
|
{
|
|
|
|
char *line = NULL;
|
|
|
|
size_t n;
|
|
|
|
FILE *file;
|
|
|
|
int nr_syms = 0;
|
|
|
|
|
2017-07-06 08:48:09 +07:00
|
|
|
file = fopen(map_path, "r");
|
2009-06-09 01:12:48 +07: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 19:21:42 +07:00
|
|
|
u64 start, size;
|
2009-06-09 01:12:48 +07: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 22:59:47 +07:00
|
|
|
sym = symbol__new(start, size, STB_GLOBAL, line + len);
|
2009-06-09 01:12:48 +07:00
|
|
|
|
|
|
|
if (sym == NULL)
|
|
|
|
goto out_delete_line;
|
|
|
|
|
2016-09-02 05:25:52 +07:00
|
|
|
symbols__insert(&dso->symbols[map->type], sym);
|
|
|
|
nr_syms++;
|
2009-06-09 01:12:48 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
free(line);
|
|
|
|
fclose(file);
|
|
|
|
|
|
|
|
return nr_syms;
|
|
|
|
|
|
|
|
out_delete_line:
|
|
|
|
free(line);
|
|
|
|
out_failure:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-02-20 08:32:56 +07:00
|
|
|
static bool dso__is_compatible_symtab_type(struct dso *dso, bool kmod,
|
|
|
|
enum dso_binary_type type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case DSO_BINARY_TYPE__JAVA_JIT:
|
|
|
|
case DSO_BINARY_TYPE__DEBUGLINK:
|
|
|
|
case DSO_BINARY_TYPE__SYSTEM_PATH_DSO:
|
|
|
|
case DSO_BINARY_TYPE__FEDORA_DEBUGINFO:
|
|
|
|
case DSO_BINARY_TYPE__UBUNTU_DEBUGINFO:
|
|
|
|
case DSO_BINARY_TYPE__BUILDID_DEBUGINFO:
|
|
|
|
case DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO:
|
|
|
|
return !kmod && dso->kernel == DSO_TYPE_USER;
|
|
|
|
|
|
|
|
case DSO_BINARY_TYPE__KALLSYMS:
|
|
|
|
case DSO_BINARY_TYPE__VMLINUX:
|
|
|
|
case DSO_BINARY_TYPE__KCORE:
|
|
|
|
return dso->kernel == DSO_TYPE_KERNEL;
|
|
|
|
|
|
|
|
case DSO_BINARY_TYPE__GUEST_KALLSYMS:
|
|
|
|
case DSO_BINARY_TYPE__GUEST_VMLINUX:
|
|
|
|
case DSO_BINARY_TYPE__GUEST_KCORE:
|
|
|
|
return dso->kernel == DSO_TYPE_GUEST_KERNEL;
|
|
|
|
|
|
|
|
case DSO_BINARY_TYPE__GUEST_KMODULE:
|
2014-11-04 08:14:27 +07:00
|
|
|
case DSO_BINARY_TYPE__GUEST_KMODULE_COMP:
|
2014-02-20 08:32:56 +07:00
|
|
|
case DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE:
|
2014-11-04 08:14:27 +07:00
|
|
|
case DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP:
|
2014-02-20 08:32:56 +07:00
|
|
|
/*
|
|
|
|
* kernel modules know their symtab type - it's set when
|
perf machine: Fix up some more method names
Calling the function 'machine__new_module' implies a new 'module' will
be allocated, when in fact what is returned is a 'struct map' instance,
that not necessarily will be instantiated, as if one already exists with
the given module name, it will be returned instead.
So be consistent with other "find and if not there, create" like
functions, like machine__findnew_thread, machine__findnew_dso, etc, and
rename it to machine__findnew_module_map(), that in turn will call
machine__findnew_module_dso().
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/n/tip-acv830vd3hwww2ih5vjtbmu3@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-06-01 22:01:02 +07:00
|
|
|
* creating a module dso in machine__findnew_module_map().
|
2014-02-20 08:32:56 +07:00
|
|
|
*/
|
|
|
|
return kmod && dso->symtab_type == type;
|
|
|
|
|
|
|
|
case DSO_BINARY_TYPE__BUILD_ID_CACHE:
|
2017-07-06 08:48:13 +07:00
|
|
|
case DSO_BINARY_TYPE__BUILD_ID_CACHE_DEBUGINFO:
|
2014-02-20 08:32:56 +07:00
|
|
|
return true;
|
|
|
|
|
|
|
|
case DSO_BINARY_TYPE__NOT_FOUND:
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-06 08:48:09 +07:00
|
|
|
/* Checks for the existence of the perf-<pid>.map file in two different
|
|
|
|
* locations. First, if the process is a separate mount namespace, check in
|
|
|
|
* that namespace using the pid of the innermost pid namespace. If's not in a
|
|
|
|
* namespace, or the file can't be found there, try in the mount namespace of
|
|
|
|
* the tracing process using our view of its pid.
|
|
|
|
*/
|
|
|
|
static int dso__find_perf_map(char *filebuf, size_t bufsz,
|
|
|
|
struct nsinfo **nsip)
|
|
|
|
{
|
|
|
|
struct nscookie nsc;
|
|
|
|
struct nsinfo *nsi;
|
|
|
|
struct nsinfo *nnsi;
|
|
|
|
int rc = -1;
|
|
|
|
|
|
|
|
nsi = *nsip;
|
|
|
|
|
|
|
|
if (nsi->need_setns) {
|
|
|
|
snprintf(filebuf, bufsz, "/tmp/perf-%d.map", nsi->nstgid);
|
|
|
|
nsinfo__mountns_enter(nsi, &nsc);
|
|
|
|
rc = access(filebuf, R_OK);
|
|
|
|
nsinfo__mountns_exit(&nsc);
|
|
|
|
if (rc == 0)
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
nnsi = nsinfo__copy(nsi);
|
|
|
|
if (nnsi) {
|
|
|
|
nsinfo__put(nsi);
|
|
|
|
|
|
|
|
nnsi->need_setns = false;
|
|
|
|
snprintf(filebuf, bufsz, "/tmp/perf-%d.map", nnsi->tgid);
|
|
|
|
*nsip = nnsi;
|
|
|
|
rc = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2016-09-02 05:25:52 +07:00
|
|
|
int dso__load(struct dso *dso, struct map *map)
|
2009-05-29 00:55:04 +07:00
|
|
|
{
|
2009-11-21 05:51:27 +07:00
|
|
|
char *name;
|
2009-05-29 00:55:04 +07:00
|
|
|
int ret = -1;
|
2012-07-22 19:14:32 +07:00
|
|
|
u_int i;
|
2010-04-28 07:17:50 +07:00
|
|
|
struct machine *machine;
|
2012-07-22 19:14:32 +07:00
|
|
|
char *root_dir = (char *) "";
|
2012-08-11 05:23:02 +07:00
|
|
|
int ss_pos = 0;
|
|
|
|
struct symsrc ss_[2];
|
|
|
|
struct symsrc *syms_ss = NULL, *runtime_ss = NULL;
|
2014-02-20 08:32:56 +07:00
|
|
|
bool kmod;
|
2017-07-06 08:48:09 +07:00
|
|
|
bool perfmap;
|
2015-09-08 07:34:19 +07:00
|
|
|
unsigned char build_id[BUILD_ID_SIZE];
|
2017-07-06 08:48:08 +07:00
|
|
|
struct nscookie nsc;
|
2017-07-06 08:48:09 +07:00
|
|
|
char newmapname[PATH_MAX];
|
|
|
|
const char *map_path = dso->long_name;
|
|
|
|
|
|
|
|
perfmap = strncmp(dso->name, "/tmp/perf-", 10) == 0;
|
|
|
|
if (perfmap) {
|
|
|
|
if (dso->nsinfo && (dso__find_perf_map(newmapname,
|
|
|
|
sizeof(newmapname), &dso->nsinfo) == 0)) {
|
|
|
|
map_path = newmapname;
|
|
|
|
}
|
|
|
|
}
|
2009-05-29 00:55:04 +07:00
|
|
|
|
2017-07-06 08:48:08 +07:00
|
|
|
nsinfo__mountns_enter(dso->nsinfo, &nsc);
|
2015-05-18 07:30:40 +07:00
|
|
|
pthread_mutex_lock(&dso->lock);
|
|
|
|
|
|
|
|
/* check again under the dso->lock */
|
|
|
|
if (dso__loaded(dso, map->type)) {
|
|
|
|
ret = 1;
|
|
|
|
goto out;
|
|
|
|
}
|
2009-10-29 06:51:21 +07:00
|
|
|
|
2015-05-18 07:30:40 +07:00
|
|
|
if (dso->kernel) {
|
|
|
|
if (dso->kernel == DSO_TYPE_KERNEL)
|
2016-09-02 05:25:52 +07:00
|
|
|
ret = dso__load_kernel_sym(dso, map);
|
2015-05-18 07:30:40 +07:00
|
|
|
else if (dso->kernel == DSO_TYPE_GUEST_KERNEL)
|
2016-09-02 05:25:52 +07:00
|
|
|
ret = dso__load_guest_kernel_sym(dso, map);
|
2015-05-18 07:30:40 +07:00
|
|
|
|
|
|
|
goto out;
|
|
|
|
}
|
2010-04-19 12:32:50 +07:00
|
|
|
|
2010-04-28 07:17:50 +07:00
|
|
|
if (map->groups && map->groups->machine)
|
|
|
|
machine = map->groups->machine;
|
2010-04-19 12:32:50 +07:00
|
|
|
else
|
2010-04-28 07:17:50 +07:00
|
|
|
machine = NULL;
|
2009-11-21 05:51:27 +07:00
|
|
|
|
2011-03-31 20:56:28 +07:00
|
|
|
dso->adjust_symbols = 0;
|
2009-06-30 21:43:17 +07:00
|
|
|
|
2017-07-06 08:48:09 +07:00
|
|
|
if (perfmap) {
|
2011-08-10 02:54:18 +07:00
|
|
|
struct stat st;
|
|
|
|
|
2017-07-06 08:48:09 +07:00
|
|
|
if (lstat(map_path, &st) < 0)
|
2015-05-18 07:30:40 +07:00
|
|
|
goto out;
|
2011-08-10 02:54:18 +07:00
|
|
|
|
2015-11-13 02:50:13 +07:00
|
|
|
if (!symbol_conf.force && st.st_uid && (st.st_uid != geteuid())) {
|
2011-08-10 02:54:18 +07:00
|
|
|
pr_warning("File %s not owned by current user or root, "
|
2017-07-06 08:48:09 +07:00
|
|
|
"ignoring it (use -f to override).\n", map_path);
|
2015-05-18 07:30:40 +07:00
|
|
|
goto out;
|
2011-08-10 02:54:18 +07:00
|
|
|
}
|
|
|
|
|
2017-07-06 08:48:09 +07:00
|
|
|
ret = dso__load_perf_map(map_path, dso, map);
|
2012-07-22 19:14:32 +07:00
|
|
|
dso->symtab_type = ret > 0 ? DSO_BINARY_TYPE__JAVA_JIT :
|
|
|
|
DSO_BINARY_TYPE__NOT_FOUND;
|
2015-05-18 07:30:40 +07:00
|
|
|
goto out;
|
2009-08-07 00:43:17 +07:00
|
|
|
}
|
|
|
|
|
2012-07-22 19:14:32 +07:00
|
|
|
if (machine)
|
|
|
|
root_dir = machine->root_dir;
|
|
|
|
|
2013-01-15 00:46:47 +07:00
|
|
|
name = malloc(PATH_MAX);
|
|
|
|
if (!name)
|
2015-05-18 07:30:40 +07:00
|
|
|
goto out;
|
2013-01-15 00:46:47 +07:00
|
|
|
|
2014-02-20 08:32:56 +07:00
|
|
|
kmod = dso->symtab_type == DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE ||
|
2014-11-04 08:14:27 +07:00
|
|
|
dso->symtab_type == DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP ||
|
|
|
|
dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE ||
|
|
|
|
dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE_COMP;
|
2014-02-20 08:32:56 +07:00
|
|
|
|
2015-09-08 07:34:19 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Read the build id if possible. This is required for
|
|
|
|
* DSO_BINARY_TYPE__BUILDID_DEBUGINFO to work
|
|
|
|
*/
|
2016-12-13 22:29:44 +07:00
|
|
|
if (!dso->has_build_id &&
|
2017-02-07 06:48:28 +07:00
|
|
|
is_regular_file(dso->long_name)) {
|
|
|
|
__symbol__join_symfs(name, PATH_MAX, dso->long_name);
|
|
|
|
if (filename__read_build_id(name, build_id, BUILD_ID_SIZE) > 0)
|
2015-09-08 07:34:19 +07:00
|
|
|
dso__set_build_id(dso, build_id);
|
2017-02-07 06:48:28 +07:00
|
|
|
}
|
2015-09-08 07:34:19 +07:00
|
|
|
|
2014-02-20 08:32:56 +07:00
|
|
|
/*
|
|
|
|
* Iterate over candidate debug images.
|
2012-08-11 05:23:02 +07:00
|
|
|
* Keep track of "interesting" ones (those which have a symtab, dynsym,
|
|
|
|
* and/or opd section) for processing.
|
2010-07-30 19:50:09 +07:00
|
|
|
*/
|
2012-07-22 19:14:32 +07:00
|
|
|
for (i = 0; i < DSO_BINARY_TYPE__SYMTAB_CNT; i++) {
|
2012-08-11 05:23:02 +07:00
|
|
|
struct symsrc *ss = &ss_[ss_pos];
|
|
|
|
bool next_slot = false;
|
2017-07-06 08:48:11 +07:00
|
|
|
bool is_reg;
|
2017-07-06 08:48:13 +07:00
|
|
|
bool nsexit;
|
2017-07-06 08:48:11 +07:00
|
|
|
int sirc;
|
2010-07-30 19:50:09 +07:00
|
|
|
|
2012-08-11 05:22:58 +07:00
|
|
|
enum dso_binary_type symtab_type = binary_type_symtab[i];
|
2010-12-10 03:27:07 +07:00
|
|
|
|
2017-07-06 08:48:13 +07:00
|
|
|
nsexit = (symtab_type == DSO_BINARY_TYPE__BUILD_ID_CACHE ||
|
|
|
|
symtab_type == DSO_BINARY_TYPE__BUILD_ID_CACHE_DEBUGINFO);
|
|
|
|
|
2014-02-20 08:32:56 +07:00
|
|
|
if (!dso__is_compatible_symtab_type(dso, kmod, symtab_type))
|
|
|
|
continue;
|
|
|
|
|
2013-12-17 03:03:18 +07:00
|
|
|
if (dso__read_binary_type_filename(dso, symtab_type,
|
|
|
|
root_dir, name, PATH_MAX))
|
2012-07-22 19:14:32 +07:00
|
|
|
continue;
|
2010-07-30 19:50:09 +07:00
|
|
|
|
2017-07-06 08:48:13 +07:00
|
|
|
if (nsexit)
|
2017-07-06 08:48:11 +07:00
|
|
|
nsinfo__mountns_exit(&nsc);
|
|
|
|
|
|
|
|
is_reg = is_regular_file(name);
|
|
|
|
sirc = symsrc__init(ss, dso, name, symtab_type);
|
2016-01-20 18:56:32 +07:00
|
|
|
|
2017-07-06 08:48:13 +07:00
|
|
|
if (nsexit)
|
2017-07-06 08:48:11 +07:00
|
|
|
nsinfo__mountns_enter(dso->nsinfo, &nsc);
|
|
|
|
|
|
|
|
if (!is_reg || sirc < 0) {
|
|
|
|
if (sirc >= 0)
|
|
|
|
symsrc__destroy(ss);
|
2010-07-30 19:50:09 +07:00
|
|
|
continue;
|
2017-07-06 08:48:11 +07:00
|
|
|
}
|
2009-05-29 00:55:04 +07:00
|
|
|
|
2012-08-11 05:23:02 +07:00
|
|
|
if (!syms_ss && symsrc__has_symtab(ss)) {
|
|
|
|
syms_ss = ss;
|
|
|
|
next_slot = true;
|
2013-12-03 14:23:08 +07:00
|
|
|
if (!dso->symsrc_filename)
|
|
|
|
dso->symsrc_filename = strdup(name);
|
2012-08-11 05:23:00 +07:00
|
|
|
}
|
|
|
|
|
2012-08-11 05:23:02 +07:00
|
|
|
if (!runtime_ss && symsrc__possibly_runtime(ss)) {
|
|
|
|
runtime_ss = ss;
|
|
|
|
next_slot = true;
|
2012-08-11 05:22:59 +07:00
|
|
|
}
|
2009-05-29 00:55:04 +07:00
|
|
|
|
2012-08-11 05:23:02 +07:00
|
|
|
if (next_slot) {
|
|
|
|
ss_pos++;
|
2012-04-18 20:46:58 +07:00
|
|
|
|
2012-08-11 05:23:02 +07:00
|
|
|
if (syms_ss && runtime_ss)
|
|
|
|
break;
|
2014-02-20 08:32:54 +07:00
|
|
|
} else {
|
|
|
|
symsrc__destroy(ss);
|
2010-07-30 19:50:09 +07:00
|
|
|
}
|
2012-08-11 05:23:02 +07: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 22:18:36 +07:00
|
|
|
}
|
2010-07-30 19:50:09 +07:00
|
|
|
|
2012-08-11 05:23:02 +07:00
|
|
|
if (!runtime_ss && !syms_ss)
|
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
if (runtime_ss && !syms_ss) {
|
|
|
|
syms_ss = runtime_ss;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We'll have to hope for the best */
|
|
|
|
if (!runtime_ss && syms_ss)
|
|
|
|
runtime_ss = syms_ss;
|
|
|
|
|
2014-02-20 08:32:56 +07:00
|
|
|
if (syms_ss)
|
2016-09-02 05:25:52 +07:00
|
|
|
ret = dso__load_sym(dso, map, syms_ss, runtime_ss, kmod);
|
2014-02-20 08:32:56 +07:00
|
|
|
else
|
2012-08-11 05:23:02 +07:00
|
|
|
ret = -1;
|
|
|
|
|
2012-08-19 22:47:14 +07:00
|
|
|
if (ret > 0) {
|
2012-08-11 05:23:02 +07:00
|
|
|
int nr_plt;
|
|
|
|
|
2016-09-02 05:25:52 +07:00
|
|
|
nr_plt = dso__synthesize_plt_symbols(dso, runtime_ss, map);
|
2012-08-11 05:23:02 +07:00
|
|
|
if (nr_plt > 0)
|
|
|
|
ret += nr_plt;
|
2011-03-23 01:42:14 +07:00
|
|
|
}
|
|
|
|
|
2012-08-11 05:23:02 +07:00
|
|
|
for (; ss_pos > 0; ss_pos--)
|
|
|
|
symsrc__destroy(&ss_[ss_pos - 1]);
|
|
|
|
out_free:
|
2009-05-29 00:55:04 +07:00
|
|
|
free(name);
|
2011-03-31 20:56:28 +07:00
|
|
|
if (ret < 0 && strstr(dso->name, " (deleted)") != NULL)
|
2015-05-18 07:30:40 +07:00
|
|
|
ret = 0;
|
|
|
|
out:
|
|
|
|
dso__set_loaded(dso, map->type);
|
|
|
|
pthread_mutex_unlock(&dso->lock);
|
2017-07-06 08:48:08 +07:00
|
|
|
nsinfo__mountns_exit(&nsc);
|
2015-05-18 07:30:40 +07:00
|
|
|
|
2009-05-29 00:55:04 +07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-03-31 20:56:28 +07: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 03:50:22 +07:00
|
|
|
enum map_type type, const char *name)
|
2009-10-02 13:29:58 +07:00
|
|
|
{
|
2015-05-22 22:58:53 +07:00
|
|
|
struct maps *maps = &mg->maps[type];
|
2015-05-22 21:52:22 +07:00
|
|
|
struct map *map;
|
2009-10-02 13:29:58 +07:00
|
|
|
|
2017-04-04 23:15:04 +07:00
|
|
|
down_read(&maps->lock);
|
2015-05-22 23:45:24 +07:00
|
|
|
|
2015-05-22 21:52:22 +07:00
|
|
|
for (map = maps__first(maps); map; map = map__next(map)) {
|
perf tools: Encode kernel module mappings in perf.data
We were always looking at the running machine /proc/modules,
even when processing a perf.data file, which only makes sense
when we're doing 'perf record' and 'perf report' on the same
machine, and in close sucession, or if we don't use modules at
all, right Peter? ;-)
Now, at 'perf record' time we read /proc/modules, find the long
path for modules, and put them as PERF_MMAP events, just like we
did to encode the reloc reference symbol for vmlinux. Talking
about that now it is encoded in .pgoff, so that we can use
.{start,len} to store the address boundaries for the kernel so
that when we reconstruct the kmaps tree we can do lookups right
away, without having to fixup the end of the kernel maps like we
did in the past (and now only in perf record).
One more step in the 'perf archive' direction when we'll finally
be able to collect data in one machine and analyse in another.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1263396139-4798-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-13 22:22:17 +07:00
|
|
|
if (map->dso && strcmp(map->dso->short_name, name) == 0)
|
2015-05-22 23:45:24 +07:00
|
|
|
goto out_unlock;
|
2009-10-02 13:29:58 +07:00
|
|
|
}
|
|
|
|
|
2015-05-22 23:45:24 +07:00
|
|
|
map = NULL;
|
|
|
|
|
|
|
|
out_unlock:
|
2017-04-04 23:15:04 +07:00
|
|
|
up_read(&maps->lock);
|
2015-05-22 23:45:24 +07:00
|
|
|
return map;
|
2009-10-02 13:29:58 +07:00
|
|
|
}
|
|
|
|
|
2011-03-31 20:56:28 +07:00
|
|
|
int dso__load_vmlinux(struct dso *dso, struct map *map,
|
2016-09-02 05:25:52 +07:00
|
|
|
const char *vmlinux, bool vmlinux_allocated)
|
2009-05-29 00:55:04 +07:00
|
|
|
{
|
2012-08-11 05:22:57 +07:00
|
|
|
int err = -1;
|
|
|
|
struct symsrc ss;
|
2010-12-10 03:27:07 +07:00
|
|
|
char symfs_vmlinux[PATH_MAX];
|
2012-08-11 05:22:58 +07:00
|
|
|
enum dso_binary_type symtab_type;
|
2009-05-29 00:55:04 +07:00
|
|
|
|
2013-07-17 15:08:15 +07:00
|
|
|
if (vmlinux[0] == '/')
|
|
|
|
snprintf(symfs_vmlinux, sizeof(symfs_vmlinux), "%s", vmlinux);
|
|
|
|
else
|
2014-07-29 20:21:58 +07:00
|
|
|
symbol__join_symfs(symfs_vmlinux, vmlinux);
|
2009-05-29 00:55:04 +07:00
|
|
|
|
2012-08-11 05:22:56 +07:00
|
|
|
if (dso->kernel == DSO_TYPE_GUEST_KERNEL)
|
2012-08-11 05:22:58 +07:00
|
|
|
symtab_type = DSO_BINARY_TYPE__GUEST_VMLINUX;
|
2012-08-11 05:22:56 +07:00
|
|
|
else
|
2012-08-11 05:22:58 +07:00
|
|
|
symtab_type = DSO_BINARY_TYPE__VMLINUX;
|
2012-08-11 05:22:56 +07:00
|
|
|
|
2012-08-11 05:22:58 +07:00
|
|
|
if (symsrc__init(&ss, dso, symfs_vmlinux, symtab_type))
|
2012-08-11 05:22:57 +07:00
|
|
|
return -1;
|
|
|
|
|
2016-09-02 05:25:52 +07:00
|
|
|
err = dso__load_sym(dso, map, &ss, &ss, 0);
|
2012-08-11 05:22:57 +07:00
|
|
|
symsrc__destroy(&ss);
|
2009-05-29 00:55:04 +07:00
|
|
|
|
2012-08-11 05:22:54 +07:00
|
|
|
if (err > 0) {
|
2013-08-07 18:38:47 +07:00
|
|
|
if (dso->kernel == DSO_TYPE_GUEST_KERNEL)
|
2013-12-18 02:14:07 +07:00
|
|
|
dso->binary_type = DSO_BINARY_TYPE__GUEST_VMLINUX;
|
2013-08-07 18:38:47 +07:00
|
|
|
else
|
2013-12-18 02:14:07 +07:00
|
|
|
dso->binary_type = DSO_BINARY_TYPE__VMLINUX;
|
2013-12-11 01:19:23 +07:00
|
|
|
dso__set_long_name(dso, vmlinux, vmlinux_allocated);
|
2012-08-11 05:22:54 +07:00
|
|
|
dso__set_loaded(dso, map->type);
|
2010-12-10 03:27:07 +07:00
|
|
|
pr_debug("Using %s for symbols\n", symfs_vmlinux);
|
2012-08-11 05:22:54 +07:00
|
|
|
}
|
2010-02-23 02:15:39 +07:00
|
|
|
|
2009-05-29 00:55:04 +07:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2016-09-02 05:25:52 +07:00
|
|
|
int dso__load_vmlinux_path(struct dso *dso, struct map *map)
|
2010-01-28 06:05:50 +07:00
|
|
|
{
|
|
|
|
int i, err = 0;
|
2014-11-04 08:14:32 +07:00
|
|
|
char *filename = NULL;
|
2010-01-28 06:05:50 +07:00
|
|
|
|
perf symbols: Try the .debug/ DSO cache as a last resort
Not as the first attempt at finding a vmlinux for the running kernel,
this way we get a more informative filename to present in tools, it will
check that the build-id is the same as the one previously loaded in the
DSO in dso->build_id, reading from /sys/kernel/notes, for instance.
E.g. in the annotation TUI, going from 'perf top', for the scsi_sg_alloc
kernel function, in the first line:
Before:
scsi_sg_alloc /root/.debug/.build-id/28/2777c262e6b3c0451375163c9a81c893218ab1
After:
scsi_sg_alloc /lib/modules/4.3.0-rc1+/build/vmlinux
And:
# ls -la /root/.debug/.build-id/28/2777c262e6b3c0451375163c9a81c893218ab1
lrwxrwxrwx. 1 root root 81 Sep 22 16:11 /root/.debug/.build-id/28/2777c262e6b3c0451375163c9a81c893218ab1 -> ../../home/git/build/v4.3.0-rc1+/vmlinux/282777c262e6b3c0451375163c9a81c893218ab1
# file ~/.debug/home/git/build/v4.3.0-rc1+/vmlinux/282777c262e6b3c0451375163c9a81c893218ab1
/root/.debug/home/git/build/v4.3.0-rc1+/vmlinux/282777c262e6b3c0451375163c9a81c893218ab1: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, BuildID[sha1]=282777c262e6b3c0451375163c9a81c893218ab1, not stripped
#
The same as:
# file /lib/modules/4.3.0-rc1+/build/vmlinux
/lib/modules/4.3.0-rc1+/build/vmlinux: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, BuildID[sha1]=282777c262e6b3c0451375163c9a81c893218ab1, not stripped
Furthermore:
# sha256sum /lib/modules/4.3.0-rc1+/build/vmlinux
e7a789bbdc61029ec09140c228e1dd651271f38ef0b8416c0b7d5ff727b98be2 /lib/modules/4.3.0-rc1+/build/vmlinux
# sha256sum ~/.debug/home/git/build/v4.3.0-rc1+/vmlinux/282777c262e6b3c0451375163c9a81c893218ab1
e7a789bbdc61029ec09140c228e1dd651271f38ef0b8416c0b7d5ff727b98be2 /root/.debug/home/git/build/v4.3.0-rc1+/vmlinux/282777c262e6b3c0451375163c9a81c893218ab1
[root@zoo new]#
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-9y42ikzq3jisiddoi6f07n8z@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-10-12 03:17:24 +07:00
|
|
|
pr_debug("Looking at the vmlinux_path (%d entries long)\n",
|
|
|
|
vmlinux_path__nr_entries + 1);
|
|
|
|
|
|
|
|
for (i = 0; i < vmlinux_path__nr_entries; ++i) {
|
2016-09-02 05:25:52 +07:00
|
|
|
err = dso__load_vmlinux(dso, map, vmlinux_path[i], false);
|
perf symbols: Try the .debug/ DSO cache as a last resort
Not as the first attempt at finding a vmlinux for the running kernel,
this way we get a more informative filename to present in tools, it will
check that the build-id is the same as the one previously loaded in the
DSO in dso->build_id, reading from /sys/kernel/notes, for instance.
E.g. in the annotation TUI, going from 'perf top', for the scsi_sg_alloc
kernel function, in the first line:
Before:
scsi_sg_alloc /root/.debug/.build-id/28/2777c262e6b3c0451375163c9a81c893218ab1
After:
scsi_sg_alloc /lib/modules/4.3.0-rc1+/build/vmlinux
And:
# ls -la /root/.debug/.build-id/28/2777c262e6b3c0451375163c9a81c893218ab1
lrwxrwxrwx. 1 root root 81 Sep 22 16:11 /root/.debug/.build-id/28/2777c262e6b3c0451375163c9a81c893218ab1 -> ../../home/git/build/v4.3.0-rc1+/vmlinux/282777c262e6b3c0451375163c9a81c893218ab1
# file ~/.debug/home/git/build/v4.3.0-rc1+/vmlinux/282777c262e6b3c0451375163c9a81c893218ab1
/root/.debug/home/git/build/v4.3.0-rc1+/vmlinux/282777c262e6b3c0451375163c9a81c893218ab1: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, BuildID[sha1]=282777c262e6b3c0451375163c9a81c893218ab1, not stripped
#
The same as:
# file /lib/modules/4.3.0-rc1+/build/vmlinux
/lib/modules/4.3.0-rc1+/build/vmlinux: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, BuildID[sha1]=282777c262e6b3c0451375163c9a81c893218ab1, not stripped
Furthermore:
# sha256sum /lib/modules/4.3.0-rc1+/build/vmlinux
e7a789bbdc61029ec09140c228e1dd651271f38ef0b8416c0b7d5ff727b98be2 /lib/modules/4.3.0-rc1+/build/vmlinux
# sha256sum ~/.debug/home/git/build/v4.3.0-rc1+/vmlinux/282777c262e6b3c0451375163c9a81c893218ab1
e7a789bbdc61029ec09140c228e1dd651271f38ef0b8416c0b7d5ff727b98be2 /root/.debug/home/git/build/v4.3.0-rc1+/vmlinux/282777c262e6b3c0451375163c9a81c893218ab1
[root@zoo new]#
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-9y42ikzq3jisiddoi6f07n8z@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-10-12 03:17:24 +07:00
|
|
|
if (err > 0)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2014-11-04 08:14:32 +07:00
|
|
|
if (!symbol_conf.ignore_vmlinux_buildid)
|
2017-07-06 08:48:13 +07:00
|
|
|
filename = dso__build_id_filename(dso, NULL, 0, false);
|
2010-05-26 23:26:02 +07:00
|
|
|
if (filename != NULL) {
|
2016-09-02 05:25:52 +07:00
|
|
|
err = dso__load_vmlinux(dso, map, filename, true);
|
2013-12-10 21:58:52 +07:00
|
|
|
if (err > 0)
|
2010-05-26 23:26:02 +07:00
|
|
|
goto out;
|
|
|
|
free(filename);
|
|
|
|
}
|
|
|
|
out:
|
2010-01-28 06:05:50 +07:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2016-05-11 20:52:08 +07:00
|
|
|
static bool visible_dir_filter(const char *name, struct dirent *d)
|
|
|
|
{
|
|
|
|
if (d->d_type != DT_DIR)
|
|
|
|
return false;
|
|
|
|
return lsdir_no_dot_filter(name, d);
|
|
|
|
}
|
|
|
|
|
2013-10-14 17:43:43 +07:00
|
|
|
static int find_matching_kcore(struct map *map, char *dir, size_t dir_sz)
|
|
|
|
{
|
|
|
|
char kallsyms_filename[PATH_MAX];
|
|
|
|
int ret = -1;
|
2016-05-11 20:52:08 +07:00
|
|
|
struct strlist *dirs;
|
|
|
|
struct str_node *nd;
|
2013-10-14 17:43:43 +07:00
|
|
|
|
2016-05-11 20:52:08 +07:00
|
|
|
dirs = lsdir(dir, visible_dir_filter);
|
|
|
|
if (!dirs)
|
2013-10-14 17:43:43 +07:00
|
|
|
return -1;
|
|
|
|
|
2016-06-23 21:31:20 +07:00
|
|
|
strlist__for_each_entry(nd, dirs) {
|
2013-10-14 17:43:43 +07:00
|
|
|
scnprintf(kallsyms_filename, sizeof(kallsyms_filename),
|
2016-05-11 20:52:08 +07:00
|
|
|
"%s/%s/kallsyms", dir, nd->s);
|
2014-01-29 21:14:41 +07:00
|
|
|
if (!validate_kcore_addresses(kallsyms_filename, map)) {
|
2013-10-14 17:43:43 +07:00
|
|
|
strlcpy(dir, kallsyms_filename, dir_sz);
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-11 20:52:08 +07:00
|
|
|
strlist__delete(dirs);
|
2013-10-14 17:43:43 +07:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-05-28 22:15:13 +07:00
|
|
|
/*
|
|
|
|
* Use open(O_RDONLY) to check readability directly instead of access(R_OK)
|
|
|
|
* since access(R_OK) only checks with real UID/GID but open() use effective
|
|
|
|
* UID/GID and actual capabilities (e.g. /proc/kcore requires CAP_SYS_RAWIO).
|
|
|
|
*/
|
|
|
|
static bool filename__readable(const char *file)
|
|
|
|
{
|
|
|
|
int fd = open(file, O_RDONLY);
|
|
|
|
if (fd < 0)
|
|
|
|
return false;
|
|
|
|
close(fd);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-10-14 17:43:43 +07:00
|
|
|
static char *dso__find_kallsyms(struct dso *dso, struct map *map)
|
|
|
|
{
|
|
|
|
u8 host_build_id[BUILD_ID_SIZE];
|
2016-05-11 20:51:59 +07:00
|
|
|
char sbuild_id[SBUILD_ID_SIZE];
|
2013-10-14 17:43:43 +07:00
|
|
|
bool is_host = false;
|
|
|
|
char path[PATH_MAX];
|
|
|
|
|
|
|
|
if (!dso->has_build_id) {
|
|
|
|
/*
|
|
|
|
* Last resort, if we don't have a build-id and couldn't find
|
|
|
|
* any vmlinux file, try the running kernel kallsyms table.
|
|
|
|
*/
|
|
|
|
goto proc_kallsyms;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sysfs__read_build_id("/sys/kernel/notes", host_build_id,
|
|
|
|
sizeof(host_build_id)) == 0)
|
|
|
|
is_host = dso__build_id_equal(dso, host_build_id);
|
|
|
|
|
2016-05-28 22:15:28 +07:00
|
|
|
/* Try a fast path for /proc/kallsyms if possible */
|
2013-10-14 17:43:43 +07:00
|
|
|
if (is_host) {
|
|
|
|
/*
|
2016-05-28 22:15:13 +07:00
|
|
|
* Do not check the build-id cache, unless we know we cannot use
|
|
|
|
* /proc/kcore or module maps don't match to /proc/kallsyms.
|
|
|
|
* To check readability of /proc/kcore, do not use access(R_OK)
|
|
|
|
* since /proc/kcore requires CAP_SYS_RAWIO to read and access
|
|
|
|
* can't check it.
|
2013-10-14 17:43:43 +07:00
|
|
|
*/
|
2016-05-28 22:15:13 +07:00
|
|
|
if (filename__readable("/proc/kcore") &&
|
|
|
|
!validate_kcore_addresses("/proc/kallsyms", map))
|
|
|
|
goto proc_kallsyms;
|
2013-10-14 17:43:43 +07:00
|
|
|
}
|
|
|
|
|
2016-05-28 22:15:28 +07:00
|
|
|
build_id__sprintf(dso->build_id, sizeof(dso->build_id), sbuild_id);
|
|
|
|
|
2013-11-26 20:19:24 +07:00
|
|
|
/* Find kallsyms in build-id cache with kcore */
|
2016-05-28 22:15:28 +07:00
|
|
|
scnprintf(path, sizeof(path), "%s/%s/%s",
|
|
|
|
buildid_dir, DSO__NAME_KCORE, sbuild_id);
|
|
|
|
|
2013-11-26 20:19:24 +07:00
|
|
|
if (!find_matching_kcore(map, path, sizeof(path)))
|
|
|
|
return strdup(path);
|
|
|
|
|
2016-05-28 22:15:28 +07:00
|
|
|
/* Use current /proc/kallsyms if possible */
|
|
|
|
if (is_host) {
|
|
|
|
proc_kallsyms:
|
|
|
|
return strdup("/proc/kallsyms");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Finally, find a cache of kallsyms */
|
2016-05-28 22:15:37 +07:00
|
|
|
if (!build_id_cache__kallsyms_path(sbuild_id, path, sizeof(path))) {
|
2013-10-14 17:43:43 +07:00
|
|
|
pr_err("No kallsyms or vmlinux with build-id %s was found\n",
|
|
|
|
sbuild_id);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return strdup(path);
|
|
|
|
}
|
|
|
|
|
2016-09-02 05:25:52 +07:00
|
|
|
static int dso__load_kernel_sym(struct dso *dso, struct map *map)
|
2009-05-29 00:55:19 +07:00
|
|
|
{
|
2009-11-24 01:39:10 +07:00
|
|
|
int err;
|
2010-01-15 03:30:06 +07:00
|
|
|
const char *kallsyms_filename = NULL;
|
|
|
|
char *kallsyms_allocated_filename = NULL;
|
2010-01-19 19:36:14 +07:00
|
|
|
/*
|
2010-12-08 09:39:46 +07: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 19:36:14 +07: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 09:39:46 +07:00
|
|
|
if (symbol_conf.kallsyms_name != NULL) {
|
|
|
|
kallsyms_filename = symbol_conf.kallsyms_name;
|
|
|
|
goto do_kallsyms;
|
|
|
|
}
|
|
|
|
|
2013-09-14 15:32:59 +07:00
|
|
|
if (!symbol_conf.ignore_vmlinux && symbol_conf.vmlinux_name != NULL) {
|
2016-09-02 05:25:52 +07:00
|
|
|
return dso__load_vmlinux(dso, map, symbol_conf.vmlinux_name, false);
|
2010-01-19 19:36:14 +07:00
|
|
|
}
|
2009-11-24 01:39:10 +07:00
|
|
|
|
2013-09-14 15:32:59 +07:00
|
|
|
if (!symbol_conf.ignore_vmlinux && vmlinux_path != NULL) {
|
2016-09-02 05:25:52 +07:00
|
|
|
err = dso__load_vmlinux_path(dso, map);
|
2010-01-28 06:05:50 +07:00
|
|
|
if (err > 0)
|
2013-08-07 18:38:47 +07:00
|
|
|
return err;
|
2009-11-24 01:39:10 +07:00
|
|
|
}
|
|
|
|
|
2010-12-10 03:27:07 +07:00
|
|
|
/* do not try local files if a symfs was given */
|
|
|
|
if (symbol_conf.symfs[0] != 0)
|
|
|
|
return -1;
|
|
|
|
|
2013-10-14 17:43:43 +07:00
|
|
|
kallsyms_allocated_filename = dso__find_kallsyms(dso, map);
|
|
|
|
if (!kallsyms_allocated_filename)
|
|
|
|
return -1;
|
2010-01-22 23:35:02 +07:00
|
|
|
|
2013-10-14 17:43:43 +07:00
|
|
|
kallsyms_filename = kallsyms_allocated_filename;
|
2009-10-02 13:29:58 +07:00
|
|
|
|
2009-11-24 01:39:10 +07:00
|
|
|
do_kallsyms:
|
2016-09-02 05:25:52 +07:00
|
|
|
err = dso__load_kallsyms(dso, kallsyms_filename, map);
|
2010-02-23 02:15:39 +07:00
|
|
|
if (err > 0)
|
|
|
|
pr_debug("Using %s for symbols\n", kallsyms_filename);
|
2010-01-19 19:36:14 +07:00
|
|
|
free(kallsyms_allocated_filename);
|
2009-10-02 13:29:58 +07:00
|
|
|
|
2013-08-07 18:38:51 +07:00
|
|
|
if (err > 0 && !dso__is_kcore(dso)) {
|
2014-07-14 17:02:43 +07:00
|
|
|
dso->binary_type = DSO_BINARY_TYPE__KALLSYMS;
|
2016-05-15 10:19:40 +07:00
|
|
|
dso__set_long_name(dso, DSO__NAME_KALLSYMS, false);
|
2009-11-28 01:29:17 +07:00
|
|
|
map__fixup_start(map);
|
|
|
|
map__fixup_end(map);
|
2009-10-02 13:29:58 +07:00
|
|
|
}
|
2009-08-07 00:43:17 +07:00
|
|
|
|
2009-05-29 00:55:19 +07:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2016-09-02 05:25:52 +07:00
|
|
|
static int dso__load_guest_kernel_sym(struct dso *dso, struct map *map)
|
2010-04-19 12:32:50 +07:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
const char *kallsyms_filename = NULL;
|
2010-04-28 07:17:50 +07:00
|
|
|
struct machine *machine;
|
2010-04-19 12:32:50 +07: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 07:17:50 +07:00
|
|
|
machine = map->groups->machine;
|
2010-04-19 12:32:50 +07:00
|
|
|
|
2010-04-28 07:17:50 +07:00
|
|
|
if (machine__is_default_guest(machine)) {
|
2010-04-19 12:32:50 +07: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 20:56:28 +07:00
|
|
|
err = dso__load_vmlinux(dso, map,
|
2013-12-10 21:58:52 +07:00
|
|
|
symbol_conf.default_guest_vmlinux_name,
|
2016-09-02 05:25:52 +07:00
|
|
|
false);
|
2013-08-07 18:38:47 +07:00
|
|
|
return err;
|
2010-04-19 12:32:50 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
kallsyms_filename = symbol_conf.default_guest_kallsyms;
|
|
|
|
if (!kallsyms_filename)
|
|
|
|
return -1;
|
|
|
|
} else {
|
2010-04-28 07:17:50 +07:00
|
|
|
sprintf(path, "%s/proc/kallsyms", machine->root_dir);
|
2010-04-19 12:32:50 +07:00
|
|
|
kallsyms_filename = path;
|
|
|
|
}
|
|
|
|
|
2016-09-02 05:25:52 +07:00
|
|
|
err = dso__load_kallsyms(dso, kallsyms_filename, map);
|
2013-08-07 18:38:51 +07:00
|
|
|
if (err > 0)
|
2013-08-07 18:38:47 +07:00
|
|
|
pr_debug("Using %s for symbols\n", kallsyms_filename);
|
2013-08-07 18:38:51 +07:00
|
|
|
if (err > 0 && !dso__is_kcore(dso)) {
|
2014-07-14 17:02:43 +07:00
|
|
|
dso->binary_type = DSO_BINARY_TYPE__GUEST_KALLSYMS;
|
2013-08-07 18:38:47 +07:00
|
|
|
machine__mmap_name(machine, path, sizeof(path));
|
2013-12-11 01:08:44 +07:00
|
|
|
dso__set_long_name(dso, strdup(path), true);
|
2010-04-19 12:32:50 +07:00
|
|
|
map__fixup_start(map);
|
|
|
|
map__fixup_end(map);
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
2009-08-12 15:03:49 +07:00
|
|
|
|
2009-11-24 01:39:10 +07:00
|
|
|
static void vmlinux_path__exit(void)
|
|
|
|
{
|
2013-12-27 03:41:15 +07:00
|
|
|
while (--vmlinux_path__nr_entries >= 0)
|
|
|
|
zfree(&vmlinux_path[vmlinux_path__nr_entries]);
|
2015-05-17 17:56:27 +07:00
|
|
|
vmlinux_path__nr_entries = 0;
|
2009-11-24 01:39:10 +07:00
|
|
|
|
2013-12-27 03:41:15 +07:00
|
|
|
zfree(&vmlinux_path);
|
2009-11-24 01:39:10 +07:00
|
|
|
}
|
|
|
|
|
2015-11-25 23:32:45 +07:00
|
|
|
static const char * const vmlinux_paths[] = {
|
|
|
|
"vmlinux",
|
|
|
|
"/boot/vmlinux"
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char * const vmlinux_paths_upd[] = {
|
|
|
|
"/boot/vmlinux-%s",
|
|
|
|
"/usr/lib/debug/boot/vmlinux-%s",
|
|
|
|
"/lib/modules/%s/build/vmlinux",
|
2015-11-25 23:32:46 +07:00
|
|
|
"/usr/lib/debug/lib/modules/%s/vmlinux",
|
|
|
|
"/usr/lib/debug/boot/vmlinux-%s.debug"
|
2015-11-25 23:32:45 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
static int vmlinux_path__add(const char *new_entry)
|
|
|
|
{
|
|
|
|
vmlinux_path[vmlinux_path__nr_entries] = strdup(new_entry);
|
|
|
|
if (vmlinux_path[vmlinux_path__nr_entries] == NULL)
|
|
|
|
return -1;
|
|
|
|
++vmlinux_path__nr_entries;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-08-28 16:48:04 +07:00
|
|
|
static int vmlinux_path__init(struct perf_env *env)
|
2009-11-24 01:39:10 +07:00
|
|
|
{
|
|
|
|
struct utsname uts;
|
|
|
|
char bf[PATH_MAX];
|
2014-08-12 13:40:45 +07:00
|
|
|
char *kernel_version;
|
2015-11-25 23:32:45 +07:00
|
|
|
unsigned int i;
|
2009-11-24 01:39:10 +07:00
|
|
|
|
2015-11-25 23:32:45 +07:00
|
|
|
vmlinux_path = malloc(sizeof(char *) * (ARRAY_SIZE(vmlinux_paths) +
|
|
|
|
ARRAY_SIZE(vmlinux_paths_upd)));
|
2009-11-24 01:39:10 +07:00
|
|
|
if (vmlinux_path == NULL)
|
|
|
|
return -1;
|
|
|
|
|
2015-11-25 23:32:45 +07:00
|
|
|
for (i = 0; i < ARRAY_SIZE(vmlinux_paths); i++)
|
|
|
|
if (vmlinux_path__add(vmlinux_paths[i]) < 0)
|
|
|
|
goto out_fail;
|
2010-12-10 03:27:07 +07:00
|
|
|
|
2014-08-12 13:40:45 +07:00
|
|
|
/* only try kernel version if no symfs was given */
|
2010-12-10 03:27:07 +07:00
|
|
|
if (symbol_conf.symfs[0] != 0)
|
|
|
|
return 0;
|
|
|
|
|
2014-08-12 13:40:45 +07:00
|
|
|
if (env) {
|
|
|
|
kernel_version = env->os_release;
|
|
|
|
} else {
|
|
|
|
if (uname(&uts) < 0)
|
|
|
|
goto out_fail;
|
|
|
|
|
|
|
|
kernel_version = uts.release;
|
|
|
|
}
|
2010-12-10 03:27:07 +07:00
|
|
|
|
2015-11-25 23:32:45 +07:00
|
|
|
for (i = 0; i < ARRAY_SIZE(vmlinux_paths_upd); i++) {
|
|
|
|
snprintf(bf, sizeof(bf), vmlinux_paths_upd[i], kernel_version);
|
|
|
|
if (vmlinux_path__add(bf) < 0)
|
|
|
|
goto out_fail;
|
|
|
|
}
|
2009-11-24 01:39:10 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_fail:
|
|
|
|
vmlinux_path__exit();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-11-19 03:32:48 +07:00
|
|
|
int setup_list(struct strlist **list, const char *list_str,
|
2009-12-16 05:04:40 +07:00
|
|
|
const char *list_name)
|
|
|
|
{
|
|
|
|
if (list_str == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2015-07-20 22:13:34 +07:00
|
|
|
*list = strlist__new(list_str, NULL);
|
2009-12-16 05:04:40 +07:00
|
|
|
if (!*list) {
|
|
|
|
pr_err("problems parsing %s list\n", list_name);
|
|
|
|
return -1;
|
|
|
|
}
|
perf symbols: Store if there is a filter in place
When setting yup the symbols library we setup several filter lists,
for dsos, comms, symbols, etc, and there is code that, if there are
filters, do certain operations, like recalculate the number of non
filtered histogram entries in the top/report TUI.
But they were considering just the "Zoom" filters, when they need to
take into account as well the above mentioned filters (perf top --comms,
--dsos, etc).
So store in symbol_conf.has_filter true if any of those filters is in
place.
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-f5edfmhq69vfvs1kmikq1wep@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-07-13 18:21:57 +07:00
|
|
|
|
|
|
|
symbol_conf.has_filter = true;
|
2009-12-16 05:04:40 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-24 22:52:41 +07:00
|
|
|
int setup_intlist(struct intlist **list, const char *list_str,
|
|
|
|
const char *list_name)
|
|
|
|
{
|
|
|
|
if (list_str == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
*list = intlist__new(list_str);
|
|
|
|
if (!*list) {
|
|
|
|
pr_err("problems parsing %s list\n", list_name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
perf symbols: Handle /proc/sys/kernel/kptr_restrict
Perf uses /proc/modules to figure out where kernel modules are loaded.
With the advent of kptr_restrict, non root users get zeroes for all module
start addresses.
So check if kptr_restrict is non zero and don't generate the syntethic
PERF_RECORD_MMAP events for them.
Warn the user about it in perf record and in perf report.
In perf report the reference relocation symbol being zero means that
kptr_restrict was set, thus /proc/kallsyms has only zeroed addresses, so don't
use it to fixup symbol addresses when using a valid kallsyms (in the buildid
cache) or vmlinux (in the vmlinux path) build-id located automatically or
specified by the user.
Provide an explanation about it in 'perf report' if kernel samples were taken,
checking if a suitable vmlinux or kallsyms was found/specified.
Restricted /proc/kallsyms don't go to the buildid cache anymore.
Example:
[acme@emilia ~]$ perf record -F 100000 sleep 1
WARNING: Kernel address maps (/proc/{kallsyms,modules}) are restricted, check
/proc/sys/kernel/kptr_restrict.
Samples in kernel functions may not be resolved if a suitable vmlinux file is
not found in the buildid cache or in the vmlinux path.
Samples in kernel modules won't be resolved at all.
If some relocation was applied (e.g. kexec) symbols may be misresolved even
with a suitable vmlinux or kallsyms file.
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.005 MB perf.data (~231 samples) ]
[acme@emilia ~]$
[acme@emilia ~]$ perf report --stdio
Kernel address maps (/proc/{kallsyms,modules}) were restricted,
check /proc/sys/kernel/kptr_restrict before running 'perf record'.
If some relocation was applied (e.g. kexec) symbols may be misresolved.
Samples in kernel modules can't be resolved as well.
# Events: 13 cycles
#
# Overhead Command Shared Object Symbol
# ........ ....... ................. .....................
#
20.24% sleep [kernel.kallsyms] [k] page_fault
20.04% sleep [kernel.kallsyms] [k] filemap_fault
19.78% sleep [kernel.kallsyms] [k] __lru_cache_add
19.69% sleep ld-2.12.so [.] memcpy
14.71% sleep [kernel.kallsyms] [k] dput
4.70% sleep [kernel.kallsyms] [k] flush_signal_handlers
0.73% sleep [kernel.kallsyms] [k] perf_event_comm
0.11% sleep [kernel.kallsyms] [k] native_write_msr_safe
#
# (For a higher level overview, try: perf report --sort comm,dso)
#
[acme@emilia ~]$
This is because it found a suitable vmlinux (build-id checked) in
/lib/modules/2.6.39-rc7+/build/vmlinux (use -v in perf report to see the long
file name).
If we remove that file from the vmlinux path:
[root@emilia ~]# mv /lib/modules/2.6.39-rc7+/build/vmlinux \
/lib/modules/2.6.39-rc7+/build/vmlinux.OFF
[acme@emilia ~]$ perf report --stdio
[kernel.kallsyms] with build id 57298cdbe0131f6871667ec0eaab4804dcf6f562
not found, continuing without symbols
Kernel address maps (/proc/{kallsyms,modules}) were restricted, check
/proc/sys/kernel/kptr_restrict before running 'perf record'.
As no suitable kallsyms nor vmlinux was found, kernel samples can't be
resolved.
Samples in kernel modules can't be resolved as well.
# Events: 13 cycles
#
# Overhead Command Shared Object Symbol
# ........ ....... ................. ......
#
80.31% sleep [kernel.kallsyms] [k] 0xffffffff8103425a
19.69% sleep ld-2.12.so [.] memcpy
#
# (For a higher level overview, try: perf report --sort comm,dso)
#
[acme@emilia ~]$
Reported-by: Stephane Eranian <eranian@google.com>
Suggested-by: David Miller <davem@davemloft.net>
Cc: Dave Jones <davej@redhat.com>
Cc: David Miller <davem@davemloft.net>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Kees Cook <kees.cook@canonical.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
Link: http://lkml.kernel.org/n/tip-mt512joaxxbhhp1odop04yit@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2011-05-26 19:53:51 +07:00
|
|
|
static bool symbol__read_kptr_restrict(void)
|
|
|
|
{
|
|
|
|
bool value = false;
|
2016-05-24 16:21:27 +07:00
|
|
|
FILE *fp = fopen("/proc/sys/kernel/kptr_restrict", "r");
|
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 19:53:51 +07:00
|
|
|
|
2016-05-24 16:21:27 +07:00
|
|
|
if (fp != NULL) {
|
|
|
|
char line[8];
|
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 19:53:51 +07:00
|
|
|
|
2016-05-24 16:21:27 +07:00
|
|
|
if (fgets(line, sizeof(line), fp) != NULL)
|
2016-11-15 11:05:45 +07:00
|
|
|
value = ((geteuid() != 0) || (getuid() != 0)) ?
|
2016-05-24 16:21:27 +07:00
|
|
|
(atoi(line) != 0) :
|
|
|
|
(atoi(line) == 2);
|
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 19:53:51 +07:00
|
|
|
|
2016-05-24 16:21:27 +07:00
|
|
|
fclose(fp);
|
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 19:53:51 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2016-08-26 02:09:21 +07:00
|
|
|
int symbol__annotation_init(void)
|
|
|
|
{
|
|
|
|
if (symbol_conf.initialized) {
|
|
|
|
pr_err("Annotation needs to be init before symbol__init()\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (symbol_conf.init_annotation) {
|
|
|
|
pr_warning("Annotation being initialized multiple times\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
symbol_conf.priv_size += sizeof(struct annotation);
|
|
|
|
symbol_conf.init_annotation = true;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-08-28 16:48:04 +07:00
|
|
|
int symbol__init(struct perf_env *env)
|
2009-11-19 05:20:53 +07:00
|
|
|
{
|
2010-12-10 03:27:07 +07:00
|
|
|
const char *symfs;
|
|
|
|
|
2010-09-09 23:30:59 +07:00
|
|
|
if (symbol_conf.initialized)
|
|
|
|
return 0;
|
|
|
|
|
2012-09-11 05:15:01 +07:00
|
|
|
symbol_conf.priv_size = PERF_ALIGN(symbol_conf.priv_size, sizeof(u64));
|
2011-03-30 00:18:39 +07:00
|
|
|
|
2012-08-06 11:41:19 +07:00
|
|
|
symbol__elf_init();
|
|
|
|
|
2009-12-16 05:04:39 +07:00
|
|
|
if (symbol_conf.sort_by_name)
|
|
|
|
symbol_conf.priv_size += (sizeof(struct symbol_name_rb_node) -
|
|
|
|
sizeof(struct symbol));
|
2009-11-24 21:05:15 +07:00
|
|
|
|
2014-08-12 13:40:45 +07:00
|
|
|
if (symbol_conf.try_vmlinux_path && vmlinux_path__init(env) < 0)
|
2009-11-19 05:20:53 +07:00
|
|
|
return -1;
|
|
|
|
|
2009-12-16 05:04:41 +07: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 05:04:40 +07:00
|
|
|
if (setup_list(&symbol_conf.dso_list,
|
|
|
|
symbol_conf.dso_list_str, "dso") < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (setup_list(&symbol_conf.comm_list,
|
|
|
|
symbol_conf.comm_list_str, "comm") < 0)
|
|
|
|
goto out_free_dso_list;
|
|
|
|
|
2015-03-24 22:52:41 +07:00
|
|
|
if (setup_intlist(&symbol_conf.pid_list,
|
|
|
|
symbol_conf.pid_list_str, "pid") < 0)
|
|
|
|
goto out_free_comm_list;
|
|
|
|
|
|
|
|
if (setup_intlist(&symbol_conf.tid_list,
|
|
|
|
symbol_conf.tid_list_str, "tid") < 0)
|
|
|
|
goto out_free_pid_list;
|
|
|
|
|
2009-12-16 05:04:40 +07:00
|
|
|
if (setup_list(&symbol_conf.sym_list,
|
|
|
|
symbol_conf.sym_list_str, "symbol") < 0)
|
2015-03-24 22:52:41 +07:00
|
|
|
goto out_free_tid_list;
|
2009-12-16 05:04:40 +07:00
|
|
|
|
2016-11-26 03:00:21 +07:00
|
|
|
if (setup_list(&symbol_conf.bt_stop_list,
|
|
|
|
symbol_conf.bt_stop_list_str, "symbol") < 0)
|
|
|
|
goto out_free_sym_list;
|
|
|
|
|
2010-12-10 03:27:07 +07: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 19:53:51 +07:00
|
|
|
symbol_conf.kptr_restrict = symbol__read_kptr_restrict();
|
|
|
|
|
2010-09-09 23:30:59 +07: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 04:50:29 +07:00
|
|
|
return 0;
|
2009-12-16 05:04:40 +07:00
|
|
|
|
2016-11-26 03:00:21 +07:00
|
|
|
out_free_sym_list:
|
|
|
|
strlist__delete(symbol_conf.sym_list);
|
2015-03-24 22:52:41 +07:00
|
|
|
out_free_tid_list:
|
|
|
|
intlist__delete(symbol_conf.tid_list);
|
|
|
|
out_free_pid_list:
|
|
|
|
intlist__delete(symbol_conf.pid_list);
|
2009-12-16 05:04:40 +07:00
|
|
|
out_free_comm_list:
|
|
|
|
strlist__delete(symbol_conf.comm_list);
|
2011-12-12 22:16:52 +07:00
|
|
|
out_free_dso_list:
|
|
|
|
strlist__delete(symbol_conf.dso_list);
|
2009-12-16 05:04:40 +07: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 04:50:29 +07:00
|
|
|
}
|
|
|
|
|
2010-07-31 04:31:28 +07:00
|
|
|
void symbol__exit(void)
|
|
|
|
{
|
2010-09-09 23:30:59 +07:00
|
|
|
if (!symbol_conf.initialized)
|
|
|
|
return;
|
2016-11-26 03:00:21 +07:00
|
|
|
strlist__delete(symbol_conf.bt_stop_list);
|
2010-07-31 04:31:28 +07:00
|
|
|
strlist__delete(symbol_conf.sym_list);
|
|
|
|
strlist__delete(symbol_conf.dso_list);
|
|
|
|
strlist__delete(symbol_conf.comm_list);
|
2015-03-24 22:52:41 +07:00
|
|
|
intlist__delete(symbol_conf.tid_list);
|
|
|
|
intlist__delete(symbol_conf.pid_list);
|
2010-07-31 04:31:28 +07:00
|
|
|
vmlinux_path__exit();
|
|
|
|
symbol_conf.sym_list = symbol_conf.dso_list = symbol_conf.comm_list = NULL;
|
2016-11-26 03:00:21 +07:00
|
|
|
symbol_conf.bt_stop_list = NULL;
|
2010-09-09 23:30:59 +07:00
|
|
|
symbol_conf.initialized = false;
|
2010-07-31 04:31:28 +07:00
|
|
|
}
|
2016-05-19 18:47:37 +07:00
|
|
|
|
|
|
|
int symbol__config_symfs(const struct option *opt __maybe_unused,
|
|
|
|
const char *dir, int unset __maybe_unused)
|
|
|
|
{
|
|
|
|
char *bf = NULL;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
symbol_conf.symfs = strdup(dir);
|
|
|
|
if (symbol_conf.symfs == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
/* skip the locally configured cache if a symfs is given, and
|
|
|
|
* config buildid dir to symfs/.debug
|
|
|
|
*/
|
|
|
|
ret = asprintf(&bf, "%s/%s", dir, ".debug");
|
|
|
|
if (ret < 0)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
set_buildid_dir(bf);
|
|
|
|
|
|
|
|
free(bf);
|
|
|
|
return 0;
|
|
|
|
}
|