[for-next][PATCH 0/3] tracing: Trigger a warning on build if a tracepoint is defined but unused

Steven Rostedt posted 3 patches 1 month ago
include/asm-generic/vmlinux.lds.h |   1 +
include/linux/tracepoint.h        |  12 +
kernel/trace/Kconfig              |  10 +
scripts/Makefile                  |   6 +
scripts/Makefile.vmlinux          |   2 +
scripts/elf-parse.c               | 198 ++++++++++++++++
scripts/elf-parse.h               | 305 ++++++++++++++++++++++++
scripts/link-vmlinux.sh           |   4 +
scripts/sorttable.c               | 477 +++-----------------------------------
scripts/tracepoint-update.c       | 232 ++++++++++++++++++
10 files changed, 804 insertions(+), 443 deletions(-)
create mode 100644 scripts/elf-parse.c
create mode 100644 scripts/elf-parse.h
create mode 100644 scripts/tracepoint-update.c
[for-next][PATCH 0/3] tracing: Trigger a warning on build if a tracepoint is defined but unused
Posted by Steven Rostedt 1 month ago
Stephen,

I plan on pushing this to my for-next branch, which will add this to the
linux-next tree. When the kconfig option "TRACEPOINT_WARN_ON_UNUSED" is
enabled, it will warn whenever a tracepoint is created but not used. This is
similar to adding a static variable or function and not using it. This means
that an allmodconfig and allyesconfig builds may start having warnings that
will get bisected down to this commit. The bug is not this commit though, but
whatever has created an event but never used it. As tracepoints can take up to
5K of memory, even when not used, this is a waste and should be fixed.

I hope that adding this to linux-next will start the push to clean up these
unused tracepoints that are in the kernel, as well as prevent new ones from
being added. Hopefully by the time the merge window rolls around, most of
these will be cleaned up and this can be merged upstream without triggering
warnings.

I built this against all archs in my tree (26 of them) with a allyesconfig.
Unfortunately, only 10 build successfully with that (they all build
successfully with defconfig and this option with tracing enabled). This
detected 178 unique tracepoints that are defined and not used:

$ grep '^warning:' /work/autotest/cross-unused-traceevnts.log | sort -u |wc -l
178

Among them, 78 tracepoints were created and never referenced.

$ grep '^warning:' /work/autotest/cross-unused-traceevents.log | sort -u |cut -d"'" -f2 |
    while read a ; do if ! git grep -q trace_$a ; then echo $a; fi ; done | wc -l
78

The 100 remaining are likely in strange #ifdef CONFIG combinations where an
allyesconfig defines the tracepoint but doesn't enable the code that uses
them.

Expect even more warnings with different combos of config settings, as this
will warn whenever a tracepoint is defined but not used.

-- Steve

  git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git
unused-tracepoints/for-next

Head SHA1: d492e79ec6892ce1928a4c929ea29c0d5986e117


Steven Rostedt (3):
      sorttable: Move ELF parsing into scripts/elf-parse.[ch]
      tracing: Add a tracepoint verification check at build time
      tracepoint: Do not warn for unused event that is exported

----
 include/asm-generic/vmlinux.lds.h |   1 +
 include/linux/tracepoint.h        |  12 +
 kernel/trace/Kconfig              |  10 +
 scripts/Makefile                  |   6 +
 scripts/Makefile.vmlinux          |   2 +
 scripts/elf-parse.c               | 198 ++++++++++++++++
 scripts/elf-parse.h               | 305 ++++++++++++++++++++++++
 scripts/link-vmlinux.sh           |   4 +
 scripts/sorttable.c               | 477 +++-----------------------------------
 scripts/tracepoint-update.c       | 232 ++++++++++++++++++
 10 files changed, 804 insertions(+), 443 deletions(-)
 create mode 100644 scripts/elf-parse.c
 create mode 100644 scripts/elf-parse.h
 create mode 100644 scripts/tracepoint-update.c
Re: [for-next][PATCH 0/3] tracing: Trigger a warning on build if a tracepoint is defined but unused
Posted by Stephen Rothwell 1 month ago
Hi Steven,

