Update version to 0.16
[ust.git] / libust / tracer.c
index 8c3f77466f057f8fc89afcfc3c1dd2a5ac57b45f..347ca482db91c1b13edd3dd4eb2e954d49c2e286 100644 (file)
 
 #include "tracercore.h"
 #include "tracer.h"
-#include "usterr.h"
-
-//ust// static void async_wakeup(unsigned long data);
-//ust// 
-//ust// static DEFINE_TIMER(ltt_async_wakeup_timer, async_wakeup, 0, 0);
-
-/* Default callbacks for modules */
-notrace int ltt_filter_control_default(enum ltt_filter_control_msg msg,
-               struct ust_trace *trace)
-{
-       return 0;
-}
-
-int ltt_statedump_default(struct ust_trace *trace)
-{
-       return 0;
-}
-
-/* Callbacks for registered modules */
-
-int (*ltt_filter_control_functor)
-       (enum ltt_filter_control_msg msg, struct ust_trace *trace) =
-                                       ltt_filter_control_default;
-struct module *ltt_filter_control_owner;
-
-/* These function pointers are protected by a trace activation check */
-struct module *ltt_run_filter_owner;
-int (*ltt_statedump_functor)(struct ust_trace *trace) =
-                                       ltt_statedump_default;
-struct module *ltt_statedump_owner;
+#include "usterr_signal_safe.h"
 
 struct chan_info_struct chan_infos[] = {
        [LTT_CHANNEL_METADATA] = {
@@ -96,93 +67,9 @@ static enum ltt_channels get_channel_type_from_name(const char *name)
        return LTT_CHANNEL_UST;
 }
 
-/**
- * ltt_module_register - LTT module registration
- * @name: module type
- * @function: callback to register
- * @owner: module which owns the callback
- *
- * The module calling this registration function must ensure that no
- * trap-inducing code will be executed by "function". E.g. vmalloc_sync_all()
- * must be called between a vmalloc and the moment the memory is made visible to
- * "function". This registration acts as a vmalloc_sync_all. Therefore, only if
- * the module allocates virtual memory after its registration must it
- * synchronize the TLBs.
- */
-//ust// int ltt_module_register(enum ltt_module_function name, void *function,
-//ust//                struct module *owner)
-//ust// {
-//ust//        int ret = 0;
-//ust// 
-//ust//        /*
-//ust//         * Make sure no page fault can be triggered by the module about to be
-//ust//         * registered. We deal with this here so we don't have to call
-//ust//         * vmalloc_sync_all() in each module's init.
-//ust//         */
-//ust//        vmalloc_sync_all();
-//ust// 
-//ust//        switch (name) {
-//ust//        case LTT_FUNCTION_RUN_FILTER:
-//ust//                if (ltt_run_filter_owner != NULL) {
-//ust//                        ret = -EEXIST;
-//ust//                        goto end;
-//ust//                }
-//ust//                ltt_filter_register((ltt_run_filter_functor)function);
-//ust//                ltt_run_filter_owner = owner;
-//ust//                break;
-//ust//        case LTT_FUNCTION_FILTER_CONTROL:
-//ust//                if (ltt_filter_control_owner != NULL) {
-//ust//                        ret = -EEXIST;
-//ust//                        goto end;
-//ust//                }
-//ust//                ltt_filter_control_functor =
-//ust//                        (int (*)(enum ltt_filter_control_msg,
-//ust//                        struct ust_trace *))function;
-//ust//                ltt_filter_control_owner = owner;
-//ust//                break;
-//ust//        case LTT_FUNCTION_STATEDUMP:
-//ust//                if (ltt_statedump_owner != NULL) {
-//ust//                        ret = -EEXIST;
-//ust//                        goto end;
-//ust//                }
-//ust//                ltt_statedump_functor =
-//ust//                        (int (*)(struct ust_trace *))function;
-//ust//                ltt_statedump_owner = owner;
-//ust//                break;
-//ust//        }
-//ust// 
-//ust// end:
-//ust// 
-//ust//        return ret;
-//ust// }
-
-/**
- * ltt_module_unregister - LTT module unregistration
- * @name: module type
- */
-//ust// void ltt_module_unregister(enum ltt_module_function name)
-//ust// {
-//ust//        switch (name) {
-//ust//        case LTT_FUNCTION_RUN_FILTER:
-//ust//                ltt_filter_unregister();
-//ust//                ltt_run_filter_owner = NULL;
-//ust//                /* Wait for preempt sections to finish */
-//ust//                synchronize_sched();
-//ust//                break;
-//ust//        case LTT_FUNCTION_FILTER_CONTROL:
-//ust//                ltt_filter_control_functor = ltt_filter_control_default;
-//ust//                ltt_filter_control_owner = NULL;
-//ust//                break;
-//ust//        case LTT_FUNCTION_STATEDUMP:
-//ust//                ltt_statedump_functor = ltt_statedump_default;
-//ust//                ltt_statedump_owner = NULL;
-//ust//                break;
-//ust//        }
-//ust// 
-//ust// }
-
-static LIST_HEAD(ltt_transport_list);
-
+static CDS_LIST_HEAD(ltt_transport_list);
+/* transport mutex, nests inside traces mutex (ltt_lock_traces) */
+static DEFINE_MUTEX(ltt_transport_mutex);
 /**
  * ltt_transport_register - LTT transport registration
  * @transport: transport structure
@@ -197,16 +84,9 @@ static LIST_HEAD(ltt_transport_list);
  */
 void ltt_transport_register(struct ltt_transport *transport)
 {
-       /*
-        * Make sure no page fault can be triggered by the module about to be
-        * registered. We deal with this here so we don't have to call
-        * vmalloc_sync_all() in each module's init.
-        */
-//ust//        vmalloc_sync_all();
-
-       ltt_lock_traces();
-       list_add_tail(&transport->node, &ltt_transport_list);
-       ltt_unlock_traces();
+       pthread_mutex_lock(&ltt_transport_mutex);
+       cds_list_add_tail(&transport->node, &ltt_transport_list);
+       pthread_mutex_unlock(&ltt_transport_mutex);
 }
 
 /**
@@ -215,9 +95,9 @@ void ltt_transport_register(struct ltt_transport *transport)
  */
 void ltt_transport_unregister(struct ltt_transport *transport)
 {
-       ltt_lock_traces();
-       list_del(&transport->node);
-       ltt_unlock_traces();
+       pthread_mutex_lock(&ltt_transport_mutex);
+       cds_list_del(&transport->node);
+       pthread_mutex_unlock(&ltt_transport_mutex);
 }
 
 static inline int is_channel_overwrite(enum ltt_channels chan,
@@ -258,35 +138,6 @@ static void trace_async_wakeup(struct ust_trace *trace)
        }
 }
 
