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

From: Yinan Liu
Date: Sun Oct 03 2021 - 09:43:09 EST



在 2021/9/11 下午9:59, Steven Rostedt 写道:
On Sat, 11 Sep 2021 21:50:42 +0800
Yinan Liu <yinan@xxxxxxxxxxxxxxxxx> wrote:

When ftrace is enabled, ftrace_init will consume a period of
time, usually around 15~20 ms. Approximately 40% of the time is
consumed by sort-processing. Moving the sort-processing to the
compile time can speed up the kernel boot process.

Nice. I like the idea of sorting at compile time.
Thanks !
performance test:
env: Intel(R) Xeon(R) CPU E5-2682 v4 @ 2.50GHz
method: before and after patching, compare the
total time of ftrace_init(), and verify
the functionality of ftrace.

avg_time of ftrace_init:
with patch: 8.352 ms
without patch: 15.763 ms

Signed-off-by: Yinan Liu <yinan@xxxxxxxxxxxxxxxxx>
---
kernel/trace/ftrace.c | 5 ++-
scripts/link-vmlinux.sh | 6 +--
scripts/sorttable.c | 2 +
scripts/sorttable.h | 109 +++++++++++++++++++++++++++++++++++++++++++++++-
4 files changed, 115 insertions(+), 7 deletions(-)

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 7efbc8aaf7f6..c236da868990 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -6189,8 +6189,9 @@ static int ftrace_process_locs(struct module *mod,
if (!count)
return 0;
- sort(start, count, sizeof(*start),
- ftrace_cmp_ips, NULL);
+ if (mod)
Why can't we enforce modules to be sorted too?

hi,

Sorry for my slow progress . I have encountered some problems with the sorting
of the module's mcount in compile time. The .ko file will be relocated after insmod
or modprobe, most of the mcount relocation is based on .text section, but there are
also a small part of mcount relocation based on .init.text section such as module_init().
The loading position of .init.text and .text does not seem to be in a definite order.

For example, when I insmod ip_tables.ko twice, the front and back positions of init.text
and .text are different, so we cannot sort the mcounts in the two sections, which makes
the mcount sorting in the module meaningless.

What is your opinion on this?

+ sort(start, count, sizeof(*start),
+ ftrace_cmp_ips, NULL);

Best regards! ---Yinan liu