From: Francis Deslauriers Date: Wed, 13 May 2020 14:32:26 +0000 (-0400) Subject: Add `interpreter_funcs` to `lttng_bytecode_runtime` X-Git-Tag: v2.13.0-rc1~94 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=3d650c7b255a7aa43cae96904f0c229a129d39be;p=lttng-modules.git Add `interpreter_funcs` to `lttng_bytecode_runtime` Background ========== The current filter interpreter function signature looks like this: uint64_t lttng_bytecode_filter_interpret(void *filter_data, const char *filter_stack_data); The upcoming capture interpreter function will need an output parameter to extract the top of stack register. It will look like this: uint64_t lttng_bytecode_capture_interpret(void *filter_data, const char *filter_stack_data, struct output_register *output); Problems ======== We can't reuse the same function pointer field in `struct lttng_bytecode_runtime` as both interpreter functions will have different signatures. We can't change the signature of this existing filter function because it's used in the tracepoint probes. Solution ======== Add a union of callbacks to hold both interpreter functions. This also doesn't change the layout of the `struct lttng_bytecode_runtime` objects. Signed-off-by: Francis Deslauriers Signed-off-by: Mathieu Desnoyers Change-Id: Ic4423100e1f97654fe43c0927d3b81de2d1d724f --- diff --git a/include/lttng/events.h b/include/lttng/events.h index 5393f196..bb3f9363 100644 --- a/include/lttng/events.h +++ b/include/lttng/events.h @@ -260,9 +260,11 @@ enum lttng_bytecode_interpreter_ret { struct lttng_bytecode_runtime { /* Associated bytecode */ struct lttng_bytecode_node *bc; - uint64_t (*filter)(void *filter_data, - struct lttng_probe_ctx *lttng_probe_ctx, - const char *filter_stack_data); + union { + uint64_t (*filter)(void *filter_data, + struct lttng_probe_ctx *lttng_probe_ctx, + const char *filter_stack_data); + } interpreter_funcs; int link_failed; struct list_head node; /* list of bytecode runtime in event */ struct lttng_ctx *ctx; diff --git a/include/lttng/tracepoint-event-impl.h b/include/lttng/tracepoint-event-impl.h index d5bb7ed7..d8ad2163 100644 --- a/include/lttng/tracepoint-event-impl.h +++ b/include/lttng/tracepoint-event-impl.h @@ -1249,7 +1249,7 @@ static void __event_probe__##_name(void *__data, _proto) \ __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \ tp_locvar, _args); \ lttng_list_for_each_entry_rcu(bc_runtime, &__event->filter_bytecode_runtime_head, node) { \ - if (unlikely(bc_runtime->filter(bc_runtime, &__lttng_probe_ctx, \ + if (unlikely(bc_runtime->interpreter_funcs.filter(bc_runtime, &__lttng_probe_ctx, \ __stackvar.__filter_stack_data) & LTTNG_INTERPRETER_RECORD_FLAG)) { \ __filter_record = 1; \ break; \ @@ -1345,7 +1345,7 @@ static void __event_probe__##_name(void *__data) \ __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \ tp_locvar); \ lttng_list_for_each_entry_rcu(bc_runtime, &__event->filter_bytecode_runtime_head, node) { \ - if (unlikely(bc_runtime->filter(bc_runtime, &__lttng_probe_ctx, \ + if (unlikely(bc_runtime->interpreter_funcs.filter(bc_runtime, &__lttng_probe_ctx, \ __stackvar.__filter_stack_data) & LTTNG_INTERPRETER_RECORD_FLAG)) { \ __filter_record = 1; \ break; \ @@ -1441,7 +1441,7 @@ static void __event_notifier_probe__##_name(void *__data, _proto) \ __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \ tp_locvar, _args); \ lttng_list_for_each_entry_rcu(bc_runtime, &__event_notifier->filter_bytecode_runtime_head, node) { \ - if (unlikely(bc_runtime->filter(bc_runtime, &__lttng_probe_ctx, \ + if (unlikely(bc_runtime->interpreter_funcs.filter(bc_runtime, &__lttng_probe_ctx, \ __stackvar.__filter_stack_data) & LTTNG_INTERPRETER_RECORD_FLAG)) \ __filter_record = 1; \ } \ @@ -1484,7 +1484,7 @@ static void __event_notifier_probe__##_name(void *__data) \ __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \ tp_locvar); \ lttng_list_for_each_entry_rcu(bc_runtime, &__event_notifier->filter_bytecode_runtime_head, node) { \ - if (unlikely(bc_runtime->filter(bc_runtime, &__lttng_probe_ctx, \ + if (unlikely(bc_runtime->interpreter_funcs.filter(bc_runtime, &__lttng_probe_ctx, \ __stackvar.__filter_stack_data) & LTTNG_INTERPRETER_RECORD_FLAG)) \ __filter_record = 1; \ } \ diff --git a/src/lttng-bytecode.c b/src/lttng-bytecode.c index 664a6aee..10093a7a 100644 --- a/src/lttng-bytecode.c +++ b/src/lttng-bytecode.c @@ -452,14 +452,29 @@ int _lttng_filter_link_bytecode(const struct lttng_event_desc *event_desc, if (ret) { goto link_error; } - runtime->p.filter = lttng_bytecode_filter_interpret; + + switch (bytecode->type) { + case LTTNG_BYTECODE_NODE_TYPE_FILTER: + runtime->p.interpreter_funcs.filter = lttng_bytecode_filter_interpret; + break; + default: + WARN_ON(1); + } + runtime->p.link_failed = 0; list_add_rcu(&runtime->p.node, insert_loc); dbg_printk("Linking successful.\n"); return 0; link_error: - runtime->p.filter = lttng_bytecode_filter_interpret_false; + + switch (bytecode->type) { + case LTTNG_BYTECODE_NODE_TYPE_FILTER: + runtime->p.interpreter_funcs.filter = lttng_bytecode_filter_interpret_false; + break; + default: + WARN_ON(1); + } runtime->p.link_failed = 1; list_add_rcu(&runtime->p.node, insert_loc); alloc_error: @@ -472,9 +487,9 @@ void lttng_bytecode_filter_sync_state(struct lttng_bytecode_runtime *runtime) struct lttng_bytecode_node *bc = runtime->bc; if (!bc->enabler->enabled || runtime->link_failed) - runtime->filter = lttng_bytecode_filter_interpret_false; + runtime->interpreter_funcs.filter = lttng_bytecode_filter_interpret_false; else - runtime->filter = lttng_bytecode_filter_interpret; + runtime->interpreter_funcs.filter = lttng_bytecode_filter_interpret; } /*