linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] perf test: Unwind fixes
@ 2020-05-30  8:20 Ian Rogers
  2020-05-30  8:20 ` [PATCH 1/3] tools compiler.h: Add attribute to disable tail calls Ian Rogers
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Ian Rogers @ 2020-05-30  8:20 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Quentin Monnet, Alexei Starovoitov, Jakub Kicinski, linux-kernel,
	clang-built-linux
  Cc: Stephane Eranian, Ian Rogers

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(-)

-- 
2.27.0.rc2.251.g90737beb825-goog


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/3] tools compiler.h: Add attribute to disable tail calls
  2020-05-30  8:20 [PATCH 0/3] perf test: Unwind fixes Ian Rogers
@ 2020-05-30  8:20 ` Ian Rogers
  2020-06-01 14:53   ` Arnaldo Carvalho de Melo
  2020-05-30  8:20 ` [PATCH 2/3] perf tests: Don't tail call optimize in unwind test Ian Rogers
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: Ian Rogers @ 2020-05-30  8:20 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Quentin Monnet, Alexei Starovoitov, Jakub Kicinski, linux-kernel,
	clang-built-linux
  Cc: Stephane Eranian, Ian Rogers

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 <irogers@google.com>
---
 tools/include/linux/compiler-gcc.h | 8 ++++++++
 tools/include/linux/compiler.h     | 3 +++
 2 files changed, 11 insertions(+)

diff --git a/tools/include/linux/compiler-gcc.h b/tools/include/linux/compiler-gcc.h
index 95c072b70d0e..cda555b47d3d 100644
--- a/tools/include/linux/compiler-gcc.h
+++ b/tools/include/linux/compiler-gcc.h
@@ -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
diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h
index 180f7714a5f1..9f9002734e19 100644
--- a/tools/include/linux/compiler.h
+++ b/tools/include/linux/compiler.h
@@ -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
-- 
2.27.0.rc2.251.g90737beb825-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/3] perf tests: Don't tail call optimize in unwind test
  2020-05-30  8:20 [PATCH 0/3] perf test: Unwind fixes Ian Rogers
  2020-05-30  8:20 ` [PATCH 1/3] tools compiler.h: Add attribute to disable tail calls Ian Rogers
@ 2020-05-30  8:20 ` Ian Rogers
  2020-05-30  8:20 ` [PATCH 3/3] perf test: Initialize memory in dwarf-unwind Ian Rogers
  2020-05-31 12:17 ` [PATCH 0/3] perf test: Unwind fixes Arnaldo Carvalho de Melo
  3 siblings, 0 replies; 6+ messages in thread
From: Ian Rogers @ 2020-05-30  8:20 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Quentin Monnet, Alexei Starovoitov, Jakub Kicinski, linux-kernel,
	clang-built-linux
  Cc: Stephane Eranian, Ian Rogers

The tail call optimization can unexpectedly make the stack smaller and
cause the test to fail.

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/tests/dwarf-unwind.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/tools/perf/tests/dwarf-unwind.c b/tools/perf/tests/dwarf-unwind.c
index 779ce280a0e9..2a0dac81f44c 100644
--- a/tools/perf/tests/dwarf-unwind.c
+++ b/tools/perf/tests/dwarf-unwind.c
@@ -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);
 }
-- 
2.27.0.rc2.251.g90737beb825-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/3] perf test: Initialize memory in dwarf-unwind
  2020-05-30  8:20 [PATCH 0/3] perf test: Unwind fixes Ian Rogers
  2020-05-30  8:20 ` [PATCH 1/3] tools compiler.h: Add attribute to disable tail calls Ian Rogers
  2020-05-30  8:20 ` [PATCH 2/3] perf tests: Don't tail call optimize in unwind test Ian Rogers
@ 2020-05-30  8:20 ` Ian Rogers
  2020-05-31 12:17 ` [PATCH 0/3] perf test: Unwind fixes Arnaldo Carvalho de Melo
  3 siblings, 0 replies; 6+ messages in thread
From: Ian Rogers @ 2020-05-30  8:20 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Quentin Monnet, Alexei Starovoitov, Jakub Kicinski, linux-kernel,
	clang-built-linux
  Cc: Stephane Eranian, Ian Rogers

Avoid 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.

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/arch/x86/tests/dwarf-unwind.c | 8 ++++++++
 tools/perf/tests/dwarf-unwind.c          | 1 +
 2 files changed, 9 insertions(+)

