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
21 * DEALINGS IN THE SOFTWARE.
28 #include "anv_private.h"
30 #include "perf/gen_perf.h"
31 #include "perf/gen_perf_mdapi.h"
33 struct gen_perf_config
*
34 anv_get_perf(const struct gen_device_info
*devinfo
, int fd
)
36 struct gen_perf_config
*perf
= gen_perf_new(NULL
);
38 gen_perf_init_metrics(perf
, devinfo
, fd
);
40 /* We need DRM_I915_PERF_PROP_HOLD_PREEMPTION support, only available in
43 if (anv_gem_get_param(fd
, I915_PARAM_PERF_REVISION
) < 3)
54 anv_device_perf_init(struct anv_device
*device
)
60 anv_device_perf_open(struct anv_device
*device
, uint64_t metric_id
)
62 uint64_t properties
[DRM_I915_PERF_PROP_MAX
* 2];
63 struct drm_i915_perf_open_param param
;
66 properties
[p
++] = DRM_I915_PERF_PROP_SAMPLE_OA
;
67 properties
[p
++] = true;
69 properties
[p
++] = DRM_I915_PERF_PROP_OA_METRICS_SET
;
70 properties
[p
++] = metric_id
;
72 properties
[p
++] = DRM_I915_PERF_PROP_OA_FORMAT
;
73 properties
[p
++] = device
->info
.gen
>= 8 ?
74 I915_OA_FORMAT_A32u40_A4u32_B8_C8
:
75 I915_OA_FORMAT_A45_B8_C8
;
77 properties
[p
++] = DRM_I915_PERF_PROP_OA_EXPONENT
;
78 properties
[p
++] = 31; /* slowest sampling period */
80 properties
[p
++] = DRM_I915_PERF_PROP_CTX_HANDLE
;
81 properties
[p
++] = device
->context_id
;
83 properties
[p
++] = DRM_I915_PERF_PROP_HOLD_PREEMPTION
;
84 properties
[p
++] = true;
86 memset(¶m
, 0, sizeof(param
));
88 param
.flags
|= I915_PERF_FLAG_FD_CLOEXEC
| I915_PERF_FLAG_FD_NONBLOCK
;
89 param
.properties_ptr
= (uintptr_t)properties
;
90 param
.num_properties
= p
/ 2;
92 stream_fd
= gen_ioctl(device
->fd
, DRM_IOCTL_I915_PERF_OPEN
, ¶m
);
96 VkResult
anv_InitializePerformanceApiINTEL(
98 const VkInitializePerformanceApiInfoINTEL
* pInitializeInfo
)
100 ANV_FROM_HANDLE(anv_device
, device
, _device
);
101 const struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
104 return VK_ERROR_EXTENSION_NOT_PRESENT
;
106 /* Not much to do here */
110 VkResult
anv_GetPerformanceParameterINTEL(
112 VkPerformanceParameterTypeINTEL parameter
,
113 VkPerformanceValueINTEL
* pValue
)
115 ANV_FROM_HANDLE(anv_device
, device
, _device
);
116 const struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
119 return VK_ERROR_EXTENSION_NOT_PRESENT
;
121 VkResult result
= VK_SUCCESS
;
123 case VK_PERFORMANCE_PARAMETER_TYPE_HW_COUNTERS_SUPPORTED_INTEL
:
124 pValue
->type
= VK_PERFORMANCE_VALUE_TYPE_BOOL_INTEL
;
125 pValue
->data
.valueBool
= VK_TRUE
;
128 case VK_PERFORMANCE_PARAMETER_TYPE_STREAM_MARKER_VALID_BITS_INTEL
:
129 pValue
->type
= VK_PERFORMANCE_VALUE_TYPE_UINT32_INTEL
;
130 pValue
->data
.value32
= 25;
134 result
= VK_ERROR_FEATURE_NOT_PRESENT
;
141 VkResult
anv_CmdSetPerformanceMarkerINTEL(
142 VkCommandBuffer commandBuffer
,
143 const VkPerformanceMarkerInfoINTEL
* pMarkerInfo
)
145 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
147 cmd_buffer
->intel_perf_marker
= pMarkerInfo
->marker
;
152 VkResult
anv_AcquirePerformanceConfigurationINTEL(
154 const VkPerformanceConfigurationAcquireInfoINTEL
* pAcquireInfo
,
155 VkPerformanceConfigurationINTEL
* pConfiguration
)
157 ANV_FROM_HANDLE(anv_device
, device
, _device
);
158 const struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
160 struct gen_perf_registers
*perf_config
=
161 gen_perf_load_configuration(pdevice
->perf
, device
->fd
,
162 GEN_PERF_QUERY_GUID_MDAPI
);
164 return VK_INCOMPLETE
;
166 int ret
= gen_perf_store_configuration(pdevice
->perf
, device
->fd
,
167 perf_config
, NULL
/* guid */);
169 ralloc_free(perf_config
);
170 return VK_INCOMPLETE
;
173 *pConfiguration
= (VkPerformanceConfigurationINTEL
) (uint64_t) ret
;
178 VkResult
anv_ReleasePerformanceConfigurationINTEL(
180 VkPerformanceConfigurationINTEL _configuration
)
182 ANV_FROM_HANDLE(anv_device
, device
, _device
);
183 uint64_t config
= (uint64_t) _configuration
;
185 gen_ioctl(device
->fd
, DRM_IOCTL_I915_PERF_REMOVE_CONFIG
, &config
);
190 VkResult
anv_QueueSetPerformanceConfigurationINTEL(
192 VkPerformanceConfigurationINTEL _configuration
)
194 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
195 struct anv_device
*device
= queue
->device
;
196 uint64_t configuration
= (uint64_t) _configuration
;
198 if (device
->perf_fd
< 0) {
199 device
->perf_fd
= anv_device_perf_open(device
, configuration
);
200 if (device
->perf_fd
< 0)
201 return VK_ERROR_INITIALIZATION_FAILED
;
203 int ret
= gen_ioctl(device
->perf_fd
, I915_PERF_IOCTL_CONFIG
,
204 (void *)(uintptr_t) _configuration
);
206 return anv_device_set_lost(device
, "i915-perf config failed: %m");
212 void anv_UninitializePerformanceApiINTEL(
215 ANV_FROM_HANDLE(anv_device
, device
, _device
);
217 if (device
->perf_fd
>= 0) {
218 close(device
->perf_fd
);
219 device
->perf_fd
= -1;