intel/perf: export performance counters sorted by [group|set] and name
[mesa.git] / src / intel / perf / gen_perf_mdapi.h
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 gen10_mdapi_metrics gen9_mdapi_metrics
114 #define gen11_mdapi_metrics gen9_mdapi_metrics
115
116 struct mdapi_pipeline_metrics {
117 uint64_t IAVertices;
118 uint64_t IAPrimitives;
119 uint64_t VSInvocations;
120 uint64_t GSInvocations;
121 uint64_t GSPrimitives;
122 uint64_t CInvocations;
123 uint64_t CPrimitives;
124 uint64_t PSInvocations;
125 uint64_t HSInvocations;
126 uint64_t DSInvocations;
127 uint64_t CSInvocations;
128 uint64_t Reserved1; /* Gen10+ */
129 };
130
131 int gen_perf_query_result_write_mdapi(void *data, uint32_t data_size,
132 const struct gen_device_info *devinfo,
133 const struct gen_perf_query_result *result,
134 uint64_t freq_start, uint64_t freq_end);
135
136 static inline void gen_perf_query_mdapi_write_perfcntr(void *data, uint32_t data_size,
137 const struct gen_device_info *devinfo,
138 const uint64_t *begin_perf_cntrs,
139 const uint64_t *end_perf_cntrs)
140 {
141 /* Only bits 0:43 of the 64bit registers contains the value. */
142 const uint64_t mask = (1ull << 44) - 1;
143
144 switch (devinfo->gen) {
145 case 8: {
146 if (data_size < sizeof(struct gen8_mdapi_metrics))
147 return;
148 struct gen8_mdapi_metrics *mdapi_data = data;
149 mdapi_data->PerfCounter1 =
150 (end_perf_cntrs[0] & mask) - (begin_perf_cntrs[0] & mask);
151 mdapi_data->PerfCounter2 =
152 (end_perf_cntrs[1] & mask) - (begin_perf_cntrs[1] & mask);
153 break;
154 }
155 case 9:
156 case 10:
157 case 11: {
158 if (data_size < sizeof(struct gen9_mdapi_metrics))
159 return;
160 struct gen9_mdapi_metrics *mdapi_data = data;
161 mdapi_data->PerfCounter1 =
162 (end_perf_cntrs[0] & mask) - (begin_perf_cntrs[0] & mask);
163 mdapi_data->PerfCounter2 =
164 (end_perf_cntrs[1] & mask) - (begin_perf_cntrs[1] & mask);
165 break;
166 }
167 default:
168 break;
169 }
170 }
171
172 static inline void gen_perf_query_mdapi_write_marker(void *data, uint32_t data_size,
173 const struct gen_device_info *devinfo,
174 uint64_t value)
175 {
176 switch (devinfo->gen) {
177 case 8: {
178 if (data_size < sizeof(struct gen8_mdapi_metrics))
179 return;
180 struct gen8_mdapi_metrics *mdapi_data = data;
181 mdapi_data->MarkerUser = value;
182 break;
183 }
184 case 9:
185 case 10:
186 case 11: {
187 if (data_size < sizeof(struct gen9_mdapi_metrics))
188 return;
189 struct gen9_mdapi_metrics *mdapi_data = data;
190 mdapi_data->MarkerUser = value;
191 break;
192 }
193 default:
194 break;
195 }
196 }
197
198 #endif /* GEN_PERF_MDAPI_H */