All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: dri-devel@lists.freedesktop.org
Cc: Matthew Wilcox <willy@infradead.org>
Subject: [PATCH 23/34] drm/i915: Convert context_idr to XArray
Date: Thu, 21 Feb 2019 10:42:05 -0800	[thread overview]
Message-ID: <20190221184226.2149-46-willy@infradead.org> (raw)
In-Reply-To: <20190221184226.2149-1-willy@infradead.org>

Signed-off-by: Matthew Wilcox <willy@infradead.org>
---
 drivers/gpu/drm/i915/i915_debugfs.c     | 32 ++++++++++++-------------
 drivers/gpu/drm/i915/i915_drv.h         |  4 ++--
 drivers/gpu/drm/i915/i915_gem_context.c | 31 ++++++++++--------------
 3 files changed, 30 insertions(+), 37 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
index 030263870ba6..4981d1f6e7a5 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -376,9 +376,9 @@ static void print_batch_pool_stats(struct seq_file *m,
 	print_file_stats(m, "[k]batch pool", stats);
 }
 
-static int per_file_ctx_stats(int idx, void *ptr, void *data)
+static void per_file_ctx_stats(struct i915_gem_context *ctx,
+		struct file_stats *stats)
 {
-	struct i915_gem_context *ctx = ptr;
 	struct intel_engine_cs *engine;
 	enum intel_engine_id id;
 
@@ -386,12 +386,10 @@ static int per_file_ctx_stats(int idx, void *ptr, void *data)
 		struct intel_context *ce = to_intel_context(ctx, engine);
 
 		if (ce->state)
-			per_file_stats(ce->state->obj, data);
+			per_file_stats(ce->state->obj, stats);
 		if (ce->ring)
-			per_file_stats(ce->ring->vma->obj, data);
+			per_file_stats(ce->ring->vma->obj, stats);
 	}
