[PATCH 2/3] Provide and use an always inline version of finish_task_switch
Segher Boessenkool
segher at kernel.crashing.org
Sat Oct 25 07:36:12 PDT 2025
On Fri, Oct 24, 2025 at 05:36:06PM -0400, Rik van Riel wrote:
> On Sat, 2025-10-25 at 02:35 +0800, Xie Yuanbin wrote:
> > finish_task_switch is called during context switching,
> > inlining it can bring some performance benefits.
> >
> > Add an always inline version `finish_task_switch_ainline` to be
> > called
> > during context switching, and keep the original version for being
> > called
> > elsewhere, so as to take into account the size impact.
>
> Does that actually work, or does the compiler
> still inline some of those "non-inlined" versions,
> anyway?
Of course the compiler does! That is part of the compiler's job after
all, to generate fast, efficient code!
The compiler will inline stuff when a) it *can*, mostly it has to have
the function body available; and b) it estimates it to be a win to
inline it. There is a whole bunch of heuristics for this. One of those
is that the always_inline attribute will do the utmost to get inlining
to happen.
(All that is assuming you have -finline-functions turned on, like you do
have at -O2).
Segher
More information about the linux-riscv
mailing list