From patchwork Thu Jun 27 23:30:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Widawsky X-Patchwork-Id: 2796501 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A0538BF4A1 for ; Thu, 27 Jun 2013 23:53:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8017C200EE for ; Thu, 27 Jun 2013 23:53:25 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 82B5D200ED for ; Thu, 27 Jun 2013 23:53:24 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 53C42E64A9 for ; Thu, 27 Jun 2013 16:53:24 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from shiva.localdomain (unknown [209.20.75.48]) by gabe.freedesktop.org (Postfix) with ESMTP id 63148E6469 for ; Thu, 27 Jun 2013 16:28:34 -0700 (PDT) Received: by shiva.localdomain (Postfix, from userid 99) id 66AF7886A3; Thu, 27 Jun 2013 23:28:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-5.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lundgren.jf.intel.com (jfdmzpr02-ext.jf.intel.com [134.134.137.71]) by shiva.localdomain (Postfix) with ESMTPSA id BC9B288081; Thu, 27 Jun 2013 23:28:33 +0000 (UTC) From: Ben Widawsky To: Intel GFX Date: Thu, 27 Jun 2013 16:30:50 -0700 Message-Id: <1372375867-1003-50-git-send-email-ben@bwidawsk.net> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1372375867-1003-1-git-send-email-ben@bwidawsk.net> References: <1372375867-1003-1-git-send-email-ben@bwidawsk.net> Cc: Ben Widawsky Subject: [Intel-gfx] [PATCH 49/66] drm/i915: Create a per file_priv default context X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org X-Virus-Scanned: ClamAV using ClamSMTP Every file will get it's own context, and we use this context instead of the default context. The default context still exists for future shrinker usage as well as reset handling. Since this now will cause open to fail if there is no space in the GGTT for the PPGTT PDEs, and the context object, try calling the shrinker once to see if it's not possible to carry on. v2: Updated to address Mika's recent context guilty changes Some more changes around this come up in later patches as well. Signed-off-by: Ben Widawsky Conflicts: drivers/gpu/drm/i915/i915_gem_context.c --- drivers/gpu/drm/i915/i915_drv.h | 2 +- drivers/gpu/drm/i915/i915_gem.c | 6 ++++-- drivers/gpu/drm/i915/i915_gem_context.c | 31 ++++++++++++++++++++----------- drivers/gpu/drm/i915/i915_gem_gtt.c | 13 +++++++++++++ 4 files changed, 38 insertions(+), 14 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index 5beba7a..4fbc4ab 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -1409,7 +1409,7 @@ struct drm_i915_file_private { } mm; struct idr context_idr; - struct i915_ctx_hang_stats hang_stats; + struct i915_hw_context *private_default_ctx; }; #define INTEL_INFO(dev) (((struct drm_i915_private *) (dev)->dev_private)->info) diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index d440dd5..c91abda 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -2209,9 +2209,10 @@ static bool i915_set_reset_status(struct intel_ring_buffer *ring, /* Innocent until proven guilty */ guilty = banned = false; - if (request->batch_obj) + if (request->batch_obj) { offset = i915_gem_obj_offset(request->batch_obj, request_to_vm(request)); + } if (ring->hangcheck.action != wait && i915_request_guilty(request, acthd, &inside)) { @@ -2231,7 +2232,7 @@ static bool i915_set_reset_status(struct intel_ring_buffer *ring, if (request->ctx && request->ctx->id != DEFAULT_CONTEXT_ID) hs = &request->ctx->hang_stats; else if (request->file_priv) - hs = &request->file_priv->hang_stats; + hs = &request->file_priv->private_default_ctx->hang_stats; if (hs) { if (guilty) { @@ -4859,6 +4860,7 @@ unsigned long i915_gem_obj_offset(struct drm_i915_gem_object *o, return vma->node.start; } + WARN_ON(1); return I915_INVALID_OFFSET; } diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c index e585e5a..0d6ed19 100644 --- a/drivers/gpu/drm/i915/i915_gem_context.c +++ b/drivers/gpu/drm/i915/i915_gem_context.c @@ -197,7 +197,8 @@ err_out: static inline bool is_default_context(struct i915_hw_context *ctx) { - return (ctx == ctx->ring->default_context); + /* Cheap trick to determine default contexts */ + return ctx->file_priv ? false : true; } /** @@ -422,7 +423,7 @@ i915_gem_context_get_hang_stats(struct intel_ring_buffer *ring, return ERR_PTR(-EINVAL); if (id == DEFAULT_CONTEXT_ID) - return &file_priv->hang_stats; + return &file_priv->private_default_ctx->hang_stats; to = i915_gem_context_get(file->driver_priv, id); if (to == NULL) @@ -442,9 +443,13 @@ int i915_gem_context_open(struct drm_device *dev, struct drm_file *file) return 0; } + idr_init(&file_priv->context_idr); + file_priv->private_default_ctx = create_hw_context(dev, NULL); + mutex_unlock(&dev->struct_mutex); - idr_init(&file_priv->context_idr); + if (IS_ERR(file_priv->private_default_ctx)) + return PTR_ERR(file_priv->private_default_ctx); return 0; } @@ -460,12 +465,16 @@ void i915_gem_context_close(struct drm_device *dev, struct drm_file *file) mutex_lock(&dev->struct_mutex); idr_for_each(&file_priv->context_idr, context_idr_cleanup, NULL); idr_destroy(&file_priv->context_idr); + i915_gem_context_unreference(file_priv->private_default_ctx); mutex_unlock(&dev->struct_mutex); } static struct i915_hw_context * i915_gem_context_get(struct drm_i915_file_private *file_priv, u32 id) { + + if (id == DEFAULT_CONTEXT_ID) + return file_priv->private_default_ctx; return (struct i915_hw_context *)idr_find(&file_priv->context_idr, id); } @@ -640,16 +649,13 @@ int i915_switch_context(struct intel_ring_buffer *ring, WARN_ON(!mutex_is_locked(&dev_priv->dev->struct_mutex)); - if (to_id == DEFAULT_CONTEXT_ID) { + if (file == NULL) to = ring->default_context; - } else { - if (file == NULL) - return -EINVAL; - + else to = i915_gem_context_get(file->driver_priv, to_id); - if (to == NULL) - return -ENOENT; - } + + if (to == NULL) + return -ENOENT; return do_switch(ring, to); } @@ -695,6 +701,9 @@ int i915_gem_context_destroy_ioctl(struct drm_device *dev, void *data, if (!(dev->driver->driver_features & DRIVER_GEM)) return -ENODEV; + if (args->ctx_id == DEFAULT_CONTEXT_ID) + return -EPERM; + ret = i915_mutex_lock_interruptible(dev); if (ret) return ret; diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c index 8b59729..c3294c3 100644 --- a/drivers/gpu/drm/i915/i915_gem_gtt.c +++ b/drivers/gpu/drm/i915/i915_gem_gtt.c @@ -271,6 +271,7 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt) struct drm_device *dev = vm->dev; struct drm_i915_private *dev_priv = dev->dev_private; int i; + bool retried = false; int ret = -ENOMEM; /* PPGTT PDEs reside in the GGTT stolen space, and consists of 512 @@ -279,12 +280,24 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt) * fragmentation. */ BUG_ON(!drm_mm_initialized(&dev_priv->gtt.base.mm)); +alloc: ret = drm_mm_insert_node_in_range_generic(&dev_priv->gtt.base.mm, &ppgtt->node, GEN6_PD_SIZE, GEN6_PD_ALIGN, 0, dev_priv->gtt.mappable_end, dev_priv->gtt.base.total, DRM_MM_TOPDOWN); + if (ret == -ENOSPC && !retried) { + ret = i915_gem_evict_something(dev, &dev_priv->gtt.base, + GEN6_PD_SIZE, GEN6_PD_ALIGN, + I915_CACHE_NONE, false, true); + if (ret) + return ret; + + retried = true; + goto alloc; + } + if (ret) return ret;