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
25 #include "gen_perf_mdapi.h"
27 #include "dev/gen_device_info.h"
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
)
35 switch (devinfo
->gen
) {
37 struct gen7_mdapi_metrics
*mdapi_data
= (struct gen7_mdapi_metrics
*) data
;
39 if (data_size
< sizeof(*mdapi_data
))
42 assert(devinfo
->is_haswell
);
44 for (int i
= 0; i
< ARRAY_SIZE(mdapi_data
->ACounters
); i
++)
45 mdapi_data
->ACounters
[i
] = result
->accumulator
[1 + i
];
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
];
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
);
61 struct gen8_mdapi_metrics
*mdapi_data
= (struct gen8_mdapi_metrics
*) data
;
63 if (data_size
< sizeof(*mdapi_data
))
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
];
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
);
92 struct gen9_mdapi_metrics
*mdapi_data
= (struct gen9_mdapi_metrics
*) data
;
94 if (data_size
< sizeof(*mdapi_data
))
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
];
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
);
121 unreachable("unexpected gen");