Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

tracing: Have hist_debug show what function a field uses

When CONFIG_HIST_TRIGGERS_DEBUG is enabled, each trace event has a
"hist_debug" file that explains the histogram internal data. This is very
useful for debugging histograms.

One bit of data that was missing from this file was what function a
histogram field uses to process its data. The hist_field structure now has
a fn_num that is used by a switch statement in hist_fn_call() to call a
function directly (to avoid spectre mitigations).

Instead of displaying that number, create a string array that maps to the
histogram function enums so that the function for a field may be
displayed:

~# cat /sys/kernel/tracing/events/sched/sched_switch/hist_debug
[..]
hist_data: 0000000043d62762

n_vals: 2
n_keys: 1
n_fields: 3

val fields:

hist_data->fields[0]:
flags:
VAL: HIST_FIELD_FL_HITCOUNT
type: u64
size: 8
is_signed: 0
function: hist_field_counter()

hist_data->fields[1]:
flags:
HIST_FIELD_FL_VAR
var.name: __arg_3921_2
var.idx (into tracing_map_elt.vars[]): 0
type: unsigned long[]
size: 128
is_signed: 0
function: hist_field_nop()

key fields:

hist_data->fields[2]:
flags:
HIST_FIELD_FL_KEY
ftrace_event_field name: prev_pid
type: pid_t
size: 8
is_signed: 1
function: hist_field_s32()

The "function:" field above is added.

Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Link: https://patch.msgid.link/20260122203822.58df4d80@gandalf.local.home
Reviewed-by: Tom Zanussi <zanussi@kernel.org>
Tested-by: Tom Zanussi <zanussi@kernel.org>
Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

+44 -31
+44 -31
kernel/trace/trace_events_hist.c
··· 105 105 FIELD_OP_MULT, 106 106 }; 107 107 108 + #define FIELD_FUNCS \ 109 + C(NOP, "nop"), \ 110 + C(VAR_REF, "var_ref"), \ 111 + C(COUNTER, "counter"), \ 112 + C(CONST, "const"), \ 113 + C(LOG2, "log2"), \ 114 + C(BUCKET, "bucket"), \ 115 + C(TIMESTAMP, "timestamp"), \ 116 + C(CPU, "cpu"), \ 117 + C(COMM, "comm"), \ 118 + C(STRING, "string"), \ 119 + C(DYNSTRING, "dynstring"), \ 120 + C(RELDYNSTRING, "reldynstring"), \ 121 + C(PSTRING, "pstring"), \ 122 + C(S64, "s64"), \ 123 + C(U64, "u64"), \ 124 + C(S32, "s32"), \ 125 + C(U32, "u32"), \ 126 + C(S16, "s16"), \ 127 + C(U16, "u16"), \ 128 + C(S8, "s8"), \ 129 + C(U8, "u8"), \ 130 + C(UMINUS, "uminus"), \ 131 + C(MINUS, "minus"), \ 132 + C(PLUS, "plus"), \ 133 + C(DIV, "div"), \ 134 + C(MULT, "mult"), \ 135 + C(DIV_POWER2, "div_power2"), \ 136 + C(DIV_NOT_POWER2, "div_not_power2"), \ 137 + C(DIV_MULT_SHIFT, "div_mult_shift"), \ 138 + C(EXECNAME, "execname"), \ 139 + C(STACK, "stack"), 140 + 141 + #undef C 142 + #define C(a, b) HIST_FIELD_FN_##a 143 + 108 144 enum hist_field_fn { 109 - HIST_FIELD_FN_NOP, 110 - HIST_FIELD_FN_VAR_REF, 111 - HIST_FIELD_FN_COUNTER, 112 - HIST_FIELD_FN_CONST, 113 - HIST_FIELD_FN_LOG2, 114 - HIST_FIELD_FN_BUCKET, 115 - HIST_FIELD_FN_TIMESTAMP, 116 - HIST_FIELD_FN_CPU, 117 - HIST_FIELD_FN_COMM, 118 - HIST_FIELD_FN_STRING, 119 - HIST_FIELD_FN_DYNSTRING, 120 - HIST_FIELD_FN_RELDYNSTRING, 121 - HIST_FIELD_FN_PSTRING, 122 - HIST_FIELD_FN_S64, 123 - HIST_FIELD_FN_U64, 124 - HIST_FIELD_FN_S32, 125 - HIST_FIELD_FN_U32, 126 - HIST_FIELD_FN_S16, 127 - HIST_FIELD_FN_U16, 128 - HIST_FIELD_FN_S8, 129 - HIST_FIELD_FN_U8, 130 - HIST_FIELD_FN_UMINUS, 131 - HIST_FIELD_FN_MINUS, 132 - HIST_FIELD_FN_PLUS, 133 - HIST_FIELD_FN_DIV, 134 - HIST_FIELD_FN_MULT, 135 - HIST_FIELD_FN_DIV_POWER2, 136 - HIST_FIELD_FN_DIV_NOT_POWER2, 137 - HIST_FIELD_FN_DIV_MULT_SHIFT, 138 - HIST_FIELD_FN_EXECNAME, 139 - HIST_FIELD_FN_STACK, 145 + FIELD_FUNCS 140 146 }; 141 147 142 148 /* ··· 5860 5854 }; 5861 5855 5862 5856 #ifdef CONFIG_HIST_TRIGGERS_DEBUG 5857 + 5858 + #undef C 5859 + #define C(a, b) b 5860 + 5861 + static const char * const field_funcs[] = { FIELD_FUNCS }; 5862 + 5863 5863 static void hist_field_debug_show_flags(struct seq_file *m, 5864 5864 unsigned long flags) 5865 5865 { ··· 5930 5918 seq_printf(m, " type: %s\n", field->type); 5931 5919 seq_printf(m, " size: %u\n", field->size); 5932 5920 seq_printf(m, " is_signed: %u\n", field->is_signed); 5921 + seq_printf(m, " function: hist_field_%s()\n", field_funcs[field->fn_num]); 5933 5922 5934 5923 return 0; 5935 5924 }