1 /* 2 * Copyright © 2020-2021 Collabora, Ltd. 3 * Author: Antonio Caggiano <[email protected]> 4 * Author: Rohan Garg <[email protected]> 5 * Author: Robert Beckett <[email protected]> 6 * 7 * SPDX-License-Identifier: MIT 8 */ 9 10 #pragma once 11 12 #include <pps/pps_driver.h> 13 14 #include "pan_pps_perf.h" 15 16 namespace pps { 17 /// @brief Panfrost implementation of PPS driver. 18 /// This driver queries the GPU through `drm/panfrost_drm.h`, using performance 19 /// counters ioctls, which can be enabled by setting a kernel parameter: 20 /// `modprobe panfrost unstable_ioctls=1`. The ioctl needs a buffer to copy data 21 /// from kernel to user space. 22 class PanfrostDriver : public Driver { 23 public: 24 static inline PanfrostDriver &into(Driver &dri); 25 static inline const PanfrostDriver &into(const Driver &dri); 26 27 /// @param A list of mali counter names 28 /// @return A pair with two lists: counter groups and available counters 29 static std::pair<std::vector<CounterGroup>, std::vector<Counter>> 30 create_available_counters(const PanfrostPerf &perf); 31 32 PanfrostDriver(); 33 ~PanfrostDriver(); 34 35 uint64_t get_min_sampling_period_ns() override; 36 bool init_perfcnt() override; 37 void enable_counter(uint32_t counter_id) override; 38 void enable_all_counters() override; 39 void enable_perfcnt(uint64_t sampling_period_ns) override; 40 void disable_perfcnt() override; 41 bool dump_perfcnt() override; 42 uint64_t next() override; 43 uint32_t gpu_clock_id() const override; 44 uint64_t gpu_timestamp() const override; 45 bool cpu_gpu_timestamp(uint64_t &cpu_timestamp, 46 uint64_t &gpu_timestamp) const override; 47 48 uint64_t last_dump_ts = 0; 49 50 std::unique_ptr<PanfrostDevice> dev = nullptr; 51 std::unique_ptr<PanfrostPerf> perf = nullptr; 52 }; 53 54 PanfrostDriver & into(Driver & dri)55PanfrostDriver::into(Driver &dri) 56 { 57 return reinterpret_cast<PanfrostDriver &>(dri); 58 } 59 60 const PanfrostDriver & into(const Driver & dri)61PanfrostDriver::into(const Driver &dri) 62 { 63 return reinterpret_cast<const PanfrostDriver &>(dri); 64 } 65 66 } // namespace pps 67