All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel@ffwll.ch>
To: Andrzej Hajda <a.hajda@samsung.com>
Cc: Marek Szyprowski <m.szyprowski@samsung.com>,
	dri-devel@lists.freedesktop.org,
	Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
Subject: Re: [RFC PATCH 1/6] drm: add helper for arming crtc completion event
Date: Thu, 29 Sep 2016 11:44:05 +0200	[thread overview]
Message-ID: <20160929094405.GI25432@dvetter-linux.ger.corp.intel.com> (raw)
In-Reply-To: <1474983379-852-2-git-send-email-a.hajda@samsung.com>

On Tue, Sep 27, 2016 at 03:36:14PM +0200, Andrzej Hajda wrote:
> A lot of drivers need to fire pageflip completion event at very next vblank
> interrupt. The patch adds helper to perform this operation.
> drm_crtc_arm_completion_event checks if there is an event to handle,
> if vblank reference get succeeds it arms the event, otherwise it sends the
> event immediately.
> 
> Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
> ---
>  drivers/gpu/drm/drm_irq.c | 25 +++++++++++++++++++++++++
>  include/drm/drm_irq.h     |  1 +
>  2 files changed, 26 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
> index 77f357b..313d323 100644
> --- a/drivers/gpu/drm/drm_irq.c
> +++ b/drivers/gpu/drm/drm_irq.c
> @@ -1053,6 +1053,31 @@ void drm_crtc_send_vblank_event(struct drm_crtc *crtc,
>  EXPORT_SYMBOL(drm_crtc_send_vblank_event);
>  
>  /**
> + * drm_crtc_arm_completion_event - conditionally arm crtc completion event
> + * @crtc: the source CRTC of the completion event
> + *
> + * A lot of drivers need to fire pageflip completion event at very next vblank
> + * interrupt. This helper tries to arm the event in case of successful vblank
> + * get otherwise it sends the event immediately.

This function is copypasted tons of times over all drivers because they
were broken, and this hack at least got the events working. But in general
this here is racy, and if Mario ever runs on your hw he'll get upset about
the wrong timings.

If we go with this (and I'm really not convinced it's a good idea) then it
should have real big warning that you should never use this in a new
driver.

> + */
> +void drm_crtc_arm_completion_event(struct drm_crtc *crtc)
> +{
> +	struct drm_pending_vblank_event *event = crtc->state->event;
> +
> +	if (event) {
> +		crtc->state->event = NULL;
> +
> +		spin_lock_irq(&crtc->dev->event_lock);
> +		if (drm_crtc_vblank_get(crtc) == 0)

This check here completely torpedoes the design principle of atomic
helpers that drivers always know the state of the crtc. Again I only did
this because I didn't want to buy hw&test it for all the drivers which got
this wrong.

> +			drm_crtc_arm_vblank_event(crtc, event);
> +		else
> +			drm_crtc_send_vblank_event(crtc, event);
> +		spin_unlock_irq(&crtc->dev->event_lock);
> +	}
> +}
> +EXPORT_SYMBOL(drm_crtc_arm_completion_event);

Maybe we need an EXPORT_SYMBOL_BROKEN for this .... btw the kerneldoc of
the functions you're called do explain that this is not as easy as it
seems. That's also something you throw under the rug here.
-Daniel

> +
> +/**
>   * drm_vblank_enable - enable the vblank interrupt on a CRTC
>   * @dev: DRM device
>   * @pipe: CRTC index
> diff --git a/include/drm/drm_irq.h b/include/drm/drm_irq.h
> index 2401b14..7bd9690 100644
> --- a/include/drm/drm_irq.h
> +++ b/include/drm/drm_irq.h
> @@ -144,6 +144,7 @@ extern void drm_crtc_send_vblank_event(struct drm_crtc *crtc,
>  				       struct drm_pending_vblank_event *e);
>  extern void drm_crtc_arm_vblank_event(struct drm_crtc *crtc,
>  				      struct drm_pending_vblank_event *e);
> +extern void drm_crtc_arm_completion_event(struct drm_crtc *crtc);
>  extern bool drm_handle_vblank(struct drm_device *dev, unsigned int pipe);
>  extern bool drm_crtc_handle_vblank(struct drm_crtc *crtc);
>  extern int drm_crtc_vblank_get(struct drm_crtc *crtc);
> -- 
> 2.7.4
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2016-09-29  9:44 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20160927133630eucas1p2929d2d5a0cd3c8d8ba40d94cf69801cf@eucas1p2.samsung.com>
2016-09-27 13:36 ` [RFC PATCH 0/6] add helper for arming crtc completion event Andrzej Hajda
     [not found]   ` <CGME20160927133636eucas1p139c88cf29008dc597dbbbcabc7fea9c9@eucas1p1.samsung.com>
2016-09-27 13:36     ` [RFC PATCH 1/6] drm: " Andrzej Hajda
2016-09-29  9:44       ` Daniel Vetter [this message]
2016-09-29 13:39         ` Andrzej Hajda
2016-09-29 14:24           ` Daniel Vetter
     [not found]   ` <CGME20160927133636eucas1p185e6bd5d9d324399078b61779225f4df@eucas1p1.samsung.com>
2016-09-27 13:36     ` [RFC PATCH 2/6] drm/hdlcd: use " Andrzej Hajda
     [not found]   ` <CGME20160927133637eucas1p149185d3cd9a657fa5a9ff6986db25f5f@eucas1p1.samsung.com>
2016-09-27 13:36     ` [RFC PATCH 3/6] drm/malidp: " Andrzej Hajda
     [not found]   ` <CGME20160927133637eucas1p1fda7edc6ed60b72c500b89f367f5cbf3@eucas1p1.samsung.com>
2016-09-27 13:36     ` [RFC PATCH 4/6] drm/fsl-dcu: " Andrzej Hajda
     [not found]   ` <CGME20160927133638eucas1p166ffd9c015f30b48e93dc59f21b57781@eucas1p1.samsung.com>
2016-09-27 13:36     ` [RFC PATCH 5/6] drm/hisilicon: " Andrzej Hajda
     [not found]   ` <CGME20160927133638eucas1p16614f59ca079786798cd497ecfeaa106@eucas1p1.samsung.com>
2016-09-27 13:36     ` [RFC PATCH 6/6] drm/sun4i: " Andrzej Hajda
2016-09-27 15:09       ` Alex Deucher
2016-09-29  9:44         ` Daniel Vetter

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=20160929094405.GI25432@dvetter-linux.ger.corp.intel.com \
    --to=daniel@ffwll.ch \
    --cc=a.hajda@samsung.com \
    --cc=b.zolnierkie@samsung.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=m.szyprowski@samsung.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.