On 09/11/2018 04:29 AM, Alexey Skidanov wrote:
Heap statistics have been removed and currently even basics statistics
are missing.

This patch creates per heap debugfs directory /sys/kernel/debug/<heap_name>
and adds the following counters:
- the number of allocated buffers;
- the number of allocated bytes;
- the number of allocated bytes watermark.

Signed-off-by: Alexey Skidanov <alexey.skida...@intel.com>
---

  v3:
    Removed debugfs_create_dir() return value checking

  drivers/staging/android/ion/ion.c | 46 ++++++++++++++++++++++++++++++++-------
  drivers/staging/android/ion/ion.h |  6 ++---
  2 files changed, 41 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/android/ion/ion.c 
b/drivers/staging/android/ion/ion.c
index 9907332..ba4c6e6 100644
--- a/drivers/staging/android/ion/ion.c
+++ b/drivers/staging/android/ion/ion.c
@@ -95,6 +95,11 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap 
*heap,
                goto err1;
        }
+ heap->num_of_buffers++;
+       heap->num_of_alloc_bytes += len;
+       if (heap->num_of_alloc_bytes > heap->alloc_bytes_wm)
+               heap->alloc_bytes_wm = heap->num_of_alloc_bytes;
+
        INIT_LIST_HEAD(&buffer->attachments);
        mutex_init(&buffer->lock);
        mutex_lock(&dev->buffer_lock);
@@ -117,6 +122,9 @@ void ion_buffer_destroy(struct ion_buffer *buffer)
                buffer->heap->ops->unmap_kernel(buffer->heap, buffer);
        }
        buffer->heap->ops->free(buffer);
+       buffer->heap->num_of_buffers--;
+       buffer->heap->num_of_alloc_bytes -= buffer->size;
+
        kfree(buffer);
  }
@@ -528,6 +536,8 @@ void ion_device_add_heap(struct ion_heap *heap)
  {
        struct ion_device *dev = internal_dev;
        int ret;
+       struct dentry *heap_root;
+       char debug_name[64];
if (!heap->ops->allocate || !heap->ops->free)
                pr_err("%s: can not add heap with invalid ops struct.\n",
@@ -546,6 +556,34 @@ void ion_device_add_heap(struct ion_heap *heap)
        }
heap->dev = dev;
+       heap->num_of_buffers = 0;
+       heap->num_of_alloc_bytes = 0;
+       heap->alloc_bytes_wm = 0;
+
+       /* Create heap root directory */
+       heap_root = debugfs_create_dir(heap->name, dev->debug_root);
+       debugfs_create_u64("num_of_buffers",
+                          0444, heap_root,
+                          &heap->num_of_buffers);
+       debugfs_create_u64("num_of_alloc_bytes",
+                          0444,
+                          heap_root,
+                          &heap->num_of_alloc_bytes);
+       debugfs_create_u64("alloc_bytes_wm",
+                          0444,
+                          heap_root,
+                          &heap->alloc_bytes_wm);
+
+       if (heap->shrinker.count_objects &&
+           heap->shrinker.scan_objects) {
+               snprintf(debug_name, 64, "%s_shrink", heap->name);
+               debugfs_create_file(debug_name,
+                                   0644,
+                                   heap_root,
+                                   heap,
+                                   &debug_shrink_fops);
+       }
+
        down_write(&dev->lock);
        heap->id = heap_id++;
        /*
@@ -555,14 +593,6 @@ void ion_device_add_heap(struct ion_heap *heap)
        plist_node_init(&heap->node, -heap->id);
        plist_add(&heap->node, &dev->heaps);
- if (heap->shrinker.count_objects && heap->shrinker.scan_objects) {
-               char debug_name[64];
-
-               snprintf(debug_name, 64, "%s_shrink", heap->name);
-               debugfs_create_file(debug_name, 0644, dev->debug_root,
-                                   heap, &debug_shrink_fops);
-       }
-
        dev->heap_cnt++;
        up_write(&dev->lock);
  }
diff --git a/drivers/staging/android/ion/ion.h 
b/drivers/staging/android/ion/ion.h
index 16cbd38..bea84b6 100644
--- a/drivers/staging/android/ion/ion.h
+++ b/drivers/staging/android/ion/ion.h
@@ -179,9 +179,9 @@ struct ion_heap {
        spinlock_t free_lock;
        wait_queue_head_t waitqueue;
        struct task_struct *task;
-
-       int (*debug_show)(struct ion_heap *heap, struct seq_file *s,
-                         void *unused);
+       u64 num_of_buffers;
+       u64 num_of_alloc_bytes;
+       u64 alloc_bytes_wm;

What lock is protecting these?

  };
/**


_______________________________________________
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

Reply via email to