Re: [PATCH 2/3] Provide and use an always inline version of finish_task_switch

Segher Boessenkool
2025-10-25T14:38:55Z

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