Skip to content

Commit 4812334

Browse files
Saket Kumar BhaskarKernel Patches Daemon
Saket Kumar Bhaskar
authored and
Kernel Patches Daemon
committed
powerpc, bpf: Inline bpf_get_smp_processor_id()
Inline the calls to bpf_get_smp_processor_id() in the powerpc bpf jit. powerpc saves the Logical processor number (paca_index) 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 | 41.580 ± 0.034M/s | 54.137 ± 0.019M/s | + 30.20% | | arr-inc | 39.592 ± 0.055M/s | 54.000 ± 0.026M/s | + 36.39% | | hash-inc | 25.873 ± 0.012M/s | 26.334 ± 0.058M/s | + 1.78% | +---------------+-------------------+-------------------+--------------+ [1] anakryiko/linux@8dec900975ef Signed-off-by: Saket Kumar Bhaskar <[email protected]>
1 parent 6fc897e commit 4812334

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

arch/powerpc/net/bpf_jit_comp.c

+10
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,16 @@ bool bpf_jit_supports_percpu_insn(void)
445445
return true;
446446
}
447447

448+
bool bpf_jit_inlines_helper_call(s32 imm)
449+
{
450+
switch (imm) {
451+
case BPF_FUNC_get_smp_processor_id:
452+
return true;
453+
default:
454+
return false;
455+
}
456+
}
457+
448458
void *arch_alloc_bpf_trampoline(unsigned int size)
449459
{
450460
return bpf_prog_pack_alloc(size, bpf_jit_fill_ill_insns);

arch/powerpc/net/bpf_jit_comp64.c

+5
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,11 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct code
10871087
case BPF_JMP | BPF_CALL:
10881088
ctx->seen |= SEEN_FUNC;
10891089

1090+
if (insn[i].src_reg == 0 && imm == BPF_FUNC_get_smp_processor_id) {
1091+
EMIT(PPC_RAW_LHZ(bpf_to_ppc(BPF_REG_0), _R13, offsetof(struct paca_struct, paca_index)));
1092+
break;
1093+
}
1094+
10901095
ret = bpf_jit_get_func_addr(fp, &insn[i], extra_pass,
10911096
&func_addr, &func_addr_fixed);
10921097
if (ret < 0)

0 commit comments

Comments
 (0)