rk: ion: Add trace emit function for ion debug
authorCMY <cmy@rock-chips.com>
Tue, 14 Apr 2015 11:57:37 +0000 (19:57 +0800)
committerCMY <cmy@rock-chips.com>
Tue, 14 Apr 2015 11:59:46 +0000 (19:59 +0800)
Signed-off-by: CMY <cmy@rock-chips.com>
drivers/staging/android/ion/ion.c
drivers/staging/android/trace/ion.h

index f497979b6c4051ef317d116634661b6cd58c3239..8508a40b19be0ce1b9722c4b6ae42957b9da75db 100755 (executable)
@@ -913,13 +913,13 @@ void ion_unmap_iommu(struct device *iommu_dev, struct ion_client *client,
                goto out;
        }
 
-       kref_put(&iommu_map->ref, ion_iommu_release);
-
        buffer->iommu_map_cnt--;
 
        trace_ion_iommu_unmap(client->display_name, (void*)buffer, buffer->size,
                dev_name(iommu_dev), iommu_map->iova_addr,
                iommu_map->mapped_size, buffer->iommu_map_cnt);
+
+       kref_put(&iommu_map->ref, ion_iommu_release);
 out:
        mutex_unlock(&buffer->lock);
        mutex_unlock(&client->lock);
@@ -1774,9 +1774,10 @@ static int ion_debug_heap_show(struct seq_file *s, void *unused)
                        continue;
                total_size += buffer->size;
                if (!buffer->handle_count) {
-                       seq_printf(s, "%16.s %16u %16zu %d %d\n",
+                       seq_printf(s, "%16.s %16u %16zu 0x%p %d %d\n",
                                   buffer->task_comm, buffer->pid,
-                                  buffer->size, buffer->kmap_cnt,
+                                  buffer->size, buffer,
+                                  buffer->kmap_cnt,
                                   atomic_read(&buffer->ref.refcount));
                        total_orphaned_size += buffer->size;
                }
@@ -1906,6 +1907,42 @@ static const struct file_operations debug_heap_bitmap_fops = {
 };
 #endif
 
+static ssize_t
+rockchip_ion_debug_write(struct file *filp, const char __user *ubuf, size_t cnt,
+                      loff_t *ppos)
+{
+       char buf[64];
+
+       if (copy_from_user(buf, ubuf, cnt>63?63:cnt)) {
+               return -EFAULT;
+       }
+       buf[cnt] = '\0';
+       ion_trace_lvl = simple_strtol(buf, NULL, 10);
+       *ppos += cnt;
+       return cnt;
+}
+
+static ssize_t
+rockchip_ion_debug_read(struct file *filp, char __user *ubuf, size_t cnt,
+                     loff_t *ppos)
+{
+       int r;
+       char buf[64];
+
+       if (*ppos)
+               return 0;
+
+       snprintf(buf, 63, "%d\n", ion_trace_lvl);
+       r = simple_read_from_buffer(ubuf, cnt, ppos, buf, strlen(buf));
+
+       return r;
+}
+
+static const struct file_operations rockchip_ion_debug_fops = {
+       .read = rockchip_ion_debug_read,
+       .write = rockchip_ion_debug_write,
+};
+
 void ion_device_add_heap(struct ion_device *dev, struct ion_heap *heap)
 {
        struct dentry *debug_file;
@@ -1982,6 +2019,7 @@ struct ion_device *ion_device_create(long (*custom_ioctl)
 {
        struct ion_device *idev;
        int ret;
+       struct dentry* ion_debug;
 
        idev = kzalloc(sizeof(struct ion_device), GFP_KERNEL);
        if (!idev)
@@ -2016,6 +2054,14 @@ struct ion_device *ion_device_create(long (*custom_ioctl)
        rockchip_ion_snapshot_debugfs(idev->debug_root);
 #endif
 
+       ion_debug = debugfs_create_file("debug", 0664, idev->debug_root,
+                                       NULL, &rockchip_ion_debug_fops);
+       if (!ion_debug) {
+               char buf[256], *path;
+               path = dentry_path(idev->debug_root, buf, 256);
+               pr_err("Failed to create debugfs at %s/%s\n",path, "ion_debug");
+       }
+
 debugfs_done:
 
        idev->custom_ioctl = custom_ioctl;
index 509d768da956c7937121ed7ee896c9de46bce57c..9eb14453de3b649eedc00dcd0d01c301a074cfc0 100644 (file)
@@ -1,3 +1,121 @@
+#define ION_TRACE_EMIT
+
+#ifdef ION_TRACE_EMIT
+
+/*
+  ion_trace_lvl
+    0: no trace
+    1: trace iommu
+    2: trace all
+ */
+static int ion_trace_lvl = 0;
+
+#define pr_ion_trace(lvl, fmt, ...) \
+       if (unlikely(ion_trace_lvl>=lvl)) \
+               printk(KERN_INFO "%15.s-%5.d: %s: "pr_fmt(fmt), current->comm,\
+                      current->pid, __func__, ##__VA_ARGS__)
+
+static inline void trace_ion_buffer_alloc(const char* client, void* buf,
+                                   unsigned int size)
+{
+       pr_ion_trace(2, "client=%s,buffer=%p:%d\n", client, buf, size);
+}
+
+static inline void trace_ion_buffer_free(const char* client, void* buf,
+                                   unsigned int size)
+{
+       pr_ion_trace(2, "client=%s,buffer=%p:%d\n", client, buf, size);
+}
+
+static inline void trace_ion_buffer_import(const char* client, void* buf,
+                                   unsigned int size)
+{
+       pr_ion_trace(2, "client=%s,buffer=%p:%d\n", client, buf, size);
+}
+
+static inline void trace_ion_buffer_destroy(const char* client, void* buf,
+                                   unsigned int size)
+{
+       pr_ion_trace(2, "client=%s,buffer=%p:%d\n", client, buf, size);
+}
+
+static inline void trace_ion_kernel_unmap(const char* client, void* buf,
+                                   unsigned int size)
+{
+       pr_ion_trace(2, "client=%s,buffer=%p:%d\n", client, buf, size);
+}
+
+static inline void trace_ion_buffer_share(const char* client, void* buf,
+                                   unsigned int size, int fd)
+{
+       pr_ion_trace(2, "client=%s,buffer=%p:%d,fd=%d\n", client, buf, size, fd);
+}
+
+static inline void trace_ion_client_create(const char* client)
+{
+       pr_ion_trace(2, "client=%s\n", client);
+}
+
+static inline void trace_ion_client_destroy(const char* client)
+{
+       pr_ion_trace(2, "client=%s\n", client);
+}
+
+static inline void trace_ion_iommu_map(const char* client, void* buf,
+                                unsigned int size, const char* iommu_dev,
+                                unsigned int iommu_addr,
+                                unsigned int iommu_size, unsigned int map_cnt)
+{
+       pr_ion_trace(1, "client=%s,buffer=%p:%d,iommu=%s[%08x:%08x]:%d\n",
+                    client,buf, size, iommu_dev, iommu_addr,
+                    iommu_addr+iommu_size, map_cnt);
+}
+
+static inline void trace_ion_iommu_unmap(const char* client, void* buf,
+                                unsigned int size, const char* iommu_dev,
+                                unsigned int iommu_addr,
+                                unsigned int iommu_size, unsigned int map_cnt)
+{
+       pr_ion_trace(1, "client=%s,buffer=%p:%d,iommu=%s[%08x:%08x]:%d\n",
+                    client,buf, size, iommu_dev, iommu_addr,
+                    iommu_addr+iommu_size, map_cnt);
+}
+
+static inline void trace_ion_iommu_release(const char* client, void* buf,
+                                unsigned int size, const char* iommu_dev,
+                                unsigned int iommu_addr,
+                                unsigned int iommu_size, unsigned int map_cnt)
+{
+       pr_ion_trace(1, "client=%s,buffer=%p:%d,iommu=%s[%08x:%08x]:%d\n",
+                    client,buf, size, iommu_dev, iommu_addr,
+                    iommu_addr+iommu_size, map_cnt);
+}
+
+static inline void trace_ion_kernel_map(const char* client, void* buf,
+                                 unsigned int size, void* kaddr)
+{
+       pr_ion_trace(2, "client=%s,buffer=%p:%d,kaddr=%p\n", client, buf, size,
+                    kaddr);
+}
+
+static inline void trace_ion_buffer_mmap(const char* client, void* buf,
+                                  unsigned int size, unsigned long vm_start,
+                                  unsigned long vm_end)
+{
+       pr_ion_trace(2, "client=%s,buffer=%p:%d,vma[%08lx:%08lx]\n", client,
+                    buf, size, vm_start, vm_end);
+}
+
+static inline void trace_ion_buffer_munmap(const char* client, void* buf,
+                                    unsigned int size, unsigned long vm_start,
+                                    unsigned long vm_end)
+{
+       pr_ion_trace(2, "client=%s,buffer=%p:%d,vma[%08lx:%08lx]\n", client,
+                    buf, size, vm_start, vm_end);
+}
+
+#else
+
 #undef TRACE_SYSTEM
 #define TRACE_INCLUDE_PATH ../../drivers/staging/android/trace
 #define TRACE_SYSTEM ion
@@ -183,3 +301,4 @@ DEFINE_EVENT(ion_mmap_op, ion_buffer_munmap,
 
 /* This part must be outside protection */
 #include <trace/define_trace.h>
+#endif