Skip to contentSkip to conversation

Improvements to VRR below-the-range/low framerate compensation.

PATCH In review Mario Kleiner 5 participants 11 messages Apr 18, 2019 – Apr 26, 2019 4 messages not in the archive

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

Hi

This patch-series tries to improve amdgpu's below-the-range behaviour with Freesync, hopefully not only for my use case, but also for games etc.

Patch 1/4 adds a bit of debug output i found very useful, so maybe worth adding?

Patch 2/4 fixes a bug i found when reading over the freesync code.

Patches 3/4 and 4/4 are optimizations to improve stability in BTR.

My desired application of VRR for neuroscience/vision research is to control the timing of when frames show up onscreen, e.g., to show animations at different "unconventional" framerates, so i'm mostly interested in how well one can control the timing between successive OpenGL bufferswaps. This is a bit different from what a game wants to get out of VRR, probably closer to what a movie player might want to do.

I spent quite a bit of time testing how FreeSync behaves when flipping at a rate below the displays VRR minimum refresh rate.

For that, my own application was submitting glXSwapBuffers() flip requests at different fps rates / time delays between successive flips. The test script is for GNU/Octave + psychtoolbox-3, but in principle the C equivalent would be this pseudo-code:

for (i = 0; i < n; i++) {
// Wait for pending flip to complete, get pageflip timestamp t_last // of flip completion:
glXWaitForSbcOML(...., &t_last[i],...);

// Fetch some delay value until next flip tdelay[i] tdelay[i] = Some function of varying frame delay over samples.

  // Try to flip tdelay[i] secs after previous flip t_last[i]:
  t_next = t_last[i] + tdelay[i];
  clock_nanosleep(t_next);

// Flip
glXSwapBuffers(...);
}

For tdelay[i] i used different test profiles, e.g., on a display with a VRR range from 30 Hz to 144 Hz ~ 7 msecs - 33 msecs:

tdelay[i] = 0.050 // One flip each 50 msecs, want constant 20 fps. tdelay[i] = rand() // Some randomly chosen delay for each flip. tdelay[i] = 0.007 + some sin() sine profile of changing delays/fps. tdelay[i] = 0.007 + i * 0.001; linear increase in delay by 1 msec/flip,
starting at 7 msecs.
tdelay[i] = ... linear decrease by 1 msec/flip.. starting at 120 msecs.

etc. Then i plotted requested flip delays tdelay[] against actual flip delays (~ t_last[i+1] - t_last[i]) to see how well VRR can follow requested fps.

Inside the VRR range ~ 7 msecs - 33 msecs, Freesync behaved basically perfect with average errors of less than 0.1 msecs and jitter of less than 1 msec.

When going for tdelay's > 33 msecs, ie. when low framerate compensation/ BTR kicked in, my DCN-1 Raven Ridge APU behaved almost as well as within the VRR range (for reasonably smooth changes in fps). When doing the same on a DCE-8 and DCE-11 gpu, BTR made much bigger errors between what was requested and what was measured.

Patch 3/4 helps avoiding glitches on DCN when transitioning from VRR range to below min VRR range, and helps even more in avoiding glitches on DCE.

Patch 4/4 tries to improve behaviour on pre-DCE12. It helps quite a lot when testing on DCE-8 and DCE-11 as described in the commit message. This makes sense, as the code has some TODO comment about the different hw behaviour of pre-DCE12, mentioning that pre-DCE12 hw only responds to programming different VTOTAL_MIN/MAX values with a lag of 1 frame. The patch tries to work around this hardware limitation with some success. DCE8/11 behaviour is still not as good as DCN-1 behaviour, but at least it is not totally useless for my type of application with this patchset.

I don't have a Vega discrete gpu with DCE-12, but assume it would behave like DCN-1 if the comments in the code are correct? Therefore the patch switches BTR handling for < AMDGPU_FAMILY_AI vs. >= AMDGPU_FAMILY_AI.

Thanks,
-mario

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

#2 lore raw

PATCH 1/4 drm/amd/display: Add some debug output for VRR BTR.

