intel/perf: fix raw query kernel metric selection
[mesa.git] / src / intel / perf / gen_perf.h
index 4f0805f2b269397b79ba3e0f0cc23f7fbc114b88..790719ccbadad3960acea2d5f1d7e1af2d3f39ec 100644 (file)
@@ -25,6 +25,7 @@
 #define GEN_PERF_H
 
 #include <stdio.h>
+#include <stdbool.h>
 #include <stdint.h>
 #include <string.h>
 
@@ -38,6 +39,8 @@
 #include "compiler/glsl/list.h"
 #include "util/ralloc.h"
 
+#include "drm-uapi/i915_drm.h"
+
 struct gen_device_info;
 
 struct gen_perf_config;
@@ -60,6 +63,39 @@ enum gen_perf_counter_data_type {
    GEN_PERF_COUNTER_DATA_TYPE_DOUBLE,
 };
 
+enum gen_perf_counter_units {
+   /* size */
+   GEN_PERF_COUNTER_UNITS_BYTES,
+
+   /* frequency */
+   GEN_PERF_COUNTER_UNITS_HZ,
+
+   /* time */
+   GEN_PERF_COUNTER_UNITS_NS,
+   GEN_PERF_COUNTER_UNITS_US,
+
+   /**/
+   GEN_PERF_COUNTER_UNITS_PIXELS,
+   GEN_PERF_COUNTER_UNITS_TEXELS,
+   GEN_PERF_COUNTER_UNITS_THREADS,
+   GEN_PERF_COUNTER_UNITS_PERCENT,
+
+   /* events */
+   GEN_PERF_COUNTER_UNITS_MESSAGES,
+   GEN_PERF_COUNTER_UNITS_NUMBER,
+   GEN_PERF_COUNTER_UNITS_CYCLES,
+   GEN_PERF_COUNTER_UNITS_EVENTS,
+   GEN_PERF_COUNTER_UNITS_UTILIZATION,
+
+   /**/
+   GEN_PERF_COUNTER_UNITS_EU_SENDS_TO_L3_CACHE_LINES,
+   GEN_PERF_COUNTER_UNITS_EU_ATOMIC_REQUESTS_TO_L3_CACHE_LINES,
+   GEN_PERF_COUNTER_UNITS_EU_REQUESTS_TO_L3_CACHE_LINES,
+   GEN_PERF_COUNTER_UNITS_EU_BYTES_PER_L3_CACHE_LINE,
+
+   GEN_PERF_COUNTER_UNITS_MAX
+};
+
 struct gen_pipeline_stat {
    uint32_t reg;
    uint32_t numerator;
@@ -128,8 +164,11 @@ struct gen_perf_query_result {
 struct gen_perf_query_counter {
    const char *name;
    const char *desc;
+   const char *symbol_name;
+   const char *category;
    enum gen_perf_counter_type type;
    enum gen_perf_counter_data_type data_type;
+   enum gen_perf_counter_units units;
    uint64_t raw_max;
    size_t offset;
 
@@ -151,13 +190,13 @@ struct gen_perf_query_register_prog {
 
 /* Register programming for a given query */
 struct gen_perf_registers {
-   struct gen_perf_query_register_prog *flex_regs;
+   const struct gen_perf_query_register_prog *flex_regs;
    uint32_t n_flex_regs;
 
-   struct gen_perf_query_register_prog *mux_regs;
+   const struct gen_perf_query_register_prog *mux_regs;
    uint32_t n_mux_regs;
 
-   struct gen_perf_query_register_prog *b_counter_regs;
+   const struct gen_perf_query_register_prog *b_counter_regs;
    uint32_t n_b_counter_regs;
 };
 
@@ -168,6 +207,7 @@ struct gen_perf_query_info {
       GEN_PERF_QUERY_TYPE_PIPELINE,
    } kind;
    const char *name;
+   const char *symbol_name;
    const char *guid;
    struct gen_perf_query_counter *counters;
    int n_counters;
@@ -188,6 +228,21 @@ struct gen_perf_query_info {
    struct gen_perf_registers config;
 };
 
+struct gen_perf_query_counter_info {
+   struct gen_perf_query_counter *counter;
+
+   uint64_t query_mask;
+
+   /**
+    * Each counter can be a part of many groups, each time at different index.
+    * This struct stores one of those locations.
+    */
+   struct {
+      int group_idx; /* query/group number */
+      int counter_idx; /* index inside of query/group */
+   } location;
+};
+
 struct gen_perf_config {
    /* Whether i915 has DRM_I915_QUERY_PERF_CONFIG support. */
    bool i915_query_supported;
@@ -195,9 +250,15 @@ struct gen_perf_config {
    /* Version of the i915-perf subsystem, refer to i915_drm.h. */
    int i915_perf_version;
 
+   /* Powergating configuration for the running the query. */
+   struct drm_i915_gem_context_param_sseu sseu;
+
    struct gen_perf_query_info *queries;
    int n_queries;
 
+   struct gen_perf_query_counter_info *counter_infos;
+   int n_counters;
+
    /* Variables referenced in the XML meta data for OA performance
     * counters, e.g in the normalization equations.
     *
@@ -222,6 +283,17 @@ struct gen_perf_config {
     */
    struct hash_table *oa_metrics_table;
 
+   /* When MDAPI hasn't configured the metric we need to use by the time the
+    * query begins, this OA metric is used as a fallback.
+    */
+   uint64_t fallback_raw_oa_metric;
+
+   /* Whether we have support for this platform. If true && n_queries == 0,
+    * this means we will not be able to use i915-perf because of it is in
+    * paranoid mode.
+    */
+   bool platform_supported;
+
    /* Location of the device's sysfs entry. */
    char sysfs_dev_dir[256];
 
@@ -245,9 +317,16 @@ struct gen_perf_config {
    } vtbl;
 };
 
+struct gen_perf_counter_pass {
+   struct gen_perf_query_info *query;
+   struct gen_perf_query_counter *counter;
+   uint32_t pass;
+};
+
 void gen_perf_init_metrics(struct gen_perf_config *perf_cfg,
                            const struct gen_device_info *devinfo,
-                           int drm_fd);
+                           int drm_fd,
+                           bool include_pipeline_statistics);
 
 /** Query i915 for a metric id using guid.
  */
@@ -310,4 +389,13 @@ gen_perf_new(void *ctx)
    return perf;
 }
 
+uint32_t gen_perf_get_n_passes(struct gen_perf_config *perf,
+                               const uint32_t *counter_indices,
+                               uint32_t counter_indices_count,
+                               struct gen_perf_query_info **pass_queries);
+void gen_perf_get_counters_passes(struct gen_perf_config *perf,
+                                  const uint32_t *counter_indices,
+                                  uint32_t counter_indices_count,
+                                  struct gen_perf_counter_pass *counter_pass);
+
 #endif /* GEN_PERF_H */