SoW-2019-0002: Dynamic Snapshot
[deliverable/lttng-modules.git] / probes / lttng-tracepoint-event-impl.h
index 321cdfa44c61afac7d79c857e4655bf47cc98737..0ffa1ea9d19e37a5dfccb8edd0325aa43e24f23f 100644 (file)
@@ -170,6 +170,41 @@ void __event_template_proto___##_name(void);
 
 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
 
+/*
+ * Stage 1.2 of the trace trigger.
+ *
+ * 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 <probes/lttng-events-reset.h> /* 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 __trigger_template_proto___##_template(_proto);
+
+#undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
+#define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
+void __trigger_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 __trigger_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 __trigger_template_proto___##_name(void);
+
+#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
+
+
 /*
  * Stage 1.2 of tracepoint event generation
  *
@@ -448,6 +483,28 @@ static void __event_probe__##_name(void *__data);
 
 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
 
+/*
+ * Stage 3.1 of the trace triggers.
+ *
+ * Create trigger probe callback prototypes.
+ */
+
+/* Reset all macros within TRACEPOINT_EVENT */
+#include <probes/lttng-events-reset.h>
+
+#undef TP_PROTO
+#define TP_PROTO(...)  __VA_ARGS__
+
+#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
+#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
+static void __trigger_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 __trigger_probe__##_name(void *__data);
+
+#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
+
 /*
  * Stage 4 of the trace events.
  *
@@ -1112,6 +1169,7 @@ static void __event_probe__##_name(void *__data, _proto)                \
        struct lttng_event *__event = __data;                                 \
        struct lttng_probe_ctx __lttng_probe_ctx = {                                  \
                .event = __event,                                             \
+               .trigger = NULL,                                              \
                .interruptible = !irqs_disabled(),                            \
        };                                                                    \
        struct lttng_channel *__chan = __event->chan;                         \
@@ -1205,6 +1263,7 @@ static void __event_probe__##_name(void *__data)                        \
        struct lttng_event *__event = __data;                                 \
        struct lttng_probe_ctx __lttng_probe_ctx = {                                  \
                .event = __event,                                             \
+               .trigger = NULL,                                              \
                .interruptible = !irqs_disabled(),                            \
        };                                                                    \
        struct lttng_channel *__chan = __event->chan;                         \
@@ -1294,6 +1353,124 @@ __post:                                                                       \
 
 #undef __get_dynamic_len
 
+/*
+ *
+ */
+
+#include <probes/lttng-events-reset.h> /* 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 __trigger_probe__##_name(void *__data, _proto)                   \
+{                                                                            \
+       struct probe_local_vars { _locvar };                                  \
+       struct lttng_trigger *__trigger = __data;                             \
+       struct lttng_probe_ctx __lttng_probe_ctx = {                          \
+               .event = NULL,                                                \
+               .trigger = __trigger,                                         \
+               .interruptible = !irqs_disabled(),                            \
+       };                                                                    \
+       union {                                                               \
+               size_t __dynamic_len_removed[ARRAY_SIZE(__event_fields___##_name)];   \
+               char __filter_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;                                         \
+                                                                             \
+       if (unlikely(!READ_ONCE(__trigger->enabled)))                         \
+               return;                                                       \
+       _code_pre                                                             \
+       if (unlikely(!list_empty(&__trigger->bytecode_runtime_head))) {       \
+               struct lttng_bytecode_runtime *bc_runtime;                    \
+               int __filter_record = __trigger->has_enablers_without_bytecode; \
+                                                                             \
+               __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \
+                               tp_locvar, _args);                                    \
+               lttng_list_for_each_entry_rcu(bc_runtime, &__trigger->bytecode_runtime_head, node) { \
+                       if (unlikely(bc_runtime->filter(bc_runtime, &__lttng_probe_ctx,       \
+                                       __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
+                               __filter_record = 1;                          \
+               }                                                             \
+               if (likely(!__filter_record))                                 \
+                       goto __post;                                          \
+       }                                                                     \
+                                                                             \
+       __trigger->send_notification(__trigger);                              \
+__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 __trigger_probe__##_name(void *__data)                           \
+{                                                                            \
+       struct probe_local_vars { _locvar };                                  \
+       struct lttng_trigger *__trigger = __data;                             \
+       struct lttng_probe_ctx __lttng_probe_ctx = {                          \
+               .event = NULL,                                                \
+               .trigger = __trigger,                                         \
+               .interruptible = !irqs_disabled(),                            \
+       };                                                                    \
+       union {                                                               \
+               size_t __dynamic_len_removed[ARRAY_SIZE(__event_fields___##_name)];   \
+               char __filter_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;                                         \
+                                                                             \
+       if (unlikely(!READ_ONCE(__trigger->enabled)))                         \
+               return;                                                       \
+       _code_pre                                                             \
+       if (unlikely(!list_empty(&__trigger->bytecode_runtime_head))) {       \
+               struct lttng_bytecode_runtime *bc_runtime;                    \
+               int __filter_record = __trigger->has_enablers_without_bytecode; \
+                                                                             \
+               __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \
+                               tp_locvar);                                   \
+               lttng_list_for_each_entry_rcu(bc_runtime, &__trigger->bytecode_runtime_head, node) { \
+                       if (unlikely(bc_runtime->filter(bc_runtime, &__lttng_probe_ctx, \
+                                       __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
+                               __filter_record = 1;                          \
+               }                                                             \
+               if (likely(!__filter_record))                                 \
+                       goto __post;                                          \
+       }                                                                     \
+                                                                             \
+       __trigger->send_notification(__trigger);                              \
+__post:                                                                              \
+       _code_post                                                            \
+       return;                                                               \
+}
+
+#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
 /*
  * Stage 7 of the trace events.
  *
@@ -1308,6 +1485,10 @@ __post:                                                                        \
 #define TP_PROBE_CB(_template) &__event_probe__##_template
 #endif
 
+#ifndef TP_TRIGGER_PROBE_CB
+#define TP_TRIGGER_PROBE_CB(_template) &__trigger_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 = {         \
@@ -1317,6 +1498,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,                                           \
+       .trigger_callback = (void *) TP_TRIGGER_PROBE_CB(_template),            \
 };
 
 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
This page took 0.026577 seconds and 5 git commands to generate.