Helps with debugging issues with low framerate compensation.

---
 .../amd/display/modules/freesync/freesync.c    | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
drivers/gpu/drm/amd/display/modules/freesync/freesync.c +18 -0
index 3d867e34f8b3..71274683da04 100644
@@ -1041,6 +1041,11 @@ void mod_freesync_handle_preflip(struct mod_freesync *mod_freesync,
 		average_render_time_in_us += last_render_time_in_us;
 		average_render_time_in_us /= DC_PLANE_UPDATE_TIMES_MAX;
 
+		DRM_DEBUG_DRIVER("vrr flip: avg %d us, last %d us, max %d us\n",
+				 average_render_time_in_us,
+				 last_render_time_in_us,
+				 in_out_vrr->max_duration_in_us);
+
 		if (in_out_vrr->btr.btr_enabled) {
 			apply_below_the_range(core_freesync,
 					stream,
@@ -1053,6 +1058,10 @@ void mod_freesync_handle_preflip(struct mod_freesync *mod_freesync,
 				in_out_vrr);
 		}
 
+		DRM_DEBUG_DRIVER("vrr btr_active:%d - num %d of dur %d us\n",
+				 in_out_vrr->btr.btr_active,
+				 in_out_vrr->btr.frames_to_insert,
+				 in_out_vrr->btr.inserted_duration_in_us);
 	}
 }
 
@@ -1090,11 +1099,17 @@ void mod_freesync_handle_v_update(struct mod_freesync *mod_freesync,
 				in_out_vrr->btr.inserted_duration_in_us);
 			in_out_vrr->adjust.v_total_max =
 				in_out_vrr->adjust.v_total_min;
+			DRM_DEBUG_DRIVER("btr start: c=%d, vtotal=%d\n",
+					 in_out_vrr->btr.frames_to_insert,
+					 in_out_vrr->adjust.v_total_min);
 		}
 
 		if (in_out_vrr->btr.frame_counter > 0)
 			in_out_vrr->btr.frame_counter--;
 
+		DRM_DEBUG_DRIVER("btr upd: count %d\n",
+				 in_out_vrr->btr.frame_counter);
+
 		/* Restore FreeSync */
 		if (in_out_vrr->btr.frame_counter == 0) {
 			in_out_vrr->adjust.v_total_min =
@@ -1103,6 +1118,9 @@ void mod_freesync_handle_v_update(struct mod_freesync *mod_freesync,
 			in_out_vrr->adjust.v_total_max =
 				calc_v_total_from_refresh(stream,
 				in_out_vrr->min_refresh_in_uhz);
+			DRM_DEBUG_DRIVER("btr end: vtotal_min=%d/max=%d\n",
+					 in_out_vrr->adjust.v_total_min,
+					 in_out_vrr->adjust.v_total_max);
 		}
 	}
 
Signature · 6 lines
2.20.1

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

Re: [PATCH 1/4] drm/amd/display: Add some debug output for VRR BTR.

Quoted 4 lines · Mario Kleiner

Helps with debugging issues with low framerate compensation.

---

This looks like it'd generate a ton of debug output (the flip stuff is already a bit too spammy).

But more importantly the DC and module code doesn't touch the debug prints directly.

DC has the DC_LOG_* defines but the modules shouldn't touch anything logger related.

Nicholas Kazlauskas

Quoted 50 lines
  .../amd/display/modules/freesync/freesync.c    | 18 ++++++++++++++++++
  1 file changed, 18 insertions(+)
