kmalloc, kfree, etc => malloc, free, etc
authorPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Thu, 4 Mar 2010 16:59:08 +0000 (11:59 -0500)
committerPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Thu, 4 Mar 2010 16:59:08 +0000 (11:59 -0500)
12 files changed:
include/ust/kernelcompat.h
libust/buffers.c
libust/channels.c
libust/marker-control.c
libust/marker.c
libust/tracectl.c
libust/tracepoint.c
libust/tracer.c
tests/fork/fork.c
tests/test-nevents/Makefile.am
tests/test-nevents/prog.c
ustd/lowlevel.c

index 4b43b7e3de02b03ab61156e06719b4ffe9600531..567ad03ea6d4b8162a91020283ba19d32dec5985 100644 (file)
@@ -73,17 +73,8 @@ static inline long IS_ERR(const void *ptr)
 
 /* MALLOCATION */
 
-#include <stdlib.h>
-
-#define kmalloc(s, t) malloc(s)
-#define kzalloc(s, t) zmalloc(s)
-#define kfree(p) free((void *)p)
-#define kstrdup(s, t) strdup(s)
-
 #define zmalloc(s) calloc(1, s)
 
-#define GFP_KERNEL
-
 /* ATTRIBUTES */
 
 #define ____cacheline_aligned
index c487cbfdb57f978021c01cdd04ba2a63f8dd64c4..9651beb916db5d78b8acbae83ded896513963c3f 100644 (file)
@@ -27,6 +27,7 @@
 #include <fcntl.h>
 #include <ust/kernelcompat.h>
 #include <kcompat/kref.h>
+#include <stdlib.h>
 #include "buffers.h"
 #include "channels.h"
 #include "tracer.h"
@@ -751,7 +752,7 @@ static void ust_buffers_destroy_buffer(struct ust_channel *ltt_chan, int cpu)
                ltt_release_transport);
        ltt_relay_print_buffer_errors(ltt_chan, cpu);
 //ust//        free(ltt_buf->commit_seq);
-       kfree(ltt_buf->commit_count);
+       free(ltt_buf->commit_count);
        ltt_buf->commit_count = NULL;
        kref_put(&ltt_chan->kref, ltt_relay_release_channel);
        kref_put(&trace->kref, ltt_release_trace);
index b7f35439a86e189413e7fa8ef81374c30a945d12..abb2986c4689a4354d7e49648ea9ce7ca2f0e91a 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
-//ust// #include <linux/module.h>
-//ust// #include <linux/ltt-channels.h>
-//ust// #include <linux/mutex.h>
-//ust// #include <linux/vmalloc.h>
-
+#include <stdlib.h>
 #include <ust/kernelcompat.h>
+#include <ust/marker.h>
 #include "channels.h"
 #include "usterr.h"
-#include <ust/marker.h>
 
 /*
  * ltt_channel_mutex may be nested inside the LTT trace mutex.
@@ -75,13 +71,14 @@ static void release_channel_setting(struct kref *kref)
        if (uatomic_read(&index_kref.refcount) == 0
            && uatomic_read(&setting->kref.refcount) == 0) {
                list_del(&setting->list);
-               kfree(setting);
+               free(setting);
 
                free_index = 0;
                list_for_each_entry(iter, &ltt_channels, list) {
                        iter->index = free_index++;
                        iter->free_event_id = 0;
                }
+               /* FIXME: why not run this? */
 //ust//                markers_compact_event_ids();
        }
 }
@@ -120,7 +117,7 @@ int ltt_channels_register(const char *name)
                        goto end;
                }
        }
-       setting = kzalloc(sizeof(*setting), GFP_KERNEL);
+       setting = zmalloc(sizeof(*setting));
        if (!setting) {
                ret = -ENOMEM;
                goto end;
@@ -264,8 +261,7 @@ struct ust_channel *ltt_channels_trace_alloc(unsigned int *nr_channels,
        else
                kref_get(&index_kref);
        *nr_channels = free_index;
-       channel = kzalloc(sizeof(struct ust_channel) * free_index,
-                         GFP_KERNEL);
+       channel = zmalloc(sizeof(struct ust_channel) * free_index);
        if (!channel) {
                WARN("ltt_channel_struct: channel null after alloc");
                goto end;
@@ -296,7 +292,7 @@ void ltt_channels_trace_free(struct ust_channel *channels)
 {
        lock_markers();
        mutex_lock(&ltt_channel_mutex);
-       kfree(channels);
+       free(channels);
        kref_put(&index_kref, release_trace_channel);
        mutex_unlock(&ltt_channel_mutex);
        unlock_markers();
index a0786bad6fb306af26c8c1c300b01d5f2526f1db..a24a94c6876e747ef7a7e30b5e8cd62267e8a302 100644 (file)
  * LTT marker control module over /proc
  */
 
-//ust// #include <linux/proc_fs.h>
-//ust// #include <linux/module.h>
-//ust// #include <linux/stat.h>
-//ust// #include <linux/vmalloc.h>
-//ust// #include <linux/marker.h>
-//ust// #include <linux/ltt-tracer.h>
-//ust// #include <linux/uaccess.h>
-//ust// #include <linux/string.h>
-//ust// #include <linux/ctype.h>
-//ust// #include <linux/list.h>
-//ust// #include <linux/mutex.h>
-//ust// #include <linux/seq_file.h>
-//ust// #include <linux/slab.h>
 #include <ctype.h>
+#include <stdlib.h>
 
 #include <ust/kernelcompat.h>
-//#include "list.h"
 #include "tracer.h"
 #include "usterr.h"
 
index b1e457e7fbb9c05f12e6829bf4380afee3f9174e..86b06cffdbc37a0d4e17ad9ec2be8a87d89b8bab 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 <ust/kernelcompat.h>
-
 #include <ust/marker.h>
+
 #include "usterr.h"
 #include "channels.h"
 #include "tracercore.h"
@@ -248,7 +236,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 +298,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 +363,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 +427,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 +491,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 +506,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;
@@ -971,7 +956,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 +967,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 +989,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 +1185,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 +1249,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);
index 25e96450ca70492ad1edfb1a644a759f47f35252..bafe1a94d5a56ac5e7b57f179f75aadbfd520201 100644 (file)
@@ -17,6 +17,7 @@
 
 #define _GNU_SOURCE
 #include <stdio.h>
+#include <stdlib.h>
 #include <stdint.h>
 #include <signal.h>
 #include <sys/types.h>
index 7976f7d920c3f3a6ff3e8c442e6aa2eace925e92..584b3ffe1af50ffdb01f383ed9ba6ace0fb267bc 100644 (file)
@@ -86,8 +86,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 +103,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);
        }
 }
 
@@ -233,7 +233,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);
@@ -250,7 +250,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);
 }
 
 /*
@@ -501,7 +501,7 @@ void tracepoint_probe_update_all(void)
                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);
index 5f9aa69ffe2d8531f1c88bed35eb910b82b709ae..6f3c1aeaaf58b37cfc52fd310b49f655a40d7921 100644 (file)
@@ -343,7 +343,7 @@ void ltt_release_trace(struct kref *kref)
        struct ust_trace *trace = container_of(kref,
                        struct ust_trace, kref);
        ltt_channels_trace_free(trace->channels);
-       kfree(trace);
+       free(trace);
 }
 
 static inline void prepare_chan_size_num(unsigned int *subbuf_size,
@@ -381,7 +381,7 @@ int _ltt_trace_setup(const char *trace_name)
                goto traces_error;
        }
 
-       new_trace = kzalloc(sizeof(struct ust_trace), GFP_KERNEL);
+       new_trace = zmalloc(sizeof(struct ust_trace));
        if (!new_trace) {
                ERR("Unable to allocate memory for trace %s", trace_name);
                err = -ENOMEM;
@@ -423,7 +423,7 @@ int _ltt_trace_setup(const char *trace_name)
        return 0;
 
 trace_free:
-       kfree(new_trace);
+       free(new_trace);
 traces_error:
        return err;
 }
@@ -442,7 +442,7 @@ int ltt_trace_setup(const char *trace_name)
 static void _ltt_trace_free(struct ust_trace *trace)
 {
        list_del(&trace->list);
-       kfree(trace);
+       free(trace);
 }
 
 int ltt_trace_set_type(const char *trace_name, const char *trace_type)
index a8e8e4eef99140fa793be0d41f27cb6fc44dc742..b2d7d07026d3276f1cc48769cbb4df4b060ae414 100644 (file)
@@ -1,6 +1,7 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <sys/types.h>
+#include <stdlib.h>
 
 #include <ust/marker.h>
 
index 502d6c45732eb72d2a9b6ad4660e576c2ba67589..2af5510e1805d0d76963d0cfd6c278992ac0d293 100644 (file)
@@ -1,4 +1,4 @@
-#AM_CPPFLAGS = -I$(top_srcdir)/include
+AM_CPPFLAGS = -I$(top_srcdir)/include
 
 noinst_PROGRAMS = prog
 prog_SOURCES = prog.c
index 71c03e0f4bf42698e6aca96b78c6da8c412c5a16..5e1c64ac614c9aab2135f9b814d4fd9ea083126d 100644 (file)
@@ -7,17 +7,11 @@
 int main()
 {
        int i;
-       const char teststr[] = "Hello World! 1234567890abc";
-       void *ptrs[N_ITER];
 
        for(i=0; i<N_ITER; i++) {
                trace_mark(ust, an_event, "%d", i);
                trace_mark(ust, another_event, "%s", "Hello, World!");
        }
 
-//     ltt_trace_stop("auto");
-//     ltt_trace_destroy("auto");
-//     sleep(2);
-
        return 0;
 }
index 57a9f6631c1ba53ce035a17237a4718b2e7bd802..5c145fa3f9e9ffae7cb947ef9ab76643eada4290 100644 (file)
@@ -15,6 +15,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+#include <stdlib.h>
 #include <assert.h>
 #include <byteswap.h>
 
This page took 0.032001 seconds and 4 git commands to generate.