Skip to contentSkip to conversation

handle vblank when disabling ctc with interrupt disabled (was [PATCH v2] drm/imx: correct order of crtc disable)

PATCH Superseded Robert Beckett 4 participants 13 messages Jun 25, 2019 – Jun 26, 2019

Subsystems (3)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 cover handle vblank when disabling ctc with interrupt disabled (was [PATCH v2] drm/imx: correct order of crtc disable)

Handle vblank event sent to signal crtc disable while the backend vblank interrupt has already been disabled by vblank_disable_fn.

Fixes a474478642d5 ("drm/imx: fix crtc vblank state regression")
Fixes 68036b08b91bc ("drm/vblank: Do not update vblank count if interrupts are already disabled.")
Fixes 5f2f911578fb ("drm/imx: atomic phase 3 step 1: Use atomic configuration")

Changes since v2:
Split up the patch in to smaller pieces.
Add warning when about to send bogus vblank event.
Update vblank to best guess info during drm_vblank_disable_and_save.

Robert Beckett (4):
drm/vblank: warn on sending stale event
drm/imx: notify drm core before sending event during crtc disable drm/vblank: estimate vblank while disabling vblank if interrupt
disabled
drm/imx: only send event on crtc disable if kept disabled

 drivers/gpu/drm/drm_vblank.c     | 33 +++++++++++++++++++++++++++++++-
 drivers/gpu/drm/imx/ipuv3-crtc.c |  6 +++---
 2 files changed, 35 insertions(+), 4 deletions(-)
Signature · 1 line
2.18.0
#1 lore raw

PATCH v3 1/4 drm/vblank: warn on sending stale event

Warn when about to send stale vblank info and add advice to documentation on how to avoid.

---
 drivers/gpu/drm/drm_vblank.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/gpu/drm/drm_vblank.c +17 -0
index 603ab105125d..7dabb2bdb733 100644
@@ -918,6 +918,19 @@ EXPORT_SYMBOL(drm_crtc_arm_vblank_event);
  *
  * See drm_crtc_arm_vblank_event() for a helper which can be used in certain
  * situation, especially to send out events for atomic commit operations.
+ *
+ * Care should be taken to avoid stale timestamps. If:
+ *   - your driver has vblank support (i.e. dev->num_crtcs > 0)
+ *   - the vblank irq is off (i.e. no one called drm_crtc_vblank_get)
+ *   - from the vblank code's pov the pipe is still running (i.e. not
+ *     in-between a drm_crtc_vblank_off()/on() pair)
+ * If all of these conditions hold then drm_crtc_send_vblank_event is
+ * going to give you a garbage timestamp and and sequence number (the last
+ * recorded before the irq was disabled). If you call drm_crtc_vblank_get/put
+ * around it, or after vblank_off, then either of those will have rolled things
+ * forward for you.
+ * So, drivers should call drm_crtc_vblank_off() before this function in their
+ * crtc atomic_disable handlers.
  */
 void drm_crtc_send_vblank_event(struct drm_crtc *crtc,
 				struct drm_pending_vblank_event *e)
