Commit f30120fc authored by Jiri Olsa's avatar Jiri Olsa Committed by Steven Rostedt

tracing/filter: Change filter_match_preds function to use walk_pred_tree

Changing filter_match_preds function to use unified predicates tree
processing.
Signed-off-by: default avatarJiri Olsa <jolsa@redhat.com>
Link: http://lkml.kernel.org/r/1313072754-4620-10-git-send-email-jolsa@redhat.comSigned-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
parent 96bc293a
...@@ -467,6 +467,7 @@ static int process_ops(struct filter_pred *preds, ...@@ -467,6 +467,7 @@ static int process_ops(struct filter_pred *preds,
for (i = 0; i < op->val; i++) { for (i = 0; i < op->val; i++) {
pred = &preds[op->ops[i]]; pred = &preds[op->ops[i]];
if (!WARN_ON_ONCE(!pred->fn))
match = pred->fn(pred, rec); match = pred->fn(pred, rec);
if (!!match == type) if (!!match == type)
return match; return match;
...@@ -474,60 +475,33 @@ static int process_ops(struct filter_pred *preds, ...@@ -474,60 +475,33 @@ static int process_ops(struct filter_pred *preds,
return match; return match;
} }
/* return 1 if event matches, 0 otherwise (discard) */ struct filter_match_preds_data {
int filter_match_preds(struct event_filter *filter, void *rec)
{
int match = -1;
enum move_type move = MOVE_DOWN;
struct filter_pred *preds; struct filter_pred *preds;
struct filter_pred *pred; int match;
struct filter_pred *root; void *rec;
int n_preds; };
int done = 0;
/* no filter is considered a match */
if (!filter)
return 1;
n_preds = filter->n_preds;
if (!n_preds)
return 1;
/*
* n_preds, root and filter->preds are protect with preemption disabled.
*/
preds = rcu_dereference_sched(filter->preds);
root = rcu_dereference_sched(filter->root);
if (!root)
return 1;
pred = root;
/* match is currently meaningless */ static int filter_match_preds_cb(enum move_type move, struct filter_pred *pred,
match = -1; int *err, void *data)
{
struct filter_match_preds_data *d = data;
do { *err = 0;
switch (move) { switch (move) {
case MOVE_DOWN: case MOVE_DOWN:
/* only AND and OR have children */ /* only AND and OR have children */
if (pred->left != FILTER_PRED_INVALID) { if (pred->left != FILTER_PRED_INVALID) {
/* If ops is set, then it was folded. */ /* If ops is set, then it was folded. */
if (!pred->ops) { if (!pred->ops)
/* keep going to down the left side */ return WALK_PRED_DEFAULT;
pred = &preds[pred->left];
continue;
}
/* We can treat folded ops as a leaf node */ /* We can treat folded ops as a leaf node */
match = process_ops(preds, pred, rec); d->match = process_ops(d->preds, pred, d->rec);
} else } else {
match = pred->fn(pred, rec); if (!WARN_ON_ONCE(!pred->fn))
/* If this pred is the only pred */ d->match = pred->fn(pred, d->rec);
if (pred == root) }
break;
pred = get_pred_parent(pred, preds, return WALK_PRED_PARENT;
pred->parent, &move);
continue;
case MOVE_UP_FROM_LEFT: case MOVE_UP_FROM_LEFT:
/* /*
* Check for short circuits. * Check for short circuits.
...@@ -537,29 +511,47 @@ int filter_match_preds(struct event_filter *filter, void *rec) ...@@ -537,29 +511,47 @@ int filter_match_preds(struct event_filter *filter, void *rec)
* if ((match && pred->op == OP_OR) || * if ((match && pred->op == OP_OR) ||
* (!match && pred->op == OP_AND)) * (!match && pred->op == OP_AND))
*/ */
if (!!match == (pred->op == OP_OR)) { if (!!d->match == (pred->op == OP_OR))
if (pred == root) return WALK_PRED_PARENT;
break; break;
pred = get_pred_parent(pred, preds,
pred->parent, &move);
continue;
}
/* now go down the right side of the tree. */
pred = &preds[pred->right];
move = MOVE_DOWN;
continue;
case MOVE_UP_FROM_RIGHT: case MOVE_UP_FROM_RIGHT:
/* We finished this equation. */
if (pred == root)
break; break;
pred = get_pred_parent(pred, preds,
pred->parent, &move);
continue;
} }
done = 1;
} while (!done);
return match; return WALK_PRED_DEFAULT;
}
/* return 1 if event matches, 0 otherwise (discard) */
int filter_match_preds(struct event_filter *filter, void *rec)
{
struct filter_pred *preds;
struct filter_pred *root;
struct filter_match_preds_data data = {
/* match is currently meaningless */
.match = -1,
.rec = rec,
};
int n_preds, ret;
/* no filter is considered a match */
if (!filter)
return 1;
n_preds = filter->n_preds;
if (!n_preds)
return 1;
/*
* n_preds, root and filter->preds are protect with preemption disabled.
*/
root = rcu_dereference_sched(filter->root);
if (!root)
return 1;
data.preds = preds = rcu_dereference_sched(filter->preds);
ret = walk_pred_tree(preds, root, filter_match_preds_cb, &data);
WARN_ON(ret);
return data.match;
} }
EXPORT_SYMBOL_GPL(filter_match_preds); EXPORT_SYMBOL_GPL(filter_match_preds);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment