diff options
| author | Alexei Starovoitov <ast@kernel.org> | 2026-05-20 09:25:47 -0700 |
|---|---|---|
| committer | Alexei Starovoitov <ast@kernel.org> | 2026-05-20 09:25:47 -0700 |
| commit | 3db0419c0147c3b91e2df475a1d34bcf0f645930 (patch) | |
| tree | 85dd4267667d1421a24c0eee2742ce7d8a1c1844 | |
| parent | 523d2f42b406f5be2989f436b03eacebf3679835 (diff) | |
| parent | abac8acb633a9448369d658889ac2bcfbd96f54b (diff) | |
| download | linux-3db0419c0147c3b91e2df475a1d34bcf0f645930.tar.gz linux-3db0419c0147c3b91e2df475a1d34bcf0f645930.zip | |
Merge branch 'selftests-bpf-xdp-lb-benchmark-fixes'
Puranjay Mohan says:
====================
selftests/bpf: XDP LB benchmark fixes
Changelog:
v1: https://lore.kernel.org/all/20260519163632.2220753-1-puranjay@kernel.org/
Changes in v2:
- Drop patch 3 as it was fixing a situation that can never happen in practice.
- Replace | 1 logic in patch 1 with replacing ^ operator with +
Three bug fixes and one improvement for the XDP LB and batch-timing
benchmarks.
The cold_lru validation was failing a lot because batch_hash could
compute to zero when batch_gen matched the CPU id. Similarly,
pre-populated UDP LRU entries had atime=0 so they'd expire immediately
on any CPU that calibration didn't warm. Both are fixed in patches 1-2.
Patch 3 adds IQR outlier filtering to the timing stats to stabilize
scenarios with high stddev.
====================
Link: https://patch.msgid.link/20260520133338.3392667-1-puranjay@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
| -rw-r--r-- | tools/testing/selftests/bpf/benchs/bench_bpf_timing.c | 26 | ||||
| -rw-r--r-- | tools/testing/selftests/bpf/benchs/bench_xdp_lb.c | 11 | ||||
| -rw-r--r-- | tools/testing/selftests/bpf/progs/xdp_lb_bench.c | 2 |
3 files changed, 38 insertions, 1 deletions
diff --git a/tools/testing/selftests/bpf/benchs/bench_bpf_timing.c b/tools/testing/selftests/bpf/benchs/bench_bpf_timing.c index 75a39da69655..e02ad324f7bc 100644 --- a/tools/testing/selftests/bpf/benchs/bench_bpf_timing.c +++ b/tools/testing/selftests/bpf/benchs/bench_bpf_timing.c @@ -65,6 +65,31 @@ static int collect_samples(struct bpf_bench_timing *t, return total; } +static int filter_outliers_iqr(double *sorted, int n) +{ + double q1, q3, iqr, lo, hi; + int start = 0, end = n; + + if (n < 8) + return n; + + q1 = sorted[n / 4]; + q3 = sorted[3 * n / 4]; + iqr = q3 - q1; + lo = q1 - 1.5 * iqr; + hi = q3 + 1.5 * iqr; + + while (start < end && sorted[start] < lo) + start++; + while (end > start && sorted[end - 1] > hi) + end--; + + if (start > 0) + memmove(sorted, sorted + start, (end - start) * sizeof(double)); + + return end - start; +} + static void compute_stats(const double *sorted, int n, struct timing_stats *s) { @@ -150,6 +175,7 @@ void bpf_bench_timing_report(struct bpf_bench_timing *t, const char *name, const return; } + total = filter_outliers_iqr(all, total); compute_stats(all, total, &s); if (t->machine_readable) { diff --git a/tools/testing/selftests/bpf/benchs/bench_xdp_lb.c b/tools/testing/selftests/bpf/benchs/bench_xdp_lb.c index 0b6709a2b03c..8e25bccbde92 100644 --- a/tools/testing/selftests/bpf/benchs/bench_xdp_lb.c +++ b/tools/testing/selftests/bpf/benchs/bench_xdp_lb.c @@ -563,12 +563,23 @@ static void create_per_cpu_lru_maps(struct xdp_lb_bench *skel) nr_inner_maps = nr_cpus; } +static __u64 ktime_get_ns(void) +{ + struct timespec ts; + + clock_gettime(CLOCK_MONOTONIC, &ts); + return (__u64)ts.tv_sec * 1000000000ULL + ts.tv_nsec; +} + static void populate_lru(const struct test_scenario *sc, __u32 real_idx) { struct real_pos_lru lru = { .pos = real_idx }; struct flow_key fk; int i, err; + if (sc->ip_proto == IPPROTO_UDP) + lru.atime = ktime_get_ns(); + build_flow_key(&fk, sc); /* Insert into every per-CPU inner LRU so the entry is found diff --git a/tools/testing/selftests/bpf/progs/xdp_lb_bench.c b/tools/testing/selftests/bpf/progs/xdp_lb_bench.c index b9fd848c035d..13777b3dcac8 100644 --- a/tools/testing/selftests/bpf/progs/xdp_lb_bench.c +++ b/tools/testing/selftests/bpf/progs/xdp_lb_bench.c @@ -618,7 +618,7 @@ int xdp_lb_bench(struct xdp_md *xdp) __u32 *saddr = data + saddr_off; batch_gen++; - batch_hash = (batch_gen ^ bpf_get_smp_processor_id()) * KNUTH_HASH_MULT; + batch_hash = (batch_gen + bpf_get_smp_processor_id()) * KNUTH_HASH_MULT; if ((void *)(saddr + 1) <= data_end) *saddr ^= batch_hash; } |
