1 #include "pan_pps_perf.h" 2 3 #include <lib/pan_device.h> 4 #include <perf/pan_perf.h> 5 #include <util/ralloc.h> 6 #include <pps/pps.h> 7 8 namespace pps 9 { PanfrostDevice(int fd)10PanfrostDevice::PanfrostDevice(int fd) 11 : ctx {ralloc_context(nullptr)} 12 , dev {reinterpret_cast<struct panfrost_device*>(new struct panfrost_device())} 13 { 14 assert(fd >= 0); 15 panfrost_open_device(ctx, fd, dev); 16 } 17 ~PanfrostDevice()18PanfrostDevice::~PanfrostDevice() 19 { 20 if (ctx) { 21 panfrost_close_device(dev); 22 } 23 if (dev) { 24 delete dev; 25 } 26 } 27 PanfrostDevice(PanfrostDevice && o)28PanfrostDevice::PanfrostDevice(PanfrostDevice &&o) 29 : ctx {o.ctx} 30 , dev {o.dev} 31 { 32 o.ctx = nullptr; 33 o.dev = nullptr; 34 } 35 operator =(PanfrostDevice && o)36PanfrostDevice &PanfrostDevice::operator=(PanfrostDevice &&o) 37 { 38 std::swap(ctx, o.ctx); 39 std::swap(dev, o.dev); 40 return *this; 41 } 42 PanfrostPerf(const PanfrostDevice & dev)43PanfrostPerf::PanfrostPerf(const PanfrostDevice& dev) 44 : perf {reinterpret_cast<struct panfrost_perf *>(rzalloc(nullptr, struct panfrost_perf))} 45 { 46 assert(perf); 47 assert(dev.dev); 48 panfrost_perf_init(perf, dev.dev); 49 } 50 ~PanfrostPerf()51PanfrostPerf::~PanfrostPerf() 52 { 53 if (perf) { 54 panfrost_perf_disable(perf); 55 ralloc_free(perf); 56 } 57 } 58 PanfrostPerf(PanfrostPerf && o)59PanfrostPerf::PanfrostPerf(PanfrostPerf &&o) 60 : perf {o.perf} 61 { 62 o.perf = nullptr; 63 } 64 operator =(PanfrostPerf && o)65PanfrostPerf &PanfrostPerf::operator=(PanfrostPerf &&o) 66 { 67 std::swap(perf, o.perf); 68 return *this; 69 } 70 enable() const71int PanfrostPerf::enable() const 72 { 73 assert(perf); 74 return panfrost_perf_enable(perf); 75 } 76 disable() const77void PanfrostPerf::disable() const 78 { 79 assert(perf); 80 panfrost_perf_disable(perf); 81 } 82 dump() const83int PanfrostPerf::dump() const 84 { 85 assert(perf); 86 return panfrost_perf_dump(perf); 87 } 88 89 } // namespace pps 90