drivers/gpu/drm/amd/display/modules/freesync/freesync.c +15 -0
index 3d867e34f8b3..71274683da04 100644
@@ -1041,6 +1041,11 @@ void mod_freesync_handle_preflip(struct mod_freesync *mod_freesync,
  		average_render_time_in_us += last_render_time_in_us;
  		average_render_time_in_us /= DC_PLANE_UPDATE_TIMES_MAX;
 
+		DRM_DEBUG_DRIVER("vrr flip: avg %d us, last %d us, max %d us\n",
+				 average_render_time_in_us,
+				 last_render_time_in_us,
+				 in_out_vrr->max_duration_in_us);
+
  		if (in_out_vrr->btr.btr_enabled) {
  			apply_below_the_range(core_freesync,
  					stream,
@@ -1053,6 +1058,10 @@ void mod_freesync_handle_preflip(struct mod_freesync *mod_freesync,
  				in_out_vrr);
  		}
 
+		DRM_DEBUG_DRIVER("vrr btr_active:%d - num %d of dur %d us\n",
+				 in_out_vrr->btr.btr_active,
+				 in_out_vrr->btr.frames_to_insert,
+				 in_out_vrr->btr.inserted_duration_in_us);
  	}
  }
 
@@ -1090,11 +1099,17 @@ void mod_freesync_handle_v_update(struct mod_freesync *mod_freesync,
  				in_out_vrr->btr.inserted_duration_in_us);
  			in_out_vrr->adjust.v_total_max =
  				in_out_vrr->adjust.v_total_min;
+			DRM_DEBUG_DRIVER("btr start: c=%d, vtotal=%d\n",
+					 in_out_vrr->btr.frames_to_insert,
+					 in_out_vrr->adjust.v_total_min);
  		}
 
  		if (in_out_vrr->btr.frame_counter > 0)
  			in_out_vrr->btr.frame_counter--;
 
+		DRM_DEBUG_DRIVER("btr upd: count %d\n",
+				 in_out_vrr->btr.frame_counter);
+
  		/* Restore FreeSync */
  		if (in_out_vrr->btr.frame_counter == 0) {
  			in_out_vrr->adjust.v_total_min =

drivers/gpu/drm/amd/display/modules/freesync/freesync.c void mod_freesync_handle_v_update(struct mod_freesync *mod_freesync, · line 1126

Quoted 9 lines
drivers/gpu/drm/amd/display/modules/freesync/freesync.c +3 -0
@@ -1103,6 +1118,9 @@ void mod_freesync_handle_v_update(struct mod_freesync *mod_freesync,
  			in_out_vrr->adjust.v_total_max =
  				calc_v_total_from_refresh(stream,
  				in_out_vrr->min_refresh_in_uhz);
+			DRM_DEBUG_DRIVER("btr end: vtotal_min=%d/max=%d\n",
+					 in_out_vrr->adjust.v_total_min,
+					 in_out_vrr->adjust.v_total_max);
  		}
  	}
 

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

#4 lore raw

PATCH 2/4 drm/amd/display: Fix and simplify apply_below_the_range()

In reply to a message not in the archive

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

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

Reviewed-by Nicholas Kazlauskas
#6 lore raw

Re: [PATCH 2/4] drm/amd/display: Fix and simplify apply_below_the_range()

Quoted 7 lines · Mario Kleiner

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.

Looks reasonable to me.

Quoted 12 lines
---
  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 +0 -0
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;

drivers/gpu/drm/amd/display/modules/freesync/freesync.c static void apply_below_the_range(struct core_freesync *core_freesync, · line 444

Quoted 10 lines
drivers/gpu/drm/amd/display/modules/freesync/freesync.c +2 -4
 
-		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 =

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

#7 lore raw

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

In reply to a message not in the archive

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

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

PATCH 4/4 drm/amd/display: Compensate for pre-DCE12 BTR-VRR hw limitations.

In reply to 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.

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.

---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 32 ++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +31 -1
index 76b6e621793f..9c8c94f82b35 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);
 		}
 	}
 }
