i965: move mdapi result data format to intel/perf
authorLionel Landwerlin <lionel.g.landwerlin@intel.com>
Fri, 8 Jun 2018 16:53:08 +0000 (17:53 +0100)
committerLionel Landwerlin <lionel.g.landwerlin@intel.com>
Wed, 17 Apr 2019 13:10:42 +0000 (14:10 +0100)
We want to reuse this in Anv.

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Mark Janes <mark.a.janes@intel.com>
src/intel/Makefile.sources
src/intel/perf/gen_perf_mdapi.c [new file with mode: 0644]
src/intel/perf/gen_perf_mdapi.h
src/intel/perf/meson.build
src/mesa/drivers/dri/i965/brw_performance_query.c
src/mesa/drivers/dri/i965/brw_performance_query.h
src/mesa/drivers/dri/i965/brw_performance_query_mdapi.c

index 2aaa7feee5350cc10c8ce1466746f2c0ba5c40c2..dc1425c8c1c0b50c915453f069cea2eb593e1c21 100644 (file)
@@ -334,7 +334,8 @@ GEN_PERF_XML_FILES = \
 GEN_PERF_FILES = \
        perf/gen_perf.c \
        perf/gen_perf.h \
-       perf/gen_perf_mdapi.h
+       perf/gen_perf_mdapi.h \
+       perf/gen_perf_mdapi.c
 
 GEN_PERF_GENERATED_FILES = \
        perf/gen_perf_metrics.c \
diff --git a/src/intel/perf/gen_perf_mdapi.c b/src/intel/perf/gen_perf_mdapi.c
new file mode 100644 (file)
index 0000000..38ca230
--- /dev/null
@@ -0,0 +1,116 @@
+/*
+ * Copyright © 2018 Intel Corporation
+ *
+ * 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
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * 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 NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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 "gen_perf.h"
+#include "gen_perf_mdapi.h"
+
+#include "dev/gen_device_info.h"
+
+int
+gen_perf_query_result_write_mdapi(void *data, uint32_t data_size,
+                                  const struct gen_device_info *devinfo,
+                                  const struct gen_perf_query_result *result,
+                                  uint64_t freq_start, uint64_t freq_end)
+{
+   switch (devinfo->gen) {
+   case 7: {
+      struct gen7_mdapi_metrics *mdapi_data = (struct gen7_mdapi_metrics *) data;
+
+      if (data_size < sizeof(*mdapi_data))
+         return 0;
+
+      assert(devinfo->is_haswell);
+
+      for (int i = 0; i < ARRAY_SIZE(mdapi_data->ACounters); i++)
+         mdapi_data->ACounters[i] = result->accumulator[1 + i];
+
+      for (int i = 0; i < ARRAY_SIZE(mdapi_data->NOACounters); i++) {
+         mdapi_data->NOACounters[i] =
+            result->accumulator[1 + ARRAY_SIZE(mdapi_data->ACounters) + i];
+      }
+
+      mdapi_data->ReportsCount = result->reports_accumulated;
+      mdapi_data->TotalTime =
+         gen_device_info_timebase_scale(devinfo, result->accumulator[0]);
+      mdapi_data->CoreFrequency = freq_end;
+      mdapi_data->CoreFrequencyChanged = freq_end != freq_start;
+      return sizeof(*mdapi_data);
+   }
+   case 8: {
+      struct gen8_mdapi_metrics *mdapi_data = (struct gen8_mdapi_metrics *) data;
+
+      if (data_size < sizeof(*mdapi_data))
+         return 0;
+
+      for (int i = 0; i < ARRAY_SIZE(mdapi_data->OaCntr); i++)
+         mdapi_data->OaCntr[i] = result->accumulator[2 + i];
+      for (int i = 0; i < ARRAY_SIZE(mdapi_data->NoaCntr); i++) {
+         mdapi_data->NoaCntr[i] =
+            result->accumulator[2 + ARRAY_SIZE(mdapi_data->OaCntr) + i];
+      }
+
+      mdapi_data->ReportId = result->hw_id;
+      mdapi_data->ReportsCount = result->reports_accumulated;
+      mdapi_data->TotalTime =
+         gen_device_info_timebase_scale(devinfo, result->accumulator[0]);
+      mdapi_data->GPUTicks = result->accumulator[1];
+      mdapi_data->CoreFrequency = freq_end;
+      mdapi_data->CoreFrequencyChanged = freq_end != freq_start;
+      mdapi_data->SliceFrequency =
+         (result->slice_frequency[0] + result->slice_frequency[1]) / 2ULL;
+      mdapi_data->UnsliceFrequency =
+         (result->unslice_frequency[0] + result->unslice_frequency[1]) / 2ULL;
+      return sizeof(*mdapi_data);
+   }
+   case 9:
+   case 10:
+   case 11: {
+      struct gen9_mdapi_metrics *mdapi_data = (struct gen9_mdapi_metrics *) data;
+
+      if (data_size < sizeof(*mdapi_data))
+         return 0;
+
+      for (int i = 0; i < ARRAY_SIZE(mdapi_data->OaCntr); i++)
+         mdapi_data->OaCntr[i] = result->accumulator[2 + i];
+      for (int i = 0; i < ARRAY_SIZE(mdapi_data->NoaCntr); i++) {
+         mdapi_data->NoaCntr[i] =
+            result->accumulator[2 + ARRAY_SIZE(mdapi_data->OaCntr) + i];
+      }
+
+      mdapi_data->ReportId = result->hw_id;
+      mdapi_data->ReportsCount = result->reports_accumulated;
+      mdapi_data->TotalTime =
+         gen_device_info_timebase_scale(devinfo, result->accumulator[0]);
+      mdapi_data->GPUTicks = result->accumulator[1];
+      mdapi_data->CoreFrequency = freq_end;
+      mdapi_data->CoreFrequencyChanged = freq_end != freq_start;
+      mdapi_data->SliceFrequency =
+         (result->slice_frequency[0] + result->slice_frequency[1]) / 2ULL;
+      mdapi_data->UnsliceFrequency =
+         (result->unslice_frequency[0] + result->unslice_frequency[1]) / 2ULL;
+      return sizeof(*mdapi_data);
+   }
+   default:
+      unreachable("unexpected gen");
+   }
+}
index dcaa8c3ebeb37abacee2dac1ab96c89f2aae2c00..fcdee07901341859314422c05b13b333f61cfffe 100644 (file)
@@ -26,6 +26,9 @@
 
 #include <stdint.h>
 
+struct gen_device_info;
+struct gen_perf_query_result;
+
 /*
  * Data format expected by MDAPI.
  */
