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

From: Steven Rostedt
Date: Sat Sep 11 2021 - 09:59:42 EST


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.

> 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?

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


-- Steve