From 0d6faa21f81fd62569ec2f2fa3fc9ccdd51986b1 Mon Sep 17 00:00:00 2001 From: Mark Collins Date: Fri, 12 Jul 2024 11:19:25 +0000 Subject: [PATCH] tu/kgsl: Spin unti KGSL reports queue timestamp during profiling KGSL writes the profiling values asynchronously while we read them immediately after the IOCTL returns which can result in the struct not being filled in by the time we read it, this results in AGI not correctly processing any timestamps from larger submits which take longer to queue. To fix this, we now busy-wait on until the value has been written out by KGSL. Signed-off-by: Mark Collins Part-of: --- src/freedreno/vulkan/tu_knl_kgsl.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/freedreno/vulkan/tu_knl_kgsl.cc b/src/freedreno/vulkan/tu_knl_kgsl.cc index da7ad4982c1..fe591f23184 100644 --- a/src/freedreno/vulkan/tu_knl_kgsl.cc +++ b/src/freedreno/vulkan/tu_knl_kgsl.cc @@ -1220,6 +1220,7 @@ kgsl_queue_submit(struct tu_queue *queue, struct vk_queue_submit *vk_submit) }; profiling_buffer = (struct kgsl_cmdbatch_profiling_buffer *) tu_suballoc_bo_map(bo); + memset(profiling_buffer, 0, sizeof(*profiling_buffer)); } if (tu_autotune_submit_requires_fence(cmd_buffers, cmdbuf_count)) { @@ -1300,7 +1301,13 @@ kgsl_queue_submit(struct tu_queue *queue, struct vk_queue_submit *vk_submit) uint64_t gpu_offset = 0; #if HAVE_PERFETTO - if (profiling_buffer && profiling_buffer->gpu_ticks_queued) { + if (profiling_buffer) { + /* We need to wait for KGSL to queue the GPU command before we can read + * the timestamp. Since this is just for profiling and doesn't take too + * long, we can just busy-wait for it. + */ + while (p_atomic_read(&profiling_buffer->gpu_ticks_queued) == 0); + struct kgsl_perfcounter_read_group perf = { .groupid = KGSL_PERFCOUNTER_GROUP_ALWAYSON, .countable = 0,