All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/i915/perf: fix perf stream opening lock
@ 2018-02-28 11:45 Lionel Landwerlin
  2018-02-28 12:14 ` ✓ Fi.CI.BAT: success for " Patchwork
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Lionel Landwerlin @ 2018-02-28 11:45 UTC (permalink / raw)
  To: intel-gfx; +Cc: matthew.auld, Lionel Landwerlin, stable

We're seeing on CI that some contexts don't have the programmed OA
period timer that directs the OA unit on how often to write reports.

The issue is that we're not holding the drm lock from when we edit the
context images down to when we set the exclusive_stream variable. This
leaves a window for the deferred context allocation to call
i915_oa_init_reg_state() that will not program the expected OA timer
value, because we haven't set the exclusive_stream yet.

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Fixes: 701f8231a2f ("drm/i915/perf: prune OA configs")
Cc: <stable@vger.kernel.org> # v4.14+
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=102254
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=103715
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=103755
---
 drivers/gpu/drm/i915/i915_perf.c | 41 +++++++++++++++++++---------------------
 1 file changed, 19 insertions(+), 22 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c
index 2741b1bc7095..7016abfc8ba9 100644
--- a/drivers/gpu/drm/i915/i915_perf.c
+++ b/drivers/gpu/drm/i915/i915_perf.c
@@ -1757,21 +1757,16 @@ static int gen8_switch_to_updated_kernel_context(struct drm_i915_private *dev_pr
  */
 static int gen8_configure_all_contexts(struct drm_i915_private *dev_priv,
 				       const struct i915_oa_config *oa_config,
-				       bool interruptible)
+				       bool need_lock)
 {
 	struct i915_gem_context *ctx;
 	int ret;
 	unsigned int wait_flags = I915_WAIT_LOCKED;
 
-	if (interruptible) {
-		ret = i915_mutex_lock_interruptible(&dev_priv->drm);
-		if (ret)
-			return ret;
-
-		wait_flags |= I915_WAIT_INTERRUPTIBLE;
-	} else {
+	if (need_lock)
 		mutex_lock(&dev_priv->drm.struct_mutex);
-	}
+
+	lockdep_assert_held(&dev_priv->drm.struct_mutex);
 
 	/* Switch away from any user context. */
 	ret = gen8_switch_to_updated_kernel_context(dev_priv, oa_config);
@@ -1819,7 +1814,8 @@ static int gen8_configure_all_contexts(struct drm_i915_private *dev_priv,
 	}
 
  out:
-	mutex_unlock(&dev_priv->drm.struct_mutex);
+	if (need_lock)
+		mutex_unlock(&dev_priv->drm.struct_mutex);
 
 	return ret;
 }
@@ -1863,7 +1859,7 @@ static int gen8_enable_metric_set(struct drm_i915_private *dev_priv,
 	 * to make sure all slices/subslices are ON before writing to NOA
 	 * registers.
 	 */
-	ret = gen8_configure_all_contexts(dev_priv, oa_config, true);
+	ret = gen8_configure_all_contexts(dev_priv, oa_config, false);
 	if (ret)
 		return ret;
 
@@ -1878,7 +1874,7 @@ static int gen8_enable_metric_set(struct drm_i915_private *dev_priv,
 static void gen8_disable_metric_set(struct drm_i915_private *dev_priv)
 {
 	/* Reset all contexts' slices/subslices configurations. */
-	gen8_configure_all_contexts(dev_priv, NULL, false);
+	gen8_configure_all_contexts(dev_priv, NULL, true);
 
 	I915_WRITE(GDT_CHICKEN_BITS, (I915_READ(GDT_CHICKEN_BITS) &
 				      ~GT_NOA_ENABLE));
@@ -1888,7 +1884,7 @@ static void gen8_disable_metric_set(struct drm_i915_private *dev_priv)
 static void gen10_disable_metric_set(struct drm_i915_private *dev_priv)
 {
 	/* Reset all contexts' slices/subslices configurations. */
-	gen8_configure_all_contexts(dev_priv, NULL, false);
+	gen8_configure_all_contexts(dev_priv, NULL, true);
 
 	/* Make sure we disable noa to save power. */
 	I915_WRITE(RPM_CONFIG1,
@@ -2138,13 +2134,6 @@ static int i915_oa_stream_init(struct i915_perf_stream *stream,
 	if (ret)
 		goto err_oa_buf_alloc;
 
-	ret = dev_priv->perf.oa.ops.enable_metric_set(dev_priv,
-						      stream->oa_config);
-	if (ret)
-		goto err_enable;
-
-	stream->ops = &i915_oa_stream_ops;
-
 	/* Lock device for exclusive_stream access late because
 	 * enable_metric_set() might lock as well on gen8+.
 	 */
@@ -2152,16 +2141,24 @@ static int i915_oa_stream_init(struct i915_perf_stream *stream,
 	if (ret)
 		goto err_lock;
 
+	ret = dev_priv->perf.oa.ops.enable_metric_set(dev_priv,
+						      stream->oa_config);
+	if (ret)
+		goto err_enable;
+
+	stream->ops = &i915_oa_stream_ops;
+
 	dev_priv->perf.oa.exclusive_stream = stream;
 
 	mutex_unlock(&dev_priv->drm.struct_mutex);
 
 	return 0;
 
-err_lock:
+err_enable:
+	mutex_unlock(&dev_priv->drm.struct_mutex);
 	dev_priv->perf.oa.ops.disable_metric_set(dev_priv);
 
-err_enable:
+err_lock:
 	free_oa_buffer(dev_priv);
 
 err_oa_buf_alloc:
-- 
2.16.1

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

* ✓ Fi.CI.BAT: success for drm/i915/perf: fix perf stream opening lock
  2018-02-28 11:45 [PATCH] drm/i915/perf: fix perf stream opening lock Lionel Landwerlin
@ 2018-02-28 12:14 ` Patchwork
  2018-02-28 14:54 ` ✓ Fi.CI.IGT: " Patchwork
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: Patchwork @ 2018-02-28 12:14 UTC (permalink / raw)
  To: Lionel Landwerlin; +Cc: intel-gfx

== Series Details ==

Series: drm/i915/perf: fix perf stream opening lock
URL   : https://patchwork.freedesktop.org/series/39112/
State : success

== Summary ==

Series 39112v1 drm/i915/perf: fix perf stream opening lock
https://patchwork.freedesktop.org/api/1.0/series/39112/revisions/1/mbox/

---- Known issues:

Test gem_ringfill:
        Subgroup basic-default-hang:
                dmesg-warn -> INCOMPLETE (fi-pnv-d510) fdo#101600
Test kms_pipe_crc_basic:
        Subgroup suspend-read-crc-pipe-b:
                pass       -> INCOMPLETE (fi-snb-2520m) fdo#103713

fdo#101600 https://bugs.freedesktop.org/show_bug.cgi?id=101600
fdo#103713 https://bugs.freedesktop.org/show_bug.cgi?id=103713

fi-bdw-5557u     total:288  pass:267  dwarn:0   dfail:0   fail:0   skip:21  time:415s
fi-bdw-gvtdvm    total:288  pass:264  dwarn:0   dfail:0   fail:0   skip:24  time:425s
fi-blb-e6850     total:288  pass:223  dwarn:1   dfail:0   fail:0   skip:64  time:375s
fi-bsw-n3050     total:288  pass:242  dwarn:0   dfail:0   fail:0   skip:46  time:488s
fi-bwr-2160      total:288  pass:183  dwarn:0   dfail:0   fail:0   skip:105 time:286s
fi-bxt-dsi       total:288  pass:258  dwarn:0   dfail:0   fail:0   skip:30  time:479s
fi-bxt-j4205     total:288  pass:259  dwarn:0   dfail:0   fail:0   skip:29  time:485s
fi-byt-j1900     total:288  pass:253  dwarn:0   dfail:0   fail:0   skip:35  time:471s
fi-byt-n2820     total:288  pass:249  dwarn:0   dfail:0   fail:0   skip:39  time:459s
fi-cfl-8700k     total:288  pass:260  dwarn:0   dfail:0   fail:0   skip:28  time:397s
fi-cfl-s2        total:288  pass:262  dwarn:0   dfail:0   fail:0   skip:26  time:562s
fi-cnl-y3        total:288  pass:262  dwarn:0   dfail:0   fail:0   skip:26  time:585s
fi-elk-e7500     total:288  pass:229  dwarn:0   dfail:0   fail:0   skip:59  time:417s
fi-gdg-551       total:288  pass:179  dwarn:0   dfail:0   fail:1   skip:108 time:285s
fi-glk-1         total:288  pass:260  dwarn:0   dfail:0   fail:0   skip:28  time:513s
fi-hsw-4770      total:288  pass:261  dwarn:0   dfail:0   fail:0   skip:27  time:388s
fi-ilk-650       total:288  pass:228  dwarn:0   dfail:0   fail:0   skip:60  time:410s
fi-ivb-3520m     total:288  pass:259  dwarn:0   dfail:0   fail:0   skip:29  time:463s
fi-ivb-3770      total:288  pass:255  dwarn:0   dfail:0   fail:0   skip:33  time:414s
fi-kbl-7500u     total:288  pass:263  dwarn:1   dfail:0   fail:0   skip:24  time:447s
fi-kbl-7560u     total:288  pass:269  dwarn:0   dfail:0   fail:0   skip:19  time:490s
fi-kbl-7567u     total:288  pass:268  dwarn:0   dfail:0   fail:0   skip:20  time:451s
fi-kbl-r         total:288  pass:261  dwarn:0   dfail:0   fail:0   skip:27  time:497s
fi-pnv-d510      total:146  pass:113  dwarn:0   dfail:0   fail:0   skip:32 
fi-skl-6260u     total:288  pass:268  dwarn:0   dfail:0   fail:0   skip:20  time:433s
fi-skl-6600u     total:288  pass:261  dwarn:0   dfail:0   fail:0   skip:27  time:502s
fi-skl-6700hq    total:288  pass:262  dwarn:0   dfail:0   fail:0   skip:26  time:519s
fi-skl-6700k2    total:288  pass:264  dwarn:0   dfail:0   fail:0   skip:24  time:485s
fi-skl-6770hq    total:288  pass:268  dwarn:0   dfail:0   fail:0   skip:20  time:477s
fi-skl-guc       total:288  pass:260  dwarn:0   dfail:0   fail:0   skip:28  time:409s
fi-skl-gvtdvm    total:288  pass:265  dwarn:0   dfail:0   fail:0   skip:23  time:429s
fi-snb-2520m     total:245  pass:211  dwarn:0   dfail:0   fail:0   skip:33 
fi-snb-2600      total:288  pass:248  dwarn:0   dfail:0   fail:0   skip:40  time:393s

9a02ae14ae024bdbb268333cddccbaf01d8f02ef drm-tip: 2018y-02m-28d-10h-13m-18s UTC integration manifest
7d20f8980c5b drm/i915/perf: fix perf stream opening lock

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_8186/issues.html
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

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

* ✓ Fi.CI.IGT: success for drm/i915/perf: fix perf stream opening lock
  2018-02-28 11:45 [PATCH] drm/i915/perf: fix perf stream opening lock Lionel Landwerlin
  2018-02-28 12:14 ` ✓ Fi.CI.BAT: success for " Patchwork