-//ust// /* Timer to send async wakeups to the readers */
-//ust// static void async_wakeup(unsigned long data)
-//ust// {
-//ust//        struct ust_trace *trace;
-//ust// 
-//ust//        /*
-//ust//         * PREEMPT_RT does not allow spinlocks to be taken within preempt
-//ust//         * disable sections (spinlock taken in wake_up). However, mainline won't
-//ust//         * allow mutex to be taken in interrupt context. Ugly.
-//ust//         * A proper way to do this would be to turn the timer into a
-//ust//         * periodically woken up thread, but it adds to the footprint.
-//ust//         */
-//ust// #ifndef CONFIG_PREEMPT_RT
-//ust//        rcu_read_lock_sched();
-//ust// #else
-//ust//        ltt_lock_traces();
-//ust// #endif
-//ust//        list_for_each_entry_rcu(trace, &ltt_traces.head, list) {
-//ust//                trace_async_wakeup(trace);
-//ust//        }
-//ust// #ifndef CONFIG_PREEMPT_RT
-//ust//        rcu_read_unlock_sched();
-//ust// #else
-//ust//        ltt_unlock_traces();
-//ust// #endif
-//ust// 
-//ust//        mod_timer(&ltt_async_wakeup_timer, jiffies + LTT_PERCPU_TIMER_INTERVAL);
-//ust// }
-
 /**
  * _ltt_trace_find - find a trace by given name.
  * trace_name: trace name
@@ -297,7 +148,7 @@ struct ust_trace *_ltt_trace_find(const char *trace_name)
 {
        struct ust_trace *trace;
 
-       list_for_each_entry(trace, &ltt_traces.head, list)
+       cds_list_for_each_entry(trace, &ltt_traces.head, list)
                if (!strncmp(trace->trace_name, trace_name, NAME_MAX))
                        return trace;
 
@@ -313,7 +164,7 @@ struct ust_trace *_ltt_trace_find_setup(const char *trace_name)
 {
        struct ust_trace *trace;
 
-       list_for_each_entry(trace, &ltt_traces.setup_head, list)
+       cds_list_for_each_entry(trace, &ltt_traces.setup_head, list)
                if (!strncmp(trace->trace_name, trace_name, NAME_MAX))
                        return trace;
 
@@ -324,21 +175,19 @@ struct ust_trace *_ltt_trace_find_setup(const char *trace_name)
  * ltt_release_transport - Release an LTT transport
  * @kref : reference count on the transport
  */
