Skip to contentSkip to conversation

riscv: ftrace: select HAVE_BUILDTIME_MCOUNT_SORT

PATCH In review [email protected] 3 participants 3 messages Apr 9 – May 23 RISC-V

lore
Share & tools
lore
#0 lore raw

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
index 90c531e6abf5..6fe90591a274 100644
@@ -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
Tested-by on v1 1/1
#1 lore raw

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 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 -1
index 90c531e6abf5..6fe90591a274 100644
@@ -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
maintainer
#2 lore raw
In reply to [email protected]
Quoted 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 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.

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 properly

Thanks, queued for v7.2.

- Paul