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(-)
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);
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
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
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
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 = {
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); }
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)
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 = {
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)
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
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
dri-devel@lists.freedesktop.org