@@ -4880,6 +4900,8 @@ static void update_freesync_state_on_stream(
 {
 	struct mod_vrr_params vrr_params = new_crtc_state->vrr_params;
 	struct dc_info_packet vrr_infopacket = {0};
+	struct amdgpu_device *adev = dm->adev;
+	unsigned long flags;
 
 	if (!new_stream)
 		return;
@@ -4899,6 +4921,14 @@ 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)) {
+			spin_lock_irqsave(&adev->ddev->event_lock, flags);
+			mod_freesync_handle_v_update(dm->freesync_module,
+						     new_stream, &vrr_params);
+			spin_unlock_irqrestore(&adev->ddev->event_lock, flags);
+		}
 	}
 
 	mod_freesync_build_vrr_infopacket(
Signature · 6 lines
2.20.1

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

Re: [PATCH 4/4] drm/amd/display: Compensate for pre-DCE12 BTR-VRR hw limitations.

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.

---

I did some debugging/testing with this patch and it certainly does improve things quite a bit for pre DCE12 (since this really should have been handled in VUPDATE before).

I have one comment inline below:

Quoted 77 lines
  .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 32 ++++++++++++++++++-
  1 file changed, 31 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +23 -1
index 76b6e621793f..9c8c94f82b35 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);
  		}
  	}
  }
@@ -4880,6 +4900,8 @@ static void update_freesync_state_on_stream(
  {
  	struct mod_vrr_params vrr_params = new_crtc_state->vrr_params;
  	struct dc_info_packet vrr_infopacket = {0};
+	struct amdgpu_device *adev = dm->adev;
+	unsigned long flags;
 
  	if (!new_stream)
  		return;
@@ -4899,6 +4921,14 @@ static void update_freesync_state_on_stream(
  			new_stream,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static void update_freesync_state_on_stream( · line 4931

Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +8 -0
  			flip_timestamp_in_us,
  			&vrr_params);
+
+		if (adev->family < AMDGPU_FAMILY_AI &&
+		    amdgpu_dm_vrr_active(new_crtc_state)) {
+			spin_lock_irqsave(&adev->ddev->event_lock, flags);
+			mod_freesync_handle_v_update(dm->freesync_module,
+						     new_stream, &vrr_params);
+			spin_unlock_irqrestore(&adev->ddev->event_lock, flags);
+		}

Shouldn't the locking here actually be around setting the new_crtc_state->adjust/vrr_infopacket/vrr_params?

I forgot the locking here before but it seems like we should be doing it there since all that state is accessed from the IRQs.

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static void update_freesync_state_on_stream( · line 4934

Quoted 4 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -0
  	}
 
  	mod_freesync_build_vrr_infopacket(

Nicholas Kazlauskas
_______________________________________________
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): 2a45d459-1484-3a99-d2cd-12633e56f2b4-5C7GfCeVMHo@public.gmane.org

#11 lore raw

Re: [PATCH 4/4] drm/amd/display: Compensate for pre-DCE12 BTR-VRR hw limitations.

Quoted 32 lines · Nicholas
Quoted 30 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.

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.

Quoted 7 lines
Quoted 2 lines

---

I did some debugging/testing with this patch and it certainly does improve things quite a bit for pre DCE12 (since this really should have been handled in VUPDATE before).

Do you know at which exact point in the frame cycle or vblank the new VTOTAL_MIN/MAX gets latched by the hw?

Btw. for reference i made a little git repo with a cleaned up version 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 Readme.md

Quoted 94 lines

I have one comment inline below:

Quoted 77 lines
  .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 32 ++++++++++++++++++-
  1 file changed, 31 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +23 -1
index 76b6e621793f..9c8c94f82b35 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);
              }
      }
  }
