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:

committed by
Marge Bot

parent
b554c09399
commit
446ec05fae
@@ -1,41 +1,30 @@
|
|||||||
#include "pan_pps_perf.h"
|
#include "pan_pps_perf.h"
|
||||||
|
|
||||||
#include <lib/pan_device.h>
|
#include <lib/kmod/pan_kmod.h>
|
||||||
#include <perf/pan_perf.h>
|
#include <perf/pan_perf.h>
|
||||||
|
|
||||||
#include <pps/pps.h>
|
#include <pps/pps.h>
|
||||||
#include <util/ralloc.h>
|
#include <util/ralloc.h>
|
||||||
|
|
||||||
namespace pps {
|
namespace pps {
|
||||||
PanfrostDevice::PanfrostDevice(int fd)
|
PanfrostDevice::PanfrostDevice(int fd): fd(fd)
|
||||||
: ctx{ralloc_context(nullptr)},
|
|
||||||
dev{reinterpret_cast<struct panfrost_device *>(
|
|
||||||
new struct panfrost_device())}
|
|
||||||
{
|
{
|
||||||
assert(fd >= 0);
|
assert(fd >= 0);
|
||||||
panfrost_open_device(ctx, fd, dev);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PanfrostDevice::~PanfrostDevice()
|
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.fd = -1;
|
||||||
o.dev = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PanfrostDevice &
|
PanfrostDevice &
|
||||||
PanfrostDevice::operator=(PanfrostDevice &&o)
|
PanfrostDevice::operator=(PanfrostDevice &&o)
|
||||||
{
|
{
|
||||||
std::swap(ctx, o.ctx);
|
std::swap(fd, o.fd);
|
||||||
std::swap(dev, o.dev);
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,8 +33,8 @@ PanfrostPerf::PanfrostPerf(const PanfrostDevice &dev)
|
|||||||
rzalloc(nullptr, struct panfrost_perf))}
|
rzalloc(nullptr, struct panfrost_perf))}
|
||||||
{
|
{
|
||||||
assert(perf);
|
assert(perf);
|
||||||
assert(dev.dev);
|
assert(dev.fd >= 0);
|
||||||
panfrost_perf_init(perf, dev.dev);
|
panfrost_perf_init(perf, dev.fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
PanfrostPerf::~PanfrostPerf()
|
PanfrostPerf::~PanfrostPerf()
|
||||||
|
@@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
struct panfrost_device;
|
|
||||||
struct panfrost_perf;
|
struct panfrost_perf;
|
||||||
|
|
||||||
namespace pps {
|
namespace pps {
|
||||||
@@ -22,8 +21,7 @@ class PanfrostDevice {
|
|||||||
PanfrostDevice(PanfrostDevice &&);
|
PanfrostDevice(PanfrostDevice &&);
|
||||||
PanfrostDevice &operator=(PanfrostDevice &&);
|
PanfrostDevice &operator=(PanfrostDevice &&);
|
||||||
|
|
||||||
void *ctx = nullptr;
|
int fd = -1;
|
||||||
struct panfrost_device *dev = nullptr;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class PanfrostPerf {
|
class PanfrostPerf {
|
||||||
|
@@ -21,10 +21,17 @@
|
|||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <xf86drm.h>
|
||||||
|
|
||||||
|
#include "util/macros.h"
|
||||||
|
#include "util/ralloc.h"
|
||||||
|
|
||||||
#include "pan_perf.h"
|
#include "pan_perf.h"
|
||||||
|
|
||||||
#include <drm-uapi/panfrost_drm.h>
|
#include <drm-uapi/panfrost_drm.h>
|
||||||
#include <lib/pan_device.h>
|
#include <lib/kmod/pan_kmod.h>
|
||||||
#include <lib/pan_props.h>
|
#include <lib/pan_props.h>
|
||||||
#include <pan_perf_metrics.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 belongs to shader core, accumulate values for all other cores
|
||||||
if (counter->category_index == PAN_SHADER_CORE_INDEX) {
|
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];
|
ret += perf->counter_values[offset + PAN_COUNTERS_PER_CATEGORY * core];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -63,22 +70,29 @@ panfrost_lookup_counters(const char *name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
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");
|
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)
|
if (perf->cfg == NULL)
|
||||||
unreachable("Performance counters missing!");
|
unreachable("Performance counters missing!");
|
||||||
|
|
||||||
// Generally counter blocks are laid out in the following order:
|
// Generally counter blocks are laid out in the following order:
|
||||||
// Job manager, tiler, one or more L2 caches, and one or more shader cores.
|
// Job manager, tiler, one or more L2 caches, and one or more shader cores.
|
||||||
unsigned l2_slices = panfrost_query_l2_slices(&dev->kmod.props);
|
unsigned l2_slices = panfrost_query_l2_slices(&props);
|
||||||
uint32_t n_blocks = 2 + l2_slices + dev->core_id_range;
|
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->n_counter_values = PAN_COUNTERS_PER_CATEGORY * n_blocks;
|
||||||
perf->counter_values = ralloc_array(perf, uint32_t, perf->n_counter_values);
|
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)
|
panfrost_perf_query(struct panfrost_perf *perf, uint32_t enable)
|
||||||
{
|
{
|
||||||
struct drm_panfrost_perfcnt_enable perfcnt_enable = {enable, 0};
|
struct drm_panfrost_perfcnt_enable perfcnt_enable = {enable, 0};
|
||||||
return drmIoctl(panfrost_device_fd(perf->dev),
|
return drmIoctl(perf->dev->fd, DRM_IOCTL_PANFROST_PERFCNT_ENABLE,
|
||||||
DRM_IOCTL_PANFROST_PERFCNT_ENABLE, &perfcnt_enable);
|
&perfcnt_enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@@ -116,6 +130,6 @@ panfrost_perf_dump(struct panfrost_perf *perf)
|
|||||||
// counter_values
|
// counter_values
|
||||||
struct drm_panfrost_perfcnt_dump perfcnt_dump = {
|
struct drm_panfrost_perfcnt_dump perfcnt_dump = {
|
||||||
(uint64_t)(uintptr_t)perf->counter_values};
|
(uint64_t)(uintptr_t)perf->counter_values};
|
||||||
return drmIoctl(panfrost_device_fd(perf->dev),
|
return drmIoctl(perf->dev->fd, DRM_IOCTL_PANFROST_PERFCNT_DUMP,
|
||||||
DRM_IOCTL_PANFROST_PERFCNT_DUMP, &perfcnt_dump);
|
&perfcnt_dump);
|
||||||
}
|
}
|
||||||
|
@@ -33,7 +33,9 @@ extern "C" {
|
|||||||
#define PAN_PERF_MAX_CATEGORIES 4
|
#define PAN_PERF_MAX_CATEGORIES 4
|
||||||
#define PAN_PERF_MAX_COUNTERS 64
|
#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_category;
|
||||||
struct panfrost_perf;
|
struct panfrost_perf;
|
||||||
|
|
||||||
@@ -83,8 +85,8 @@ struct panfrost_perf_config {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct panfrost_perf {
|
struct panfrost_perf {
|
||||||
struct panfrost_device *dev;
|
struct pan_kmod_dev *dev;
|
||||||
|
unsigned core_id_range;
|
||||||
const struct panfrost_perf_config *cfg;
|
const struct panfrost_perf_config *cfg;
|
||||||
|
|
||||||
// Memory where to dump counter values
|
// 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,
|
uint32_t panfrost_perf_counter_read(const struct panfrost_perf_counter *counter,
|
||||||
const struct panfrost_perf *perf);
|
const struct panfrost_perf *perf);
|
||||||
|
|
||||||
void panfrost_perf_init(struct panfrost_perf *perf,
|
void panfrost_perf_init(struct panfrost_perf *perf, int fd);
|
||||||
struct panfrost_device *dev);
|
|
||||||
|
|
||||||
int panfrost_perf_enable(struct panfrost_perf *perf);
|
int panfrost_perf_enable(struct panfrost_perf *perf);
|
||||||
|
|
||||||
|
@@ -1,5 +1,7 @@
|
|||||||
|
#include <xf86drm.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <lib/pan_device.h>
|
#include <lib/kmod/pan_kmod.h>
|
||||||
|
#include <lib/pan_props.h>
|
||||||
#include "pan_perf.h"
|
#include "pan_perf.h"
|
||||||
|
|
||||||
int
|
int
|
||||||
@@ -15,10 +17,8 @@ main(void)
|
|||||||
void *ctx = ralloc_context(NULL);
|
void *ctx = ralloc_context(NULL);
|
||||||
struct panfrost_perf *perf = rzalloc(ctx, struct panfrost_perf);
|
struct panfrost_perf *perf = rzalloc(ctx, struct panfrost_perf);
|
||||||
|
|
||||||
struct panfrost_device dev = {};
|
panfrost_perf_init(perf, fd);
|
||||||
panfrost_open_device(ctx, fd, &dev);
|
|
||||||
|
|
||||||
panfrost_perf_init(perf, &dev);
|
|
||||||
int ret = panfrost_perf_enable(perf);
|
int ret = panfrost_perf_enable(perf);
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
@@ -52,5 +52,5 @@ main(void)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
panfrost_close_device(&dev);
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user