aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTorsten Duwe <duwe@lst.de>2016-03-02 23:27:00 -0500
committerMichael Ellerman <mpe@ellerman.id.au>2016-03-06 22:53:56 -0500
commit8c50b72a3b4f1f7cdfdfebd233b1cbd121262e65 (patch)
treee705558f3855d60ef389e651ad204e5c1f3f3f9d
parent153086644fd1fb07fb3af84d9f11542a19b1e8b6 (diff)
powerpc/ftrace: Add Kconfig & Make glue for mprofile-kernel
Firstly we add logic to Kconfig to allow a user to choose if they want mprofile-kernel. This has to be user-selectable because only some current toolchains support it. If we enabled it unconditionally we would prevent some users from building the kernel entirely. Arguably it would be nice if we could detect if mprofile-kernel was available, and use it then. However that would violate the principle of least surprise because a user having choosen options such as live patching, would then see them quietly disabled at build time. We also make the user selectable option negative, ie. it disables when selected, so that allyesconfig continues to build on old toolchains. Once we've decided we do want to use mprofile-kernel, we then add a script which checks it actually works. That is because there are versions of gcc that accept the flag but don't generate correct code. Due to the way kconfig works, we can't error out when we detect a non-working toolchain. If we did a user would never be able to modify their config and run oldconfig - because the check would block oldconfig from running. Instead we emit a warning and add a bogus flag to CFLAGS so that the build will fail. Signed-off-by: Torsten Duwe <duwe@suse.de> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
-rw-r--r--arch/powerpc/Kconfig19
-rw-r--r--arch/powerpc/Makefile15
-rwxr-xr-xarch/powerpc/scripts/gcc-check-mprofile-kernel.sh23
3 files changed, 57 insertions, 0 deletions
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index e4824fd04bb7..91da283cd658 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -94,6 +94,7 @@ config PPC
94 select OF_RESERVED_MEM 94 select OF_RESERVED_MEM
95 select HAVE_FTRACE_MCOUNT_RECORD 95 select HAVE_FTRACE_MCOUNT_RECORD
96 select HAVE_DYNAMIC_FTRACE 96 select HAVE_DYNAMIC_FTRACE
97 select HAVE_DYNAMIC_FTRACE_WITH_REGS if MPROFILE_KERNEL
97 select HAVE_FUNCTION_TRACER 98 select HAVE_FUNCTION_TRACER
98 select HAVE_FUNCTION_GRAPH_TRACER 99 select HAVE_FUNCTION_GRAPH_TRACER
99 select SYSCTL_EXCEPTION_TRACE 100 select SYSCTL_EXCEPTION_TRACE
@@ -373,6 +374,24 @@ config PPC_TRANSACTIONAL_MEM
373 ---help--- 374 ---help---
374 Support user-mode Transactional Memory on POWERPC. 375 Support user-mode Transactional Memory on POWERPC.
375 376
377config DISABLE_MPROFILE_KERNEL
378 bool "Disable use of mprofile-kernel for kernel tracing"
379 depends on PPC64 && CPU_LITTLE_ENDIAN
380 default y
381 help
382 Selecting this options disables use of the mprofile-kernel ABI for
383 kernel tracing. That will cause options such as live patching
384 (CONFIG_LIVEPATCH) which depend on CONFIG_DYNAMIC_FTRACE_WITH_REGS to
385 be disabled also.
386
387 If you have a toolchain which supports mprofile-kernel, then you can
388 enable this. Otherwise leave it disabled. If you're not sure, say
389 "N".
390
391config MPROFILE_KERNEL
392 depends on PPC64 && CPU_LITTLE_ENDIAN
393 def_bool !DISABLE_MPROFILE_KERNEL
394
376config IOMMU_HELPER 395config IOMMU_HELPER
377 def_bool PPC64 396 def_bool PPC64
378 397
diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index 96efd8213c1c..f4e49a4153cb 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -133,6 +133,21 @@ else
133CFLAGS-$(CONFIG_GENERIC_CPU) += -mcpu=powerpc64 133CFLAGS-$(CONFIG_GENERIC_CPU) += -mcpu=powerpc64
134endif 134endif
135 135
136ifdef CONFIG_MPROFILE_KERNEL
137 ifeq ($(shell $(srctree)/arch/powerpc/scripts/gcc-check-mprofile-kernel.sh $(CC) -I$(srctree)/include -D__KERNEL__),OK)
138 CC_FLAGS_FTRACE := -pg -mprofile-kernel
139 KBUILD_CPPFLAGS += -DCC_USING_MPROFILE_KERNEL
140 else
141 # If the user asked for mprofile-kernel but the toolchain doesn't
142 # support it, emit a warning and deliberately break the build later
143 # with mprofile-kernel-not-supported. We would prefer to make this an
144 # error right here, but then the user would never be able to run
145 # oldconfig to change their configuration.
146 $(warning Compiler does not support mprofile-kernel, set CONFIG_DISABLE_MPROFILE_KERNEL)
147 CC_FLAGS_FTRACE := -mprofile-kernel-not-supported
148 endif
149endif
150
136CFLAGS-$(CONFIG_CELL_CPU) += $(call cc-option,-mcpu=cell) 151CFLAGS-$(CONFIG_CELL_CPU) += $(call cc-option,-mcpu=cell)
137CFLAGS-$(CONFIG_POWER4_CPU) += $(call cc-option,-mcpu=power4) 152CFLAGS-$(CONFIG_POWER4_CPU) += $(call cc-option,-mcpu=power4)
138CFLAGS-$(CONFIG_POWER5_CPU) += $(call cc-option,-mcpu=power5) 153CFLAGS-$(CONFIG_POWER5_CPU) += $(call cc-option,-mcpu=power5)
diff --git a/arch/powerpc/scripts/gcc-check-mprofile-kernel.sh b/arch/powerpc/scripts/gcc-check-mprofile-kernel.sh
new file mode 100755
index 000000000000..c658d8cf760b
--- /dev/null
+++ b/arch/powerpc/scripts/gcc-check-mprofile-kernel.sh
@@ -0,0 +1,23 @@
1#!/bin/bash
2
3set -e
4set -o pipefail
5
6# To debug, uncomment the following line
7# set -x
8
9# Test whether the compile option -mprofile-kernel exists and generates
10# profiling code (ie. a call to _mcount()).
11echo "int func() { return 0; }" | \
12 $* -S -x c -O2 -p -mprofile-kernel - -o - 2> /dev/null | \
13 grep -q "_mcount"
14
15# Test whether the notrace attribute correctly suppresses calls to _mcount().
16
17echo -e "#include <linux/compiler.h>\nnotrace int func() { return 0; }" | \
18 $* -S -x c -O2 -p -mprofile-kernel - -o - 2> /dev/null | \
19 grep -q "_mcount" && \
20 exit 1
21
22echo "OK"
23exit 0