diff --git a/src/panfrost/ds/pan_pps_perf.cpp b/src/panfrost/ds/pan_pps_perf.cpp index ddc8de9900e..5c7dab6f4e6 100644 --- a/src/panfrost/ds/pan_pps_perf.cpp +++ b/src/panfrost/ds/pan_pps_perf.cpp @@ -1,41 +1,30 @@ #include "pan_pps_perf.h" -#include +#include #include + #include #include namespace pps { -PanfrostDevice::PanfrostDevice(int fd) - : ctx{ralloc_context(nullptr)}, - dev{reinterpret_cast( - new struct panfrost_device())} +PanfrostDevice::PanfrostDevice(int fd): fd(fd) { assert(fd >= 0); - panfrost_open_device(ctx, fd, dev); } PanfrostDevice::~PanfrostDevice() { - if (ctx) { - panfrost_close_device(dev); - } - if (dev) { - delete dev; - } } -PanfrostDevice::PanfrostDevice(PanfrostDevice &&o): ctx{o.ctx}, dev{o.dev} +PanfrostDevice::PanfrostDevice(PanfrostDevice &&o): fd{o.fd} { - o.ctx = nullptr; - o.dev = nullptr; + o.fd = -1; } PanfrostDevice & PanfrostDevice::operator=(PanfrostDevice &&o) { - std::swap(ctx, o.ctx); - std::swap(dev, o.dev); + std::swap(fd, o.fd); return *this; } @@ -44,8 +33,8 @@ PanfrostPerf::PanfrostPerf(const PanfrostDevice &dev) rzalloc(nullptr, struct panfrost_perf))} { assert(perf); - assert(dev.dev); - panfrost_perf_init(perf, dev.dev); + assert(dev.fd >= 0); + panfrost_perf_init(perf, dev.fd); } PanfrostPerf::~PanfrostPerf() diff --git a/src/panfrost/ds/pan_pps_perf.h b/src/panfrost/ds/pan_pps_perf.h index c046e09b0df..d4f677750cc 100644 --- a/src/panfrost/ds/pan_pps_perf.h +++ b/src/panfrost/ds/pan_pps_perf.h @@ -7,7 +7,6 @@ #pragma once -struct panfrost_device; struct panfrost_perf; namespace pps { @@ -22,8 +21,7 @@ class PanfrostDevice { PanfrostDevice(PanfrostDevice &&); PanfrostDevice &operator=(PanfrostDevice &&); - void *ctx = nullptr; - struct panfrost_device *dev = nullptr; + int fd = -1; }; class PanfrostPerf { diff --git a/src/panfrost/perf/pan_perf.c b/src/panfrost/perf/pan_perf.c index 55885a638c4..129d84c5150 100644 --- a/src/panfrost/perf/pan_perf.c +++ b/src/panfrost/perf/pan_perf.c @@ -21,10 +21,17 @@ * THE SOFTWARE. */ +#include +#include +#include + +#include "util/macros.h" +#include "util/ralloc.h" + #include "pan_perf.h" #include -#include +#include #include #include @@ -43,7 +50,7 @@ panfrost_perf_counter_read(const struct panfrost_perf_counter *counter, // If counter belongs to shader core, accumulate values for all other cores if (counter->category_index == PAN_SHADER_CORE_INDEX) { - for (uint32_t core = 1; core < perf->dev->core_id_range; ++core) { + for (uint32_t core = 1; core < perf->core_id_range; ++core) { ret += perf->counter_values[offset + PAN_COUNTERS_PER_CATEGORY * core]; } } @@ -63,22 +70,29 @@ panfrost_lookup_counters(const char *name) } void -panfrost_perf_init(struct panfrost_perf *perf, struct panfrost_device *dev) +panfrost_perf_init(struct panfrost_perf *perf, int fd) { - perf->dev = dev; + perf->dev = pan_kmod_dev_create(fd, 0, NULL); + assert(perf->dev); - if (dev->model == NULL) + struct pan_kmod_dev_props props = {}; + pan_kmod_dev_query_props(perf->dev, &props); + + const struct panfrost_model *model = panfrost_get_model(props.gpu_prod_id); + if (model == NULL) unreachable("Invalid GPU ID"); - perf->cfg = panfrost_lookup_counters(dev->model->performance_counters); + perf->cfg = panfrost_lookup_counters(model->performance_counters); if (perf->cfg == NULL) unreachable("Performance counters missing!"); // Generally counter blocks are laid out in the following order: // Job manager, tiler, one or more L2 caches, and one or more shader cores. - unsigned l2_slices = panfrost_query_l2_slices(&dev->kmod.props); - uint32_t n_blocks = 2 + l2_slices + dev->core_id_range; + unsigned l2_slices = panfrost_query_l2_slices(&props); + panfrost_query_core_count(&props, &perf->core_id_range); + + uint32_t n_blocks = 2 + l2_slices + perf->core_id_range; perf->n_counter_values = PAN_COUNTERS_PER_CATEGORY * n_blocks; perf->counter_values = ralloc_array(perf, uint32_t, perf->n_counter_values); @@ -93,8 +107,8 @@ static int panfrost_perf_query(struct panfrost_perf *perf, uint32_t enable) { struct drm_panfrost_perfcnt_enable perfcnt_enable = {enable, 0}; - return drmIoctl(panfrost_device_fd(perf->dev), - DRM_IOCTL_PANFROST_PERFCNT_ENABLE, &perfcnt_enable); + return drmIoctl(perf->dev->fd, DRM_IOCTL_PANFROST_PERFCNT_ENABLE, + &perfcnt_enable); } int @@ -116,6 +130,6 @@ panfrost_perf_dump(struct panfrost_perf *perf) // counter_values struct drm_panfrost_perfcnt_dump perfcnt_dump = { (uint64_t)(uintptr_t)perf->counter_values}; - return drmIoctl(panfrost_device_fd(perf->dev), - DRM_IOCTL_PANFROST_PERFCNT_DUMP, &perfcnt_dump); + return drmIoctl(perf->dev->fd, DRM_IOCTL_PANFROST_PERFCNT_DUMP, + &perfcnt_dump); } diff --git a/src/panfrost/perf/pan_perf.h b/src/panfrost/perf/pan_perf.h index 4a40f2cc393..7d7bcf34276 100644 --- a/src/panfrost/perf/pan_perf.h +++ b/src/panfrost/perf/pan_perf.h @@ -33,7 +33,9 @@ extern "C" { #define PAN_PERF_MAX_CATEGORIES 4 #define PAN_PERF_MAX_COUNTERS 64 -struct panfrost_device; +struct pan_kmod_dev; +struct pan_kmod_dev_props; +struct panfrost_model; struct panfrost_perf_category; struct panfrost_perf; @@ -83,8 +85,8 @@ struct panfrost_perf_config { }; struct panfrost_perf { - struct panfrost_device *dev; - + struct pan_kmod_dev *dev; + unsigned core_id_range; const struct panfrost_perf_config *cfg; // Memory where to dump counter values @@ -98,8 +100,7 @@ struct panfrost_perf { uint32_t panfrost_perf_counter_read(const struct panfrost_perf_counter *counter, const struct panfrost_perf *perf); -void panfrost_perf_init(struct panfrost_perf *perf, - struct panfrost_device *dev); +void panfrost_perf_init(struct panfrost_perf *perf, int fd); int panfrost_perf_enable(struct panfrost_perf *perf); diff --git a/src/panfrost/perf/quick.c b/src/panfrost/perf/quick.c index 56513322306..2580d6f592e 100644 --- a/src/panfrost/perf/quick.c +++ b/src/panfrost/perf/quick.c @@ -1,5 +1,7 @@ +#include #include -#include +#include +#include #include "pan_perf.h" int @@ -15,10 +17,8 @@ main(void) void *ctx = ralloc_context(NULL); struct panfrost_perf *perf = rzalloc(ctx, struct panfrost_perf); - struct panfrost_device dev = {}; - panfrost_open_device(ctx, fd, &dev); + panfrost_perf_init(perf, fd); - panfrost_perf_init(perf, &dev); int ret = panfrost_perf_enable(perf); if (ret < 0) { @@ -52,5 +52,5 @@ main(void) exit(1); } - panfrost_close_device(&dev); + return 0; }