Path: blob/21.2-virgl/src/intel/ds/intel_pps_driver.h
4547 views
/*1* Copyright © 2020-2021 Collabora, Ltd.2* Author: Antonio Caggiano <[email protected]>3*4* SPDX-License-Identifier: MIT5*/67#pragma once89#include <pps/pps_driver.h>1011#include "intel_pps_perf.h"1213namespace pps14{15/// Timestamp correlation between CPU/GPU.16struct TimestampCorrelation {17/// In CLOCK_MONOTONIC18uint64_t cpu_timestamp;1920/// Engine timestamp associated with the OA unit21uint64_t gpu_timestamp;22};2324/// @brief Variable length sequence of bytes generated by Intel Obstervation Architecture (OA)25using PerfRecord = std::vector<uint8_t>;2627/// @brief PPS Driver implementation for Intel graphics devices.28/// When sampling it may collect multiple perf-records at once. Each perf-record holds multiple29/// counter values. Those values are continuously incremented by the GPU. In order to get a delta,30/// the driver computes an _accumulation_ (`last_perf_record - previous_perf_record`).31/// For optimization purposes, it might ignore some perf-records, considering only those32/// perf-records close to the boundary of the sampling period range.33class IntelDriver : public Driver34{35public:36std::optional<TimestampCorrelation> query_correlation_timestamps() const;37void get_new_correlation();3839/// @brief OA reports only have the lower 32 bits of the timestamp40/// register, while correlation data has the whole 36 bits.41/// @param gpu_ts a 32 bit OA report GPU timestamp42/// @return The CPU timestamp relative to the argument43uint64_t correlate_gpu_timestamp(uint32_t gpu_ts);4445uint64_t get_min_sampling_period_ns() override;46bool init_perfcnt() override;47void enable_counter(uint32_t counter_id) override;48void enable_all_counters() override;49void enable_perfcnt(uint64_t sampling_period_ns) override;50void disable_perfcnt() override;51bool dump_perfcnt() override;52uint64_t next() override;5354/// @brief Requests the next perf sample55/// @return The sample GPU timestamp56uint32_t gpu_next();5758/// @brief Requests the next perf sample accumulating those which59/// which duration is shorter than the requested sampling period60/// @return The sample CPU timestamp61uint64_t cpu_next();6263/// @param data Buffer of bytes to parse64/// @param byte_count Number of bytes to parse65/// @return A list of perf records parsed from raw data passed as input66std::vector<PerfRecord> parse_perf_records(const std::vector<uint8_t> &data, size_t byte_count);6768/// @brief Reads data from the GPU metric set69void read_data_from_metric_set();7071/// Sampling period in nanoseconds requested by the datasource72uint64_t sampling_period_ns = 0;7374/// Keep track of the timestamp of the last sample generated75uint64_t last_cpu_timestamp = 0;7677/// This is used to correlate CPU and GPU timestamps78std::array<TimestampCorrelation, 64> correlations;7980/// Data buffer used to store data read from the metric set81std::vector<uint8_t> metric_buffer = std::vector<uint8_t>(1024, 0);82/// Number of bytes read so far still un-parsed.83/// Reset once bytes from the metric buffer are parsed to perf records84size_t total_bytes_read = 0;8586/// List of OA perf records read so far87std::vector<PerfRecord> records;8889std::unique_ptr<IntelPerf> perf;9091// Accumulations are stored here92struct intel_perf_query_result result = {};93};9495} // namespace pps969798