tracectl cleanup v3
[ust.git] / libust / marker.c
index 39da7f40f08338a69ae85cc6915cac303376390e..dbabf3eeef563f415e2f5e16fae74b2a8f30e17a 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.h>
+#include <urcu-bp.h>
+#include <urcu/rculist.h>
 
-#include "kernelcompat.h"
+#include <ust/core.h>
+#include <ust/marker.h>
 
-#include "marker.h"
 #include "usterr.h"
 #include "channels.h"
 #include "tracercore.h"
 #include "tracer.h"
 
+__thread long ust_reg_stack[500];
+volatile __thread long *ust_reg_stack_ptr = (long *) 0;
+
 extern struct marker __start___markers[] __attribute__((visibility("hidden")));
 extern struct marker __stop___markers[] __attribute__((visibility("hidden")));
 
@@ -53,14 +45,17 @@ static const int marker_debug;
  */
 static DEFINE_MUTEX(markers_mutex);
 
+static LIST_HEAD(libs);
+
+
 void lock_markers(void)
 {
-       mutex_lock(&markers_mutex);
+       pthread_mutex_lock(&markers_mutex);
 }
 
 void unlock_markers(void)
 {
-       mutex_unlock(&markers_mutex);
+       pthread_mutex_unlock(&markers_mutex);
 }
 
 /*
@@ -84,7 +79,7 @@ struct marker_entry {
        char *format;
        char *name;
                        /* Probe wrapper */
-       void (*call)(const struct marker *mdata, void *call_private, ...);
+       void (*call)(const struct marker *mdata, void *call_private, struct registers *regs, ...);
        struct marker_probe_closure single;
        struct marker_probe_closure *multi;
        int refcount;   /* Number of times armed. 0 if disarmed. */
@@ -120,7 +115,7 @@ static void marker_update_processes(void)
  * operations that modifies the execution flow of preemptible code.
  */
 notrace void __mark_empty_function(const struct marker *mdata,
-       void *probe_private, void *call_private, const char *fmt, va_list *args)
+       void *probe_private, struct registers *regs, void *call_private, const char *fmt, va_list *args)
 {
 }
 //ust// EXPORT_SYMBOL_GPL(__mark_empty_function);
