From 42362c6fcc17d922ddda8efb8625f4b374c63abb Mon Sep 17 00:00:00 2001 From: Yong Cong Sin Date: Fri, 16 Aug 2024 15:59:09 +0800 Subject: [PATCH] subsys/profiling: relocate stack unwind backends Relocate stack unwind backends from `arch/` to perf's `backends/` folder, just like logging/shell/.. Signed-off-by: Yong Cong Sin Signed-off-by: Yong Cong Sin --- arch/riscv/core/CMakeLists.txt | 1 - arch/x86/core/ia32.cmake | 2 -- arch/x86/core/intel64.cmake | 1 - subsys/profiling/perf/CMakeLists.txt | 8 ++++- subsys/profiling/perf/Kconfig | 6 ++-- subsys/profiling/perf/backends/CMakeLists.txt | 15 +++++++++ subsys/profiling/perf/backends/Kconfig | 33 +++++++++++++++++++ .../profiling/perf/backends/perf_riscv.c | 0 .../profiling/perf/backends/perf_x86.c | 0 .../profiling/perf/backends/perf_x86_64.c | 0 10 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 subsys/profiling/perf/backends/CMakeLists.txt create mode 100644 subsys/profiling/perf/backends/Kconfig rename arch/riscv/core/perf.c => subsys/profiling/perf/backends/perf_riscv.c (100%) rename arch/x86/core/ia32/perf.c => subsys/profiling/perf/backends/perf_x86.c (100%) rename arch/x86/core/intel64/perf.c => subsys/profiling/perf/backends/perf_x86_64.c (100%) diff --git a/arch/riscv/core/CMakeLists.txt b/arch/riscv/core/CMakeLists.txt index 72bdee174d1..74d520458ad 100644 --- a/arch/riscv/core/CMakeLists.txt +++ b/arch/riscv/core/CMakeLists.txt @@ -27,4 +27,3 @@ zephyr_library_sources_ifdef(CONFIG_USERSPACE userspace.S) zephyr_library_sources_ifdef(CONFIG_SEMIHOST semihost.c) zephyr_library_sources_ifdef(CONFIG_EXCEPTION_STACK_TRACE stacktrace.c) zephyr_linker_sources(ROM_START SORT_KEY 0x0vectors vector_table.ld) -zephyr_library_sources_ifdef(CONFIG_PROFILING_PERF perf.c) diff --git a/arch/x86/core/ia32.cmake b/arch/x86/core/ia32.cmake index 64617f56b39..48207011b50 100644 --- a/arch/x86/core/ia32.cmake +++ b/arch/x86/core/ia32.cmake @@ -25,8 +25,6 @@ zephyr_library_sources_ifdef(CONFIG_GDBSTUB ia32/gdbstub.c) zephyr_library_sources_ifdef(CONFIG_DEBUG_COREDUMP ia32/coredump.c) -zephyr_library_sources_ifdef(CONFIG_PROFILING_PERF ia32/perf.c) - zephyr_library_sources_ifdef( CONFIG_X86_USE_THREAD_LOCAL_STORAGE ia32/tls.c diff --git a/arch/x86/core/intel64.cmake b/arch/x86/core/intel64.cmake index dd3bb38af7a..1cb25ebe220 100644 --- a/arch/x86/core/intel64.cmake +++ b/arch/x86/core/intel64.cmake @@ -20,4 +20,3 @@ zephyr_library_sources_ifdef(CONFIG_IRQ_OFFLOAD intel64/irq_offload.c) zephyr_library_sources_ifdef(CONFIG_USERSPACE intel64/userspace.S) zephyr_library_sources_ifdef(CONFIG_THREAD_LOCAL_STORAGE intel64/tls.c) zephyr_library_sources_ifdef(CONFIG_DEBUG_COREDUMP intel64/coredump.c) -zephyr_library_sources_ifdef(CONFIG_PROFILING_PERF intel64/perf.c) diff --git a/subsys/profiling/perf/CMakeLists.txt b/subsys/profiling/perf/CMakeLists.txt index 4ab7b625d72..f8b261a48bf 100644 --- a/subsys/profiling/perf/CMakeLists.txt +++ b/subsys/profiling/perf/CMakeLists.txt @@ -2,4 +2,10 @@ # # SPDX-License-Identifier: Apache-2.0 -zephyr_sources(perf.c) +add_subdirectory(backends) + +zephyr_library() + +zephyr_library_sources( + perf.c +) diff --git a/subsys/profiling/perf/Kconfig b/subsys/profiling/perf/Kconfig index 505a14846b3..31ddf7d533b 100644 --- a/subsys/profiling/perf/Kconfig +++ b/subsys/profiling/perf/Kconfig @@ -4,11 +4,9 @@ config PROFILING_PERF bool "Perf support" - depends on THREAD_STACK_INFO depends on !SMP - depends on FRAME_POINTER depends on SHELL - depends on RISCV || X86 + depends on PROFILING_PERF_HAS_BACKEND help Enable perf shell command. @@ -21,3 +19,5 @@ config PROFILING_PERF_BUFFER_SIZE Size of buffer used by perf to save stack trace samples. endif + +rsource "backends/Kconfig" diff --git a/subsys/profiling/perf/backends/CMakeLists.txt b/subsys/profiling/perf/backends/CMakeLists.txt new file mode 100644 index 00000000000..a3352739830 --- /dev/null +++ b/subsys/profiling/perf/backends/CMakeLists.txt @@ -0,0 +1,15 @@ +# Copyright (c) 2024 Meta Platforms +# +# SPDX-License-Identifier: Apache-2.0 + +zephyr_sources_ifdef(CONFIG_PROFILING_PERF_BACKEND_RISCV + perf_riscv.c +) + +zephyr_sources_ifdef(CONFIG_PROFILING_PERF_BACKEND_X86 + perf_x86.c +) + +zephyr_sources_ifdef(CONFIG_PROFILING_PERF_BACKEND_X86_64 + perf_x86_64.c +) diff --git a/subsys/profiling/perf/backends/Kconfig b/subsys/profiling/perf/backends/Kconfig new file mode 100644 index 00000000000..6ea7018f922 --- /dev/null +++ b/subsys/profiling/perf/backends/Kconfig @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Meta Platforms +# +# SPDX-License-Identifier: Apache-2.0 + +config PROFILING_PERF_HAS_BACKEND + bool + help + Selected when there's an implementation for + `arch_perf_current_stack_trace()` + +config PROFILING_PERF_BACKEND_RISCV + bool + default y + depends on RISCV + depends on THREAD_STACK_INFO + depends on FRAME_POINTER + select PROFILING_PERF_HAS_BACKEND + +config PROFILING_PERF_BACKEND_X86 + bool + default y + depends on X86 && !X86_64 + depends on THREAD_STACK_INFO + depends on FRAME_POINTER + select PROFILING_PERF_HAS_BACKEND + +config PROFILING_PERF_BACKEND_X86_64 + bool + default y + depends on X86_64 + depends on THREAD_STACK_INFO + depends on FRAME_POINTER + select PROFILING_PERF_HAS_BACKEND diff --git a/arch/riscv/core/perf.c b/subsys/profiling/perf/backends/perf_riscv.c similarity index 100% rename from arch/riscv/core/perf.c rename to subsys/profiling/perf/backends/perf_riscv.c diff --git a/arch/x86/core/ia32/perf.c b/subsys/profiling/perf/backends/perf_x86.c similarity index 100% rename from arch/x86/core/ia32/perf.c rename to subsys/profiling/perf/backends/perf_x86.c diff --git a/arch/x86/core/intel64/perf.c b/subsys/profiling/perf/backends/perf_x86_64.c similarity index 100% rename from arch/x86/core/intel64/perf.c rename to subsys/profiling/perf/backends/perf_x86_64.c