* [PATCH] tracing: Add NOT to filtering logic
@ 2014-12-02 17:04 Steven Rostedt
2014-12-02 19:49 ` Alexei Starovoitov
0 siblings, 1 reply; 5+ messages in thread
From: Steven Rostedt @ 2014-12-02 17:04 UTC (permalink / raw)
To: LKML; +Cc: Andrew Morton, Theodore Ts'o, Alexei Starovoitov, Ingo Molnar
Ted noticed that he could not filter on an event for a bit being cleared.
That's because the filtering logic only tests event fields with a limited
number of comparisons which, for bit logic, only include "&", which can
test if a bit is set, but there's no good way to see if a bit is clear.
This adds a way to do: !(field & 2048)
Which returns true if the bit is not set, and false otherwise.
Note, currently !(field1 == 10 && field2 == 15) is not supported.
That is, the 'not' only works for direct comparisons, not for the
AND and OR logic.
Link: http://lkml.kernel.org/r/20141202021912.GA29096@thunk.org
Suggested-by: "Theodore Ts'o" <tytso@mit.edu>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
kernel/trace/trace_events_filter.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
index 7a8c1528e141..9ddbf0c05340 100644
--- a/kernel/trace/trace_events_filter.c
+++ b/kernel/trace/trace_events_filter.c
@@ -37,6 +37,7 @@ enum filter_op_ids
{
OP_OR,
OP_AND,
+ OP_NOT,
OP_GLOB,
OP_NE,
OP_EQ,
@@ -59,6 +60,7 @@ struct filter_op {
static struct filter_op filter_ops[] = {
{ OP_OR, "||", 1 },
{ OP_AND, "&&", 2 },
+ { OP_NOT, "!", 3 },
{ OP_GLOB, "~", 4 },
{ OP_NE, "!=", 4 },
{ OP_EQ, "==", 4 },
@@ -166,7 +168,7 @@ static int filter_pred_##type(struct filter_pred *pred, void *event) \
break; \
} \
\
- return match; \
+ return match == !pred->not; \
}
#define DEFINE_EQUALITY_PRED(size) \
@@ -1028,7 +1030,7 @@ static int init_pred(struct filter_parse_state *ps,
}
if (pred->op == OP_NE)
- pred->not = 1;
+ pred->not ^= 1;
pred->fn = fn;
return 0;
@@ -1590,6 +1592,16 @@ static int replace_preds(struct ftrace_event_call *call,
continue;
}
+ if (elt->op == OP_NOT) {
+ if (!n_preds) {
+ err = -EINVAL;
+ goto fail;
+ }
+ if (!dry_run)
+ filter->preds[n_preds - 1].not ^= 1;
+ continue;
+ }
+
if (WARN_ON(n_preds++ == MAX_FILTER_PRED)) {
parse_error(ps, FILT_ERR_TOO_MANY_PREDS, 0);
err = -ENOSPC;
--
1.8.1.4
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] tracing: Add NOT to filtering logic
2014-12-02 17:04 [PATCH] tracing: Add NOT to filtering logic Steven Rostedt
@ 2014-12-02 19:49 ` Alexei Starovoitov
2014-12-02 19:54 ` Steven Rostedt
2014-12-02 20:35 ` [PATCH v2] " Steven Rostedt
0 siblings, 2 replies; 5+ messages in thread
From: Alexei Starovoitov @ 2014-12-02 19:49 UTC (permalink / raw)
To: Steven Rostedt; +Cc: LKML, Andrew Morton, Theodore Ts'o, Ingo Molnar
On Tue, Dec 2, 2014 at 9:04 AM, Steven Rostedt <rostedt@goodmis.org> wrote:
> \
> - return match; \
> + return match == !pred->not; \
are you sure this one works for !(var & 2) ?
'not' is either 0 or 1, so it works for other macro:
(val == *addr) ^ pred->not
whereas here 'match' is 'int' and
match = (*addr & val)
will not be 0 or 1...
the patch is small, but delicate...
In such cases I trust tests more than code review ;)
Could you add few tests for this to
CONFIG_FTRACE_STARTUP_TEST
part of the file ?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] tracing: Add NOT to filtering logic
2014-12-02 19:49 ` Alexei Starovoitov
@ 2014-12-02 19:54 ` Steven Rostedt
2014-12-02 20:35 ` [PATCH v2] " Steven Rostedt
1 sibling, 0 replies; 5+ messages in thread
From: Steven Rostedt @ 2014-12-02 19:54 UTC (permalink / raw)
To: Alexei Starovoitov; +Cc: LKML, Andrew Morton, Theodore Ts'o, Ingo Molnar
On Tue, 2 Dec 2014 11:49:58 -0800
Alexei Starovoitov <ast@plumgrid.com> wrote:
> On Tue, Dec 2, 2014 at 9:04 AM, Steven Rostedt <rostedt@goodmis.org> wrote:
> > \
> > - return match; \
> > + return match == !pred->not; \
>
> are you sure this one works for !(var & 2) ?
> 'not' is either 0 or 1, so it works for other macro:
> (val == *addr) ^ pred->not
>
> whereas here 'match' is 'int' and
> match = (*addr & val)
> will not be 0 or 1...
>
> the patch is small, but delicate...
Yeah, there's some more I'm fixing up on it. I only did some basic
tests. I should have tested '& 2' instead of '& 1' ;-)
I'll make that check: return !!match == !pred->not.
> In such cases I trust tests more than code review ;)
> Could you add few tests for this to
> CONFIG_FTRACE_STARTUP_TEST
> part of the file ?
No, but I will be adding tests to the ftracetests in
tools/testing/selftests to test the filters.
Thanks,
-- Steve
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2] tracing: Add NOT to filtering logic
2014-12-02 19:49 ` Alexei Starovoitov
2014-12-02 19:54 ` Steven Rostedt
@ 2014-12-02 20:35 ` Steven Rostedt
2014-12-02 20:44 ` Alexei Starovoitov
1 sibling, 1 reply; 5+ messages in thread
From: Steven Rostedt @ 2014-12-02 20:35 UTC (permalink / raw)
To: Alexei Starovoitov; +Cc: LKML, Andrew Morton, Theodore Ts'o, Ingo Molnar
Ted noticed that he could not filter on an event for a bit being cleared.
That's because the filtering logic only tests event fields with a limited
number of comparisons which, for bit logic, only include "&", which can
test if a bit is set, but there's no good way to see if a bit is clear.
This adds a way to do: !(field & 2048)
Which returns true if the bit is not set, and false otherwise.
Note, currently !(field1 == 10 && field2 == 15) is not supported.
That is, the 'not' only works for direct comparisons, not for the
AND and OR logic.
Link: http://lkml.kernel.org/r/20141202021912.GA29096@thunk.org
Link: http://lkml.kernel.org/r/20141202120430.71979060@gandalf.local.home
Suggested-by: "Theodore Ts'o" <tytso@mit.edu>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
kernel/trace/trace_events_filter.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
index 7a8c1528e141..e6a33db83856 100644
--- a/kernel/trace/trace_events_filter.c
+++ b/kernel/trace/trace_events_filter.c
@@ -45,6 +45,7 @@ enum filter_op_ids
OP_GT,
OP_GE,
OP_BAND,
+ OP_NOT,
OP_NONE,
OP_OPEN_PAREN,
};
@@ -67,6 +68,7 @@ static struct filter_op filter_ops[] = {
{ OP_GT, ">", 5 },
{ OP_GE, ">=", 5 },
{ OP_BAND, "&", 6 },
+ { OP_NOT, "!", 6 },
{ OP_NONE, "OP_NONE", 0 },
{ OP_OPEN_PAREN, "(", 0 },
};
@@ -85,6 +87,7 @@ enum {
FILT_ERR_MISSING_FIELD,
FILT_ERR_INVALID_FILTER,
FILT_ERR_IP_FIELD_ONLY,
+ FILT_ERR_ILLEGAL_NOT_OP,
};
static char *err_text[] = {
@@ -101,6 +104,7 @@ static char *err_text[] = {
"Missing field name and/or value",
"Meaningless filter expression",
"Only 'ip' field is supported for function trace",
+ "Illegal use of '!'",
};
struct opstack_op {
@@ -139,6 +143,7 @@ struct pred_stack {
int index;
};
+/* If not of not match is equal to not of not, then it is a match */
#define DEFINE_COMPARISON_PRED(type) \
static int filter_pred_##type(struct filter_pred *pred, void *event) \
{ \
@@ -166,7 +171,7 @@ static int filter_pred_##type(struct filter_pred *pred, void *event) \
break; \
} \
\
- return match; \
+ return !!match == !pred->not; \
}
#define DEFINE_EQUALITY_PRED(size) \
@@ -1028,7 +1033,7 @@ static int init_pred(struct filter_parse_state *ps,
}
if (pred->op == OP_NE)
- pred->not = 1;
+ pred->not ^= 1;
pred->fn = fn;
return 0;
@@ -1590,6 +1595,17 @@ static int replace_preds(struct ftrace_event_call *call,
continue;
}
+ if (elt->op == OP_NOT) {
+ if (!n_preds || operand1 || operand2) {
+ parse_error(ps, FILT_ERR_ILLEGAL_NOT_OP, 0);
+ err = -EINVAL;
+ goto fail;
+ }
+ if (!dry_run)
+ filter->preds[n_preds - 1].not ^= 1;
+ continue;
+ }
+
if (WARN_ON(n_preds++ == MAX_FILTER_PRED)) {
parse_error(ps, FILT_ERR_TOO_MANY_PREDS, 0);
err = -ENOSPC;
--
1.8.1.4
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] tracing: Add NOT to filtering logic
2014-12-02 20:35 ` [PATCH v2] " Steven Rostedt
@ 2014-12-02 20:44 ` Alexei Starovoitov
0 siblings, 0 replies; 5+ messages in thread
From: Alexei Starovoitov @ 2014-12-02 20:44 UTC (permalink / raw)
To: Steven Rostedt; +Cc: LKML, Andrew Morton, Theodore Ts'o, Ingo Molnar
On Tue, Dec 2, 2014 at 12:35 PM, Steven Rostedt <rostedt@goodmis.org> wrote:
>
> Ted noticed that he could not filter on an event for a bit being cleared.
> That's because the filtering logic only tests event fields with a limited
> number of comparisons which, for bit logic, only include "&", which can
> test if a bit is set, but there's no good way to see if a bit is clear.
>
> This adds a way to do: !(field & 2048)
>
> Which returns true if the bit is not set, and false otherwise.
>
> Note, currently !(field1 == 10 && field2 == 15) is not supported.
> That is, the 'not' only works for direct comparisons, not for the
> AND and OR logic.
>
> Link: http://lkml.kernel.org/r/20141202021912.GA29096@thunk.org
> Link: http://lkml.kernel.org/r/20141202120430.71979060@gandalf.local.home
>
> Suggested-by: "Theodore Ts'o" <tytso@mit.edu>
> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
looks good to me.
Acked-by: Alexei Starovoitov <ast@plumgrid.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-12-02 20:45 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-02 17:04 [PATCH] tracing: Add NOT to filtering logic Steven Rostedt
2014-12-02 19:49 ` Alexei Starovoitov
2014-12-02 19:54 ` Steven Rostedt
2014-12-02 20:35 ` [PATCH v2] " Steven Rostedt
2014-12-02 20:44 ` Alexei Starovoitov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®