Skip to content

Commit fe4fa4e

Browse files
valschneiderrostedt
authored andcommitted
tracing/filters: Optimise cpumask vs cpumask filtering when 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. Reuse do_filter_scalar_cpumask() when the input mask has a weight of one. Link: https://lkml.kernel.org/r/[email protected] Cc: Masami Hiramatsu <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Juri Lelli <[email protected]> Cc: Daniel Bristot de Oliveira <[email protected]> Cc: Marcelo Tosatti <[email protected]> Cc: Leonardo Bras <[email protected]> Cc: Frederic Weisbecker <[email protected]> Suggested-by: Steven Rostedt <[email protected]> Signed-off-by: Valentin Schneider <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 347d24f commit fe4fa4e

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

kernel/trace/trace_events_filter.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ enum filter_pred_fn {
7070
FILTER_PRED_FN_CPU,
7171
FILTER_PRED_FN_CPU_CPUMASK,
7272
FILTER_PRED_FN_CPUMASK,
73+
FILTER_PRED_FN_CPUMASK_CPU,
7374
FILTER_PRED_FN_FUNCTION,
7475
FILTER_PRED_FN_,
7576
FILTER_PRED_TEST_VISITED,
@@ -957,6 +958,22 @@ static int filter_pred_cpumask(struct filter_pred *pred, void *event)
957958
return do_filter_cpumask(pred->op, mask, cmp);
958959
}
959960

961+
/* Filter predicate for cpumask field vs user-provided scalar */
962+
static int filter_pred_cpumask_cpu(struct filter_pred *pred, void *event)
963+
{
964+
u32 item = *(u32 *)(event + pred->offset);
965+
int loc = item & 0xffff;
966+
const struct cpumask *mask = (event + loc);
967+
unsigned int cpu = pred->val;
968+
969+
/*
970+
* This inverts the usual usage of the function (field is first element,
971+
* user parameter is second), but that's fine because the (scalar, mask)
972+
* operations used are symmetric.
973+
*/
974+
return do_filter_scalar_cpumask(pred->op, cpu, mask);
975+
}
976+
960977
/* Filter predicate for COMM. */
961978
static int filter_pred_comm(struct filter_pred *pred, void *event)
962979
{
@@ -1453,6 +1470,8 @@ static int filter_pred_fn_call(struct filter_pred *pred, void *event)
14531470
return filter_pred_cpu_cpumask(pred, event);
14541471
case FILTER_PRED_FN_CPUMASK:
14551472
return filter_pred_cpumask(pred, event);
1473+
case FILTER_PRED_FN_CPUMASK_CPU:
1474+
return filter_pred_cpumask_cpu(pred, event);
14561475
case FILTER_PRED_FN_FUNCTION:
14571476
return filter_pred_function(pred, event);
14581477
case FILTER_PRED_TEST_VISITED:
@@ -1666,6 +1685,7 @@ static int parse_pred(const char *str, void *data,
16661685

16671686
} else if (!strncmp(str + i, "CPUS", 4)) {
16681687
unsigned int maskstart;
1688+
bool single;
16691689
char *tmp;
16701690

16711691
switch (field->filter_type) {
@@ -1724,8 +1744,21 @@ static int parse_pred(const char *str, void *data,
17241744

17251745
/* Move along */
17261746
i++;
1747+
1748+
/*
1749+
* Optimisation: if the user-provided mask has a weight of one
1750+
* then we can treat it as a scalar input.
1751+
*/
1752+
single = cpumask_weight(pred->mask) == 1;
1753+
if (single && field->filter_type == FILTER_CPUMASK) {
1754+
pred->val = cpumask_first(pred->mask);
1755+
kfree(pred->mask);
1756+
}
1757+
17271758
if (field->filter_type == FILTER_CPUMASK) {
1728-
pred->fn_num = FILTER_PRED_FN_CPUMASK;
1759+
pred->fn_num = single ?
1760+
FILTER_PRED_FN_CPUMASK_CPU :
1761+
FILTER_PRED_FN_CPUMASK;
17291762
} else if (field->filter_type == FILTER_CPU) {
17301763
pred->fn_num = FILTER_PRED_FN_CPU_CPUMASK;
17311764
} else {

0 commit comments

Comments
 (0)