drm/vmwgfx: Use DRM's vblank timer
Subsystems (3)
Thomas Zimmermann
maintainerv2 cover drm/vmwgfx: Use DRM's vblank timer
Replace vmwgfx's vblank timer with DRM's shared implementation. The common code is mostly equivalent, but provides additional protection against concurrent changes to the vblank counter.
Patches 1 and 2 align vmwgfx with the shared code, so that it can be converted easily.
The conversion is in patch 3. It replaces vmwgfx's custom timer with calls to DRM's vblank interfaces. Initialization happens internally.
This series should get some more testing.
v2:
- patch 3: fix vblank cancalling in CRTC cleanup (Zack)
- patch 2: mention timer restart in commit message (Zack)
Thomas Zimmermann (3):
drm/vmwgfx: Determine lock-waiting timeout from vblank state drm/vmwgfx: Move vblank handling into separate helper drm/vmwgfx: Convert to DRM vblank timers
drivers/gpu/drm/vmwgfx/vmwgfx_kms.h | 2 - drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c | 1 + drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c | 1 + drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c | 1 + drivers/gpu/drm/vmwgfx/vmwgfx_vkms.c | 70 ++++++++-------------------- drivers/gpu/drm/vmwgfx/vmwgfx_vkms.h | 2 +- 6 files changed, 24 insertions(+), 53 deletions(-)
Signature · 1 line
2.54.0
Thomas Zimmermann
maintainerPATCH v2 1/3 drm/vmwgfx: Determine lock-waiting timeout from vblank state
Use the calculated duration of a frame as stored in the vblank state for the lock-waiting timeout. Decouples the waiting from the details of the vblank implementation. Both values should be equal.
This will be helpful for replacing vmwgfx's vblank timer with DRM's common implementation.
--- drivers/gpu/drm/vmwgfx/vmwgfx_vkms.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_vkms.c +6 -2
@@ -516,9 +516,13 @@ vmw_vkms_set_crc_surface(struct drm_crtc *crtc,static inline u64 vmw_vkms_lock_max_wait_ns (struct vmw_display_unit *du) { -s64 nsecs =ktime_to_ns (du->vkms.period_ns); +struct drm_crtc *crtc = &du->crtc; +struct drm_vblank_crtc *vblank =drm_crtc_vblank_crtc (crtc); + +if (!vblank || !vblank->framedur_ns) +return NSEC_PER_SEC /60 ;/* disabled; assume 60 Hz */ -return (nsecs >0 ) ? nsecs :16666666 ; +return vblank->framedur_ns; }/**
Signature · 1 line
2.54.0
Thomas Zimmermann
maintainerPATCH v2 2/3 drm/vmwgfx: Move vblank handling into separate helper
In reply to Thomas ZimmermannDecouple vblank handling from the underlying hrtimer. This will be helpful for replacing vmwgfx's vblank timer with DRM's common implementation.
The new helper vmw_vkms_handle_vblank_timeout() can later be used as callback for DRM's handle_vblank call as-is. The helper also keeps the current semantics for restarting the timer. It returns true to restart the next vblank timeout even if it could not acquire vmwgfx's vblank lock.
The remaining code in vmw_vkms_vblank_simulate() will be replaced by the DRM implementation in a later patch.
v2:
- clarify return-value semantics in commit message (Zack)
--- drivers/gpu/drm/vmwgfx/vmwgfx_vkms.c | 37 +++++++++++++++++++--------- drivers/gpu/drm/vmwgfx/vmwgfx_vkms.h | 1 + 2 files changed, 26 insertions(+), 12 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_vkms.c +25 -12
@@ -157,27 +157,19 @@ crc_generate_worker(struct work_struct *work)drm_crtc_add_crc_entry (crtc, true, frame_start++, &crc32); } -static enum hrtimer_restart -vmw_vkms_vblank_simulate (struct hrtimer *timer) +bool +vmw_vkms_handle_vblank_timeout (struct drm_crtc *crtc) { - struct vmw_display_unit *du = container_of(timer, struct vmw_display_unit, vkms.timer); -struct drm_crtc *crtc = &du->crtc; +struct vmw_display_unit *du =vmw_crtc_to_du (crtc);struct vmw_private *vmw =vmw_priv (crtc->dev);bool has_surface = false; -u64 ret_overrun;bool locked, ret; - ret_overrun =hrtimer_forward_now (&du->vkms.timer, - du->vkms.period_ns); -if (ret_overrun !=1 ) -drm_dbg_driver (crtc->dev,"vblank timer missed %lld frames.\n" , - ret_overrun -1 ); - locked =vmw_vkms_vblank_trylock (crtc); ret =drm_crtc_handle_vblank (crtc);WARN_ON (!ret);if (!locked) -return HRTIMER_RESTART ; +return true; has_surface = du->vkms.surface !=NULL ;vmw_vkms_unlock (crtc);
@@ -200,6 +192,27 @@ vmw_vkms_vblank_simulate(struct hrtimer *timer)drm_dbg_driver (crtc->dev,"Composer worker already queued\n" ); } +return true; +} + +static enum hrtimer_restart +vmw_vkms_vblank_simulate (struct hrtimer *timer) +{ + struct vmw_display_unit *du = container_of(timer, struct vmw_display_unit, vkms.timer); +struct drm_crtc *crtc = &du->crtc; +u64 ret_overrun; +bool success; + + ret_overrun =hrtimer_forward_now (&du->vkms.timer, + du->vkms.period_ns); +if (ret_overrun !=1 ) +drm_dbg_driver (crtc->dev,"vblank timer missed %lld frames.\n" , + ret_overrun -1 ); + + success =vmw_vkms_handle_vblank_timeout (crtc); +if (!success) +return HRTIMER_NORESTART ; +return HRTIMER_RESTART ; }
drivers/gpu/drm/vmwgfx/vmwgfx_vkms.h +1 -0
@@ -45,6 +45,7 @@ bool vmw_vkms_modeset_lock_relaxed(struct drm_crtc *crtc);bool vmw_vkms_vblank_trylock (struct drm_crtc *crtc);void vmw_vkms_unlock (struct drm_crtc *crtc); +bool vmw_vkms_handle_vblank_timeout (struct drm_crtc *crtc); bool vmw_vkms_get_vblank_timestamp(struct drm_crtc *crtc, int *max_error, ktime_t *vblank_time,
Signature · 1 line
2.54.0
Thomas Zimmermann
maintainerPATCH v2 3/3 drm/vmwgfx: Convert to DRM vblank timers
In reply to Thomas ZimmermannReplace vmwgfx's vblank timer with DRM's common implementation. The timer handling is almost identical with a few additional bug fixes in the common code.
Replace most of vmwgfx's vmw_vkms_get_vblank_timestamp() with the shared helper drm_crtc_vblank_get_vblank_timeout(). The common helper also works in the presence of delayed vblank timeouts that modify the vblank counter concurrently.
Set the timeout handler to vmw_vkms_handle_vblank_timeout(). In addition to handling vblank events, this function also controls CRC generation.
Remove all the hrtimer-related code from vmwgfx. DRM vblank timers provides this.
v2:
- only cancel vblank timer in CRTC cleanup if vkms_enabled (Zack)
--- drivers/gpu/drm/vmwgfx/vmwgfx_kms.h | 2 - drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c | 1 + drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c | 1 + drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c | 1 + drivers/gpu/drm/vmwgfx/vmwgfx_vkms.c | 65 ++++------------------------ drivers/gpu/drm/vmwgfx/vmwgfx_vkms.h | 1 - 6 files changed, 12 insertions(+), 59 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_kms.h +0 -2
@@ -322,8 +322,6 @@ struct vmw_display_unit {struct {struct work_struct crc_generator_work; -struct hrtimer timer; -ktime_t period_ns;/* protects concurrent access to the vblank handler */ atomic_t atomic_lock;
drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c +1 -0
@@ -402,6 +402,7 @@ static const struct drm_crtc_helper_funcs vmw_ldu_crtc_helper_funcs = { .atomic_flush = vmw_vkms_crtc_atomic_flush, .atomic_enable = vmw_vkms_crtc_atomic_enable, .atomic_disable = vmw_vkms_crtc_atomic_disable, + .handle_vblank_timeout = vmw_vkms_handle_vblank_timeout, };
drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c +1 -0
@@ -797,6 +797,7 @@ static const struct drm_crtc_helper_funcs vmw_sou_crtc_helper_funcs = { .atomic_flush = vmw_vkms_crtc_atomic_flush, .atomic_enable = vmw_vkms_crtc_atomic_enable, .atomic_disable = vmw_sou_crtc_atomic_disable, + .handle_vblank_timeout = vmw_vkms_handle_vblank_timeout, };
drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c +1 -0
@@ -1515,6 +1515,7 @@ static const struct drm_crtc_helper_funcs vmw_stdu_crtc_helper_funcs = { .atomic_flush = vmw_stdu_crtc_atomic_flush, .atomic_enable = vmw_vkms_crtc_atomic_enable, .atomic_disable = vmw_stdu_crtc_atomic_disable, + .handle_vblank_timeout = vmw_vkms_handle_vblank_timeout, };
drivers/gpu/drm/vmwgfx/vmwgfx_vkms.c +9 -56
109 lines not on this page · raw message
drivers/gpu/drm/vmwgfx/vmwgfx_vkms.h +0 -1
@@ -29,7 +29,6 @@#ifndef VMWGFX_VKMS_H_ #define VMWGFX_VKMS_H_ -#include <linux/hrtimer_types.h> #include <linux/types.h> struct drm_atomic_state ;
Signature · 1 line
2.54.0
Quoted 30 lines · Thomas Zimmermann
Replace vmwgfx's vblank timer with DRM's shared implementation. The common code is mostly equivalent, but provides additional protection against concurrent changes to the vblank counter.
Patches 1 and 2 align vmwgfx with the shared code, so that it can be converted easily.
The conversion is in patch 3. It replaces vmwgfx's custom timer with calls to DRM's vblank interfaces. Initialization happens internally.
This series should get some more testing.
v2:
- patch 3: fix vblank cancalling in CRTC cleanup (Zack)
- patch 2: mention timer restart in commit message (Zack)Thomas Zimmermann (3):
drm/vmwgfx: Determine lock-waiting timeout from vblank state drm/vmwgfx: Move vblank handling into separate helper drm/vmwgfx: Convert to DRM vblank timersdrivers/gpu/drm/vmwgfx/vmwgfx_kms.h | 2 - drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c | 1 + drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c | 1 + drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c | 1 + drivers/gpu/drm/vmwgfx/vmwgfx_vkms.c | 70 ++++++++-------------------- drivers/gpu/drm/vmwgfx/vmwgfx_vkms.h | 2 +- 6 files changed, 24 insertions(+), 53 deletions(-)
Quoted 2 lines
--
2.54.0
Looks great! Feel free to push through drm-misc-next or I can do it for you if you prefer.
z
Thomas Zimmermann
maintainerHi
Am 28.04.26 um 07:54 schrieb Zack Rusin:
Quoted 30 lines · Thomas Zimmermann
Quoted 29 lines
Replace vmwgfx's vblank timer with DRM's shared implementation. The common code is mostly equivalent, but provides additional protection against concurrent changes to the vblank counter.
Patches 1 and 2 align vmwgfx with the shared code, so that it can be converted easily.
The conversion is in patch 3. It replaces vmwgfx's custom timer with calls to DRM's vblank interfaces. Initialization happens internally.
This series should get some more testing.
v2:
- patch 3: fix vblank cancalling in CRTC cleanup (Zack)
- patch 2: mention timer restart in commit message (Zack)Thomas Zimmermann (3):
drm/vmwgfx: Determine lock-waiting timeout from vblank state drm/vmwgfx: Move vblank handling into separate helper drm/vmwgfx: Convert to DRM vblank timersdrivers/gpu/drm/vmwgfx/vmwgfx_kms.h | 2 - drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c | 1 + drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c | 1 + drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c | 1 + drivers/gpu/drm/vmwgfx/vmwgfx_vkms.c | 70 ++++++++-------------------- drivers/gpu/drm/vmwgfx/vmwgfx_vkms.h | 2 +- 6 files changed, 24 insertions(+), 53 deletions(-)
Quoted 5 lines
Quoted 2 lines
--
2.54.0Looks great! Feel free to push through drm-misc-next or I can do it for you if you prefer.
I'll merge it in a few days if no further reviews come in.
Quoted 2 lines
Reviewed-by Zack Rusin <[email protected]>
Thanks a lot.
Best regards
Thomas
Quoted 2 lines
z
Signature · 6 lines
-- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
Thomas Zimmermann
maintainerHi
Am 28.04.26 um 07:54 schrieb Zack Rusin:
Quoted 30 lines · Thomas Zimmermann
Quoted 29 lines
Replace vmwgfx's vblank timer with DRM's shared implementation. The common code is mostly equivalent, but provides additional protection against concurrent changes to the vblank counter.
Patches 1 and 2 align vmwgfx with the shared code, so that it can be converted easily.
The conversion is in patch 3. It replaces vmwgfx's custom timer with calls to DRM's vblank interfaces. Initialization happens internally.
This series should get some more testing.
v2:
- patch 3: fix vblank cancalling in CRTC cleanup (Zack)
- patch 2: mention timer restart in commit message (Zack)Thomas Zimmermann (3):
drm/vmwgfx: Determine lock-waiting timeout from vblank state drm/vmwgfx: Move vblank handling into separate helper drm/vmwgfx: Convert to DRM vblank timersdrivers/gpu/drm/vmwgfx/vmwgfx_kms.h | 2 - drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c | 1 + drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c | 1 + drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c | 1 + drivers/gpu/drm/vmwgfx/vmwgfx_vkms.c | 70 ++++++++-------------------- drivers/gpu/drm/vmwgfx/vmwgfx_vkms.h | 2 +- 6 files changed, 24 insertions(+), 53 deletions(-)
Quoted 7 lines
Quoted 2 lines
--
2.54.0Looks great! Feel free to push through drm-misc-next or I can do it for you if you prefer.
Reviewed-by Zack Rusin <[email protected]>
Merged now. Thanks a lot.
Best regards
Thomas
Quoted 2 lines
z
Signature · 6 lines
-- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)