@@ -4880,6 +4900,8 @@ static void update_freesync_state_on_stream(
  {
      struct mod_vrr_params vrr_params = new_crtc_state->vrr_params;
      struct dc_info_packet vrr_infopacket = {0};
+     struct amdgpu_device *adev = dm->adev;
+     unsigned long flags;
 
      if (!new_stream)
              return;
@@ -4899,6 +4921,14 @@ static void update_freesync_state_on_stream(
                      new_stream,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static void update_freesync_state_on_stream( · line 4931

Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +8 -0
                      flip_timestamp_in_us,
                      &vrr_params);
+
+             if (adev->family < AMDGPU_FAMILY_AI &&
+                 amdgpu_dm_vrr_active(new_crtc_state)) {
+                     spin_lock_irqsave(&adev->ddev->event_lock, flags);
+                     mod_freesync_handle_v_update(dm->freesync_module,
+                                                  new_stream, &vrr_params);
+                     spin_unlock_irqrestore(&adev->ddev->event_lock, flags);
+             }

Shouldn't the locking here actually be around setting the new_crtc_state->adjust/vrr_infopacket/vrr_params?

Quoted 3 lines

I forgot the locking here before but it seems like we should be doing it there since all that state is accessed from the IRQs.

Yes, you're right. I think we need to put the whole function into the lock, and also the pre_update_freesync_state... function. I'll send out an updated patch after testing.

thanks,
-mario

Quoted 6 lines

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static void update_freesync_state_on_stream( · line 4934

Quoted 4 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -0
      }
 
      mod_freesync_build_vrr_infopacket(

Nicholas Kazlauskas

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

#12 lore raw
In reply to Mario Kleiner
Quoted 8 lines · Mario Kleiner

My desired application of VRR for neuroscience/vision research is to control the timing of when frames show up onscreen, e.g., to show animations at different "unconventional" framerates, so i'm mostly interested in how well one can control the timing between successive OpenGL bufferswaps. This is a bit different from what a game wants to get out of VRR, probably closer to what a movie player might want to do.

As discussed before, I expect that games which care about smooth animation will want to control the presentation time as well in the long run, so that they can make the presentation time match the simulation time corresponding to the frame contents.

There is already support for specifying the target presentation time in (at least, there might be more I'm not aware of) VDPAU, the Vulkan VK_GOOGLE_display_timing extension, and the X11 Present extension protocol (not actually implemented yet in xserver though).

Ideally, this should also be available in the kernel UAPI. That should allow hitting the target more accurately / reliably, and might also allow making better use of compensation mechanisms such as those touched by this series, since userspace can call into the kernel ahead of the target time, giving the kernel an opportunity to make adjustments earlier.

Since you have a strong use-case for this functionality, maybe you'd be interested in working on it?

Signature · 6 lines
Earthling Michel Dänzer               |              https://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
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): 65c584af-e2c6-a73a-a8f1-45bbe9ad527d-otUistvHUpPR7s880joybQ@public.gmane.org

#14 lore raw
Quoted 20 lines · Michel Dänzer
Quoted 8 lines · Mario Kleiner

My desired application of VRR for neuroscience/vision research is to control the timing of when frames show up onscreen, e.g., to show animations at different "unconventional" framerates, so i'm mostly interested in how well one can control the timing between successive OpenGL bufferswaps. This is a bit different from what a game wants to get out of VRR, probably closer to what a movie player might want to do.

As discussed before, I expect that games which care about smooth animation will want to control the presentation time as well in the long run, so that they can make the presentation time match the simulation time corresponding to the frame contents.

There is already support for specifying the target presentation time in (at least, there might be more I'm not aware of) VDPAU, the Vulkan VK_GOOGLE_display_timing extension, and the X11 Present extension protocol (not actually implemented yet in xserver though).

Quoted 10 lines

Ideally, this should also be available in the kernel UAPI. That should allow hitting the target more accurately / reliably, and might also allow making better use of compensation mechanisms such as those touched by this series, since userspace can call into the kernel ahead of the target time, giving the kernel an opportunity to make adjustments earlier.

Since you have a strong use-case for this functionality, maybe you'd be interested in working on it?

This would be a good real-world userspace application that takes advantage of this.

There were some threads before in the original VRR RFC and patch series that discussion this, but I think the summary was that most people interested were in favor of a timestamp in nanoseconds on the CRTC.

My thoughts on the matter would be that the driver would be enforced not to present the frame any earlier than the timestamp given. If the driver isn't capable of doing that then it can return -EINVAL (ie. userspace asks for a really large timestamp and the driver would have to stall forever in order to display it).

There could still be some leeway in terms of when the frame could be displayed. Maybe another property could be also used to specify the upper bound for presentation.

I would imagine any properties created here would be optional to drivers to add. In hindsight, the VRR CRTC property should probably have been optional as well.

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