2023-01-14 21:50:04

by Deepak R Varma

[permalink] [raw]
Subject: [PATCH 0/4] drm/amd/display: Use min()/max() helper macros

This patch series proposes using standard min() / max() helper macros instead of
direct variable comparison using the ternary operator or if/else evaluations. I
have tested the change using a dummy module and similar simulations on my x86
machine.

Deepak R Varma (4):
drm/amd/display: Use min()/max() macros in dcn_calc_math
drm/amd/display: dcn20: Use min()/max() helper macros
drm/amd/display: dcn21: Use min()/max() helper macros
drm/amd/display: dcn32: Use min()/max() helper macros

.../gpu/drm/amd/display/dc/dml/calcs/dcn_calc_math.c | 10 +++++-----
.../drm/amd/display/dc/dml/dcn20/display_mode_vba_20.c | 5 +----
.../amd/display/dc/dml/dcn20/display_mode_vba_20v2.c | 5 +----
.../drm/amd/display/dc/dml/dcn21/display_mode_vba_21.c | 5 +----
drivers/gpu/drm/amd/display/dc/dml/dcn32/dcn32_fpu.c | 4 ++--
5 files changed, 10 insertions(+), 19 deletions(-)

--
2.34.1




2023-01-14 22:11:18

by Deepak R Varma

[permalink] [raw]
Subject: [PATCH 2/4] drm/amd/display: dcn20: Use min()/max() helper macros

Use the standard min() / max() helper macros instead of direct variable
comparison using if/else blocks or ternary operator. Change identified
using minmax.cocci Coccinelle semantic patch.

