1*61046927SAndroid Build Coastguard Worker /*
2*61046927SAndroid Build Coastguard Worker * Copyright © 2018 Intel Corporation
3*61046927SAndroid Build Coastguard Worker *
4*61046927SAndroid Build Coastguard Worker * Permission is hereby granted, free of charge, to any person obtaining a
5*61046927SAndroid Build Coastguard Worker * copy of this software and associated documentation files (the "Software"),
6*61046927SAndroid Build Coastguard Worker * to deal in the Software without restriction, including without limitation
7*61046927SAndroid Build Coastguard Worker * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*61046927SAndroid Build Coastguard Worker * and/or sell copies of the Software, and to permit persons to whom the
9*61046927SAndroid Build Coastguard Worker * Software is furnished to do so, subject to the following conditions:
10*61046927SAndroid Build Coastguard Worker *
11*61046927SAndroid Build Coastguard Worker * The above copyright notice and this permission notice (including the next
12*61046927SAndroid Build Coastguard Worker * paragraph) shall be included in all copies or substantial portions of the
13*61046927SAndroid Build Coastguard Worker * Software.
14*61046927SAndroid Build Coastguard Worker *
15*61046927SAndroid Build Coastguard Worker * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16*61046927SAndroid Build Coastguard Worker * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17*61046927SAndroid Build Coastguard Worker * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18*61046927SAndroid Build Coastguard Worker * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19*61046927SAndroid Build Coastguard Worker * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20*61046927SAndroid Build Coastguard Worker * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21*61046927SAndroid Build Coastguard Worker * DEALINGS IN THE SOFTWARE.
22*61046927SAndroid Build Coastguard Worker */
23*61046927SAndroid Build Coastguard Worker
24*61046927SAndroid Build Coastguard Worker #include <assert.h>
25*61046927SAndroid Build Coastguard Worker #include <stdbool.h>
26*61046927SAndroid Build Coastguard Worker #include <stdint.h>
27*61046927SAndroid Build Coastguard Worker
28*61046927SAndroid Build Coastguard Worker #include "anv_private.h"
29*61046927SAndroid Build Coastguard Worker #include "vk_util.h"
30*61046927SAndroid Build Coastguard Worker
31*61046927SAndroid Build Coastguard Worker #include "perf/intel_perf.h"
32*61046927SAndroid Build Coastguard Worker #include "perf/intel_perf_mdapi.h"
33*61046927SAndroid Build Coastguard Worker
34*61046927SAndroid Build Coastguard Worker #include "util/mesa-sha1.h"
35*61046927SAndroid Build Coastguard Worker
36*61046927SAndroid Build Coastguard Worker void
anv_physical_device_init_perf(struct anv_physical_device * device,int fd)37*61046927SAndroid Build Coastguard Worker anv_physical_device_init_perf(struct anv_physical_device *device, int fd)
38*61046927SAndroid Build Coastguard Worker {
39*61046927SAndroid Build Coastguard Worker struct intel_perf_config *perf = intel_perf_new(NULL);
40*61046927SAndroid Build Coastguard Worker
41*61046927SAndroid Build Coastguard Worker intel_perf_init_metrics(perf, &device->info, fd,
42*61046927SAndroid Build Coastguard Worker false /* pipeline statistics */,
43*61046927SAndroid Build Coastguard Worker true /* register snapshots */);
44*61046927SAndroid Build Coastguard Worker
45*61046927SAndroid Build Coastguard Worker if (!perf->n_queries)
46*61046927SAndroid Build Coastguard Worker goto err;
47*61046927SAndroid Build Coastguard Worker
48*61046927SAndroid Build Coastguard Worker /* We need DRM_I915_PERF_PROP_HOLD_PREEMPTION support, only available in
49*61046927SAndroid Build Coastguard Worker * perf revision 2.
50*61046927SAndroid Build Coastguard Worker */
51*61046927SAndroid Build Coastguard Worker if (!INTEL_DEBUG(DEBUG_NO_OACONFIG)) {
52*61046927SAndroid Build Coastguard Worker if (!intel_perf_has_hold_preemption(perf))
53*61046927SAndroid Build Coastguard Worker goto err;
54*61046927SAndroid Build Coastguard Worker }
55*61046927SAndroid Build Coastguard Worker
56*61046927SAndroid Build Coastguard Worker device->perf = perf;
57*61046927SAndroid Build Coastguard Worker
58*61046927SAndroid Build Coastguard Worker /* Compute the number of commands we need to implement a performance
59*61046927SAndroid Build Coastguard Worker * query.
60*61046927SAndroid Build Coastguard Worker */
61*61046927SAndroid Build Coastguard Worker const struct intel_perf_query_field_layout *layout = &perf->query_layout;
62*61046927SAndroid Build Coastguard Worker device->n_perf_query_commands = 0;
63*61046927SAndroid Build Coastguard Worker for (uint32_t f = 0; f < layout->n_fields; f++) {
64*61046927SAndroid Build Coastguard Worker struct intel_perf_query_field *field = &layout->fields[f];
65*61046927SAndroid Build Coastguard Worker
66*61046927SAndroid Build Coastguard Worker switch (field->type) {
67*61046927SAndroid Build Coastguard Worker case INTEL_PERF_QUERY_FIELD_TYPE_MI_RPC:
68*61046927SAndroid Build Coastguard Worker device->n_perf_query_commands++;
69*61046927SAndroid Build Coastguard Worker break;
70*61046927SAndroid Build Coastguard Worker case INTEL_PERF_QUERY_FIELD_TYPE_SRM_PERFCNT:
71*61046927SAndroid Build Coastguard Worker case INTEL_PERF_QUERY_FIELD_TYPE_SRM_RPSTAT:
72*61046927SAndroid Build Coastguard Worker case INTEL_PERF_QUERY_FIELD_TYPE_SRM_OA_A:
73*61046927SAndroid Build Coastguard Worker case INTEL_PERF_QUERY_FIELD_TYPE_SRM_OA_B:
74*61046927SAndroid Build Coastguard Worker case INTEL_PERF_QUERY_FIELD_TYPE_SRM_OA_C:
75*61046927SAndroid Build Coastguard Worker case INTEL_PERF_QUERY_FIELD_TYPE_SRM_OA_PEC:
76*61046927SAndroid Build Coastguard Worker device->n_perf_query_commands += field->size / 4;
77*61046927SAndroid Build Coastguard Worker break;
78*61046927SAndroid Build Coastguard Worker default:
79*61046927SAndroid Build Coastguard Worker unreachable("Unhandled register type");
80*61046927SAndroid Build Coastguard Worker }
81*61046927SAndroid Build Coastguard Worker }
82*61046927SAndroid Build Coastguard Worker device->n_perf_query_commands *= 2; /* Begin & End */
83*61046927SAndroid Build Coastguard Worker device->n_perf_query_commands += 1; /* availability */
84*61046927SAndroid Build Coastguard Worker
85*61046927SAndroid Build Coastguard Worker return;
86*61046927SAndroid Build Coastguard Worker
87*61046927SAndroid Build Coastguard Worker err:
88*61046927SAndroid Build Coastguard Worker intel_perf_free(perf);
89*61046927SAndroid Build Coastguard Worker }
90*61046927SAndroid Build Coastguard Worker
91*61046927SAndroid Build Coastguard Worker void
anv_device_perf_init(struct anv_device * device)92*61046927SAndroid Build Coastguard Worker anv_device_perf_init(struct anv_device *device)
93*61046927SAndroid Build Coastguard Worker {
94*61046927SAndroid Build Coastguard Worker device->perf_fd = -1;
95*61046927SAndroid Build Coastguard Worker device->perf_queue = NULL;
96*61046927SAndroid Build Coastguard Worker }
97*61046927SAndroid Build Coastguard Worker
98*61046927SAndroid Build Coastguard Worker void
anv_device_perf_close(struct anv_device * device)99*61046927SAndroid Build Coastguard Worker anv_device_perf_close(struct anv_device *device)
100*61046927SAndroid Build Coastguard Worker {
101*61046927SAndroid Build Coastguard Worker if (device->perf_fd == -1)
102*61046927SAndroid Build Coastguard Worker return;
103*61046927SAndroid Build Coastguard Worker
104*61046927SAndroid Build Coastguard Worker close(device->perf_fd);
105*61046927SAndroid Build Coastguard Worker device->perf_fd = -1;
106*61046927SAndroid Build Coastguard Worker }
107*61046927SAndroid Build Coastguard Worker
108*61046927SAndroid Build Coastguard Worker static int
anv_device_perf_open(struct anv_device * device,struct anv_queue * queue,uint64_t metric_id)109*61046927SAndroid Build Coastguard Worker anv_device_perf_open(struct anv_device *device, struct anv_queue *queue, uint64_t metric_id)
110*61046927SAndroid Build Coastguard Worker {
111*61046927SAndroid Build Coastguard Worker uint32_t context_or_exec_queue_id;
112*61046927SAndroid Build Coastguard Worker uint64_t period_exponent = 31; /* slowest sampling period */
113*61046927SAndroid Build Coastguard Worker int ret;
114*61046927SAndroid Build Coastguard Worker
115*61046927SAndroid Build Coastguard Worker switch (device->physical->info.kmd_type) {
116*61046927SAndroid Build Coastguard Worker case INTEL_KMD_TYPE_I915:
117*61046927SAndroid Build Coastguard Worker context_or_exec_queue_id = device->physical->has_vm_control ?
118*61046927SAndroid Build Coastguard Worker queue->context_id : device->context_id;
119*61046927SAndroid Build Coastguard Worker break;
120*61046927SAndroid Build Coastguard Worker case INTEL_KMD_TYPE_XE:
121*61046927SAndroid Build Coastguard Worker context_or_exec_queue_id = queue->exec_queue_id;
122*61046927SAndroid Build Coastguard Worker break;
123*61046927SAndroid Build Coastguard Worker default:
124*61046927SAndroid Build Coastguard Worker unreachable("missing");
125*61046927SAndroid Build Coastguard Worker context_or_exec_queue_id = 0;
126*61046927SAndroid Build Coastguard Worker }
127*61046927SAndroid Build Coastguard Worker
128*61046927SAndroid Build Coastguard Worker ret = intel_perf_stream_open(device->physical->perf, device->fd,
129*61046927SAndroid Build Coastguard Worker context_or_exec_queue_id, metric_id,
130*61046927SAndroid Build Coastguard Worker period_exponent, true, true);
131*61046927SAndroid Build Coastguard Worker if (ret >= 0)
132*61046927SAndroid Build Coastguard Worker device->perf_queue = queue;
133*61046927SAndroid Build Coastguard Worker
134*61046927SAndroid Build Coastguard Worker return ret;
135*61046927SAndroid Build Coastguard Worker }
136*61046927SAndroid Build Coastguard Worker
137*61046927SAndroid Build Coastguard Worker /* VK_INTEL_performance_query */
anv_InitializePerformanceApiINTEL(VkDevice _device,const VkInitializePerformanceApiInfoINTEL * pInitializeInfo)138*61046927SAndroid Build Coastguard Worker VkResult anv_InitializePerformanceApiINTEL(
139*61046927SAndroid Build Coastguard Worker VkDevice _device,
140*61046927SAndroid Build Coastguard Worker const VkInitializePerformanceApiInfoINTEL* pInitializeInfo)
141*61046927SAndroid Build Coastguard Worker {
142*61046927SAndroid Build Coastguard Worker ANV_FROM_HANDLE(anv_device, device, _device);
143*61046927SAndroid Build Coastguard Worker
144*61046927SAndroid Build Coastguard Worker if (!device->physical->perf)
145*61046927SAndroid Build Coastguard Worker return VK_ERROR_EXTENSION_NOT_PRESENT;
146*61046927SAndroid Build Coastguard Worker
147*61046927SAndroid Build Coastguard Worker /* Not much to do here */
148*61046927SAndroid Build Coastguard Worker return VK_SUCCESS;
149*61046927SAndroid Build Coastguard Worker }
150*61046927SAndroid Build Coastguard Worker
anv_GetPerformanceParameterINTEL(VkDevice _device,VkPerformanceParameterTypeINTEL parameter,VkPerformanceValueINTEL * pValue)151*61046927SAndroid Build Coastguard Worker VkResult anv_GetPerformanceParameterINTEL(
152*61046927SAndroid Build Coastguard Worker VkDevice _device,
153*61046927SAndroid Build Coastguard Worker VkPerformanceParameterTypeINTEL parameter,
154*61046927SAndroid Build Coastguard Worker VkPerformanceValueINTEL* pValue)
155*61046927SAndroid Build Coastguard Worker {
156*61046927SAndroid Build Coastguard Worker ANV_FROM_HANDLE(anv_device, device, _device);
157*61046927SAndroid Build Coastguard Worker
158*61046927SAndroid Build Coastguard Worker if (!device->physical->perf)
159*61046927SAndroid Build Coastguard Worker return VK_ERROR_EXTENSION_NOT_PRESENT;
160*61046927SAndroid Build Coastguard Worker
161*61046927SAndroid Build Coastguard Worker VkResult result = VK_SUCCESS;
162*61046927SAndroid Build Coastguard Worker switch (parameter) {
163*61046927SAndroid Build Coastguard Worker case VK_PERFORMANCE_PARAMETER_TYPE_HW_COUNTERS_SUPPORTED_INTEL:
164*61046927SAndroid Build Coastguard Worker pValue->type = VK_PERFORMANCE_VALUE_TYPE_BOOL_INTEL;
165*61046927SAndroid Build Coastguard Worker pValue->data.valueBool = VK_TRUE;
166*61046927SAndroid Build Coastguard Worker break;
167*61046927SAndroid Build Coastguard Worker
168*61046927SAndroid Build Coastguard Worker case VK_PERFORMANCE_PARAMETER_TYPE_STREAM_MARKER_VALID_BITS_INTEL:
169*61046927SAndroid Build Coastguard Worker pValue->type = VK_PERFORMANCE_VALUE_TYPE_UINT32_INTEL;
170*61046927SAndroid Build Coastguard Worker pValue->data.value32 = 25;
171*61046927SAndroid Build Coastguard Worker break;
172*61046927SAndroid Build Coastguard Worker
173*61046927SAndroid Build Coastguard Worker default:
174*61046927SAndroid Build Coastguard Worker result = VK_ERROR_FEATURE_NOT_PRESENT;
175*61046927SAndroid Build Coastguard Worker break;
176*61046927SAndroid Build Coastguard Worker }
177*61046927SAndroid Build Coastguard Worker
178*61046927SAndroid Build Coastguard Worker return result;
179*61046927SAndroid Build Coastguard Worker }
180*61046927SAndroid Build Coastguard Worker
anv_CmdSetPerformanceMarkerINTEL(VkCommandBuffer commandBuffer,const VkPerformanceMarkerInfoINTEL * pMarkerInfo)181*61046927SAndroid Build Coastguard Worker VkResult anv_CmdSetPerformanceMarkerINTEL(
182*61046927SAndroid Build Coastguard Worker VkCommandBuffer commandBuffer,
183*61046927SAndroid Build Coastguard Worker const VkPerformanceMarkerInfoINTEL* pMarkerInfo)
184*61046927SAndroid Build Coastguard Worker {
185*61046927SAndroid Build Coastguard Worker ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
186*61046927SAndroid Build Coastguard Worker
187*61046927SAndroid Build Coastguard Worker cmd_buffer->intel_perf_marker = pMarkerInfo->marker;
188*61046927SAndroid Build Coastguard Worker
189*61046927SAndroid Build Coastguard Worker return VK_SUCCESS;
190*61046927SAndroid Build Coastguard Worker }
191*61046927SAndroid Build Coastguard Worker
anv_AcquirePerformanceConfigurationINTEL(VkDevice _device,const VkPerformanceConfigurationAcquireInfoINTEL * pAcquireInfo,VkPerformanceConfigurationINTEL * pConfiguration)192*61046927SAndroid Build Coastguard Worker VkResult anv_AcquirePerformanceConfigurationINTEL(
193*61046927SAndroid Build Coastguard Worker VkDevice _device,
194*61046927SAndroid Build Coastguard Worker const VkPerformanceConfigurationAcquireInfoINTEL* pAcquireInfo,
195*61046927SAndroid Build Coastguard Worker VkPerformanceConfigurationINTEL* pConfiguration)
196*61046927SAndroid Build Coastguard Worker {
197*61046927SAndroid Build Coastguard Worker ANV_FROM_HANDLE(anv_device, device, _device);
198*61046927SAndroid Build Coastguard Worker struct anv_performance_configuration_intel *config;
199*61046927SAndroid Build Coastguard Worker
200*61046927SAndroid Build Coastguard Worker config = vk_object_alloc(&device->vk, NULL, sizeof(*config),
201*61046927SAndroid Build Coastguard Worker VK_OBJECT_TYPE_PERFORMANCE_CONFIGURATION_INTEL);
202*61046927SAndroid Build Coastguard Worker if (!config)
203*61046927SAndroid Build Coastguard Worker return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
204*61046927SAndroid Build Coastguard Worker
205*61046927SAndroid Build Coastguard Worker if (!INTEL_DEBUG(DEBUG_NO_OACONFIG)) {
206*61046927SAndroid Build Coastguard Worker config->register_config =
207*61046927SAndroid Build Coastguard Worker intel_perf_load_configuration(device->physical->perf, device->fd,
208*61046927SAndroid Build Coastguard Worker INTEL_PERF_QUERY_GUID_MDAPI);
209*61046927SAndroid Build Coastguard Worker if (!config->register_config) {
210*61046927SAndroid Build Coastguard Worker vk_object_free(&device->vk, NULL, config);
211*61046927SAndroid Build Coastguard Worker return VK_INCOMPLETE;
212*61046927SAndroid Build Coastguard Worker }
213*61046927SAndroid Build Coastguard Worker
214*61046927SAndroid Build Coastguard Worker uint64_t ret =
215*61046927SAndroid Build Coastguard Worker intel_perf_store_configuration(device->physical->perf, device->fd,
216*61046927SAndroid Build Coastguard Worker config->register_config, NULL /* guid */);
217*61046927SAndroid Build Coastguard Worker if (ret == 0) {
218*61046927SAndroid Build Coastguard Worker ralloc_free(config->register_config);
219*61046927SAndroid Build Coastguard Worker vk_object_free(&device->vk, NULL, config);
220*61046927SAndroid Build Coastguard Worker return VK_INCOMPLETE;
221*61046927SAndroid Build Coastguard Worker }
222*61046927SAndroid Build Coastguard Worker
223*61046927SAndroid Build Coastguard Worker config->config_id = ret;
224*61046927SAndroid Build Coastguard Worker }
225*61046927SAndroid Build Coastguard Worker
226*61046927SAndroid Build Coastguard Worker *pConfiguration = anv_performance_configuration_intel_to_handle(config);
227*61046927SAndroid Build Coastguard Worker
228*61046927SAndroid Build Coastguard Worker return VK_SUCCESS;
229*61046927SAndroid Build Coastguard Worker }
230*61046927SAndroid Build Coastguard Worker
anv_ReleasePerformanceConfigurationINTEL(VkDevice _device,VkPerformanceConfigurationINTEL _configuration)231*61046927SAndroid Build Coastguard Worker VkResult anv_ReleasePerformanceConfigurationINTEL(
232*61046927SAndroid Build Coastguard Worker VkDevice _device,
233*61046927SAndroid Build Coastguard Worker VkPerformanceConfigurationINTEL _configuration)
234*61046927SAndroid Build Coastguard Worker {
235*61046927SAndroid Build Coastguard Worker ANV_FROM_HANDLE(anv_device, device, _device);
236*61046927SAndroid Build Coastguard Worker ANV_FROM_HANDLE(anv_performance_configuration_intel, config, _configuration);
237*61046927SAndroid Build Coastguard Worker
238*61046927SAndroid Build Coastguard Worker if (!INTEL_DEBUG(DEBUG_NO_OACONFIG))
239*61046927SAndroid Build Coastguard Worker intel_perf_remove_configuration(device->physical->perf, device->fd, config->config_id);
240*61046927SAndroid Build Coastguard Worker
241*61046927SAndroid Build Coastguard Worker ralloc_free(config->register_config);
242*61046927SAndroid Build Coastguard Worker
243*61046927SAndroid Build Coastguard Worker vk_object_free(&device->vk, NULL, config);
244*61046927SAndroid Build Coastguard Worker
245*61046927SAndroid Build Coastguard Worker return VK_SUCCESS;
246*61046927SAndroid Build Coastguard Worker }
247*61046927SAndroid Build Coastguard Worker
248*61046927SAndroid Build Coastguard Worker static struct anv_queue *
anv_device_get_perf_queue(struct anv_device * device)249*61046927SAndroid Build Coastguard Worker anv_device_get_perf_queue(struct anv_device *device)
250*61046927SAndroid Build Coastguard Worker {
251*61046927SAndroid Build Coastguard Worker for (uint32_t i = 0; i < device->queue_count; i++) {
252*61046927SAndroid Build Coastguard Worker struct anv_queue *queue = &device->queues[i];
253*61046927SAndroid Build Coastguard Worker const struct anv_queue_family *family = queue->family;
254*61046927SAndroid Build Coastguard Worker
255*61046927SAndroid Build Coastguard Worker if (family->supports_perf)
256*61046927SAndroid Build Coastguard Worker return queue;
257*61046927SAndroid Build Coastguard Worker }
258*61046927SAndroid Build Coastguard Worker
259*61046927SAndroid Build Coastguard Worker return NULL;
260*61046927SAndroid Build Coastguard Worker }
261*61046927SAndroid Build Coastguard Worker
anv_QueueSetPerformanceConfigurationINTEL(VkQueue _queue,VkPerformanceConfigurationINTEL _configuration)262*61046927SAndroid Build Coastguard Worker VkResult anv_QueueSetPerformanceConfigurationINTEL(
263*61046927SAndroid Build Coastguard Worker VkQueue _queue,
264*61046927SAndroid Build Coastguard Worker VkPerformanceConfigurationINTEL _configuration)
265*61046927SAndroid Build Coastguard Worker {
266*61046927SAndroid Build Coastguard Worker ANV_FROM_HANDLE(anv_queue, queue, _queue);
267*61046927SAndroid Build Coastguard Worker ANV_FROM_HANDLE(anv_performance_configuration_intel, config, _configuration);
268*61046927SAndroid Build Coastguard Worker struct anv_device *device = queue->device;
269*61046927SAndroid Build Coastguard Worker
270*61046927SAndroid Build Coastguard Worker if (queue != anv_device_get_perf_queue(device))
271*61046927SAndroid Build Coastguard Worker return VK_ERROR_UNKNOWN;
272*61046927SAndroid Build Coastguard Worker
273*61046927SAndroid Build Coastguard Worker if (!INTEL_DEBUG(DEBUG_NO_OACONFIG)) {
274*61046927SAndroid Build Coastguard Worker if (device->perf_fd < 0) {
275*61046927SAndroid Build Coastguard Worker device->perf_fd = anv_device_perf_open(device, queue, config->config_id);
276*61046927SAndroid Build Coastguard Worker if (device->perf_fd < 0)
277*61046927SAndroid Build Coastguard Worker return VK_ERROR_INITIALIZATION_FAILED;
278*61046927SAndroid Build Coastguard Worker } else {
279*61046927SAndroid Build Coastguard Worker int ret = intel_perf_stream_set_metrics_id(device->physical->perf,
280*61046927SAndroid Build Coastguard Worker device->perf_fd,
281*61046927SAndroid Build Coastguard Worker config->config_id);
282*61046927SAndroid Build Coastguard Worker if (ret < 0)
283*61046927SAndroid Build Coastguard Worker return vk_device_set_lost(&device->vk, "i915-perf config failed: %m");
284*61046927SAndroid Build Coastguard Worker }
285*61046927SAndroid Build Coastguard Worker }
286*61046927SAndroid Build Coastguard Worker
287*61046927SAndroid Build Coastguard Worker return VK_SUCCESS;
288*61046927SAndroid Build Coastguard Worker }
289*61046927SAndroid Build Coastguard Worker
anv_UninitializePerformanceApiINTEL(VkDevice _device)290*61046927SAndroid Build Coastguard Worker void anv_UninitializePerformanceApiINTEL(
291*61046927SAndroid Build Coastguard Worker VkDevice _device)
292*61046927SAndroid Build Coastguard Worker {
293*61046927SAndroid Build Coastguard Worker ANV_FROM_HANDLE(anv_device, device, _device);
294*61046927SAndroid Build Coastguard Worker
295*61046927SAndroid Build Coastguard Worker anv_device_perf_close(device);
296*61046927SAndroid Build Coastguard Worker }
297*61046927SAndroid Build Coastguard Worker
298*61046927SAndroid Build Coastguard Worker /* VK_KHR_performance_query */
299*61046927SAndroid Build Coastguard Worker static const VkPerformanceCounterUnitKHR
300*61046927SAndroid Build Coastguard Worker intel_perf_counter_unit_to_vk_unit[] = {
301*61046927SAndroid Build Coastguard Worker [INTEL_PERF_COUNTER_UNITS_BYTES] = VK_PERFORMANCE_COUNTER_UNIT_BYTES_KHR,
302*61046927SAndroid Build Coastguard Worker [INTEL_PERF_COUNTER_UNITS_HZ] = VK_PERFORMANCE_COUNTER_UNIT_HERTZ_KHR,
303*61046927SAndroid Build Coastguard Worker [INTEL_PERF_COUNTER_UNITS_NS] = VK_PERFORMANCE_COUNTER_UNIT_NANOSECONDS_KHR,
304*61046927SAndroid Build Coastguard Worker [INTEL_PERF_COUNTER_UNITS_US] = VK_PERFORMANCE_COUNTER_UNIT_NANOSECONDS_KHR, /* todo */
305*61046927SAndroid Build Coastguard Worker [INTEL_PERF_COUNTER_UNITS_PIXELS] = VK_PERFORMANCE_COUNTER_UNIT_GENERIC_KHR,
306*61046927SAndroid Build Coastguard Worker [INTEL_PERF_COUNTER_UNITS_TEXELS] = VK_PERFORMANCE_COUNTER_UNIT_GENERIC_KHR,
307*61046927SAndroid Build Coastguard Worker [INTEL_PERF_COUNTER_UNITS_THREADS] = VK_PERFORMANCE_COUNTER_UNIT_GENERIC_KHR,
308*61046927SAndroid Build Coastguard Worker [INTEL_PERF_COUNTER_UNITS_PERCENT] = VK_PERFORMANCE_COUNTER_UNIT_PERCENTAGE_KHR,
309*61046927SAndroid Build Coastguard Worker [INTEL_PERF_COUNTER_UNITS_MESSAGES] = VK_PERFORMANCE_COUNTER_UNIT_GENERIC_KHR,
310*61046927SAndroid Build Coastguard Worker [INTEL_PERF_COUNTER_UNITS_NUMBER] = VK_PERFORMANCE_COUNTER_UNIT_GENERIC_KHR,
311*61046927SAndroid Build Coastguard Worker [INTEL_PERF_COUNTER_UNITS_CYCLES] = VK_PERFORMANCE_COUNTER_UNIT_GENERIC_KHR,
312*61046927SAndroid Build Coastguard Worker [INTEL_PERF_COUNTER_UNITS_EVENTS] = VK_PERFORMANCE_COUNTER_UNIT_GENERIC_KHR,
313*61046927SAndroid Build Coastguard Worker [INTEL_PERF_COUNTER_UNITS_UTILIZATION] = VK_PERFORMANCE_COUNTER_UNIT_GENERIC_KHR,
314*61046927SAndroid Build Coastguard Worker [INTEL_PERF_COUNTER_UNITS_EU_SENDS_TO_L3_CACHE_LINES] = VK_PERFORMANCE_COUNTER_UNIT_GENERIC_KHR,
315*61046927SAndroid Build Coastguard Worker [INTEL_PERF_COUNTER_UNITS_EU_ATOMIC_REQUESTS_TO_L3_CACHE_LINES] = VK_PERFORMANCE_COUNTER_UNIT_GENERIC_KHR,
316*61046927SAndroid Build Coastguard Worker [INTEL_PERF_COUNTER_UNITS_EU_REQUESTS_TO_L3_CACHE_LINES] = VK_PERFORMANCE_COUNTER_UNIT_GENERIC_KHR,
317*61046927SAndroid Build Coastguard Worker [INTEL_PERF_COUNTER_UNITS_EU_BYTES_PER_L3_CACHE_LINE] = VK_PERFORMANCE_COUNTER_UNIT_GENERIC_KHR,
318*61046927SAndroid Build Coastguard Worker };
319*61046927SAndroid Build Coastguard Worker
320*61046927SAndroid Build Coastguard Worker static const VkPerformanceCounterStorageKHR
321*61046927SAndroid Build Coastguard Worker intel_perf_counter_data_type_to_vk_storage[] = {
322*61046927SAndroid Build Coastguard Worker [INTEL_PERF_COUNTER_DATA_TYPE_BOOL32] = VK_PERFORMANCE_COUNTER_STORAGE_UINT32_KHR,
323*61046927SAndroid Build Coastguard Worker [INTEL_PERF_COUNTER_DATA_TYPE_UINT32] = VK_PERFORMANCE_COUNTER_STORAGE_UINT32_KHR,
324*61046927SAndroid Build Coastguard Worker [INTEL_PERF_COUNTER_DATA_TYPE_UINT64] = VK_PERFORMANCE_COUNTER_STORAGE_UINT64_KHR,
325*61046927SAndroid Build Coastguard Worker [INTEL_PERF_COUNTER_DATA_TYPE_FLOAT] = VK_PERFORMANCE_COUNTER_STORAGE_FLOAT32_KHR,
326*61046927SAndroid Build Coastguard Worker [INTEL_PERF_COUNTER_DATA_TYPE_DOUBLE] = VK_PERFORMANCE_COUNTER_STORAGE_FLOAT64_KHR,
327*61046927SAndroid Build Coastguard Worker };
328*61046927SAndroid Build Coastguard Worker
anv_EnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(VkPhysicalDevice physicalDevice,uint32_t queueFamilyIndex,uint32_t * pCounterCount,VkPerformanceCounterKHR * pCounters,VkPerformanceCounterDescriptionKHR * pCounterDescriptions)329*61046927SAndroid Build Coastguard Worker VkResult anv_EnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(
330*61046927SAndroid Build Coastguard Worker VkPhysicalDevice physicalDevice,
331*61046927SAndroid Build Coastguard Worker uint32_t queueFamilyIndex,
332*61046927SAndroid Build Coastguard Worker uint32_t* pCounterCount,
333*61046927SAndroid Build Coastguard Worker VkPerformanceCounterKHR* pCounters,
334*61046927SAndroid Build Coastguard Worker VkPerformanceCounterDescriptionKHR* pCounterDescriptions)
335*61046927SAndroid Build Coastguard Worker {
336*61046927SAndroid Build Coastguard Worker ANV_FROM_HANDLE(anv_physical_device, pdevice, physicalDevice);
337*61046927SAndroid Build Coastguard Worker struct intel_perf_config *perf = pdevice->perf;
338*61046927SAndroid Build Coastguard Worker
339*61046927SAndroid Build Coastguard Worker uint32_t desc_count = *pCounterCount;
340*61046927SAndroid Build Coastguard Worker
341*61046927SAndroid Build Coastguard Worker VK_OUTARRAY_MAKE_TYPED(VkPerformanceCounterKHR, out, pCounters, pCounterCount);
342*61046927SAndroid Build Coastguard Worker VK_OUTARRAY_MAKE_TYPED(VkPerformanceCounterDescriptionKHR, out_desc,
343*61046927SAndroid Build Coastguard Worker pCounterDescriptions, &desc_count);
344*61046927SAndroid Build Coastguard Worker
345*61046927SAndroid Build Coastguard Worker /* We cannot support performance queries on anything other than RCS,
346*61046927SAndroid Build Coastguard Worker * because the MI_REPORT_PERF_COUNT command is not available on other
347*61046927SAndroid Build Coastguard Worker * engines.
348*61046927SAndroid Build Coastguard Worker */
349*61046927SAndroid Build Coastguard Worker struct anv_queue_family *queue_family =
350*61046927SAndroid Build Coastguard Worker &pdevice->queue.families[queueFamilyIndex];
351*61046927SAndroid Build Coastguard Worker if (queue_family->engine_class != INTEL_ENGINE_CLASS_RENDER)
352*61046927SAndroid Build Coastguard Worker return vk_outarray_status(&out);
353*61046927SAndroid Build Coastguard Worker
354*61046927SAndroid Build Coastguard Worker for (int c = 0; c < (perf ? perf->n_counters : 0); c++) {
355*61046927SAndroid Build Coastguard Worker const struct intel_perf_query_counter *intel_counter = perf->counter_infos[c].counter;
356*61046927SAndroid Build Coastguard Worker
357*61046927SAndroid Build Coastguard Worker vk_outarray_append_typed(VkPerformanceCounterKHR, &out, counter) {
358*61046927SAndroid Build Coastguard Worker counter->unit = intel_perf_counter_unit_to_vk_unit[intel_counter->units];
359*61046927SAndroid Build Coastguard Worker counter->scope = VK_PERFORMANCE_COUNTER_SCOPE_COMMAND_KHR;
360*61046927SAndroid Build Coastguard Worker counter->storage = intel_perf_counter_data_type_to_vk_storage[intel_counter->data_type];
361*61046927SAndroid Build Coastguard Worker
362*61046927SAndroid Build Coastguard Worker unsigned char sha1_result[20];
363*61046927SAndroid Build Coastguard Worker _mesa_sha1_compute(intel_counter->symbol_name,
364*61046927SAndroid Build Coastguard Worker strlen(intel_counter->symbol_name),
365*61046927SAndroid Build Coastguard Worker sha1_result);
366*61046927SAndroid Build Coastguard Worker memcpy(counter->uuid, sha1_result, sizeof(counter->uuid));
367*61046927SAndroid Build Coastguard Worker }
368*61046927SAndroid Build Coastguard Worker
369*61046927SAndroid Build Coastguard Worker vk_outarray_append_typed(VkPerformanceCounterDescriptionKHR, &out_desc, desc) {
370*61046927SAndroid Build Coastguard Worker desc->flags = 0; /* None so far. */
371*61046927SAndroid Build Coastguard Worker snprintf(desc->name, sizeof(desc->name), "%s",
372*61046927SAndroid Build Coastguard Worker INTEL_DEBUG(DEBUG_PERF_SYMBOL_NAMES) ?
373*61046927SAndroid Build Coastguard Worker intel_counter->symbol_name :
374*61046927SAndroid Build Coastguard Worker intel_counter->name);
375*61046927SAndroid Build Coastguard Worker snprintf(desc->category, sizeof(desc->category), "%s", intel_counter->category);
376*61046927SAndroid Build Coastguard Worker snprintf(desc->description, sizeof(desc->description), "%s", intel_counter->desc);
377*61046927SAndroid Build Coastguard Worker }
378*61046927SAndroid Build Coastguard Worker }
379*61046927SAndroid Build Coastguard Worker
380*61046927SAndroid Build Coastguard Worker return vk_outarray_status(&out);
381*61046927SAndroid Build Coastguard Worker }
382*61046927SAndroid Build Coastguard Worker
anv_GetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR(VkPhysicalDevice physicalDevice,const VkQueryPoolPerformanceCreateInfoKHR * pPerformanceQueryCreateInfo,uint32_t * pNumPasses)383*61046927SAndroid Build Coastguard Worker void anv_GetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR(
384*61046927SAndroid Build Coastguard Worker VkPhysicalDevice physicalDevice,
385*61046927SAndroid Build Coastguard Worker const VkQueryPoolPerformanceCreateInfoKHR* pPerformanceQueryCreateInfo,
386*61046927SAndroid Build Coastguard Worker uint32_t* pNumPasses)
387*61046927SAndroid Build Coastguard Worker {
388*61046927SAndroid Build Coastguard Worker ANV_FROM_HANDLE(anv_physical_device, pdevice, physicalDevice);
389*61046927SAndroid Build Coastguard Worker struct intel_perf_config *perf = pdevice->perf;
390*61046927SAndroid Build Coastguard Worker
391*61046927SAndroid Build Coastguard Worker if (!perf) {
392*61046927SAndroid Build Coastguard Worker *pNumPasses = 0;
393*61046927SAndroid Build Coastguard Worker return;
394*61046927SAndroid Build Coastguard Worker }
395*61046927SAndroid Build Coastguard Worker
396*61046927SAndroid Build Coastguard Worker *pNumPasses = intel_perf_get_n_passes(perf,
397*61046927SAndroid Build Coastguard Worker pPerformanceQueryCreateInfo->pCounterIndices,
398*61046927SAndroid Build Coastguard Worker pPerformanceQueryCreateInfo->counterIndexCount,
399*61046927SAndroid Build Coastguard Worker NULL);
400*61046927SAndroid Build Coastguard Worker }
401*61046927SAndroid Build Coastguard Worker
anv_AcquireProfilingLockKHR(VkDevice _device,const VkAcquireProfilingLockInfoKHR * pInfo)402*61046927SAndroid Build Coastguard Worker VkResult anv_AcquireProfilingLockKHR(
403*61046927SAndroid Build Coastguard Worker VkDevice _device,
404*61046927SAndroid Build Coastguard Worker const VkAcquireProfilingLockInfoKHR* pInfo)
405*61046927SAndroid Build Coastguard Worker {
406*61046927SAndroid Build Coastguard Worker ANV_FROM_HANDLE(anv_device, device, _device);
407*61046927SAndroid Build Coastguard Worker struct intel_perf_config *perf = device->physical->perf;
408*61046927SAndroid Build Coastguard Worker struct intel_perf_query_info *first_metric_set = &perf->queries[0];
409*61046927SAndroid Build Coastguard Worker int fd = -1;
410*61046927SAndroid Build Coastguard Worker
411*61046927SAndroid Build Coastguard Worker assert(device->perf_fd == -1);
412*61046927SAndroid Build Coastguard Worker
413*61046927SAndroid Build Coastguard Worker if (!INTEL_DEBUG(DEBUG_NO_OACONFIG)) {
414*61046927SAndroid Build Coastguard Worker struct anv_queue *queue = anv_device_get_perf_queue(device);
415*61046927SAndroid Build Coastguard Worker
416*61046927SAndroid Build Coastguard Worker if (queue == NULL)
417*61046927SAndroid Build Coastguard Worker return VK_ERROR_UNKNOWN;
418*61046927SAndroid Build Coastguard Worker fd = anv_device_perf_open(device, queue, first_metric_set->oa_metrics_set_id);
419*61046927SAndroid Build Coastguard Worker if (fd < 0)
420*61046927SAndroid Build Coastguard Worker return VK_TIMEOUT;
421*61046927SAndroid Build Coastguard Worker }
422*61046927SAndroid Build Coastguard Worker
423*61046927SAndroid Build Coastguard Worker device->perf_fd = fd;
424*61046927SAndroid Build Coastguard Worker return VK_SUCCESS;
425*61046927SAndroid Build Coastguard Worker }
426*61046927SAndroid Build Coastguard Worker
anv_ReleaseProfilingLockKHR(VkDevice _device)427*61046927SAndroid Build Coastguard Worker void anv_ReleaseProfilingLockKHR(
428*61046927SAndroid Build Coastguard Worker VkDevice _device)
429*61046927SAndroid Build Coastguard Worker {
430*61046927SAndroid Build Coastguard Worker ANV_FROM_HANDLE(anv_device, device, _device);
431*61046927SAndroid Build Coastguard Worker
432*61046927SAndroid Build Coastguard Worker anv_device_perf_close(device);
433*61046927SAndroid Build Coastguard Worker }
434*61046927SAndroid Build Coastguard Worker
435*61046927SAndroid Build Coastguard Worker void
anv_perf_write_pass_results(struct intel_perf_config * perf,struct anv_query_pool * pool,uint32_t pass,const struct intel_perf_query_result * accumulated_results,union VkPerformanceCounterResultKHR * results)436*61046927SAndroid Build Coastguard Worker anv_perf_write_pass_results(struct intel_perf_config *perf,
437*61046927SAndroid Build Coastguard Worker struct anv_query_pool *pool, uint32_t pass,
438*61046927SAndroid Build Coastguard Worker const struct intel_perf_query_result *accumulated_results,
439*61046927SAndroid Build Coastguard Worker union VkPerformanceCounterResultKHR *results)
440*61046927SAndroid Build Coastguard Worker {
441*61046927SAndroid Build Coastguard Worker const struct intel_perf_query_info *query = pool->pass_query[pass];
442*61046927SAndroid Build Coastguard Worker
443*61046927SAndroid Build Coastguard Worker for (uint32_t c = 0; c < pool->n_counters; c++) {
444*61046927SAndroid Build Coastguard Worker const struct intel_perf_counter_pass *counter_pass = &pool->counter_pass[c];
445*61046927SAndroid Build Coastguard Worker
446*61046927SAndroid Build Coastguard Worker if (counter_pass->query != query)
447*61046927SAndroid Build Coastguard Worker continue;
448*61046927SAndroid Build Coastguard Worker
449*61046927SAndroid Build Coastguard Worker switch (pool->pass_query[pass]->kind) {
450*61046927SAndroid Build Coastguard Worker case INTEL_PERF_QUERY_TYPE_PIPELINE: {
451*61046927SAndroid Build Coastguard Worker assert(counter_pass->counter->data_type == INTEL_PERF_COUNTER_DATA_TYPE_UINT64);
452*61046927SAndroid Build Coastguard Worker uint32_t accu_offset = counter_pass->counter->offset / sizeof(uint64_t);
453*61046927SAndroid Build Coastguard Worker results[c].uint64 = accumulated_results->accumulator[accu_offset];
454*61046927SAndroid Build Coastguard Worker break;
455*61046927SAndroid Build Coastguard Worker }
456*61046927SAndroid Build Coastguard Worker
457*61046927SAndroid Build Coastguard Worker case INTEL_PERF_QUERY_TYPE_OA:
458*61046927SAndroid Build Coastguard Worker case INTEL_PERF_QUERY_TYPE_RAW:
459*61046927SAndroid Build Coastguard Worker switch (counter_pass->counter->data_type) {
460*61046927SAndroid Build Coastguard Worker case INTEL_PERF_COUNTER_DATA_TYPE_UINT64:
461*61046927SAndroid Build Coastguard Worker results[c].uint64 =
462*61046927SAndroid Build Coastguard Worker counter_pass->counter->oa_counter_read_uint64(perf,
463*61046927SAndroid Build Coastguard Worker counter_pass->query,
464*61046927SAndroid Build Coastguard Worker accumulated_results);
465*61046927SAndroid Build Coastguard Worker break;
466*61046927SAndroid Build Coastguard Worker case INTEL_PERF_COUNTER_DATA_TYPE_FLOAT:
467*61046927SAndroid Build Coastguard Worker results[c].float32 =
468*61046927SAndroid Build Coastguard Worker counter_pass->counter->oa_counter_read_float(perf,
469*61046927SAndroid Build Coastguard Worker counter_pass->query,
470*61046927SAndroid Build Coastguard Worker accumulated_results);
471*61046927SAndroid Build Coastguard Worker break;
472*61046927SAndroid Build Coastguard Worker default:
473*61046927SAndroid Build Coastguard Worker /* So far we aren't using uint32, double or bool32... */
474*61046927SAndroid Build Coastguard Worker unreachable("unexpected counter data type");
475*61046927SAndroid Build Coastguard Worker }
476*61046927SAndroid Build Coastguard Worker break;
477*61046927SAndroid Build Coastguard Worker
478*61046927SAndroid Build Coastguard Worker default:
479*61046927SAndroid Build Coastguard Worker unreachable("invalid query type");
480*61046927SAndroid Build Coastguard Worker }
481*61046927SAndroid Build Coastguard Worker
482*61046927SAndroid Build Coastguard Worker /* The Vulkan extension only has nanoseconds as a unit */
483*61046927SAndroid Build Coastguard Worker if (counter_pass->counter->units == INTEL_PERF_COUNTER_UNITS_US) {
484*61046927SAndroid Build Coastguard Worker assert(counter_pass->counter->data_type == INTEL_PERF_COUNTER_DATA_TYPE_UINT64);
485*61046927SAndroid Build Coastguard Worker results[c].uint64 *= 1000;
486*61046927SAndroid Build Coastguard Worker }
487*61046927SAndroid Build Coastguard Worker }
488*61046927SAndroid Build Coastguard Worker }
489