BPF List
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: Song Liu <song@kernel.org>
Cc: bpf <bpf@vger.kernel.org>, Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Kernel Team <kernel-team@fb.com>,
	joannelkoong@gmail.com
Subject: Re: [PATCH bpf-next v4 3/5] bpf: Inline calls to bpf_loop when callback is known
Date: Sat, 11 Jun 2022 01:49:43 +0300	[thread overview]
Message-ID: <f712fb0e6e0d72542b047f174f8590888d025918.camel@gmail.com> (raw)
In-Reply-To: <CAPhsuW7wPz+jwdT01BjLgpr0zPCkhc2gFzXBhph64FDvjh0oCQ@mail.gmail.com>

> On Fri, 2022-06-10 at 15:40 -0700, Song Liu wrote:
> Yes, I was thinking about this change. I guess it can also be clear:
> 
> static void update_loop_inline_state(struct bpf_verifier_env *env, u32
> subprogno)
> {
>         struct bpf_loop_inline_state *state = &cur_aux(env)->loop_inline_state;
>         struct bpf_reg_state *regs = cur_regs(env);
>         struct bpf_reg_state *flags_reg = &regs[BPF_REG_4];
>         int flags_is_zero;
> 
>         if (state->cannot_inline)
>                 return;
> 
>         flags_is_zero = register_is_const(flags_reg) &&
> flags_reg->var_off.value == 0;
> 
>         if (!state->initialized) {
>                 state->initialized = 1;
>                 state->cannot_inline = !flags_is_zero;
>                 state->callback_subprogno = subprogno;
>                 return;
>         }
> 
>         state->cannot_inline = !flags_is_zero ||
>                 state->callback_subprogno != subprogno;
> }
> 
> What do you think about this version?

Maybe keep `fit_for_inline` to minimize amount of negations?
As below:

static void update_loop_inline_state(struct bpf_verifier_env *env, u32 subprogno)
{
        struct bpf_loop_inline_state *state = &cur_aux(env)->loop_inline_state;
        struct bpf_reg_state *regs = cur_regs(env);
        struct bpf_reg_state *flags_reg = &regs[BPF_REG_4];
        int flags_is_zero;

/* this should be compiled as a single instruction anyway */
        if (!state->fit_for_inline)
                return;

        flags_is_zero = register_is_const(flags_reg) && flags_reg->var_off.value == 0;

        if (!state->initialized) {
                state->initialized = 1;
                state->fit_for_inline = flags_is_zero;
                state->callback_subprogno = subprogno;
                return;
        }

        state->fit_for_inline = flags_is_zero &&
                state->callback_subprogno == subprogno;
}

// ...

static int optimize_bpf_loop(struct bpf_verifier_env *env)
{
	if (is_bpf_loop_call(insn) && inline_state->fit_for_inline) { ... }
// vs
	if (is_bpf_loop_call(insn) && !inline_state->cannot_inline) { ... }
}

Thanks,
Eduard


  reply	other threads:[~2022-06-10 22:49 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-08 19:26 [PATCH bpf-next v4 0/5] bpf_loop inlining Eduard Zingerman
2022-06-08 19:26 ` [PATCH bpf-next v4 1/5] selftests/bpf: specify expected instructions in test_verifier tests Eduard Zingerman
2022-06-10 17:56   ` Song Liu
2022-06-08 19:26 ` [PATCH bpf-next v4 2/5] selftests/bpf: allow BTF specs and func infos " Eduard Zingerman
2022-06-10 18:09   ` Song Liu
2022-06-10 19:16     ` Eduard Zingerman
2022-06-10 20:56       ` Song Liu
2022-06-08 19:26 ` [PATCH bpf-next v4 3/5] bpf: Inline calls to bpf_loop when callback is known Eduard Zingerman
2022-06-09 14:56   ` kernel test robot
2022-06-10 20:54   ` Song Liu
2022-06-10 21:54     ` Eduard Zingerman
2022-06-10 22:40       ` Song Liu
2022-06-10 22:49         ` Eduard Zingerman [this message]
2022-06-10 23:01           ` Song Liu
2022-06-10 23:21             ` Eduard Zingerman
2022-06-11  1:46               ` Song Liu
2022-06-08 19:26 ` [PATCH bpf-next v4 4/5] selftests/bpf: BPF test_verifier selftests for bpf_loop inlining Eduard Zingerman
2022-06-10 18:14   ` Song Liu
2022-06-10 19:20     ` Eduard Zingerman
2022-06-10 20:57       ` Song Liu
2022-06-08 19:26 ` [PATCH bpf-next v4 5/5] selftests/bpf: BPF test_prog " Eduard Zingerman
2022-06-10 18:15   ` Song Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f712fb0e6e0d72542b047f174f8590888d025918.camel@gmail.com \
    --to=eddyz87@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=joannelkoong@gmail.com \
    --cc=kernel-team@fb.com \
    --cc=song@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox