diff mbox

[49/66] drm/i915: Create a per file_priv default context

Message ID 1372375867-1003-50-git-send-email-ben@bwidawsk.net (mailing list archive)
State New, archived
Headers show

Commit Message

Ben Widawsky June 27, 2013, 11:30 p.m. UTC
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 <ben@bwidawsk.net>

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 mbox

Patch

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;