Skip to content

Commit c84455b

Browse files
committed
drm/i915: Move debug only per-request pid tracking from request to ctx
Since contexts are not currently shared between userspace processes, we have an exact correspondence between context creator and guilty batch submitter. Therefore we can save some per-batch work by inspecting the context->pid upon error instead. Note that we take the context's creator's pid rather than the file's pid in order to better track fd passed over sockets. Signed-off-by: Chris Wilson <[email protected]> Reviewed-by: Joonas Lahtinen <[email protected]> Link: http://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent bde13eb commit c84455b

File tree

6 files changed

+32
-21
lines changed

6 files changed

+32
-21
lines changed

drivers/gpu/drm/i915/i915_debugfs.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,8 @@ static int i915_gem_object_info(struct seq_file *m, void* data)
460460
print_context_stats(m, dev_priv);
461461
list_for_each_entry_reverse(file, &dev->filelist, lhead) {
462462
struct file_stats stats;
463+
struct drm_i915_file_private *file_priv = file->driver_priv;
464+
struct drm_i915_gem_request *request;
463465
struct task_struct *task;
464466

465467
memset(&stats, 0, sizeof(stats));
@@ -473,10 +475,17 @@ static int i915_gem_object_info(struct seq_file *m, void* data)
473475
* still alive (e.g. get_pid(current) => fork() => exit()).
474476
* Therefore, we need to protect this ->comm access using RCU.
475477
*/
478+
mutex_lock(&dev->struct_mutex);
479+
request = list_first_entry_or_null(&file_priv->mm.request_list,
480+
struct drm_i915_gem_request,
481+
client_list);
476482
rcu_read_lock();
477-
task = pid_task(file->pid, PIDTYPE_PID);
483+
task = pid_task(request && request->ctx->pid ?
484+
request->ctx->pid : file->pid,
485+
PIDTYPE_PID);
478486
print_file_stats(m, task ? task->comm : "<unknown>", stats);
479487
rcu_read_unlock();
488+
mutex_unlock(&dev->struct_mutex);
480489
}
481490
mutex_unlock(&dev->filelist_mutex);
482491

@@ -658,12 +667,11 @@ static int i915_gem_request_info(struct seq_file *m, void *data)
658667

