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 struct gen_device_info
;
43 struct gen_perf_config
;
44 struct gen_perf_query_info
;
46 enum gen_perf_counter_type
{
47 GEN_PERF_COUNTER_TYPE_EVENT
,
48 GEN_PERF_COUNTER_TYPE_DURATION_NORM
,
49 GEN_PERF_COUNTER_TYPE_DURATION_RAW
,
50 GEN_PERF_COUNTER_TYPE_THROUGHPUT
,
51 GEN_PERF_COUNTER_TYPE_RAW
,
52 GEN_PERF_COUNTER_TYPE_TIMESTAMP
,
55 enum gen_perf_counter_data_type
{
56 GEN_PERF_COUNTER_DATA_TYPE_BOOL32
,
57 GEN_PERF_COUNTER_DATA_TYPE_UINT32
,
58 GEN_PERF_COUNTER_DATA_TYPE_UINT64
,
59 GEN_PERF_COUNTER_DATA_TYPE_FLOAT
,
60 GEN_PERF_COUNTER_DATA_TYPE_DOUBLE
,
63 struct gen_pipeline_stat
{
70 * The largest OA formats we can use include:
72 * 1 timestamp, 45 A counters, 8 B counters and 8 C counters.
74 * 1 timestamp, 1 clock, 36 A counters, 8 B counters and 8 C counters
76 #define MAX_OA_REPORT_COUNTERS 62
79 * When currently allocate only one page for pipeline statistics queries. Here
80 * we derived the maximum number of counters for that amount.
82 #define STATS_BO_SIZE 4096
83 #define STATS_BO_END_OFFSET_BYTES (STATS_BO_SIZE / 2)
84 #define MAX_STAT_COUNTERS (STATS_BO_END_OFFSET_BYTES / 8)
86 #define I915_PERF_OA_SAMPLE_SIZE (8 + /* drm_i915_perf_record_header */ \
87 256) /* OA counter report */
89 struct gen_perf_query_result
{
91 * Storage for the final accumulated OA counters.
93 uint64_t accumulator
[MAX_OA_REPORT_COUNTERS
];
96 * Hw ID used by the context on which the query was running.
101 * Number of reports accumulated to produce the results.
103 uint32_t reports_accumulated
;
106 * Frequency in the slices of the GT at the begin and end of the
109 uint64_t slice_frequency
[2];
112 * Frequency in the unslice of the GT at the begin and end of the
115 uint64_t unslice_frequency
[2];
118 struct gen_perf_query_counter
{
121 enum gen_perf_counter_type type
;
122 enum gen_perf_counter_data_type data_type
;
127 uint64_t (*oa_counter_read_uint64
)(struct gen_perf_config
*perf
,
128 const struct gen_perf_query_info
*query
,
129 const uint64_t *accumulator
);
130 float (*oa_counter_read_float
)(struct gen_perf_config
*perf
,
131 const struct gen_perf_query_info
*query
,
132 const uint64_t *accumulator
);
133 struct gen_pipeline_stat pipeline_stat
;
137 struct gen_perf_query_register_prog
{
142 /* Register programming for a given query */
143 struct gen_perf_configuration
{
144 struct gen_perf_query_register_prog
*flex_regs
;
145 uint32_t n_flex_regs
;
147 struct gen_perf_query_register_prog
*mux_regs
;
150 struct gen_perf_query_register_prog
*b_counter_regs
;
151 uint32_t n_b_counter_regs
;
154 struct gen_perf_query_info
{
155 enum gen_perf_query_type
{
156 GEN_PERF_QUERY_TYPE_OA
,
157 GEN_PERF_QUERY_TYPE_RAW
,
158 GEN_PERF_QUERY_TYPE_PIPELINE
,
162 struct gen_perf_query_counter
*counters
;
168 uint64_t oa_metrics_set_id
;
171 /* For indexing into the accumulator[] ... */
173 int gpu_clock_offset
;
178 struct gen_perf_configuration config
;
181 struct gen_perf_config
{
182 struct gen_perf_query_info
*queries
;
185 /* Variables referenced in the XML meta data for OA performance
186 * counters, e.g in the normalization equations.
188 * All uint64_t for consistent operand types in generated code
191 uint64_t timestamp_frequency
; /** $GpuTimestampFrequency */
192 uint64_t n_eus
; /** $EuCoresTotalCount */
193 uint64_t n_eu_slices
; /** $EuSlicesTotalCount */
194 uint64_t n_eu_sub_slices
; /** $EuSubslicesTotalCount */
195 uint64_t eu_threads_count
; /** $EuThreadsCount */
196 uint64_t slice_mask
; /** $SliceMask */
197 uint64_t subslice_mask
; /** $SubsliceMask */
198 uint64_t gt_min_freq
; /** $GpuMinFrequency */
199 uint64_t gt_max_freq
; /** $GpuMaxFrequency */
200 uint64_t revision
; /** $SkuRevisionId */
203 /* OA metric sets, indexed by GUID, as know by Mesa at build time, to
204 * cross-reference with the GUIDs of configs advertised by the kernel at
207 struct hash_table
*oa_metrics_table
;
209 /* Location of the device's sysfs entry. */
210 char sysfs_dev_dir
[256];
213 void *(*bo_alloc
)(void *bufmgr
, const char *name
, uint64_t size
);
214 void (*bo_unreference
)(void *bo
);
215 void *(*bo_map
)(void *ctx
, void *bo
, unsigned flags
);
216 void (*bo_unmap
)(void *bo
);
217 bool (*batch_references
)(void *batch
, void *bo
);
218 void (*bo_wait_rendering
)(void *bo
);
219 int (*bo_busy
)(void *bo
);
220 void (*emit_mi_flush
)(void *ctx
);
221 void (*emit_mi_report_perf_count
)(void *ctx
,
223 uint32_t offset_in_bytes
,
225 void (*batchbuffer_flush
)(void *ctx
,
226 const char *file
, int line
);
227 void (*capture_frequency_stat_register
)(void *ctx
, void *bo
,
229 void (*store_register_mem64
)(void *ctx
, void *bo
, uint32_t reg
, uint32_t offset
);
234 struct gen_perf_query_object
;
235 const struct gen_perf_query_info
* gen_perf_query_info(const struct gen_perf_query_object
*);
237 void gen_perf_init_metrics(struct gen_perf_config
*perf_cfg
,
238 const struct gen_device_info
*devinfo
,
241 /** Query i915 for a metric id using guid.
243 bool gen_perf_load_metric_id(struct gen_perf_config
*perf_cfg
,
245 uint64_t *metric_id
);
247 /** Read the slice/unslice frequency from 2 OA reports and store then into
250 void gen_perf_query_result_read_frequencies(struct gen_perf_query_result
*result
,
251 const struct gen_device_info
*devinfo
,
252 const uint32_t *start
,
253 const uint32_t *end
);
254 /** Accumulate the delta between 2 OA reports into result for a given query.
256 void gen_perf_query_result_accumulate(struct gen_perf_query_result
*result
,
257 const struct gen_perf_query_info
*query
,
258 const uint32_t *start
,
259 const uint32_t *end
);
260 void gen_perf_query_result_clear(struct gen_perf_query_result
*result
);
262 struct gen_perf_context
;
263 struct gen_perf_context
*gen_perf_new_context(void *parent
);
265 void gen_perf_init_context(struct gen_perf_context
*perf_ctx
,
266 struct gen_perf_config
*perf_cfg
,
267 void * ctx
, /* driver context (eg, brw_context) */
268 void * bufmgr
, /* eg brw_bufmgr */
269 const struct gen_device_info
*devinfo
,
273 struct gen_perf_config
*gen_perf_config(struct gen_perf_context
*ctx
);
275 int gen_perf_active_queries(struct gen_perf_context
*perf_ctx
,
276 const struct gen_perf_query_info
*query
);
279 gen_perf_query_counter_get_size(const struct gen_perf_query_counter
*counter
)
281 switch (counter
->data_type
) {
282 case GEN_PERF_COUNTER_DATA_TYPE_BOOL32
:
283 return sizeof(uint32_t);
284 case GEN_PERF_COUNTER_DATA_TYPE_UINT32
:
285 return sizeof(uint32_t);
286 case GEN_PERF_COUNTER_DATA_TYPE_UINT64
:
287 return sizeof(uint64_t);
288 case GEN_PERF_COUNTER_DATA_TYPE_FLOAT
:
289 return sizeof(float);
290 case GEN_PERF_COUNTER_DATA_TYPE_DOUBLE
:
291 return sizeof(double);
293 unreachable("invalid counter data type");
297 static inline struct gen_perf_config
*
298 gen_perf_new(void *ctx
)
300 struct gen_perf_config
*perf
= rzalloc(ctx
, struct gen_perf_config
);
304 struct gen_perf_query_object
*
305 gen_perf_new_query(struct gen_perf_context
*, unsigned query_index
);
308 bool gen_perf_begin_query(struct gen_perf_context
*perf_ctx
,
309 struct gen_perf_query_object
*query
);
310 void gen_perf_end_query(struct gen_perf_context
*perf_ctx
,
311 struct gen_perf_query_object
*query
);
312 void gen_perf_wait_query(struct gen_perf_context
*perf_ctx
,
313 struct gen_perf_query_object
*query
,
314 void *current_batch
);
315 bool gen_perf_is_query_ready(struct gen_perf_context
*perf_ctx
,
316 struct gen_perf_query_object
*query
,
317 void *current_batch
);
318 void gen_perf_delete_query(struct gen_perf_context
*perf_ctx
,
319 struct gen_perf_query_object
*query
);
320 void gen_perf_get_query_data(struct gen_perf_context
*perf_ctx
,
321 struct gen_perf_query_object
*query
,
324 unsigned *bytes_written
);
326 void gen_perf_dump_query_count(struct gen_perf_context
*perf_ctx
);
327 void gen_perf_dump_query(struct gen_perf_context
*perf_ctx
,
328 struct gen_perf_query_object
*obj
,
329 void *current_batch
);
331 #endif /* GEN_PERF_H */