Skip to content

Commit e18eb87

Browse files
committed
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/[email protected] Cc: Masami Hiramatsu <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Zheng Yejian <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent ef38c79 commit e18eb87

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

kernel/trace/trace.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2180,10 +2180,12 @@ void tracing_reset_online_cpus(struct array_buffer *buf)
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)
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ int tracing_is_enabled(void);
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2972,7 +2972,7 @@ static void trace_module_remove_events(struct module *mod)
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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,7 +1425,6 @@ int synth_event_delete(const char *event_name)
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)
14371436
* occur.
14381437
*/
14391438
tracing_reset_all_online_cpus();
1440-
mutex_unlock(&trace_types_lock);
14411439
}
14421440

14431441
return ret;

0 commit comments

Comments
 (0)