On Thu, 28 Aug 2025 14:27:54 -0400 Steven Rostedt <rostedt@kernel.org> wrote:
>
> I built this against all archs in my tree (26 of them) with a allyesconfig.
> Unfortunately, only 10 build successfully with that (they all build
> successfully with defconfig and this option with tracing enabled). This
> detected 178 unique tracepoints that are defined and not used:
> 
> $ grep '^warning:' /work/autotest/cross-unused-traceevnts.log | sort -u |wc -l
> 178
> 
> Among them, 78 tracepoints were created and never referenced.
> 
> $ grep '^warning:' /work/autotest/cross-unused-traceevents.log | sort -u |cut -d"'" -f2 |
>     while read a ; do if ! git grep -q trace_$a ; then echo $a; fi ; done | wc -l
> 78
> 
> The 100 remaining are likely in strange #ifdef CONFIG combinations where an
> allyesconfig defines the tracepoint but doesn't enable the code that uses
> them.

[Pretending to be Linus :-)]

So, have you fixed up the 178 new warnings you know about?  I cannot
possibly do that, or even notify the offenders.  Please do that before
adding this code to linux-next.

But, really, these known warnings can just make it so much harder to
notice new ones.
-- 
Cheers,
Stephen Rothwell
Re: [for-next][PATCH 0/3] tracing: Trigger a warning on build if a tracepoint is defined but unused
Posted by Steven Rostedt 1 month ago
On Fri, 29 Aug 2025 07:02:24 +1000
Stephen Rothwell <sfr@canb.auug.org.au> wrote:

> But, really, these known warnings can just make it so much harder to
> notice new ones.

They all should be fixed. Note, this is not a compiler warning. It's a tool
that states "Your code is causing wasted memory to be allocate in the
running machine". If your tracepoint shows up in this list, then you should
fix it.

On an allyesconfig for x86_64:

warning: tracepoint 'kvm_iocsr' is unused.
warning: tracepoint 'nfs4_rename' is unused.
warning: tracepoint 'nfs4_renew' is unused.
warning: tracepoint 'xfs_metadir_link' is unused.
warning: tracepoint 'xfs_metadir_start_link' is unused.
warning: tracepoint 'xrep_rtbitmap_load_word' is unused.
warning: tracepoint 'xrep_rtbitmap_load_words' is unused.
warning: tracepoint 'xrep_rtbitmap_load' is unused.
warning: tracepoint 'xrep_nlinks_set_record' is unused.
warning: tracepoint 'xrep_cow_free_staging' is unused.
warning: tracepoint 'ocfs2_encode_fh_begin' is unused.
warning: tracepoint 'ocfs2_duplicate_clusters_by_jbd' is unused.
warning: tracepoint 'trans_restart_relock_key_cache_fill' is unused.
warning: tracepoint 'zonefs_file_dio_append' is unused.
warning: tracepoint 'edma_readb' is unused.
warning: tracepoint 'edma_readw' is unused.
warning: tracepoint 'host1x_syncpt_wait_check' is unused.
warning: tracepoint 'host1x_channel_submit_complete' is unused.
warning: tracepoint 'host1x_channel_release' is unused.
warning: tracepoint 'host1x_channel_open' is unused.
warning: tracepoint 'amdgpu_reset_reg_dumps' is unused.
warning: tracepoint 'amdgpu_dm_atomic_state_template' is unused.
warning: tracepoint 'xe_exec_queue_supress_resume' is unused.
warning: tracepoint 'xe_vm_restart' is unused.
warning: tracepoint 'xe_vma_userptr_rebind_exec' is unused.
warning: tracepoint 'xe_vma_userptr_rebind_worker' is unused.
warning: tracepoint 'xe_vma_flush' is unused.
warning: tracepoint 'dpu_rm_reserve_intf' is unused.
warning: tracepoint 'dpu_enc_atomic_check_flags' is unused.
warning: tracepoint 'dpu_crtc_runtime_resume' is unused.
warning: tracepoint 'dpu_enc_atomic_check' is unused.
warning: tracepoint 'dpu_trace_counter' is unused.
warning: tracepoint 'scsi_zone_wp_update' is unused.
warning: tracepoint 'scsi_prepare_zone_append' is unused.
warning: tracepoint 'ath12k_htt_rxdesc' is unused.
warning: tracepoint 'ath12k_htt_ppdu_stats' is unused.
warning: tracepoint 'ath12k_htt_pktlog' is unused.
warning: tracepoint 'brcms_dpc' is unused.
warning: tracepoint 'brcms_timer' is unused.
warning: tracepoint 'mt_tx_status' is unused.
warning: tracepoint 'ee_read' is unused.
warning: tracepoint 'cdns3_mapped_request' is unused.
warning: tracepoint 'cdns3_map_request' is unused.
warning: tracepoint 'cdns3_stream_transfer_split_next_part' is unused.
warning: tracepoint 'cdns3_stream_transfer_split' is unused.
warning: tracepoint 'cdnsp_handle_cmd_flush_ep' is unused.
warning: tracepoint 'cdnsp_setup_device' is unused.
warning: tracepoint 'cdnsp_free_priv_device' is unused.
warning: tracepoint 'cdnsp_defered_event' is unused.
warning: tracepoint 'cdnsp_ep0_halted' is unused.
warning: tracepoint 'cdns2_iso_out_ep_disable' is unused.
warning: tracepoint 'cdns2_mapped_request' is unused.
warning: tracepoint 'cdns2_map_request' is unused.
warning: tracepoint 'cdns2_ep0_enqueue' is unused.
warning: tracepoint 'cdns2_ep_queue' is unused.
warning: tracepoint 'cdns2_ep0_set_config' is unused.
warning: tracepoint 'cdns2_may_wakeup' is unused.
warning: tracepoint 'cdns2_lpm' is unused.
warning: tracepoint 'ucsi_reset_ppm' is unused.
warning: tracepoint 'ucsi_run_command' is unused.
warning: tracepoint 'icm_send_mra' is unused.
warning: tracepoint 'open_err_template' is unused.
warning: tracepoint 'irdma_send_cm_event_no_node' is unused.
warning: tracepoint 'hfi1_txq_xmit_stopped' is unused.
warning: tracepoint 'hfi1_mmu_invalidate' is unused.
warning: tracepoint 'rvt_mr_fmr_seg' is unused.
warning: tracepoint 'camera_debug' is unused.
warning: tracepoint 'camera_meminfo' is unused.
warning: tracepoint 'rpc_socket_reset_connection' is unused.
warning: tracepoint 'rxrpc_drop_ack' is unused.
warning: tracepoint 'cfg80211_return_u32' is unused.
warning: tracepoint 'cfg80211_return_uint' is unused.
warning: tracepoint 'cfg80211_chandef_dfs_required' is unused.
warning: tracepoint 'cfg80211_send_rx_auth' is unused.
warning: tracepoint 'rdev_return_void_tx_rx' is unused.
warning: tracepoint 'drv_offchannel_tx_cancel_wait' is unused.
warning: tracepoint 'tipc_node_dump' is unused.
warning: tracepoint '802154_new_scan_event' is unused.
warning: tracepoint '802154_drv_set_pan_coord' is unused.

Each one of those causes around 5K of wasted memory on your machine.

Most of them is because of some crazy config combinations the maintainer
has, as they are used, but for some reason an allyesconfig isn't the right
config option to enable them.

I'll push this branch up, and if it causes issues for you, I'll remove it.
But then, I'm not doing anymore work on fixing this.

-- Steve
Re: [for-next][PATCH 0/3] tracing: Trigger a warning on build if a tracepoint is defined but unused
Posted by Steven Rostedt 1 month ago
On Fri, 29 Aug 2025 07:02:24 +1000
Stephen Rothwell <sfr@canb.auug.org.au> wrote:

> [Pretending to be Linus :-)]
> 
> So, have you fixed up the 178 new warnings you know about?  I cannot
> possibly do that, or even notify the offenders.  Please do that before
> adding this code to linux-next.
> 
> But, really, these known warnings can just make it so much harder to
> notice new ones.

Then this won't get in. I simply don't have the time to fix the current
ones. I did 20 or so, and that took me all day (which I did on a
holiday). And this work is something I'm already doing on my own time,
as my employer has other priorities for me to work on.

But it is something that is needed as there's currently nothing that
tells you that you have a tracepoint not used, and the are growing in
numbers and wasting more memory.

There is an option that needs to be enabled. Now this will get enabled
with allmodconfig or allyesconfig, but scripts that do tests could
disable it. Or I can make it a tri op that doesn't get set by one of
those (but randconfig may set it).

As for fixing the warnings, it really belongs to whoever added the
tracepoint (git blame will give you that). And would be a great project
for an intern (which I don't have any).

-- Steve