From: mpi Date: Thu, 22 Apr 2021 09:36:39 +0000 (+0000) Subject: Remove support for in-kernel filters. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=466f73187d2dc84ea16a2749fa79807847728c89;p=openbsd Remove support for in-kernel filters. This might be added back in a future if copying events to userland becomes a performance issue. However note that it is not always possible to filter in-kernel if, for example. a variable has to be evaluated when a rule fires. --- diff --git a/usr.sbin/btrace/bt_parse.y b/usr.sbin/btrace/bt_parse.y index 44f4204051f..6a4aa5d8361 100644 --- a/usr.sbin/btrace/bt_parse.y +++ b/usr.sbin/btrace/bt_parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: bt_parse.y,v 1.29 2021/04/21 10:53:17 mpi Exp $ */ +/* $OpenBSD: bt_parse.y,v 1.30 2021/04/22 09:36:39 mpi Exp $ */ /* * Copyright (c) 2019-2021 Martin Pieuchot @@ -58,7 +58,6 @@ SLIST_HEAD(, bt_var) l_variables; struct bt_rule *br_new(struct bt_probe *, struct bt_filter *, struct bt_stmt *, enum bt_rtype); -struct bt_filter *bf_new(enum bt_argtype, enum bt_filtervar, int); struct bt_probe *bp_new(const char *, const char *, const char *, int32_t); struct bt_arg *ba_append(struct bt_arg *, struct bt_arg *); struct bt_arg *ba_op(enum bt_argtype, struct bt_arg *, struct bt_arg *); @@ -121,7 +120,7 @@ static int pflag; %type gvar lvar %type staticval -%type fval testop binop builtin +%type testop binop builtin %type BUILTIN F_DELETE F_PRINT FUNC0 FUNC1 FUNCN OP1 OP4 %type MOP0 MOP1 %type probe probename @@ -156,11 +155,6 @@ probename : STRING ':' STRING ':' STRING { $$ = bp_new($1, $3, $5, 0); } | STRING ':' HZ ':' NUMBER { $$ = bp_new($1, "hz", NULL, $5); } ; - -fval : PID { $$ = B_FV_PID; } - | TID { $$ = B_FV_TID; } - ; - testop : OP_EQ { $$ = B_AT_OP_EQ; } | OP_NE { $$ = B_AT_OP_NE; } | OP_LE { $$ = B_AT_OP_LE; } @@ -301,25 +295,6 @@ br_new(struct bt_probe *probe, struct bt_filter *filter, struct bt_stmt *head, return br; } -/* Create a new event filter */ -struct bt_filter * -bf_new(enum bt_argtype op, enum bt_filtervar var, int val) -{ - struct bt_filter *bf; - - if (val < 0 || val > INT_MAX) - errx(1, "invalid pid '%d'", val); - - bf = calloc(1, sizeof(*bf)); - if (bf == NULL) - err(1, "bt_filter: calloc"); - bf->bf_evtfilter.bf_op = op; - bf->bf_evtfilter.bf_var = var; - bf->bf_evtfilter.bf_val = val; - - return bf; -} - /* Create a new condition */ struct bt_filter * bc_new(struct bt_arg *term, enum bt_argtype op, struct bt_arg *ba) diff --git a/usr.sbin/btrace/bt_parser.h b/usr.sbin/btrace/bt_parser.h index 3181ab78926..7ebacf6a14e 100644 --- a/usr.sbin/btrace/bt_parser.h +++ b/usr.sbin/btrace/bt_parser.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bt_parser.h,v 1.15 2021/04/21 10:28:54 mpi Exp $ */ +/* $OpenBSD: bt_parser.h,v 1.16 2021/04/22 09:36:39 mpi Exp $ */ /* * Copyright (c) 2019-2021 Martin Pieuchot @@ -59,12 +59,10 @@ struct bt_evtfilter { * Filters, also known as predicates, describe under which set of * conditions a rule is executed. * - * Depending on their type they are performed in-kernel or when a rule - * is evaluated. In the first case they might prevent the recording of - * events, in the second case events might be discarded at runtime. + * They are performed when a rule is evaluated and events might be + * discarded at runtime. */ struct bt_filter { - struct bt_evtfilter bf_evtfilter; /* in-kernel event filter */ struct bt_stmt *bf_condition; /* per event condition */ }; diff --git a/usr.sbin/btrace/btrace.c b/usr.sbin/btrace/btrace.c index 4a617633019..9720e0ec511 100644 --- a/usr.sbin/btrace/btrace.c +++ b/usr.sbin/btrace/btrace.c @@ -1,4 +1,4 @@ -/* $OpenBSD: btrace.c,v 1.34 2021/04/21 13:23:56 jmc Exp $ */ +/* $OpenBSD: btrace.c,v 1.35 2021/04/22 09:36:39 mpi Exp $ */ /* * Copyright (c) 2019 - 2020 Martin Pieuchot @@ -386,31 +386,6 @@ rules_do(int fd) } } -static inline enum dt_operand -dop2dt(enum bt_argtype op) -{ - switch (op) { - case B_AT_OP_EQ: return DT_OP_EQ; - case B_AT_OP_NE: return DT_OP_NE; - default: break; - } - xabort("unknown operand %d", op); -} - - -static inline enum dt_filtervar -dvar2dt(enum bt_filtervar var) -{ - switch (var) { - case B_FV_PID: return DT_FV_PID; - case B_FV_TID: return DT_FV_TID; - case B_FV_NONE: return DT_FV_NONE; - default: break; - } - xabort("unknown filter %d", var); -} - - void rules_setup(int fd) { @@ -445,14 +420,6 @@ rules_setup(int fd) r->br_pbn = dtpi->dtpi_pbn; dtrq->dtrq_pbn = dtpi->dtpi_pbn; - if (r->br_filter != NULL && - r->br_filter->bf_condition == NULL) { - struct bt_evtfilter *df = &r->br_filter->bf_evtfilter; - - dtrq->dtrq_filter.dtf_operand = dop2dt(df->bf_op); - dtrq->dtrq_filter.dtf_variable = dvar2dt(df->bf_var); - dtrq->dtrq_filter.dtf_value = df->bf_val; - } dtrq->dtrq_rate = r->br_probe->bp_rate; SLIST_FOREACH(bs, &r->br_action, bs_next) { @@ -1407,50 +1374,19 @@ debugx(const char *fmt, ...) va_end(ap); } -static inline const char * -debug_getfiltervar(struct bt_evtfilter *df) -{ - switch (df->bf_var) { - case B_FV_PID: return "pid"; - case B_FV_TID: return "tid"; - case B_FV_NONE: return ""; - default: - xabort("invalid filtervar %d", df->bf_var); - } -} - -static inline const char * -debug_getfilterop(struct bt_evtfilter *df) -{ - switch (df->bf_op) { - case B_AT_OP_EQ: return "=="; - case B_AT_OP_NE: return "!="; - default: - xabort("invalid operand %d", df->bf_op); - } -} - void debug_dump_filter(struct bt_rule *r) { if (r->br_filter != NULL) { struct bt_stmt *bs = r->br_filter->bf_condition; + struct bt_arg *bop = SLIST_FIRST(&bs->bs_args); + struct bt_arg *a, *b; - if (bs == NULL) { - struct bt_evtfilter *df = &r->br_filter->bf_evtfilter; + a = bop->ba_value; + b = SLIST_NEXT(a, ba_next); - debugx(" / %s %s %u /", debug_getfiltervar(df), - debug_getfilterop(df), df->bf_val); - } else { - struct bt_arg *bop = SLIST_FIRST(&bs->bs_args); - struct bt_arg *a, *b; - - a = bop->ba_value; - b = SLIST_NEXT(a, ba_next); - - debugx(" / %s %s %s /", ba_name(a), ba_name(bop), - (b != NULL) ? ba_name(b) : "NULL"); - } + debugx(" / %s %s %s /", ba_name(a), ba_name(bop), + (b != NULL) ? ba_name(b) : "NULL"); } debugx("\n"); }