Skip to content

Commit

Permalink
tracing: Only add filter list when needed
Browse files Browse the repository at this point in the history
replace_system_preds() creates a filter list to free even when it doesn't
really need to have it. Only save filters that require synchronize_sched()
in the filter list to free. This will allow the code to be updated a bit
easier in the future.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
  • Loading branch information
Steven Rostedt (VMware) committed Mar 10, 2018
1 parent c739970 commit 404a3ad
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions kernel/trace/trace_events_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1769,6 +1769,7 @@ static int replace_system_preds(struct trace_subsystem_dir *dir,
{
struct trace_event_file *file;
struct filter_list *filter_item;
struct event_filter *filter = NULL;
struct filter_list *tmp;
LIST_HEAD(filter_list);
bool fail = true;
Expand All @@ -1790,24 +1791,16 @@ static int replace_system_preds(struct trace_subsystem_dir *dir,
}

list_for_each_entry(file, &tr->events, list) {
struct event_filter *filter;

if (file->system != dir)
continue;

if (event_no_set_filter_flag(file))
continue;

filter_item = kzalloc(sizeof(*filter_item), GFP_KERNEL);
if (!filter_item)
goto fail_mem;

list_add_tail(&filter_item->list, &filter_list);

filter_item->filter = kzalloc(sizeof(*filter), GFP_KERNEL);
if (!filter_item->filter)
filter = kzalloc(sizeof(*filter), GFP_KERNEL);
if (!filter)
goto fail_mem;
filter = filter_item->filter;

/* Can only fail on no memory */
err = replace_filter_string(filter, filter_string);
Expand All @@ -1821,13 +1814,20 @@ static int replace_system_preds(struct trace_subsystem_dir *dir,
append_filter_err(ps, filter);
} else
event_set_filtered_flag(file);


filter_item = kzalloc(sizeof(*filter_item), GFP_KERNEL);
if (!filter_item)
goto fail_mem;

list_add_tail(&filter_item->list, &filter_list);
/*
* Regardless of if this returned an error, we still
* replace the filter for the call.
*/
filter = event_filter(file);
event_set_filter(file, filter_item->filter);
filter_item->filter = filter;
filter_item->filter = event_filter(file);
event_set_filter(file, filter);
filter = NULL;

fail = false;
}
Expand Down Expand Up @@ -1856,6 +1856,7 @@ static int replace_system_preds(struct trace_subsystem_dir *dir,
parse_error(ps, FILT_ERR_BAD_SUBSYS_FILTER, 0);
return -EINVAL;
fail_mem:
kfree(filter);
/* If any call succeeded, we still need to sync */
if (!fail)
synchronize_sched();
Expand Down

0 comments on commit 404a3ad

Please sign in to comment.