[PATCH 02/14] drm/i915: Expose OA sample source to userspace

Sagar Arun Kamble sagar.a.kamble at intel.com
Wed Jul 12 09:56:50 UTC 2017


From: Sourab Gupta <sourab.gupta at intel.com>

This patch exposes a new sample source field to userspace. This field can
be populated to specify the origin of the OA report.
Currently, the OA samples are being generated only periodically, and hence
there's only source flag enum definition right now, but there are other
means of generating OA samples, such as via MI_RPC commands. The OA_SOURCE
sample type is introducing a mechanism (for userspace) to distinguish
various OA reports generated via different sources.
This is not intended as a replacement for the reason field that's part of
Gen8+ OA reports. For automatically triggered reports written to the
OABUFFER the reason field will distinguish e.g. periodic vs ctx-switch vs
GO transition reasons for the OA unit writing a report. However, The reason
field is overloaded as the RPT_ID field for MI_RPC reports so we need our
own way of tracking the difference.

v2: Renamed the source enum type and values. Robert had suggested to change
the type of new payload fields to 64 bit. However, it might waste space and
packing multiple fields makes it clumsier to handle based on user selection
, hence staying with u32. Updated commit description. (Robert)

Signed-off-by: Sourab Gupta <sourab.gupta at intel.com>
Signed-off-by: Robert Bragg <robert at sixbynine.org>
Signed-off-by: Sagar Arun Kamble <sagar.a.kamble at intel.com>
---
 drivers/gpu/drm/i915/i915_perf.c | 26 ++++++++++++++++++++++++++
 include/uapi/drm/i915_drm.h      | 13 +++++++++++++
 2 files changed, 39 insertions(+)

diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c
index d9f77a4..49e4c93 100644
--- a/drivers/gpu/drm/i915/i915_perf.c
+++ b/drivers/gpu/drm/i915/i915_perf.c
@@ -329,6 +329,7 @@
 };
 
 #define SAMPLE_OA_REPORT      (1<<0)
+#define SAMPLE_OA_SOURCE      (1<<1)
 
 /**
  * struct perf_open_properties - for validated properties given to open a stream
@@ -559,6 +560,23 @@ static int append_oa_sample(struct i915_perf_stream *stream,
 		return -EFAULT;
 	buf += sizeof(header);
 
+	/*
+	 * Sample has metadata containting OA_SOURCE followed by OA_REPORT.
+	 * Need to maintain this uapi w.r.t any reorganizing later not realizing
+	 * the ordering.
+	 * Currently there are a number of different automatic triggers for
+	 * writing OA reports to the OABUFFER like periodic, ctx-switch, go
+	 * transition. These are considered as source 'OABUFFER'.
+	 */
+	if (sample_flags & SAMPLE_OA_SOURCE) {
+		enum drm_i915_perf_sample_oa_source source;
+
+		source = I915_PERF_SAMPLE_OA_SOURCE_OABUFFER;
+		if (copy_to_user(buf, &source, 4))
+			return -EFAULT;
+		buf += 4;
+	}
+
 	if (sample_flags & SAMPLE_OA_REPORT) {
 		if (copy_to_user(buf, report, report_size))
 			return -EFAULT;
@@ -2048,6 +2066,11 @@ static int i915_oa_stream_init(struct i915_perf_stream *stream,
 	stream->sample_flags |= SAMPLE_OA_REPORT;
 	stream->sample_size += format_size;
 
+	if (props->sample_flags & SAMPLE_OA_SOURCE) {
+		stream->sample_flags |= SAMPLE_OA_SOURCE;
+		stream->sample_size += 4;
+	}
+
 	dev_priv->perf.oa.oa_buffer.format_size = format_size;
 	if (WARN_ON(dev_priv->perf.oa.oa_buffer.format_size == 0))
 		return -EINVAL;
@@ -2771,6 +2794,9 @@ static int read_properties_unlocked(struct drm_i915_private *dev_priv,
 			props->oa_periodic = true;
 			props->oa_period_exponent = value;
 			break;
+		case DRM_I915_PERF_PROP_SAMPLE_OA_SOURCE:
+			props->sample_flags |= SAMPLE_OA_SOURCE;
+			break;
 		case DRM_I915_PERF_PROP_MAX:
 			MISSING_CASE(id);
 			return -EINVAL;
diff --git a/include/uapi/drm/i915_drm.h b/include/uapi/drm/i915_drm.h
index 29f1501..59074df 100644
--- a/include/uapi/drm/i915_drm.h
+++ b/include/uapi/drm/i915_drm.h
@@ -1348,6 +1348,11 @@ enum drm_i915_oa_format {
 	I915_OA_FORMAT_MAX	    /* non-ABI */
 };
 
+enum drm_i915_perf_sample_oa_source {
+	I915_PERF_SAMPLE_OA_SOURCE_OABUFFER,
+	I915_PERF_SAMPLE_OA_SOURCE_MAX	/* non-ABI */
+};
+
 enum drm_i915_perf_property_id {
 	/**
 	 * Open the stream for a specific context handle (as used with
@@ -1382,6 +1387,13 @@ enum drm_i915_perf_property_id {
 	 */
 	DRM_I915_PERF_PROP_OA_EXPONENT,
 
+	/**
+	 * The value of this property set to 1 requests inclusion of sample
+	 * source field to be given to userspace. The sample source field
+	 * specifies the origin of OA report.
+	 */
+	DRM_I915_PERF_PROP_SAMPLE_OA_SOURCE,
+
 	DRM_I915_PERF_PROP_MAX /* non-ABI */
 };
 
@@ -1447,6 +1459,7 @@ enum drm_i915_perf_record_type {
 	 * struct {
 	 *     struct drm_i915_perf_record_header header;
 	 *
+	 *     { u32 source; } && DRM_I915_PERF_PROP_SAMPLE_OA_SOURCE
 	 *     { u32 oa_report[]; } && DRM_I915_PERF_PROP_SAMPLE_OA
 	 * };
 	 */
-- 
1.9.1



More information about the Intel-gfx-trybot mailing list