Skip to contentSkip to conversation

drm/amd/display: Keep FreeSync flip timing across plane resets

PATCH In review Davey Hughes 2 participants 4 messages Oct 28 – Nov 4

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

v2 cover drm/amd/display: Keep FreeSync flip timing across plane resets

On a 48-165 Hz FreeSync panel, fullscreen clients under KWin with HDR enabled and color accuracy set to "Prefer efficiency" run at about 51 fps instead of 60, with flips locked to the 13.45 ms BTR mid-point grid. That grid drifts upward at the rate expected if FreeSync takes the 32-bit microsecond timestamp itself as the last render time (3.46 us/s measured, 3.45 predicted).

KWin replaces the CRTC GAMMA_LUT blob on every commit in that mode, so every flip resets the plane and the new DC plane starts with zeroed flip timing. Patch 1 carries the timing over from the old DC plane, as DM already does for flip_addr (amdgpu_dm_plane_drm_plane_duplicate_state()) and for the BTR state itself (dm_irq_params.vrr_params). Patch 2 adds KUnit tests, kept separate so patch 1 backports to stable trees without the KUnit infrastructure.

Tested with KUnit (UML, all AMD display suites pass; the new timing tests fail without the fix) and on 7.2.11 with a Navi 31, an AW3423DWF over DP, KWin 6.8.1 and Mesa 26.2.5: 60 fps content now flips at a steady 16.65 ms instead of on the 13.45 ms grid, 30 fps content still gets BTR (30 fps, no 13.45 ms grid), and debugfs shows color_mgmt_changed=1 on the CRTC in every sampled commit. Not tested:
DCE, overlay planes, other compositors.

I am not sure of the current AI disclosure policy, but I will freely mention that I used Claude Opus 5.5 to help debug and write this patch + tests. I have tried to do my best to match existing style/procedures.

---
Changes in v2:
- Copy the flip timing in amdgpu_dm_commit_planes() instead of in
atomic check, so it can't race with the previous commit still writing
it (reported by Sashiko AI review)
- Skip the copy when the plane keeps its DC plane
- Add dm_plane_inherit_flip_time() in patch 1; patch 2 only exposes it
to KUnit
- Check the whole flip timing struct in the KUnit tests
- Link to v1: https://patch.msgid.link/[email protected]

---
Davey Hughes (2):
drm/amd/display: Keep FreeSync flip timing across plane resets drm/amd/display: Test FreeSync flip timing across plane resets

 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c  |  23 +++
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h  |   3 +
 .../amd/display/amdgpu_dm/tests/amdgpu_dm_test.c   | 188 +++++++++++++++++++++
 3 files changed, 214 insertions(+)

---
base-commit: 77f548b127c6de34ce271fa09ba270cb1ef9f2da
change-id: 20261027-freesync-plane-reset-time-5db657eebfde

Best regards,

Signature · 1 line
Davey Hughes <[email protected]>
#1 lore raw

PATCH v2 1/2 drm/amd/display: Keep FreeSync flip timing across plane resets

dm_update_plane_state() replaces the DC plane with a newly allocated one whenever the plane is reset. The new plane's flip timing is zero, and mod_freesync_handle_preflip() runs before DC stores the new plane's first flip timestamp, so FreeSync takes the 32-bit microsecond timestamp itself as the last render time: the monotonic clock modulo about 71.6 minutes.

On a panel with below-the-range compensation (BTR), that engages BTR and pins the frame time at the BTR mid-point (13.447 ms on a 48-165 Hz panel). A panel without BTR (max refresh below twice the min) goes through the fixed refresh path instead and locks to its max refresh after six frames.

It takes a reset on every flip to keep the panel there, and color management changes reset the plane. DRM sets color_mgmt_changed whenever a color property is given a different blob, even one with the same contents, and KWin 6.8.1 with HDR enabled and its color accuracy setting at "Prefer efficiency" sets a new GAMMA_LUT blob on every commit (current KWin master no longer does). Plane resets for CRTC color changes, added by
commit 7316c4ad2996 ("drm/amd/display: Reset planes for color management changes"), and later for plane color properties and colorops, made this reachable on every flip.

