Skip to contentSkip to conversation

drm/i915: add msecs_to_jiffies_timeout to guarantee minimum duration

PATCH In review Imre Deak 3 participants 11 messages May 21, 2013 – May 22, 2013

Subsystems (2)
lore
Share & tools
lore

Imre Deak

author
#0 lore raw

PATCH 1/4 drm/i915: add msecs_to_jiffies_timeout to guarantee minimum duration

We need this to avoid premature timeouts whenever scheduling a timeout based on the current jiffies value. For an explanation see [1]. The following patches will take the helper into use.

Once the more generic solution proposed in the thread at [1] is accepted this patch can be reverted while keeping the follow-up patches.

[1] http://marc.info/?l=linux-kernel&m=136854294730957&w=2

---
 drivers/gpu/drm/i915/i915_drv.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/gpu/drm/i915/i915_drv.h +15 -0
index 639ec0b..78b6c56 100644
@@ -1981,4 +1981,19 @@ static inline void __user *to_user_ptr(u64 address)
 	return (void __user *)(uintptr_t)address;
 }
 
+static inline unsigned long msecs_to_jiffies_timeout(const unsigned int m)
+{
+	unsigned long j = msecs_to_jiffies(m);
+
+	return min_t(unsigned long, MAX_JIFFY_OFFSET, j + 1);
+}
+
+static inline unsigned long
+timespec_to_jiffies_timeout(const struct timespec *value)
+{
+	unsigned long j = timespec_to_jiffies(value);
+
+	return min_t(unsigned long, MAX_JIFFY_OFFSET, j + 1);
+}
+
 #endif
Signature · 1 line
1.8.1.2
author
#1 lore raw

PATCH 2/4 drm/i915: use msecs_to_jiffies_timeout instead of open coding the same

---
 drivers/gpu/drm/i915/intel_i2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/i915/intel_i2c.c +1 -1
