riscv: ftrace: select HAVE_BUILDTIME_MCOUNT_SORT
PATCH 1/1 riscv: ftrace: select HAVE_BUILDTIME_MCOUNT_SORT
From: Chen Pei <[email protected]>
RISC-V already satisfies all prerequisites for build-time mcount sorting:
the sorttable host tool handles EM_RISCV in its machine-type dispatch, and the __mcount_loc section entries are stored as direct virtual addresses in the final vmlinux binary, so no relocation processing is required during the sort step.
Select HAVE_BUILDTIME_MCOUNT_SORT so that BUILDTIME_MCOUNT_SORT is automatically enabled when DYNAMIC_FTRACE is configured. This allows sorttable to sort the __mcount_loc section at link time, making the run-time ftrace initialisation path skip the software sort and reducing kernel startup overhead.
Verified with CONFIG_FTRACE_SORT_STARTUP_TEST=y, which confirms that the section produced by the build is already in ascending order:
[ 0.000000] ftrace section at ffffffff81015a60 sorted properly
--- arch/riscv/Kconfig | 1 + 1 file changed, 1 insertion(+)
arch/riscv/Kconfig +1 -0
@@ -151,6 +151,7 @@ config RISCV select HAVE_ARCH_USERFAULTFD_WP if 64BIT && MMU && USERFAULTFD && RISCV_ISA_SVRSW60T59B select HAVE_ARCH_VMAP_STACK if MMU && 64BIT select HAVE_ASM_MODVERSIONS + select HAVE_BUILDTIME_MCOUNT_SORT select HAVE_CONTEXT_TRACKING_USER select HAVE_DEBUG_KMEMLEAK select HAVE_DMA_CONTIGUOUS if MMU
Signature · 1 line
2.50.1
Hi Chen,
Cool, we missed that. Good catch!
Quoted 40 lines · On Thu, Apr 9, 2026 at 7:48 PM <[email protected]> wrote:
From: Chen Pei <[email protected]>
RISC-V already satisfies all prerequisites for build-time mcount sorting:
the sorttable host tool handlesEM_RISCVin its machine-type dispatch, and the__mcount_locsection entries are stored as direct virtual addresses in the final vmlinux binary, so no relocation processing is required during the sort step.Select
HAVE_BUILDTIME_MCOUNT_SORTso thatBUILDTIME_MCOUNT_SORTis automatically enabled whenDYNAMIC_FTRACEis configured. This allows sorttable to sort the__mcount_locsection at link time, making the run-time ftrace initialisation path skip the software sort and reducing kernel startup overhead.Verified with
CONFIG_FTRACE_SORT_STARTUP_TEST=y, which confirms that the section produced by the build is already in ascending order:[ 0.000000] ftrace section at ffffffff81015a60 sorted properlySigned-off-by Chen Pei <[email protected]>--- arch/riscv/Kconfig | 1 + 1 file changed, 1 insertion(+)arch/riscv/Kconfig +1
-1@@ -151,6 +151,7 @@ config RISCV select HAVE_ARCH_USERFAULTFD_WP if 64BIT && MMU && USERFAULTFD && RISCV_ISA_SVRSW60T59B select HAVE_ARCH_VMAP_STACK if MMU && 64BIT select HAVE_ASM_MODVERSIONS + select HAVE_BUILDTIME_MCOUNT_SORT select HAVE_CONTEXT_TRACKING_USER select HAVE_DEBUG_KMEMLEAK select HAVE_DMA_CONTIGUOUS if MMU --2.50.1
Signature · 2 lines
Best Regards Guo Ren
Paul Walmsley
maintainerQuoted 14 lines · On Thu, 9 Apr 2026, [email protected] wrote:
From: Chen Pei <[email protected]>
RISC-V already satisfies all prerequisites for build-time mcount sorting:
the sorttable host tool handlesEM_RISCVin its machine-type dispatch, and the__mcount_locsection entries are stored as direct virtual addresses in the final vmlinux binary, so no relocation processing is required during the sort step.Select
HAVE_BUILDTIME_MCOUNT_SORTso thatBUILDTIME_MCOUNT_SORTis automatically enabled whenDYNAMIC_FTRACEis configured. This allows sorttable to sort the__mcount_locsection at link time, making the run-time ftrace initialisation path skip the software sort and reducing kernel startup overhead.
Quoted 6 lines
Verified with
CONFIG_FTRACE_SORT_STARTUP_TEST=y, which confirms that the section produced by the build is already in ascending order:[ 0.000000] ftrace section at ffffffff81015a60 sorted properlySigned-off-by Chen Pei <[email protected]>
Thanks, queued for v7.2.
- Paul