linux-kbuild.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@kernel.org>
To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
	linux-kbuild@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Arnd Bergmann <arnd@arndb.de>,
	Masahiro Yamada <masahiroy@kernel.org>,
	Nathan Chancellor <nathan@kernel.org>,
	Nicolas Schier <nicolas.schier@linux.dev>,
	Nick Desaulniers <nick.desaulniers+lkml@gmail.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Randy Dunlap <rdunlap@infradead.org>,
	Stephen Rothwell <sfr@canb.auug.org.au>
Subject: [PATCH v9 0/4] tracepoints: Add warnings for unused tracepoints and trace events
Date: Wed, 15 Oct 2025 16:38:42 -0400	[thread overview]
Message-ID: <20251015203842.618059565@kernel.org> (raw)


Every trace event can take up to 5K of memory in text and metadata regardless
if they are used or not. Trace events should not be created if they are not
used.  Currently there's several events in the kernel that are defined
but unused, either because their callers were removed without removing the
trace event with it, or a config hides the trace event caller but not the
trace event itself. And in some cases, trace events were simply added but were
never called for whatever reason. The number of unused trace events continues
to grow.

This patch series aims to fix this.

The first patch moves the elf parsing out of sorttable.c so that it can be
used by other tooling.

The second patch creates a new program to run during build called
tracepoint-update (note this may be extended to do other tracepoint
modifications in the future). It also creates a new section called
__tracepoint_check, where all callers of a tracepoint creates a variable
that is placed in this section with the name of the tracepoint they use.
The scripts/tracepoint-update.c is used to find tracepoints that are defined
but not used which would mean they would not be in the __tracepoint_check
section. It sorts the names from that section, and then reads the
__tracepoint_strings section that has all compiled in tracepoint names. It
makes sure that every tracepoint is found in the check section and if not, it
prints a warning message about it.  This lists the missing tracepoints at
build time.

The third patch adds EXPORT_TRACEPOINT() to the __tracepoint_check section as
well. There was several locations that adds tracepoints in the kernel proper
that are only used in modules. It was getting quite complex trying to move
things around that I just decided to make any tracepoint in a
EXPORT_TRACEPOINT "used". I'm using the analogy of static and global
functions. An unused static function gets a warning but an unused global one
does not.

The last patch triggers warnings when a module defines a tracepoint but
does not use it.

Instead of hiding this behind a config option, where allmodconfig can
cause the warnings to trigger, and we don't want current warnings
to suddenly appear. Have the warnings trigger by a new make command line:

   make UT=1

This will enable the unused tracepoints warnings. Now this should not
be an issue to upstream before all warnings are removed. When all current
warnings are removed, we can then make this the default option where
it will always cause the build to warn if there's a unused tracepoint
defined.

Changes since v8: https://lore.kernel.org/linux-trace-kernel/20250828203555.783399758@kernel.org/

- Instead of hiding the unused tracepoint warnings behind a config
  option, which means allmodconfig will trigger it, make it a
  make command line option. Now to enable the warnings, on must run

    make UT=1

- Trigger warnings for modules as well as built in unused tracepoints.

Steven Rostedt (4):
      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
      tracing: Add warnings for unused tracepoints for modules

----
 Makefile                          |  15 ++
 include/asm-generic/vmlinux.lds.h |   1 +
 include/linux/tracepoint.h        |  13 ++
 scripts/Makefile                  |   6 +
 scripts/Makefile.modfinal         |   7 +
 scripts/elf-parse.c               | 198 ++++++++++++++++
 scripts/elf-parse.h               | 305 ++++++++++++++++++++++++
 scripts/link-vmlinux.sh           |   7 +
 scripts/sorttable.c               | 477 +++-----------------------------------
 scripts/tracepoint-update.c       | 239 +++++++++++++++++++
 10 files changed, 825 insertions(+), 443 deletions(-)
 create mode 100644 scripts/elf-parse.c
 create mode 100644 scripts/elf-parse.h
 create mode 100644 scripts/tracepoint-update.c

             reply	other threads:[~2025-10-15 20:39 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-15 20:38 Steven Rostedt [this message]
2025-10-15 20:38 ` [PATCH v9 1/4] sorttable: Move ELF parsing into scripts/elf-parse.[ch] Steven Rostedt
2025-10-15 20:38 ` [PATCH v9 2/4] tracing: Add a tracepoint verification check at build time Steven Rostedt
2025-10-15 23:12   ` Nathan Chancellor
2025-10-15 23:14     ` Steven Rostedt
2025-10-17 20:15   ` Nicolas Schier
2025-10-21 19:47     ` Steven Rostedt
2025-10-21 21:21       ` Nicolas Schier
2025-10-15 20:38 ` [PATCH v9 3/4] tracepoint: Do not warn for unused event that is exported Steven Rostedt
2025-10-15 20:38 ` [PATCH v9 4/4] tracing: Add warnings for unused tracepoints for modules Steven Rostedt
2025-10-15 23:19   ` Nathan Chancellor
2025-10-17 20:22     ` Nicolas Schier
2025-10-21 19:48       ` Steven Rostedt
2025-10-21 19:57     ` Steven Rostedt
2025-10-16 10:54   ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251015203842.618059565@kernel.org \
    --to=rostedt@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=catalin.marinas@arm.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=masahiroy@kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=nathan@kernel.org \
    --cc=nick.desaulniers+lkml@gmail.com \
    --cc=nicolas.schier@linux.dev \
    --cc=rdunlap@infradead.org \
    --cc=sfr@canb.auug.org.au \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).