Skip to contentSkip to conversation

drm/i915: Add wait_for_us

PATCH In review Tvrtko Ursulin 4 participants 12 messages Feb 1, 2016 – Feb 2, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/6 drm/i915: Add wait_for_us

From: Tvrtko Ursulin <[email protected]>

This is for callers who want micro-second precision but are not waiting from the atomic context.

---
 drivers/gpu/drm/i915/intel_dp.c  | 3 +--
 drivers/gpu/drm/i915/intel_drv.h | 9 +++++----
 drivers/gpu/drm/i915/intel_psr.c | 2 +-
 3 files changed, 7 insertions(+), 7 deletions(-)
drivers/gpu/drm/i915/intel_dp.c +1 -2
index e2bea710614f..fb8a76ec6ade 100644
@@ -1788,11 +1788,10 @@ static void wait_panel_status(struct intel_dp *intel_dp,
 			I915_READ(pp_stat_reg),
 			I915_READ(pp_ctrl_reg));
 
-	if (_wait_for((I915_READ(pp_stat_reg) & mask) == value, 5000, 10)) {
+	if (_wait_for((I915_READ(pp_stat_reg) & mask) == value, 5000000, 10000))
 		DRM_ERROR("Panel status timeout: status %08x control %08x\n",
 				I915_READ(pp_stat_reg),
 				I915_READ(pp_ctrl_reg));
-	}
 
 	DRM_DEBUG_KMS("Wait complete\n");
 }
drivers/gpu/drm/i915/intel_drv.h +5 -4
index f620023ed134..779d17a9fcce 100644
@@ -45,8 +45,8 @@
  * having timed out, since the timeout could be due to preemption or similar and
  * we've never had a chance to check the condition before the timeout.
  */
-#define _wait_for(COND, MS, W) ({ \
-	unsigned long timeout__ = jiffies + msecs_to_jiffies(MS) + 1;	\
+#define _wait_for(COND, US, W) ({ \
+	unsigned long timeout__ = jiffies + usecs_to_jiffies(US) + 1;	\
 	int ret__ = 0;							\
 	while (!(COND)) {						\
 		if (time_after(jiffies, timeout__)) {			\
@@ -55,7 +55,7 @@
 			break;						\
 		}							\
 		if ((W) && drm_can_sleep()) {				\
-			usleep_range((W)*1000, (W)*2000);		\
+			usleep_range((W), (W)*2);			\
 		} else {						\
 			cpu_relax();					\
 		}							\
@@ -63,7 +63,8 @@
 	ret__;								\
 })
 
-#define wait_for(COND, MS) _wait_for(COND, MS, 1)
+#define wait_for(COND, MS) _wait_for(COND, (MS) * 1000, 1000)
+#define wait_for_us(COND, US) _wait_for(COND, US, 1)
 #define wait_for_atomic(COND, MS) _wait_for(COND, MS, 0)
 #define wait_for_atomic_us(COND, US) _wait_for((COND), \
 					       DIV_ROUND_UP((US), 1000), 0)
drivers/gpu/drm/i915/intel_psr.c +1 -1
index 9ccff3011523..e12377963839 100644
@@ -492,7 +492,7 @@ static void hsw_psr_disable(struct intel_dp *intel_dp)
 
 		/* Wait till PSR is idle */
 		if (_wait_for((I915_READ(EDP_PSR_STATUS_CTL) &
-			       EDP_PSR_STATUS_STATE_MASK) == 0, 2000, 10))
+			       EDP_PSR_STATUS_STATE_MASK) == 0, 2000000, 10000))
 			DRM_ERROR("Timed out waiting for PSR Idle State\n");
 
 		dev_priv->psr.active = false;
Signature · 6 lines
1.9.1

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

PATCH 2/6 drm/i915: Do not wait atomically for display clocks

From: Tvrtko Ursulin <[email protected]>

Looks like this code does not need to wait atomically since it otherwise takes the mutex. But did it rely on on the requested 1us wait actually being up to 1ms?

---
 drivers/gpu/drm/i915/intel_display.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/i915/intel_display.c +4 -4
index 304fc9637026..a7530cf612d7 100644
@@ -9753,8 +9753,8 @@ static void broadwell_set_cdclk(struct drm_device *dev, int cdclk)
 	val |= LCPLL_CD_SOURCE_FCLK;
 	I915_WRITE(LCPLL_CTL, val);
 