@@ -925,8 +938,12 @@ void drm_crtc_send_vblank_event(struct drm_crtc *crtc,
 	struct drm_device *dev = crtc->dev;
 	u64 seq;
 	unsigned int pipe = drm_crtc_index(crtc);
+	struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
 	ktime_t now;
 
+	WARN_ONCE(dev->num_crtcs > 0 && !vblank->enabled && !vblank->inmodeset,
+		  "sending stale vblank info\n");
+
 	if (dev->num_crtcs > 0) {
 		seq = drm_vblank_count_and_time(dev, pipe, &now);
 	} else {
Signature · 1 line
2.18.0
Reviewed-by on v3 1/4
#2 lore raw

Re: [PATCH v3 1/4] drm/vblank: warn on sending stale event

Quoted 13 lines · Robert Beckett

Warn when about to send stale vblank info and add advice to documentation on how to avoid.

---
 drivers/gpu/drm/drm_vblank.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/gpu/drm/drm_vblank.c +0 -0
index 603ab105125d..7dabb2bdb733 100644

drivers/gpu/drm/drm_vblank.c EXPORT_SYMBOL(drm_crtc_arm_vblank_event); · line 924

Quoted 7 lines
drivers/gpu/drm/drm_vblank.c +4 -0
@@ -918,6 +918,19 @@ EXPORT_SYMBOL(drm_crtc_arm_vblank_event);
  *
  * See drm_crtc_arm_vblank_event() for a helper which can be used in certain
  * situation, especially to send out events for atomic commit operations.
+ *
+ * Care should be taken to avoid stale timestamps. If:
+ *   - your driver has vblank support (i.e. dev->num_crtcs > 0)
+ *   - the vblank irq is off (i.e. no one called drm_crtc_vblank_get)

drm_crtc_vblank_get() so it becomes a neat hyperlink.

drivers/gpu/drm/drm_vblank.c EXPORT_SYMBOL(drm_crtc_arm_vblank_event); · line 926

Quoted 2 lines
drivers/gpu/drm/drm_vblank.c +2 -0
+ *   - from the vblank code's pov the pipe is still running (i.e. not
+ *     in-between a drm_crtc_vblank_off()/on() pair)

Not sure the above will lead to great markup, maybe spell out the drm_crtc_vblank_on() and maybe make it a bit clearer like "i.e. not after the call to drm_crtc_vblank_off() but before the next call to drm_crtc_vblank_on()" so it's clear which said of this pair we're talking about.

drivers/gpu/drm/drm_vblank.c EXPORT_SYMBOL(drm_crtc_arm_vblank_event); · line 927

Quoted 1 line
drivers/gpu/drm/drm_vblank.c +1 -0
+ * If all of these conditions hold then drm_crtc_send_vblank_event is

style nit: the enumeration is one sentence (and and oxford comman missing but whatever), but you don't continue it here. Also, does the enumeration look pretty in the htmldocs output?

drivers/gpu/drm/drm_vblank.c EXPORT_SYMBOL(drm_crtc_arm_vblank_event); · line 931

Quoted 4 lines
drivers/gpu/drm/drm_vblank.c +4 -0
+ * going to give you a garbage timestamp and and sequence number (the last
+ * recorded before the irq was disabled). If you call drm_crtc_vblank_get/put
+ * around it, or after vblank_off, then either of those will have rolled things
+ * forward for you.

Again pls fix the markup so all the function reference stick out and work.

drivers/gpu/drm/drm_vblank.c EXPORT_SYMBOL(drm_crtc_arm_vblank_event); · line 933

Quoted 2 lines
drivers/gpu/drm/drm_vblank.c +2 -0
+ * So, drivers should call drm_crtc_vblank_off() before this function in their
+ * crtc atomic_disable handlers.

Imo this sentence here is needed but a bit confusing, and we have it documented already in the atomic_disable hook.

Other option would be to list all the places where a driver might want to call this and how they could get it wrong, which imo doesn't make sense.

With the nits addressed:

Quoted 19 lines
drivers/gpu/drm/drm_vblank.c +4 -0
  */
 void drm_crtc_send_vblank_event(struct drm_crtc *crtc,
 				struct drm_pending_vblank_event *e)
@@ -925,8 +938,12 @@ void drm_crtc_send_vblank_event(struct drm_crtc *crtc,
 	struct drm_device *dev = crtc->dev;
 	u64 seq;
 	unsigned int pipe = drm_crtc_index(crtc);
+	struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
 	ktime_t now;
 
+	WARN_ONCE(dev->num_crtcs > 0 && !vblank->enabled && !vblank->inmodeset,
+		  "sending stale vblank info\n");
+
 	if (dev->num_crtcs > 0) {
 		seq = drm_vblank_count_and_time(dev, pipe, &now);
 	} else {
Signature · 1 line
2.18.0
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#3 lore raw

Re: [PATCH v3 1/4] drm/vblank: warn on sending stale event

Quoted 39 lines · Daniel Vetter
Quoted 13 lines · Robert Beckett

Warn when about to send stale vblank info and add advice to documentation on how to avoid.

---
 drivers/gpu/drm/drm_vblank.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/gpu/drm/drm_vblank.c +0 -0
index 603ab105125d..7dabb2bdb733 100644

drivers/gpu/drm/drm_vblank.c EXPORT_SYMBOL(drm_crtc_arm_vblank_event); · line 924

Quoted 7 lines
drivers/gpu/drm/drm_vblank.c +4 -0
@@ -918,6 +918,19 @@ EXPORT_SYMBOL(drm_crtc_arm_vblank_event);
  *
  * See drm_crtc_arm_vblank_event() for a helper which can be used in certain
  * situation, especially to send out events for atomic commit operations.
+ *
+ * Care should be taken to avoid stale timestamps. If:
+ *   - your driver has vblank support (i.e. dev->num_crtcs > 0)
+ *   - the vblank irq is off (i.e. no one called drm_crtc_vblank_get)

drm_crtc_vblank_get() so it becomes a neat hyperlink.

drivers/gpu/drm/drm_vblank.c EXPORT_SYMBOL(drm_crtc_arm_vblank_event); · line 926

Quoted 2 lines
drivers/gpu/drm/drm_vblank.c +2 -0
+ *   - from the vblank code's pov the pipe is still running (i.e. not
+ *     in-between a drm_crtc_vblank_off()/on() pair)

Not sure the above will lead to great markup, maybe spell out the drm_crtc_vblank_on() and maybe make it a bit clearer like "i.e. not after the call to drm_crtc_vblank_off() but before the next call to drm_crtc_vblank_on()" so it's clear which said of this pair we're talking about.

drivers/gpu/drm/drm_vblank.c EXPORT_SYMBOL(drm_crtc_arm_vblank_event); · line 927

Quoted 1 line
drivers/gpu/drm/drm_vblank.c +1 -0
+ * If all of these conditions hold then drm_crtc_send_vblank_event is

style nit: the enumeration is one sentence (and and oxford comman missing but whatever), but you don't continue it here. Also, does the enumeration look pretty in the htmldocs output?

Quoted 6 lines

drivers/gpu/drm/drm_vblank.c EXPORT_SYMBOL(drm_crtc_arm_vblank_event); · line 931

Quoted 4 lines
drivers/gpu/drm/drm_vblank.c +4 -0
+ * going to give you a garbage timestamp and and sequence number (the last
+ * recorded before the irq was disabled). If you call drm_crtc_vblank_get/put
+ * around it, or after vblank_off, then either of those will have rolled things
+ * forward for you.

Again pls fix the markup so all the function reference stick out and work.

One more style nit: s/you/drivers/, so maybe:

"Drivers must either hold a vblank reference acquired through drm_crtc_vblank_get() or the vblank must have been shut off by calling drm_crtc_vblank_off()." Those functions then have in turn links and hints what you also need to do, like not forget to call drm_crtc_vblank_put().

Quoted 38 lines

drivers/gpu/drm/drm_vblank.c EXPORT_SYMBOL(drm_crtc_arm_vblank_event); · line 933

Quoted 3 lines
drivers/gpu/drm/drm_vblank.c +2 -0
+ * So, drivers should call drm_crtc_vblank_off() before this function in their
+ * crtc atomic_disable handlers.

Imo this sentence here is needed but a bit confusing, and we have it documented already in the atomic_disable hook.

Other option would be to list all the places where a driver might want to call this and how they could get it wrong, which imo doesn't make sense.

With the nits addressed:

Quoted 19 lines
drivers/gpu/drm/drm_vblank.c +4 -0
  */
 void drm_crtc_send_vblank_event(struct drm_crtc *crtc,
 				struct drm_pending_vblank_event *e)
@@ -925,8 +938,12 @@ void drm_crtc_send_vblank_event(struct drm_crtc *crtc,
 	struct drm_device *dev = crtc->dev;
 	u64 seq;
 	unsigned int pipe = drm_crtc_index(crtc);
+	struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
 	ktime_t now;
 
+	WARN_ONCE(dev->num_crtcs > 0 && !vblank->enabled && !vblank->inmodeset,
+		  "sending stale vblank info\n");
+
 	if (dev->num_crtcs > 0) {
 		seq = drm_vblank_count_and_time(dev, pipe, &now);
 	} else {
Signature · 1 line
2.18.0
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#4 lore raw

PATCH v3 2/4 drm/imx: notify drm core before sending event during crtc disable

In reply to Robert Beckett

Notify drm core before sending pending events during crtc disable. This fixes the first event after disable having an old stale timestamp by having drm_crtc_vblank_off update the timestamp to now.

This was seen while debugging weston log message:
Warning: computed repaint delay is insane: -8212 msec

This occured due to:
1. driver starts up
2. fbcon comes along and restores fbdev, enabling vblank
3. vblank_disable_fn fires via timer disabling vblank, keeping vblank seq number and time set at current value
(some time later)
4. weston starts and does a modeset
5. atomic commit disables crtc while it does the modeset
6. ipu_crtc_atomic_disable sends vblank with old seq number and time

Fixes a474478642d5 ("drm/imx: fix crtc vblank state regression")
---
 drivers/gpu/drm/imx/ipuv3-crtc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/imx/ipuv3-crtc.c +2 -2
index 9cc1d678674f..e04d6efff1b5 100644
@@ -91,14 +91,14 @@ static void ipu_crtc_atomic_disable(struct drm_crtc *crtc,
 	ipu_dc_disable(ipu);
 	ipu_prg_disable(ipu);
 
+	drm_crtc_vblank_off(crtc);
+
 	spin_lock_irq(&crtc->dev->event_lock);
 	if (crtc->state->event) {
 		drm_crtc_send_vblank_event(crtc, crtc->state->event);
 		crtc->state->event = NULL;
 	}
 	spin_unlock_irq(&crtc->dev->event_lock);
-
-	drm_crtc_vblank_off(crtc);
 }
 
 static void imx_drm_crtc_reset(struct drm_crtc *crtc)
Signature · 6 lines
2.18.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v3 2/4
#5 lore raw

Re: [PATCH v3 2/4] drm/imx: notify drm core before sending event during crtc disable

Quoted 17 lines · Robert Beckett

Notify drm core before sending pending events during crtc disable. This fixes the first event after disable having an old stale timestamp by having drm_crtc_vblank_off update the timestamp to now.

This was seen while debugging weston log message:
Warning: computed repaint delay is insane: -8212 msec

This occured due to:
1. driver starts up
2. fbcon comes along and restores fbdev, enabling vblank
3. vblank_disable_fn fires via timer disabling vblank, keeping vblank seq number and time set at current value
(some time later)
4. weston starts and does a modeset
5. atomic commit disables crtc while it does the modeset
6. ipu_crtc_atomic_disable sends vblank with old seq number and time

Quoted 3 lines
Fixes a474478642d5 ("drm/imx: fix crtc vblank state regression")

Now that I understand what's going on here:

Quoted 28 lines
---
 drivers/gpu/drm/imx/ipuv3-crtc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/imx/ipuv3-crtc.c +2 -2
index 9cc1d678674f..e04d6efff1b5 100644
@@ -91,14 +91,14 @@ static void ipu_crtc_atomic_disable(struct drm_crtc *crtc,
 	ipu_dc_disable(ipu);
 	ipu_prg_disable(ipu);
 
+	drm_crtc_vblank_off(crtc);
+
 	spin_lock_irq(&crtc->dev->event_lock);
 	if (crtc->state->event) {
 		drm_crtc_send_vblank_event(crtc, crtc->state->event);
 		crtc->state->event = NULL;
 	}
 	spin_unlock_irq(&crtc->dev->event_lock);
-
-	drm_crtc_vblank_off(crtc);
 }
 
 static void imx_drm_crtc_reset(struct drm_crtc *crtc)
Signature · 1 line
2.18.0
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#6 lore raw

PATCH v3 3/4 drm/vblank: estimate vblank while disabling vblank if interrupt disabled

In reply to Robert Beckett

If interrupts are disabled (e.g. via vblank_disable_fn) and we come to disable vblank, update the vblank count to best guess as to what it would be had the interrupts remained enabled, and update the timesamp to now.

This avoids a stale vblank event being sent while disabling crtcs during atomic modeset.

Fixes 68036b08b91bc ("drm/vblank: Do not update vblank count if interrupts

are already disabled.")

---
 drivers/gpu/drm/drm_vblank.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_vblank.c +15 -1
index 7dabb2bdb733..db68b8cbf797 100644
@@ -375,9 +375,23 @@ void drm_vblank_disable_and_save(struct drm_device *dev, unsigned int pipe)
 	 * interrupts were enabled. This avoids calling the ->disable_vblank()
 	 * operation in atomic context with the hardware potentially runtime
 	 * suspended.
+	 * If interrupts are disabled (e.g. via blank_disable_fn) then make
+	 * best guess as to what it would be now and make sure we have an up
+	 * to date timestamp.
 	 */
-	if (!vblank->enabled)
+	if (!vblank->enabled) {
+		ktime_t now = ktime_get();
+		u32 diff = 0;
+		if (vblank->framedur_ns) {
+			u64 diff_ns = ktime_to_ns(ktime_sub(now, vblank->time));
+			diff = DIV_ROUND_CLOSEST_ULL(diff_ns,
+						     vblank->framedur_ns);
+		}
+
+		store_vblank(dev, pipe, diff, now, vblank->count);
+
 		goto out;
+	}
 
 	/*
 	 * Update the count and timestamp to maintain the
Signature · 6 lines
2.18.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#7 lore raw

Re: [PATCH v3 3/4] drm/vblank: estimate vblank while disabling vblank if interrupt disabled

Quoted 21 lines · Robert Beckett

If interrupts are disabled (e.g. via vblank_disable_fn) and we come to disable vblank, update the vblank count to best guess as to what it would be had the interrupts remained enabled, and update the timesamp to now.

This avoids a stale vblank event being sent while disabling crtcs during atomic modeset.

Fixes 68036b08b91bc ("drm/vblank: Do not update vblank count if interrupts

are already disabled.")

---
 drivers/gpu/drm/drm_vblank.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_vblank.c +0 -0
index 7dabb2bdb733..db68b8cbf797 100644

drivers/gpu/drm/drm_vblank.c void drm_vblank_disable_and_save(struct drm_device *dev, unsigned int pipe) · line 383

Quoted 10 lines
drivers/gpu/drm/drm_vblank.c +5 -1
@@ -375,9 +375,23 @@ void drm_vblank_disable_and_save(struct drm_device *dev, unsigned int pipe)
 	 * interrupts were enabled. This avoids calling the ->disable_vblank()
 	 * operation in atomic context with the hardware potentially runtime
 	 * suspended.
+	 * If interrupts are disabled (e.g. via blank_disable_fn) then make
+	 * best guess as to what it would be now and make sure we have an up
+	 * to date timestamp.
 	 */
-	if (!vblank->enabled)
+	if (!vblank->enabled) {
+		ktime_t now = ktime_get();

Would be nice to fake this a bit more accurately and round the timestamp here to a multiple of the frame duration, i.e. ...

drivers/gpu/drm/drm_vblank.c void drm_vblank_disable_and_save(struct drm_device *dev, unsigned int pipe) · line 389

Quoted 6 lines
drivers/gpu/drm/drm_vblank.c +6 -0
+		u32 diff = 0;
+		if (vblank->framedur_ns) {
+			u64 diff_ns = ktime_to_ns(ktime_sub(now, vblank->time));
+			diff = DIV_ROUND_CLOSEST_ULL(diff_ns,
+						     vblank->framedur_ns);
+		}
		now = vblank->time + diff * vblank_framedur_ns;

Picking the right macro for doing 64bit multiplies left to you :-)

drivers/gpu/drm/drm_vblank.c void drm_vblank_disable_and_save(struct drm_device *dev, unsigned int pipe) · line 397

Quoted 8 lines
drivers/gpu/drm/drm_vblank.c +4 -0
+
+		store_vblank(dev, pipe, diff, now, vblank->count);
+
 		goto out;
+	}
 
 	/*
 	 * Update the count and timestamp to maintain the

Somewhat unhappy that we're duplicating this logic with drm_update_vblank_count, but it's just 2 lines of math. -Daniel

Quoted 3 lines
Signature · 1 line
2.18.0
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#8 lore raw

Re: [PATCH v3 3/4] drm/vblank: estimate vblank while disabling vblank if interrupt disabled

In reply to Robert Beckett
Quoted 10 lines · Robert Beckett

If interrupts are disabled (e.g. via vblank_disable_fn) and we come to disable vblank, update the vblank count to best guess as to what it would be had the interrupts remained enabled, and update the timesamp to now.

This avoids a stale vblank event being sent while disabling crtcs during atomic modeset.

Fixes 68036b08b91bc ("drm/vblank: Do not update vblank count if interrupts

are already disabled.")

I don't understand that commit. drm_vblank_off() should be called when the power is still present, so it looks to me like that commit is actually wrong. So I think we may want to just revert it and figure out what the actual bug was.

Quoted 42 lines
---
 drivers/gpu/drm/drm_vblank.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_vblank.c +15 -1
index 7dabb2bdb733..db68b8cbf797 100644
@@ -375,9 +375,23 @@ void drm_vblank_disable_and_save(struct drm_device *dev, unsigned int pipe)
 	 * interrupts were enabled. This avoids calling the ->disable_vblank()
 	 * operation in atomic context with the hardware potentially runtime
 	 * suspended.
+	 * If interrupts are disabled (e.g. via blank_disable_fn) then make
+	 * best guess as to what it would be now and make sure we have an up
+	 * to date timestamp.
 	 */
-	if (!vblank->enabled)
+	if (!vblank->enabled) {
+		ktime_t now = ktime_get();
+		u32 diff = 0;
+		if (vblank->framedur_ns) {
+			u64 diff_ns = ktime_to_ns(ktime_sub(now, vblank->time));
+			diff = DIV_ROUND_CLOSEST_ULL(diff_ns,
+						     vblank->framedur_ns);
+		}
+
+		store_vblank(dev, pipe, diff, now, vblank->count);
+
 		goto out;
+	}
 
 	/*
 	 * Update the count and timestamp to maintain the
Signature · 6 lines
2.18.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 2 lines
Ville Syrjälä
Intel
#9 lore raw

Re: [PATCH v3 3/4] drm/vblank: estimate vblank while disabling vblank if interrupt disabled

Quoted 9 lines · Ville Syrjälä
Quoted 8 lines · Robert Beckett

If interrupts are disabled (e.g. via vblank_disable_fn) and we come to disable vblank, update the vblank count to best guess as to what it would be had the interrupts remained enabled, and update the timesamp to now.

This avoids a stale vblank event being sent while disabling crtcs during atomic modeset.

Quoted 7 lines
Quoted 2 lines
Fixes 68036b08b91bc ("drm/vblank: Do not update vblank count if interrupts

are already disabled.")

I don't understand that commit. drm_vblank_off() should be called when the power is still present, so it looks to me like that commit is actually wrong. So I think we may want to just revert it and figure out what the actual bug was.

Hm yeah we might need a power domain get/put around our drm_crtc_vblank_off() call to make sure it dtrt. Revert sounds like a good idea instead of adding more kludges ... a-b: me on the revert, even though I did ack the original patch too.
-Daniel

Quoted 51 lines
Quoted 43 lines
---
 drivers/gpu/drm/drm_vblank.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_vblank.c +15 -1
index 7dabb2bdb733..db68b8cbf797 100644
@@ -375,9 +375,23 @@ void drm_vblank_disable_and_save(struct drm_device *dev, unsigned int pipe)
 	 * interrupts were enabled. This avoids calling the ->disable_vblank()
 	 * operation in atomic context with the hardware potentially runtime
 	 * suspended.
+	 * If interrupts are disabled (e.g. via blank_disable_fn) then make
+	 * best guess as to what it would be now and make sure we have an up
+	 * to date timestamp.
 	 */
-	if (!vblank->enabled)
+	if (!vblank->enabled) {
+		ktime_t now = ktime_get();
+		u32 diff = 0;
+		if (vblank->framedur_ns) {
+			u64 diff_ns = ktime_to_ns(ktime_sub(now, vblank->time));
+			diff = DIV_ROUND_CLOSEST_ULL(diff_ns,
+						     vblank->framedur_ns);
+		}
+
+		store_vblank(dev, pipe, diff, now, vblank->count);
+
 		goto out;
+	}
 
 	/*
 	 * Update the count and timestamp to maintain the
Signature · 6 lines
2.18.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 6 lines
Ville Syrjälä
Intel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#10 lore raw

PATCH v3 4/4 drm/imx: only send event on crtc disable if kept disabled

In reply to Robert Beckett

The event will be sent as part of the vblank enable during the modeset if the crtc is not being kept disabled.

Fixes 5f2f911578fb ("drm/imx: atomic phase 3 step 1: Use atomic configuration")
---
 drivers/gpu/drm/imx/ipuv3-crtc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/imx/ipuv3-crtc.c +1 -1
index e04d6efff1b5..c436a28d50e4 100644
@@ -94,7 +94,7 @@ static void ipu_crtc_atomic_disable(struct drm_crtc *crtc,
 	drm_crtc_vblank_off(crtc);
 
 	spin_lock_irq(&crtc->dev->event_lock);
-	if (crtc->state->event) {
+	if (crtc->state->event && !crtc->state->active) {
 		drm_crtc_send_vblank_event(crtc, crtc->state->event);
 		crtc->state->event = NULL;
 	}
Signature · 1 line
2.18.0
Reviewed-by on v3 4/4
#11 lore raw

Re: [PATCH v3 4/4] drm/imx: only send event on crtc disable if kept disabled

Quoted 6 lines · Robert Beckett

The event will be sent as part of the vblank enable during the modeset if the crtc is not being kept disabled.

Fixes 5f2f911578fb ("drm/imx: atomic phase 3 step 1: Use atomic configuration")
Quoted 20 lines
---
 drivers/gpu/drm/imx/ipuv3-crtc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/imx/ipuv3-crtc.c +1 -1
index e04d6efff1b5..c436a28d50e4 100644
@@ -94,7 +94,7 @@ static void ipu_crtc_atomic_disable(struct drm_crtc *crtc,
 	drm_crtc_vblank_off(crtc);
 
 	spin_lock_irq(&crtc->dev->event_lock);
-	if (crtc->state->event) {
+	if (crtc->state->event && !crtc->state->active) {
 		drm_crtc_send_vblank_event(crtc, crtc->state->event);
 		crtc->state->event = NULL;
 	}
Signature · 1 line
2.18.0
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#12 lore raw

Re: [PATCH v3 4/4] drm/imx: only send event on crtc disable if kept disabled

Quoted 9 lines · Daniel Vetter
Quoted 6 lines · Robert Beckett

The event will be sent as part of the vblank enable during the modeset if the crtc is not being kept disabled.

Fixes 5f2f911578fb ("drm/imx: atomic phase 3 step 1: Use atomic configuration")

Thank you, patches 2 and 4 applied to imx-drm/fixes.

regards
Philipp
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel