tracing: Remove most uses of "disabled" field
Subsystems (4)
Steven Rostedt
maintainerv2 cover tracing: Remove most uses of "disabled" field
Looking into allowing syscall events to fault and read user space, I found that the use of the per CPU data "disabled" field was mostly obsolete. This goes back to 2008 when the tracing subsystem was first created. The "disabled" field was the only way to know if tracing was disabled or not. But things have changed in the last 17 years! The ring buffer itself can disable tracing, and for the most part, that is what determines if tracing is enabled or not.
Now the stack tracer and latency tracers still use the disabled field to prevent corruption while its doing its per CPU accounting.
This series removes most uses of the disabled field. It also does some various clean ups, like convert the disabled field into a local_t type from an atomic_t type as it only is used to synchronize with interrupts and such.
Also, while inspecting the per CPU data, I realized that there's a "buffer_page" field that was supposed to hold the reader page to be able to reuse it. But that is done by the ring buffer infrastructure itself and this field is unneeded, so it is removed.
Note, with this change, the trace events shouldn't need to be called with preemption disabled anymore. This should allow the syscall trace event to be updated to read user memory. It still has some code that requires preemption disabled, but it does it internally and doesn't expect the functions to be called with preemption disabled.
Changes since v1: https://lore.kernel.org/linux-trace-kernel/[email protected]/
- Fixed "raw_smp_process_id()" to "raw_smp_processor_id()" in branch tracer (kernel test robot)
- Fixed unused "int cpu;" (kernel test robot)
- Add tracer_tracing_disable/enable() functions
- Use tracer_tracing_disable() instead of tracer_tracing_on() for ftrace_dump_one()
- Use the new tracer_tracing_disable() instead of tracer_tracing_off() for kdb_ftdump (Doug Anderson)
Head SHA1: 70b9ea306f1c611f81d6365f0866ee421c664200
Steven Rostedt (13):
tracing/mmiotrace: Remove reference to unused per CPU data pointer
ftrace: Do not bother checking per CPU "disabled" flag
tracing: Just use this_cpu_read() to access ignore_pid
tracing: Add tracer_tracing_disable/enable() functions
tracing: Use tracer_tracing_disable() instead of "disabled" field for ftrace_dump_one()
tracing: kdb: Use tracer_tracing_on/off() instead of setting per CPU disabled
ftrace: Do not disabled function graph based on "disabled" field
tracing: Do not use per CPU array_buffer.data->disabled for cpumask
ring-buffer: Add ring_buffer_record_is_on_cpu()
tracing: branch: Use trace_tracing_is_on_cpu() instead of "disabled" field
tracing: Convert the per CPU "disabled" counter to local from atomic
tracing: Use atomic_inc_return() for updating "disabled" counter in irqsoff tracer
tracing: Remove unused buffer_page field from trace_array_cpu structure
----
include/linux/ring_buffer.h | 1 + kernel/trace/ring_buffer.c | 18 ++++++++++++++ kernel/trace/trace.c | 46 ++++++++++++++++++++++++++++------- kernel/trace/trace.h | 20 +++++++++++++-- kernel/trace/trace_branch.c | 4 +-- kernel/trace/trace_events.c | 9 ++++--- kernel/trace/trace_functions.c | 24 ++++++------------ kernel/trace/trace_functions_graph.c | 38 +++++++---------------------- kernel/trace/trace_irqsoff.c | 47 +++++++++++++++++++++--------------- kernel/trace/trace_kdb.c | 9 ++----- kernel/trace/trace_mmiotrace.c | 12 ++------- kernel/trace/trace_sched_wakeup.c | 18 +++++++------- 12 files changed, 136 insertions(+), 110 deletions(-)
Steven Rostedt
maintainerPATCH v2 1/13 tracing/mmiotrace: Remove reference to unused per CPU data pointer
From: Steven Rostedt <[email protected]>
The mmiotracer referenced the per CPU array_buffer->data descriptor but never actually used it. Remove the references to it.
--- kernel/trace/trace_mmiotrace.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)
kernel/trace/trace_mmiotrace.c +2 -10
@@ -291,7 +291,6 @@ __init static int init_mmio_trace(void)device_initcall (init_mmio_trace);static void __trace_mmiotrace_rw (struct trace_array *tr, -struct trace_array_cpu *data,struct mmiotrace_rw *rw) {struct trace_buffer *buffer = tr->array_buffer.buffer;
@@ -315,12 +314,10 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,void mmio_trace_rw (struct mmiotrace_rw *rw) {struct trace_array *tr = mmio_trace_array; -struct trace_array_cpu *data =per_cpu_ptr (tr->array_buffer.data,smp_processor_id ()); -__trace_mmiotrace_rw (tr, data, rw); +__trace_mmiotrace_rw (tr, rw); }static void __trace_mmiotrace_map (struct trace_array *tr, -struct trace_array_cpu *data,struct mmiotrace_map *map) {struct trace_buffer *buffer = tr->array_buffer.buffer;
@@ -344,12 +341,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,void mmio_trace_mapping (struct mmiotrace_map *map) {struct trace_array *tr = mmio_trace_array; -struct trace_array_cpu *data; - -preempt_disable (); - data =per_cpu_ptr (tr->array_buffer.data,smp_processor_id ()); -__trace_mmiotrace_map (tr, data, map); -preempt_enable (); +__trace_mmiotrace_map (tr, map); }int mmio_trace_printk (const char *fmt,va_list args)
Signature · 1 line
2.47.2
Steven Rostedt
maintainerPATCH v2 2/13 ftrace: Do not bother checking per CPU "disabled" flag
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
The per CPU "disabled" value was the original way to disable tracing when the tracing subsystem was first created. Today, the ring buffer infrastructure has its own way to disable tracing. In fact, things have changed so much since 2008 that many things ignore the disable flag.
There's no reason for the function tracer to check it, if tracing is disabled, the ring buffer will not record the event anyway.
--- kernel/trace/trace_functions.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-)
kernel/trace/trace_functions.c +3 -13
@@ -209,7 +209,6 @@ function_trace_call(unsigned long ip, unsigned long parent_ip, struct ftrace_ops *op, struct ftrace_regs *fregs) { struct trace_array *tr = op->private; -struct trace_array_cpu *data;unsigned int trace_ctx;int bit;
@@ -224,9 +223,7 @@ function_trace_call(unsigned long ip, unsigned long parent_ip, trace_ctx =tracing_gen_ctx_dec (); - data =this_cpu_ptr (tr->array_buffer.data); -if (!atomic_read (&data->disabled)) -trace_function (tr, ip, parent_ip, trace_ctx,NULL ); +trace_function (tr, ip, parent_ip, trace_ctx,NULL );ftrace_test_recursion_unlock (bit); }
@@ -236,10 +233,8 @@ function_args_trace_call(unsigned long ip, unsigned long parent_ip, struct ftrace_ops *op, struct ftrace_regs *fregs) { struct trace_array *tr = op->private; -struct trace_array_cpu *data;unsigned int trace_ctx;int bit; -int cpu;if (unlikely (!tr->function_enabled))return ;
@@ -250,10 +245,7 @@ function_args_trace_call(unsigned long ip, unsigned long parent_ip, trace_ctx =tracing_gen_ctx (); - cpu =smp_processor_id (); - data =per_cpu_ptr (tr->array_buffer.data, cpu); -if (!atomic_read (&data->disabled)) -trace_function (tr, ip, parent_ip, trace_ctx, fregs); +trace_function (tr, ip, parent_ip, trace_ctx, fregs);ftrace_test_recursion_unlock (bit); }
@@ -352,7 +344,6 @@ function_no_repeats_trace_call(unsigned long ip, unsigned long parent_ip, {struct trace_func_repeats *last_info;struct trace_array *tr = op->private; -struct trace_array_cpu *data;unsigned int trace_ctx;int bit;
@@ -364,8 +355,7 @@ function_no_repeats_trace_call(unsigned long ip, unsigned long parent_ip,return ; parent_ip =function_get_true_parent_ip (parent_ip, fregs); - data =this_cpu_ptr (tr->array_buffer.data); -if (atomic_read (&data->disabled)) +if (!tracer_tracing_is_on (tr)) goto out;/*
Signature · 1 line
2.47.2
Steven Rostedt
maintainerPATCH v2 3/13 tracing: Just use this_cpu_read() to access ignore_pid
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
The ignore_pid boolean on the per CPU data descriptor is updated at sched_switch when a new task is scheduled in. If the new task is to be ignored, it is set to true, otherwise it is set to false. The current task should always have the correct value as it is updated when the task is scheduled in.
Instead of breaking up the read of this value, which requires preemption to be disabled, just use this_cpu_read() which gives a snapshot of the value. Since the value will always be correct for a given task (because it's updated at sched switch) it doesn't need preemption disabled.
This will also allow trace events to be called with preemption enabled.
--- kernel/trace/trace_events.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
kernel/trace/trace_events.c +5 -4
@@ -622,7 +622,6 @@ EXPORT_SYMBOL_GPL(trace_event_raw_init);bool trace_event_ignore_this_pid (struct trace_event_file *trace_file) {struct trace_array *tr = trace_file->tr; -struct trace_array_cpu *data;struct trace_pid_list *no_pid_list;struct trace_pid_list *pid_list;
@@ -632,9 +631,11 @@ bool trace_event_ignore_this_pid(struct trace_event_file *trace_file)if (!pid_list && !no_pid_list)return false; - data =this_cpu_ptr (tr->array_buffer.data); - -return data->ignore_pid; +/* +* This is recorded at every sched_switch for this task. +* Thus, even if the task migrates the ignore value will be the same. +*/ +return this_cpu_read (tr->array_buffer.data->ignore_pid) !=0 ; }EXPORT_SYMBOL_GPL (trace_event_ignore_this_pid);
Signature · 1 line
2.47.2
Steven Rostedt
maintainerPATCH v2 4/13 tracing: Add tracer_tracing_disable/enable() functions
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
Allow a tracer to disable writing to its buffer for a temporary amount of time and re-enable it.
The tracer_tracing_disable() will disable writing to the trace array buffer, and requires a tracer_tracing_enable() to re-enable it.
The difference between tracer_tracing_disable() and tracer_tracing_off() is that the disable version can nest, and requires as many enable() calls as disable() calls to re-enable the buffer. Where as the off() function can be called multiple times and only requires a singe tracer_tracing_on() to re-enable the buffer.
--- kernel/trace/trace.c | 33 +++++++++++++++++++++++++++++++++ kernel/trace/trace.h | 2 ++ 2 files changed, 35 insertions(+)
kernel/trace/trace.c +33 -0
@@ -1582,6 +1582,39 @@ void tracer_tracing_off(struct trace_array *tr)smp_wmb (); } +/** +* tracer_tracing_disable() - temporary disable the buffer from write +* @tr: The trace array to disable its buffer for +* +* Expects trace_tracing_enable() to re-enable tracing. +* The difference between this and tracer_tracing_off() is that this +* is a counter and can nest, whereas, tracer_tracing_off() can +* be called multiple times and a single trace_tracing_on() will +* enable it. +*/ +void tracer_tracing_disable (struct trace_array *tr) +{ +if (WARN_ON_ONCE (!tr->array_buffer.buffer)) +return ; + +ring_buffer_record_disable (tr->array_buffer.buffer); +} + +/** +* tracer_tracing_enable() - counter part of tracer_tracing_disable() +* @tr: The trace array that had tracer_tracincg_disable() called on it +* +* This is called after tracer_tracing_disable() has been called on @tr, +* when it's safe to re-enable tracing. +*/ +void tracer_tracing_enable (struct trace_array *tr) +{ +if (WARN_ON_ONCE (!tr->array_buffer.buffer)) +return ; + +ring_buffer_record_enable (tr->array_buffer.buffer); +} +/** * tracing_off - turn off tracing buffers *
kernel/trace/trace.h +2 -0
@@ -665,6 +665,8 @@ bool tracing_is_disabled(void);bool tracer_tracing_is_on (struct trace_array *tr);void tracer_tracing_on (struct trace_array *tr);void tracer_tracing_off (struct trace_array *tr); +void tracer_tracing_disable (struct trace_array *tr); +void tracer_tracing_enable (struct trace_array *tr); struct dentry *trace_create_file(const char *name, umode_t mode, struct dentry *parent,
Signature · 1 line
2.47.2
Steven Rostedt
maintainerPATCH v2 5/13 tracing: Use tracer_tracing_disable() instead of "disabled" field for ftrace_dump_one()
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
The per CPU "disabled" value was the original way to disable tracing when the tracing subsystem was first created. Today, the ring buffer infrastructure has its own way to disable tracing. In fact, things have changed so much since 2008 that many things ignore the disable flag.
The ftrace_dump_one() function iterates over all the current tracing CPUs and increments the "disabled" counter before doing the dump, and decrements it afterward.
As the disabled flag can be ignored, doing this today is not reliable. Instead use the new tracer_tracing_disable() that calls into the ring buffer code to do the disabling.
---
Changes since v1: https://lore.kernel.org/[email protected]
- Use tracer_tracing_disable() instead of tracer_tracing_on()
kernel/trace/trace.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
kernel/trace/trace.c +4 -7
@@ -10481,7 +10481,7 @@ static void ftrace_dump_one(struct trace_array *tr, enum ftrace_dump_mode dump_mstatic struct trace_iterator iter;unsigned int old_userobj;unsigned long flags; -int cnt =0 , cpu; +int cnt =0 ;/* * Always turn off tracing when we dump.
@@ -10498,9 +10498,8 @@ static void ftrace_dump_one(struct trace_array *tr, enum ftrace_dump_mode dump_m/* Simulate the iterator */ trace_init_iter (&iter, tr); -for_each_tracing_cpu (cpu) { -atomic_inc (&per_cpu_ptr (iter.array_buffer->data, cpu)->disabled); - } +/* While dumping, do not allow the buffer to be enable */ +tracer_tracing_disable (tr); old_userobj = tr->trace_flags &TRACE_ITER_SYM_USEROBJ ;
@@ -10559,9 +10558,7 @@ static void ftrace_dump_one(struct trace_array *tr, enum ftrace_dump_mode dump_m tr->trace_flags |= old_userobj; -for_each_tracing_cpu (cpu) { -atomic_dec (&per_cpu_ptr (iter.array_buffer->data, cpu)->disabled); - } +tracer_tracing_enable (tr);local_irq_restore (flags); }
Signature · 1 line
2.47.2
Steven Rostedt
maintainerPATCH v2 6/13 tracing: kdb: Use tracer_tracing_on/off() instead of setting per CPU disabled
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
The per CPU "disabled" value was the original way to disable tracing when the tracing subsystem was first created. Today, the ring buffer infrastructure has its own way to disable tracing. In fact, things have changed so much since 2008 that many things ignore the disable flag.
The kdb_ftdump() function iterates over all the current tracing CPUs and increments the "disabled" counter before doing the dump, and decrements it afterward.
As the disabled flag can be ignored, doing this today is not reliable. Instead, simply call tracer_tracing_off() and then tracer_tracing_on() to disable and then enabled the entire ring buffer in one go!
---
Changes since v2: https://lore.kernel.org/[email protected]
- Fixed unused "int cpu;" (kernel test robot)
- Use the new tracer_tracing_disable() instead of tracer_tracing_off() (Doug Anderson)
kernel/trace/trace_kdb.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
kernel/trace/trace_kdb.c +2 -7
@@ -98,7 +98,6 @@ static int kdb_ftdump(int argc, const char **argv)long cpu_file;int err;int cnt; -int cpu;if (argc >2 )return KDB_ARGCOUNT ;
@@ -120,9 +119,7 @@ static int kdb_ftdump(int argc, const char **argv)trace_init_global_iter (&iter); iter.buffer_iter = buffer_iter; -for_each_tracing_cpu (cpu) { -atomic_inc (&per_cpu_ptr (iter.array_buffer->data, cpu)->disabled); - } +tracer_tracing_disable (iter.tr);/* A negative skip_entries means skip all but the last entries */ if (skip_entries <0 ) {
@@ -135,9 +132,7 @@ static int kdb_ftdump(int argc, const char **argv)ftrace_dump_buf (skip_entries, cpu_file); -for_each_tracing_cpu (cpu) { -atomic_dec (&per_cpu_ptr (iter.array_buffer->data, cpu)->disabled); - } +tracer_tracing_enable (iter.tr); kdb_trap_printk--;
Signature · 1 line
2.47.2
Steven Rostedt
maintainerPATCH v2 7/13 ftrace: Do not disabled function graph based on "disabled" field
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
The per CPU "disabled" value was the original way to disable tracing when the tracing subsystem was first created. Today, the ring buffer infrastructure has its own way to disable tracing. In fact, things have changed so much since 2008 that many things ignore the disable flag.
Do not bother disabling the function graph tracer if the per CPU disabled field is set. Just record as normal. If tracing is disabled in the ring buffer it will not be recorded.
Also, when tracing is enabled again, it will not drop the return call of the function.
--- kernel/trace/trace_functions_graph.c | 38 +++++++--------------------- 1 file changed, 9 insertions(+), 29 deletions(-)
kernel/trace/trace_functions_graph.c +9 -29
@@ -202,12 +202,9 @@ static int graph_entry(struct ftrace_graph_ent *trace, {unsigned long *task_var =fgraph_get_task_var (gops);struct trace_array *tr = gops->private; -struct trace_array_cpu *data;struct fgraph_times *ftimes;unsigned int trace_ctx; -long disabled;int ret =0 ; -int cpu;if (*task_var &TRACE_GRAPH_NOTRACE )return 0 ;
@@ -257,21 +254,14 @@ static int graph_entry(struct ftrace_graph_ent *trace,if (tracing_thresh)return 1 ; -preempt_disable_notrace (); - cpu =raw_smp_processor_id (); - data =per_cpu_ptr (tr->array_buffer.data, cpu); - disabled =atomic_read (&data->disabled); -if (likely (!disabled)) { - trace_ctx =tracing_gen_ctx (); -if (IS_ENABLED (CONFIG_FUNCTION_GRAPH_RETADDR ) && -tracer_flags_is_set (TRACE_GRAPH_PRINT_RETADDR )) { -unsigned long retaddr =ftrace_graph_top_ret_addr (current); - ret =__trace_graph_retaddr_entry (tr, trace, trace_ctx, retaddr); - }else { - ret =__graph_entry (tr, trace, trace_ctx, fregs); - } + trace_ctx =tracing_gen_ctx (); +if (IS_ENABLED (CONFIG_FUNCTION_GRAPH_RETADDR ) && +tracer_flags_is_set (TRACE_GRAPH_PRINT_RETADDR )) { +unsigned long retaddr =ftrace_graph_top_ret_addr (current); + ret =__trace_graph_retaddr_entry (tr, trace, trace_ctx, retaddr); + }else { + ret =__graph_entry (tr, trace, trace_ctx, fregs); } -preempt_enable_notrace ();return ret; }
@@ -351,13 +341,10 @@ void trace_graph_return(struct ftrace_graph_ret *trace, {unsigned long *task_var =fgraph_get_task_var (gops);struct trace_array *tr = gops->private; -struct trace_array_cpu *data;struct fgraph_times *ftimes;unsigned int trace_ctx;u64 calltime, rettime; -long disabled;int size; -int cpu; rettime =trace_clock_local ();
@@ -376,15 +363,8 @@ void trace_graph_return(struct ftrace_graph_ret *trace, calltime = ftimes->calltime; -preempt_disable_notrace (); - cpu =raw_smp_processor_id (); - data =per_cpu_ptr (tr->array_buffer.data, cpu); - disabled =atomic_read (&data->disabled); -if (likely (!disabled)) { - trace_ctx =tracing_gen_ctx (); -__trace_graph_return (tr, trace, trace_ctx, calltime, rettime); - } -preempt_enable_notrace (); + trace_ctx =tracing_gen_ctx (); +__trace_graph_return (tr, trace, trace_ctx, calltime, rettime); } static void trace_graph_thresh_return(struct ftrace_graph_ret *trace,
Signature · 1 line
2.47.2
Steven Rostedt
maintainerPATCH v2 8/13 tracing: Do not use per CPU array_buffer.data->disabled for cpumask
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
The per CPU "disabled" value was the original way to disable tracing when the tracing subsystem was first created. Today, the ring buffer infrastructure has its own way to disable tracing. In fact, things have changed so much since 2008 that many things ignore the disable flag.
Do not bother setting the per CPU disabled flag of the array_buffer data to use to determine what CPUs can write to the buffer and only rely on the ring buffer code itself to disabled it.
--- kernel/trace/trace.c | 2 -- 1 file changed, 2 deletions(-)
kernel/trace/trace.c +0 -2
@@ -5081,7 +5081,6 @@ int tracing_set_cpumask(struct trace_array *tr,*/ if (cpumask_test_cpu (cpu, tr->tracing_cpumask) && !cpumask_test_cpu (cpu, tracing_cpumask_new)) { -atomic_inc (&per_cpu_ptr (tr->array_buffer.data, cpu)->disabled);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);
@@ -5089,7 +5088,6 @@ int tracing_set_cpumask(struct trace_array *tr, }if (!cpumask_test_cpu (cpu, tr->tracing_cpumask) &&cpumask_test_cpu (cpu, tracing_cpumask_new)) { -atomic_dec (&per_cpu_ptr (tr->array_buffer.data, cpu)->disabled);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);
Signature · 1 line
2.47.2
Steven Rostedt
maintainerPATCH v2 9/13 ring-buffer: Add ring_buffer_record_is_on_cpu()
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
Add the function ring_buffer_record_is_on_cpu() that returns true if the ring buffer for a give CPU is writable and false otherwise.
Also add tracer_tracing_is_on_cpu() to return if the ring buffer for a given CPU is writeable for a given trace_array.
--- include/linux/ring_buffer.h | 1 + kernel/trace/ring_buffer.c | 18 ++++++++++++++++++ kernel/trace/trace.h | 15 +++++++++++++++ 3 files changed, 34 insertions(+)
include/linux/ring_buffer.h +1 -0
@@ -192,6 +192,7 @@ void ring_buffer_record_off(struct trace_buffer *buffer);void ring_buffer_record_on (struct trace_buffer *buffer);bool ring_buffer_record_is_on (struct trace_buffer *buffer);bool ring_buffer_record_is_set_on (struct trace_buffer *buffer); +bool ring_buffer_record_is_on_cpu (struct trace_buffer *buffer,int cpu);void ring_buffer_record_disable_cpu (struct trace_buffer *buffer,int cpu);void ring_buffer_record_enable_cpu (struct trace_buffer *buffer,int cpu);
kernel/trace/ring_buffer.c +18 -0
@@ -4882,6 +4882,24 @@ bool ring_buffer_record_is_set_on(struct trace_buffer *buffer)return !(atomic_read (&buffer->record_disabled) &RB_BUFFER_OFF ); } +/** +* ring_buffer_record_is_on_cpu - return true if the ring buffer can write +* @buffer: The ring buffer to see if write is enabled +* @cpu: The CPU to test if the ring buffer can write too +* +* Returns true if the ring buffer is in a state that it accepts writes +* for a particular CPU. +*/ +bool ring_buffer_record_is_on_cpu (struct trace_buffer *buffer,int cpu) +{ +struct ring_buffer_per_cpu *cpu_buffer; + + cpu_buffer = buffer->buffers[cpu]; + +return ring_buffer_record_is_set_on (buffer) && + !atomic_read (&cpu_buffer->record_disabled); +} +/** * ring_buffer_record_disable_cpu - stop all writes into the cpu_buffer * @buffer: The ring buffer to stop writes to.
kernel/trace/trace.h +15 -0
@@ -673,6 +673,21 @@ struct dentry *trace_create_file(const char *name,void *data, const struct file_operations *fops); + +/** +* tracer_tracing_is_on_cpu - show real state of ring buffer enabled on for a cpu +* @tr : the trace array to know if ring buffer is enabled +* @cpu: The cpu buffer to check if enabled +* +* Shows real state of the per CPU buffer if it is enabled or not. +*/ +static inline bool tracer_tracing_is_on_cpu (struct trace_array *tr,int cpu) +{ +if (tr->array_buffer.buffer) +return ring_buffer_record_is_on_cpu (tr->array_buffer.buffer, cpu); +return false; +} +int tracing_init_dentry (void );struct ring_buffer_event ;
Signature · 1 line
2.47.2
Steven Rostedt
maintainerPATCH v2 10/13 tracing: branch: Use trace_tracing_is_on_cpu() instead of "disabled" field
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
The branch tracer currently checks the per CPU "disabled" field to know if tracing is enabled or not for the CPU. As the "disabled" value is not used anymore to turn of tracing generically, use tracing_tracer_is_on_cpu() instead.
---
Changes since v1: https://lore.kernel.org/[email protected]
- Fixed "raw_smp_process_id()" to "raw_smp_processor_id()" (kernel test robot)
kernel/trace/trace_branch.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/trace/trace_branch.c +1 -3
@@ -32,7 +32,6 @@ probe_likely_condition(struct ftrace_likely_data *f, int val, int expect) {struct trace_array *tr = branch_tracer;struct trace_buffer *buffer; -struct trace_array_cpu *data;struct ring_buffer_event *event;struct trace_branch *entry;unsigned long flags;
@@ -54,8 +53,7 @@ probe_likely_condition(struct ftrace_likely_data *f, int val, int expect)raw_local_irq_save (flags); current->trace_recursion |=TRACE_BRANCH_BIT ; - data =this_cpu_ptr (tr->array_buffer.data); -if (atomic_read (&data->disabled)) +if (!tracer_tracing_is_on_cpu (tr,raw_smp_processor_id ())) goto out; trace_ctx =tracing_gen_ctx_flags (flags);
Signature · 1 line
2.47.2
Steven Rostedt
maintainerPATCH v2 11/13 tracing: Convert the per CPU "disabled" counter to local from atomic
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
The per CPU "disabled" counter is used for the latency tracers and stack tracers to make sure that their accounting isn't messed up by an NMI or interrupt coming in and affecting the same CPU data. But the counter is an atomic_t type. As it only needs to synchronize against the current CPU, switch it over to local_t type.
--- kernel/trace/trace.h | 2 +- kernel/trace/trace_functions.c | 8 ++++---- kernel/trace/trace_irqsoff.c | 22 +++++++++++----------- kernel/trace/trace_sched_wakeup.c | 18 +++++++++--------- 4 files changed, 25 insertions(+), 25 deletions(-)
kernel/trace/trace.h +1 -1
@@ -183,7 +183,7 @@ struct trace_array;* the trace, etc.) */ struct trace_array_cpu { -atomic_t disabled; +local_t disabled;void *buffer_page;/* ring buffer spare */ unsigned long entries;
kernel/trace/trace_functions.c +4 -4
@@ -291,7 +291,7 @@ function_stack_trace_call(unsigned long ip, unsigned long parent_ip, parent_ip =function_get_true_parent_ip (parent_ip, fregs); cpu =raw_smp_processor_id (); data =per_cpu_ptr (tr->array_buffer.data, cpu); - disabled =atomic_inc_return (&data->disabled); + disabled =local_inc_return (&data->disabled);if (likely (disabled ==1 )) { trace_ctx =tracing_gen_ctx_flags (flags);
@@ -303,7 +303,7 @@ function_stack_trace_call(unsigned long ip, unsigned long parent_ip,__trace_stack (tr, trace_ctx, skip); } -atomic_dec (&data->disabled); +local_dec (&data->disabled);local_irq_restore (flags); }
@@ -402,7 +402,7 @@ function_stack_no_repeats_trace_call(unsigned long ip, unsigned long parent_ip, parent_ip =function_get_true_parent_ip (parent_ip, fregs); cpu =raw_smp_processor_id (); data =per_cpu_ptr (tr->array_buffer.data, cpu); - disabled =atomic_inc_return (&data->disabled); + disabled =local_inc_return (&data->disabled);if (likely (disabled ==1 )) { last_info =per_cpu_ptr (tr->last_func_repeats, cpu);
@@ -417,7 +417,7 @@ function_stack_no_repeats_trace_call(unsigned long ip, unsigned long parent_ip, } out: -atomic_dec (&data->disabled); +local_dec (&data->disabled);local_irq_restore (flags); }
kernel/trace/trace_irqsoff.c +11 -11
@@ -123,12 +123,12 @@ static int func_prolog_dec(struct trace_array *tr,return 0 ; *data =per_cpu_ptr (tr->array_buffer.data, cpu); - disabled =atomic_inc_return (&(*data)->disabled); + disabled =local_inc_return (&(*data)->disabled);if (likely (disabled ==1 ))return 1 ; -atomic_dec (&(*data)->disabled); +local_dec (&(*data)->disabled);return 0 ; }
@@ -152,7 +152,7 @@ irqsoff_tracer_call(unsigned long ip, unsigned long parent_ip,trace_function (tr, ip, parent_ip, trace_ctx, fregs); - atomic_dec(&data->disabled); + local_dec(&data->disabled); }#endif /* CONFIG_FUNCTION_TRACER */
@@ -209,7 +209,7 @@ static int irqsoff_graph_entry(struct ftrace_graph_ent *trace, trace_ctx =tracing_gen_ctx_flags (flags); ret =__trace_graph_entry (tr, trace, trace_ctx); -atomic_dec (&data->disabled); +local_dec (&data->disabled);return ret; }
@@ -238,7 +238,7 @@ static void irqsoff_graph_return(struct ftrace_graph_ret *trace, trace_ctx =tracing_gen_ctx_flags (flags);__trace_graph_return (tr, trace, trace_ctx, *calltime, rettime); -atomic_dec (&data->disabled); +local_dec (&data->disabled); }static struct fgraph_ops fgraph_ops = {
@@ -408,10 +408,10 @@ start_critical_timing(unsigned long ip, unsigned long parent_ip) data =per_cpu_ptr (tr->array_buffer.data, cpu); -if (unlikely (!data) ||atomic_read (&data->disabled)) +if (unlikely (!data) ||local_read (&data->disabled))return ; -atomic_inc (&data->disabled); +local_inc (&data->disabled); data->critical_sequence = max_sequence; data->preempt_timestamp =ftrace_now (cpu);
@@ -421,7 +421,7 @@ start_critical_timing(unsigned long ip, unsigned long parent_ip)per_cpu (tracing_cpu, cpu) =1 ; -atomic_dec (&data->disabled); +local_dec (&data->disabled); }static nokprobe_inline void
@@ -445,16 +445,16 @@ stop_critical_timing(unsigned long ip, unsigned long parent_ip) data =per_cpu_ptr (tr->array_buffer.data, cpu);if (unlikely (!data) || - !data->critical_start ||atomic_read (&data->disabled)) + !data->critical_start ||local_read (&data->disabled))return ; -atomic_inc (&data->disabled); +local_inc (&data->disabled); trace_ctx =tracing_gen_ctx ();__trace_function (tr, ip, parent_ip, trace_ctx);check_critical_timing (tr, data, parent_ip ? : ip, cpu); data->critical_start =0 ; -atomic_dec (&data->disabled); +local_dec (&data->disabled); }/* start and stop critical timings used to for stoppage (in idle) */
kernel/trace/trace_sched_wakeup.c +9 -9
@@ -83,14 +83,14 @@ func_prolog_preempt_disable(struct trace_array *tr, goto out_enable; *data =per_cpu_ptr (tr->array_buffer.data, cpu); - disabled =atomic_inc_return (&(*data)->disabled); + disabled =local_inc_return (&(*data)->disabled);if (unlikely (disabled !=1 )) goto out;return 1 ; out: -atomic_dec (&(*data)->disabled); +local_dec (&(*data)->disabled); out_enable:preempt_enable_notrace ();
@@ -144,7 +144,7 @@ static int wakeup_graph_entry(struct ftrace_graph_ent *trace, *calltime =trace_clock_local (); ret =__trace_graph_entry (tr, trace, trace_ctx); -atomic_dec (&data->disabled); +local_dec (&data->disabled);preempt_enable_notrace ();return ret;
@@ -173,7 +173,7 @@ static void wakeup_graph_return(struct ftrace_graph_ret *trace,return ;__trace_graph_return (tr, trace, trace_ctx, *calltime, rettime); -atomic_dec (&data->disabled); +local_dec (&data->disabled);preempt_enable_notrace ();return ;
@@ -243,7 +243,7 @@ wakeup_tracer_call(unsigned long ip, unsigned long parent_ip,trace_function (tr, ip, parent_ip, trace_ctx, fregs);local_irq_restore (flags); -atomic_dec (&data->disabled); +local_dec (&data->disabled);preempt_enable_notrace (); }
@@ -471,7 +471,7 @@ probe_wakeup_sched_switch(void *ignore, bool preempt,/* disable local data, not wakeup_cpu data */ cpu =raw_smp_processor_id (); - disabled =atomic_inc_return (&per_cpu_ptr (wakeup_trace->array_buffer.data, cpu)->disabled); + disabled =local_inc_return (&per_cpu_ptr (wakeup_trace->array_buffer.data, cpu)->disabled);if (likely (disabled !=1 )) goto out;
@@ -508,7 +508,7 @@ probe_wakeup_sched_switch(void *ignore, bool preempt,arch_spin_unlock (&wakeup_lock);local_irq_restore (flags); out: -atomic_dec (&per_cpu_ptr (wakeup_trace->array_buffer.data, cpu)->disabled); +local_dec (&per_cpu_ptr (wakeup_trace->array_buffer.data, cpu)->disabled); }static void __wakeup_reset (struct trace_array *tr)
@@ -563,7 +563,7 @@ probe_wakeup(void *ignore, struct task_struct *p) (!dl_task(p) && (p->prio >= wakeup_prio || p->prio >= current->prio))) return; - disabled =atomic_inc_return (&per_cpu_ptr (wakeup_trace->array_buffer.data, cpu)->disabled); + disabled =local_inc_return (&per_cpu_ptr (wakeup_trace->array_buffer.data, cpu)->disabled);if (unlikely (disabled !=1 )) goto out;
@@ -610,7 +610,7 @@ probe_wakeup(void *ignore, struct task_struct *p) out_locked:arch_spin_unlock (&wakeup_lock); out: -atomic_dec (&per_cpu_ptr (wakeup_trace->array_buffer.data, cpu)->disabled); +local_dec (&per_cpu_ptr (wakeup_trace->array_buffer.data, cpu)->disabled); }static void start_wakeup_tracer (struct trace_array *tr)
Signature · 1 line
2.47.2
Steven Rostedt
maintainerPATCH v2 12/13 tracing: Use atomic_inc_return() for updating "disabled" counter in irqsoff tracer
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
The irqsoff tracer uses the per CPU "disabled" field to prevent corruption of the accounting when it starts to trace interrupts disabled, but there's a slight race that could happen if for some reason it was called twice. Use atomic_inc_return() instead.
--- kernel/trace/trace_irqsoff.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-)
kernel/trace/trace_irqsoff.c +18 -11
@@ -397,6 +397,7 @@ start_critical_timing(unsigned long ip, unsigned long parent_ip)int cpu;struct trace_array *tr = irqsoff_trace;struct trace_array_cpu *data; +long disabled;if (!tracer_enabled || !tracing_is_enabled ())return ;
@@ -411,15 +412,17 @@ start_critical_timing(unsigned long ip, unsigned long parent_ip)if (unlikely (!data) ||local_read (&data->disabled))return ; -local_inc (&data->disabled); + disabled =local_inc_return (&data->disabled); - data->critical_sequence = max_sequence; - data->preempt_timestamp =ftrace_now (cpu); - data->critical_start = parent_ip ? : ip; +if (disabled ==1 ) { + data->critical_sequence = max_sequence; + data->preempt_timestamp =ftrace_now (cpu); + data->critical_start = parent_ip ? : ip; -__trace_function (tr, ip, parent_ip,tracing_gen_ctx ()); +__trace_function (tr, ip, parent_ip,tracing_gen_ctx ()); -per_cpu (tracing_cpu, cpu) =1 ; +per_cpu (tracing_cpu, cpu) =1 ; + }local_dec (&data->disabled); }
@@ -431,6 +434,7 @@ stop_critical_timing(unsigned long ip, unsigned long parent_ip)struct trace_array *tr = irqsoff_trace;struct trace_array_cpu *data;unsigned int trace_ctx; +long disabled; cpu =raw_smp_processor_id ();/* Always clear the tracing cpu on stopping the trace */
@@ -448,12 +452,15 @@ stop_critical_timing(unsigned long ip, unsigned long parent_ip) !data->critical_start || local_read(&data->disabled)) return; -local_inc (&data->disabled); + disabled =local_inc_return (&data->disabled); + +if (disabled ==1 ) { + trace_ctx =tracing_gen_ctx (); +__trace_function (tr, ip, parent_ip, trace_ctx); +check_critical_timing (tr, data, parent_ip ? : ip, cpu); + data->critical_start =0 ; + } - trace_ctx =tracing_gen_ctx (); -__trace_function (tr, ip, parent_ip, trace_ctx); -check_critical_timing (tr, data, parent_ip ? : ip, cpu); - data->critical_start =0 ;local_dec (&data->disabled); }
Signature · 1 line
2.47.2
Steven Rostedt
maintainerPATCH v2 13/13 tracing: Remove unused buffer_page field from trace_array_cpu structure
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
The trace_array_cpu had a "buffer_page" field that was originally going to be used as a backup page for the ring buffer. But the ring buffer has its own way of reusing pages and this field was never used.
Remove it.
--- kernel/trace/trace.h | 1 - 1 file changed, 1 deletion(-)
kernel/trace/trace.h +0 -1
@@ -184,7 +184,6 @@ struct trace_array;*/ struct trace_array_cpu {local_t disabled; -void *buffer_page;/* ring buffer spare */ unsigned long entries;unsigned long saved_latency;
Signature · 1 line
2.47.2