selftests/bpf: XDP LB benchmark fixes
Subsystems (4)
v2 cover selftests/bpf: XDP LB benchmark fixes
Changelog:
v1: https://lore.kernel.org/all/[email protected]/
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.
Puranjay Mohan (3):
selftests/bpf: Fix cold_lru producing zero batch_hash in XDP LB
benchmark
selftests/bpf: Fix expired UDP LRU entries in XDP LB benchmark selftests/bpf: Filter timing outliers with IQR in batch-timing library
.../selftests/bpf/benchs/bench_bpf_timing.c | 26 +++++++++++++++++++ .../selftests/bpf/benchs/bench_xdp_lb.c | 11 ++++++++ .../selftests/bpf/progs/xdp_lb_bench.c | 2 +- 3 files changed, 38 insertions(+), 1 deletion(-)
Signature · 1 line
2.53.0-Meta
PATCH v2 1/3 selftests/bpf: Fix cold_lru producing zero batch_hash in XDP LB benchmark
batch_hash = (batch_gen ^ cpu_id) * KNUTH_HASH_MULT;
When batch_gen == cpu_id the XOR produces zero, batch_hash is zero, and *saddr ^= 0 is a no-op. Every iteration hits the warm LRU entry.
During validation batch_gen is 2, so running on CPU 2 triggers:
[udp-v4-lru-miss] COUNTER FAIL: LRU misses=0, expected 1
Replace XOR with addition so the multiplier input is always >= 1. This also preserves the per-CPU salt for multi-producer runs.
--- tools/testing/selftests/bpf/progs/xdp_lb_bench.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/progs/xdp_lb_bench.c +1 -1
@@ -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; }
Signature · 1 line
2.53.0-Meta
PATCH v2 2/3 selftests/bpf: Fix expired UDP LRU entries in XDP LB benchmark
In reply to Puranjay Mohanpopulate_lru() zero-initializes atime:
struct real_pos_lru lru = { .pos = real_idx };connection_table_lookup() treats UDP entries with cur_time - atime > 30s as expired, so every pre-populated entry expires immediately. Calibration masks this on the CPU it runs on, but if validation migrates to another CPU:
[udp-v4-lru-hit] COUNTER FAIL: LRU misses=1, expected 0
Initialize atime from CLOCK_MONOTONIC for UDP flows.
--- tools/testing/selftests/bpf/benchs/bench_xdp_lb.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
tools/testing/selftests/bpf/benchs/bench_xdp_lb.c +11 -0
@@ -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
Signature · 1 line
2.53.0-Meta
PATCH v2 3/3 selftests/bpf: Filter timing outliers with IQR in batch-timing library
In reply to Puranjay MohanSystem noise (timer interrupts, scheduling) can inflate the reported stddev. tcp-v4-syn showed stddev 37.86 ns without filtering vs 0.16 ns with filtering on the same run data.
Filter samples outside [Q1 - 1.5*IQR, Q3 + 1.5*IQR] before computing statistics. Scenarios with genuinely wide distributions have large IQR so the fences stay wide and the filter has minimal effect.
--- .../selftests/bpf/benchs/bench_bpf_timing.c | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+)
tools/testing/selftests/bpf/benchs/bench_bpf_timing.c +26 -0
@@ -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, constreturn ; } + total =filter_outliers_iqr (all, total);compute_stats (all, total, &s);if (t->machine_readable) {
Signature · 1 line
2.53.0-Meta
This series was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Hello:
This series was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Quoted 10 lines · On Wed, 20 May 2026 06:33:29 -0700 you wrote:
Changelog:
v1: https://lore.kernel.org/all/[email protected]/
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.
[...]
Here is the summary with links:
- [bpf-next,v2,1/3] selftests/bpf: Fix cold_lru producing zero batch_hash in XDP LB benchmark
https://git.kernel.org/bpf/bpf-next/c/fa747e9f843b - [bpf-next,v2,2/3] selftests/bpf: Fix expired UDP LRU entries in XDP LB benchmark https://git.kernel.org/bpf/bpf-next/c/12e896b9794b - [bpf-next,v2,3/3] selftests/bpf: Filter timing outliers with IQR in batch-timing library https://git.kernel.org/bpf/bpf-next/c/abac8acb633a
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html