Re: [PATCH net-next v7] net/core: Introduce netdev_core_stats_inc()

Steven Rostedt
2023-10-09T14:27:24Z

On Mon, 9 Oct 2023 18:58:27 +0800
Yajun Deng <yajun.deng@linux.dev> wrote:

> > C compiler decides to inline or not, depending on various factors.
> >
> > The most efficient (and small) code is generated by this_cpu_inc()
> > version, allowing the compiler to inline it.
> >
> > If you copy/paste this_cpu_inc() twenty times, then the compiler
> > would not inline the function anymore.

Yes, if you want something to be visible by ftrace, it must not be inlined
(as inlined functions are not function calls by definition). And as Eric
stated, the compiler is perfectly allowed to inline something if it
believes it will be more efficient. i.e. There may be code around the function
call that could be more efficient if it wasn't change to parameters. If you
want to make sure a function stays out of line, you must explicitly tell
the compiler you want the function not to ever be inlined (hence the
"noinline" attribute).

>
>
> Got it. Thank you.

Great.

-- Steve