Use template header for overwrite vs discard modes
[lttng-modules.git] / ltt-events.c
index a85b7932e38e42ffda5fba7fa501aa55b0282381..21c6d29e2a2d5d5ba592e9a5aacf40a49f4308d1 100644 (file)
@@ -13,6 +13,14 @@ static LIST_HEAD(sessions);
 static DEFINE_MUTEX(sessions_mutex);
 static struct kmem_cache *event_cache;
 
+static void synchronize_trace(void)
+{
+       synchronize_sched();
+#ifdef CONFIG_PREEMPT_RT
+       synchronize_rcu();
+#endif
+}
+
 struct ltt_session *ltt_session_create(char *name)
 {
        struct ltt_session *session;
@@ -41,6 +49,8 @@ int ltt_session_destroy(struct ltt_session *session)
        struct ltt_event *event, *tmpevent;
 
        mutex_lock(&sessions_mutex);
+       session->active = 0;
+       synchronize_trace();    /* Wait for in-flight events to complete */
        list_for_each_entry_safe(event, tmpevent, &session->events, list)
                _ltt_event_destroy(event);
        list_for_each_entry_safe(chan, tmpchan, &session->chan, list)
@@ -59,6 +69,8 @@ struct ltt_channel *ltt_channel_create(struct ltt_session *session, char *name,
        struct ltt_channel *chan;
 
        mutex_lock(&sessions_mutex);
+       if (session->active)
+               goto active;    /* Refuse to add channel to active session */
        list_for_each_entry(chan, &session->chan, list)
                if (!strcmp(chan->name, name))
                        goto exist;
@@ -74,6 +86,7 @@ struct ltt_channel *ltt_channel_create(struct ltt_session *session, char *name,
        return chan;
 
 exist:
+active:
        mutex_unlock(&sessions_mutex);
        return NULL;
 }
@@ -83,16 +96,23 @@ exist:
  */
 int _ltt_channel_destroy(struct ltt_channel *chan)
 {
+       /* TODO: destroy rb channel */
        list_del(&chan->list);
        kfree(chan);
 }
 
+/*
+ * Supports event creation while tracing session is active.
+ */
 struct ltt_event *ltt_event_create(struct ltt_channel *chan, char *name,
                                   void *filter)
 {
        struct ltt_event *event;
+       int ret;
 
        mutex_lock(&sessions_mutex);
+       if (chan->free_event_id == -1UL)
+               goto full;
        /*
         * This is O(n^2) (for each event loop called at event creation).
         * Might require a hash if we have lots of events.
@@ -109,15 +129,17 @@ struct ltt_event *ltt_event_create(struct ltt_channel *chan, char *name,
        strcpy(event->name, name);
        event->chan = chan;
        event->filter = filter;
-       event->id = atomic_inc_return(&chan->free_event_id) - 1;
-       /* TODO register to tracepoint */
+       event->id = chan->free_event_id++;
        mutex_unlock(&sessions_mutex);
+       /* Populate ltt_event structure before tracepoint registration. */
+       smp_wmb();
        return event;
 
 error:
        kmem_cache_free(event);
 cache_error:
 exist:
+full:
        mutex_unlock(&sessions_mutex);
        return NULL;
 }
@@ -139,10 +161,23 @@ static int __init ltt_events_init(void)
        events_cache = KMEM_CACHE(ltt_event, 0);
        if (!events_cache)
                return -ENOMEM;
+
+       /* TODO: show ABI to userspace */
+
        return 0;
 }
 
 static void __exit ltt_events_exit(void)
 {
+       struct ltt_session *session, *tmpsession;
+
+       /* TODO: hide ABI from userspace, wait for callers to release refs. */
+
+       list_for_each_entry_safe(session, tmpsession, &sessions, list)
+               ltt_session_destroy(session);
        kmem_cache_destroy(events_cache);
 }
+
+MODULE_LICENSE("GPL and additional rights");
+MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@efficios.com>");
+MODULE_DESCRIPTION("LTTng Events");
This page took 0.026117 seconds and 4 git commands to generate.