@@ -116,4 +119,9 @@ struct mdapi_pipeline_metrics {
    uint64_t CSInvocations;
 };
 
+int gen_perf_query_result_write_mdapi(void *data, uint32_t data_size,
+                                      const struct gen_device_info *devinfo,
+                                      const struct gen_perf_query_result *result,
+                                      uint64_t freq_start, uint64_t freq_end);
+
 #endif /* GEN_PERF_MDAPI_H */
index 3620f6885a4b6499432298bd237cbf8e1127d77f..d6426d0958a78ec318b3bc4d1233871f787fc471 100644 (file)
@@ -15,7 +15,8 @@ foreach hw : gen_hw_metrics
 endforeach
 
 gen_perf_sources = [
-  'gen_perf.c'
+  'gen_perf.c',
+  'gen_perf_mdapi.c',
 ]
 
 gen_perf_sources += custom_target(
index b3b34a82da78e6ef163af7b0902b8d102245cb3a..831ad97a6750fe99c4250f5b40498ae5a3bdd692 100644 (file)
@@ -74,6 +74,7 @@
 #include "intel_batchbuffer.h"
 
 #include "perf/gen_perf.h"
+#include "perf/gen_perf_mdapi.h"
 
 #define FILE_DEBUG_FLAG DEBUG_PERFMON
 
@@ -1488,10 +1489,16 @@ brw_get_perf_query_data(struct gl_context *ctx,
          brw_bo_unmap(obj->oa.bo);
          obj->oa.map = NULL;
       }
-      if (obj->query->kind == GEN_PERF_QUERY_TYPE_OA)
+      if (obj->query->kind == GEN_PERF_QUERY_TYPE_OA) {
          written = get_oa_counter_data(brw, obj, data_size, (uint8_t *)data);
-      else
-         written = brw_perf_query_get_mdapi_oa_data(brw, obj, data_size, (uint8_t *)data);
+      } else {
+         const struct gen_device_info *devinfo = &brw->screen->devinfo;
+
+         written = gen_perf_query_result_write_mdapi((uint8_t *)data, data_size,
+                                                     devinfo, &obj->oa.result,
+                                                     obj->oa.gt_frequency[0],
+                                                     obj->oa.gt_frequency[1]);
+      }
       break;
 
    case GEN_PERF_QUERY_TYPE_PIPELINE:
index 86632e06a61878516af4340ffd3b4188344de578..b0bf60cc4fffd547659e661153fa7b142d7afc3e 100644 (file)
@@ -114,10 +114,6 @@ struct brw_perf_query_object
    };
 };
 
-int brw_perf_query_get_mdapi_oa_data(struct brw_context *brw,
-                                     struct brw_perf_query_object *obj,
-                                     size_t data_size,
-                                     uint8_t *data);
 void brw_perf_query_register_mdapi_oa_query(struct brw_context *brw);
 void brw_perf_query_register_mdapi_statistic_query(struct brw_context *brw);
 
index 919069f9e39766d0db0cb3edbc1ec0a0b4c476cf..fbdbca1260c163432ff88755ef9e9bea59e668e9 100644 (file)
 #include "perf/gen_perf.h"
 #include "perf/gen_perf_mdapi.h"
 
