Skip to contentSkip to conversation

intel_gpu_top: Wrap interactive header

PATCH In review Tvrtko Ursulin 3 participants 13 messages Feb 10, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 intel_gpu_top: Wrap interactive header

From: Tvrtko Ursulin <[email protected]>

Slight improvement with regards to wrapping header components to fit console width. If a single element is wider than max it can still overflow but it should now work better for practical console widths.

---
 tools/intel_gpu_top.c | 81 ++++++++++++++++++++++++++++++++++++-------
 1 file changed, 68 insertions(+), 13 deletions(-)
tools/intel_gpu_top.c +68 -13
index 21084185d896..63ef77056341 100644
@@ -1461,6 +1461,41 @@ static bool print_groups(struct cnt_group **groups)
 	return print_data;
 }
 
+static int __attribute__ ((format(__printf__, 6, 7)))
+print_header_token(const char *cont, int lines, int con_w, int con_h, int *rem,
+		   const char *fmt, ...)
+{
+	const char *indent = "\n   ";
+	char buf[256];
+	va_list args;
+	int ret;
+
+	if (lines >= con_h)
+		return lines;
+
+	va_start(args, fmt);
+	ret = vsnprintf(buf, sizeof(buf), fmt, args);
+	assert(ret < sizeof(buf));
+	va_end(args);
+
+	ret = (cont ? strlen(cont) : 0) + strlen(buf);
+	*rem -= ret;
+	if (*rem < 0) {
+		if (++lines >= con_h)
+			return lines;
+
+		*rem = con_w - ret - strlen(indent);
+		cont = indent;
+	}
+
+	if (cont)
+		ret = printf("%s%s", cont, buf);
+	else
+		ret = printf("%s", buf);
+
+	return lines;
+}
+
 static const char *header_msg;
 
 static int
