All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH 0/6] add helper for arming crtc completion event
       [not found] <CGME20160927133630eucas1p2929d2d5a0cd3c8d8ba40d94cf69801cf@eucas1p2.samsung.com>
@ 2016-09-27 13:36 ` Andrzej Hajda
       [not found]   ` <CGME20160927133636eucas1p139c88cf29008dc597dbbbcabc7fea9c9@eucas1p1.samsung.com>
                     ` (5 more replies)
  0 siblings, 6 replies; 12+ messages in thread
From: Andrzej Hajda @ 2016-09-27 13:36 UTC (permalink / raw)
  To: Daniel Vetter; +Cc: Marek Szyprowski, dri-devel, Bartlomiej Zolnierkiewicz

Hi,

During playing with vblanks on Exynos I have encountered
common pattern of arming completion event. I have put it
into core helper.
Since I am not sure if it will be accepted I have not added
subsystem maintainers to CC.

I have tested it on Exynos with some pending patches.
Other drivers were only compile tested.

Regards
Andrzej


Andrzej Hajda (6):
  drm: add helper for arming crtc completion event
  drm/hdlcd: use helper for arming crtc completion event
  drm/malidp: use helper for arming crtc completion event
  drm/fsl-dcu: use helper for arming crtc completion event
  drm/hisilicon: use helper for arming crtc completion event
  drm/sun4i: use helper for arming crtc completion event

 drivers/gpu/drm/arm/hdlcd_crtc.c                | 13 +------------
 drivers/gpu/drm/arm/malidp_drv.c                | 13 +------------
 drivers/gpu/drm/drm_irq.c                       | 25 +++++++++++++++++++++++++
 drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c      | 13 +------------
 drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c | 12 +-----------
 drivers/gpu/drm/sun4i/sun4i_crtc.c              | 12 +-----------
 include/drm/drm_irq.h                           |  1 +
 7 files changed, 31 insertions(+), 58 deletions(-)

-- 
2.7.4

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [RFC PATCH 1/6] drm: add helper for arming crtc completion event
       [not found]   ` <CGME20160927133636eucas1p139c88cf29008dc597dbbbcabc7fea9c9@eucas1p1.samsung.com>
@ 2016-09-27 13:36     ` Andrzej Hajda
  2016-09-29  9:44       ` Daniel Vetter
  0 siblings, 1 reply; 12+ messages in thread
