Skip to contentSkip to conversation

i915 perf support for command stream based OA, GPU and workload metrics capture

PATCH New Sagar Arun Kamble 2 participants 17 messages Aug 28, 2017

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

cover i915 perf support for command stream based OA, GPU and workload metrics capture

This is follow up series based on reviews for
https://patchwork.freedesktop.org/series/28104/

Major change is assignment of samples at the time of request submission onto HW instead of assigning at user submission time. Restructured patches to make some of the earlier code-heavy patches little lighter by modularizing them. Added base i-g-t testcase dapc for testing exposed sample fields like PID, Timestamps, CTX ID etc.

Reiterating the intent of this series:
1. Collection of OA reports associated with the render command stream, which are collected around batchbuffer boundaries.
2. Collect other metadata such as ctx_id, pid, tag etc. with the samples, and thus we can establish the association of samples collected with the corresponding process/workload.
3. Collection of GPU performance metrics associated with the command stream of a particular engine. These metrics include timestamps of work submission and completion on engines, mmio metrics, etc. These metrics are are collected around batchbuffer boundaries.

Functionality to be added in future patches:
1. GPU/CPU cross-timestamp sync patches need to be reworked as requested by kernel maintainers.
2. Some of the data types being collected through these patches can be done in the userspace and that is yet to be finalized. Based on that some of the functionality from this series can be pruned.

Cc Lionel Landwerlin <[email protected]>
Cc Matthew Auld <[email protected]>
Cc Chris Wilson <[email protected]>

Sagar Arun Kamble (2):
drm/i915: Define CTX_ID property for perf sampling drm/i915: Link perf stream structures with Engines

Sourab Gupta (12):
drm/i915: Add ctx getparam ioctl parameter to retrieve ctx unique id drm/i915: Expose OA sample source to userspace
drm/i915: Framework for capturing command stream based OA reports. drm/i915: Flush periodic samples, in case of no pending CS sample
requests
drm/i915: Inform userspace about command stream OA buf overflow drm/i915: Populate ctx ID for periodic OA reports drm/i915: Add support for having pid output with OA report drm/i915: Add support for emitting execbuffer tags through OA counter
reports
drm/i915: Add support for collecting timestamps on all gpu engines drm/i915: Extract raw GPU timestamps from OA reports to forward in
perf samples
drm/i915: Async check for streams data availability with hrtimer
rescheduling
drm/i915: Support for capturing MMIO register values

 drivers/gpu/drm/i915/i915_drv.h            |  176 ++-
 drivers/gpu/drm/i915/i915_gem.c            |    1 +
 drivers/gpu/drm/i915/i915_gem_context.c    |    3 +
 drivers/gpu/drm/i915/i915_gem_execbuffer.c |   11 +
 drivers/gpu/drm/i915/i915_gem_request.c    |    2 +
 drivers/gpu/drm/i915/i915_gem_request.h    |   10 +
 drivers/gpu/drm/i915/i915_perf.c           | 1904 ++++++++++++++++++++++++----
 drivers/gpu/drm/i915/i915_reg.h            |    6 +
 drivers/gpu/drm/i915/intel_engine_cs.c     |    4 +
 drivers/gpu/drm/i915/intel_ringbuffer.c    |    2 +
 drivers/gpu/drm/i915/intel_ringbuffer.h    |   11 +
 include/uapi/drm/i915_drm.h                |   69 +
 12 files changed, 1935 insertions(+), 264 deletions(-)
Signature · 6 lines
1.9.1

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

PATCH 1/14 drm/i915: Add ctx getparam ioctl parameter to retrieve ctx unique id

From: Sourab Gupta <[email protected]>

This patch adds a new ctx getparam ioctl parameter, which can be used to retrieve ctx unique id by userspace.

This can be used by userspace to map the OA reports received in the i915 perf samples with their associated ctx's (The OA reports have the hw ctx ID information embedded for Gen8+).
Otherwise the userspace has no way of maintaining this association, since it has the knowledge of only per-drm file specific ctx handles.

---
 drivers/gpu/drm/i915/i915_gem_context.c | 3 +++
 include/uapi/drm/i915_drm.h             | 1 +
 2 files changed, 4 insertions(+)
drivers/gpu/drm/i915/i915_gem_context.c +3 -0
index 58a2a44..2d7f1f0 100644
@@ -1036,6 +1036,9 @@ int i915_gem_context_getparam_ioctl(struct drm_device *dev, void *data,
 	case I915_CONTEXT_PARAM_BANNABLE:
 		args->value = i915_gem_context_is_bannable(ctx);
 		break;
+	case I915_CONTEXT_PARAM_HW_ID:
+		args->value = ctx->hw_id;
+		break;
 	default:
 		ret = -EINVAL;
 		break;
include/uapi/drm/i915_drm.h +1 -0
index 6598fb7..92acfc2 100644
@@ -1358,6 +1358,7 @@ struct drm_i915_gem_context_param {
 #define I915_CONTEXT_PARAM_GTT_SIZE	0x3
 #define I915_CONTEXT_PARAM_NO_ERROR_CAPTURE	0x4
 #define I915_CONTEXT_PARAM_BANNABLE	0x5
+#define I915_CONTEXT_PARAM_HW_ID	0x6
 	__u64 value;
 };
 
Signature · 6 lines
1.9.1

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

PATCH 2/14 drm/i915: Expose OA sample source to userspace

In reply to Sagar Arun Kamble

From: Sourab Gupta <[email protected]>

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. Updated commit description. (Robert). Changed payload field source to u64 to keep all sample data aligned at 8 bytes. (Lionel)

---
 drivers/gpu/drm/i915/i915_perf.c | 25 +++++++++++++++++++++++++
 include/uapi/drm/i915_drm.h      | 13 +++++++++++++
 2 files changed, 38 insertions(+)
drivers/gpu/drm/i915/i915_perf.c +25 -0
index 94185d6..0133e09 100644
@@ -330,6 +330,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
@@ -608,6 +609,22 @@ 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) {
+		u64 source = I915_PERF_SAMPLE_OA_SOURCE_OABUFFER;
+
+		if (copy_to_user(buf, &source, 8))
+			return -EFAULT;
+		buf += 8;
+	}
+
 	if (sample_flags & SAMPLE_OA_REPORT) {
 		if (copy_to_user(buf, report, report_size))
 			return -EFAULT;
@@ -2087,6 +2104,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 += 8;
+	}
+
 	dev_priv->perf.oa.oa_buffer.format_size = format_size;
 	if (WARN_ON(dev_priv->perf.oa.oa_buffer.format_size == 0))
 		return -EINVAL;
@@ -2805,6 +2827,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;
include/uapi/drm/i915_drm.h +13 -0
index 92acfc2..8ff5631 100644
@@ -1379,6 +1379,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
@@ -1413,6 +1418,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 */
 };
 
