freedreno/ds: Use gpu timestamps

This will simplify things for PERFCNTR_CONFIG, where we will be getting
GPU timestamps along with the sampled counter values.

Signed-off-by: Rob Clark <rob.clark@oss.qualcomm.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41315>
This commit is contained in:
Rob Clark 2026-04-27 14:25:39 -07:00 committed by Marge Bot
parent e4b77237ac
commit 5ca8c2107e

View file

@ -14,6 +14,7 @@
#include "drm/freedreno_ringbuffer.h"
#include "perfcntrs/freedreno_dt.h"
#include "perfcntrs/freedreno_perfcntr.h"
#include "util/hash_table.h"
#include "pps/pps.h"
#include "pps/pps_algorithm.h"
@ -1493,12 +1494,21 @@ FreedrenoDriver::configure_counters(bool reset, bool wait)
void
FreedrenoDriver::collect_countables()
{
last_dump_ts = perfetto::base::GetBootTimeNs().count();
last_dump_ts = gpu_timestamp();
for (const auto &countable : countables)
countable.collect();
}
static uint64_t
ticks_to_ns(uint64_t ticks)
{
constexpr uint64_t ALWAYS_ON_FREQUENCY_HZ = 19200000;
constexpr double GPU_TICKS_PER_NS = ALWAYS_ON_FREQUENCY_HZ / 1000000000.0;
return ticks / GPU_TICKS_PER_NS;
}
bool
FreedrenoDriver::init_perfcnt()
{
@ -1617,7 +1627,7 @@ FreedrenoDriver::dump_perfcnt()
collect_countables();
auto elapsed_time_ns = last_dump_ts - last_ts;
auto elapsed_time_ns = ticks_to_ns(last_dump_ts - last_ts);
time = (float)elapsed_time_ns / 1000000000.0;
@ -1777,13 +1787,26 @@ FreedrenoDriver::counter(std::string name, Counter::Units units,
uint32_t
FreedrenoDriver::gpu_clock_id() const
{
return perfetto::protos::pbzero::BUILTIN_CLOCK_BOOTTIME;
static uint32_t gpu_clock_id;
if (!gpu_clock_id) {
/* Note: clock_id's below 128 are reserved.. for custom clock sources,
* using the hash of a namespaced string is the recommended approach.
* See: https://perfetto.dev/docs/concepts/clock-sync
*/
gpu_clock_id =
_mesa_hash_string("org.freedesktop.pps.freedreno") | 0x80000000;
}
return gpu_clock_id;
}
uint64_t
FreedrenoDriver::gpu_timestamp() const
{
return perfetto::base::GetBootTimeNs().count();
uint64_t ts;
fd_pipe_get_param(pipe, FD_TIMESTAMP, &ts);
return ts;
}
bool