add average script
[ust.git] / libust / marker.c
index 8e8fb71ee52999f8c6b542eb30c2001f3d8662ab..56ffe39960dd6d6e79281410cf5cf5002019906d 100644 (file)
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
  */
-//ust// #include <linux/module.h>
-//ust// #include <linux/mutex.h>
-//ust// #include <linux/types.h>
-//#include "jhash.h"
-//#include "list.h"
-//#include "rcupdate.h"
-//ust// #include <linux/marker.h>
-#include <errno.h>
-//ust// #include <linux/slab.h>
-//ust// #include <linux/immediate.h>
-//ust// #include <linux/sched.h>
-//ust// #include <linux/uaccess.h>
-//ust// #include <linux/user_marker.h>
-//ust// #include <linux/ltt-tracer.h>
 
+#include <stdlib.h>
+#include <errno.h>
 #define _LGPL_SOURCE
 #include <urcu-bp.h>
+#include <urcu/rculist.h>
 
-#include <ust/kernelcompat.h>
-
+#include <ust/core.h>
 #include <ust/marker.h>
+
 #include "usterr.h"
 #include "channels.h"
 #include "tracercore.h"
@@ -248,7 +237,7 @@ static void free_old_closure(struct rcu_head *head)
 {
        struct marker_entry *entry = container_of(head,
                struct marker_entry, rcu);
-       kfree(entry->oldptr);
+       free(entry->oldptr);
        /* Make sure we free the data before setting the pending flag to 0 */
        smp_wmb();
        entry->rcu_pending = 0;
@@ -310,8 +299,7 @@ marker_entry_add_probe(struct marker_entry *entry,
                                return ERR_PTR(-EBUSY);
        }
        /* + 2 : one for new probe, one for NULL func */
-       new = kzalloc((nr_probes + 2) * sizeof(struct marker_probe_closure),
-                       GFP_KERNEL);
+       new = zmalloc((nr_probes + 2) * sizeof(struct marker_probe_closure));
        if (new == NULL)
                return ERR_PTR(-ENOMEM);
        if (!old)
@@ -376,8 +364,7 @@ marker_entry_remove_probe(struct marker_entry *entry,
                int j = 0;
                /* N -> M, (N > 1, M > 1) */
                /* + 1 for NULL */
-               new = kzalloc((nr_probes - nr_del + 1)
-                       * sizeof(struct marker_probe_closure), GFP_KERNEL);
+               new = zmalloc((nr_probes - nr_del + 1) * sizeof(struct marker_probe_closure));
                if (new == NULL)
                        return ERR_PTR(-ENOMEM);
                for (i = 0; old[i].func; i++)
@@ -441,12 +428,11 @@ static struct marker_entry *add_marker(const char *channel, const char *name,
                }
        }
        /*
-        * Using kmalloc here to allocate a variable length element. Could
+        * Using malloc here to allocate a variable length element. Could
         * cause some memory fragmentation if overused.
         */
-       e = kmalloc(sizeof(struct marker_entry)
-                   + channel_len + name_len + format_len,
-                   GFP_KERNEL);
+       e = malloc(sizeof(struct marker_entry)
+                   + channel_len + name_len + format_len);
        if (!e)
                return ERR_PTR(-ENOMEM);
        memcpy(e->channel, channel, channel_len);
@@ -506,13 +492,13 @@ static int remove_marker(const char *channel, const char *name)
                return -EBUSY;
        hlist_del(&e->hlist);
        if (e->format_allocated)
-               kfree(e->format);
+               free(e->format);
        ret = ltt_channels_unregister(e->channel);
        WARN_ON(ret);
        /* Make sure the call_rcu has been executed */
 //ust//        if (e->rcu_pending)
 //ust//                rcu_barrier_sched();
-       kfree(e);
+       free(e);
        return 0;
 }
 
