ac/spm: introduce ac_spm_trace and ac_spm_get_trace()
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Wed, 26 Apr 2023 08:55:28 +0000 (10:55 +0200)
committerMarge Bot <emma+marge@anholt.net>
Thu, 27 Apr 2023 07:24:54 +0000 (07:24 +0000)
For more code isolation.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22707>

src/amd/common/ac_rgp.c
src/amd/common/ac_rgp.h
src/amd/common/ac_spm.c
src/amd/common/ac_spm.h
src/amd/vulkan/layers/radv_sqtt_layer.c
src/gallium/drivers/radeonsi/si_sqtt.c

index 6271444..c7dde6f 100644 (file)
@@ -892,7 +892,7 @@ struct sqtt_file_chunk_spm_db {
 static_assert(sizeof(struct sqtt_file_chunk_spm_db) == 32,
               "sqtt_file_chunk_spm_db doesn't match RGP spec");
 
-static void ac_sqtt_fill_spm_db(const struct ac_spm_trace_data *spm_trace,
+static void ac_sqtt_fill_spm_db(const struct ac_spm_trace *spm_trace,
                                 struct sqtt_file_chunk_spm_db *chunk,
                                 uint32_t num_samples,
                                 uint32_t chunk_size)
@@ -909,12 +909,12 @@ static void ac_sqtt_fill_spm_db(const struct ac_spm_trace_data *spm_trace,
    chunk->sample_interval = spm_trace->sample_interval;
 }
 
-static void ac_sqtt_dump_spm(const struct ac_spm_trace_data *spm_trace,
+static void ac_sqtt_dump_spm(const struct ac_spm_trace *spm_trace,
                              size_t file_offset,
                              FILE *output)
 {
-   uint32_t sample_size_in_bytes = ac_spm_get_sample_size(spm_trace);
-   uint32_t num_samples = ac_spm_get_num_samples(spm_trace);
+   uint32_t sample_size_in_bytes = spm_trace->sample_size_in_bytes;
+   uint32_t num_samples = spm_trace->num_samples;
    uint8_t *spm_data_ptr = (uint8_t *)spm_trace->ptr;
    struct sqtt_file_chunk_spm_db spm_db;
    size_t file_spm_db_offset = file_offset;
@@ -983,7 +983,7 @@ static void ac_sqtt_dump_spm(const struct ac_spm_trace_data *spm_trace,
 #if defined(USE_LIBELF)
 static void ac_sqtt_dump_data(struct radeon_info *rad_info,
                               struct ac_thread_trace *thread_trace,
-                              const struct ac_spm_trace_data *spm_trace,
+                              const struct ac_spm_trace *spm_trace,
                               FILE *output)
 {
    struct ac_thread_trace_data *thread_trace_data = thread_trace->data;
@@ -1171,7 +1171,7 @@ static void ac_sqtt_dump_data(struct radeon_info *rad_info,
 
 int ac_dump_rgp_capture(struct radeon_info *info,
                         struct ac_thread_trace *thread_trace,
-                        const struct ac_spm_trace_data *spm_trace)
+                        const struct ac_spm_trace *spm_trace)
 {
 #if !defined(USE_LIBELF)
    return -1;
index b53bb02..c33129d 100644 (file)
@@ -34,7 +34,7 @@
 struct radeon_info;
 struct ac_thread_trace;
 struct ac_thread_trace_data;
-struct ac_spm_trace_data;
+struct ac_spm_trace;
 
 enum rgp_hardware_stages {
    RGP_HW_STAGE_VS = 0,
@@ -191,7 +191,7 @@ struct rgp_clock_calibration {
 int
 ac_dump_rgp_capture(struct radeon_info *info,
                     struct ac_thread_trace *thread_trace,
-                    const struct ac_spm_trace_data *spm_trace);
+                    const struct ac_spm_trace *spm_trace);
 
 void
 ac_rgp_file_write_elf_object(FILE *output, size_t file_elf_start,
index 2e28556..b8546be 100644 (file)
@@ -342,7 +342,7 @@ void ac_destroy_spm(struct ac_spm_trace_data *spm_trace)
    FREE(spm_trace->counters);
 }
 
-uint32_t ac_spm_get_sample_size(const struct ac_spm_trace_data *spm_trace)
+static uint32_t ac_spm_get_sample_size(const struct ac_spm_trace_data *spm_trace)
 {
    uint32_t sample_size = 0; /* in bytes */
 
@@ -353,7 +353,7 @@ uint32_t ac_spm_get_sample_size(const struct ac_spm_trace_data *spm_trace)
    return sample_size;
 }
 
-uint32_t ac_spm_get_num_samples(const struct ac_spm_trace_data *spm_trace)
+static uint32_t ac_spm_get_num_samples(const struct ac_spm_trace_data *spm_trace)
 {
    uint32_t sample_size = ac_spm_get_sample_size(spm_trace);
    uint32_t *ptr = (uint32_t *)spm_trace->ptr;
@@ -375,3 +375,16 @@ uint32_t ac_spm_get_num_samples(const struct ac_spm_trace_data *spm_trace)
 
    return num_samples;
 }
+
+void ac_spm_get_trace(const struct ac_spm_trace_data *spm,
+                      struct ac_spm_trace *trace)
+{
+   memset(trace, 0, sizeof(*trace));
+
+   trace->ptr = spm->ptr;
+   trace->sample_interval = spm->sample_interval;
+   trace->num_counters = spm->num_counters;
+   trace->counters = spm->counters;
+   trace->sample_size_in_bytes = ac_spm_get_sample_size(spm);
+   trace->num_samples = ac_spm_get_num_samples(spm);
+}
index 8ce49f8..1fc6c71 100644 (file)
@@ -112,6 +112,15 @@ struct ac_spm_trace_data {
    struct ac_spm_muxsel_line *muxsel_lines[AC_SPM_SEGMENT_TYPE_COUNT];
 };
 
+struct ac_spm_trace {
+   void *ptr;
+   uint16_t sample_interval;
+   unsigned num_counters;
+   struct ac_spm_counter_info *counters;
+   uint32_t sample_size_in_bytes;
+   uint32_t num_samples;
+};
+
 bool ac_init_spm(const struct radeon_info *info,
                  const struct ac_perfcounters *pc,
                  unsigned num_counters,
@@ -119,7 +128,7 @@ bool ac_init_spm(const struct radeon_info *info,
                  struct ac_spm_trace_data *spm_trace);
 void ac_destroy_spm(struct ac_spm_trace_data *spm_trace);
 
-uint32_t ac_spm_get_sample_size(const struct ac_spm_trace_data *spm_trace);
-uint32_t ac_spm_get_num_samples(const struct ac_spm_trace_data *spm_trace);
+void ac_spm_get_trace(const struct ac_spm_trace_data *spm,
+                      struct ac_spm_trace *trace);
 
 #endif
index d0afb8b..310f9fb 100644 (file)
@@ -541,12 +541,13 @@ radv_handle_thread_trace(VkQueue _queue)
       queue->device->vk.dispatch_table.QueueWaitIdle(_queue);
 
       if (radv_get_thread_trace(queue, &thread_trace)) {
-         struct ac_spm_trace_data *spm_trace = NULL;
+         struct ac_spm_trace spm_trace;
 
          if (queue->device->spm_trace.bo)
-            spm_trace = &queue->device->spm_trace;
+            ac_spm_get_trace(&queue->device->spm_trace, &spm_trace);
 
-         ac_dump_rgp_capture(&queue->device->physical_device->rad_info, &thread_trace, spm_trace);
+         ac_dump_rgp_capture(&queue->device->physical_device->rad_info, &thread_trace,
+                             queue->device->spm_trace.bo ? &spm_trace : NULL);
       } else {
          /* Trigger a new capture if the driver failed to get
           * the trace because the buffer was too small.
index 49840b9..1b8228a 100644 (file)
@@ -849,12 +849,16 @@ si_handle_thread_trace(struct si_context *sctx, struct radeon_cmdbuf *rcs)
       /* Wait for SQTT to finish and read back the bo */
       if (sctx->ws->fence_wait(sctx->ws, sctx->last_sqtt_fence, PIPE_TIMEOUT_INFINITE) &&
           si_get_thread_trace(sctx, &thread_trace)) {
+         struct ac_spm_trace spm_trace;
+
          /* Map the SPM counter buffer */
-         if (sctx->spm_trace.bo)
+         if (sctx->spm_trace.bo) {
             sctx->spm_trace.ptr = sctx->ws->buffer_map(sctx->ws, sctx->spm_trace.bo,
                                                        NULL, PIPE_MAP_READ | RADEON_MAP_TEMPORARY);
+            ac_spm_get_trace(&sctx->spm_trace, &spm_trace);
+         }
 
-         ac_dump_rgp_capture(&sctx->screen->info, &thread_trace, sctx->spm_trace.bo ? &sctx->spm_trace : NULL);
+         ac_dump_rgp_capture(&sctx->screen->info, &thread_trace, sctx->spm_trace.bo ? &spm_trace : NULL);
 
          if (sctx->spm_trace.ptr)
             sctx->ws->buffer_unmap(sctx->ws, sctx->spm_trace.bo);