1 /*
2 * Copyright © 2018 Intel Corporation
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * IN THE SOFTWARE.
22 */
23
24 #ifndef GEN_PERF_MDAPI_H
25 #define GEN_PERF_MDAPI_H
26
27 #include <stdint.h>
28
29 #include "dev/gen_device_info.h"
30
31 struct gen_perf_query_result;
32
33 /* Guid has to matches with MDAPI's. */
34 #define GEN_PERF_QUERY_GUID_MDAPI "2f01b241-7014-42a7-9eb6-a925cad3daba"
35
36 /*
37 * Data format expected by MDAPI.
38 */
39
40 struct gen7_mdapi_metrics {
41 uint64_t TotalTime;
42
43 uint64_t ACounters[45];
44 uint64_t NOACounters[16];
45
46 uint64_t PerfCounter1;
47 uint64_t PerfCounter2;
48 uint32_t SplitOccured;
49 uint32_t CoreFrequencyChanged;
50 uint64_t CoreFrequency;
51 uint32_t ReportId;
52 uint32_t ReportsCount;
53 };
54
55 #define GTDI_QUERY_BDW_METRICS_OA_COUNT 36
56 #define GTDI_QUERY_BDW_METRICS_OA_40b_COUNT 32
57 #define GTDI_QUERY_BDW_METRICS_NOA_COUNT 16
58 struct gen8_mdapi_metrics {
59 uint64_t TotalTime;
60 uint64_t GPUTicks;
61 uint64_t OaCntr[GTDI_QUERY_BDW_METRICS_OA_COUNT];
62 uint64_t NoaCntr[GTDI_QUERY_BDW_METRICS_NOA_COUNT];
63 uint64_t BeginTimestamp;
64 uint64_t Reserved1;
65 uint64_t Reserved2;
66 uint32_t Reserved3;
67 uint32_t OverrunOccured;
68 uint64_t MarkerUser;
69 uint64_t MarkerDriver;
70
71 uint64_t SliceFrequency;
72 uint64_t UnsliceFrequency;
73 uint64_t PerfCounter1;
74 uint64_t PerfCounter2;
75 uint32_t SplitOccured;
76 uint32_t CoreFrequencyChanged;
77 uint64_t CoreFrequency;
78 uint32_t ReportId;
79 uint32_t ReportsCount;
80 };
81
82 #define GTDI_MAX_READ_REGS 16
83
84 struct gen9_mdapi_metrics {
85 uint64_t TotalTime;
86 uint64_t GPUTicks;
87 uint64_t OaCntr[GTDI_QUERY_BDW_METRICS_OA_COUNT];
88 uint64_t NoaCntr[GTDI_QUERY_BDW_METRICS_NOA_COUNT];
89 uint64_t BeginTimestamp;
90 uint64_t Reserved1;
91 uint64_t Reserved2;
92 uint32_t Reserved3;
93 uint32_t OverrunOccured;
94 uint64_t MarkerUser;
95 uint64_t MarkerDriver;
96
97 uint64_t SliceFrequency;
98 uint64_t UnsliceFrequency;
99 uint64_t PerfCounter1;
100 uint64_t PerfCounter2;
101 uint32_t SplitOccured;
102 uint32_t CoreFrequencyChanged;
103 uint64_t CoreFrequency;
104 uint32_t ReportId;
105 uint32_t ReportsCount;
106
107 uint64_t UserCntr[GTDI_MAX_READ_REGS];
108 uint32_t UserCntrCfgId;
109 uint32_t Reserved4;
110 };
111
112 /* Add new definition */
113 #define gen11_mdapi_metrics gen9_mdapi_metrics
114
115 struct mdapi_pipeline_metrics {
116 uint64_t IAVertices;
117 uint64_t IAPrimitives;
118 uint64_t VSInvocations;
119 uint64_t GSInvocations;
120 uint64_t GSPrimitives;
121 uint64_t CInvocations;
122 uint64_t CPrimitives;
123 uint64_t PSInvocations;
124 uint64_t HSInvocations;
125 uint64_t DSInvocations;
126 uint64_t CSInvocations;
127 uint64_t Reserved1; /* Gen10+ */
128 };
129
130 int gen_perf_query_result_write_mdapi(void *data, uint32_t data_size,
131 const struct gen_device_info *devinfo,
132 const struct gen_perf_query_result *result,
133 uint64_t freq_start, uint64_t freq_end);
134
gen_perf_query_mdapi_write_perfcntr(void * data,uint32_t data_size,const struct gen_device_info * devinfo,const uint64_t * begin_perf_cntrs,const uint64_t * end_perf_cntrs)135 static inline void gen_perf_query_mdapi_write_perfcntr(void *data, uint32_t data_size,
136 const struct gen_device_info *devinfo,
137 const uint64_t *begin_perf_cntrs,
138 const uint64_t *end_perf_cntrs)
139 {
140 /* Only bits 0:43 of the 64bit registers contains the value. */
141 const uint64_t mask = (1ull << 44) - 1;
142
143 switch (devinfo->gen) {
144 case 8: {
145 if (data_size < sizeof(struct gen8_mdapi_metrics))
146 return;
147 struct gen8_mdapi_metrics *mdapi_data = data;
148 mdapi_data->PerfCounter1 =
149 (end_perf_cntrs[0] & mask) - (begin_perf_cntrs[0] & mask);
150 mdapi_data->PerfCounter2 =
151 (end_perf_cntrs[1] & mask) - (begin_perf_cntrs[1] & mask);
152 break;
153 }
154 case 9:
155 case 11: {
156 if (data_size < sizeof(struct gen9_mdapi_metrics))
157 return;
158 struct gen9_mdapi_metrics *mdapi_data = data;
159 mdapi_data->PerfCounter1 =
160 (end_perf_cntrs[0] & mask) - (begin_perf_cntrs[0] & mask);
161 mdapi_data->PerfCounter2 =
162 (end_perf_cntrs[1] & mask) - (begin_perf_cntrs[1] & mask);
163 break;
164 }
165 default:
166 break;
167 }
168 }
169
gen_perf_query_mdapi_write_marker(void * data,uint32_t data_size,const struct gen_device_info * devinfo,uint64_t value)170 static inline void gen_perf_query_mdapi_write_marker(void *data, uint32_t data_size,
171 const struct gen_device_info *devinfo,
172 uint64_t value)
173 {
174 switch (devinfo->gen) {
175 case 8: {
176 if (data_size < sizeof(struct gen8_mdapi_metrics))
177 return;
178 struct gen8_mdapi_metrics *mdapi_data = data;
179 mdapi_data->MarkerUser = value;
180 break;
181 }
182 case 9:
183 case 11: {
184 if (data_size < sizeof(struct gen9_mdapi_metrics))
185 return;
186 struct gen9_mdapi_metrics *mdapi_data = data;
187 mdapi_data->MarkerUser = value;
188 break;
189 }
190 default:
191 break;
192 }
193 }
194
195 #endif /* GEN_PERF_MDAPI_H */
196