1 /* 2 * Copyright © 2021 Google, Inc. 3 * 4 * SPDX-License-Identifier: MIT 5 */ 6 7 #pragma once 8 9 #include "pps/pps_driver.h" 10 11 #include "common/freedreno_dev_info.h" 12 #include "drm/freedreno_drmif.h" 13 #include "drm/freedreno_ringbuffer.h" 14 #include "perfcntrs/freedreno_dt.h" 15 #include "perfcntrs/freedreno_perfcntr.h" 16 17 namespace pps 18 { 19 20 class FreedrenoDriver : public Driver 21 { 22 public: 23 uint64_t get_min_sampling_period_ns() override; 24 bool init_perfcnt() override; 25 void enable_counter(uint32_t counter_id) override; 26 void enable_all_counters() override; 27 void enable_perfcnt(uint64_t sampling_period_ns) override; 28 void disable_perfcnt() override; 29 bool dump_perfcnt() override; 30 uint64_t next() override; 31 32 private: 33 struct fd_device *dev; 34 struct fd_pipe *pipe; 35 const struct fd_dev_id *dev_id; 36 uint32_t max_freq; 37 uint32_t next_counter_id; 38 uint32_t next_countable_id; 39 uint64_t last_dump_ts = 0; 40 uint64_t last_capture_ts; 41 42 bool has_suspend_count; 43 uint32_t suspend_count; 44 45 const struct fd_dev_info *info; 46 47 /** 48 * The memory mapped i/o space for counter readback: 49 */ 50 void *io; 51 52 const struct fd_perfcntr_group *perfcntrs; 53 unsigned num_perfcntrs; 54 55 /** 56 * The number of counters assigned per perfcntr group, the index 57 * into this matches the index into perfcntrs 58 */ 59 std::vector<int> assigned_counters; 60 61 /* 62 * Values that can be used by derived counters evaluation 63 */ 64 float time; /* time since last sample in fraction of second */ 65 // uint32_t cycles; /* the number of clock cycles since last sample */ 66 67 void setup_a6xx_counters(); 68 69 void configure_counters(bool reset, bool wait); 70 void collect_countables(); 71 72 /** 73 * Split out countable mutable state from the class so that copy- 74 * constructor does something sane when lambda derive function 75 * tries to get the countable value. 76 */ 77 struct CountableState { 78 uint64_t last_value, value; 79 const struct fd_perfcntr_countable *countable; 80 const struct fd_perfcntr_counter *counter; 81 }; 82 83 std::vector<struct CountableState> state; 84 85 /** 86 * Performance counters on adreno consist of sets of counters in various 87 * blocks of the GPU, where each counter can be can be muxed to collect 88 * one of a set of countables. 89 * 90 * But the countables tend to be too low level to be directly useful to 91 * visualize. Instead various combinations of countables are combined 92 * with various formulas to derive the high level "Counter" value exposed 93 * via gfx-pps. 94 * 95 * This class serves to decouple the logic of those formulas from the 96 * details of collecting countable values. 97 */ 98 class Countable { 99 public: 100 Countable(FreedrenoDriver *d, std::string name); 101 int64_t()102 operator int64_t() const { return get_value(); }; 103 104 void configure(struct fd_ringbuffer *ring, bool reset); 105 void collect(); 106 void resolve(); 107 108 private: 109 110 uint64_t get_value() const; 111 112 uint32_t id; 113 FreedrenoDriver *d; 114 std::string name; 115 }; 116 117 Countable countable(std::string name); 118 119 std::vector<Countable> countables; 120 121 /** 122 * A derived "Counter" (from pps's perspective) 123 */ 124 class DerivedCounter : public Counter { 125 public: 126 DerivedCounter(FreedrenoDriver *d, std::string name, Counter::Units units, 127 std::function<int64_t()> derive); 128 }; 129 130 DerivedCounter counter(std::string name, Counter::Units units, 131 std::function<int64_t()> derive); 132 }; 133 134 } // namespace pps 135