Re: [PATCH bpf-next v2] bpf: make update_prog_stats always_inline

From: Alexei Starovoitov
Date: Mon Jun 23 2025 - 12:28:07 EST


On Fri, Jun 20, 2025 at 9:57 PM Menglong Dong <menglong8.dong@xxxxxxxxx> wrote:
>
> The function update_prog_stats() will be called in the bpf trampoline.
> In most cases, it will be optimized by the compiler by making it inline.
> However, we can't rely on the compiler all the time, and just make it
> __always_inline to reduce the possible overhead.
>
> Signed-off-by: Menglong Dong <dongml2@xxxxxxxxxxxxxxx>
> ---
> v2:
> - split out __update_prog_stats() and make update_prog_stats()
> __always_inline, as Alexei's advice
> ---
> kernel/bpf/trampoline.c | 23 ++++++++++++++---------
> 1 file changed, 14 insertions(+), 9 deletions(-)
>
> diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c
> index c4b1a98ff726..1f92246117eb 100644
> --- a/kernel/bpf/trampoline.c
> +++ b/kernel/bpf/trampoline.c
> @@ -911,18 +911,16 @@ static u64 notrace __bpf_prog_enter_recur(struct bpf_prog *prog, struct bpf_tram
> return bpf_prog_start_time();
> }
>
> -static void notrace update_prog_stats(struct bpf_prog *prog,
> - u64 start)
> +static void notrace __update_prog_stats(struct bpf_prog *prog, u64 start)
> {
> struct bpf_prog_stats *stats;
>
> - if (static_branch_unlikely(&bpf_stats_enabled_key) &&
> - /* static_key could be enabled in __bpf_prog_enter*
> - * and disabled in __bpf_prog_exit*.
> - * And vice versa.
> - * Hence check that 'start' is valid.
> - */
> - start > NO_START_TIME) {
> + /* static_key could be enabled in __bpf_prog_enter*
> + * and disabled in __bpf_prog_exit*.
> + * And vice versa.
> + * Hence check that 'start' is valid.
> + */


Instead of old networking style I reformatted above to normal
kernel style comment.

> + if (start > NO_START_TIME) {

and refactored it to <= and removed extra indent in below.
while applying.