@ 2018-02-28 14:54 ` Patchwork
  2018-02-28 18:10   ` Matthew Auld
  2018-03-01  8:18 ` [Intel-gfx] " Chris Wilson
  3 siblings, 0 replies; 8+ messages in thread
From: Patchwork @ 2018-02-28 14:54 UTC (permalink / raw)
  To: Lionel Landwerlin; +Cc: intel-gfx

== Series Details ==

Series: drm/i915/perf: fix perf stream opening lock
URL   : https://patchwork.freedesktop.org/series/39112/
State : success

== Summary ==

---- Possible new issues:

Test kms_rotation_crc:
        Subgroup primary-rotation-270:
                fail       -> PASS       (shard-apl)

---- Known issues:

Test gem_softpin:
        Subgroup noreloc-s3:
                incomplete -> PASS       (shard-hsw) fdo#103540
Test kms_chv_cursor_fail:
        Subgroup pipe-b-256x256-left-edge:
                dmesg-warn -> PASS       (shard-snb) fdo#105185
Test kms_flip:
        Subgroup basic-flip-vs-wf_vblank:
                pass       -> FAIL       (shard-hsw) fdo#103928
        Subgroup modeset-vs-vblank-race:
                pass       -> FAIL       (shard-hsw) fdo#103060
        Subgroup plain-flip-ts-check-interruptible:
                fail       -> PASS       (shard-hsw) fdo#100368
Test perf:
        Subgroup oa-exponents:
                incomplete -> PASS       (shard-apl) fdo#102254
        Subgroup polling:
                fail       -> PASS       (shard-hsw) fdo#102252
Test perf_pmu:
        Subgroup busy-start-vcs0:
                pass       -> FAIL       (shard-snb) fdo#105106

fdo#103540 https://bugs.freedesktop.org/show_bug.cgi?id=103540
fdo#105185 https://bugs.freedesktop.org/show_bug.cgi?id=105185
fdo#103928 https://bugs.freedesktop.org/show_bug.cgi?id=103928
fdo#103060 https://bugs.freedesktop.org/show_bug.cgi?id=103060
fdo#100368 https://bugs.freedesktop.org/show_bug.cgi?id=100368
fdo#102254 https://bugs.freedesktop.org/show_bug.cgi?id=102254
fdo#102252 https://bugs.freedesktop.org/show_bug.cgi?id=102252
fdo#105106 https://bugs.freedesktop.org/show_bug.cgi?id=105106

shard-apl        total:3460 pass:1819 dwarn:1   dfail:0   fail:7   skip:1632 time:12215s
shard-hsw        total:3460 pass:1765 dwarn:1   dfail:0   fail:3   skip:1690 time:11640s
shard-snb        total:3460 pass:1357 dwarn:1   dfail:0   fail:3   skip:2099 time:6604s
Blacklisted hosts:
shard-kbl        total:3452 pass:1939 dwarn:1   dfail:0   fail:7   skip:1504 time:9341s

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_8186/shards.html
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

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

* Re: [Intel-gfx] [PATCH] drm/i915/perf: fix perf stream opening lock
  2018-02-28 11:45 [PATCH] drm/i915/perf: fix perf stream opening lock Lionel Landwerlin
@ 2018-02-28 18:10   ` Matthew Auld
  2018-02-28 14:54 ` ✓ Fi.CI.IGT: " Patchwork
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: Matthew Auld @ 2018-02-28 18:10 UTC (permalink / raw)
  To: Lionel Landwerlin; +Cc: Intel Graphics Development, stable, Matthew Auld

On 28 February 2018 at 11:45, Lionel Landwerlin
<lionel.g.landwerlin@intel.com> wrote:
> We're seeing on CI that some contexts don't have the programmed OA
> period timer that directs the OA unit on how often to write reports.
>
> The issue is that we're not holding the drm lock from when we edit the
> context images down to when we set the exclusive_stream variable. This
> leaves a window for the deferred context allocation to call
> i915_oa_init_reg_state() that will not program the expected OA timer
> value, because we haven't set the exclusive_stream yet.
>
> Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
> Fixes: 701f8231a2f ("drm/i915/perf: prune OA configs")
> Cc: <stable@vger.kernel.org> # v4.14+
> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=102254
> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=103715
> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=103755
> ---
>  drivers/gpu/drm/i915/i915_perf.c | 41 +++++++++++++++++++---------------------
>  1 file changed, 19 insertions(+), 22 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c
> index 2741b1bc7095..7016abfc8ba9 100644
> --- a/drivers/gpu/drm/i915/i915_perf.c
> +++ b/drivers/gpu/drm/i915/i915_perf.c
> @@ -1757,21 +1757,16 @@ static int gen8_switch_to_updated_kernel_context(struct drm_i915_private *dev_pr
>   */
>  static int gen8_configure_all_contexts(struct drm_i915_private *dev_priv,
>                                        const struct i915_oa_config *oa_config,
> -                                      bool interruptible)
> +                                      bool need_lock)
>  {
>         struct i915_gem_context *ctx;
>         int ret;
>         unsigned int wait_flags = I915_WAIT_LOCKED;
>
> -       if (interruptible) {
> -               ret = i915_mutex_lock_interruptible(&dev_priv->drm);
> -               if (ret)
> -                       return ret;
> -
> -               wait_flags |= I915_WAIT_INTERRUPTIBLE;
> -       } else {
> +       if (need_lock)
>                 mutex_lock(&dev_priv->drm.struct_mutex);
> -       }
> +
> +       lockdep_assert_held(&dev_priv->drm.struct_mutex);
>
>         /* Switch away from any user context. */
>         ret = gen8_switch_to_updated_kernel_context(dev_priv, oa_config);
> @@ -1819,7 +1814,8 @@ static int gen8_configure_all_contexts(struct drm_i915_private *dev_priv,
>         }
>
>   out:
> -       mutex_unlock(&dev_priv->drm.struct_mutex);
> +       if (need_lock)
> +               mutex_unlock(&dev_priv->drm.struct_mutex);
>
>         return ret;
>  }
> @@ -1863,7 +1859,7 @@ static int gen8_enable_metric_set(struct drm_i915_private *dev_priv,
>          * to make sure all slices/subslices are ON before writing to NOA
>          * registers.
>          */
> -       ret = gen8_configure_all_contexts(dev_priv, oa_config, true);
> +       ret = gen8_configure_all_contexts(dev_priv, oa_config, false);
>         if (ret)
>                 return ret;
>
> @@ -1878,7 +1874,7 @@ static int gen8_enable_metric_set(struct drm_i915_private *dev_priv,
>  static void gen8_disable_metric_set(struct drm_i915_private *dev_priv)
>  {
>         /* Reset all contexts' slices/subslices configurations. */
> -       gen8_configure_all_contexts(dev_priv, NULL, false);
> +       gen8_configure_all_contexts(dev_priv, NULL, true);

Maybe move the ops.disable_metric_set() to also be within the lock, so
need_lock=false, then we can get rid of need_lock?

>
>         I915_WRITE(GDT_CHICKEN_BITS, (I915_READ(GDT_CHICKEN_BITS) &
>                                       ~GT_NOA_ENABLE));
> @@ -1888,7 +1884,7 @@ static void gen8_disable_metric_set(struct drm_i915_private *dev_priv)
>  static void gen10_disable_metric_set(struct drm_i915_private *dev_priv)
>  {
>         /* Reset all contexts' slices/subslices configurations. */
> -       gen8_configure_all_contexts(dev_priv, NULL, false);
> +       gen8_configure_all_contexts(dev_priv, NULL, true);
>
>         /* Make sure we disable noa to save power. */
>         I915_WRITE(RPM_CONFIG1,
> @@ -2138,13 +2134,6 @@ static int i915_oa_stream_init(struct i915_perf_stream *stream,
>         if (ret)
>                 goto err_oa_buf_alloc;
>
> -       ret = dev_priv->perf.oa.ops.enable_metric_set(dev_priv,
> -                                                     stream->oa_config);
> -       if (ret)
> -               goto err_enable;
> -
> -       stream->ops = &i915_oa_stream_ops;
> -
>         /* Lock device for exclusive_stream access late because
>          * enable_metric_set() might lock as well on gen8+.
>          */

Ok, we can get rid of this comment now.

> @@ -2152,16 +2141,24 @@ static int i915_oa_stream_init(struct i915_perf_stream *stream,
>         if (ret)
>                 goto err_lock;
>
> +       ret = dev_priv->perf.oa.ops.enable_metric_set(dev_priv,
> +                                                     stream->oa_config);
> +       if (ret)
> +               goto err_enable;
> +
> +       stream->ops = &i915_oa_stream_ops;
> +
>         dev_priv->perf.oa.exclusive_stream = stream;
>
>         mutex_unlock(&dev_priv->drm.struct_mutex);
>
>         return 0;
>
> -err_lock:
> +err_enable:
> +       mutex_unlock(&dev_priv->drm.struct_mutex);
>         dev_priv->perf.oa.ops.disable_metric_set(dev_priv);

We can drop the disable_metric_set here; no need to disable it if we
never enabled it.

Nice catch,
Reviewed-by: Matthew Auld <matthew.auld@intel.com>

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

* Re: [PATCH] drm/i915/perf: fix perf stream opening lock
@ 2018-02-28 18:10   ` Matthew Auld
  0 siblings, 0 replies; 8+ messages in thread