@@ -1540,23 +1575,43 @@ print_header(const struct igt_device_card *card,
 	*consumed = print_groups(groups);
 
 	if (output_mode == INTERACTIVE) {
+		int rem = con_w;
+
 		printf("\033[H\033[J");
 
-		if (lines++ < con_h)
-			printf("intel-gpu-top: %s @ %s\n",
-			       codename, card->card);
-		if (lines++ < con_h) {
-			printf("%s/%s MHz; %s%% RC6; ",
-			       freq_items[1].buf, freq_items[0].buf,
-			       rc6_items[0].buf);
-			if (engines->r_gpu.present) {
-				printf("%s/%s W; ",
-				       power_items[0].buf,
-				       power_items[1].buf);
-			}
-			printf("%s irqs/s\n", irq_items[0].buf);
+		lines = print_header_token(NULL, lines, con_w, con_h, &rem,
+					   "intel-gpu-top:");
+
+		lines = print_header_token(" ", lines, con_w, con_h, &rem,
+					   "%s", codename);
+
+		lines = print_header_token(" @ ", lines, con_w, con_h, &rem,
+					   "%s", card->card);
+
+		lines = print_header_token(" - ", lines, con_w, con_h, &rem,
+					   "%s/%s MHz",
+					   freq_items[1].buf,
+					   freq_items[0].buf);
+
+		lines = print_header_token("; ", lines, con_w, con_h, &rem,
+					   "%s%% RC6",
+					   rc6_items[0].buf);
+
+		if (engines->r_gpu.present) {
+			lines = print_header_token("; ", lines, con_w, con_h,
+						   &rem,
+						   "%s/%s W",
+						   power_items[0].buf,
+						   power_items[1].buf);
 		}
 
+		lines = print_header_token("; ", lines, con_w, con_h, &rem,
+					   "%s irqs/s",
+					   irq_items[0].buf);
+
+		if (lines++ < con_h)
+			printf("\n");
+
 		if (lines++ < con_h) {
 			if (header_msg) {
 				printf(" >>> %s\n", header_msg);
Signature · 6 lines
2.27.0

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
#1 lore raw

PATCH 2/3 intel_gpu_top: Aggregate clients by PID by default

From: Tvrtko Ursulin <[email protected]>

Implement a default view where clients are aggregated by their PID.

Toggled by pressing 'H' similar to top(1).

---
 man/intel_gpu_top.rst |   1 +
 tools/intel_gpu_top.c | 109 +++++++++++++++++++++++++++++++++++++-----
 2 files changed, 97 insertions(+), 13 deletions(-)
man/intel_gpu_top.rst +1 -0
index b145d85c0440..20658e291db0 100644
@@ -58,6 +58,7 @@ Supported keys:
     'n'    Toggle display of numeric client busyness overlay.
     's'    Toggle between sort modes (runtime, total runtime, pid, client id).
     'i'    Toggle display of clients which used no GPU time.
+    'H'    Toggle between per PID aggregation and individual clients.
 
 DEVICE SELECTION
 ================
tools/intel_gpu_top.c +96 -13

190 lines not on this page · raw message

Signature · 6 lines
2.27.0

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw

PATCH 2/3 intel_gpu_top: Aggregate clients by PID by default

From: Tvrtko Ursulin <[email protected]>

Implement a default view where clients are aggregated by their PID.

Toggled by pressing 'H' similar to top(1).

v2:
* Fix memory leak.

---
 man/intel_gpu_top.rst |   1 +
 tools/intel_gpu_top.c | 121 +++++++++++++++++++++++++++++++++++++-----
 2 files changed, 109 insertions(+), 13 deletions(-)
man/intel_gpu_top.rst +1 -0
index b145d85c0440..20658e291db0 100644
@@ -58,6 +58,7 @@ Supported keys:
     'n'    Toggle display of numeric client busyness overlay.
     's'    Toggle between sort modes (runtime, total runtime, pid, client id).
     'i'    Toggle display of clients which used no GPU time.
+    'H'    Toggle between per PID aggregation and individual clients.
 
 DEVICE SELECTION
 ================
tools/intel_gpu_top.c +108 -13

202 lines not on this page · raw message

Signature · 6 lines
2.27.0

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#3 lore raw

Re: [igt-dev] [PATCH i-g-t 2/3] intel_gpu_top: Aggregate clients by PID by default

In reply to Tvrtko Ursulin

Quoting Tvrtko Ursulin (2021-02-10 09:37:55)

tools/intel_gpu_top.c static void sort_clients(struct clients *clients) · line 1026

Quoted 8 lines
tools/intel_gpu_top.c +8 -0
+static struct clients *aggregated_clients(struct clients *clients)
+{
+       struct client *ac, *c, *cp = NULL;
+       struct clients *aggregated;
+       int tmp, num = 0;
+
+       /* Sort by pid first to make it easy to aggregate while walking. */
+       sort_clients(clients, client_pid_cmp);

You could eliminate this tiny bit of duplication by always calling aggregated_clients() and returning here for !aggregate_pids.

Quoted 43 lines
tools/intel_gpu_top.c +43 -0
+       aggregated = calloc(1, sizeof(*clients));
+       assert(aggregated);
+
+       ac = calloc(clients->num_clients, sizeof(*c));
+       assert(ac);
+
+       aggregated->num_classes = clients->num_classes;
+       aggregated->class = clients->class;
+       aggregated->client = ac;
+
+       for_each_client(clients, c, tmp) {
+               unsigned int i;
+
+               if (c->status == FREE)
+                       break;
+
+               assert(c->status == ALIVE);
+
+               if ((cp && c->pid != cp->pid) || !cp) {
+                       ac = &aggregated->client[num];
+
+                       /* New pid. */
+                       ac->clients = aggregated;
+                       ac->status = ALIVE;
+                       ac->id = ++num;
+                       ac->pid = c->pid;
+                       strcpy(ac->name, c->name);
+                       strcpy(ac->print_name, c->print_name);
+                       ac->engines = c->engines;
+                       ac->val = calloc(clients->num_classes,
+                                        sizeof(ac->val[0]));
+                       assert(ac->val);
+                       ac->samples = 1;
+               }
+
+               cp = c;
+
+               if (c->samples < 2)
+                       continue;
+
+               ac->samples = 2; /* All what matters for display. */
+               ac->total_runtime += c->total_runtime;
+               ac->last_runtime += c->last_runtime;

tools/intel_gpu_top.c static void sort_clients(struct clients *clients) · line 1080

Quoted 10 lines
tools/intel_gpu_top.c +9 -0
+
+               for (i = 0; i < clients->num_classes; i++)
+                       ac->val[i] += c->val[i];
+       }
+
+       aggregated->num_clients = num;
+       aggregated->active_clients = num;
+
+       return sort_clients(aggregated, client_cmp);
 }

Ok, that works very well. Hmm. The sort order does seem a little jumpy though. May I suggest ac->id = -c->pid; instead of num; -Chris
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev

#4 lore raw

Re: [igt-dev] [PATCH i-g-t 2/3] intel_gpu_top: Aggregate clients by PID by default

Quoted 12 lines · Chris Wilson

Quoting Tvrtko Ursulin (2021-02-10 09:37:55)

tools/intel_gpu_top.c static void sort_clients(struct clients *clients) · line 1026

Quoted 8 lines
tools/intel_gpu_top.c +8 -0
+static struct clients *aggregated_clients(struct clients *clients)
+{
+       struct client *ac, *c, *cp = NULL;
+       struct clients *aggregated;
+       int tmp, num = 0;
+
+       /* Sort by pid first to make it easy to aggregate while walking. */
+       sort_clients(clients, client_pid_cmp);

You could eliminate this tiny bit of duplication by always calling aggregated_clients() and returning here for !aggregate_pids.

Okay, I did something like that.

Quoted 48 lines
Quoted 48 lines
tools/intel_gpu_top.c +48 -0
+       aggregated = calloc(1, sizeof(*clients));
+       assert(aggregated);
+
+       ac = calloc(clients->num_clients, sizeof(*c));
+       assert(ac);
+
+       aggregated->num_classes = clients->num_classes;
+       aggregated->class = clients->class;
+       aggregated->client = ac;
+
+       for_each_client(clients, c, tmp) {
+               unsigned int i;
+
+               if (c->status == FREE)
+                       break;
+
+               assert(c->status == ALIVE);
+
+               if ((cp && c->pid != cp->pid) || !cp) {
+                       ac = &aggregated->client[num];
+
+                       /* New pid. */
+                       ac->clients = aggregated;
+                       ac->status = ALIVE;
+                       ac->id = ++num;
+                       ac->pid = c->pid;
+                       strcpy(ac->name, c->name);
+                       strcpy(ac->print_name, c->print_name);
+                       ac->engines = c->engines;
+                       ac->val = calloc(clients->num_classes,
+                                        sizeof(ac->val[0]));
+                       assert(ac->val);
+                       ac->samples = 1;
+               }
+
+               cp = c;
+
+               if (c->samples < 2)
+                       continue;
+
+               ac->samples = 2; /* All what matters for display. */
+               ac->total_runtime += c->total_runtime;
+               ac->last_runtime += c->last_runtime;
+
+               for (i = 0; i < clients->num_classes; i++)
+                       ac->val[i] += c->val[i];
+       }
+
Quoted 8 lines

tools/intel_gpu_top.c static void sort_clients(struct clients *clients) · line 1080

Quoted 5 lines
tools/intel_gpu_top.c +4 -0
+       aggregated->num_clients = num;
+       aggregated->active_clients = num;
+
+       return sort_clients(aggregated, client_cmp);
  }

Ok, that works very well. Hmm. The sort order does seem a little jumpy though. May I suggest ac->id = -c->pid; instead of num;

Done it although I thought 1st pass being sort by pid already, num as id would follow a stable order. I guess your point was inversion to preserve order when cycling sort modes?

Regards,

Tvrtko
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev

#5 lore raw

Re: [Intel-gfx] [igt-dev] [PATCH i-g-t 2/3] intel_gpu_top: Aggregate clients by PID by default

Quoting Tvrtko Ursulin (2021-02-10 10:55:44)

Quoted 9 lines · Chris Wilson
Quoted 3 lines

Quoting Tvrtko Ursulin (2021-02-10 09:37:55)
Ok, that works very well. Hmm. The sort order does seem a little jumpy though. May I suggest ac->id = -c->pid; instead of num;

Done it although I thought 1st pass being sort by pid already, num as id would follow a stable order. I guess your point was inversion to preserve order when cycling sort modes?

I thought that makes more sense for 'aggregate-by-pid', that it should either be in ascending/descending pid order for idle.

It just felt very jumpy; it may have been tiny amount of %busy, but I suspected it may have been slightly unstable sorting with changing clients.
-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#6 lore raw

PATCH 2/3 intel_gpu_top: Aggregate clients by PID by default

In reply to Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

Implement a default view where clients are aggregated by their PID.

Toggled by pressing 'H' similar to top(1).

v2:
* Fix memory leak.

v3:
* Do not allow sort by client id in aggregated mode.
* Tweak sort criteria and sorting decisions. (Chris)

---
 man/intel_gpu_top.rst |   1 +
 tools/intel_gpu_top.c | 130 +++++++++++++++++++++++++++++++++++++-----
 2 files changed, 118 insertions(+), 13 deletions(-)
man/intel_gpu_top.rst +1 -0
index b145d85c0440..20658e291db0 100644
@@ -58,6 +58,7 @@ Supported keys:
     'n'    Toggle display of numeric client busyness overlay.
     's'    Toggle between sort modes (runtime, total runtime, pid, client id).
     'i'    Toggle display of clients which used no GPU time.
+    'H'    Toggle between per PID aggregation and individual clients.
 
 DEVICE SELECTION
 ================
tools/intel_gpu_top.c +117 -13

222 lines not on this page · raw message

Signature · 6 lines
2.27.0

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Reviewed-by on v1 2/3
#7 lore raw

Re: [igt-dev] [Intel-gfx] [PATCH i-g-t 2/3] intel_gpu_top: Aggregate clients by PID by default

Quoting Tvrtko Ursulin (2021-02-10 10:53:43)

tools/intel_gpu_top.c static void sort_clients(struct clients *clients) · line 1028

Quoted 8 lines
tools/intel_gpu_top.c +8 -0
+static struct clients *display_clients(struct clients *clients)
+{
+       struct client *ac, *c, *cp = NULL;
+       struct clients *aggregated;
+       int tmp, num = 0;
+
+       if (!aggregate_pids)
+               return sort_clients(clients, client_cmp);

Still two calls to return sort_clients(foo, client_cmp) in this function :) [a clients = aggregated; after processing would merge the two paths].

-Chris
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev

#8 lore raw

PATCH 2/3 intel_gpu_top: Aggregate clients by PID by default

In reply to Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

Implement a default view where clients are aggregated by their PID.

Toggled by pressing 'H' similar to top(1).

v2:
* Fix memory leak.

v3:
* Do not allow sort by client id in aggregated mode.
* Tweak sort criteria and sorting decisions. (Chris)

v4:
* More tweaks to code flow. (Chris)

---
 man/intel_gpu_top.rst |   1 +
 tools/intel_gpu_top.c | 133 +++++++++++++++++++++++++++++++++++++-----
 2 files changed, 121 insertions(+), 13 deletions(-)
man/intel_gpu_top.rst +1 -0
index b145d85c0440..20658e291db0 100644
@@ -58,6 +58,7 @@ Supported keys:
     'n'    Toggle display of numeric client busyness overlay.
     's'    Toggle between sort modes (runtime, total runtime, pid, client id).
     'i'    Toggle display of clients which used no GPU time.
+    'H'    Toggle between per PID aggregation and individual clients.
 
 DEVICE SELECTION
 ================
tools/intel_gpu_top.c +120 -13

225 lines not on this page · raw message

Signature · 6 lines
2.27.0

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
#9 lore raw

PATCH 3/3 intel_gpu_top: Interactive help screen

In reply to Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

Show a list of supported interactive commands when pressing 'h'.

---
 man/intel_gpu_top.rst |  1 +
 tools/intel_gpu_top.c | 68 ++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 61 insertions(+), 8 deletions(-)
man/intel_gpu_top.rst +1 -0
index 20658e291db0..f6d74852558b 100644
@@ -54,6 +54,7 @@ RUNTIME CONTROL
 Supported keys:
 
     'q'    Exit from the tool.
+    'h'    Show interactive help.
     '1'    Toggle between aggregated engine class and physical engine mode.
     'n'    Toggle display of numeric client busyness overlay.
     's'    Toggle between sort modes (runtime, total runtime, pid, client id).
tools/intel_gpu_top.c +60 -8

97 lines not on this page · raw message

Signature · 6 lines
2.27.0

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
Reviewed-by on v1 3/3
#10 lore raw

Re: [igt-dev] [PATCH i-g-t 3/3] intel_gpu_top: Interactive help screen

Quoting Tvrtko Ursulin (2021-02-10 09:37:56)

Quoted 5 lines

From: Tvrtko Ursulin <[email protected]>

Show a list of supported interactive commands when pressing 'h'.

-Chris
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev

Reviewed-by on v1 1/3
#11 lore raw
In reply to Tvrtko Ursulin

Quoting Tvrtko Ursulin (2021-02-10 09:37:54)

Quoted 5 lines

From: Tvrtko Ursulin <[email protected]>

Slight improvement with regards to wrapping header components to fit console width. If a single element is wider than max it can still overflow but it should now work better for practical console widths.

I'm not fond of this layout, but that's just a personal preference.

-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#12 lore raw

[igt-dev] ✗ Fi.CI.BUILD: failure for series starting with [i-g-t,1/3] intel_gpu_top: Wrap interactive header (rev4)

In reply to Tvrtko Ursulin
== Series Details ==

== Series Details ==

Series: series starting with [i-g-t,1/3] intel_gpu_top: Wrap interactive header (rev4)
URL : https://patchwork.freedesktop.org/series/86938/
State : failure

== Summary ==

Applying: intel_gpu_top: Wrap interactive header
Applying: intel_gpu_top: Aggregate clients by PID by default
Applying: intel_gpu_top: Interactive help screen
Patch failed at 0003 intel_gpu_top: Interactive help screen When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort".

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev