Re: [PATCH 1/2] scripts: ftrace - move the sort-processing in ftrace_init to compile time

From: Yinan Liu
Date: Mon Oct 25 2021 - 09:20:55 EST




On 2021/10/9 上午10:56, Yinan Liu wrote:

Probably just keep the sorting algorithm in the kernel and take place
on module load.

If you still want to sort at compile time, then do the sort for .init
functions separate from the .text ones, and have a way to extract this
information (shouldn't be too hard) in the kernel at module load, and
then just swap the init and text functions if they were added in the
reverse order that was expect.

The functions in .init will either be before all the functions in .text
or after. They wont be intermingled. Thus, if they are both sorted,
then they are placed correctly or the two groups of functions need to
be switched. No other sorting should be necessary.


Hi, Steven

I try to apply for memory during the relocation phase to separate and adjust the mcount of .init.text and .text. After processing, I found that the mcount redirection in .ko is based on ".text", ".init.text", ".ref.text", ".sched.text", ".spinlock.text", ".irqentry .text", ".softirqentry.text", ".kprobes.text", ".cpuidle.text", ".text.unlikely", which makes the sorting process at compile time cumbersome and inefficient. And .ko is inserted after the kernel start, to a certain extent, the optimization meaning of this part is relatively small. Now I think it makes more sense to optimize mcount during the startup period, because these mcounts based on different section redirects are relatively orderly
just like 11, 13, 15, 17, 19, 1, 3, 5, 7, 9, 21, 23, 25, 27, 29
.

At present, it seems that the processing of compile-time sorting is only suitable for vmlinux but not suitable for modules. Please review the code of mcount sorting in vmlinux, thank you.

Best regards!
-- Yinan liu