From patchwork Thu Mar 16 06:14:15 2017 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: 9627249 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 4CD6760522 for ; Thu, 16 Mar 2017 06:12:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3D3AD2843D for ; Thu, 16 Mar 2017 06:12:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 31F8728639; Thu, 16 Mar 2017 06:12:49 +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.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID 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 775402843D for ; Thu, 16 Mar 2017 06:12:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1424B6EA01; Thu, 16 Mar 2017 06:12:48 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id 062776EA01 for ; Thu, 16 Mar 2017 06:12:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1489644767; x=1521180767; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=KLnknAiaCqRBievbkjXiu18htzocS89aqB80gEyi++U=; b=he9E/aAb1nXsXKXlk+6U3Uo5mCFGaXtibSdYGgVPHLYG//P+47tQwUOU 0DRc3Z6sVKfG6g92szYIAHK7fmWUYA==; Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Mar 2017 23:12:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,170,1486454400"; d="scan'208";a="944882034" Received: from sourab-desktop.iind.intel.com ([10.223.82.140]) by orsmga003.jf.intel.com with ESMTP; 15 Mar 2017 23:12:44 -0700 From: sourab.gupta@intel.com To: intel-gfx@lists.freedesktop.org Date: Thu, 16 Mar 2017 11:44:15 +0530 Message-Id: <1489644855-25562-9-git-send-email-sourab.gupta@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1489644855-25562-1-git-send-email-sourab.gupta@intel.com> References: <1489644855-25562-1-git-send-email-sourab.gupta@intel.com> Cc: Daniel Vetter , Sourab Gupta , Matthew Auld Subject: [Intel-gfx] [PATCH 8/8] drm/i915: Add support for emitting execbuffer tags through OA counter reports 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 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. Signed-off-by: Sourab Gupta --- drivers/gpu/drm/i915/i915_drv.h | 17 +++++++++++-- drivers/gpu/drm/i915/i915_gem_execbuffer.c | 6 +++-- drivers/gpu/drm/i915/i915_perf.c | 40 +++++++++++++++++++++++++----- include/uapi/drm/i915_drm.h | 12 +++++++++ 4 files changed, 65 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index fa1d3fc..414afa5 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -1982,7 +1982,8 @@ struct i915_perf_stream_ops { * the batch buffer. */ void (*command_stream_hook)(struct i915_perf_stream *stream, - struct drm_i915_gem_request *request); + struct drm_i915_gem_request *request, + u32 tag); }; enum i915_perf_stream_state { @@ -2171,6 +2172,17 @@ struct i915_perf_cs_sample { * submitted, pertaining to this perf sample */ u32 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 { @@ -2627,6 +2639,7 @@ struct drm_i915_private { u32 last_cmd_stream_ctx_id; u32 last_pid; + u32 last_tag; struct list_head cs_samples; spinlock_t sample_lock; } perf; @@ -3690,7 +3703,7 @@ void i915_oa_init_reg_state(struct intel_engine_cs *engine, void i915_oa_update_reg_state(struct intel_engine_cs *engine, struct i915_gem_context *ctx, uint32_t *reg_state); -void i915_perf_command_stream_hook(struct drm_i915_gem_request *req); +void i915_perf_command_stream_hook(struct drm_i915_gem_request *req, u32 tag); /* i915_gem_evict.c */ int __must_check i915_gem_evict_something(struct i915_address_space *vm, diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c index 7af32c97..b42d47e 100644 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c @@ -59,6 +59,7 @@ struct i915_execbuffer_params { struct intel_engine_cs *engine; struct i915_gem_context *ctx; struct drm_i915_gem_request *request; + uint32_t tag; }; struct eb_vmas { @@ -1441,7 +1442,7 @@ static void eb_export_fence(struct drm_i915_gem_object *obj, if (exec_len == 0) exec_len = params->batch->size - params->args_batch_start_offset; - i915_perf_command_stream_hook(params->request); + i915_perf_command_stream_hook(params->request, params->tag); ret = params->engine->emit_bb_start(params->request, exec_start, exec_len, @@ -1449,7 +1450,7 @@ static void eb_export_fence(struct drm_i915_gem_object *obj, if (ret) return ret; - i915_perf_command_stream_hook(params->request); + i915_perf_command_stream_hook(params->request, params->tag); i915_gem_execbuffer_move_to_active(vmas, params->request); @@ -1791,6 +1792,7 @@ static void eb_export_fence(struct drm_i915_gem_object *obj, params->engine = engine; params->dispatch_flags = dispatch_flags; params->ctx = ctx; + params->tag = i915_execbuffer2_get_tag(*args); trace_i915_gem_request_queue(params->request, dispatch_flags); diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c index 6e8af2d..759865e 100644 --- a/drivers/gpu/drm/i915/i915_perf.c +++ b/drivers/gpu/drm/i915/i915_perf.c @@ -290,6 +290,7 @@ struct oa_sample_data { u32 source; u32 ctx_id; u32 pid; + u32 tag; const u8 *report; }; @@ -344,6 +345,7 @@ struct oa_sample_data { #define SAMPLE_OA_SOURCE_INFO (1<<1) #define SAMPLE_CTX_ID (1<<2) #define SAMPLE_PID (1<<3) +#define SAMPLE_TAG (1<<4) /** * struct perf_open_properties - for validated properties given to open a stream @@ -387,7 +389,8 @@ struct perf_open_properties { * The function provides a hook through which the commands to capture perf * metrics, are inserted into the command stream of a GPU engine. */ -void i915_perf_command_stream_hook(struct drm_i915_gem_request *request) +void i915_perf_command_stream_hook(struct drm_i915_gem_request *request, + u32 tag) { struct intel_engine_cs *engine = request->engine; struct drm_i915_private *dev_priv = engine->i915; @@ -400,7 +403,7 @@ void i915_perf_command_stream_hook(struct drm_i915_gem_request *request) list_for_each_entry(stream, &dev_priv->perf.streams, link) { if ((stream->state == I915_PERF_STREAM_ENABLED) && stream->cs_mode) - stream->ops->command_stream_hook(stream, request); + stream->ops->command_stream_hook(stream, request, tag); } mutex_unlock(&dev_priv->perf.streams_lock); } @@ -510,10 +513,11 @@ static void insert_perf_sample(struct drm_i915_private *dev_priv, * metrics into the render command stream * @stream: An i915-perf stream opened for OA metrics * @request: request in whose context the metrics are being collected. - * + * @tag: userspace provided tag to be associated with the perf sample */ static void i915_perf_command_stream_hook_oa(struct i915_perf_stream *stream, - struct drm_i915_gem_request *request) + struct drm_i915_gem_request *request, + u32 tag) { struct drm_i915_private *dev_priv = request->i915; struct i915_gem_context *ctx = request->ctx; @@ -535,6 +539,7 @@ static void i915_perf_command_stream_hook_oa(struct i915_perf_stream *stream, sample->ctx_id = ctx->hw_id; sample->pid = current->pid; + sample->tag = tag; i915_gem_request_assign(&sample->request, request); insert_perf_sample(dev_priv, sample); @@ -986,6 +991,12 @@ static int append_oa_sample(struct i915_perf_stream *stream, buf += 4; } + if (sample_flags & SAMPLE_TAG) { + if (copy_to_user(buf, &data->tag, 4)) + return -EFAULT; + buf += 4; + } + if (sample_flags & SAMPLE_OA_REPORT) { if (copy_to_user(buf, data->report, report_size)) return -EFAULT; @@ -1025,6 +1036,9 @@ static int append_oa_buffer_sample(struct i915_perf_stream *stream, if (sample_flags & SAMPLE_PID) data.pid = dev_priv->perf.last_pid; + if (sample_flags & SAMPLE_TAG) + data.tag = dev_priv->perf.last_tag; + if (sample_flags & SAMPLE_OA_REPORT) data.report = report; @@ -1606,6 +1620,11 @@ static int append_oa_rcs_sample(struct i915_perf_stream *stream, dev_priv->perf.last_pid = node->pid; } + if (sample_flags & SAMPLE_TAG) { + data.tag = node->tag; + dev_priv->perf.last_tag = node->tag; + } + if (sample_flags & SAMPLE_OA_REPORT) data.report = report; @@ -2682,7 +2701,8 @@ 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 require_cs_mode = props->sample_flags & (SAMPLE_PID | + SAMPLE_TAG); bool cs_sample_data = props->sample_flags & SAMPLE_OA_REPORT; int ret; @@ -2819,7 +2839,7 @@ static int i915_oa_stream_init(struct i915_perf_stream *stream, } if (require_cs_mode && !props->cs_mode) { - DRM_ERROR("PID sampling requires a ring to be specified"); + DRM_ERROR("PID/TAG sampling requires a ring to be specified"); ret = -EINVAL; goto err_enable; } @@ -2851,6 +2871,11 @@ static int i915_oa_stream_init(struct i915_perf_stream *stream, stream->sample_size += 4; } + if (props->sample_flags & SAMPLE_TAG) { + stream->sample_flags |= SAMPLE_TAG; + stream->sample_size += 4; + } + ret = alloc_command_stream_buf(dev_priv); if (ret) goto err_enable; @@ -3648,6 +3673,9 @@ static int read_properties_unlocked(struct drm_i915_private *dev_priv, case DRM_I915_PERF_PROP_SAMPLE_PID: props->sample_flags |= SAMPLE_PID; break; + case DRM_I915_PERF_PROP_SAMPLE_TAG: + props->sample_flags |= SAMPLE_TAG; + break; default: MISSING_CASE(id); DRM_DEBUG("Unknown i915 perf property ID\n"); diff --git a/include/uapi/drm/i915_drm.h b/include/uapi/drm/i915_drm.h index 25cf612..ab5fdc0 100644 --- a/include/uapi/drm/i915_drm.h +++ b/include/uapi/drm/i915_drm.h @@ -899,6 +899,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) + struct drm_i915_gem_pin { /** Handle of the buffer to be pinned. */ __u32 handle; @@ -1379,6 +1384,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 */ }; @@ -1447,6 +1458,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 tag; } && DRM_I915_PERF_PROP_SAMPLE_TAG * { u32 oa_report[]; } && DRM_I915_PERF_PROP_SAMPLE_OA * }; */