panfrost: Add a performance counter dump utility

This uses Antonio's src/panfrost/perf for all the heavylifting, just
like the Perfetto producer. Unlike the Perfetto producer, it has no
dependencies and is a lot less useful. But it's a good smoke test.

Signed-off-by: Alyssa Rosenzweig <alyssa@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11733>
This commit is contained in:
Alyssa Rosenzweig
2021-06-15 18:59:33 -04:00
committed by Marge Bot
parent 7748ab117f
commit c20dde5179
2 changed files with 73 additions and 0 deletions

View File

@@ -55,3 +55,24 @@ dep_panfrost_perf = declare_dependency(
link_with: libpanfrost_perf,
include_directories: [inc_panfrost, inc_src, inc_include]
)
panfrost_quick = executable(
'panquick',
'quick.c',
include_directories : [
inc_mapi,
inc_mesa,
inc_gallium,
inc_gallium_aux,
inc_include,
inc_src,
inc_panfrost,
inc_panfrost_hw,
],
dependencies : [
dep_libdrm,
libpanfrost_dep,
dep_panfrost_perf,
],
build_by_default : with_tools.contains('panfrost')
)

52
src/panfrost/perf/quick.c Normal file
View File

@@ -0,0 +1,52 @@
#include <stdio.h>
#include <lib/pan_device.h>
#include "pan_perf.h"
int main(void) {
int fd = drmOpenWithType("panfrost", NULL, DRM_NODE_RENDER);
if (fd < 0) {
fprintf(stderr, "No panfrost device\n");
exit(1);
}
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, &dev);
int ret = panfrost_perf_enable(perf);
if (ret < 0) {
fprintf(stderr, "failed to enable counters (%d)\n", ret);
fprintf(stderr, "try `# echo Y > /sys/module/panfrost/parameters/unstable_ioctls`\n");
exit(1);
}
sleep(1);
panfrost_perf_dump(perf);
for (unsigned i = 0; i < perf->cfg->n_categories; ++i) {
const struct panfrost_perf_category *cat = &perf->cfg->categories[i];
printf("%s\n", cat->name);
for (unsigned j = 0; j < cat->n_counters; ++j) {
const struct panfrost_perf_counter *ctr = &cat->counters[j];
uint32_t val = panfrost_perf_counter_read(ctr, perf);
printf("%s (%s): %u\n", ctr->name, ctr->symbol_name, val);
}
printf("\n");
}
if (panfrost_perf_disable(perf) < 0) {
fprintf(stderr, "failed to disable counters\n");
exit(1);
}
panfrost_close_device(&dev);
}