Skip to content

Commit 64dee86

Browse files
committed
tracing: Make tracing_disabled global for tracing system
The tracing_disabled variable is set to one on boot up to prevent some parts of tracing to access the tracing infrastructure before it is set up. It also can be set after boot if an anomaly is discovered. It is currently a static variable in trace.c and can be accessed via a function call trace_is_disabled(). There's really no reason to use a function call as the tracing subsystem should be able to access it directly. By making the variable accessed directly, code can be moved out of trace.c without adding overhead of a function call to see if tracing is disabled or not. Make tracing_disabled global and remove the tracing_is_disabled() helper function. Also add some "unlikely()"s around tracing_disabled where it's checked in hot paths. 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/20260208032449.483690153@kernel.org Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent ba73713 commit 64dee86

4 files changed

Lines changed: 8 additions & 12 deletions

File tree

kernel/trace/trace.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ DEFINE_PER_CPU(bool, trace_taskinfo_save);
114114
* of the tracer is successful. But that is the only place that sets
115115
* this back to zero.
116116
*/
117-
static int tracing_disabled = 1;
117+
int tracing_disabled = 1;
118118

119119
cpumask_var_t __read_mostly tracing_buffer_mask;
120120

@@ -3423,7 +3423,7 @@ int __trace_array_vprintk(struct trace_buffer *buffer,
34233423
unsigned int trace_ctx;
34243424
char *tbuffer;
34253425

3426-
if (tracing_disabled)
3426+
if (unlikely(tracing_disabled))
34273427
return 0;
34283428

34293429
/* Don't pollute graph traces with trace_vprintk internals */
@@ -4765,11 +4765,6 @@ int tracing_open_generic(struct inode *inode, struct file *filp)
47654765
return 0;
47664766
}
47674767

4768-
bool tracing_is_disabled(void)
4769-
{
4770-
return (tracing_disabled) ? true: false;
4771-
}
4772-
47734768
/*
47744769
* Open and update trace_array ref count.
47754770
* Must have the current trace_array passed to it.
@@ -7609,7 +7604,7 @@ tracing_mark_write(struct file *filp, const char __user *ubuf,
76097604
unsigned long ip;
76107605
char *buf;
76117606

7612-
if (tracing_disabled)
7607+
if (unlikely(tracing_disabled))
76137608
return -EINVAL;
76147609

76157610
if (!(tr->trace_flags & TRACE_ITER(MARKERS)))
@@ -7689,7 +7684,7 @@ tracing_mark_raw_write(struct file *filp, const char __user *ubuf,
76897684
ssize_t written = -ENODEV;
76907685
char *buf;
76917686

7692-
if (tracing_disabled)
7687+
if (unlikely(tracing_disabled))
76937688
return -EINVAL;
76947689

76957690
if (!(tr->trace_flags & TRACE_ITER(MARKERS)))

kernel/trace/trace.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,8 @@ trace_buffer_iter(struct trace_iterator *iter, int cpu)
657657
return iter->buffer_iter ? iter->buffer_iter[cpu] : NULL;
658658
}
659659

660+
extern int tracing_disabled;
661+
660662
int tracer_init(struct tracer *t, struct trace_array *tr);
661663
int tracing_is_enabled(void);
662664
void tracing_reset_online_cpus(struct array_buffer *buf);
@@ -668,7 +670,6 @@ int tracing_release_generic_tr(struct inode *inode, struct file *file);
668670
int tracing_open_file_tr(struct inode *inode, struct file *filp);
669671
int tracing_release_file_tr(struct inode *inode, struct file *filp);
670672
int tracing_single_release_file_tr(struct inode *inode, struct file *filp);
671-
bool tracing_is_disabled(void);
672673
bool tracer_tracing_is_on(struct trace_array *tr);
673674
void tracer_tracing_on(struct trace_array *tr);
674675
void tracer_tracing_off(struct trace_array *tr);

kernel/trace/trace_events.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2268,7 +2268,7 @@ static int subsystem_open(struct inode *inode, struct file *filp)
22682268
struct event_subsystem *system = NULL;
22692269
int ret;
22702270

2271-
if (tracing_is_disabled())
2271+
if (unlikely(tracing_disabled))
22722272
return -ENODEV;
22732273

22742274
/* Make sure the system still exists */

kernel/trace/trace_kprobe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2083,7 +2083,7 @@ static __init int kprobe_trace_self_tests_init(void)
20832083
struct trace_kprobe *tk;
20842084
struct trace_event_file *file;
20852085

2086-
if (tracing_is_disabled())
2086+
if (unlikely(tracing_disabled))
20872087
return -ENODEV;
20882088

20892089
if (tracing_selftest_disabled)

0 commit comments

Comments
 (0)