Skip to contentSkip to conversation

drm/amd/display: avoid 64-bit division

PATCH In review Arnd Bergmann 4 participants 6 messages Jul 8, 2019 – Jul 9, 2019 2 messages not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amd/display: avoid 64-bit division

On 32-bit architectures, dividing a 64-bit integer in the kernel leads to a link error:

ERROR: "__udivdi3" [drivers/gpu/drm/amd/amdgpu/amdgpu.ko] undefined!
ERROR: "__divdi3" [drivers/gpu/drm/amd/amdgpu/amdgpu.ko] undefined!

Change the two recently introduced instances to a multiply+shift operation that is also much cheaper on 32-bit architectures. We can do that here, since both of them are really 32-bit numbers that change a few percent.

Fixes bedbbe6af4be ("drm/amd/display: Move link functions from dc to dc_link")
Fixes f18bc4e53ad6 ("drm/amd/display: update calculated bounding box logic for NV")
---
 drivers/gpu/drm/amd/display/dc/core/dc_link.c         | 4 ++--
 drivers/gpu/drm/amd/display/dc/dcn20/dcn20_resource.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/display/dc/core/dc_link.c +2 -2
index c17db5c144aa..8dbf759eba45 100644
@@ -3072,8 +3072,8 @@ uint32_t dc_link_bandwidth_kbps(
 		 * but the difference is minimal and is in a safe direction,
 		 * which all works well around potential ambiguity of DP 1.4a spec.
 		 */
-		long long fec_link_bw_kbps = link_bw_kbps * 970LL;
-		link_bw_kbps = (uint32_t)(fec_link_bw_kbps / 1000LL);
+		link_bw_kbps = mul_u64_u32_shr(BIT_ULL(32) * 970LL / 1000,
+					       link_bw_kbps, 32);
 	}
 #endif
 