-	if (wait_for_atomic_us(I915_READ(LCPLL_CTL) &
-			       LCPLL_CD_SOURCE_FCLK_DONE, 1))
+	if (wait_for_us(I915_READ(LCPLL_CTL) &
+			LCPLL_CD_SOURCE_FCLK_DONE, 1))
 		DRM_ERROR("Switching to FCLK failed\n");
 
 	val = I915_READ(LCPLL_CTL);
@@ -9788,8 +9788,8 @@ static void broadwell_set_cdclk(struct drm_device *dev, int cdclk)
 	val &= ~LCPLL_CD_SOURCE_FCLK;
 	I915_WRITE(LCPLL_CTL, val);
 
-	if (wait_for_atomic_us((I915_READ(LCPLL_CTL) &
-				LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1))
+	if (wait_for_us((I915_READ(LCPLL_CTL) &
+			LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1))
 		DRM_ERROR("Switching back to LCPLL failed\n");
 
 	mutex_lock(&dev_priv->rps.hw_lock);
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Reviewed-by on v1 2/6
#2 lore raw

Re: [PATCH 2/6] drm/i915: Do not wait atomically for display clocks

Quoted 5 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

Looks like this code does not need to wait atomically since it otherwise takes the mutex. But did it rely on on the requested 1us wait actually being up to 1ms?

Bspec says 1 us, so it *should* be fine.

Quoted 35 lines
---
 drivers/gpu/drm/i915/intel_display.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/i915/intel_display.c +4 -4
index 304fc9637026..a7530cf612d7 100644
@@ -9753,8 +9753,8 @@ static void broadwell_set_cdclk(struct drm_device *dev, int cdclk)
 	val |= LCPLL_CD_SOURCE_FCLK;
 	I915_WRITE(LCPLL_CTL, val);
 
-	if (wait_for_atomic_us(I915_READ(LCPLL_CTL) &
-			       LCPLL_CD_SOURCE_FCLK_DONE, 1))
+	if (wait_for_us(I915_READ(LCPLL_CTL) &
+			LCPLL_CD_SOURCE_FCLK_DONE, 1))
 		DRM_ERROR("Switching to FCLK failed\n");
 
 	val = I915_READ(LCPLL_CTL);
@@ -9788,8 +9788,8 @@ static void broadwell_set_cdclk(struct drm_device *dev, int cdclk)
 	val &= ~LCPLL_CD_SOURCE_FCLK;
 	I915_WRITE(LCPLL_CTL, val);
 
-	if (wait_for_atomic_us((I915_READ(LCPLL_CTL) &
-				LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1))
+	if (wait_for_us((I915_READ(LCPLL_CTL) &
+			LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1))
 		DRM_ERROR("Switching back to LCPLL failed\n");
 
 	mutex_lock(&dev_priv->rps.hw_lock);
Signature · 1 line
1.9.1
Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#3 lore raw

PATCH 3/6 drm/i915/guc: Do not wait for firmware load atomically

In reply to Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

It does not look like this code needs to wait atomically?

Higher in the call chain it calls the GEM API and I do not see that the section is under any spin locks or such.

---
 drivers/gpu/drm/i915/intel_guc_loader.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/intel_guc_loader.c +3 -3
index 3accd914490f..82a3c03fbc0e 100644
@@ -199,7 +199,7 @@ static void set_guc_init_params(struct drm_i915_private *dev_priv)
  * the value matches either of two values representing completion
  * of the GuC boot process.
  *
- * This is used for polling the GuC status in a wait_for_atomic()
+ * This is used for polling the GuC status in a wait_for()
  * loop below.
  */
 static inline bool guc_ucode_response(struct drm_i915_private *dev_priv,
@@ -259,14 +259,14 @@ static int guc_ucode_xfer_dma(struct drm_i915_private *dev_priv)
 	I915_WRITE(DMA_CTRL, _MASKED_BIT_ENABLE(UOS_MOVE | START_DMA));
 
 	/*
-	 * Spin-wait for the DMA to complete & the GuC to start up.
+	 * Wait for the DMA to complete & the GuC to start up.
 	 * NB: Docs recommend not using the interrupt for completion.
 	 * Measurements indicate this should take no more than 20ms, so a
 	 * timeout here indicates that the GuC has failed and is unusable.
 	 * (Higher levels of the driver will attempt to fall back to
 	 * execlist mode if this happens.)
 	 */
-	ret = wait_for_atomic(guc_ucode_response(dev_priv, &status), 100);
+	ret = wait_for(guc_ucode_response(dev_priv, &status), 100);
 
 	DRM_DEBUG_DRIVER("DMA status 0x%x, GuC status 0x%x\n",
 			I915_READ(DMA_CTRL), status);
Signature · 6 lines
1.9.1

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

PATCH 4/6 drm/i915/lrc: Do not wait atomically when stopping engines

In reply to Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

I do not see that this needs to be done atomically and up to one second is quite a long time to busy loop.

---
 drivers/gpu/drm/i915/intel_lrc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/i915/intel_lrc.c +1 -1
index 3a03646e343d..3ca7f48a418b 100644
@@ -1049,7 +1049,7 @@ void intel_logical_ring_stop(struct intel_engine_cs *ring)
 
 	/* TODO: Is this correct with Execlists enabled? */
 	I915_WRITE_MODE(ring, _MASKED_BIT_ENABLE(STOP_RING));
-	if (wait_for_atomic((I915_READ_MODE(ring) & MODE_IDLE) != 0, 1000)) {
+	if (wait_for((I915_READ_MODE(ring) & MODE_IDLE) != 0, 1000)) {
 		DRM_ERROR("%s :timed out trying to stop ring\n", ring->name);
 		return;
 	}
Signature · 6 lines
1.9.1

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

PATCH 5/6 drm/i915: Kconfig for extra driver debugging

In reply to Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

---
 drivers/gpu/drm/i915/Kconfig | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/gpu/drm/i915/Kconfig +12 -0
index 051eab33e4c7..7636bf918d97 100644
@@ -47,3 +47,15 @@ config DRM_I915_PRELIMINARY_HW_SUPPORT
 	  option changes the default for that module option.
 
 	  If in doubt, say "N".
+
+config DRM_I915_DEBUG
+	bool "Enable additional driver debugging"
+	depends on DRM_I915
+	default n
+	help
+	  Choose this option to turn on extra driver debugging that may affect
+	  performance but will catch some internal issues.
+
+	  Recommended for driver developers only.
+
+	  If in doubt, say "N".
Signature · 6 lines
1.9.1

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

Re: [PATCH 5/6] drm/i915: Kconfig for extra driver debugging

Quoted 17 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

---
 drivers/gpu/drm/i915/Kconfig | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/gpu/drm/i915/Kconfig +2 -0
index 051eab33e4c7..7636bf918d97 100644
@@ -47,3 +47,15 @@ config DRM_I915_PRELIMINARY_HW_SUPPORT
 	  option changes the default for that module option.
 
 	  If in doubt, say "N".
+
+config DRM_I915_DEBUG

drivers/gpu/drm/i915/Kconfig config DRM_I915_PRELIMINARY_HW_SUPPORT · line 61

Quoted 10 lines
drivers/gpu/drm/i915/Kconfig +10 -0
+	bool "Enable additional driver debugging"
+	depends on DRM_I915
+	default n
+	help
+	  Choose this option to turn on extra driver debugging that may affect
+	  performance but will catch some internal issues.
+
+	  Recommended for driver developers only.
+
+	  If in doubt, say "N".

I kind of liked Chris' approach of adding a submenu
http://patchwork.freedesktop.org/patch/msgid/[email protected]

BR,
Jani.

Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#7 lore raw

Re: [PATCH 5/6] drm/i915: Kconfig for extra driver debugging

Quoted 15 lines · Jani Nikula
Quoted 14 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

---
  drivers/gpu/drm/i915/Kconfig | 12 ++++++++++++
  1 file changed, 12 insertions(+)
drivers/gpu/drm/i915/Kconfig +0 -0
index 051eab33e4c7..7636bf918d97 100644
@@ -47,3 +47,15 @@ config DRM_I915_PRELIMINARY_HW_SUPPORT
  	  option changes the default for that module option.
 
Quoted 16 lines

drivers/gpu/drm/i915/Kconfig config DRM_I915_PRELIMINARY_HW_SUPPORT · line 61

Quoted 13 lines
drivers/gpu/drm/i915/Kconfig +12 -0
  	  If in doubt, say "N".
+
+config DRM_I915_DEBUG
+	bool "Enable additional driver debugging"
+	depends on DRM_I915
+	default n
+	help
+	  Choose this option to turn on extra driver debugging that may affect
+	  performance but will catch some internal issues.
+
+	  Recommended for driver developers only.
+
+	  If in doubt, say "N".

I kind of liked Chris' approach of adding a submenu
http://patchwork.freedesktop.org/patch/msgid/[email protected]

I don't mind either way - what was decided for that patch - is it going in?

Regards,

Tvrtko

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

maintainer
#8 lore raw

Re: [PATCH 5/6] drm/i915: Kconfig for extra driver debugging

Quoted 33 lines · Tvrtko Ursulin
Quoted 15 lines · Jani Nikula
Quoted 14 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

---
  drivers/gpu/drm/i915/Kconfig | 12 ++++++++++++
  1 file changed, 12 insertions(+)
drivers/gpu/drm/i915/Kconfig +0 -0
index 051eab33e4c7..7636bf918d97 100644
@@ -47,3 +47,15 @@ config DRM_I915_PRELIMINARY_HW_SUPPORT
  	  option changes the default for that module option.
 
Quoted 16 lines

drivers/gpu/drm/i915/Kconfig config DRM_I915_PRELIMINARY_HW_SUPPORT · line 61

Quoted 13 lines
drivers/gpu/drm/i915/Kconfig +12 -0
  	  If in doubt, say "N".
+
+config DRM_I915_DEBUG
+	bool "Enable additional driver debugging"
+	depends on DRM_I915
+	default n
+	help
+	  Choose this option to turn on extra driver debugging that may affect
+	  performance but will catch some internal issues.
+
+	  Recommended for driver developers only.
+
+	  If in doubt, say "N".

I kind of liked Chris' approach of adding a submenu
http://patchwork.freedesktop.org/patch/msgid/[email protected]

Quoted 2 lines

I don't mind either way - what was decided for that patch - is it going in?

I think we'd like to have it, but last time it blew up on randconfig. Chris, do we avoid that now?

Tvrtko, in any case, you could pick up the submenu part from there.

BR,
Jani.

Quoted 5 lines

Regards,

Tvrtko

Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#9 lore raw

Re: [PATCH 5/6] drm/i915: Kconfig for extra driver debugging

Quoted 34 lines · Jani Nikula
Quoted 33 lines · Tvrtko Ursulin
Quoted 31 lines · Jani Nikula
Quoted 17 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

---
   drivers/gpu/drm/i915/Kconfig | 12 ++++++++++++
   1 file changed, 12 insertions(+)
drivers/gpu/drm/i915/Kconfig +2 -0
index 051eab33e4c7..7636bf918d97 100644
@@ -47,3 +47,15 @@ config DRM_I915_PRELIMINARY_HW_SUPPORT
   	  option changes the default for that module option.
 
   	  If in doubt, say "N".
+
+config DRM_I915_DEBUG

drivers/gpu/drm/i915/Kconfig config DRM_I915_PRELIMINARY_HW_SUPPORT · line 61

Quoted 10 lines
drivers/gpu/drm/i915/Kconfig +10 -0
+	bool "Enable additional driver debugging"
+	depends on DRM_I915
+	default n
+	help
+	  Choose this option to turn on extra driver debugging that may affect
+	  performance but will catch some internal issues.
+
+	  Recommended for driver developers only.
+
+	  If in doubt, say "N".

I kind of liked Chris' approach of adding a submenu
http://patchwork.freedesktop.org/patch/msgid/[email protected]

Quoted 7 lines
Quoted 2 lines

I don't mind either way - what was decided for that patch - is it going in?

I think we'd like to have it, but last time it blew up on randconfig. Chris, do we avoid that now?

Tvrtko, in any case, you could pick up the submenu part from there.

I have - and also respun the enlarged series of misc fixes and debugging infrastructure. Reviewers welcome. :)

Regards,

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

#10 lore raw

PATCH 6/6 drm/i915: Do not lie about atomic wait granularity

In reply to Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

Currently the wait_for_atomic_us only allows for a millisecond granularity which is not nice towards callers requesting small micro-second waits.

Re-implement it so micro-second granularity is really supported and not just in the name of the macro.

v2:
* Warn when used from non-atomic context (if possible).
* Warn on too long atomic waits.

---
 drivers/gpu/drm/i915/intel_drv.h | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/intel_drv.h +24 -3
index 779d17a9fcce..af6c1539106f 100644
@@ -63,11 +63,32 @@
 	ret__;								\
 })
 
+#if defined(CONFIG_DRM_I915_DEBUG) && defined(CONFIG_PREEMPT_COUNT)
+  #define _WAIT_FOR_ATOMIC_CHECK WARN_ON_ONCE(!in_atomic())
+#else
+  #define _WAIT_FOR_ATOMIC_CHECK do { } while(0)
+#endif
+
+#define _wait_for_atomic(COND, US) ({ \
+	unsigned long end__; \
+	int ret__ = 0; \
+	_WAIT_FOR_ATOMIC_CHECK; \
+	BUILD_BUG_ON((US) > 50000); \
+	end__ = (local_clock() >> 10) + (US) + 1; \
+	while (!(COND)) { \
+		if (time_after((unsigned long)(local_clock() >> 10), end__)) { \
+			ret__ = -ETIMEDOUT; \
+			break; \
+		} \
+		cpu_relax(); \
+	} \
+	ret__; \
+})
+
 #define wait_for(COND, MS) _wait_for(COND, (MS) * 1000, 1000)
 #define wait_for_us(COND, US) _wait_for(COND, US, 1)
-#define wait_for_atomic(COND, MS) _wait_for(COND, MS, 0)
-#define wait_for_atomic_us(COND, US) _wait_for((COND), \
-					       DIV_ROUND_UP((US), 1000), 0)
+#define wait_for_atomic(COND, MS) _wait_for_atomic(COND, (MS) * 1000)
+#define wait_for_atomic_us(COND, US) _wait_for_atomic((COND), (US))
 
 #define KHz(x) (1000 * (x))
 #define MHz(x) KHz(1000 * (x))