From: Andrzej Hajda @ 2016-09-27 13:36 UTC (permalink / raw)
  To: Daniel Vetter; +Cc: Marek Szyprowski, dri-devel, Bartlomiej Zolnierkiewicz

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.
+ */
+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)
+			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);
+
+/**
  * 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

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [RFC PATCH 2/6] drm/hdlcd: use helper for arming crtc completion event
       [not found]   ` <CGME20160927133636eucas1p185e6bd5d9d324399078b61779225f4df@eucas1p1.samsung.com>
@ 2016-09-27 13:36     ` Andrzej Hajda
  0 siblings, 0 replies; 12+ messages in thread
From: Andrzej Hajda @ 2016-09-27 13:36 UTC (permalink / raw)
  To: Daniel Vetter; +Cc: Marek Szyprowski, dri-devel, Bartlomiej Zolnierkiewicz

Replace custom code with core helper.

Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
---
 drivers/gpu/drm/arm/hdlcd_crtc.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/arm/hdlcd_crtc.c b/drivers/gpu/drm/arm/hdlcd_crtc.c
index 48019ae..a17ddb5 100644
--- a/drivers/gpu/drm/arm/hdlcd_crtc.c
+++ b/drivers/gpu/drm/arm/hdlcd_crtc.c
@@ -182,18 +182,7 @@ static int hdlcd_crtc_atomic_check(struct drm_crtc *crtc,
 static void hdlcd_crtc_atomic_begin(struct drm_crtc *crtc,
 				    struct drm_crtc_state *state)
 {
-	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)
-			drm_crtc_arm_vblank_event(crtc, event);
-		else
-			drm_crtc_send_vblank_event(crtc, event);
-		spin_unlock_irq(&crtc->dev->event_lock);
-	}
+	drm_crtc_arm_completion_event(crtc);
 }
 
 static const struct drm_crtc_helper_funcs hdlcd_crtc_helper_funcs = {
-- 
2.7.4

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [RFC PATCH 3/6] drm/malidp: use helper for arming crtc completion event
       [not found]   ` <CGME20160927133637eucas1p149185d3cd9a657fa5a9ff6986db25f5f@eucas1p1.samsung.com>
@ 2016-09-27 13:36     ` Andrzej Hajda
  0 siblings, 0 replies; 12+ messages in thread
From: Andrzej Hajda @ 2016-09-27 13:36 UTC (permalink / raw)
  To: Daniel Vetter; +Cc: Marek Szyprowski, dri-devel, Bartlomiej Zolnierkiewicz

Replace custom code with core helper.

Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
---
 drivers/gpu/drm/arm/malidp_drv.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/arm/malidp_drv.c b/drivers/gpu/drm/arm/malidp_drv.c
index 82171d2..e8bd8b0 100644
--- a/drivers/gpu/drm/arm/malidp_drv.c
+++ b/drivers/gpu/drm/arm/malidp_drv.c
@@ -63,7 +63,6 @@ static void malidp_output_poll_changed(struct drm_device *drm)
 
 static void malidp_atomic_commit_hw_done(struct drm_atomic_state *state)
 {
-	struct drm_pending_vblank_event *event;
 	struct drm_device *drm = state->dev;
 	struct malidp_drm *malidp = drm->dev_private;
 	int ret = malidp_set_and_wait_config_valid(drm);
@@ -71,17 +70,7 @@ static void malidp_atomic_commit_hw_done(struct drm_atomic_state *state)
 	if (ret)
 		DRM_DEBUG_DRIVER("timed out waiting for updated configuration\n");
 
-	event = malidp->crtc.state->event;
-	if (event) {
-		malidp->crtc.state->event = NULL;
-
-		spin_lock_irq(&drm->event_lock);
-		if (drm_crtc_vblank_get(&malidp->crtc) == 0)
-			drm_crtc_arm_vblank_event(&malidp->crtc, event);
-		else
-			drm_crtc_send_vblank_event(&malidp->crtc, event);
-		spin_unlock_irq(&drm->event_lock);
-	}
+	drm_crtc_arm_completion_event(&malidp->crtc);
 	drm_atomic_helper_commit_hw_done(state);
 }
 
-- 
2.7.4

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [RFC PATCH 4/6] drm/fsl-dcu: use helper for arming crtc completion event
       [not found]   ` <CGME20160927133637eucas1p1fda7edc6ed60b72c500b89f367f5cbf3@eucas1p1.samsung.com>
@ 2016-09-27 13:36     ` Andrzej Hajda
  0 siblings, 0 replies; 12+ messages in thread
From: Andrzej Hajda @ 2016-09-27 13:36 UTC (permalink / raw)
  To: Daniel Vetter; +Cc: Marek Szyprowski, dri-devel, Bartlomiej Zolnierkiewicz

Replace custom code with core helper.

Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
---
 drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c
index 3371635..8121bfd 100644
--- a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c
+++ b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c
@@ -25,18 +25,7 @@
 static void fsl_dcu_drm_crtc_atomic_flush(struct drm_crtc *crtc,
 					  struct drm_crtc_state *old_crtc_state)
 {
-	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)
-			drm_crtc_arm_vblank_event(crtc, event);
-		else
-			drm_crtc_send_vblank_event(crtc, event);
-		spin_unlock_irq(&crtc->dev->event_lock);
-	}
+	drm_crtc_arm_completion_event(crtc);
 }
 
 static void fsl_dcu_drm_disable_crtc(struct drm_crtc *crtc)
-- 
2.7.4

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [RFC PATCH 5/6] drm/hisilicon: use helper for arming crtc completion event
       [not found]   ` <CGME20160927133638eucas1p166ffd9c015f30b48e93dc59f21b57781@eucas1p1.samsung.com>
@ 2016-09-27 13:36     ` Andrzej Hajda
  0 siblings, 0 replies; 12+ messages in thread
From: Andrzej Hajda @ 2016-09-27 13:36 UTC (permalink / raw)
  To: Daniel Vetter; +Cc: Marek Szyprowski, dri-devel, Bartlomiej Zolnierkiewicz

Replace custom code with core helper.

Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
---
 drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
index c3707d4..26f8091 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
@@ -532,7 +532,6 @@ static void ade_crtc_atomic_flush(struct drm_crtc *crtc,
 {
 	struct ade_crtc *acrtc = to_ade_crtc(crtc);
 	struct ade_hw_ctx *ctx = acrtc->ctx;
-	struct drm_pending_vblank_event *event = crtc->state->event;
 	void __iomem *base = ctx->base;
 
 	/* only crtc is enabled regs take effect */
