video: tegra: nvmap: add handle share count to debug stats
Krishna Reddy [Fri, 20 Jun 2014 00:34:01 +0000 (17:34 -0700)]
handle share count provides info on how many processes are sharing
the handle. IOW, how many processes are holding a ref on handle.
Update the comments for umap/kmap_count.

Bug 1529015

Change-Id: I9f543ebf51842dad6ecd3bfeb7480496c98963be
Signed-off-by: Krishna Reddy <vdumpa@nvidia.com>
Reviewed-on: http://git-master/r/426302
(cherry picked from commit 244c41508be0705cc232942b9403e17611f63e45)
Reviewed-on: http://git-master/r/448521
Tested-by: Maneet Maneet Singh <mmaneetsingh@nvidia.com>

drivers/video/tegra/nvmap/nvmap_dev.c
drivers/video/tegra/nvmap/nvmap_handle.c
drivers/video/tegra/nvmap/nvmap_priv.h

index 6ae8e71..9b874d3 100644 (file)
@@ -444,6 +444,7 @@ static void destroy_client(struct nvmap_client *client)
 
                dma_buf_put(ref->handle->dmabuf);
                rb_erase(&ref->node, &client->handle_refs);
+               atomic_dec(&ref->handle->share_count);
 
                dupes = atomic_read(&ref->dupes);
                while (dupes--)
@@ -822,13 +823,14 @@ static void allocations_stringify(struct nvmap_client *client,
                        phys_addr_t base = iovmm ? 0 :
                                           (handle->carveout->base);
                        seq_printf(s,
-                               "%-18s %-18s %8llx %10zuK %8x %6u %6u %6u %8p\n",
+                               "%-18s %-18s %8llx %10zuK %8x %6u %6u %6u %6u %8p\n",
                                "", "",
                                (unsigned long long)base, K(handle->size),
                                handle->userflags,
                                atomic_read(&handle->ref),
                                atomic_read(&ref->dupes),
                                atomic_read(&ref->pin),
+                               atomic_read(&handle->share_count),
                                handle);
                }
        }
@@ -844,9 +846,9 @@ static int nvmap_debug_allocations_show(struct seq_file *s, void *unused)
        spin_lock(&node->clients_lock);
        seq_printf(s, "%-18s %18s %8s %11s\n",
                "CLIENT", "PROCESS", "PID", "SIZE");
-       seq_printf(s, "%-18s %18s %8s %11s %8s %6s %6s %6s %8s\n",
+       seq_printf(s, "%-18s %18s %8s %11s %8s %6s %6s %6s %6s %8s\n",
                        "", "", "BASE", "SIZE", "FLAGS", "REFS",
-                       "DUPES", "PINS", "UID");
+                       "DUPES", "PINS", "SHARE", "UID");
        list_for_each_entry(commit, &node->clients, list) {
                struct nvmap_client *client =
                        get_client_from_carveout_commit(node, commit);
@@ -965,9 +967,9 @@ static int nvmap_debug_iovmm_allocations_show(struct seq_file *s, void *unused)
        spin_lock(&dev->clients_lock);
        seq_printf(s, "%-18s %18s %8s %11s\n",
                "CLIENT", "PROCESS", "PID", "SIZE");
-       seq_printf(s, "%-18s %18s %8s %11s %8s %6s %6s %6s %8s\n",
+       seq_printf(s, "%-18s %18s %8s %11s %8s %6s %6s %6s %6s %8s\n",
                        "", "", "BASE", "SIZE", "FLAGS", "REFS",
-                       "DUPES", "PINS", "UID");
+                       "DUPES", "PINS", "SHARE", "UID");
        list_for_each_entry(client, &dev->clients, list) {
                int iovm_commit = atomic_read(&client->iovm_commit);
                client_stringify(client, s);
index 0959a98..40ebbb0 100644 (file)
@@ -418,6 +418,7 @@ void nvmap_free_handle(struct nvmap_client *client,
        pins = atomic_read(&ref->pin);
        rb_erase(&ref->node, &client->handle_refs);
        client->handle_count--;
+       atomic_dec(&ref->handle->share_count);
 
        if (h->alloc && h->heap_pgalloc)
                atomic_sub(h->size, &client->iovm_commit);
@@ -478,6 +479,7 @@ static void add_handle_ref(struct nvmap_client *client,
        client->handle_count++;
        if (client->handle_count > nvmap_max_handle_count)
                nvmap_max_handle_count = client->handle_count;
+       atomic_inc(&ref->handle->share_count);
        nvmap_ref_unlock(client);
 }
 
index 7489263..a3c45d8 100644 (file)
@@ -135,6 +135,7 @@ struct nvmap_handle {
        u32 userflags;          /* flags passed from userspace */
        void *vaddr;            /* mapping used inside kernel */
        struct list_head vmas;  /* list of all user vma's */
+       atomic_t share_count;   /* number of processes sharing the handle */
        struct mutex lock;
        void *nvhost_priv;      /* nvhost private data */
        void (*nvhost_priv_delete)(void *priv);