2 * Copyright 2015 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
24 * Marek Olšák <maraeo@gmail.com>
30 #include "sid_tables.h"
31 #include "ddebug/dd_util.h"
32 #include "util/u_memory.h"
35 DEBUG_GET_ONCE_OPTION(replace_shaders
, "RADEON_REPLACE_SHADERS", NULL
)
37 static void si_dump_shader(struct si_screen
*sscreen
,
38 struct si_shader_ctx_state
*state
, FILE *f
)
40 struct si_shader
*current
= state
->current
;
42 if (!state
->cso
|| !current
)
45 if (current
->shader_log
)
46 fwrite(current
->shader_log
, current
->shader_log_size
, 1, f
);
48 si_shader_dump(sscreen
, state
->current
, NULL
,
49 state
->cso
->info
.processor
, f
, false);
53 * Shader compiles can be overridden with arbitrary ELF objects by setting
54 * the environment variable RADEON_REPLACE_SHADERS=num1:filename1[;num2:filename2]
56 bool si_replace_shader(unsigned num
, struct ac_shader_binary
*binary
)
58 const char *p
= debug_get_option_replace_shaders();
59 const char *semicolon
;
64 bool replaced
= false;
72 i
= strtoul(p
, &endp
, 0);
76 fprintf(stderr
, "RADEON_REPLACE_SHADERS formatted badly.\n");
92 semicolon
= strchr(p
, ';');
94 p
= copy
= strndup(p
, semicolon
- p
);
96 fprintf(stderr
, "out of memory\n");
101 fprintf(stderr
, "radeonsi: replace shader %u by %s\n", num
, p
);
105 perror("radeonsi: failed to open file");
109 if (fseek(f
, 0, SEEK_END
) != 0)
116 if (fseek(f
, 0, SEEK_SET
) != 0)
119 buf
= MALLOC(filesize
);
121 fprintf(stderr
, "out of memory\n");
125 nread
= fread(buf
, 1, filesize
, f
);
126 if (nread
!= filesize
)
129 ac_elf_read(buf
, filesize
, binary
);
140 perror("radeonsi: reading shader");
144 /* Parsed IBs are difficult to read without colors. Use "less -R file" to
145 * read them, or use "aha -b -f file" to convert them to html.
147 #define COLOR_RESET "\033[0m"
148 #define COLOR_RED "\033[31m"
149 #define COLOR_GREEN "\033[1;32m"
150 #define COLOR_YELLOW "\033[1;33m"
151 #define COLOR_CYAN "\033[1;36m"
153 static void si_dump_mmapped_reg(struct si_context
*sctx
, FILE *f
,
156 struct radeon_winsys
*ws
= sctx
->b
.ws
;
159 if (ws
->read_registers(ws
, offset
, 1, &value
))
160 ac_dump_reg(f
, offset
, value
, ~0);
163 static void si_dump_debug_registers(struct si_context
*sctx
, FILE *f
)
165 if (sctx
->screen
->b
.info
.drm_major
== 2 &&
166 sctx
->screen
->b
.info
.drm_minor
< 42)
167 return; /* no radeon support */
169 fprintf(f
, "Memory-mapped registers:\n");
170 si_dump_mmapped_reg(sctx
, f
, R_008010_GRBM_STATUS
);
172 /* No other registers can be read on DRM < 3.1.0. */
173 if (sctx
->screen
->b
.info
.drm_major
< 3 ||
174 sctx
->screen
->b
.info
.drm_minor
< 1) {
179 si_dump_mmapped_reg(sctx
, f
, R_008008_GRBM_STATUS2
);
180 si_dump_mmapped_reg(sctx
, f
, R_008014_GRBM_STATUS_SE0
);
181 si_dump_mmapped_reg(sctx
, f
, R_008018_GRBM_STATUS_SE1
);
182 si_dump_mmapped_reg(sctx
, f
, R_008038_GRBM_STATUS_SE2
);
183 si_dump_mmapped_reg(sctx
, f
, R_00803C_GRBM_STATUS_SE3
);
184 si_dump_mmapped_reg(sctx
, f
, R_00D034_SDMA0_STATUS_REG
);
185 si_dump_mmapped_reg(sctx
, f
, R_00D834_SDMA1_STATUS_REG
);
186 if (sctx
->b
.chip_class
<= VI
) {
187 si_dump_mmapped_reg(sctx
, f
, R_000E50_SRBM_STATUS
);
188 si_dump_mmapped_reg(sctx
, f
, R_000E4C_SRBM_STATUS2
);
189 si_dump_mmapped_reg(sctx
, f
, R_000E54_SRBM_STATUS3
);
191 si_dump_mmapped_reg(sctx
, f
, R_008680_CP_STAT
);
192 si_dump_mmapped_reg(sctx
, f
, R_008674_CP_STALLED_STAT1
);
193 si_dump_mmapped_reg(sctx
, f
, R_008678_CP_STALLED_STAT2
);
194 si_dump_mmapped_reg(sctx
, f
, R_008670_CP_STALLED_STAT3
);
195 si_dump_mmapped_reg(sctx
, f
, R_008210_CP_CPC_STATUS
);
196 si_dump_mmapped_reg(sctx
, f
, R_008214_CP_CPC_BUSY_STAT
);
197 si_dump_mmapped_reg(sctx
, f
, R_008218_CP_CPC_STALLED_STAT1
);
198 si_dump_mmapped_reg(sctx
, f
, R_00821C_CP_CPF_STATUS
);
199 si_dump_mmapped_reg(sctx
, f
, R_008220_CP_CPF_BUSY_STAT
);
200 si_dump_mmapped_reg(sctx
, f
, R_008224_CP_CPF_STALLED_STAT1
);
204 static void si_dump_last_ib(struct si_context
*sctx
, FILE *f
)
206 int last_trace_id
= -1;
208 if (!sctx
->last_gfx
.ib
)
211 if (sctx
->last_trace_buf
) {
212 /* We are expecting that the ddebug pipe has already
213 * waited for the context, so this buffer should be idle.
214 * If the GPU is hung, there is no point in waiting for it.
216 uint32_t *map
= sctx
->b
.ws
->buffer_map(sctx
->last_trace_buf
->buf
,
218 PIPE_TRANSFER_UNSYNCHRONIZED
|
221 last_trace_id
= *map
;
224 if (sctx
->init_config
)
225 ac_parse_ib(f
, sctx
->init_config
->pm4
, sctx
->init_config
->ndw
,
226 -1, "IB2: Init config", sctx
->b
.chip_class
,
229 if (sctx
->init_config_gs_rings
)
230 ac_parse_ib(f
, sctx
->init_config_gs_rings
->pm4
,
231 sctx
->init_config_gs_rings
->ndw
,
232 -1, "IB2: Init GS rings", sctx
->b
.chip_class
,
235 ac_parse_ib(f
, sctx
->last_gfx
.ib
, sctx
->last_gfx
.num_dw
,
236 last_trace_id
, "IB", sctx
->b
.chip_class
,
240 static const char *priority_to_string(enum radeon_bo_priority priority
)
242 #define ITEM(x) [RADEON_PRIO_##x] = #x
243 static const char *table
[64] = {
246 ITEM(SO_FILLED_SIZE
),
260 ITEM(SAMPLER_BUFFER
),
262 ITEM(SHADER_RW_BUFFER
),
263 ITEM(COMPUTE_GLOBAL
),
264 ITEM(SAMPLER_TEXTURE
),
265 ITEM(SHADER_RW_IMAGE
),
266 ITEM(SAMPLER_TEXTURE_MSAA
),
269 ITEM(COLOR_BUFFER_MSAA
),
270 ITEM(DEPTH_BUFFER_MSAA
),
276 ITEM(SCRATCH_BUFFER
),
280 assert(priority
< ARRAY_SIZE(table
));
281 return table
[priority
];
284 static int bo_list_compare_va(const struct radeon_bo_list_item
*a
,
285 const struct radeon_bo_list_item
*b
)
287 return a
->vm_address
< b
->vm_address
? -1 :
288 a
->vm_address
> b
->vm_address
? 1 : 0;
291 static void si_dump_bo_list(struct si_context
*sctx
,
292 const struct radeon_saved_cs
*saved
, FILE *f
)
299 /* Sort the list according to VM adddresses first. */
300 qsort(saved
->bo_list
, saved
->bo_count
,
301 sizeof(saved
->bo_list
[0]), (void*)bo_list_compare_va
);
303 fprintf(f
, "Buffer list (in units of pages = 4kB):\n"
304 COLOR_YELLOW
" Size VM start page "
305 "VM end page Usage" COLOR_RESET
"\n");
307 for (i
= 0; i
< saved
->bo_count
; i
++) {
308 /* Note: Buffer sizes are expected to be aligned to 4k by the winsys. */
309 const unsigned page_size
= sctx
->b
.screen
->info
.gart_page_size
;
310 uint64_t va
= saved
->bo_list
[i
].vm_address
;
311 uint64_t size
= saved
->bo_list
[i
].bo_size
;
314 /* If there's unused virtual memory between 2 buffers, print it. */
316 uint64_t previous_va_end
= saved
->bo_list
[i
-1].vm_address
+
317 saved
->bo_list
[i
-1].bo_size
;
319 if (va
> previous_va_end
) {
320 fprintf(f
, " %10"PRIu64
" -- hole --\n",
321 (va
- previous_va_end
) / page_size
);
325 /* Print the buffer. */
326 fprintf(f
, " %10"PRIu64
" 0x%013"PRIX64
" 0x%013"PRIX64
" ",
327 size
/ page_size
, va
/ page_size
, (va
+ size
) / page_size
);
329 /* Print the usage. */
330 for (j
= 0; j
< 64; j
++) {
331 if (!(saved
->bo_list
[i
].priority_usage
& (1llu << j
)))
334 fprintf(f
, "%s%s", !hit
? "" : ", ", priority_to_string(j
));
339 fprintf(f
, "\nNote: The holes represent memory not used by the IB.\n"
340 " Other buffers can still be allocated there.\n\n");
343 static void si_dump_framebuffer(struct si_context
*sctx
, FILE *f
)
345 struct pipe_framebuffer_state
*state
= &sctx
->framebuffer
.state
;
346 struct r600_texture
*rtex
;
349 for (i
= 0; i
< state
->nr_cbufs
; i
++) {
350 if (!state
->cbufs
[i
])
353 rtex
= (struct r600_texture
*)state
->cbufs
[i
]->texture
;
354 fprintf(f
, COLOR_YELLOW
"Color buffer %i:" COLOR_RESET
"\n", i
);
355 r600_print_texture_info(sctx
->b
.screen
, rtex
, f
);
360 rtex
= (struct r600_texture
*)state
->zsbuf
->texture
;
361 fprintf(f
, COLOR_YELLOW
"Depth-stencil buffer:" COLOR_RESET
"\n");
362 r600_print_texture_info(sctx
->b
.screen
, rtex
, f
);
367 static void si_dump_descriptor_list(struct si_descriptors
*desc
,
368 const char *shader_name
,
369 const char *elem_name
,
370 unsigned num_elements
,
374 uint32_t *cpu_list
= desc
->list
;
375 uint32_t *gpu_list
= desc
->gpu_list
;
376 const char *list_note
= "GPU list";
380 list_note
= "CPU list";
383 for (i
= 0; i
< num_elements
; i
++) {
384 fprintf(f
, COLOR_GREEN
"%s%s slot %u (%s):" COLOR_RESET
"\n",
385 shader_name
, elem_name
, i
, list_note
);
387 switch (desc
->element_dw_size
) {
389 for (j
= 0; j
< 4; j
++)
390 ac_dump_reg(f
, R_008F00_SQ_BUF_RSRC_WORD0
+ j
*4,
391 gpu_list
[j
], 0xffffffff);
394 for (j
= 0; j
< 8; j
++)
395 ac_dump_reg(f
, R_008F10_SQ_IMG_RSRC_WORD0
+ j
*4,
396 gpu_list
[j
], 0xffffffff);
398 fprintf(f
, COLOR_CYAN
" Buffer:" COLOR_RESET
"\n");
399 for (j
= 0; j
< 4; j
++)
400 ac_dump_reg(f
, R_008F00_SQ_BUF_RSRC_WORD0
+ j
*4,
401 gpu_list
[4+j
], 0xffffffff);
404 for (j
= 0; j
< 8; j
++)
405 ac_dump_reg(f
, R_008F10_SQ_IMG_RSRC_WORD0
+ j
*4,
406 gpu_list
[j
], 0xffffffff);
408 fprintf(f
, COLOR_CYAN
" Buffer:" COLOR_RESET
"\n");
409 for (j
= 0; j
< 4; j
++)
410 ac_dump_reg(f
, R_008F00_SQ_BUF_RSRC_WORD0
+ j
*4,
411 gpu_list
[4+j
], 0xffffffff);
413 fprintf(f
, COLOR_CYAN
" FMASK:" COLOR_RESET
"\n");
414 for (j
= 0; j
< 8; j
++)
415 ac_dump_reg(f
, R_008F10_SQ_IMG_RSRC_WORD0
+ j
*4,
416 gpu_list
[8+j
], 0xffffffff);
418 fprintf(f
, COLOR_CYAN
" Sampler state:" COLOR_RESET
"\n");
419 for (j
= 0; j
< 4; j
++)
420 ac_dump_reg(f
, R_008F30_SQ_IMG_SAMP_WORD0
+ j
*4,
421 gpu_list
[12+j
], 0xffffffff);
425 if (memcmp(gpu_list
, cpu_list
, desc
->element_dw_size
* 4) != 0) {
426 fprintf(f
, COLOR_RED
"!!!!! This slot was corrupted in GPU memory !!!!!"
431 gpu_list
+= desc
->element_dw_size
;
432 cpu_list
+= desc
->element_dw_size
;
436 static void si_dump_descriptors(struct si_context
*sctx
,
437 struct si_shader_ctx_state
*state
,
440 if (!state
->cso
|| !state
->current
)
443 unsigned type
= state
->cso
->type
;
444 const struct tgsi_shader_info
*info
= &state
->cso
->info
;
445 struct si_descriptors
*descs
=
446 &sctx
->descriptors
[SI_DESCS_FIRST_SHADER
+
447 type
* SI_NUM_SHADER_DESCS
];
448 static const char *shader_name
[] = {"VS", "PS", "GS", "TCS", "TES", "CS"};
450 static const char *elem_name
[] = {
451 " - Constant buffer",
456 unsigned num_elements
[] = {
457 util_last_bit(info
->const_buffers_declared
),
458 util_last_bit(info
->shader_buffers_declared
),
459 util_last_bit(info
->samplers_declared
),
460 util_last_bit(info
->images_declared
),
463 if (type
== PIPE_SHADER_VERTEX
) {
464 si_dump_descriptor_list(&sctx
->vertex_buffers
, shader_name
[type
],
465 " - Vertex buffer", info
->num_inputs
, f
);
468 for (unsigned i
= 0; i
< SI_NUM_SHADER_DESCS
; ++i
, ++descs
)
469 si_dump_descriptor_list(descs
, shader_name
[type
], elem_name
[i
],
473 struct si_shader_inst
{
474 char text
[160]; /* one disasm line */
475 unsigned offset
; /* instruction offset */
476 unsigned size
; /* instruction size = 4 or 8 */
479 /* Split a disassembly string into lines and add them to the array pointed
480 * to by "instructions". */
481 static void si_add_split_disasm(const char *disasm
,
484 struct si_shader_inst
*instructions
)
486 struct si_shader_inst
*last_inst
= *num
? &instructions
[*num
- 1] : NULL
;
489 while ((next
= strchr(disasm
, '\n'))) {
490 struct si_shader_inst
*inst
= &instructions
[*num
];
491 unsigned len
= next
- disasm
;
493 assert(len
< ARRAY_SIZE(inst
->text
));
494 memcpy(inst
->text
, disasm
, len
);
496 inst
->offset
= last_inst
? last_inst
->offset
+ last_inst
->size
: 0;
498 const char *semicolon
= strchr(disasm
, ';');
500 /* More than 16 chars after ";" means the instruction is 8 bytes long. */
501 inst
->size
= next
- semicolon
> 16 ? 8 : 4;
503 snprintf(inst
->text
+ len
, ARRAY_SIZE(inst
->text
) - len
,
504 " [PC=0x%"PRIx64
", off=%u, size=%u]",
505 start_addr
+ inst
->offset
, inst
->offset
, inst
->size
);
513 #define MAX_WAVES_PER_CHIP (64 * 40)
515 struct si_wave_info
{
516 unsigned se
; /* shader engine */
517 unsigned sh
; /* shader array */
518 unsigned cu
; /* compute unit */
522 uint64_t pc
; /* program counter */
526 bool matched
; /* whether the wave is used by a currently-bound shader */
529 static int compare_wave(const void *p1
, const void *p2
)
531 struct si_wave_info
*w1
= (struct si_wave_info
*)p1
;
532 struct si_wave_info
*w2
= (struct si_wave_info
*)p2
;
534 /* Sort waves according to PC and then SE, SH, CU, etc. */
551 if (w1
->simd
< w2
->simd
)
553 if (w1
->simd
> w2
->simd
)
555 if (w1
->wave
< w2
->wave
)
557 if (w1
->wave
> w2
->wave
)
563 /* Return wave information. "waves" should be a large enough array. */
564 static unsigned si_get_wave_info(struct si_wave_info waves
[MAX_WAVES_PER_CHIP
])
567 unsigned num_waves
= 0;
569 FILE *p
= popen("umr -wa", "r");
573 if (!fgets(line
, sizeof(line
), p
) ||
574 strncmp(line
, "SE", 2) != 0) {
579 while (fgets(line
, sizeof(line
), p
)) {
580 struct si_wave_info
*w
;
581 uint32_t pc_hi
, pc_lo
, exec_hi
, exec_lo
;
583 assert(num_waves
< MAX_WAVES_PER_CHIP
);
584 w
= &waves
[num_waves
];
586 if (sscanf(line
, "%u %u %u %u %u %x %x %x %x %x %x %x",
587 &w
->se
, &w
->sh
, &w
->cu
, &w
->simd
, &w
->wave
,
588 &w
->status
, &pc_hi
, &pc_lo
, &w
->inst_dw0
,
589 &w
->inst_dw1
, &exec_hi
, &exec_lo
) == 12) {
590 w
->pc
= ((uint64_t)pc_hi
<< 32) | pc_lo
;
591 w
->exec
= ((uint64_t)exec_hi
<< 32) | exec_lo
;
597 qsort(waves
, num_waves
, sizeof(struct si_wave_info
), compare_wave
);
603 /* If the shader is being executed, print its asm instructions, and annotate
604 * those that are being executed right now with information about waves that
605 * execute them. This is most useful during a GPU hang.
607 static void si_print_annotated_shader(struct si_shader
*shader
,
608 struct si_wave_info
*waves
,
612 if (!shader
|| !shader
->binary
.disasm_string
)
615 uint64_t start_addr
= shader
->bo
->gpu_address
;
616 uint64_t end_addr
= start_addr
+ shader
->bo
->b
.b
.width0
;
619 /* See if any wave executes the shader. */
620 for (i
= 0; i
< num_waves
; i
++) {
621 if (start_addr
<= waves
[i
].pc
&& waves
[i
].pc
<= end_addr
)
625 return; /* the shader is not being executed */
627 /* Remember the first found wave. The waves are sorted according to PC. */
631 /* Get the list of instructions.
632 * Buffer size / 4 is the upper bound of the instruction count.
634 unsigned num_inst
= 0;
635 struct si_shader_inst
*instructions
=
636 calloc(shader
->bo
->b
.b
.width0
/ 4, sizeof(struct si_shader_inst
));
638 if (shader
->prolog
) {
639 si_add_split_disasm(shader
->prolog
->binary
.disasm_string
,
640 start_addr
, &num_inst
, instructions
);
642 if (shader
->previous_stage
) {
643 si_add_split_disasm(shader
->previous_stage
->binary
.disasm_string
,
644 start_addr
, &num_inst
, instructions
);
646 si_add_split_disasm(shader
->binary
.disasm_string
,
647 start_addr
, &num_inst
, instructions
);
648 if (shader
->epilog
) {
649 si_add_split_disasm(shader
->epilog
->binary
.disasm_string
,
650 start_addr
, &num_inst
, instructions
);
653 fprintf(f
, COLOR_YELLOW
"%s - annotated disassembly:" COLOR_RESET
"\n",
654 si_get_shader_name(shader
, shader
->selector
->type
));
656 /* Print instructions with annotations. */
657 for (i
= 0; i
< num_inst
; i
++) {
658 struct si_shader_inst
*inst
= &instructions
[i
];
660 fprintf(f
, "%s\n", inst
->text
);
662 /* Print which waves execute the instruction right now. */
663 while (num_waves
&& start_addr
+ inst
->offset
== waves
->pc
) {
665 " " COLOR_GREEN
"^ SE%u SH%u CU%u "
666 "SIMD%u WAVE%u EXEC=%016"PRIx64
" ",
667 waves
->se
, waves
->sh
, waves
->cu
, waves
->simd
,
668 waves
->wave
, waves
->exec
);
670 if (inst
->size
== 4) {
671 fprintf(f
, "INST32=%08X" COLOR_RESET
"\n",
674 fprintf(f
, "INST64=%08X %08X" COLOR_RESET
"\n",
675 waves
->inst_dw0
, waves
->inst_dw1
);
678 waves
->matched
= true;
688 static void si_dump_annotated_shaders(struct si_context
*sctx
, FILE *f
)
690 struct si_wave_info waves
[MAX_WAVES_PER_CHIP
];
691 unsigned num_waves
= si_get_wave_info(waves
);
693 fprintf(f
, COLOR_CYAN
"The number of active waves = %u" COLOR_RESET
696 si_print_annotated_shader(sctx
->vs_shader
.current
, waves
, num_waves
, f
);
697 si_print_annotated_shader(sctx
->tcs_shader
.current
, waves
, num_waves
, f
);
698 si_print_annotated_shader(sctx
->tes_shader
.current
, waves
, num_waves
, f
);
699 si_print_annotated_shader(sctx
->gs_shader
.current
, waves
, num_waves
, f
);
700 si_print_annotated_shader(sctx
->ps_shader
.current
, waves
, num_waves
, f
);
702 /* Print waves executing shaders that are not currently bound. */
705 for (i
= 0; i
< num_waves
; i
++) {
706 if (waves
[i
].matched
)
710 fprintf(f
, COLOR_CYAN
711 "Waves not executing currently-bound shaders:"
715 fprintf(f
, " SE%u SH%u CU%u SIMD%u WAVE%u EXEC=%016"PRIx64
716 " INST=%08X %08X PC=%"PRIx64
"\n",
717 waves
[i
].se
, waves
[i
].sh
, waves
[i
].cu
, waves
[i
].simd
,
718 waves
[i
].wave
, waves
[i
].exec
, waves
[i
].inst_dw0
,
719 waves
[i
].inst_dw1
, waves
[i
].pc
);
725 static void si_dump_command(const char *title
, const char *command
, FILE *f
)
729 FILE *p
= popen(command
, "r");
733 fprintf(f
, COLOR_YELLOW
"%s: " COLOR_RESET
"\n", title
);
734 while (fgets(line
, sizeof(line
), p
))
740 static void si_dump_debug_state(struct pipe_context
*ctx
, FILE *f
,
743 struct si_context
*sctx
= (struct si_context
*)ctx
;
745 if (flags
& PIPE_DUMP_DEVICE_STATUS_REGISTERS
)
746 si_dump_debug_registers(sctx
, f
);
748 if (flags
& PIPE_DUMP_CURRENT_STATES
)
749 si_dump_framebuffer(sctx
, f
);
751 if (flags
& PIPE_DUMP_CURRENT_SHADERS
) {
752 si_dump_shader(sctx
->screen
, &sctx
->vs_shader
, f
);
753 si_dump_shader(sctx
->screen
, &sctx
->tcs_shader
, f
);
754 si_dump_shader(sctx
->screen
, &sctx
->tes_shader
, f
);
755 si_dump_shader(sctx
->screen
, &sctx
->gs_shader
, f
);
756 si_dump_shader(sctx
->screen
, &sctx
->ps_shader
, f
);
758 if (flags
& PIPE_DUMP_DEVICE_STATUS_REGISTERS
) {
759 si_dump_annotated_shaders(sctx
, f
);
760 si_dump_command("Active waves (raw data)", "umr -wa | column -t", f
);
761 si_dump_command("Wave information", "umr -O bits -wa", f
);
764 si_dump_descriptor_list(&sctx
->descriptors
[SI_DESCS_RW_BUFFERS
],
765 "", "RW buffers", SI_NUM_RW_BUFFERS
, f
);
766 si_dump_descriptors(sctx
, &sctx
->vs_shader
, f
);
767 si_dump_descriptors(sctx
, &sctx
->tcs_shader
, f
);
768 si_dump_descriptors(sctx
, &sctx
->tes_shader
, f
);
769 si_dump_descriptors(sctx
, &sctx
->gs_shader
, f
);
770 si_dump_descriptors(sctx
, &sctx
->ps_shader
, f
);
773 if (flags
& PIPE_DUMP_LAST_COMMAND_BUFFER
) {
774 si_dump_bo_list(sctx
, &sctx
->last_gfx
, f
);
775 si_dump_last_ib(sctx
, f
);
777 fprintf(f
, "Done.\n");
780 radeon_clear_saved_cs(&sctx
->last_gfx
);
781 r600_resource_reference(&sctx
->last_trace_buf
, NULL
);
785 static void si_dump_dma(struct si_context
*sctx
,
786 struct radeon_saved_cs
*saved
, FILE *f
)
788 static const char ib_name
[] = "sDMA IB";
791 si_dump_bo_list(sctx
, saved
, f
);
793 fprintf(f
, "------------------ %s begin ------------------\n", ib_name
);
795 for (i
= 0; i
< saved
->num_dw
; ++i
) {
796 fprintf(f
, " %08x\n", saved
->ib
[i
]);
799 fprintf(f
, "------------------- %s end -------------------\n", ib_name
);
802 fprintf(f
, "SDMA Dump Done.\n");
805 static bool si_vm_fault_occured(struct si_context
*sctx
, uint32_t *out_addr
)
810 uint64_t timestamp
= 0;
813 FILE *p
= popen("dmesg", "r");
817 while (fgets(line
, sizeof(line
), p
)) {
820 if (!line
[0] || line
[0] == '\n')
823 /* Get the timestamp. */
824 if (sscanf(line
, "[%u.%u]", &sec
, &usec
) != 2) {
825 static bool hit
= false;
827 fprintf(stderr
, "%s: failed to parse line '%s'\n",
833 timestamp
= sec
* 1000000llu + usec
;
835 /* If just updating the timestamp. */
839 /* Process messages only if the timestamp is newer. */
840 if (timestamp
<= sctx
->dmesg_timestamp
)
843 /* Only process the first VM fault. */
847 /* Remove trailing \n */
849 if (len
&& line
[len
-1] == '\n')
852 /* Get the message part. */
853 msg
= strchr(line
, ']');
862 if (strstr(msg
, "GPU fault detected:"))
866 msg
= strstr(msg
, "VM_CONTEXT1_PROTECTION_FAULT_ADDR");
868 msg
= strstr(msg
, "0x");
871 if (sscanf(msg
, "%X", out_addr
) == 1)
883 if (timestamp
> sctx
->dmesg_timestamp
)
884 sctx
->dmesg_timestamp
= timestamp
;
888 void si_check_vm_faults(struct r600_common_context
*ctx
,
889 struct radeon_saved_cs
*saved
, enum ring_type ring
)
891 struct si_context
*sctx
= (struct si_context
*)ctx
;
892 struct pipe_screen
*screen
= sctx
->b
.b
.screen
;
897 if (!si_vm_fault_occured(sctx
, &addr
))
900 f
= dd_get_debug_file(false);
904 fprintf(f
, "VM fault report.\n\n");
905 if (os_get_command_line(cmd_line
, sizeof(cmd_line
)))
906 fprintf(f
, "Command: %s\n", cmd_line
);
907 fprintf(f
, "Driver vendor: %s\n", screen
->get_vendor(screen
));
908 fprintf(f
, "Device vendor: %s\n", screen
->get_device_vendor(screen
));
909 fprintf(f
, "Device name: %s\n\n", screen
->get_name(screen
));
910 fprintf(f
, "Failing VM page: 0x%08x\n\n", addr
);
912 if (sctx
->apitrace_call_number
)
913 fprintf(f
, "Last apitrace call: %u\n\n",
914 sctx
->apitrace_call_number
);
918 si_dump_debug_state(&sctx
->b
.b
, f
,
919 PIPE_DUMP_CURRENT_STATES
|
920 PIPE_DUMP_CURRENT_SHADERS
|
921 PIPE_DUMP_LAST_COMMAND_BUFFER
);
925 si_dump_dma(sctx
, saved
, f
);
934 fprintf(stderr
, "Detected a VM fault, exiting...\n");
938 void si_init_debug_functions(struct si_context
*sctx
)
940 sctx
->b
.b
.dump_debug_state
= si_dump_debug_state
;
941 sctx
->b
.check_vm_faults
= si_check_vm_faults
;
943 /* Set the initial dmesg timestamp for this context, so that
944 * only new messages will be checked for VM faults.
946 if (sctx
->screen
->b
.debug_flags
& DBG_CHECK_VM
)
947 si_vm_fault_occured(sctx
, NULL
);