Skip to contentSkip to conversation

faster vblank disable

PATCH In review Hamza Mahfooz 2 participants 6 messages Aug 22, 2024

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

v4 cover faster vblank disable

Since, drm_crtc_vblank_on_config() was recently introduced, we want to apply laxer vblanking policies across the board, since:

1. It will allow us to shut down interrupts faster for better power savings.

2. As a payment towards tech debt, since drm_vblank_offdelay (which defaults to 5s) isn't necessary on AMD hardware.

Also, patches 2-3 in this series provide even laxer policies and they are intentionally separated from patch #1. This way, if issues with them are encountered in the wild, it should be easy to bisect the issue to those patches.

Hamza Mahfooz (3):
drm/amd/display: use drm_crtc_vblank_on_config() drm/amd/display: use a more lax vblank enable policy for DCN35+ drm/amd/display: use a more lax vblank enable policy for older ASICs

 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 39 +++++++++++++------
 1 file changed, 28 insertions(+), 11 deletions(-)
Signature · 1 line
2.46.0
#1 lore raw

PATCH v4 1/3 drm/amd/display: use drm_crtc_vblank_on_config()

Hook up drm_crtc_vblank_on_config() in amdgpu_dm. So, that we can enable PSR and other static screen optimizations more quickly, while avoiding stuttering issues that are accompanied by the following dmesg error:

[drm:dc_dmub_srv_wait_idle [amdgpu]] *ERROR* Error waiting for DMUB idle: status=3

This also allows us to mimic how vblanking is handled by the windows amdgpu driver.

---
v3: use a less conservative policy

v4: drop TODO, use simplified calculation from Michel, use
DIV64_U64_ROUND_UP() and use a different policy.

---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 36 +++++++++++++------
 1 file changed, 25 insertions(+), 11 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +25 -11
index 7e7929f24ae4..00d4c97e8d26 100644
@@ -4934,12 +4934,6 @@ static int amdgpu_dm_initialize_drm_device(struct amdgpu_device *adev)
 
 				if (psr_feature_enabled)
 					amdgpu_dm_set_psr_caps(link);
-
-				/* TODO: Fix vblank control helpers to delay PSR entry to allow this when
-				 * PSR is also supported.
-				 */
-				if (link->psr_settings.psr_feature_enabled)
-					adev_to_drm(adev)->vblank_disable_immediate = false;
 			}
 		}
 		amdgpu_set_panel_orientation(&aconnector->base);
@@ -8232,7 +8226,7 @@ static int amdgpu_dm_encoder_init(struct drm_device *dev,
 
 static void manage_dm_interrupts(struct amdgpu_device *adev,
 				 struct amdgpu_crtc *acrtc,
-				 bool enable)
+				 struct dm_crtc_state *acrtc_state)
 {
 	/*
 	 * We have no guarantee that the frontend index maps to the same
@@ -8244,9 +8238,28 @@ static void manage_dm_interrupts(struct amdgpu_device *adev,
 		amdgpu_display_crtc_idx_to_irq_type(
 			adev,
 			acrtc->crtc_id);
+	struct drm_vblank_crtc_config config = {0};
+	struct dc_crtc_timing *timing;
+	int offdelay;
+
+	if (acrtc_state) {
+		if (amdgpu_ip_version(adev, DCE_HWIP, 0) <
+		    IP_VERSION(3, 5, 0)) {
+			drm_crtc_vblank_on(&acrtc->base);
+		} else {
+			timing = &acrtc_state->stream->timing;
+
+			/* at least 2 frames */
+			offdelay = DIV64_U64_ROUND_UP((u64)20 *
+						      timing->v_total *
+						      timing->h_total,
+						      timing->pix_clk_100hz);
+
+			config.offdelay_ms = offdelay ?: 30;
+			drm_crtc_vblank_on_config(&acrtc->base,
+						  &config);
+		}
 
-	if (enable) {
-		drm_crtc_vblank_on(&acrtc->base);
 		amdgpu_irq_get(
 			adev,
 			&adev->pageflip_irq,
@@ -9320,7 +9333,7 @@ static void amdgpu_dm_commit_streams(struct drm_atomic_state *state,
 		if (old_crtc_state->active &&
 		    (!new_crtc_state->active ||
 		     drm_atomic_crtc_needs_modeset(new_crtc_state))) {
-			manage_dm_interrupts(adev, acrtc, false);
+			manage_dm_interrupts(adev, acrtc, NULL);
 			dc_stream_release(dm_old_crtc_state->stream);
 		}
 	}
@@ -9835,7 +9848,8 @@ static void amdgpu_dm_atomic_commit_tail(struct drm_atomic_state *state)
 		     drm_atomic_crtc_needs_modeset(new_crtc_state))) {
 			dc_stream_retain(dm_new_crtc_state->stream);
 			acrtc->dm_irq_params.stream = dm_new_crtc_state->stream;
-			manage_dm_interrupts(adev, acrtc, true);
+			manage_dm_interrupts(adev, acrtc,
+					     to_dm_crtc_state(new_crtc_state));
 		}
 		/* Handle vrr on->off / off->on transitions */
 		amdgpu_dm_handle_vrr_transition(dm_old_crtc_state, dm_new_crtc_state);