Signed-off-by: Deepak R Varma <[email protected]>
---
.../gpu/drm/amd/display/dc/dml/dcn20/display_mode_vba_20.c | 5 +----
.../gpu/drm/amd/display/dc/dml/dcn20/display_mode_vba_20v2.c | 5 +----
2 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/dml/dcn20/display_mode_vba_20.c b/drivers/gpu/drm/amd/display/dc/dml/dcn20/display_mode_vba_20.c
index d3b5b6fedf04..850bb0f973d4 100644
--- a/drivers/gpu/drm/amd/display/dc/dml/dcn20/display_mode_vba_20.c
+++ b/drivers/gpu/drm/amd/display/dc/dml/dcn20/display_mode_vba_20.c
@@ -626,10 +626,7 @@ static bool CalculatePrefetchSchedule(

dst_y_prefetch_oto = Tpre_oto / LineTime;

- if (dst_y_prefetch_oto < dst_y_prefetch_equ)
- *DestinationLinesForPrefetch = dst_y_prefetch_oto;
- else
- *DestinationLinesForPrefetch = dst_y_prefetch_equ;
+ *DestinationLinesForPrefetch = min(dst_y_prefetch_oto, dst_y_prefetch_equ);

*DestinationLinesForPrefetch = dml_floor(4.0 * (*DestinationLinesForPrefetch + 0.125), 1)
/ 4;
diff --git a/drivers/gpu/drm/amd/display/dc/dml/dcn20/display_mode_vba_20v2.c b/drivers/gpu/drm/amd/display/dc/dml/dcn20/display_mode_vba_20v2.c
index edd098c7eb92..6f4903525acc 100644
--- a/drivers/gpu/drm/amd/display/dc/dml/dcn20/display_mode_vba_20v2.c
+++ b/drivers/gpu/drm/amd/display/dc/dml/dcn20/display_mode_vba_20v2.c
@@ -686,10 +686,7 @@ static bool CalculatePrefetchSchedule(

dst_y_prefetch_oto = Tpre_oto / LineTime;

- if (dst_y_prefetch_oto < dst_y_prefetch_equ)
- *DestinationLinesForPrefetch = dst_y_prefetch_oto;
- else
- *DestinationLinesForPrefetch = dst_y_prefetch_equ;
+ *DestinationLinesForPrefetch = min(dst_y_prefetch_oto, dst_y_prefetch_equ);

*DestinationLinesForPrefetch = dml_floor(4.0 * (*DestinationLinesForPrefetch + 0.125), 1)
/ 4;
--
2.34.1



2023-01-14 22:11:30

by Deepak R Varma

[permalink] [raw]
Subject: [PATCH 4/4] drm/amd/display: dcn32: Use min()/max() helper macros

Use the standard min() / max() helper macros instead of direct variable
comparison using if/else blocks or ternary operator. Change identified
using minmax.cocci Coccinelle semantic patch.

Signed-off-by: Deepak R Varma <[email protected]>
---
drivers/gpu/drm/amd/display/dc/dml/dcn32/dcn32_fpu.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/dml/dcn32/dcn32_fpu.c b/drivers/gpu/drm/amd/display/dc/dml/dcn32/dcn32_fpu.c
index f94abd124021..80820f012891 100644
--- a/drivers/gpu/drm/amd/display/dc/dml/dcn32/dcn32_fpu.c
+++ b/drivers/gpu/drm/amd/display/dc/dml/dcn32/dcn32_fpu.c
@@ -908,7 +908,7 @@ static bool subvp_drr_schedulable(struct dc *dc, struct dc_state *context, struc
stretched_drr_us = drr_frame_us + mall_region_us + SUBVP_DRR_MARGIN_US;
drr_stretched_vblank_us = (drr_timing->v_total - drr_timing->v_addressable) * drr_timing->h_total /
(double)(drr_timing->pix_clk_100hz * 100) * 1000000 + (stretched_drr_us - drr_frame_us);
- max_vblank_mallregion = drr_stretched_vblank_us > mall_region_us ? drr_stretched_vblank_us : mall_region_us;
+ max_vblank_mallregion = max(drr_stretched_vblank_us, mall_region_us);

/* We consider SubVP + DRR schedulable if the stretched frame duration of the DRR display (i.e. the
* highest refresh rate + margin that can support UCLK P-State switch) passes the static analysis
@@ -999,7 +999,7 @@ static bool subvp_vblank_schedulable(struct dc *dc, struct dc_state *context)
(double)(vblank_timing->pix_clk_100hz * 100) * 1000000;
subvp_active_us = main_timing->v_addressable * main_timing->h_total /
(double)(main_timing->pix_clk_100hz * 100) * 1000000;
- max_vblank_mallregion = vblank_blank_us > mall_region_us ? vblank_blank_us : mall_region_us;
+ max_vblank_mallregion = max(vblank_blank_us, mall_region_us);

// Schedulable if VACTIVE region of the SubVP pipe can fit the MALL prefetch, VBLANK frame time,
// and the max of (VBLANK blanking time, MALL region)
--
2.34.1



2023-01-14 22:11:39

by Deepak R Varma

[permalink] [raw]
Subject: [PATCH 3/4] drm/amd/display: dcn21: Use min()/max() helper macros

Use the standard min() / max() helper macros instead of direct variable
comparison using if/else blocks or ternary operator. Change identified
using minmax.cocci Coccinelle semantic patch.

Signed-off-by: Deepak R Varma <[email protected]>
---
.../gpu/drm/amd/display/dc/dml/dcn21/display_mode_vba_21.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/dml/dcn21/display_mode_vba_21.c b/drivers/gpu/drm/amd/display/dc/dml/dcn21/display_mode_vba_21.c
index 1d84ae50311d..41fb5fddd85d 100644
--- a/drivers/gpu/drm/amd/display/dc/dml/dcn21/display_mode_vba_21.c
+++ b/drivers/gpu/drm/amd/display/dc/dml/dcn21/display_mode_vba_21.c
@@ -838,10 +838,7 @@ static bool CalculatePrefetchSchedule(

dst_y_prefetch_equ = dml_floor(4.0 * (dst_y_prefetch_equ + 0.125), 1) / 4.0;

- if (dst_y_prefetch_oto < dst_y_prefetch_equ)
- *DestinationLinesForPrefetch = dst_y_prefetch_oto;
- else
- *DestinationLinesForPrefetch = dst_y_prefetch_equ;
+ *DestinationLinesForPrefetch = min(dst_y_prefetch_oto, dst_y_prefetch_equ);

// Limit to prevent overflow in DST_Y_PREFETCH register
*DestinationLinesForPrefetch = dml_min(*DestinationLinesForPrefetch, 63.75);
--
2.34.1



2023-01-22 18:46:10

by Deepak R Varma

[permalink] [raw]
Subject: Re: [PATCH 0/4] drm/amd/display: Use min()/max() helper macros

On Sun, Jan 15, 2023 at 02:48:45AM +0530, Deepak R Varma wrote:
> This patch series proposes using standard min() / max() helper macros instead of
> direct variable comparison using the ternary operator or if/else evaluations. I
> have tested the change using a dummy module and similar simulations on my x86
> machine.

Hello,
May I request a review feedback and comments on this patch set please?

Thank you,
./drv

>
> Deepak R Varma (4):
> drm/amd/display: Use min()/max() macros in dcn_calc_math
> drm/amd/display: dcn20: Use min()/max() helper macros
> drm/amd/display: dcn21: Use min()/max() helper macros
> drm/amd/display: dcn32: Use min()/max() helper macros
>
> .../gpu/drm/amd/display/dc/dml/calcs/dcn_calc_math.c | 10 +++++-----
> .../drm/amd/display/dc/dml/dcn20/display_mode_vba_20.c | 5 +----
> .../amd/display/dc/dml/dcn20/display_mode_vba_20v2.c | 5 +----
> .../drm/amd/display/dc/dml/dcn21/display_mode_vba_21.c | 5 +----
> drivers/gpu/drm/amd/display/dc/dml/dcn32/dcn32_fpu.c | 4 ++--
> 5 files changed, 10 insertions(+), 19 deletions(-)
>
> --
> 2.34.1
>
>
>