[PATCH 2/8] ARM: ftrace: use ADD not POP to counter PUSH at entry

Linus Walleij linus.walleij at linaro.org
Wed Feb 2 15:59:19 PST 2022


On Tue, Jan 25, 2022 at 4:37 PM Ard Biesheuvel <ardb at kernel.org> wrote:

> The compiler emitted hook used for ftrace consists of a PUSH {LR} to
> preserve the link register, followed by a branch-and-link (BL) to
> __gnu_mount_nc. Dynamic ftrace patches away the latter to turn the
> combined sequence into a NOP, using a POP {LR} instruction.
>
> This is not necessary, since the link register does not get clobbered in
> this case, and simply adding #4 to the stack pointer is sufficient, and
> avoids a memory access that may take a few cycles to resolve depending
> on the micro-architecture.
>
> Signed-off-by: Ard Biesheuvel <ardb at kernel.org>

That's on the hotpath for ftrace so definitely worth optimizing!
Reviewed-by: Linus Walleij <linus.walleij at linaro.org>

Maybe some of the commit message should go into
the code comment as well? "The compiler hook pushed 4 bytes with
a PUSH{LR}, so discard them by simply adding 4 to the
stack pointer" or so? Just a suggestion.

Yours,
Linus Walleij



More information about the linux-arm-kernel mailing list