From patchwork Thu Sep 7 10:06:04 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: 9941981 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 079F4604D5 for ; Thu, 7 Sep 2017 10:03:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 199E628600 for ; Thu, 7 Sep 2017 10:03:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0E6CC28607; Thu, 7 Sep 2017 10:03:07 +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 960A728606 for ; Thu, 7 Sep 2017 10:03:06 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7B7A76E8D7; Thu, 7 Sep 2017 10:03:05 +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 BF7526E8CC for ; Thu, 7 Sep 2017 10:03:00 +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:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,357,1500966000"; d="scan'208";a="126439700" Received: from sakamble-desktop.iind.intel.com ([10.223.26.118]) by orsmga004.jf.intel.com with ESMTP; 07 Sep 2017 03:02:59 -0700 From: Sagar Arun Kamble To: intel-gfx@lists.freedesktop.org Date: Thu, 7 Sep 2017 15:36:04 +0530 Message-Id: <1504778774-18117-5-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> Subject: [Intel-gfx] [PATCH 04/14] drm/i915: Define CTX_ID property for perf sampling 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 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. v2: Updated stream->last_ctx_id to INVALID_CTX_ID during stream_init. Testcase: igt/intel_perf_dapc/perf-ctxid Signed-off-by: Sagar Arun Kamble --- drivers/gpu/drm/i915/i915_drv.h | 5 ++++ drivers/gpu/drm/i915/i915_perf.c | 56 ++++++++++++++++++++++++++++++++++++++++ include/uapi/drm/i915_drm.h | 7 +++++ 3 files changed, 68 insertions(+) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index 3c1bc01..4b425f2 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -2245,6 +2245,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 { diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c index bce7388..8c6913a 100644 --- a/drivers/gpu/drm/i915/i915_perf.c +++ b/drivers/gpu/drm/i915/i915_perf.c @@ -293,6 +293,7 @@ /* Data common to periodic and RCS based OA samples */ struct i915_perf_sample_data { u64 source; + u64 ctx_id; const u8 *report; }; @@ -347,6 +348,7 @@ struct i915_perf_sample_data { #define SAMPLE_OA_REPORT (1<<0) #define SAMPLE_OA_SOURCE (1<<1) +#define SAMPLE_CTX_ID (1<<2) /** * struct perf_open_properties - for validated properties given to open a stream @@ -620,6 +622,7 @@ static void i915_perf_stream_patch_request(struct i915_perf_stream *stream, list_move_tail(&sample->link, &stream->cs_samples); sample->request = i915_gem_request_get(request); sample->id = sample_id; + sample->ctx_id = request->ctx->hw_id; if (stream->sample_flags & (SAMPLE_OA_REPORT | SAMPLE_OA_SOURCE)) i915_perf_stream_patch_sample_oa(stream, request, @@ -877,6 +880,12 @@ static int append_perf_sample(struct i915_perf_stream *stream, buf += 8; } + if (sample_flags & SAMPLE_CTX_ID) { + if (copy_to_user(buf, &data->ctx_id, 8)) + return -EFAULT; + buf += 8; + } + if (sample_flags & SAMPLE_OA_REPORT) { if (copy_to_user(buf, data->report, report_size)) return -EFAULT; @@ -903,12 +912,27 @@ static int append_oa_buffer_sample(struct i915_perf_stream *stream, char __user *buf, size_t count, size_t *offset, const u8 *report) { + struct drm_i915_private *dev_priv = stream->dev_priv; u32 sample_flags = stream->sample_flags; struct i915_perf_sample_data data = { 0 }; + u32 *report32 = (u32 *)report; if (sample_flags & SAMPLE_OA_SOURCE) data.source = I915_PERF_SAMPLE_OA_SOURCE_OABUFFER; + if (sample_flags & SAMPLE_CTX_ID) { + if (INTEL_INFO(dev_priv)->gen < 8) + data.ctx_id = 0; + else { + /* + * XXX: Just keep the lower 21 bits for now since I'm + * not entirely sure if the HW touches any of the higher + * bits in this field + */ + data.ctx_id = report32[2] & 0x1fffff; + } + } + if (sample_flags & SAMPLE_OA_REPORT) data.report = report; @@ -1487,6 +1511,9 @@ static int append_cs_buffer_sample(struct i915_perf_stream *stream, if (sample_flags & SAMPLE_OA_SOURCE) data.source = I915_PERF_SAMPLE_OA_SOURCE_CS; + if (sample_flags & SAMPLE_CTX_ID) + data.ctx_id = node->ctx_id; + return append_perf_sample(stream, buf, count, offset, &data); } @@ -2665,6 +2692,19 @@ static int i915_perf_stream_init(struct i915_perf_stream *stream, struct intel_engine_cs *engine = NULL; int ret; + if ((props->sample_flags & SAMPLE_CTX_ID) && !props->cs_mode) { + if (IS_HASWELL(dev_priv)) { + DRM_ERROR("On HSW, context ID sampling only supported " + "via command stream\n"); + return -EINVAL; + } else if (!i915.enable_execlists) { + DRM_ERROR("On Gen8+ without execlists, context ID " + "sampling only supported via " + "command stream\n"); + return -EINVAL; + } + } + /* We set up some ratelimit state to potentially throttle any _NOTES * about spurious, invalid OA reports which we don't forward to * userspace. @@ -2794,6 +2834,12 @@ 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; + stream->last_ctx_id = INVALID_CTX_ID; + } + if (props->cs_mode) { if (!cs_sample_data) { DRM_DEBUG_DRIVER( @@ -2803,6 +2849,13 @@ static int i915_perf_stream_init(struct i915_perf_stream *stream, goto err_enable; } + if (!(props->sample_flags & SAMPLE_CTX_ID)) { + DRM_ERROR("Stream engine given without requesting any " + "CS specific property\n"); + ret = -EINVAL; + goto err_enable; + } + idx = srcu_read_lock(&dev_priv->perf.oa.srcu); curr_stream = srcu_dereference( dev_priv->perf.oa.exclusive_stream, @@ -3520,6 +3573,9 @@ static int read_properties_unlocked(struct drm_i915_private *dev_priv, props->engine = engine; } break; + case DRM_I915_PERF_PROP_SAMPLE_CTX_ID: + props->sample_flags |= SAMPLE_CTX_ID; + 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 2e0b239..68baaf9 100644 --- a/include/uapi/drm/i915_drm.h +++ b/include/uapi/drm/i915_drm.h @@ -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 * }; */