]> Gentwo Git Trees - linux/.git/commitdiff
tracing: Have function tracer define options per instance
authorSteven Rostedt <rostedt@goodmis.org>
Tue, 11 Nov 2025 23:24:08 +0000 (18:24 -0500)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Wed, 12 Nov 2025 14:59:54 +0000 (09:59 -0500)
Currently the function tracer's options are saved via a global mask when
it should be per instance. Use the new infrastructure to define a
"default_flags" field in the tracer structure that is used for the top
level instance as well as new ones.

Currently the global mask causes confusion:

  # cd /sys/kernel/tracing
  # mkdir instances/foo
  # echo function > instances/foo/current_tracer
  # echo 1 > options/func-args
  # echo function > current_tracer
  # cat trace
[..]
  <idle>-0       [005] d..3.  1050.656187: rcu_needs_cpu() <-tick_nohz_next_event
  <idle>-0       [005] d..3.  1050.656188: get_next_timer_interrupt(basej=0x10002dbad, basem=0xf45fd7d300) <-tick_nohz_next_event
  <idle>-0       [005] d..3.  1050.656189: _raw_spin_lock(lock=0xffff8944bdf5de80) <-__get_next_timer_interrupt
  <idle>-0       [005] d..4.  1050.656190: do_raw_spin_lock(lock=0xffff8944bdf5de80) <-__get_next_timer_interrupt
  <idle>-0       [005] d..4.  1050.656191: _raw_spin_lock_nested(lock=0xffff8944bdf5f140, subclass=1) <-__get_next_timer_interrupt
 # cat instances/foo/options/func-args
 1
 # cat instances/foo/trace
[..]
  kworker/4:1-88      [004] ...1.   298.127735: next_zone <-refresh_cpu_vm_stats
  kworker/4:1-88      [004] ...1.   298.127736: first_online_pgdat <-refresh_cpu_vm_stats
  kworker/4:1-88      [004] ...1.   298.127738: next_online_pgdat <-refresh_cpu_vm_stats
  kworker/4:1-88      [004] ...1.   298.127739: fold_diff <-refresh_cpu_vm_stats
  kworker/4:1-88      [004] ...1.   298.127741: round_jiffies_relative <-vmstat_update
[..]

The above shows that updating the "func-args" option at the top level
instance also updates the "func-args" option in the instance but because
the update is only done by the instance that gets changed (as it should),
it's confusing to see that the option is already set in the other instance.

Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Link: https://patch.msgid.link/20251111232429.470883736@kernel.org
Fixes: f20a580627f43 ("ftrace: Allow instances to use function tracing")
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
kernel/trace/trace_functions.c

index d17c18934445fd84156497a3060ff1e99e55e7db..c12795c2fb393524e43aebcacdfea1917c4d94d8 100644 (file)
@@ -154,11 +154,11 @@ static int function_trace_init(struct trace_array *tr)
        if (!tr->ops)
                return -ENOMEM;
 
-       func = select_trace_function(func_flags.val);
+       func = select_trace_function(tr->current_trace_flags->val);
        if (!func)
                return -EINVAL;
 
-       if (!handle_func_repeats(tr, func_flags.val))
+       if (!handle_func_repeats(tr, tr->current_trace_flags->val))
                return -ENOMEM;
 
        ftrace_init_array_ops(tr, func);
@@ -459,14 +459,14 @@ func_set_flag(struct trace_array *tr, u32 old_flags, u32 bit, int set)
        u32 new_flags;
 
        /* Do nothing if already set. */
-       if (!!set == !!(func_flags.val & bit))
+       if (!!set == !!(tr->current_trace_flags->val & bit))
                return 0;
 
        /* We can change this flag only when not running. */
        if (tr->current_trace != &function_trace)
                return 0;
 
-       new_flags = (func_flags.val & ~bit) | (set ? bit : 0);
+       new_flags = (tr->current_trace_flags->val & ~bit) | (set ? bit : 0);
        func = select_trace_function(new_flags);
        if (!func)
                return -EINVAL;
@@ -491,7 +491,7 @@ static struct tracer function_trace __tracer_data =
        .init           = function_trace_init,
        .reset          = function_trace_reset,
        .start          = function_trace_start,
-       .flags          = &func_flags,
+       .default_flags  = &func_flags,
        .set_flag       = func_set_flag,
        .allow_instances = true,
 #ifdef CONFIG_FTRACE_SELFTEST