Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tracing/filters: Further optimise scalar vs cpumask comparison

Per the previous commits, we now only enter do_filter_scalar_cpumask() with
a mask of weight greater than one. Optimise the equality checks.

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

authored by

Valentin Schneider and committed by
Steven Rostedt (Google)
38c6f680 1cffbe6c

+20 -6
+20 -6
kernel/trace/trace_events_filter.c
··· 668 668 static inline int 669 669 do_filter_scalar_cpumask(int op, unsigned int cpu, const struct cpumask *mask) 670 670 { 671 + /* 672 + * Per the weight-of-one cpumask optimisations, the mask passed in this 673 + * function has a weight >= 2, so it is never equal to a single scalar. 674 + */ 675 + switch (op) { 676 + case OP_EQ: 677 + return false; 678 + case OP_NE: 679 + return true; 680 + case OP_BAND: 681 + return cpumask_test_cpu(cpu, mask); 682 + default: 683 + return 0; 684 + } 685 + } 686 + 687 + static inline int 688 + do_filter_cpumask_scalar(int op, const struct cpumask *mask, unsigned int cpu) 689 + { 671 690 switch (op) { 672 691 case OP_EQ: 673 692 return cpumask_test_cpu(cpu, mask) && ··· 985 966 const struct cpumask *mask = (event + loc); 986 967 unsigned int cpu = pred->val; 987 968 988 - /* 989 - * This inverts the usual usage of the function (field is first element, 990 - * user parameter is second), but that's fine because the (scalar, mask) 991 - * operations used are symmetric. 992 - */ 993 - return do_filter_scalar_cpumask(pred->op, cpu, mask); 969 + return do_filter_cpumask_scalar(pred->op, mask, cpu); 994 970 } 995 971 996 972 /* Filter predicate for COMM. */