Mesa (main): pps: fixup sporadic missing counters

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Nov 22 12:17:08 UTC 2021


Module: Mesa
Branch: main
Commit: 21a1c6995c3ee0fa8374247914784f083919150f
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=21a1c6995c3ee0fa8374247914784f083919150f

Author: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
Date:   Wed Nov 17 10:34:23 2021 +0200

pps: fixup sporadic missing counters

The issue seems to be that without proper timestamps & clock_id, the
recording might discard some packets if they go backward in time.

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
Reviewed-by: Antonio Caggiano <antonio.caggiano at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13831>

---

 src/tool/pps/pps_datasource.cc | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/src/tool/pps/pps_datasource.cc b/src/tool/pps/pps_datasource.cc
index 9eac41b9ade..5584e9833ea 100644
--- a/src/tool/pps/pps_datasource.cc
+++ b/src/tool/pps/pps_datasource.cc
@@ -111,6 +111,8 @@ void GpuDataSource::OnStart(const StartArgs &args)
 void close_callback(GpuDataSource::TraceContext ctx)
 {
    auto packet = ctx.NewTracePacket();
+   packet->set_timestamp_clock_id(perfetto::protos::pbzero::BUILTIN_CLOCK_BOOTTIME);
+   packet->set_timestamp(perfetto::base::GetBootTimeNs().count());
    packet->Finalize();
    ctx.Flush();
    PPS_LOG("Context flushed");
@@ -263,35 +265,43 @@ void GpuDataSource::trace(TraceContext &ctx)
 {
    using namespace perfetto::protos::pbzero;
 
-   auto state = ctx.GetIncrementalState();
-   if (state->was_cleared) {
-      // Mark any incremental state before this point invalid
+   if (auto state = ctx.GetIncrementalState(); state->was_cleared) {
+      descriptor_timestamp = perfetto::base::GetBootTimeNs().count();
+
       {
+         // Mark any incremental state before this point invalid
          auto packet = ctx.NewTracePacket();
-         packet->set_timestamp(perfetto::base::GetBootTimeNs().count());
+         packet->set_timestamp_clock_id(perfetto::protos::pbzero::BUILTIN_CLOCK_BOOTTIME);
+         packet->set_timestamp(descriptor_timestamp);
          packet->set_sequence_flags(TracePacket::SEQ_INCREMENTAL_STATE_CLEARED);
       }
 
-      auto packet = ctx.NewTracePacket();
       descriptor_timestamp = perfetto::base::GetBootTimeNs().count();
-      packet->set_timestamp(descriptor_timestamp);
-
       {
+         // Counter descriptions
+         auto packet = ctx.NewTracePacket();
+         packet->set_timestamp_clock_id(perfetto::protos::pbzero::BUILTIN_CLOCK_BOOTTIME);
+         packet->set_timestamp(descriptor_timestamp);
          auto event = packet->set_gpu_counter_event();
          event->set_gpu_id(driver->drm_device.gpu_num);
 
          auto &groups = driver->groups;
          auto &counters = driver->enabled_counters;
-         PPS_LOG("Sending counter descriptors");
          add_descriptors(event, groups, counters, *driver);
       }
 
       {
+         // Initial timestamp correlation event
+         auto packet = ctx.NewTracePacket();
+         packet->set_timestamp_clock_id(perfetto::protos::pbzero::BUILTIN_CLOCK_BOOTTIME);
+         packet->set_timestamp(descriptor_timestamp);
          last_correlation_timestamp = perfetto::base::GetBootTimeNs().count();
          auto event = packet->set_clock_snapshot();
          add_timestamp(event, driver);
       }
 
+      // Capture GPU timestamp of the first packet. Anything prior to this can
+      // be discarded.
       descriptor_gpu_timestamp = driver->gpu_timestamp();
       state->was_cleared = false;
    }
@@ -330,6 +340,8 @@ void GpuDataSource::trace(TraceContext &ctx)
    uint64_t cpu_ts = perfetto::base::GetBootTimeNs().count();
    if ((cpu_ts - last_correlation_timestamp) > CORRELATION_TIMESTAMP_PERIOD) {
       auto packet = ctx.NewTracePacket();
+      packet->set_timestamp_clock_id(perfetto::protos::pbzero::BUILTIN_CLOCK_BOOTTIME);
+      packet->set_timestamp(cpu_ts);
       auto event = packet->set_clock_snapshot();
       add_timestamp(event, driver);
       last_correlation_timestamp = cpu_ts;



More information about the mesa-commit mailing list