-void ltt_release_transport(struct kref *kref)
+void ltt_release_transport(struct urcu_ref *urcu_ref)
 {
-//ust//        struct ust_trace *trace = container_of(kref,
-//ust//                        struct ust_trace, ltt_transport_kref);
-//ust//        trace->ops->remove_dirs(trace);
+       return;
 }
 
 /**
  * ltt_release_trace - Release a LTT trace
  * @kref : reference count on the trace
  */
-void ltt_release_trace(struct kref *kref)
+void ltt_release_trace(struct urcu_ref *urcu_ref)
 {
-       struct ust_trace *trace = container_of(kref,
-                       struct ust_trace, kref);
+       struct ust_trace *trace = _ust_container_of(urcu_ref,
+                       struct ust_trace, urcu_ref);
        ltt_channels_trace_free(trace->channels);
        free(trace);
 }
@@ -417,7 +266,7 @@ int _ltt_trace_setup(const char *trace_name)
                        chan_infos[chantype].def_subbufcount;
        }
 
-       list_add(&new_trace->list, &ltt_traces.setup_head);
+       cds_list_add(&new_trace->list, &ltt_traces.setup_head);
        return 0;
 
 trace_free:
@@ -439,7 +288,7 @@ int ltt_trace_setup(const char *trace_name)
 /* must be called from within a traces lock. */
 static void _ltt_trace_free(struct ust_trace *trace)
 {
-       list_del(&trace->list);
+       cds_list_del(&trace->list);
        free(trace);
 }
 
@@ -458,12 +307,15 @@ int ltt_trace_set_type(const char *trace_name, const char *trace_type)
                goto traces_error;
        }
 
-       list_for_each_entry(tran_iter, &ltt_transport_list, node) {
+       pthread_mutex_lock(&ltt_transport_mutex);
+       cds_list_for_each_entry(tran_iter, &ltt_transport_list, node) {
                if (!strcmp(tran_iter->name, trace_type)) {
                        transport = tran_iter;
                        break;
                }
        }
+       pthread_mutex_unlock(&ltt_transport_mutex);
+
        if (!transport) {
                ERR("Transport %s is not present", trace_type);
                err = -EINVAL;
@@ -622,7 +474,6 @@ int ltt_trace_alloc(const char *trace_name)
        int err = 0;
        struct ust_trace *trace;
        unsigned int subbuf_size, subbuf_cnt;
-//ust//        unsigned long flags;
        int chan;
        const char *channel_name;
 
@@ -640,11 +491,9 @@ int ltt_trace_alloc(const char *trace_name)
                goto traces_error;
        }
 
-       kref_init(&trace->kref);
-       kref_init(&trace->ltt_transport_kref);
-//ust//        init_waitqueue_head(&trace->kref_wq);
+       urcu_ref_init(&trace->urcu_ref);
+       urcu_ref_init(&trace->ltt_transport_urcu_ref);
        trace->active = 0;
-//ust//        get_trace_clock();
        trace->freq_scale = trace_clock_freq_scale();
 
        if (!trace->transport) {
@@ -652,24 +501,11 @@ int ltt_trace_alloc(const char *trace_name)
                err = -EINVAL;
                goto transport_error;
        }
-//ust//        if (!try_module_get(trace->transport->owner)) {
-//ust//                ERR("Can't lock transport module");
-//ust//                err = -ENODEV;
-//ust//                goto transport_error;
-//ust//        }
        trace->ops = &trace->transport->ops;
 
-//ust//        err = trace->ops->create_dirs(trace);
-//ust//        if (err) {
-//ust//                ERR("Can't create dir for trace %s", trace_name);
-//ust//                goto dirs_error;
-//ust//        }
-
-//ust//        local_irq_save(flags);
        trace->start_freq = trace_clock_frequency();
        trace->start_tsc = trace_clock_read64();
        gettimeofday(&trace->start_time, NULL); //ust// changed /* FIXME: is this ok? */
-//ust//        local_irq_restore(flags);
 
        for (chan = 0; chan < trace->nr_channels; chan++) {
                if (!(trace->channels[chan].active))
@@ -692,14 +528,8 @@ int ltt_trace_alloc(const char *trace_name)
                }
        }
 
