Skip to content

Add bpf_loop helper

Joanne Koong bpf 4 versions – Applied

Status from this message: Applied. Thanks

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest4 patches 1 replyApplied
  2. v34 patches 6 repliesSuperseded
  3. v24 patches 10 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v13 patches16 repliesSuperseded

Changes in v4 from the cover letter

~ Address nits: use usleep for triggering bpf programs, fix copyright style

Patches in v4 Applied

#Subject and filesSizeRepliesApplied
1/4bpf: Add bpf_loop helperinclude/linux/bpf.h include/uapi/linux/bpf.h kernel/bpf/bpf_iter.c +3 more+142 -340 replies
2/4selftests/bpf: Add bpf_loop testtools/testing/selftests/bpf/prog_tests/bpf_loop.c tools/testing/selftests/bpf/progs/bpf_loop.c+257 -00 replies
3/4selftests/bpf: Measure bpf_loop verifier performancetools/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 +2 more+169 -40 replies
4/4selftest/bpf/benchs: Add bpf_loop benchmarktools/testing/selftests/bpf/Makefile tools/testing/selftests/bpf/bench.c tools/testing/selftests/bpf/bench.h +4 more+203 -10 replies

Reviews trailers per patch

All 4 patches have a Reviewed-by or Acked-by.

PatchAndrii Nakryiko
1/4A-b
2/4A-b
3/4A-b
4/4A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v4 thread

Cover letter [PATCH v4 bpf-next 0/4] Add bpf_loop helper

This patchset add a new helper, bpf_loop.

One of the complexities of using for loops in bpf programs is that the verifier needs to ensure that in every possibility of the loop logic, the loop will always terminate. As such, there is a limit on how many iterations the loop can do.

The bpf_loop helper moves the loop logic into the kernel and can thereby guarantee that the loop will always terminate. The bpf_loop helper simplifies a lot of the complexity the verifier needs to check, as well as removes the constraint on the number of loops able to be run.

From the test results, we see that using bpf_loop in place of the traditional for loop led to a decrease in verification time and number of bpf instructions by ~99%. The benchmark results show that as the number of iterations increases, the overhead per iteration decreases.

The high-level overview of the patches -
Patch 1 - kernel-side + API changes for adding bpf_loop
Patch 2 - tests
Patch 3 - use bpf_loop in strobemeta + pyperf600 and measure verifier performance Patch 4 - benchmark for throughput + latency of bpf_loop call

v3 -> v4:
~ Address nits: use usleep for triggering bpf programs, fix copyright style

v2 -> v3:
~ Rerun benchmarks on physical machine, update results ~ Propagate original error codes in the verifier

v1 -> v2:
~ Change helper name to bpf_loop (instead of bpf_for_each)
~ Set max nr_loops (~8 million loops) for bpf_loop call
~ Split tests + strobemeta/pyperf600 changes into two patches ~ Add new ops_report_final helper for outputting throughput and latency

Joanne Koong (4):
bpf: Add bpf_loop helper
selftests/bpf: Add bpf_loop test selftests/bpf: Measure bpf_loop verifier performance selftest/bpf/benchs: Add bpf_loop benchmark

 include/linux/bpf.h                           |   1 +
 include/uapi/linux/bpf.h                      |  25 +++
 kernel/bpf/bpf_iter.c                         |  35 +++++
 kernel/bpf/helpers.c                          |   2 +
 kernel/bpf/verifier.c                         |  88 +++++++----
 tools/include/uapi/linux/bpf.h                |  25 +++
 tools/testing/selftests/bpf/Makefile          |   4 +-
 tools/testing/selftests/bpf/bench.c           |  37 +++++
 tools/testing/selftests/bpf/bench.h           |   2 +
 .../selftests/bpf/benchs/bench_bpf_loop.c     | 105 +++++++++++++
 .../bpf/benchs/run_bench_bpf_loop.sh          |  15 ++
 .../selftests/bpf/benchs/run_common.sh        |  15 ++
 .../selftests/bpf/prog_tests/bpf_loop.c       | 145 ++++++++++++++++++
 .../bpf/prog_tests/bpf_verif_scale.c          |  12 ++
 tools/testing/selftests/bpf/progs/bpf_loop.c  | 112 ++++++++++++++
 .../selftests/bpf/progs/bpf_loop_bench.c      |  26 ++++
 tools/testing/selftests/bpf/progs/pyperf.h    |  71 ++++++++-
 .../selftests/bpf/progs/pyperf600_bpf_loop.c  |   6 +
 .../testing/selftests/bpf/progs/strobemeta.h  |  75 ++++++++-
 .../selftests/bpf/progs/strobemeta_bpf_loop.c |   9 ++
 20 files changed, 771 insertions(+), 39 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/benchs/bench_bpf_loop.c
 create mode 100755 tools/testing/selftests/bpf/benchs/run_bench_bpf_loop.sh
 create mode 100644 tools/testing/selftests/bpf/prog_tests/bpf_loop.c
 create mode 100644 tools/testing/selftests/bpf/progs/bpf_loop.c
 create mode 100644 tools/testing/selftests/bpf/progs/bpf_loop_bench.c
 create mode 100644 tools/testing/selftests/bpf/progs/pyperf600_bpf_loop.c
 create mode 100644 tools/testing/selftests/bpf/progs/strobemeta_bpf_loop.c
Signature · 1 line
2.30.2