From patchwork Thu Jun 2 05:18:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: sourab.gupta@intel.com X-Patchwork-Id: 9149051 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 071A760467 for ; Thu, 2 Jun 2016 05:17:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE76B25EF7 for ; Thu, 2 Jun 2016 05:17:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E368B271FD; Thu, 2 Jun 2016 05:17:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C37625EF7 for ; Thu, 2 Jun 2016 05:17:27 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3C8BC6E365; Thu, 2 Jun 2016 05:17:26 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by gabe.freedesktop.org (Postfix) with ESMTP id 85B2D6E365 for ; Thu, 2 Jun 2016 05:17:18 +0000 (UTC) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP; 01 Jun 2016 22:17:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,404,1459839600"; d="scan'208";a="967198444" Received: from sourab-desktop.iind.intel.com ([10.223.82.156]) by orsmga001.jf.intel.com with ESMTP; 01 Jun 2016 22:17:15 -0700 From: sourab.gupta@intel.com To: intel-gfx@lists.freedesktop.org Date: Thu, 2 Jun 2016 10:48:41 +0530 Message-Id: <1464844729-2774-8-git-send-email-sourab.gupta@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1464844729-2774-1-git-send-email-sourab.gupta@intel.com> References: <1464844729-2774-1-git-send-email-sourab.gupta@intel.com> Cc: Daniel Vetter , Sourab Gupta , Deepak S Subject: [Intel-gfx] [PATCH 07/15] drm/i915: Add support for having pid output with OA report X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Sourab Gupta 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. Signed-off-by: Sourab Gupta --- drivers/gpu/drm/i915/i915_drv.h | 2 ++ drivers/gpu/drm/i915/i915_perf.c | 48 +++++++++++++++++++++++++++++++++++++++- include/uapi/drm/i915_drm.h | 7 ++++++ 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index 9d23ca1..60e94e6 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -1851,6 +1851,7 @@ struct i915_perf_cs_data_node { struct drm_i915_gem_request *request; u32 offset; u32 ctx_id; + u32 pid; }; struct drm_i915_private { @@ -2197,6 +2198,7 @@ struct drm_i915_private { } command_stream_buf; u32 last_ctx_id; + u32 last_pid; 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 2496a4b..bb5356f 100644 --- a/drivers/gpu/drm/i915/i915_perf.c +++ b/drivers/gpu/drm/i915/i915_perf.c @@ -88,6 +88,7 @@ static u32 i915_perf_stream_paranoid = true; struct oa_sample_data { u32 source; u32 ctx_id; + u32 pid; const u8 *report; }; @@ -143,6 +144,7 @@ static const enum intel_engine_id user_ring_map[I915_USER_RINGS + 1] = { #define SAMPLE_OA_REPORT (1<<0) #define SAMPLE_OA_SOURCE_INFO (1<<1) #define SAMPLE_CTX_ID (1<<2) +#define SAMPLE_PID (1<<3) struct perf_open_properties { u32 sample_flags; @@ -322,6 +324,7 @@ static void i915_perf_command_stream_hook_oa(struct drm_i915_gem_request *req) goto out; entry->ctx_id = ctx->hw_id; + entry->pid = current->pid; i915_gem_request_assign(&entry->request, req); addr = dev_priv->perf.command_stream_buf.vma->node.start + @@ -582,6 +585,12 @@ static int append_oa_sample(struct i915_perf_stream *stream, buf += 4; } + if (sample_flags & SAMPLE_PID) { + if (copy_to_user(buf, &data->pid, 4)) + return -EFAULT; + buf += 4; + } + if (sample_flags & SAMPLE_OA_REPORT) { if (copy_to_user(buf, data->report, report_size)) return -EFAULT; @@ -624,6 +633,9 @@ static int append_oa_buffer_sample(struct i915_perf_stream *stream, data.ctx_id = dev_priv->perf.oa.ops.oa_buffer_get_ctx_id( stream, report); + if (sample_flags & SAMPLE_PID) + data.pid = dev_priv->perf.last_pid; + if (sample_flags & SAMPLE_OA_REPORT) data.report = report; @@ -1092,6 +1104,11 @@ static int append_oa_rcs_sample(struct i915_perf_stream *stream, dev_priv->perf.last_ctx_id = node->ctx_id; } + if (sample_flags & SAMPLE_PID) { + data.pid = node->pid; + dev_priv->perf.last_pid = node->pid; + } + if (sample_flags & SAMPLE_OA_REPORT) data.report = report; @@ -1873,6 +1890,7 @@ static int i915_oa_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_INFO); + bool require_cs_mode = props->sample_flags & SAMPLE_PID; bool cs_sample_data = props->sample_flags & SAMPLE_OA_REPORT; int ret; @@ -2005,6 +2023,20 @@ static int i915_oa_stream_init(struct i915_perf_stream *stream, if (props->sample_flags & SAMPLE_CTX_ID) { stream->sample_flags |= SAMPLE_CTX_ID; stream->sample_size += 4; + + /* + * 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 cs_error; } if (props->cs_mode) { @@ -2015,7 +2047,13 @@ static int i915_oa_stream_init(struct i915_perf_stream *stream, goto cs_error; } - 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( "Ring given without requesting any CS specific property"); ret = -EINVAL; @@ -2024,6 +2062,11 @@ static int i915_oa_stream_init(struct i915_perf_stream *stream, stream->cs_mode = true; + if (props->sample_flags & SAMPLE_PID) { + stream->sample_flags |= SAMPLE_PID; + stream->sample_size += 4; + } + ret = alloc_command_stream_buf(dev_priv); if (ret) goto cs_error; @@ -2661,6 +2704,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: BUG(); } diff --git a/include/uapi/drm/i915_drm.h b/include/uapi/drm/i915_drm.h index 7faced8..8069790 100644 --- a/include/uapi/drm/i915_drm.h +++ b/include/uapi/drm/i915_drm.h @@ -1255,6 +1255,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 */ }; @@ -1321,6 +1327,7 @@ enum drm_i915_perf_record_type { * * { u32 source_info; } && DRM_I915_PERF_PROP_SAMPLE_OA_SOURCE * { u32 ctx_id; } && DRM_I915_PERF_PROP_SAMPLE_CTX_ID + * { u32 pid; } && DRM_I915_PERF_PROP_SAMPLE_PID * { u32 oa_report[]; } && DRM_I915_PERF_PROP_SAMPLE_OA * }; */