X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=include%2Flttng%2Ftracepoint-event-impl.h;h=d659a6d6359a0f114d3036d4626a74176c13bf51;hb=refs%2Fheads%2Fsow-2020-0002-rev2;hp=25077772d77419b47346b9c4ad0f43df04f83ca5;hpb=3b4aafcbbef722c5d04f2fe06a47c47d4d23eda0;p=deliverable%2Flttng-modules.git diff --git a/include/lttng/tracepoint-event-impl.h b/include/lttng/tracepoint-event-impl.h index 25077772..d659a6d6 100644 --- a/include/lttng/tracepoint-event-impl.h +++ b/include/lttng/tracepoint-event-impl.h @@ -12,16 +12,16 @@ #include #include -#include -#include #include /* for wrapper_vmalloc_sync_mappings() */ #include #include #include #include -#include -#include -#include +#include +#include +#include +#include +#include #define __LTTNG_NULL_STRING "(null)" @@ -172,6 +172,41 @@ void __event_template_proto___##_name(void); #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) +/* + * Stage 1.2 of the trace event_notifier. + * + * Create dummy trace prototypes for each event class, and for each used + * template. This will allow checking whether the prototypes from the + * class and the instance using the class actually match. + */ + +#include /* Reset all macros within TRACE_EVENT */ + +#undef TP_PROTO +#define TP_PROTO(...) __VA_ARGS__ + +#undef TP_ARGS +#define TP_ARGS(...) __VA_ARGS__ + +#undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP +#define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \ +void __event_notifier_template_proto___##_template(_proto); + +#undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS +#define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \ +void __event_notifier_template_proto___##_template(void); + +#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE +#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \ +void __event_notifier_template_proto___##_name(_proto); + +#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS +#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \ +void __event_notifier_template_proto___##_name(void); + +#include TRACE_INCLUDE(TRACE_INCLUDE_FILE) + + /* * Stage 1.2 of tracepoint event generation * @@ -461,11 +496,13 @@ void __event_template_proto___##_name(void); #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \ -static void __event_probe__##_name(void *__data, _proto); +static void __event_probe__##_name(void *__data, _proto); \ +static void __event_notifier_probe__##_name(void *__data, _proto); #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \ -static void __event_probe__##_name(void *__data); +static void __event_probe__##_name(void *__data); \ +static void __event_notifier_probe__##_name(void *__data); #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) @@ -765,7 +802,7 @@ error: \ #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \ static inline \ -void __event_prepare_filter_stack__##_name(char *__stack_data, \ +void __event_prepare_interpreter_stack__##_name(char *__stack_data, \ void *__tp_locvar) \ { \ struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \ @@ -776,7 +813,7 @@ void __event_prepare_filter_stack__##_name(char *__stack_data, \ #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \ static inline \ -void __event_prepare_filter_stack__##_name(char *__stack_data, \ +void __event_prepare_interpreter_stack__##_name(char *__stack_data, \ void *__tp_locvar, _proto) \ { \ struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \ @@ -1131,15 +1168,14 @@ static void __event_probe__##_name(void *__data, _proto) \ { \ struct probe_local_vars { _locvar }; \ struct lttng_event *__event = __data; \ - struct lttng_probe_ctx __lttng_probe_ctx = { \ + struct lttng_probe_ctx __lttng_probe_ctx = { \ .event = __event, \ + .event_notifier = NULL, \ .interruptible = !irqs_disabled(), \ }; \ - struct lttng_channel *__chan = __event->chan; \ - struct lttng_session *__session = __chan->session; \ + struct lttng_event_container *__container = __event->container; \ + struct lttng_session *__session = __container->session; \ struct lib_ring_buffer_ctx __ctx; \ - ssize_t __event_len; \ - size_t __event_align; \ size_t __orig_dynamic_len_offset, __dynamic_len_idx __attribute__((unused)); \ union { \ size_t __dynamic_len_removed[ARRAY_SIZE(__event_fields___##_name)]; \ @@ -1153,11 +1189,11 @@ static void __event_probe__##_name(void *__data, _proto) \ \ if (!_TP_SESSION_CHECK(session, __session)) \ return; \ - if (unlikely(!READ_ONCE(__session->active))) \ + if (unlikely(!LTTNG_READ_ONCE(__session->active))) \ return; \ - if (unlikely(!READ_ONCE(__chan->enabled))) \ + if (unlikely(!LTTNG_READ_ONCE(__container->enabled))) \ return; \ - if (unlikely(!READ_ONCE(__event->enabled))) \ + if (unlikely(!LTTNG_READ_ONCE(__event->enabled))) \ return; \ __lf = lttng_rcu_dereference(__session->pid_tracker.p); \ if (__lf && likely(!lttng_id_tracker_lookup(__lf, current->tgid))) \ @@ -1184,15 +1220,15 @@ static void __event_probe__##_name(void *__data, _proto) \ __orig_dynamic_len_offset = this_cpu_ptr(<tng_dynamic_len_stack)->offset; \ __dynamic_len_idx = __orig_dynamic_len_offset; \ _code_pre \ - if (unlikely(!list_empty(&__event->bytecode_runtime_head))) { \ + if (unlikely(!list_empty(&__event->filter_bytecode_runtime_head))) { \ struct lttng_bytecode_runtime *bc_runtime; \ int __filter_record = __event->has_enablers_without_bytecode; \ \ - __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \ + __event_prepare_interpreter_stack__##_name(__stackvar.__filter_stack_data, \ tp_locvar, _args); \ - lttng_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \ - if (unlikely(bc_runtime->filter(bc_runtime, &__lttng_probe_ctx, \ - __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) { \ + lttng_list_for_each_entry_rcu(bc_runtime, &__event->filter_bytecode_runtime_head, node) { \ + if (unlikely(bc_runtime->interpreter_funcs.filter(bc_runtime, &__lttng_probe_ctx, \ + __stackvar.__filter_stack_data) & LTTNG_INTERPRETER_RECORD_FLAG)) { \ __filter_record = 1; \ break; \ } \ @@ -1200,19 +1236,37 @@ static void __event_probe__##_name(void *__data, _proto) \ if (likely(!__filter_record)) \ goto __post; \ } \ - __event_len = __event_get_size__##_name(tp_locvar, _args); \ - if (unlikely(__event_len < 0)) { \ - lib_ring_buffer_lost_event_too_big(__chan->chan); \ - goto __post; \ + switch (__container->type) { \ + case LTTNG_EVENT_CONTAINER_CHANNEL: \ + { \ + struct lttng_channel *__chan = lttng_event_container_get_channel(__container); \ + ssize_t __event_len; \ + size_t __event_align; \ + \ + __event_len = __event_get_size__##_name(tp_locvar, _args); \ + if (unlikely(__event_len < 0)) { \ + lib_ring_buffer_lost_event_too_big(__chan->chan); \ + goto __post; \ + } \ + __event_align = __event_get_align__##_name(tp_locvar, _args); \ + lib_ring_buffer_ctx_init(&__ctx, __chan->chan, &__lttng_probe_ctx, __event_len, \ + __event_align, -1); \ + __ret = __chan->ops->event_reserve(&__ctx, __event->id); \ + if (__ret < 0) \ + goto __post; \ + _fields \ + __chan->ops->event_commit(&__ctx); \ + break; \ + } \ + case LTTNG_EVENT_CONTAINER_COUNTER: \ + { \ + struct lttng_counter *__counter = lttng_event_container_get_counter(__container); \ + size_t __index = __event->id; \ + \ + (void) __counter->ops->counter_add(__counter->counter, &__index, 1); \ + break; \ + } \ } \ - __event_align = __event_get_align__##_name(tp_locvar, _args); \ - lib_ring_buffer_ctx_init(&__ctx, __chan->chan, &__lttng_probe_ctx, __event_len, \ - __event_align, -1); \ - __ret = __chan->ops->event_reserve(&__ctx, __event->id); \ - if (__ret < 0) \ - goto __post; \ - _fields \ - __chan->ops->event_commit(&__ctx); \ __post: \ _code_post \ barrier(); /* use before un-reserve. */ \ @@ -1226,15 +1280,13 @@ static void __event_probe__##_name(void *__data) \ { \ struct probe_local_vars { _locvar }; \ struct lttng_event *__event = __data; \ - struct lttng_probe_ctx __lttng_probe_ctx = { \ + struct lttng_probe_ctx __lttng_probe_ctx = { \ .event = __event, \ + .event_notifier = NULL, \ .interruptible = !irqs_disabled(), \ }; \ - struct lttng_channel *__chan = __event->chan; \ - struct lttng_session *__session = __chan->session; \ - struct lib_ring_buffer_ctx __ctx; \ - ssize_t __event_len; \ - size_t __event_align; \ + struct lttng_event_container *__container = __event->container; \ + struct lttng_session *__session = __container->session; \ size_t __orig_dynamic_len_offset, __dynamic_len_idx __attribute__((unused)); \ union { \ size_t __dynamic_len_removed[ARRAY_SIZE(__event_fields___##_name)]; \ @@ -1248,11 +1300,11 @@ static void __event_probe__##_name(void *__data) \ \ if (!_TP_SESSION_CHECK(session, __session)) \ return; \ - if (unlikely(!READ_ONCE(__session->active))) \ + if (unlikely(!LTTNG_READ_ONCE(__session->active))) \ return; \ - if (unlikely(!READ_ONCE(__chan->enabled))) \ + if (unlikely(!LTTNG_READ_ONCE(__container->enabled))) \ return; \ - if (unlikely(!READ_ONCE(__event->enabled))) \ + if (unlikely(!LTTNG_READ_ONCE(__event->enabled))) \ return; \ __lf = lttng_rcu_dereference(__session->pid_tracker.p); \ if (__lf && likely(!lttng_id_tracker_lookup(__lf, current->tgid))) \ @@ -1279,15 +1331,15 @@ static void __event_probe__##_name(void *__data) \ __orig_dynamic_len_offset = this_cpu_ptr(<tng_dynamic_len_stack)->offset; \ __dynamic_len_idx = __orig_dynamic_len_offset; \ _code_pre \ - if (unlikely(!list_empty(&__event->bytecode_runtime_head))) { \ + if (unlikely(!list_empty(&__event->filter_bytecode_runtime_head))) { \ struct lttng_bytecode_runtime *bc_runtime; \ int __filter_record = __event->has_enablers_without_bytecode; \ \ - __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \ + __event_prepare_interpreter_stack__##_name(__stackvar.__filter_stack_data, \ tp_locvar); \ - lttng_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \ - if (unlikely(bc_runtime->filter(bc_runtime, &__lttng_probe_ctx, \ - __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) { \ + lttng_list_for_each_entry_rcu(bc_runtime, &__event->filter_bytecode_runtime_head, node) { \ + if (unlikely(bc_runtime->interpreter_funcs.filter(bc_runtime, &__lttng_probe_ctx, \ + __stackvar.__filter_stack_data) & LTTNG_INTERPRETER_RECORD_FLAG)) { \ __filter_record = 1; \ break; \ } \ @@ -1295,19 +1347,38 @@ static void __event_probe__##_name(void *__data) \ if (likely(!__filter_record)) \ goto __post; \ } \ - __event_len = __event_get_size__##_name(tp_locvar); \ - if (unlikely(__event_len < 0)) { \ - lib_ring_buffer_lost_event_too_big(__chan->chan); \ - goto __post; \ + switch (__container->type) { \ + case LTTNG_EVENT_CONTAINER_CHANNEL: \ + { \ + struct lttng_channel *__chan = lttng_event_container_get_channel(__container); \ + struct lib_ring_buffer_ctx __ctx; \ + ssize_t __event_len; \ + size_t __event_align; \ + \ + __event_len = __event_get_size__##_name(tp_locvar); \ + if (unlikely(__event_len < 0)) { \ + lib_ring_buffer_lost_event_too_big(__chan->chan); \ + goto __post; \ + } \ + __event_align = __event_get_align__##_name(tp_locvar); \ + lib_ring_buffer_ctx_init(&__ctx, __chan->chan, &__lttng_probe_ctx, __event_len, \ + __event_align, -1); \ + __ret = __chan->ops->event_reserve(&__ctx, __event->id); \ + if (__ret < 0) \ + goto __post; \ + _fields \ + __chan->ops->event_commit(&__ctx); \ + break; \ + } \ + case LTTNG_EVENT_CONTAINER_COUNTER: \ + { \ + struct lttng_counter *__counter = lttng_event_container_get_counter(__container); \ + size_t __index = __event->id; \ + \ + (void) __counter->ops->counter_add(__counter->counter, &__index, 1); \ + break; \ + } \ } \ - __event_align = __event_get_align__##_name(tp_locvar); \ - lib_ring_buffer_ctx_init(&__ctx, __chan->chan, &__lttng_probe_ctx, __event_len, \ - __event_align, -1); \ - __ret = __chan->ops->event_reserve(&__ctx, __event->id); \ - if (__ret < 0) \ - goto __post; \ - _fields \ - __chan->ops->event_commit(&__ctx); \ __post: \ _code_post \ barrier(); /* use before un-reserve. */ \ @@ -1319,6 +1390,153 @@ __post: \ #undef __get_dynamic_len + +/* + * Stage 6.1 of tracepoint generation: generate event notifier probes + * + * Create the probe function. This function evaluates the filter bytecode and + * queue a notification to be sent to userspace. + */ + +#include /* Reset all macros within LTTNG_TRACEPOINT_EVENT */ + +#undef TP_PROTO +#define TP_PROTO(...) __VA_ARGS__ + +#undef TP_ARGS +#define TP_ARGS(...) __VA_ARGS__ + +#undef TP_FIELDS +#define TP_FIELDS(...) __VA_ARGS__ + +#undef TP_locvar +#define TP_locvar(...) __VA_ARGS__ + +#undef TP_code_pre +#define TP_code_pre(...) __VA_ARGS__ + +#undef TP_code_post +#define TP_code_post(...) __VA_ARGS__ + +/* + * Using twice size for filter stack data to hold size and pointer for + * each field (worse case). For integers, max size required is 64-bit. + * Same for double-precision floats. Those fit within + * 2*sizeof(unsigned long) for all supported architectures. + * Perform UNION (||) of filter runtime list. + */ +#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE +#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \ +static void __event_notifier_probe__##_name(void *__data, _proto) \ +{ \ + struct probe_local_vars { _locvar }; \ + struct lttng_event_notifier *__event_notifier = __data; \ + struct lttng_probe_ctx __lttng_probe_ctx = { \ + .event = NULL, \ + .event_notifier = __event_notifier, \ + .interruptible = !irqs_disabled(), \ + }; \ + union { \ + size_t __dynamic_len_removed[ARRAY_SIZE(__event_fields___##_name)]; \ + char __interpreter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \ + } __stackvar; \ + struct probe_local_vars __tp_locvar; \ + struct probe_local_vars *tp_locvar __attribute__((unused)) = \ + &__tp_locvar; \ + struct lttng_kernel_notifier_ctx __notif_ctx; \ + bool __interpreter_stack_prepared = false; \ + \ + if (unlikely(!READ_ONCE(__event_notifier->enabled))) \ + return; \ + _code_pre \ + if (unlikely(!list_empty(&__event_notifier->filter_bytecode_runtime_head))) { \ + struct lttng_bytecode_runtime *bc_runtime; \ + int __filter_record = __event_notifier->has_enablers_without_bytecode; \ + \ + __event_prepare_interpreter_stack__##_name(__stackvar.__interpreter_stack_data, \ + tp_locvar, _args); \ + __interpreter_stack_prepared = true; \ + lttng_list_for_each_entry_rcu(bc_runtime, &__event_notifier->filter_bytecode_runtime_head, node) { \ + if (unlikely(bc_runtime->interpreter_funcs.filter(bc_runtime, &__lttng_probe_ctx, \ + __stackvar.__interpreter_stack_data) & LTTNG_INTERPRETER_RECORD_FLAG)) \ + __filter_record = 1; \ + } \ + if (likely(!__filter_record)) \ + goto __post; \ + } \ + \ + __notif_ctx.eval_capture = LTTNG_READ_ONCE(__event_notifier->eval_capture); \ + if (unlikely(!__interpreter_stack_prepared && __notif_ctx.eval_capture)) \ + __event_prepare_interpreter_stack__##_name( \ + __stackvar.__interpreter_stack_data, \ + tp_locvar, _args); \ + \ + __event_notifier->send_notification(__event_notifier, \ + &__lttng_probe_ctx, \ + __stackvar.__interpreter_stack_data, \ + &__notif_ctx); \ + \ +__post: \ + _code_post \ + return; \ +} + +#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS +#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \ +static void __event_notifier_probe__##_name(void *__data) \ +{ \ + struct probe_local_vars { _locvar }; \ + struct lttng_event_notifier *__event_notifier = __data; \ + struct lttng_probe_ctx __lttng_probe_ctx = { \ + .event = NULL, \ + .event_notifier = __event_notifier, \ + .interruptible = !irqs_disabled(), \ + }; \ + union { \ + size_t __dynamic_len_removed[ARRAY_SIZE(__event_fields___##_name)]; \ + char __interpreter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \ + } __stackvar; \ + struct probe_local_vars __tp_locvar; \ + struct probe_local_vars *tp_locvar __attribute__((unused)) = \ + &__tp_locvar; \ + struct lttng_kernel_notifier_ctx __notif_ctx; \ + bool __interpreter_stack_prepared = false; \ + \ + if (unlikely(!READ_ONCE(__event_notifier->enabled))) \ + return; \ + _code_pre \ + if (unlikely(!list_empty(&__event_notifier->filter_bytecode_runtime_head))) { \ + struct lttng_bytecode_runtime *bc_runtime; \ + int __filter_record = __event_notifier->has_enablers_without_bytecode; \ + \ + __event_prepare_interpreter_stack__##_name(__stackvar.__interpreter_stack_data, \ + tp_locvar); \ + __interpreter_stack_prepared = true; \ + lttng_list_for_each_entry_rcu(bc_runtime, &__event_notifier->filter_bytecode_runtime_head, node) { \ + if (unlikely(bc_runtime->interpreter_funcs.filter(bc_runtime, &__lttng_probe_ctx, \ + __stackvar.__interpreter_stack_data) & LTTNG_INTERPRETER_RECORD_FLAG)) \ + __filter_record = 1; \ + } \ + if (likely(!__filter_record)) \ + goto __post; \ + } \ + \ + __notif_ctx.eval_capture = LTTNG_READ_ONCE(__event_notifier->eval_capture); \ + if (unlikely(!__interpreter_stack_prepared && __notif_ctx.eval_capture)) \ + __event_prepare_interpreter_stack__##_name( \ + __stackvar.__interpreter_stack_data, \ + tp_locvar); \ + \ + __event_notifier->send_notification(__event_notifier, \ + &__lttng_probe_ctx, \ + __stackvar.__interpreter_stack_data, \ + &__notif_ctx); \ +__post: \ + _code_post \ + return; \ +} + +#include TRACE_INCLUDE(TRACE_INCLUDE_FILE) /* * Stage 7 of the trace events. * @@ -1333,6 +1551,10 @@ __post: \ #define TP_PROBE_CB(_template) &__event_probe__##_template #endif +#ifndef TP_EVENT_NOTIFIER_PROBE_CB +#define TP_EVENT_NOTIFIER_PROBE_CB(_template) &__event_notifier_probe__##_template +#endif + #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \ static const struct lttng_event_desc __event_desc___##_map = { \ @@ -1342,6 +1564,7 @@ static const struct lttng_event_desc __event_desc___##_map = { \ .probe_callback = (void *) TP_PROBE_CB(_template), \ .nr_fields = ARRAY_SIZE(__event_fields___##_template), \ .owner = THIS_MODULE, \ + .event_notifier_callback = (void *) TP_EVENT_NOTIFIER_PROBE_CB(_template), \ }; #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP