2 * Copyright © 2019 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 shall be included
12 * in all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
25 #include "iris_context.h"
26 #include "iris_perf.h"
28 #include "perf/gen_perf.h"
29 #include "perf/gen_perf_regs.h"
31 struct iris_perf_query
{
32 struct gl_perf_query_object base
;
33 struct gen_perf_query_object
*query
;
37 iris_init_perf_query_info(struct pipe_context
*pipe
)
39 struct iris_context
*ice
= (void *) pipe
;
40 struct iris_screen
*screen
= (struct iris_screen
*) ice
->ctx
.screen
;
41 struct gen_perf_config
*perf_cfg
= NULL
;
43 /* make sure pipe perf counter type/data-type enums are matched with gen_perf's */
44 STATIC_ASSERT(PIPE_PERF_COUNTER_TYPE_EVENT
== (enum pipe_perf_counter_type
)GEN_PERF_COUNTER_TYPE_EVENT
);
45 STATIC_ASSERT(PIPE_PERF_COUNTER_TYPE_DURATION_NORM
== (enum pipe_perf_counter_type
)GEN_PERF_COUNTER_TYPE_DURATION_NORM
);
46 STATIC_ASSERT(PIPE_PERF_COUNTER_TYPE_DURATION_RAW
== (enum pipe_perf_counter_type
)GEN_PERF_COUNTER_TYPE_DURATION_RAW
);
47 STATIC_ASSERT(PIPE_PERF_COUNTER_TYPE_THROUGHPUT
== (enum pipe_perf_counter_type
)GEN_PERF_COUNTER_TYPE_THROUGHPUT
);
48 STATIC_ASSERT(PIPE_PERF_COUNTER_TYPE_RAW
== (enum pipe_perf_counter_type
)GEN_PERF_COUNTER_TYPE_RAW
);
50 STATIC_ASSERT(PIPE_PERF_COUNTER_DATA_TYPE_BOOL32
== (enum pipe_perf_counter_data_type
)GEN_PERF_COUNTER_DATA_TYPE_BOOL32
);
51 STATIC_ASSERT(PIPE_PERF_COUNTER_DATA_TYPE_UINT32
== (enum pipe_perf_counter_data_type
)GEN_PERF_COUNTER_DATA_TYPE_UINT32
);
52 STATIC_ASSERT(PIPE_PERF_COUNTER_DATA_TYPE_UINT64
== (enum pipe_perf_counter_data_type
)GEN_PERF_COUNTER_DATA_TYPE_UINT64
);
53 STATIC_ASSERT(PIPE_PERF_COUNTER_DATA_TYPE_FLOAT
== (enum pipe_perf_counter_data_type
)GEN_PERF_COUNTER_DATA_TYPE_FLOAT
);
54 STATIC_ASSERT(PIPE_PERF_COUNTER_DATA_TYPE_DOUBLE
== (enum pipe_perf_counter_data_type
)GEN_PERF_COUNTER_DATA_TYPE_DOUBLE
);
57 ice
->perf_ctx
= gen_perf_new_context(ice
);
59 if (unlikely(!ice
->perf_ctx
))
62 perf_cfg
= gen_perf_config(ice
->perf_ctx
);
65 return perf_cfg
->n_queries
;
67 perf_cfg
= gen_perf_new(ice
->perf_ctx
);
69 iris_perf_init_vtbl(perf_cfg
);
71 gen_perf_init_context(ice
->perf_ctx
,
76 ice
->batches
[IRIS_BATCH_RENDER
].hw_ctx_id
,
79 gen_perf_init_metrics(perf_cfg
, &screen
->devinfo
, screen
->fd
);
81 return perf_cfg
->n_queries
;
84 static struct pipe_query
*
85 iris_new_perf_query_obj(struct pipe_context
*pipe
, unsigned query_index
)
87 struct iris_context
*ice
= (void *) pipe
;
88 struct gen_perf_context
*perf_ctx
= ice
->perf_ctx
;
89 struct gen_perf_query_object
* obj
= gen_perf_new_query(perf_ctx
, query_index
);
93 struct iris_perf_query
*q
= calloc(1, sizeof(struct iris_perf_query
));
95 gen_perf_delete_query(perf_ctx
, obj
);
100 return (struct pipe_query
*)&q
->base
;
104 iris_begin_perf_query(struct pipe_context
*pipe
, struct pipe_query
*q
)
106 struct iris_context
*ice
= (void *) pipe
;
107 struct iris_perf_query
*perf_query
= (struct iris_perf_query
*) q
;
108 struct gen_perf_query_object
*obj
= perf_query
->query
;
109 struct gen_perf_context
*perf_ctx
= ice
->perf_ctx
;
111 gen_perf_begin_query(perf_ctx
, obj
);
115 iris_end_perf_query(struct pipe_context
*pipe
, struct pipe_query
*q
)
117 struct iris_context
*ice
= (void *) pipe
;
118 struct iris_perf_query
*perf_query
= (struct iris_perf_query
*) q
;
119 struct gen_perf_query_object
*obj
= perf_query
->query
;
120 struct gen_perf_context
*perf_ctx
= ice
->perf_ctx
;
122 gen_perf_end_query(perf_ctx
, obj
);
126 iris_delete_perf_query(struct pipe_context
*pipe
, struct pipe_query
*q
)
128 struct iris_context
*ice
= (void *) pipe
;
129 struct iris_perf_query
*perf_query
= (struct iris_perf_query
*) q
;
130 struct gen_perf_query_object
*obj
= perf_query
->query
;
131 struct gen_perf_context
*perf_ctx
= ice
->perf_ctx
;
133 gen_perf_delete_query(perf_ctx
, obj
);
138 iris_get_perf_query_info(struct pipe_context
*pipe
,
139 unsigned query_index
,
142 uint32_t *n_counters
,
145 struct iris_context
*ice
= (void *) pipe
;
146 struct gen_perf_context
*perf_ctx
= ice
->perf_ctx
;
147 struct gen_perf_config
*perf_cfg
= gen_perf_config(perf_ctx
);
148 const struct gen_perf_query_info
*info
= &perf_cfg
->queries
[query_index
];
151 *data_size
= info
->data_size
;
152 *n_counters
= info
->n_counters
;
153 *n_active
= gen_perf_active_queries(perf_ctx
, info
);
157 iris_get_perf_counter_info(struct pipe_context
*pipe
,
158 unsigned query_index
,
159 unsigned counter_index
,
165 uint32_t *data_type_enum
,
168 struct iris_context
*ice
= (void *) pipe
;
169 struct gen_perf_context
*perf_ctx
= ice
->perf_ctx
;
170 struct gen_perf_config
*perf_cfg
= gen_perf_config(perf_ctx
);
171 const struct gen_perf_query_info
*info
= &perf_cfg
->queries
[query_index
];
172 const struct gen_perf_query_counter
*counter
= &info
->counters
[counter_index
];
174 *name
= counter
->name
;
175 *desc
= counter
->desc
;
176 *offset
= counter
->offset
;
177 *data_size
= gen_perf_query_counter_get_size(counter
);
178 *type_enum
= counter
->type
;
179 *data_type_enum
= counter
->data_type
;
180 *raw_max
= counter
->raw_max
;
184 iris_wait_perf_query(struct pipe_context
*pipe
, struct pipe_query
*q
)
186 struct iris_context
*ice
= (void *) pipe
;
187 struct iris_perf_query
*perf_query
= (struct iris_perf_query
*) q
;
188 struct gen_perf_query_object
*obj
= perf_query
->query
;
189 struct gen_perf_context
*perf_ctx
= ice
->perf_ctx
;
191 gen_perf_wait_query(perf_ctx
, obj
, &ice
->batches
[IRIS_BATCH_RENDER
]);
195 iris_is_perf_query_ready(struct pipe_context
*pipe
, struct pipe_query
*q
)
197 struct iris_context
*ice
= (void *) pipe
;
198 struct iris_perf_query
*perf_query
= (struct iris_perf_query
*) q
;
199 struct gen_perf_query_object
*obj
= perf_query
->query
;
200 struct gen_perf_context
*perf_ctx
= ice
->perf_ctx
;
202 if (perf_query
->base
.Ready
)
205 return gen_perf_is_query_ready(perf_ctx
, obj
, &ice
->batches
[IRIS_BATCH_RENDER
]);
209 iris_get_perf_query_data(struct pipe_context
*pipe
,
210 struct pipe_query
*q
,
213 uint32_t *bytes_written
)
215 struct iris_context
*ice
= (void *) pipe
;
216 struct iris_perf_query
*perf_query
= (struct iris_perf_query
*) q
;
217 struct gen_perf_query_object
*obj
= perf_query
->query
;
218 struct gen_perf_context
*perf_ctx
= ice
->perf_ctx
;
220 gen_perf_get_query_data(perf_ctx
, obj
, data_size
, data
, bytes_written
);
224 iris_init_perfquery_functions(struct pipe_context
*ctx
)
226 ctx
->init_intel_perf_query_info
= iris_init_perf_query_info
;
227 ctx
->get_intel_perf_query_info
= iris_get_perf_query_info
;
228 ctx
->get_intel_perf_query_counter_info
= iris_get_perf_counter_info
;
229 ctx
->new_intel_perf_query_obj
= iris_new_perf_query_obj
;
230 ctx
->begin_intel_perf_query
= iris_begin_perf_query
;
231 ctx
->end_intel_perf_query
= iris_end_perf_query
;
232 ctx
->delete_intel_perf_query
= iris_delete_perf_query
;
233 ctx
->wait_intel_perf_query
= iris_wait_perf_query
;
234 ctx
->is_intel_perf_query_ready
= iris_is_perf_query_ready
;
235 ctx
->get_intel_perf_query_data
= iris_get_perf_query_data
;