intel/perf: report query split for mdapi
[mesa.git] / src / intel / perf / gen_perf_mdapi.c
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 #include "gen_perf.h"
25 #include "gen_perf_mdapi.h"
26
27 #include "dev/gen_device_info.h"
28
29 int
30 gen_perf_query_result_write_mdapi(void *data, uint32_t data_size,
31 const struct gen_device_info *devinfo,
32 const struct gen_perf_query_result *result,
33 uint64_t freq_start, uint64_t freq_end)
34 {
35 switch (devinfo->gen) {
36 case 7: {
37 struct gen7_mdapi_metrics *mdapi_data = (struct gen7_mdapi_metrics *) data;
38
39 if (data_size < sizeof(*mdapi_data))
40 return 0;
41
42 assert(devinfo->is_haswell);
43
44 for (int i = 0; i < ARRAY_SIZE(mdapi_data->ACounters); i++)
45 mdapi_data->ACounters[i] = result->accumulator[1 + i];
46
47 for (int i = 0; i < ARRAY_SIZE(mdapi_data->NOACounters); i++) {
48 mdapi_data->NOACounters[i] =
49 result->accumulator[1 + ARRAY_SIZE(mdapi_data->ACounters) + i];
50 }
51
52 mdapi_data->ReportsCount = result->reports_accumulated;
53 mdapi_data->TotalTime =
54 gen_device_info_timebase_scale(devinfo, result->accumulator[0]);
55 mdapi_data->CoreFrequency = freq_end;
56 mdapi_data->CoreFrequencyChanged = freq_end != freq_start;
57 mdapi_data->SplitOccured = result->query_disjoint;
58 return sizeof(*mdapi_data);
59 }
60 case 8: {
61 struct gen8_mdapi_metrics *mdapi_data = (struct gen8_mdapi_metrics *) data;
62
63 if (data_size < sizeof(*mdapi_data))
64 return 0;
65
66 for (int i = 0; i < ARRAY_SIZE(mdapi_data->OaCntr); i++)
67 mdapi_data->OaCntr[i] = result->accumulator[2 + i];
68 for (int i = 0; i < ARRAY_SIZE(mdapi_data->NoaCntr); i++) {
69 mdapi_data->NoaCntr[i] =
70 result->accumulator[2 + ARRAY_SIZE(mdapi_data->OaCntr) + i];
71 }
72
73 mdapi_data->ReportId = result->hw_id;
74 mdapi_data->ReportsCount = result->reports_accumulated;
75 mdapi_data->TotalTime =
76 gen_device_info_timebase_scale(devinfo, result->accumulator[0]);
77 mdapi_data->BeginTimestamp =
78 gen_device_info_timebase_scale(devinfo, result->begin_timestamp);
79 mdapi_data->GPUTicks = result->accumulator[1];
80 mdapi_data->CoreFrequency = freq_end;
81 mdapi_data->CoreFrequencyChanged = freq_end != freq_start;
82 mdapi_data->SliceFrequency =
83 (result->slice_frequency[0] + result->slice_frequency[1]) / 2ULL;
84 mdapi_data->UnsliceFrequency =
85 (result->unslice_frequency[0] + result->unslice_frequency[1]) / 2ULL;
86 mdapi_data->SplitOccured = result->query_disjoint;
87 return sizeof(*mdapi_data);
88 }
89 case 9:
90 case 10:
91 case 11: {
92 struct gen9_mdapi_metrics *mdapi_data = (struct gen9_mdapi_metrics *) data;
93
94 if (data_size < sizeof(*mdapi_data))
95 return 0;
96
97 for (int i = 0; i < ARRAY_SIZE(mdapi_data->OaCntr); i++)
98 mdapi_data->OaCntr[i] = result->accumulator[2 + i];
99 for (int i = 0; i < ARRAY_SIZE(mdapi_data->NoaCntr); i++) {
100 mdapi_data->NoaCntr[i] =
101 result->accumulator[2 + ARRAY_SIZE(mdapi_data->OaCntr) + i];
102 }
103
104 mdapi_data->ReportId = result->hw_id;
105 mdapi_data->ReportsCount = result->reports_accumulated;
106 mdapi_data->TotalTime =
107 gen_device_info_timebase_scale(devinfo, result->accumulator[0]);
108 mdapi_data->BeginTimestamp =
109 gen_device_info_timebase_scale(devinfo, result->begin_timestamp);
110 mdapi_data->GPUTicks = result->accumulator[1];
111 mdapi_data->CoreFrequency = freq_end;
112 mdapi_data->CoreFrequencyChanged = freq_end != freq_start;
113 mdapi_data->SliceFrequency =
114 (result->slice_frequency[0] + result->slice_frequency[1]) / 2ULL;
115 mdapi_data->UnsliceFrequency =
116 (result->unslice_frequency[0] + result->unslice_frequency[1]) / 2ULL;
117 mdapi_data->SplitOccured = result->query_disjoint;
118 return sizeof(*mdapi_data);
119 }
120 default:
121 unreachable("unexpected gen");
122 }
123 }