Skip to content

Commit 1cffbe6

Browse files
valschneiderrostedt
authored andcommitted
tracing/filters: Optimise CPU vs cpumask filtering when the user mask is a single CPU
Steven noted that when the user-provided cpumask contains a single CPU, then the filtering function can use a scalar as input instead of a full-fledged cpumask. In this case we can directly re-use filter_pred_cpu(), we just need to transform '&' into '==' before executing it. Link: https://lkml.kernel.org/r/20230707172155.70873-8-vschneid@redhat.com Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Juri Lelli <juri.lelli@redhat.com> Cc: Daniel Bristot de Oliveira <bristot@redhat.com> Cc: Marcelo Tosatti <mtosatti@redhat.com> Cc: Leonardo Bras <leobras@redhat.com> Cc: Frederic Weisbecker <frederic@kernel.org> Suggested-by: Steven Rostedt <rostedt@goodmis.org> Signed-off-by: Valentin Schneider <vschneid@redhat.com> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent ca77dd8 commit 1cffbe6

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

kernel/trace/trace_events_filter.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,7 +1750,7 @@ static int parse_pred(const char *str, void *data,
17501750
* then we can treat it as a scalar input.
17511751
*/
17521752
single = cpumask_weight(pred->mask) == 1;
1753-
if (single && field->filter_type != FILTER_CPU) {
1753+
if (single) {
17541754
pred->val = cpumask_first(pred->mask);
17551755
kfree(pred->mask);
17561756
}
@@ -1760,7 +1760,12 @@ static int parse_pred(const char *str, void *data,
17601760
FILTER_PRED_FN_CPUMASK_CPU :
17611761
FILTER_PRED_FN_CPUMASK;
17621762
} else if (field->filter_type == FILTER_CPU) {
1763-
pred->fn_num = FILTER_PRED_FN_CPU_CPUMASK;
1763+
if (single) {
1764+
pred->op = pred->op == OP_BAND ? OP_EQ : pred->op;
1765+
pred->fn_num = FILTER_PRED_FN_CPU;
1766+
} else {
1767+
pred->fn_num = FILTER_PRED_FN_CPU_CPUMASK;
1768+
}
17641769
} else if (single) {
17651770
pred->op = pred->op == OP_BAND ? OP_EQ : pred->op;
17661771
pred->fn_num = select_comparison_fn(pred->op, field->size, false);

0 commit comments

Comments
 (0)