dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: Prike Liang <Prike.Liang@amd.com>
Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	Alexander.Deucher@amd.com, Christian.Koenig@amd.com,
	Harry.Wentland@amd.com, Sunpeng.Li@amd.com, tzimmermann@suse.de
Subject: Re: [PATCH v2 2/5] drm/vblank: Add drm_crtc_wait_one_vblank_interruptible()
Date: Thu, 19 Nov 2026 16:33:19 +0200	[thread overview]
Message-ID: <av8Ir1li1-eeoTcQ@intel.com> (raw)
In-Reply-To: <20261119082424.554841-2-Prike.Liang@amd.com>

On Thu, Nov 19, 2026 at 04:24:21PM +0800, Prike Liang wrote:
> drm_crtc_wait_one_vblank() waits uninterruptibly and only gives up after
> one second. That doesn't suit a wait that userspace asks for, such as
> FBIO_WAITFORVSYNC: if no vblank interrupt arrives, the task sleeps in D
> state for the whole second and can't be interrupted, not even by
> SIGKILL.
> 
> Add drm_crtc_wait_one_vblank_interruptible(), a DRM-internal variant of
> drm_crtc_wait_one_vblank() that a signal can interrupt. It returns
> -ERESTARTSYS in that case and otherwise behaves like
> drm_crtc_wait_one_vblank(), which includes ending the wait when vblank
> is turned off. Move the wait to __drm_crtc_wait_one_vblank(), which
> implements both functions.
> 
> drm_crtc_wait_one_vblank() doesn't change, and drivers keep using it.
> The new function has no user yet. The next patch uses it in
> drm_client_modeset_wait_for_vblank().
> 
> Version update:
> 1) https://lists.freedesktop.org/archives/dri-devel/2026-November/616727.html
> 
> Cc: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
> Assisted-by: Copilot:claude-opus-5.5
> Signed-off-by: Prike Liang <Prike.Liang@amd.com>

Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>

> ---
>  drivers/gpu/drm/drm_internal.h |  1 +
>  drivers/gpu/drm/drm_vblank.c   | 64 ++++++++++++++++++++++++----------
>  2 files changed, 47 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_internal.h b/drivers/gpu/drm/drm_internal.h
> index f893b1e3a596..2be21c20eb78 100644
> --- a/drivers/gpu/drm/drm_internal.h
> +++ b/drivers/gpu/drm/drm_internal.h
> @@ -115,6 +115,7 @@ void drm_vblank_disable_and_save(struct drm_device *dev, unsigned int pipe);
>  int drm_vblank_get(struct drm_device *dev, unsigned int pipe);
>  void drm_vblank_put(struct drm_device *dev, unsigned int pipe);
>  u64 drm_vblank_count(struct drm_device *dev, unsigned int pipe);
> +int drm_crtc_wait_one_vblank_interruptible(struct drm_crtc *crtc);
>  
>  /* drm_vblank_work.c */
>  static inline void drm_vblank_flush_worker(struct drm_vblank_crtc *vblank)
> diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
> index 54118eb1413c..5e247663978a 100644
> --- a/drivers/gpu/drm/drm_vblank.c
> +++ b/drivers/gpu/drm/drm_vblank.c
> @@ -1297,22 +1297,12 @@ void drm_crtc_vblank_put(struct drm_crtc *crtc)
>  }
>  EXPORT_SYMBOL(drm_crtc_vblank_put);
>  
> -/**
> - * drm_crtc_wait_one_vblank - wait for one vblank
> - * @crtc: DRM crtc
> - *
> - * This waits for one vblank to pass on @crtc, using the irq driver interfaces.
> - * It is a failure to call this when the vblank irq for @crtc is disabled, e.g.
> - * due to lack of driver support or because the crtc is off. The wait also fails
> - * if drm_crtc_vblank_off() disables the vblank irq before a vblank passes.
> - *
> - * Returns: 0 on success, negative error on failures.
> - */
> -int drm_crtc_wait_one_vblank(struct drm_crtc *crtc)
> +static int __drm_crtc_wait_one_vblank(struct drm_crtc *crtc, bool interruptible)
>  {
>  	struct drm_device *dev = crtc->dev;
>  	int pipe = drm_crtc_index(crtc);
>  	struct drm_vblank_crtc *vblank = drm_crtc_vblank_crtc(crtc);
> +	long timeout = msecs_to_jiffies(1000);
>  	int ret;
>  	u64 last;
>  
> @@ -1323,14 +1313,22 @@ int drm_crtc_wait_one_vblank(struct drm_crtc *crtc)
>  
>  	last = drm_vblank_count(dev, pipe);
>  
> -	ret = wait_event_timeout(vblank->queue,
> -				 last != drm_vblank_count(dev, pipe) ||
> -				 !READ_ONCE(vblank->enabled),
> -				 msecs_to_jiffies(1000));
> +	if (interruptible)
> +		timeout = wait_event_interruptible_timeout(vblank->queue,
> +							   last != drm_vblank_count(dev, pipe) ||
> +							   !READ_ONCE(vblank->enabled),
> +							   timeout);
> +	else
> +		timeout = wait_event_timeout(vblank->queue,
> +					     last != drm_vblank_count(dev, pipe) ||
> +					     !READ_ONCE(vblank->enabled),
> +					     timeout);
>  
> -	drm_WARN(dev, ret == 0, "vblank wait timed out on crtc %i\n", pipe);
> +	drm_WARN(dev, timeout == 0, "vblank wait timed out on crtc %i\n", pipe);
>  
> -	if (!ret)
> +	if (timeout < 0)
> +		ret = timeout;
> +	else if (!timeout)
>  		ret = -ETIMEDOUT;
>  	else if (last == drm_vblank_count(dev, pipe))
>  		ret = -EINVAL; /* drm_crtc_vblank_off() ended the wait */
> @@ -1341,8 +1339,38 @@ int drm_crtc_wait_one_vblank(struct drm_crtc *crtc)
>  
>  	return ret;
>  }
> +
> +/**
> + * drm_crtc_wait_one_vblank - wait for one vblank
> + * @crtc: DRM crtc
> + *
> + * This waits for one vblank to pass on @crtc, using the irq driver interfaces.
> + * It is a failure to call this when the vblank irq for @crtc is disabled, e.g.
> + * due to lack of driver support or because the crtc is off. The wait also fails
> + * if drm_crtc_vblank_off() disables the vblank irq before a vblank passes.
> + *
> + * Returns: 0 on success, negative error on failures.
> + */
> +int drm_crtc_wait_one_vblank(struct drm_crtc *crtc)
> +{
> +	return __drm_crtc_wait_one_vblank(crtc, false);
> +}
>  EXPORT_SYMBOL(drm_crtc_wait_one_vblank);
>  
> +/**
> + * drm_crtc_wait_one_vblank_interruptible - wait for one vblank, interruptibly
> + * @crtc: DRM crtc
> + *
> + * Like drm_crtc_wait_one_vblank(), but a signal interrupts the wait.
> + *
> + * Returns: 0 on success, -ERESTARTSYS if a signal interrupted the wait,
> + * negative error on other failures.
> + */
> +int drm_crtc_wait_one_vblank_interruptible(struct drm_crtc *crtc)
> +{
> +	return __drm_crtc_wait_one_vblank(crtc, true);
> +}
> +
>  /**
>   * drm_crtc_vblank_off - disable vblank events on a CRTC
>   * @crtc: CRTC in question
> -- 
> 2.34.1

-- 
Ville Syrjälä
Intel

  reply	other threads:[~2026-11-19 14:33 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19  8:24 [PATCH v2 1/5] drm/vblank: Stop drm_crtc_wait_one_vblank() when vblank is turned off Prike Liang
2026-11-19  8:24 ` [PATCH v2 2/5] drm/vblank: Add drm_crtc_wait_one_vblank_interruptible() Prike Liang
2026-11-19 14:33   ` Ville Syrjälä [this message]
2026-11-19  8:24 ` [PATCH v2 3/5] drm/client: Make the FBIO_WAITFORVSYNC vblank wait interruptible Prike Liang
2026-11-19 14:40   ` Ville Syrjälä
2026-11-19  8:24 ` [PATCH v2 4/5] drm/amd/display: send the flip event right away if vblank is off Prike Liang
2026-11-19  8:24 ` [PATCH v2 5/5] drm/amd/display: turn vblank off in DRM across GPU reset Prike Liang
2026-11-19  8:56   ` sashiko-bot
2026-11-19 14:31 ` [PATCH v2 1/5] drm/vblank: Stop drm_crtc_wait_one_vblank() when vblank is turned off Ville Syrjälä

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=av8Ir1li1-eeoTcQ@intel.com \
    --to=ville.syrjala@linux.intel.com \
    --cc=Alexander.Deucher@amd.com \
    --cc=Christian.Koenig@amd.com \
    --cc=Harry.Wentland@amd.com \
    --cc=Prike.Liang@amd.com \
    --cc=Sunpeng.Li@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox