Skip to content

Commit e4c1a09

Browse files
committed
tracing: Add tracer_uses_snapshot() helper to remove #ifdefs
Instead of having #ifdef CONFIG_TRACER_MAX_TRACE around every access to the struct tracer's use_max_tr field, add a helper function for that access and if CONFIG_TRACER_MAX_TRACE is not configured it just returns false. 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/20260208183856.599390238@kernel.org Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 694b3f6 commit e4c1a09

2 files changed

Lines changed: 28 additions & 35 deletions

File tree

kernel/trace/trace.c

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,6 @@ EXPORT_SYMBOL_GPL(tracing_on);
810810
static void tracing_snapshot_instance_cond(struct trace_array *tr,
811811
void *cond_data)
812812
{
813-
struct tracer *tracer = tr->current_trace;
814813
unsigned long flags;
815814

816815
if (in_nmi()) {
@@ -827,7 +826,7 @@ static void tracing_snapshot_instance_cond(struct trace_array *tr,
827826
}
828827

829828
/* Note, snapshot can not be used when the tracer uses it */
830-
if (tracer->use_max_tr) {
829+
if (tracer_uses_snapshot(tr->current_trace)) {
831830
trace_array_puts(tr, "*** LATENCY TRACER ACTIVE ***\n");
832831
trace_array_puts(tr, "*** Can not use snapshot (sorry) ***\n");
833832
return;
@@ -1076,7 +1075,7 @@ int tracing_snapshot_cond_enable(struct trace_array *tr, void *cond_data,
10761075

10771076
guard(mutex)(&trace_types_lock);
10781077

1079-
if (tr->current_trace->use_max_tr)
1078+
if (tracer_uses_snapshot(tr->current_trace))
10801079
return -EBUSY;
10811080

10821081
/*
@@ -1787,7 +1786,7 @@ static int run_tracer_selftest(struct tracer *type)
17871786
tr->current_trace_flags = type->flags ? : type->default_flags;
17881787

17891788
#ifdef CONFIG_TRACER_MAX_TRACE
1790-
if (type->use_max_tr) {
1789+
if (tracer_uses_snapshot(type)) {
17911790
/* If we expanded the buffers, make sure the max is expanded too */
17921791
if (tr->ring_buffer_expanded)
17931792
ring_buffer_resize(tr->snapshot_buffer.buffer, trace_buf_size,
@@ -1812,7 +1811,7 @@ static int run_tracer_selftest(struct tracer *type)
18121811
tracing_reset_online_cpus(&tr->array_buffer);
18131812

18141813
#ifdef CONFIG_TRACER_MAX_TRACE
1815-
if (type->use_max_tr) {
1814+
if (tracer_uses_snapshot(type)) {
18161815
tr->allocated_snapshot = false;
18171816

18181817
/* Shrink the max buffer again */
@@ -3240,10 +3239,8 @@ static void *s_start(struct seq_file *m, loff_t *pos)
32403239
}
32413240
mutex_unlock(&trace_types_lock);
32423241

3243-
#ifdef CONFIG_TRACER_MAX_TRACE
3244-
if (iter->snapshot && iter->trace->use_max_tr)
3242+
if (iter->snapshot && tracer_uses_snapshot(iter->trace))
32453243
return ERR_PTR(-EBUSY);
3246-
#endif
32473244

32483245
if (*pos != iter->pos) {
32493246
iter->ent = NULL;
@@ -3282,10 +3279,8 @@ static void s_stop(struct seq_file *m, void *p)
32823279
{
32833280
struct trace_iterator *iter = m->private;
32843281

3285-
#ifdef CONFIG_TRACER_MAX_TRACE
3286-
if (iter->snapshot && iter->trace->use_max_tr)
3282+
if (iter->snapshot && tracer_uses_snapshot(iter->trace))
32873283
return;
3288-
#endif
32893284

32903285
trace_access_unlock(iter->cpu_file);
32913286
trace_event_read_unlock();
@@ -4177,11 +4172,9 @@ static int tracing_open(struct inode *inode, struct file *file)
41774172
static bool
41784173
trace_ok_for_array(struct tracer *t, struct trace_array *tr)
41794174
{
4180-
#ifdef CONFIG_TRACER_SNAPSHOT
41814175
/* arrays with mapped buffer range do not have snapshots */
4182-
if (tr->range_addr_start && t->use_max_tr)
4176+
if (tr->range_addr_start && tracer_uses_snapshot(t))
41834177
return false;
4184-
#endif
41854178
return (tr->flags & TRACE_ARRAY_FL_GLOBAL) || t->allow_instances;
41864179
}
41874180

@@ -5550,9 +5543,7 @@ int tracing_set_tracer(struct trace_array *tr, const char *buf)
55505543
{
55515544
struct tracer *trace = NULL;
55525545
struct tracers *t;
5553-
#ifdef CONFIG_TRACER_MAX_TRACE
55545546
bool had_max_tr;
5555-
#endif
55565547
int ret;
55575548

55585549
guard(mutex)(&trace_types_lock);
@@ -5580,7 +5571,7 @@ int tracing_set_tracer(struct trace_array *tr, const char *buf)
55805571
return 0;
55815572

55825573
#ifdef CONFIG_TRACER_SNAPSHOT
5583-
if (trace->use_max_tr) {
5574+
if (tracer_uses_snapshot(trace)) {
55845575
local_irq_disable();
55855576
arch_spin_lock(&tr->max_lock);
55865577
ret = tr->cond_snapshot ? -EBUSY : 0;
@@ -5612,14 +5603,13 @@ int tracing_set_tracer(struct trace_array *tr, const char *buf)
56125603
if (tr->current_trace->reset)
56135604
tr->current_trace->reset(tr);
56145605

5615-
#ifdef CONFIG_TRACER_MAX_TRACE
5616-
had_max_tr = tr->current_trace->use_max_tr;
5606+
had_max_tr = tracer_uses_snapshot(tr->current_trace);
56175607

56185608
/* Current trace needs to be nop_trace before synchronize_rcu */
56195609
tr->current_trace = &nop_trace;
56205610
tr->current_trace_flags = nop_trace.flags;
56215611

5622-
if (had_max_tr && !trace->use_max_tr) {
5612+
if (had_max_tr && !tracer_uses_snapshot(trace)) {
56235613
/*
56245614
* We need to make sure that the update_max_tr sees that
56255615
* current_trace changed to nop_trace to keep it from
@@ -5632,24 +5622,19 @@ int tracing_set_tracer(struct trace_array *tr, const char *buf)
56325622
tracing_disarm_snapshot(tr);
56335623
}
56345624

5635-
if (!had_max_tr && trace->use_max_tr) {
5625+
if (!had_max_tr && tracer_uses_snapshot(trace)) {
56365626
ret = tracing_arm_snapshot_locked(tr);
56375627
if (ret)
56385628
return ret;
56395629
}
5640-
#else
5641-
tr->current_trace = &nop_trace;
5642-
#endif
56435630

56445631
tr->current_trace_flags = t->flags ? : t->tracer->flags;
56455632

56465633
if (trace->init) {
56475634
ret = tracer_init(trace, tr);
56485635
if (ret) {
5649-
#ifdef CONFIG_TRACER_MAX_TRACE
5650-
if (trace->use_max_tr)
5636+
if (tracer_uses_snapshot(trace))
56515637
tracing_disarm_snapshot(tr);
5652-
#endif
56535638
tr->current_trace_flags = nop_trace.flags;
56545639
return ret;
56555640
}
@@ -7207,7 +7192,7 @@ tracing_snapshot_write(struct file *filp, const char __user *ubuf, size_t cnt,
72077192

72087193
guard(mutex)(&trace_types_lock);
72097194

7210-
if (tr->current_trace->use_max_tr)
7195+
if (tracer_uses_snapshot(tr->current_trace))
72117196
return -EBUSY;
72127197

72137198
local_irq_disable();
@@ -7306,7 +7291,7 @@ static int snapshot_raw_open(struct inode *inode, struct file *filp)
73067291

73077292
info = filp->private_data;
73087293

7309-
if (info->iter.trace->use_max_tr) {
7294+
if (tracer_uses_snapshot(info->iter.trace)) {
73107295
tracing_buffers_release(inode, filp);
73117296
return -EBUSY;
73127297
}
@@ -7862,10 +7847,8 @@ tracing_buffers_read(struct file *filp, char __user *ubuf,
78627847
if (!count)
78637848
return 0;
78647849

7865-
#ifdef CONFIG_TRACER_MAX_TRACE
7866-
if (iter->snapshot && iter->tr->current_trace->use_max_tr)
7850+
if (iter->snapshot && tracer_uses_snapshot(iter->tr->current_trace))
78677851
return -EBUSY;
7868-
#endif
78697852

78707853
page_size = ring_buffer_subbuf_size_get(iter->array_buffer->buffer);
78717854

@@ -8049,10 +8032,8 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos,
80498032
int entries, i;
80508033
ssize_t ret = 0;
80518034

8052-
#ifdef CONFIG_TRACER_MAX_TRACE
8053-
if (iter->snapshot && iter->tr->current_trace->use_max_tr)
8035+
if (iter->snapshot && tracer_uses_snapshot(iter->tr->current_trace))
80548036
return -EBUSY;
8055-
#endif
80568037

80578038
page_size = ring_buffer_subbuf_size_get(iter->array_buffer->buffer);
80588039
if (*ppos & (page_size - 1))

kernel/trace/trace.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,18 @@ static inline void __trace_stack(struct trace_array *tr, unsigned int trace_ctx,
817817
}
818818
#endif /* CONFIG_STACKTRACE */
819819

820+
#ifdef CONFIG_TRACER_MAX_TRACE
821+
static inline bool tracer_uses_snapshot(struct tracer *tracer)
822+
{
823+
return tracer->use_max_tr;
824+
}
825+
#else
826+
static inline bool tracer_uses_snapshot(struct tracer *tracer)
827+
{
828+
return false;
829+
}
830+
#endif
831+
820832
void trace_last_func_repeats(struct trace_array *tr,
821833
struct trace_func_repeats *last_info,
822834
unsigned int trace_ctx);

0 commit comments

Comments
 (0)