Signature · 1 line
2.46.0
maintainer
#2 lore raw

Re: [PATCH v4 1/3] drm/amd/display: use drm_crtc_vblank_on_config()

Quoted 9 lines · Hamza Mahfooz

Hook up drm_crtc_vblank_on_config() in amdgpu_dm. So, that we can enable PSR and other static screen optimizations more quickly, while avoiding stuttering issues that are accompanied by the following dmesg error:

[drm:dc_dmub_srv_wait_idle [amdgpu]] *ERROR* Error waiting for DMUB idle: status=3

This also allows us to mimic how vblanking is handled by the windows amdgpu driver.

Please call out the policy change in the commit description and title. While this is using drm_crtc_vblank_on_config() the important part is that this stops vblank_disable_immediate = false bit (and associated 5s delay) and replaces it with a 2 vblank delay, if I read it right.

Harry

Quoted 86 lines

---
v3: use a less conservative policy

v4: drop TODO, use simplified calculation from Michel, use
DIV64_U64_ROUND_UP() and use a different policy.

---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 36 +++++++++++++------
 1 file changed, 25 insertions(+), 11 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +25 -11
index 7e7929f24ae4..00d4c97e8d26 100644
@@ -4934,12 +4934,6 @@ static int amdgpu_dm_initialize_drm_device(struct amdgpu_device *adev)
 
 				if (psr_feature_enabled)
 					amdgpu_dm_set_psr_caps(link);
-
-				/* TODO: Fix vblank control helpers to delay PSR entry to allow this when
-				 * PSR is also supported.
-				 */
-				if (link->psr_settings.psr_feature_enabled)
-					adev_to_drm(adev)->vblank_disable_immediate = false;
 			}
 		}
 		amdgpu_set_panel_orientation(&aconnector->base);
@@ -8232,7 +8226,7 @@ static int amdgpu_dm_encoder_init(struct drm_device *dev,
 
 static void manage_dm_interrupts(struct amdgpu_device *adev,
 				 struct amdgpu_crtc *acrtc,
-				 bool enable)
+				 struct dm_crtc_state *acrtc_state)
 {
 	/*
 	 * We have no guarantee that the frontend index maps to the same
@@ -8244,9 +8238,28 @@ static void manage_dm_interrupts(struct amdgpu_device *adev,
 		amdgpu_display_crtc_idx_to_irq_type(
 			adev,
 			acrtc->crtc_id);
+	struct drm_vblank_crtc_config config = {0};
+	struct dc_crtc_timing *timing;
+	int offdelay;
+
+	if (acrtc_state) {
+		if (amdgpu_ip_version(adev, DCE_HWIP, 0) <
+		    IP_VERSION(3, 5, 0)) {
+			drm_crtc_vblank_on(&acrtc->base);
+		} else {
+			timing = &acrtc_state->stream->timing;
+
+			/* at least 2 frames */
+			offdelay = DIV64_U64_ROUND_UP((u64)20 *
+						      timing->v_total *
+						      timing->h_total,
+						      timing->pix_clk_100hz);
+
+			config.offdelay_ms = offdelay ?: 30;
+			drm_crtc_vblank_on_config(&acrtc->base,
+						  &config);
+		}
 
-	if (enable) {
-		drm_crtc_vblank_on(&acrtc->base);
 		amdgpu_irq_get(
 			adev,
 			&adev->pageflip_irq,
@@ -9320,7 +9333,7 @@ static void amdgpu_dm_commit_streams(struct drm_atomic_state *state,
 		if (old_crtc_state->active &&
 		    (!new_crtc_state->active ||
 		     drm_atomic_crtc_needs_modeset(new_crtc_state))) {
-			manage_dm_interrupts(adev, acrtc, false);
+			manage_dm_interrupts(adev, acrtc, NULL);
 			dc_stream_release(dm_old_crtc_state->stream);
 		}
 	}
@@ -9835,7 +9848,8 @@ static void amdgpu_dm_atomic_commit_tail(struct drm_atomic_state *state)
 		     drm_atomic_crtc_needs_modeset(new_crtc_state))) {
 			dc_stream_retain(dm_new_crtc_state->stream);
 			acrtc->dm_irq_params.stream = dm_new_crtc_state->stream;
-			manage_dm_interrupts(adev, acrtc, true);
+			manage_dm_interrupts(adev, acrtc,
+					     to_dm_crtc_state(new_crtc_state));
 		}
 		/* Handle vrr on->off / off->on transitions */
 		amdgpu_dm_handle_vrr_transition(dm_old_crtc_state, dm_new_crtc_state);
