tracing: Add bitmask-list option for human-readable bitmask display
Subsystems (3)
v3 cover tracing: Add bitmask-list option for human-readable bitmask display
Hi Steve,
This patch adds support for displaying bitmasks in human-readable list format (e.g., 0,2-5,7) in addition to the default hexadecimal bitmap representation. This is particularly useful when tracing CPU masks and other large bitmasks where individual bit positions are more meaningful than their hexadecimal encoding.
When the "bitmask-list" option is enabled, the printk "%*pbl" format specifier is used to render bitmasks as comma-separated ranges, making trace output easier to interpret for complex CPU configurations and large bitmask values.
This iteration incorporates the use of iter->tmp_seq to ensure the implementation is robust, instance-aware, and free from buffer contention or duplication issues.
Please let me know your thoughts.
Changes since v2 [1]:
- Fix build error by correcting redundant and missing stubs in the !CONFIG_TRACING block (0-DAY CI Kernel Test Service)
Changes since v1 [2]:
- Introduce new helper trace_seq_bitmask_list() (Steven Rostedt)
- Use iter->tmp_seq as a scratchpad to prevent buffer collisions and duplication
- Update trace_print_bitmask_seq() signature to accept trace_iterator instead of trace_seq
- Add declaration for trace_seq_bitmask_list() and provide necessary stub definitions
- Update __get_bitmask and __get_rel_bitmask macros to pass iter to the bitmask helper
- Implement instance-aware bitmask formatting using iter->tmp_seq as a scratchpad to prevent buffer collisions and duplication
[1]: https://lore.kernel.org/lkml/[email protected]/
[2]: https://lore.kernel.org/lkml/[email protected]/
Aaron Tomlin (1):
tracing: Add bitmask-list option for human-readable bitmask display
Documentation/trace/ftrace.rst | 9 +++++++ include/linux/trace_events.h | 8 +++--- include/linux/trace_seq.h | 12 ++++++++- include/trace/stages/stage3_trace_output.h | 4 +-- kernel/trace/trace.h | 1 + kernel/trace/trace_output.c | 30 +++++++++++++++++++--- kernel/trace/trace_seq.c | 29 ++++++++++++++++++++- 7 files changed, 82 insertions(+), 11 deletions(-)
Signature · 1 line
2.51.0
PATCH v3 1/1 tracing: Add bitmask-list option for human-readable bitmask display
Add support for displaying bitmasks in human-readable list format (e.g., 0,2-5,7) in addition to the default hexadecimal bitmap representation. This is particularly useful when tracing CPU masks and other large bitmasks where individual bit positions are more meaningful than their hexadecimal encoding.
When the "bitmask-list" option is enabled, the printk "%*pbl" format specifier is used to render bitmasks as comma-separated ranges, making trace output easier to interpret for complex CPU configurations and large bitmask values.
--- Documentation/trace/ftrace.rst | 9 +++++++ include/linux/trace_events.h | 8 +++--- include/linux/trace_seq.h | 12 ++++++++- include/trace/stages/stage3_trace_output.h | 4 +-- kernel/trace/trace.h | 1 + kernel/trace/trace_output.c | 30 +++++++++++++++++++--- kernel/trace/trace_seq.c | 29 ++++++++++++++++++++- 7 files changed, 82 insertions(+), 11 deletions(-)
Documentation/trace/ftrace.rst +9 -0
@@ -1290,6 +1290,15 @@ Here are the available options: This will be useful if you want to find out which hashed value is corresponding to the real value in trace log. + bitmask-list + When enabled, bitmasks are displayed as a human-readable list of + ranges (e.g., 0,2-5,7) using the printk "%*pbl" format specifier. + When disabled (the default), bitmasks are displayed in the + traditional hexadecimal bitmap representation. The list format is + particularly useful for tracing CPU masks and other large bitmasks + where individual bit positions are more meaningful than their + hexadecimal encoding. + record-cmd When any event or tracer is enabled, a hook is enabled in the sched_switch trace point to fill comm cache
include/linux/trace_events.h +4 -4
@@ -38,7 +38,10 @@ const char *trace_print_symbols_seq_u64(struct trace_seq *p, *symbol_array);#endif -const char *trace_print_bitmask_seq (struct trace_seq *p,void *bitmask_ptr, +struct trace_iterator ; +struct trace_event ; + +const char *trace_print_bitmask_seq (struct trace_iterator *iter,void *bitmask_ptr,unsigned int bitmask_size); const char *trace_print_hex_seq(struct trace_seq *p,
@@ -54,9 +57,6 @@ trace_print_hex_dump_seq(struct trace_seq *p, const char *prefix_str, int prefix_type, int rowsize, int groupsize, const void *buf, size_t len, bool ascii); -struct trace_iterator ; -struct trace_event ; -int trace_raw_output_prep (struct trace_iterator *iter,struct trace_event *event); extern __printf(2, 3)
include/linux/trace_seq.h +11 -1
@@ -114,7 +114,11 @@ extern void trace_seq_putmem_hex(struct trace_seq *s, const void *mem,extern int trace_seq_path (struct trace_seq *s,const struct path *path);extern void trace_seq_bitmask (struct trace_seq *s,const unsigned long *maskp, -int nmaskbits); +int nmaskbits); + +extern void trace_seq_bitmask_list (struct trace_seq *s, +const unsigned long *maskp, +int nmaskbits); extern int trace_seq_hex_dump(struct trace_seq *s, const char *prefix_str, int prefix_type, int rowsize, int groupsize,
@@ -137,6 +141,12 @@ trace_seq_bitmask(struct trace_seq *s, const unsigned long *maskp, { } +static inline void +trace_seq_bitmask_list (struct trace_seq *s,const unsigned long *maskp, +int nmaskbits) +{ +} +static inline int trace_print_seq (struct seq_file *m,struct trace_seq *s) {return 0 ;
include/trace/stages/stage3_trace_output.h +2 -2
@@ -39,7 +39,7 @@void *__bitmask =__get_dynamic_array (field); \unsigned int __bitmask_size; \ __bitmask_size =__get_dynamic_array_len (field); \ -trace_print_bitmask_seq (p, __bitmask, __bitmask_size); \ +trace_print_bitmask_seq (iter, __bitmask, __bitmask_size); \ })#undef __get_cpumask
@@ -51,7 +51,7 @@void *__bitmask =__get_rel_dynamic_array (field); \unsigned int __bitmask_size; \ __bitmask_size =__get_rel_dynamic_array_len (field); \ -trace_print_bitmask_seq (p, __bitmask, __bitmask_size); \ +trace_print_bitmask_seq (iter, __bitmask, __bitmask_size); \ })#undef __get_rel_cpumask
kernel/trace/trace.h +1 -0
@@ -1411,6 +1411,7 @@ extern int trace_get_user(struct trace_parser *parser, const char __user *ubuf,C (COPY_MARKER ,"copy_trace_marker" ), \C (PAUSE_ON_TRACE ,"pause-on-trace" ), \C (HASH_PTR ,"hash-ptr" ),/* Print hashed pointer */ \ +C (BITMASK_LIST ,"bitmask-list" ), \ FUNCTION_FLAGS \FGRAPH_FLAGS \STACK_FLAGS \
kernel/trace/trace_output.c +27 -3
@@ -194,13 +194,37 @@ trace_print_symbols_seq_u64(struct trace_seq *p, unsigned long long val,EXPORT_SYMBOL (trace_print_symbols_seq_u64);#endif +/** +* trace_print_bitmask_seq - print a bitmask to a sequence buffer +* @iter: The trace iterator for the current event instance +* @bitmask_ptr: The pointer to the bitmask data +* @bitmask_size: The size of the bitmask in bytes +* +* Prints a bitmask into a sequence buffer as either a hex string or a +* human-readable range list, depending on the instance's "bitmask-list" +* trace option. The bitmask is formatted into the iterator's temporary +* scratchpad rather than the primary sequence buffer. This avoids +* duplication and pointer-collision issues when the returned string is +* processed by a "%s" specifier in a TP_printk() macro. +* +* Returns a pointer to the formatted string within the temporary buffer. +*/ const char * -trace_print_bitmask_seq (struct trace_seq *p,void *bitmask_ptr, +trace_print_bitmask_seq (struct trace_iterator *iter,void *bitmask_ptr,unsigned int bitmask_size) { -const char *ret =trace_seq_buffer_ptr (p); +struct trace_seq *p = &iter->tmp_seq; +const struct trace_array *tr = iter->tr; +const char *ret; + +trace_seq_init (p); + ret =trace_seq_buffer_ptr (p); + +if (tr->trace_flags &TRACE_ITER (BITMASK_LIST )) +trace_seq_bitmask_list (p, bitmask_ptr, bitmask_size *8 ); +else +trace_seq_bitmask (p, bitmask_ptr, bitmask_size *8 ); -trace_seq_bitmask (p, bitmask_ptr, bitmask_size *8 );trace_seq_putc (p,0 );return ret;
kernel/trace/trace_seq.c +28 -1
@@ -106,7 +106,7 @@ EXPORT_SYMBOL_GPL(trace_seq_printf);* Writes a ASCII representation of a bitmask string into @s. */ void trace_seq_bitmask (struct trace_seq *s,const unsigned long *maskp, -int nmaskbits) +int nmaskbits) {unsigned int save_len = s->seq.len;
@@ -124,6 +124,33 @@ void trace_seq_bitmask(struct trace_seq *s, const unsigned long *maskp, }EXPORT_SYMBOL_GPL (trace_seq_bitmask); +/** +* trace_seq_bitmask_list - write a bitmask array in its list representation +* @s: trace sequence descriptor +* @maskp: points to an array of unsigned longs that represent a bitmask +* @nmaskbits: The number of bits that are valid in @maskp +* +* Writes a list representation (e.g., 0-3,5-7) of a bitmask string into @s. +*/ +void trace_seq_bitmask_list (struct trace_seq *s,const unsigned long *maskp, +int nmaskbits) +{ +unsigned int save_len = s->seq.len; + +if (s->full) +return ; + +__trace_seq_init (s); + +seq_buf_printf (&s->seq,"%*pbl" , nmaskbits, maskp); + +if (unlikely (seq_buf_has_overflowed (&s->seq))) { + s->seq.len = save_len; + s->full =1 ; + } +} +EXPORT_SYMBOL_GPL (trace_seq_bitmask_list); +/** * trace_seq_vprintf - sequence printing of trace information * @s: trace sequence descriptor
Signature · 1 line
2.51.0
Quoted 13 lines · Aaron Tomlin
Hi Steve,
This patch adds support for displaying bitmasks in human-readable list format (e.g., 0,2-5,7) in addition to the default hexadecimal bitmap representation. This is particularly useful when tracing CPU masks and other large bitmasks where individual bit positions are more meaningful than their hexadecimal encoding.
When the "bitmask-list" option is enabled, the printk "%*pbl" format specifier is used to render bitmasks as comma-separated ranges, making trace output easier to interpret for complex CPU configurations and large bitmask values.
Quoted 5 lines
This iteration incorporates the use of
iter->tmp_seqto ensure the implementation is robust, instance-aware, and free from buffer contention or duplication issues.Please let me know your thoughts.
Hi Steve,
I would like to ask if this iteration is suitable for inclusion, or should any further refinements be made?
Kind regards,
Signature · 1 line
Aaron Tomlin
Steven Rostedt
maintainerQuoted 18 lines · On Sat, 10 Jan 2026 16:06:02 -0500 Aaron Tomlin <[email protected]> wrote:
Quoted 17 lines · Aaron Tomlin
Hi Steve,
This patch adds support for displaying bitmasks in human-readable list format (e.g., 0,2-5,7) in addition to the default hexadecimal bitmap representation. This is particularly useful when tracing CPU masks and other large bitmasks where individual bit positions are more meaningful than their hexadecimal encoding.
When the "bitmask-list" option is enabled, the printk "%*pbl" format specifier is used to render bitmasks as comma-separated ranges, making trace output easier to interpret for complex CPU configurations and large bitmask values.
This iteration incorporates the use of
iter->tmp_seqto ensure the implementation is robust, instance-aware, and free from buffer contention or duplication issues.
Quoted 7 lines
Quoted 1 line
Please let me know your thoughts.
Hi Steve,
I would like to ask if this iteration is suitable for inclusion, or should any further refinements be made?
You can always check the status of a patch from patchwork. This one is here:
https://patchwork.kernel.org/project/linux-trace-kernel/patch/[email protected]/
The states are:
New - I haven't looked at it.
Under Review - I have it in a local queue (can still be rejected)
Queued - It's moved to linux-next
Accepted - It's in Linus's tree
Other states I will most likely have a response to.
This one is currently in the "Under Review" state. It also means I haven't found anything wrong with it. It just hasn't gone through all my tests.
-- Steve
Quoted 2 lines
Kind regards,