Re: [Intel-gfx] [PATCH 06/15] drm/i915: Populate ctx ID for periodic OA reports

2016-11-04 Thread Chris Wilson
On Fri, Nov 04, 2016 at 03:00:35PM +0530, sourab.gu...@intel.com wrote:
> +static u32 gen8_oa_buffer_get_ctx_id(struct i915_perf_stream *stream,
> + const u8 *report)
> +{
> + struct drm_i915_private *dev_priv = stream->dev_priv;
> +
> + /* The ctx ID present in the OA reports have intel_context::global_id
> +  * present, since this is programmed into the ELSP in execlist mode.
> +  * In non-execlist mode, fall back to retrieving the ctx ID from the
> +  * last saved ctx ID from command stream mode.
> +  */
> + if (i915.enable_execlists) {
> + u32 ctx_id = *(u32 *)(report + 12);
> + ctx_id &= 0xf;

This does not match the hw maximum. Please check to see who is correct.

> + return ctx_id;
> + } else {
> + if (!stream->cs_mode)
> + WARN_ONCE(1,
> + "CTX ID can't be retrieved if command stream mode not 
> enabled");

All these WARNs appear to be user triggerable.
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH 06/15] drm/i915: Populate ctx ID for periodic OA reports

2016-11-04 Thread sourab . gupta
From: Sourab Gupta 

This adds support for populating the ctx id for the periodic OA reports
when requested through the corresponding property.

For Gen8, the OA reports itself have the ctx ID and it is the one programmed
into HW while submitting workloads. Thus it's retrieved from reports itself.
For Gen7, the OA reports don't have any such field, and we can populate this
field with the last seen ctx ID while sending CS reports.

Signed-off-by: Sourab Gupta 
---
 drivers/gpu/drm/i915/i915_drv.h  |  3 +++
 drivers/gpu/drm/i915/i915_perf.c | 52 +---
 2 files changed, 52 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index e9cf939..853cc7db 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -1859,6 +1859,8 @@ struct i915_oa_ops {
u32 ts, u32 max_records);
int (*oa_buffer_num_samples)(struct drm_i915_private *dev_priv,
u32 *last_ts);
+   u32 (*oa_buffer_get_ctx_id)(struct i915_perf_stream *stream,
+   const u8 *report);
 };
 
 /*
@@ -2239,6 +2241,7 @@ struct drm_i915_private {
u32 status;
} command_stream_buf;
 
+   u32 last_ctx_id;
struct list_head node_list;
spinlock_t node_list_lock;
} perf;
diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c
index e10e78f..84457f8 100644
--- a/drivers/gpu/drm/i915/i915_perf.c
+++ b/drivers/gpu/drm/i915/i915_perf.c
@@ -637,6 +637,46 @@ gen7_oa_buffer_num_samples_fop_unlocked(struct 
drm_i915_private *dev_priv,
return num_samples;
 }
 
+static u32 gen7_oa_buffer_get_ctx_id(struct i915_perf_stream *stream,
+   const u8 *report)
+{
+   struct drm_i915_private *dev_priv = stream->dev_priv;
+
+   if (!stream->cs_mode)
+   WARN_ONCE(1,
+   "CTX ID can't be retrieved if command stream mode not 
enabled");
+
+   /*
+* OA reports generated in Gen7 don't have the ctx ID information.
+* Therefore, just rely on the ctx ID information from the last CS
+* sample forwarded
+*/
+   return dev_priv->perf.last_ctx_id;
+}
+
+static u32 gen8_oa_buffer_get_ctx_id(struct i915_perf_stream *stream,
+   const u8 *report)
+{
+   struct drm_i915_private *dev_priv = stream->dev_priv;
+
+   /* The ctx ID present in the OA reports have intel_context::global_id
+* present, since this is programmed into the ELSP in execlist mode.
+* In non-execlist mode, fall back to retrieving the ctx ID from the
+* last saved ctx ID from command stream mode.
+*/
+   if (i915.enable_execlists) {
+   u32 ctx_id = *(u32 *)(report + 12);
+   ctx_id &= 0xf;
+   return ctx_id;
+   } else {
+   if (!stream->cs_mode)
+   WARN_ONCE(1,
+   "CTX ID can't be retrieved if command stream mode not 
enabled");
+
+   return dev_priv->perf.last_ctx_id;
+   }
+}
+
 /**
  * Appends a status record to a userspace read() buffer.
  */
@@ -733,9 +773,9 @@ static int append_oa_buffer_sample(struct i915_perf_stream 
*stream,
data.source = source;
}
 
-#warning "FIXME: append_oa_buffer_sample: read ctx ID from report and map that 
to an intel_context::global_id"
if (sample_flags & SAMPLE_CTX_ID)
-   data.ctx_id = 0;
+   data.ctx_id = dev_priv->perf.oa.ops.oa_buffer_get_ctx_id(
+   stream, report);
 
if (sample_flags & SAMPLE_OA_REPORT)
data.report = report;
@@ -1248,8 +1288,10 @@ static int append_oa_rcs_sample(struct i915_perf_stream 
*stream,
if (sample_flags & SAMPLE_OA_SOURCE_INFO)
data.source = I915_PERF_OA_EVENT_SOURCE_RCS;
 
-   if (sample_flags & SAMPLE_CTX_ID)
+   if (sample_flags & SAMPLE_CTX_ID) {
data.ctx_id = node->ctx_id;
+   dev_priv->perf.last_ctx_id = node->ctx_id;
+   }
 
if (sample_flags & SAMPLE_OA_REPORT)
data.report = report;
@@ -3092,6 +3134,8 @@ void i915_perf_init(struct drm_i915_private *dev_priv)
dev_priv->perf.oa.ops.read = gen7_oa_read;
dev_priv->perf.oa.ops.oa_buffer_num_samples =
gen7_oa_buffer_num_samples_fop_unlocked;
+   dev_priv->perf.oa.ops.oa_buffer_get_ctx_id =
+   gen7_oa_buffer_get_ctx_id;
 
dev_priv->perf.oa.timestamp_frequency = 1250;
 
@@ -3106,6 +3150,8 @@ void i915_perf_init(struct drm_i915_private *dev_priv)
dev_priv->perf.oa.ops.read = gen8_oa_read;
dev_priv->perf.oa.ops.oa_buffer_num_sam

[Intel-gfx] [PATCH 06/15] drm/i915: Populate ctx ID for periodic OA reports

2016-06-01 Thread sourab . gupta
From: Sourab Gupta 

This adds support for populating the ctx id for the periodic OA reports
when requested through the corresponding property.

For Gen8, the OA reports itself have the ctx ID and it is the one programmed
into HW while submitting workloads. Thus it's retrieved from reports itself.
For Gen7, the OA reports don't have any such field, and we can populate this
field with the last seen ctx ID while sending CS reports.

Signed-off-by: Sourab Gupta 
---
 drivers/gpu/drm/i915/i915_drv.h  |  3 +++
 drivers/gpu/drm/i915/i915_perf.c | 52 +---
 2 files changed, 52 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 8cce8bd..9d23ca1 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -1838,6 +1838,8 @@ struct i915_oa_ops {
u32 ts, u32 max_records);
int (*oa_buffer_num_samples)(struct drm_i915_private *dev_priv,
u32 *last_ts);
+   u32 (*oa_buffer_get_ctx_id)(struct i915_perf_stream *stream,
+   const u8 *report);
 };
 
 /*
@@ -2194,6 +2196,7 @@ struct drm_i915_private {
u32 status;
} command_stream_buf;
 
+   u32 last_ctx_id;
struct list_head node_list;
spinlock_t node_list_lock;
} perf;
diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c
index a9cf103..2496a4b 100644
--- a/drivers/gpu/drm/i915/i915_perf.c
+++ b/drivers/gpu/drm/i915/i915_perf.c
@@ -485,6 +485,46 @@ gen7_oa_buffer_num_samples_fop_unlocked(struct 
drm_i915_private *dev_priv,
return num_samples;
 }
 
+static u32 gen7_oa_buffer_get_ctx_id(struct i915_perf_stream *stream,
+   const u8 *report)
+{
+   struct drm_i915_private *dev_priv = stream->dev_priv;
+
+   if (!stream->cs_mode)
+   WARN_ONCE(1,
+   "CTX ID can't be retrieved if command stream mode not 
enabled");
+
+   /*
+* OA reports generated in Gen7 don't have the ctx ID information.
+* Therefore, just rely on the ctx ID information from the last CS
+* sample forwarded
+*/
+   return dev_priv->perf.last_ctx_id;
+}
+
+static u32 gen8_oa_buffer_get_ctx_id(struct i915_perf_stream *stream,
+   const u8 *report)
+{
+   struct drm_i915_private *dev_priv = stream->dev_priv;
+
+   /* The ctx ID present in the OA reports have intel_context::global_id
+* present, since this is programmed into the ELSP in execlist mode.
+* In non-execlist mode, fall back to retrieving the ctx ID from the
+* last saved ctx ID from command stream mode.
+*/
+   if (i915.enable_execlists) {
+   u32 ctx_id = *(u32 *)(report + 12);
+   ctx_id &= 0xf;
+   return ctx_id;
+   } else {
+   if (!stream->cs_mode)
+   WARN_ONCE(1,
+   "CTX ID can't be retrieved if command stream mode not 
enabled");
+
+   return dev_priv->perf.last_ctx_id;
+   }
+}
+
 /**
  * Appends a status record to a userspace read() buffer.
  */
@@ -580,9 +620,9 @@ static int append_oa_buffer_sample(struct i915_perf_stream 
*stream,
 
data.source = source;
}
-#warning "FIXME: append_oa_buffer_sample: read ctx ID from report and map that 
to an intel_context::global_id"
if (sample_flags & SAMPLE_CTX_ID)
-   data.ctx_id = 0;
+   data.ctx_id = dev_priv->perf.oa.ops.oa_buffer_get_ctx_id(
+   stream, report);
 
if (sample_flags & SAMPLE_OA_REPORT)
data.report = report;
@@ -1047,8 +1087,10 @@ static int append_oa_rcs_sample(struct i915_perf_stream 
*stream,
if (sample_flags & SAMPLE_OA_SOURCE_INFO)
data.source = I915_PERF_OA_EVENT_SOURCE_RCS;
 
-   if (sample_flags & SAMPLE_CTX_ID)
+   if (sample_flags & SAMPLE_CTX_ID) {
data.ctx_id = node->ctx_id;
+   dev_priv->perf.last_ctx_id = node->ctx_id;
+   }
 
if (sample_flags & SAMPLE_OA_REPORT)
data.report = report;
@@ -2743,6 +2785,8 @@ void i915_perf_init(struct drm_device *dev)
dev_priv->perf.oa.ops.read = gen7_oa_read;
dev_priv->perf.oa.ops.oa_buffer_num_samples =
gen7_oa_buffer_num_samples_fop_unlocked;
+   dev_priv->perf.oa.ops.oa_buffer_get_ctx_id =
+   gen7_oa_buffer_get_ctx_id;
 
dev_priv->perf.oa.timestamp_frequency = 1250;
 
@@ -2760,6 +2804,8 @@ void i915_perf_init(struct drm_device *dev)
dev_priv->perf.oa.ops.read = gen8_oa_read;
dev_priv->perf.oa.ops.oa_buffer_num_samples =