From c20dde51797b37950f8067f451221b1daf7cd413 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Tue, 15 Jun 2021 18:59:33 -0400 Subject: [PATCH] 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 Part-of: --- src/panfrost/perf/meson.build | 21 +++++++++++++++++ src/panfrost/perf/quick.c | 52 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 src/panfrost/perf/quick.c diff --git a/src/panfrost/perf/meson.build b/src/panfrost/perf/meson.build index 5f762c3..86b21ef 100644 --- a/src/panfrost/perf/meson.build +++ b/src/panfrost/perf/meson.build @@ -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') +) diff --git a/src/panfrost/perf/quick.c b/src/panfrost/perf/quick.c new file mode 100644 index 0000000..286c726 --- /dev/null +++ b/src/panfrost/perf/quick.c @@ -0,0 +1,52 @@ +#include +#include +#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); +} -- 2.7.4