Add `interpreter_funcs` to `lttng_bytecode_runtime`
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Mon, 27 Apr 2020 19:11:38 +0000 (15:11 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 26 Nov 2020 18:36:07 +0000 (13:36 -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 *capture_data,
                  const char *capture_stack_data,
                  struct output_register *output);

Problems
========
We can't reuse the same function pointer field in `struct
lttng_bytecode_runtime` as the two 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: I9fcd6def9ce7783087b9648ddbf5ec71fb7b997a

include/lttng/ust-events.h
include/lttng/ust-tracepoint-event.h
liblttng-ust/lttng-bytecode.c

index ae5ce5f636b9a5f91e56069e5166ce80bc029b35..41164ac348eb1edf14e83960f07027205cb037ca 100644 (file)
@@ -443,8 +443,10 @@ enum lttng_bytecode_interpreter_ret {
 struct lttng_bytecode_runtime {
        /* Associated bytecode */
        struct lttng_ust_bytecode_node *bc;
-       uint64_t (*filter)(void *interpreter_data,
-                       const char *interpreter_stack_data);
+       union {
+               uint64_t (*filter)(void *interpreter_data,
+                               const char *interpreter_stack_data);
+       } interpreter_funcs;
        int link_failed;
        struct cds_list_head node;      /* list of bytecode runtime in event */
        /*
index 00e931a83a26037aa5b24b72c9bd500b127426b3..1f8be1a99efd4c5eeb80fd4d6db775dfbd835b11 100644 (file)
@@ -878,7 +878,7 @@ void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args))           \
                __event_prepare_filter_stack__##_provider##___##_name(__stackvar.__filter_stack_data, \
                        _TP_ARGS_DATA_VAR(_args));                            \
                tp_list_for_each_entry_rcu(__filter_bc_runtime, &__event->filter_bytecode_runtime_head, node) { \
-                       if (caa_unlikely(__filter_bc_runtime->filter(__filter_bc_runtime,             \
+                       if (caa_unlikely(__filter_bc_runtime->interpreter_funcs.filter(__filter_bc_runtime,     \
                                        __stackvar.__filter_stack_data) & LTTNG_INTERPRETER_RECORD_FLAG)) { \
                                __filter_record = 1;                          \
                                break;                                        \
@@ -960,7 +960,7 @@ void __event_notifier_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args))
                __event_prepare_filter_stack__##_provider##___##_name(__stackvar.__filter_stack_data, \
                        _TP_ARGS_DATA_VAR(_args));                            \
                tp_list_for_each_entry_rcu(__filter_bc_runtime, &__event_notifier->filter_bytecode_runtime_head, node) { \
-                       if (caa_unlikely(__filter_bc_runtime->filter(__filter_bc_runtime,            \
+                       if (caa_unlikely(__filter_bc_runtime->interpreter_funcs.filter(__filter_bc_runtime,       \
                                        __stackvar.__filter_stack_data) & LTTNG_INTERPRETER_RECORD_FLAG)) \
                                __filter_record = 1;                          \
                }                                                             \
index 47efdecafd25be983b0e4622f300cf0e6a9d3509..bbf8e7e7b036aca0afb41a21dd3590c4eb411e55 100644 (file)
@@ -478,14 +478,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_UST_BYTECODE_NODE_TYPE_FILTER:
+               runtime->p.interpreter_funcs.filter = lttng_bytecode_filter_interpret;
+               break;
+       default:
+               abort();
+       }
+
        runtime->p.link_failed = 0;
        cds_list_add_rcu(&runtime->p.node, insert_loc);
        dbg_printf("Linking successful.\n");
        return 0;
 
 link_error:
-       runtime->p.filter = lttng_bytecode_filter_interpret_false;
+       switch (bytecode->type) {
+       case LTTNG_UST_BYTECODE_NODE_TYPE_FILTER:
+               runtime->p.interpreter_funcs.filter = lttng_bytecode_filter_interpret_false;
+               break;
+       default:
+               abort();
+       }
+
        runtime->p.link_failed = 1;
        cds_list_add_rcu(&runtime->p.node, insert_loc);
 alloc_error:
@@ -498,9 +513,9 @@ void lttng_bytecode_filter_sync_state(struct lttng_bytecode_runtime *runtime)
        struct lttng_ust_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.027472 seconds and 4 git commands to generate.