All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sagar Arun Kamble <sagar.a.kamble@intel.com>
To: intel-gfx@lists.freedesktop.org
Cc: Sourab Gupta <sourab.gupta@intel.com>
Subject: [PATCH 07/12] drm/i915: Add support for having pid output with OA report
Date: Mon, 31 Jul 2017 13:29:40 +0530	[thread overview]
Message-ID: <1501487985-2017-8-git-send-email-sagar.a.kamble@intel.com> (raw)
In-Reply-To: <1501487985-2017-1-git-send-email-sagar.a.kamble@intel.com>

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

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)

Signed-off-by: Sourab Gupta <sourab.gupta@intel.com>
Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
---
 drivers/gpu/drm/i915/i915_drv.h  |  7 ++++++
 drivers/gpu/drm/i915/i915_perf.c | 48 +++++++++++++++++++++++++++++++++++++++-
 include/uapi/drm/i915_drm.h      |  7 ++++++
 3 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 6c011f3..b56ea20 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -2079,6 +2079,7 @@ struct i915_perf_stream {
 	bool pollin;
 
 	u32 last_ctx_id;
+	u32 last_pid;
 };
 
 /**
@@ -2189,6 +2190,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
+	 */
+	u32 pid;
 };
 
 struct intel_cdclk_state {
diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c
index 1f5ebdb..5ac1a41 100644
--- a/drivers/gpu/drm/i915/i915_perf.c
+++ b/drivers/gpu/drm/i915/i915_perf.c
@@ -293,6 +293,7 @@
 struct i915_perf_sample_data {
 	u64 source;
 	u64 ctx_id;
+	u64 pid;
 	const u8 *report;
 };
 
@@ -348,6 +349,7 @@ struct i915_perf_sample_data {
 #define SAMPLE_OA_REPORT      (1<<0)
 #define SAMPLE_OA_SOURCE      (1<<1)
 #define SAMPLE_CTX_ID	      (1<<2)
+#define SAMPLE_PID	      (1<<3)
 
 /**
  * struct perf_open_properties - for validated properties given to open a stream
@@ -608,6 +610,7 @@ static void i915_perf_stream_emit_sample_capture(
 
 	sample->request = i915_gem_request_get(request);
 	sample->ctx_id = request->ctx->hw_id;
+	sample->pid = current->pid;
 
 	insert_perf_sample(stream, sample);
 
@@ -924,6 +927,12 @@ static int append_perf_sample(struct i915_perf_stream *stream,
 		buf += 8;
 	}
 
+	if (sample_flags & SAMPLE_PID) {
+		if (copy_to_user(buf, &data->pid, 8))
+			return -EFAULT;
+		buf += 8;
+	}
+
 	if (sample_flags & SAMPLE_OA_REPORT) {
 		if (copy_to_user(buf, data->report, report_size))
 			return -EFAULT;
@@ -961,6 +970,9 @@ static int append_oa_buffer_sample(struct i915_perf_stream *stream,
 		data.ctx_id = dev_priv->perf.oa.ops.get_ctx_id(stream, report);
 	}
 
+	if (sample_flags & SAMPLE_PID)
+		data.pid = stream->last_pid;
+
 	if (sample_flags & SAMPLE_OA_REPORT)
 		data.report = report;
 
@@ -1558,6 +1570,11 @@ static int append_cs_buffer_sample(struct i915_perf_stream *stream,
 		stream->last_ctx_id = data.ctx_id;
 	}
 
+	if (sample_flags & SAMPLE_PID) {
+		data.pid = node->pid;
+		stream->last_pid = node->pid;
+	}
+
 	return append_perf_sample(stream, buf, count, offset, &data);
 }
 
@@ -2719,6 +2736,7 @@ static int i915_perf_stream_init(struct i915_perf_stream *stream,
 	struct drm_i915_private *dev_priv = stream->dev_priv;
 	bool require_oa_unit = props->sample_flags & (SAMPLE_OA_REPORT |
 						      SAMPLE_OA_SOURCE);
+	bool require_cs_mode = props->sample_flags & SAMPLE_PID;
 	bool cs_sample_data = props->sample_flags & SAMPLE_OA_REPORT;
 	struct i915_perf_stream *curr_stream;
 	struct intel_engine_cs *engine = NULL;
@@ -2866,6 +2884,20 @@ static int i915_perf_stream_init(struct i915_perf_stream *stream,
 	if (props->sample_flags & SAMPLE_CTX_ID) {
 		stream->sample_flags |= SAMPLE_CTX_ID;
 		stream->sample_size += 8;
+
+		/*
+		 * NB: it's meaningful to request SAMPLE_CTX_ID with just CS
+		 * mode or periodic OA mode sampling but we don't allow
+		 * SAMPLE_CTX_ID without either mode
+		 */
+		if (!require_oa_unit)
+			require_cs_mode = true;
+	}
+
+	if (require_cs_mode && !props->cs_mode) {
+		DRM_ERROR("PID sampling requires a ring to be specified");
+		ret = -EINVAL;
+		goto err_enable;
 	}
 
 	if (props->cs_mode) {
@@ -2875,12 +2907,23 @@ static int i915_perf_stream_init(struct i915_perf_stream *stream,
 			goto err_enable;
 		}
 
-		if (!(props->sample_flags & SAMPLE_CTX_ID)) {
+		/*
+		 * The only time we should allow enabling CS mode if it's not
+		 * strictly required, is if SAMPLE_CTX_ID has been requested
+		 * as it's usable with periodic OA or CS sampling.
+		 */
+		if (!require_cs_mode &&
+		    !(props->sample_flags & SAMPLE_CTX_ID)) {
 			DRM_ERROR("Stream engine given without requesting any CS specific property\n");
 			ret = -EINVAL;
 			goto err_enable;
 		}
 
+		if (props->sample_flags & SAMPLE_PID) {
+			stream->sample_flags |= SAMPLE_PID;
+			stream->sample_size += 8;
+		}
+
 		engine = dev_priv->engine[props->engine];
 
 		idx = srcu_read_lock(&engine->perf_srcu);
@@ -3595,6 +3638,9 @@ static int read_properties_unlocked(struct drm_i915_private *dev_priv,
 		case DRM_I915_PERF_PROP_SAMPLE_CTX_ID:
 			props->sample_flags |= SAMPLE_CTX_ID;
 			break;
+		case DRM_I915_PERF_PROP_SAMPLE_PID:
+			props->sample_flags |= SAMPLE_PID;
+			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 768b1a5..34d8e41 100644
--- a/include/uapi/drm/i915_drm.h
+++ b/include/uapi/drm/i915_drm.h
@@ -1408,6 +1408,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 */
 };
 
@@ -1475,6 +1481,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
 	 * };
 	 */
-- 
1.9.1

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

  parent reply	other threads:[~2017-07-31  7:58 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-31  7:59 [PATCH 00/12] i915 perf support for command stream based OA, GPU and workload metrics capture Sagar Arun Kamble
2017-07-31  7:59 ` [PATCH 01/12] drm/i915: Add ctx getparam ioctl parameter to retrieve ctx unique id Sagar Arun Kamble
2017-07-31  7:59 ` [PATCH 02/12] drm/i915: Expose OA sample source to userspace Sagar Arun Kamble
2017-07-31  7:59 ` [PATCH 03/12] drm/i915: Framework for capturing command stream based OA reports and ctx id info Sagar Arun Kamble
2017-07-31  8:34   ` Chris Wilson
2017-07-31 10:11     ` Chris Wilson
2017-08-02  4:44       ` Kamble, Sagar A
2017-07-31  9:43   ` Lionel Landwerlin
2017-07-31 11:38     ` sourab gupta
2017-07-31 14:25       ` Lionel Landwerlin
2017-07-31 15:38   ` kbuild test robot
2017-07-31 15:45   ` Lionel Landwerlin
2017-08-01  9:29     ` Kamble, Sagar A
2017-08-01 18:05       ` sourab gupta
2017-08-01 20:58         ` Lionel Landwerlin
2017-08-02  2:47           ` sourab gupta
2017-08-02  4:25             ` Kamble, Sagar A
2017-07-31  7:59 ` [PATCH 04/12] drm/i915: Flush periodic samples, in case of no pending CS sample requests Sagar Arun Kamble
2017-07-31 16:52   ` kbuild test robot
2017-07-31  7:59 ` [PATCH 05/12] drm/i915: Inform userspace about command stream OA buf overflow Sagar Arun Kamble
2017-07-31  7:59 ` [PATCH 06/12] drm/i915: Populate ctx ID for periodic OA reports Sagar Arun Kamble
2017-07-31  9:27   ` Lionel Landwerlin
2017-07-31 10:42     ` Kamble, Sagar A
2017-07-31 18:17   ` kbuild test robot
2017-07-31  7:59 ` Sagar Arun Kamble [this message]
2017-07-31 19:24   ` [PATCH 07/12] drm/i915: Add support for having pid output with OA report kbuild test robot
2017-07-31  7:59 ` [PATCH 08/12] drm/i915: Add support for emitting execbuffer tags through OA counter reports Sagar Arun Kamble
2017-07-31  7:59 ` [PATCH 09/12] drm/i915: Add support for collecting timestamps on all gpu engines Sagar Arun Kamble
2017-07-31  7:59 ` [PATCH 10/12] drm/i915: Extract raw GPU timestamps from OA reports to forward in perf samples Sagar Arun Kamble
2017-07-31  7:59 ` [PATCH 11/12] drm/i915: Async check for streams data availability with hrtimer rescheduling Sagar Arun Kamble
2017-07-31  7:59 ` [PATCH 12/12] drm/i915: Support for capturing MMIO register values Sagar Arun Kamble
2017-07-31 11:49   ` kbuild test robot
2017-07-31 12:08   ` kbuild test robot
2017-07-31  9:02 ` ✓ Fi.CI.BAT: success for i915 perf support for command stream based OA, GPU and workload metrics capture Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1501487985-2017-8-git-send-email-sagar.a.kamble@intel.com \
    --to=sagar.a.kamble@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=sourab.gupta@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.