summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/bpf/test_cpp.cpp
diff options
context:
space:
mode:
authorAndrii Nakryiko <andrii@kernel.org>2026-09-21 09:26:41 -0700
committerAndrii Nakryiko <andrii@kernel.org>2026-09-21 09:26:41 -0700
commit83aa20cc3585da1742a11da47b5bd4bf0394fbce (patch)
treed95322b461d511de538915e64071418b5bf77e4d /tools/testing/selftests/bpf/test_cpp.cpp
parent6e36e099b15bed1e8e5b3e3136c5e3eb56a15aa7 (diff)
parent66c22d8c0f62a6dfb4e9eaa58fddb804126f683d (diff)
downloadlinux-next-83aa20cc3585da1742a11da47b5bd4bf0394fbce.tar.gz
linux-next-83aa20cc3585da1742a11da47b5bd4bf0394fbce.zip
Merge branch 'libbpf-improve-bpf-load-performance-by-selectively-loading-module-btfs'
Fuyu Zhao says: ==================== libbpf: improve BPF load performance by selectively loading module BTFs Currently, load_module_btfs() unconditionally iterates over all kernel module BTFs and loads each one. This introduces unnecessary overhead when a BPF program only needs BTFs from a small subset of modules. In our Android testing, BPF programs are loaded on demand rather than preloaded to avoid unnecessary memory usage from unused programs. With 93 module BTFs present, the total BPF loading time exceeds 300 ms, with module BTF loading accounting for around 69% of the total loading time. The existing module qualification in SEC(), such as SEC("fentry/mymod:foo"), does not reduce this overhead, as module BTFs are loaded before the module-qualified target is resolved. Use btf_module_allowlist and btf_module_allowlist_cnt to skip unrelated module BTFs during iteration and stop once all allowed module BTFs have been loaded. When the allowlist is not specified, the existing behavior remains unchanged. Performance impact (BPF skeleton open and load time): Module BTFs | Default | Selective loading | Time reduction ------------|---------|-------------------|--------------- 1 | 35.6 ms | 35.6 ms | Baseline 10 | 37.2 ms | 35.7 ms | 4.0% 100 | 46.7 ms | 36.5 ms | 21.8% 300 | 65.2 ms | 38.5 ms | 40.9% Changelog: v9: - Change btf_module_allowlist_cnt to size_t in opts and use ssize_t internally. (Andrii) - Clarify the empty allowlist test comment. (bot+bpf-ci) - Match subtest names with function names. (bot+bpf-ci) v8: - Link: https://lore.kernel.org/bpf/20260911120820.46900-1-zhaofuyu@vivo.com/ - Reset btf_module_allowlist_cnt on allocation failure to avoid a NULL pointer dereference during cleanup. (sashiko-bot) - Fix errno handling in invalid input tests. (sashiko-bot) - Remove the redundant default opts test. (Jiri) - Test skipping unlisted module BTFs using bpf_program__set_attach_target(). (Jiri) - Simplify module BTF loading logic by using btf_module_allowlist_cnt alone for subsequent checks. (Jiri) - Fix remaining libbpf_get_error() usage in selftests. (Andrii) v7: - Link: https://lore.kernel.org/bpf/20260907053847.1115-1-zhaofuyu@vivo.com/ - Rename btf_module_names to btf_module_allowlist and use _cnt naming. (Andrii) - Simplify allowlist handling and documentation, and drop unnecessary logging, cleanup, and helper logic. (Andrii) - Simplify selftests, add invalid allowlist/count coverage, and add skip reasons for missing BTF prerequisites. (Andrii, bot+bpf-ci) v6: - Link: https://lore.kernel.org/bpf/20260831133809.1161-1-zhaofuyu@vivo.com/ - Document module-qualified tracing multi-attach targets and invalid module name handling. (bot+bpf-ci) - Remove unnecessary `static` qualifiers from test module name arrays. (bot+bpf-ci) - Check that bpf_testmod BTF is available before running the tests. (bot+bpf-ci) v5: - Link: https://lore.kernel.org/bpf/20260826131428.302-1-zhaofuyu@vivo.com/ - Add no_module_btfs_needed() to skip loading module BTFs early when the module BTF name list is empty. (sashiko-bot) - Document struct_ops as an affected use case for btf_module_names. (bot+bpf-ci) - Add invalid input tests and assert expected error codes for negative cases. (bot+bpf-ci) v4: - Link: https://lore.kernel.org/bpf/20260824125310.1384-1-zhaofuyu@vivo.com/ - Simplify and rename newly added struct members and their documentation. (Eduard) - Use array search instead of a hashmap for module name matching to simplify the code. (Eduard) - Allow an empty module name list to skip loading all module BTFs. (Eduard, sashiko-bot) - Move btf_module_names option handling before bpf_object__elf_init(). (Eduard) - Rename internal helpers to follow libbpf naming conventions. (Andrii) - Reject duplicate module names and document the rejection rule. (Andrii) - Replace log interception with functional tests and simplify selftests. (Andrii) v3: - Link: https://lore.kernel.org/bpf/20260819090426.267-1-zhaofuyu@vivo.com/ - Use bpf_object_open_opts to specify kernel module BTFs to load rather than introducing a new .kmod_btfs ELF section, as suggested by Andrii. v2: - Link: https://lore.kernel.org/bpf/20260813032613.2755-1-zhaofuyu@vivo.com/ - Addressed issues with allocation error handling, multiple .kmod_btfs sections, the transient stack pointer in is_kmod_btf_needed(), and selftest dependency and comment formatting. (sashiko-bot) - Removed KMODS_BTF_LOADED and KMODS_BTF_UNLOADED and simplified the related logic. v1: - Link: https://lore.kernel.org/bpf/20260806042042.3239428-1-zhaofuyu@vivo.com/ ==================== Link: https://patch.msgid.link/20260915124104.77287-1-zhaofuyu@vivo.com Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Diffstat (limited to 'tools/testing/selftests/bpf/test_cpp.cpp')
0 files changed, 0 insertions, 0 deletions