diff --git a/tools/perf/arch/x86/tests/dwarf-unwind.c b/tools/perf/arch/x86/tests/dwarf-unwind.c
index ef43be9b6ec2..4e40402a4f81 100644
--- a/tools/perf/arch/x86/tests/dwarf-unwind.c
+++ b/tools/perf/arch/x86/tests/dwarf-unwind.c
@@ -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;
diff --git a/tools/perf/tests/dwarf-unwind.c b/tools/perf/tests/dwarf-unwind.c
index 2a0dac81f44c..2491d167bf76 100644
--- a/tools/perf/tests/dwarf-unwind.c
+++ b/tools/perf/tests/dwarf-unwind.c
@@ -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);
 }
-- 
2.27.0.rc2.251.g90737beb825-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/3] perf test: Unwind fixes
  2020-05-30  8:20 [PATCH 0/3] perf test: Unwind fixes Ian Rogers
                   ` (2 preceding siblings ...)
  2020-05-30  8:20 ` [PATCH 3/3] perf test: Initialize memory in dwarf-unwind Ian Rogers
@ 2020-05-31 12:17 ` Arnaldo Carvalho de Melo
  3 siblings, 0 replies; 6+ messages in thread
From: Arnaldo Carvalho de Melo @ 2020-05-31 12:17 UTC (permalink / raw)
  To: Ian Rogers
  Cc: Peter Zijlstra, Ingo Molnar, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Namhyung Kim, Quentin Monnet, Alexei Starovoitov,
	Jakub Kicinski, linux-kernel, clang-built-linux,
	Stephane Eranian

Em Sat, May 30, 2020 at 01:20:12AM -0700, Ian Rogers escreveu:
> Fix stack frame count and memory sanitizer issues when running the
> dwarf unwinding test with the elfutils/libdw unwinder (libunwind
> disabled).

Thanks, applied.
 
> 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(-)
> 
> -- 
> 2.27.0.rc2.251.g90737beb825-goog
> 

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/3] tools compiler.h: Add attribute to disable tail calls
  2020-05-30  8:20 ` [PATCH 1/3] tools compiler.h: Add attribute to disable tail calls Ian Rogers
@ 2020-06-01 14:53   ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 6+ messages in thread
From: Arnaldo Carvalho de Melo @ 2020-06-01 14:53 UTC (permalink / raw)
  To: Ian Rogers
  Cc: Peter Zijlstra, Ingo Molnar, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Namhyung Kim, Quentin Monnet, Alexei Starovoitov,
	Jakub Kicinski, linux-kernel, clang-built-linux,
	Stephane Eranian

Em Sat, May 30, 2020 at 01:20:13AM -0700, Ian Rogers escreveu:
> 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 <irogers@google.com>
> ---
>  tools/include/linux/compiler-gcc.h | 8 ++++++++
>  tools/include/linux/compiler.h     | 3 +++
>  2 files changed, 11 insertions(+)
> 
> diff --git a/tools/include/linux/compiler-gcc.h b/tools/include/linux/compiler-gcc.h
> index 95c072b70d0e..cda555b47d3d 100644
> --- a/tools/include/linux/compiler-gcc.h
> +++ b/tools/include/linux/compiler-gcc.h
> @@ -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

Added this for some retro-computing old distros when building with old
clang versions :-)

- Arnaldo

diff --git a/tools/include/linux/compiler-gcc.h b/tools/include/linux/compiler-gcc.h
index cda555b47d3d..dea7378ad646 100644
--- a/tools/include/linux/compiler-gcc.h
+++ b/tools/include/linux/compiler-gcc.h
@@ -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))

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-06-01 14:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-30  8:20 [PATCH 0/3] perf test: Unwind fixes Ian Rogers
2020-05-30  8:20 ` [PATCH 1/3] tools compiler.h: Add attribute to disable tail calls Ian Rogers
2020-06-01 14:53   ` Arnaldo Carvalho de Melo
2020-05-30  8:20 ` [PATCH 2/3] perf tests: Don't tail call optimize in unwind test Ian Rogers
2020-05-30  8:20 ` [PATCH 3/3] perf test: Initialize memory in dwarf-unwind Ian Rogers
2020-05-31 12:17 ` [PATCH 0/3] perf test: Unwind fixes Arnaldo Carvalho de Melo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).