Re: [PATCH] drm/mm: add ability to dump mm lists via debugfs (v2)

2009-08-21 Thread Thomas Hellström
Dave Airlie wrote:
> 2009/8/21 Thomas Hellström :
>   
>> Dave Airlie wrote:
>> 
>>> From: Dave Airlie 
>>>
>>> This adds code to the drm_mm to talk to debugfs, and adds
>>> support to radeon to add the VRAM and GTT mm lists to debugfs.
>>>
>>> changes since v1:
>>> don't bother with free list just add used/free to main list
>>> add totals in pages
>>>
>>> Signed-off-by: Dave Airlie 
>>> ---
>>>  drivers/gpu/drm/drm_mm.c|   25 ++
>>>  drivers/gpu/drm/radeon/radeon_ttm.c |   39
>>> +++
>>>  include/drm/drm_mm.h|4 +++
>>>  3 files changed, 68 insertions(+), 0 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/drm_mm.c b/drivers/gpu/drm/drm_mm.c
>>> index 3e47869..a454e55 100644
>>> --- a/drivers/gpu/drm/drm_mm.c
>>> +++ b/drivers/gpu/drm/drm_mm.c
>>> @@ -44,6 +44,7 @@
>>>  #include "drmP.h"
>>>  #include "drm_mm.h"
>>>  #include 
>>> +#include 
>>>   #define MM_UNUSED_TARGET 4
>>>  @@ -370,3 +371,27 @@ void drm_mm_takedown(struct drm_mm * mm)
>>>BUG_ON(mm->num_unused != 0);
>>>  }
>>>  EXPORT_SYMBOL(drm_mm_takedown);
>>> +
>>> +#if defined(CONFIG_DEBUG_FS)
>>> +int drm_mm_dump_table(struct seq_file *m, void *data)
>>> +{
>>> +   struct drm_info_node *node = (struct drm_info_node *)m->private;
>>> +   struct drm_mm *mm = (struct drm_mm *)node->info_ent->data;
>>> +   struct drm_mm_node *entry;
>>> +   int total_used = 0, total_free = 0, total = 0;
>>> +   spin_lock(&mm->unused_lock);
>>>
>>>   
>> This is not correct. The mm::unused_lock is there only to protect the list
>> of cached drm_mm_node allocations that we
>> use instead of kmalloc() when atomic.
>>
>> Instead the lock the user uses to protect the mm:s must be taken. In the TTM
>> case IIRC its the bo_glob::lru_lock.
>>
>> Is it safe to use seq_printf() from within a spinlocked region?
>>
>> 
>
> Good point, this was one of those quick hacks to have a look at fragmentation
> so I sorta guessed at the lock,
>
> I'd probably be best not locking anything, but I'll try and add a
> driver layer before
> drm_mm to do the correct locking, though as its debugging info even 
> inconsistent
> is better than none.
>   
Yes, but you might end up traversing the list in the middle of a list 
pointer modification, which is bad.

> I'll fix it up next week and send v3, thanks again.
> Dave.
>   

/Thomas




--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
--
___
Dri-devel mailing list
Dri-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dri-devel


Re: [PATCH] drm/mm: add ability to dump mm lists via debugfs (v2)

2009-08-21 Thread Dave Airlie
2009/8/21 Thomas Hellström :
> Dave Airlie wrote:
>>
>> From: Dave Airlie 
>>
>> This adds code to the drm_mm to talk to debugfs, and adds
>> support to radeon to add the VRAM and GTT mm lists to debugfs.
>>
>> changes since v1:
>> don't bother with free list just add used/free to main list
>> add totals in pages
>>
>> Signed-off-by: Dave Airlie 
>> ---
>>  drivers/gpu/drm/drm_mm.c            |   25 ++
>>  drivers/gpu/drm/radeon/radeon_ttm.c |   39
>> +++
>>  include/drm/drm_mm.h                |    4 +++
>>  3 files changed, 68 insertions(+), 0 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/drm_mm.c b/drivers/gpu/drm/drm_mm.c
>> index 3e47869..a454e55 100644
>> --- a/drivers/gpu/drm/drm_mm.c
>> +++ b/drivers/gpu/drm/drm_mm.c
>> @@ -44,6 +44,7 @@
>>  #include "drmP.h"
>>  #include "drm_mm.h"
>>  #include 
>> +#include 
>>   #define MM_UNUSED_TARGET 4
>>  @@ -370,3 +371,27 @@ void drm_mm_takedown(struct drm_mm * mm)
>>        BUG_ON(mm->num_unused != 0);
>>  }
>>  EXPORT_SYMBOL(drm_mm_takedown);
>> +
>> +#if defined(CONFIG_DEBUG_FS)
>> +int drm_mm_dump_table(struct seq_file *m, void *data)
>> +{
>> +       struct drm_info_node *node = (struct drm_info_node *)m->private;
>> +       struct drm_mm *mm = (struct drm_mm *)node->info_ent->data;
>> +       struct drm_mm_node *entry;
>> +       int total_used = 0, total_free = 0, total = 0;
>> +       spin_lock(&mm->unused_lock);
>>
>
> This is not correct. The mm::unused_lock is there only to protect the list
> of cached drm_mm_node allocations that we
> use instead of kmalloc() when atomic.
>
> Instead the lock the user uses to protect the mm:s must be taken. In the TTM
> case IIRC its the bo_glob::lru_lock.
>
> Is it safe to use seq_printf() from within a spinlocked region?
>

Good point, this was one of those quick hacks to have a look at fragmentation
so I sorta guessed at the lock,

I'd probably be best not locking anything, but I'll try and add a
driver layer before
drm_mm to do the correct locking, though as its debugging info even inconsistent
is better than none.

I'll fix it up next week and send v3, thanks again.
Dave.

--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
--
___
Dri-devel mailing list
Dri-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dri-devel


Re: [PATCH] drm/mm: add ability to dump mm lists via debugfs (v2)

2009-08-20 Thread Thomas Hellström
Dave Airlie wrote:
> From: Dave Airlie 
>
> This adds code to the drm_mm to talk to debugfs, and adds
> support to radeon to add the VRAM and GTT mm lists to debugfs.
>
> changes since v1:
> don't bother with free list just add used/free to main list
> add totals in pages
>
> Signed-off-by: Dave Airlie 
> ---
>  drivers/gpu/drm/drm_mm.c|   25 ++
>  drivers/gpu/drm/radeon/radeon_ttm.c |   39 
> +++
>  include/drm/drm_mm.h|4 +++
>  3 files changed, 68 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_mm.c b/drivers/gpu/drm/drm_mm.c
> index 3e47869..a454e55 100644
> --- a/drivers/gpu/drm/drm_mm.c
> +++ b/drivers/gpu/drm/drm_mm.c
> @@ -44,6 +44,7 @@
>  #include "drmP.h"
>  #include "drm_mm.h"
>  #include 
> +#include 
>  
>  #define MM_UNUSED_TARGET 4
>  
> @@ -370,3 +371,27 @@ void drm_mm_takedown(struct drm_mm * mm)
>   BUG_ON(mm->num_unused != 0);
>  }
>  EXPORT_SYMBOL(drm_mm_takedown);
> +
> +#if defined(CONFIG_DEBUG_FS)
> +int drm_mm_dump_table(struct seq_file *m, void *data)
> +{
> + struct drm_info_node *node = (struct drm_info_node *)m->private;
> + struct drm_mm *mm = (struct drm_mm *)node->info_ent->data;
> + struct drm_mm_node *entry;
> + int total_used = 0, total_free = 0, total = 0;
> + spin_lock(&mm->unused_lock);
>   

This is not correct. The mm::unused_lock is there only to protect the 
list of cached drm_mm_node allocations that we
use instead of kmalloc() when atomic.

Instead the lock the user uses to protect the mm:s must be taken. In the 
TTM case IIRC its the bo_glob::lru_lock.

Is it safe to use seq_printf() from within a spinlocked region?

Otherwise looks nice.
/Thomas




--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
--
___
Dri-devel mailing list
Dri-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dri-devel


[PATCH] drm/mm: add ability to dump mm lists via debugfs (v2)

2009-08-20 Thread Dave Airlie
From: Dave Airlie 

This adds code to the drm_mm to talk to debugfs, and adds
support to radeon to add the VRAM and GTT mm lists to debugfs.

changes since v1:
don't bother with free list just add used/free to main list
add totals in pages

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/drm_mm.c|   25 ++
 drivers/gpu/drm/radeon/radeon_ttm.c |   39 +++
 include/drm/drm_mm.h|4 +++
 3 files changed, 68 insertions(+), 0 deletions(-)

diff --git a/drivers/gpu/drm/drm_mm.c b/drivers/gpu/drm/drm_mm.c
index 3e47869..a454e55 100644
--- a/drivers/gpu/drm/drm_mm.c
+++ b/drivers/gpu/drm/drm_mm.c
@@ -44,6 +44,7 @@
 #include "drmP.h"
 #include "drm_mm.h"
 #include 
+#include 
 
 #define MM_UNUSED_TARGET 4
 
@@ -370,3 +371,27 @@ void drm_mm_takedown(struct drm_mm * mm)
BUG_ON(mm->num_unused != 0);
 }
 EXPORT_SYMBOL(drm_mm_takedown);
