From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: Intel-gfx@lists.freedesktop.org
Cc: Chris Wilson <chris@chris-wilson.co.uk>, dri-devel@lists.freedesktop.org
Subject: [Intel-gfx] [PATCH 3/8] drm/i915: Make GEM contexts track DRM clients
Date: Mon, 12 Jul 2021 13:17:14 +0100 [thread overview]
Message-ID: <20210712121719.891536-4-tvrtko.ursulin@linux.intel.com> (raw)
In-Reply-To: <20210712121719.891536-1-tvrtko.ursulin@linux.intel.com>
From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
If we make GEM contexts keep a reference to i915_drm_client for the whole
of their lifetime, we can consolidate the current task pid and name usage
by getting it from the client.
v2: Don't bother supporting selftests contexts from debugfs. (Chris)
v3 (Lucas): Finish constructing ctx before adding it to the list
v4 (Ram): Rebase.
v5: Trivial rebase for proto ctx changes.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Aravind Iddamsetty <aravind.iddamsetty@intel.com>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
drivers/gpu/drm/i915/gem/i915_gem_context.c | 13 +++++++----
.../gpu/drm/i915/gem/i915_gem_context_types.h | 13 +++--------
drivers/gpu/drm/i915/i915_gpu_error.c | 22 +++++++++++--------
3 files changed, 25 insertions(+), 23 deletions(-)
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c
index ae9d4e087a92..5a38cb163f04 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c
@@ -989,10 +989,11 @@ void i915_gem_context_release(struct kref *ref)
trace_i915_context_free(ctx);
GEM_BUG_ON(!i915_gem_context_is_closed(ctx));
+ if (ctx->client)
+ i915_drm_client_put(ctx->client);
+
mutex_destroy(&ctx->engines_mutex);
mutex_destroy(&ctx->lut_mutex);
-
- put_pid(ctx->pid);
mutex_destroy(&ctx->mutex);
kfree_rcu(ctx, rcu);
@@ -1436,9 +1437,13 @@ static void gem_context_register(struct i915_gem_context *ctx,
ctx->file_priv = fpriv;
- ctx->pid = get_task_pid(current, PIDTYPE_PID);
+ ctx->client = i915_drm_client_get(fpriv->client);
+
+ rcu_read_lock();
snprintf(ctx->name, sizeof(ctx->name), "%s[%d]",
- current->comm, pid_nr(ctx->pid));
+ i915_drm_client_name(ctx->client),
+ pid_nr(i915_drm_client_pid(ctx->client)));
+ rcu_read_unlock();
/* And finally expose ourselves to userspace via the idr */
old = xa_store(&fpriv->context_xa, id, ctx, GFP_KERNEL);
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context_types.h b/drivers/gpu/drm/i915/gem/i915_gem_context_types.h
index 94c03a97cb77..d28678385d16 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_context_types.h
+++ b/drivers/gpu/drm/i915/gem/i915_gem_context_types.h
@@ -264,19 +264,12 @@ struct i915_gem_context {
*/
struct i915_address_space __rcu *vm;
- /**
- * @pid: process id of creator
- *
- * Note that who created the context may not be the principle user,
- * as the context may be shared across a local socket. However,
- * that should only affect the default context, all contexts created
- * explicitly by the client are expected to be isolated.
- */
- struct pid *pid;
-
/** @link: place with &drm_i915_private.context_list */
struct list_head link;
+ /** @client: struct i915_drm_client */
+ struct i915_drm_client *client;
+
/**
* @ref: reference count
*
diff --git a/drivers/gpu/drm/i915/i915_gpu_error.c b/drivers/gpu/drm/i915/i915_gpu_error.c
index a2c58b54a592..b1f17477d0cb 100644
--- a/drivers/gpu/drm/i915/i915_gpu_error.c
+++ b/drivers/gpu/drm/i915/i915_gpu_error.c
@@ -1235,7 +1235,9 @@ static void record_request(const struct i915_request *request,
ctx = rcu_dereference(request->context->gem_context);
if (ctx)
- erq->pid = pid_nr(ctx->pid);
+ erq->pid = I915_SELFTEST_ONLY(!ctx->client) ?
+ 0 :
+ pid_nr(i915_drm_client_pid(ctx->client));
}
rcu_read_unlock();
}
@@ -1256,23 +1258,25 @@ static bool record_context(struct i915_gem_context_coredump *e,
const struct i915_request *rq)
{
struct i915_gem_context *ctx;
- struct task_struct *task;
bool simulated;
rcu_read_lock();
+
ctx = rcu_dereference(rq->context->gem_context);
if (ctx && !kref_get_unless_zero(&ctx->ref))
ctx = NULL;
- rcu_read_unlock();
- if (!ctx)
+ if (!ctx) {
+ rcu_read_unlock();
return true;
+ }
- rcu_read_lock();
- task = pid_task(ctx->pid, PIDTYPE_PID);
- if (task) {
- strcpy(e->comm, task->comm);
- e->pid = task->pid;
+ if (I915_SELFTEST_ONLY(!ctx->client)) {
+ strcpy(e->comm, "[kernel]");
+ } else {
+ strcpy(e->comm, i915_drm_client_name(ctx->client));
+ e->pid = pid_nr(i915_drm_client_pid(ctx->client));
}
+
rcu_read_unlock();
e->sched_attr = ctx->sched;
--
2.30.2
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
next prev parent reply other threads:[~2021-07-12 12:17 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-12 12:17 [Intel-gfx] [PATCH 0/8] Per client engine busyness Tvrtko Ursulin
2021-07-12 12:17 ` [Intel-gfx] [PATCH 1/8] drm/i915: Explicitly track DRM clients Tvrtko Ursulin
2021-07-12 14:42 ` Daniel Vetter
2021-07-12 15:51 ` Tvrtko Ursulin
2021-07-12 16:12 ` Daniel Vetter
2021-07-13 8:50 ` Tvrtko Ursulin
2021-07-12 12:17 ` [Intel-gfx] [PATCH 2/8] drm/i915: Update client name on context create Tvrtko Ursulin
2021-07-12 12:17 ` Tvrtko Ursulin [this message]
2021-07-12 12:17 ` [Intel-gfx] [PATCH 4/8] drm/i915: Track runtime spent in closed and unreachable GEM contexts Tvrtko Ursulin
2021-07-12 12:17 ` [Intel-gfx] [PATCH 5/8] drm/i915: Track all user contexts per client Tvrtko Ursulin
2021-07-12 12:17 ` [Intel-gfx] [PATCH 6/8] drm/i915: Track context current active time Tvrtko Ursulin
2021-07-12 12:17 ` [Intel-gfx] [RFC 7/8] drm/i915: Expose client engine utilisation via fdinfo Tvrtko Ursulin
2021-07-12 12:17 ` [Intel-gfx] [RFC 8/8] drm: Document fdinfo format specification Tvrtko Ursulin
2021-07-12 12:35 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for Per client engine busyness Patchwork
2021-07-12 12:37 ` [Intel-gfx] ✗ Fi.CI.SPARSE: " Patchwork
2021-07-12 12:40 ` [Intel-gfx] ✗ Fi.CI.DOCS: " Patchwork
2021-07-12 13:01 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2021-07-12 16:00 ` [Intel-gfx] ✗ Fi.CI.IGT: failure " Patchwork
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=20210712121719.891536-4-tvrtko.ursulin@linux.intel.com \
--to=tvrtko.ursulin@linux.intel.com \
--cc=Intel-gfx@lists.freedesktop.org \
--cc=chris@chris-wilson.co.uk \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox