Skip to contentSkip to conversation

drm/amdgpu: New method to check block continuous

PATCH In review xinhui pan 2 participants 4 messages Nov 27, 2022 – Nov 29, 2022

Subsystems (2)
lore
Share & tools
lore

xinhui pan

author
#0 lore raw

PATCH 1/1 drm/amdgpu: New method to check block continuous

Blocks are not guarnteed to be in ascending order.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 21 ++++++++------------
 1 file changed, 8 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +8 -13
index 27159f1d112e..17175d284869 100644
@@ -59,22 +59,17 @@ amdgpu_vram_mgr_first_block(struct list_head *list)
 static inline bool amdgpu_is_vram_mgr_blocks_contiguous(struct list_head *head)
 {
 	struct drm_buddy_block *block;
-	u64 start, size;
+	u64 start = LONG_MAX, end = 0, size = 0;
 
-	block = amdgpu_vram_mgr_first_block(head);
-	if (!block)
-		return false;
+	list_for_each_entry(block, head, link) {
+		u64 bstart = amdgpu_vram_mgr_block_start(block);
+		u64 bsize = amdgpu_vram_mgr_block_size(block);
 
-	while (head != block->link.next) {
-		start = amdgpu_vram_mgr_block_start(block);
-		size = amdgpu_vram_mgr_block_size(block);
-
-		block = list_entry(block->link.next, struct drm_buddy_block, link);
-		if (start + size != amdgpu_vram_mgr_block_start(block))
-			return false;
+		start = min(bstart, start);
+		end = max(bstart + bsize, end);
+		size += bsize;
 	}
-
-	return true;
+	return end == start + size;
 }
 
 
Signature · 1 line
2.34.1
#1 lore raw

Am 27.11.22 um 06:39 schrieb xinhui pan:

Quoted 1 line

Blocks are not guarnteed to be in ascending order.

Well certainly a NAK. Blocks are required to be in ascending order to be contiguous.

Regards,
Christian.

Quoted 41 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 21 ++++++++------------
  1 file changed, 8 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +8 -13
index 27159f1d112e..17175d284869 100644
@@ -59,22 +59,17 @@ amdgpu_vram_mgr_first_block(struct list_head *list)
  static inline bool amdgpu_is_vram_mgr_blocks_contiguous(struct list_head *head)
  {
  	struct drm_buddy_block *block;
-	u64 start, size;
+	u64 start = LONG_MAX, end = 0, size = 0;
 
-	block = amdgpu_vram_mgr_first_block(head);
-	if (!block)
-		return false;
+	list_for_each_entry(block, head, link) {
+		u64 bstart = amdgpu_vram_mgr_block_start(block);
+		u64 bsize = amdgpu_vram_mgr_block_size(block);
 
-	while (head != block->link.next) {
-		start = amdgpu_vram_mgr_block_start(block);
-		size = amdgpu_vram_mgr_block_size(block);
-
-		block = list_entry(block->link.next, struct drm_buddy_block, link);
-		if (start + size != amdgpu_vram_mgr_block_start(block))
-			return false;
+		start = min(bstart, start);
+		end = max(bstart + bsize, end);
+		size += bsize;
  	}
-
-	return true;
+	return end == start + size;
  }
 
 
#2 lore raw

[AMD Official Use Only - General]

What I am thinking is that
Hi Chris,

For continuous memory allocation, of course the blocks are in ascending order.

For non-continuous memory allocation, the allocated memory might be continuous while the blocks are not in ascending order.

Anyway, could we just re-sort these blocks in ascending order if memory is indeed continuous?

thanks
xinhui

________________________________________
发件人: Christian König <[email protected]> 发送时间: 2022年11月29日 1:11
收件人: Pan, Xinhui; [email protected]
抄送: Deucher, Alexander
主题: Re: [PATCH] drm/amdgpu: New method to check block continuous

Am 27.11.22 um 06:39 schrieb xinhui pan:

Quoted 1 line

Blocks are not guarnteed to be in ascending order.

Well certainly a NAK. Blocks are required to be in ascending order to be contiguous.

Regards,
Christian.

Quoted 41 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 21 ++++++++------------
  1 file changed, 8 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +8 -13
index 27159f1d112e..17175d284869 100644
@@ -59,22 +59,17 @@ amdgpu_vram_mgr_first_block(struct list_head *list)
  static inline bool amdgpu_is_vram_mgr_blocks_contiguous(struct list_head *head)
  {
      struct drm_buddy_block *block;
-     u64 start, size;
+     u64 start = LONG_MAX, end = 0, size = 0;
 
-     block = amdgpu_vram_mgr_first_block(head);
-     if (!block)
-             return false;
+     list_for_each_entry(block, head, link) {
+             u64 bstart = amdgpu_vram_mgr_block_start(block);
+             u64 bsize = amdgpu_vram_mgr_block_size(block);
 
-     while (head != block->link.next) {
-             start = amdgpu_vram_mgr_block_start(block);
-             size = amdgpu_vram_mgr_block_size(block);
-
-             block = list_entry(block->link.next, struct drm_buddy_block, link);
-             if (start + size != amdgpu_vram_mgr_block_start(block))
-                     return false;
+             start = min(bstart, start);
+             end = max(bstart + bsize, end);
+             size += bsize;
      }
-
-     return true;
+     return end == start + size;
  }
 
 
#3 lore raw

Hi Xinhui,

Am 29.11.22 um 03:11 schrieb Pan, Xinhui:

Quoted 10 lines

[AMD Official Use Only - General]

What I am thinking is that
Hi Chris,

For continuous memory allocation, of course the blocks are in ascending order.

For non-continuous memory allocation, the allocated memory might be continuous while the blocks are not in ascending order.

Anyway, could we just re-sort these blocks in ascending order if memory is indeed continuous?

Well that the blocks are in continuous order by coincident is just extremely unlikely.

So this doesn't make much sense.

Regards,
Christian.

Quoted 59 lines

thanks
xinhui

________________________________________
发件人: Christian König <[email protected]> 发送时间: 2022年11月29日 1:11
收件人: Pan, Xinhui; [email protected]
抄送: Deucher, Alexander
主题: Re: [PATCH] drm/amdgpu: New method to check block continuous

Am 27.11.22 um 06:39 schrieb xinhui pan:

Quoted 1 line

Blocks are not guarnteed to be in ascending order.

Well certainly a NAK. Blocks are required to be in ascending order to be contiguous.

Regards,
Christian.

Quoted 40 lines
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 21 ++++++++------------
   1 file changed, 8 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +8 -13
index 27159f1d112e..17175d284869 100644
@@ -59,22 +59,17 @@ amdgpu_vram_mgr_first_block(struct list_head *list)
   static inline bool amdgpu_is_vram_mgr_blocks_contiguous(struct list_head *head)
   {
       struct drm_buddy_block *block;
-     u64 start, size;
+     u64 start = LONG_MAX, end = 0, size = 0;
 
-     block = amdgpu_vram_mgr_first_block(head);
-     if (!block)
-             return false;
+     list_for_each_entry(block, head, link) {
+             u64 bstart = amdgpu_vram_mgr_block_start(block);
+             u64 bsize = amdgpu_vram_mgr_block_size(block);
 
-     while (head != block->link.next) {
-             start = amdgpu_vram_mgr_block_start(block);
-             size = amdgpu_vram_mgr_block_size(block);
-
-             block = list_entry(block->link.next, struct drm_buddy_block, link);
-             if (start + size != amdgpu_vram_mgr_block_start(block))
-                     return false;
+             start = min(bstart, start);
+             end = max(bstart + bsize, end);
+             size += bsize;
       }
-
-     return true;
+     return end == start + size;
   }