From patchwork Thu Apr 4 06:28:33 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Semwal X-Patchwork-Id: 15894 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id AE76323DEE for ; Thu, 4 Apr 2013 06:29:20 +0000 (UTC) Received: from mail-qc0-f197.google.com (mail-qc0-f197.google.com [209.85.216.197]) by fiordland.canonical.com (Postfix) with ESMTP id 51B29A18CAF for ; Thu, 4 Apr 2013 06:29:20 +0000 (UTC) Received: by mail-qc0-f197.google.com with SMTP id b14sf3005849qcs.8 for ; Wed, 03 Apr 2013 23:29:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:mime-version:x-beenthere:x-received:received-spf :x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-received:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe; bh=OZl0DuHqDD2jylGnUAhuwRvHfJbyq2idwHdGWpABWQA=; b=RNK4vq/Zutd8GXQnMUqvWkOkxsY4wJNy3bMwXhT++FXGhD/4F/MI5zQwdfithCk0hs q0EyCfG5rf8LrPMItOdD2ce+MOEOGcSn1U9cw4f5r89AXlnKBLffYt+C++6JCuCtrCRS bFT4V10cNZfn/SVcD1TodFgX8C3MInVS/vpXiwG5to3F5hUp2Mm/RK4bxj+zctfzSxpL mtBkcmlTnyBIohqjzFnqA8SWyVyNC+UVqu1I7kvKOptuifjvgjBUWBUMOALDYohfdQYX eWxH7sXesKs16F/nb7UvuKYuKsYkUmSzqSzd02BSADerZABA+xdCD1NA2L93NRg2s6RM ne7w== X-Received: by 10.224.110.68 with SMTP id m4mr2716186qap.2.1365056959694; Wed, 03 Apr 2013 23:29:19 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.50.196 with SMTP id e4ls1374185qeo.75.gmail; Wed, 03 Apr 2013 23:29:19 -0700 (PDT) X-Received: by 10.52.122.18 with SMTP id lo18mr3171875vdb.32.1365056959529; Wed, 03 Apr 2013 23:29:19 -0700 (PDT) Received: from mail-vc0-f182.google.com (mail-vc0-f182.google.com [209.85.220.182]) by mx.google.com with ESMTPS id x3si7419880vdh.42.2013.04.03.23.29.19 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 03 Apr 2013 23:29:19 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.182 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.182; Received: by mail-vc0-f182.google.com with SMTP id ht11so2109902vcb.27 for ; Wed, 03 Apr 2013 23:29:19 -0700 (PDT) X-Received: by 10.52.21.212 with SMTP id x20mr3130305vde.106.1365056959400; Wed, 03 Apr 2013 23:29:19 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.58.85.136 with SMTP id h8csp202464vez; Wed, 3 Apr 2013 23:29:18 -0700 (PDT) X-Received: by 10.66.231.5 with SMTP id tc5mr7612292pac.144.1365056958387; Wed, 03 Apr 2013 23:29:18 -0700 (PDT) Received: from mail-pb0-f48.google.com (mail-pb0-f48.google.com [209.85.160.48]) by mx.google.com with ESMTPS id iv6si6016346pac.328.2013.04.03.23.29.18 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 03 Apr 2013 23:29:18 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.160.48 is neither permitted nor denied by best guess record for domain of sumit.semwal@linaro.org) client-ip=209.85.160.48; Received: by mail-pb0-f48.google.com with SMTP id xb4so1260837pbc.21 for ; Wed, 03 Apr 2013 23:29:18 -0700 (PDT) X-Received: by 10.68.211.8 with SMTP id my8mr7126232pbc.7.1365056957982; Wed, 03 Apr 2013 23:29:17 -0700 (PDT) Received: from localhost.localdomain ([122.172.176.105]) by mx.google.com with ESMTPS id pl10sm5353036pbc.1.2013.04.03.23.29.14 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 03 Apr 2013 23:29:17 -0700 (PDT) From: Sumit Semwal To: linaro-mm-sig@lists.linaro.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org Cc: patches@linaro.org, linaro-kernel@lists.linaro.org, Sumit Semwal , Dave Airlie Subject: [PATCH v3 2/2] dma-buf: Add debugfs support Date: Thu, 4 Apr 2013 11:58:33 +0530 Message-Id: <1365056913-25772-3-git-send-email-sumit.semwal@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1365056913-25772-1-git-send-email-sumit.semwal@linaro.org> References: <1365056913-25772-1-git-send-email-sumit.semwal@linaro.org> X-Gm-Message-State: ALoCoQlaAus/lT3e2nKT1USLHl0R2V2UNisyRmItkw+g0ph5MItOzbMzxQ6ot7FA9IYxIOdYdcg2 X-Original-Sender: sumit.semwal@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.182 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Add debugfs support to make it easier to print debug information about the dma-buf buffers. Cc: Dave Airlie [minor fixes on init and warning fix] Signed-off-by: Sumit Semwal --- changes since v2: (based on review comments from Laurent Pinchart) - reordered functions to avoid forward declaration - added __exitcall for dma_buf_deinit() changes since v1: - fixes on init and warnings as reported and corrected by Dave Airlie. - add locking while walking attachment list - reported by Daniel Vetter. --- drivers/base/dma-buf.c | 159 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/dma-buf.h | 5 +- 2 files changed, 163 insertions(+), 1 deletion(-) diff --git a/drivers/base/dma-buf.c b/drivers/base/dma-buf.c index d89102a..466476f 100644 --- a/drivers/base/dma-buf.c +++ b/drivers/base/dma-buf.c @@ -27,9 +27,18 @@ #include #include #include +#include +#include static inline int is_dma_buf_file(struct file *); +struct dma_buf_list { + struct list_head head; + struct mutex lock; +}; + +static struct dma_buf_list db_list; + static int dma_buf_release(struct inode *inode, struct file *file) { struct dma_buf *dmabuf; @@ -42,6 +51,11 @@ static int dma_buf_release(struct inode *inode, struct file *file) BUG_ON(dmabuf->vmapping_counter); dmabuf->ops->release(dmabuf); + + mutex_lock(&db_list.lock); + list_del(&dmabuf->list_node); + mutex_unlock(&db_list.lock); + kfree(dmabuf); return 0; } @@ -125,6 +139,10 @@ struct dma_buf *dma_buf_export_named(void *priv, const struct dma_buf_ops *ops, mutex_init(&dmabuf->lock); INIT_LIST_HEAD(&dmabuf->attachments); + mutex_lock(&db_list.lock); + list_add(&dmabuf->list_node, &db_list.head); + mutex_unlock(&db_list.lock); + return dmabuf; } EXPORT_SYMBOL_GPL(dma_buf_export_named); @@ -551,3 +569,144 @@ void dma_buf_vunmap(struct dma_buf *dmabuf, void *vaddr) mutex_unlock(&dmabuf->lock); } EXPORT_SYMBOL_GPL(dma_buf_vunmap); + +#ifdef CONFIG_DEBUG_FS +static int dma_buf_describe(struct seq_file *s) +{ + int ret; + struct dma_buf *buf_obj; + struct dma_buf_attachment *attach_obj; + int count = 0, attach_count; + size_t size = 0; + + ret = mutex_lock_interruptible(&db_list.lock); + + if (ret) + return ret; + + seq_printf(s, "\nDma-buf Objects:\n"); + seq_printf(s, "\texp_name\tsize\tflags\tmode\tcount\n"); + + list_for_each_entry(buf_obj, &db_list.head, list_node) { + ret = mutex_lock_interruptible(&buf_obj->lock); + + if (ret) { + seq_printf(s, + "\tERROR locking buffer object: skipping\n"); + goto skip_buffer; + } + + seq_printf(s, "\t"); + + seq_printf(s, "\t%s\t%08zu\t%08x\t%08x\t%08d\n", + buf_obj->exp_name, buf_obj->size, + buf_obj->file->f_flags, buf_obj->file->f_mode, + buf_obj->file->f_count.counter); + + seq_printf(s, "\t\tAttached Devices:\n"); + attach_count = 0; + + list_for_each_entry(attach_obj, &buf_obj->attachments, node) { + seq_printf(s, "\t\t"); + + seq_printf(s, "%s\n", attach_obj->dev->init_name); + attach_count++; + } + + seq_printf(s, "\n\t\tTotal %d devices attached\n", + attach_count); + + count++; + size += buf_obj->size; +skip_buffer: + mutex_unlock(&buf_obj->lock); + } + + seq_printf(s, "\nTotal %d objects, %zu bytes\n", count, size); + + mutex_unlock(&db_list.lock); + return 0; +} + +static int dma_buf_show(struct seq_file *s, void *unused) +{ + void (*func)(struct seq_file *) = s->private; + func(s); + return 0; +} + +static int dma_buf_debug_open(struct inode *inode, struct file *file) +{ + return single_open(file, dma_buf_show, inode->i_private); +} + +static const struct file_operations dma_buf_debug_fops = { + .open = dma_buf_debug_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static struct dentry *dma_buf_debugfs_dir; + +static int dma_buf_init_debugfs(void) +{ + int err = 0; + dma_buf_debugfs_dir = debugfs_create_dir("dma_buf", NULL); + if (IS_ERR(dma_buf_debugfs_dir)) { + err = PTR_ERR(dma_buf_debugfs_dir); + dma_buf_debugfs_dir = NULL; + return err; + } + + err = dma_buf_debugfs_create_file("bufinfo", dma_buf_describe); + + if (err) + pr_debug("dma_buf: debugfs: failed to create node bufinfo\n"); + + return err; +} + +static void dma_buf_uninit_debugfs(void) +{ + if (dma_buf_debugfs_dir) + debugfs_remove_recursive(dma_buf_debugfs_dir); +} + +int dma_buf_debugfs_create_file(const char *name, + int (*write)(struct seq_file *)) +{ + struct dentry *d; + + d = debugfs_create_file(name, S_IRUGO, dma_buf_debugfs_dir, + write, &dma_buf_debug_fops); + + if (IS_ERR(d)) + return PTR_ERR(d); + + return 0; +} +#else +static inline int dma_buf_init_debugfs(void) +{ + return 0; +} +static inline void dma_buf_uninit_debugfs(void) +{ +} +#endif + +static int __init dma_buf_init(void) +{ + mutex_init(&db_list.lock); + INIT_LIST_HEAD(&db_list.head); + dma_buf_init_debugfs(); + return 0; +} +subsys_initcall(dma_buf_init); + +static void __exit dma_buf_deinit(void) +{ + dma_buf_uninit_debugfs(); +} +__exitcall(dma_buf_deinit); diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h index 6f55c04..dfac5ed 100644 --- a/include/linux/dma-buf.h +++ b/include/linux/dma-buf.h @@ -113,6 +113,7 @@ struct dma_buf_ops { * @attachments: list of dma_buf_attachment that denotes all devices attached. * @ops: dma_buf_ops associated with this buffer object. * @exp_name: name of the exporter; useful for debugging. + * @list_node: node for dma_buf accounting and debugging. * @priv: exporter specific private data for this buffer object. */ struct dma_buf { @@ -125,6 +126,7 @@ struct dma_buf { unsigned vmapping_counter; void *vmap_ptr; const char *exp_name; + struct list_head list_node; void *priv; }; @@ -192,5 +194,6 @@ int dma_buf_mmap(struct dma_buf *, struct vm_area_struct *, unsigned long); void *dma_buf_vmap(struct dma_buf *); void dma_buf_vunmap(struct dma_buf *, void *vaddr); - +int dma_buf_debugfs_create_file(const char *name, + int (*write)(struct seq_file *)); #endif /* __DMA_BUF_H__ */