Signature · 6 lines
1.9.1

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

✓ Fi.CI.BAT: success for series starting with [1/6] drm/i915: Add wait_for_us

In reply to Tvrtko Ursulin
== Summary ==

== Summary ==

Series 2990v1 Series without cover letter
http://patchwork.freedesktop.org/api/1.0/series/2990/revisions/1/mbox/

Test kms_force_connector_basic:

        Subgroup force-edid:
                pass       -> SKIP       (snb-dellxps)
Test kms_pipe_crc_basic:
        Subgroup suspend-read-crc-pipe-a:
                incomplete -> PASS       (hsw-gt2)
        Subgroup suspend-read-crc-pipe-c:
                dmesg-warn -> PASS       (bsw-nuc-2)
bdw-nuci7        total:156  pass:147  dwarn:0   dfail:0   fail:0   skip:9  
bdw-ultra        total:159  pass:147  dwarn:0   dfail:0   fail:0   skip:12 
bsw-nuc-2        total:159  pass:129  dwarn:0   dfail:0   fail:0   skip:30 
byt-nuc          total:159  pass:136  dwarn:0   dfail:0   fail:0   skip:23 
hsw-brixbox      total:159  pass:146  dwarn:0   dfail:0   fail:0   skip:13 
hsw-gt2          total:159  pass:149  dwarn:0   dfail:0   fail:0   skip:10 
ilk-hp8440p      total:159  pass:111  dwarn:0   dfail:0   fail:0   skip:48 
ivb-t430s        total:159  pass:145  dwarn:0   dfail:0   fail:0   skip:14 
skl-i5k-2        total:159  pass:144  dwarn:1   dfail:0   fail:0   skip:14 
snb-dellxps      total:159  pass:136  dwarn:0   dfail:0   fail:0   skip:23 

Results at /archive/results/CI_IGT_test/Patchwork_1338/

6b1049b84dcd979f631d15b2ada325d8e5b2c4e1 drm-intel-nightly: 2016y-01m-29d-22h-50m-57s UTC integration manifest c43605cbd64f5215a1b798aff7c461948d441d41 drm/i915: Do not lie about atomic wait granularity 852c8518cbcdf79c1d8da52674aee2f5fe83ef15 drm/i915: Kconfig for extra driver debugging ea7e006468a761cbfaa6834c5c4d58b17ca4d95c drm/i915/lrc: Do not wait atomically when stopping engines 90e7d18b84392d5f3f496c36a53a7570c7e0629c drm/i915/guc: Do not wait for firmware load atomically 92267a75b4c54df08f02597944425442cd5d7e9f drm/i915: Do not wait atomically for display clocks b5d8c277bffd039047bce76754500a41bc1a9cf2 drm/i915: Add wait_for_us

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