misc: tegra-profiler: fix incorrect names
Igor Nabirushkin [Sat, 7 Sep 2013 07:36:23 +0000 (11:36 +0400)]
Tegra Profiler: fix incorrect names of modules.
mmap buffers are created for each core

Bug 1364251
Bug 1312406

Change-Id: Ib60fa45e5418de3acf2afd782c53650f17731976
Signed-off-by: Igor Nabirushkin <inabirushkin@nvidia.com>
Reviewed-on: http://git-master/r/276975
(cherry picked from commit be01a69b08224236d447b2a1a2fb0d23698fed98)
Reviewed-on: http://git-master/r/339999
Reviewed-by: Harry Hong <hhong@nvidia.com>
Tested-by: Harry Hong <hhong@nvidia.com>

drivers/misc/tegra-profiler/main.c
drivers/misc/tegra-profiler/mmap.c
drivers/misc/tegra-profiler/mmap.h
drivers/misc/tegra-profiler/version.h

index dc46c6d..7cc0762 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <linux/init.h>
 #include <linux/module.h>
+#include <linux/err.h>
 
 #include <linux/tegra_profiler.h>
 
@@ -428,9 +429,9 @@ static int __init quadd_module_init(void)
        }
 
        ctx.mmap = quadd_mmap_init(&ctx);
-       if (!ctx.mmap) {
+       if (IS_ERR(ctx.mmap)) {
                pr_err("error: MMAP init failed\n");
-               return -ENODEV;
+               return PTR_ERR(ctx.mmap);
        }
 
        err = quadd_power_clk_init(&ctx);
index a52b11f..370508b 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/crc32.h>
 #include <linux/fs.h>
 #include <linux/slab.h>
+#include <linux/err.h>
 
 #include <linux/tegra_profiler.h>
 
@@ -103,14 +104,16 @@ char *quadd_get_mmap(struct quadd_cpu_context *cpu_ctx,
                     struct pt_regs *regs, struct quadd_mmap_data *sample,
                     unsigned int *extra_length)
 {
+       u32 crc;
+       unsigned long ip;
+       int length, length_aligned;
        struct mm_struct *mm = current->mm;
        struct vm_area_struct *vma;
        struct file *vm_file;
        struct path *path;
        char *file_name = NULL;
-       int length, length_aligned;
-       u32 crc;
-       unsigned long ip;
+       struct quadd_mmap_cpu_ctx *mm_cpu_ctx = this_cpu_ptr(mmap_ctx.cpu_ctx);
+       char *tmp_buf = mm_cpu_ctx->tmp_buf;
 
        if (!mm) {
                *extra_length = 0;
@@ -130,8 +133,10 @@ char *quadd_get_mmap(struct quadd_cpu_context *cpu_ctx,
 
                        path = &vm_file->f_path;
 
-                       file_name = d_path(path, mmap_ctx.tmp_buf, PATH_MAX);
-                       if (file_name) {
+                       file_name = d_path(path, tmp_buf, PATH_MAX);
+                       if (IS_ERR(file_name)) {
+                               file_name = NULL;
+                       } else {
                                sample->addr = vma->vm_start;
                                sample->len = vma->vm_end - vma->vm_start;
                                sample->pgoff =
@@ -184,29 +189,39 @@ char *quadd_get_mmap(struct quadd_cpu_context *cpu_ctx,
 
 struct quadd_mmap_ctx *quadd_mmap_init(struct quadd_ctx *quadd_ctx)
 {
+       int cpu_id;
        u32 *hash;
        char *tmp;
+       struct quadd_mmap_cpu_ctx *cpu_ctx;
 
        mmap_ctx.quadd_ctx = quadd_ctx;
 
        hash = kzalloc(QUADD_MMAP_SIZE_ARRAY * sizeof(unsigned int),
                       GFP_KERNEL);
        if (!hash) {
-               pr_err("Alloc error\n");
-               return NULL;
+               pr_err("Failed to allocate mmap buffer\n");
+               return ERR_PTR(-ENOMEM);
        }
        mmap_ctx.hash_array = hash;
 
        mmap_ctx.nr_hashes = 0;
        spin_lock_init(&mmap_ctx.lock);
 
-       tmp = kzalloc(PATH_MAX + sizeof(unsigned long long),
-                     GFP_KERNEL);
-       if (!tmp) {
-               pr_err("Alloc error\n");
-               return NULL;
+       mmap_ctx.cpu_ctx = alloc_percpu(struct quadd_mmap_cpu_ctx);
+       if (!mmap_ctx.cpu_ctx)
+               return ERR_PTR(-ENOMEM);
+
+       for (cpu_id = 0; cpu_id < nr_cpu_ids; cpu_id++) {
+               cpu_ctx = per_cpu_ptr(mmap_ctx.cpu_ctx, cpu_id);
+
+               tmp = kzalloc(PATH_MAX + sizeof(unsigned long long),
+                             GFP_KERNEL);
+               if (!tmp) {
+                       pr_err("Failed to allocate mmap buffer\n");
+                       return ERR_PTR(-ENOMEM);
+               }
+               cpu_ctx->tmp_buf = tmp;
        }
-       mmap_ctx.tmp_buf = tmp;
 
        return &mmap_ctx;
 }
@@ -222,15 +237,19 @@ void quadd_mmap_reset(void)
 
 void quadd_mmap_deinit(void)
 {
+       int cpu_id;
        unsigned long flags;
+       struct quadd_mmap_cpu_ctx *cpu_ctx;
 
        spin_lock_irqsave(&mmap_ctx.lock, flags);
-
        kfree(mmap_ctx.hash_array);
        mmap_ctx.hash_array = NULL;
 
-       kfree(mmap_ctx.tmp_buf);
-       mmap_ctx.tmp_buf = NULL;
+       for (cpu_id = 0; cpu_id < nr_cpu_ids; cpu_id++) {
+               cpu_ctx = per_cpu_ptr(mmap_ctx.cpu_ctx, cpu_id);
+               kfree(cpu_ctx->tmp_buf);
+       }
+       free_percpu(mmap_ctx.cpu_ctx);
 
        spin_unlock_irqrestore(&mmap_ctx.lock, flags);
 }
index f12ec4d..dd750f9 100644 (file)
@@ -25,12 +25,16 @@ struct quadd_mmap_data;
 
 #define QUADD_MMAP_SIZE_ARRAY  4096
 
+struct quadd_mmap_cpu_ctx {
+       char *tmp_buf;
+};
+
 struct quadd_mmap_ctx {
        u32 *hash_array;
        unsigned int nr_hashes;
        spinlock_t lock;
 
-       char *tmp_buf;
+       struct quadd_mmap_cpu_ctx * __percpu cpu_ctx;
 
        struct quadd_ctx *quadd_ctx;
 };
index efaa135..c248954 100644 (file)
@@ -18,7 +18,7 @@
 #ifndef __QUADD_VERSION_H
 #define __QUADD_VERSION_H
 
-#define QUADD_MODULE_VERSION           "1.27"
-#define QUADD_MODULE_BRANCH            "Blackrock2"
+#define QUADD_MODULE_VERSION           "1.28"
+#define QUADD_MODULE_BRANCH            "Dev"
 
 #endif /* __QUADD_VERSION_H */