Re: [RFC PATCH bpf-next 0/2] bpf: Add generic kfunc bpf_ffs64()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Jan 31, 2024 at 7:56 AM Leon Hwang <hffilwlqm@xxxxxxxxx> wrote:
>
> This patchset introduces a new generic kfunc bpf_ffs64(). This kfunc
> allows bpf to reuse kernel's __ffs64() function to improve ffs
> performance in bpf.
>

The downside of using kfunc for this is that the compiler will assume
that R1-R5 have to be spilled/filled, because that's function call
convention in BPF.

If this was an instruction, though, it would be much more efficient
and would avoid this problem. But I see how something like ffs64 is
useful. I think it would be good to also have popcnt instruction and a
few other fast bit manipulation operations as well.

Perhaps we should think about another BPF ISA extension to add fast
bit manipulation instructions?

> In patch "bpf: Add generic kfunc bpf_ffs64()", there is some data to
> confirm that this kfunc is able to save around 10ns for every time on
> "Intel(R) Xeon(R) Silver 4116 CPU @ 2.10GHz" CPU server, by comparing
> with bpf-implemented __ffs64().
>
> However, it will be better when convert this kfunc to "rep bsf" in
> JIT on x86, which is able to avoid a call. But, I haven't figure out the
> way.
>
> Leon Hwang (2):
>   bpf: Add generic kfunc bpf_ffs64()
>   selftests/bpf: Add testcases for generic kfunc bpf_ffs64()
>
>  kernel/bpf/helpers.c                          |  7 +++
>  .../testing/selftests/bpf/prog_tests/bitops.c | 54 +++++++++++++++++++
>  tools/testing/selftests/bpf/progs/bitops.c    | 21 ++++++++
>  3 files changed, 82 insertions(+)
>  create mode 100644 tools/testing/selftests/bpf/prog_tests/bitops.c
>  create mode 100644 tools/testing/selftests/bpf/progs/bitops.c
>
>
> base-commit: c5809f0c308111adbcdbf95462a72fa79eb267d1
> --
> 2.42.1
>





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux