Skip to contentSkip to conversation

drm/amdgpu: Use DIV_ROUND_UP_ULL instead of DIV_ROUND_UP

PATCH In review He Ying 2 participants 3 messages Jun 10, 2021

Subsystems (2)
lore
Share & tools
lore

He Ying

author
#0 lore raw

PATCH 1/1 drm/amdgpu: Use DIV_ROUND_UP_ULL instead of DIV_ROUND_UP

When compiling the kernel for MIPS with CONFIG_DRM_AMDGPU = y, errors are encountered as follows:

drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.o: In function `amdgpu_vram_mgr_new':
amdgpu_vram_mgr.c:(.text+0x740): undefined reference to `__udivdi3'

Making a 64 bit division by a/b (a is uint64_t) is not supported by default in linux kernel space. Instead, using do_div is OK for this situation. For this problem, using DIV_ROUND_UP_ULL instead of DIV_ROUND_UP is better.

Fixes 6a7f76e70fac ("drm/amdgpu: add VRAM manager v2")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +1 -1
index 9a6df02477ce..436ec246a7da 100644
@@ -407,7 +407,7 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man,
 #endif
 		pages_per_node = max_t(uint32_t, pages_per_node,
 				       tbo->page_alignment);
-		num_nodes = DIV_ROUND_UP(PFN_UP(mem_bytes), pages_per_node);
+		num_nodes = DIV_ROUND_UP_ULL(PFN_UP(mem_bytes), pages_per_node);
 	}
 
 	node = kvmalloc(struct_size(node, mm_nodes, num_nodes),
Signature · 1 line
2.17.1
maintainer
#1 lore raw

Am 10.06.21 um 10:20 schrieb He Ying:

Quoted 9 lines

When compiling the kernel for MIPS with CONFIG_DRM_AMDGPU = y, errors are encountered as follows:

drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.o: In function `amdgpu_vram_mgr_new':
amdgpu_vram_mgr.c:(.text+0x740): undefined reference to `__udivdi3'

Making a 64 bit division by a/b (a is uint64_t) is not supported by default in linux kernel space. Instead, using do_div is OK for this situation. For this problem, using DIV_ROUND_UP_ULL instead of DIV_ROUND_UP is better.

Already fixed by this patch in drm-next:

commit 691cf8cd7a531dbfcc29d09a23c509a86fd9b24f
Author: Dave Airlie <[email protected]>
Date:   Thu Jun 10 12:59:00 2021 +1000

    drm/amdgpu: use correct rounding macro for 64-bit

    This fixes 32-bit arm build due to lack of 64-bit divides.

Regards,
Christian.

Quoted 13 lines
Fixes 6a7f76e70fac ("drm/amdgpu: add VRAM manager v2")
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +0 -0
index 9a6df02477ce..436ec246a7da 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man, · line 413

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +1 -1
@@ -407,7 +407,7 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man,
  #endif
  		pages_per_node = max_t(uint32_t, pages_per_node,
  				       tbo->page_alignment);
-		num_nodes = DIV_ROUND_UP(PFN_UP(mem_bytes), pages_per_node);
+		num_nodes = DIV_ROUND_UP_ULL(PFN_UP(mem_bytes), pages_per_node);
  	}
 
  	node = kvmalloc(struct_size(node, mm_nodes, num_nodes),

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

author
#2 lore raw

Hello,

Quoted 15 lines · Christian König

Am 10.06.21 um 10:20 schrieb He Ying:

Quoted 9 lines

When compiling the kernel for MIPS with CONFIG_DRM_AMDGPU = y, errors are encountered as follows:

drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.o: In function `amdgpu_vram_mgr_new':
amdgpu_vram_mgr.c:(.text+0x740): undefined reference to `__udivdi3'

Making a 64 bit division by a/b (a is uint64_t) is not supported by default in linux kernel space. Instead, using do_div is OK for this situation. For this problem, using DIV_ROUND_UP_ULL instead of DIV_ROUND_UP is better.

Already fixed by this patch in drm-next:

Quoted 7 lines

commit 691cf8cd7a531dbfcc29d09a23c509a86fd9b24f
Author: Dave Airlie <[email protected]>
Date:   Thu Jun 10 12:59:00 2021 +1000

    drm/amdgpu: use correct rounding macro for 64-bit

    This fixes 32-bit arm build due to lack of 64-bit divides.

OK. Sigh.

Before sending my patch, I searched patches in https://lore.kernel.org/lkml/

but I didn't find this patch. How can I find whether my patch is duplicated

before sending it? Any suggestions?

Thanks.

Quoted 28 lines

Regards,
Christian.

Quoted 21 lines
Fixes 6a7f76e70fac ("drm/amdgpu: add VRAM manager v2")

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +1 -1
index 9a6df02477ce..436ec246a7da 100644
@@ -407,7 +407,7 @@ static int amdgpu_vram_mgr_new(struct 
 ttm_resource_manager *man,
   #endif
           pages_per_node = max_t(uint32_t, pages_per_node,
                          tbo->page_alignment);
-        num_nodes = DIV_ROUND_UP(PFN_UP(mem_bytes), pages_per_node);
+        num_nodes = DIV_ROUND_UP_ULL(PFN_UP(mem_bytes), 
 pages_per_node);
       }
Quoted 1 line

        node = kvmalloc(struct_size(node, mm_nodes, num_nodes),

.