From: Matthew Auld @ 2018-02-28 18:10 UTC (permalink / raw)
  To: Lionel Landwerlin; +Cc: Intel Graphics Development, Matthew Auld, stable

On 28 February 2018 at 11:45, Lionel Landwerlin
<lionel.g.landwerlin@intel.com> wrote:
> We're seeing on CI that some contexts don't have the programmed OA
> period timer that directs the OA unit on how often to write reports.
>
> The issue is that we're not holding the drm lock from when we edit the
> context images down to when we set the exclusive_stream variable. This
> leaves a window for the deferred context allocation to call
> i915_oa_init_reg_state() that will not program the expected OA timer
> value, because we haven't set the exclusive_stream yet.
>
> Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
> Fixes: 701f8231a2f ("drm/i915/perf: prune OA configs")
> Cc: <stable@vger.kernel.org> # v4.14+
> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=102254
> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=103715
> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=103755
> ---
>  drivers/gpu/drm/i915/i915_perf.c | 41 +++++++++++++++++++---------------------
>  1 file changed, 19 insertions(+), 22 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c
> index 2741b1bc7095..7016abfc8ba9 100644
> --- a/drivers/gpu/drm/i915/i915_perf.c
> +++ b/drivers/gpu/drm/i915/i915_perf.c
> @@ -1757,21 +1757,16 @@ static int gen8_switch_to_updated_kernel_context(struct drm_i915_private *dev_pr
>   */
>  static int gen8_configure_all_contexts(struct drm_i915_private *dev_priv,
>                                        const struct i915_oa_config *oa_config,
> -                                      bool interruptible)
> +                                      bool need_lock)
>  {
>         struct i915_gem_context *ctx;
>         int ret;
>         unsigned int wait_flags = I915_WAIT_LOCKED;
>
> -       if (interruptible) {
> -               ret = i915_mutex_lock_interruptible(&dev_priv->drm);
> -               if (ret)
> -                       return ret;
> -
> -               wait_flags |= I915_WAIT_INTERRUPTIBLE;
> -       } else {
> +       if (need_lock)
>                 mutex_lock(&dev_priv->drm.struct_mutex);
> -       }
> +
> +       lockdep_assert_held(&dev_priv->drm.struct_mutex);
>
>         /* Switch away from any user context. */
>         ret = gen8_switch_to_updated_kernel_context(dev_priv, oa_config);
> @@ -1819,7 +1814,8 @@ static int gen8_configure_all_contexts(struct drm_i915_private *dev_priv,
>         }
>
>   out:
> -       mutex_unlock(&dev_priv->drm.struct_mutex);
> +       if (need_lock)
> +               mutex_unlock(&dev_priv->drm.struct_mutex);
>
>         return ret;
>  }
> @@ -1863,7 +1859,7 @@ static int gen8_enable_metric_set(struct drm_i915_private *dev_priv,
>          * to make sure all slices/subslices are ON before writing to NOA
>          * registers.
>          */
> -       ret = gen8_configure_all_contexts(dev_priv, oa_config, true);
> +       ret = gen8_configure_all_contexts(dev_priv, oa_config, false);
>         if (ret)
>                 return ret;
>
> @@ -1878,7 +1874,7 @@ static int gen8_enable_metric_set(struct drm_i915_private *dev_priv,
>  static void gen8_disable_metric_set(struct drm_i915_private *dev_priv)
>  {
>         /* Reset all contexts' slices/subslices configurations. */
> -       gen8_configure_all_contexts(dev_priv, NULL, false);
> +       gen8_configure_all_contexts(dev_priv, NULL, true);

Maybe move the ops.disable_metric_set() to also be within the lock, so
need_lock=false, then we can get rid of need_lock?

>
>         I915_WRITE(GDT_CHICKEN_BITS, (I915_READ(GDT_CHICKEN_BITS) &
>                                       ~GT_NOA_ENABLE));
> @@ -1888,7 +1884,7 @@ static void gen8_disable_metric_set(struct drm_i915_private *dev_priv)
>  static void gen10_disable_metric_set(struct drm_i915_private *dev_priv)
>  {
>         /* Reset all contexts' slices/subslices configurations. */
> -       gen8_configure_all_contexts(dev_priv, NULL, false);
> +       gen8_configure_all_contexts(dev_priv, NULL, true);
>
>         /* Make sure we disable noa to save power. */
>         I915_WRITE(RPM_CONFIG1,
> @@ -2138,13 +2134,6 @@ static int i915_oa_stream_init(struct i915_perf_stream *stream,
>         if (ret)
>                 goto err_oa_buf_alloc;
>
> -       ret = dev_priv->perf.oa.ops.enable_metric_set(dev_priv,
> -                                                     stream->oa_config);
> -       if (ret)
> -               goto err_enable;
> -
> -       stream->ops = &i915_oa_stream_ops;
> -
>         /* Lock device for exclusive_stream access late because
>          * enable_metric_set() might lock as well on gen8+.
>          */

Ok, we can get rid of this comment now.

> @@ -2152,16 +2141,24 @@ static int i915_oa_stream_init(struct i915_perf_stream *stream,
>         if (ret)
>                 goto err_lock;
>
> +       ret = dev_priv->perf.oa.ops.enable_metric_set(dev_priv,
> +                                                     stream->oa_config);
> +       if (ret)
> +               goto err_enable;
> +
> +       stream->ops = &i915_oa_stream_ops;
> +
>         dev_priv->perf.oa.exclusive_stream = stream;
>
>         mutex_unlock(&dev_priv->drm.struct_mutex);
>
>         return 0;
>
> -err_lock:
> +err_enable:
> +       mutex_unlock(&dev_priv->drm.struct_mutex);
>         dev_priv->perf.oa.ops.disable_metric_set(dev_priv);

We can drop the disable_metric_set here; no need to disable it if we
never enabled it.

Nice catch,
Reviewed-by: Matthew Auld <matthew.auld@intel.com>
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

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

* Re: [Intel-gfx] [PATCH] drm/i915/perf: fix perf stream opening lock
  2018-02-28 11:45 [PATCH] drm/i915/perf: fix perf stream opening lock Lionel Landwerlin
                   ` (2 preceding siblings ...)
  2018-02-28 18:10   ` Matthew Auld
@ 2018-03-01  8:18 ` Chris Wilson
  3 siblings, 0 replies; 8+ messages in thread
From: Chris Wilson @ 2018-03-01  8:18 UTC (permalink / raw)
  To: Lionel Landwerlin, intel-gfx; +Cc: stable, matthew.auld

Quoting Lionel Landwerlin (2018-02-28 11:45:48)
> We're seeing on CI that some contexts don't have the programmed OA
> period timer that directs the OA unit on how often to write reports.
> 
> The issue is that we're not holding the drm lock from when we edit the
> context images down to when we set the exclusive_stream variable. This
> leaves a window for the deferred context allocation to call
> i915_oa_init_reg_state() that will not program the expected OA timer
> value, because we haven't set the exclusive_stream yet.

Thank you for this quick explanation. After staring at the diff to
figure out what race you saw, the succinct explanation of the window
between altering all previous contexts and marking up new contexts,
enlightens.

> Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
> Fixes: 701f8231a2f ("drm/i915/perf: prune OA configs")
> Cc: <stable@vger.kernel.org> # v4.14+
> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=102254
> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=103715
> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=103755

Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
-Chris

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

* Re: [Intel-gfx] [PATCH] drm/i915/perf: fix perf stream opening lock
  2018-02-28 18:10   ` Matthew Auld
@ 2018-03-01 10:30     ` Lionel Landwerlin
  -1 siblings, 0 replies; 8+ messages in thread
From: Lionel Landwerlin @ 2018-03-01 10:30 UTC (permalink / raw)
  To: Matthew Auld; +Cc: Intel Graphics Development, stable, Matthew Auld

On 28/02/18 18:10, Matthew Auld wrote:
> On 28 February 2018 at 11:45, Lionel Landwerlin
> <lionel.g.landwerlin@intel.com> wrote:
>> We're seeing on CI that some contexts don't have the programmed OA
>> period timer that directs the OA unit on how often to write reports.
>>
>> The issue is that we're not holding the drm lock from when we edit the
>> context images down to when we set the exclusive_stream variable. This
>> leaves a window for the deferred context allocation to call
>> i915_oa_init_reg_state() that will not program the expected OA timer
>> value, because we haven't set the exclusive_stream yet.
>>
>> Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
>> Fixes: 701f8231a2f ("drm/i915/perf: prune OA configs")
>> Cc: <stable@vger.kernel.org> # v4.14+
>> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=102254
>> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=103715
>> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=103755
>> ---
>>   drivers/gpu/drm/i915/i915_perf.c | 41 +++++++++++++++++++---------------------
>>   1 file changed, 19 insertions(+), 22 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c
>> index 2741b1bc7095..7016abfc8ba9 100644
>> --- a/drivers/gpu/drm/i915/i915_perf.c
>> +++ b/drivers/gpu/drm/i915/i915_perf.c
>> @@ -1757,21 +1757,16 @@ static int gen8_switch_to_updated_kernel_context(struct drm_i915_private *dev_pr
>>    */
>>   static int gen8_configure_all_contexts(struct drm_i915_private *dev_priv,
>>                                         const struct i915_oa_config *oa_config,
>> -                                      bool interruptible)
>> +                                      bool need_lock)
>>   {
>>          struct i915_gem_context *ctx;
>>          int ret;
>>          unsigned int wait_flags = I915_WAIT_LOCKED;
>>
>> -       if (interruptible) {
>> -               ret = i915_mutex_lock_interruptible(&dev_priv->drm);
>> -               if (ret)
>> -                       return ret;
>> -
>> -               wait_flags |= I915_WAIT_INTERRUPTIBLE;
>> -       } else {
>> +       if (need_lock)
>>                  mutex_lock(&dev_priv->drm.struct_mutex);
>> -       }
>> +
>> +       lockdep_assert_held(&dev_priv->drm.struct_mutex);
>>
>>          /* Switch away from any user context. */
>>          ret = gen8_switch_to_updated_kernel_context(dev_priv, oa_config);
>> @@ -1819,7 +1814,8 @@ static int gen8_configure_all_contexts(struct drm_i915_private *dev_priv,
>>          }
>>
>>    out:
>> -       mutex_unlock(&dev_priv->drm.struct_mutex);
>> +       if (need_lock)
>> +               mutex_unlock(&dev_priv->drm.struct_mutex);
>>
>>          return ret;
>>   }
>> @@ -1863,7 +1859,7 @@ static int gen8_enable_metric_set(struct drm_i915_private *dev_priv,
>>           * to make sure all slices/subslices are ON before writing to NOA
>>           * registers.
>>           */
>> -       ret = gen8_configure_all_contexts(dev_priv, oa_config, true);
>> +       ret = gen8_configure_all_contexts(dev_priv, oa_config, false);
>>          if (ret)
>>                  return ret;
>>
>> @@ -1878,7 +1874,7 @@ static int gen8_enable_metric_set(struct drm_i915_private *dev_priv,
>>   static void gen8_disable_metric_set(struct drm_i915_private *dev_priv)
>>   {
>>          /* Reset all contexts' slices/subslices configurations. */
>> -       gen8_configure_all_contexts(dev_priv, NULL, false);
>> +       gen8_configure_all_contexts(dev_priv, NULL, true);
> Maybe move the ops.disable_metric_set() to also be within the lock, so
> need_lock=false, then we can get rid of need_lock?

Yeah, sounds like a nice cleanup.

>
>>          I915_WRITE(GDT_CHICKEN_BITS, (I915_READ(GDT_CHICKEN_BITS) &
>>                                        ~GT_NOA_ENABLE));
>> @@ -1888,7 +1884,7 @@ static void gen8_disable_metric_set(struct drm_i915_private *dev_priv)
>>   static void gen10_disable_metric_set(struct drm_i915_private *dev_priv)
>>   {
>>          /* Reset all contexts' slices/subslices configurations. */
>> -       gen8_configure_all_contexts(dev_priv, NULL, false);
>> +       gen8_configure_all_contexts(dev_priv, NULL, true);
>>
>>          /* Make sure we disable noa to save power. */
>>          I915_WRITE(RPM_CONFIG1,
>> @@ -2138,13 +2134,6 @@ static int i915_oa_stream_init(struct i915_perf_stream *stream,
>>          if (ret)
>>                  goto err_oa_buf_alloc;
>>
>> -       ret = dev_priv->perf.oa.ops.enable_metric_set(dev_priv,
>> -                                                     stream->oa_config);
>> -       if (ret)
>> -               goto err_enable;
>> -
>> -       stream->ops = &i915_oa_stream_ops;
>> -
>>          /* Lock device for exclusive_stream access late because
>>           * enable_metric_set() might lock as well on gen8+.
>>           */
> Ok, we can get rid of this comment now.

Thanks, removing.

>
>> @@ -2152,16 +2141,24 @@ static int i915_oa_stream_init(struct i915_perf_stream *stream,
>>          if (ret)
>>                  goto err_lock;
>>
>> +       ret = dev_priv->perf.oa.ops.enable_metric_set(dev_priv,
>> +                                                     stream->oa_config);
>> +       if (ret)
>> +               goto err_enable;
>> +
>> +       stream->ops = &i915_oa_stream_ops;
>> +
>>          dev_priv->perf.oa.exclusive_stream = stream;
>>
>>          mutex_unlock(&dev_priv->drm.struct_mutex);
>>
>>          return 0;
>>
>> -err_lock:
>> +err_enable:
>> +       mutex_unlock(&dev_priv->drm.struct_mutex);
>>          dev_priv->perf.oa.ops.disable_metric_set(dev_priv);
> We can drop the disable_metric_set here; no need to disable it if we
> never enabled it.

Well in this case we did, we edited all the context images.
Better cleanup out changes.

>
> Nice catch,
> Reviewed-by: Matthew Auld <matthew.auld@intel.com>
>

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

* Re: [PATCH] drm/i915/perf: fix perf stream opening lock
@ 2018-03-01 10:30     ` Lionel Landwerlin
  0 siblings, 0 replies; 8+ messages in thread
From: Lionel Landwerlin @ 2018-03-01 10:30 UTC (permalink / raw)
  To: Matthew Auld; +Cc: Intel Graphics Development, Matthew Auld, stable

On 28/02/18 18:10, Matthew Auld wrote:
> On 28 February 2018 at 11:45, Lionel Landwerlin
> <lionel.g.landwerlin@intel.com> wrote:
>> We're seeing on CI that some contexts don't have the programmed OA
>> period timer that directs the OA unit on how often to write reports.
>>
>> The issue is that we're not holding the drm lock from when we edit the
>> context images down to when we set the exclusive_stream variable. This
>> leaves a window for the deferred context allocation to call
>> i915_oa_init_reg_state() that will not program the expected OA timer
>> value, because we haven't set the exclusive_stream yet.
>>
>> Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
>> Fixes: 701f8231a2f ("drm/i915/perf: prune OA configs")
>> Cc: <stable@vger.kernel.org> # v4.14+
>> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=102254
>> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=103715
>> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=103755
>> ---
>>   drivers/gpu/drm/i915/i915_perf.c | 41 +++++++++++++++++++---------------------
>>   1 file changed, 19 insertions(+), 22 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c
>> index 2741b1bc7095..7016abfc8ba9 100644
>> --- a/drivers/gpu/drm/i915/i915_perf.c
>> +++ b/drivers/gpu/drm/i915/i915_perf.c
>> @@ -1757,21 +1757,16 @@ static int gen8_switch_to_updated_kernel_context(struct drm_i915_private *dev_pr
>>    */
>>   static int gen8_configure_all_contexts(struct drm_i915_private *dev_priv,
>>                                         const struct i915_oa_config *oa_config,
>> -                                      bool interruptible)
>> +                                      bool need_lock)
>>   {
>>          struct i915_gem_context *ctx;
>>          int ret;
>>          unsigned int wait_flags = I915_WAIT_LOCKED;
>>
>> -       if (interruptible) {
>> -               ret = i915_mutex_lock_interruptible(&dev_priv->drm);
>> -               if (ret)
>> -                       return ret;
>> -
>> -               wait_flags |= I915_WAIT_INTERRUPTIBLE;
>> -       } else {
>> +       if (need_lock)
>>                  mutex_lock(&dev_priv->drm.struct_mutex);
>> -       }
>> +
>> +       lockdep_assert_held(&dev_priv->drm.struct_mutex);
>>
>>          /* Switch away from any user context. */
>>          ret = gen8_switch_to_updated_kernel_context(dev_priv, oa_config);
>> @@ -1819,7 +1814,8 @@ static int gen8_configure_all_contexts(struct drm_i915_private *dev_priv,
>>          }
>>
>>    out:
>> -       mutex_unlock(&dev_priv->drm.struct_mutex);
>> +       if (need_lock)
>> +               mutex_unlock(&dev_priv->drm.struct_mutex);
>>
>>          return ret;
>>   }
>> @@ -1863,7 +1859,7 @@ static int gen8_enable_metric_set(struct drm_i915_private *dev_priv,
>>           * to make sure all slices/subslices are ON before writing to NOA
>>           * registers.
>>           */
>> -       ret = gen8_configure_all_contexts(dev_priv, oa_config, true);
>> +       ret = gen8_configure_all_contexts(dev_priv, oa_config, false);
>>          if (ret)
>>                  return ret;
>>
>> @@ -1878,7 +1874,7 @@ static int gen8_enable_metric_set(struct drm_i915_private *dev_priv,
>>   static void gen8_disable_metric_set(struct drm_i915_private *dev_priv)
>>   {
>>          /* Reset all contexts' slices/subslices configurations. */
>> -       gen8_configure_all_contexts(dev_priv, NULL, false);
>> +       gen8_configure_all_contexts(dev_priv, NULL, true);
> Maybe move the ops.disable_metric_set() to also be within the lock, so
> need_lock=false, then we can get rid of need_lock?

Yeah, sounds like a nice cleanup.

>
>>          I915_WRITE(GDT_CHICKEN_BITS, (I915_READ(GDT_CHICKEN_BITS) &
>>                                        ~GT_NOA_ENABLE));
>> @@ -1888,7 +1884,7 @@ static void gen8_disable_metric_set(struct drm_i915_private *dev_priv)
>>   static void gen10_disable_metric_set(struct drm_i915_private *dev_priv)
>>   {
>>          /* Reset all contexts' slices/subslices configurations. */
>> -       gen8_configure_all_contexts(dev_priv, NULL, false);
>> +       gen8_configure_all_contexts(dev_priv, NULL, true);
>>
>>          /* Make sure we disable noa to save power. */
>>          I915_WRITE(RPM_CONFIG1,
>> @@ -2138,13 +2134,6 @@ static int i915_oa_stream_init(struct i915_perf_stream *stream,
>>          if (ret)
>>                  goto err_oa_buf_alloc;
>>
>> -       ret = dev_priv->perf.oa.ops.enable_metric_set(dev_priv,
>> -                                                     stream->oa_config);
>> -       if (ret)
>> -               goto err_enable;
>> -
>> -       stream->ops = &i915_oa_stream_ops;
>> -
>>          /* Lock device for exclusive_stream access late because
>>           * enable_metric_set() might lock as well on gen8+.
>>           */
> Ok, we can get rid of this comment now.

Thanks, removing.

>
>> @@ -2152,16 +2141,24 @@ static int i915_oa_stream_init(struct i915_perf_stream *stream,
>>          if (ret)
>>                  goto err_lock;
>>
>> +       ret = dev_priv->perf.oa.ops.enable_metric_set(dev_priv,
>> +                                                     stream->oa_config);
>> +       if (ret)
>> +               goto err_enable;
>> +
>> +       stream->ops = &i915_oa_stream_ops;
>> +
>>          dev_priv->perf.oa.exclusive_stream = stream;
>>
>>          mutex_unlock(&dev_priv->drm.struct_mutex);
>>
>>          return 0;
>>
>> -err_lock:
>> +err_enable:
>> +       mutex_unlock(&dev_priv->drm.struct_mutex);
>>          dev_priv->perf.oa.ops.disable_metric_set(dev_priv);
> We can drop the disable_metric_set here; no need to disable it if we
> never enabled it.

Well in this case we did, we edited all the context images.
Better cleanup out changes.

>
> Nice catch,
> Reviewed-by: Matthew Auld <matthew.auld@intel.com>
>

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

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

end of thread, other threads:[~2018-03-01 10:30 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-28 11:45 [PATCH] drm/i915/perf: fix perf stream opening lock Lionel Landwerlin
2018-02-28 12:14 ` ✓ Fi.CI.BAT: success for " Patchwork
2018-02-28 14:54 ` ✓ Fi.CI.IGT: " Patchwork
2018-02-28 18:10 ` [Intel-gfx] [PATCH] " Matthew Auld
2018-02-28 18:10   ` Matthew Auld
2018-03-01 10:30   ` [Intel-gfx] " Lionel Landwerlin
2018-03-01 10:30     ` Lionel Landwerlin
2018-03-01  8:18 ` [Intel-gfx] " Chris Wilson

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.