freedreno/gmemtool: add verbose mode
authorRob Clark <robdclark@chromium.org>
Sat, 23 May 2020 19:03:14 +0000 (12:03 -0700)
committerMarge Bot <eric+marge@anholt.net>
Tue, 26 May 2020 19:29:34 +0000 (19:29 +0000)
And real getopt arg parsing.. now that we have one.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5189>

src/gallium/drivers/freedreno/freedreno_gmem.c
src/gallium/drivers/freedreno/gmemtool.c

index 4c694df1c63130aa56b9fe0e4534d1c1603c5e31..a2bbd0acb29142430a62ea1cdb3143060f4776e6 100644 (file)
@@ -69,7 +69,9 @@
  * resolve.
  */
 
-#define BIN_DEBUG 0
+#ifndef BIN_DEBUG
+#  define BIN_DEBUG 0
+#endif
 
 /*
  * GMEM Cache:
index 37fca9cb81fe562a6fb35753db4af2a4725e2d6b..2185f58c35155d087a2faf1cbbe2b297defca4cf 100644 (file)
  * SOFTWARE.
  */
 
+#include <getopt.h>
+#include <stdbool.h>
+
+static bool bin_debug = false;
+#define BIN_DEBUG bin_debug
+
 #include "freedreno_gmem.c"
 
 /* NOTE, non-interesting gmem keys (ie. things that are small enough to fit
@@ -95,15 +101,51 @@ static const struct gpu_info gpu_infos[] = {
        { "a630", 630, 32, 32, 32, 1, SZ_1M   },
 };
 
+
+static const struct option opts[] = {
+       { .name = "gpu",     .has_arg = 1, NULL, 'g' },
+       { .name = "help",    .has_arg = 0, NULL, 'h' },
+       { .name = "verbose", .has_arg = 0, NULL, 'v' },
+       {}
+};
+
+static void
+usage(void)
+{
+       fprintf(stderr, "Usage:\n\n"
+                       "\tgmemtool [-hv] [-g GPU]\n\n"
+                       "Options:\n"
+                       "\t-g, --gpu=GPU   - use GMEM size/alignment/etc settings for the specified GPU\n"
+                       "\t-h, --help      - this usage message\n"
+                       "\t-v, --verbose   - dump more verbose output\n"
+                       "\n"
+               );
+       fprintf(stderr, "Where GPU is one of:\n");
+       for (int i = 0; i < ARRAY_SIZE(gpu_infos); i++)
+               fprintf(stderr, "\t%s\n", gpu_infos[i].name);
+       exit(2);
+}
+
 int
 main(int argc, char **argv)
 {
-       if (argc < 2) {
-               printf("usage: gmemtest GPU_NAME\n");
-               return -1;
+       const char *gpu_name = "a630";
+       int c;
+
+       while ((c = getopt_long(argc, argv, "g:hv", opts, NULL)) != -1) {
+               switch (c) {
+               case 'g':
+                       gpu_name = optarg;
+                       break;
+               case 'v':
+                       bin_debug = true;
+                       break;
+               case 'h':
+               default:
+                       usage();
+               }
        }
 
-       const char *gpu_name = argv[1];
        const struct gpu_info *gpu_info = NULL;
 
        for (int i = 0; i < ARRAY_SIZE(gpu_infos); i++) {
@@ -115,10 +157,7 @@ main(int argc, char **argv)
 
        if (!gpu_info) {
                printf("unrecognized gpu name: %s\n", gpu_name);
-               printf("supported gpus:\n");
-               for (int i = 0; i < ARRAY_SIZE(gpu_infos); i++)
-                       printf("\t%s\n", gpu_infos[i].name);
-               return -1;
+               usage();
        }
 
        /* Setup a fake screen with enough GMEM related configuration