Skip to content

Commit fc9a2ff

Browse files
Saket Kumar BhaskarKernel Patches Daemon
authored andcommitted
powerpc64/bpf: Inline bpf_get_smp_processor_id() and bpf_get_current_task/_btf()
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] anakryiko/linux@8dec900975ef Reviewed-by: Puranjay Mohan <[email protected]> Signed-off-by: Saket Kumar Bhaskar <[email protected]>
1 parent 478d0fe commit fc9a2ff

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

arch/powerpc/net/bpf_jit_comp.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,18 @@ bool bpf_jit_supports_percpu_insn(void)
471471
return IS_ENABLED(CONFIG_PPC64);
472472
}
473473

474+
bool bpf_jit_inlines_helper_call(s32 imm)
475+
{
476+
switch (imm) {
477+
case BPF_FUNC_get_smp_processor_id:
478+
case BPF_FUNC_get_current_task:
479+
case BPF_FUNC_get_current_task_btf:
480+
return true;
481+
default:
482+
return false;
483+
}
484+
}
485+
474486
void *arch_alloc_bpf_trampoline(unsigned int size)
475487
{
476488
return bpf_prog_pack_alloc(size, bpf_jit_fill_ill_insns);

arch/powerpc/net/bpf_jit_comp64.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,17 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct code
13991399
case BPF_JMP | BPF_CALL:
14001400
ctx->seen |= SEEN_FUNC;
14011401

1402+
if (src_reg == bpf_to_ppc(BPF_REG_0)) {
1403+
if (imm == BPF_FUNC_get_smp_processor_id) {
1404+
EMIT(PPC_RAW_LHZ(src_reg, _R13, offsetof(struct paca_struct, paca_index)));
1405+
break;
1406+
} else if (imm == BPF_FUNC_get_current_task ||
1407+
imm == BPF_FUNC_get_current_task_btf) {
1408+
EMIT(PPC_RAW_LD(src_reg, _R13, offsetof(struct paca_struct, __current)));
1409+
break;
1410+
}
1411+
}
1412+
14021413
ret = bpf_jit_get_func_addr(fp, &insn[i], extra_pass,
14031414
&func_addr, &func_addr_fixed);
14041415
if (ret < 0)

0 commit comments

Comments
 (0)