Skip to content

Commit b78edd4

Browse files
committed
drm/lima: save task info dump when task fail
Save all information to start a task which can be exported to user for debug usage. Dump file data format is specified in lima_dump.h v2: Add include header to address build robot complain. Tested-by: Andreas Baierl <ichgeh@imkreisrum.de> Reviewed-by: Vasily Khoruzhick <anarsoul@gmail.com> Signed-off-by: Qiang Yu <yuq825@gmail.com> Link: https://patchwork.freedesktop.org/patch/msgid/20200307134423.24329-1-yuq825@gmail.com
1 parent c67a3d4 commit b78edd4

5 files changed

Lines changed: 235 additions & 0 deletions

File tree

‎drivers/gpu/drm/lima/lima_device.c‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,12 @@ int lima_device_init(struct lima_device *ldev)
344344
if (err)
345345
goto err_out5;
346346

347+
ldev->dump.magic = LIMA_DUMP_MAGIC;
348+
ldev->dump.version_major = LIMA_DUMP_MAJOR;
349+
ldev->dump.version_minor = LIMA_DUMP_MINOR;
350+
INIT_LIST_HEAD(&ldev->error_task_list);
351+
mutex_init(&ldev->error_task_list_lock);
352+
347353
dev_info(ldev->dev, "bus rate = %lu\n", clk_get_rate(ldev->clk_bus));
348354
dev_info(ldev->dev, "mod rate = %lu", clk_get_rate(ldev->clk_gpu));
349355

