tracing/filters: Optimise scalar vs cpumask filtering when the user mask is a single CPU
authorValentin Schneider <vschneid@redhat.com>
Fri, 7 Jul 2023 17:21:52 +0000 (18:21 +0100)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Tue, 22 Aug 2023 09:13:29 +0000 (05:13 -0400)
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.

When the mask contains a single CPU, directly re-use the unsigned field
predicate functions. Transform '&' into '==' beforehand.

Link: https://lkml.kernel.org/r/20230707172155.70873-7-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>
kernel/trace/trace_events_filter.c

index 2fe65dd..54d642f 100644 (file)
@@ -1750,7 +1750,7 @@ static int parse_pred(const char *str, void *data,
                 * then we can treat it as a scalar input.
                 */
                single = cpumask_weight(pred->mask) == 1;
-               if (single && field->filter_type == FILTER_CPUMASK) {
+               if (single && field->filter_type != FILTER_CPU) {
                        pred->val = cpumask_first(pred->mask);
                        kfree(pred->mask);
                }
@@ -1761,6 +1761,11 @@ static int parse_pred(const char *str, void *data,
                                FILTER_PRED_FN_CPUMASK;
                } else if (field->filter_type == FILTER_CPU) {
                        pred->fn_num = FILTER_PRED_FN_CPU_CPUMASK;
+               } else if (single) {
+                       pred->op = pred->op == OP_BAND ? OP_EQ : pred->op;
+                       pred->fn_num = select_comparison_fn(pred->op, field->size, false);
+                       if (pred->op == OP_NE)
+                               pred->not = 1;
                } else {
                        switch (field->size) {
                        case 8: