Re: [PATCH] dma-buf: Add debugfs support

2012-12-19 Thread Dave Airlie
On Thu, Dec 20, 2012 at 11:26 AM, Dave Airlie  wrote:
> On Fri, Dec 14, 2012 at 7:36 PM,   wrote:
>> From: Sumit Semwal 
>>
>> Add debugfs support to make it easier to print debug information
>> about the dma-buf buffers.
>>

I've attached two patches that make it work on my system, and fix the warnings,

I've used it to debug some leaks I was seeing, feel free to squash
these patches into the original patch.

Dave.


0001-dma_buf-fix-debugfs-init.patch
Description: Binary data


0002-dma-buf-fix-warning-in-seq_printf.patch
Description: Binary data


Re: [PATCH] dma-buf: Add debugfs support

2012-12-19 Thread Dave Airlie
On Fri, Dec 14, 2012 at 7:36 PM,   wrote:
> From: Sumit Semwal 
>
> Add debugfs support to make it easier to print debug information
> about the dma-buf buffers.
>

I like thie idea,

/home/airlied/devel/kernel/drm-2.6/drivers/base/dma-buf.c: In function
‘dma_buf_describe’:
/home/airlied/devel/kernel/drm-2.6/drivers/base/dma-buf.c:563:5:
warning: format ‘%d’ expects argument of type ‘int’, but argument 6
has type ‘long int’ [-Wformat]
/home/airlied/devel/kernel/drm-2.6/drivers/base/dma-buf.c: At top level:
/home/airlied/devel/kernel/drm-2.6/drivers/base/dma-buf.c:528:123:
warning: ‘dma_buf_init’ defined but not used [-Wunused-function]

not sure my compiler does though.

Dave.
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] dma-buf: Add debugfs support

2012-12-17 Thread Sumit Semwal
On 14 December 2012 16:04, Daniel Vetter  wrote:
>
> Missed one ...
>
> On Fri, Dec 14, 2012 at 10:36 AM,   wrote:
> > +   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++;
> > +   }
>
> You need to hold dmabuf->lock while walking the attachment list.
> -Daniel


Thanks Daniel!

Will update in next version.
>
> --
> Daniel Vetter
> Software Engineer, Intel Corporation
> +41 (0) 79 365 57 48 - http://blog.ffwll.ch



Best regards,

Sumit Semwal
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] dma-buf: Add debugfs support

2012-12-14 Thread Daniel Vetter
Missed one ...

On Fri, Dec 14, 2012 at 10:36 AM,   wrote:
> +   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++;
> +   }

You need to hold dmabuf->lock while walking the attachment list.
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] dma-buf: Add debugfs support

2012-12-14 Thread Daniel Vetter
On Fri, Dec 14, 2012 at 10:36 AM,   wrote:
> From: Sumit Semwal 
>
> Add debugfs support to make it easier to print debug information
> about the dma-buf buffers.
>
> Signed-off-by: Sumit Semwal 

Looks line, only nitpick is that we have no idea who exported a given
buffer. So what about adding a new dma_buf_export_named which takes a
char * to identify the exporter, and then add a bit of cpp magic like
this:

#define dma_buf_export(args) dma_buf_export_named(args, stringify(__FILE))

At least for drm drivers using the prime helpers this should add the
file of the exporting driver, so would be good enough to identify the
exporter. Or we could add a dma_buf_export_dev which has a struct
device * as additional argument ... Otoh that wouldn't really work for
exporting dma_bufs from ION, so maybe a const char * is better.
-Daniel

> ---
>  drivers/base/dma-buf.c  |  149 
> +++
>  include/linux/dma-buf.h |6 +-
>  2 files changed, 154 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/base/dma-buf.c b/drivers/base/dma-buf.c
> index a3f79c4..49fcf0f 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;
> @@ -40,6 +49,11 @@ static int dma_buf_release(struct inode *inode, struct 
> file *file)
> dmabuf = file->private_data;
>
> dmabuf->ops->release(dmabuf);
> +
> +   mutex_lock(&db_list.lock);
> +   list_del(&dmabuf->list_node);
> +   mutex_unlock(&db_list.lock);
> +
> kfree(dmabuf);
> return 0;
>  }
> @@ -120,6 +134,10 @@ struct dma_buf *dma_buf_export(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);
> @@ -505,3 +523,134 @@ void dma_buf_vunmap(struct dma_buf *dmabuf, void *vaddr)
> dmabuf->ops->vunmap(dmabuf, vaddr);
>  }
>  EXPORT_SYMBOL_GPL(dma_buf_vunmap);
> +
> +static int dma_buf_init_debugfs(void);
> +static void dma_buf_uninit_debugfs(void);
> +
> +static void __init dma_buf_init(void)
> +{
> +   mutex_init(&db_list.lock);
> +   INIT_LIST_HEAD(&db_list.head);
> +   dma_buf_init_debugfs();
> +}
> +
> +static void __exit dma_buf_deinit(void)
> +{
> +   dma_buf_uninit_debugfs();
> +}
> +
> +#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, "\tsize\tflags\tmode\tcount\n");
> +
> +   list_for_each_entry(buf_obj, &db_list.head, list_node) {
> +   seq_printf(s, "\t");
> +
> +   seq_printf(s, "%08zu\t%08x\t%08x\t%08d\n",
> +   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;
> +   }
> +
> +   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 stru