@@ -136,7 +131,7 @@ notrace void __mark_empty_function(const struct marker *mdata,
  * rcu_dereference() for the pointer read.
  */
 notrace void marker_probe_cb(const struct marker *mdata,
-               void *call_private, ...)
+               void *call_private, struct registers *regs, ...)
 {
        va_list args;
        char ptype;
@@ -157,8 +152,8 @@ notrace void marker_probe_cb(const struct marker *mdata,
                /* Must read the ptr before private data. They are not data
                 * dependant, so we put an explicit smp_rmb() here. */
                smp_rmb();
-               va_start(args, call_private);
-               func(mdata, mdata->single.probe_private, call_private,
+               va_start(args, regs);
+               func(mdata, mdata->single.probe_private, regs, call_private,
                        mdata->format, &args);
                va_end(args);
        } else {
@@ -178,9 +173,9 @@ notrace void marker_probe_cb(const struct marker *mdata,
                 */
                smp_read_barrier_depends();
                for (i = 0; multi[i].func; i++) {
-                       va_start(args, call_private);
+                       va_start(args, regs);
                        multi[i].func(mdata, multi[i].probe_private,
-                               call_private, mdata->format, &args);
+                               regs, call_private, mdata->format, &args);
                        va_end(args);
                }
        }
@@ -197,7 +192,7 @@ notrace void marker_probe_cb(const struct marker *mdata,
  * Should be connected to markers "MARK_NOARGS".
  */
 static notrace void marker_probe_cb_noarg(const struct marker *mdata,
-               void *call_private, ...)
+               void *call_private, struct registers *regs, ...)
 {
        va_list args;   /* not initialized */
        char ptype;
@@ -213,7 +208,7 @@ static notrace void marker_probe_cb_noarg(const struct marker *mdata,
                /* Must read the ptr before private data. They are not data
                 * dependant, so we put an explicit smp_rmb() here. */
                smp_rmb();
-               func(mdata, mdata->single.probe_private, call_private,
+               func(mdata, mdata->single.probe_private, regs, call_private,
                        mdata->format, &args);
        } else {
                struct marker_probe_closure *multi;
@@ -232,7 +227,7 @@ static notrace void marker_probe_cb_noarg(const struct marker *mdata,
                 */
                smp_read_barrier_depends();
                for (i = 0; multi[i].func; i++)
-                       multi[i].func(mdata, multi[i].probe_private,
+                       multi[i].func(mdata, multi[i].probe_private, regs,
                                call_private, mdata->format, &args);
        }
 //ust//        rcu_read_unlock_sched_notrace();
@@ -242,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;
@@ -256,12 +251,12 @@ static void debug_print_probes(struct marker_entry *entry)
                return;
 
        if (!entry->ptype) {
-               printk(KERN_DEBUG "Single probe : %p %p\n",
+               DBG("Single probe : %p %p",
                        entry->single.func,
                        entry->single.probe_private);
        } else {
                for (i = 0; entry->multi[i].func; i++)
-                       printk(KERN_DEBUG "Multi probe %d : %p %p\n", i,
+                       DBG("Multi probe %d : %p %p", i,
                                entry->multi[i].func,
                                entry->multi[i].probe_private);
        }
@@ -304,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)
@@ -370,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++)
@@ -430,25 +423,23 @@ static struct marker_entry *add_marker(const char *channel, const char *name,
        head = &marker_table[hash & ((1 << MARKER_HASH_BITS)-1)];
        hlist_for_each_entry(e, node, head, hlist) {
                if (!strcmp(channel, e->channel) && !strcmp(name, e->name)) {
-                       printk(KERN_NOTICE
-                               "Marker %s.%s busy\n", channel, name);
+                       DBG("Marker %s.%s busy", channel, name);
                        return ERR_PTR(-EBUSY); /* Already there */
                }
        }
        /*
-        * Using kmalloc here to allocate a variable length element. Could
+        * Using zmalloc 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 = zmalloc(sizeof(struct marker_entry)
+                   + channel_len + name_len + format_len);
        if (!e)
                return ERR_PTR(-ENOMEM);
        memcpy(e->channel, channel, channel_len);
        e->name = &e->channel[channel_len];
        memcpy(e->name, name, name_len);
        if (format) {
-               e->format = &e->name[channel_len + name_len];
+               e->format = &e->name[name_len];
                memcpy(e->format, format, format_len);
                if (strcmp(e->format, MARK_NOARGS) == 0)
                        e->call = marker_probe_cb_noarg;
@@ -501,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;
 }
 
@@ -516,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;
@@ -538,9 +529,7 @@ static int set_marker(struct marker_entry *entry, struct marker *elem,
 
        if (entry->format) {
                if (strcmp(entry->format, elem->format) != 0) {
-                       printk(KERN_NOTICE
-                               "Format mismatch for probe %s "
-                               "(%s), marker (%s)\n",
+                       ERR("Format mismatch for probe %s (%s), marker (%s)",
                                entry->name,
                                entry->format,
                                elem->format);
@@ -588,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,21 +623,21 @@ static void disable_marker(struct marker *elem)
        int ret;
 
        /* 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//                 */
+       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 */
@@ -661,6 +650,24 @@ static void disable_marker(struct marker *elem)
         */
 }
 
+/*
+ * is_marker_enabled - Check if a marker is enabled
+ * @channel: channel name
+ * @name: marker name
+ *
+ * Returns 1 if the marker is enabled, 0 if disabled.
+ */
+int is_marker_enabled(const char *channel, const char *name)
+{
+       struct marker_entry *entry;
+
+       pthread_mutex_lock(&markers_mutex);
+       entry = get_marker(channel, name);
+       pthread_mutex_unlock(&markers_mutex);
+
+       return entry && !!entry->refcount;
+}
+
 /**
  * marker_update_probe_range - Update a probe range
  * @begin: beginning of the range
@@ -674,7 +681,7 @@ void marker_update_probe_range(struct marker *begin,
        struct marker *iter;
        struct marker_entry *mark_entry;
 
-       mutex_lock(&markers_mutex);
+       pthread_mutex_lock(&markers_mutex);
        for (iter = begin; iter < end; iter++) {
                mark_entry = get_marker(iter->channel, iter->name);
                if (mark_entry) {
@@ -700,7 +707,19 @@ void marker_update_probe_range(struct marker *begin,
                        disable_marker(iter);
                }
        }
-       mutex_unlock(&markers_mutex);
+       pthread_mutex_unlock(&markers_mutex);
+}
+
+static void lib_update_markers(void)
+{
+       struct lib *lib;
+
+       /* FIXME: we should probably take a mutex here on libs */
+//ust//        pthread_mutex_lock(&module_mutex);
+       list_for_each_entry(lib, &libs, list)
+               marker_update_probe_range(lib->markers_start,
+                               lib->markers_start + lib->markers_count);
+//ust//        pthread_mutex_unlock(&module_mutex);
 }
 
 /*
@@ -727,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? */
@@ -755,7 +774,7 @@ int marker_probe_register(const char *channel, const char *name,
        struct marker_probe_closure *old;
        int first_probe = 0;
 
-       mutex_lock(&markers_mutex);
+       pthread_mutex_lock(&markers_mutex);
        entry = get_marker(channel, name);
        if (!entry) {
                first_probe = 1;
@@ -806,11 +825,12 @@ int marker_probe_register(const char *channel, const char *name,
                else
                        goto end;
        }
-       mutex_unlock(&markers_mutex);
+       pthread_mutex_unlock(&markers_mutex);
 
+       /* Activate marker if necessary */
        marker_update_probes();
 
-       mutex_lock(&markers_mutex);
+       pthread_mutex_lock(&markers_mutex);
        entry = get_marker(channel, name);
        if (!entry)
                goto end;
@@ -831,7 +851,7 @@ error_remove_marker:
        ret_err = remove_marker(channel, name);
        WARN_ON(ret_err);
 end:
-       mutex_unlock(&markers_mutex);
+       pthread_mutex_unlock(&markers_mutex);
        return ret;
 }
 //ust// EXPORT_SYMBOL_GPL(marker_probe_register);
@@ -856,18 +876,18 @@ int marker_probe_unregister(const char *channel, const char *name,
        struct marker_probe_closure *old;
        int ret = -ENOENT;
 
-       mutex_lock(&markers_mutex);
+       pthread_mutex_lock(&markers_mutex);
        entry = get_marker(channel, name);
        if (!entry)
                goto end;
 //ust//        if (entry->rcu_pending)
 //ust//                rcu_barrier_sched();
        old = marker_entry_remove_probe(entry, probe, probe_private);
-       mutex_unlock(&markers_mutex);
+       pthread_mutex_unlock(&markers_mutex);
 
        marker_update_probes();
 
-       mutex_lock(&markers_mutex);
+       pthread_mutex_lock(&markers_mutex);
        entry = get_marker(channel, name);
        if (!entry)
                goto end;
@@ -882,7 +902,7 @@ int marker_probe_unregister(const char *channel, const char *name,
        remove_marker(channel, name);   /* Ignore busy error message */
        ret = 0;
 end:
-       mutex_unlock(&markers_mutex);
+       pthread_mutex_unlock(&markers_mutex);
        return ret;
 }
 //ust// EXPORT_SYMBOL_GPL(marker_probe_unregister);
@@ -937,9 +957,9 @@ 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);
+       pthread_mutex_lock(&markers_mutex);
        entry = get_marker_from_private_data(probe, probe_private);
        if (!entry) {
                ret = -ENOENT;
@@ -948,13 +968,13 @@ 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);
-       mutex_unlock(&markers_mutex);
+       channel = strdup(entry->channel);
+       name = strdup(entry->name);
+       pthread_mutex_unlock(&markers_mutex);
 
        marker_update_probes();
 
-       mutex_lock(&markers_mutex);
+       pthread_mutex_lock(&markers_mutex);
        entry = get_marker(channel, name);
        if (!entry)
                goto end;
@@ -969,9 +989,9 @@ int marker_probe_unregister_private_data(marker_probe_func *probe,
        /* Ignore busy error message */
        remove_marker(channel, name);
 end:
-       mutex_unlock(&markers_mutex);
-       kfree(channel);
-       kfree(name);
+       pthread_mutex_unlock(&markers_mutex);
+       free(channel);
+       free(name);
        return ret;
 }
 //ust// EXPORT_SYMBOL_GPL(marker_probe_unregister_private_data);
@@ -1056,6 +1076,33 @@ void *marker_get_private_data(const char *channel, const char *name,
 
 //ust//#ifdef CONFIG_MODULES
 
+/*
+ * Returns 0 if current not found.
+ * Returns 1 if current found.
+ */
+int lib_get_iter_markers(struct marker_iter *iter)
+{
+       struct lib *iter_lib;
+       int found = 0;
+
+//ust//        pthread_mutex_lock(&module_mutex);
+       list_for_each_entry(iter_lib, &libs, list) {
+               if (iter_lib < iter->lib)
+                       continue;
+               else if (iter_lib > iter->lib)
+                       iter->marker = NULL;
+               found = marker_get_iter_range(&iter->marker,
+                       iter_lib->markers_start,
+                       iter_lib->markers_start + iter_lib->markers_count);
+               if (found) {
+                       iter->lib = iter_lib;
+                       break;
+               }
+       }
+//ust//        pthread_mutex_unlock(&module_mutex);
+       return found;
+}
+
 /**
  * marker_get_iter_range - Get a next marker iterator given a range.
  * @marker: current markers (in), next marker (out)
@@ -1139,196 +1186,55 @@ 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);
                }
        }
 }
 
-//ust// asmlinkage long sys_marker(char __user *name, char __user *format,
-//ust//                char __user *state, int reg)
+/*
+ * Update current process.
+ * Note that we have to wait a whole scheduler period before we are sure that
+ * every running userspace threads have their markers updated.
+ * (synchronize_sched() can be used to insure this).
+ */
+//ust// void marker_update_process(void)
 //ust// {
 //ust//        struct user_marker *umark;
-//ust//        long len;
+//ust//        struct hlist_node *pos;
 //ust//        struct marker_entry *entry;
-//ust//        int ret = 0;
 //ust// 
-//ust//        printk(KERN_DEBUG "Program %s %s marker [%p, %p]\n",
-//ust//                current->comm, reg ? "registers" : "unregisters",
-//ust//                name, state);
-//ust//        if (reg) {
-//ust//                umark = kmalloc(sizeof(struct user_marker), GFP_KERNEL);
-//ust//                umark->name[MAX_USER_MARKER_NAME_LEN - 1] = '\0';
-//ust//                umark->format[MAX_USER_MARKER_FORMAT_LEN - 1] = '\0';
-//ust//                umark->state = state;
-//ust//                len = strncpy_from_user(umark->name, name,
-//ust//                        MAX_USER_MARKER_NAME_LEN - 1);
-//ust//                if (len < 0) {
-//ust//                        ret = -EFAULT;
-//ust//                        goto error;
-//ust//                }
-//ust//                len = strncpy_from_user(umark->format, format,
-//ust//                        MAX_USER_MARKER_FORMAT_LEN - 1);
-//ust//                if (len < 0) {
-//ust//                        ret = -EFAULT;
-//ust//                        goto error;
-//ust//                }
-//ust//                printk(KERN_DEBUG "Marker name : %s, format : %s", umark->name,
-//ust//                        umark->format);
-//ust//                mutex_lock(&markers_mutex);
+//ust//        pthread_mutex_lock(&markers_mutex);
+//ust//        pthread_mutex_lock(&current->group_leader->user_markers_mutex);
+//ust//        if (strcmp(current->comm, "testprog") == 0)
+//ust//                DBG("do update pending for testprog");
+//ust//        hlist_for_each_entry(umark, pos,
+//ust//                        &current->group_leader->user_markers, hlist) {
+//ust//                DBG("Updating marker %s in %s", umark->name, current->comm);
 //ust//                entry = get_marker("userspace", umark->name);
 //ust//                if (entry) {
 //ust//                        if (entry->format &&
 //ust//                                strcmp(entry->format, umark->format) != 0) {
-//ust//                                printk(" error, wrong format in process %s",
+//ust//                                WARN("error, wrong format in process %s",
 //ust//                                        current->comm);
-//ust//                                ret = -EPERM;
-//ust//                                goto error_unlock;
+//ust//                                break;
 //ust//                        }
-//ust//                        printk(" %s", !!entry->refcount
-//ust//                                        ? "enabled" : "disabled");
-//ust//                        if (put_user(!!entry->refcount, state)) {
-//ust//                                ret = -EFAULT;
-//ust//                                goto error_unlock;
+//ust//                        if (put_user(!!entry->refcount, umark->state)) {
+//ust//                                WARN("Marker in %s caused a fault",
+//ust//                                        current->comm);
+//ust//                                break;
 //ust//                        }
-//ust//                        printk("\n");
 //ust//                } else {
-//ust//                        printk(" disabled\n");
 //ust//                        if (put_user(0, umark->state)) {
-//ust//                                printk(KERN_WARNING
-//ust//                                        "Marker in %s caused a fault\n",
-//ust//                                        current->comm);
-//ust//                                goto error_unlock;
+//ust//                                WARN("Marker in %s caused a fault", current->comm);
+//ust//                                break;
 //ust//                        }
 //ust//                }
-//ust//                mutex_lock(&current->group_leader->user_markers_mutex);
-//ust//                hlist_add_head(&umark->hlist,
-//ust//                        &current->group_leader->user_markers);
-//ust//                current->group_leader->user_markers_sequence++;
-//ust//                mutex_unlock(&current->group_leader->user_markers_mutex);
-//ust//                mutex_unlock(&markers_mutex);
-//ust//        } else {
-//ust//                mutex_lock(&current->group_leader->user_markers_mutex);
-//ust//                free_user_marker(state,
-//ust//                        &current->group_leader->user_markers);
-//ust//                current->group_leader->user_markers_sequence++;
-//ust//                mutex_unlock(&current->group_leader->user_markers_mutex);
 //ust//        }
-//ust//        goto end;
-//ust// error_unlock:
-//ust//        mutex_unlock(&markers_mutex);
-//ust// error:
-//ust//        kfree(umark);
-//ust// end:
-//ust//        return ret;
-//ust// }
-//ust// 
-//ust// /*
-//ust//  * Types :
-//ust//  * string : 0
-//ust//  */
-//ust// asmlinkage long sys_trace(int type, uint16_t id,
-//ust//                char __user *ubuf)
-//ust// {
-//ust//        long ret = -EPERM;
-//ust//        char *page;
-//ust//        int len;
-//ust// 
-//ust//        switch (type) {
-//ust//        case 0: /* String */
-//ust//                ret = -ENOMEM;
-//ust//                page = (char *)__get_free_page(GFP_TEMPORARY);
-//ust//                if (!page)
-//ust//                        goto string_out;
-//ust//                len = strncpy_from_user(page, ubuf, PAGE_SIZE);
-//ust//                if (len < 0) {
-//ust//                        ret = -EFAULT;
-//ust//                        goto string_err;
-//ust//                }
-//ust//                trace_mark(userspace, string, "string %s", page);
-//ust// string_err:
-//ust//                free_page((unsigned long) page);
-//ust// string_out:
-//ust//                break;
-//ust//        default:
-//ust//                break;
-//ust//        }
-//ust//        return ret;
-//ust// }
-
-//ust// static void marker_update_processes(void)
-//ust// {
-//ust//        struct task_struct *g, *t;
-//ust// 
-//ust//        /*
-//ust//         * markers_mutex is taken to protect the p->user_markers read.
-//ust//         */
-//ust//        mutex_lock(&markers_mutex);
-//ust//        read_lock(&tasklist_lock);
-//ust//        for_each_process(g) {
-//ust//                WARN_ON(!thread_group_leader(g));
-//ust//                if (hlist_empty(&g->user_markers))
-//ust//                        continue;
-//ust//                if (strcmp(g->comm, "testprog") == 0)
-//ust//                        printk(KERN_DEBUG "set update pending for testprog\n");
-//ust//                t = g;
-//ust//                do {
-//ust//                        /* TODO : implement this thread flag in each arch. */
-//ust//                        set_tsk_thread_flag(t, TIF_MARKER_PENDING);
-//ust//                } while ((t = next_thread(t)) != g);
-//ust//        }
-//ust//        read_unlock(&tasklist_lock);
-//ust//        mutex_unlock(&markers_mutex);
+//ust//        clear_thread_flag(TIF_MARKER_PENDING);
+//ust//        pthread_mutex_unlock(&current->group_leader->user_markers_mutex);
+//ust//        pthread_mutex_unlock(&markers_mutex);
 //ust// }
 
-/*
- * Update current process.
- * Note that we have to wait a whole scheduler period before we are sure that
- * every running userspace threads have their markers updated.
- * (synchronize_sched() can be used to insure this).
- */
-void marker_update_process(void)
-{
-       struct user_marker *umark;
-       struct hlist_node *pos;
-       struct marker_entry *entry;
-
-       mutex_lock(&markers_mutex);
-       mutex_lock(&current->group_leader->user_markers_mutex);
-       if (strcmp(current->comm, "testprog") == 0)
-               printk(KERN_DEBUG "do update pending for testprog\n");
-       hlist_for_each_entry(umark, pos,
-                       &current->group_leader->user_markers, hlist) {
-               printk(KERN_DEBUG "Updating marker %s in %s\n",
-                       umark->name, current->comm);
-               entry = get_marker("userspace", umark->name);
-               if (entry) {
-                       if (entry->format &&
-                               strcmp(entry->format, umark->format) != 0) {
-                               printk(KERN_WARNING
-                                       " error, wrong format in process %s\n",
-                                       current->comm);
-                               break;
-                       }
-                       if (put_user(!!entry->refcount, umark->state)) {
-                               printk(KERN_WARNING
-                                       "Marker in %s caused a fault\n",
-                                       current->comm);
-                               break;
-                       }
-               } else {
-                       if (put_user(0, umark->state)) {
-                               printk(KERN_WARNING
-                                       "Marker in %s caused a fault\n",
-                                       current->comm);
-                               break;
-                       }
-               }
-       }
-       clear_thread_flag(TIF_MARKER_PENDING);
-       mutex_unlock(&current->group_leader->user_markers_mutex);
-       mutex_unlock(&markers_mutex);
-}
-
 /*
  * Called at process exit and upon do_execve().
  * We assume that when the leader exits, no more references can be done to the
@@ -1340,15 +1246,15 @@ void exit_user_markers(struct task_struct *p)
        struct hlist_node *pos, *n;
 
        if (thread_group_leader(p)) {
-               mutex_lock(&markers_mutex);
-               mutex_lock(&p->user_markers_mutex);
+               pthread_mutex_lock(&markers_mutex);
+               pthread_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);
-               mutex_unlock(&markers_mutex);
+               pthread_mutex_unlock(&p->user_markers_mutex);
+               pthread_mutex_unlock(&markers_mutex);
        }
 }
 
@@ -1356,9 +1262,9 @@ int is_marker_enabled(const char *channel, const char *name)
 {
        struct marker_entry *entry;
 
-       mutex_lock(&markers_mutex);
+       pthread_mutex_lock(&markers_mutex);
        entry = get_marker(channel, name);
-       mutex_unlock(&markers_mutex);
+       pthread_mutex_unlock(&markers_mutex);
 
        return entry && !!entry->refcount;
 }
@@ -1396,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;
@@ -1404,7 +1310,7 @@ void ltt_dump_marker_state(struct ltt_trace_struct *trace)
        struct hlist_node *node;
        unsigned int i;
 
-       mutex_lock(&markers_mutex);
+       pthread_mutex_lock(&markers_mutex);
        call_data.trace = trace;
        call_data.serializer = NULL;
 
@@ -1432,51 +1338,10 @@ void ltt_dump_marker_state(struct ltt_trace_struct *trace)
                                        entry->format);
                }
        }
-       mutex_unlock(&markers_mutex);
+       pthread_mutex_unlock(&markers_mutex);
 }
 //ust// EXPORT_SYMBOL_GPL(ltt_dump_marker_state);
 
-
-static LIST_HEAD(libs);
-
-/*
- * Returns 0 if current not found.
- * Returns 1 if current found.
- */
-int lib_get_iter_markers(struct marker_iter *iter)
-{
-       struct lib *iter_lib;
-       int found = 0;
-
-//ust//        mutex_lock(&module_mutex);
-       list_for_each_entry(iter_lib, &libs, list) {
-               if (iter_lib < iter->lib)
-                       continue;
-               else if (iter_lib > iter->lib)
-                       iter->marker = NULL;
-               found = marker_get_iter_range(&iter->marker,
-                       iter_lib->markers_start,
-                       iter_lib->markers_start + iter_lib->markers_count);
-               if (found) {
-                       iter->lib = iter_lib;
-                       break;
-               }
-       }
-//ust//        mutex_unlock(&module_mutex);
-       return found;
-}
-
-void lib_update_markers(void)
-{
-       struct lib *lib;
-
-//ust//        mutex_lock(&module_mutex);
-       list_for_each_entry(lib, &libs, list)
-               marker_update_probe_range(lib->markers_start,
-                               lib->markers_start + lib->markers_count);
-//ust//        mutex_unlock(&module_mutex);
-}
-
 static void (*new_marker_cb)(struct marker *) = NULL;
 
 void marker_set_new_marker_cb(void (*cb)(struct marker *))
@@ -1498,7 +1363,7 @@ int marker_register_lib(struct marker *markers_start, int markers_count)
 {
        struct lib *pl;
 
-       pl = (struct lib *) malloc(sizeof(struct lib));
+       pl = (struct lib *) zmalloc(sizeof(struct lib));
 
        pl->markers_start = markers_start;
        pl->markers_count = markers_count;
@@ -1518,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//        pthread_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;
 }
 
@@ -1532,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));
-               printf("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.036833 seconds and 4 git commands to generate.