Mesa (master): freedreno/gmemtool: add verbose mode

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue May 26 19:45:23 UTC 2020


Module: Mesa
Branch: master
Commit: 1679efe92755871d48f81d6b3f45158f36c6f711
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=1679efe92755871d48f81d6b3f45158f36c6f711

Author: Rob Clark <robdclark at chromium.org>
Date:   Sat May 23 12:03:14 2020 -0700

freedreno/gmemtool: add verbose mode

And real getopt arg parsing.. now that we have one.

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

---

 src/gallium/drivers/freedreno/freedreno_gmem.c |  4 +-
 src/gallium/drivers/freedreno/gmemtool.c       | 55 ++++++++++++++++++++++----
 2 files changed, 50 insertions(+), 9 deletions(-)

diff --git a/src/gallium/drivers/freedreno/freedreno_gmem.c b/src/gallium/drivers/freedreno/freedreno_gmem.c
index 4c694df1c63..a2bbd0acb29 100644
--- a/src/gallium/drivers/freedreno/freedreno_gmem.c
+++ b/src/gallium/drivers/freedreno/freedreno_gmem.c
@@ -69,7 +69,9 @@
  * resolve.
  */
 
-#define BIN_DEBUG 0
+#ifndef BIN_DEBUG
+#  define BIN_DEBUG 0
+#endif
 
 /*
  * GMEM Cache:
diff --git a/src/gallium/drivers/freedreno/gmemtool.c b/src/gallium/drivers/freedreno/gmemtool.c
index 37fca9cb81f..2185f58c351 100644
--- a/src/gallium/drivers/freedreno/gmemtool.c
+++ b/src/gallium/drivers/freedreno/gmemtool.c
@@ -21,6 +21,12 @@
  * 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



More information about the mesa-commit mailing list