History

tracing: Add tracing_reset_all_online_cpus_unlocked() function

Currently the tracing_reset_all_online_cpus() requires the trace_types_lock held. But only one caller of this function actually has that lock held before calling it, and the other just takes the lock so that it can call it. More users of this function is needed where the lock is not held. Add a tracing_reset_all_online_cpus_unlocked() function for the one use case that calls it without being held, and also add a lockdep_assert to make sure it is held when called. Then have tracing_reset_all_online_cpus() take the lock internally, such that callers do not need to worry about taking it. Link: https://lkml.kernel.org/r/20221123192741.658273220@goodmis.org

Steven Rostedt (Google) committed 3 years ago

Commit e18eb871 parent ef38c794 files · +12 −4Browse files

Unified · Split

4 files
  1. kernel/trace/trace.c +10 −1
  2. kernel/trace/trace.h +1 −0
  3. kernel/trace/trace_events.c +1 −1
  4. kernel/trace/trace_events_synth.c +0 −2
kernel/trace/trace.c+10−1
@@ -2180,10 +2180,12 @@ void tracing_reset_online_cpus(struct array_buffer *buf) · 2179 unmodified lines
21802180 }
21812181
21822182 /* Must have trace_types_lock held */
2183−void tracing_reset_all_online_cpus(void)
2183+void tracing_reset_all_online_cpus_unlocked(void)
21842184 {
21852185 struct trace_array *tr;
21862186
2187+ lockdep_assert_held(&trace_types_lock);
2188+
21872189 list_for_each_entry(tr, &ftrace_trace_arrays, list) {
21882190 if (!tr->clear_trace)
21892191 continue;
@@ -2195,6 +2197,13 @@ void tracing_reset_all_online_cpus(void) · 5 unmodified lines
21952197 }
21962198 }
21972199
2200+void tracing_reset_all_online_cpus(void)
2201+{
2202+ mutex_lock(&trace_types_lock);
2203+ tracing_reset_all_online_cpus_unlocked();
2204+ mutex_unlock(&trace_types_lock);
2205+}
2206+
21982207 /*
21992208 * The tgid_map array maps from pid to tgid; i.e. the value stored at index i
22002209 * is the tgid last observed corresponding to pid=i.
kernel/trace/trace.h+1−0
@@ -580,6 +580,7 @@ int tracing_is_enabled(void); · 579 unmodified lines
580580 void tracing_reset_online_cpus(struct array_buffer *buf);
581581 void tracing_reset_current(int cpu);
582582 void tracing_reset_all_online_cpus(void);
583+void tracing_reset_all_online_cpus_unlocked(void);
583584 int tracing_open_generic(struct inode *inode, struct file *filp);
584585 int tracing_open_generic_tr(struct inode *inode, struct file *filp);
585586 bool tracing_is_disabled(void);
kernel/trace/trace_events.c+1−1
@@ -2972,7 +2972,7 @@ static void trace_module_remove_events(struct module *mod) · 2971 unmodified lines
29722972 * over from this module may be passed to the new module events and
29732973 * unexpected results may occur.
29742974 */
2975− tracing_reset_all_online_cpus();
2975+ tracing_reset_all_online_cpus_unlocked();
29762976 }
29772977
29782978 static int trace_module_notify(struct notifier_block *self,
kernel/trace/trace_events_synth.c+0−2
@@ -1425,7 +1425,6 @@ int synth_event_delete(const char *event_name) · 1424 unmodified lines
14251425 mutex_unlock(&event_mutex);
14261426
14271427 if (mod) {
1428− mutex_lock(&trace_types_lock);
14291428 /*
14301429 * It is safest to reset the ring buffer if the module
14311430 * being unloaded registered any events that were
@@ -1437,7 +1436,6 @@ int synth_event_delete(const char *event_name) · 5 unmodified lines
14371436 * occur.
14381437 */
14391438 tracing_reset_all_online_cpus();
1440− mutex_unlock(&trace_types_lock);
14411439 }
14421440
14431441 return ret;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t