From patchwork Fri Apr 22 11:33:57 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: 8911101 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A8C769F1D3 for ; Fri, 22 Apr 2016 11:33:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id ACB7C20212 for ; Fri, 22 Apr 2016 11:33:47 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id C10DD2020F for ; Fri, 22 Apr 2016 11:33:41 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 33E0B6EEA3; Fri, 22 Apr 2016 11:33:34 +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 B24096EE9E for ; Fri, 22 Apr 2016 11:32:42 +0000 (UTC) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP; 22 Apr 2016 04:32:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,517,1455004800"; d="scan'208";a="690445867" Received: from sourab-desktop.iind.intel.com ([10.223.82.63]) by FMSMGA003.fm.intel.com with ESMTP; 22 Apr 2016 04:32:40 -0700 From: sourab.gupta@intel.com To: intel-gfx@lists.freedesktop.org Date: Fri, 22 Apr 2016 17:03:57 +0530 Message-Id: <1461324845-25755-9-git-send-email-sourab.gupta@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1461324845-25755-1-git-send-email-sourab.gupta@intel.com> References: <1461324845-25755-1-git-send-email-sourab.gupta@intel.com> Cc: Daniel Vetter , Sourab Gupta , Deepak S Subject: [Intel-gfx] [PATCH 08/16] drm/i915: Handle the overflow condition for command stream buf 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-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Sourab Gupta Add a compile time option for detecting the overflow condition of command stream buffer, and not overwriting the old entries in such a case. Also, set a status flag to forward the overflow condition to userspace if overflow is detected. Signed-off-by: Sourab Gupta --- drivers/gpu/drm/i915/i915_drv.h | 2 ++ drivers/gpu/drm/i915/i915_perf.c | 76 +++++++++++++++++++++++++++++++--------- 2 files changed, 62 insertions(+), 16 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index bc4fc1b..6bea3bb 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -2170,6 +2170,8 @@ struct drm_i915_private { struct drm_i915_gem_object *obj; struct i915_vma *vma; u8 *addr; +#define I915_PERF_CMD_STREAM_BUF_STATUS_OVERFLOW (1<<0) + u32 status; } command_stream_buf; struct list_head node_list; diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c index 222de00..147f377 100644 --- a/drivers/gpu/drm/i915/i915_perf.c +++ b/drivers/gpu/drm/i915/i915_perf.c @@ -80,6 +80,9 @@ static u32 i915_perf_stream_paranoid = true; #define GEN8_OAREPORT_REASON_GO_TRANSITION (1<<23) #define GEN9_OAREPORT_REASON_CLK_RATIO (1<<24) +/* For determining the behavior on overflow of command stream samples */ +#define CMD_STREAM_BUF_OVERFLOW_ALLOWED + /* Data common to periodic and RCS based samples */ struct oa_sample_data { u32 source; @@ -170,6 +173,7 @@ void i915_perf_command_stream_hook(struct drm_i915_gem_request *req) mutex_unlock(&dev_priv->perf.streams_lock); } +#ifdef CMD_STREAM_BUF_OVERFLOW_ALLOWED /* * Release some perf entries to make space for a new entry data. We dereference * the associated request before deleting the entry. Also, no need to check for @@ -196,25 +200,26 @@ static void release_some_perf_entries(struct drm_i915_private *dev_priv, break; } } +#endif /* - * Insert the perf entry to the end of the list. This function never fails, - * since it always manages to insert the entry. If the space is exhausted in - * the buffer, it will remove the oldest entries in order to make space. + * Insert the perf entry to the end of the list. If the overwrite of old entries + * is allowed, the function always manages to insert the entry and returns 0. + * If overwrite is not allowed, on detection of overflow condition, an + * appropriate status flag is set, and function returns -ENOSPC. */ -static void insert_perf_entry(struct drm_i915_private *dev_priv, +static int insert_perf_entry(struct drm_i915_private *dev_priv, struct i915_perf_cs_data_node *entry) { struct i915_perf_cs_data_node *first_entry, *last_entry; int max_offset = dev_priv->perf.command_stream_buf.obj->base.size; u32 entry_size = dev_priv->perf.oa.oa_buffer.format_size; + int ret = 0; spin_lock(&dev_priv->perf.node_list_lock); if (list_empty(&dev_priv->perf.node_list)) { entry->offset = 0; - list_add_tail(&entry->link, &dev_priv->perf.node_list); - spin_unlock(&dev_priv->perf.node_list_lock); - return; + goto out; } first_entry = list_first_entry(&dev_priv->perf.node_list, @@ -232,29 +237,49 @@ static void insert_perf_entry(struct drm_i915_private *dev_priv, */ else if (entry_size < first_entry->offset) entry->offset = 0; - /* Insufficient space. Overwrite existing old entries */ + /* Insufficient space */ else { +#ifdef CMD_STREAM_BUF_OVERFLOW_ALLOWED u32 target_size = entry_size - first_entry->offset; release_some_perf_entries(dev_priv, target_size); entry->offset = 0; +#else + dev_priv->perf.command_stream_buf.status |= + I915_PERF_CMD_STREAM_BUF_STATUS_OVERFLOW; + ret = -ENOSPC; + goto out_unlock; +#endif } } else { /* Sufficient space available? */ if (last_entry->offset + 2*entry_size < first_entry->offset) entry->offset = last_entry->offset + entry_size; - /* Insufficient space. Overwrite existing old entries */ + /* Insufficient space */ else { +#ifdef CMD_STREAM_BUF_OVERFLOW_ALLOWED u32 target_size = entry_size - (first_entry->offset - last_entry->offset - entry_size); release_some_perf_entries(dev_priv, target_size); entry->offset = last_entry->offset + entry_size; +#else + dev_priv->perf.command_stream_buf.status |= + I915_PERF_CMD_STREAM_BUF_STATUS_OVERFLOW; + ret = -ENOSPC; + goto out_unlock; +#endif } } + +out: list_add_tail(&entry->link, &dev_priv->perf.node_list); +#ifndef CMD_STREAM_BUF_OVERFLOW_ALLOWED +out_unlock: +#endif spin_unlock(&dev_priv->perf.node_list_lock); + return ret; } static void i915_perf_command_stream_hook_oa(struct drm_i915_gem_request *req) @@ -276,21 +301,20 @@ static void i915_perf_command_stream_hook_oa(struct drm_i915_gem_request *req) return; } + ret = insert_perf_entry(dev_priv, entry); + if (ret) + goto out_free; + if (i915.enable_execlists) ret = intel_logical_ring_begin(req, 4); else ret = intel_ring_begin(req, 4); - - if (ret) { - kfree(entry); - return; - } + if (ret) + goto out; entry->ctx_id = ctx->global_id; i915_gem_request_assign(&entry->request, req); - insert_perf_entry(dev_priv, entry); - addr = dev_priv->perf.command_stream_buf.vma->node.start + entry->offset; @@ -321,6 +345,13 @@ static void i915_perf_command_stream_hook_oa(struct drm_i915_gem_request *req) intel_ring_advance(engine); } i915_vma_move_to_active(dev_priv->perf.command_stream_buf.vma, req); + return; +out: + spin_lock(&dev_priv->perf.node_list_lock); + list_del(&entry->link); + spin_unlock(&dev_priv->perf.node_list_lock); +out_free: + kfree(entry); } static int i915_oa_rcs_wait_gpu(struct drm_i915_private *dev_priv) @@ -991,7 +1022,20 @@ static int oa_rcs_append_reports(struct i915_perf_stream *stream, struct i915_perf_cs_data_node *entry, *next; LIST_HEAD(free_list); int ret = 0; +#ifndef CMD_STREAM_BUF_OVERFLOW_ALLOWED + u32 cs_buf_status = dev_priv->perf.command_stream_buf.status; + + if (unlikely(cs_buf_status & + I915_PERF_CMD_STREAM_BUF_STATUS_OVERFLOW)) { + ret = append_oa_status(stream, read_state, + DRM_I915_PERF_RECORD_OA_BUFFER_OVERFLOW); + if (ret) + return ret; + dev_priv->perf.command_stream_buf.status &= + ~I915_PERF_CMD_STREAM_BUF_STATUS_OVERFLOW; + } +#endif spin_lock(&dev_priv->perf.node_list_lock); if (list_empty(&dev_priv->perf.node_list)) { spin_unlock(&dev_priv->perf.node_list_lock);