drivers/gpu/drm/amd/display/dc/dcn20/dcn20_resource.c +1 -1
index b35327bafbc5..70ac8a95d2db 100644
@@ -2657,7 +2657,7 @@ static void update_bounding_box(struct dc *dc, struct _vcs_dpi_soc_bounding_box_
 		calculated_states[i].dram_speed_mts = uclk_states[i] * 16 / 1000;
 
 		// FCLK:UCLK ratio is 1.08
-		min_fclk_required_by_uclk = ((unsigned long long)uclk_states[i]) * 1080 / 1000000;
+		min_fclk_required_by_uclk = mul_u64_u32_shr(BIT_ULL(32) * 1080 / 1000000, uclk_states[i], 32);
 
 		calculated_states[i].fabricclk_mhz = (min_fclk_required_by_uclk < min_dcfclk) ?
 				min_dcfclk : min_fclk_required_by_uclk;
Signature · 6 lines
2.20.0

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

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw
Quoted 39 lines · Arnd Bergmann

On 32-bit architectures, dividing a 64-bit integer in the kernel leads to a link error:

ERROR: "__udivdi3" [drivers/gpu/drm/amd/amdgpu/amdgpu.ko] undefined!
ERROR: "__divdi3" [drivers/gpu/drm/amd/amdgpu/amdgpu.ko] undefined!

Change the two recently introduced instances to a multiply+shift operation that is also much cheaper on 32-bit architectures. We can do that here, since both of them are really 32-bit numbers that change a few percent.

Fixes bedbbe6af4be ("drm/amd/display: Move link functions from dc to dc_link")
Fixes f18bc4e53ad6 ("drm/amd/display: update calculated bounding box logic for NV")
---
  drivers/gpu/drm/amd/display/dc/core/dc_link.c         | 4 ++--
  drivers/gpu/drm/amd/display/dc/dcn20/dcn20_resource.c | 2 +-
  2 files changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/display/dc/core/dc_link.c +2 -2
index c17db5c144aa..8dbf759eba45 100644
@@ -3072,8 +3072,8 @@ uint32_t dc_link_bandwidth_kbps(
  		 * but the difference is minimal and is in a safe direction,
  		 * which all works well around potential ambiguity of DP 1.4a spec.
  		 */
-		long long fec_link_bw_kbps = link_bw_kbps * 970LL;
-		link_bw_kbps = (uint32_t)(fec_link_bw_kbps / 1000LL);
+		link_bw_kbps = mul_u64_u32_shr(BIT_ULL(32) * 970LL / 1000,
+					       link_bw_kbps, 32);
  	}
  #endif
 
drivers/gpu/drm/amd/display/dc/dcn20/dcn20_resource.c +0 -0
index b35327bafbc5..70ac8a95d2db 100644

drivers/gpu/drm/amd/display/dc/dcn20/dcn20_resource.c static void update_bounding_box(struct dc *dc, struct _vcs_dpi_soc_bounding_box_ · line 2660

Quoted 5 lines
drivers/gpu/drm/amd/display/dc/dcn20/dcn20_resource.c +1 -1
@@ -2657,7 +2657,7 @@ static void update_bounding_box(struct dc *dc, struct _vcs_dpi_soc_bounding_box_
  		calculated_states[i].dram_speed_mts = uclk_states[i] * 16 / 1000;
 
  		// FCLK:UCLK ratio is 1.08
-		min_fclk_required_by_uclk = ((unsigned long long)uclk_states[i]) * 1080 / 1000000;
+		min_fclk_required_by_uclk = mul_u64_u32_shr(BIT_ULL(32) * 1080 / 1000000, uclk_states[i], 32);

Even though the mul + shift will be faster here, I would prefer that this just be a div_u64 for clarity.

Nicholas Kazlauskas

drivers/gpu/drm/amd/display/dc/dcn20/dcn20_resource.c static void update_bounding_box(struct dc *dc, struct _vcs_dpi_soc_bounding_box_

Quoted 4 lines
drivers/gpu/drm/amd/display/dc/dcn20/dcn20_resource.c +0 -0
  		calculated_states[i].fabricclk_mhz = (min_fclk_required_by_uclk < min_dcfclk) ?
  				min_dcfclk : min_fclk_required_by_uclk;
 

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

Acked-by Tested-by on v1 1/1
#3 lore raw
In reply to Arnd Bergmann

________________________________
From: amd-gfx <[email protected]> on behalf of Arnd Bergmann <[email protected]>
Sent: Monday, July 8, 2019 9:52:08 AM
To: Wentland, Harry; Li, Sun peng (Leo); Deucher, Alexander; Koenig, Christian; Zhou, David(ChunMing); David Airlie; Daniel Vetter
Cc: Liu, Charlene; Park, Chris; Arnd Bergmann; Cheng, Tony; Francis, David; [email protected]; [email protected]; Cornij, Nikola; Laktyushkin, Dmytro; [email protected]; Lei, Jun; Lakha, Bhawanpreet; Koo, Anthony
Subject: [PATCH] drm/amd/display: avoid 64-bit division

On 32-bit architectures, dividing a 64-bit integer in the kernel leads to a link error:

ERROR: "__udivdi3" [drivers/gpu/drm/amd/amdgpu/amdgpu.ko] undefined!
ERROR: "__divdi3" [drivers/gpu/drm/amd/amdgpu/amdgpu.ko] undefined!

Change the two recently introduced instances to a multiply+shift operation that is also much cheaper on 32-bit architectures. We can do that here, since both of them are really 32-bit numbers that change a few percent.

Fixes bedbbe6af4be ("drm/amd/display: Move link functions from dc to dc_link")
Fixes f18bc4e53ad6 ("drm/amd/display: update calculated bounding box logic for NV")
---
 drivers/gpu/drm/amd/display/dc/core/dc_link.c         | 4 ++--
 drivers/gpu/drm/amd/display/dc/dcn20/dcn20_resource.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/display/dc/core/dc_link.c +2 -2
index c17db5c144aa..8dbf759eba45 100644
@@ -3072,8 +3072,8 @@ uint32_t dc_link_bandwidth_kbps(
                  * but the difference is minimal and is in a safe direction,
                  * which all works well around potential ambiguity of DP 1.4a spec.
                  */
-               long long fec_link_bw_kbps = link_bw_kbps * 970LL;
-               link_bw_kbps = (uint32_t)(fec_link_bw_kbps / 1000LL);
+               link_bw_kbps = mul_u64_u32_shr(BIT_ULL(32) * 970LL / 1000,
+                                              link_bw_kbps, 32);
         }
 #endif
 
drivers/gpu/drm/amd/display/dc/dcn20/dcn20_resource.c +1 -1
index b35327bafbc5..70ac8a95d2db 100644
@@ -2657,7 +2657,7 @@ static void update_bounding_box(struct dc *dc, struct _vcs_dpi_soc_bounding_box_
                 calculated_states[i].dram_speed_mts = uclk_states[i] * 16 / 1000;
 
                 // FCLK:UCLK ratio is 1.08
-               min_fclk_required_by_uclk = ((unsigned long long)uclk_states[i]) * 1080 / 1000000;
+               min_fclk_required_by_uclk = mul_u64_u32_shr(BIT_ULL(32) * 1080 / 1000000, uclk_states[i], 32);
 
                 calculated_states[i].fabricclk_mhz = (min_fclk_required_by_uclk < min_dcfclk) ?
                                 min_dcfclk : min_fclk_required_by_uclk;

--
2.20.0

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

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

#4 lore raw
In reply to Arnd Bergmann

Hi Arnd!

Thanks for bisecting this issue.

I wonder whether you are going to commit your patch or planning to update it and it's still in your work queue. We have one of our 32-bit builds failing because of this issue, so that I would like either to fix it or wait to your fix if it has chances to go upstream today.

Sincerely,

Slava Abramov

________________________________
From: amd-gfx <[email protected]> on behalf of Arnd Bergmann <[email protected]>
Sent: Monday, July 8, 2019 9:52:08 AM
To: Wentland, Harry; Li, Sun peng (Leo); Deucher, Alexander; Koenig, Christian; Zhou, David(ChunMing); David Airlie; Daniel Vetter
Cc: Liu, Charlene; Park, Chris; Arnd Bergmann; Cheng, Tony; Francis, David; [email protected]; [email protected]; Cornij, Nikola; Laktyushkin, Dmytro; [email protected]; Lei, Jun; Lakha, Bhawanpreet; Koo, Anthony
Subject: [PATCH] drm/amd/display: avoid 64-bit division

On 32-bit architectures, dividing a 64-bit integer in the kernel leads to a link error:

ERROR: "__udivdi3" [drivers/gpu/drm/amd/amdgpu/amdgpu.ko] undefined!
ERROR: "__divdi3" [drivers/gpu/drm/amd/amdgpu/amdgpu.ko] undefined!

Change the two recently introduced instances to a multiply+shift operation that is also much cheaper on 32-bit architectures. We can do that here, since both of them are really 32-bit numbers that change a few percent.

Fixes bedbbe6af4be ("drm/amd/display: Move link functions from dc to dc_link")
Fixes f18bc4e53ad6 ("drm/amd/display: update calculated bounding box logic for NV")
---
 drivers/gpu/drm/amd/display/dc/core/dc_link.c         | 4 ++--
 drivers/gpu/drm/amd/display/dc/dcn20/dcn20_resource.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/display/dc/core/dc_link.c +2 -2
index c17db5c144aa..8dbf759eba45 100644
@@ -3072,8 +3072,8 @@ uint32_t dc_link_bandwidth_kbps(
                  * but the difference is minimal and is in a safe direction,
                  * which all works well around potential ambiguity of DP 1.4a spec.
                  */
-               long long fec_link_bw_kbps = link_bw_kbps * 970LL;
-               link_bw_kbps = (uint32_t)(fec_link_bw_kbps / 1000LL);
+               link_bw_kbps = mul_u64_u32_shr(BIT_ULL(32) * 970LL / 1000,
+                                              link_bw_kbps, 32);
         }
 #endif
 
drivers/gpu/drm/amd/display/dc/dcn20/dcn20_resource.c +1 -1
index b35327bafbc5..70ac8a95d2db 100644
@@ -2657,7 +2657,7 @@ static void update_bounding_box(struct dc *dc, struct _vcs_dpi_soc_bounding_box_
                 calculated_states[i].dram_speed_mts = uclk_states[i] * 16 / 1000;
 
                 // FCLK:UCLK ratio is 1.08
-               min_fclk_required_by_uclk = ((unsigned long long)uclk_states[i]) * 1080 / 1000000;
+               min_fclk_required_by_uclk = mul_u64_u32_shr(BIT_ULL(32) * 1080 / 1000000, uclk_states[i], 32);
 
                 calculated_states[i].fabricclk_mhz = (min_fclk_required_by_uclk < min_dcfclk) ?
                                 min_dcfclk : min_fclk_required_by_uclk;

--
2.20.0

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

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

A message that is not in the archive (sent off-list or not yet received): DM6PR12MB320967C48957C4F2F0E92438FEF10-lmeGfMZKVrEA9tGwT7oCEgdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org

#6 lore raw

I'll just apply Arnd's patch. If the display team wants to adjust it later to clarify the operation, they should go ahead as a follow up patch.

Thanks,

Alex
________________________________
From: Abramov, Slava
Sent: Tuesday, July 9, 2019 12:31 PM
To: Arnd Bergmann; Wentland, Harry; Li, Sun peng (Leo); Deucher, Alexander; Koenig, Christian; Zhou, David(ChunMing); David Airlie; Daniel Vetter
Cc: Liu, Charlene; Park, Chris; Cheng, Tony; Francis, David; [email protected]; [email protected]; Cornij, Nikola; Laktyushkin, Dmytro; [email protected]; Lei, Jun; Lakha, Bhawanpreet; Koo, Anthony
Subject: Re: [PATCH] drm/amd/display: avoid 64-bit division

Hi Arnd!

Thanks for bisecting this issue.

I wonder whether you are going to commit your patch or planning to update it and it's still in your work queue. We have one of our 32-bit builds failing because of this issue, so that I would like either to fix it or wait to your fix if it has chances to go upstream today.

Sincerely,

Slava Abramov

________________________________
From: amd-gfx <amd-gfx-bounces-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org> on behalf of Arnd Bergmann <[email protected]>
Sent: Monday, July 8, 2019 9:52:08 AM
To: Wentland, Harry; Li, Sun peng (Leo); Deucher, Alexander; Koenig, Christian; Zhou, David(ChunMing); David Airlie; Daniel Vetter
Cc: Liu, Charlene; Park, Chris; Arnd Bergmann; Cheng, Tony; Francis, David; [email protected]; [email protected]; Cornij, Nikola; Laktyushkin, Dmytro; [email protected]; Lei, Jun; Lakha, Bhawanpreet; Koo, Anthony
Subject: [PATCH] drm/amd/display: avoid 64-bit division

On 32-bit architectures, dividing a 64-bit integer in the kernel leads to a link error:

ERROR: "__udivdi3" [drivers/gpu/drm/amd/amdgpu/amdgpu.ko] undefined!
ERROR: "__divdi3" [drivers/gpu/drm/amd/amdgpu/amdgpu.ko] undefined!

Change the two recently introduced instances to a multiply+shift operation that is also much cheaper on 32-bit architectures. We can do that here, since both of them are really 32-bit numbers that change a few percent.

Fixes bedbbe6af4be ("drm/amd/display: Move link functions from dc to dc_link")
Fixes f18bc4e53ad6 ("drm/amd/display: update calculated bounding box logic for NV")
---
 drivers/gpu/drm/amd/display/dc/core/dc_link.c         | 4 ++--
 drivers/gpu/drm/amd/display/dc/dcn20/dcn20_resource.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/display/dc/core/dc_link.c +2 -2
index c17db5c144aa..8dbf759eba45 100644
@@ -3072,8 +3072,8 @@ uint32_t dc_link_bandwidth_kbps(
                  * but the difference is minimal and is in a safe direction,
                  * which all works well around potential ambiguity of DP 1.4a spec.
                  */
-               long long fec_link_bw_kbps = link_bw_kbps * 970LL;
-               link_bw_kbps = (uint32_t)(fec_link_bw_kbps / 1000LL);
+               link_bw_kbps = mul_u64_u32_shr(BIT_ULL(32) * 970LL / 1000,
+                                              link_bw_kbps, 32);
         }
 #endif
 
drivers/gpu/drm/amd/display/dc/dcn20/dcn20_resource.c +1 -1
index b35327bafbc5..70ac8a95d2db 100644
@@ -2657,7 +2657,7 @@ static void update_bounding_box(struct dc *dc, struct _vcs_dpi_soc_bounding_box_
                 calculated_states[i].dram_speed_mts = uclk_states[i] * 16 / 1000;
 
                 // FCLK:UCLK ratio is 1.08
-               min_fclk_required_by_uclk = ((unsigned long long)uclk_states[i]) * 1080 / 1000000;
+               min_fclk_required_by_uclk = mul_u64_u32_shr(BIT_ULL(32) * 1080 / 1000000, uclk_states[i], 32);
 
                 calculated_states[i].fabricclk_mhz = (min_fclk_required_by_uclk < min_dcfclk) ?
                                 min_dcfclk : min_fclk_required_by_uclk;

--
2.20.0

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

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

#7 lore raw
Quoted 3 lines · Alexander

I'll just apply Arnd's patch. If the display team wants to adjust it later to clarify the operation, they should go ahead as a follow up patch.

Thanks!

Quoted 8 lines

From: Abramov, Slava
Sent: Tuesday, July 9, 2019 12:31 PM

Quoted 6 lines

Thanks for bisecting this issue.

I wonder whether you are going to commit your patch or planning to update it and it's still in your work queue. We have one of our 32-bit builds failing because of this issue, so that I would like either to fix it or wait to your fix if it has chances to go upstream today.

I was going to update the patch, but had not gotten to that yet.

Arnd