remove mutex_lock, mutex_unlock macros
[ust.git] / libust / tracepoint.c
index ebcbe252f1a0eba3d58711d9bb2e3106c5fb66e7..6155e2900e43ff6d6c3b40220aae18f4fea3cbae 100644 (file)
@@ -2,43 +2,31 @@
  * Copyright (C) 2008 Mathieu Desnoyers
  * Copyright (C) 2009 Pierre-Marc Fournier
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
  *
- * This program is distributed in the hope that it will be useful,
+ * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
  *
  * Ported to userspace by Pierre-Marc Fournier.
  */
 
-//ust// #include <linux/module.h>
-//ust// #include <linux/mutex.h>
-//ust// #include <linux/types.h>
-//ust// #include <linux/jhash.h>
-//ust// #include <linux/list.h>
-//ust// #include <linux/rcupdate.h>
-//ust// #include <linux/tracepoint.h>
-//ust// #include <linux/err.h>
-//ust// #include <linux/slab.h>
-//ust// #include <linux/immediate.h>
-
 #include <errno.h>
-
-#include "kernelcompat.h"
-#include "tracepoint.h"
+#include <ust/tracepoint.h>
+#include <ust/core.h>
+#include <ust/kcompat/kcompat.h>
 #include "usterr.h"
-//#include "list.h"
 
 #define _LGPL_SOURCE
-#include <urcu.h>
+#include <urcu-bp.h>
 
 //extern struct tracepoint __start___tracepoints[] __attribute__((visibility("hidden")));
 //extern struct tracepoint __stop___tracepoints[] __attribute__((visibility("hidden")));
@@ -86,8 +74,8 @@ struct tp_probes {
 
 static inline void *allocate_probes(int count)
 {
-       struct tp_probes *p  = kmalloc(count * sizeof(void *)
-                       + sizeof(struct tp_probes), GFP_KERNEL);
+       struct tp_probes *p  = malloc(count * sizeof(void *)
+                       + sizeof(struct tp_probes));
        return p == NULL ? NULL : p->probes;
 }
 
@@ -103,7 +91,7 @@ static inline void release_probes(void *old)
                        struct tp_probes, probes[0]);
 //ust//                call_rcu_sched(&tp_probes->u.rcu, rcu_free_old_probes);
                synchronize_rcu();
-               kfree(tp_probes);
+               free(tp_probes);
        }
 }
 
@@ -115,7 +103,7 @@ static void debug_print_probes(struct tracepoint_entry *entry)
                return;
 
        for (i = 0; entry->funcs[i]; i++)
-               printk(KERN_DEBUG "Probe %d : %p\n", i, entry->funcs[i]);
+               DBG("Probe %d : %p", i, entry->funcs[i]);
 }
 
 static void *
@@ -225,8 +213,7 @@ static struct tracepoint_entry *add_tracepoint(const char *name)
        head = &tracepoint_table[hash & (TRACEPOINT_TABLE_SIZE - 1)];
        hlist_for_each_entry(e, node, head, hlist) {
                if (!strcmp(name, e->name)) {
-                       printk(KERN_NOTICE
-                               "tracepoint %s busy\n", name);
+                       DBG("tracepoint %s busy", name);
                        return ERR_PTR(-EEXIST);        /* Already there */
                }
        }
@@ -234,7 +221,7 @@ static struct tracepoint_entry *add_tracepoint(const char *name)
         * Using kmalloc here to allocate a variable length element. Could
         * cause some memory fragmentation if overused.
         */
-       e = kmalloc(sizeof(struct tracepoint_entry) + name_len, GFP_KERNEL);
+       e = malloc(sizeof(struct tracepoint_entry) + name_len);
        if (!e)
                return ERR_PTR(-ENOMEM);
        memcpy(&e->name[0], name, name_len);
