Skip to contentSkip to conversation

VRR BTR patches revision 2

PATCH New Mario Kleiner 3 participants 6 messages Apr 26, 2019 2 messages not in the archive

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

Updated series. The debug patch is dropped, a r-b by Nicholas is tacked onto patch 1/3 and patch 3/3 has the locking fix that Nicholas proposed. In terms of testing 3/3 didn't change anything for the better or worse, observed behaviour on retested DCN-1 and DCE-8 is the same. Patch 2/3 is identical.

For reference i made a little git repo with a cleaned up version of my test script VRRTest.m and some pdf's with some plots from my testing with a slightly earlier version of that script:

https://github.com/kleinerm/VRRTestPlots

Easy to use on a Debian/Ubuntu based system as you can get GNU/Octave
+ psychtoolbox-3 from the distro repo. Explanations in the Readm

The following plots illustrate how patch 2/3 can sometimes help to make transition to BTR a bit smoother min VRR was 25 Hz or 40 msecs in this test case on DCE8 and 30 Hz or 33 msecs on DCE11.

Without patch 2/3:

https://github.com/kleinerm/VRRTestPlots/blob/master/VRR_DCE8_2upstepping_VUPDATEbtr+removehysteresispatch.pdf
https://github.com/kleinerm/VRRTestPlots/blob/master/VRR_DCE11_2upstepping_VUPDATEbtr+removehysteresispatch.pdf

With patch 2/3:

https://github.com/kleinerm/VRRTestPlots/blob/master/VRR_DCE11_2upstepping_VUPDATEbtr.pdf
https://github.com/kleinerm/VRRTestPlots/blob/master/VRR_DCE8_2upstepping_VUPDATEbtr.pdf

-mario

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

#1 lore raw

PATCH 1/3 drm/amd/display: Fix and simplify apply_below_the_range()

The comparison of inserted_frame_duration_in_us against a duration calculated from max_refresh_in_uhz is both wrong in its math and not needed, as the min_duration_in_us value is already cached in in_out_vrr for reuse. No need to recalculate it wrongly at each invocation.

---
 drivers/gpu/drm/amd/display/modules/freesync/freesync.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/display/modules/freesync/freesync.c +2 -4
index 71274683da04..e56543c36eba 100644
@@ -437,10 +437,8 @@ static void apply_below_the_range(struct core_freesync *core_freesync,
 			inserted_frame_duration_in_us = last_render_time_in_us /
 							frames_to_insert;
 
-		if (inserted_frame_duration_in_us <
-			(1000000 / in_out_vrr->max_refresh_in_uhz))
-			inserted_frame_duration_in_us =
-				(1000000 / in_out_vrr->max_refresh_in_uhz);
+		if (inserted_frame_duration_in_us < in_out_vrr->min_duration_in_us)
+			inserted_frame_duration_in_us = in_out_vrr->min_duration_in_us;
 
 		/* Cache the calculated variables */
 		in_out_vrr->btr.inserted_duration_in_us =
Signature · 6 lines
2.20.1

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

PATCH 2/3 drm/amd/display: Enter VRR BTR earlier.

In reply to Mario Kleiner

Use a 2 msecs switching headroom not only for slightly delayed exiting of BTR mode, but now also for entering it a bit before the max frame duration is exceeded.

With slowly changing time delay between successive flips or with a bit of jitter in arrival of flips, this adapts vblank early and prevents missed vblanks at the border between non-BTR and BTR.

Testing on DCE-8, DCE-11 and DCN-1.0 shows that this more often avoids skipped frames when moving across the BTR boundary, especially on DCE-8 and DCE-11 with the followup commit for dealing with pre-DCE-12 hw.

---
 drivers/gpu/drm/amd/display/modules/freesync/freesync.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/display/modules/freesync/freesync.c +1 -1
index e56543c36eba..a965ab5466dc 100644
@@ -350,7 +350,7 @@ static void apply_below_the_range(struct core_freesync *core_freesync,
 			in_out_vrr->btr.frame_counter = 0;
 			in_out_vrr->btr.btr_active = false;
 		}
-	} else if (last_render_time_in_us > max_render_time_in_us) {
+	} else if (last_render_time_in_us + BTR_EXIT_MARGIN > max_render_time_in_us) {
 		/* Enter Below the Range */
 		in_out_vrr->btr.btr_active = true;
 	}
