radeonsi/sqtt: support sqtt buffer auto-resizing

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29073>
This commit is contained in:
Pierre-Eric Pelloux-Prayer 2023-11-13 21:48:22 +01:00 committed by Marge Bot
parent 316fff7d41
commit 5794a86f19

View file

@ -36,8 +36,6 @@ static bool si_sqtt_init_bo(struct si_context *sctx)
1 << SQTT_BUFFER_ALIGN_SHIFT);
size += sctx->sqtt->buffer_size * (uint64_t)max_se;
sctx->sqtt->pipeline_bos = _mesa_hash_table_u64_create(NULL);
sctx->sqtt->bo =
ws->buffer_create(ws, size, 4096, RADEON_DOMAIN_VRAM,
RADEON_FLAG_NO_INTERPROCESS_SHARING |
@ -562,11 +560,28 @@ static void si_end_sqtt(struct si_context *sctx, struct radeon_cmdbuf *rcs)
sctx->ws->cs_flush(cs, 0, &sctx->last_sqtt_fence);
}
static bool
si_sqtt_resize_bo(struct si_context *sctx)
{
/* Destroy the previous thread trace BO. */
struct pb_buffer_lean *bo = sctx->sqtt->bo;
radeon_bo_reference(sctx->screen->ws, &bo, NULL);
/* Double the size of the thread trace buffer per SE. */
sctx->sqtt->buffer_size *= 2;
fprintf(stderr,
"Failed to get the thread trace because the buffer "
"was too small, resizing to %d KB\n",
sctx->sqtt->buffer_size / 1024);
/* Re-create the thread trace BO. */
return si_sqtt_init_bo(sctx);
}
static bool si_get_sqtt_trace(struct si_context *sctx,
struct ac_sqtt_trace *sqtt)
{
unsigned max_se = sctx->screen->info.max_se;
memset(sqtt, 0, sizeof(*sqtt));
sctx->sqtt->ptr =
@ -576,34 +591,17 @@ static bool si_get_sqtt_trace(struct si_context *sctx,
return false;
if (!ac_sqtt_get_trace(sctx->sqtt, &sctx->screen->info, sqtt)) {
void *sqtt_ptr = sctx->sqtt->ptr;
for (unsigned se = 0; se < max_se; se++) {
uint64_t info_offset = ac_sqtt_get_info_offset(se);
void *info_ptr = sqtt_ptr + info_offset;
struct ac_sqtt_data_info *info = (struct ac_sqtt_data_info *)info_ptr;
if (ac_sqtt_se_is_disabled(&sctx->screen->info, se))
continue;
if (!ac_is_sqtt_complete(&sctx->screen->info, sctx->sqtt, info)) {
uint32_t expected_size =
ac_get_expected_buffer_size(&sctx->screen->info, info);
uint32_t available_size = (info->cur_offset * 32) / 1024;
fprintf(stderr,
"Failed to get the thread trace "
"because the buffer is too small. The "
"hardware needs %d KB but the "
"buffer size is %d KB.\n",
expected_size, available_size);
fprintf(stderr, "Please update the buffer size with "
"AMD_THREAD_TRACE_BUFFER_SIZE=<size_in_kbytes>\n");
if (!si_sqtt_resize_bo(sctx)) {
fprintf(stderr, "radeonsi: Failed to resize the SQTT buffer.\n");
} else {
for (int i = 0; i < ARRAY_SIZE(sctx->sqtt->start_cs); i++) {
sctx->screen->ws->cs_destroy(sctx->sqtt->start_cs[i]);
sctx->screen->ws->cs_destroy(sctx->sqtt->stop_cs[i]);
}
si_sqtt_init_cs(sctx);
}
return false;
}
}
}
return true;
}
@ -650,6 +648,8 @@ bool si_init_sqtt(struct si_context *sctx)
if (!si_sqtt_init_bo(sctx))
return false;
sctx->sqtt->pipeline_bos = _mesa_hash_table_u64_create(NULL);
ac_sqtt_init(sctx->sqtt);
if (sctx->gfx_level >= GFX10 &&
@ -795,6 +795,9 @@ void si_handle_sqtt(struct si_context *sctx, struct radeon_cmdbuf *rcs)
sctx->ws->buffer_unmap(sctx->ws, sctx->spm.bo);
} else {
fprintf(stderr, "Failed to read the trace\n");
if (!sctx->sqtt->trigger_file) {
sctx->sqtt->start_frame = num_frames + 10;
}
}
}