Export consumer ABI, implement ring buffer modifications for consumer
[lttng-ust.git] / libust / ltt-events.c
index 39167d4b82ccdcc4f10668d0b8ab2ab09be1f732..18fb8599ee09a5e87b5f529cbe4c4750d57185bf 100644 (file)
@@ -34,16 +34,17 @@ typedef u32 uint32_t;
 
 /*
  * The sessions mutex is the centralized mutex across UST tracing
- * control and probe registration.
+ * control and probe registration. All operations within this file are
+ * called by the communication thread, under ust_lock protection.
  */
 static DEFINE_MUTEX(sessions_mutex);
 
-void lock_ust(void)
+void ust_lock(void)
 {
        pthread_mutex_lock(&sessions_mutex);
 }
 
-void unlock_ust(void)
+void ust_unlock(void)
 {
        pthread_mutex_unlock(&sessions_mutex);
 }
@@ -84,7 +85,6 @@ static
 int add_pending_probe(struct ltt_event *event, const char *name)
 {
        struct cds_hlist_head *head;
-       struct cds_hlist_node *node;
        struct ust_pending_probe *e;
        size_t name_len = strlen(name) + 1;
        u32 hash = jhash(name, name_len - 1, 0);
@@ -163,12 +163,10 @@ struct ltt_session *ltt_session_create(void)
        session = zmalloc(sizeof(struct ltt_session));
        if (!session)
                return NULL;
-       pthread_mutex_lock(&sessions_mutex);
        CDS_INIT_LIST_HEAD(&session->chan);
        CDS_INIT_LIST_HEAD(&session->events);
        uuid_generate(session->uuid);
        cds_list_add(&session->list, &sessions);
-       pthread_mutex_unlock(&sessions_mutex);
        return session;
 }
 
@@ -178,7 +176,6 @@ void ltt_session_destroy(struct ltt_session *session)
        struct ltt_event *event, *tmpevent;
        int ret;
 
-       pthread_mutex_lock(&sessions_mutex);
        CMM_ACCESS_ONCE(session->active) = 0;
        cds_list_for_each_entry(event, &session->events, list) {
                ret = _ltt_event_unregister(event);
@@ -190,7 +187,6 @@ void ltt_session_destroy(struct ltt_session *session)
        cds_list_for_each_entry_safe(chan, tmpchan, &session->chan, list)
                _ltt_channel_destroy(chan);
        cds_list_del(&session->list);
-       pthread_mutex_unlock(&sessions_mutex);
        free(session);
 }
 
@@ -199,7 +195,6 @@ int ltt_session_enable(struct ltt_session *session)
        int ret = 0;
        struct ltt_channel *chan;
 
-       pthread_mutex_lock(&sessions_mutex);
        if (session->active) {
                ret = -EBUSY;
                goto end;
@@ -224,7 +219,6 @@ int ltt_session_enable(struct ltt_session *session)
        if (ret)
                CMM_ACCESS_ONCE(session->active) = 0;
 end:
-       pthread_mutex_unlock(&sessions_mutex);
        return ret;
 }
 
@@ -232,14 +226,12 @@ int ltt_session_disable(struct ltt_session *session)
 {
        int ret = 0;
 
-       pthread_mutex_lock(&sessions_mutex);
        if (!session->active) {
                ret = -EBUSY;
                goto end;
        }
        CMM_ACCESS_ONCE(session->active) = 0;
 end:
-       pthread_mutex_unlock(&sessions_mutex);
        return ret;
 }
 
@@ -307,12 +299,13 @@ struct ltt_channel *ltt_channel_create(struct ltt_session *session,
                                       void *buf_addr,
                                       size_t subbuf_size, size_t num_subbuf,
                                       unsigned int switch_timer_interval,
-                                      unsigned int read_timer_interval)
+                                      unsigned int read_timer_interval,
+                                      int *shm_fd, int *wait_fd,
+                                      uint64_t *memory_map_size)
 {
        struct ltt_channel *chan;
        struct ltt_transport *transport;
 
-       pthread_mutex_lock(&sessions_mutex);
        if (session->been_active)
                goto active;    /* Refuse to add channel to active session */
        transport = ltt_transport_find(transport_name);
@@ -333,13 +326,13 @@ struct ltt_channel *ltt_channel_create(struct ltt_session *session,
         */
        transport->ops.channel_create("[lttng]", chan, buf_addr,
                        subbuf_size, num_subbuf, switch_timer_interval,
-                       read_timer_interval);
+                       read_timer_interval, shm_fd, wait_fd,
+                       memory_map_size);
        if (!chan->chan)
                goto create_error;
        chan->enabled = 1;
        chan->ops = &transport->ops;
        cds_list_add(&chan->list, &session->chan);
-       pthread_mutex_unlock(&sessions_mutex);
        return chan;
 
 create_error:
@@ -347,7 +340,6 @@ create_error:
 nomem:
 notransport:
 active:
-       pthread_mutex_unlock(&sessions_mutex);
        return NULL;
 }
 