-
-	return 0;
 }
 
 static void print_context_stats(struct seq_file *m,
@@ -405,11 +403,15 @@ static void print_context_stats(struct seq_file *m,
 
 	mutex_lock(&dev->struct_mutex);
 	if (dev_priv->kernel_context)
-		per_file_ctx_stats(0, dev_priv->kernel_context, &stats);
+		per_file_ctx_stats(dev_priv->kernel_context, &stats);
 
 	list_for_each_entry(file, &dev->filelist, lhead) {
 		struct drm_i915_file_private *fpriv = file->driver_priv;
-		idr_for_each(&fpriv->context_idr, per_file_ctx_stats, &stats);
+		struct i915_gem_context *ctx;
+		unsigned long index;
+
+		xa_for_each(&fpriv->contexts, index, ctx)
+			per_file_ctx_stats(ctx, &stats);
 	}
 	mutex_unlock(&dev->struct_mutex);
 
@@ -2078,16 +2080,14 @@ static int i915_swizzle_info(struct seq_file *m, void *data)
 	return 0;
 }
 
-static int per_file_ctx(int id, void *ptr, void *data)
+static void per_file_ctx(struct i915_gem_context *ctx, struct seq_file *m)
 {
-	struct i915_gem_context *ctx = ptr;
-	struct seq_file *m = data;
 	struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
 
 	if (!ppgtt) {
 		seq_printf(m, "  no ppgtt for context %d\n",
 			   ctx->user_handle);
-		return 0;
+		return;
 	}
 
 	if (i915_gem_context_is_default(ctx))
@@ -2095,8 +2095,6 @@ static int per_file_ctx(int id, void *ptr, void *data)
 	else
 		seq_printf(m, "  context %d:\n", ctx->user_handle);
 	ppgtt->debug_dump(ppgtt, m);
-
-	return 0;
 }
 
 static void gen8_ppgtt_info(struct seq_file *m,
@@ -2176,6 +2174,8 @@ static int i915_ppgtt_info(struct seq_file *m, void *data)
 	list_for_each_entry_reverse(file, &dev->filelist, lhead) {
 		struct drm_i915_file_private *file_priv = file->driver_priv;
 		struct task_struct *task;
+		struct i915_gem_context *ctx;
+		unsigned long index;
 
 		task = get_pid_task(file->pid, PIDTYPE_PID);
 		if (!task) {
@@ -2184,8 +2184,8 @@ static int i915_ppgtt_info(struct seq_file *m, void *data)
 		}
 		seq_printf(m, "\nproc: %s\n", task->comm);
 		put_task_struct(task);
-		idr_for_each(&file_priv->context_idr, per_file_ctx,
-			     (void *)(unsigned long)m);
+		xa_for_each(&file_priv->contexts, index, ctx)
+			per_file_ctx(ctx, m);
 	}
 
 out_rpm:
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 4b5ce517cbcf..1b7663258f42 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -213,7 +213,7 @@ struct drm_i915_file_private {
  */
 #define DRM_I915_THROTTLE_JIFFIES msecs_to_jiffies(20)
 	} mm;
-	struct idr context_idr;
+	struct xarray contexts;
 
 	struct intel_rps_client {
 		atomic_t boosts;
@@ -3118,7 +3118,7 @@ void i915_gem_object_save_bit_17_swizzle(struct drm_i915_gem_object *obj,
 static inline struct i915_gem_context *
 __i915_gem_context_lookup_rcu(struct drm_i915_file_private *file_priv, u32 id)
 {
-	return idr_find(&file_priv->context_idr, id);
+	return xa_load(&file_priv->contexts, id);
 }
 
 static inline struct i915_gem_context *
diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c
index 9db04b2e65cf..033a6fd72e40 100644
--- a/drivers/gpu/drm/i915/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/i915_gem_context.c
@@ -350,12 +350,12 @@ __create_hw_context(struct drm_i915_private *dev_priv,
 	/* Default context will never have a file_priv */
 	ret = DEFAULT_CONTEXT_HANDLE;
 	if (file_priv) {
-		ret = idr_alloc(&file_priv->context_idr, ctx,
-				DEFAULT_CONTEXT_HANDLE, 0, GFP_KERNEL);
+		ret = xa_alloc(&file_priv->contexts, &ctx->user_handle, ctx,
+				XA_LIMIT(DEFAULT_CONTEXT_HANDLE, UINT_MAX),
+				GFP_KERNEL);
 		if (ret < 0)
 			goto err_lut;
 	}
-	ctx->user_handle = ret;
 
 	ctx->file_priv = file_priv;
 	if (file_priv) {
@@ -384,7 +384,7 @@ __create_hw_context(struct drm_i915_private *dev_priv,
 
 err_pid:
 	put_pid(ctx->pid);
-	idr_remove(&file_priv->context_idr, ctx->user_handle);
+	xa_erase(&file_priv->contexts, ctx->user_handle);
 err_lut:
 	context_close(ctx);
 	return ERR_PTR(ret);
@@ -393,7 +393,7 @@ __create_hw_context(struct drm_i915_private *dev_priv,
 static void __destroy_hw_context(struct i915_gem_context *ctx,
 				 struct drm_i915_file_private *file_priv)
 {
-	idr_remove(&file_priv->context_idr, ctx->user_handle);
+	xa_erase(&file_priv->contexts, ctx->user_handle);
 	context_close(ctx);
 }
 
@@ -597,29 +597,19 @@ void i915_gem_contexts_fini(struct drm_i915_private *i915)
 	ida_destroy(&i915->contexts.hw_ida);
 }
 
-static int context_idr_cleanup(int id, void *p, void *data)
-{
-	struct i915_gem_context *ctx = p;
-
-	context_close(ctx);
-	return 0;
-}
-
 int i915_gem_context_open(struct drm_i915_private *i915,
 			  struct drm_file *file)
 {
 	struct drm_i915_file_private *file_priv = file->driver_priv;
 	struct i915_gem_context *ctx;
 
-	idr_init(&file_priv->context_idr);
+	xa_init_flags(&file_priv->contexts, XA_FLAGS_ALLOC);
 
 	mutex_lock(&i915->drm.struct_mutex);
 	ctx = i915_gem_create_context(i915, file_priv);
 	mutex_unlock(&i915->drm.struct_mutex);
-	if (IS_ERR(ctx)) {
-		idr_destroy(&file_priv->context_idr);
+	if (IS_ERR(ctx))
 		return PTR_ERR(ctx);
-	}
 
 	GEM_BUG_ON(i915_gem_context_is_kernel(ctx));
 
@@ -629,11 +619,14 @@ int i915_gem_context_open(struct drm_i915_private *i915,
 void i915_gem_context_close(struct drm_file *file)
 {
 	struct drm_i915_file_private *file_priv = file->driver_priv;
+	struct i915_gem_context *ctx;
+	unsigned long index;
 
 	lockdep_assert_held(&file_priv->dev_priv->drm.struct_mutex);
 
-	idr_for_each(&file_priv->context_idr, context_idr_cleanup, NULL);
-	idr_destroy(&file_priv->context_idr);
+	xa_for_each(&file_priv->contexts, index, ctx)
+		context_close(ctx);
+	xa_destroy(&file_priv->contexts);
 }
 
 static struct i915_request *
-- 
2.20.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  parent reply	other threads:[~2019-02-21 18:42 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-21 18:41 [PATCH 00/34] Convert DRM to XArray Matthew Wilcox
2019-02-21 18:41 ` [PATCH 01/34] drm: Convert drm_minors_idr " Matthew Wilcox
2019-02-22  9:11   ` Daniel Vetter
2019-02-22  9:55     ` Daniel Vetter
2019-02-22 15:13     ` Matthew Wilcox
2019-02-21 18:41 ` [PATCH 02/34] drm: Convert aux_idr " Matthew Wilcox
2019-02-25 17:57   ` Ville Syrjälä
2019-02-25 18:42     ` Matthew Wilcox
2019-02-25 18:50       ` Ville Syrjälä
2019-02-21 18:41 ` [PATCH 03/34] drm: Convert object_name_idr " Matthew Wilcox
2019-02-22  9:17   ` Daniel Vetter
2019-02-21 18:41 ` [PATCH 04/34] drm: Convert object_idr " Matthew Wilcox
2019-02-21 18:41 ` [PATCH 05/34] drm: Convert syncobj_idr " Matthew Wilcox
2019-02-21 18:41 ` [PATCH 06/34] drm: Convert magic_map " Matthew Wilcox
2019-02-21 18:41 ` [PATCH 07/34] drm: Convert lessee_idr " Matthew Wilcox
2019-02-21 18:41 ` [PATCH 08/34] drm: Remove linked lists for lessees Matthew Wilcox
2019-02-21 18:41 ` [PATCH 09/34] drm: Convert ctx_idr to XArray Matthew Wilcox
2019-02-21 18:41 ` [PATCH 10/34] drm: Convert tile_idr " Matthew Wilcox
2019-02-21 18:41 ` [PATCH 11/34] drm: Convert crtc_idr " Matthew Wilcox
2019-02-22  9:40   ` Daniel Vetter
2019-02-22 15:32     ` Matthew Wilcox
2019-02-22 17:12       ` Daniel Vetter
2019-02-21 18:41 ` [PATCH 12/34] drm/agp: Convert bo_list_handles " Matthew Wilcox
2019-02-25 16:06   ` Christian König
2019-02-25 16:39     ` Matthew Wilcox
2019-02-21 18:41 ` [PATCH 13/34] drm/amdgpu: Convert ctx_handles " Matthew Wilcox
2019-02-25 16:07   ` Christian König
2019-02-25 16:39     ` Matthew Wilcox
2019-02-25 16:59       ` Koenig, Christian
2019-02-25 18:47         ` Matthew Wilcox
2019-02-21 18:41 ` [PATCH 14/34] drm/amdgpu: Convert pasid_idr " Matthew Wilcox
2019-02-21 18:41 ` [PATCH 15/34] drm/amdkfd: Convert event_idr " Matthew Wilcox
2019-02-21 18:41 ` [PATCH 16/34] drm/amdkfd: Convert alloc_idr " Matthew Wilcox
2019-02-21 18:41 ` [PATCH 17/34] drm/etnaviv: Convert fence_idr " Matthew Wilcox
2019-02-21 18:41 ` [PATCH 18/34] drm/i915: Convert handles_vma " Matthew Wilcox
2019-02-21 18:41 ` [PATCH 19/34] drm/i915: Convert spt_tree " Matthew Wilcox
2019-02-21 18:41 ` [PATCH 20/34] drm/i915: Convert page_track_tree " Matthew Wilcox
2019-02-21 18:42 ` [PATCH 21/34] drm/i915: Convert get_page " Matthew Wilcox
2019-02-21 18:42 ` [PATCH 22/34] drm/i915: Convert object_idr to IDA Matthew Wilcox
2019-02-21 18:42 ` Matthew Wilcox [this message]
2019-02-21 18:42 ` [PATCH 24/34] drm/i915: Convert metrics_idr to XArray Matthew Wilcox
2019-02-21 18:42 ` [PATCH 25/34] drm/i915: Convert vgpus_idr " Matthew Wilcox
2019-02-21 18:42 ` [PATCH 26/34] drm/qxl: Convert release_idr " Matthew Wilcox
2019-02-21 18:42 ` [PATCH 27/34] drm/qxl: Convert surf_id_idr " Matthew Wilcox
2019-02-21 18:42 ` [PATCH 28/34] drm/tegra: Convert contexts IDR " Matthew Wilcox
2019-02-21 18:42 ` [PATCH 29/34] drm/vc4: Convert perfmon " Matthew Wilcox
2019-02-21 18:42 ` [PATCH 30/34] drm/sis: Convert object_idr " Matthew Wilcox
2019-02-21 18:42 ` [PATCH 31/34] drm/vgem: Convert fence_idr " Matthew Wilcox
2019-02-21 18:42 ` [PATCH 32/34] drm/via: Convert object_idr " Matthew Wilcox
2019-02-21 18:42 ` [PATCH 33/34] drm/vmwgfx: Convert base IDR " Matthew Wilcox
2019-02-21 18:42 ` [PATCH 34/34] drm/vmwgfx: Convert res_idr " Matthew Wilcox
2019-02-22  9:54 ` [PATCH 00/34] Convert DRM " Daniel Vetter
2019-02-24  4:21   ` Matthew Wilcox

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190221184226.2149-46-willy@infradead.org \
    --to=willy@infradead.org \
    --cc=dri-devel@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.