intel/perf: expose timestamp begin 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 return sizeof(*mdapi_data);
58 }
59 case 8: {
60 struct gen8_mdapi_metrics *mdapi_data = (struct gen8_mdapi_metrics *) data;
61
62 if (data_size < sizeof(*mdapi_data))
63 return 0;
64
65 for (int i = 0; i < ARRAY_SIZE(mdapi_data->OaCntr); i++)
66 mdapi_data->OaCntr[i] = result->accumulator[2 + i];
67 for (int i = 0; i < ARRAY_SIZE(mdapi_data->NoaCntr); i++) {
68 mdapi_data->NoaCntr[i] =
69 result->accumulator[2 + ARRAY_SIZE(mdapi_data->OaCntr) + i];
70 }
71
72 mdapi_data->ReportId = result->hw_id;
73 mdapi_data->ReportsCount = result->reports_accumulated;
74 mdapi_data->TotalTime =
75 gen_device_info_timebase_scale(devinfo, result->accumulator[0]);
76 mdapi_data->BeginTimestamp = result->begin_timestamp;
77 mdapi_data->GPUTicks = result->accumulator[1];
78 mdapi_data->CoreFrequency = freq_end;
79 mdapi_data->CoreFrequencyChanged = freq_end != freq_start;
80 mdapi_data->SliceFrequency =
81 (result->slice_frequency[0] + result->slice_frequency[1]) / 2ULL;
82 mdapi_data->UnsliceFrequency =
83 (result->unslice_frequency[0] + result->unslice_frequency[1]) / 2ULL;
84 return sizeof(*mdapi_data);
85 }
86 case 9:
87 case 10:
88 case 11: {
89 struct gen9_mdapi_metrics *mdapi_data = (struct gen9_mdapi_metrics *) data;
90
91 if (data_size < sizeof(*mdapi_data))
92 return 0;
93
94 for (int i = 0; i < ARRAY_SIZE(mdapi_data->OaCntr); i++)
95 mdapi_data->OaCntr[i] = result->accumulator[2 + i];
96 for (int i = 0; i < ARRAY_SIZE(mdapi_data->NoaCntr); i++) {
97 mdapi_data->NoaCntr[i] =
98 result->accumulator[2 + ARRAY_SIZE(mdapi_data->OaCntr) + i];
99 }
100
101 mdapi_data->ReportId = result->hw_id;
102 mdapi_data->ReportsCount = result->reports_accumulated;
103 mdapi_data->TotalTime =
104 gen_device_info_timebase_scale(devinfo, result->accumulator[0]);
105 mdapi_data->BeginTimestamp = result->begin_timestamp;
106 mdapi_data->GPUTicks = result->accumulator[1];
107 mdapi_data->CoreFrequency = freq_end;
108 mdapi_data->CoreFrequencyChanged = freq_end != freq_start;
109 mdapi_data->SliceFrequency =
110 (result->slice_frequency[0] + result->slice_frequency[1]) / 2ULL;
111 mdapi_data->UnsliceFrequency =
112 (result->unslice_frequency[0] + result->unslice_frequency[1]) / 2ULL;
113 return sizeof(*mdapi_data);
114 }
115 default:
116 unreachable("unexpected gen");
117 }
118 }