659668
seq_printf(m, "%s requests: %d\n", engine->name, count);
660669
list_for_each_entry(req, &engine->request_list, link) {
670+
struct pid *pid = req->ctx->pid;
661671
struct task_struct *task;
662672

663673
rcu_read_lock();
664-
task = NULL;
665-
if (req->pid)
666-
task = pid_task(req->pid, PIDTYPE_PID);
674+
task = pid ? pid_task(pid, PIDTYPE_PID) : NULL;
667675
seq_printf(m, " %x @ %d: %s [%d]\n",
668676
req->fence.seqno,
669677
(int) (jiffies - req->emitted_jiffies),
@@ -1952,18 +1960,17 @@ static int i915_context_status(struct seq_file *m, void *unused)
19521960

19531961
list_for_each_entry(ctx, &dev_priv->context_list, link) {
19541962
seq_printf(m, "HW context %u ", ctx->hw_id);
1955-
if (IS_ERR(ctx->file_priv)) {
1956-
seq_puts(m, "(deleted) ");
1957-
} else if (ctx->file_priv) {
1958-
struct pid *pid = ctx->file_priv->file->pid;
1963+
if (ctx->pid) {
19591964
struct task_struct *task;
19601965

1961-
task = get_pid_task(pid, PIDTYPE_PID);
1966+
task = get_pid_task(ctx->pid, PIDTYPE_PID);
19621967
if (task) {
19631968
seq_printf(m, "(%s [%d]) ",
19641969
task->comm, task->pid);
19651970
put_task_struct(task);
19661971
}
1972+
} else if (IS_ERR(ctx->file_priv)) {
1973+
seq_puts(m, "(deleted) ");
19671974
} else {
19681975
seq_puts(m, "(kernel) ");
19691976
}

drivers/gpu/drm/i915/i915_drv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,7 @@ struct drm_i915_error_state {
782782

783783
struct drm_i915_error_request {
784784
long jiffies;
785+
pid_t pid;
785786
u32 seqno;
786787
u32 head;
787788
u32 tail;
@@ -880,6 +881,7 @@ struct i915_gem_context {
880881
struct drm_i915_private *i915;
881882
struct drm_i915_file_private *file_priv;
882883
struct i915_hw_ppgtt *ppgtt;
884+
struct pid *pid;
883885

884886
struct i915_ctx_hang_stats hang_stats;
885887

drivers/gpu/drm/i915/i915_gem_context.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ void i915_gem_context_free(struct kref *ctx_ref)
158158
i915_vma_put(ce->state);
159159
}
160160

161+
put_pid(ctx->pid);
161162
list_del(&ctx->link);
162163

163164
ida_simple_remove(&ctx->i915->context_hw_ida, ctx->hw_id);
@@ -311,6 +312,9 @@ __create_hw_context(struct drm_device *dev,
311312
ret = DEFAULT_CONTEXT_HANDLE;
312313

313314
ctx->file_priv = file_priv;
315+
if (file_priv)
316+
ctx->pid = get_task_pid(current, PIDTYPE_PID);
317+
314318
ctx->user_handle = ret;
315319
/* NB: Mark all slices as needing a remap so that when the context first
316320
* loads it will restore whatever remap state already exists. If there

drivers/gpu/drm/i915/i915_gem_request.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,6 @@ int i915_gem_request_add_to_client(struct drm_i915_gem_request *req,
137137
list_add_tail(&req->client_list, &file_priv->mm.request_list);
138138
spin_unlock(&file_priv->mm.lock);
139139

140-
req->pid = get_pid(task_pid(current));
141-
142140
return 0;
143141
}
144142

@@ -154,9 +152,6 @@ i915_gem_request_remove_from_client(struct drm_i915_gem_request *request)
154152
list_del(&request->client_list);
155153
request->file_priv = NULL;
156154
spin_unlock(&file_priv->mm.lock);
157-
158-
put_pid(request->pid);
159-
request->pid = NULL;
160155
}
161156

162157
void i915_gem_retire_noop(struct i915_gem_active *active,
@@ -407,7 +402,6 @@ i915_gem_request_alloc(struct intel_engine_cs *engine,
407402
req->previous_context = NULL;
408403
req->file_priv = NULL;
409404
req->batch = NULL;
410-
req->pid = NULL;
411405
req->elsp_submitted = 0;
412406

413407
/*

drivers/gpu/drm/i915/i915_gem_request.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,6 @@ struct drm_i915_gem_request {
134134
/** file_priv list entry for this request */
135135
struct list_head client_list;
136136

137-
/** process identifier submitting this request */
138-
struct pid *pid;
139-
140137
/**
141138
* The ELSP only accepts two elements at a time, so we queue
142139
* context/tail pairs on a given queue (ring->execlist_queue) until the

drivers/gpu/drm/i915/i915_gpu_error.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,8 @@ int i915_error_state_to_str(struct drm_i915_error_state_buf *m,
470470
dev_priv->engine[i].name,
471471
ee->num_requests);
472472
for (j = 0; j < ee->num_requests; j++) {
473-
err_printf(m, " seqno 0x%08x, emitted %ld, head 0x%08x, tail 0x%08x\n",
473+
err_printf(m, " pid %d, seqno 0x%08x, emitted %ld, head 0x%08x, tail 0x%08x\n",
474+
ee->requests[j].pid,
474475
ee->requests[j].seqno,
475476
ee->requests[j].jiffies,
476477
ee->requests[j].head,
@@ -1076,6 +1077,7 @@ static void i915_gem_record_rings(struct drm_i915_private *dev_priv,
10761077
request = i915_gem_find_active_request(engine);
10771078
if (request) {
10781079
struct intel_ring *ring;
1080+
struct pid *pid;
10791081

10801082
ee->vm = request->ctx->ppgtt ?
10811083
&request->ctx->ppgtt->base : &ggtt->base;
@@ -1097,11 +1099,12 @@ static void i915_gem_record_rings(struct drm_i915_private *dev_priv,
10971099
i915_error_object_create(dev_priv,
10981100
request->ctx->engine[i].state);
10991101

1100-
if (request->pid) {
1102+
pid = request->ctx->pid;
1103+
if (pid) {
11011104
struct task_struct *task;
11021105

11031106
rcu_read_lock();
1104-
task = pid_task(request->pid, PIDTYPE_PID);
1107+
task = pid_task(pid, PIDTYPE_PID);
11051108
if (task) {
11061109
strcpy(ee->comm, task->comm);
11071110
ee->pid = task->pid;
@@ -1166,6 +1169,10 @@ static void i915_gem_record_rings(struct drm_i915_private *dev_priv,
11661169
erq->jiffies = request->emitted_jiffies;
11671170
erq->head = request->head;
11681171
erq->tail = request->tail;
1172+
1173+
rcu_read_lock();
1174+
erq->pid = request->ctx->pid ? pid_nr(request->ctx->pid) : 0;
1175+
rcu_read_unlock();
11691176
}
11701177
}
11711178
}

0 commit comments

Comments
 (0)