-       list_del(&trace->list);
-//ust//        if (list_empty(&ltt_traces.head)) {
-//ust//                mod_timer(&ltt_async_wakeup_timer,
-//ust//                                jiffies + LTT_PERCPU_TIMER_INTERVAL);
-//ust//                set_kernel_trace_flag_all_tasks();
-//ust//        }
-       list_add_rcu(&trace->list, &ltt_traces.head);
-//ust//        synchronize_sched();
+       cds_list_del(&trace->list);
+       cds_list_add_rcu(&trace->list, &ltt_traces.head);
 
        ltt_unlock_traces();
 
@@ -710,43 +540,12 @@ create_channel_error:
                if (trace->channels[chan].active)
                        trace->ops->remove_channel(&trace->channels[chan]);
 
-//ust// dirs_error:
-//ust//        module_put(trace->transport->owner);
 transport_error:
-//ust//        put_trace_clock();
 traces_error:
        ltt_unlock_traces();
        return err;
 }
 
-/*
- * It is worked as a wrapper for current version of ltt_control.ko.
- * We will make a new ltt_control based on debugfs, and control each channel's
- * buffer.
- */
-//ust// static int ltt_trace_create(const char *trace_name, const char *trace_type,
-//ust//                enum trace_mode mode,
-//ust//                unsigned int subbuf_size_low, unsigned int n_subbufs_low,
-//ust//                unsigned int subbuf_size_med, unsigned int n_subbufs_med,
-//ust//                unsigned int subbuf_size_high, unsigned int n_subbufs_high)
-//ust// {
-//ust//        int err = 0;
-//ust// 
-//ust//        err = ltt_trace_setup(trace_name);
-//ust//        if (IS_ERR_VALUE(err))
-//ust//                return err;
-//ust// 
-//ust//        err = ltt_trace_set_type(trace_name, trace_type);
-//ust//        if (IS_ERR_VALUE(err))
-//ust//                return err;
-//ust// 
-//ust//        err = ltt_trace_alloc(trace_name);
-//ust//        if (IS_ERR_VALUE(err))
-//ust//                return err;
-//ust// 
-//ust//        return err;
-//ust// }
-
 /* Must be called while sure that trace is in the list. */
 static int _ltt_trace_destroy(struct ust_trace *trace)
 {
@@ -761,21 +560,12 @@ static int _ltt_trace_destroy(struct ust_trace *trace)
                err = -EBUSY;
                goto active_error;
        }
-       /* Everything went fine */
-       list_del_rcu(&trace->list);
+
+       cds_list_del_rcu(&trace->list);
        synchronize_rcu();
-       if (list_empty(&ltt_traces.head)) {
-//ust//                clear_kernel_trace_flag_all_tasks();
-               /*
-                * We stop the asynchronous delivery of reader wakeup, but
-                * we must make one last check for reader wakeups pending
-                * later in __ltt_trace_destroy.
-                */
-//ust//                del_timer_sync(&ltt_async_wakeup_timer);
-       }
+
        return 0;
 
-       /* error handling */
 active_error:
 traces_error:
        return err;
@@ -795,9 +585,6 @@ static void __ltt_trace_destroy(struct ust_trace *trace, int drop)
                }
        }
 
-       return; /* FIXME: temporary for ust */
-//ust//        flush_scheduled_work();
-
        /*
         * The currently destroyed trace is not in the trace list anymore,
         * so it's safe to call the async wakeup ourself. It will deliver
@@ -811,20 +598,9 @@ static void __ltt_trace_destroy(struct ust_trace *trace, int drop)
                        trace->ops->remove_channel(chan);
        }
 
-       kref_put(&trace->ltt_transport_kref, ltt_release_transport);
-
-//ust//        module_put(trace->transport->owner);
+       urcu_ref_put(&trace->ltt_transport_urcu_ref, ltt_release_transport);
 
-       /*
-        * Wait for lttd readers to release the files, therefore making sure
-        * the last subbuffers have been read.
-        */
-//ust//        if (atomic_read(&trace->kref.refcount) > 1) {
-//ust//                int ret = 0;
-//ust//                __wait_event_interruptible(trace->kref_wq,
-//ust//                        (atomic_read(&trace->kref.refcount) == 1), ret);
-//ust//        }
-       kref_put(&trace->kref, ltt_release_trace);
+       urcu_ref_put(&trace->urcu_ref, ltt_release_trace);
 }
 
 int ltt_trace_destroy(const char *trace_name, int drop)
