Skip to content

Commit 6479325

Browse files
committed
tracing: Have function graph tracer option funcgraph-irqs be per instance
Currently the option to trace interrupts in the function graph tracer is global when the interface is per-instance. Changing the value in one instance will affect the results of another instance that is also running the function graph tracer. This can lead to confusing results. 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/20251114192318.613867934@kernel.org Fixes: c132be2 ("function_graph: Have the instances use their own ftrace_ops for filtering") Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 97e047f commit 6479325

1 file changed

Lines changed: 31 additions & 10 deletions

File tree

kernel/trace/trace_functions_graph.c

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "trace.h"
1717
#include "trace_output.h"
1818

19-
/* When set, irq functions will be ignored */
19+
/* When set, irq functions might be ignored */
2020
static int ftrace_graph_skip_irqs;
2121

2222
struct fgraph_cpu_data {
@@ -190,11 +190,14 @@ int __trace_graph_retaddr_entry(struct trace_array *tr,
190190
}
191191
#endif
192192

193-
static inline int ftrace_graph_ignore_irqs(void)
193+
static inline int ftrace_graph_ignore_irqs(struct trace_array *tr)
194194
{
195195
if (!ftrace_graph_skip_irqs || trace_recursion_test(TRACE_IRQ_BIT))
196196
return 0;
197197

198+
if (tracer_flags_is_set(tr, TRACE_GRAPH_PRINT_IRQS))
199+
return 0;
200+
198201
return in_hardirq();
199202
}
200203

@@ -238,7 +241,7 @@ static int graph_entry(struct ftrace_graph_ent *trace,
238241
if (ftrace_graph_ignore_func(gops, trace))
239242
return 0;
240243

241-
if (ftrace_graph_ignore_irqs())
244+
if (ftrace_graph_ignore_irqs(tr))
242245
return 0;
243246

244247
if (fgraph_sleep_time) {
@@ -451,6 +454,9 @@ static int graph_trace_init(struct trace_array *tr)
451454
else
452455
tr->gops->retfunc = trace_graph_return;
453456

457+
if (!tracer_flags_is_set(tr, TRACE_GRAPH_PRINT_IRQS))
458+
ftrace_graph_skip_irqs++;
459+
454460
/* Make gops functions visible before we start tracing */
455461
smp_mb();
456462

@@ -468,10 +474,6 @@ static int ftrace_graph_trace_args(struct trace_array *tr, int set)
468474
{
469475
trace_func_graph_ent_t entry;
470476

471-
/* Do nothing if the current tracer is not this tracer */
472-
if (tr->current_trace != &graph_trace)
473-
return 0;
474-
475477
if (set)
476478
entry = trace_graph_entry_args;
477479
else
@@ -492,6 +494,11 @@ static int ftrace_graph_trace_args(struct trace_array *tr, int set)
492494

493495
static void graph_trace_reset(struct trace_array *tr)
494496
{
497+
if (!tracer_flags_is_set(tr, TRACE_GRAPH_PRINT_IRQS))
498+
ftrace_graph_skip_irqs--;
499+
if (WARN_ON_ONCE(ftrace_graph_skip_irqs < 0))
500+
ftrace_graph_skip_irqs = 0;
501+
495502
tracing_stop_cmdline_record();
496503
unregister_ftrace_graph(tr->gops);
497504
}
@@ -1617,15 +1624,29 @@ void graph_trace_close(struct trace_iterator *iter)
16171624
static int
16181625
func_graph_set_flag(struct trace_array *tr, u32 old_flags, u32 bit, int set)
16191626
{
1620-
if (bit == TRACE_GRAPH_PRINT_IRQS)
1621-
ftrace_graph_skip_irqs = !set;
1622-
16231627
if (bit == TRACE_GRAPH_SLEEP_TIME)
16241628
ftrace_graph_sleep_time_control(set);
16251629

16261630
if (bit == TRACE_GRAPH_GRAPH_TIME)
16271631
ftrace_graph_graph_time_control(set);
16281632

1633+
/* Do nothing if the current tracer is not this tracer */
1634+
if (tr->current_trace != &graph_trace)
1635+
return 0;
1636+
1637+
/* Do nothing if already set. */
1638+
if (!!set == !!(tr->current_trace_flags->val & bit))
1639+
return 0;
1640+
1641+
if (bit == TRACE_GRAPH_PRINT_IRQS) {
1642+
if (set)
1643+
ftrace_graph_skip_irqs--;
1644+
else
1645+
ftrace_graph_skip_irqs++;
1646+
if (WARN_ON_ONCE(ftrace_graph_skip_irqs < 0))
1647+
ftrace_graph_skip_irqs = 0;
1648+
}
1649+
16291650
if (bit == TRACE_GRAPH_ARGS)
16301651
return ftrace_graph_trace_args(tr, set);
16311652

0 commit comments

Comments
 (0)