Fix: update writeback instrumentation for kernel 4.14
[lttng-modules.git] / lttng-events.c
index 5307b722b237991935d75a93f61d04caac36e06b..21c41133b859623e6a5ea63c65927021cb646171 100644 (file)
 #include <wrapper/random.h>
 #include <wrapper/tracepoint.h>
 #include <wrapper/list.h>
+#include <wrapper/types.h>
 #include <lttng-kernel-version.h>
 #include <lttng-events.h>
 #include <lttng-tracer.h>
 #include <lttng-abi-old.h>
 #include <lttng-endian.h>
+#include <lttng-string-utils.h>
 #include <wrapper/vzalloc.h>
+#include <wrapper/ringbuffer/backend.h>
+#include <wrapper/ringbuffer/frontend.h>
 
 #define METADATA_CACHE_DEFAULT_SIZE 4096
 
@@ -128,7 +132,7 @@ struct lttng_session *lttng_session_create(void)
        int i;
 
        mutex_lock(&sessions_mutex);
-       session = kzalloc(sizeof(struct lttng_session), GFP_KERNEL);
+       session = lttng_kvzalloc(sizeof(struct lttng_session), GFP_KERNEL);
        if (!session)
                goto err;
        INIT_LIST_HEAD(&session->chan);
@@ -159,7 +163,7 @@ struct lttng_session *lttng_session_create(void)
 err_free_cache:
        kfree(metadata_cache);
 err_free_session:
-       kfree(session);
+       lttng_kvfree(session);
 err:
        mutex_unlock(&sessions_mutex);
        return NULL;
@@ -208,7 +212,17 @@ void lttng_session_destroy(struct lttng_session *session)
        kref_put(&session->metadata_cache->refcount, metadata_cache_destroy);
        list_del(&session->list);
        mutex_unlock(&sessions_mutex);
-       kfree(session);
+       lttng_kvfree(session);
+}
+
+int lttng_session_statedump(struct lttng_session *session)
+{
+       int ret;
+
+       mutex_lock(&sessions_mutex);
+       ret = lttng_statedump_start(session);
+       mutex_unlock(&sessions_mutex);
+       return ret;
 }
 
 int lttng_session_enable(struct lttng_session *session)
@@ -241,6 +255,12 @@ int lttng_session_enable(struct lttng_session *session)
        /* We need to sync enablers with session before activation. */
        lttng_session_sync_enablers(session);
 
+       /* Clear each stream's quiescent state. */
+       list_for_each_entry(chan, &session->chan, list) {
+               if (chan->channel_type != METADATA_CHANNEL)
+                       lib_ring_buffer_clear_quiescent_channel(chan->chan);
+       }
+
        ACCESS_ONCE(session->active) = 1;
        ACCESS_ONCE(session->been_active) = 1;
        ret = _lttng_session_metadata_statedump(session);
