2
* Copyright © 2020-2021 Collabora, Ltd.
3
* Author: Antonio Caggiano <antonio.caggiano@collabora.com>
5
* SPDX-License-Identifier: MIT
10
#include <pps/pps_driver.h>
13
struct intel_perf_query_info;
21
/// @brief Variable length sequence of bytes generated by Intel Obstervation Architecture (OA)
23
/// Timestamp in the GPU clock domain
26
/// drm_i915_perf_record_header + report data
27
std::vector<uint8_t> data;
30
/// @brief PPS Driver implementation for Intel graphics devices.
31
/// When sampling it may collect multiple perf-records at once. Each perf-record holds multiple
32
/// counter values. Those values are continuously incremented by the GPU. In order to get a delta,
33
/// the driver computes an _accumulation_ (`last_perf_record - previous_perf_record`).
34
/// For optimization purposes, it might ignore some perf-records, considering only those
35
/// perf-records close to the boundary of the sampling period range.
36
class IntelDriver : public Driver
42
uint64_t get_min_sampling_period_ns() override;
43
bool init_perfcnt() override;
44
void enable_counter(uint32_t counter_id) override;
45
void enable_all_counters() override;
46
void enable_perfcnt(uint64_t sampling_period_ns) override;
47
void disable_perfcnt() override;
48
bool dump_perfcnt() override;
49
uint64_t next() override;
50
uint32_t gpu_clock_id() const override;
51
uint64_t gpu_timestamp() const override;
54
/// @brief Requests the next perf sample
55
/// @return The sample GPU timestamp
58
/// @param data Buffer of bytes to parse
59
/// @param byte_count Number of bytes to parse
60
/// @return A list of perf records parsed from raw data passed as input
61
std::vector<PerfRecord> parse_perf_records(const std::vector<uint8_t> &data, size_t byte_count);
63
/// @brief Reads data from the GPU metric set
64
void read_data_from_metric_set();
66
/// Sampling period in nanoseconds requested by the datasource
67
uint64_t sampling_period_ns = 0;
69
/// Last upper 32bits of the GPU timestamp in the parsed reports
70
uint64_t gpu_timestamp_udw = 0;
72
/// Keep track of the timestamp of the last sample generated (upper & lower
74
uint64_t last_gpu_timestamp = 0;
76
/// Data buffer used to store data read from the metric set
77
std::vector<uint8_t> metric_buffer = std::vector<uint8_t>(1024, 0);
78
/// Number of bytes read so far still un-parsed.
79
/// Reset once bytes from the metric buffer are parsed to perf records
80
size_t total_bytes_read = 0;
82
/// List of OA perf records read so far
83
std::vector<PerfRecord> records;
85
std::unique_ptr<IntelPerf> perf;
87
// Gpu clock ID used to correlate GPU/CPU timestamps
88
uint32_t clock_id = 0;
91
intel_perf_query_info *selected_query = nullptr;