@@ -370,6 +376,13 @@ int lima_device_init(struct lima_device *ldev)
370376
void lima_device_fini(struct lima_device *ldev)
371377
{
372378
int i;
379+
struct lima_sched_error_task *et, *tmp;
380+
381+
list_for_each_entry_safe(et, tmp, &ldev->error_task_list, list) {
382+
list_del(&et->list);
383+
kvfree(et);
384+
}
385+
mutex_destroy(&ldev->error_task_list_lock);
373386

374387
lima_fini_pp_pipe(ldev);
375388
lima_fini_gp_pipe(ldev);

‎drivers/gpu/drm/lima/lima_device.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66

77
#include <drm/drm_device.h>
88
#include <linux/delay.h>
9+
#include <linux/list.h>
10+
#include <linux/mutex.h>
911

1012
#include "lima_sched.h"
13+
#include "lima_dump.h"
1114

1215
enum lima_gpu_id {
1316
lima_gpu_mali400 = 0,
@@ -94,6 +97,11 @@ struct lima_device {
9497

9598
u32 *dlbu_cpu;
9699
dma_addr_t dlbu_dma;
100+
101+
/* debug info */
102+
struct lima_dump_head dump;
103+
struct list_head error_task_list;
104+
struct mutex error_task_list_lock;
97105
};
98106

99107
static inline struct lima_device *

‎drivers/gpu/drm/lima/lima_dump.h‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/* SPDX-License-Identifier: GPL-2.0 OR MIT */
2+
/* Copyright 2020 Qiang Yu <yuq825@gmail.com> */
3+
4+
#ifndef __LIMA_DUMP_H__
5+
#define __LIMA_DUMP_H__
6+
7+
#include <linux/types.h>
8+
9+
/**
10+
* dump file format for all the information to start a lima task
11+
*
12+
* top level format
13+
* | magic code "LIMA" | format version | num tasks | data size |
14+
* | reserved | reserved | reserved | reserved |
15+
* | task 1 ID | task 1 size | num chunks | reserved | task 1 data |
16+
* | task 2 ID | task 2 size | num chunks | reserved | task 2 data |
17+
* ...
18+
*
19+
* task data format
20+
* | chunk 1 ID | chunk 1 size | reserved | reserved | chunk 1 data |
21+
* | chunk 2 ID | chunk 2 size | reserved | reserved | chunk 2 data |
22+
* ...
23+
*
24+
*/
25+
26+
#define LIMA_DUMP_MAJOR 1
27+
#define LIMA_DUMP_MINOR 0
28+
29+
#define LIMA_DUMP_MAGIC 0x414d494c
30+
31+
struct lima_dump_head {
32+
__u32 magic;
33+
__u16 version_major;
34+
__u16 version_minor;
35+
__u32 num_tasks;
36+
__u32 size;
37+
__u32 reserved[4];
38+
};
39+
40+
#define LIMA_DUMP_TASK_GP 0
41+
#define LIMA_DUMP_TASK_PP 1
42+
#define LIMA_DUMP_TASK_NUM 2
43+
44+
struct lima_dump_task {
45+
__u32 id;
46+
__u32 size;
47+
__u32 num_chunks;
48+
__u32 reserved;
49+
};
50+
51+
#define LIMA_DUMP_CHUNK_FRAME 0
52+
#define LIMA_DUMP_CHUNK_BUFFER 1
53+
#define LIMA_DUMP_CHUNK_PROCESS_NAME 2
54+
#define LIMA_DUMP_CHUNK_PROCESS_ID 3
55+
#define LIMA_DUMP_CHUNK_NUM 4
56+
57+
struct lima_dump_chunk {
58+
__u32 id;
59+
__u32 size;
60+
__u32 reserved[2];
61+
};
62+
63+
struct lima_dump_chunk_buffer {
64+
__u32 id;
65+
__u32 size;
66+
__u32 va;
67+
__u32 reserved;
68+
};
69+
70+
struct lima_dump_chunk_pid {
71+
__u32 id;
72+
__u32 size;
73+
__u32 pid;
74+
__u32 reserved;
75+
};
76+
77+
#endif

‎drivers/gpu/drm/lima/lima_sched.c‎

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <linux/kthread.h>
55
#include <linux/slab.h>
66
#include <linux/xarray.h>
7+
#include <linux/vmalloc.h>
78

89
#include "lima_drv.h"
910
#include "lima_sched.h"
@@ -256,6 +257,133 @@ static struct dma_fence *lima_sched_run_job(struct drm_sched_job *job)
256257
return task->fence;
257258
}
258259

260+
static void lima_sched_build_error_task_list(struct lima_sched_task *task)
261+
{
262+
struct lima_sched_error_task *et;
263+
struct lima_sched_pipe *pipe = to_lima_pipe(task->base.sched);
264+
struct lima_ip *ip = pipe->processor[0];
265+
int pipe_id = ip->id == lima_ip_gp ? lima_pipe_gp : lima_pipe_pp;
266+
struct lima_device *dev = ip->dev;
267+
struct lima_sched_context *sched_ctx =
268+
container_of(task->base.entity,
269+
struct lima_sched_context, base);
270+
struct lima_ctx *ctx =
271+
container_of(sched_ctx, struct lima_ctx, context[pipe_id]);
272+
struct lima_dump_task *dt;
273+
struct lima_dump_chunk *chunk;
274+
struct lima_dump_chunk_pid *pid_chunk;
275+
struct lima_dump_chunk_buffer *buffer_chunk;
276+
u32 size, task_size, mem_size;
277+
int i;
278+
279+
mutex_lock(&dev->error_task_list_lock);
280+
281+
if (dev->dump.num_tasks >= lima_max_error_tasks) {
282+
dev_info(dev->dev, "fail to save task state: error task list is full\n");
283+
goto out;
284+
}
285+
286+
/* frame chunk */
287+
size = sizeof(struct lima_dump_chunk) + pipe->frame_size;
288+
/* process name chunk */
289+
size += sizeof(struct lima_dump_chunk) + sizeof(ctx->pname);
290+
/* pid chunk */
291+
size += sizeof(struct lima_dump_chunk);
292+
/* buffer chunks */
293+
for (i = 0; i < task->num_bos; i++) {
294+
struct lima_bo *bo = task->bos[i];
295+
296+
size += sizeof(struct lima_dump_chunk);
297+
size += bo->heap_size ? bo->heap_size : lima_bo_size(bo);
298+
}
299+
300+
task_size = size + sizeof(struct lima_dump_task);
301+
mem_size = task_size + sizeof(*et);
302+
et = kvmalloc(mem_size, GFP_KERNEL);
303+
if (!et) {
304+
dev_err(dev->dev, "fail to alloc task dump buffer of size %x\n",
305+
mem_size);
306+
goto out;
307+
}
308+
309+
et->data = et + 1;
310+
et->size = task_size;
311+
312+
dt = et->data;
313+
memset(dt, 0, sizeof(*dt));
314+
dt->id = pipe_id;
315+
dt->size = size;
316+
317+
chunk = (struct lima_dump_chunk *)(dt + 1);
318+
memset(chunk, 0, sizeof(*chunk));
319+
chunk->id = LIMA_DUMP_CHUNK_FRAME;
320+
chunk->size = pipe->frame_size;
321+
memcpy(chunk + 1, task->frame, pipe->frame_size);
322+
dt->num_chunks++;
323+
324+
chunk = (void *)(chunk + 1) + chunk->size;
325+
memset(chunk, 0, sizeof(*chunk));
326+
chunk->id = LIMA_DUMP_CHUNK_PROCESS_NAME;
327+
chunk->size = sizeof(ctx->pname);
328+
memcpy(chunk + 1, ctx->pname, sizeof(ctx->pname));
329+
dt->num_chunks++;
330+
331+
pid_chunk = (void *)(chunk + 1) + chunk->size;
332+
memset(pid_chunk, 0, sizeof(*pid_chunk));
333+
pid_chunk->id = LIMA_DUMP_CHUNK_PROCESS_ID;
334+
pid_chunk->pid = ctx->pid;
335+
dt->num_chunks++;
336+
337+
buffer_chunk = (void *)(pid_chunk + 1) + pid_chunk->size;
338+
for (i = 0; i < task->num_bos; i++) {
339+
struct lima_bo *bo = task->bos[i];
340+
void *data;
341+
342+
memset(buffer_chunk, 0, sizeof(*buffer_chunk));
343+
buffer_chunk->id = LIMA_DUMP_CHUNK_BUFFER;
344+
buffer_chunk->va = lima_vm_get_va(task->vm, bo);
345+
346+
if (bo->heap_size) {
347+
buffer_chunk->size = bo->heap_size;
348+
349+
data = vmap(bo->base.pages, bo->heap_size >> PAGE_SHIFT,
350+
VM_MAP, pgprot_writecombine(PAGE_KERNEL));
351+
if (!data) {
352+
kvfree(et);
353+
goto out;
354+
}
355+
356+
memcpy(buffer_chunk + 1, data, buffer_chunk->size);
357+
358+
vunmap(data);
359+
} else {
360+
buffer_chunk->size = lima_bo_size(bo);
361+
362+
data = drm_gem_shmem_vmap(&bo->base.base);
363+
if (IS_ERR_OR_NULL(data)) {
364+
kvfree(et);
365+
goto out;
366+
}
367+
368+
memcpy(buffer_chunk + 1, data, buffer_chunk->size);
369+
370+
drm_gem_shmem_vunmap(&bo->base.base, data);
371+
}
372+
373+
buffer_chunk = (void *)(buffer_chunk + 1) + buffer_chunk->size;
374+
dt->num_chunks++;
375+
}
376+
377+
list_add(&et->list, &dev->error_task_list);
378+
dev->dump.size += et->size;
379+
dev->dump.num_tasks++;
380+
381+
dev_info(dev->dev, "save error task state success\n");
382+
383+
out:
384+
mutex_unlock(&dev->error_task_list_lock);
385+
}
386+
259387
static void lima_sched_timedout_job(struct drm_sched_job *job)
260388
{
261389
struct lima_sched_pipe *pipe = to_lima_pipe(job->sched);
@@ -268,6 +396,8 @@ static void lima_sched_timedout_job(struct drm_sched_job *job)
268396

269397
drm_sched_increase_karma(&task->base);
270398

399+
lima_sched_build_error_task_list(task);
400+
271401
pipe->task_error(pipe);
272402

273403
if (pipe->bcast_mmu)

‎drivers/gpu/drm/lima/lima_sched.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,16 @@
55
#define __LIMA_SCHED_H__
66

77
#include <drm/gpu_scheduler.h>
8+
#include <linux/list.h>
89

910
struct lima_vm;
1011

12+
struct lima_sched_error_task {
13+
struct list_head list;
14+
void *data;
15+
u32 size;
16+
};
17+
1118
struct lima_sched_task {
1219
struct drm_sched_job base;
1320

0 commit comments

Comments
 (0)