xref: /aosp_15_r20/external/mesa3d/src/panfrost/ds/pan_pps_perf.cpp (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 #include "pan_pps_perf.h"
2 
3 #include <lib/kmod/pan_kmod.h>
4 #include <perf/pan_perf.h>
5 
6 #include <pps/pps.h>
7 #include <util/ralloc.h>
8 
9 namespace pps {
PanfrostDevice(int fd)10 PanfrostDevice::PanfrostDevice(int fd): fd(fd)
11 {
12    assert(fd >= 0);
13 }
14 
~PanfrostDevice()15 PanfrostDevice::~PanfrostDevice()
16 {
17 }
18 
PanfrostDevice(PanfrostDevice && o)19 PanfrostDevice::PanfrostDevice(PanfrostDevice &&o): fd{o.fd}
20 {
21    o.fd = -1;
22 }
23 
24 PanfrostDevice &
operator =(PanfrostDevice && o)25 PanfrostDevice::operator=(PanfrostDevice &&o)
26 {
27    std::swap(fd, o.fd);
28    return *this;
29 }
30 
PanfrostPerf(const PanfrostDevice & dev)31 PanfrostPerf::PanfrostPerf(const PanfrostDevice &dev)
32     : perf{reinterpret_cast<struct panfrost_perf *>(
33          rzalloc(nullptr, struct panfrost_perf))}
34 {
35    assert(perf);
36    assert(dev.fd >= 0);
37    panfrost_perf_init(perf, dev.fd);
38 }
39 
~PanfrostPerf()40 PanfrostPerf::~PanfrostPerf()
41 {
42    if (perf) {
43       panfrost_perf_disable(perf);
44       ralloc_free(perf);
45    }
46 }
47 
PanfrostPerf(PanfrostPerf && o)48 PanfrostPerf::PanfrostPerf(PanfrostPerf &&o): perf{o.perf}
49 {
50    o.perf = nullptr;
51 }
52 
53 PanfrostPerf &
operator =(PanfrostPerf && o)54 PanfrostPerf::operator=(PanfrostPerf &&o)
55 {
56    std::swap(perf, o.perf);
57    return *this;
58 }
59 
60 int
enable() const61 PanfrostPerf::enable() const
62 {
63    assert(perf);
64    return panfrost_perf_enable(perf);
65 }
66 
67 void
disable() const68 PanfrostPerf::disable() const
69 {
70    assert(perf);
71    panfrost_perf_disable(perf);
72 }
73 
74 int
dump() const75 PanfrostPerf::dump() const
76 {
77    assert(perf);
78    return panfrost_perf_dump(perf);
79 }
80 
81 } // namespace pps
82