Add `interpreter_funcs` to `lttng_bytecode_runtime`
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Wed, 13 May 2020 14:32:26 +0000 (10:32 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 25 Nov 2020 18:15:26 +0000 (13:15 -0500)
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 <francis.deslauriers@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Ic4423100e1f97654fe43c0927d3b81de2d1d724f

include/lttng/events.h
include/lttng/tracepoint-event-impl.h
src/lttng-bytecode.c

index 5393f196f18d63701fa72d46f7443a29d4bf1b88..bb3f9363f3d346d45e41ef054269bb8512df4101 100644 (file)
@@ -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;
index d5bb7ed7acc0e9e9d1549331f72f03a8fbf437b7..d8ad21632a8d8a3012bc7a90f57529cb6af8559b 100644 (file)
@@ -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;                          \
                }                                                             \
index 664a6aeeb133302ce14864434bbe499ffce41f1f..10093a7a40aacc9923d2aae24317ef6a72aac1f9 100644 (file)
@@ -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;
 }
 
 /*
This page took 0.029498 seconds and 4 git commands to generate.