1*61046927SAndroid Build Coastguard Worker /* 2*61046927SAndroid Build Coastguard Worker * Copyright © 2020 Collabora, Ltd. 3*61046927SAndroid Build Coastguard Worker * Author: Antonio Caggiano <[email protected]> 4*61046927SAndroid Build Coastguard Worker * Author: Robert Beckett <[email protected]> 5*61046927SAndroid Build Coastguard Worker * Author: Corentin Noël <[email protected]> 6*61046927SAndroid Build Coastguard Worker * 7*61046927SAndroid Build Coastguard Worker * SPDX-License-Identifier: MIT 8*61046927SAndroid Build Coastguard Worker */ 9*61046927SAndroid Build Coastguard Worker 10*61046927SAndroid Build Coastguard Worker #pragma once 11*61046927SAndroid Build Coastguard Worker 12*61046927SAndroid Build Coastguard Worker #include <memory> 13*61046927SAndroid Build Coastguard Worker #include <string> 14*61046927SAndroid Build Coastguard Worker #include <unordered_map> 15*61046927SAndroid Build Coastguard Worker #include <vector> 16*61046927SAndroid Build Coastguard Worker 17*61046927SAndroid Build Coastguard Worker #include "pps_counter.h" 18*61046927SAndroid Build Coastguard Worker #include "pps_device.h" 19*61046927SAndroid Build Coastguard Worker 20*61046927SAndroid Build Coastguard Worker namespace pps 21*61046927SAndroid Build Coastguard Worker { 22*61046927SAndroid Build Coastguard Worker /// @brief Abstract Driver class 23*61046927SAndroid Build Coastguard Worker class Driver 24*61046927SAndroid Build Coastguard Worker { 25*61046927SAndroid Build Coastguard Worker public: 26*61046927SAndroid Build Coastguard Worker /// @return A map of supported DRM device names and their relative pps driver 27*61046927SAndroid Build Coastguard Worker static const std::unordered_map<std::string, std::unique_ptr<Driver>> &get_supported_drivers(); 28*61046927SAndroid Build Coastguard Worker 29*61046927SAndroid Build Coastguard Worker /// @return A list of supported DRM device names 30*61046927SAndroid Build Coastguard Worker static const std::vector<std::string> supported_device_names(); 31*61046927SAndroid Build Coastguard Worker 32*61046927SAndroid Build Coastguard Worker /// @return A driver supporting a specific DRM device 33*61046927SAndroid Build Coastguard Worker static Driver *get_driver(DrmDevice &&drm_device); 34*61046927SAndroid Build Coastguard Worker 35*61046927SAndroid Build Coastguard Worker /// @return The name of a default selected PPS driver 36*61046927SAndroid Build Coastguard Worker static std::string default_driver_name(); 37*61046927SAndroid Build Coastguard Worker 38*61046927SAndroid Build Coastguard Worker /// @return The name of a driver based on the request, otherwise the default driver name 39*61046927SAndroid Build Coastguard Worker static std::string find_driver_name(const char *requested_name); 40*61046927SAndroid Build Coastguard Worker 41*61046927SAndroid Build Coastguard Worker Driver() = default; 42*61046927SAndroid Build Coastguard Worker virtual ~Driver() = default; 43*61046927SAndroid Build Coastguard Worker 44*61046927SAndroid Build Coastguard Worker // Forbid copy 45*61046927SAndroid Build Coastguard Worker Driver(const Driver &) = delete; 46*61046927SAndroid Build Coastguard Worker Driver &operator=(const Driver &) = delete; 47*61046927SAndroid Build Coastguard Worker 48*61046927SAndroid Build Coastguard Worker /// @return Whether dump_perfcnt is preemptible is_dump_perfcnt_preemptible()49*61046927SAndroid Build Coastguard Worker virtual bool is_dump_perfcnt_preemptible() const { return true; } 50*61046927SAndroid Build Coastguard Worker 51*61046927SAndroid Build Coastguard Worker /// @return The minimum sampling period for the current device 52*61046927SAndroid Build Coastguard Worker virtual uint64_t get_min_sampling_period_ns() = 0; 53*61046927SAndroid Build Coastguard Worker 54*61046927SAndroid Build Coastguard Worker /// @brief Enable a counter by its ID 55*61046927SAndroid Build Coastguard Worker virtual void enable_counter(uint32_t counter_id) = 0; 56*61046927SAndroid Build Coastguard Worker 57*61046927SAndroid Build Coastguard Worker virtual void enable_all_counters() = 0; 58*61046927SAndroid Build Coastguard Worker 59*61046927SAndroid Build Coastguard Worker /// @brief Initialize performance counters data such as groups and counters 60*61046927SAndroid Build Coastguard Worker /// @return Whether it was successful or not 61*61046927SAndroid Build Coastguard Worker virtual bool init_perfcnt() = 0; 62*61046927SAndroid Build Coastguard Worker 63*61046927SAndroid Build Coastguard Worker /// @brief Enables performance counters, meaning that from now on they can be sampled 64*61046927SAndroid Build Coastguard Worker virtual void enable_perfcnt(uint64_t sampling_period_ns) = 0; 65*61046927SAndroid Build Coastguard Worker 66*61046927SAndroid Build Coastguard Worker /// @brief Disables performance counters on the device 67*61046927SAndroid Build Coastguard Worker virtual void disable_perfcnt() = 0; 68*61046927SAndroid Build Coastguard Worker 69*61046927SAndroid Build Coastguard Worker /// @brief Asking the GPU to dump performance counters could have different meanings 70*61046927SAndroid Build Coastguard Worker /// depending on the concrete driver. Some could just ask the GPU to dump counters to a 71*61046927SAndroid Build Coastguard Worker /// user space buffer, while some others will need to read data from a stream which was 72*61046927SAndroid Build Coastguard Worker /// written asynchronously. 73*61046927SAndroid Build Coastguard Worker /// @return Whether it was able to dump, false otherwise 74*61046927SAndroid Build Coastguard Worker virtual bool dump_perfcnt() = 0; 75*61046927SAndroid Build Coastguard Worker 76*61046927SAndroid Build Coastguard Worker /// @brief After dumping performance counters, with this function you can iterate 77*61046927SAndroid Build Coastguard Worker /// through the samples collected. 78*61046927SAndroid Build Coastguard Worker /// @return The GPU timestamp associated to current sample, or 0 if there are no more samples 79*61046927SAndroid Build Coastguard Worker virtual uint64_t next() = 0; 80*61046927SAndroid Build Coastguard Worker 81*61046927SAndroid Build Coastguard Worker /// Clock ID in which the values returned by gpu_timestamp() belong 82*61046927SAndroid Build Coastguard Worker virtual uint32_t gpu_clock_id() const = 0; 83*61046927SAndroid Build Coastguard Worker 84*61046927SAndroid Build Coastguard Worker /// Sample a timestamp from the GPU 85*61046927SAndroid Build Coastguard Worker virtual uint64_t gpu_timestamp() const = 0; 86*61046927SAndroid Build Coastguard Worker 87*61046927SAndroid Build Coastguard Worker /// Sample a timestamp from both the CPU & the GPU 88*61046927SAndroid Build Coastguard Worker /// 89*61046927SAndroid Build Coastguard Worker /// This is useful when the driver can do a better timestamp correlation 90*61046927SAndroid Build Coastguard Worker /// than sampling separately CPU & GPU timestamps. 91*61046927SAndroid Build Coastguard Worker virtual bool cpu_gpu_timestamp(uint64_t &cpu_timestamp, uint64_t &gpu_timestamp) const = 0; 92*61046927SAndroid Build Coastguard Worker 93*61046927SAndroid Build Coastguard Worker DrmDevice drm_device; 94*61046927SAndroid Build Coastguard Worker 95*61046927SAndroid Build Coastguard Worker /// List of counter groups 96*61046927SAndroid Build Coastguard Worker std::vector<CounterGroup> groups; 97*61046927SAndroid Build Coastguard Worker 98*61046927SAndroid Build Coastguard Worker /// List of counters exposed by the GPU 99*61046927SAndroid Build Coastguard Worker std::vector<Counter> counters; 100*61046927SAndroid Build Coastguard Worker 101*61046927SAndroid Build Coastguard Worker /// List of counters that are actually enabled 102*61046927SAndroid Build Coastguard Worker std::vector<Counter> enabled_counters; 103*61046927SAndroid Build Coastguard Worker 104*61046927SAndroid Build Coastguard Worker protected: 105*61046927SAndroid Build Coastguard Worker // Prevent object slicing by allowing move only from subclasses 106*61046927SAndroid Build Coastguard Worker Driver(Driver &&) = default; 107*61046927SAndroid Build Coastguard Worker Driver &operator=(Driver &&) = default; 108*61046927SAndroid Build Coastguard Worker }; 109*61046927SAndroid Build Coastguard Worker 110*61046927SAndroid Build Coastguard Worker } // namespace pps 111