perfetto/pps-producer: add optimized cpu/gpu timestamp correlation support

The Intel Xe driver added the ability to do cpu/gpu timestamp
correlation giving a much better alignment of timestamps (we use to
have ~20us delta between the 2 samples, just because of the ioctl
barrier potentially sneaking in some work).

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: José Roberto de Souza <jose.souza@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24591>
This commit is contained in:
Lionel Landwerlin 2023-09-01 10:12:39 +03:00 committed by Marge Bot
parent fdec724bd1
commit b2bf141b6a
8 changed files with 51 additions and 2 deletions

View File

@ -710,4 +710,11 @@ FreedrenoDriver::gpu_timestamp() const
return perfetto::base::GetBootTimeNs().count(); return perfetto::base::GetBootTimeNs().count();
} }
bool
FreedrenoDriver::cpu_gpu_timestamp(uint64_t &, uint64_t &) const
{
/* Not supported */
return false;
}
} // namespace pps } // namespace pps

View File

@ -31,6 +31,8 @@ public:
uint64_t next() override; uint64_t next() override;
uint32_t gpu_clock_id() const override; uint32_t gpu_clock_id() const override;
uint64_t gpu_timestamp() const override; uint64_t gpu_timestamp() const override;
bool cpu_gpu_timestamp(uint64_t &cpu_timestamp,
uint64_t &gpu_timestamp) const override;
private: private:
struct fd_device *dev; struct fd_device *dev;

View File

@ -342,4 +342,21 @@ uint64_t IntelDriver::gpu_timestamp() const
return intel_device_info_timebase_scale(&perf->devinfo, timestamp); return intel_device_info_timebase_scale(&perf->devinfo, timestamp);
} }
bool IntelDriver::cpu_gpu_timestamp(uint64_t &cpu_timestamp,
uint64_t &gpu_timestamp) const
{
if (!intel_gem_read_correlate_cpu_gpu_timestamp(drm_device.fd,
perf->devinfo.kmd_type,
INTEL_ENGINE_CLASS_RENDER, 0,
CLOCK_BOOTTIME,
&cpu_timestamp,
&gpu_timestamp,
NULL))
return false;
gpu_timestamp =
intel_device_info_timebase_scale(&perf->devinfo, gpu_timestamp);
return true;
}
} // namespace pps } // namespace pps

View File

@ -49,6 +49,8 @@ class IntelDriver : public Driver
uint64_t next() override; uint64_t next() override;
uint32_t gpu_clock_id() const override; uint32_t gpu_clock_id() const override;
uint64_t gpu_timestamp() const override; uint64_t gpu_timestamp() const override;
bool cpu_gpu_timestamp(uint64_t &cpu_timestamp,
uint64_t &gpu_timestamp) const override;
private: private:
/// @brief Requests the next perf sample /// @brief Requests the next perf sample

View File

@ -180,4 +180,11 @@ PanfrostDriver::gpu_timestamp() const
return perfetto::base::GetBootTimeNs().count(); return perfetto::base::GetBootTimeNs().count();
} }
bool
PanfrostDriver::cpu_gpu_timestamp(uint64_t &, uint64_t &) const
{
/* Not supported */
return false;
}
} // namespace pps } // namespace pps

View File

@ -42,6 +42,8 @@ class PanfrostDriver : public Driver {
uint64_t next() override; uint64_t next() override;
uint32_t gpu_clock_id() const override; uint32_t gpu_clock_id() const override;
uint64_t gpu_timestamp() const override; uint64_t gpu_timestamp() const override;
bool cpu_gpu_timestamp(uint64_t &cpu_timestamp,
uint64_t &gpu_timestamp) const override;
uint64_t last_dump_ts = 0; uint64_t last_dump_ts = 0;

View File

@ -245,8 +245,14 @@ void add_timestamp(perfetto::protos::pbzero::ClockSnapshot *event, const Driver
return; return;
// Send a correlation event between GPU & CPU timestamps // Send a correlation event between GPU & CPU timestamps
uint64_t cpu_ts = perfetto::base::GetBootTimeNs().count(); uint64_t cpu_ts, gpu_ts;
uint64_t gpu_ts = driver->gpu_timestamp();
// Try to use the optimized driver correlation if available, otherwise do a
// separate CPU & GPU sample
if (!driver->cpu_gpu_timestamp(cpu_ts, gpu_ts)) {
cpu_ts = perfetto::base::GetBootTimeNs().count();
gpu_ts = driver->gpu_timestamp();
}
{ {
auto clock = event->add_clocks(); auto clock = event->add_clocks();

View File

@ -84,6 +84,12 @@ class Driver
/// Sample a timestamp from the GPU /// Sample a timestamp from the GPU
virtual uint64_t gpu_timestamp() const = 0; virtual uint64_t gpu_timestamp() const = 0;
/// Sample a timestamp from both the CPU & the GPU
///
/// This is useful when the driver can do a better timestamp correlation
/// than sampling separately CPU & GPU timestamps.
virtual bool cpu_gpu_timestamp(uint64_t &cpu_timestamp, uint64_t &gpu_timestamp) const = 0;
DrmDevice drm_device; DrmDevice drm_device;
/// List of counter groups /// List of counter groups