Path: blob/21.2-virgl/src/freedreno/ds/fd_pps_driver.h
4565 views
/*1* Copyright © 2021 Google, Inc.2*3* SPDX-License-Identifier: MIT4*/56#pragma once78#include "pps/pps_driver.h"910#include "common/freedreno_dev_info.h"11#include "drm/freedreno_drmif.h"12#include "drm/freedreno_ringbuffer.h"13#include "perfcntrs/freedreno_dt.h"14#include "perfcntrs/freedreno_perfcntr.h"1516namespace pps17{1819class FreedrenoDriver : public Driver20{21public:22uint64_t get_min_sampling_period_ns() override;23bool init_perfcnt() override;24void enable_counter(uint32_t counter_id) override;25void enable_all_counters() override;26void enable_perfcnt(uint64_t sampling_period_ns) override;27void disable_perfcnt() override;28bool dump_perfcnt() override;29uint64_t next() override;3031private:32struct fd_device *dev;33struct fd_pipe *pipe;34uint32_t gpu_id;35uint32_t max_freq;36uint32_t next_counter_id;37uint32_t next_countable_id;38uint64_t last_dump_ts = 0;39uint64_t last_capture_ts;4041bool has_suspend_count;42uint32_t suspend_count;4344const struct fd_dev_info *info;4546/**47* The memory mapped i/o space for counter readback:48*/49void *io;5051const struct fd_perfcntr_group *perfcntrs;52unsigned num_perfcntrs;5354/**55* The number of counters assigned per perfcntr group, the index56* into this matches the index into perfcntrs57*/58std::vector<int> assigned_counters;5960/*61* Values that can be used by derived counters evaluation62*/63float time; /* time since last sample in fraction of second */64// uint32_t cycles; /* the number of clock cycles since last sample */6566void setup_a6xx_counters();6768void configure_counters(bool reset, bool wait);69void collect_countables();7071/**72* Split out countable mutable state from the class so that copy-73* constructor does something sane when lambda derive function74* tries to get the countable value.75*/76struct CountableState {77uint64_t last_value, value;78const struct fd_perfcntr_countable *countable;79const struct fd_perfcntr_counter *counter;80};8182std::vector<struct CountableState> state;8384/**85* Performance counters on adreno consist of sets of counters in various86* blocks of the GPU, where each counter can be can be muxed to collect87* one of a set of countables.88*89* But the countables tend to be too low level to be directly useful to90* visualize. Instead various combinations of countables are combined91* with various formulas to derive the high level "Counter" value exposed92* via gfx-pps.93*94* This class serves to decouple the logic of those formulas from the95* details of collecting countable values.96*/97class Countable {98public:99Countable(FreedrenoDriver *d, std::string name);100101operator int64_t() const { return get_value(); };102103void configure(struct fd_ringbuffer *ring, bool reset);104void collect();105void resolve();106107private:108109uint64_t get_value() const;110111uint32_t id;112FreedrenoDriver *d;113std::string name;114};115116Countable countable(std::string name);117118std::vector<Countable> countables;119120/**121* A derived "Counter" (from pps's perspective)122*/123class DerivedCounter : public Counter {124public:125DerivedCounter(FreedrenoDriver *d, std::string name, Counter::Units units,126std::function<int64_t()> derive);127};128129DerivedCounter counter(std::string name, Counter::Units units,130std::function<int64_t()> derive);131};132133} // namespace pps134135136