Signature · 6 lines
2.20.1

_______________________________________________
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): 20190426105016.12210-1-mario.kleiner.de-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#4 lore raw

PATCH 3/3 drm/amd/display: Compensate for pre-DCE12 BTR-VRR hw limitations. (v2)

Pre-DCE12 needs special treatment for BTR / low framerate compensation for more stable behaviour:

According to comments in the code and some testing on DCE-8 and DCE-11, DCE-11 and earlier only apply VTOTAL_MIN/MAX programming with a lag of one frame, so the special BTR hw programming for intermediate fixed duration frames must be done inside the current frame at flip submission in atomic commit tail, ie. one vblank earlier, and the fixed refresh intermediate frame mode must be also terminated one vblank earlier on pre-DCE12 display engines.

To achieve proper termination on < DCE-12 shift the point when the switch-back from fixed vblank duration to variable vblank duration happens from the start of VBLANK (vblank irq, as done on DCE-12+) to back-porch or end of VBLANK (handled by vupdate irq handler). We must leave the switch-back code inside VBLANK irq for DCE12+, as before.

Doing this, we get much better behaviour of BTR for up-sweeps, ie. going from short to long frame durations (~high to low fps) and for constant framerate flips, as tested on DCE-8 and DCE-11. Behaviour is still not quite as good as on DCN-1 though.

On down-sweeps, going from long to short frame durations (low fps to high fps) < DCE-12 is a little bit improved, although by far not as much as for up-sweeps and constant fps.

v2: Fix some wrong locking, as pointed out by Nicholas.

---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 45 +++++++++++++++++--
 1 file changed, 42 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +42 -3
index 76b6e621793f..7241e1f3ebec 100644
@@ -364,6 +364,7 @@ static void dm_vupdate_high_irq(void *interrupt_params)
 	struct amdgpu_device *adev = irq_params->adev;
 	struct amdgpu_crtc *acrtc;
 	struct dm_crtc_state *acrtc_state;
+	unsigned long flags;
 
 	acrtc = get_crtc_by_otg_inst(adev, irq_params->irq_src - IRQ_TYPE_VUPDATE);
 
@@ -381,6 +382,22 @@ static void dm_vupdate_high_irq(void *interrupt_params)
 		 */
 		if (amdgpu_dm_vrr_active(acrtc_state))
 			drm_crtc_handle_vblank(&acrtc->base);
+
+		if (acrtc_state->stream && adev->family < AMDGPU_FAMILY_AI &&
+		    acrtc_state->vrr_params.supported &&
+		    acrtc_state->freesync_config.state == VRR_STATE_ACTIVE_VARIABLE) {
+			spin_lock_irqsave(&adev->ddev->event_lock, flags);
+			mod_freesync_handle_v_update(
+			    adev->dm.freesync_module,
+			    acrtc_state->stream,
+			    &acrtc_state->vrr_params);
+
+			dc_stream_adjust_vmin_vmax(
+			    adev->dm.dc,
+			    acrtc_state->stream,
+			    &acrtc_state->vrr_params.adjust);
+			spin_unlock_irqrestore(&adev->ddev->event_lock, flags);
+		}
 	}
 }
 
@@ -390,6 +407,7 @@ static void dm_crtc_high_irq(void *interrupt_params)
 	struct amdgpu_device *adev = irq_params->adev;
 	struct amdgpu_crtc *acrtc;
 	struct dm_crtc_state *acrtc_state;
+	unsigned long flags;
 
 	acrtc = get_crtc_by_otg_inst(adev, irq_params->irq_src - IRQ_TYPE_VBLANK);
 
@@ -412,9 +430,10 @@ static void dm_crtc_high_irq(void *interrupt_params)
 		 */
 		amdgpu_dm_crtc_handle_crc_irq(&acrtc->base);
 
