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 DEALINGS
24 #ifndef GEN_PERF_MDAPI_H
25 #define GEN_PERF_MDAPI_H
29 #include "dev/gen_device_info.h"
31 struct gen_perf_query_result
;
33 /* Guid has to matches with MDAPI's. */
34 #define GEN_PERF_QUERY_GUID_MDAPI "2f01b241-7014-42a7-9eb6-a925cad3daba"
37 * Data format expected by MDAPI.
40 struct gen7_mdapi_metrics
{
43 uint64_t ACounters
[45];
44 uint64_t NOACounters
[16];
46 uint64_t PerfCounter1
;
47 uint64_t PerfCounter2
;
48 uint32_t SplitOccured
;
49 uint32_t CoreFrequencyChanged
;
50 uint64_t CoreFrequency
;
52 uint32_t ReportsCount
;
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
{
61 uint64_t OaCntr
[GTDI_QUERY_BDW_METRICS_OA_COUNT
];
62 uint64_t NoaCntr
[GTDI_QUERY_BDW_METRICS_NOA_COUNT
];
63 uint64_t BeginTimestamp
;
67 uint32_t OverrunOccured
;
69 uint64_t MarkerDriver
;
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
;
79 uint32_t ReportsCount
;
82 #define GTDI_MAX_READ_REGS 16
84 struct gen9_mdapi_metrics
{
87 uint64_t OaCntr
[GTDI_QUERY_BDW_METRICS_OA_COUNT
];
88 uint64_t NoaCntr
[GTDI_QUERY_BDW_METRICS_NOA_COUNT
];
89 uint64_t BeginTimestamp
;
93 uint32_t OverrunOccured
;
95 uint64_t MarkerDriver
;
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
;
105 uint32_t ReportsCount
;
107 uint64_t UserCntr
[GTDI_MAX_READ_REGS
];
108 uint32_t UserCntrCfgId
;
112 /* Add new definition */
113 #define gen10_mdapi_metrics gen9_mdapi_metrics
114 #define gen11_mdapi_metrics gen9_mdapi_metrics
116 struct mdapi_pipeline_metrics
{
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+ */
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
);
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
)
141 /* Only bits 0:43 of the 64bit registers contains the value. */
142 const uint64_t mask
= (1ull << 44) - 1;
144 switch (devinfo
->gen
) {
146 if (data_size
< sizeof(struct gen8_mdapi_metrics
))
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
);
158 if (data_size
< sizeof(struct gen9_mdapi_metrics
))
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
);
172 static inline void gen_perf_query_mdapi_write_marker(void *data
, uint32_t data_size
,
173 const struct gen_device_info
*devinfo
,
176 switch (devinfo
->gen
) {
178 if (data_size
< sizeof(struct gen8_mdapi_metrics
))
180 struct gen8_mdapi_metrics
*mdapi_data
= data
;
181 mdapi_data
->MarkerUser
= value
;
187 if (data_size
< sizeof(struct gen9_mdapi_metrics
))
189 struct gen9_mdapi_metrics
*mdapi_data
= data
;
190 mdapi_data
->MarkerUser
= value
;
198 #endif /* GEN_PERF_MDAPI_H */