Skip to contentSkip to conversation

powerpc/64: Use -mprofile-kernel for big endian ELFv2 kernels

PATCH In review Nicholas Piggin 2 participants 2 messages May 6, 2023 – May 9, 2023 PowerPC

lore
Share & tools
lore

Nicholas Piggin

author reviewer
#0 lore raw

PATCH 1/1 powerpc/64: Use -mprofile-kernel for big endian ELFv2 kernels

-mprofile-kernel is an optimised calling convention for mcount that Linux has only implemented with the ELFv2 ABI, so it was disabled for big endian kernels. However it does work with ELFv2 big endian, so let's allow that if the compiler supports it.

---
Christophe had the good idea that we could use -mprofile-kernel for ELFv2 BE. Unfortunately can't remove -pg due to lack of -mprofile-kernel in clang, but this gives BE the nicer ftrace code with GCC at least. Function tracer works for me with a BE kernel.

Thanks,
Nick

 arch/powerpc/Kconfig                            | 6 ++++--
 arch/powerpc/tools/gcc-check-mprofile-kernel.sh | 4 ++--
 2 files changed, 6 insertions(+), 4 deletions(-)
arch/powerpc/Kconfig +4 -2
index a64bfd9b8a1d..bd2ee7af1342 100644
@@ -547,8 +547,10 @@ config LD_HEAD_STUB_CATCH
 	  If unsure, say "N".
 
 config MPROFILE_KERNEL
-	depends on PPC64 && CPU_LITTLE_ENDIAN && FUNCTION_TRACER
-	def_bool $(success,$(srctree)/arch/powerpc/tools/gcc-check-mprofile-kernel.sh $(CC) -I$(srctree)/include -D__KERNEL__)
+	depends on PPC64 && FUNCTION_TRACER
+	depends on CPU_LITTLE_ENDIAN || PPC64_BIG_ENDIAN_ELF_ABI_V2
+	def_bool $(success,$(srctree)/arch/powerpc/tools/gcc-check-mprofile-kernel.sh $(CC) -mlittle-endian) if CPU_LITTLE_ENDIAN
+	def_bool $(success,$(srctree)/arch/powerpc/tools/gcc-check-mprofile-kernel.sh $(CC) -mbig-endian) if CPU_BIG_ENDIAN
 
 config HOTPLUG_CPU
 	bool "Support for enabling/disabling CPUs"
arch/powerpc/tools/gcc-check-mprofile-kernel.sh +2 -2
index 137f3376ac2b..e78c599251ff 100755
@@ -14,13 +14,13 @@ set -o pipefail
 # Test whether the compile option -mprofile-kernel exists and generates
 # profiling code (ie. a call to _mcount()).
 echo "int func() { return 0; }" | \
-    $* -m64 -mlittle-endian -S -x c -O2 -p -mprofile-kernel - -o - \
+    $* -m64 -S -x c -O2 -p -mprofile-kernel - -o - \
     2> /dev/null | grep -q "_mcount"
 
 # Test whether the notrace attribute correctly suppresses calls to _mcount().
 
 echo -e "#include <linux/compiler.h>\nnotrace int func() { return 0; }" | \
-    $* -m64 -mlittle-endian -S -x c -O2 -p -mprofile-kernel - -o - \
+    $* -m64 -S -x c -O2 -p -mprofile-kernel - -o - \
     2> /dev/null | grep -q "_mcount" && \
     exit 1
 
Signature · 1 line
2.40.1
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Nicholas Piggin

-mprofile-kernel is an optimised calling convention for mcount that Linux has only implemented with the ELFv2 ABI, so it was disabled for big endian kernels. However it does work with ELFv2 big endian, so let's allow that if the compiler supports it.

Quoted 8 lines

---
Christophe had the good idea that we could use -mprofile-kernel for ELFv2 BE. Unfortunately can't remove -pg due to lack of -mprofile-kernel in clang, but this gives BE the nicer ftrace code with GCC at least. Function tracer works for me with a BE kernel.

LGTM. With a few minor nits below:

Quoted 13 lines

Thanks,
Nick

 arch/powerpc/Kconfig                            | 6 ++++--
 arch/powerpc/tools/gcc-check-mprofile-kernel.sh | 4 ++--
 2 files changed, 6 insertions(+), 4 deletions(-)
arch/powerpc/Kconfig +0 -0
index a64bfd9b8a1d..bd2ee7af1342 100644

arch/powerpc/Kconfig config LD_HEAD_STUB_CATCH · line 551

Quoted 7 lines
arch/powerpc/Kconfig +2 -2
@@ -547,8 +547,10 @@ config LD_HEAD_STUB_CATCH
 	  If unsure, say "N".
 
 config MPROFILE_KERNEL
-	depends on PPC64 && CPU_LITTLE_ENDIAN && FUNCTION_TRACER
-	def_bool $(success,$(srctree)/arch/powerpc/tools/gcc-check-mprofile-kernel.sh $(CC) -I$(srctree)/include -D__KERNEL__)
+	depends on PPC64 && FUNCTION_TRACER
+	depends on CPU_LITTLE_ENDIAN || PPC64_BIG_ENDIAN_ELF_ABI_V2

Can't we just check for PPC64_ELF_ABI_V2?

arch/powerpc/tools/gcc-check-mprofile-kernel.sh set -o pipefail

Quoted 10 lines
arch/powerpc/Kconfig +2 -0
+	def_bool $(success,$(srctree)/arch/powerpc/tools/gcc-check-mprofile-kernel.sh $(CC) -mlittle-endian) if CPU_LITTLE_ENDIAN
+	def_bool $(success,$(srctree)/arch/powerpc/tools/gcc-check-mprofile-kernel.sh $(CC) -mbig-endian) if CPU_BIG_ENDIAN
 
 config HOTPLUG_CPU
 	bool "Support for enabling/disabling CPUs"
arch/powerpc/tools/gcc-check-mprofile-kernel.sh +0 -0
index 137f3376ac2b..e78c599251ff 100755
@@ -14,13 +14,13 @@ set -o pipefail

We have this comment before the below code, which should also be updated/removed:
# -mprofile-kernel is only supported on 64le, so this should not be invoked

 # for other targets. Therefore we can pass in -m64 and -mlittle-endian
 # explicitly, to take care of toolchains defaulting to other targets.
Quoted 5 lines
arch/powerpc/tools/gcc-check-mprofile-kernel.sh +1 -1
 # Test whether the compile option -mprofile-kernel exists and generates
 # profiling code (ie. a call to _mcount()).
 echo "int func() { return 0; }" | \
-    $* -m64 -mlittle-endian -S -x c -O2 -p -mprofile-kernel - -o - \
+    $* -m64 -S -x c -O2 -p -mprofile-kernel - -o - \

arch/powerpc/tools/gcc-check-mprofile-kernel.sh set -o pipefail · line 26

Quoted 10 lines
arch/powerpc/tools/gcc-check-mprofile-kernel.sh +1 -1
     2> /dev/null | grep -q "_mcount"
 
 # Test whether the notrace attribute correctly suppresses calls to _mcount().
 
 echo -e "#include <linux/compiler.h>\nnotrace int func() { return 0; }" | \
-    $* -m64 -mlittle-endian -S -x c -O2 -p -mprofile-kernel - -o - \
+    $* -m64 -S -x c -O2 -p -mprofile-kernel - -o - \
     2> /dev/null | grep -q "_mcount" && \
     exit 1
 

- Naveen