Re: [RFC PATCH] x86: add function metadata support

From: Steven Rostedt
Date: Tue Feb 11 2025 - 11:24:18 EST


On Tue, 11 Feb 2025 20:03:38 +0800
Menglong Dong <menglong8.dong@xxxxxxxxx> wrote:


>
> Another beneficiary can be ftrace. For now, all the kernel functions that
> are enabled by dynamic ftrace will be added to a filter hash. And hash
> lookup will happen when then traced functions are called, which has an
> impact on the performance, see
> __ftrace_ops_list_func() -> ftrace_ops_test(). With the per-function metadata
> support, we can store the information that if the ftrace ops is enabled on the
> kernel function to the metadata.

Note, ftrace only uses ftrace_ops_list if there's more than one callback
attached to the same function. Otherwise it calls directly to a single
trampoline, and is rather efficient. No meta data needed.

> > Arm64 and other archs add meta data before the functions too. Can we have
> > an effort to perhaps share these methods?
>
> I have not done research on arm64 yet. AFAIK, arm64 insn is 16-bytes aligned,
> so the way we process can be a little different here, as making kernel function
> non 16-bytes aligned can have a huge influence.

Arm64 already uses the meta data before every function. That's where it
stores a pointer to the ftrace_ops. So in ftrace, when there's a single
callback attached to a function in arm64, it jumps to a ftrace trampoline,
that will reference the function's meta data to find the ftrace_ops to use
for that callback.

If more than one callback is attached to the same function, then it acts
just like x86 and does the loop.

-- Steve