Skip to content

Commit 575380d

Browse files
Steven Rostedt (Red Hat)rostedt
authored andcommitted
tracing: Only clear trace buffer on module unload if event was traced
Currently, when a module with events is unloaded, the trace buffer is cleared. This is just a safety net in case the module might have some strange callback when its event is outputted. But there's no reason to reset the buffer if the module didn't have any of its events traced. Add a flag to the event "call" structure called WAS_ENABLED and gets set when the event is ever enabled, and this flag never gets cleared. When a module gets unloaded, if any of its events have this flag set, then the trace buffer will get cleared. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent 2a30c11 commit 575380d

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

include/linux/ftrace_event.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ enum {
197197
TRACE_EVENT_FL_CAP_ANY_BIT,
198198
TRACE_EVENT_FL_NO_SET_FILTER_BIT,
199199
TRACE_EVENT_FL_IGNORE_ENABLE_BIT,
200+
TRACE_EVENT_FL_WAS_ENABLED_BIT,
200201
};
201202

202203
/*
@@ -205,12 +206,16 @@ enum {
205206
* CAP_ANY - Any user can enable for perf
206207
* NO_SET_FILTER - Set when filter has error and is to be ignored
207208
* IGNORE_ENABLE - For ftrace internal events, do not enable with debugfs file
209+
* WAS_ENABLED - Set and stays set when an event was ever enabled
210+
* (used for module unloading, if a module event is enabled,
211+
* it is best to clear the buffers that used it).
208212
*/
209213
enum {
210214
TRACE_EVENT_FL_FILTERED = (1 << TRACE_EVENT_FL_FILTERED_BIT),
211215
TRACE_EVENT_FL_CAP_ANY = (1 << TRACE_EVENT_FL_CAP_ANY_BIT),
212216
TRACE_EVENT_FL_NO_SET_FILTER = (1 << TRACE_EVENT_FL_NO_SET_FILTER_BIT),
213217
TRACE_EVENT_FL_IGNORE_ENABLE = (1 << TRACE_EVENT_FL_IGNORE_ENABLE_BIT),
218+
TRACE_EVENT_FL_WAS_ENABLED = (1 << TRACE_EVENT_FL_WAS_ENABLED_BIT),
214219
};
215220

216221
struct ftrace_event_call {

kernel/trace/trace_events.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,9 @@ static int ftrace_event_enable_disable(struct ftrace_event_file *file,
245245
break;
246246
}
247247
file->flags |= FTRACE_EVENT_FL_ENABLED;
248+
249+
/* WAS_ENABLED gets set but never cleared. */
250+
call->flags |= TRACE_EVENT_FL_WAS_ENABLED;
248251
}
249252
break;
250253
}
@@ -1626,12 +1629,13 @@ static void trace_module_remove_events(struct module *mod)
16261629
{
16271630
struct ftrace_module_file_ops *file_ops;
16281631
struct ftrace_event_call *call, *p;
1629-
bool found = false;
1632+
bool clear_trace = false;
16301633

16311634
down_write(&trace_event_mutex);
16321635
list_for_each_entry_safe(call, p, &ftrace_events, list) {
16331636
if (call->mod == mod) {
1634-
found = true;
1637+
if (call->flags & TRACE_EVENT_FL_WAS_ENABLED)
1638+
clear_trace = true;
16351639
__trace_remove_event_call(call);
16361640
}
16371641
}
@@ -1648,9 +1652,9 @@ static void trace_module_remove_events(struct module *mod)
16481652

16491653
/*
16501654
* It is safest to reset the ring buffer if the module being unloaded
1651-
* registered any events.
1655+
* registered any events that were used.
16521656
*/
1653-
if (found)
1657+
if (clear_trace)
16541658
tracing_reset_current_online_cpus();
16551659
up_write(&trace_event_mutex);
16561660
}

0 commit comments

Comments
 (0)