selftests/bpf: Measure bpf_loop verifier performance
authorJoanne Koong <joannekoong@fb.com>
Tue, 30 Nov 2021 03:06:21 +0000 (19:06 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 30 Nov 2021 18:56:28 +0000 (10:56 -0800)
commitf6e659b7f97c76d0471d12bf274ea2a097cf3c5c
treeb8130dd0f6a15b2b28121d425169ef8f707382c2
parent4e5070b64b375a9c1f570893cfceeba108382bef
selftests/bpf: Measure bpf_loop verifier performance

This patch tests bpf_loop in pyperf and strobemeta, and measures the
verifier performance of replacing the traditional for loop
with bpf_loop.

The results are as follows:

~strobemeta~

Baseline
    verification time 6808200 usec
    stack depth 496
    processed 554252 insns (limit 1000000) max_states_per_insn 16
    total_states 15878 peak_states 13489  mark_read 3110
    #192 verif_scale_strobemeta:OK (unrolled loop)

Using bpf_loop
    verification time 31589 usec
    stack depth 96+400
    processed 1513 insns (limit 1000000) max_states_per_insn 2
    total_states 106 peak_states 106 mark_read 60
    #193 verif_scale_strobemeta_bpf_loop:OK

~pyperf600~

Baseline
    verification time 29702486 usec
    stack depth 368
    processed 626838 insns (limit 1000000) max_states_per_insn 7
    total_states 30368 peak_states 30279 mark_read 748
    #182 verif_scale_pyperf600:OK (unrolled loop)

Using bpf_loop
    verification time 148488 usec
    stack depth 320+40
    processed 10518 insns (limit 1000000) max_states_per_insn 10
    total_states 705 peak_states 517 mark_read 38
    #183 verif_scale_pyperf600_bpf_loop:OK

Using the bpf_loop helper led to approximately a 99% decrease
in the verification time and in the number of instructions.

Signed-off-by: Joanne Koong <joannekoong@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20211130030622.4131246-4-joannekoong@fb.com
tools/testing/selftests/bpf/prog_tests/bpf_verif_scale.c
tools/testing/selftests/bpf/progs/pyperf.h
tools/testing/selftests/bpf/progs/pyperf600_bpf_loop.c [new file with mode: 0644]
tools/testing/selftests/bpf/progs/strobemeta.h
tools/testing/selftests/bpf/progs/strobemeta_bpf_loop.c [new file with mode: 0644]