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: 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>

+28 -35
+16 -35
kernel/trace/trace.c
··· 810 810 static void tracing_snapshot_instance_cond(struct trace_array *tr, 811 811 void *cond_data) 812 812 { 813 - struct tracer *tracer = tr->current_trace; 814 813 unsigned long flags; 815 814 816 815 if (in_nmi()) { ··· 826 827 } 827 828 828 829 /* Note, snapshot can not be used when the tracer uses it */ 829 - if (tracer->use_max_tr) { 830 + if (tracer_uses_snapshot(tr->current_trace)) { 830 831 trace_array_puts(tr, "*** LATENCY TRACER ACTIVE ***\n"); 831 832 trace_array_puts(tr, "*** Can not use snapshot (sorry) ***\n"); 832 833 return; ··· 1075 1076 1076 1077 guard(mutex)(&trace_types_lock); 1077 1078 1078 - if (tr->current_trace->use_max_tr) 1079 + if (tracer_uses_snapshot(tr->current_trace)) 1079 1080 return -EBUSY; 1080 1081 1081 1082 /* ··· 1786 1787 tr->current_trace_flags = type->flags ? : type->default_flags; 1787 1788 1788 1789 #ifdef CONFIG_TRACER_MAX_TRACE 1789 - if (type->use_max_tr) { 1790 + if (tracer_uses_snapshot(type)) { 1790 1791 /* If we expanded the buffers, make sure the max is expanded too */ 1791 1792 if (tr->ring_buffer_expanded) 1792 1793 ring_buffer_resize(tr->snapshot_buffer.buffer, trace_buf_size, ··· 1811 1812 tracing_reset_online_cpus(&tr->array_buffer); 1812 1813 1813 1814 #ifdef CONFIG_TRACER_MAX_TRACE 1814 - if (type->use_max_tr) { 1815 + if (tracer_uses_snapshot(type)) { 1815 1816 tr->allocated_snapshot = false; 1816 1817 1817 1818 /* Shrink the max buffer again */ ··· 3239 3240 } 3240 3241 mutex_unlock(&trace_types_lock); 3241 3242 3242 - #ifdef CONFIG_TRACER_MAX_TRACE 3243 - if (iter->snapshot && iter->trace->use_max_tr) 3243 + if (iter->snapshot && tracer_uses_snapshot(iter->trace)) 3244 3244 return ERR_PTR(-EBUSY); 3245 - #endif 3246 3245 3247 3246 if (*pos != iter->pos) { 3248 3247 iter->ent = NULL; ··· 3279 3282 { 3280 3283 struct trace_iterator *iter = m->private; 3281 3284 3282 - #ifdef CONFIG_TRACER_MAX_TRACE 3283 - if (iter->snapshot && iter->trace->use_max_tr) 3285 + if (iter->snapshot && tracer_uses_snapshot(iter->trace)) 3284 3286 return; 3285 - #endif 3286 3287 3287 3288 trace_access_unlock(iter->cpu_file); 3288 3289 trace_event_read_unlock(); ··· 4172 4177 static bool 4173 4178 trace_ok_for_array(struct tracer *t, struct trace_array *tr) 4174 4179 { 4175 - #ifdef CONFIG_TRACER_SNAPSHOT 4176 4180 /* arrays with mapped buffer range do not have snapshots */ 4177 - if (tr->range_addr_start && t->use_max_tr) 4181 + if (tr->range_addr_start && tracer_uses_snapshot(t)) 4178 4182 return false; 4179 - #endif 4180 4183 return (tr->flags & TRACE_ARRAY_FL_GLOBAL) || t->allow_instances; 4181 4184 } 4182 4185 ··· 5543 5550 { 5544 5551 struct tracer *trace = NULL; 5545 5552 struct tracers *t; 5546 - #ifdef CONFIG_TRACER_MAX_TRACE 5547 5553 bool had_max_tr; 5548 - #endif 5549 5554 int ret; 5550 5555 5551 5556 guard(mutex)(&trace_types_lock); ··· 5571 5580 return 0; 5572 5581 5573 5582 #ifdef CONFIG_TRACER_SNAPSHOT 5574 - if (trace->use_max_tr) { 5583 + if (tracer_uses_snapshot(trace)) { 5575 5584 local_irq_disable(); 5576 5585 arch_spin_lock(&tr->max_lock); 5577 5586 ret = tr->cond_snapshot ? -EBUSY : 0; ··· 5603 5612 if (tr->current_trace->reset) 5604 5613 tr->current_trace->reset(tr); 5605 5614 5606 - #ifdef CONFIG_TRACER_MAX_TRACE 5607 - had_max_tr = tr->current_trace->use_max_tr; 5615 + had_max_tr = tracer_uses_snapshot(tr->current_trace); 5608 5616 5609 5617 /* Current trace needs to be nop_trace before synchronize_rcu */ 5610 5618 tr->current_trace = &nop_trace; 5611 5619 tr->current_trace_flags = nop_trace.flags; 5612 5620 5613 - if (had_max_tr && !trace->use_max_tr) { 5621 + if (had_max_tr && !tracer_uses_snapshot(trace)) { 5614 5622 /* 5615 5623 * We need to make sure that the update_max_tr sees that 5616 5624 * current_trace changed to nop_trace to keep it from ··· 5622 5632 tracing_disarm_snapshot(tr); 5623 5633 } 5624 5634 5625 - if (!had_max_tr && trace->use_max_tr) { 5635 + if (!had_max_tr && tracer_uses_snapshot(trace)) { 5626 5636 ret = tracing_arm_snapshot_locked(tr); 5627 5637 if (ret) 5628 5638 return ret; 5629 5639 } 5630 - #else 5631 - tr->current_trace = &nop_trace; 5632 - #endif 5633 5640 5634 5641 tr->current_trace_flags = t->flags ? : t->tracer->flags; 5635 5642 5636 5643 if (trace->init) { 5637 5644 ret = tracer_init(trace, tr); 5638 5645 if (ret) { 5639 - #ifdef CONFIG_TRACER_MAX_TRACE 5640 - if (trace->use_max_tr) 5646 + if (tracer_uses_snapshot(trace)) 5641 5647 tracing_disarm_snapshot(tr); 5642 - #endif 5643 5648 tr->current_trace_flags = nop_trace.flags; 5644 5649 return ret; 5645 5650 } ··· 7192 7207 7193 7208 guard(mutex)(&trace_types_lock); 7194 7209 7195 - if (tr->current_trace->use_max_tr) 7210 + if (tracer_uses_snapshot(tr->current_trace)) 7196 7211 return -EBUSY; 7197 7212 7198 7213 local_irq_disable(); ··· 7291 7306 7292 7307 info = filp->private_data; 7293 7308 7294 - if (info->iter.trace->use_max_tr) { 7309 + if (tracer_uses_snapshot(info->iter.trace)) { 7295 7310 tracing_buffers_release(inode, filp); 7296 7311 return -EBUSY; 7297 7312 } ··· 7847 7862 if (!count) 7848 7863 return 0; 7849 7864 7850 - #ifdef CONFIG_TRACER_MAX_TRACE 7851 - if (iter->snapshot && iter->tr->current_trace->use_max_tr) 7865 + if (iter->snapshot && tracer_uses_snapshot(iter->tr->current_trace)) 7852 7866 return -EBUSY; 7853 - #endif 7854 7867 7855 7868 page_size = ring_buffer_subbuf_size_get(iter->array_buffer->buffer); 7856 7869 ··· 8032 8049 int entries, i; 8033 8050 ssize_t ret = 0; 8034 8051 8035 - #ifdef CONFIG_TRACER_MAX_TRACE 8036 - if (iter->snapshot && iter->tr->current_trace->use_max_tr) 8052 + if (iter->snapshot && tracer_uses_snapshot(iter->tr->current_trace)) 8037 8053 return -EBUSY; 8038 - #endif 8039 8054 8040 8055 page_size = ring_buffer_subbuf_size_get(iter->array_buffer->buffer); 8041 8056 if (*ppos & (page_size - 1))
+12
kernel/trace/trace.h
··· 817 817 } 818 818 #endif /* CONFIG_STACKTRACE */ 819 819 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 + 820 832 void trace_last_func_repeats(struct trace_array *tr, 821 833 struct trace_func_repeats *last_info, 822 834 unsigned int trace_ctx);