From 1a4bfb1fcd052fb0ffe180e7897d711777a78da2 Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Sat, 13 Sep 2025 16:23:07 -0700 Subject: [PATCH] panvk: fix broken clock sync after using CLOCK_MONOTONIC_RAW Use sequence-scoped clock (64 <= ID < 128) for GPU clock because there's no central daemon emitting consistent snapshots for synchronization between CPU and GPU clocks on behalf of renderstages and counters producers. When CPU clock is the same with the authoritative trace clock (normally default to CLOCK_BOOTTIME), perfetto drops the non-monotonic snapshots to ensure validity of the global source clock in the resolution graph. When they are different, the clocks are marked invalid and the rest of the clock syncs will fail during trace processing. Now that PanVK has switched to use CLOCK_MONOTONIC_RAW CPU clock, here we make the GPU clock sequence-scoped so that clock sync for all the trace packets emitted with the same trusted_packet_sequence_id will be done in an isolated manner (basically perfetto makes each scoped GPU clock globally unique). Meanwhile, since the clock is now sequence-scoped (unique per producer + writer pair within the tracing session), we can simply pick 64 to start with, and later extend to support multi-gpu (offset with primary minor). Fixes: e278a89fddd ("panvk/perfetto: improve clock synchronization using CLOCK_MONOTONIC_RAW") Reviewed-by: Mary Guillemard Reviewed-by: Chia-I Wu Part-of: --- src/panfrost/vulkan/panvk_utrace_perfetto.cc | 26 ++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/panfrost/vulkan/panvk_utrace_perfetto.cc b/src/panfrost/vulkan/panvk_utrace_perfetto.cc index f71a36bf79a..ed5bd37e98b 100644 --- a/src/panfrost/vulkan/panvk_utrace_perfetto.cc +++ b/src/panfrost/vulkan/panvk_utrace_perfetto.cc @@ -288,8 +288,30 @@ PANVK_UTRACE_PERFETTO_PROCESS_EVENT(sync64_wait, SYNC_WAIT) static uint32_t get_gpu_clock_id(void) { - /* see https://perfetto.dev/docs/concepts/clock-sync */ - return _mesa_hash_string("org.freedesktop.mesa.panfrost") | 0x80000000; + /* see https://perfetto.dev/docs/concepts/clock-sync + * + * Use sequence-scoped clock (64 <= ID < 128) for GPU clock because there's + * no central daemon emitting consistent snapshots for synchronization + * between CPU and GPU clocks on behalf of renderstages and counters + * producers. + * + * When CPU clock is the same with the authoritative trace clock (normally + * default to CLOCK_BOOTTIME), perfetto drops the non-monotonic snapshots + * to ensure validity of the global source clock in the resolution graph. + * When they are different, the clocks are marked invalid and the rest of + * the clock syncs will fail during trace processing. + * + * Now that PanVK has switched to use CLOCK_MONOTONIC_RAW CPU clock, here + * we make the GPU clock sequence-scoped so that clock sync for all the + * trace packets emitted with the same trusted_packet_sequence_id will be + * done in an isolated manner (basically perfetto makes each scoped GPU + * clock globally unique). + * + * Meanwhile, since the clock is now sequence-scoped (unique per producer + + * writer pair within the tracing session), we can simply pick 64 to start + * with since there's no multi-mali-gpu setup yet. + */ + return 64; } static void