tracing: Clean up the snapshot and max tracer code
Subsystems (2)
v2 cover tracing: Clean up the snapshot and max tracer code
When tracing first was added it had latency tracers that used a separate snapshot buffer to swap the current buffer being written to with a static buffer that is only read. This later became a feature that user space could use by attaching to the latency tracer snapshot buffer. But the buffer was named max_buffer which is not what it is used for in all cases.
Rename the max_buffer name to snapshot_buffer.
The "use_max_tr" field of the tracer structure is only defined when CONFIG_TRACER_MAX_TRACE is defined. To get rid of some of the #ifdefs in the code around accesses of that field, use a helper function tracer_uses_snapshot() that access the field when the config is defined, or returns false if not.
Finally, since the latency tracers use the snapshot buffer and snapshot buffers do not need latency tracers, have the TRACER_MAX_TRACE config select TRACE_SNAPSHOT config and not the other way around. Also clean up the code to properly protect the max tracer references and the snapshot references.
Changes since v1: https://lore.kernel.org/linux-trace-kernel/[email protected]/
- This separates the updates to snapshot buffer and max tracers from the last series. It was a rewrite.
Steven Rostedt (3):
tracing: Rename trace_array field max_buffer to snapshot_buffer
tracing: Add tracer_uses_snapshot() helper to remove #ifdefs
tracing: Better separate SNAPSHOT and MAX_TRACE options
----
kernel/trace/Kconfig | 8 +- kernel/trace/trace.c | 190 +++++++++++++++++++----------------------- kernel/trace/trace.h | 44 ++++++---- kernel/trace/trace_selftest.c | 10 +-- 4 files changed, 127 insertions(+), 125 deletions(-)
PATCH v2 1/3 tracing: Rename trace_array field max_buffer to snapshot_buffer
From: Steven Rostedt <[email protected]>
When tracing was first added, there were latency tracers that would take a snapshot of the current trace when a new max latency was hit. This snapshot buffer was called "max_buffer". Since then, a snapshot feature was added that allowed user space or event triggers to trigger a snapshot of the current buffer using the same max_buffer of the trace_array.
As this snapshot buffer now has a more generic use case, calling it "max_buffer" is confusing. Rename it to snapshot_buffer.
--- kernel/trace/trace.c | 72 +++++++++++++++++------------------ kernel/trace/trace.h | 13 ++++--- kernel/trace/trace_selftest.c | 10 ++--- 3 files changed, 48 insertions(+), 47 deletions(-)
kernel/trace/trace.c +36 -36
@@ -934,12 +934,12 @@ int tracing_alloc_snapshot_instance(struct trace_array *tr)/* Make the snapshot buffer have the same order as main buffer */ order =ring_buffer_subbuf_order_get (tr->array_buffer.buffer); - ret =ring_buffer_subbuf_order_set (tr->max_buffer.buffer, order); + ret =ring_buffer_subbuf_order_set (tr->snapshot_buffer.buffer, order);if (ret <0 )return ret;/* allocate spare buffer */ - ret =resize_buffer_duplicate_size (&tr->max_buffer, + ret =resize_buffer_duplicate_size (&tr->snapshot_buffer, &tr->array_buffer,RING_BUFFER_ALL_CPUS );if (ret <0 )return ret;
@@ -957,10 +957,10 @@ static void free_snapshot(struct trace_array *tr)* The max_tr ring buffer has some state (e.g. ring->clock) and * we want preserve it. */ -ring_buffer_subbuf_order_set (tr->max_buffer.buffer,0 ); -ring_buffer_resize (tr->max_buffer.buffer,1 ,RING_BUFFER_ALL_CPUS ); -set_buffer_entries (&tr->max_buffer,1 ); -tracing_reset_online_cpus (&tr->max_buffer); +ring_buffer_subbuf_order_set (tr->snapshot_buffer.buffer,0 ); +ring_buffer_resize (tr->snapshot_buffer.buffer,1 ,RING_BUFFER_ALL_CPUS ); +set_buffer_entries (&tr->snapshot_buffer,1 ); +tracing_reset_online_cpus (&tr->snapshot_buffer); tr->allocated_snapshot = false; }
@@ -1556,7 +1556,7 @@ static void __update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) { struct array_buffer *trace_buf = &tr->array_buffer; -struct array_buffer *max_buf = &tr->max_buffer; +struct array_buffer *max_buf = &tr->snapshot_buffer;struct trace_array_cpu *data =per_cpu_ptr (trace_buf->data, cpu);struct trace_array_cpu *max_data =per_cpu_ptr (max_buf->data, cpu);
@@ -1616,9 +1616,9 @@ update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu,/* Inherit the recordable setting from array_buffer */ if (ring_buffer_record_is_set_on (tr->array_buffer.buffer)) -ring_buffer_record_on (tr->max_buffer.buffer); +ring_buffer_record_on (tr->snapshot_buffer.buffer);else -ring_buffer_record_off (tr->max_buffer.buffer); +ring_buffer_record_off (tr->snapshot_buffer.buffer);#ifdef CONFIG_TRACER_SNAPSHOT if (tr->cond_snapshot && !tr->cond_snapshot->update (tr, cond_data)) {
@@ -1626,7 +1626,7 @@ update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu, return; }#endif -swap (tr->array_buffer.buffer, tr->max_buffer.buffer); +swap (tr->array_buffer.buffer, tr->snapshot_buffer.buffer);__update_max_tr (tr, tsk, cpu);
@@ -1661,7 +1661,7 @@ update_max_tr_single(struct trace_array *tr, struct task_struct *tsk, int cpu)arch_spin_lock (&tr->max_lock); - ret =ring_buffer_swap_cpu (tr->max_buffer.buffer, tr->array_buffer.buffer, cpu); + ret =ring_buffer_swap_cpu (tr->snapshot_buffer.buffer, tr->array_buffer.buffer, cpu);if (ret == -EBUSY ) {/*
@@ -1671,7 +1671,7 @@ update_max_tr_single(struct trace_array *tr, struct task_struct *tsk, int cpu)* and flag that it failed. * Another reason is resize is in progress. */ -trace_array_printk_buf (tr->max_buffer.buffer, _THIS_IP_, +trace_array_printk_buf (tr->snapshot_buffer.buffer, _THIS_IP_,"Failed to swap buffers due to commit or resize in progress\n" ); }
@@ -1722,7 +1722,7 @@ static int wait_on_pipe(struct trace_iterator *iter, int full)* to happen, this would now be the main buffer. */ if (iter->snapshot) - iter->array_buffer = &iter->tr->max_buffer; + iter->array_buffer = &iter->tr->snapshot_buffer;#endif return ret; }
@@ -1790,7 +1790,7 @@ static int run_tracer_selftest(struct tracer *type)if (type->use_max_tr) {/* If we expanded the buffers, make sure the max is expanded too */ if (tr->ring_buffer_expanded) -ring_buffer_resize (tr->max_buffer.buffer, trace_buf_size, +ring_buffer_resize (tr->snapshot_buffer.buffer, trace_buf_size,RING_BUFFER_ALL_CPUS ); tr->allocated_snapshot = true; }
@@ -1817,7 +1817,7 @@ static int run_tracer_selftest(struct tracer *type)/* Shrink the max buffer again */ if (tr->ring_buffer_expanded) -ring_buffer_resize (tr->max_buffer.buffer,1 , +ring_buffer_resize (tr->snapshot_buffer.buffer,1 , RING_BUFFER_ALL_CPUS); }#endif
@@ -2060,7 +2060,7 @@ void tracing_reset_all_online_cpus_unlocked(void) tr->clear_trace = false;tracing_reset_online_cpus (&tr->array_buffer);#ifdef CONFIG_TRACER_MAX_TRACE -tracing_reset_online_cpus (&tr->max_buffer); +tracing_reset_online_cpus (&tr->snapshot_buffer);#endif } }
@@ -2100,7 +2100,7 @@ static void tracing_start_tr(struct trace_array *tr)ring_buffer_record_enable (buffer);#ifdef CONFIG_TRACER_MAX_TRACE - buffer = tr->max_buffer.buffer; + buffer = tr->snapshot_buffer.buffer;if (buffer)ring_buffer_record_enable (buffer);#endif
@@ -2136,7 +2136,7 @@ static void tracing_stop_tr(struct trace_array *tr)ring_buffer_record_disable (buffer);#ifdef CONFIG_TRACER_MAX_TRACE - buffer = tr->max_buffer.buffer; + buffer = tr->snapshot_buffer.buffer;if (buffer)ring_buffer_record_disable (buffer);#endif
@@ -3943,7 +3943,7 @@ __tracing_open(struct inode *inode, struct file *file, bool snapshot)#ifdef CONFIG_TRACER_MAX_TRACE /* Currently only the top directory has a snapshot */ if (tr->current_trace->print_max || snapshot) - iter->array_buffer = &tr->max_buffer; + iter->array_buffer = &tr->snapshot_buffer; else#endif iter->array_buffer = &tr->array_buffer;
@@ -4146,7 +4146,7 @@ static int tracing_open(struct inode *inode, struct file *file)#ifdef CONFIG_TRACER_MAX_TRACE if (tr->current_trace->print_max) - trace_buf = &tr->max_buffer; + trace_buf = &tr->snapshot_buffer;#endif if (cpu ==RING_BUFFER_ALL_CPUS )
@@ -4359,14 +4359,14 @@ int tracing_set_cpumask(struct trace_array *tr, !cpumask_test_cpu(cpu, tracing_cpumask_new)) {ring_buffer_record_disable_cpu (tr->array_buffer.buffer, cpu);#ifdef CONFIG_TRACER_MAX_TRACE -ring_buffer_record_disable_cpu (tr->max_buffer.buffer, cpu); +ring_buffer_record_disable_cpu (tr->snapshot_buffer.buffer, cpu);#endif }if (!cpumask_test_cpu (cpu, tr->tracing_cpumask) &&cpumask_test_cpu (cpu, tracing_cpumask_new)) {ring_buffer_record_enable_cpu (tr->array_buffer.buffer, cpu);#ifdef CONFIG_TRACER_MAX_TRACE -ring_buffer_record_enable_cpu (tr->max_buffer.buffer, cpu); +ring_buffer_record_enable_cpu (tr->snapshot_buffer.buffer, cpu);#endif } }
@@ -4576,7 +4576,7 @@ int set_tracer_flag(struct trace_array *tr, u64 mask, int enabled)case TRACE_ITER (OVERWRITE ):ring_buffer_change_overwrite (tr->array_buffer.buffer, enabled);#ifdef CONFIG_TRACER_MAX_TRACE -ring_buffer_change_overwrite (tr->max_buffer.buffer, enabled); +ring_buffer_change_overwrite (tr->snapshot_buffer.buffer, enabled);#endif break ;
@@ -5294,7 +5294,7 @@ static int __tracing_resize_ring_buffer(struct trace_array *tr,if (!tr->allocated_snapshot) goto out; - ret =ring_buffer_resize (tr->max_buffer.buffer, size, cpu); + ret =ring_buffer_resize (tr->snapshot_buffer.buffer, size, cpu);if (ret <0 ) {int r =resize_buffer_duplicate_size (&tr->array_buffer, &tr->array_buffer, cpu);
@@ -5319,7 +5319,7 @@ static int __tracing_resize_ring_buffer(struct trace_array *tr, goto out_start; } -update_buffer_entries (&tr->max_buffer, cpu); +update_buffer_entries (&tr->snapshot_buffer, cpu); out:#endif /* CONFIG_TRACER_MAX_TRACE */
@@ -7036,9 +7036,9 @@ int tracing_set_clock(struct trace_array *tr, const char *clockstr)tracing_reset_online_cpus (&tr->array_buffer);#ifdef CONFIG_TRACER_MAX_TRACE -if (tr->max_buffer.buffer) -ring_buffer_set_clock (tr->max_buffer.buffer, trace_clocks[i].func); -tracing_reset_online_cpus (&tr->max_buffer); +if (tr->snapshot_buffer.buffer) +ring_buffer_set_clock (tr->snapshot_buffer.buffer, trace_clocks[i].func); +tracing_reset_online_cpus (&tr->snapshot_buffer);#endif if (tr->scratch && !(tr->flags &TRACE_ARRAY_FL_LAST_BOOT )) {
@@ -7170,7 +7170,7 @@ static int tracing_snapshot_open(struct inode *inode, struct file *file) ret =0 ; iter->tr = tr; - iter->array_buffer = &tr->max_buffer; + iter->array_buffer = &tr->snapshot_buffer; iter->cpu_file =tracing_get_cpu (inode); m->private = iter; file->private_data = m;
@@ -7233,7 +7233,7 @@ tracing_snapshot_write(struct file *filp, const char __user *ubuf, size_t cnt,return -EINVAL ;#endif if (tr->allocated_snapshot) - ret =resize_buffer_duplicate_size (&tr->max_buffer, + ret =resize_buffer_duplicate_size (&tr->snapshot_buffer, &tr->array_buffer, iter->cpu_file); ret =tracing_arm_snapshot_locked (tr);
@@ -7254,9 +7254,9 @@ tracing_snapshot_write(struct file *filp, const char __user *ubuf, size_t cnt,default :if (tr->allocated_snapshot) {if (iter->cpu_file ==RING_BUFFER_ALL_CPUS ) -tracing_reset_online_cpus (&tr->max_buffer); +tracing_reset_online_cpus (&tr->snapshot_buffer);else -tracing_reset_cpu (&tr->max_buffer, iter->cpu_file); +tracing_reset_cpu (&tr->snapshot_buffer, iter->cpu_file); }break ; }
@@ -7312,7 +7312,7 @@ static int snapshot_raw_open(struct inode *inode, struct file *filp) } info->iter.snapshot = true; - info->iter.array_buffer = &info->iter.tr->max_buffer; + info->iter.array_buffer = &info->iter.tr->snapshot_buffer;return ret; }
@@ -9195,7 +9195,7 @@ buffer_subbuf_size_write(struct file *filp, const char __user *ubuf,if (!tr->allocated_snapshot) goto out_max; - ret =ring_buffer_subbuf_order_set (tr->max_buffer.buffer, order); + ret =ring_buffer_subbuf_order_set (tr->snapshot_buffer.buffer, order);if (ret) {/* Put back the old order */ cnt =ring_buffer_subbuf_order_set (tr->array_buffer.buffer, old_order);
@@ -9416,7 +9416,7 @@ static int allocate_trace_buffers(struct trace_array *tr, int size)if (tr->range_addr_start)return 0 ; - ret =allocate_trace_buffer (tr, &tr->max_buffer, + ret =allocate_trace_buffer (tr, &tr->snapshot_buffer, allocate_snapshot ? size :1 );if (MEM_FAIL (ret,"Failed to allocate trace buffer\n" )) {free_trace_buffer (&tr->array_buffer);
@@ -9439,7 +9439,7 @@ static void free_trace_buffers(struct trace_array *tr)kfree (tr->module_delta);#ifdef CONFIG_TRACER_MAX_TRACE -free_trace_buffer (&tr->max_buffer); +free_trace_buffer (&tr->snapshot_buffer);#endif }
kernel/trace/trace.h +7 -6
@@ -331,17 +331,18 @@ struct trace_array {struct array_buffer array_buffer;#ifdef CONFIG_TRACER_MAX_TRACE /* -* The max_buffer is used to snapshot the trace when a maximum +* The snapshot_buffer is used to snapshot the trace when a maximum * latency is reached, or when the user initiates a snapshot. * Some tracers will use this to store a maximum trace while * it continues examining live traces. * -* The buffers for the max_buffer are set up the same as the array_buffer -* When a snapshot is taken, the buffer of the max_buffer is swapped -* with the buffer of the array_buffer and the buffers are reset for -* the array_buffer so the tracing can continue. +* The buffers for the snapshot_buffer are set up the same as the +* array_buffer. When a snapshot is taken, the buffer of the +* snapshot_buffer is swapped with the buffer of the array_buffer +* and the buffers are reset for the array_buffer so the tracing can +* continue. */ -struct array_buffer max_buffer; +struct array_buffer snapshot_buffer;bool allocated_snapshot;spinlock_t snapshot_trigger_lock;unsigned int snapshot;
kernel/trace/trace_selftest.c +5 -5
@@ -1225,7 +1225,7 @@ trace_selftest_startup_irqsoff(struct tracer *trace, struct trace_array *tr)/* check both trace buffers */ ret =trace_test_buffer (&tr->array_buffer,NULL );if (!ret) - ret =trace_test_buffer (&tr->max_buffer, &count); + ret =trace_test_buffer (&tr->snapshot_buffer, &count); trace->reset (tr);tracing_start ();
@@ -1287,7 +1287,7 @@ trace_selftest_startup_preemptoff(struct tracer *trace, struct trace_array *tr)/* check both trace buffers */ ret =trace_test_buffer (&tr->array_buffer,NULL );if (!ret) - ret =trace_test_buffer (&tr->max_buffer, &count); + ret =trace_test_buffer (&tr->snapshot_buffer, &count); trace->reset (tr);tracing_start ();
@@ -1355,7 +1355,7 @@ trace_selftest_startup_preemptirqsoff(struct tracer *trace, struct trace_array *if (ret) goto out; - ret =trace_test_buffer (&tr->max_buffer, &count); + ret =trace_test_buffer (&tr->snapshot_buffer, &count);if (ret) goto out;
@@ -1385,7 +1385,7 @@ trace_selftest_startup_preemptirqsoff(struct tracer *trace, struct trace_array *if (ret) goto out; - ret =trace_test_buffer (&tr->max_buffer, &count); + ret =trace_test_buffer (&tr->snapshot_buffer, &count);if (!ret && !count) {printk (KERN_CONT ".. no entries found .." );
@@ -1513,7 +1513,7 @@ trace_selftest_startup_wakeup(struct tracer *trace, struct trace_array *tr)/* check both trace buffers */ ret =trace_test_buffer (&tr->array_buffer,NULL );if (!ret) - ret =trace_test_buffer (&tr->max_buffer, &count); + ret =trace_test_buffer (&tr->snapshot_buffer, &count); trace->reset (tr);
Signature · 1 line
2.51.0
PATCH v2 2/3 tracing: Add tracer_uses_snapshot() helper to remove #ifdefs
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
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.
--- kernel/trace/trace.c | 52 +++++++++++++++----------------------------- kernel/trace/trace.h | 12 ++++++++++ 2 files changed, 29 insertions(+), 35 deletions(-)
kernel/trace/trace.c +17 -35
@@ -810,7 +810,6 @@ EXPORT_SYMBOL_GPL(tracing_on);static void tracing_snapshot_instance_cond (struct trace_array *tr,void *cond_data) { -struct tracer *tracer = tr->current_trace;unsigned long flags;if (in_nmi ()) {
@@ -827,7 +826,7 @@ static void tracing_snapshot_instance_cond(struct trace_array *tr, }/* Note, snapshot can not be used when the tracer uses it */ -if (tracer->use_max_tr) { +if (tracer_uses_snapshot (tr->current_trace)) {trace_array_puts (tr,"*** LATENCY TRACER ACTIVE ***\n" );trace_array_puts (tr,"*** Can not use snapshot (sorry) ***\n" );return ;
@@ -1076,7 +1075,7 @@ int tracing_snapshot_cond_enable(struct trace_array *tr, void *cond_data,guard (mutex)(&trace_types_lock); -if (tr->current_trace->use_max_tr) +if (tracer_uses_snapshot (tr->current_trace))return -EBUSY ;/*
@@ -1787,7 +1786,7 @@ static int run_tracer_selftest(struct tracer *type) tr->current_trace_flags = type->flags ? : type->default_flags;#ifdef CONFIG_TRACER_MAX_TRACE -if (type->use_max_tr) { +if (tracer_uses_snapshot (type)) {/* If we expanded the buffers, make sure the max is expanded too */ if (tr->ring_buffer_expanded) ring_buffer_resize(tr->snapshot_buffer.buffer, trace_buf_size,
@@ -1812,7 +1811,7 @@ static int run_tracer_selftest(struct tracer *type)tracing_reset_online_cpus (&tr->array_buffer);#ifdef CONFIG_TRACER_MAX_TRACE -if (type->use_max_tr) { +if (tracer_uses_snapshot (type)) { tr->allocated_snapshot = false;/* Shrink the max buffer again */
@@ -3240,10 +3239,8 @@ static void *s_start(struct seq_file *m, loff_t *pos) }mutex_unlock (&trace_types_lock); -#ifdef CONFIG_TRACER_MAX_TRACE -if (iter->snapshot && iter->trace->use_max_tr) +if (iter->snapshot &&tracer_uses_snapshot (iter->trace))return ERR_PTR (-EBUSY ); -#endif if (*pos != iter->pos) { iter->ent =NULL ;
@@ -3282,10 +3279,8 @@ static void s_stop(struct seq_file *m, void *p) {struct trace_iterator *iter = m->private; -#ifdef CONFIG_TRACER_MAX_TRACE -if (iter->snapshot && iter->trace->use_max_tr) +if (iter->snapshot &&tracer_uses_snapshot (iter->trace))return ; -#endif trace_access_unlock (iter->cpu_file);trace_event_read_unlock ();
@@ -4177,11 +4172,9 @@ static int tracing_open(struct inode *inode, struct file *file)static bool trace_ok_for_array (struct tracer *t,struct trace_array *tr) { -#ifdef CONFIG_TRACER_SNAPSHOT /* arrays with mapped buffer range do not have snapshots */ -if (tr->range_addr_start && t->use_max_tr) +if (tr->range_addr_start &&tracer_uses_snapshot (t))return false; -#endif return (tr->flags &TRACE_ARRAY_FL_GLOBAL ) || t->allow_instances; }
@@ -5579,8 +5572,7 @@ int tracing_set_tracer(struct trace_array *tr, const char *buf)if (trace == tr->current_trace)return 0 ; -#ifdef CONFIG_TRACER_SNAPSHOT -if (trace->use_max_tr) { +if (tracer_uses_snapshot (trace)) {local_irq_disable ();arch_spin_lock (&tr->max_lock); ret = tr->cond_snapshot ? -EBUSY :0 ;
@@ -5589,7 +5581,7 @@ int tracing_set_tracer(struct trace_array *tr, const char *buf)if (ret)return ret; } -#endif +/* Some tracers won't work on kernel command line */ if (system_state <SYSTEM_RUNNING && trace->noboot) { pr_warn("Tracer '%s' is not allowed on command line, ignored\n",
@@ -5612,14 +5604,13 @@ int tracing_set_tracer(struct trace_array *tr, const char *buf)if (tr->current_trace->reset) tr->current_trace->reset (tr); -#ifdef CONFIG_TRACER_MAX_TRACE - had_max_tr = tr->current_trace->use_max_tr; + had_max_tr =tracer_uses_snapshot (tr->current_trace);/* Current trace needs to be nop_trace before synchronize_rcu */ tr->current_trace = &nop_trace; tr->current_trace_flags = nop_trace.flags; -if (had_max_tr && !trace->use_max_tr) { +if (had_max_tr && !tracer_uses_snapshot (trace)) {/* * We need to make sure that the update_max_tr sees that * current_trace changed to nop_trace to keep it from
@@ -5632,24 +5623,19 @@ int tracing_set_tracer(struct trace_array *tr, const char *buf)tracing_disarm_snapshot (tr); } -if (!had_max_tr && trace->use_max_tr) { +if (!had_max_tr &&tracer_uses_snapshot (trace)) { ret =tracing_arm_snapshot_locked (tr);if (ret)return ret; } -#else - tr->current_trace = &nop_trace; -#endif tr->current_trace_flags = t->flags ? : t->tracer->flags;if (trace->init) { ret =tracer_init (trace, tr);if (ret) { -#ifdef CONFIG_TRACER_MAX_TRACE -if (trace->use_max_tr) +if (tracer_uses_snapshot (trace))tracing_disarm_snapshot (tr); -#endif tr->current_trace_flags = nop_trace.flags;return ret; }
@@ -7207,7 +7193,7 @@ tracing_snapshot_write(struct file *filp, const char __user *ubuf, size_t cnt,guard (mutex)(&trace_types_lock); -if (tr->current_trace->use_max_tr) +if (tracer_uses_snapshot (tr->current_trace))return -EBUSY ;local_irq_disable ();
@@ -7306,7 +7292,7 @@ static int snapshot_raw_open(struct inode *inode, struct file *filp) info = filp->private_data; -if (info->iter.trace->use_max_tr) { +if (tracer_uses_snapshot (info->iter.trace)) {tracing_buffers_release (inode, filp);return -EBUSY ; }
@@ -7862,10 +7848,8 @@ tracing_buffers_read(struct file *filp, char __user *ubuf,if (!count)return 0 ; -#ifdef CONFIG_TRACER_MAX_TRACE -if (iter->snapshot && iter->tr->current_trace->use_max_tr) +if (iter->snapshot &&tracer_uses_snapshot (iter->tr->current_trace))return -EBUSY ; -#endif page_size =ring_buffer_subbuf_size_get (iter->array_buffer->buffer);
@@ -8049,10 +8033,8 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos,int entries, i;ssize_t ret =0 ; -#ifdef CONFIG_TRACER_MAX_TRACE -if (iter->snapshot && iter->tr->current_trace->use_max_tr) +if (iter->snapshot &&tracer_uses_snapshot (iter->tr->current_trace))return -EBUSY ; -#endif page_size =ring_buffer_subbuf_size_get (iter->array_buffer->buffer);if (*ppos & (page_size -1 ))
kernel/trace/trace.h +12 -0
@@ -817,6 +817,18 @@ static inline void __trace_stack(struct trace_array *tr, unsigned int trace_ctx, }#endif /* CONFIG_STACKTRACE */ +#ifdef CONFIG_TRACER_MAX_TRACE +static inline bool tracer_uses_snapshot (struct tracer *tracer) +{ +return tracer->use_max_tr; +} +#else +static inline bool tracer_uses_snapshot (struct tracer *tracer) +{ +return false; +} +#endif +void trace_last_func_repeats (struct trace_array *tr,struct trace_func_repeats *last_info,unsigned int trace_ctx);
Signature · 1 line
2.51.0
kernel test robot
build botRe: [PATCH v2 2/3] tracing: Add tracer_uses_snapshot() helper to remove #ifdefs
kernel test robot noticed the following build errors:
Hi Steven,
kernel test robot noticed the following build errors:
[auto build test ERROR on trace/for-next]
[also build test ERROR on linus/master v6.19-rc8 next-20260205] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Steven-Rostedt/tracing-Rename-trace_array-field-max_buffer-to-snapshot_buffer/20260208-120355 base: https://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace for-next patch link: https://lore.kernel.org/r/20260208040221.900653834%40kernel.org patch subject: [PATCH v2 2/3] tracing: Add tracer_uses_snapshot() helper to remove #ifdefs config: sh-defconfig (https://download.01.org/0day-ci/archive/20260208/[email protected]/config) compiler: sh4-linux-gcc (GCC) 15.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260208/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
kernel/trace/trace.c: In function 'tracing_set_tracer':
>> kernel/trace/trace.c:6337:25: error: 'struct trace_array' has no member named 'cond_snapshot'
6337 | ret = tr->cond_snapshot ? -EBUSY : 0;
| ^~
kernel/trace/trace.c:6366:9: error: 'had_max_tr' undeclared (first use in this function)
6366 | had_max_tr = tracer_uses_snapshot(tr->current_trace);
| ^~~~~~~~~~ kernel/trace/trace.c:6366:9: note: each undeclared identifier is reported only once for each function it appears in
vim +6337 kernel/trace/trace.c
ef9188bcc6ca1d Mark-PK Tsai 2022-04-26 6300
9c5b9d3d65e485 Masami Hiramatsu 2020-01-11 6301 int tracing_set_tracer(struct trace_array *tr, const char *buf)
09d23a1d8a82e8 Steven Rostedt (Red Hat 2015-02-03 6302) {
428add559b6923 Steven Rostedt 2025-11-11 6303 struct tracer *trace = NULL;
428add559b6923 Steven Rostedt 2025-11-11 6304 struct tracers *t;
12883efb670c28 Steven Rostedt (Red Hat 2013-03-05 6305) #ifdef CONFIG_TRACER_MAX_TRACE
34600f0e9c33c9 Steven Rostedt 2013-01-22 6306 bool had_max_tr;
12883efb670c28 Steven Rostedt (Red Hat 2013-03-05 6307) #endif
d33b10c0c73adc Steven Rostedt 2024-12-24 6308 int ret;
bc0c38d139ec7f Steven Rostedt 2008-05-12 6309
d33b10c0c73adc Steven Rostedt 2024-12-24 6310 guard(mutex)(&trace_types_lock);
1027fcb206a0fb Steven Rostedt 2009-03-12 6311
7a1d1e4b9639ff Steven Rostedt (Google 2024-06-12 6312) update_last_data(tr);
7a1d1e4b9639ff Steven Rostedt (Google 2024-06-12 6313)
a1f157c7a3bb34 Zheng Yejian 2023-09-06 6314 if (!tr->ring_buffer_expanded) {
2b6080f28c7cc3 Steven Rostedt 2012-05-11 6315 ret = __tracing_resize_ring_buffer(tr, trace_buf_size,
438ced1720b584 Vaibhav Nagarnaik 2012-02-02 6316 RING_BUFFER_ALL_CPUS);
73c5162aa362a5 Steven Rostedt 2009-03-11 6317 if (ret < 0)
d33b10c0c73adc Steven Rostedt 2024-12-24 6318 return ret;
73c5162aa362a5 Steven Rostedt 2009-03-11 6319 ret = 0;
73c5162aa362a5 Steven Rostedt 2009-03-11 6320 }
73c5162aa362a5 Steven Rostedt 2009-03-11 6321
428add559b6923 Steven Rostedt 2025-11-11 6322 list_for_each_entry(t, &tr->tracers, list) {
428add559b6923 Steven Rostedt 2025-11-11 6323 if (strcmp(t->tracer->name, buf) == 0) {
428add559b6923 Steven Rostedt 2025-11-11 6324 trace = t->tracer;
bc0c38d139ec7f Steven Rostedt 2008-05-12 6325 break;
bc0c38d139ec7f Steven Rostedt 2008-05-12 6326 }
428add559b6923 Steven Rostedt 2025-11-11 6327 }
428add559b6923 Steven Rostedt 2025-11-11 6328 if (!trace)
d33b10c0c73adc Steven Rostedt 2024-12-24 6329 return -EINVAL;
d33b10c0c73adc Steven Rostedt 2024-12-24 6330
428add559b6923 Steven Rostedt 2025-11-11 6331 if (trace == tr->current_trace)
d33b10c0c73adc Steven Rostedt 2024-12-24 6332 return 0;
bc0c38d139ec7f Steven Rostedt 2008-05-12 6333
b1e5d74d04bbcf Steven Rostedt 2026-02-07 6334 if (tracer_uses_snapshot(trace)) {
c0a581d7126c0b Waiman Long 2022-09-22 6335 local_irq_disable();
a35873a0993b4d Tom Zanussi 2019-02-13 6336 arch_spin_lock(&tr->max_lock);
22bec11a569983 Steven Rostedt 2025-01-06 @6337 ret = tr->cond_snapshot ? -EBUSY : 0;
a35873a0993b4d Tom Zanussi 2019-02-13 6338 arch_spin_unlock(&tr->max_lock);
c0a581d7126c0b Waiman Long 2022-09-22 6339 local_irq_enable();
a35873a0993b4d Tom Zanussi 2019-02-13 6340 if (ret)
d33b10c0c73adc Steven Rostedt 2024-12-24 6341 return ret;
a35873a0993b4d Tom Zanussi 2019-02-13 6342 }
b1e5d74d04bbcf Steven Rostedt 2026-02-07 6343
c7b3ae0bd2ca65 Ziqian SUN (Zamir 2017-09-11 6344) /* Some tracers won't work on kernel command line */
428add559b6923 Steven Rostedt 2025-11-11 6345 if (system_state < SYSTEM_RUNNING && trace->noboot) {
c7b3ae0bd2ca65 Ziqian SUN (Zamir 2017-09-11 6346) pr_warn("Tracer '%s' is not allowed on command line, ignored\n",
428add559b6923 Steven Rostedt 2025-11-11 6347 trace->name);
d1e27ee9c6f21c Steven Rostedt 2024-12-19 6348 return -EINVAL;
c7b3ae0bd2ca65 Ziqian SUN (Zamir 2017-09-11 6349) }
c7b3ae0bd2ca65 Ziqian SUN (Zamir 2017-09-11 6350)
607e2ea167e56d Steven Rostedt (Red Hat 2013-11-06 6351) /* Some tracers are only allowed for the top level buffer */
428add559b6923 Steven Rostedt 2025-11-11 6352 if (!trace_ok_for_array(trace, tr))
d33b10c0c73adc Steven Rostedt 2024-12-24 6353 return -EINVAL;
607e2ea167e56d Steven Rostedt (Red Hat 2013-11-06 6354)
cf6ab6d9143b15 Steven Rostedt (Red Hat 2014-12-15 6355) /* If trace pipe files are being read, we can't change the tracer */
d33b10c0c73adc Steven Rostedt 2024-12-24 6356 if (tr->trace_ref)
d33b10c0c73adc Steven Rostedt 2024-12-24 6357 return -EBUSY;
cf6ab6d9143b15 Steven Rostedt (Red Hat 2014-12-15 6358)
9f029e83e968e5 Steven Rostedt 2008-11-12 6359 trace_branch_disable();
613f04a0f51e6e Steven Rostedt (Red Hat 2013-03-14 6360)
50512ab576e1ce Steven Rostedt (Red Hat 2014-01-14 6361) tr->current_trace->enabled--;
613f04a0f51e6e Steven Rostedt (Red Hat 2013-03-14 6362)
2b6080f28c7cc3 Steven Rostedt 2012-05-11 6363 if (tr->current_trace->reset)
2b6080f28c7cc3 Steven Rostedt 2012-05-11 6364 tr->current_trace->reset(tr);
613f04a0f51e6e Steven Rostedt (Red Hat 2013-03-14 6365)
b1e5d74d04bbcf Steven Rostedt 2026-02-07 6366 had_max_tr = tracer_uses_snapshot(tr->current_trace);
a541a9559bb0a8 Steven Rostedt (Google 2022-10-05 6367)
7440172974e85b Paul E. McKenney 2018-11-06 6368 /* Current trace needs to be nop_trace before synchronize_rcu */
2b6080f28c7cc3 Steven Rostedt 2012-05-11 6369 tr->current_trace = &nop_trace;
428add559b6923 Steven Rostedt 2025-11-11 6370 tr->current_trace_flags = nop_trace.flags;
34600f0e9c33c9 Steven Rostedt 2013-01-22 6371
b1e5d74d04bbcf Steven Rostedt 2026-02-07 6372 if (had_max_tr && !tracer_uses_snapshot(trace)) {
34600f0e9c33c9 Steven Rostedt 2013-01-22 6373 /*
34600f0e9c33c9 Steven Rostedt 2013-01-22 6374 * We need to make sure that the update_max_tr sees that
34600f0e9c33c9 Steven Rostedt 2013-01-22 6375 * current_trace changed to nop_trace to keep it from
34600f0e9c33c9 Steven Rostedt 2013-01-22 6376 * swapping the buffers after we resize it.
34600f0e9c33c9 Steven Rostedt 2013-01-22 6377 * The update_max_tr is called from interrupts disabled
34600f0e9c33c9 Steven Rostedt 2013-01-22 6378 * so a synchronized_sched() is sufficient.
34600f0e9c33c9 Steven Rostedt 2013-01-22 6379 */
7440172974e85b Paul E. McKenney 2018-11-06 6380 synchronize_rcu();
3209cff4490bee Steven Rostedt (Red Hat 2013-03-12 6381) free_snapshot(tr);
180e4e390978af Vincent Donnefort 2024-02-20 6382 tracing_disarm_snapshot(tr);
ef710e100c1068 KOSAKI Motohiro 2010-07-01 6383 }
12883efb670c28 Steven Rostedt (Red Hat 2013-03-05 6384)
b1e5d74d04bbcf Steven Rostedt 2026-02-07 6385 if (!had_max_tr && tracer_uses_snapshot(trace)) {
180e4e390978af Vincent Donnefort 2024-02-20 6386 ret = tracing_arm_snapshot_locked(tr);
180e4e390978af Vincent Donnefort 2024-02-20 6387 if (ret)
d33b10c0c73adc Steven Rostedt 2024-12-24 6388 return ret;
ef710e100c1068 KOSAKI Motohiro 2010-07-01 6389 }
577b785f55168d Steven Rostedt 2009-02-26 6390
428add559b6923 Steven Rostedt 2025-11-11 6391 tr->current_trace_flags = t->flags ? : t->tracer->flags;
428add559b6923 Steven Rostedt 2025-11-11 6392
428add559b6923 Steven Rostedt 2025-11-11 6393 if (trace->init) {
428add559b6923 Steven Rostedt 2025-11-11 6394 ret = tracer_init(trace, tr);
180e4e390978af Vincent Donnefort 2024-02-20 6395 if (ret) {
b1e5d74d04bbcf Steven Rostedt 2026-02-07 6396 if (tracer_uses_snapshot(trace))
180e4e390978af Vincent Donnefort 2024-02-20 6397 tracing_disarm_snapshot(tr);
428add559b6923 Steven Rostedt 2025-11-11 6398 tr->current_trace_flags = nop_trace.flags;
d33b10c0c73adc Steven Rostedt 2024-12-24 6399 return ret;
1c80025a49855b Frederic Weisbecker 2008-11-16 6400 }
180e4e390978af Vincent Donnefort 2024-02-20 6401 }
bc0c38d139ec7f Steven Rostedt 2008-05-12 6402
428add559b6923 Steven Rostedt 2025-11-11 6403 tr->current_trace = trace;
50512ab576e1ce Steven Rostedt (Red Hat 2014-01-14 6404) tr->current_trace->enabled++;
9f029e83e968e5 Steven Rostedt 2008-11-12 6405 trace_branch_enable(tr);
bc0c38d139ec7f Steven Rostedt 2008-05-12 6406
d33b10c0c73adc Steven Rostedt 2024-12-24 6407 return 0;
d9e540762f5cdd Peter Zijlstra 2008-11-01 6408 }
d9e540762f5cdd Peter Zijlstra 2008-11-01 6409 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH v2 2/3] tracing: Add tracer_uses_snapshot() helper to remove #ifdefs
In reply to Steven Rostedtkernel test robot noticed the following build errors:
Hi Steven,
kernel test robot noticed the following build errors:
[auto build test ERROR on trace/for-next]
[also build test ERROR on linus/master v6.19-rc8 next-20260205] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Steven-Rostedt/tracing-Rename-trace_array-field-max_buffer-to-snapshot_buffer/20260208-120355 base: https://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace for-next patch link: https://lore.kernel.org/r/20260208040221.900653834%40kernel.org patch subject: [PATCH v2 2/3] tracing: Add tracer_uses_snapshot() helper to remove #ifdefs config: x86_64-kexec (https://download.01.org/0day-ci/archive/20260208/[email protected]/config) compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260208/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> kernel/trace/trace.c:6337:13: error: no member named 'cond_snapshot' in 'struct trace_array'
6337 | ret = tr->cond_snapshot ? -EBUSY : 0;
| ~~ ^
kernel/trace/trace.c:6366:2: error: use of undeclared identifier 'had_max_tr'
6366 | had_max_tr = tracer_uses_snapshot(tr->current_trace);
| ^
kernel/trace/trace.c:6372:6: error: use of undeclared identifier 'had_max_tr'
6372 | if (had_max_tr && !tracer_uses_snapshot(trace)) {
| ^
kernel/trace/trace.c:6385:7: error: use of undeclared identifier 'had_max_tr'
6385 | if (!had_max_tr && tracer_uses_snapshot(trace)) {
| ^
kernel/trace/trace.c:9795:23: warning: shift count is negative [-Wshift-count-negative]
9795 | !((1ULL << i) & TOP_LEVEL_TRACE_FLAGS)) {
| ^~~~~~~~~~~~~~~~~~~~~
kernel/trace/trace.c:523:9: note: expanded from macro 'TOP_LEVEL_TRACE_FLAGS'
523 | TRACE_ITER(PROF_TEXT_OFFSET) | FPROFILE_DEFAULT_FLAGS)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
kernel/trace/trace.h:1452:42: note: expanded from macro 'TRACE_ITER'
1452 | (TRACE_ITER_##flag##_BIT < 0 ? 0 : 1ULL << (TRACE_ITER_##flag##_BIT))
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~1 warning and 4 errors generated.
vim +6337 kernel/trace/trace.c
ef9188bcc6ca1d Mark-PK Tsai 2022-04-26 6300
9c5b9d3d65e485 Masami Hiramatsu 2020-01-11 6301 int tracing_set_tracer(struct trace_array *tr, const char *buf)
09d23a1d8a82e8 Steven Rostedt (Red Hat 2015-02-03 6302) {
428add559b6923 Steven Rostedt 2025-11-11 6303 struct tracer *trace = NULL;
428add559b6923 Steven Rostedt 2025-11-11 6304 struct tracers *t;
12883efb670c28 Steven Rostedt (Red Hat 2013-03-05 6305) #ifdef CONFIG_TRACER_MAX_TRACE
34600f0e9c33c9 Steven Rostedt 2013-01-22 6306 bool had_max_tr;
12883efb670c28 Steven Rostedt (Red Hat 2013-03-05 6307) #endif
d33b10c0c73adc Steven Rostedt 2024-12-24 6308 int ret;
bc0c38d139ec7f Steven Rostedt 2008-05-12 6309
d33b10c0c73adc Steven Rostedt 2024-12-24 6310 guard(mutex)(&trace_types_lock);
1027fcb206a0fb Steven Rostedt 2009-03-12 6311
7a1d1e4b9639ff Steven Rostedt (Google 2024-06-12 6312) update_last_data(tr);
7a1d1e4b9639ff Steven Rostedt (Google 2024-06-12 6313)
a1f157c7a3bb34 Zheng Yejian 2023-09-06 6314 if (!tr->ring_buffer_expanded) {
2b6080f28c7cc3 Steven Rostedt 2012-05-11 6315 ret = __tracing_resize_ring_buffer(tr, trace_buf_size,
438ced1720b584 Vaibhav Nagarnaik 2012-02-02 6316 RING_BUFFER_ALL_CPUS);
73c5162aa362a5 Steven Rostedt 2009-03-11 6317 if (ret < 0)
d33b10c0c73adc Steven Rostedt 2024-12-24 6318 return ret;
73c5162aa362a5 Steven Rostedt 2009-03-11 6319 ret = 0;
73c5162aa362a5 Steven Rostedt 2009-03-11 6320 }
73c5162aa362a5 Steven Rostedt 2009-03-11 6321
428add559b6923 Steven Rostedt 2025-11-11 6322 list_for_each_entry(t, &tr->tracers, list) {
428add559b6923 Steven Rostedt 2025-11-11 6323 if (strcmp(t->tracer->name, buf) == 0) {
428add559b6923 Steven Rostedt 2025-11-11 6324 trace = t->tracer;
bc0c38d139ec7f Steven Rostedt 2008-05-12 6325 break;
bc0c38d139ec7f Steven Rostedt 2008-05-12 6326 }
428add559b6923 Steven Rostedt 2025-11-11 6327 }
428add559b6923 Steven Rostedt 2025-11-11 6328 if (!trace)
d33b10c0c73adc Steven Rostedt 2024-12-24 6329 return -EINVAL;
d33b10c0c73adc Steven Rostedt 2024-12-24 6330
428add559b6923 Steven Rostedt 2025-11-11 6331 if (trace == tr->current_trace)
d33b10c0c73adc Steven Rostedt 2024-12-24 6332 return 0;
bc0c38d139ec7f Steven Rostedt 2008-05-12 6333
b1e5d74d04bbcf Steven Rostedt 2026-02-07 6334 if (tracer_uses_snapshot(trace)) {
c0a581d7126c0b Waiman Long 2022-09-22 6335 local_irq_disable();
a35873a0993b4d Tom Zanussi 2019-02-13 6336 arch_spin_lock(&tr->max_lock);
22bec11a569983 Steven Rostedt 2025-01-06 @6337 ret = tr->cond_snapshot ? -EBUSY : 0;
a35873a0993b4d Tom Zanussi 2019-02-13 6338 arch_spin_unlock(&tr->max_lock);
c0a581d7126c0b Waiman Long 2022-09-22 6339 local_irq_enable();
a35873a0993b4d Tom Zanussi 2019-02-13 6340 if (ret)
d33b10c0c73adc Steven Rostedt 2024-12-24 6341 return ret;
a35873a0993b4d Tom Zanussi 2019-02-13 6342 }
b1e5d74d04bbcf Steven Rostedt 2026-02-07 6343
c7b3ae0bd2ca65 Ziqian SUN (Zamir 2017-09-11 6344) /* Some tracers won't work on kernel command line */
428add559b6923 Steven Rostedt 2025-11-11 6345 if (system_state < SYSTEM_RUNNING && trace->noboot) {
c7b3ae0bd2ca65 Ziqian SUN (Zamir 2017-09-11 6346) pr_warn("Tracer '%s' is not allowed on command line, ignored\n",
428add559b6923 Steven Rostedt 2025-11-11 6347 trace->name);
d1e27ee9c6f21c Steven Rostedt 2024-12-19 6348 return -EINVAL;
c7b3ae0bd2ca65 Ziqian SUN (Zamir 2017-09-11 6349) }
c7b3ae0bd2ca65 Ziqian SUN (Zamir 2017-09-11 6350)
607e2ea167e56d Steven Rostedt (Red Hat 2013-11-06 6351) /* Some tracers are only allowed for the top level buffer */
428add559b6923 Steven Rostedt 2025-11-11 6352 if (!trace_ok_for_array(trace, tr))
d33b10c0c73adc Steven Rostedt 2024-12-24 6353 return -EINVAL;
607e2ea167e56d Steven Rostedt (Red Hat 2013-11-06 6354)
cf6ab6d9143b15 Steven Rostedt (Red Hat 2014-12-15 6355) /* If trace pipe files are being read, we can't change the tracer */
d33b10c0c73adc Steven Rostedt 2024-12-24 6356 if (tr->trace_ref)
d33b10c0c73adc Steven Rostedt 2024-12-24 6357 return -EBUSY;
cf6ab6d9143b15 Steven Rostedt (Red Hat 2014-12-15 6358)
9f029e83e968e5 Steven Rostedt 2008-11-12 6359 trace_branch_disable();
613f04a0f51e6e Steven Rostedt (Red Hat 2013-03-14 6360)
50512ab576e1ce Steven Rostedt (Red Hat 2014-01-14 6361) tr->current_trace->enabled--;
613f04a0f51e6e Steven Rostedt (Red Hat 2013-03-14 6362)
2b6080f28c7cc3 Steven Rostedt 2012-05-11 6363 if (tr->current_trace->reset)
2b6080f28c7cc3 Steven Rostedt 2012-05-11 6364 tr->current_trace->reset(tr);
613f04a0f51e6e Steven Rostedt (Red Hat 2013-03-14 6365)
b1e5d74d04bbcf Steven Rostedt 2026-02-07 6366 had_max_tr = tracer_uses_snapshot(tr->current_trace);
a541a9559bb0a8 Steven Rostedt (Google 2022-10-05 6367)
7440172974e85b Paul E. McKenney 2018-11-06 6368 /* Current trace needs to be nop_trace before synchronize_rcu */
2b6080f28c7cc3 Steven Rostedt 2012-05-11 6369 tr->current_trace = &nop_trace;
428add559b6923 Steven Rostedt 2025-11-11 6370 tr->current_trace_flags = nop_trace.flags;
34600f0e9c33c9 Steven Rostedt 2013-01-22 6371
b1e5d74d04bbcf Steven Rostedt 2026-02-07 6372 if (had_max_tr && !tracer_uses_snapshot(trace)) {
34600f0e9c33c9 Steven Rostedt 2013-01-22 6373 /*
34600f0e9c33c9 Steven Rostedt 2013-01-22 6374 * We need to make sure that the update_max_tr sees that
34600f0e9c33c9 Steven Rostedt 2013-01-22 6375 * current_trace changed to nop_trace to keep it from
34600f0e9c33c9 Steven Rostedt 2013-01-22 6376 * swapping the buffers after we resize it.
34600f0e9c33c9 Steven Rostedt 2013-01-22 6377 * The update_max_tr is called from interrupts disabled
34600f0e9c33c9 Steven Rostedt 2013-01-22 6378 * so a synchronized_sched() is sufficient.
34600f0e9c33c9 Steven Rostedt 2013-01-22 6379 */
7440172974e85b Paul E. McKenney 2018-11-06 6380 synchronize_rcu();
3209cff4490bee Steven Rostedt (Red Hat 2013-03-12 6381) free_snapshot(tr);
180e4e390978af Vincent Donnefort 2024-02-20 6382 tracing_disarm_snapshot(tr);
ef710e100c1068 KOSAKI Motohiro 2010-07-01 6383 }
12883efb670c28 Steven Rostedt (Red Hat 2013-03-05 6384)
b1e5d74d04bbcf Steven Rostedt 2026-02-07 6385 if (!had_max_tr && tracer_uses_snapshot(trace)) {
180e4e390978af Vincent Donnefort 2024-02-20 6386 ret = tracing_arm_snapshot_locked(tr);
180e4e390978af Vincent Donnefort 2024-02-20 6387 if (ret)
d33b10c0c73adc Steven Rostedt 2024-12-24 6388 return ret;
ef710e100c1068 KOSAKI Motohiro 2010-07-01 6389 }
577b785f55168d Steven Rostedt 2009-02-26 6390
428add559b6923 Steven Rostedt 2025-11-11 6391 tr->current_trace_flags = t->flags ? : t->tracer->flags;
428add559b6923 Steven Rostedt 2025-11-11 6392
428add559b6923 Steven Rostedt 2025-11-11 6393 if (trace->init) {
428add559b6923 Steven Rostedt 2025-11-11 6394 ret = tracer_init(trace, tr);
180e4e390978af Vincent Donnefort 2024-02-20 6395 if (ret) {
b1e5d74d04bbcf Steven Rostedt 2026-02-07 6396 if (tracer_uses_snapshot(trace))
180e4e390978af Vincent Donnefort 2024-02-20 6397 tracing_disarm_snapshot(tr);
428add559b6923 Steven Rostedt 2025-11-11 6398 tr->current_trace_flags = nop_trace.flags;
d33b10c0c73adc Steven Rostedt 2024-12-24 6399 return ret;
1c80025a49855b Frederic Weisbecker 2008-11-16 6400 }
180e4e390978af Vincent Donnefort 2024-02-20 6401 }
bc0c38d139ec7f Steven Rostedt 2008-05-12 6402
428add559b6923 Steven Rostedt 2025-11-11 6403 tr->current_trace = trace;
50512ab576e1ce Steven Rostedt (Red Hat 2014-01-14 6404) tr->current_trace->enabled++;
9f029e83e968e5 Steven Rostedt 2008-11-12 6405 trace_branch_enable(tr);
bc0c38d139ec7f Steven Rostedt 2008-05-12 6406
d33b10c0c73adc Steven Rostedt 2024-12-24 6407 return 0;
d9e540762f5cdd Peter Zijlstra 2008-11-01 6408 }
d9e540762f5cdd Peter Zijlstra 2008-11-01 6409 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH v2 3/3 tracing: Better separate SNAPSHOT and MAX_TRACE options
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
The latency tracers (scheduler, irqsoff, etc) were created when tracing was first added. These tracers required a "snapshot" buffer that was the same size as the ring buffer being written to. When a new max latency was hit, the main ring buffer would swap with the snapshot buffer so that the trace leading up to the latency would be saved in the snapshot buffer (The snapshot buffer is never written to directly and the data within it can be viewed without fear of being overwritten).
Later, a new feature was added to allow snapshots to be taken by user space or even event triggers. This created a "snapshot" file that allowed users to trigger a snapshot from user space to save the current trace.
The config for this new feature (CONFIG_TRACER_SNAPSHOT) would select the latency tracer config (CONFIG_TRACER_MAX_LATENCY) as it would need all the functionality from it as it already existed. But this was incorrect. As the snapshot feature is really what the latency tracers need and not the other way around.
Have CONFIG_TRACER_MAX_TRACE select CONFIG_TRACER_SNAPSHOT where the tracers that needs the max latency buffer selects the TRACE_MAX_TRACE which will then select TRACER_SNAPSHOT.
Also, go through trace.c and trace.h and make the code that only needs the TRACER_MAX_TRACE protected by that and the code that always requires the snapshot to be protected by TRACER_SNAPSHOT.
--- kernel/trace/Kconfig | 8 ++--- kernel/trace/trace.c | 70 +++++++++++++++++++++++--------------------- kernel/trace/trace.h | 19 +++++++----- 3 files changed, 52 insertions(+), 45 deletions(-)
kernel/trace/Kconfig +4 -4
@@ -133,6 +133,7 @@ config BUILDTIME_MCOUNT_SORT config TRACER_MAX_TRACE bool + select TRACER_SNAPSHOT config TRACE_CLOCK bool
@@ -422,7 +423,6 @@ config IRQSOFF_TRACER select GENERIC_TRACER select TRACER_MAX_TRACE select RING_BUFFER_ALLOW_SWAP - select TRACER_SNAPSHOT select TRACER_SNAPSHOT_PER_CPU_SWAP help This option measures the time spent in irqs-off critical
@@ -445,7 +445,6 @@ config PREEMPT_TRACER select GENERIC_TRACER select TRACER_MAX_TRACE select RING_BUFFER_ALLOW_SWAP - select TRACER_SNAPSHOT select TRACER_SNAPSHOT_PER_CPU_SWAP select TRACE_PREEMPT_TOGGLE help
@@ -467,7 +466,6 @@ config SCHED_TRACER select GENERIC_TRACER select CONTEXT_SWITCH_TRACER select TRACER_MAX_TRACE - select TRACER_SNAPSHOT help This tracer tracks the latency of the highest priority task to be scheduled in, starting from the point it has woken up.
@@ -617,7 +615,6 @@ config TRACE_SYSCALL_BUF_SIZE_DEFAULT config TRACER_SNAPSHOT bool "Create a snapshot trace buffer" - select TRACER_MAX_TRACE help Allow tracing users to take snapshot of the current buffer using the ftrace interface, e.g.:
@@ -625,6 +622,9 @@ config TRACER_SNAPSHOT echo 1 > /sys/kernel/tracing/snapshot cat snapshot + Note, the latency tracers select this option. To disable it, + all the latency tracers need to be disabled. + config TRACER_SNAPSHOT_PER_CPU_SWAP bool "Allow snapshot to swap per CPU" depends on TRACER_SNAPSHOT
kernel/trace/trace.c +37 -33
249 lines not on this page · raw message
kernel/trace/trace.h +11 -8
@@ -329,7 +329,7 @@ struct trace_array {struct list_head list;char *name;struct array_buffer array_buffer; -#ifdef CONFIG_TRACER_MAX_TRACE +#ifdef CONFIG_TRACER_SNAPSHOT /* * The snapshot_buffer is used to snapshot the trace when a maximum * latency is reached, or when the user initiates a snapshot.
@@ -346,13 +346,16 @@ struct trace_array {bool allocated_snapshot;spinlock_t snapshot_trigger_lock;unsigned int snapshot; +#ifdef CONFIG_TRACER_MAX_TRACE unsigned long max_latency;#ifdef CONFIG_FSNOTIFY struct dentry *d_max_latency;struct work_struct fsnotify_work;struct irq_work fsnotify_irqwork; -#endif -#endif +#endif /* CONFIG_FSNOTIFY */ +#endif /* CONFIG_TRACER_MAX_TRACE */ +#endif /* CONFIG_TRACER_SNAPSHOT */ +/* The below is for memory mapped ring buffer */ unsigned int mapped;unsigned long range_addr_start;
@@ -378,7 +381,7 @@ struct trace_array {* * It is also used in other places outside the update_max_tr * so it needs to be defined outside of the -* CONFIG_TRACER_MAX_TRACE. +* CONFIG_TRACER_SNAPSHOT. */ arch_spinlock_t max_lock;#ifdef CONFIG_FTRACE_SYSCALLS
@@ -791,22 +794,22 @@ int trace_pid_write(struct trace_pid_list *filtered_pids,struct trace_pid_list **new_pid_list, const char __user *ubuf, size_t cnt); -#ifdef CONFIG_TRACER_MAX_TRACE +#ifdef CONFIG_TRACER_SNAPSHOT void update_max_tr (struct trace_array *tr,struct task_struct *tsk,int cpu,void *cond_data);void update_max_tr_single (struct trace_array *tr,struct task_struct *tsk,int cpu); -#ifdef CONFIG_FSNOTIFY -#define LATENCY_FS_NOTIFY +#if defined(CONFIG_TRACER_MAX_TRACE ) && defined(CONFIG_FSNOTIFY ) +# define LATENCY_FS_NOTIFY #endif -#endif /* CONFIG_TRACER_MAX_TRACE */ #ifdef LATENCY_FS_NOTIFY void latency_fsnotify (struct trace_array *tr);#else static inline void latency_fsnotify (struct trace_array *tr) { }#endif +#endif /* CONFIG_TRACER_SNAPSHOT */ #ifdef CONFIG_STACKTRACE void __trace_stack (struct trace_array *tr,unsigned int trace_ctx,int skip);
Signature · 1 line
2.51.0