17ec681f3Smrg/* 27ec681f3Smrg * Copyright © 2020 Collabora, Ltd. 37ec681f3Smrg * Author: Antonio Caggiano <antonio.caggiano@collabora.com> 47ec681f3Smrg * Author: Robert Beckett <bob.beckett@collabora.com> 57ec681f3Smrg * Author: Corentin Noël <corentin.noel@collabora.com> 67ec681f3Smrg * 77ec681f3Smrg * SPDX-License-Identifier: MIT 87ec681f3Smrg */ 97ec681f3Smrg 107ec681f3Smrg#pragma once 117ec681f3Smrg 127ec681f3Smrg#include <memory> 137ec681f3Smrg#include <string> 147ec681f3Smrg#include <unordered_map> 157ec681f3Smrg#include <vector> 167ec681f3Smrg 177ec681f3Smrg#include "pps_counter.h" 187ec681f3Smrg#include "pps_device.h" 197ec681f3Smrg 207ec681f3Smrgnamespace pps 217ec681f3Smrg{ 227ec681f3Smrg/// @brief Abstract Driver class 237ec681f3Smrgclass Driver 247ec681f3Smrg{ 257ec681f3Smrg public: 267ec681f3Smrg /// @return A map of supported DRM device names and their relative pps driver 277ec681f3Smrg static const std::unordered_map<std::string, std::unique_ptr<Driver>> &get_supported_drivers(); 287ec681f3Smrg 297ec681f3Smrg /// @return A list of supported DRM device names 307ec681f3Smrg static const std::vector<std::string> supported_device_names(); 317ec681f3Smrg 327ec681f3Smrg /// @return A driver supporting a specific DRM device 337ec681f3Smrg static Driver *get_driver(DrmDevice &&drm_device); 347ec681f3Smrg 357ec681f3Smrg /// @return The name of a default selected PPS driver 367ec681f3Smrg static std::string default_driver_name(); 377ec681f3Smrg 387ec681f3Smrg /// @return The name of a driver based on the request, otherwise the default driver name 397ec681f3Smrg static std::string find_driver_name(const char *requested_name); 407ec681f3Smrg 417ec681f3Smrg Driver() = default; 427ec681f3Smrg virtual ~Driver() = default; 437ec681f3Smrg 447ec681f3Smrg // Forbid copy 457ec681f3Smrg Driver(const Driver &) = delete; 467ec681f3Smrg Driver &operator=(const Driver &) = delete; 477ec681f3Smrg 487ec681f3Smrg /// @return The minimum sampling period for the current device 497ec681f3Smrg virtual uint64_t get_min_sampling_period_ns() = 0; 507ec681f3Smrg 517ec681f3Smrg /// @brief Enable a counter by its ID 527ec681f3Smrg virtual void enable_counter(uint32_t counter_id) = 0; 537ec681f3Smrg 547ec681f3Smrg virtual void enable_all_counters() = 0; 557ec681f3Smrg 567ec681f3Smrg /// @brief Initialize performance counters data such as groups and counters 577ec681f3Smrg /// @return Whether it was successful or not 587ec681f3Smrg virtual bool init_perfcnt() = 0; 597ec681f3Smrg 607ec681f3Smrg /// @brief Enables performance counters, meaning that from now on they can be sampled 617ec681f3Smrg virtual void enable_perfcnt(uint64_t sampling_period_ns) = 0; 627ec681f3Smrg 637ec681f3Smrg /// @brief Disables performance counters on the device 647ec681f3Smrg virtual void disable_perfcnt() = 0; 657ec681f3Smrg 667ec681f3Smrg /// @brief Asking the GPU to dump performance counters could have different meanings 677ec681f3Smrg /// depending on the concrete driver. Some could just ask the GPU to dump counters to a 687ec681f3Smrg /// user space buffer, while some others will need to read data from a stream which was 697ec681f3Smrg /// written asynchronously. 707ec681f3Smrg /// @return Whether it was able to dump, false otherwise 717ec681f3Smrg virtual bool dump_perfcnt() = 0; 727ec681f3Smrg 737ec681f3Smrg /// @brief After dumping performance counters, with this function you can iterate 747ec681f3Smrg /// through the samples collected. 757ec681f3Smrg /// @return The CPU timestamp associated to current sample, or 0 if there are no more samples 767ec681f3Smrg virtual uint64_t next() = 0; 777ec681f3Smrg 787ec681f3Smrg DrmDevice drm_device; 797ec681f3Smrg 807ec681f3Smrg /// List of counter groups 817ec681f3Smrg std::vector<CounterGroup> groups; 827ec681f3Smrg 837ec681f3Smrg /// List of counters exposed by the GPU 847ec681f3Smrg std::vector<Counter> counters; 857ec681f3Smrg 867ec681f3Smrg /// List of counters that are actually enabled 877ec681f3Smrg std::vector<Counter> enabled_counters; 887ec681f3Smrg 897ec681f3Smrg protected: 907ec681f3Smrg // Prevent object slicing by allowing move only from subclasses 917ec681f3Smrg Driver(Driver &&) = default; 927ec681f3Smrg Driver &operator=(Driver &&) = default; 937ec681f3Smrg}; 947ec681f3Smrg 957ec681f3Smrg} // namespace pps 96