@@ -843,7 +619,6 @@ int ltt_trace_destroy(const char *trace_name, int drop)
                ltt_unlock_traces();
 
                __ltt_trace_destroy(trace, drop);
-//ust//                put_trace_clock();
 
                return 0;
        }
@@ -857,7 +632,6 @@ int ltt_trace_destroy(const char *trace_name, int drop)
 
        err = -ENOENT;
 
-       /* Error handling */
 error:
        ltt_unlock_traces();
        return err;
@@ -874,18 +648,11 @@ static int _ltt_trace_start(struct ust_trace *trace)
        }
        if (trace->active)
                DBG("Tracing already active for trace %s", trace->trace_name);
-//ust//        if (!try_module_get(ltt_run_filter_owner)) {
-//ust//                err = -ENODEV;
-//ust//                ERR("Cannot lock filter module");
-//ust//                goto get_ltt_run_filter_error;
-//ust//        }
        trace->active = 1;
        /* Read by trace points without protection : be careful */
        ltt_traces.num_active_traces++;
        return err;
 
-       /* error handling */
-//ust// get_ltt_run_filter_error:
 traces_error:
        return err;
 }
@@ -905,22 +672,14 @@ int ltt_trace_start(const char *trace_name)
        ltt_unlock_traces();
 
        /*
-        * Call the kernel state dump.
-        * Events will be mixed with real kernel events, it's ok.
+        * Call the process-wide state dump.
         * Notice that there is no protection on the trace : that's exactly
         * why we iterate on the list and check for trace equality instead of
-        * directly using this trace handle inside the logging function.
+        * directly using this trace handle inside the logging function: we want
+        * to record events only in a single trace in the trace session list.
         */
 
-       ltt_dump_marker_state(trace);
-
-//ust//        if (!try_module_get(ltt_statedump_owner)) {
-//ust//                err = -ENODEV;
-//ust//                ERR("Cannot lock state dump module");
-//ust//        } else {
-               ltt_statedump_functor(trace);
-//ust//                module_put(ltt_statedump_owner);
-//ust//        }
+       ltt_dump_ust_marker_state(trace);
 
        return err;
 
@@ -944,13 +703,9 @@ static int _ltt_trace_stop(struct ust_trace *trace)
        if (trace->active) {
                trace->active = 0;
                ltt_traces.num_active_traces--;
-//ust//                synchronize_sched(); /* Wait for each tracing to be finished */
        }
-//ust//        module_put(ltt_run_filter_owner);
-       /* Everything went fine */
        return 0;
 
-       /* Error handling */
 traces_error:
        return err;
 }
@@ -966,45 +721,3 @@ int ltt_trace_stop(const char *trace_name)
        ltt_unlock_traces();
        return err;
 }
-
-/**
- * ltt_filter_control - Trace filter control in-kernel API
- * @msg: Action to perform on the filter
- * @trace_name: Trace on which the action must be done
- */
-int ltt_filter_control(enum ltt_filter_control_msg msg, const char *trace_name)
-{
-       int err;
-       struct ust_trace *trace;
-
-       DBG("ltt_filter_control : trace %s", trace_name);
-       ltt_lock_traces();
-       trace = _ltt_trace_find(trace_name);
-       if (trace == NULL) {
-               ERR("Trace does not exist. Cannot proxy control request");
-               err = -ENOENT;
-               goto trace_error;
-       }
-//ust//        if (!try_module_get(ltt_filter_control_owner)) {
-//ust//                err = -ENODEV;
-//ust//                goto get_module_error;
-//ust//        }
-       switch (msg) {
-       case LTT_FILTER_DEFAULT_ACCEPT:
-               DBG("Proxy filter default accept %s", trace_name);
-               err = (*ltt_filter_control_functor)(msg, trace);
-               break;
-       case LTT_FILTER_DEFAULT_REJECT:
-               DBG("Proxy filter default reject %s", trace_name);
-               err = (*ltt_filter_control_functor)(msg, trace);
-               break;
-       default:
-               err = -EPERM;
-       }
-//ust//        module_put(ltt_filter_control_owner);
-
-//ust// get_module_error:
-trace_error:
-       ltt_unlock_traces();
-       return err;
-}
This page took 0.03009 seconds and 4 git commands to generate.