linux-trace-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v5 0/3] tracepoints: Add warnings for unused tracepoints and trace events
@ 2025-07-25  2:51 Steven Rostedt
  2025-07-25  2:51 ` [PATCH v5 1/3] sorttable: Move ELF parsing into scripts/elf-parse.[ch] Steven Rostedt
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Steven Rostedt @ 2025-07-25  2:51 UTC (permalink / raw)
  To: linux-kernel, linux-trace-kernel, linux-kbuild, llvm
  Cc: Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers, Andrew Morton,
	Arnd Bergmann, Masahiro Yamada, Nathan Chancellor, Nicolas Schier,
	Nick Desaulniers, Catalin Marinas, Linus Torvalds

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 over a hundred 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 it, 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.

Changes since v4: https://lore.kernel.org/linux-trace-kernel/20250723194141.617125835@kernel.org/

- Took out the last patch that updated trace_ftrace_test_filter boot up self
  test as it was agnostic to the rest of the patches. I just queued it up by
  itself.

- Added elf-parse.c that takes the elf parsing code out of sorttable.c so
  that it can be used with tracepoint-update.c.

- Use the tracepoint name instead of the pointer to map the checks to the
  tracepoints (Mathieu Desnoyers)

- Create a new tool "tracepoint-update" instead of hacking sorttable

- Move the __tracepoint_check into the discard section so it is never
  loaded into memory. (Linus Torvalds)

- Parse the vmlinux.o instead of vmlinux as the discard section is removed
  between those two steps.


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/elf-parse.c               | 198 ++++++++++++++++
 scripts/elf-parse.h               | 306 ++++++++++++++++++++++++
 scripts/link-vmlinux.sh           |   4 +
 scripts/sorttable.c               | 477 +++-----------------------------------
 scripts/tracepoint-update.c       | 217 +++++++++++++++++
 9 files changed, 788 insertions(+), 443 deletions(-)
 create mode 100644 scripts/elf-parse.c
 create mode 100644 scripts/elf-parse.h
 create mode 100644 scripts/tracepoint-update.c

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-07-26 10:37 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-25  2:51 [PATCH v5 0/3] tracepoints: Add warnings for unused tracepoints and trace events Steven Rostedt
2025-07-25  2:51 ` [PATCH v5 1/3] sorttable: Move ELF parsing into scripts/elf-parse.[ch] Steven Rostedt
2025-07-25  2:51 ` [PATCH v5 2/3] tracing: Add a tracepoint verification check at build time Steven Rostedt
2025-07-25 13:15   ` Mathieu Desnoyers
2025-07-25 13:41     ` Steven Rostedt
2025-07-25 13:49   ` Steven Rostedt
2025-07-26 10:36   ` kernel test robot
2025-07-25  2:51 ` [PATCH v5 3/3] tracepoint: Do not warn for unused event that is exported Steven Rostedt

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).