@@ -1478,6 +1490,7 @@ enum drm_i915_perf_record_type {
 	 * struct {
 	 *     struct drm_i915_perf_record_header header;
 	 *
+	 *     { u64 source; } && DRM_I915_PERF_PROP_SAMPLE_OA_SOURCE
 	 *     { u32 oa_report[]; } && DRM_I915_PERF_PROP_SAMPLE_OA
 	 * };
 	 */
Signature · 6 lines
1.9.1

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

PATCH 3/14 drm/i915: Framework for capturing command stream based OA reports.

In reply to Sagar Arun Kamble

From: Sourab Gupta <[email protected]>

This patch introduces a framework to capture OA counter reports associated with Render command stream. We can then associate the reports captured through this mechanism with their corresponding context id's. This can be further extended to associate any other metadata information with the corresponding samples (since the association with Render command stream gives us the ability to capture these information while inserting the corresponding capture commands into the command stream).

The OA reports generated in this way are associated with a corresponding workload, and thus can be used the delimit the workload (i.e. sample the counters at the workload boundaries), within an ongoing stream of periodic counter snapshots.

There may be usecases wherein we need more than periodic OA capture mode which is supported currently. This mode is primarily used for two usecases:
- Ability to capture system wide metrics, alongwith the ability to map the reports back to individual contexts (particularly for HSW).
- Ability to inject tags for work, into the reports. This provides visibility into the multiple stages of work within single context.

The userspace will be able to distinguish between the periodic and CS based OA reports by the virtue of source_info sample field.

The command MI_REPORT_PERF_COUNT can be used to capture snapshots of OA counters, and is inserted at BB boundaries.
The data thus captured will be stored in a separate buffer, which will be different from the buffer used otherwise for periodic OA capture mode. The metadata information pertaining to snapshot is maintained in a list, which also has offsets into the gem buffer object per captured snapshot. In order to track whether the gpu has completed processing the node, a field pertaining to corresponding gem request is added, which is tracked for completion of the command.

Both periodic and CS based reports are associated with a single stream (corresponding to render engine), and it is expected to have the samples in the sequential order according to their timestamps. Now, since these reports are collected in separate buffers, these are merge sorted at the time of forwarding to userspace during the read call.

v2: Aligning with the non-perf interface (custom drm ioctl based). Also, few related patches are squashed together for better readability

v3: Updated perf sample capture emit hook name. Reserving space upfront in the ring for emitting sample capture commands and using req->fence.seqno for tracking samples. Added SRCU protection for streams. Changed the stream last_request tracking to resv object. (Chris) Updated perf.sample_lock spin_lock usage to avoid softlockups. Moved stream to global per-engine structure. (Sagar)
Update unpin and put in the free routines to i915_vma_unpin_and_release. Making use of perf stream cs_buffer vma resv instead of separate resv obj. Pruned perf stream vma resv during gem_idle. (Chris)
Changed payload field ctx_id to u64 to keep all sample data aligned at 8 bytes. (Lionel)
stall/flush prior to sample capture is not added. Do we need to give this control to user to select whether to stall/flush at each sample?

v4: Removed state enum and relying on bool state. Kept single srcu as currently only RCS stream is opened. Removed ctx id support, will be added in the next patch in series. polling workqueue related structures are kept singleton too for now. (Lionel)
Moved the CS samples allocation from request emission to submission as the backed __i915_gem_request_submit determines the order of execution on the hardware. Changed assigning the offset from cs_buffer vma to sample based to make sure we reuse the samples non-linearly in case some samples are discarded due to preemption later.
Added sample identifier to know where in the request execution sample is captured. This can be useful to associate OA reports based on begin and end of request execution.

Testcase: igt/dapc

---
 drivers/gpu/drm/i915/i915_drv.h            |   94 ++-
 drivers/gpu/drm/i915/i915_gem.c            |    1 +
 drivers/gpu/drm/i915/i915_gem_execbuffer.c |    8 +
 drivers/gpu/drm/i915/i915_gem_request.c    |    2 +
 drivers/gpu/drm/i915/i915_gem_request.h    |    3 +
 drivers/gpu/drm/i915/i915_perf.c           | 1139 ++++++++++++++++++++++------
 include/uapi/drm/i915_drm.h                |    8 +
 7 files changed, 1037 insertions(+), 218 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +87 -7
index 8352cbe..ea96274 100644
@@ -2014,6 +2014,30 @@ struct i915_perf_stream_ops {
 	 * The stream will always be disabled before this is called.
 	 */
 	void (*destroy)(struct i915_perf_stream *stream);
+
+	/*
+	 * @emit_sample_capture: Emit the commands in the command streamer
+	 * for a particular gpu engine.
+	 *
+	 * The commands are inserted to capture the perf sample data at
+	 * specific points during workload execution, such as before and after
+	 * the batch buffer.
+	 */
+	void (*emit_sample_capture)(struct i915_perf_stream *stream,
+				    struct drm_i915_gem_request *request,
+				    bool preallocate);
+
+	/*
+	 * @patch_sample_capture: Patch the offsets in commands to capture perf
+	 * sample data in the ringbuffer corresponding to request.
+	 *
+	 * To get the perf samples in the order of execution on the engines, we
+	 * emit the commands to capture the data while populating the request in
+	 * the ringbuffer but update the location and maintain the ordered list
+	 * during __i915_gem_request_submit.
+	 */
+	void (*patch_request)(struct i915_perf_stream *stream,
+			      struct drm_i915_gem_request *request);
 };
 
 /**
@@ -2026,11 +2050,6 @@ struct i915_perf_stream {
 	struct drm_i915_private *dev_priv;
 
 	/**
-	 * @link: Links the stream into ``&drm_i915_private->streams``
-	 */
-	struct list_head link;
-
-	/**
 	 * @sample_flags: Flags representing the `DRM_I915_PERF_PROP_SAMPLE_*`
 	 * properties given when opening a stream, representing the contents
 	 * of a single sample as read() by userspace.
@@ -2067,6 +2086,27 @@ struct i915_perf_stream {
 	 * @oa_config: The OA configuration used by the stream.
 	 */
 	struct i915_oa_config *oa_config;
+
+	/**
+	 * @cs_mode: Whether command stream based perf sample collection is
+	 * enabled for this stream
+	 */
+	bool cs_mode;
+
+	/**
+	 * @using_oa: Whether OA unit is in use for this particular stream
+	 */
+	bool using_oa;
+
+	/* Command stream based perf data buffer */
+	struct {
+		struct i915_vma *vma;
+		u8 *vaddr;
+	} cs_buffer;
+
+	struct list_head cs_samples;
+	struct list_head free_samples;
+	spinlock_t samples_lock;
 };
 
 /**
@@ -2141,7 +2181,8 @@ struct i915_oa_ops {
 	int (*read)(struct i915_perf_stream *stream,
 		    char __user *buf,
 		    size_t count,
-		    size_t *offset);
+		    size_t *offset,
+		    u32 ts);
 
 	/**
 	 * @oa_hw_tail_read: read the OA tail pointer register
@@ -2153,6 +2194,41 @@ struct i915_oa_ops {
 	u32 (*oa_hw_tail_read)(struct drm_i915_private *dev_priv);
 };
 
+enum request_sample_id {
+	PRE_REQUEST_SAMPLE_ID,
+	POST_REQUEST_SAMPLE_ID,
+	MAX_REQUEST_SAMPLE_ID
+};
+
+/*
+ * i915_perf_cs_sample - Sample element to hold info about a single perf
+ * sample data associated with a particular GPU command stream.
+ */
+struct i915_perf_cs_sample {
+	/**
+	 * @link: Links the sample into ``&stream->cs_samples`` or
+	 * ``&stream->free_samples``
+	 */
+	struct list_head link;
+
+	/**
+	 * @request: GEM request associated with the sample. The commands to
+	 * capture the perf metrics are inserted into the command streamer in
+	 * context of this request.
+	 */
+	struct drm_i915_gem_request *request;
+
+	/**
+	 * @oa_offset: Offset into ``&stream->cs_buffer``
+	 * where the perf metrics will be collected, when the commands inserted
+	 * into the command stream are executed by GPU.
+	 */
+	u32 oa_offset;
+
+	/* Is this sample prior to request start or post request end */
+	enum request_sample_id id;
+};
+
 struct intel_cdclk_state {
 	unsigned int cdclk, vco, ref;
 };
