a1c0a6199793877f2116afad4914d05a13ad8396
2 * Copyright © 2016 Red Hat.
3 * Copyright © 2016 Bas Nieuwenhuizen
5 * based in part on anv driver which is:
6 * Copyright © 2015 Intel Corporation
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
32 #include "radv_debug.h"
33 #include "radv_shader.h"
36 radv_init_trace(struct radv_device
*device
)
38 struct radeon_winsys
*ws
= device
->ws
;
40 device
->trace_bo
= ws
->buffer_create(ws
, 4096, 8, RADEON_DOMAIN_VRAM
,
41 RADEON_FLAG_CPU_ACCESS
);
42 if (!device
->trace_bo
)
45 device
->trace_id_ptr
= ws
->buffer_map(device
->trace_bo
);
46 if (!device
->trace_id_ptr
)
49 ac_vm_fault_occured(device
->physical_device
->rad_info
.chip_class
,
50 &device
->dmesg_timestamp
, NULL
);
56 radv_dump_trace(struct radv_device
*device
, struct radeon_winsys_cs
*cs
)
58 const char *filename
= getenv("RADV_TRACE_FILE");
59 FILE *f
= fopen(filename
, "w");
62 fprintf(stderr
, "Failed to write trace dump to %s\n", filename
);
66 fprintf(f
, "Trace ID: %x\n", *device
->trace_id_ptr
);
67 device
->ws
->cs_dump(cs
, f
, (const int*)device
->trace_id_ptr
, 2);
72 radv_gpu_hang_occured(struct radv_queue
*queue
)
74 struct radeon_winsys
*ws
= queue
->device
->ws
;
77 ring
= radv_queue_family_to_ring(queue
->queue_family_index
);
79 if (!ws
->ctx_wait_idle(queue
->hw_ctx
, ring
, queue
->queue_idx
))
86 radv_check_gpu_hangs(struct radv_queue
*queue
, struct radeon_winsys_cs
*cs
)
88 struct radv_device
*device
= queue
->device
;
91 if (!radv_gpu_hang_occured(queue
))
94 if (ac_vm_fault_occured(device
->physical_device
->rad_info
.chip_class
,
95 &device
->dmesg_timestamp
, &addr
)) {
96 fprintf(stderr
, "VM fault report.\n\n");
97 fprintf(stderr
, "Failing VM page: 0x%08"PRIx64
"\n\n", addr
);
100 radv_dump_trace(queue
->device
, cs
);
105 radv_print_spirv(struct radv_shader_module
*module
, FILE *fp
)
107 char path
[] = "/tmp/fileXXXXXX";
108 char line
[2048], command
[128];
112 /* Dump the binary into a temporary file. */
117 if (write(fd
, module
->data
, module
->size
) == -1)
120 sprintf(command
, "spirv-dis %s", path
);
122 /* Disassemble using spirv-dis if installed. */
123 p
= popen(command
, "r");
125 while (fgets(line
, sizeof(line
), p
))
126 fprintf(fp
, "%s", line
);