@@ -542,16 +541,7 @@ static void ade_crtc_atomic_flush(struct drm_crtc *crtc,
 		writel(ADE_ENABLE, base + ADE_EN);
 	}
 
-	if (event) {
-		crtc->state->event = NULL;
-
-		spin_lock_irq(&crtc->dev->event_lock);
-		if (drm_crtc_vblank_get(crtc) == 0)
-			drm_crtc_arm_vblank_event(crtc, event);
-		else
-			drm_crtc_send_vblank_event(crtc, event);
-		spin_unlock_irq(&crtc->dev->event_lock);
-	}
+	drm_crtc_arm_completion_event(crtc);
 }
 
 static const struct drm_crtc_helper_funcs ade_crtc_helper_funcs = {
-- 
2.7.4

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [RFC PATCH 6/6] drm/sun4i: use helper for arming crtc completion event
       [not found]   ` <CGME20160927133638eucas1p16614f59ca079786798cd497ecfeaa106@eucas1p1.samsung.com>
@ 2016-09-27 13:36     ` Andrzej Hajda
  2016-09-27 15:09       ` Alex Deucher
  0 siblings, 1 reply; 12+ messages in thread
From: Andrzej Hajda @ 2016-09-27 13:36 UTC (permalink / raw)
  To: Daniel Vetter; +Cc: Marek Szyprowski, dri-devel, Bartlomiej Zolnierkiewicz

Replace custom code with core helper.

Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
---
 drivers/gpu/drm/sun4i/sun4i_crtc.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/sun4i/sun4i_crtc.c b/drivers/gpu/drm/sun4i/sun4i_crtc.c
index 4a19221..238c08c 100644
--- a/drivers/gpu/drm/sun4i/sun4i_crtc.c
+++ b/drivers/gpu/drm/sun4i/sun4i_crtc.c
@@ -51,22 +51,12 @@ static void sun4i_crtc_atomic_flush(struct drm_crtc *crtc,
 {
 	struct sun4i_crtc *scrtc = drm_crtc_to_sun4i_crtc(crtc);
 	struct sun4i_drv *drv = scrtc->drv;
-	struct drm_pending_vblank_event *event = crtc->state->event;
 
 	DRM_DEBUG_DRIVER("Committing plane changes\n");
 
 	sun4i_backend_commit(drv->backend);
 
-	if (event) {
-		crtc->state->event = NULL;
-
-		spin_lock_irq(&crtc->dev->event_lock);
-		if (drm_crtc_vblank_get(crtc) == 0)
-			drm_crtc_arm_vblank_event(crtc, event);
-		else
-			drm_crtc_send_vblank_event(crtc, event);
-		spin_unlock_irq(&crtc->dev->event_lock);
-	}
+	drm_crtc_arm_completion_event(crtc);
 }
 
 static void sun4i_crtc_disable(struct drm_crtc *crtc)
-- 
2.7.4

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [RFC PATCH 6/6] drm/sun4i: use helper for arming crtc completion event
  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
  0 siblings, 1 reply; 12+ messages in thread
From: Alex Deucher @ 2016-09-27 15:09 UTC (permalink / raw)
  To: Andrzej Hajda
  Cc: Bartlomiej Zolnierkiewicz, Maling list - DRI developers,
	Marek Szyprowski

On Tue, Sep 27, 2016 at 9:36 AM, Andrzej Hajda <a.hajda@samsung.com> wrote:
> Replace custom code with core helper.
>
> Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>

Nice cleanup.  Series is:
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>

> ---
>  drivers/gpu/drm/sun4i/sun4i_crtc.c | 12 +-----------
>  1 file changed, 1 insertion(+), 11 deletions(-)
>
> diff --git a/drivers/gpu/drm/sun4i/sun4i_crtc.c b/drivers/gpu/drm/sun4i/sun4i_crtc.c
> index 4a19221..238c08c 100644
> --- a/drivers/gpu/drm/sun4i/sun4i_crtc.c
> +++ b/drivers/gpu/drm/sun4i/sun4i_crtc.c
> @@ -51,22 +51,12 @@ static void sun4i_crtc_atomic_flush(struct drm_crtc *crtc,
>  {
>         struct sun4i_crtc *scrtc = drm_crtc_to_sun4i_crtc(crtc);
>         struct sun4i_drv *drv = scrtc->drv;
> -       struct drm_pending_vblank_event *event = crtc->state->event;
>
>         DRM_DEBUG_DRIVER("Committing plane changes\n");
>
>         sun4i_backend_commit(drv->backend);
>
> -       if (event) {
> -               crtc->state->event = NULL;
> -
> -               spin_lock_irq(&crtc->dev->event_lock);
> -               if (drm_crtc_vblank_get(crtc) == 0)
> -                       drm_crtc_arm_vblank_event(crtc, event);
> -               else
> -                       drm_crtc_send_vblank_event(crtc, event);
> -               spin_unlock_irq(&crtc->dev->event_lock);
> -       }
> +       drm_crtc_arm_completion_event(crtc);
>  }
>
>  static void sun4i_crtc_disable(struct drm_crtc *crtc)
> --
> 2.7.4
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [RFC PATCH 1/6] drm: add helper for arming crtc completion event
  2016-09-27 13:36     ` [RFC PATCH 1/6] drm: " Andrzej Hajda
@ 2016-09-29  9:44       ` Daniel Vetter
  2016-09-29 13:39         ` Andrzej Hajda
  0 siblings, 1 reply; 12+ messages in thread
From: Daniel Vetter @ 2016-09-29  9:44 UTC (permalink / raw)
  To: Andrzej Hajda; +Cc: Marek Szyprowski, dri-devel, Bartlomiej Zolnierkiewicz

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [RFC PATCH 6/6] drm/sun4i: use helper for arming crtc completion event
  2016-09-27 15:09       ` Alex Deucher
@ 2016-09-29  9:44         ` Daniel Vetter
  0 siblings, 0 replies; 12+ messages in thread
From: Daniel Vetter @ 2016-09-29  9:44 UTC (permalink / raw)
  To: Alex Deucher
  Cc: Bartlomiej Zolnierkiewicz, Maling list - DRI developers,
	Marek Szyprowski

On Tue, Sep 27, 2016 at 11:09:53AM -0400, Alex Deucher wrote:
> On Tue, Sep 27, 2016 at 9:36 AM, Andrzej Hajda <a.hajda@samsung.com> wrote:
> > Replace custom code with core helper.
> >
> > Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
> 
> Nice cleanup.  Series is:
> Reviewed-by: Alex Deucher <alexander.deucher@amd.com>

Replied to the helper patch with the reasons, but as-is nack.
-Daniel

> 
> > ---
> >  drivers/gpu/drm/sun4i/sun4i_crtc.c | 12 +-----------
> >  1 file changed, 1 insertion(+), 11 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/sun4i/sun4i_crtc.c b/drivers/gpu/drm/sun4i/sun4i_crtc.c
> > index 4a19221..238c08c 100644
> > --- a/drivers/gpu/drm/sun4i/sun4i_crtc.c
> > +++ b/drivers/gpu/drm/sun4i/sun4i_crtc.c
> > @@ -51,22 +51,12 @@ static void sun4i_crtc_atomic_flush(struct drm_crtc *crtc,
> >  {
> >         struct sun4i_crtc *scrtc = drm_crtc_to_sun4i_crtc(crtc);
> >         struct sun4i_drv *drv = scrtc->drv;
> > -       struct drm_pending_vblank_event *event = crtc->state->event;
> >
> >         DRM_DEBUG_DRIVER("Committing plane changes\n");
> >
> >         sun4i_backend_commit(drv->backend);
> >
> > -       if (event) {
> > -               crtc->state->event = NULL;
> > -
> > -               spin_lock_irq(&crtc->dev->event_lock);
> > -               if (drm_crtc_vblank_get(crtc) == 0)
> > -                       drm_crtc_arm_vblank_event(crtc, event);
> > -               else
> > -                       drm_crtc_send_vblank_event(crtc, event);
> > -               spin_unlock_irq(&crtc->dev->event_lock);
> > -       }
> > +       drm_crtc_arm_completion_event(crtc);
> >  }
> >
> >  static void sun4i_crtc_disable(struct drm_crtc *crtc)
> > --
> > 2.7.4
> >
> > _______________________________________________
> > dri-devel mailing list
> > dri-devel@lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [RFC PATCH 1/6] drm: add helper for arming crtc completion event
  2016-09-29  9:44       ` Daniel Vetter
@ 2016-09-29 13:39         ` Andrzej Hajda
  2016-09-29 14:24           ` Daniel Vetter
  0 siblings, 1 reply; 12+ messages in thread
From: Andrzej Hajda @ 2016-09-29 13:39 UTC (permalink / raw)
  To: Daniel Vetter; +Cc: Marek Szyprowski, dri-devel, Bartlomiej Zolnierkiewicz

Hi Daniel,


On 29.09.2016 11:44, Daniel Vetter wrote:
> 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.

Could you explain what is racy here? I am not vblank expert, but the code
for me looked more or less OK.

>
> 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.

It looked to me as an easy copy/paste cleaning :)
Anyway I would like to have correct solution, at least in case of exynos.

>
>> + */
>> +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.

If you mean driver should know that getting vblank should be possible
or not this code could be probably parametrized, for example:

drm_crtc_handle_completion_event(struct drm_crtc *crtc, bool send_immediately)


>> +			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

After quick look I have not found these kerneldocs, where can read about it.

Regards
Andrzej

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [RFC PATCH 1/6] drm: add helper for arming crtc completion event
  2016-09-29 13:39         ` Andrzej Hajda
@ 2016-09-29 14:24           ` Daniel Vetter
  0 siblings, 0 replies; 12+ messages in thread
From: Daniel Vetter @ 2016-09-29 14:24 UTC (permalink / raw)
  To: Andrzej Hajda; +Cc: Marek Szyprowski, dri-devel, Bartlomiej Zolnierkiewicz

On Thu, Sep 29, 2016 at 3:39 PM, Andrzej Hajda <a.hajda@samsung.com> wrote:
>
>>> +                    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
>
> After quick look I have not found these kerneldocs, where can read about it.

Oops, it's indeed not there. It should be right next to
arm_vblank_event as a real big warning, but looks like I only put that
in some commit message and not into the docs itself :( Will fix asap.
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2016-09-29 14:24 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [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
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

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.