@@ -2494,7 +2570,6 @@ struct drm_i915_private {
 		 * except exclusive_stream.
 		 */
 		struct mutex lock;
-		struct list_head streams;
 
 		struct {
 			/*
@@ -2504,6 +2579,7 @@ struct drm_i915_private {
 			 * dev_priv->drm.struct_mutex.
 			 */
 			struct i915_perf_stream *exclusive_stream;
+			struct srcu_struct srcu;
 
 			u32 specific_ctx_id;
 
@@ -3861,6 +3937,10 @@ int intel_engine_cmd_parser(struct intel_engine_cs *engine,
 extern void i915_perf_fini(struct drm_i915_private *dev_priv);
 extern void i915_perf_register(struct drm_i915_private *dev_priv);
 extern void i915_perf_unregister(struct drm_i915_private *dev_priv);
+void i915_perf_emit_sample_capture(struct drm_i915_gem_request *req,
+				   bool preallocate);
+void i915_perf_patch_request(struct drm_i915_gem_request *request);
+void i915_perf_streams_mark_idle(struct drm_i915_private *dev_priv);
 
 /* i915_suspend.c */
 extern int i915_save_state(struct drm_i915_private *dev_priv);
drivers/gpu/drm/i915/i915_gem.c +1 -0
index ac02785..7c62549 100644
@@ -3222,6 +3222,7 @@ bool i915_gem_unset_wedged(struct drm_i915_private *i915)
 
 	intel_engines_mark_idle(dev_priv);
 	i915_gem_timelines_mark_idle(dev_priv);
+	i915_perf_streams_mark_idle(dev_priv);
 
 	GEM_BUG_ON(!dev_priv->gt.awake);
 	dev_priv->gt.awake = false;
drivers/gpu/drm/i915/i915_gem_execbuffer.c +8 -0
index 1c4fac0..b95c745 100644
@@ -1108,12 +1108,16 @@ static int __reloc_gpu_alloc(struct i915_execbuffer *eb,
 	if (err)
 		goto err_request;
 
+	i915_perf_emit_sample_capture(rq, true);
+
 	err = eb->engine->emit_bb_start(rq,
 					batch->node.start, PAGE_SIZE,
 					cache->gen > 5 ? 0 : I915_DISPATCH_SECURE);
 	if (err)
 		goto err_request;
 
+	i915_perf_emit_sample_capture(rq, false);
+
 	GEM_BUG_ON(!reservation_object_test_signaled_rcu(batch->resv, true));
 	i915_vma_move_to_active(batch, rq, 0);
 	reservation_object_lock(batch->resv, NULL);
@@ -1959,6 +1963,8 @@ static int eb_submit(struct i915_execbuffer *eb)
 			return err;
 	}
 
+	i915_perf_emit_sample_capture(eb->request, true);
+
 	err = eb->engine->emit_bb_start(eb->request,
 					eb->batch->node.start +
 					eb->batch_start_offset,
@@ -1967,6 +1973,8 @@ static int eb_submit(struct i915_execbuffer *eb)
 	if (err)
 		return err;
 
+	i915_perf_emit_sample_capture(eb->request, false);
+
 	return 0;
 }
 
drivers/gpu/drm/i915/i915_gem_request.c +2 -0
index 813a3b5..6833518 100644
@@ -481,6 +481,8 @@ void __i915_gem_request_submit(struct drm_i915_gem_request *request)
 	list_move_tail(&request->link, &timeline->requests);
 	spin_unlock(&request->timeline->lock);
 
+	i915_perf_patch_request(request);
+
 	wake_up_all(&request->execute);
 }
 
drivers/gpu/drm/i915/i915_gem_request.h +3 -0
index 49a4c89..ffda982a 100644
@@ -195,6 +195,9 @@ struct drm_i915_gem_request {
 	struct drm_i915_file_private *file_priv;
 	/** file_priv list entry for this request */
 	struct list_head client_link;
+
+	u32 *pre_oa_offset;
+	u32 *post_oa_offset;
 };
 
 extern const struct dma_fence_ops i915_fence_ops;
drivers/gpu/drm/i915/i915_perf.c +928 -211

1,590 lines not on this page · raw message

include/uapi/drm/i915_drm.h +8 -0
index 8ff5631..2e0b239 100644
@@ -1381,6 +1381,7 @@ enum drm_i915_oa_format {
 
 enum drm_i915_perf_sample_oa_source {
 	I915_PERF_SAMPLE_OA_SOURCE_OABUFFER,
+	I915_PERF_SAMPLE_OA_SOURCE_CS,
 	I915_PERF_SAMPLE_OA_SOURCE_MAX	/* non-ABI */
 };
 
@@ -1425,6 +1426,13 @@ enum drm_i915_perf_property_id {
 	 */
 	DRM_I915_PERF_PROP_SAMPLE_OA_SOURCE,
 
+	/**
+	 * The value of this property specifies the GPU engine for which
+	 * the samples need to be collected. Specifying this property also
+	 * implies the command stream based sample collection.
+	 */
+	DRM_I915_PERF_PROP_ENGINE,
+
 	DRM_I915_PERF_PROP_MAX /* non-ABI */
 };
 
Signature · 6 lines
1.9.1

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

PATCH 4/14 drm/i915: Define CTX_ID property for perf sampling

In reply to Sagar Arun Kamble

This patch enables to sample CTX ID corresponding to requests being submitted on the engines through perf stream. OA report already embed this information from Gen8+. For previous Gens we can leverage value sampled from request->ctx->hw_id to associate with OA reports.

---
 drivers/gpu/drm/i915/i915_drv.h  |  5 ++++
 drivers/gpu/drm/i915/i915_perf.c | 55 ++++++++++++++++++++++++++++++++++++++++
 include/uapi/drm/i915_drm.h      |  7 +++++
 3 files changed, 67 insertions(+)
drivers/gpu/drm/i915/i915_drv.h +5 -0
index ea96274..9a1c3f7 100644
@@ -2227,6 +2227,11 @@ struct i915_perf_cs_sample {
 
 	/* Is this sample prior to request start or post request end */
 	enum request_sample_id id;
+
+	/**
+	 * @ctx_id: Context ID associated with this perf sample
+	 */
+	u32 ctx_id;
 };
 
 struct intel_cdclk_state {
drivers/gpu/drm/i915/i915_perf.c +55 -0

121 lines not on this page · raw message

include/uapi/drm/i915_drm.h +7 -0
index 2e0b239..68baaf9 100644
@@ -1433,6 +1433,12 @@ enum drm_i915_perf_property_id {
 	 */
 	DRM_I915_PERF_PROP_ENGINE,
 
+	/**
+	 * The value of this property set to 1 requests inclusion of context ID
+	 * in the perf sample data.
+	 */
+	DRM_I915_PERF_PROP_SAMPLE_CTX_ID,
+
 	DRM_I915_PERF_PROP_MAX /* non-ABI */
 };
 
@@ -1499,6 +1505,7 @@ enum drm_i915_perf_record_type {
 	 *     struct drm_i915_perf_record_header header;
 	 *
 	 *     { u64 source; } && DRM_I915_PERF_PROP_SAMPLE_OA_SOURCE
+	 *     { u64 ctx_id; } && DRM_I915_PERF_PROP_SAMPLE_CTX_ID
 	 *     { u32 oa_report[]; } && DRM_I915_PERF_PROP_SAMPLE_OA
 	 * };
 	 */
Signature · 6 lines
1.9.1

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

PATCH 5/14 drm/i915: Flush periodic samples, in case of no pending CS sample requests

In reply to Sagar Arun Kamble

From: Sourab Gupta <[email protected]>

When there are no pending CS OA samples, flush the periodic OA samples collected so far.

We can safely forward the periodic OA samples in the case we have no pending CS samples, but we can't do so in the case we have pending CS samples, since we don't know what the ordering between pending CS samples and periodic samples will eventually be. If we have no pending CS sample, it won't be possible for future pending CS sample to have timestamps earlier than current periodic timestamp.

---
 drivers/gpu/drm/i915/i915_drv.h  |   5 +-
 drivers/gpu/drm/i915/i915_perf.c | 142 ++++++++++++++++++++++++++++++---------
 2 files changed, 113 insertions(+), 34 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +4 -1
index 9a1c3f7..9359adb 100644
@@ -2182,7 +2182,8 @@ struct i915_oa_ops {
 		    char __user *buf,
 		    size_t count,
 		    size_t *offset,
-		    u32 ts);
+		    u32 ts,
+		    u32 max_reports);
 
 	/**
 	 * @oa_hw_tail_read: read the OA tail pointer register
@@ -2679,6 +2680,8 @@ struct drm_i915_private {
 			u32 gen7_latched_oastatus1;
 			u32 ctx_oactxctrl_offset;
 			u32 ctx_flexeu0_offset;
+			u32 n_pending_periodic_samples;
+			u32 pending_periodic_ts;
 
 			/**
 			 * The RPT_ID/reason field for Gen8+ includes a bit
drivers/gpu/drm/i915/i915_perf.c +109 -33

343 lines not on this page · raw message

Signature · 6 lines
1.9.1

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

PATCH 6/14 drm/i915: Inform userspace about command stream OA buf overflow

In reply to Sagar Arun Kamble

From: Sourab Gupta <[email protected]>

Considering how we don't currently give userspace control over the OA buffer size and always configure a large 16MB buffer, then a buffer overflow does anyway likely indicate that something has gone quite badly wrong.

Here we set a status flag to detect overflow and inform userspace of the report_lost condition accordingly. This is in line with the behavior of the periodic OA buffer.

---
 drivers/gpu/drm/i915/i915_drv.h  |  2 ++
 drivers/gpu/drm/i915/i915_perf.c | 16 +++++++++++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_drv.h +2 -0
index 9359adb..cf70a6f1 100644
@@ -2102,6 +2102,8 @@ struct i915_perf_stream {
 	struct {
 		struct i915_vma *vma;
 		u8 *vaddr;
+#define I915_PERF_CMD_STREAM_BUF_STATUS_OVERFLOW (1<<0)
+		u32 status;
 	} cs_buffer;
 
 	struct list_head cs_samples;
drivers/gpu/drm/i915/i915_perf.c +15 -1
index 90e1e09..d34ad9a 100644
@@ -613,8 +613,11 @@ static void i915_perf_stream_patch_request(struct i915_perf_stream *stream,
 
 	while (sample_id < MAX_REQUEST_SAMPLE_ID) {
 		spin_lock_irqsave(&stream->samples_lock, flags);
-		if (list_empty(&stream->free_samples))
+		if (list_empty(&stream->free_samples)) {
+			stream->cs_buffer.status |=
+				I915_PERF_CMD_STREAM_BUF_STATUS_OVERFLOW;
 			release_perf_sample(stream);
+		}
 		sample = list_first_entry_or_null(&stream->free_samples,
 				struct i915_perf_cs_sample, link);
 		WARN_ON(sample == NULL);
@@ -1572,6 +1575,17 @@ static int append_cs_buffer_samples(struct i915_perf_stream *stream,
 	LIST_HEAD(free_list);
 	int ret = 0;
 	unsigned long flags;
+	u32 status = stream->cs_buffer.status;
+
+	if (unlikely(status & I915_PERF_CMD_STREAM_BUF_STATUS_OVERFLOW)) {
+		ret = append_oa_status(stream, buf, count, offset,
+				       DRM_I915_PERF_RECORD_OA_BUFFER_LOST);
+		if (ret)
+			return ret;
+
+		stream->cs_buffer.status &=
+				~I915_PERF_CMD_STREAM_BUF_STATUS_OVERFLOW;
+	}
 
 	spin_lock_irqsave(&stream->samples_lock, flags);
 	if (list_empty(&stream->cs_samples)) {
Signature · 6 lines
1.9.1

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

PATCH 7/14 drm/i915: Populate ctx ID for periodic OA reports

In reply to Sagar Arun Kamble

From: Sourab Gupta <[email protected]>

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.

v2: Updated last_ctx_id for stream based on the id of perf sample as the periodic OA reports after the request gets completed should not be associated with any context.

---
 drivers/gpu/drm/i915/i915_drv.h  |  8 +++++
 drivers/gpu/drm/i915/i915_perf.c | 68 +++++++++++++++++++++++++++++++++-------
 2 files changed, 64 insertions(+), 12 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +8 -0
index cf70a6f1..4a1de0e 100644
@@ -2109,6 +2109,8 @@ struct i915_perf_stream {
 	struct list_head cs_samples;
 	struct list_head free_samples;
 	spinlock_t samples_lock;
+
+	u32 last_ctx_id;
 };
 
 /**
@@ -2195,6 +2197,12 @@ struct i915_oa_ops {
 	 * generations.
 	 */
 	u32 (*oa_hw_tail_read)(struct drm_i915_private *dev_priv);
+
+	/**
+	 * @get_ctx_id: Retrieve the ctx_id associated with the (periodic) OA
+	 * report.
+	 */
+	u32 (*get_ctx_id)(struct i915_perf_stream *stream, const u8 *report);
 };
 
 enum request_sample_id {
drivers/gpu/drm/i915/i915_perf.c +56 -12

104 lines not on this page · raw message

Signature · 6 lines
1.9.1

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

PATCH 8/14 drm/i915: Add support for having pid output with OA report

In reply to Sagar Arun Kamble

From: Sourab Gupta <[email protected]>

This patch introduces flags and adds support for having pid output with the OA reports generated through the RCS commands.

When the stream is opened with pid sample type, the pid information is also captured through the command stream samples and forwarded along with the OA reports.

v2: Changed payload field pid to u64 to keep all sample data aligned at 8 bytes. (Lionel)
Updated last_pid for stream based on the id of perf sample as the periodic OA reports after the request gets completed should not be associated with any pid.

---
 drivers/gpu/drm/i915/i915_drv.h         |  7 +++++
 drivers/gpu/drm/i915/i915_gem_request.h |  1 +
 drivers/gpu/drm/i915/i915_perf.c        | 55 ++++++++++++++++++++++++++++++++-
 include/uapi/drm/i915_drm.h             |  7 +++++
 4 files changed, 69 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_drv.h +7 -0
index 4a1de0e..a1de30c 100644
@@ -2111,6 +2111,7 @@ struct i915_perf_stream {
 	spinlock_t samples_lock;
 
 	u32 last_ctx_id;
+	u64 last_pid;
 };
 
 /**
@@ -2243,6 +2244,12 @@ struct i915_perf_cs_sample {
 	 * @ctx_id: Context ID associated with this perf sample
 	 */
 	u32 ctx_id;
+
+	/**
+	 * @pid: PID of the process in context of which the workload was
+	 * submitted, pertaining to this perf sample
+	 */
+	u64 pid;
 };
 
 struct intel_cdclk_state {
drivers/gpu/drm/i915/i915_gem_request.h +1 -0
index ffda982a..c839e34 100644
@@ -198,6 +198,7 @@ struct drm_i915_gem_request {
 
 	u32 *pre_oa_offset;
 	u32 *post_oa_offset;
+	u64 pid;
 };
 
 extern const struct dma_fence_ops i915_fence_ops;
drivers/gpu/drm/i915/i915_perf.c +54 -1

133 lines not on this page · raw message

include/uapi/drm/i915_drm.h +7 -0
index 68baaf9..f96ecfd 100644
@@ -1439,6 +1439,12 @@ enum drm_i915_perf_property_id {
 	 */
 	DRM_I915_PERF_PROP_SAMPLE_CTX_ID,
 
+	/**
+	 * The value of this property set to 1 requests inclusion of pid in the
+	 * perf sample data.
+	 */
+	DRM_I915_PERF_PROP_SAMPLE_PID,
+
 	DRM_I915_PERF_PROP_MAX /* non-ABI */
 };
 
@@ -1506,6 +1512,7 @@ enum drm_i915_perf_record_type {
 	 *
 	 *     { u64 source; } && DRM_I915_PERF_PROP_SAMPLE_OA_SOURCE
 	 *     { u64 ctx_id; } && DRM_I915_PERF_PROP_SAMPLE_CTX_ID
+	 *     { u64 pid; } && DRM_I915_PERF_PROP_SAMPLE_PID
 	 *     { u32 oa_report[]; } && DRM_I915_PERF_PROP_SAMPLE_OA
 	 * };
 	 */
Signature · 6 lines
1.9.1

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

PATCH 9/14 drm/i915: Add support for emitting execbuffer tags through OA counter reports

In reply to Sagar Arun Kamble

From: Sourab Gupta <[email protected]>

This patch enables userspace to specify tags (per workload), provided via execbuffer ioctl, which could be added to OA reports, to help associate reports with the corresponding workloads.

There may be multiple stages within a single context, from a userspace perspective. An ability is needed to individually associate the OA reports with their corresponding workloads(execbuffers), which may not be possible solely with ctx_id or pid information. This patch enables such a mechanism.

In this patch, upper 32 bits of rsvd1 field, which were previously unused are now being used to pass in the tag.

v2: Updated i915_execbuffer2_get_tag to get the tag properly. (Sagar) Changed tag size to 64 bit to ensure all sample fields are aligned at 8 bytes. (Lionel)
Updated last_tag for stream based on the id of perf sample as the periodic OA reports after the request gets completed should not be associated with any tag.

---
 drivers/gpu/drm/i915/i915_drv.h            | 18 +++++++++--
 drivers/gpu/drm/i915/i915_gem_execbuffer.c | 11 ++++---
 drivers/gpu/drm/i915/i915_gem_request.h    |  1 +
 drivers/gpu/drm/i915/i915_perf.c           | 49 +++++++++++++++++++++++++++---
 include/uapi/drm/i915_drm.h                | 12 ++++++++
 5 files changed, 80 insertions(+), 11 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +16 -2
index a1de30c..9989f01 100644
@@ -2025,7 +2025,8 @@ struct i915_perf_stream_ops {
 	 */
 	void (*emit_sample_capture)(struct i915_perf_stream *stream,
 				    struct drm_i915_gem_request *request,
-				    bool preallocate);
+				    bool preallocate,
+				    u32 tag);
 
 	/*
 	 * @patch_sample_capture: Patch the offsets in commands to capture perf
@@ -2112,6 +2113,7 @@ struct i915_perf_stream {
 
 	u32 last_ctx_id;
 	u64 last_pid;
+	u32 last_tag;
 };
 
 /**
@@ -2250,6 +2252,17 @@ struct i915_perf_cs_sample {
 	 * submitted, pertaining to this perf sample
 	 */
 	u64 pid;
+
+	/**
+	 * @tag: Tag associated with workload, for which the perf sample is
+	 * being collected.
+	 *
+	 * Userspace can specify tags (provided via execbuffer ioctl), which
+	 * can be associated with the perf samples, and be used to functionally
+	 * distinguish different workload stages, and associate samples with
+	 * these different stages.
+	 */
+	u32 tag;
 };
 
 struct intel_cdclk_state {
@@ -3963,7 +3976,8 @@ int intel_engine_cmd_parser(struct intel_engine_cs *engine,
 extern void i915_perf_register(struct drm_i915_private *dev_priv);
 extern void i915_perf_unregister(struct drm_i915_private *dev_priv);
 void i915_perf_emit_sample_capture(struct drm_i915_gem_request *req,
-				   bool preallocate);
+				   bool preallocate,
+				   u32 tag);
 void i915_perf_patch_request(struct drm_i915_gem_request *request);
 void i915_perf_streams_mark_idle(struct drm_i915_private *dev_priv);
 
drivers/gpu/drm/i915/i915_gem_execbuffer.c +7 -4
index b95c745..bfd1329 100644
@@ -245,6 +245,7 @@ struct i915_execbuffer {
 	 */
 	int lut_size;
 	struct hlist_head *buckets; /** ht for relocation handles */
+	uint32_t tag;
 };
 
 #define exec_entry(EB, VMA) (&(EB)->exec[(VMA)->exec_flags - (EB)->flags])
@@ -1108,7 +1109,7 @@ static int __reloc_gpu_alloc(struct i915_execbuffer *eb,
 	if (err)
 		goto err_request;
 
-	i915_perf_emit_sample_capture(rq, true);
+	i915_perf_emit_sample_capture(rq, true, eb->tag);
 
 	err = eb->engine->emit_bb_start(rq,
 					batch->node.start, PAGE_SIZE,
@@ -1116,7 +1117,7 @@ static int __reloc_gpu_alloc(struct i915_execbuffer *eb,
 	if (err)
 		goto err_request;
 
-	i915_perf_emit_sample_capture(rq, false);
+	i915_perf_emit_sample_capture(rq, false, eb->tag);
 
 	GEM_BUG_ON(!reservation_object_test_signaled_rcu(batch->resv, true));
 	i915_vma_move_to_active(batch, rq, 0);
@@ -1963,7 +1964,7 @@ static int eb_submit(struct i915_execbuffer *eb)
 			return err;
 	}
 
-	i915_perf_emit_sample_capture(eb->request, true);
+	i915_perf_emit_sample_capture(eb->request, true, eb->tag);
 
 	err = eb->engine->emit_bb_start(eb->request,
 					eb->batch->node.start +
@@ -1973,7 +1974,7 @@ static int eb_submit(struct i915_execbuffer *eb)
 	if (err)
 		return err;
 
-	i915_perf_emit_sample_capture(eb->request, false);
+	i915_perf_emit_sample_capture(eb->request, false, eb->tag);
 
 	return 0;
 }
@@ -2223,6 +2224,8 @@ static int eb_submit(struct i915_execbuffer *eb)
 	if (!eb.engine)
 		return -EINVAL;
 
+	eb.tag	= i915_execbuffer2_get_tag(*args);
+
 	if (args->flags & I915_EXEC_RESOURCE_STREAMER) {
 		if (!HAS_RESOURCE_STREAMER(eb.i915)) {
 			DRM_DEBUG("RS is only allowed for Haswell, Gen8 and above\n");
drivers/gpu/drm/i915/i915_gem_request.h +1 -0
index c839e34..a2535c6 100644
@@ -199,6 +199,7 @@ struct drm_i915_gem_request {
 	u32 *pre_oa_offset;
 	u32 *post_oa_offset;
 	u64 pid;
+	u32 tag;
 };
 
 extern const struct dma_fence_ops i915_fence_ops;
drivers/gpu/drm/i915/i915_perf.c +44 -5

148 lines not on this page · raw message

include/uapi/drm/i915_drm.h +12 -0
index f96ecfd..3884330 100644
@@ -966,6 +966,11 @@ struct drm_i915_gem_execbuffer2 {
 #define i915_execbuffer2_get_context_id(eb2) \
 	((eb2).rsvd1 & I915_EXEC_CONTEXT_ID_MASK)
 
+/* upper 32 bits of rsvd1 field contain tag */
+#define I915_EXEC_TAG_MASK		(0xffffffff00000000UL)
+#define i915_execbuffer2_get_tag(eb2) \
+	(((eb2).rsvd1 & I915_EXEC_TAG_MASK) >> 32)
+
 struct drm_i915_gem_pin {
 	/** Handle of the buffer to be pinned. */
 	__u32 handle;
@@ -1445,6 +1450,12 @@ enum drm_i915_perf_property_id {
 	 */
 	DRM_I915_PERF_PROP_SAMPLE_PID,
 
+	/**
+	 * The value of this property set to 1 requests inclusion of tag in the
+	 * perf sample data.
+	 */
+	DRM_I915_PERF_PROP_SAMPLE_TAG,
+
 	DRM_I915_PERF_PROP_MAX /* non-ABI */
 };
 
@@ -1513,6 +1524,7 @@ enum drm_i915_perf_record_type {
 	 *     { u64 source; } && DRM_I915_PERF_PROP_SAMPLE_OA_SOURCE
 	 *     { u64 ctx_id; } && DRM_I915_PERF_PROP_SAMPLE_CTX_ID
 	 *     { u64 pid; } && DRM_I915_PERF_PROP_SAMPLE_PID
+	 *     { u64 tag; } && DRM_I915_PERF_PROP_SAMPLE_TAG
 	 *     { u32 oa_report[]; } && DRM_I915_PERF_PROP_SAMPLE_OA
 	 * };
 	 */
Signature · 6 lines
1.9.1

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

PATCH 10/14 drm/i915: Link perf stream structures with Engines

In reply to Sagar Arun Kamble

To allow opening CS perf streams for other engines, this patch associates exclusive stream with each engine and correspondingly updates the required fields per stream.

---
 drivers/gpu/drm/i915/i915_drv.h         |  26 +++--
 drivers/gpu/drm/i915/i915_perf.c        | 166 +++++++++++++++-----------------
 drivers/gpu/drm/i915/intel_engine_cs.c  |   4 +
 drivers/gpu/drm/i915/intel_ringbuffer.c |   2 +
 drivers/gpu/drm/i915/intel_ringbuffer.h |   8 ++
 5 files changed, 102 insertions(+), 104 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +11 -15
index 9989f01..554f84fb 100644
@@ -2050,6 +2050,11 @@ struct i915_perf_stream {
 	 */
 	struct drm_i915_private *dev_priv;
 
+	/*
+	 * @engine: Engine to which this stream corresponds.
+	 */
+	struct intel_engine_cs *engine;
+
 	/**
 	 * @sample_flags: Flags representing the `DRM_I915_PERF_PROP_SAMPLE_*`
 	 * properties given when opening a stream, representing the contents
@@ -2114,6 +2119,10 @@ struct i915_perf_stream {
 	u32 last_ctx_id;
 	u64 last_pid;
 	u32 last_tag;
+
+	u32 specific_ctx_id;
+	wait_queue_head_t poll_wq;
+	bool pollin;
 };
 
 /**
@@ -2601,6 +2610,8 @@ struct drm_i915_private {
 		 */
 		struct idr metrics_idr;
 
+		struct hrtimer poll_check_timer;
+
 		/*
 		 * Lock associated with anything below within this structure
 		 * except exclusive_stream.
@@ -2608,21 +2619,6 @@ struct drm_i915_private {
 		struct mutex lock;
 
 		struct {
-			/*
-			 * The stream currently using the OA unit. If accessed
-			 * outside a syscall associated to its file
-			 * descriptor, you need to hold
-			 * dev_priv->drm.struct_mutex.
-			 */
-			struct i915_perf_stream *exclusive_stream;
-			struct srcu_struct srcu;
-
-			u32 specific_ctx_id;
-
-			struct hrtimer poll_check_timer;
-			wait_queue_head_t poll_wq;
-			bool pollin;
-
 			/**
 			 * For rate limiting any notifications of spurious
 			 * invalid OA reports
drivers/gpu/drm/i915/i915_perf.c +77 -89

406 lines not on this page · raw message

drivers/gpu/drm/i915/intel_engine_cs.c +4 -0
index a6ac9d0..20df519 100644
@@ -317,6 +317,10 @@ int intel_engines_init(struct drm_i915_private *dev_priv)
 			goto cleanup;
 
 		GEM_BUG_ON(!engine->submit_request);
+
+		/* Perf stream related initialization for Engine */
+		rcu_assign_pointer(engine->exclusive_stream, NULL);
+		init_srcu_struct(&engine->srcu);
 	}
 
 	return 0;
drivers/gpu/drm/i915/intel_ringbuffer.c +2 -0
index cdf084e..501c544 100644
@@ -1622,6 +1622,8 @@ void intel_engine_cleanup(struct intel_engine_cs *engine)
 
 	intel_engine_cleanup_common(engine);
 
+	cleanup_srcu_struct(&engine->srcu);
+
 	dev_priv->engine[engine->id] = NULL;
 	kfree(engine);
 }
drivers/gpu/drm/i915/intel_ringbuffer.h +8 -0
index 02d8974..2fcfaf4 100644
@@ -441,6 +441,14 @@ struct intel_engine_cs {
 	 * certain bits to encode the command length in the header).
 	 */
 	u32 (*get_cmd_length_mask)(u32 cmd_header);
+
+	/*
+	 * For RCS, This stream can use the OA unit. All accesses guarded by
+	 * SRCU including those in syscall as we can't hold
+	 * dev_priv->drm.struct_mutex in the execbuf path.
+	 */
+	struct i915_perf_stream __rcu *exclusive_stream;
+	struct srcu_struct srcu;
 };
 
 static inline unsigned int
Signature · 6 lines
1.9.1

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

PATCH 11/14 drm/i915: Add support for collecting timestamps on all gpu engines

In reply to Sagar Arun Kamble

From: Sourab Gupta <[email protected]>

With this patch, for RCS, timestamps and OA reports can be collected together, and provided to userspace in separate sample fields. For other engines, the capabilility to collect timestamps is added.

The thing to note is that, still only a single stream instance can be opened at any particular time. Though that stream may now be opened for any gpu engine, for collection of timestamp samples.

So, this patch doesn't add the support to open multiple concurrent streams, as yet.

v2: Patching the offsets for TS capture similar to OA.

---
 drivers/gpu/drm/i915/i915_drv.h         |  18 ++-
 drivers/gpu/drm/i915/i915_gem_request.h |   2 +
 drivers/gpu/drm/i915/i915_perf.c        | 223 +++++++++++++++++++++++++++++---
 drivers/gpu/drm/i915/i915_reg.h         |   2 +
 include/uapi/drm/i915_drm.h             |   7 +
 5 files changed, 230 insertions(+), 22 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +15 -3
index 554f84fb..5515e3b 100644
@@ -2242,12 +2242,24 @@ struct i915_perf_cs_sample {
 	struct drm_i915_gem_request *request;
 
 	/**
-	 * @oa_offset: Offset into ``&stream->cs_buffer``
-	 * where the perf metrics will be collected, when the commands inserted
-	 * into the command stream are executed by GPU.
+	 * @oa_offset: Offset into ``&stream->cs_buffer
+	 * where the OA report will be collected (if the stream is configured
+	 * for collection of OA samples).
 	 */
 	u32 oa_offset;
 
+	/**
+	 * @ts_offset: Offset into ``&stream->cs_buffer
+	 * where the timestamps will be collected (if the stream is configured
+	 * for collection of timestamp data)
+	 */
+	u32 ts_offset;
+
+	/**
+	 * @size: buffer size corresponding to this perf sample
+	 */
+	u32 size;
+
 	/* Is this sample prior to request start or post request end */
 	enum request_sample_id id;
 
drivers/gpu/drm/i915/i915_gem_request.h +2 -0
index a2535c6..691a0eb 100644
@@ -200,6 +200,8 @@ struct drm_i915_gem_request {
 	u32 *post_oa_offset;
 	u64 pid;
 	u32 tag;
+	u32 *pre_ts_offset;
+	u32 *post_ts_offset;
 };
 
 extern const struct dma_fence_ops i915_fence_ops;
drivers/gpu/drm/i915/i915_perf.c +204 -19

337 lines not on this page · raw message

drivers/gpu/drm/i915/i915_reg.h +2 -0
index e2908ae..04d7cda 100644
@@ -547,6 +547,7 @@ static inline bool i915_mmio_reg_valid(i915_reg_t reg)
 #define   MI_FLUSH_DW_STORE_INDEX	(1<<21)
 #define   MI_INVALIDATE_TLB		(1<<18)
 #define   MI_FLUSH_DW_OP_STOREDW	(1<<14)
+#define   MI_FLUSH_DW_OP_STAMP		(3<<14)
 #define   MI_FLUSH_DW_OP_MASK		(3<<14)
 #define   MI_FLUSH_DW_NOTIFY		(1<<8)
 #define   MI_INVALIDATE_BSD		(1<<7)
@@ -630,6 +631,7 @@ static inline bool i915_mmio_reg_valid(i915_reg_t reg)
 #define   PIPE_CONTROL_TLB_INVALIDATE			(1<<18)
 #define   PIPE_CONTROL_MEDIA_STATE_CLEAR		(1<<16)
 #define   PIPE_CONTROL_QW_WRITE				(1<<14)
+#define   PIPE_CONTROL_TIMESTAMP_WRITE			(3<<14)
 #define   PIPE_CONTROL_POST_SYNC_OP_MASK                (3<<14)
 #define   PIPE_CONTROL_DEPTH_STALL			(1<<13)
 #define   PIPE_CONTROL_WRITE_FLUSH			(1<<12)
include/uapi/drm/i915_drm.h +7 -0
index 3884330..ad0df78 100644
@@ -1456,6 +1456,12 @@ enum drm_i915_perf_property_id {
 	 */
 	DRM_I915_PERF_PROP_SAMPLE_TAG,
 
+	/**
+	 * The value of this property set to 1 requests inclusion of timestamp
+	 * in the perf sample data.
+	 */
+	DRM_I915_PERF_PROP_SAMPLE_TS,
+
 	DRM_I915_PERF_PROP_MAX /* non-ABI */
 };
 
@@ -1525,6 +1531,7 @@ enum drm_i915_perf_record_type {
 	 *     { u64 ctx_id; } && DRM_I915_PERF_PROP_SAMPLE_CTX_ID
 	 *     { u64 pid; } && DRM_I915_PERF_PROP_SAMPLE_PID
 	 *     { u64 tag; } && DRM_I915_PERF_PROP_SAMPLE_TAG
+	 *     { u64 timestamp; } && DRM_I915_PERF_PROP_SAMPLE_TS
 	 *     { u32 oa_report[]; } && DRM_I915_PERF_PROP_SAMPLE_OA
 	 * };
 	 */
Signature · 6 lines
1.9.1

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

PATCH 12/14 drm/i915: Extract raw GPU timestamps from OA reports to forward in perf samples

In reply to Sagar Arun Kamble

From: Sourab Gupta <[email protected]>

The OA reports contain the least significant 32 bits of the gpu timestamp. This patch enables retrieval of the timestamp field from OA reports, to forward as 64 bit raw gpu timestamps in the perf samples.

---
 drivers/gpu/drm/i915/i915_drv.h  |  1 +
 drivers/gpu/drm/i915/i915_perf.c | 48 ++++++++++++++++++++++++++++++----------
 drivers/gpu/drm/i915/i915_reg.h  |  4 ++++
 3 files changed, 41 insertions(+), 12 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +1 -0
index 5515e3b..b5e8d95 100644
@@ -2720,6 +2720,7 @@ struct drm_i915_private {
 			u32 ctx_flexeu0_offset;
 			u32 n_pending_periodic_samples;
 			u32 pending_periodic_ts;
+			u64 last_gpu_ts;
 
 			/**
 			 * The RPT_ID/reason field for Gen8+ includes a bit
drivers/gpu/drm/i915/i915_perf.c +36 -12

90 lines not on this page · raw message

drivers/gpu/drm/i915/i915_reg.h +4 -0
index 04d7cda..c379cb5 100644
@@ -730,6 +730,10 @@ static inline bool i915_mmio_reg_valid(i915_reg_t reg)
 #define PS_DEPTH_COUNT                  _MMIO(0x2350)
 #define PS_DEPTH_COUNT_UDW		_MMIO(0x2350 + 4)
 
+/* Timestamp count register */
+#define GT_TIMESTAMP_COUNT		_MMIO(0x2358)
+#define GT_TIMESTAMP_COUNT_UDW		_MMIO(0x2358 + 4)
+
 /* There are the 4 64-bit counter registers, one for each stream output */
 #define GEN7_SO_NUM_PRIMS_WRITTEN(n)		_MMIO(0x5200 + (n) * 8)
 #define GEN7_SO_NUM_PRIMS_WRITTEN_UDW(n)	_MMIO(0x5200 + (n) * 8 + 4)
Signature · 6 lines
1.9.1

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

PATCH 13/14 drm/i915: Async check for streams data availability with hrtimer rescheduling

In reply to Sagar Arun Kamble

From: Sourab Gupta <[email protected]>

This patch ensures hrtimer is rescheduled immediately during cb by doing async call to check for streams data availability.

---
 drivers/gpu/drm/i915/i915_perf.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/gpu/drm/i915/i915_perf.c +11 -4
index 33842fc..8605b83 100644
@@ -3462,12 +3462,10 @@ static ssize_t i915_perf_read(struct file *file,
 	return ret;
 }
 
-static enum hrtimer_restart poll_check_timer_cb(struct hrtimer *hrtimer)
+static void wake_up_perf_streams(void *data, async_cookie_t cookie)
 {
+	struct drm_i915_private *dev_priv = data;
 	struct i915_perf_stream *stream;
-	struct drm_i915_private *dev_priv =
-		container_of(hrtimer, typeof(*dev_priv),
-			     perf.poll_check_timer);
 	int idx;
 	struct intel_engine_cs *engine;
 	enum intel_engine_id id;
@@ -3483,6 +3481,15 @@ static enum hrtimer_restart poll_check_timer_cb(struct hrtimer *hrtimer)
 		}
 		srcu_read_unlock(&engine->srcu, idx);
 	}
+}
+
+static enum hrtimer_restart poll_check_timer_cb(struct hrtimer *hrtimer)
+{
+	struct drm_i915_private *dev_priv =
+		container_of(hrtimer, typeof(*dev_priv),
+			     perf.poll_check_timer);
+
+	async_schedule(wake_up_perf_streams, dev_priv);
 
 	hrtimer_forward_now(hrtimer, ns_to_ktime(POLL_PERIOD));
 
Signature · 6 lines
1.9.1

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

PATCH 14/14 drm/i915: Support for capturing MMIO register values

In reply to Sagar Arun Kamble

From: Sourab Gupta <[email protected]>

This patch adds support for capturing MMIO register values through i915 perf interface.
The userspace can request upto 8 MMIO register values to be dumped. The addresses of these registers can be passed through the corresponding property 'value' field while opening the stream.
The commands to dump the values of these MMIO registers are then inserted into the ring alongwith other commands.

v2: Updated error return on copy_from_user failure. (Chris)

v3: Adjusted the patching of request ringbuffer contents w.r.t new of allocating samples.

---
 drivers/gpu/drm/i915/i915_drv.h         |  10 ++
 drivers/gpu/drm/i915/i915_gem_request.h |   3 +
 drivers/gpu/drm/i915/i915_perf.c        | 193 +++++++++++++++++++++++++++++++-
 drivers/gpu/drm/i915/intel_ringbuffer.h |   3 +
 include/uapi/drm/i915_drm.h             |  14 +++
 5 files changed, 220 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +10 -0
index b5e8d95..0e8735fdf 100644
@@ -2256,6 +2256,13 @@ struct i915_perf_cs_sample {
 	u32 ts_offset;
 
 	/**
+	 * @mmio_offset: Offset into ``&stream->cs_buffer`` where the mmio reg
+	 * values for this perf sample will be collected (if the stream is
+	 * configured for collection of mmio data)
+	 */
+	u32 mmio_offset;
+
+	/**
 	 * @size: buffer size corresponding to this perf sample
 	 */
 	u32 size;
@@ -2732,6 +2739,9 @@ struct drm_i915_private {
 			struct i915_oa_ops ops;
 			const struct i915_oa_format *oa_formats;
 		} oa;
+
+		u32 num_mmio;
+		u32 mmio_list[I915_PERF_MMIO_NUM_MAX];
 	} perf;
 
 	/* Abstract the submission mechanism (legacy ringbuffer or execlists) away */
drivers/gpu/drm/i915/i915_gem_request.h +3 -0
index 691a0eb..60aee3f 100644
@@ -29,6 +29,7 @@
 
 #include "i915_gem.h"
 #include "i915_sw_fence.h"
+#include <drm/i915_drm.h>
 
 struct drm_file;
 struct drm_i915_gem_object;
@@ -202,6 +203,8 @@ struct drm_i915_gem_request {
 	u32 tag;
 	u32 *pre_ts_offset;
 	u32 *post_ts_offset;
+	u32 *pre_mmio_offset[I915_PERF_MMIO_NUM_MAX];
+	u32 *post_mmio_offset[I915_PERF_MMIO_NUM_MAX];
 };
 
 extern const struct dma_fence_ops i915_fence_ops;
drivers/gpu/drm/i915/i915_perf.c +190 -3

296 lines not on this page · raw message

drivers/gpu/drm/i915/intel_ringbuffer.h +3 -0
index 2fcfaf4..3ad429a 100644
@@ -449,6 +449,9 @@ struct intel_engine_cs {
 	 */
 	struct i915_perf_stream __rcu *exclusive_stream;
 	struct srcu_struct srcu;
+
+	u32 num_mmio;
+	u32 mmio_list[I915_PERF_MMIO_NUM_MAX];
 };
 
 static inline unsigned int
include/uapi/drm/i915_drm.h +14 -0
index ad0df78..36520e4 100644
@@ -1390,6 +1390,12 @@ enum drm_i915_perf_sample_oa_source {
 	I915_PERF_SAMPLE_OA_SOURCE_MAX	/* non-ABI */
 };
 
+#define I915_PERF_MMIO_NUM_MAX	8
+struct drm_i915_perf_mmio_list {
+	__u32 num_mmio;
+	__u32 mmio_list[I915_PERF_MMIO_NUM_MAX];
+};
+
 enum drm_i915_perf_property_id {
 	/**
 	 * Open the stream for a specific context handle (as used with
@@ -1462,6 +1468,13 @@ enum drm_i915_perf_property_id {
 	 */
 	DRM_I915_PERF_PROP_SAMPLE_TS,
 
+	/**
+	 * This property requests inclusion of mmio register values in the perf
+	 * sample data. The value of this property specifies the address of user
+	 * struct having the register addresses.
+	 */
+	DRM_I915_PERF_PROP_SAMPLE_MMIO,
+
 	DRM_I915_PERF_PROP_MAX /* non-ABI */
 };
 
@@ -1532,6 +1545,7 @@ enum drm_i915_perf_record_type {
 	 *     { u64 pid; } && DRM_I915_PERF_PROP_SAMPLE_PID
 	 *     { u64 tag; } && DRM_I915_PERF_PROP_SAMPLE_TAG
 	 *     { u64 timestamp; } && DRM_I915_PERF_PROP_SAMPLE_TS
+	 *     { u32 mmio[]; } && DRM_I915_PERF_PROP_SAMPLE_MMIO
 	 *     { u32 oa_report[]; } && DRM_I915_PERF_PROP_SAMPLE_OA
 	 * };
 	 */
Signature · 6 lines
1.9.1

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

✓ Fi.CI.BAT: success for i915 perf support for command stream based OA, GPU and workload metrics capture (rev2)

In reply to Sagar Arun Kamble
== Series Details ==

== Series Details ==

Series: i915 perf support for command stream based OA, GPU and workload metrics capture (rev2)
URL : https://patchwork.freedesktop.org/series/28104/
State : success

== Summary ==

Series 28104v2 i915 perf support for command stream based OA, GPU and workload metrics capture
https://patchwork.freedesktop.org/api/1.0/series/28104/revisions/2/mbox/

fi-bdw-5557u     total:279  pass:268  dwarn:0   dfail:0   fail:0   skip:11  time:457s
fi-bdw-gvtdvm    total:279  pass:265  dwarn:0   dfail:0   fail:0   skip:14  time:441s
fi-blb-e6850     total:279  pass:224  dwarn:1   dfail:0   fail:0   skip:54  time:364s
fi-bsw-n3050     total:279  pass:243  dwarn:0   dfail:0   fail:0   skip:36  time:559s
fi-bwr-2160      total:279  pass:184  dwarn:0   dfail:0   fail:0   skip:95  time:252s
fi-bxt-j4205     total:279  pass:260  dwarn:0   dfail:0   fail:0   skip:19  time:525s
fi-byt-j1900     total:279  pass:254  dwarn:1   dfail:0   fail:0   skip:24  time:526s
fi-byt-n2820     total:279  pass:250  dwarn:1   dfail:0   fail:0   skip:28  time:514s
fi-elk-e7500     total:279  pass:230  dwarn:0   dfail:0   fail:0   skip:49  time:438s
fi-glk-2a        total:279  pass:260  dwarn:0   dfail:0   fail:0   skip:19  time:611s
fi-hsw-4770      total:279  pass:263  dwarn:0   dfail:0   fail:0   skip:16  time:446s
fi-hsw-4770r     total:279  pass:263  dwarn:0   dfail:0   fail:0   skip:16  time:423s
fi-ilk-650       total:279  pass:229  dwarn:0   dfail:0   fail:0   skip:50  time:426s
fi-ivb-3520m     total:279  pass:261  dwarn:0   dfail:0   fail:0   skip:18  time:505s
fi-ivb-3770      total:279  pass:261  dwarn:0   dfail:0   fail:0   skip:18  time:475s
fi-kbl-7500u     total:279  pass:261  dwarn:0   dfail:0   fail:0   skip:18  time:484s
fi-kbl-7560u     total:279  pass:269  dwarn:0   dfail:0   fail:0   skip:10  time:596s
fi-kbl-r         total:279  pass:261  dwarn:0   dfail:0   fail:0   skip:18  time:601s
fi-pnv-d510      total:279  pass:223  dwarn:1   dfail:0   fail:0   skip:55  time:524s
fi-skl-6260u     total:279  pass:269  dwarn:0   dfail:0   fail:0   skip:10  time:468s
fi-skl-6700k     total:279  pass:261  dwarn:0   dfail:0   fail:0   skip:18  time:483s
fi-skl-6770hq    total:279  pass:269  dwarn:0   dfail:0   fail:0   skip:10  time:496s
fi-skl-gvtdvm    total:279  pass:266  dwarn:0   dfail:0   fail:0   skip:13  time:441s
fi-skl-x1585l    total:279  pass:268  dwarn:0   dfail:0   fail:0   skip:11  time:477s
fi-snb-2520m     total:279  pass:251  dwarn:0   dfail:0   fail:0   skip:28  time:548s
fi-snb-2600      total:279  pass:248  dwarn:0   dfail:0   fail:2   skip:29  time:412s

c52f5322612a688655751c4dd44baa43e39d4dec drm-tip: 2017y-08m-26d-11h-41m-06s UTC integration manifest a419e5fcb12f drm/i915: Support for capturing MMIO register values
1b48288a71cf drm/i915: Async check for streams data availability with hrtimer rescheduling f168e3fa2f06 drm/i915: Extract raw GPU timestamps from OA reports to forward in perf samples bde0d0d6eb4e drm/i915: Add support for collecting timestamps on all gpu engines 8b0fab464e1a drm/i915: Link perf stream structures with Engines
b4e368066fb1 drm/i915: Add support for emitting execbuffer tags through OA counter reports 0b79f744a467 drm/i915: Add support for having pid output with OA report
4d197fda9cac drm/i915: Populate ctx ID for periodic OA reports
f923eda48bc8 drm/i915: Inform userspace about command stream OA buf overflow 6490dde322c2 drm/i915: Flush periodic samples, in case of no pending CS sample requests 3aab294733f8 drm/i915: Define CTX_ID property for perf sampling
a2d5a39d29bb drm/i915: Framework for capturing command stream based OA reports. bf3d4fd72084 drm/i915: Expose OA sample source to userspace
27302bb9bfd3 drm/i915: Add ctx getparam ioctl parameter to retrieve ctx unique id

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_5503/
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#16 lore raw

✗ Fi.CI.IGT: failure for i915 perf support for command stream based OA, GPU and workload metrics capture (rev2)

In reply to Sagar Arun Kamble
== Series Details ==

== Series Details ==

Series: i915 perf support for command stream based OA, GPU and workload metrics capture (rev2)
URL : https://patchwork.freedesktop.org/series/28104/
State : failure

== Summary ==

Test perf:

        Subgroup short-reads:
                pass       -> FAIL       (shard-hsw)
        Subgroup disabled-read-error:
                pass       -> FAIL       (shard-hsw)
        Subgroup buffer-fill:
                pass       -> INCOMPLETE (shard-hsw)
        Subgroup missing-sample-flags:
                pass       -> INCOMPLETE (shard-hsw)
        Subgroup blocking:
                pass       -> INCOMPLETE (shard-hsw) fdo#102252
Test kms_plane_multiple:
        Subgroup atomic-pipe-A-tiling-x:
                pass       -> SKIP       (shard-hsw)
Test gem_ctx_param:
        Subgroup invalid-param-get:
                pass       -> FAIL       (shard-hsw)

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

shard-hsw total:2133 pass:1176 dwarn:0 dfail:0 fail:19 skip:935 time:9259s

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_5503/shards.html
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx