perf/urgent fixes
Arnaldo Carvalho de Melo
maintainerHi Ingo,
Please consider pulling,
- Arnaldo
The following changes since commit 33636732dcd7cc738a5913bb730d663c6b03c8fb:
perf/x86/intel: Fix bug for "cycles:p" and "cycles:pp" on SLM (2015-01-16 09:06:59 +0100)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git tags/perf-urgent-for-mingo
for you to fetch changes up to 6bcf9c1ff3ec22fd81eba336737d9865476509b1:
perf tools powerpc: Use dwfl_report_elf() instead of offline. (2015-01-16 17:49:30 -0300)
----------------------------------------------------------------
perf/urgent fixes:
User visible:
- Fix segfault when using both the map symtab viewer and annotation in the TUI (Namhyung Kim).
Developer stuff:
- uClibc build fixes (Alexey Brodkin, Vineet Gupta).
- bitops/hweight were moved from tools/perf/ too tools/include, move some leftovers (Arnaldo Carvalho de Melo)
- Fix dwarf unwind x86_64 build error (Namhyung Kim)
- Fix __machine__findnew_thread() error path (Namhyung Kim)
- Propagate error code when write(2) failed in 'perf probe' (Namhyung Kim)
- Use dwfl_report_elf() instead of offline in powerpc bits to properly handle non prelinked DSOs (Sukadev Bhattiprolu).
- Fix dwarf unwind using libunwind in 'perf test' (Wang Nan)
----------------------------------------------------------------
Alexey Brodkin (1):
perf tools: Fix statfs.f_type data type mismatch build error with uclibc
Arnaldo Carvalho de Melo (1):
tools: Remove bitops/hweight usage of bits in tools/perf
Namhyung Kim (4):
perf probe: Propagate error code when write(2) failed perf tools: Fix building error in x86_64 when dwarf unwind is on perf machine: Fix __machine__findnew_thread() error path perf tools: Fix segfault for symbol annotation on TUI
Sukadev Bhattiprolu (1):
perf tools powerpc: Use dwfl_report_elf() instead of offline.
Vineet Gupta (2):
perf tools: Elide strlcpy warning with uclibc
perf tools: Avoid build splat for syscall numbers with uclibc
Wang Nan (1):
perf test: Fix dwarf unwind using libunwind.
tools/include/asm-generic/bitops.h | 2 ++ tools/include/asm-generic/bitops/arch_hweight.h | 1 + tools/include/asm-generic/bitops/const_hweight.h | 1 + tools/include/asm-generic/bitops/hweight.h | 7 +++++ tools/include/linux/bitops.h | 7 ++++- tools/lib/api/fs/debugfs.c | 2 +- tools/lib/api/fs/fs.c | 2 +- tools/perf/MANIFEST | 6 ++++ tools/perf/Makefile.perf | 11 +++++-- tools/perf/arch/powerpc/util/skip-callchain-idx.c | 19 +++++++----- tools/perf/bench/sched-pipe.c | 2 +- tools/perf/builtin-top.c | 1 - tools/perf/config/Makefile | 2 +- tools/perf/config/Makefile.arch | 26 ++++++++-------- tools/perf/perf-sys.h | 1 - tools/perf/tests/dwarf-unwind.c | 36 +++++++++++++++++++++-- tools/perf/util/annotate.h | 8 +---- tools/perf/util/cache.h | 2 ++ tools/perf/util/hweight.c | 31 ------------------- tools/perf/util/include/asm/hweight.h | 8 ----- tools/perf/util/machine.c | 4 ++- tools/perf/util/probe-event.c | 4 ++- tools/perf/util/python-ext-sources | 2 +- tools/perf/util/unwind-libunwind.c | 28 +++++++++++++++++- 24 files changed, 131 insertions(+), 82 deletions(-) create mode 100644 tools/include/asm-generic/bitops/arch_hweight.h create mode 100644 tools/include/asm-generic/bitops/const_hweight.h create mode 100644 tools/include/asm-generic/bitops/hweight.h delete mode 100644 tools/perf/util/hweight.c delete mode 100644 tools/perf/util/include/asm/hweight.h
Arnaldo Carvalho de Melo
maintainerPATCH 1/10 perf probe: Propagate error code when write(2) failed
From: Namhyung Kim <[email protected]>
When it failed to write probe commands to the probe_event file in debugfs, it needs to propagate the error code properly. Current code blindly uses the return value of the write(2) so it always uses -1 (-EPERM) and it might confuse users.
--- tools/perf/util/probe-event.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/util/probe-event.c +3 -1
@@ -2052,9 +2052,11 @@ static int write_probe_trace_event(int fd, struct probe_trace_event *tev)pr_debug ("Writing event: %s\n" , buf);if (!probe_event_dry_run) { ret =write (fd, buf,strlen (buf)); -if (ret <=0 ) +if (ret <=0 ) { + ret = -errno;pr_warning ("Failed to write event: %s\n" ,strerror_r (errno, sbuf,sizeof (sbuf))); + } }free (buf);return ret;
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 2/10 perf tools: Fix building error in x86_64 when dwarf unwind is on
In reply to Arnaldo Carvalho de MeloFrom: Namhyung Kim <[email protected]>
When build with 'make ARCH=x86' and dwarf unwind is on, there is a compiling error:
CC /home/wn/perf/arch/x86/util/unwind-libdw.o
CC /home/wn/perf/arch/x86/tests/regs_load.o
arch/x86/tests/regs_load.S: Assembler messages:
arch/x86/tests/regs_load.S:65: Error: operand type mismatch for push' arch/x86/tests/regs_load.S:72: Error: operand type mismatch for pop' make[1]: *** [/home/wn/perf/arch/x86/tests/regs_load.o] Error 1 make[1]: INTERNAL: Exiting with 25 jobserver tokens available; should be 24!
make: *** [all] Error 2
...
Which is caused by incorrectly undefine macro HAVE_ARCH_X86_64_SUPPORT. 'config/Makefile.arch' tests __x86_64__ only when 'ARCH=x86_64'. However, when building x86_64 kernel, ARCH=x86 is valid and commonly used. Build systems, such as yocto, uses x86_64 compiler with 'ARCH=x86' to build x86_64 perf, which causes mismatching.
As __LP64__ is defined for x86_64 as well, we can consolidate the __x86_64__ check to the __LP64__ check and get rid of the IS_X86_64 IMHO.
(This patch is made by Namhyung Kim when replying my v1 patch:
https://lkml.org/lkml/2015/1/7/17
I modified the code to remove dependency on RAW_ARCH:
https://lkml.org/lkml/2015/1/7/865
Namhyung Kim didn't provide his SOB in his original email. I add mine only for my modification.)
--- tools/perf/Makefile.perf | 4 +++- tools/perf/config/Makefile | 2 +- tools/perf/config/Makefile.arch | 26 +++++++++++++------------- 3 files changed, 17 insertions(+), 15 deletions(-)
tools/perf/Makefile.perf +3 -1
@@ -462,10 +462,12 @@ BUILTIN_OBJS += $(OUTPUT)builtin-bench.o # Benchmark modules BUILTIN_OBJS += $(OUTPUT)bench/sched-messaging.o BUILTIN_OBJS += $(OUTPUT)bench/sched-pipe.o -ifeq ($(RAW_ARCH),x86_64) +ifeq ($(ARCH), x86) +ifeq ($(IS_64_BIT), 1) BUILTIN_OBJS += $(OUTPUT)bench/mem-memcpy-x86-64-asm.o BUILTIN_OBJS += $(OUTPUT)bench/mem-memset-x86-64-asm.o endif +endif BUILTIN_OBJS += $(OUTPUT)bench/mem-memcpy.o BUILTIN_OBJS += $(OUTPUT)bench/futex-hash.o BUILTIN_OBJS += $(OUTPUT)bench/futex-wake.o
tools/perf/config/Makefile +1 -1
@@ -20,7 +20,7 @@ NO_PERF_REGS := 1 # Additional ARCH settings for x86 ifeq ($(ARCH),x86) - ifeq (${IS_X86_64}, 1) + ifeq (${IS_64_BIT}, 1) CFLAGS += -DHAVE_ARCH_X86_64_SUPPORT ARCH_INCLUDE = ../../arch/x86/lib/memcpy_64.S ../../arch/x86/lib/memset_64.S LIBUNWIND_LIBS = -lunwind -lunwind-x86_64
tools/perf/config/Makefile.arch +13 -13
@@ -1,7 +1,7 @@ uname_M := $(shell uname -m 2>/dev/null || echo not) -ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \ +RAW_ARCH := $(shell echo $(uname_M) | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \ -e s/arm.*/arm/ -e s/sa110/arm/ \ -e s/s390x/s390/ -e s/parisc64/parisc/ \ -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
@@ -9,23 +9,23 @@ ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \ -e s/tile.*/tile/ ) # Additional ARCH settings for x86 -ifeq ($(ARCH),i386) - override ARCH := x86 +ifeq ($(RAW_ARCH),i386) + ARCH ?= x86 endif -ifeq ($(ARCH),x86_64) - override ARCH := x86 - IS_X86_64 := 0 - ifeq (, $(findstring m32,$(CFLAGS))) - IS_X86_64 := $(shell echo __x86_64__ | ${CC} -E -x c - | tail -n 1) - RAW_ARCH := x86_64 +ifeq ($(RAW_ARCH),x86_64) + ARCH ?= x86 + + ifneq (, $(findstring m32,$(CFLAGS))) + RAW_ARCH := x86_32 endif endif -ifeq (${IS_X86_64}, 1) +ARCH ?= $(RAW_ARCH) + +LP64 := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1) +ifeq ($(LP64), 1) IS_64_BIT := 1 -else ifeq ($(ARCH),x86) - IS_64_BIT := 0 else - IS_64_BIT := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1) + IS_64_BIT := 0 endif
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 3/10 perf machine: Fix __machine__findnew_thread() error path
In reply to Arnaldo Carvalho de MeloFrom: Namhyung Kim <[email protected]>
When thread__init_map_groups() fails, a new thread should be removed from the rbtree since it's gonna be freed. Also update last match cache only if the function succeeded.
--- tools/perf/util/machine.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/util/machine.c +3 -1
@@ -389,7 +389,6 @@ static struct thread *__machine__findnew_thread(struct machine *machine,if (th !=NULL ) {rb_link_node (&th->rb_node, parent, p);rb_insert_color (&th->rb_node, &machine->threads); - machine->last_match = th;/* * We have to initialize map_groups separately
@@ -400,9 +399,12 @@ static struct thread *__machine__findnew_thread(struct machine *machine,* leader and that would screwed the rb tree. */ if (thread__init_map_groups (th, machine)) { +rb_erase (&th->rb_node, &machine->threads);thread__delete (th);return NULL ; } + + machine->last_match = th; }return th;
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 4/10 tools: Remove bitops/hweight usage of bits in tools/perf
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
We need to use lib/hweight.c for that, just like we do for lib/rbtree.c, so tools need to link hweight.o. For now do it directly, but we need to have a tools/lib/lk.a or .so that collects these goodies...
--- tools/include/asm-generic/bitops.h | 2 ++ tools/include/asm-generic/bitops/arch_hweight.h | 1 + tools/include/asm-generic/bitops/const_hweight.h | 1 + tools/include/asm-generic/bitops/hweight.h | 7 ++++++ tools/include/linux/bitops.h | 7 +++++- tools/perf/MANIFEST | 6 +++++ tools/perf/Makefile.perf | 7 +++++- tools/perf/util/hweight.c | 31 ------------------------ tools/perf/util/include/asm/hweight.h | 8 ------ tools/perf/util/python-ext-sources | 2 +- 10 files changed, 30 insertions(+), 42 deletions(-) create mode 100644 tools/include/asm-generic/bitops/arch_hweight.h create mode 100644 tools/include/asm-generic/bitops/const_hweight.h create mode 100644 tools/include/asm-generic/bitops/hweight.h delete mode 100644 tools/perf/util/hweight.c delete mode 100644 tools/perf/util/include/asm/hweight.h
tools/include/asm-generic/bitops.h +2 -0
@@ -22,6 +22,8 @@#error only <linux/bitops.h> can be included directly#endif +#include <asm-generic/bitops/hweight.h> +#include <asm-generic/bitops/atomic.h> #endif /* __TOOLS_ASM_GENERIC_BITOPS_H */
tools/include/asm-generic/bitops/arch_hweight.h new file +1 -0
@@ -0,0 +1 @@ +#include "../../../../include/asm-generic/bitops/arch_hweight.h"
tools/include/asm-generic/bitops/const_hweight.h new file +1 -0
@@ -0,0 +1 @@ +#include "../../../../include/asm-generic/bitops/const_hweight.h"
tools/include/asm-generic/bitops/hweight.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef _TOOLS_LINUX_ASM_GENERIC_BITOPS_HWEIGHT_H_ +#define _TOOLS_LINUX_ASM_GENERIC_BITOPS_HWEIGHT_H_ + +#include <asm-generic/bitops/arch_hweight.h> +#include <asm-generic/bitops/const_hweight.h> + +#endif /* _TOOLS_LINUX_ASM_GENERIC_BITOPS_HWEIGHT_H_ */
tools/include/linux/bitops.h +6 -1
@@ -1,9 +1,9 @@#ifndef _TOOLS_LINUX_BITOPS_H_#define _TOOLS_LINUX_BITOPS_H_ +#include <asm/types.h> #include <linux/kernel.h> #include <linux/compiler.h> -#include <asm/hweight.h> #ifndef __WORDSIZE#define __WORDSIZE (__SIZEOF_LONG__ * 8)
@@ -19,6 +19,11 @@#define BITS_TO_U32 (nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(u32))#define BITS_TO_BYTES (nr) DIV_ROUND_UP(nr, BITS_PER_BYTE) +extern unsigned int __sw_hweight8 (unsigned int w); +extern unsigned int __sw_hweight16 (unsigned int w); +extern unsigned int __sw_hweight32 (unsigned int w); +extern unsigned long __sw_hweight64 (__u64 w); +/* * Include this here because some architectures need generic_ffs/fls in * scope
tools/perf/MANIFEST +6 -0
@@ -6,12 +6,15 @@ tools/lib/symbol/kallsyms.c tools/lib/symbol/kallsyms.h tools/lib/util/find_next_bit.c tools/include/asm/bug.h +tools/include/asm-generic/bitops/arch_hweight.h tools/include/asm-generic/bitops/atomic.h +tools/include/asm-generic/bitops/const_hweight.h tools/include/asm-generic/bitops/__ffs.h tools/include/asm-generic/bitops/__fls.h tools/include/asm-generic/bitops/find.h tools/include/asm-generic/bitops/fls64.h tools/include/asm-generic/bitops/fls.h +tools/include/asm-generic/bitops/hweight.h tools/include/asm-generic/bitops.h tools/include/linux/bitops.h tools/include/linux/compiler.h
@@ -19,6 +22,8 @@ tools/include/linux/export.h tools/include/linux/hash.h tools/include/linux/log2.h tools/include/linux/types.h +include/asm-generic/bitops/arch_hweight.h +include/asm-generic/bitops/const_hweight.h include/asm-generic/bitops/fls64.h include/asm-generic/bitops/__fls.h include/asm-generic/bitops/fls.h
@@ -29,6 +34,7 @@ include/linux/list.h include/linux/hash.h include/linux/stringify.h lib/find_next_bit.c +lib/hweight.c lib/rbtree.c include/linux/swab.h arch/*/include/asm/unistd*.h
tools/perf/Makefile.perf +6 -1
@@ -232,12 +232,15 @@ LIB_H += ../include/linux/hash.h LIB_H += ../../include/linux/stringify.h LIB_H += util/include/linux/bitmap.h LIB_H += ../include/linux/bitops.h +LIB_H += ../include/asm-generic/bitops/arch_hweight.h LIB_H += ../include/asm-generic/bitops/atomic.h +LIB_H += ../include/asm-generic/bitops/const_hweight.h LIB_H += ../include/asm-generic/bitops/find.h LIB_H += ../include/asm-generic/bitops/fls64.h LIB_H += ../include/asm-generic/bitops/fls.h LIB_H += ../include/asm-generic/bitops/__ffs.h LIB_H += ../include/asm-generic/bitops/__fls.h +LIB_H += ../include/asm-generic/bitops/hweight.h LIB_H += ../include/asm-generic/bitops.h LIB_H += ../include/linux/compiler.h LIB_H += ../include/linux/log2.h
@@ -255,7 +258,6 @@ LIB_H += util/include/linux/linkage.h LIB_H += util/include/asm/asm-offsets.h LIB_H += ../include/asm/bug.h LIB_H += util/include/asm/byteorder.h -LIB_H += util/include/asm/hweight.h LIB_H += util/include/asm/swab.h LIB_H += util/include/asm/system.h LIB_H += util/include/asm/uaccess.h
@@ -745,6 +747,9 @@ $(OUTPUT)util/kallsyms.o: ../lib/symbol/kallsyms.c $(OUTPUT)PERF-CFLAGS $(OUTPUT)util/rbtree.o: ../../lib/rbtree.c $(OUTPUT)PERF-CFLAGS $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) -Wno-unused-parameter -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< +$(OUTPUT)util/hweight.o: ../../lib/hweight.c $(OUTPUT)PERF-CFLAGS + $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) -Wno-unused-parameter -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< + $(OUTPUT)util/find_next_bit.o: ../lib/util/find_next_bit.c $(OUTPUT)PERF-CFLAGS $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) -Wno-unused-parameter -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<
tools/perf/util/hweight.c deleted +0 -31
@@ -1,31 +0,0 @@ -#include <linux/bitops.h> - -/** -* hweightN - returns the hamming weight of a N-bit word -* @x: the word to weigh -* -* The Hamming Weight of a number is the total number of bits set in it. -*/ - -unsigned int hweight32 (unsigned int w) -{ -unsigned int res = w - ((w >>1 ) &0x55555555 ); - res = (res &0x33333333 ) + ((res >>2 ) &0x33333333 ); - res = (res + (res >>4 )) &0x0F0F0F0F ; - res = res + (res >>8 ); -return (res + (res >>16 )) &0x000000FF ; -} - -unsigned long hweight64 (__u64 w) -{ -#if BITS_PER_LONG ==32 -return hweight32 ((unsigned int )(w >>32 )) +hweight32 ((unsigned int )w); -#elif BITS_PER_LONG ==64 -__u64 res = w - ((w >>1 ) &0x5555555555555555ul ); - res = (res &0x3333333333333333ul ) + ((res >>2 ) &0x3333333333333333ul ); - res = (res + (res >>4 )) &0x0F0F0F0F0F0F0F0Ful ; - res = res + (res >>8 ); - res = res + (res >>16 ); -return (res + (res >>32 )) &0x00000000000000FFul ; -#endif -}
tools/perf/util/include/asm/hweight.h deleted +0 -8
@@ -1,8 +0,0 @@ -#ifndef PERF_HWEIGHT_H -#define PERF_HWEIGHT_H - -#include <linux/types.h> -unsigned int hweight32 (unsigned int w); -unsigned long hweight64 (__u64 w); - -#endif /* PERF_HWEIGHT_H */
tools/perf/util/python-ext-sources +1 -1
@@ -10,7 +10,7 @@ util/ctype.c util/evlist.c util/evsel.c util/cpumap.c -util/hweight.c +../../lib/hweight.c util/thread_map.c util/util.c util/xyarray.c
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 5/10 perf tools: Fix statfs.f_type data type mismatch build error with uclibc
In reply to Arnaldo Carvalho de MeloFrom: Alexey Brodkin <[email protected]>
ARC Linux uses the no legacy syscalls abi and corresponding uClibc headers statfs defines f_type to be U32 which causes perf build breakage
http://git.uclibc.org/uClibc/tree/libc/sysdeps/linux/common-generic/bits/statfs.h
----------->8---------------
CC fs/fs.o
fs/fs.c: In function 'fs__valid_mount':
fs/fs.c:82:24: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
else if (st_fs.f_type != magic)
^ cc1: all warnings being treated as errors
----------->8---------------
--- tools/lib/api/fs/debugfs.c | 2 +- tools/lib/api/fs/fs.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
tools/lib/api/fs/debugfs.c +1 -1
@@ -67,7 +67,7 @@ int debugfs_valid_mountpoint(const char *debugfs)if (statfs (debugfs, &st_fs) <0 )return -ENOENT ; -else if (st_fs.f_type != (long )DEBUGFS_MAGIC ) +else if ((long )st_fs.f_type != (long )DEBUGFS_MAGIC )return -ENOENT ;return 0 ;
tools/lib/api/fs/fs.c +1 -1
@@ -79,7 +79,7 @@ static int fs__valid_mount(const char *fs, long magic)if (statfs (fs, &st_fs) <0 )return -ENOENT ; -else if (st_fs.f_type != magic) +else if ((long )st_fs.f_type != magic)return -ENOENT ;return 0 ;
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 6/10 perf tools: Elide strlcpy warning with uclibc
In reply to Arnaldo Carvalho de MeloFrom: Vineet Gupta <[email protected]>
----------------->8------------------
CC bench/sched-pipe.o
In file included from builtin-annotate.c:13:0:util/cache.h:76:15: warning: redundant redeclaration of 'strlcpy' [-Wredundant-decls]
extern size_t strlcpy(char *dest, const char *src, size_t size);
^In file included from util/util.h:55:0,
from builtin.h:4,
from builtin-annotate.c:8:~/vineetg/arc/gnu/INSTALL_1412-arc-2014.12-rc1/arc-snps-linux-uclibc/sysroot/usr/include/string.h:396:15:
note: previous declaration of 'strlcpy' was here
extern size_t strlcpy(char *__restrict dst, const char *__restrict src,
----------------->8------------------
--- tools/perf/util/cache.h | 2 ++ 1 file changed, 2 insertions(+)
tools/perf/util/cache.h +2 -0
@@ -71,7 +71,9 @@ extern char *perf_path(const char *fmt, ...) __attribute__((format (printf, 1, 2extern char *perf_pathdup (const char *fmt, ...) __attribute__((format (printf,1 ,2 ))); +#ifndef __UCLIBC__/* Matches the libc/libbsd function attribute so we declare this unconditionally: */ extern size_t strlcpy (char *dest,const char *src,size_t size); +#endif #endif /* __PERF_CACHE_H */
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 7/10 perf tools: Avoid build splat for syscall numbers with uclibc
In reply to Arnaldo Carvalho de MeloFrom: Vineet Gupta <[email protected]>
This is due to duplicated unistd inclusion (via uClibc headers + kernel headers) Also seen on ARM uClibc based tools
------- ARC build ---------->8-------------
CC util/evlist.o
In file included from ~/arc/k.org/arch/arc/include/uapi/asm/unistd.h:25:0,
from util/../perf-sys.h:10,
from util/../perf.h:15,
from util/event.h:7,
from util/event.c:3:~/arc/k.org/include/uapi/asm-generic/unistd.h:906:0:
warning: "__NR_fcntl64" redefined [enabled by default]
#define __NR_fcntl64 __NR3264_fcntl
^
In file included from ~/arc/gnu/INSTALL_1412-arc-2014.12-rc1/arc-snps-linux-uclibc/sysroot/usr/include/sys/syscall.h:24:0,
from util/../perf-sys.h:6,
----------------->8-------------------
------- ARM build ---------->8-------------
CC FPIC plugin_scsi.o
In file included from util/../perf-sys.h:9:0,
from util/../perf.h:15,
from util/cache.h:7,
from perf.c:12:~/arc/k.org/arch/arm/include/uapi/asm/unistd.h:28:0:
warning: "__NR_restart_syscall" redefined [enabled by default]
In file included from ~/buildroot/host/usr/arm-buildroot-linux-uclibcgnueabi/sysroot/usr/include/sys/syscall.h:25:0,
from util/../perf-sys.h:6,
from util/../perf.h:15,
from util/cache.h:7,
from perf.c:12:~/buildroot/host/usr/arm-buildroot-linux-uclibcgnueabi/sysroot/usr/include/bits/sysnum.h:17:0:
note: this is the location of the previous definition
----------------->8-------------------
--- tools/perf/bench/sched-pipe.c | 2 +- tools/perf/builtin-top.c | 1 - tools/perf/perf-sys.h | 1 - 3 files changed, 1 insertion(+), 3 deletions(-)
tools/perf/bench/sched-pipe.c +1 -1
@@ -19,12 +19,12 @@#include <stdlib.h> #include <signal.h> #include <sys/wait.h> -#include <linux/unistd.h> #include <string.h> #include <errno.h> #include <assert.h> #include <sys/time.h> #include <sys/types.h> +#include <sys/syscall.h> #include <pthread.h>
tools/perf/builtin-top.c +0 -1
@@ -66,7 +66,6 @@#include <sys/utsname.h> #include <sys/mman.h> -#include <linux/unistd.h> #include <linux/types.h> static volatile int done;
tools/perf/perf-sys.h +0 -1
@@ -6,7 +6,6 @@#include <sys/syscall.h> #include <linux/types.h> #include <linux/perf_event.h> -#include <asm/unistd.h> #if defined(__i386__)#define mb () asm volatile("lock; addl $0,0(%%esp)" ::: "memory")
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 8/10 perf test: Fix dwarf unwind using libunwind.
In reply to Arnaldo Carvalho de MeloFrom: Wang Nan <[email protected]>
Perf tool fails to unwind user stack if the event raises in a shared object. This patch improves tests/dwarf-unwind.c to demonstrate the problem by utilizing commonly used glibc function "bsearch". If perf is not statically linked, the testcase will try to unwind a mixed call trace.
By debugging libunwind I found that there is a bug in unwind-libunwind:
it always passes 0 as segbase to libunwind, cause libunwind unable to locate debug_frame entry fir first level ip address (I add some more debugging output into libunwind to make things clear):
>_Uarm_dwarf_find_debug_frame: start_ip = 10be98, end_ip = 10c2a4
>_Uarm_dwarf_find_debug_frame: found debug_frame table `/lib/libc-2.18.so': segbase=0x0, len=7, gp=0x0, table_data=0x449388
>_Uarm_dwarf_search_unwind_table: call lookup:ip = b6cd3bcc, segbase = 0, rel_ip = b6cd3bcc
>lookup: e->start_ip_offset = bcf18 (rel_ip = b6cd3bcc)
>lookup: e->start_ip_offset = 6d314 (rel_ip = b6cd3bcc)
>lookup: e->start_ip_offset = 33d0c (rel_ip = b6cd3bcc)
...
>lookup: e->start_ip_offset = 15d0c (rel_ip = b6cd3bcc)
>lookup: e->start_ip_offset = 15c40 (rel_ip = b6cd3bcc)Quoted 1 line
_Uarm_dwarf_search_unwind_table: IPb6cd3bccinside range b6c12000-b6d4c000, but no explicit unwind info found
>put_rs_cache: unmasking signals/interrupts and releasing lock
>_Uarm_dwarf_step: returning -10
Quoted 1 line
_Uarm_step: dwarf_step()=-10
This patch passes map->start as segbase to dwarf_find_debug_frame(), so di will be initialized correctly.
In addition, dso and executable are different when setting segbase. This patch first check whether the elf is executable, and pass segbase only for shared object.
--- tools/perf/tests/dwarf-unwind.c | 36 ++++++++++++++++++++++++++++++++++-- tools/perf/util/unwind-libunwind.c | 28 +++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 3 deletions(-)
tools/perf/tests/dwarf-unwind.c +34 -2
@@ -11,6 +11,9 @@#include "thread.h" #include "callchain.h" +/* For bsearch. We try to unwind functions in shared object. */ +#include <stdlib.h> + static int mmap_handler(struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample __maybe_unused,
@@ -28,7 +31,7 @@ static int init_live_machine(struct machine *machine) mmap_handler, machine, true); } -#define MAX_STACK 6 +#define MAX_STACK 8static int unwind_entry (struct unwind_entry *entry,void *arg) {
@@ -37,6 +40,8 @@ static int unwind_entry(struct unwind_entry *entry, void *arg)static const char *funcs[MAX_STACK ] = {"test__arch_unwind_sample" ,"unwind_thread" , +"compare" , +"bsearch" ,"krava_3" ,"krava_2" ,"krava_1" ,
@@ -88,10 +93,37 @@ static int unwind_thread(struct thread *thread)return err; } +static int global_unwind_retval = -INT_MAX ; + +__attribute__ ((noinline)) +static int compare (void *p1,void *p2) +{ +/* Any possible value should be 'thread' */ +struct thread *thread = *(struct thread **)p1; + +if (global_unwind_retval == -INT_MAX ) + global_unwind_retval =unwind_thread (thread); + +return p1 - p2; +} + __attribute__ ((noinline))static int krava_3 (struct thread *thread) { -return unwind_thread (thread); +struct thread *array[2 ] = {thread, thread}; +void *fp = &bsearch; +/* +* make _bsearch a volatile function pointer to +* prevent potential optimization, which may expand +* bsearch and call compare directly from this function, +* instead of libc shared object. +*/ +void *(*volatile _bsearch)(void *,void *,size_t , +size_t ,int (*)(void *,void *)); + + _bsearch = fp; +_bsearch (array, &thread,2 ,sizeof (struct thread **), compare); +return global_unwind_retval; } __attribute__ ((noinline))
tools/perf/util/unwind-libunwind.c +27 -1
@@ -185,6 +185,28 @@ static u64 elf_section_offset(int fd, const char *name)return offset; } +#ifndef NO_LIBUNWIND_DEBUG_FRAME +static int elf_is_exec (int fd,const char *name) +{ +Elf *elf; +GElf_Ehdr ehdr; +int retval =0 ; + + elf =elf_begin (fd,PERF_ELF_C_READ_MMAP ,NULL ); +if (elf ==NULL ) +return 0 ; +if (gelf_getehdr (elf, &ehdr) ==NULL ) + goto out; + + retval = (ehdr.e_type ==ET_EXEC ); + +out: +elf_end (elf); +pr_debug ("unwind: elf_is_exec(%s): %d\n" , name, retval); +return retval; +} +#endif +struct table_entry {u32 start_ip_offset;u32 fde_offset;
@@ -322,8 +344,12 @@ find_proc_info(unw_addr_space_t as, unw_word_t ip, unw_proc_info_t *pi,#ifndef NO_LIBUNWIND_DEBUG_FRAME /* Check the .debug_frame section for unwinding info */ if (!read_unwind_spec_debug_frame (map->dso, ui->machine, &segbase)) { +int fd =dso__data_fd (map->dso, ui->machine); +int is_exec =elf_is_exec (fd, map->dso->name); +unw_word_t base = is_exec ?0 : map->start; +memset (&di,0 ,sizeof (di)); -if (dwarf_find_debug_frame (0 , &di, ip,0 , map->dso->name, +if (dwarf_find_debug_frame (0 , &di, ip, base, map->dso->name, map->start, map->end))return dwarf_search_unwind_table (as, ip, &di, pi, need_unwind_info, arg);
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 9/10 perf tools: Fix segfault for symbol annotation on TUI
In reply to Arnaldo Carvalho de MeloFrom: Namhyung Kim <[email protected]>
Currently the symbol structure is allocated with symbol_conf.priv_size to carry sideband information like annotation, map browser on TUI and sort-by-name tree node. So retrieving these information from symbol needs to care about the details of such placement.
However the annotation code just assumes that the symbol is placed after the struct annotation. But actually there's other info between them. So accessing those struct will lead to an undefined behavior (usually a crash) after they write their info to the same location.
To reproduce the problem, please follow the steps below:
1. run perf report (TUI of course) with -v option
2. open map browser (by pressing right arrow key for any entry)
3. search any function (by pressing '/' key and input whatever..)
4. return to the hist browser (by pressing 'q' or left arrow key)
5. open annotation window for the same entry (by pressing 'a' key)
--- tools/perf/util/annotate.h | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
tools/perf/util/annotate.h +1 -7
@@ -116,11 +116,6 @@ struct annotation {struct annotated_source *src; }; -struct sannotation { -struct annotation annotation; -struct symbol symbol; -}; -static inline struct sym_hist *annotation__histogram (struct annotation *notes,int idx) { return (((void *)¬es->src->histograms) +
@@ -129,8 +124,7 @@ static inline struct sym_hist *annotation__histogram(struct annotation *notes, istatic inline struct annotation *symbol__annotation (struct symbol *sym) { - struct sannotation *a = container_of(sym, struct sannotation, symbol); -return &a->annotation; +return (void *)sym - symbol_conf.priv_size; }int addr_map_symbol__inc_samples (struct addr_map_symbol *ams,int evidx);
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 10/10 perf tools powerpc: Use dwfl_report_elf() instead of offline.
In reply to Arnaldo Carvalho de MeloFrom: Sukadev Bhattiprolu <[email protected]>
dwfl_report_offline() works only when libraries are prelinked.
Replace dwfl_report_offline() with dwfl_report_elf() so we correctly extract debug info even from libraries that are not prelinked.
--- tools/perf/arch/powerpc/util/skip-callchain-idx.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-)
tools/perf/arch/powerpc/util/skip-callchain-idx.c +11 -8
@@ -103,7 +103,7 @@ static Dwarf_Frame *get_eh_frame(Dwfl_Module *mod, Dwarf_Addr pc)return NULL ; } - result =dwarf_cfi_addrframe (cfi, pc, &frame); + result =dwarf_cfi_addrframe (cfi, pc-bias, &frame);if (result) {pr_debug ("%s(): %s\n" , __func__,dwfl_errmsg (-1 ));return NULL ;
@@ -128,7 +128,7 @@ static Dwarf_Frame *get_dwarf_frame(Dwfl_Module *mod, Dwarf_Addr pc)return NULL ; } - result =dwarf_cfi_addrframe (cfi, pc, &frame); + result =dwarf_cfi_addrframe (cfi, pc-bias, &frame);if (result) {pr_debug ("%s(): %s\n" , __func__,dwfl_errmsg (-1 ));return NULL ;
@@ -145,7 +145,7 @@ static Dwarf_Frame *get_dwarf_frame(Dwfl_Module *mod, Dwarf_Addr pc)* yet used) * -1 in case of errors */ -static int check_return_addr (struct dso *dso,Dwarf_Addr pc) +static int check_return_addr (struct dso *dso,u64 map_start,Dwarf_Addr pc) {int rc =-1 ;Dwfl *dwfl;
@@ -155,6 +155,7 @@ static int check_return_addr(struct dso *dso, Dwarf_Addr pc)Dwarf_Addr start = pc;Dwarf_Addr end = pc;bool signalp; +const char *exec_file = dso->long_name; dwfl = dso->dwfl;
@@ -165,8 +166,10 @@ static int check_return_addr(struct dso *dso, Dwarf_Addr pc)return -1 ; } -if (dwfl_report_offline (dwfl,"" , dso->long_name,-1 ) ==NULL ) { -pr_debug ("dwfl_report_offline() failed %s\n" , + mod =dwfl_report_elf (dwfl, exec_file, exec_file,-1 , + map_start, false); +if (!mod) { +pr_debug ("dwfl_report_elf() failed %s\n" ,dwarf_errmsg (-1 ));/* * We normally cache the DWARF debug info and never
@@ -256,10 +259,10 @@ int arch_skip_callchain_idx(struct thread *thread, struct ip_callchain *chain)return skip_slot; } - rc =check_return_addr (dso, ip); + rc =check_return_addr (dso, al.map->start, ip); -pr_debug ("DSO %s, nr %" PRIx64", ip 0x%" PRIx64"rc %d\n" , - dso->long_name, chain->nr, ip, rc); +pr_debug ("[DSO %s, sym %s, ip 0x%" PRIx64"] rc %d\n" , + dso->long_name, al.sym->name, ip, rc);if (rc ==0 ) {/*
Signature · 1 line
1.9.3
Quoted 91 lines · Arnaldo Carvalho de Melo
Hi Ingo,
Please consider pulling,
- Arnaldo
The following changes since commit
33636732dcd7cc738a5913bb730d663c6b03c8fb:perf/x86/intel: Fix bug for "cycles:p" and "cycles:pp" on SLM (2015-01-16 09:06:59 +0100)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.gittags/perf-urgent-for-mingofor you to fetch changes up to
6bcf9c1ff3ec22fd81eba336737d9865476509b1:perf tools powerpc: Use
dwfl_report_elf()instead of offline. (2015-01-16 17:49:30 -0300)----------------------------------------------------------------
perf/urgent fixes:User visible:
- Fix segfault when using both the map symtab viewer and annotation in the TUI (Namhyung Kim).
Developer stuff:
- uClibc build fixes (Alexey Brodkin, Vineet Gupta).
- bitops/hweight were moved from
tools/perf/tootools/include, move some leftovers (Arnaldo Carvalho de Melo)- Fix dwarf unwind
x86_64build error (Namhyung Kim)- Fix
__machine__findnew_thread()error path (Namhyung Kim)- Propagate error code when write(2) failed in 'perf probe' (Namhyung Kim)
- Use
dwfl_report_elf()instead of offline in powerpc bits to properly handle non prelinked DSOs (Sukadev Bhattiprolu).- Fix dwarf unwind using libunwind in 'perf test' (Wang Nan)
Signed-off-by Arnaldo Carvalho de Melo <[email protected]>----------------------------------------------------------------
Alexey Brodkin (1):
perf tools: Fix statfs.f_type data type mismatch build error with uclibcArnaldo Carvalho de Melo (1):
tools: Remove bitops/hweight usage of bits intools/perfNamhyung Kim (4):
perf probe: Propagate error code when write(2) failed perf tools: Fix building error inx86_64when dwarf unwind is on perf machine: Fix__machine__findnew_thread()error path perf tools: Fix segfault for symbol annotation on TUISukadev Bhattiprolu (1):
perf tools powerpc: Usedwfl_report_elf()instead of offline.Vineet Gupta (2):
perf tools: Elide strlcpy warning with uclibc
perf tools: Avoid build splat for syscall numbers with uclibcWang Nan (1):
perf test: Fix dwarf unwind using libunwind.tools/include/asm-generic/bitops.h | 2 ++ tools/include/asm-generic/bitops/arch_hweight.h | 1 + tools/include/asm-generic/bitops/const_hweight.h | 1 + tools/include/asm-generic/bitops/hweight.h | 7 +++++ tools/include/linux/bitops.h | 7 ++++- tools/lib/api/fs/debugfs.c | 2 +- tools/lib/api/fs/fs.c | 2 +- tools/perf/MANIFEST | 6 ++++ tools/perf/Makefile.perf | 11 +++++-- tools/perf/arch/powerpc/util/skip-callchain-idx.c | 19 +++++++----- tools/perf/bench/sched-pipe.c | 2 +- tools/perf/builtin-top.c | 1 - tools/perf/config/Makefile | 2 +- tools/perf/config/Makefile.arch | 26 ++++++++-------- tools/perf/perf-sys.h | 1 - tools/perf/tests/dwarf-unwind.c | 36 +++++++++++++++++++++-- tools/perf/util/annotate.h | 8 +---- tools/perf/util/cache.h | 2 ++ tools/perf/util/hweight.c | 31 ------------------- tools/perf/util/include/asm/hweight.h | 8 ----- tools/perf/util/machine.c | 4 ++- tools/perf/util/probe-event.c | 4 ++-
Quoted 8 lines
tools/perf/util/python-ext-sources | 2 +- tools/perf/util/unwind-libunwind.c | 28 +++++++++++++++++- 24 files changed, 131 insertions(+), 82 deletions(-) create mode 100644 tools/include/asm-generic/bitops/arch_hweight.h create mode 100644 tools/include/asm-generic/bitops/const_hweight.h create mode 100644 tools/include/asm-generic/bitops/hweight.h delete mode 100644 tools/perf/util/hweight.c delete mode 100644 tools/perf/util/include/asm/hweight.h
Pulled, thanks a lot Arnaldo!
Ingo