@@ -251,7 +238,7 @@ static struct tracepoint_entry *add_tracepoint(const char *name)
 static inline void remove_tracepoint(struct tracepoint_entry *e)
 {
        hlist_del(&e->hlist);
-       kfree(e);
+       free(e);
 }
 
 /*
@@ -298,7 +285,7 @@ void tracepoint_update_probe_range(struct tracepoint *begin,
        struct tracepoint *iter;
        struct tracepoint_entry *mark_entry;
 
-       mutex_lock(&tracepoints_mutex);
+       pthread_mutex_lock(&tracepoints_mutex);
        for (iter = begin; iter < end; iter++) {
                mark_entry = get_tracepoint(iter->name);
                if (mark_entry) {
@@ -308,7 +295,18 @@ void tracepoint_update_probe_range(struct tracepoint *begin,
                        disable_tracepoint(iter);
                }
        }
-       mutex_unlock(&tracepoints_mutex);
+       pthread_mutex_unlock(&tracepoints_mutex);
+}
+
+static void lib_update_tracepoints(void)
+{
+       struct tracepoint_lib *lib;
+
+//ust//        pthread_mutex_lock(&module_mutex);
+       list_for_each_entry(lib, &libs, list)
+               tracepoint_update_probe_range(lib->tracepoints_start,
+                               lib->tracepoints_start + lib->tracepoints_count);
+//ust//        pthread_mutex_unlock(&module_mutex);
 }
 
 /*
@@ -355,9 +353,9 @@ int tracepoint_probe_register(const char *name, void *probe)
 {
        void *old;
 
-       mutex_lock(&tracepoints_mutex);
+       pthread_mutex_lock(&tracepoints_mutex);
        old = tracepoint_add_probe(name, probe);
-       mutex_unlock(&tracepoints_mutex);
+       pthread_mutex_unlock(&tracepoints_mutex);
        if (IS_ERR(old))
                return PTR_ERR(old);
 
@@ -397,9 +395,9 @@ int tracepoint_probe_unregister(const char *name, void *probe)
 {
        void *old;
 
-       mutex_lock(&tracepoints_mutex);
+       pthread_mutex_lock(&tracepoints_mutex);
        old = tracepoint_remove_probe(name, probe);
-       mutex_unlock(&tracepoints_mutex);
+       pthread_mutex_unlock(&tracepoints_mutex);
        if (IS_ERR(old))
                return PTR_ERR(old);
 
@@ -433,14 +431,14 @@ int tracepoint_probe_register_noupdate(const char *name, void *probe)
 {
        void *old;
 
-       mutex_lock(&tracepoints_mutex);
+       pthread_mutex_lock(&tracepoints_mutex);
        old = tracepoint_add_probe(name, probe);
        if (IS_ERR(old)) {
-               mutex_unlock(&tracepoints_mutex);
+               pthread_mutex_unlock(&tracepoints_mutex);
                return PTR_ERR(old);
        }
        tracepoint_add_old_probes(old);
-       mutex_unlock(&tracepoints_mutex);
+       pthread_mutex_unlock(&tracepoints_mutex);
        return 0;
 }
 //ust// EXPORT_SYMBOL_GPL(tracepoint_probe_register_noupdate);
@@ -456,14 +454,14 @@ int tracepoint_probe_unregister_noupdate(const char *name, void *probe)
 {
        void *old;
 
-       mutex_lock(&tracepoints_mutex);
+       pthread_mutex_lock(&tracepoints_mutex);
        old = tracepoint_remove_probe(name, probe);
        if (IS_ERR(old)) {
-               mutex_unlock(&tracepoints_mutex);
+               pthread_mutex_unlock(&tracepoints_mutex);
                return PTR_ERR(old);
        }
        tracepoint_add_old_probes(old);
-       mutex_unlock(&tracepoints_mutex);
+       pthread_mutex_unlock(&tracepoints_mutex);
        return 0;
 }
 //ust// EXPORT_SYMBOL_GPL(tracepoint_probe_unregister_noupdate);
@@ -476,26 +474,53 @@ void tracepoint_probe_update_all(void)
        LIST_HEAD(release_probes);
        struct tp_probes *pos, *next;
 
-       mutex_lock(&tracepoints_mutex);
+       pthread_mutex_lock(&tracepoints_mutex);
        if (!need_update) {
-               mutex_unlock(&tracepoints_mutex);
+               pthread_mutex_unlock(&tracepoints_mutex);
                return;
        }
        if (!list_empty(&old_probes))
                list_replace_init(&old_probes, &release_probes);
        need_update = 0;
-       mutex_unlock(&tracepoints_mutex);
+       pthread_mutex_unlock(&tracepoints_mutex);
 
        tracepoint_update_probes();
        list_for_each_entry_safe(pos, next, &release_probes, u.list) {
                list_del(&pos->u.list);
 //ust//                call_rcu_sched(&pos->u.rcu, rcu_free_old_probes);
                synchronize_rcu();
-               kfree(pos);
+               free(pos);
        }
 }
 //ust// EXPORT_SYMBOL_GPL(tracepoint_probe_update_all);
 
+/*
+ * Returns 0 if current not found.
+ * Returns 1 if current found.
+ */
+int lib_get_iter_tracepoints(struct tracepoint_iter *iter)
+{
+       struct tracepoint_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->tracepoint = NULL;
+               found = tracepoint_get_iter_range(&iter->tracepoint,
+                       iter_lib->tracepoints_start,
+                       iter_lib->tracepoints_start + iter_lib->tracepoints_count);
+               if (found) {
+                       iter->lib = iter_lib;
+                       break;
+               }
+       }
+//ust//        pthread_mutex_unlock(&module_mutex);
+       return found;
+}
+
 /**
  * tracepoint_get_iter_range - Get a next tracepoint iterator given a range.
  * @tracepoint: current tracepoints (in), next tracepoint (out)
@@ -532,7 +557,7 @@ static void tracepoint_get_iter(struct tracepoint_iter *iter)
 //ust//        }
        /* tracepoints in libs. */
        found = lib_get_iter_tracepoints(iter);
