mirror of https://github.com/torvalds/linux.git
If a tracepoint is defined via DECLARE_TRACE() or TRACE_EVENT() but never called (via the trace_<tracepoint>() function), its metadata is still around in memory and not discarded. When created via TRACE_EVENT() the situation is worse because the TRACE_EVENT() creates metadata that can be around 5k per trace event. Having unused trace events causes several thousand of wasted bytes. Add a verifier that injects a string of the name of the tracepoint it calls that is added to the discarded section "__tracepoint_check". For every builtin tracepoint, its name (which is saved in the in-memory section "__tracepoint_strings") will have its name also in the "__tracepoint_check" section if it is used. Add a new program that is run on build called tracepoint-update. This is executed on the vmlinux.o before the __tracepoint_check section is discarded (the section is discarded before vmlinux is created). This program will create an array of each string in the __tracepoint_check section and then sort it. Then it will walk the strings in the __tracepoint_strings section and do a binary search to check if its name is in the __tracepoint_check section. If it is not, then it is unused and a warning is printed. Note, this currently only handles tracepoints that are builtin and not in modules. Enabling this currently with a given config produces: warning: tracepoint 'sched_move_numa' is unused. warning: tracepoint 'sched_stick_numa' is unused. warning: tracepoint 'sched_swap_numa' is unused. warning: tracepoint 'pelt_hw_tp' is unused. warning: tracepoint 'pelt_irq_tp' is unused. warning: tracepoint 'rcu_preempt_task' is unused. warning: tracepoint 'rcu_unlock_preempted_task' is unused. warning: tracepoint 'xdp_bulk_tx' is unused. warning: tracepoint 'xdp_redirect_map' is unused. warning: tracepoint 'xdp_redirect_map_err' is unused. warning: tracepoint 'vma_mas_szero' is unused. warning: tracepoint 'vma_store' is unused. warning: tracepoint 'hugepage_set_pmd' is unused. warning: tracepoint 'hugepage_set_pud' is unused. warning: tracepoint 'hugepage_update_pmd' is unused. warning: tracepoint 'hugepage_update_pud' is unused. warning: tracepoint 'block_rq_remap' is unused. warning: tracepoint 'xhci_dbc_handle_event' is unused. warning: tracepoint 'xhci_dbc_handle_transfer' is unused. warning: tracepoint 'xhci_dbc_gadget_ep_queue' is unused. warning: tracepoint 'xhci_dbc_alloc_request' is unused. warning: tracepoint 'xhci_dbc_free_request' is unused. warning: tracepoint 'xhci_dbc_queue_request' is unused. warning: tracepoint 'xhci_dbc_giveback_request' is unused. warning: tracepoint 'tcp_ao_wrong_maclen' is unused. warning: tracepoint 'tcp_ao_mismatch' is unused. warning: tracepoint 'tcp_ao_key_not_found' is unused. warning: tracepoint 'tcp_ao_rnext_request' is unused. warning: tracepoint 'tcp_ao_synack_no_key' is unused. warning: tracepoint 'tcp_ao_snd_sne_update' is unused. warning: tracepoint 'tcp_ao_rcv_sne_update' is unused. Some of the above is totally unused but others are not used due to their "trace_" functions being inside configs, in which case, the defined tracepoints should also be inside those same configs. Others are architecture specific but defined in generic code, where they should either be moved to the architecture or be surrounded by #ifdef for the architectures they are for. This tool could be updated to process modules in the future. I'd like to thank Mathieu Desnoyers for suggesting using strings instead of pointers, as using pointers in vmlinux.o required handling relocations and it required implementing almost a full feature linker to do so. To enable this check, run the build with: make UT=1 Note, when all the existing unused tracepoints are removed from the build, the "UT=1" will be removed and this will always be enabled when tracepoints are configured to warn on any new tracepoints. The reason this isn't always enabled now is because it will introduce a lot of warnings for the current unused tracepoints, and all bisects would end at this commit for those warnings. Link: https://lore.kernel.org/all/20250528114549.4d8a5e03@gandalf.local.home/ Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Masahiro Yamada <masahiroy@kernel.org> Cc: Nathan Chancellor <nathan@kernel.org> Cc: Nicolas Schier <nicolas.schier@linux.dev> Cc: Nick Desaulniers <nick.desaulniers+lkml@gmail.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Randy Dunlap <rdunlap@infradead.org> Cc: Stephen Rothwell <sfr@canb.auug.org.au> Link: https://lore.kernel.org/20251022004452.920728129@kernel.org Suggested-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> # for using strings instead of pointers Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org> |
||
|---|---|---|
| .. | ||
| atomic | ||
| bash-completion | ||
| basic | ||
| clang-tools | ||
| coccinelle | ||
| crypto | ||
| dtc | ||
| dummy-tools | ||
| gcc-plugins | ||
| gdb | ||
| gendwarfksyms | ||
| genksyms | ||
| include | ||
| ipe | ||
| kconfig | ||
| ksymoops | ||
| lib | ||
| mod | ||
| package | ||
| selinux | ||
| tracing | ||
| .gitignore | ||
| Kbuild.include | ||
| Kconfig.include | ||
| Lindent | ||
| Makefile | ||
| Makefile.asm-headers | ||
| Makefile.autofdo | ||
| Makefile.btf | ||
| Makefile.build | ||
| Makefile.clang | ||
| Makefile.clean | ||
| Makefile.compiler | ||
| Makefile.debug | ||
| Makefile.defconf | ||
| Makefile.dtbinst | ||
| Makefile.dtbs | ||
| Makefile.extrawarn | ||
| Makefile.gcc-plugins | ||
| Makefile.headersinst | ||
| Makefile.host | ||
| Makefile.kasan | ||
| Makefile.kcov | ||
| Makefile.kcsan | ||
| Makefile.kmsan | ||
| Makefile.kstack_erase | ||
| Makefile.lib | ||
| Makefile.modfinal | ||
| Makefile.modinst | ||
| Makefile.modpost | ||
| Makefile.package | ||
| Makefile.propeller | ||
| Makefile.randstruct | ||
| Makefile.ubsan | ||
| Makefile.userprogs | ||
| Makefile.vdsoinst | ||
| Makefile.vmlinux | ||
| Makefile.vmlinux_o | ||
| as-version.sh | ||
| asn1_compiler.c | ||
| bloat-o-meter | ||
| bootgraph.pl | ||
| bpf_doc.py | ||
| build-version | ||
| cc-can-link.sh | ||
| cc-version.sh | ||
| check-git | ||
| check-sysctl-docs | ||
| check-uapi.sh | ||
| check-variable-fonts.sh | ||
| check_extable.sh | ||
| checkdeclares.pl | ||
| checkincludes.pl | ||
| checkkconfigsymbols.py | ||
| checkpatch.pl | ||
| checkstack.pl | ||
| checksyscalls.sh | ||
| checktransupdate.py | ||
| checkversion.pl | ||
| cleanfile | ||
| cleanpatch | ||
| coccicheck | ||
| config | ||
| const_structs.checkpatch | ||
| decode_stacktrace.sh | ||
| decodecode | ||
| depmod.sh | ||
| dev-needs.sh | ||
| diffconfig | ||
| documentation-file-ref-check | ||
| elf-parse.c | ||
| elf-parse.h | ||
| extract-fwblobs | ||
| extract-ikconfig | ||
| extract-module-sig.pl | ||
| extract-sys-certs.pl | ||
| extract-vmlinux | ||
| extract_xc3028.pl | ||
| faddr2line | ||
| file-size.sh | ||
| find-unused-docs.sh | ||
| gen-crc-consts.py | ||
| gen-randstruct-seed.sh | ||
| gen_packed_field_checks.c | ||
| generate_builtin_ranges.awk | ||
| generate_initcall_order.pl | ||
| generate_rust_analyzer.py | ||
| generate_rust_target.rs | ||
| get_abi.py | ||
| get_dvb_firmware | ||
| get_feat.pl | ||
| get_maintainer.pl | ||
| gfp-translate | ||
| git-resolve.sh | ||
| git.orderFile | ||
| head-object-list.txt | ||
| headerdep.pl | ||
| headers_install.sh | ||
| insert-sys-cert.c | ||
| install.sh | ||
| integer-wrap-ignore.scl | ||
| jobserver-exec | ||
| kallsyms.c | ||
| kernel-doc | ||
| kernel-doc.pl | ||
| kernel-doc.py | ||
| ld-version.sh | ||
| leaking_addresses.pl | ||
| link-vmlinux.sh | ||
| macro_checker.py | ||
| make_fit.py | ||
| makelst | ||
| markup_oops.pl | ||
| min-tool-version.sh | ||
| misc-check | ||
| mkcompile_h | ||
| mksysmap | ||
| mkuboot.sh | ||
| module-common.c | ||
| module.lds.S | ||
| modules-check.sh | ||
| nsdeps | ||
| objdiff | ||
| objdump-func | ||
| orc_hash.sh | ||
| pahole-version.sh | ||
| parse-maintainers.pl | ||
| patch-kernel | ||
| profile2linkerlist.pl | ||
| prune-kernel | ||
| recordmcount.c | ||
| recordmcount.h | ||
| recordmcount.pl | ||
| relocs_check.sh | ||
| remove-stale-files | ||
| rust_is_available.sh | ||
| rust_is_available_bindgen_0_66.h | ||
| rust_is_available_bindgen_libclang.h | ||
| rust_is_available_bindgen_libclang_concat.h | ||
| rust_is_available_test.py | ||
| rustc-llvm-version.sh | ||
| rustc-version.sh | ||
| rustdoc_test_builder.rs | ||
| rustdoc_test_gen.rs | ||
| setlocalversion | ||
| show_delta | ||
| sign-file.c | ||
| sorttable.c | ||
| spdxcheck-test.sh | ||
| spdxcheck.py | ||
| spdxexclude | ||
| spelling.txt | ||
| sphinx-build-wrapper | ||
| sphinx-pre-install | ||
| split-man.pl | ||
| ssl-common.h | ||
| stackdelta | ||
| stackusage | ||
| subarch.include | ||
| syscall.tbl | ||
| syscallhdr.sh | ||
| syscallnr.sh | ||
| syscalltbl.sh | ||
| tags.sh | ||
| test_doc_build.py | ||
| tools-support-relr.sh | ||
| tracepoint-update.c | ||
| unifdef.c | ||
| ver_linux | ||
| verify_builtin_ranges.awk | ||
| xen-hypercalls.sh | ||
| xz_wrap.sh | ||