From: Hari Bathini <hbathini@linux.ibm.com>
To: Saket Kumar Bhaskar <skb99@linux.ibm.com>,
bpf@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
linux-kernel@vger.kernel.org
Cc: sachinpb@linux.ibm.com, venkat88@linux.ibm.com,
andrii@kernel.org, eddyz87@gmail.com, ast@kernel.org,
daniel@iogearbox.net, martin.lau@linux.dev, song@kernel.org,
yonghong.song@linux.dev, john.fastabend@gmail.com,
kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com,
jolsa@kernel.org, christophe.leroy@csgroup.eu, naveen@kernel.org,
maddy@linux.ibm.com, mpe@ellerman.id.au, npiggin@gmail.com
Subject: Re: [PATCH bpf-next v4 2/2] powerpc64/bpf: Inline bpf_get_smp_processor_id() and bpf_get_current_task/_btf()
Date: Wed, 17 Dec 2025 10:42:10 +0530 [thread overview]
Message-ID: <a8345e11-d0b4-4000-9f2c-b02f01c8df44@linux.ibm.com> (raw)
In-Reply-To: <89abfdd6f6721fbe7897865e74f2f691e5f7824a.1765343385.git.skb99@linux.ibm.com>
On 10/12/25 12:20 pm, Saket Kumar Bhaskar wrote:
> Inline the calls to bpf_get_smp_processor_id() and bpf_get_current_task/_btf()
> in the powerpc bpf jit.
>
> powerpc saves the Logical processor number (paca_index) and pointer
> to current task (__current) in paca.
>
> Here is how the powerpc JITed assembly changes after this commit:
>
> Before:
>
> cpu = bpf_get_smp_processor_id();
>
> addis 12, 2, -517
> addi 12, 12, -29456
> mtctr 12
> bctrl
> mr 8, 3
>
> After:
>
> cpu = bpf_get_smp_processor_id();
>
> lhz 8, 8(13)
>
> To evaluate the performance improvements introduced by this change,
> the benchmark described in [1] was employed.
>
> +---------------+-------------------+-------------------+--------------+
> | Name | Before | After | % change |
> |---------------+-------------------+-------------------+--------------|
> | glob-arr-inc | 40.701 ± 0.008M/s | 55.207 ± 0.021M/s | + 35.64% |
> | arr-inc | 39.401 ± 0.007M/s | 56.275 ± 0.023M/s | + 42.42% |
> | hash-inc | 24.944 ± 0.004M/s | 26.212 ± 0.003M/s | + 5.08% |
> +---------------+-------------------+-------------------+--------------+
>
> [1] https://github.com/anakryiko/linux/commit/8dec900975ef
>
Looks good.
Acked-by: Hari Bathini <hbathini@linux.ibm.com>
> Reviewed-by: Puranjay Mohan <puranjay@kernel.org>
> Signed-off-by: Saket Kumar Bhaskar <skb99@linux.ibm.com>
> ---
> arch/powerpc/net/bpf_jit_comp.c | 12 ++++++++++++
> arch/powerpc/net/bpf_jit_comp64.c | 11 +++++++++++
> 2 files changed, 23 insertions(+)
>
> diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c
> index d53e9cd7563f..b243ee205885 100644
> --- a/arch/powerpc/net/bpf_jit_comp.c
> +++ b/arch/powerpc/net/bpf_jit_comp.c
> @@ -471,6 +471,18 @@ bool bpf_jit_supports_percpu_insn(void)
> return IS_ENABLED(CONFIG_PPC64);
> }
>
> +bool bpf_jit_inlines_helper_call(s32 imm)
> +{
> + switch (imm) {
> + case BPF_FUNC_get_smp_processor_id:
> + case BPF_FUNC_get_current_task:
> + case BPF_FUNC_get_current_task_btf:
> + return true;
> + default:
> + return false;
> + }
> +}
> +
> void *arch_alloc_bpf_trampoline(unsigned int size)
> {
> return bpf_prog_pack_alloc(size, bpf_jit_fill_ill_insns);
> diff --git a/arch/powerpc/net/bpf_jit_comp64.c b/arch/powerpc/net/bpf_jit_comp64.c
> index 37723ee9344e..6c827e7aa691 100644
> --- a/arch/powerpc/net/bpf_jit_comp64.c
> +++ b/arch/powerpc/net/bpf_jit_comp64.c
> @@ -1400,6 +1400,17 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct code
> case BPF_JMP | BPF_CALL:
> ctx->seen |= SEEN_FUNC;
>
> + if (src_reg == bpf_to_ppc(BPF_REG_0)) {
> + if (imm == BPF_FUNC_get_smp_processor_id) {
> + EMIT(PPC_RAW_LHZ(src_reg, _R13, offsetof(struct paca_struct, paca_index)));
> + break;
> + } else if (imm == BPF_FUNC_get_current_task ||
> + imm == BPF_FUNC_get_current_task_btf) {
> + EMIT(PPC_RAW_LD(src_reg, _R13, offsetof(struct paca_struct, __current)));
> + break;
> + }
> + }
> +
> ret = bpf_jit_get_func_addr(fp, &insn[i], extra_pass,
> &func_addr, &func_addr_fixed);
> if (ret < 0)
next prev parent reply other threads:[~2025-12-17 5:13 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-10 6:50 [PATCH bpf-next v4 0/2] powerpc64/bpf: Inline helper in powerpc JIT Saket Kumar Bhaskar
2025-12-10 6:50 ` [PATCH bpf-next v4 1/2] powerpc64/bpf: Support internal-only MOV instruction to resolve per-CPU addrs Saket Kumar Bhaskar
2025-12-17 5:11 ` Hari Bathini
2025-12-10 6:50 ` [PATCH bpf-next v4 2/2] powerpc64/bpf: Inline bpf_get_smp_processor_id() and bpf_get_current_task/_btf() Saket Kumar Bhaskar
2025-12-17 5:12 ` Hari Bathini [this message]
2025-12-16 18:16 ` [PATCH bpf-next v4 0/2] powerpc64/bpf: Inline helper in powerpc JIT Andrii Nakryiko
2025-12-17 5:13 ` Hari Bathini
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=a8345e11-d0b4-4000-9f2c-b02f01c8df44@linux.ibm.com \
--to=hbathini@linux.ibm.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=christophe.leroy@csgroup.eu \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maddy@linux.ibm.com \
--cc=martin.lau@linux.dev \
--cc=mpe@ellerman.id.au \
--cc=naveen@kernel.org \
--cc=npiggin@gmail.com \
--cc=sachinpb@linux.ibm.com \
--cc=sdf@fomichev.me \
--cc=skb99@linux.ibm.com \
--cc=song@kernel.org \
--cc=venkat88@linux.ibm.com \
--cc=yonghong.song@linux.dev \
/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;
as well as URLs for NNTP newsgroup(s).