-		if (acrtc_state->stream &&
+		if (acrtc_state->stream && adev->family >= AMDGPU_FAMILY_AI &&
 		    acrtc_state->vrr_params.supported &&
 		    acrtc_state->freesync_config.state == VRR_STATE_ACTIVE_VARIABLE) {
+			spin_lock_irqsave(&adev->ddev->event_lock, flags);
 			mod_freesync_handle_v_update(
 				adev->dm.freesync_module,
 				acrtc_state->stream,
@@ -424,6 +443,7 @@ static void dm_crtc_high_irq(void *interrupt_params)
 				adev->dm.dc,
 				acrtc_state->stream,
 				&acrtc_state->vrr_params.adjust);
+			spin_unlock_irqrestore(&adev->ddev->event_lock, flags);
 		}
 	}
 }
@@ -4878,8 +4898,10 @@ static void update_freesync_state_on_stream(
 	struct dc_plane_state *surface,
 	u32 flip_timestamp_in_us)
 {
-	struct mod_vrr_params vrr_params = new_crtc_state->vrr_params;
+	struct mod_vrr_params vrr_params;
 	struct dc_info_packet vrr_infopacket = {0};
+	struct amdgpu_device *adev = dm->adev;
+	unsigned long flags;
 
 	if (!new_stream)
 		return;
@@ -4892,6 +4914,9 @@ static void update_freesync_state_on_stream(
 	if (!new_stream->timing.h_total || !new_stream->timing.v_total)
 		return;
 
+	spin_lock_irqsave(&adev->ddev->event_lock, flags);
+	vrr_params = new_crtc_state->vrr_params;
+
 	if (surface) {
 		mod_freesync_handle_preflip(
 			dm->freesync_module,
@@ -4899,6 +4924,12 @@ static void update_freesync_state_on_stream(
 			new_stream,
 			flip_timestamp_in_us,
 			&vrr_params);
+
+		if (adev->family < AMDGPU_FAMILY_AI &&
+		    amdgpu_dm_vrr_active(new_crtc_state)) {
+			mod_freesync_handle_v_update(dm->freesync_module,
+						     new_stream, &vrr_params);
+		}
 	}
 
 	mod_freesync_build_vrr_infopacket(
@@ -4930,6 +4961,8 @@ static void update_freesync_state_on_stream(
 			      new_crtc_state->base.crtc->base.id,
 			      (int)new_crtc_state->base.vrr_enabled,
 			      (int)vrr_params.state);
+
+	spin_unlock_irqrestore(&adev->ddev->event_lock, flags);
 }
 
 static void pre_update_freesync_state_on_stream(
@@ -4937,8 +4970,10 @@ static void pre_update_freesync_state_on_stream(
 	struct dm_crtc_state *new_crtc_state)
 {
 	struct dc_stream_state *new_stream = new_crtc_state->stream;
-	struct mod_vrr_params vrr_params = new_crtc_state->vrr_params;
+	struct mod_vrr_params vrr_params;
 	struct mod_freesync_config config = new_crtc_state->freesync_config;
+	struct amdgpu_device *adev = dm->adev;
+	unsigned long flags;
 
 	if (!new_stream)
 		return;
@@ -4950,6 +4985,9 @@ static void pre_update_freesync_state_on_stream(
 	if (!new_stream->timing.h_total || !new_stream->timing.v_total)
 		return;
 
+	spin_lock_irqsave(&adev->ddev->event_lock, flags);
+	vrr_params = new_crtc_state->vrr_params;
+
 	if (new_crtc_state->vrr_supported &&
 	    config.min_refresh_in_uhz &&
 	    config.max_refresh_in_uhz) {
@@ -4970,6 +5008,7 @@ static void pre_update_freesync_state_on_stream(
 			sizeof(vrr_params.adjust)) != 0);
 
 	new_crtc_state->vrr_params = vrr_params;
+	spin_unlock_irqrestore(&adev->ddev->event_lock, flags);
 }
 
 static void amdgpu_dm_handle_vrr_transition(struct dm_crtc_state *old_state,
Signature · 6 lines
2.20.1

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

A message that is not in the archive (sent off-list or not yet received): 20190426105016.12210-4-mario.kleiner.de-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#6 lore raw

Re: [PATCH 3/3] drm/amd/display: Compensate for pre-DCE12 BTR-VRR hw limitations. (v2)

Quoted 25 lines · Mario Kleiner

Pre-DCE12 needs special treatment for BTR / low framerate compensation for more stable behaviour:

According to comments in the code and some testing on DCE-8 and DCE-11, DCE-11 and earlier only apply VTOTAL_MIN/MAX programming with a lag of one frame, so the special BTR hw programming for intermediate fixed duration frames must be done inside the current frame at flip submission in atomic commit tail, ie. one vblank earlier, and the fixed refresh intermediate frame mode must be also terminated one vblank earlier on pre-DCE12 display engines.

To achieve proper termination on < DCE-12 shift the point when the switch-back from fixed vblank duration to variable vblank duration happens from the start of VBLANK (vblank irq, as done on DCE-12+) to back-porch or end of VBLANK (handled by vupdate irq handler). We must leave the switch-back code inside VBLANK irq for DCE12+, as before.

Doing this, we get much better behaviour of BTR for up-sweeps, ie. going from short to long frame durations (~high to low fps) and for constant framerate flips, as tested on DCE-8 and DCE-11. Behaviour is still not quite as good as on DCN-1 though.

Quoted 7 lines

On down-sweeps, going from long to short frame durations (low fps to high fps) < DCE-12 is a little bit improved, although by far not as much as for up-sweeps and constant fps.

v2: Fix some wrong locking, as pointed out by Nicholas.

Still looks good to me, but I just noticed one other minor nitpick (sorry!)

Quoted 17 lines
---
  .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 45 +++++++++++++++++--
  1 file changed, 42 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -0
index 76b6e621793f..7241e1f3ebec 100644
@@ -364,6 +364,7 @@ static void dm_vupdate_high_irq(void *interrupt_params)
  	struct amdgpu_device *adev = irq_params->adev;
  	struct amdgpu_crtc *acrtc;
  	struct dm_crtc_state *acrtc_state;
+	unsigned long flags;
 
  	acrtc = get_crtc_by_otg_inst(adev, irq_params->irq_src - IRQ_TYPE_VUPDATE);
 

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static void dm_vupdate_high_irq(void *interrupt_params) · line 384

Quoted 3 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -0
@@ -381,6 +382,22 @@ static void dm_vupdate_high_irq(void *interrupt_params)
  		 */
  		if (amdgpu_dm_vrr_active(acrtc_state))
  			drm_crtc_handle_vblank(&acrtc->base);

Can't this block be merged with the one below?

With the condition also changed to just:

if (acrtc_state->stream && adev->family < AMDGPU_FAMILY_AI)

	...

I also noticed that the crtc_state itself is always accessed unlocked for checking whether VRR is on/off which is probably a bug... but this patch shouldn't be the one to fix that. At the very least though it can leave things in a bit better shape like you've already done. Thanks!

Nicholas Kazlauskas

Quoted 115 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +40 -3
+
+		if (acrtc_state->stream && adev->family < AMDGPU_FAMILY_AI &&
+		    acrtc_state->vrr_params.supported &&
+		    acrtc_state->freesync_config.state == VRR_STATE_ACTIVE_VARIABLE) {
+			spin_lock_irqsave(&adev->ddev->event_lock, flags);
+			mod_freesync_handle_v_update(
+			    adev->dm.freesync_module,
+			    acrtc_state->stream,
+			    &acrtc_state->vrr_params);
+
+			dc_stream_adjust_vmin_vmax(
+			    adev->dm.dc,
+			    acrtc_state->stream,
+			    &acrtc_state->vrr_params.adjust);
+			spin_unlock_irqrestore(&adev->ddev->event_lock, flags);
+		}
  	}
  }
 
@@ -390,6 +407,7 @@ static void dm_crtc_high_irq(void *interrupt_params)
  	struct amdgpu_device *adev = irq_params->adev;
  	struct amdgpu_crtc *acrtc;
  	struct dm_crtc_state *acrtc_state;
+	unsigned long flags;
 
  	acrtc = get_crtc_by_otg_inst(adev, irq_params->irq_src - IRQ_TYPE_VBLANK);
 
@@ -412,9 +430,10 @@ static void dm_crtc_high_irq(void *interrupt_params)
  		 */
  		amdgpu_dm_crtc_handle_crc_irq(&acrtc->base);
 
-		if (acrtc_state->stream &&
+		if (acrtc_state->stream && adev->family >= AMDGPU_FAMILY_AI &&
  		    acrtc_state->vrr_params.supported &&
  		    acrtc_state->freesync_config.state == VRR_STATE_ACTIVE_VARIABLE) {
+			spin_lock_irqsave(&adev->ddev->event_lock, flags);
  			mod_freesync_handle_v_update(
  				adev->dm.freesync_module,
  				acrtc_state->stream,
@@ -424,6 +443,7 @@ static void dm_crtc_high_irq(void *interrupt_params)
  				adev->dm.dc,
  				acrtc_state->stream,
  				&acrtc_state->vrr_params.adjust);
+			spin_unlock_irqrestore(&adev->ddev->event_lock, flags);
  		}
  	}
  }
@@ -4878,8 +4898,10 @@ static void update_freesync_state_on_stream(
  	struct dc_plane_state *surface,
  	u32 flip_timestamp_in_us)
  {
-	struct mod_vrr_params vrr_params = new_crtc_state->vrr_params;
+	struct mod_vrr_params vrr_params;
  	struct dc_info_packet vrr_infopacket = {0};
+	struct amdgpu_device *adev = dm->adev;
+	unsigned long flags;
 
  	if (!new_stream)
  		return;
@@ -4892,6 +4914,9 @@ static void update_freesync_state_on_stream(
  	if (!new_stream->timing.h_total || !new_stream->timing.v_total)
  		return;
 
+	spin_lock_irqsave(&adev->ddev->event_lock, flags);
+	vrr_params = new_crtc_state->vrr_params;
+
  	if (surface) {
  		mod_freesync_handle_preflip(
  			dm->freesync_module,
@@ -4899,6 +4924,12 @@ static void update_freesync_state_on_stream(
  			new_stream,
  			flip_timestamp_in_us,
  			&vrr_params);
+
+		if (adev->family < AMDGPU_FAMILY_AI &&
+		    amdgpu_dm_vrr_active(new_crtc_state)) {
+			mod_freesync_handle_v_update(dm->freesync_module,
+						     new_stream, &vrr_params);
+		}
  	}
 
  	mod_freesync_build_vrr_infopacket(
@@ -4930,6 +4961,8 @@ static void update_freesync_state_on_stream(
  			      new_crtc_state->base.crtc->base.id,
  			      (int)new_crtc_state->base.vrr_enabled,
  			      (int)vrr_params.state);
+
+	spin_unlock_irqrestore(&adev->ddev->event_lock, flags);
  }
 
  static void pre_update_freesync_state_on_stream(
@@ -4937,8 +4970,10 @@ static void pre_update_freesync_state_on_stream(
  	struct dm_crtc_state *new_crtc_state)
  {
  	struct dc_stream_state *new_stream = new_crtc_state->stream;
-	struct mod_vrr_params vrr_params = new_crtc_state->vrr_params;
+	struct mod_vrr_params vrr_params;
  	struct mod_freesync_config config = new_crtc_state->freesync_config;
+	struct amdgpu_device *adev = dm->adev;
+	unsigned long flags;
 
  	if (!new_stream)
  		return;
@@ -4950,6 +4985,9 @@ static void pre_update_freesync_state_on_stream(
  	if (!new_stream->timing.h_total || !new_stream->timing.v_total)
  		return;
 
+	spin_lock_irqsave(&adev->ddev->event_lock, flags);
+	vrr_params = new_crtc_state->vrr_params;
+
  	if (new_crtc_state->vrr_supported &&
  	    config.min_refresh_in_uhz &&
  	    config.max_refresh_in_uhz) {

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static void pre_update_freesync_state_on_stream( · line 5014

Quoted 7 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -0
@@ -4970,6 +5008,7 @@ static void pre_update_freesync_state_on_stream(
  			sizeof(vrr_params.adjust)) != 0);
 
  	new_crtc_state->vrr_params = vrr_params;
+	spin_unlock_irqrestore(&adev->ddev->event_lock, flags);
  }
 
  static void amdgpu_dm_handle_vrr_transition(struct dm_crtc_state *old_state,

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

#7 lore raw

Re: [PATCH 3/3] drm/amd/display: Compensate for pre-DCE12 BTR-VRR hw limitations. (v2)

Quoted 60 lines · Nicholas
Quoted 25 lines · Mario Kleiner

Pre-DCE12 needs special treatment for BTR / low framerate compensation for more stable behaviour:

According to comments in the code and some testing on DCE-8 and DCE-11, DCE-11 and earlier only apply VTOTAL_MIN/MAX programming with a lag of one frame, so the special BTR hw programming for intermediate fixed duration frames must be done inside the current frame at flip submission in atomic commit tail, ie. one vblank earlier, and the fixed refresh intermediate frame mode must be also terminated one vblank earlier on pre-DCE12 display engines.

To achieve proper termination on < DCE-12 shift the point when the switch-back from fixed vblank duration to variable vblank duration happens from the start of VBLANK (vblank irq, as done on DCE-12+) to back-porch or end of VBLANK (handled by vupdate irq handler). We must leave the switch-back code inside VBLANK irq for DCE12+, as before.

Doing this, we get much better behaviour of BTR for up-sweeps, ie. going from short to long frame durations (~high to low fps) and for constant framerate flips, as tested on DCE-8 and DCE-11. Behaviour is still not quite as good as on DCN-1 though.

Quoted 7 lines

On down-sweeps, going from long to short frame durations (low fps to high fps) < DCE-12 is a little bit improved, although by far not as much as for up-sweeps and constant fps.

v2: Fix some wrong locking, as pointed out by Nicholas.

Still looks good to me, but I just noticed one other minor nitpick (sorry!)

Quoted 17 lines
---
  .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 45 +++++++++++++++++--
  1 file changed, 42 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -0
index 76b6e621793f..7241e1f3ebec 100644
@@ -364,6 +364,7 @@ static void dm_vupdate_high_irq(void *interrupt_params)
      struct amdgpu_device *adev = irq_params->adev;
      struct amdgpu_crtc *acrtc;
      struct dm_crtc_state *acrtc_state;
+     unsigned long flags;
 
      acrtc = get_crtc_by_otg_inst(adev, irq_params->irq_src - IRQ_TYPE_VUPDATE);
 

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static void dm_vupdate_high_irq(void *interrupt_params) · line 384

Quoted 3 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -0
@@ -381,6 +382,22 @@ static void dm_vupdate_high_irq(void *interrupt_params)
               */
              if (amdgpu_dm_vrr_active(acrtc_state))
                      drm_crtc_handle_vblank(&acrtc->base);

Can't this block be merged with the one below?

Quoted 4 lines

With the condition also changed to just:

if (acrtc_state->stream && adev->family < AMDGPU_FAMILY_AI)

        ...

Done. New series out, retested.
-mario

Quoted 124 lines

I also noticed that the crtc_state itself is always accessed unlocked for checking whether VRR is on/off which is probably a bug... but this patch shouldn't be the one to fix that. At the very least though it can leave things in a bit better shape like you've already done. Thanks!

Nicholas Kazlauskas

Quoted 116 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +40 -3
+
+             if (acrtc_state->stream && adev->family < AMDGPU_FAMILY_AI &&
+                 acrtc_state->vrr_params.supported &&
+                 acrtc_state->freesync_config.state == VRR_STATE_ACTIVE_VARIABLE) {
+                     spin_lock_irqsave(&adev->ddev->event_lock, flags);
+                     mod_freesync_handle_v_update(
+                         adev->dm.freesync_module,
+                         acrtc_state->stream,
+                         &acrtc_state->vrr_params);
+
+                     dc_stream_adjust_vmin_vmax(
+                         adev->dm.dc,
+                         acrtc_state->stream,
+                         &acrtc_state->vrr_params.adjust);
+                     spin_unlock_irqrestore(&adev->ddev->event_lock, flags);
+             }
      }
  }
 
@@ -390,6 +407,7 @@ static void dm_crtc_high_irq(void *interrupt_params)
      struct amdgpu_device *adev = irq_params->adev;
      struct amdgpu_crtc *acrtc;
      struct dm_crtc_state *acrtc_state;
+     unsigned long flags;
 
      acrtc = get_crtc_by_otg_inst(adev, irq_params->irq_src - IRQ_TYPE_VBLANK);
 
@@ -412,9 +430,10 @@ static void dm_crtc_high_irq(void *interrupt_params)
               */
              amdgpu_dm_crtc_handle_crc_irq(&acrtc->base);
 
-             if (acrtc_state->stream &&
+             if (acrtc_state->stream && adev->family >= AMDGPU_FAMILY_AI &&
                  acrtc_state->vrr_params.supported &&
                  acrtc_state->freesync_config.state == VRR_STATE_ACTIVE_VARIABLE) {
+                     spin_lock_irqsave(&adev->ddev->event_lock, flags);
                      mod_freesync_handle_v_update(
                              adev->dm.freesync_module,
                              acrtc_state->stream,
@@ -424,6 +443,7 @@ static void dm_crtc_high_irq(void *interrupt_params)
                              adev->dm.dc,
                              acrtc_state->stream,
                              &acrtc_state->vrr_params.adjust);
+                     spin_unlock_irqrestore(&adev->ddev->event_lock, flags);
              }
      }
  }
@@ -4878,8 +4898,10 @@ static void update_freesync_state_on_stream(
      struct dc_plane_state *surface,
      u32 flip_timestamp_in_us)
  {
-     struct mod_vrr_params vrr_params = new_crtc_state->vrr_params;
+     struct mod_vrr_params vrr_params;
      struct dc_info_packet vrr_infopacket = {0};
+     struct amdgpu_device *adev = dm->adev;
+     unsigned long flags;
 
      if (!new_stream)
              return;
@@ -4892,6 +4914,9 @@ static void update_freesync_state_on_stream(
      if (!new_stream->timing.h_total || !new_stream->timing.v_total)
              return;
 
+     spin_lock_irqsave(&adev->ddev->event_lock, flags);
+     vrr_params = new_crtc_state->vrr_params;
+
      if (surface) {
              mod_freesync_handle_preflip(
                      dm->freesync_module,
@@ -4899,6 +4924,12 @@ static void update_freesync_state_on_stream(
                      new_stream,
                      flip_timestamp_in_us,
                      &vrr_params);
+
+             if (adev->family < AMDGPU_FAMILY_AI &&
+                 amdgpu_dm_vrr_active(new_crtc_state)) {
+                     mod_freesync_handle_v_update(dm->freesync_module,
+                                                  new_stream, &vrr_params);
+             }
      }
 
      mod_freesync_build_vrr_infopacket(
@@ -4930,6 +4961,8 @@ static void update_freesync_state_on_stream(
                            new_crtc_state->base.crtc->base.id,
                            (int)new_crtc_state->base.vrr_enabled,
                            (int)vrr_params.state);
+
+     spin_unlock_irqrestore(&adev->ddev->event_lock, flags);
  }
 
  static void pre_update_freesync_state_on_stream(
@@ -4937,8 +4970,10 @@ static void pre_update_freesync_state_on_stream(
      struct dm_crtc_state *new_crtc_state)
  {
      struct dc_stream_state *new_stream = new_crtc_state->stream;
-     struct mod_vrr_params vrr_params = new_crtc_state->vrr_params;
+     struct mod_vrr_params vrr_params;
      struct mod_freesync_config config = new_crtc_state->freesync_config;
+     struct amdgpu_device *adev = dm->adev;
+     unsigned long flags;
 
      if (!new_stream)
              return;
@@ -4950,6 +4985,9 @@ static void pre_update_freesync_state_on_stream(
      if (!new_stream->timing.h_total || !new_stream->timing.v_total)
              return;
 
+     spin_lock_irqsave(&adev->ddev->event_lock, flags);
+     vrr_params = new_crtc_state->vrr_params;
+
      if (new_crtc_state->vrr_supported &&
          config.min_refresh_in_uhz &&
          config.max_refresh_in_uhz) {
@@ -4970,6 +5008,7 @@ static void pre_update_freesync_state_on_stream(
                      sizeof(vrr_params.adjust)) != 0);
 
Quoted 7 lines

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static void pre_update_freesync_state_on_stream( · line 5014

Quoted 6 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -0
      new_crtc_state->vrr_params = vrr_params;
+     spin_unlock_irqrestore(&adev->ddev->event_lock, flags);
  }
 
  static void amdgpu_dm_handle_vrr_transition(struct dm_crtc_state *old_state,

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