From: Francis Deslauriers Date: Thu, 28 Nov 2019 19:15:02 +0000 (-0500) Subject: Decouple `struct lttng_session` from filter code X-Git-Tag: v2.13.0-rc1~460 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=b77aaa1b8edf2;p=lttng-ust.git Decouple `struct lttng_session` from filter code Use `struct lttng_ctx` directly so that the future event notifier infrastructure, which will be outside any session, can use it. Signed-off-by: Francis Deslauriers Signed-off-by: Mathieu Desnoyers Change-Id: I84109a0c01636bc5206f43e7abdceee27124c520 --- diff --git a/include/lttng/ust-events.h b/include/lttng/ust-events.h index 3fee93c4..66c7390b 100644 --- a/include/lttng/ust-events.h +++ b/include/lttng/ust-events.h @@ -471,7 +471,11 @@ struct lttng_bytecode_runtime { uint64_t (*filter)(void *filter_data, const char *filter_stack_data); int link_failed; struct cds_list_head node; /* list of bytecode runtime in event */ - struct lttng_session *session; + /* + * Pointer to a `struct lttng_session`-owned and URCU-protected + * pointer. + */ + struct lttng_ctx **pctx; }; /* diff --git a/liblttng-ust/lttng-filter-interpreter.c b/liblttng-ust/lttng-filter-interpreter.c index 6c42b20f..49daa211 100644 --- a/liblttng-ust/lttng-filter-interpreter.c +++ b/liblttng-ust/lttng-filter-interpreter.c @@ -370,7 +370,7 @@ static int context_get_index(struct lttng_ctx *ctx, return 0; } -static int dynamic_get_index(struct lttng_session *session, +static int dynamic_get_index(struct lttng_ctx *ctx, struct bytecode_runtime *runtime, uint64_t index, struct estack_entry *stack_top) { @@ -437,9 +437,6 @@ static int dynamic_get_index(struct lttng_session *session, case LOAD_ROOT_CONTEXT: case LOAD_ROOT_APP_CONTEXT: /* Fall-through */ { - struct lttng_ctx *ctx; - - ctx = rcu_dereference(session->ctx); ret = context_get_index(ctx, &stack_top->u.ptr, gid->ctx_index); @@ -634,7 +631,7 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, const char *filter_stack_data) { struct bytecode_runtime *bytecode = filter_data; - struct lttng_session *session = bytecode->p.session; + struct lttng_ctx *ctx = rcu_dereference(*bytecode->p.pctx); void *pc, *next_pc, *start_pc; int ret = -EINVAL; uint64_t retval = 0; @@ -2013,13 +2010,11 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, { struct load_op *insn = (struct load_op *) pc; struct field_ref *ref = (struct field_ref *) insn->data; - struct lttng_ctx *ctx; struct lttng_ctx_field *ctx_field; struct lttng_ctx_value v; dbg_printf("get context ref offset %u type dynamic\n", ref->offset); - ctx = rcu_dereference(session->ctx); ctx_field = &ctx->fields[ref->offset]; ctx_field->get_value(ctx_field, &v); estack_push(stack, top, ax, bx, ax_t, bx_t); @@ -2063,13 +2058,11 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, { struct load_op *insn = (struct load_op *) pc; struct field_ref *ref = (struct field_ref *) insn->data; - struct lttng_ctx *ctx; struct lttng_ctx_field *ctx_field; struct lttng_ctx_value v; dbg_printf("get context ref offset %u type string\n", ref->offset); - ctx = rcu_dereference(session->ctx); ctx_field = &ctx->fields[ref->offset]; ctx_field->get_value(ctx_field, &v); estack_push(stack, top, ax, bx, ax_t, bx_t); @@ -2092,13 +2085,11 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, { struct load_op *insn = (struct load_op *) pc; struct field_ref *ref = (struct field_ref *) insn->data; - struct lttng_ctx *ctx; struct lttng_ctx_field *ctx_field; struct lttng_ctx_value v; dbg_printf("get context ref offset %u type s64\n", ref->offset); - ctx = rcu_dereference(session->ctx); ctx_field = &ctx->fields[ref->offset]; ctx_field->get_value(ctx_field, &v); estack_push(stack, top, ax, bx, ax_t, bx_t); @@ -2113,13 +2104,11 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, { struct load_op *insn = (struct load_op *) pc; struct field_ref *ref = (struct field_ref *) insn->data; - struct lttng_ctx *ctx; struct lttng_ctx_field *ctx_field; struct lttng_ctx_value v; dbg_printf("get context ref offset %u type double\n", ref->offset); - ctx = rcu_dereference(session->ctx); ctx_field = &ctx->fields[ref->offset]; ctx_field->get_value(ctx_field, &v); estack_push(stack, top, ax, bx, ax_t, bx_t); @@ -2205,7 +2194,7 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, struct get_index_u16 *index = (struct get_index_u16 *) insn->data; dbg_printf("op get index u16\n"); - ret = dynamic_get_index(session, bytecode, index->index, estack_ax(stack, top)); + ret = dynamic_get_index(ctx, bytecode, index->index, estack_ax(stack, top)); if (ret) goto end; estack_ax_v = estack_ax(stack, top)->u.v; @@ -2220,7 +2209,7 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, struct get_index_u64 *index = (struct get_index_u64 *) insn->data; dbg_printf("op get index u64\n"); - ret = dynamic_get_index(session, bytecode, index->index, estack_ax(stack, top)); + ret = dynamic_get_index(ctx, bytecode, index->index, estack_ax(stack, top)); if (ret) goto end; estack_ax_v = estack_ax(stack, top)->u.v; diff --git a/liblttng-ust/lttng-filter-specialize.c b/liblttng-ust/lttng-filter-specialize.c index ba46a103..0a19896b 100644 --- a/liblttng-ust/lttng-filter-specialize.c +++ b/liblttng-ust/lttng-filter-specialize.c @@ -507,7 +507,7 @@ static int specialize_load_object(const struct lttng_event_field *field, return 0; } -static int specialize_context_lookup(struct lttng_session *session, +static int specialize_context_lookup(struct lttng_ctx *ctx, struct bytecode_runtime *runtime, struct load_op *insn, struct vstack_load *load) @@ -518,11 +518,11 @@ static int specialize_context_lookup(struct lttng_session *session, struct filter_get_index_data gid; ssize_t data_offset; - idx = specialize_context_lookup_name(session->ctx, runtime, insn); + idx = specialize_context_lookup_name(ctx, runtime, insn); if (idx < 0) { return -ENOENT; } - ctx_field = &session->ctx->fields[idx]; + ctx_field = &ctx->fields[idx]; field = &ctx_field->event_field; ret = specialize_load_object(field, load, true); if (ret) @@ -541,7 +541,7 @@ static int specialize_context_lookup(struct lttng_session *session, return 0; } -static int specialize_app_context_lookup(struct lttng_session *session, +static int specialize_app_context_lookup(struct lttng_ctx **pctx, struct bytecode_runtime *runtime, struct load_op *insn, struct vstack_load *load) @@ -564,19 +564,18 @@ static int specialize_app_context_lookup(struct lttng_session *session, } strcpy(name, "$app."); strcat(name, orig_name); - idx = lttng_get_context_index(session->ctx, name); + idx = lttng_get_context_index(*pctx, name); if (idx < 0) { assert(lttng_context_is_app(name)); ret = lttng_ust_add_app_context_to_ctx_rcu(name, - &session->ctx); + pctx); if (ret) return ret; - idx = lttng_get_context_index(session->ctx, - name); + idx = lttng_get_context_index(*pctx, name); if (idx < 0) return -ENOENT; } - ctx_field = &session->ctx->fields[idx]; + ctx_field = &(*pctx)->fields[idx]; field = &ctx_field->event_field; ret = specialize_load_object(field, load, true); if (ret) @@ -685,7 +684,7 @@ int lttng_filter_specialize_bytecode(struct lttng_event *event, int ret = -EINVAL; struct vstack _stack; struct vstack *stack = &_stack; - struct lttng_session *session = bytecode->p.session; + struct lttng_ctx **pctx = bytecode->p.pctx; vstack_init(stack); @@ -1412,7 +1411,7 @@ int lttng_filter_specialize_bytecode(struct lttng_event *event, goto end; case LOAD_ROOT_CONTEXT: /* Lookup context field. */ - ret = specialize_context_lookup(session, + ret = specialize_context_lookup(*pctx, bytecode, insn, &vstack_ax(stack)->load); if (ret) @@ -1420,7 +1419,7 @@ int lttng_filter_specialize_bytecode(struct lttng_event *event, break; case LOAD_ROOT_APP_CONTEXT: /* Lookup app context field. */ - ret = specialize_app_context_lookup(session, + ret = specialize_app_context_lookup(pctx, bytecode, insn, &vstack_ax(stack)->load); if (ret) diff --git a/liblttng-ust/lttng-filter.c b/liblttng-ust/lttng-filter.c index bbc21289..7dbe6f26 100644 --- a/liblttng-ust/lttng-filter.c +++ b/liblttng-ust/lttng-filter.c @@ -300,22 +300,21 @@ int apply_context_reloc(struct lttng_event *event, struct load_op *op; struct lttng_ctx_field *ctx_field; int idx; - struct lttng_session *session = runtime->p.session; + struct lttng_ctx *ctx = *runtime->p.pctx; dbg_printf("Apply context reloc: %u %s\n", reloc_offset, context_name); /* Get context index */ - idx = lttng_get_context_index(session->ctx, context_name); + idx = lttng_get_context_index(ctx, context_name); if (idx < 0) { if (lttng_context_is_app(context_name)) { int ret; ret = lttng_ust_add_app_context_to_ctx_rcu(context_name, - &session->ctx); + &ctx); if (ret) return ret; - idx = lttng_get_context_index(session->ctx, - context_name); + idx = lttng_get_context_index(ctx, context_name); if (idx < 0) return -ENOENT; } else { @@ -327,7 +326,7 @@ int apply_context_reloc(struct lttng_event *event, return -EINVAL; /* Get context return type */ - ctx_field = &session->ctx->fields[idx]; + ctx_field = &ctx->fields[idx]; op = (struct load_op *) &runtime->code[reloc_offset]; switch (filter_op) { @@ -449,7 +448,7 @@ int _lttng_filter_event_link_bytecode(struct lttng_event *event, goto alloc_error; } runtime->p.bc = filter_bytecode; - runtime->p.session = event->chan->session; + runtime->p.pctx = &event->chan->session->ctx; runtime->len = filter_bytecode->bc.reloc_offset; /* copy original bytecode */ memcpy(runtime->code, filter_bytecode->bc.data, runtime->len); @@ -569,13 +568,19 @@ int lttng_filter_enabler_attach_bytecode(struct lttng_enabler *enabler, return 0; } -void lttng_free_event_filter_runtime(struct lttng_event *event) +static +void free_filter_runtime(struct cds_list_head *bytecode_runtime_head) { struct bytecode_runtime *runtime, *tmp; - cds_list_for_each_entry_safe(runtime, tmp, - &event->bytecode_runtime_head, p.node) { + cds_list_for_each_entry_safe(runtime, tmp, bytecode_runtime_head, + p.node) { free(runtime->data); free(runtime); } } + +void lttng_free_event_filter_runtime(struct lttng_event *event) +{ + free_filter_runtime(&event->bytecode_runtime_head); +}