trace: tracing_event_filter: fast path when no subsystem filters
PATCH 1/1 trace: tracing_event_filter: fast path when no subsystem filters
From: Nicholas Lowell <[email protected]>
If there are no filters in the event subsystem, then there's no reason to continue and hit the potentially time consuming tracepoint_synchronize_unregister function. This should give a speed up for initial disabling/configuring
--- kernel/trace/trace_events_filter.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
kernel/trace/trace_events_filter.c +14 -5
@@ -1317,22 +1317,29 @@ void free_event_filter(struct event_filter *filter)__free_filter (filter); } -static inline void __remove_filter (struct trace_event_file *file) +static inline int __remove_filter (struct trace_event_file *file) {filter_disable (file); -remove_filter_string (file->filter); +if (file->filter) +remove_filter_string (file->filter); +else +return 0 ; + +return 1 ; } -static void filter_free_subsystem_preds (struct trace_subsystem_dir *dir, +static int filter_free_subsystem_preds (struct trace_subsystem_dir *dir,struct trace_array *tr) {struct trace_event_file *file; +int i =0 ;list_for_each_entry (file, &tr->events, list) {if (file->system != dir)continue ; -__remove_filter (file); + i +=__remove_filter (file); } +return i; }static inline void __free_subsystem_filter (struct trace_event_file *file)
@@ -2411,7 +2418,9 @@ int apply_subsystem_event_filter(struct trace_subsystem_dir *dir, }if (!strcmp (strstrip (filter_string),"0" )) { -filter_free_subsystem_preds (dir, tr); +if (filter_free_subsystem_preds (dir, tr) ==0 ) + goto out_unlock; +remove_filter_string (system->filter); filter = system->filter; system->filter =NULL ;
Signature · 1 line
2.25.1
Steven Rostedt
maintainerQuoted 21 lines · On Tue, 26 Sep 2023 10:20:58 -0400 Nicholas Lowell <[email protected]>…
From: Nicholas Lowell <[email protected]>
If there are no filters in the event subsystem, then there's no reason to continue and hit the potentially time consuming
tracepoint_synchronize_unregisterfunction. This should give a speed up for initial disabling/configuringSigned-off-by Nicholas Lowell <[email protected]>--- kernel/trace/trace_events_filter.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)kernel/trace/trace_events_filter.c +0
-1@@ -1317,22 +1317,29 @@ void free_event_filter(struct event_filter *filter)__free_filter (filter); } -static inline void __remove_filter (struct trace_event_file *file)
kernel/trace/trace_events_filter.c void free_event_filter(struct event_filter *filter) · line 1328
Quoted 10 lines
kernel/trace/trace_events_filter.c +7
-1+static inline int __remove_filter (struct trace_event_file *file) {filter_disable (file); -remove_filter_string (file->filter); +if (file->filter) +remove_filter_string (file->filter); +else +return 0 ; + +return 1 ;
The above looks awkward. What about:
if (!file->filter) return 0; remove_filter_string(file->filter); return 1;
?
Or better yet:
if (!file->filter) return false; remove_filter_string(file->filter); return true;
and ...
kernel/trace/trace_events_filter.c void free_event_filter(struct event_filter *filter) · line 1335
Quoted 8 lines
kernel/trace/trace_events_filter.c +2
-1} -static void filter_free_subsystem_preds (struct trace_subsystem_dir *dir, +static int filter_free_subsystem_preds (struct trace_subsystem_dir *dir,struct trace_array *tr) {struct trace_event_file *file; +int i =0 ;
We don't really need a counter. It's either do the synchronization or we don't.
bool do_sync = false;
kernel/trace/trace_events_filter.c void free_event_filter(struct event_filter *filter) · line 1340
Quoted 6 lines
kernel/trace/trace_events_filter.c +1
-1list_for_each_entry (file, &tr->events, list) {if (file->system != dir)continue ; -__remove_filter (file); + i +=__remove_filter (file);
if (remove_filter(file)) do_sync = true;
kernel/trace/trace_events_filter.c void free_event_filter(struct event_filter *filter) · line 1340
Quoted 1 line
kernel/trace/trace_events_filter.c +0
-0}
return do_sync;
kernel/trace/trace_events_filter.c int apply_subsystem_event_filter(struct trace_subsystem_dir *dir, · line 2423
Quoted 12 lines
kernel/trace/trace_events_filter.c +4
-1+return i; }static inline void __free_subsystem_filter (struct trace_event_file *file)@@ -2411,7 +2418,9 @@ int apply_subsystem_event_filter(struct trace_subsystem_dir *dir, }if (!strcmp (strstrip (filter_string),"0" )) { -filter_free_subsystem_preds (dir, tr); +if (filter_free_subsystem_preds (dir, tr) ==0 ) + goto out_unlock; +
/* If nothing was freed, we do not need to sync */ if (!filter_free_subsystem_preds(dir, tr)) goto out_unlock;
And yes, add the comment.
And actually, in that block with the goto out_unlock, we should have:
if (!filter_free_subsystem_preds(dir, tr)) {
if (!(WARN_ON_ONCE(system->filter))
goto out_unlock;
}If there were no preds, ideally there would be no subsystem filter. But if that's not the case, we need to warn about that and then continue.
-- Steve
Quoted 3 lines
kernel/trace/trace_events_filter.c +0
-0remove_filter_string (system->filter); filter = system->filter; system->filter =NULL ;
Sending again in plain text mode.
Thanks for the great feedback! Hopefully my inline comments/questions aren't garbled.
Quoted 46 lines · Steven Rostedt
Quoted 21 lines · On Tue, 26 Sep 2023 10:20:58 -0400 Nicholas Lowell <[email protected]>…
From: Nicholas Lowell <[email protected]>
If there are no filters in the event subsystem, then there's no reason to continue and hit the potentially time consuming
tracepoint_synchronize_unregisterfunction. This should give a speed up for initial disabling/configuringSigned-off-by Nicholas Lowell <[email protected]>--- kernel/trace/trace_events_filter.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)kernel/trace/trace_events_filter.c +0
-1@@ -1317,22 +1317,29 @@ void free_event_filter(struct event_filter *filter)__free_filter (filter); } -static inline void __remove_filter (struct trace_event_file *file)kernel/trace/trace_events_filter.c void free_event_filter(struct event_filter *filter) · line 1328
Quoted 10 lines
kernel/trace/trace_events_filter.c +7
-1+static inline int __remove_filter (struct trace_event_file *file) {filter_disable (file); -remove_filter_string (file->filter); +if (file->filter) +remove_filter_string (file->filter); +else +return 0 ; + +return 1 ;The above looks awkward. What about:
if (!file->filter) return 0; remove_filter_string(file->filter); return 1;?
Quoted 8 lines
Or better yet:
if (!file->filter) return false; remove_filter_string(file->filter); return true;
Is it safe to assume you would like the function's return type to change from int to bool if I go with option 2?
Quoted 23 lines
and ...
kernel/trace/trace_events_filter.c void free_event_filter(struct event_filter *filter) · line 1335
Quoted 8 lines
kernel/trace/trace_events_filter.c +2
-1} -static void filter_free_subsystem_preds (struct trace_subsystem_dir *dir, +static int filter_free_subsystem_preds (struct trace_subsystem_dir *dir,struct trace_array *tr) {struct trace_event_file *file; +int i =0 ;We don't really need a counter. It's either do the synchronization or we don't.
bool do_sync = false;kernel/trace/trace_events_filter.c void free_event_filter(struct event_filter *filter) · line 1340
Quoted 6 lines
kernel/trace/trace_events_filter.c +1
-1list_for_each_entry (file, &tr->events, list) {if (file->system != dir)continue ; -__remove_filter (file); + i +=__remove_filter (file);
Quoted 7 lines
if (remove_filter(file)) do_sync = true;kernel/trace/trace_events_filter.c void free_event_filter(struct event_filter *filter) · line 1340
Quoted 1 line
kernel/trace/trace_events_filter.c +0
-0}return do_sync;
Going to assume the same here--that return type should change from int to bool.
Quoted 17 lines
kernel/trace/trace_events_filter.c int apply_subsystem_event_filter(struct trace_subsystem_dir *dir, · line 2423
Quoted 12 lines
kernel/trace/trace_events_filter.c +4
-1+return i; }static inline void __free_subsystem_filter (struct trace_event_file *file)@@ -2411,7 +2418,9 @@ int apply_subsystem_event_filter(struct trace_subsystem_dir *dir, }if (!strcmp (strstrip (filter_string),"0" )) { -filter_free_subsystem_preds (dir, tr); +if (filter_free_subsystem_preds (dir, tr) ==0 ) + goto out_unlock; +/* If nothing was freed, we do not need to sync */ if (!filter_free_subsystem_preds(dir, tr)) goto out_unlock;
Quoted 9 lines
And yes, add the comment.
And actually, in that block with the goto
out_unlock, we should have:if (!filter_free_subsystem_preds(dir, tr)) { if (!(WARN_ON_ONCE(system->filter)) goto out_unlock; }
Can you explain why the WARN_ON_ONCE should be in a conditional? Don't we still want the original conditional to cause the goto regardless?
if (!filter_free_subsystem_preds(dir, tr)) {
WARN_ON_ONCE(system->filter);
goto out_unlock;
}Quoted 9 lines
If there were no preds, ideally there would be no subsystem filter. But if that's not the case, we need to warn about that and then continue.
-- Steve
Quoted 3 lines
kernel/trace/trace_events_filter.c +0
-0remove_filter_string (system->filter); filter = system->filter; system->filter =NULL ;
Steven Rostedt
maintainerQuoted 16 lines · On Mon, 2 Oct 2023 09:57:34 -0400 Nick Lowell <[email protected]> wrote:
Quoted 16 lines
The above looks awkward. What about:
if (!file->filter) return 0; remove_filter_string(file->filter); return 1;?
Or better yet:
if (!file->filter) return false;
Quoted 6 lines
Quoted 4 lines
remove_filter_string(file->filter); return true;Is it safe to assume you would like the function's return type to change from int to bool if I go with option 2?
Yes.
Quoted 28 lines
Quoted 28 lines
and ...
kernel/trace/trace_events_filter.c void free_event_filter(struct event_filter *filter) · line 1335
Quoted 8 lines
}
kernel/trace/trace_events_filter.c +2
-1-static void filter_free_subsystem_preds (struct trace_subsystem_dir *dir, +static int filter_free_subsystem_preds (struct trace_subsystem_dir *dir,struct trace_array *tr) {struct trace_event_file *file; +int i =0 ;We don't really need a counter. It's either do the synchronization or we don't.
bool do_sync = false;kernel/trace/trace_events_filter.c void free_event_filter(struct event_filter *filter) · line 1340
Quoted 6 lines
list_for_each_entry(file, &tr->events, list) { if (file->system != dir) continue;kernel/trace/trace_events_filter.c +1
-1-__remove_filter (file); + i +=__remove_filter (file);if (remove_filter(file)) do_sync = true;
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
}return do_sync;Going to assume the same here--that return type should change from int to bool.
Correct.
Quoted 30 lines
Quoted 20 lines
Quoted 5 lines
+ return i;
}static inline void __free_subsystem_filter(struct
trace_event_file*file)
Review int apply_subsystem_event_filter(struct
Quoted 1 line
(quoted diff) +0
-0@@ -2411,7 +2418,9 @@ int apply_subsystem_event_filter(struct
trace_subsystem_dir*dir,kernel/trace/trace_events_filter.c int apply_subsystem_event_filter(struct trace_subsystem_dir *dir, · line 2423
Quoted 7 lines
kernel/trace/trace_events_filter.c +3
-1}if (!strcmp (strstrip (filter_string),"0" )) { -filter_free_subsystem_preds (dir, tr); +if (filter_free_subsystem_preds (dir, tr) ==0 ) + goto out_unlock; +/* If nothing was freed, we do not need to sync */ if (!filter_free_subsystem_preds(dir, tr)) goto out_unlock;Quoted 10 lines
And yes, add the comment.
And actually, in that block with the goto
out_unlock, we should have:if (!filter_free_subsystem_preds(dir, tr)) { if (!(WARN_ON_ONCE(system->filter)) goto out_unlock; }
Quoted 4 lines
Can you explain why the
WARN_ON_ONCEshould be in a conditional.Don't we still want the original conditional to cause the goto regardless?
Because if it exists, we still want to free it and do the synchronization, and set it to NULL. In other words, it means we missed something and need to revert back to the original behavior.
The WARN_ON_ONCE() documents that we never expect that to happen, and if it does, it means we have a bug.
-- Steve
Quoted 7 lines
if (!filter_free_subsystem_preds(dir, tr)) {
WARN_ON_ONCE(system->filter);
goto out_unlock;
}