@@ -259,6 +279,7 @@ end:
 int lttng_session_disable(struct lttng_session *session)
 {
        int ret = 0;
+       struct lttng_channel *chan;
 
        mutex_lock(&sessions_mutex);
        if (!session->active) {
@@ -270,6 +291,12 @@ int lttng_session_disable(struct lttng_session *session)
        /* Set transient enabler state to "disabled" */
        session->tstate = 0;
        lttng_session_sync_enablers(session);
+
+       /* Set each stream's quiescent state. */
+       list_for_each_entry(chan, &session->chan, list) {
+               if (chan->channel_type != METADATA_CHANNEL)
+                       lib_ring_buffer_set_quiescent_channel(chan->chan);
+       }
 end:
        mutex_unlock(&sessions_mutex);
        return ret;
@@ -1117,11 +1144,11 @@ fd_error:
  * Enabler management.
  */
 static
-int lttng_match_enabler_wildcard(const char *desc_name,
-               const char *name)
+int lttng_match_enabler_star_glob(const char *desc_name,
+               const char *pattern)
 {
-       /* Compare excluding final '*' */
-       if (strncmp(desc_name, name, strlen(name) - 1))
+       if (!strutils_star_glob_match(pattern, LTTNG_SIZE_MAX,
+                       desc_name, LTTNG_SIZE_MAX))
                return 0;
        return 1;
 }
@@ -1166,8 +1193,8 @@ int lttng_desc_match_enabler(const struct lttng_event_desc *desc,
                return -EINVAL;
        }
        switch (enabler->type) {
-       case LTTNG_ENABLER_WILDCARD:
-               return lttng_match_enabler_wildcard(desc_name, enabler_name);
+       case LTTNG_ENABLER_STAR_GLOB:
+               return lttng_match_enabler_star_glob(desc_name, enabler_name);
        case LTTNG_ENABLER_NAME:
                return lttng_match_enabler_name(desc_name, enabler_name);
        default:
@@ -1884,7 +1911,7 @@ int _lttng_enum_statedump(struct lttng_session *session,
        if (ret)
                goto end;
        ret = lttng_metadata_printf(session,
-               "enum : integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u; } {\n",
+               "enum : integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } {\n",
                container_type->size,
                container_type->alignment,
                container_type->signedness,
@@ -1893,7 +1920,13 @@ int _lttng_enum_statedump(struct lttng_session *session,
                        : (container_type->encoding == lttng_encode_UTF8)
                                ? "UTF8"
                                : "ASCII",
-               container_type->base);
+               container_type->base,
+#if __BYTE_ORDER == __BIG_ENDIAN
+               container_type->reverse_byte_order ? " byte_order = le;" : ""
+#else
+               container_type->reverse_byte_order ? " byte_order = be;" : ""
+#endif
+               );
        if (ret)
                goto end;
        /* Dump all entries */
@@ -1930,33 +1963,46 @@ int _lttng_enum_statedump(struct lttng_session *session,
                        if (ret)
                                goto end;
                }
-               ret = lttng_metadata_printf(session,
-                               "\" = ");
-               if (ret)
-                       goto end;
-               if (entry->start.signedness)
-                       ret = lttng_metadata_printf(session,
-                               "%lld", (long long) entry->start.value);
-               else
-                       ret = lttng_metadata_printf(session,
-                               "%llu", entry->start.value);
+               ret = lttng_metadata_printf(session, "\"");
                if (ret)
                        goto end;
-               if (entry->start.signedness == entry->end.signedness &&
-                               entry->start.value == entry->end.value) {
-                       ret = lttng_metadata_printf(session,
-                               ",\n");
+
+               if (entry->options.is_auto) {
+                       ret = lttng_metadata_printf(session, ",\n");
+                       if (ret)
+                               goto end;
                } else {
-                       if (entry->end.signedness) {
+                       ret = lttng_metadata_printf(session,
+                                       " = ");
+                       if (ret)
+                               goto end;
+                       if (entry->start.signedness)
                                ret = lttng_metadata_printf(session,
-                                       " ... %lld,\n", (long long) entry->end.value);
-                       } else {
+                                       "%lld", (long long) entry->start.value);
+                       else
+                               ret = lttng_metadata_printf(session,
+                                       "%llu", entry->start.value);
+                       if (ret)
+                               goto end;
+                       if (entry->start.signedness == entry->end.signedness &&
+                                       entry->start.value
+                                               == entry->end.value) {
                                ret = lttng_metadata_printf(session,
-                                       " ... %llu,\n", entry->end.value);
+                                       ",\n");
+                       } else {
+                               if (entry->end.signedness) {
+                                       ret = lttng_metadata_printf(session,
+                                               " ... %lld,\n",
+                                               (long long) entry->end.value);
+                               } else {
+                                       ret = lttng_metadata_printf(session,
+                                               " ... %llu,\n",
+                                               entry->end.value);
+                               }
                        }
+                       if (ret)
+                               goto end;
                }
-               if (ret)
-                       goto end;
        }
        ret = print_tabs(session, nesting);
        if (ret)
@@ -2377,7 +2423,7 @@ int64_t measure_clock_offset(void)
        /* Disable interrupts to increase correlation precision. */
        local_irq_save(flags);
        monotonic[0] = trace_clock_read64();
-       getnstimeofday(&rts);      
+       getnstimeofday(&rts);
        monotonic[1] = trace_clock_read64();
        local_irq_restore(flags);
 
@@ -2600,6 +2646,133 @@ void lttng_transport_unregister(struct lttng_transport *transport)
 }
 EXPORT_SYMBOL_GPL(lttng_transport_unregister);
 
+#if (defined(CONFIG_HOTPLUG_CPU) && (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)))
+
+enum cpuhp_state lttng_hp_prepare;
+enum cpuhp_state lttng_hp_online;
+
+static int lttng_hotplug_prepare(unsigned int cpu, struct hlist_node *node)
+{
+       struct lttng_cpuhp_node *lttng_node;
+
+       lttng_node = container_of(node, struct lttng_cpuhp_node, node);
+       switch (lttng_node->component) {
+       case LTTNG_RING_BUFFER_FRONTEND:
+               return 0;
+       case LTTNG_RING_BUFFER_BACKEND:
+               return lttng_cpuhp_rb_backend_prepare(cpu, lttng_node);
+       case LTTNG_RING_BUFFER_ITER:
+               return 0;
+       case LTTNG_CONTEXT_PERF_COUNTERS:
+               return 0;
+       default:
+               return -EINVAL;
+       }
+}
+
+static int lttng_hotplug_dead(unsigned int cpu, struct hlist_node *node)
+{
+       struct lttng_cpuhp_node *lttng_node;
+
+       lttng_node = container_of(node, struct lttng_cpuhp_node, node);
+       switch (lttng_node->component) {
+       case LTTNG_RING_BUFFER_FRONTEND:
+               return lttng_cpuhp_rb_frontend_dead(cpu, lttng_node);
+       case LTTNG_RING_BUFFER_BACKEND:
+               return 0;
+       case LTTNG_RING_BUFFER_ITER:
+               return 0;
+       case LTTNG_CONTEXT_PERF_COUNTERS:
+               return lttng_cpuhp_perf_counter_dead(cpu, lttng_node);
+       default:
+               return -EINVAL;
+       }
+}
+
+static int lttng_hotplug_online(unsigned int cpu, struct hlist_node *node)
+{
+       struct lttng_cpuhp_node *lttng_node;
+
+       lttng_node = container_of(node, struct lttng_cpuhp_node, node);
+       switch (lttng_node->component) {
+       case LTTNG_RING_BUFFER_FRONTEND:
+               return lttng_cpuhp_rb_frontend_online(cpu, lttng_node);
+       case LTTNG_RING_BUFFER_BACKEND:
+               return 0;
+       case LTTNG_RING_BUFFER_ITER:
+               return lttng_cpuhp_rb_iter_online(cpu, lttng_node);
+       case LTTNG_CONTEXT_PERF_COUNTERS:
+               return lttng_cpuhp_perf_counter_online(cpu, lttng_node);
+       default:
+               return -EINVAL;
+       }
+}
+
+static int lttng_hotplug_offline(unsigned int cpu, struct hlist_node *node)
+{
+       struct lttng_cpuhp_node *lttng_node;
+
+       lttng_node = container_of(node, struct lttng_cpuhp_node, node);
+       switch (lttng_node->component) {
+       case LTTNG_RING_BUFFER_FRONTEND:
+               return lttng_cpuhp_rb_frontend_offline(cpu, lttng_node);
+       case LTTNG_RING_BUFFER_BACKEND:
+               return 0;
+       case LTTNG_RING_BUFFER_ITER:
+               return 0;
+       case LTTNG_CONTEXT_PERF_COUNTERS:
+               return 0;
+       default:
+               return -EINVAL;
+       }
+}
+
+static int __init lttng_init_cpu_hotplug(void)
+{
+       int ret;
+
+       ret = cpuhp_setup_state_multi(CPUHP_BP_PREPARE_DYN, "lttng:prepare",
+                       lttng_hotplug_prepare,
+                       lttng_hotplug_dead);
+       if (ret < 0) {
+               return ret;
+       }
+       lttng_hp_prepare = ret;
+       lttng_rb_set_hp_prepare(ret);
+
+       ret = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN, "lttng:online",
+                       lttng_hotplug_online,
+                       lttng_hotplug_offline);
+       if (ret < 0) {
+               cpuhp_remove_multi_state(lttng_hp_prepare);
+               lttng_hp_prepare = 0;
+               return ret;
+       }
+       lttng_hp_online = ret;
+       lttng_rb_set_hp_online(ret);
+
+       return 0;
+}
+
+static void __exit lttng_exit_cpu_hotplug(void)
+{
+       lttng_rb_set_hp_online(0);
+       cpuhp_remove_multi_state(lttng_hp_online);
+       lttng_rb_set_hp_prepare(0);
+       cpuhp_remove_multi_state(lttng_hp_prepare);
+}
+
+#else /* #if (CONFIG_HOTPLUG_CPU && (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0))) */
+static int lttng_init_cpu_hotplug(void)
+{
+       return 0;
+}
+static void lttng_exit_cpu_hotplug(void)
+{
+}
+#endif /* #else #if (CONFIG_HOTPLUG_CPU && (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0))) */
+
+
 static int __init lttng_events_init(void)
 {
        int ret;
@@ -2633,8 +2806,19 @@ static int __init lttng_events_init(void)
        ret = lttng_logger_init();
        if (ret)
                goto error_logger;
+       ret = lttng_init_cpu_hotplug();
+       if (ret)
+               goto error_hotplug;
+       printk(KERN_NOTICE "LTTng: Loaded modules v%s.%s.%s%s (%s)\n",
+               __stringify(LTTNG_MODULES_MAJOR_VERSION),
+               __stringify(LTTNG_MODULES_MINOR_VERSION),
+               __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION),
+               LTTNG_MODULES_EXTRAVERSION,
+               LTTNG_VERSION_NAME);
        return 0;
 
+error_hotplug:
+       lttng_logger_exit();
 error_logger:
        lttng_abi_exit();
 error_abi:
@@ -2643,6 +2827,12 @@ error_kmem:
        lttng_tracepoint_exit();
 error_tp:
        lttng_context_exit();
+       printk(KERN_NOTICE "LTTng: Failed to load modules v%s.%s.%s%s (%s)\n",
+               __stringify(LTTNG_MODULES_MAJOR_VERSION),
+               __stringify(LTTNG_MODULES_MINOR_VERSION),
+               __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION),
+               LTTNG_MODULES_EXTRAVERSION,
+               LTTNG_VERSION_NAME);
        return ret;
 }
 
@@ -2652,6 +2842,7 @@ static void __exit lttng_events_exit(void)
 {
        struct lttng_session *session, *tmpsession;
 
+       lttng_exit_cpu_hotplug();
        lttng_logger_exit();
        lttng_abi_exit();
        list_for_each_entry_safe(session, tmpsession, &sessions, list)
@@ -2659,6 +2850,12 @@ static void __exit lttng_events_exit(void)
        kmem_cache_destroy(event_cache);
        lttng_tracepoint_exit();
        lttng_context_exit();
+       printk(KERN_NOTICE "LTTng: Unloaded modules v%s.%s.%s%s (%s)\n",
+               __stringify(LTTNG_MODULES_MAJOR_VERSION),
+               __stringify(LTTNG_MODULES_MINOR_VERSION),
+               __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION),
+               LTTNG_MODULES_EXTRAVERSION,
+               LTTNG_VERSION_NAME);
 }
 
 module_exit(lttng_events_exit);
This page took 0.028308 seconds and 4 git commands to generate.