linux/tools/testing/selftests/bpf/prog_tests
Alexei Starovoitov c4781e37c6 selftests/bpf: Add BPF trampoline performance test
Add a test that benchmarks different ways of attaching BPF program to a kernel function.
Here are the results for 2.4Ghz x86 cpu on a kernel without mitigations:
$ ./test_progs -n 49 -v|grep events
task_rename base	2743K events per sec
task_rename kprobe	2419K events per sec
task_rename kretprobe	1876K events per sec
task_rename raw_tp	2578K events per sec
task_rename fentry	2710K events per sec
task_rename fexit	2685K events per sec

On a kernel with retpoline:
$ ./test_progs -n 49 -v|grep events
task_rename base	2401K events per sec
task_rename kprobe	1930K events per sec
task_rename kretprobe	1485K events per sec
task_rename raw_tp	2053K events per sec
task_rename fentry	2351K events per sec
task_rename fexit	2185K events per sec

All 5 approaches:
- kprobe/kretprobe in __set_task_comm()
- raw tracepoint in trace_task_rename()
- fentry/fexit in __set_task_comm()
are roughly equivalent.

__set_task_comm() by itself is quite fast, so any extra instructions add up.
Until BPF trampoline was introduced the fastest mechanism was raw tracepoint.
kprobe via ftrace was second best. kretprobe is slow due to trap. New
fentry/fexit methods via BPF trampoline are clearly the fastest and the
difference is more pronounced with retpoline on, since BPF trampoline doesn't
use indirect jumps.

Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/bpf/20191122011515.255371-1-ast@kernel.org
2019-11-24 16:58:46 -08:00
..
.gitignore
attach_probe.c libbpf: Make DECLARE_LIBBPF_OPTS macro strictly a variable declaration 2019-10-22 21:35:03 +02:00
bpf_obj_id.c selftests/bpf: test_progs: remove asserts from subtests 2019-08-28 00:35:40 +02:00
bpf_verif_scale.c selftests/bpf: Integrate verbose verifier log into test_progs 2019-11-24 16:58:45 -08:00
btf_dump.c selftests/bpf: Convert test_btf_dump into test_progs test 2019-10-09 15:38:36 -07:00
core_reloc.c selftests/bpf: Ensure core_reloc_kernel is reading test_progs's data only 2019-11-24 16:58:46 -08:00
fentry_fexit.c selftests/bpf: Add combined fentry/fexit test 2019-11-15 23:43:41 +01:00
fentry_test.c selftests/bpf: Add test for BPF trampoline 2019-11-15 23:43:15 +01:00
fexit_bpf2bpf.c selftests/bpf: Add a test for attaching BPF prog to another BPF prog and subprog 2019-11-15 23:46:09 +01:00
fexit_stress.c selftests/bpf: Add stress test for maximum number of progs 2019-11-15 23:43:53 +01:00
fexit_test.c selftests/bpf: Add fexit tests for BPF trampoline 2019-11-15 23:43:28 +01:00
flow_dissector.c selftests/bpf: remove wrong nhoff in flow dissector test 2019-08-28 00:39:43 +02:00
flow_dissector_load_bytes.c selftests/bpf: add flow dissector bpf_skb_load_bytes helper test 2019-04-23 18:36:34 +02:00
flow_dissector_reattach.c selftests/bpf: Restore the netns after flow dissector reattach test 2019-10-17 12:10:16 -07:00
get_stack_raw_tp.c selftests/bpf: test_progs: remove global fail/success counts 2019-08-28 00:35:40 +02:00
global_data.c selftests/bpf: test_progs: remove global fail/success counts 2019-08-28 00:35:40 +02:00
kfree_skb.c selftest/bpf: Simple test for fentry/fexit 2019-11-15 23:42:46 +01:00
l4lb_all.c selftests/bpf: test_progs: remove global fail/success counts 2019-08-28 00:35:40 +02:00
map_lock.c selftests/bpf: test_progs: remove asserts from subtests 2019-08-28 00:35:40 +02:00
mmap.c selftests/bpf: Add BPF_TYPE_MAP_ARRAY mmap() tests 2019-11-18 11:42:00 +01:00
obj_name.c selftests: bpf: break up test_progs - misc 2019-03-02 11:10:40 -08:00
perf_buffer.c selftests/bpf: fix perf_buffer on s390 2019-07-16 18:41:00 -07:00
pinning.c selftests/bpf: Add tests for automatic map unpinning on load failure 2019-11-10 19:26:30 -08:00
pkt_access.c selftests/bpf: test_progs: remove global fail/success counts 2019-08-28 00:35:40 +02:00
pkt_md_access.c selftests/bpf: test_progs: remove global fail/success counts 2019-08-28 00:35:40 +02:00
probe_user.c bpf, testing: Add selftest to read/write sockaddr from user space 2019-11-02 12:45:08 -07:00
prog_run_xattr.c selftests: bpf: break up test_progs - misc 2019-03-02 11:10:40 -08:00
queue_stack_map.c selftests/bpf: test_progs: remove global fail/success counts 2019-08-28 00:35:40 +02:00
raw_tp_writable_reject_nbd_invalid.c selftests: bpf: test writable buffers in raw tps 2019-04-26 19:04:19 -07:00
raw_tp_writable_test_run.c selftests: bpf: test writable buffers in raw tps 2019-04-26 19:04:19 -07:00
rdonly_maps.c selftest/bpf: Get rid of a bunch of explicit BPF program type setting 2019-10-21 14:49:12 +02:00
reference_tracking.c libbpf: Make DECLARE_LIBBPF_OPTS macro strictly a variable declaration 2019-10-22 21:35:03 +02:00
section_names.c selftests/bpf: Move test_section_names into test_progs and fix it 2019-10-23 10:06:46 -07:00
send_signal.c selftests/bpf: test_progs: remove unused ret 2019-08-28 00:35:40 +02:00
signal_pending.c selftests: bpf: test_progs: initialize duration in singal_pending test 2019-03-07 10:46:25 +01:00
skb_ctx.c selftests: bpf: Add selftest for __sk_buff tstamp 2019-10-15 16:24:26 -07:00
sockopt.c selftests/bpf: test_progs: convert test_sockopt 2019-09-06 09:59:05 -07:00
sockopt_inherit.c selftests/bpf: test_progs: Don't leak server_fd in test_sockopt_inherit 2019-10-02 00:58:07 +02:00
sockopt_multi.c selftests/bpf: test_progs: convert test_sockopt_multi 2019-09-06 09:59:05 -07:00
sockopt_sk.c selftests/bpf: test_progs: convert test_sockopt_sk 2019-09-06 09:59:05 -07:00
spinlock.c selftests/bpf: test_progs: remove asserts from subtests 2019-08-28 00:35:40 +02:00
stacktrace_build_id.c selftests/bpf: test_progs: remove asserts from subtests 2019-08-28 00:35:40 +02:00
stacktrace_build_id_nmi.c selftests/bpf: test_progs: remove asserts from subtests 2019-08-28 00:35:40 +02:00
stacktrace_map.c selftests/bpf: test_progs: remove global fail/success counts 2019-08-28 00:35:40 +02:00
stacktrace_map_raw_tp.c selftests/bpf: test_progs: remove global fail/success counts 2019-08-28 00:35:40 +02:00
task_fd_query_rawtp.c selftests/bpf: test_progs: remove global fail/success counts 2019-08-28 00:35:40 +02:00
task_fd_query_tp.c selftests/bpf: test_progs: remove global fail/success counts 2019-08-28 00:35:40 +02:00
tcp_estats.c selftests/bpf: test_progs: remove global fail/success counts 2019-08-28 00:35:40 +02:00
tcp_rtt.c selftests/bpf: test_progs: Don't leak server_fd in tcp_rtt 2019-10-02 00:56:46 +02:00
test_overhead.c selftests/bpf: Add BPF trampoline performance test 2019-11-24 16:58:46 -08:00
tp_attach_query.c selftests: bpf: initialize bpf_object pointers where needed 2019-05-09 15:53:56 -07:00
xdp.c selftests/bpf: test_progs: remove global fail/success counts 2019-08-28 00:35:40 +02:00
xdp_adjust_tail.c selftests/bpf: test_progs: remove global fail/success counts 2019-08-28 00:35:40 +02:00
xdp_noinline.c selftests/bpf: test_progs: remove global fail/success counts 2019-08-28 00:35:40 +02:00