2 * Copyright © 2018 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
31 #if defined(MAJOR_IN_SYSMACROS)
32 #include <sys/sysmacros.h>
33 #elif defined(MAJOR_IN_MKDEV)
34 #include <sys/mkdev.h>
37 #include "util/hash_table.h"
38 #include "compiler/glsl/list.h"
39 #include "util/ralloc.h"
41 #include "drm-uapi/i915_drm.h"
43 struct gen_device_info
;
45 struct gen_perf_config
;
46 struct gen_perf_query_info
;
48 enum gen_perf_counter_type
{
49 GEN_PERF_COUNTER_TYPE_EVENT
,
50 GEN_PERF_COUNTER_TYPE_DURATION_NORM
,
51 GEN_PERF_COUNTER_TYPE_DURATION_RAW
,
52 GEN_PERF_COUNTER_TYPE_THROUGHPUT
,
53 GEN_PERF_COUNTER_TYPE_RAW
,
54 GEN_PERF_COUNTER_TYPE_TIMESTAMP
,
57 enum gen_perf_counter_data_type
{
58 GEN_PERF_COUNTER_DATA_TYPE_BOOL32
,
59 GEN_PERF_COUNTER_DATA_TYPE_UINT32
,
60 GEN_PERF_COUNTER_DATA_TYPE_UINT64
,
61 GEN_PERF_COUNTER_DATA_TYPE_FLOAT
,
62 GEN_PERF_COUNTER_DATA_TYPE_DOUBLE
,
65 struct gen_pipeline_stat
{
72 * The largest OA formats we can use include:
74 * 1 timestamp, 45 A counters, 8 B counters and 8 C counters.
76 * 1 timestamp, 1 clock, 36 A counters, 8 B counters and 8 C counters
78 #define MAX_OA_REPORT_COUNTERS 62
81 * When currently allocate only one page for pipeline statistics queries. Here
82 * we derived the maximum number of counters for that amount.
84 #define STATS_BO_SIZE 4096
85 #define STATS_BO_END_OFFSET_BYTES (STATS_BO_SIZE / 2)
86 #define MAX_STAT_COUNTERS (STATS_BO_END_OFFSET_BYTES / 8)
88 #define I915_PERF_OA_SAMPLE_SIZE (8 + /* drm_i915_perf_record_header */ \
89 256) /* OA counter report */
91 struct gen_perf_query_result
{
93 * Storage for the final accumulated OA counters.
95 uint64_t accumulator
[MAX_OA_REPORT_COUNTERS
];
98 * Hw ID used by the context on which the query was running.
103 * Number of reports accumulated to produce the results.
105 uint32_t reports_accumulated
;
108 * Frequency in the slices of the GT at the begin and end of the
111 uint64_t slice_frequency
[2];
114 * Frequency in the unslice of the GT at the begin and end of the
117 uint64_t unslice_frequency
[2];
120 * Timestamp of the query.
122 uint64_t begin_timestamp
;
125 * Whether the query was interrupted by another workload (aka preemption).
130 struct gen_perf_query_counter
{
133 const char *symbol_name
;
134 enum gen_perf_counter_type type
;
135 enum gen_perf_counter_data_type data_type
;
141 uint64_t (*oa_counter_read_uint64
)(struct gen_perf_config
*perf
,
142 const struct gen_perf_query_info
*query
,
143 const uint64_t *accumulator
);
144 float (*oa_counter_read_float
)(struct gen_perf_config
*perf
,
145 const struct gen_perf_query_info
*query
,
146 const uint64_t *accumulator
);
147 struct gen_pipeline_stat pipeline_stat
;
151 struct gen_perf_query_register_prog
{
156 /* Register programming for a given query */
157 struct gen_perf_registers
{
158 struct gen_perf_query_register_prog
*flex_regs
;
159 uint32_t n_flex_regs
;
161 struct gen_perf_query_register_prog
*mux_regs
;
164 struct gen_perf_query_register_prog
*b_counter_regs
;
165 uint32_t n_b_counter_regs
;
168 struct gen_perf_query_info
{
169 enum gen_perf_query_type
{
170 GEN_PERF_QUERY_TYPE_OA
,
171 GEN_PERF_QUERY_TYPE_RAW
,
172 GEN_PERF_QUERY_TYPE_PIPELINE
,
176 struct gen_perf_query_counter
*counters
;
182 uint64_t oa_metrics_set_id
;
185 /* For indexing into the accumulator[] ... */
187 int gpu_clock_offset
;
192 struct gen_perf_registers config
;
195 struct gen_perf_config
{
196 /* Whether i915 has DRM_I915_QUERY_PERF_CONFIG support. */
197 bool i915_query_supported
;
199 /* Version of the i915-perf subsystem, refer to i915_drm.h. */
200 int i915_perf_version
;
202 /* Powergating configuration for the running the query. */
203 struct drm_i915_gem_context_param_sseu sseu
;
205 struct gen_perf_query_info
*queries
;
208 struct gen_perf_query_counter
**counters
;
211 /* Variables referenced in the XML meta data for OA performance
212 * counters, e.g in the normalization equations.
214 * All uint64_t for consistent operand types in generated code
217 uint64_t timestamp_frequency
; /** $GpuTimestampFrequency */
218 uint64_t n_eus
; /** $EuCoresTotalCount */
219 uint64_t n_eu_slices
; /** $EuSlicesTotalCount */
220 uint64_t n_eu_sub_slices
; /** $EuSubslicesTotalCount */
221 uint64_t eu_threads_count
; /** $EuThreadsCount */
222 uint64_t slice_mask
; /** $SliceMask */
223 uint64_t subslice_mask
; /** $SubsliceMask */
224 uint64_t gt_min_freq
; /** $GpuMinFrequency */
225 uint64_t gt_max_freq
; /** $GpuMaxFrequency */
226 uint64_t revision
; /** $SkuRevisionId */
229 /* OA metric sets, indexed by GUID, as know by Mesa at build time, to
230 * cross-reference with the GUIDs of configs advertised by the kernel at
233 struct hash_table
*oa_metrics_table
;
235 /* Location of the device's sysfs entry. */
236 char sysfs_dev_dir
[256];
239 void *(*bo_alloc
)(void *bufmgr
, const char *name
, uint64_t size
);
240 void (*bo_unreference
)(void *bo
);
241 void *(*bo_map
)(void *ctx
, void *bo
, unsigned flags
);
242 void (*bo_unmap
)(void *bo
);
243 bool (*batch_references
)(void *batch
, void *bo
);
244 void (*bo_wait_rendering
)(void *bo
);
245 int (*bo_busy
)(void *bo
);
246 void (*emit_stall_at_pixel_scoreboard
)(void *ctx
);
247 void (*emit_mi_report_perf_count
)(void *ctx
,
249 uint32_t offset_in_bytes
,
251 void (*batchbuffer_flush
)(void *ctx
,
252 const char *file
, int line
);
253 void (*store_register_mem
)(void *ctx
, void *bo
, uint32_t reg
, uint32_t reg_size
, uint32_t offset
);
258 void gen_perf_init_metrics(struct gen_perf_config
*perf_cfg
,
259 const struct gen_device_info
*devinfo
,
261 bool include_pipeline_statistics
);
263 /** Query i915 for a metric id using guid.
265 bool gen_perf_load_metric_id(struct gen_perf_config
*perf_cfg
,
267 uint64_t *metric_id
);
269 /** Load a configuation's content from i915 using a guid.
271 struct gen_perf_registers
*gen_perf_load_configuration(struct gen_perf_config
*perf_cfg
,
272 int fd
, const char *guid
);
274 /** Store a configuration into i915 using guid and return a new metric id.
276 * If guid is NULL, then a generated one will be provided by hashing the
277 * content of the configuration.
279 uint64_t gen_perf_store_configuration(struct gen_perf_config
*perf_cfg
, int fd
,
280 const struct gen_perf_registers
*config
,
283 /** Read the slice/unslice frequency from 2 OA reports and store then into
286 void gen_perf_query_result_read_frequencies(struct gen_perf_query_result
*result
,
287 const struct gen_device_info
*devinfo
,
288 const uint32_t *start
,
289 const uint32_t *end
);
290 /** Accumulate the delta between 2 OA reports into result for a given query.
292 void gen_perf_query_result_accumulate(struct gen_perf_query_result
*result
,
293 const struct gen_perf_query_info
*query
,
294 const uint32_t *start
,
295 const uint32_t *end
);
296 void gen_perf_query_result_clear(struct gen_perf_query_result
*result
);
299 gen_perf_query_counter_get_size(const struct gen_perf_query_counter
*counter
)
301 switch (counter
->data_type
) {
302 case GEN_PERF_COUNTER_DATA_TYPE_BOOL32
:
303 return sizeof(uint32_t);
304 case GEN_PERF_COUNTER_DATA_TYPE_UINT32
:
305 return sizeof(uint32_t);
306 case GEN_PERF_COUNTER_DATA_TYPE_UINT64
:
307 return sizeof(uint64_t);
308 case GEN_PERF_COUNTER_DATA_TYPE_FLOAT
:
309 return sizeof(float);
310 case GEN_PERF_COUNTER_DATA_TYPE_DOUBLE
:
311 return sizeof(double);
313 unreachable("invalid counter data type");
317 static inline struct gen_perf_config
*
318 gen_perf_new(void *ctx
)
320 struct gen_perf_config
*perf
= rzalloc(ctx
, struct gen_perf_config
);
324 uint32_t gen_perf_get_n_passes(struct gen_perf_config
*perf
,
325 const uint32_t *counter_indices
,
326 uint32_t counter_indices_count
,
327 struct gen_perf_query_info
**pass_queries
);
329 #endif /* GEN_PERF_H */