@@ -373,7 +365,6 @@ struct ltt_event *ltt_event_create(struct ltt_channel *chan,
        struct ltt_event *event;
        int ret;
 
-       pthread_mutex_lock(&sessions_mutex);
        if (chan->used_event_id == -1UL)
                goto full;
        /*
@@ -427,7 +418,6 @@ struct ltt_event *ltt_event_create(struct ltt_channel *chan,
                        goto statedump_error;
        }
        cds_list_add(&event->list, &chan->session->events);
-       pthread_mutex_unlock(&sessions_mutex);
        return event;
 
 statedump_error:
@@ -443,7 +433,6 @@ register_error:
 cache_error:
 exist:
 full:
-       pthread_mutex_unlock(&sessions_mutex);
        return NULL;
 }
 
@@ -495,7 +484,7 @@ void _ltt_event_destroy(struct ltt_event *event)
 
 /*
  * We have exclusive access to our metadata buffer (protected by the
- * sessions_mutex), so we can do racy operations such as looking for
+ * ust_lock), so we can do racy operations such as looking for
  * remaining space left in packet and write, since mutual exclusion
  * protects us from concurrent writes.
  */
@@ -563,7 +552,7 @@ int _ltt_field_statedump(struct ltt_session *session,
        switch (field->type.atype) {
        case atype_integer:
                ret = lttng_metadata_printf(session,
-                       "               integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } %s;\n",
+                       "               integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s;\n",
                        field->type.u.basic.integer.size,
                        field->type.u.basic.integer.alignment,
                        field->type.u.basic.integer.signedness,
@@ -582,7 +571,7 @@ int _ltt_field_statedump(struct ltt_session *session,
                break;
        case atype_float:
                ret = lttng_metadata_printf(session,
-                       "               floating_point { exp_dig = %u; mant_dig = %u; align = %u; } %s;\n",
+                       "               floating_point { exp_dig = %u; mant_dig = %u; align = %u; } _%s;\n",
                        field->type.u.basic._float.exp_dig,
                        field->type.u.basic._float.mant_dig,
                        field->type.u.basic._float.alignment,
@@ -605,7 +594,7 @@ int _ltt_field_statedump(struct ltt_session *session,
 
                elem_type = &field->type.u.array.elem_type;
                ret = lttng_metadata_printf(session,
-                       "               integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } %s[%u];\n",
+                       "               integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[%u];\n",
                        elem_type->u.basic.integer.size,
                        elem_type->u.basic.integer.alignment,
                        elem_type->u.basic.integer.signedness,
@@ -651,7 +640,7 @@ int _ltt_field_statedump(struct ltt_session *session,
                        return ret;
 
                ret = lttng_metadata_printf(session,
-                       "               integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } %s[ __%s_length ];\n",
+                       "               integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[ __%s_length ];\n",
                        elem_type->u.basic.integer.size,
                        (unsigned int) elem_type->u.basic.integer.alignment,
                        elem_type->u.basic.integer.signedness,
@@ -674,7 +663,7 @@ int _ltt_field_statedump(struct ltt_session *session,
        case atype_string:
                /* Default encoding is UTF8 */
                ret = lttng_metadata_printf(session,
-                       "               string%s %s;\n",
+                       "               string%s _%s;\n",
                        field->type.u.basic.string.encoding == lttng_encode_ASCII ?
                                " { encoding = ASCII; }" : "",
                        field->name);
@@ -991,24 +980,21 @@ end:
  * @transport: transport structure
  *
  * Registers a transport which can be used as output to extract the data out of
- * LTTng.
+ * LTTng. Called with ust_lock held.
  */
 void ltt_transport_register(struct ltt_transport *transport)
 {
-       pthread_mutex_lock(&sessions_mutex);
        cds_list_add_tail(&transport->node, &ltt_transport_list);
-       pthread_mutex_unlock(&sessions_mutex);
 }
 
 /**
  * ltt_transport_unregister - LTT transport unregistration
  * @transport: transport structure
+ * Called with ust_lock held.
  */
 void ltt_transport_unregister(struct ltt_transport *transport)
 {
-       pthread_mutex_lock(&sessions_mutex);
        cds_list_del(&transport->node);
-       pthread_mutex_unlock(&sessions_mutex);
 }
 
 void ltt_events_exit(void)
This page took 0.026857 seconds and 4 git commands to generate.