perf test: Unwind fixes
Ian Rogers
reviewerPATCH 1/3 tools compiler.h: Add attribute to disable tail calls
In reply to Ian RogersTail call optimizations can remove stack frames that are used in unwinding tests. Add an attribute that can be used to disable the tail call optimization. Tested on clang and GCC.
--- tools/include/linux/compiler-gcc.h | 8 ++++++++ tools/include/linux/compiler.h | 3 +++ 2 files changed, 11 insertions(+)
tools/include/linux/compiler-gcc.h +8 -0
@@ -27,6 +27,14 @@#define __pure __attribute__((pure))#endif #define noinline __attribute__((noinline)) +#ifdef __has_attribute +#if __has_attribute (disable_tail_calls) +#define __no_tail_call __attribute__((disable_tail_calls)) +#endif +#endif +#ifndef __no_tail_call +#define __no_tail_call __attribute__((optimize("no-optimize-sibling-calls"))) +#endif #ifndef __packed#define __packed __attribute__((packed))#endif
tools/include/linux/compiler.h +3 -0
@@ -47,6 +47,9 @@#ifndef noinline#define noinline#endif +#ifndef __no_tail_call +#define __no_tail_call +#endif /* Are two types/vars the same type (ignoring qualifiers)? */ #ifndef __same_type
Signature · 1 line
2.27.0.rc2.251.g90737beb825-goog
Ian Rogers
reviewercover perf test: Unwind fixes
Fix stack frame count and memory sanitizer issues when running the dwarf unwinding test with the elfutils/libdw unwinder (libunwind disabled).
Ian Rogers (3):
tools compiler.h: Add attribute to disable tail calls perf tests: Don't tail call optimize in unwind test perf test: Initialize memory in dwarf-unwind
tools/include/linux/compiler-gcc.h | 8 ++++++++ tools/include/linux/compiler.h | 3 +++ tools/perf/arch/x86/tests/dwarf-unwind.c | 8 ++++++++ tools/perf/tests/dwarf-unwind.c | 11 ++++++----- 4 files changed, 25 insertions(+), 5 deletions(-)
Signature · 1 line
2.27.0.rc2.251.g90737beb825-goog
Ian Rogers
reviewerPATCH 2/3 perf tests: Don't tail call optimize in unwind test
The tail call optimization can unexpectedly make the stack smaller and cause the test to fail.
--- tools/perf/tests/dwarf-unwind.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
tools/perf/tests/dwarf-unwind.c +5 -5
@@ -94,7 +94,7 @@ static int unwind_entry(struct unwind_entry *entry, void *arg)return strcmp ((const char *) symbol, funcs[idx]); } -noinline int test_dwarf_unwind__thread(struct thread *thread) +__no_tail_call noinline int test_dwarf_unwind__thread(struct thread *thread) {struct perf_sample sample;unsigned long cnt =0 ;
@@ -125,7 +125,7 @@ noinline int test_dwarf_unwind__thread(struct thread *thread)static int global_unwind_retval = -INT_MAX ; -noinline int test_dwarf_unwind__compare(void *p1, void *p2) +__no_tail_call noinline int test_dwarf_unwind__compare(void *p1, void *p2) {/* Any possible value should be 'thread' */ struct thread *thread = *(struct thread **)p1;
@@ -144,7 +144,7 @@ noinline int test_dwarf_unwind__compare(void *p1, void *p2)return p1 - p2; } -noinline int test_dwarf_unwind__krava_3(struct thread *thread) +__no_tail_call noinline int test_dwarf_unwind__krava_3(struct thread *thread) {struct thread *array[2 ] = {thread, thread};void *fp = &bsearch;
@@ -163,12 +163,12 @@ noinline int test_dwarf_unwind__krava_3(struct thread *thread)return global_unwind_retval; } -noinline int test_dwarf_unwind__krava_2(struct thread *thread) +__no_tail_call noinline int test_dwarf_unwind__krava_2(struct thread *thread) {return test_dwarf_unwind__krava_3 (thread); } -noinline int test_dwarf_unwind__krava_1(struct thread *thread) +__no_tail_call noinline int test_dwarf_unwind__krava_1(struct thread *thread) {return test_dwarf_unwind__krava_2 (thread); }
Signature · 1 line
2.27.0.rc2.251.g90737beb825-goog
Ian Rogers
reviewerPATCH 3/3 perf test: Initialize memory in dwarf-unwind
In reply to Ian RogersAvoid a false positive caused by assembly code in arch/x86. In tests, zero the perf_event to avoid uninitialized memory uses. Warnings were caught using clang with -fsanitize=memory.
--- tools/perf/arch/x86/tests/dwarf-unwind.c | 8 ++++++++ tools/perf/tests/dwarf-unwind.c | 1 + 2 files changed, 9 insertions(+)
tools/perf/arch/x86/tests/dwarf-unwind.c +8 -0
@@ -55,6 +55,14 @@ int test__arch_unwind_sample(struct perf_sample *sample,return -1 ; } +#ifdef MEMORY_SANITIZER +/* +* Assignments to buf in the assembly function perf_regs_load aren't +* seen by memory sanitizer. Zero the memory to convince memory +* sanitizer the memory is initialized. +*/ +memset (buf,0 ,sizeof (u64) *PERF_REGS_MAX ); +#endif perf_regs_load (buf); regs->abi =PERF_SAMPLE_REGS_ABI ; regs->regs = buf;
tools/perf/tests/dwarf-unwind.c +1 -0
@@ -37,6 +37,7 @@ static int init_live_machine(struct machine *machine)union perf_event event;pid_t pid =getpid (); +memset (&event,0 ,sizeof (event));return perf_event__synthesize_mmap_events (NULL , &event, pid, pid, mmap_handler, machine, true); }
Signature · 1 line
2.27.0.rc2.251.g90737beb825-goog
Em Sat, May 30, 2020 at 01:20:12AM -0700, Ian Rogers escreveu:
Quoted 3 lines
Fix stack frame count and memory sanitizer issues when running the dwarf unwinding test with the elfutils/libdw unwinder (libunwind disabled).
Thanks, applied.
Quoted 14 lines
Ian Rogers (3):
toolscompiler.h: Add attribute to disable tail calls perf tests: Don't tail call optimize in unwind test perf test: Initialize memory in dwarf-unwindtools/include/linux/compiler-gcc.h | 8 ++++++++ tools/include/linux/compiler.h | 3 +++ tools/perf/arch/x86/tests/dwarf-unwind.c | 8 ++++++++ tools/perf/tests/dwarf-unwind.c | 11 ++++++----- 4 files changed, 25 insertions(+), 5 deletions(-)Signature · 1 line
2.27.0.rc2.251.g90737beb825-goog
Signature · 1 line
- Arnaldo
Arnaldo Carvalho de Melo
maintainerRe: [PATCH 1/3] tools compiler.h: Add attribute to disable tail calls
In reply to Ian RogersEm Sat, May 30, 2020 at 01:20:13AM -0700, Ian Rogers escreveu:
Quoted 16 lines
Tail call optimizations can remove stack frames that are used in unwinding tests. Add an attribute that can be used to disable the tail call optimization. Tested on clang and GCC.
Signed-off-by Ian Rogers <[email protected]>--- tools/include/linux/compiler-gcc.h | 8 ++++++++ tools/include/linux/compiler.h | 3 +++ 2 files changed, 11 insertions(+)tools/include/linux/compiler-gcc.h +0
-0@@ -27,6 +27,14 @@#define __pure __attribute__((pure))
tools/include/linux/compiler-gcc.h line 37
Quoted 10 lines
tools/include/linux/compiler-gcc.h +8
-0#endif #define noinline __attribute__((noinline)) +#ifdef __has_attribute +#if __has_attribute (disable_tail_calls) +#define __no_tail_call __attribute__((disable_tail_calls)) +#endif +#endif +#ifndef __no_tail_call +#define __no_tail_call __attribute__((optimize("no-optimize-sibling-calls"))) +#endif
Added this for some retro-computing old distros when building with old clang versions :-)
- Arnaldo
tools/include/linux/compiler-gcc.h +3 -0
@@ -33,7 +33,10 @@#endif #endif #ifndef __no_tail_call +#if GCC_VERSION >40201 #define __no_tail_call __attribute__((optimize("no-optimize-sibling-calls"))) +#else +#define __no_tail_call#endif #ifndef __packed#define __packed __attribute__((packed))