Skip to content

Commit c0fec7f

Browse files
Jordan Crouserobclark
authored andcommitted
drm/msm/gpu: Capture the GPU state on a GPU hang
Capture the GPU state on a GPU hang and store it for later playback via the devcoredump facility. Only one crash state is stored at a time on the assumption that the first hang is usually the most interesting. The existing crash state can be cleared after capturing it and then a new one will be captured on the next hang. Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org> Signed-off-by: Rob Clark <robdclark@gmail.com>
1 parent 65a3c27 commit c0fec7f

9 files changed

Lines changed: 154 additions & 23 deletions

File tree

‎drivers/gpu/drm/msm/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ config DRM_MSM
1212
select SHMEM
1313
select TMPFS
1414
select QCOM_SCM
15+
select WANT_DEV_COREDUMP
1516
select SND_SOC_HDMI_CODEC if SND_SOC
1617
select SYNC_FILE
1718
select PM_OPP

‎drivers/gpu/drm/msm/adreno/a3xx_gpu.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ static const struct adreno_gpu_funcs funcs = {
454454
.active_ring = adreno_active_ring,
455455
.irq = a3xx_irq,
456456
.destroy = a3xx_destroy,
457-
#ifdef CONFIG_DEBUG_FS
457+
#if defined(CONFIG_DEBUG_FS) || defined(CONFIG_DEV_COREDUMP)
458458
.show = adreno_show,
459459
#endif
460460
.gpu_state_get = a3xx_gpu_state_get,

‎drivers/gpu/drm/msm/adreno/a4xx_gpu.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ static const struct adreno_gpu_funcs funcs = {
540540
.active_ring = adreno_active_ring,
541541
.irq = a4xx_irq,
542542
.destroy = a4xx_destroy,
543-
#ifdef CONFIG_DEBUG_FS
543+
#if defined(CONFIG_DEBUG_FS) || defined(CONFIG_DEV_COREDUMP)
544544
.show = adreno_show,
545545
#endif
546546
.gpu_state_get = a4xx_gpu_state_get,

‎drivers/gpu/drm/msm/adreno/a5xx_gpu.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1243,8 +1243,10 @@ static const struct adreno_gpu_funcs funcs = {
12431243
.active_ring = a5xx_active_ring,
12441244
.irq = a5xx_irq,
12451245
.destroy = a5xx_destroy,
1246-
#ifdef CONFIG_DEBUG_FS
1246+
#if defined(CONFIG_DEBUG_FS) || defined(CONFIG_DEV_COREDUMP)
12471247
.show = adreno_show,
1248+
#endif
1249+
#if defined(CONFIG_DEBUG_FS)
12481250
.debugfs_init = a5xx_debugfs_init,
12491251
#endif
12501252
.gpu_busy = a5xx_gpu_busy,

‎drivers/gpu/drm/msm/adreno/adreno_gpu.c‎

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,8 @@ struct msm_gpu_state *adreno_gpu_state_get(struct msm_gpu *gpu)
378378
if (!state)
379379
return ERR_PTR(-ENOMEM);
380380

381+
kref_init(&state->ref);
382+
381383
do_gettimeofday(&state->time);
382384

383385
for (i = 0; i < gpu->nr_rings; i++) {
@@ -414,42 +416,52 @@ struct msm_gpu_state *adreno_gpu_state_get(struct msm_gpu *gpu)
414416
return state;
415417
}
416418

417-
void adreno_gpu_state_put(struct msm_gpu_state *state)
419+
static void adreno_gpu_state_destroy(struct kref *kref)
418420
{
419-
if (IS_ERR_OR_NULL(state))
420-
return;
421+
struct msm_gpu_state *state = container_of(kref,
422+
struct msm_gpu_state, ref);
421423

424+
kfree(state->comm);
425+
kfree(state->cmd);
422426
kfree(state->registers);
423427
kfree(state);
424428
}
425429

426-
#ifdef CONFIG_DEBUG_FS
430+
int adreno_gpu_state_put(struct msm_gpu_state *state)
431+
{
432+
if (IS_ERR_OR_NULL(state))
433+
return 1;
434+
435+
return kref_put(&state->ref, adreno_gpu_state_destroy);
436+
}
437+
438+
#if defined(CONFIG_DEBUG_FS) || defined(CONFIG_DEV_COREDUMP)
427439
void adreno_show(struct msm_gpu *gpu, struct msm_gpu_state *state,
428-
struct seq_file *m)
440+
struct drm_printer *p)
429441
{
430442
struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
431443
int i;
432444

433445
if (IS_ERR_OR_NULL(state))
434446
return;
435447

436-
seq_printf(m, "status: %08x\n", state->rbbm_status);
437-
seq_printf(m, "revision: %d (%d.%d.%d.%d)\n",
448+
drm_printf(p, "status: %08x\n", state->rbbm_status);
449+
drm_printf(p, "revision: %d (%d.%d.%d.%d)\n",
438450
adreno_gpu->info->revn, adreno_gpu->rev.core,
439451
adreno_gpu->rev.major, adreno_gpu->rev.minor,
440452
adreno_gpu->rev.patchid);
441453

442454
for (i = 0; i < gpu->nr_rings; i++) {
443-
seq_printf(m, "rb %d: fence: %d/%d\n", i,
455+
drm_printf(p, "rb %d: fence: %d/%d\n", i,
444456
state->ring[i].fence, state->ring[i].seqno);
445457

446-
seq_printf(m, " rptr: %d\n", state->ring[i].rptr);
447-
seq_printf(m, "rb wptr: %d\n", state->ring[i].wptr);
458+
drm_printf(p, " rptr: %d\n", state->ring[i].rptr);
459+
drm_printf(p, "rb wptr: %d\n", state->ring[i].wptr);
448460
}
449461

450-
seq_printf(m, "IO:region %s 00000000 00020000\n", gpu->name);
462+
drm_printf(p, "IO:region %s 00000000 00020000\n", gpu->name);
451463
for (i = 0; i < state->nr_registers; i++) {
452-
seq_printf(m, "IO:R %08x %08x\n",
464+
drm_printf(p, "IO:R %08x %08x\n",
453465
state->registers[i * 2] << 2,
454466
state->registers[(i * 2) + 1]);
455467
}

‎drivers/gpu/drm/msm/adreno/adreno_gpu.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,9 @@ void adreno_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit,
215215
struct msm_file_private *ctx);
216216
void adreno_flush(struct msm_gpu *gpu, struct msm_ringbuffer *ring);
217217
bool adreno_idle(struct msm_gpu *gpu, struct msm_ringbuffer *ring);
218-
#ifdef CONFIG_DEBUG_FS
218+
#if defined(CONFIG_DEBUG_FS) || defined(CONFIG_DEV_COREDUMP)
219219
void adreno_show(struct msm_gpu *gpu, struct msm_gpu_state *state,
220-
struct seq_file *m);
220+
struct drm_printer *p);
221221
#endif
222222
void adreno_dump_info(struct msm_gpu *gpu);
223223
void adreno_dump(struct msm_gpu *gpu);
@@ -231,7 +231,7 @@ void adreno_gpu_cleanup(struct adreno_gpu *gpu);
231231

232232

233233
struct msm_gpu_state *adreno_gpu_state_get(struct msm_gpu *gpu);
234-
void adreno_gpu_state_put(struct msm_gpu_state *state);
234+
int adreno_gpu_state_put(struct msm_gpu_state *state);
235235

236236
/* ringbuffer helpers (the parts that are adreno specific) */
237237

‎drivers/gpu/drm/msm/msm_debugfs.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ struct msm_gpu_show_priv {
2929

3030
static int msm_gpu_show(struct seq_file *m, void *arg)
3131
{
32+
struct drm_printer p = drm_seq_file_printer(m);
3233
struct msm_gpu_show_priv *show_priv = m->private;
3334
struct msm_drm_private *priv = show_priv->dev->dev_private;
3435
struct msm_gpu *gpu = priv->gpu;
@@ -38,8 +39,8 @@ static int msm_gpu_show(struct seq_file *m, void *arg)
3839
if (ret)
3940
return ret;
4041

41-
seq_printf(m, "%s Status:\n", gpu->name);
42-
gpu->funcs->show(gpu, show_priv->state, m);
42+
drm_printf(&p, "%s Status:\n", gpu->name);
43+
gpu->funcs->show(gpu, show_priv->state, &p);
4344

4445
mutex_unlock(&show_priv->dev->struct_mutex);
4546

‎drivers/gpu/drm/msm/msm_gpu.c‎

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
#include "msm_mmu.h"
2121
#include "msm_fence.h"
2222

23+
#include <generated/utsrelease.h>
2324
#include <linux/string_helpers.h>
2425
#include <linux/pm_opp.h>
2526
#include <linux/devfreq.h>
26-
27+
#include <linux/devcoredump.h>
2728

2829
/*
2930
* Power Management:
@@ -273,6 +274,81 @@ int msm_gpu_hw_init(struct msm_gpu *gpu)
273274
return ret;
274275
}
275276

277+
#ifdef CONFIG_DEV_COREDUMP
278+
static ssize_t msm_gpu_devcoredump_read(char *buffer, loff_t offset,
279+
size_t count, void *data, size_t datalen)
280+
{
281+
struct msm_gpu *gpu = data;
282+
struct drm_print_iterator iter;
283+
struct drm_printer p;
284+
struct msm_gpu_state *state;
285+
286+
state = msm_gpu_crashstate_get(gpu);
287+
if (!state)
288+
return 0;
289+
290+
iter.data = buffer;
291+
iter.offset = 0;
292+
iter.start = offset;
293+
iter.remain = count;
294+
295+
p = drm_coredump_printer(&iter);
296+
297+
drm_printf(&p, "---\n");
298+
drm_printf(&p, "kernel: " UTS_RELEASE "\n");
299+
drm_printf(&p, "module: " KBUILD_MODNAME "\n");
300+
drm_printf(&p, "time: %ld.%ld\n",
301+
state->time.tv_sec, state->time.tv_usec);
302+
if (state->comm)
303+
drm_printf(&p, "comm: %s\n", state->comm);
304+
if (state->cmd)
305+
drm_printf(&p, "cmdline: %s\n", state->cmd);
306+
307+
gpu->funcs->show(gpu, state, &p);
308+
309+
msm_gpu_crashstate_put(gpu);
310+
311+
return count - iter.remain;
312+
}
313+
314+
static void msm_gpu_devcoredump_free(void *data)
315+
{
316+
struct msm_gpu *gpu = data;
317+
318+
msm_gpu_crashstate_put(gpu);
319+
}
320+
321+
static void msm_gpu_crashstate_capture(struct msm_gpu *gpu, char *comm,
322+
char *cmd)
323+
{
324+
struct msm_gpu_state *state;
325+
326+
/* Only save one crash state at a time */
327+
if (gpu->crashstate)
328+
return;
329+
330+
state = gpu->funcs->gpu_state_get(gpu);
331+
if (IS_ERR_OR_NULL(state))
332+
return;
333+
334+
/* Fill in the additional crash state information */
335+
state->comm = kstrdup(comm, GFP_KERNEL);
336+
state->cmd = kstrdup(cmd, GFP_KERNEL);
337+
338+
/* Set the active crash state to be dumped on failure */
339+
gpu->crashstate = state;
340+
341+
/* FIXME: Release the crashstate if this errors out? */
342+
dev_coredumpm(gpu->dev->dev, THIS_MODULE, gpu, 0, GFP_KERNEL,
343+
msm_gpu_devcoredump_read, msm_gpu_devcoredump_free);
344+
}
345+
#else
346+
static void msm_gpu_crashstate_capture(struct msm_gpu *gpu, char *comm,
347+
char *cmd)
348+
{
349+
}
350+
#endif
351+
276352
/*
277353
* Hangcheck detection for locked gpu:
278354
*/
@@ -356,6 +432,11 @@ static void recover_worker(struct work_struct *work)
356432
msm_rd_dump_submit(priv->hangrd, submit, NULL);
357433
}
358434

435+
/* Record the crash state */
436+
pm_runtime_get_sync(&gpu->pdev->dev);
437+
msm_gpu_crashstate_capture(gpu, comm, cmd);
438+
pm_runtime_put_sync(&gpu->pdev->dev);
439+
359440
kfree(cmd);
360441
kfree(comm);
361442

‎drivers/gpu/drm/msm/msm_gpu.h‎

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ struct msm_gpu_funcs {
6666
#ifdef CONFIG_DEBUG_FS
6767
/* show GPU status in debugfs: */
6868
void (*show)(struct msm_gpu *gpu, struct msm_gpu_state *state,
69-
struct seq_file *m);
69+
struct drm_printer *p);
7070
/* for generation specific debugfs: */
7171
int (*debugfs_init)(struct msm_gpu *gpu, struct drm_minor *minor);
7272
#endif
7373
int (*gpu_busy)(struct msm_gpu *gpu, uint64_t *value);
7474
struct msm_gpu_state *(*gpu_state_get)(struct msm_gpu *gpu);
75-
void (*gpu_state_put)(struct msm_gpu_state *state);
75+
int (*gpu_state_put)(struct msm_gpu_state *state);
7676
};
7777

7878
struct msm_gpu {
@@ -133,6 +133,8 @@ struct msm_gpu {
133133
u64 busy_cycles;
134134
ktime_t time;
135135
} devfreq;
136+
137+
struct msm_gpu_state *crashstate;
136138
};
137139

138140
/* It turns out that all targets use the same ringbuffer size */
@@ -180,6 +182,7 @@ struct msm_gpu_submitqueue {
180182
};
181183

182184
struct msm_gpu_state {
185+
struct kref ref;
183186
struct timeval time;
184187

185188
struct {
@@ -194,6 +197,9 @@ struct msm_gpu_state {
194197
u32 *registers;
195198

196199
u32 rbbm_status;
200+
201+
char *comm;
202+
char *cmd;
197203
};
198204

199205
static inline void gpu_write(struct msm_gpu *gpu, u32 reg, u32 data)
@@ -275,4 +281,32 @@ static inline void msm_submitqueue_put(struct msm_gpu_submitqueue *queue)
275281
kref_put(&queue->ref, msm_submitqueue_destroy);
276282
}
277283

284+
static inline struct msm_gpu_state *msm_gpu_crashstate_get(struct msm_gpu *gpu)
285+
{
286+
struct msm_gpu_state *state = NULL;
287+
288+
mutex_lock(&gpu->dev->struct_mutex);
289+
290+
if (gpu->crashstate) {
291+
kref_get(&gpu->crashstate->ref);
292+
state = gpu->crashstate;
293+
}
294+
295+
mutex_unlock(&gpu->dev->struct_mutex);
296+
297+
return state;
298+
}
299+
300+
static inline void msm_gpu_crashstate_put(struct msm_gpu *gpu)
301+
{
302+
mutex_lock(&gpu->dev->struct_mutex);
303+
304+
if (gpu->crashstate) {
305+
if (gpu->funcs->gpu_state_put(gpu->crashstate))
306+
gpu->crashstate = NULL;
307+
}
308+
309+
mutex_unlock(&gpu->dev->struct_mutex);
310+
}
311+
278312
#endif /* __MSM_GPU_H__ */

0 commit comments

Comments
 (0)