panfrost: Make pan_perf panfrost_device agnostic

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26698>
This commit is contained in:
Boris Brezillon
2023-12-12 15:27:26 +01:00
committed by Marge Bot
parent b554c09399
commit 446ec05fae
5 changed files with 46 additions and 44 deletions

View File

@@ -1,41 +1,30 @@
#include "pan_pps_perf.h"
#include <lib/pan_device.h>
#include <lib/kmod/pan_kmod.h>
#include <perf/pan_perf.h>
#include <pps/pps.h>
#include <util/ralloc.h>
namespace pps {
PanfrostDevice::PanfrostDevice(int fd)
: ctx{ralloc_context(nullptr)},
dev{reinterpret_cast<struct panfrost_device *>(
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()

View File

@@ -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 {

View File

@@ -21,10 +21,17 @@
* THE SOFTWARE.
*/
#include <assert.h>
#include <string.h>
#include <xf86drm.h>
#include "util/macros.h"
#include "util/ralloc.h"
#include "pan_perf.h"
#include <drm-uapi/panfrost_drm.h>
#include <lib/pan_device.h>
#include <lib/kmod/pan_kmod.h>
#include <lib/pan_props.h>
#include <pan_perf_metrics.h>
@@ -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);
}

View File

@@ -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);

View File

@@ -1,5 +1,7 @@
#include <xf86drm.h>
#include <stdio.h>
#include <lib/pan_device.h>
#include <lib/kmod/pan_kmod.h>
#include <lib/pan_props.h>
#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;
}