Skip to content

Commit a17a12c

Browse files
mflemingKernel Patches Daemon
authored andcommitted
selftests/bpf: Add LPM trie microbenchmarks
Add benchmarks for the standard set of operations: lookup, update, delete. Also, include a benchmark for trie_free() which is known to have terrible performance for maps with many entries. Benchmarks operate on tries without gaps in the key range, i.e. each test begins with a trie with valid keys in the range [0, nr_entries). This is intended to cause maximum branching when traversing the trie. All measurements are recorded inside the kernel to remove syscall overhead. Most benchmarks run an XDP program to generate stats but free needs to collect latencies using fentry/fexit on map_free_deferred() because it's not possible to use fentry directly on lpm_trie.c since commit c83508d ("bpf: Avoid deadlock caused by nested kprobe and fentry bpf programs") and there's no way to create/destroy a map from within an XDP program. Here is example output from an AMD EPYC 9684X 96-Core machine for each of the benchmarks using a trie with 10K entries and a 32-bit prefix length, e.g. $ ./bench lpm-trie-$op \ --prefix_len=32 \ --producers=1 \ --nr_entries=10000 lookup: throughput 7.423 ± 0.023 M ops/s ( 7.423M ops/prod), latency 134.710 ns/op update: throughput 2.643 ± 0.015 M ops/s ( 2.643M ops/prod), latency 378.310 ns/op delete: throughput 0.712 ± 0.008 M ops/s ( 0.712M ops/prod), latency 1405.152 ns/op free: throughput 0.574 ± 0.003 K ops/s ( 0.574K ops/prod), latency 1.743 ms/op Signed-off-by: Matt Fleming <[email protected]> Tested-by: Jesper Dangaard Brouer <[email protected]> Reviewed-by: Jesper Dangaard Brouer <[email protected]>
1 parent ffefc6d commit a17a12c

File tree

6 files changed

+552
-0
lines changed

6 files changed

+552
-0
lines changed

tools/testing/selftests/bpf/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,7 @@ $(OUTPUT)/bench_bpf_hashmap_lookup.o: $(OUTPUT)/bpf_hashmap_lookup.skel.h
816816
$(OUTPUT)/bench_htab_mem.o: $(OUTPUT)/htab_mem_bench.skel.h
817817
$(OUTPUT)/bench_bpf_crypto.o: $(OUTPUT)/crypto_bench.skel.h
818818
$(OUTPUT)/bench_sockmap.o: $(OUTPUT)/bench_sockmap_prog.skel.h
819+
$(OUTPUT)/bench_lpm_trie_map.o: $(OUTPUT)/lpm_trie_bench.skel.h $(OUTPUT)/lpm_trie_map.skel.h
819820
$(OUTPUT)/bench.o: bench.h testing_helpers.h $(BPFOBJ)
820821
$(OUTPUT)/bench: LDLIBS += -lm
821822
$(OUTPUT)/bench: $(OUTPUT)/bench.o \
@@ -837,6 +838,7 @@ $(OUTPUT)/bench: $(OUTPUT)/bench.o \
837838
$(OUTPUT)/bench_htab_mem.o \
838839
$(OUTPUT)/bench_bpf_crypto.o \
839840
$(OUTPUT)/bench_sockmap.o \
841+
$(OUTPUT)/bench_lpm_trie_map.o \
840842
#
841843
$(call msg,BINARY,,$@)
842844
$(Q)$(CC) $(CFLAGS) $(LDFLAGS) $(filter %.a %.o,$^) $(LDLIBS) -o $@

tools/testing/selftests/bpf/bench.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ extern struct argp bench_htab_mem_argp;
284284
extern struct argp bench_trigger_batch_argp;
285285
extern struct argp bench_crypto_argp;
286286
extern struct argp bench_sockmap_argp;
287+
extern struct argp bench_lpm_trie_map_argp;
287288

288289
static const struct argp_child bench_parsers[] = {
289290
{ &bench_ringbufs_argp, 0, "Ring buffers benchmark", 0 },
@@ -299,6 +300,7 @@ static const struct argp_child bench_parsers[] = {
299300
{ &bench_trigger_batch_argp, 0, "BPF triggering benchmark", 0 },
300301
{ &bench_crypto_argp, 0, "bpf crypto benchmark", 0 },
301302
{ &bench_sockmap_argp, 0, "bpf sockmap benchmark", 0 },
303+
{ &bench_lpm_trie_map_argp, 0, "LPM trie map benchmark", 0 },
302304
{},
303305
};
304306

@@ -558,6 +560,10 @@ extern const struct bench bench_htab_mem;
558560
extern const struct bench bench_crypto_encrypt;
559561
extern const struct bench bench_crypto_decrypt;
560562
extern const struct bench bench_sockmap;
563+
extern const struct bench bench_lpm_trie_lookup;
564+
extern const struct bench bench_lpm_trie_update;
565+
extern const struct bench bench_lpm_trie_delete;
566+
extern const struct bench bench_lpm_trie_free;
561567

562568
static const struct bench *benchs[] = {
563569
&bench_count_global,
@@ -625,6 +631,10 @@ static const struct bench *benchs[] = {
625631
&bench_crypto_encrypt,
626632
&bench_crypto_decrypt,
627633
&bench_sockmap,
634+
&bench_lpm_trie_lookup,
635+
&bench_lpm_trie_update,
636+
&bench_lpm_trie_delete,
637+
&bench_lpm_trie_free,
628638
};
629639

630640
static void find_benchmark(void)

tools/testing/selftests/bpf/bench.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ struct bench_res {
4646
unsigned long gp_ns;
4747
unsigned long gp_ct;
4848
unsigned int stime;
49+
unsigned long duration_ns;
4950
};
5051

5152
struct bench {

0 commit comments

Comments
 (0)