ac/radv: move sqtt structs and helpers to amd/common
authorPierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Tue, 8 Dec 2020 10:31:08 +0000 (11:31 +0100)
committerPierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Thu, 7 Jan 2021 09:09:47 +0000 (10:09 +0100)
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Acked-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8002>

src/amd/Makefile.sources
src/amd/common/ac_sqtt.c [new file with mode: 0644]
src/amd/common/ac_sqtt.h
src/amd/common/meson.build
src/amd/vulkan/layers/radv_sqtt_layer.c
src/amd/vulkan/radv_private.h
src/amd/vulkan/radv_rgp.c
src/amd/vulkan/radv_sqtt.c

index 3c408ff..b14ddb0 100644 (file)
@@ -52,6 +52,7 @@ AMD_COMMON_FILES = \
        common/ac_shader_util.h \
        common/ac_shadowed_regs.c \
        common/ac_shadowed_regs.h \
+       common/ac_sqtt.c \
        common/ac_sqtt.h
 
 AMD_COMMON_LLVM_FILES = \
diff --git a/src/amd/common/ac_sqtt.c b/src/amd/common/ac_sqtt.c
new file mode 100644 (file)
index 0000000..bdf4b87
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2020 Advanced Micro Devices, Inc.
+ * Copyright 2020 Valve Corporation
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, and/or sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "ac_sqtt.h"
+
+#include "util/u_math.h"
+
+uint64_t
+ac_thread_trace_get_info_offset(unsigned se)
+{
+   return sizeof(struct ac_thread_trace_info) * se;
+}
+
+uint64_t
+ac_thread_trace_get_data_offset(struct ac_thread_trace_data *data, unsigned se)
+{
+   uint64_t data_offset;
+
+   data_offset = align64(sizeof(struct ac_thread_trace_info) * 4,
+               1 << SQTT_BUFFER_ALIGN_SHIFT);
+   data_offset += data->buffer_size * se;
+
+   return data_offset;
+}
+
+uint64_t
+ac_thread_trace_get_info_va(uint64_t va, unsigned se)
+{
+   return va + ac_thread_trace_get_info_offset(se);
+}
+
+uint64_t
+ac_thread_trace_get_data_va(struct ac_thread_trace_data *data, uint64_t va, unsigned se)
+{
+   return va + ac_thread_trace_get_data_offset(data, se);
+}
index 778850d..9680be4 100644 (file)
@@ -26,6 +26,8 @@
 #ifndef AC_SQTT_H
 #define AC_SQTT_H
 