Copy the flip timing from the old DC plane into the new one when the plane stays on the same CRTC. Do it in amdgpu_dm_commit_planes() before the preflip, after drm_atomic_helper_wait_for_dependencies() has waited for the previous commit, so the copy holds that commit's flip and does not race with DC writing it. This covers both the BTR and the fixed refresh path. A plane that is newly enabled or moved to another CRTC still starts without history.

Fixes 180db303ff46 ("drm/amd/display: Add below the range support for FreeSync")
---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +22 -0
index bdabb4bf14da..7a0afe6d1b8a 100644
@@ -3848,6 +3848,25 @@ STATIC_IFN_KUNIT void dm_arm_vblank_event_pre_programming(struct amdgpu_crtc *ac
 }
 EXPORT_IF_KUNIT(dm_arm_vblank_event_pre_programming);
 
+/*
+ * FreeSync times each frame from the plane's previous flip, and a plane
+ * reset gives the new DC plane zeroed flip timing, so copy it over. Do
+ * this at commit time, not in atomic check: by then the previous commit
+ * has finished writing it.
+ */
+static void
+dm_plane_inherit_flip_time(struct dc_plane_state *dc_plane_state,
+			   struct drm_plane_state *old_plane_state,
+			   struct drm_plane_state *new_plane_state)
+{
+	struct dc_plane_state *old_dc_plane_state =
+		to_dm_plane_state(old_plane_state)->dc_state;
+
+	if (old_dc_plane_state && old_dc_plane_state != dc_plane_state &&
+	    old_plane_state->crtc == new_plane_state->crtc)
+		dc_plane_state->time = old_dc_plane_state->time;
+}
+
 static void amdgpu_dm_commit_planes(struct drm_atomic_commit *state,
 				    struct drm_device *dev,
 				    struct amdgpu_display_manager *dm,
@@ -3952,6 +3971,9 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_commit *state,
 		if (!dc_plane)
 			continue;
 
+		dm_plane_inherit_flip_time(dc_plane, old_plane_state,
+					   new_plane_state);
+
 		bundle->surface_updates[planes_count].surface = dc_plane;
 		if (new_pcrtc_state->color_mgmt_changed || new_plane_state->color_mgmt_changed) {
 			bundle->surface_updates[planes_count].gamma = &dc_plane->gamma_correction;
Signature · 1 line
2.56.0
#2 lore raw

PATCH v2 2/2 drm/amd/display: Test FreeSync flip timing across plane resets

In reply to Davey Hughes

KUnit can't call amdgpu_dm_commit_planes(), so test the flip timing copy through dm_plane_inherit_flip_time(), exposed to KUnit here. Test that a plane reset on the same CRTC keeps its flip timing, and that a newly enabled plane or one moved to another CRTC starts over.

Also flip a reset plane one 60 Hz frame after its last flip on a 48-165 Hz panel with BTR. With the inherited timing BTR stays off; without it FreeSync engages BTR.

---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c  |   3 +-
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h  |   3 +
 .../amd/display/amdgpu_dm/tests/amdgpu_dm_test.c   | 188 +++++++++++++++++++++
 3 files changed, 193 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +2 -1
index 7a0afe6d1b8a..b655a3333b7b 100644
@@ -3854,7 +3854,7 @@ EXPORT_IF_KUNIT(dm_arm_vblank_event_pre_programming);
  * this at commit time, not in atomic check: by then the previous commit
  * has finished writing it.
  */
-static void
+STATIC_IFN_KUNIT void
 dm_plane_inherit_flip_time(struct dc_plane_state *dc_plane_state,
 			   struct drm_plane_state *old_plane_state,
 			   struct drm_plane_state *new_plane_state)
@@ -3866,6 +3866,7 @@ dm_plane_inherit_flip_time(struct dc_plane_state *dc_plane_state,
 	    old_plane_state->crtc == new_plane_state->crtc)
 		dc_plane_state->time = old_dc_plane_state->time;
 }
+EXPORT_IF_KUNIT(dm_plane_inherit_flip_time);
 
 static void amdgpu_dm_commit_planes(struct drm_atomic_commit *state,
 				    struct drm_device *dev,
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h +3 -0
index 594d275918d5..18dce8244af1 100644
@@ -1266,6 +1266,9 @@ int dm_update_plane_state(struct dc *dc,
 			  bool enable,
 			  bool *lock_and_validation_needed,
 			  bool *is_top_most_overlay);
+void dm_plane_inherit_flip_time(struct dc_plane_state *dc_plane_state,
+				struct drm_plane_state *old_plane_state,
+				struct drm_plane_state *new_plane_state);
 int amdgpu_dm_atomic_check(struct drm_device *dev,
 			   struct drm_atomic_commit *state);
 void amdgpu_dm_mod_power_update_streams(struct drm_atomic_commit *state,
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c +188 -0

206 lines not on this page · raw message

Signature · 1 line
2.56.0
maintainer Reviewed-by on the v2 series
#3 lore raw
In reply to Davey Hughes
Quoted 24 lines · On 10/28/26 18:54, Davey Hughes via B4 Relay wrote:

On a 48-165 Hz FreeSync panel, fullscreen clients under KWin with HDR enabled and color accuracy set to "Prefer efficiency" run at about 51 fps instead of 60, with flips locked to the 13.45 ms BTR mid-point grid. That grid drifts upward at the rate expected if FreeSync takes the 32-bit microsecond timestamp itself as the last render time (3.46 us/s measured, 3.45 predicted).

KWin replaces the CRTC GAMMA_LUT blob on every commit in that mode, so every flip resets the plane and the new DC plane starts with zeroed flip timing. Patch 1 carries the timing over from the old DC plane, as DM already does for flip_addr (amdgpu_dm_plane_drm_plane_duplicate_state()) and for the BTR state itself (dm_irq_params.vrr_params). Patch 2 adds KUnit tests, kept separate so patch 1 backports to stable trees without the KUnit infrastructure.

Tested with KUnit (UML, all AMD display suites pass; the new timing tests fail without the fix) and on 7.2.11 with a Navi 31, an AW3423DWF over DP, KWin 6.8.1 and Mesa 26.2.5: 60 fps content now flips at a steady 16.65 ms instead of on the 13.45 ms grid, 30 fps content still gets BTR (30 fps, no 13.45 ms grid), and debugfs shows color_mgmt_changed=1 on the CRTC in every sampled commit. Not tested:
DCE, overlay planes, other compositors.

Quoted 4 lines

I am not sure of the current AI disclosure policy, but I will freely mention that I used Claude Opus 5.5 to help debug and write this patch + tests. I have tried to do my best to match existing style/procedures.

Series is

Harry

Quoted 27 lines

---
Changes in v2:
- Copy the flip timing in amdgpu_dm_commit_planes() instead of in
atomic check, so it can't race with the previous commit still writing
it (reported by Sashiko AI review)
- Skip the copy when the plane keeps its DC plane
- Add dm_plane_inherit_flip_time() in patch 1; patch 2 only exposes it
to KUnit
- Check the whole flip timing struct in the KUnit tests
- Link to v1: https://patch.msgid.link/[email protected]

---
Davey Hughes (2):
drm/amd/display: Keep FreeSync flip timing across plane resets drm/amd/display: Test FreeSync flip timing across plane resets

 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c  |  23 +++
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h  |   3 +
 .../amd/display/amdgpu_dm/tests/amdgpu_dm_test.c   | 188 +++++++++++++++++++++
 3 files changed, 214 insertions(+)

---
base-commit: 77f548b127c6de34ce271fa09ba270cb1ef9f2da
change-id: 20261027-freesync-plane-reset-time-5db657eebfde

Best regards,

Signature · 1 line
Davey Hughes <[email protected]>