From: Francis Deslauriers Date: Tue, 7 Jan 2020 16:00:55 +0000 (-0500) Subject: Decouple `struct lttng_event` from filter code X-Git-Tag: v2.13.0-rc1~153 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=2dfda770cc6781ec372ee8dadd8eb4f6ab37375a;p=lttng-modules.git Decouple `struct lttng_event` from filter code The filter infrastructure will be used by event notifiers and decoupling this will allow for massive code reuse. Of all `struct lttng_event`'s fields, filter code needs: 1. The `const struct lttng_event_desc *desc` field, 2. The `struct cds_list_head bytecode_runtime_head` list. These fields are used to do the tracepoint field relocation (`apply_field_reloc()` and `specialize_event_payload_lookup()`). Considering that only these two field are needed, we can pass them directly to these functions. Signed-off-by: Francis Deslauriers Signed-off-by: Mathieu Desnoyers Change-Id: If569b7d315700660aa84241d112668f2451b715a --- diff --git a/include/lttng/events.h b/include/lttng/events.h index 69aca1e0..833a344a 100644 --- a/include/lttng/events.h +++ b/include/lttng/events.h @@ -255,7 +255,7 @@ struct lttng_bytecode_runtime { const char *filter_stack_data); int link_failed; struct list_head node; /* list of bytecode runtime in event */ - struct lttng_event *event; + struct lttng_ctx *ctx; }; /* @@ -711,8 +711,11 @@ static inline long lttng_channel_syscall_mask(struct lttng_channel *channel, void lttng_filter_sync_state(struct lttng_bytecode_runtime *runtime); int lttng_event_enabler_attach_bytecode(struct lttng_event_enabler *event_enabler, struct lttng_kernel_filter_bytecode __user *bytecode); -void lttng_event_enabler_link_bytecode(struct lttng_event *event, - struct lttng_event_enabler *event_enabler); + +void lttng_enabler_link_bytecode(const struct lttng_event_desc *event_desc, + struct lttng_ctx *ctx, + struct list_head *bytecode_runtime_head, + struct lttng_enabler *enabler); int lttng_probes_init(void); diff --git a/include/lttng/filter.h b/include/lttng/filter.h index e999a057..a9477870 100644 --- a/include/lttng/filter.h +++ b/include/lttng/filter.h @@ -235,7 +235,7 @@ struct estack { const char *lttng_filter_print_op(enum filter_op op); int lttng_filter_validate_bytecode(struct bytecode_runtime *bytecode); -int lttng_filter_specialize_bytecode(struct lttng_event *event, +int lttng_filter_specialize_bytecode(const struct lttng_event_desc *event_desc, struct bytecode_runtime *bytecode); uint64_t lttng_filter_false(void *filter_data, diff --git a/src/lttng-events.c b/src/lttng-events.c index cd0c5eb7..34e5fe9d 100644 --- a/src/lttng-events.c +++ b/src/lttng-events.c @@ -1484,7 +1484,10 @@ int lttng_event_enabler_ref_events(struct lttng_event_enabler *event_enabler) /* * Link filter bytecodes if not linked yet. */ - lttng_event_enabler_link_bytecode(event, event_enabler); + lttng_enabler_link_bytecode(event->desc, + lttng_static_ctx, + &event->bytecode_runtime_head, + lttng_event_enabler_as_enabler(event_enabler)); /* TODO: merge event context. */ } diff --git a/src/lttng-filter-specialize.c b/src/lttng-filter-specialize.c index 1d7f29a4..c7718ec7 100644 --- a/src/lttng-filter-specialize.c +++ b/src/lttng-filter-specialize.c @@ -297,7 +297,8 @@ end: return ret; } -static int specialize_context_lookup_name(struct bytecode_runtime *bytecode, +static int specialize_context_lookup_name(struct lttng_ctx *ctx, + struct bytecode_runtime *bytecode, struct load_op *insn) { uint16_t offset; @@ -305,7 +306,7 @@ static int specialize_context_lookup_name(struct bytecode_runtime *bytecode, offset = ((struct get_symbol *) insn->data)->offset; name = bytecode->p.bc->bc.data + bytecode->p.bc->bc.reloc_offset + offset; - return lttng_get_context_index(lttng_static_ctx, name); + return lttng_get_context_index(ctx, name); } static int specialize_load_object(const struct lttng_event_field *field, @@ -383,7 +384,8 @@ static int specialize_load_object(const struct lttng_event_field *field, return 0; } -static int specialize_context_lookup(struct bytecode_runtime *runtime, +static int specialize_context_lookup(struct lttng_ctx *ctx, + struct bytecode_runtime *runtime, struct load_op *insn, struct vstack_load *load) { @@ -393,7 +395,7 @@ static int specialize_context_lookup(struct bytecode_runtime *runtime, struct filter_get_index_data gid; ssize_t data_offset; - idx = specialize_context_lookup_name(runtime, insn); + idx = specialize_context_lookup_name(ctx, runtime, insn); if (idx < 0) { return -ENOENT; } @@ -416,14 +418,13 @@ static int specialize_context_lookup(struct bytecode_runtime *runtime, return 0; } -static int specialize_event_payload_lookup(struct lttng_event *event, +static int specialize_payload_lookup(const struct lttng_event_desc *event_desc, struct bytecode_runtime *runtime, struct load_op *insn, struct vstack_load *load) { const char *name; uint16_t offset; - const struct lttng_event_desc *desc = event->desc; unsigned int i, nr_fields; bool found = false; uint32_t field_offset = 0; @@ -432,11 +433,11 @@ static int specialize_event_payload_lookup(struct lttng_event *event, struct filter_get_index_data gid; ssize_t data_offset; - nr_fields = desc->nr_fields; + nr_fields = event_desc->nr_fields; offset = ((struct get_symbol *) insn->data)->offset; name = runtime->p.bc->bc.data + runtime->p.bc->bc.reloc_offset + offset; for (i = 0; i < nr_fields; i++) { - field = &desc->fields[i]; + field = &event_desc->fields[i]; if (field->nofilter) { continue; } @@ -489,13 +490,14 @@ end: return ret; } -int lttng_filter_specialize_bytecode(struct lttng_event *event, +int lttng_filter_specialize_bytecode(const struct lttng_event_desc *event_desc, struct bytecode_runtime *bytecode) { void *pc, *next_pc, *start_pc; int ret = -EINVAL; struct vstack _stack; struct vstack *stack = &_stack; + struct lttng_ctx *ctx = bytecode->p.ctx; vstack_init(stack); @@ -1150,7 +1152,7 @@ int lttng_filter_specialize_bytecode(struct lttng_event *event, goto end; case LOAD_ROOT_CONTEXT: /* Lookup context field. */ - ret = specialize_context_lookup(bytecode, insn, + ret = specialize_context_lookup(ctx, bytecode, insn, &vstack_ax(stack)->load); if (ret) goto end; @@ -1160,7 +1162,7 @@ int lttng_filter_specialize_bytecode(struct lttng_event *event, goto end; case LOAD_ROOT_PAYLOAD: /* Lookup event payload field. */ - ret = specialize_event_payload_lookup(event, + ret = specialize_payload_lookup(event_desc, bytecode, insn, &vstack_ax(stack)->load); if (ret) diff --git a/src/lttng-filter.c b/src/lttng-filter.c index 0b5e872f..b33ae929 100644 --- a/src/lttng-filter.c +++ b/src/lttng-filter.c @@ -167,14 +167,13 @@ const char *lttng_filter_print_op(enum filter_op op) } static -int apply_field_reloc(struct lttng_event *event, +int apply_field_reloc(const struct lttng_event_desc *event_desc, struct bytecode_runtime *runtime, uint32_t runtime_len, uint32_t reloc_offset, const char *field_name, enum filter_op filter_op) { - const struct lttng_event_desc *desc; const struct lttng_event_field *fields, *field = NULL; unsigned int nr_fields, i; struct load_op *op; @@ -183,13 +182,12 @@ int apply_field_reloc(struct lttng_event *event, dbg_printk("Apply field reloc: %u %s\n", reloc_offset, field_name); /* Lookup event by name */ - desc = event->desc; - if (!desc) + if (!event_desc) return -EINVAL; - fields = desc->fields; + fields = event_desc->fields; if (!fields) return -EINVAL; - nr_fields = desc->nr_fields; + nr_fields = event_desc->nr_fields; for (i = 0; i < nr_fields; i++) { if (fields[i].nofilter) continue; @@ -274,8 +272,7 @@ int apply_field_reloc(struct lttng_event *event, } static -int apply_context_reloc(struct lttng_event *event, - struct bytecode_runtime *runtime, +int apply_context_reloc(struct bytecode_runtime *runtime, uint32_t runtime_len, uint32_t reloc_offset, const char *context_name, @@ -344,7 +341,7 @@ int apply_context_reloc(struct lttng_event *event, } static -int apply_reloc(struct lttng_event *event, +int apply_reloc(const struct lttng_event_desc *event_desc, struct bytecode_runtime *runtime, uint32_t runtime_len, uint32_t reloc_offset, @@ -361,10 +358,10 @@ int apply_reloc(struct lttng_event *event, op = (struct load_op *) &runtime->code[reloc_offset]; switch (op->op) { case FILTER_OP_LOAD_FIELD_REF: - return apply_field_reloc(event, runtime, runtime_len, + return apply_field_reloc(event_desc, runtime, runtime_len, reloc_offset, name, op->op); case FILTER_OP_GET_CONTEXT_REF: - return apply_context_reloc(event, runtime, runtime_len, + return apply_context_reloc(runtime, runtime_len, reloc_offset, name, op->op); case FILTER_OP_GET_SYMBOL: case FILTER_OP_GET_SYMBOL_FIELD: @@ -382,12 +379,11 @@ int apply_reloc(struct lttng_event *event, static int bytecode_is_linked(struct lttng_filter_bytecode_node *filter_bytecode, - struct lttng_event *event) + struct list_head *bytecode_runtime_head) { struct lttng_bytecode_runtime *bc_runtime; - list_for_each_entry(bc_runtime, - &event->bytecode_runtime_head, node) { + list_for_each_entry(bc_runtime, bytecode_runtime_head, node) { if (bc_runtime->bc == filter_bytecode) return 1; } @@ -399,7 +395,8 @@ int bytecode_is_linked(struct lttng_filter_bytecode_node *filter_bytecode, * bytecode runtime. */ static -int _lttng_filter_event_link_bytecode(struct lttng_event *event, +int _lttng_filter_link_bytecode(const struct lttng_event_desc *event_desc, + struct lttng_ctx *ctx, struct lttng_filter_bytecode_node *filter_bytecode, struct list_head *insert_loc) { @@ -410,7 +407,7 @@ int _lttng_filter_event_link_bytecode(struct lttng_event *event, if (!filter_bytecode) return 0; /* Bytecode already linked */ - if (bytecode_is_linked(filter_bytecode, event)) + if (bytecode_is_linked(filter_bytecode, insert_loc)) return 0; dbg_printk("Linking...\n"); @@ -423,7 +420,7 @@ int _lttng_filter_event_link_bytecode(struct lttng_event *event, goto alloc_error; } runtime->p.bc = filter_bytecode; - runtime->p.event = event; + runtime->p.ctx = ctx; runtime->len = filter_bytecode->bc.reloc_offset; /* copy original bytecode */ memcpy(runtime->code, filter_bytecode->bc.data, runtime->len); @@ -439,7 +436,7 @@ int _lttng_filter_event_link_bytecode(struct lttng_event *event, const char *name = (const char *) &filter_bytecode->bc.data[offset + sizeof(uint16_t)]; - ret = apply_reloc(event, runtime, runtime->len, reloc_offset, name); + ret = apply_reloc(event_desc, runtime, runtime->len, reloc_offset, name); if (ret) { goto link_error; } @@ -451,7 +448,7 @@ int _lttng_filter_event_link_bytecode(struct lttng_event *event, goto link_error; } /* Specialize bytecode */ - ret = lttng_filter_specialize_bytecode(event, runtime); + ret = lttng_filter_specialize_bytecode(event_desc, runtime); if (ret) { goto link_error; } @@ -483,23 +480,24 @@ void lttng_filter_sync_state(struct lttng_bytecode_runtime *runtime) /* * Link bytecode for all enablers referenced by an event. */ -void lttng_event_enabler_link_bytecode(struct lttng_event *event, - struct lttng_event_enabler *event_enabler) +void lttng_enabler_link_bytecode(const struct lttng_event_desc *event_desc, + struct lttng_ctx *ctx, + struct list_head *bytecode_runtime_head, + struct lttng_enabler *enabler) { struct lttng_filter_bytecode_node *bc; struct lttng_bytecode_runtime *runtime; - struct lttng_enabler *base_enabler = lttng_event_enabler_as_enabler(event_enabler); /* Can only be called for events with desc attached */ - WARN_ON_ONCE(!event->desc); + WARN_ON_ONCE(!event_desc); /* Link each bytecode. */ - list_for_each_entry(bc, &base_enabler->filter_bytecode_head, node) { + list_for_each_entry(bc, &enabler->filter_bytecode_head, node) { int found = 0, ret; struct list_head *insert_loc; list_for_each_entry(runtime, - &event->bytecode_runtime_head, node) { + bytecode_runtime_head, node) { if (runtime->bc == bc) { found = 1; break; @@ -515,7 +513,7 @@ void lttng_event_enabler_link_bytecode(struct lttng_event *event, * insert the new bytecode right after it. */ list_for_each_entry_reverse(runtime, - &event->bytecode_runtime_head, node) { + bytecode_runtime_head, node) { if (runtime->bc->bc.seqnum <= bc->bc.seqnum) { /* insert here */ insert_loc = &runtime->node; @@ -523,11 +521,11 @@ void lttng_event_enabler_link_bytecode(struct lttng_event *event, } } /* Add to head to list */ - insert_loc = &event->bytecode_runtime_head; + insert_loc = bytecode_runtime_head; add_within: dbg_printk("linking bytecode\n"); - ret = _lttng_filter_event_link_bytecode(event, bc, - insert_loc); + ret = _lttng_filter_link_bytecode(event_desc, ctx, bc, + insert_loc); if (ret) { dbg_printk("[lttng filter] warning: cannot link event bytecode\n"); }