#3 lore raw

PATCH v4 2/3 drm/amd/display: use a more lax vblank enable policy for DCN35+

In reply to Hamza Mahfooz

Ideally, we want to enable immediate vblank disable, when possible and we should be able to do so on DCN35+, if PSR isn't supported by a given CRTC.

---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +6 -1
index 00d4c97e8d26..68442cb857fc 100644
@@ -8246,7 +8246,8 @@ static void manage_dm_interrupts(struct amdgpu_device *adev,
 		if (amdgpu_ip_version(adev, DCE_HWIP, 0) <
 		    IP_VERSION(3, 5, 0)) {
 			drm_crtc_vblank_on(&acrtc->base);
-		} else {
+		} else if (acrtc_state->stream->link->psr_settings.psr_version <
+			   DC_PSR_VERSION_UNSUPPORTED) {
 			timing = &acrtc_state->stream->timing;
 
 			/* at least 2 frames */
@@ -8258,6 +8259,10 @@ static void manage_dm_interrupts(struct amdgpu_device *adev,
 			config.offdelay_ms = offdelay ?: 30;
 			drm_crtc_vblank_on_config(&acrtc->base,
 						  &config);
+		} else {
+			config.disable_immediate = true;
+			drm_crtc_vblank_on_config(&acrtc->base,
+						  &config);
 		}
 
 		amdgpu_irq_get(
Signature · 1 line
2.46.0
#4 lore raw

PATCH v4 3/3 drm/amd/display: use a more lax vblank enable policy for older ASICs

In reply to Hamza Mahfooz

Ideally, we want to drop the legacy vblank enable for older ASICs. This should be possible now, since we can now specify how many frames we need to wait before disabling vblanking instead of being forced to either choose between no delay (which can still be buggy) and drm_vblank_offdelay (which is much longer by default than is required on AMD hardware).

---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +6 -8
index 68442cb857fc..8c34a7756c58 100644
@@ -8244,10 +8244,9 @@ static void manage_dm_interrupts(struct amdgpu_device *adev,
 
 	if (acrtc_state) {
 		if (amdgpu_ip_version(adev, DCE_HWIP, 0) <
-		    IP_VERSION(3, 5, 0)) {
-			drm_crtc_vblank_on(&acrtc->base);
-		} else if (acrtc_state->stream->link->psr_settings.psr_version <
-			   DC_PSR_VERSION_UNSUPPORTED) {
+		    IP_VERSION(3, 5, 0) ||
+		    acrtc_state->stream->link->psr_settings.psr_version <
+		    DC_PSR_VERSION_UNSUPPORTED) {
 			timing = &acrtc_state->stream->timing;
 
 			/* at least 2 frames */
@@ -8257,14 +8256,13 @@ static void manage_dm_interrupts(struct amdgpu_device *adev,
 						      timing->pix_clk_100hz);
 
 			config.offdelay_ms = offdelay ?: 30;
-			drm_crtc_vblank_on_config(&acrtc->base,
-						  &config);
 		} else {
 			config.disable_immediate = true;
-			drm_crtc_vblank_on_config(&acrtc->base,
-						  &config);
 		}
 
+		drm_crtc_vblank_on_config(&acrtc->base,
+					  &config);
+
 		amdgpu_irq_get(
 			adev,
 			&adev->pageflip_irq,
Signature · 1 line
2.46.0
maintainer
#5 lore raw
In reply to Hamza Mahfooz
Quoted 6 lines · Hamza Mahfooz

Since, drm_crtc_vblank_on_config() was recently introduced, we want to apply laxer vblanking policies across the board, since:

1. It will allow us to shut down interrupts faster for better power savings.

Quoted 8 lines

2. As a payment towards tech debt, since drm_vblank_offdelay (which defaults to 5s) isn't necessary on AMD hardware.

Also, patches 2-3 in this series provide even laxer policies and they are intentionally separated from patch #1. This way, if issues with them are encountered in the wild, it should be easy to bisect the issue to those patches.

With an updated description for patch 1 that calls out the new behavior this series is

Harry

Quoted 9 lines

Hamza Mahfooz (3):
drm/amd/display: use drm_crtc_vblank_on_config() drm/amd/display: use a more lax vblank enable policy for DCN35+ drm/amd/display: use a more lax vblank enable policy for older ASICs

 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 39 +++++++++++++------
 1 file changed, 28 insertions(+), 11 deletions(-)