Use event enabler for event recorder creation for all instrumentation types
[lttng-modules.git] / src / lttng-events.c
index 8d2bf46991d78703a2bbeed96333282211319600..02c62b0cefaa269aa15a9b4c3e17f806d33ac163 100644 (file)
@@ -28,6 +28,7 @@
 #include <linux/vmalloc.h>
 #include <linux/dmi.h>
 
+#include <wrapper/compiler_attributes.h>
 #include <wrapper/uuid.h>
 #include <wrapper/vmalloc.h>   /* for wrapper_vmalloc_sync_mappings() */
 #include <wrapper/random.h>
@@ -65,7 +66,6 @@ static struct kmem_cache *event_notifier_private_cache;
 
 static void lttng_session_lazy_sync_event_enablers(struct lttng_kernel_session *session);
 static void lttng_session_sync_event_enablers(struct lttng_kernel_session *session);
-static void lttng_event_enabler_destroy(struct lttng_event_enabler *event_enabler);
 static void lttng_event_notifier_enabler_destroy(struct lttng_event_notifier_enabler *event_notifier_enabler);
 static void lttng_event_notifier_group_sync_enablers(struct lttng_event_notifier_group *event_notifier_group);
 
@@ -93,7 +93,8 @@ int _lttng_field_statedump(struct lttng_kernel_session *session,
 
 void synchronize_trace(void)
 {
-#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,1,0))
+#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,1,0) || \
+       LTTNG_RHEL_KERNEL_RANGE(4,18,0,193,0,0, 4,19,0,0,0,0))
        synchronize_rcu();
 #else
        synchronize_sched();
@@ -658,12 +659,14 @@ int lttng_event_enable(struct lttng_kernel_event_common *event)
                goto end;
        }
        switch (event->priv->instrumentation) {
-       case LTTNG_KERNEL_ABI_TRACEPOINT:       /* Fall-through */
+       case LTTNG_KERNEL_ABI_TRACEPOINT:
+               lttng_fallthrough;
        case LTTNG_KERNEL_ABI_SYSCALL:
                ret = -EINVAL;
                break;
 
-       case LTTNG_KERNEL_ABI_KPROBE:           /* Fall-through */
+       case LTTNG_KERNEL_ABI_KPROBE:
+               lttng_fallthrough;
        case LTTNG_KERNEL_ABI_UPROBE:
                WRITE_ONCE(event->enabled, 1);
                break;
@@ -672,8 +675,10 @@ int lttng_event_enable(struct lttng_kernel_event_common *event)
                ret = lttng_kretprobes_event_enable_state(event, 1);
                break;
 
-       case LTTNG_KERNEL_ABI_FUNCTION:         /* Fall-through */
-       case LTTNG_KERNEL_ABI_NOOP:             /* Fall-through */
+       case LTTNG_KERNEL_ABI_FUNCTION:
+               lttng_fallthrough;
+       case LTTNG_KERNEL_ABI_NOOP:
+               lttng_fallthrough;
        default:
                WARN_ON_ONCE(1);
                ret = -EINVAL;
@@ -718,12 +723,14 @@ int lttng_event_disable(struct lttng_kernel_event_common *event)
                goto end;
        }
        switch (event->priv->instrumentation) {
-       case LTTNG_KERNEL_ABI_TRACEPOINT:       /* Fall-through */
+       case LTTNG_KERNEL_ABI_TRACEPOINT:
+               lttng_fallthrough;
        case LTTNG_KERNEL_ABI_SYSCALL:
                ret = -EINVAL;
                break;
 
-       case LTTNG_KERNEL_ABI_KPROBE:           /* Fall-through */
+       case LTTNG_KERNEL_ABI_KPROBE:
+               lttng_fallthrough;
        case LTTNG_KERNEL_ABI_UPROBE:
                WRITE_ONCE(event->enabled, 0);
                break;
@@ -732,8 +739,10 @@ int lttng_event_disable(struct lttng_kernel_event_common *event)
                ret = lttng_kretprobes_event_enable_state(event, 0);
                break;
 
-       case LTTNG_KERNEL_ABI_FUNCTION:         /* Fall-through */
-       case LTTNG_KERNEL_ABI_NOOP:             /* Fall-through */
+       case LTTNG_KERNEL_ABI_FUNCTION:
+               lttng_fallthrough;
+       case LTTNG_KERNEL_ABI_NOOP:
+               lttng_fallthrough;
        default:
                WARN_ON_ONCE(1);
                ret = -EINVAL;
@@ -850,11 +859,12 @@ void _lttng_metadata_channel_hangup(struct lttng_metadata_stream *stream)
  * Supports event creation while tracing session is active.
  * Needs to be called with sessions mutex held.
  */
-struct lttng_kernel_event_recorder *_lttng_kernel_event_recorder_create(struct lttng_kernel_channel_buffer *chan,
-                               struct lttng_kernel_abi_event *event_param,
-                               const struct lttng_kernel_event_desc *event_desc,
-                               enum lttng_kernel_abi_instrumentation itype)
+struct lttng_kernel_event_recorder *_lttng_kernel_event_recorder_create(struct lttng_event_enabler *event_enabler,
+                               const struct lttng_kernel_event_desc *event_desc)
 {
+       struct lttng_kernel_channel_buffer *chan = event_enabler->chan;
+       struct lttng_kernel_abi_event *event_param = &event_enabler->base.event_param;
+       enum lttng_kernel_abi_instrumentation itype = event_param->instrumentation;
        struct lttng_kernel_session *session = chan->parent.session;
        struct lttng_kernel_event_recorder *event_recorder;
        struct lttng_kernel_event_recorder_private *event_recorder_priv;
@@ -872,15 +882,20 @@ struct lttng_kernel_event_recorder *_lttng_kernel_event_recorder_create(struct l
                event_name = event_desc->event_name;
                break;
 
-       case LTTNG_KERNEL_ABI_KPROBE:           /* Fall-through */
-       case LTTNG_KERNEL_ABI_UPROBE:           /* Fall-through */
-       case LTTNG_KERNEL_ABI_KRETPROBE:        /* Fall-through */
+       case LTTNG_KERNEL_ABI_KPROBE:
+               lttng_fallthrough;
+       case LTTNG_KERNEL_ABI_UPROBE:
+               lttng_fallthrough;
+       case LTTNG_KERNEL_ABI_KRETPROBE:
+               lttng_fallthrough;
        case LTTNG_KERNEL_ABI_SYSCALL:
                event_name = event_param->name;
                break;
 
-       case LTTNG_KERNEL_ABI_FUNCTION:         /* Fall-through */
-       case LTTNG_KERNEL_ABI_NOOP:             /* Fall-through */
+       case LTTNG_KERNEL_ABI_FUNCTION:
+               lttng_fallthrough;
+       case LTTNG_KERNEL_ABI_NOOP:
+               lttng_fallthrough;
        default:
                WARN_ON_ONCE(1);
                ret = -EINVAL;
@@ -1092,8 +1107,10 @@ struct lttng_kernel_event_recorder *_lttng_kernel_event_recorder_create(struct l
                WARN_ON_ONCE(!ret);
                break;
 
-       case LTTNG_KERNEL_ABI_FUNCTION:         /* Fall-through */
-       case LTTNG_KERNEL_ABI_NOOP:             /* Fall-through */
+       case LTTNG_KERNEL_ABI_FUNCTION:
+               lttng_fallthrough;
+       case LTTNG_KERNEL_ABI_NOOP:
+               lttng_fallthrough;
        default:
                WARN_ON_ONCE(1);
                ret = -EINVAL;
@@ -1140,15 +1157,20 @@ struct lttng_kernel_event_notifier *_lttng_event_notifier_create(
                event_name = event_desc->event_name;
                break;
 
-       case LTTNG_KERNEL_ABI_KPROBE:           /* Fall-through */
-       case LTTNG_KERNEL_ABI_UPROBE:           /* Fall-through */
+       case LTTNG_KERNEL_ABI_KPROBE:
+               lttng_fallthrough;
+       case LTTNG_KERNEL_ABI_UPROBE:
+               lttng_fallthrough;
        case LTTNG_KERNEL_ABI_SYSCALL:
                event_name = event_notifier_param->event.name;
                break;
 
-       case LTTNG_KERNEL_ABI_KRETPROBE:        /* Fall-through */
-       case LTTNG_KERNEL_ABI_FUNCTION:         /* Fall-through */
-       case LTTNG_KERNEL_ABI_NOOP:             /* Fall-through */
+       case LTTNG_KERNEL_ABI_KRETPROBE:
+               lttng_fallthrough;
+       case LTTNG_KERNEL_ABI_FUNCTION:
+               lttng_fallthrough;
+       case LTTNG_KERNEL_ABI_NOOP:
+               lttng_fallthrough;
        default:
                WARN_ON_ONCE(1);
                ret = -EINVAL;
@@ -1295,9 +1317,12 @@ struct lttng_kernel_event_notifier *_lttng_event_notifier_create(
                WARN_ON_ONCE(!ret);
                break;
 
-       case LTTNG_KERNEL_ABI_KRETPROBE:        /* Fall-through */
-       case LTTNG_KERNEL_ABI_FUNCTION:         /* Fall-through */
-       case LTTNG_KERNEL_ABI_NOOP:             /* Fall-through */
+       case LTTNG_KERNEL_ABI_KRETPROBE:
+               lttng_fallthrough;
+       case LTTNG_KERNEL_ABI_FUNCTION:
+               lttng_fallthrough;
+       case LTTNG_KERNEL_ABI_NOOP:
+               lttng_fallthrough;
        default:
                WARN_ON_ONCE(1);
                ret = -EINVAL;
@@ -1370,15 +1395,13 @@ int lttng_kernel_counter_clear(struct lttng_counter *counter,
        return counter->ops->counter_clear(counter->counter, dim_indexes);
 }
 
-struct lttng_kernel_event_recorder *lttng_kernel_event_recorder_create(struct lttng_kernel_channel_buffer *chan,
-                               struct lttng_kernel_abi_event *event_param,
-                               const struct lttng_kernel_event_desc *event_desc,
-                               enum lttng_kernel_abi_instrumentation itype)
+struct lttng_kernel_event_recorder *lttng_kernel_event_recorder_create(struct lttng_event_enabler *event_enabler,
+                               const struct lttng_kernel_event_desc *event_desc)
 {
        struct lttng_kernel_event_recorder *event;
 
        mutex_lock(&sessions_mutex);
-       event = _lttng_kernel_event_recorder_create(chan, event_param, event_desc, itype);
+       event = _lttng_kernel_event_recorder_create(event_enabler, event_desc);
        mutex_unlock(&sessions_mutex);
        return event;
 }
@@ -1422,14 +1445,18 @@ void register_event(struct lttng_kernel_event_recorder *event_recorder)
                ret = lttng_syscall_filter_enable_event(event_recorder->chan, event_recorder);
                break;
 
-       case LTTNG_KERNEL_ABI_KPROBE:           /* Fall-through */
-       case LTTNG_KERNEL_ABI_UPROBE:           /* Fall-through */
+       case LTTNG_KERNEL_ABI_KPROBE:
+               lttng_fallthrough;
+       case LTTNG_KERNEL_ABI_UPROBE:
+               lttng_fallthrough;
        case LTTNG_KERNEL_ABI_KRETPROBE:
                ret = 0;
                break;
 
-       case LTTNG_KERNEL_ABI_FUNCTION:         /* Fall-through */
-       case LTTNG_KERNEL_ABI_NOOP:             /* Fall-through */
+       case LTTNG_KERNEL_ABI_FUNCTION:
+               lttng_fallthrough;
+       case LTTNG_KERNEL_ABI_NOOP:
+               lttng_fallthrough;
        default:
                WARN_ON_ONCE(1);
        }
@@ -1480,7 +1507,8 @@ int _lttng_event_unregister(struct lttng_kernel_event_recorder *event_recorder)
                ret = 0;
                break;
 
-       case LTTNG_KERNEL_ABI_FUNCTION: /* Fall-through */
+       case LTTNG_KERNEL_ABI_FUNCTION:
+               lttng_fallthrough;
        default:
                WARN_ON_ONCE(1);
        }
@@ -1511,14 +1539,18 @@ void register_event_notifier(struct lttng_kernel_event_notifier *event_notifier)
                ret = lttng_syscall_filter_enable_event_notifier(event_notifier);
                break;
 
-       case LTTNG_KERNEL_ABI_KPROBE:           /* Fall-through */
+       case LTTNG_KERNEL_ABI_KPROBE:
+               lttng_fallthrough;
        case LTTNG_KERNEL_ABI_UPROBE:
                ret = 0;
                break;
 
-       case LTTNG_KERNEL_ABI_KRETPROBE:        /* Fall-through */
-       case LTTNG_KERNEL_ABI_FUNCTION:         /* Fall-through */
-       case LTTNG_KERNEL_ABI_NOOP:             /* Fall-through */
+       case LTTNG_KERNEL_ABI_KRETPROBE:
+               lttng_fallthrough;
+       case LTTNG_KERNEL_ABI_FUNCTION:
+               lttng_fallthrough;
+       case LTTNG_KERNEL_ABI_NOOP:
+               lttng_fallthrough;
        default:
                WARN_ON_ONCE(1);
        }
@@ -1558,9 +1590,12 @@ int _lttng_event_notifier_unregister(
                ret = lttng_syscall_filter_disable_event_notifier(event_notifier);
                break;
 
-       case LTTNG_KERNEL_ABI_KRETPROBE:        /* Fall-through */
-       case LTTNG_KERNEL_ABI_FUNCTION:         /* Fall-through */
-       case LTTNG_KERNEL_ABI_NOOP:             /* Fall-through */
+       case LTTNG_KERNEL_ABI_KRETPROBE:
+               lttng_fallthrough;
+       case LTTNG_KERNEL_ABI_FUNCTION:
+               lttng_fallthrough;
+       case LTTNG_KERNEL_ABI_NOOP:
+               lttng_fallthrough;
        default:
                WARN_ON_ONCE(1);
        }
@@ -1613,8 +1648,10 @@ void _lttng_event_destroy(struct lttng_kernel_event_common *event)
                        lttng_uprobes_destroy_event_private(event_recorder);
                        break;
 
-               case LTTNG_KERNEL_ABI_FUNCTION:         /* Fall-through */
-               case LTTNG_KERNEL_ABI_NOOP:             /* Fall-through */
+               case LTTNG_KERNEL_ABI_FUNCTION:
+                       lttng_fallthrough;
+               case LTTNG_KERNEL_ABI_NOOP:
+                       lttng_fallthrough;
                default:
                        WARN_ON_ONCE(1);
                }
@@ -1646,9 +1683,12 @@ void _lttng_event_destroy(struct lttng_kernel_event_common *event)
                        lttng_uprobes_destroy_event_notifier_private(event_notifier);
                        break;
 
-               case LTTNG_KERNEL_ABI_KRETPROBE:        /* Fall-through */
-               case LTTNG_KERNEL_ABI_FUNCTION:         /* Fall-through */
-               case LTTNG_KERNEL_ABI_NOOP:             /* Fall-through */
+               case LTTNG_KERNEL_ABI_KRETPROBE:
+                       lttng_fallthrough;
+               case LTTNG_KERNEL_ABI_FUNCTION:
+                       lttng_fallthrough;
+               case LTTNG_KERNEL_ABI_NOOP:
+                       lttng_fallthrough;
                default:
                        WARN_ON_ONCE(1);
                }
@@ -2118,8 +2158,7 @@ void lttng_create_tracepoint_event_if_missing(struct lttng_event_enabler *event_
                         * We need to create an event for this
                         * event probe.
                         */
-                       event_recorder = _lttng_kernel_event_recorder_create(event_enabler->chan,
-                                       NULL, desc, LTTNG_KERNEL_ABI_TRACEPOINT);
+                       event_recorder = _lttng_kernel_event_recorder_create(event_enabler, desc);
                        if (!event_recorder) {
                                printk(KERN_INFO "LTTng: Unable to create event %s\n",
                                        probe_desc->event_desc[i]->event_name);
@@ -2450,11 +2489,17 @@ struct lttng_event_enabler *lttng_event_enabler_create(
        event_enabler->chan = chan;
        /* ctx left NULL */
        event_enabler->base.enabled = 0;
+       return event_enabler;
+}
+
+void lttng_event_enabler_session_add(struct lttng_kernel_session *session,
+               struct lttng_event_enabler *event_enabler)
+{
        mutex_lock(&sessions_mutex);
-       list_add(&event_enabler->node, &event_enabler->chan->parent.session->priv->enablers_head);
-       lttng_session_lazy_sync_event_enablers(event_enabler->chan->parent.session);
+       list_add(&event_enabler->node, &session->priv->enablers_head);
+       event_enabler->published = true;
+       lttng_session_lazy_sync_event_enablers(session);
        mutex_unlock(&sessions_mutex);
-       return event_enabler;
 }
 
 int lttng_event_enabler_enable(struct lttng_event_enabler *event_enabler)
@@ -2548,12 +2593,12 @@ void lttng_enabler_destroy(struct lttng_enabler *enabler)
        }
 }
 
-static
 void lttng_event_enabler_destroy(struct lttng_event_enabler *event_enabler)
 {
        lttng_enabler_destroy(lttng_event_enabler_as_enabler(event_enabler));
 
-       list_del(&event_enabler->node);
+       if (event_enabler->published)
+               list_del(&event_enabler->node);
        kfree(event_enabler);
 }
 
@@ -2712,7 +2757,8 @@ void lttng_session_sync_event_enablers(struct lttng_kernel_session *session)
                int nr_filters = 0;
 
                switch (event_recorder_priv->parent.instrumentation) {
-               case LTTNG_KERNEL_ABI_TRACEPOINT:       /* Fall-through */
+               case LTTNG_KERNEL_ABI_TRACEPOINT:
+                       lttng_fallthrough;
                case LTTNG_KERNEL_ABI_SYSCALL:
                        /* Enable events */
                        list_for_each_entry(enabler_ref,
@@ -2806,7 +2852,8 @@ void lttng_event_notifier_group_sync_enablers(struct lttng_event_notifier_group
                int nr_filters = 0, nr_captures = 0;
 
                switch (event_notifier_priv->parent.instrumentation) {
-               case LTTNG_KERNEL_ABI_TRACEPOINT:       /* Fall-through */
+               case LTTNG_KERNEL_ABI_TRACEPOINT:
+                       lttng_fallthrough;
                case LTTNG_KERNEL_ABI_SYSCALL:
                        /* Enable event_notifiers */
                        list_for_each_entry(enabler_ref,
@@ -2924,7 +2971,7 @@ int lttng_metadata_output_channel(struct lttng_metadata_stream *stream,
        }
        stream->transport->ops.event_write(&ctx,
                        stream->metadata_cache->data + stream->metadata_in,
-                       reserve_len);
+                       reserve_len, 1);
        stream->transport->ops.event_commit(&ctx);
        stream->metadata_in += reserve_len;
        if (reserve_len < len)
@@ -3876,7 +3923,7 @@ int print_escaped_ctf_string(struct lttng_kernel_session *session, const char *s
                        if (ret)
                                goto error;
                        /* We still print the current char */
-                       /* Fallthrough */
+                       lttng_fallthrough;
                default:
                        ret = lttng_metadata_printf(session, "%c", cur);
                        break;
@@ -4362,6 +4409,9 @@ static int __init lttng_events_init(void)
 #else
                "");
 #endif
+#ifdef CONFIG_LTTNG_EXPERIMENTAL_BITWISE_ENUM
+       printk(KERN_NOTICE "LTTng: Experimental bitwise enum enabled.\n");
+#endif /* CONFIG_LTTNG_EXPERIMENTAL_BITWISE_ENUM */
        return 0;
 
 error_hotplug:
This page took 0.02949 seconds and 4 git commands to generate.