-int
-brw_perf_query_get_mdapi_oa_data(struct brw_context *brw,
-                                 struct brw_perf_query_object *obj,
-                                 size_t data_size,
-                                 uint8_t *data)
-{
-   const struct gen_device_info *devinfo = &brw->screen->devinfo;
-   const struct gen_perf_query_result *result = &obj->oa.result;
-
-   switch (devinfo->gen) {
-   case 7: {
-      struct gen7_mdapi_metrics *mdapi_data = (struct gen7_mdapi_metrics *) data;
-
-      if (data_size < sizeof(*mdapi_data))
-         return 0;
-
-      assert(devinfo->is_haswell);
-
-      for (int i = 0; i < ARRAY_SIZE(mdapi_data->ACounters); i++)
-         mdapi_data->ACounters[i] = result->accumulator[1 + i];
-
-      for (int i = 0; i < ARRAY_SIZE(mdapi_data->NOACounters); i++) {
-         mdapi_data->NOACounters[i] =
-            result->accumulator[1 + ARRAY_SIZE(mdapi_data->ACounters) + i];
-      }
-
-      mdapi_data->ReportsCount = result->reports_accumulated;
-      mdapi_data->TotalTime = gen_device_info_timebase_scale(devinfo, result->accumulator[0]);
-      mdapi_data->CoreFrequency = obj->oa.gt_frequency[1];
-      mdapi_data->CoreFrequencyChanged = obj->oa.gt_frequency[0] != obj->oa.gt_frequency[1];
-      return sizeof(*mdapi_data);
-   }
-   case 8: {
-      struct gen8_mdapi_metrics *mdapi_data = (struct gen8_mdapi_metrics *) data;
-
-      if (data_size < sizeof(*mdapi_data))
-         return 0;
-
-      for (int i = 0; i < ARRAY_SIZE(mdapi_data->OaCntr); i++)
-         mdapi_data->OaCntr[i] = result->accumulator[2 + i];
-      for (int i = 0; i < ARRAY_SIZE(mdapi_data->NoaCntr); i++) {
-         mdapi_data->NoaCntr[i] =
-            result->accumulator[2 + ARRAY_SIZE(mdapi_data->OaCntr) + i];
-      }
-
-      mdapi_data->ReportId = result->hw_id;
-      mdapi_data->ReportsCount = result->reports_accumulated;
-      mdapi_data->TotalTime = gen_device_info_timebase_scale(devinfo, result->accumulator[0]);
-      mdapi_data->GPUTicks = result->accumulator[1];
-      mdapi_data->CoreFrequency = obj->oa.gt_frequency[1];
-      mdapi_data->CoreFrequencyChanged = obj->oa.gt_frequency[0] != obj->oa.gt_frequency[1];
-      mdapi_data->SliceFrequency = (result->slice_frequency[0] + result->slice_frequency[1]) / 2ULL;
-      mdapi_data->UnsliceFrequency = (result->unslice_frequency[0] + result->unslice_frequency[1]) / 2ULL;
-
-      return sizeof(*mdapi_data);
-   }
-   case 9:
-   case 10:
-   case 11: {
-      struct gen9_mdapi_metrics *mdapi_data = (struct gen9_mdapi_metrics *) data;
-
-      if (data_size < sizeof(*mdapi_data))
-         return 0;
-
-      for (int i = 0; i < ARRAY_SIZE(mdapi_data->OaCntr); i++)
-         mdapi_data->OaCntr[i] = result->accumulator[2 + i];
-      for (int i = 0; i < ARRAY_SIZE(mdapi_data->NoaCntr); i++) {
-         mdapi_data->NoaCntr[i] =
-            result->accumulator[2 + ARRAY_SIZE(mdapi_data->OaCntr) + i];
-      }
-
-      mdapi_data->ReportId = result->hw_id;
-      mdapi_data->ReportsCount = result->reports_accumulated;
-      mdapi_data->TotalTime = gen_device_info_timebase_scale(devinfo, result->accumulator[0]);
-      mdapi_data->GPUTicks = result->accumulator[1];
-      mdapi_data->CoreFrequency = obj->oa.gt_frequency[1];
-      mdapi_data->CoreFrequencyChanged = obj->oa.gt_frequency[0] != obj->oa.gt_frequency[1];
-      mdapi_data->SliceFrequency = (result->slice_frequency[0] + result->slice_frequency[1]) / 2ULL;
-      mdapi_data->UnsliceFrequency = (result->unslice_frequency[0] + result->unslice_frequency[1]) / 2ULL;
-
-      return sizeof(*mdapi_data);
-   }
-   default:
-      unreachable("unexpected gen");
-   }
-
-   return 0;
-}
-
 static void
 fill_mdapi_perf_query_counter(struct gen_perf_query_info *query,
                               const char *name,