Mesa (main): freedreno/fdperf: support dumping counters

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sat May 14 22:52:05 UTC 2022


Module: Mesa
Branch: main
Commit: e9e8c649cd134586ccd272031645ab9b23da5f5e
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=e9e8c649cd134586ccd272031645ab9b23da5f5e

Author: Chia-I Wu <olvaffe at gmail.com>
Date:   Thu May 12 13:04:19 2022 -0700

freedreno/fdperf: support dumping counters

This is useful for comparing two workloads.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16488>

---

 src/freedreno/perfcntrs/fdperf.c | 56 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 54 insertions(+), 2 deletions(-)

diff --git a/src/freedreno/perfcntrs/fdperf.c b/src/freedreno/perfcntrs/fdperf.c
index 161f9c8de3b..407fdda24c8 100644
--- a/src/freedreno/perfcntrs/fdperf.c
+++ b/src/freedreno/perfcntrs/fdperf.c
@@ -49,8 +49,10 @@
 
 static struct {
    int refresh_ms;
+   bool dump;
 } options = {
    .refresh_ms = REFRESH_MS,
+   .dump = false,
 };
 
 /* NOTE first counter group should always be CP, since we unconditionally
@@ -113,6 +115,16 @@ gettime_us(void)
    return (ts.tv_sec * 1000000) + (ts.tv_nsec / 1000);
 }
 
+static void
+sleep_us(uint32_t us)
+{
+   const struct timespec ts = {
+      .tv_sec = us / 1000000,
+      .tv_nsec = (us % 1000000) * 1000,
+   };
+   clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, NULL);
+}
+
 static uint32_t
 delta(uint32_t a, uint32_t b)
 {
@@ -705,6 +717,39 @@ out:
    refresh();
 }
 
+static void
+dump_counters(void)
+{
+   resample();
+   sleep_us(options.refresh_ms * 1000);
+   resample();
+
+   for (unsigned i = 0; i < dev.ngroups; i++) {
+      const struct counter_group *group = &dev.groups[i];
+      for (unsigned j = 0; j < group->group->num_counters; j++) {
+         const char *label = group->label[j];
+         float val = group->current[j];
+
+         /* we did not config the first CP counter */
+         if (i == 0 && j == 0)
+            label = group->group->countables[0].name;
+
+         int n = printf("%s: ", label) - 2;
+         while (n++ < ctr_width)
+            fputc(' ', stdout);
+
+         if (strstr(label, "CYCLE") ||
+             strstr(label, "BUSY") ||
+             strstr(label, "IDLE")) {
+            val = val / dev.max_freq * 100.0f;
+            printf("%.2f%%\n", val);
+         } else {
+            printf("%'.2f\n", val);
+         }
+      }
+   }
+}
+
 static void
 restore_counter_groups(void)
 {
@@ -846,6 +891,7 @@ print_usage(const char *argv0)
            "Usage: %s [OPTION]...\n"
            "\n"
            "  -r <N>     refresh every N milliseconds\n"
+           "  -d         dump counters and exit\n"
            "  -h         show this message\n",
            argv0);
    exit(2);
@@ -856,11 +902,14 @@ parse_options(int argc, char **argv)
 {
    int c;
 
-   while ((c = getopt(argc, argv, "r:")) != -1) {
+   while ((c = getopt(argc, argv, "r:d")) != -1) {
       switch (c) {
       case 'r':
          options.refresh_ms = atoi(optarg);
          break;
+      case 'd':
+         options.dump = true;
+         break;
       default:
          print_usage(argv[0]);
          break;
@@ -897,7 +946,10 @@ main(int argc, char **argv)
    config_restore();
    flush_ring();
 
-   main_ui();
+   if (options.dump)
+      dump_counters();
+   else
+      main_ui();
 
    return 0;
 }



More information about the mesa-commit mailing list