intel/perf: fix how pipeline stats are stored
[mesa.git] / src / intel / perf / gen_perf_query.c
index 3ad511b0e0083895172665337039a687b1474cc2..3d4f922b2b3c7b2e33847b6715df9e4cd4653a76 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "perf/gen_perf.h"
 #include "perf/gen_perf_mdapi.h"
+#include "perf/gen_perf_private.h"
 #include "perf/gen_perf_query.h"
 #include "perf/gen_perf_regs.h"
 
@@ -347,6 +348,8 @@ gen_perf_close(struct gen_perf_context *perfquery,
    }
 }
 
+#define NUM_PERF_PROPERTIES(array) (ARRAY_SIZE(array) / 2)
+
 static bool
 gen_perf_open(struct gen_perf_context *perf_ctx,
               int metrics_set_id,
@@ -366,12 +369,17 @@ gen_perf_open(struct gen_perf_context *perf_ctx,
       DRM_I915_PERF_PROP_OA_METRICS_SET, metrics_set_id,
       DRM_I915_PERF_PROP_OA_FORMAT, report_format,
       DRM_I915_PERF_PROP_OA_EXPONENT, period_exponent,
+
+      /* SSEU configuration */
+      DRM_I915_PERF_PROP_GLOBAL_SSEU, to_user_pointer(&perf_ctx->perf->sseu),
    };
    struct drm_i915_perf_open_param param = {
       .flags = I915_PERF_FLAG_FD_CLOEXEC |
                I915_PERF_FLAG_FD_NONBLOCK |
                I915_PERF_FLAG_DISABLED,
-      .num_properties = ARRAY_SIZE(properties) / 2,
+      .num_properties = perf_ctx->perf->i915_perf_version >= 4 ?
+                        NUM_PERF_PROPERTIES(properties) :
+                        NUM_PERF_PROPERTIES(properties) - 1,
       .properties_ptr = (uintptr_t) properties,
    };
    int fd = gen_ioctl(drm_fd, DRM_IOCTL_I915_PERF_OPEN, &param);
@@ -617,7 +625,7 @@ snapshot_statistics_registers(struct gen_perf_context *ctx,
 
       perf->vtbl.store_register_mem(ctx->ctx, obj->pipeline_stats.bo,
                                     counter->pipeline_stat.reg, 8,
-                                    offset_in_bytes + i * sizeof(uint64_t));
+                                    offset_in_bytes + counter->offset);
    }
 }
 
@@ -1461,7 +1469,9 @@ get_oa_counter_data(struct gen_perf_context *perf_ctx,
             /* So far we aren't using uint32, double or bool32... */
             unreachable("unexpected counter data type");
          }
-         written = counter->offset + counter_size;
+
+         if (counter->offset + counter_size > written)
+            written = counter->offset + counter_size;
       }
    }