@@ -521,7 +507,7 @@ static int remove_marker(const char *channel, const char *name)
  */
 static int marker_set_format(struct marker_entry *entry, const char *format)
 {
-       entry->format = kstrdup(format, GFP_KERNEL);
+       entry->format = strdup(format);
        if (!entry->format)
                return -ENOMEM;
        entry->format_allocated = 1;
@@ -591,36 +577,36 @@ static int set_marker(struct marker_entry *entry, struct marker *elem,
        smp_wmb();
        elem->ptype = entry->ptype;
 
-//ust//        if (elem->tp_name && (active ^ _imv_read(elem->state))) {
-//ust//                WARN_ON(!elem->tp_cb);
-//ust//                /*
-//ust//                 * It is ok to directly call the probe registration because type
-//ust//                 * checking has been done in the __trace_mark_tp() macro.
-//ust//                 */
-//ust//
-//ust//                if (active) {
-//ust//                        /*
-//ust//                         * try_module_get should always succeed because we hold
-//ust//                         * markers_mutex to get the tp_cb address.
-//ust//                         */
+       if (elem->tp_name && (active ^ _imv_read(elem->state))) {
+               WARN_ON(!elem->tp_cb);
+               /*
+                * It is ok to directly call the probe registration because type
+                * checking has been done in the __trace_mark_tp() macro.
+                */
+
+               if (active) {
+                       /*
+                        * try_module_get should always succeed because we hold
+                        * markers_mutex to get the tp_cb address.
+                        */
 //ust//                        ret = try_module_get(__module_text_address(
 //ust//                                (unsigned long)elem->tp_cb));
 //ust//                        BUG_ON(!ret);
-//ust//                        ret = tracepoint_probe_register_noupdate(
-//ust//                                elem->tp_name,
-//ust//                                elem->tp_cb);
-//ust//                } else {
-//ust//                        ret = tracepoint_probe_unregister_noupdate(
-//ust//                                elem->tp_name,
-//ust//                                elem->tp_cb);
-//ust//                        /*
-//ust//                         * tracepoint_probe_update_all() must be called
-//ust//                         * before the module containing tp_cb is unloaded.
-//ust//                         */
+                       ret = tracepoint_probe_register_noupdate(
+                               elem->tp_name,
+                               elem->tp_cb);
+               } else {
+                       ret = tracepoint_probe_unregister_noupdate(
+                               elem->tp_name,
+                               elem->tp_cb);
+                       /*
+                        * tracepoint_probe_update_all() must be called
+                        * before the module containing tp_cb is unloaded.
+                        */
 //ust//                        module_put(__module_text_address(
 //ust//                                (unsigned long)elem->tp_cb));
-//ust//                }
-//ust//        }
+               }
+       }
        elem->state__imv = active;
 
        return ret;
@@ -634,24 +620,24 @@ static int set_marker(struct marker_entry *entry, struct marker *elem,
  */
 static void disable_marker(struct marker *elem)
 {
-//ust//        int ret;
-//ust//
-//ust//        /* leave "call" as is. It is known statically. */
-//ust//        if (elem->tp_name && _imv_read(elem->state)) {
-//ust//                WARN_ON(!elem->tp_cb);
-//ust//                /*
-//ust//                 * It is ok to directly call the probe registration because type
-//ust//                 * checking has been done in the __trace_mark_tp() macro.
-//ust//                 */
-//ust//                ret = tracepoint_probe_unregister_noupdate(elem->tp_name,
-//ust//                        elem->tp_cb);
-//ust//                WARN_ON(ret);
-//ust//                /*
-//ust//                 * tracepoint_probe_update_all() must be called
-//ust//                 * before the module containing tp_cb is unloaded.
-//ust//                 */
+       int ret;
+
+       /* leave "call" as is. It is known statically. */
+       if (elem->tp_name && _imv_read(elem->state)) {
+               WARN_ON(!elem->tp_cb);
+               /*
+                * It is ok to directly call the probe registration because type
+                * checking has been done in the __trace_mark_tp() macro.
+                */
+               ret = tracepoint_probe_unregister_noupdate(elem->tp_name,
+                       elem->tp_cb);
+               WARN_ON(ret);
+               /*
+                * tracepoint_probe_update_all() must be called
+                * before the module containing tp_cb is unloaded.
+                */
 //ust//                module_put(__module_text_address((unsigned long)elem->tp_cb));
-//ust//        }
+       }
        elem->state__imv = 0;
        elem->single.func = __mark_empty_function;
        /* Update the function before setting the ptype */
@@ -760,7 +746,7 @@ static void marker_update_probes(void)
        /* Markers in modules. */
 //ust//        module_update_markers();
        lib_update_markers();
-//ust//        tracepoint_probe_update_all();
+       tracepoint_probe_update_all();
        /* Update immediate values */
        core_imv_update();
 //ust//        module_imv_update(); /* FIXME: need to port for libs? */
@@ -971,7 +957,7 @@ int marker_probe_unregister_private_data(marker_probe_func *probe,
        struct marker_entry *entry;
        int ret = 0;
        struct marker_probe_closure *old;
-       const char *channel = NULL, *name = NULL;
+       char *channel = NULL, *name = NULL;
 
        mutex_lock(&markers_mutex);
        entry = get_marker_from_private_data(probe, probe_private);
@@ -982,8 +968,8 @@ int marker_probe_unregister_private_data(marker_probe_func *probe,
 //ust//        if (entry->rcu_pending)
 //ust//                rcu_barrier_sched();
        old = marker_entry_remove_probe(entry, NULL, probe_private);
-       channel = kstrdup(entry->channel, GFP_KERNEL);
-       name = kstrdup(entry->name, GFP_KERNEL);
+       channel = strdup(entry->channel);
+       name = strdup(entry->name);
        mutex_unlock(&markers_mutex);
 
        marker_update_probes();
@@ -1004,8 +990,8 @@ int marker_probe_unregister_private_data(marker_probe_func *probe,
        remove_marker(channel, name);
 end:
        mutex_unlock(&markers_mutex);
-       kfree(channel);
-       kfree(name);
+       free(channel);
+       free(name);
        return ret;
 }
 //ust// EXPORT_SYMBOL_GPL(marker_probe_unregister_private_data);
@@ -1200,7 +1186,7 @@ static void free_user_marker(char __user *state, struct hlist_head *head)
        hlist_for_each_entry_safe(umark, pos, n, head, hlist) {
                if (umark->state == state) {
                        hlist_del(&umark->hlist);
-                       kfree(umark);
+                       free(umark);
                }
        }
 }
@@ -1264,7 +1250,7 @@ void exit_user_markers(struct task_struct *p)
                mutex_lock(&p->user_markers_mutex);
                hlist_for_each_entry_safe(umark, pos, n, &p->user_markers,
                        hlist)
-                   kfree(umark);
+                   free(umark);
                INIT_HLIST_HEAD(&p->user_markers);
                p->user_markers_sequence++;
                mutex_unlock(&p->user_markers_mutex);
@@ -1316,7 +1302,7 @@ struct notifier_block marker_module_nb = {
 
 #endif /* CONFIG_MODULES */
 
-void ltt_dump_marker_state(struct ltt_trace_struct *trace)
+void ltt_dump_marker_state(struct ust_trace *trace)
 {
        struct marker_entry *entry;
        struct ltt_probe_private_data call_data;
@@ -1376,7 +1362,6 @@ static void new_markers(struct marker *start, struct marker *end)
 int marker_register_lib(struct marker *markers_start, int markers_count)
 {
        struct lib *pl;
-       struct marker_addr *addr;
 
        pl = (struct lib *) malloc(sizeof(struct lib));
 
@@ -1398,11 +1383,28 @@ int marker_register_lib(struct marker *markers_start, int markers_count)
        return 0;
 }
 
-int marker_unregister_lib(struct marker *markers_start, int markers_count)
+int marker_unregister_lib(struct marker *markers_start)
 {
+       struct lib *lib;
+
        /*FIXME: implement; but before implementing, marker_register_lib must
           have appropriate locking. */
 
+       lock_markers();
+
+       /* FIXME: we should probably take a mutex here on libs */
+//ust//        mutex_lock(&module_mutex);
+       list_for_each_entry(lib, &libs, list) {
+               if(lib->markers_start == markers_start) {
+                       struct lib *lib2free = lib;
+                       list_del(&lib->list);
+                       free(lib2free);
+                       break;
+               }
+       }
+
+       unlock_markers();
+
        return 0;
 }
 
@@ -1412,7 +1414,11 @@ void __attribute__((constructor)) init_markers(void)
 {
        if(!initialized) {
                marker_register_lib(__start___markers, (((long)__stop___markers)-((long)__start___markers))/sizeof(struct marker));
-               //DBG("markers_start: %p, markers_stop: %p\n", __start___markers, __stop___markers);
                initialized = 1;
        }
 }
+
+void __attribute__((constructor)) destroy_markers(void)
+{
+       marker_unregister_lib(__start___markers);
+}
This page took 0.027873 seconds and 4 git commands to generate.