+#include <stdint.h>
+
 struct ac_thread_trace_data {
    struct radeon_cmdbuf *start_cs[2];
    struct radeon_cmdbuf *stop_cs[2];
@@ -37,4 +39,38 @@ struct ac_thread_trace_data {
    char *trigger_file;
 };
 
+#define SQTT_BUFFER_ALIGN_SHIFT 12
+
+struct ac_thread_trace_info {
+   uint32_t cur_offset;
+   uint32_t trace_status;
+   union {
+      uint32_t gfx9_write_counter;
+      uint32_t gfx10_dropped_cntr;
+   };
+};
+
+struct ac_thread_trace_se {
+   struct ac_thread_trace_info info;
+   void *data_ptr;
+   uint32_t shader_engine;
+   uint32_t compute_unit;
+};
+
+struct ac_thread_trace {
+   uint32_t num_traces;
+   struct ac_thread_trace_se traces[4];
+};
+
+uint64_t
+ac_thread_trace_get_info_offset(unsigned se);
+
+uint64_t
+ac_thread_trace_get_data_offset(struct ac_thread_trace_data *data, unsigned se);
+uint64_t
+ac_thread_trace_get_info_va(uint64_t va, unsigned se);
+
+uint64_t
+ac_thread_trace_get_data_va(struct ac_thread_trace_data *data, uint64_t va, unsigned se);
+
 #endif
index c734db5..d0e7fee 100644 (file)
@@ -80,6 +80,7 @@ amd_common_files = files(
   'ac_debug.h',
   'ac_shadowed_regs.c',
   'ac_shadowed_regs.h',
+  'ac_sqtt.c',
   'ac_sqtt.h',
 )
 
index bf80dce..0f6761b 100644 (file)
@@ -624,7 +624,7 @@ radv_handle_thread_trace(VkQueue _queue)
        static uint64_t num_frames = 0;
 
        if (thread_trace_enabled) {
-               struct radv_thread_trace thread_trace = {0};
+               struct ac_thread_trace thread_trace = {0};
 
                radv_end_thread_trace(queue);
                thread_trace_enabled = false;
index d2a674d..6ac7e07 100644 (file)
@@ -2554,41 +2554,18 @@ void radv_nir_shader_info_pass(const struct nir_shader *nir,
 
 void radv_nir_shader_info_init(struct radv_shader_info *info);
 
-/* radv_sqtt.c */
-struct radv_thread_trace_info {
-       uint32_t cur_offset;
-       uint32_t trace_status;
-       union {
-               uint32_t gfx9_write_counter;
-               uint32_t gfx10_dropped_cntr;
-       };
-};
-
-struct radv_thread_trace_se {
-       struct radv_thread_trace_info info;
-       void *data_ptr;
-       uint32_t shader_engine;
-       uint32_t compute_unit;
-};
-
-struct radv_thread_trace {
-       uint32_t num_traces;
-       struct radv_thread_trace_se traces[4];
-};
-
 bool radv_thread_trace_init(struct radv_device *device);
 void radv_thread_trace_finish(struct radv_device *device);
 bool radv_begin_thread_trace(struct radv_queue *queue);
 bool radv_end_thread_trace(struct radv_queue *queue);
 bool radv_get_thread_trace(struct radv_queue *queue,
-                          struct radv_thread_trace *thread_trace);
+                          struct ac_thread_trace *thread_trace);
 void radv_emit_thread_trace_userdata(const struct radv_device *device,
                                     struct radeon_cmdbuf *cs,
                                     const void *data, uint32_t num_dwords);
-
 /* radv_rgp.c */
 int radv_dump_thread_trace(struct radv_device *device,
-                          const struct radv_thread_trace *trace);
+                           const struct ac_thread_trace *trace);
 
 /* radv_sqtt_layer_.c */
 struct radv_barrier_data {
index 1f889ed..7037e51 100644 (file)
@@ -583,7 +583,7 @@ radv_sqtt_fill_sqtt_data(struct sqtt_file_chunk_sqtt_data *chunk,
 
 static void
 radv_sqtt_dump_data(struct radv_device *device,
-                   const struct radv_thread_trace *thread_trace,
+                   const struct ac_thread_trace *thread_trace,
                    FILE *output)
 {
        struct sqtt_file_chunk_asic_info asic_info = {0};
@@ -614,8 +614,8 @@ radv_sqtt_dump_data(struct radv_device *device,
 
        if (thread_trace) {
                for (unsigned i = 0; i < thread_trace->num_traces; i++) {
-                       const struct radv_thread_trace_se *se = &thread_trace->traces[i];
-                       const struct radv_thread_trace_info *info = &se->info;
+                       const struct ac_thread_trace_se *se = &thread_trace->traces[i];
+                       const struct ac_thread_trace_info *info = &se->info;
                        struct sqtt_file_chunk_sqtt_desc desc = {0};
                        struct sqtt_file_chunk_sqtt_data data = {0};
                        uint64_t size = info->cur_offset * 32; /* unit of 32 bytes */
@@ -641,7 +641,7 @@ radv_sqtt_dump_data(struct radv_device *device,
 
 int
 radv_dump_thread_trace(struct radv_device *device,
-                      const struct radv_thread_trace *thread_trace)
+                      const struct ac_thread_trace *thread_trace)
 {
        char filename[2048];
        struct tm now;
index 634efa5..5f176d9 100644 (file)
 
 #define SQTT_BUFFER_ALIGN_SHIFT 12
 
-static uint64_t
-radv_thread_trace_get_info_offset(unsigned se)
-{
-       return sizeof(struct radv_thread_trace_info) * se;
-}
-
-static uint64_t
-radv_thread_trace_get_data_offset(struct radv_device *device, unsigned se)
-{
-       uint64_t data_offset;
-
-       data_offset = align64(sizeof(struct radv_thread_trace_info) * 4,
-                             1 << SQTT_BUFFER_ALIGN_SHIFT);
-       data_offset += device->thread_trace.buffer_size * se;
-
-       return data_offset;
-}
-
-static uint64_t
-radv_thread_trace_get_info_va(struct radv_device *device, unsigned se)
-{
-       uint64_t va = radv_buffer_get_va(device->thread_trace.bo);
-       return va + radv_thread_trace_get_info_offset(se);
-}
-
-static uint64_t
-radv_thread_trace_get_data_va(struct radv_device *device, unsigned se)
-{
-       uint64_t va = radv_buffer_get_va(device->thread_trace.bo);
-       return va + radv_thread_trace_get_data_offset(device, se);
-}
 
 static void
 radv_emit_thread_trace_start(struct radv_device *device,
@@ -72,7 +41,8 @@ radv_emit_thread_trace_start(struct radv_device *device,
        assert(device->physical_device->rad_info.chip_class >= GFX8);
 
        for (unsigned se = 0; se < max_se; se++) {
-               uint64_t data_va = radv_thread_trace_get_data_va(device, se);
+               uint64_t va = radv_buffer_get_va(device->thread_trace.bo);
+               uint64_t data_va = ac_thread_trace_get_data_va(&device->thread_trace, va, se);
                uint64_t shifted_va = data_va >> SQTT_BUFFER_ALIGN_SHIFT;
 
                /* Target SEx and SH0. */
@@ -250,7 +220,8 @@ radv_copy_thread_trace_info_regs(struct radv_device *device,
        }
 
        /* Get the VA where the info struct is stored for this SE. */
-       uint64_t info_va = radv_thread_trace_get_info_va(device, se_index);
+       uint64_t va = radv_buffer_get_va(device->thread_trace.bo);
+       uint64_t info_va = ac_thread_trace_get_info_va(va, se_index);
 
        /* Copy back the info struct one DWORD at a time. */
        for (unsigned i = 0; i < 3; i++) {
@@ -504,7 +475,7 @@ radv_thread_trace_init_bo(struct radv_device *device)
                                                   1u << SQTT_BUFFER_ALIGN_SHIFT);
 
        /* Compute total size of the thread trace BO for 4 SEs. */
-       size = align64(sizeof(struct radv_thread_trace_info) * 4,
+       size = align64(sizeof(struct ac_thread_trace_info) * 4,
                       1 << SQTT_BUFFER_ALIGN_SHIFT);
        size += device->thread_trace.buffer_size * 4;
 
@@ -568,7 +539,7 @@ radv_end_thread_trace(struct radv_queue *queue)
 
 static bool
 radv_is_thread_trace_complete(struct radv_device *device,
-                             const struct radv_thread_trace_info *info)
+                             const struct ac_thread_trace_info *info)
 {
        if (device->physical_device->rad_info.chip_class == GFX10) {
                /* GFX10 doesn't have THREAD_TRACE_CNTR but it reports the
@@ -586,7 +557,7 @@ radv_is_thread_trace_complete(struct radv_device *device,
 
 static uint32_t
 radv_get_expected_buffer_size(struct radv_device *device,
-                             const struct radv_thread_trace_info *info)
+                             const struct ac_thread_trace_info *info)
 {
        if (device->physical_device->rad_info.chip_class == GFX10) {
                uint32_t dropped_cntr_per_se = info->gfx10_dropped_cntr / device->physical_device->rad_info.max_se;
@@ -598,7 +569,7 @@ radv_get_expected_buffer_size(struct radv_device *device,
 
 bool
 radv_get_thread_trace(struct radv_queue *queue,
-                     struct radv_thread_trace *thread_trace)
+                     struct ac_thread_trace *thread_trace)
 {
        struct radv_device *device = queue->device;
        unsigned max_se = device->physical_device->rad_info.max_se;
@@ -608,13 +579,13 @@ radv_get_thread_trace(struct radv_queue *queue,
        thread_trace->num_traces = max_se;
 
        for (unsigned se = 0; se < max_se; se++) {
-               uint64_t info_offset = radv_thread_trace_get_info_offset(se);
-               uint64_t data_offset = radv_thread_trace_get_data_offset(device, se);
+               uint64_t info_offset = ac_thread_trace_get_info_offset(se);
+               uint64_t data_offset = ac_thread_trace_get_data_offset(&device->thread_trace, se);
                void *info_ptr = thread_trace_ptr + info_offset;
                void *data_ptr = thread_trace_ptr + data_offset;
-               struct radv_thread_trace_info *info =
-                       (struct radv_thread_trace_info *)info_ptr;
-               struct radv_thread_trace_se thread_trace_se = {0};
+               struct ac_thread_trace_info *info =
+                       (struct ac_thread_trace_info *)info_ptr;
+               struct ac_thread_trace_se thread_trace_se = {0};
 
                if (!radv_is_thread_trace_complete(device, info)) {
                        uint32_t expected_size =