-end:
+//ust// end:
        if (!found)
                tracepoint_iter_reset(iter);
 }
@@ -600,44 +625,6 @@ void tracepoint_iter_reset(struct tracepoint_iter *iter)
 
 //ust// #endif /* CONFIG_MODULES */
 
-/*
- * Returns 0 if current not found.
- * Returns 1 if current found.
- */
-int lib_get_iter_tracepoints(struct tracepoint_iter *iter)
-{
-       struct tracepoint_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->tracepoint = NULL;
-               found = marker_get_iter_range(&iter->tracepoint,
-                       iter_lib->tracepoints_start,
-                       iter_lib->tracepoints_start + iter_lib->tracepoints_count);
-               if (found) {
-                       iter->lib = iter_lib;
-                       break;
-               }
-       }
-//ust//        mutex_unlock(&module_mutex);
-       return found;
-}
-
-void lib_update_tracepoints(void)
-{
-       struct tracepoint_lib *lib;
-
-//ust//        mutex_lock(&module_mutex);
-       list_for_each_entry(lib, &libs, list)
-               tracepoint_update_probe_range(lib->tracepoints_start,
-                               lib->tracepoints_start + lib->tracepoints_count);
-//ust//        mutex_unlock(&module_mutex);
-}
-
 static void (*new_tracepoint_cb)(struct tracepoint *) = NULL;
 
 void tracepoint_set_new_tracepoint_cb(void (*cb)(struct tracepoint *))
@@ -665,9 +652,9 @@ int tracepoint_register_lib(struct tracepoint *tracepoints_start, int tracepoint
        pl->tracepoints_count = tracepoints_count;
 
        /* FIXME: maybe protect this with its own mutex? */
-       mutex_lock(&tracepoints_mutex);
+       pthread_mutex_lock(&tracepoints_mutex);
        list_add(&pl->list, &libs);
-       mutex_unlock(&tracepoints_mutex);
+       pthread_mutex_unlock(&tracepoints_mutex);
 
        new_tracepoints(tracepoints_start, tracepoints_start + tracepoints_count);
 
@@ -679,10 +666,22 @@ int tracepoint_register_lib(struct tracepoint *tracepoints_start, int tracepoint
        return 0;
 }
 
-int tracepoint_unregister_lib(struct tracepoint *tracepoints_start, int tracepoints_count)
+int tracepoint_unregister_lib(struct tracepoint *tracepoints_start)
 {
-       /*FIXME: implement; but before implementing, tracepoint_register_lib must
-          have appropriate locking. */
+       struct tracepoint_lib *lib;
+
+       pthread_mutex_lock(&tracepoints_mutex);
+
+       list_for_each_entry(lib, &libs, list) {
+               if(lib->tracepoints_start == tracepoints_start) {
+                       struct tracepoint_lib *lib2free = lib;
+                       list_del(&lib->list);
+                       free(lib2free);
+                       break;
+               }
+       }
+
+       pthread_mutex_unlock(&tracepoints_mutex);
 
        return 0;
 }
This page took 0.028287 seconds and 4 git commands to generate.