[PATCH v3 0/2] perf trace: Correct cpumask formatting and add --bitmask-list

From: Aaron Tomlin

Date: Sat Jul 18 2026 - 20:15:36 EST


This series corrects cpumask formatting inside 'perf trace' and introduces
a new command-line option to display these masks as human-readable CPU
lists.

Currently, when parsing tracepoints containing 'cpumask_t' fields (which
are represented as dynamic non-array fields in libtraceevent), 'perf trace'
incorrectly interprets and prints the raw length and offset descriptor as a
decimal integer (i.e., "cpumask: 524320") rather than formatting the actual
mask data.

The first patch addresses this anomaly by introducing helper functions to
correctly parse and extract raw bits from dynamic fields that do not have
the TEP_FIELD_IS_ARRAY flag set. Once the raw bytes are resolved, 'perf
trace' displays them as a zero-padded hexadecimal string by default.

The second patch introduces a '--bitmask-list' option. When specified,
formatting is delegated to bitmap_scnprintf(), allowing the resolved
cpumask to be rendered as a condensed, human-readable list of CPUs
(e.g., "0,2-5,7").

Changes since v2:

- Provided an example output of the newly introduced '--bitmask-list'
option (Namhyung Kim)

- Updated the documentation to include the new option (Namhyung Kim)

- Linked to v2: https://lore.kernel.org/lkml/20260717013544.257768-1-atomlin@xxxxxxxxxxx/

Changes since v1:

- Refactored cpumask parsing by moving the dynamic bitmask
reconstruction logic into a new helper function,
format_field__get_cpumask()

- Made bitmask parsing cross-platform, word-size, and endianness-safe

- Added a new helper function, bitmap_byte() to extract bytes from the
host-native bitmask in a host-endianness-independent manner,
simplifying hexadecimal cpumask formatting

- Cleaned up trace__fprintf_tp_fields() to remove complex inline
parsing logic

- Linked to v1: https://lore.kernel.org/lkml/20260714162947.214270-1-atomlin@xxxxxxxxxxx/


Aaron Tomlin (2):
perf trace: Correct default cpumask formatting to hexadecimal
perf trace: Add --bitmask-list command-line option

tools/perf/Documentation/perf-trace.txt | 4 ++
tools/perf/builtin-trace.c | 75 ++++++++++++++++++---
tools/perf/util/evsel.c | 90 +++++++++++++++++++++++++
tools/perf/util/evsel.h | 6 ++
4 files changed, 166 insertions(+), 9 deletions(-)

--
2.54.0