From patchwork Thu Sep 7 10:06:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: sagar.a.kamble@intel.com X-Patchwork-Id: 9941987 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 9EB0F602CC for ; Thu, 7 Sep 2017 10:03:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF66D28606 for ; Thu, 7 Sep 2017 10:03:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A3E8F28608; Thu, 7 Sep 2017 10:03:09 +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]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1A89E28606 for ; Thu, 7 Sep 2017 10:03:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5AF866E8DF; Thu, 7 Sep 2017 10:03:08 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by gabe.freedesktop.org (Postfix) with ESMTPS id 79A616E8DA for ; Thu, 7 Sep 2017 10:03:06 +0000 (UTC) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Sep 2017 03:03:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,357,1500966000"; d="scan'208";a="126439740" Received: from sakamble-desktop.iind.intel.com ([10.223.26.118]) by orsmga004.jf.intel.com with ESMTP; 07 Sep 2017 03:03:05 -0700 From: Sagar Arun Kamble To: intel-gfx@lists.freedesktop.org Date: Thu, 7 Sep 2017 15:36:08 +0530 Message-Id: <1504778774-18117-9-git-send-email-sagar.a.kamble@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1504778774-18117-1-git-send-email-sagar.a.kamble@intel.com> References: <1504778774-18117-1-git-send-email-sagar.a.kamble@intel.com> Cc: Sourab Gupta Subject: [Intel-gfx] [PATCH 08/14] 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. 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. v3: Updated stream->last_pid to INVALID_PID during stream_init. Testcase: igt/intel_perf_dapc/perf-pid Signed-off-by: Sourab Gupta Signed-off-by: Sagar Arun Kamble --- drivers/gpu/drm/i915/i915_drv.h | 7 +++++ drivers/gpu/drm/i915/i915_gem_request.h | 1 + drivers/gpu/drm/i915/i915_perf.c | 56 ++++++++++++++++++++++++++++++++- include/uapi/drm/i915_drm.h | 7 +++++ 4 files changed, 70 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index a72ba20..c1102fe 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -2129,6 +2129,7 @@ struct i915_perf_stream { spinlock_t samples_lock; u32 last_ctx_id; + u64 last_pid; }; /** @@ -2261,6 +2262,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 { diff --git a/drivers/gpu/drm/i915/i915_gem_request.h b/drivers/gpu/drm/i915/i915_gem_request.h index ffda982a..c839e34 100644 --- a/drivers/gpu/drm/i915/i915_gem_request.h +++ b/drivers/gpu/drm/i915/i915_gem_request.h @@ -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; diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c index c3c2674..ecfcffa 100644 --- a/drivers/gpu/drm/i915/i915_perf.c +++ b/drivers/gpu/drm/i915/i915_perf.c @@ -282,6 +282,7 @@ #define OA_EXPONENT_MAX 31 #define INVALID_CTX_ID 0xffffffff +#define INVALID_PID 0xffffffff /* On Gen8+ automatically triggered OA reports include a 'reason' field... */ #define OAREPORT_REASON_MASK 0x3f @@ -294,6 +295,7 @@ struct i915_perf_sample_data { u64 source; u64 ctx_id; + u64 pid; const u8 *report; }; @@ -349,6 +351,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 @@ -512,6 +515,9 @@ static void i915_perf_stream_emit_sample_capture( DRM_ERROR("Emit of OA capture commands failed\n"); } + if (stream->sample_flags & SAMPLE_PID) + request->pid = current->pid; + reservation_object_lock(resv, NULL); if (reservation_object_reserve_shared(resv) == 0) reservation_object_add_shared_fence(resv, &request->fence); @@ -626,6 +632,7 @@ static void i915_perf_stream_patch_request(struct i915_perf_stream *stream, sample->request = i915_gem_request_get(request); sample->id = sample_id; sample->ctx_id = request->ctx->hw_id; + sample->pid = request->pid; if (stream->sample_flags & (SAMPLE_OA_REPORT | SAMPLE_OA_SOURCE)) i915_perf_stream_patch_sample_oa(stream, request, @@ -943,6 +950,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; @@ -980,6 +993,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; @@ -1588,6 +1604,14 @@ static int append_cs_buffer_sample(struct i915_perf_stream *stream, stream->last_ctx_id = INVALID_CTX_ID; } + if (sample_flags & SAMPLE_PID) { + data.pid = node->pid; + if (node->id == PRE_REQUEST_SAMPLE_ID) + stream->last_pid = node->pid; + else + stream->last_pid = INVALID_PID; + } + return append_perf_sample(stream, buf, count, offset, &data); } @@ -2820,6 +2844,7 @@ static int i915_perf_stream_init(struct i915_perf_stream *stream, bool require_oa_unit = props->sample_flags & (SAMPLE_OA_REPORT | SAMPLE_OA_SOURCE); bool cs_sample_data = props->sample_flags & SAMPLE_OA_REPORT; + bool require_cs_mode = props->sample_flags & SAMPLE_PID; struct i915_perf_stream *curr_stream; struct intel_engine_cs *engine = NULL; int ret; @@ -2970,6 +2995,20 @@ static int i915_perf_stream_init(struct i915_perf_stream *stream, stream->sample_flags |= SAMPLE_CTX_ID; stream->sample_size += 8; stream->last_ctx_id = INVALID_CTX_ID; + + /* + * 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) { @@ -2981,13 +3020,25 @@ 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; + stream->last_pid = INVALID_PID; + } + idx = srcu_read_lock(&dev_priv->perf.oa.srcu); curr_stream = srcu_dereference( dev_priv->perf.oa.exclusive_stream, @@ -3708,6 +3759,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 68baaf9..f96ecfd 100644 --- a/include/uapi/drm/i915_drm.h +++ b/include/uapi/drm/i915_drm.h @@ -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 * }; */