+
+#if defined(CONFIG_DEBUG_FS)
+int drm_mm_dump_table(struct seq_file *m, void *data)
+{
+   struct drm_info_node *node = (struct drm_info_node *)m->private;
+   struct drm_mm *mm = (struct drm_mm *)node->info_ent->data;
+   struct drm_mm_node *entry;
+   int total_used = 0, total_free = 0, total = 0;
+   spin_lock(&mm->unused_lock);
+   
+   list_for_each_entry(entry, &mm->ml_entry, ml_entry) {
+   seq_printf(m, "0x%08lx-0x%08lx: 0x%08lx: %s\n", entry->start, 
entry->start+entry->size, entry->size, entry->free ? "free" : "used");
+   total += entry->size;
+   if (entry->free)
+   total_free += entry->size;
+   else
+   total_used += entry->size;
+   }
+   seq_printf(m,"total: %d, used %d free %d\n", total, total_free, 
total_used);
+   spin_unlock(&mm->unused_lock);
+   return 0;
+}
+EXPORT_SYMBOL(drm_mm_dump_table);
+#endif
diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c 
b/drivers/gpu/drm/radeon/radeon_ttm.c
index 0a85e7b..aaa1ebd 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -40,6 +40,8 @@
 
 #define DRM_FILE_PAGE_OFFSET (0x1ULL >> PAGE_SHIFT)
 
+static int radeon_ttm_debugfs_init(struct radeon_device *rdev);
+
 static struct radeon_device *radeon_get_rdev(struct ttm_bo_device *bdev)
 {
struct radeon_mman *mman;
@@ -504,6 +506,12 @@ int radeon_ttm_init(struct radeon_device *rdev)
if (unlikely(rdev->mman.bdev.dev_mapping == NULL)) {
rdev->mman.bdev.dev_mapping = rdev->ddev->dev_mapping;
}
+
+   r = radeon_ttm_debugfs_init(rdev);
+   if (r) {
+   DRM_ERROR("Failed to init debugfs\n");
+   return r;
+   }
return 0;
 }
 
@@ -678,3 +686,34 @@ struct ttm_backend *radeon_ttm_backend_create(struct 
radeon_device *rdev)
gtt->bound = false;
return >t->backend;
 }
+
+#define RADEON_DEBUGFS_MEM_TYPES 2
+
+static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES];
+static char radeon_mem_types_names[RADEON_DEBUGFS_MEM_TYPES][32];
+
+static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
+{
+#if defined(CONFIG_DEBUG_FS)
+   unsigned i;
+
+
+   for (i = 0; i < RADEON_DEBUGFS_MEM_TYPES; i++) {
+   if (i == 0)
+   sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
+   else
+   sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
+   radeon_mem_types_list[i].name = radeon_mem_types_names[i];
+   radeon_mem_types_list[i].show = &drm_mm_dump_table;
+   radeon_mem_types_list[i].driver_features = 0;
+   if (i == 0)
+   radeon_mem_types_list[i].data = 
&rdev->mman.bdev.man[TTM_PL_VRAM].manager;
+   else
+   radeon_mem_types_list[i].data = 
&rdev->mman.bdev.man[TTM_PL_TT].manager;
+
+   }
+   return radeon_debugfs_add_files(rdev, radeon_mem_types_list, 
RADEON_DEBUGFS_MEM_TYPES);
+   
+#endif
+   return 0;
+}
diff --git a/include/drm/drm_mm.h b/include/drm/drm_mm.h
index f833207..7055014 100644
--- a/include/drm/drm_mm.h
+++ b/include/drm/drm_mm.h
@@ -96,4 +96,8 @@ static inline struct drm_mm *drm_get_mm(struct drm_mm_node 
*block)
return block->mm;
 }
 
+#ifdef CONFIG_DEBUG_FS
+int drm_mm_dump_table(struct seq_file *m, void *data);
+#endif
+
 #endif
-- 
1.6.4


--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
--
___
Dri-devel mailing list
Dri-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dri-devel