index 5d24503..98cd8535 100644
@@ -228,7 +228,7 @@ gmbus_wait_hw_status(struct drm_i915_private *dev_priv,
 	 * need to wake up periodically and check that ourselves. */
 	I915_WRITE(GMBUS4 + reg_offset, gmbus4_irq_en);
 
-	for (i = 0; i < msecs_to_jiffies(50) + 1; i++) {
+	for (i = 0; i < msecs_to_jiffies_timeout(50); i++) {
 		prepare_to_wait(&dev_priv->gmbus_wait_queue, &wait,
 				TASK_UNINTERRUPTIBLE);
 
Signature · 1 line
1.8.1.2
#2 lore raw

Re: [PATCH 2/4] drm/i915: use msecs_to_jiffies_timeout instead of open coding the same

We have another one of these in the wait_for register wait macro in intel_drv.h Can you please amend your patch with that fixed up, too?

Thanks, Daniel

Quoted 25 lines · Imre Deak
---
 drivers/gpu/drm/i915/intel_i2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/i915/intel_i2c.c +1 -2
index 5d24503..98cd8535 100644
@@ -228,7 +228,7 @@ gmbus_wait_hw_status(struct drm_i915_private *dev_priv,
         * need to wake up periodically and check that ourselves. */
        I915_WRITE(GMBUS4 + reg_offset, gmbus4_irq_en);
 
-       for (i = 0; i < msecs_to_jiffies(50) + 1; i++) {
+       for (i = 0; i < msecs_to_jiffies_timeout(50); i++) {
                prepare_to_wait(&dev_priv->gmbus_wait_queue, &wait,
                                TASK_UNINTERRUPTIBLE);
 
--

1.8.1.2

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
author
#3 lore raw

Re: [PATCH 2/4] drm/i915: use msecs_to_jiffies_timeout instead of open coding the same

Quoted 2 lines · Daniel Vetter

We have another one of these in the wait_for register wait macro in intel_drv.h Can you please amend your patch with that fixed up, too?

I noticed it, but didn't change it since we don't need there the +1 adjustment to begin with. The time_after() check already makes sure we wait at least MS amount. So I think we should remove +1 from there..

--Imre

#4 lore raw

Re: [PATCH 2/4] drm/i915: use msecs_to_jiffies_timeout instead of open coding the same

Quoted 7 lines · Imre Deak
Quoted 2 lines · Daniel Vetter

We have another one of these in the wait_for register wait macro in intel_drv.h Can you please amend your patch with that fixed up, too?

I noticed it, but didn't change it since we don't need there the +1 adjustment to begin with. The time_after() check already makes sure we wait at least MS amount. So I think we should remove +1 from there..

Hm, right. Looks like the important part of

commit 1d5bfac96f1e1856fbdb3f06679691e5b9c2ba8f

Author: Daniel Vetter <[email protected]>
Date:   Thu Mar 28 00:03:25 2013 +0100

drm/i915: fix up _wait_for macro

was to just recheck the condition after the timeout expired. I agree that this is a separate patch.
-Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

author
#5 lore raw

PATCH 3/4 drm/i915: avoid premature timeouts in __wait_seqno()

In reply to Imre Deak

At the moment wait_event_timeout/wait_event_interruptible_timeout may time out 1 jiffy too early, as the calculated expiry time is 1 less than needed. Besides timing out too early this also means that the calculation of the remaining time will be incorrect and we will pass a non-zero remaining time to user space in case of a time out. This is one reason for the following bugzilla report:

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=64270

---
 drivers/gpu/drm/i915/i915_gem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_gem.c +1 -1
index a1a282c..2b51fa7 100644
@@ -1003,7 +1003,7 @@ static int __wait_seqno(struct intel_ring_buffer *ring, u32 seqno,
 		wait_forever = false;
 	}
 
-	timeout_jiffies = timespec_to_jiffies(&wait_time);
+	timeout_jiffies = timespec_to_jiffies_timeout(&wait_time);
 
 	if (WARN_ON(!ring->irq_get(ring)))
 		return -ENODEV;
Signature · 1 line
1.8.1.2
author
#6 lore raw

PATCH 4/4 drm/i915: avoid premature DP AUX timeouts

In reply to Imre Deak

During DP AUX communication we might time out 1 jiffy too early, because the calculated expiry jiffy value is one less than needed.

This is only one reason for false DP AUX timeouts. For a complete solution we also need the following fix, which is now queued for
mainline: http://marc.info/?l=linux-kernel&m=136748515710837&w=2

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=64133

---
 drivers/gpu/drm/i915/intel_dp.c  | 2 +-
 drivers/gpu/drm/i915/intel_i2c.c | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/intel_dp.c +1 -1
index 3426a61..8cdc3d7 100644
@@ -276,7 +276,7 @@ intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
 #define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
 	if (has_aux_irq)
 		done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
-					  msecs_to_jiffies(10));
+					  msecs_to_jiffies_timeout(10));
 	else
 		done = wait_for_atomic(C, 10) == 0;
 	if (!done)
drivers/gpu/drm/i915/intel_i2c.c +2 -1
index 98cd8535..639fe19 100644
@@ -263,7 +263,8 @@ gmbus_wait_idle(struct drm_i915_private *dev_priv)
 	/* Important: The hw handles only the first bit, so set only one! */
 	I915_WRITE(GMBUS4 + reg_offset, GMBUS_IDLE_EN);
 
-	ret = wait_event_timeout(dev_priv->gmbus_wait_queue, C, 10);
+	ret = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
+				 msecs_to_jiffies_timeout(10));
 
 	I915_WRITE(GMBUS4 + reg_offset, 0);
 
Signature · 1 line
1.8.1.2
maintainer
#7 lore raw
In reply to Imre Deak
Quoted 8 lines · Imre Deak

We need this to avoid premature timeouts whenever scheduling a timeout based on the current jiffies value. For an explanation see [1]. The following patches will take the helper into use.

Once the more generic solution proposed in the thread at [1] is accepted this patch can be reverted while keeping the follow-up patches.

[1] http://marc.info/?l=linux-kernel&m=136854294730957&w=2

With the name clashes, what happens when the generic solution is merged? Blows up the build? To avoid confusion with merging upstream and potential stable backports, should we err on the safe side and rename these? Or add suitable trickery to use the generic version when available?

BR,
Jani.

Quoted 37 lines
---
 drivers/gpu/drm/i915/i915_drv.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/gpu/drm/i915/i915_drv.h +15 -0
index 639ec0b..78b6c56 100644
@@ -1981,4 +1981,19 @@ static inline void __user *to_user_ptr(u64 address)
 	return (void __user *)(uintptr_t)address;
 }
 
+static inline unsigned long msecs_to_jiffies_timeout(const unsigned int m)
+{
+	unsigned long j = msecs_to_jiffies(m);
+
+	return min_t(unsigned long, MAX_JIFFY_OFFSET, j + 1);
+}
+
+static inline unsigned long
+timespec_to_jiffies_timeout(const struct timespec *value)
+{
+	unsigned long j = timespec_to_jiffies(value);
+
+	return min_t(unsigned long, MAX_JIFFY_OFFSET, j + 1);
+}
+
 #endif
Signature · 6 lines
1.8.1.2

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#8 lore raw
Quoted 8 lines · Jani Nikula
Quoted 7 lines · Imre Deak

We need this to avoid premature timeouts whenever scheduling a timeout based on the current jiffies value. For an explanation see [1]. The following patches will take the helper into use.

Once the more generic solution proposed in the thread at [1] is accepted this patch can be reverted while keeping the follow-up patches.

Quoted 7 lines
Quoted 1 line

[1] http://marc.info/?l=linux-kernel&m=136854294730957&w=2

With the name clashes, what happens when the generic solution is merged? Blows up the build? To avoid confusion with merging upstream and potential stable backports, should we err on the safe side and rename these? Or add suitable trickery to use the generic version when available?

linux-next should catch such fallout and we can fix up things in the merge. And since Linus has intel graphics I expect that he'll catch it if it fails to compile ;-)
-Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

author
#9 lore raw
Quoted 18 lines · Daniel Vetter
Quoted 8 lines · Jani Nikula
Quoted 7 lines · Imre Deak

We need this to avoid premature timeouts whenever scheduling a timeout based on the current jiffies value. For an explanation see [1]. The following patches will take the helper into use.

Once the more generic solution proposed in the thread at [1] is accepted this patch can be reverted while keeping the follow-up patches.

Quoted 7 lines
Quoted 1 line

[1] http://marc.info/?l=linux-kernel&m=136854294730957&w=2

With the name clashes, what happens when the generic solution is merged? Blows up the build? To avoid confusion with merging upstream and potential stable backports, should we err on the safe side and rename these? Or add suitable trickery to use the generic version when available?

Quoted 3 lines

linux-next should catch such fallout and we can fix up things in the merge. And since Linus has intel graphics I expect that he'll catch it if it fails to compile ;-)

Yea, I haven't thought this through properly. But after discussing with Jani, this seems to be doable. I only hope Linus won't have to resolve anything :)

--Imre

#10 lore raw
Quoted 19 lines · Imre Deak
Quoted 18 lines · Daniel Vetter
Quoted 15 lines · Jani Nikula
Quoted 8 lines · Imre Deak

We need this to avoid premature timeouts whenever scheduling a timeout based on the current jiffies value. For an explanation see [1]. The following patches will take the helper into use.

Once the more generic solution proposed in the thread at [1] is accepted this patch can be reverted while keeping the follow-up patches.

[1] http://marc.info/?l=linux-kernel&m=136854294730957&w=2

With the name clashes, what happens when the generic solution is merged? Blows up the build? To avoid confusion with merging upstream and potential stable backports, should we err on the safe side and rename these? Or add suitable trickery to use the generic version when available?

Quoted 7 lines
Quoted 3 lines

linux-next should catch such fallout and we can fix up things in the merge. And since Linus has intel graphics I expect that he'll catch it if it fails to compile ;-)

Yea, I haven't thought this through properly. But after discussing with Jani, this seems to be doable. I only hope Linus won't have to resolve anything :)

Ok, I've picked up the entire pile for -fixes, thanks for the patches. -Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch