[Mesa-dev] [PATCH] panfrost: Expose perf counters in environment

Alyssa Rosenzweig alyssa at rosenzweig.io
Mon Feb 25 03:33:40 UTC 2019


Previously, we were guarded by an #ifdef, which is generally a bad form.
This patch instead guards them behind an environmental variable.

Signed-off-by: Alyssa Rosenzweig <alyssa at rosenzweig.io>
---
 src/gallium/drivers/panfrost/pan_context.c |  9 +++------
 src/gallium/drivers/panfrost/pan_screen.c  | 13 ++++++++-----
 src/gallium/drivers/panfrost/pan_screen.h  |  2 --
 3 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/src/gallium/drivers/panfrost/pan_context.c b/src/gallium/drivers/panfrost/pan_context.c
index 508f55200af..81c29dc929d 100644
--- a/src/gallium/drivers/panfrost/pan_context.c
+++ b/src/gallium/drivers/panfrost/pan_context.c
@@ -43,9 +43,8 @@
 #include "pan_blend_shaders.h"
 #include "pan_wallpaper.h"
 
-#ifdef DUMP_PERFORMANCE_COUNTERS
 static int performance_counter_number = 0;
-#endif
+extern const char *pan_counters_base;
 
 /* Do not actually send anything to the GPU; merely generate the cmdstream as fast as possible. Disables framebuffer writes */
 //#define DRY_RUN
@@ -1570,17 +1569,15 @@ panfrost_submit_frame(struct panfrost_context *ctx, bool flush_immediate)
         if (panfrost_is_scanout(ctx) && flush_immediate)
                 screen->driver->force_flush_fragment(ctx);
 
-#ifdef DUMP_PERFORMANCE_COUNTERS
-        if (screen->driver->dump_counters) {
+        if (screen->driver->dump_counters && pan_counters_base) {
                 screen->driver->dump_counters(screen);
 
                 char filename[128];
-                snprintf(filename, sizeof(filename), "/dev/shm/frame%d.mdgprf", ++performance_counter_number);
+                snprintf(filename, sizeof(filename), "%s/frame%d.mdgprf", pan_counters_base, ++performance_counter_number);
                 FILE *fp = fopen(filename, "wb");
                 fwrite(screen->perf_counters.cpu,  4096, sizeof(uint32_t), fp);
                 fclose(fp);
         }
-#endif
 
 #endif
 }
diff --git a/src/gallium/drivers/panfrost/pan_screen.c b/src/gallium/drivers/panfrost/pan_screen.c
index f61758d1bb9..b8a119fd343 100644
--- a/src/gallium/drivers/panfrost/pan_screen.c
+++ b/src/gallium/drivers/panfrost/pan_screen.c
@@ -53,6 +53,8 @@
 struct panfrost_driver *panfrost_create_drm_driver(int fd);
 struct panfrost_driver *panfrost_create_nondrm_driver(int fd);
 
+const char *pan_counters_base = NULL;
+
 static const char *
 panfrost_get_name(struct pipe_screen *screen)
 {
@@ -551,17 +553,18 @@ panfrost_create_screen(int fd, struct renderonly *ro, bool is_drm)
 #endif
         }
 
-        /* Enable pantrace iff asked for in the environment */
+        /* Dump memory and/or performance counters iff asked for in the environment */
         const char *pantrace_base = getenv("PANTRACE_BASE");
+        pan_counters_base = getenv("PANCOUNTERS_BASE");
 
         if (pantrace_base) {
                 pantrace_initialize(pantrace_base);
         }
 
-#ifdef DUMP_PERFORMANCE_COUNTERS
-        screen->driver->allocate_slab(screen, &screen->perf_counters, 64, true, 0, 0, 0);
-        screen->driver->enable_counters(screen);
-#endif
+        if (pan_counters_base) {
+                screen->driver->allocate_slab(screen, &screen->perf_counters, 64, true, 0, 0, 0);
+                screen->driver->enable_counters(screen);
+        }
 
         screen->base.destroy = panfrost_destroy_screen;
 
diff --git a/src/gallium/drivers/panfrost/pan_screen.h b/src/gallium/drivers/panfrost/pan_screen.h
index e976b78b5a2..0005b2feb15 100644
--- a/src/gallium/drivers/panfrost/pan_screen.h
+++ b/src/gallium/drivers/panfrost/pan_screen.h
@@ -41,8 +41,6 @@ struct panfrost_context;
 struct panfrost_resource;
 struct panfrost_screen;
 
-//#define DUMP_PERFORMANCE_COUNTERS
-
 /* Flags for allocated memory */
 #define PAN_ALLOCATE_EXECUTE (1 << 0)
 #define PAN_ALLOCATE_GROWABLE (1 << 1)
-- 
2.20.1



More information about the mesa-dev mailing list