Skip to contentSkip to conversation

intel_gpu_top: Per-client engine busyness

RFC In review Tvrtko Ursulin 3 participants 5 messages May 10, 2019

lore
Share & tools
lore
#0 lore raw

cover intel_gpu_top: Per-client engine busyness

From: Tvrtko Ursulin <[email protected]>

Extension to intel_gpu_top which uses the corresponding sysfs interface proposal to implement per client and per class engine utilization view. Example output:

==========================================================================
intel-gpu-top - 935/ 935 MHz; 0% RC6; 14.73 Watts; 1097 irqs/s

IMC reads: 1401 MiB/s
IMC writes: 4 MiB/s

ENGINE BUSY MI_SEMA MI_WAIT
Render/3D/0 63.73% |███████████████████ | 3% 0%
Blitter/0 9.53% |██▊ | 6% 0%
Video/0 39.32% |███████████▊ | 16% 0%
Video/1 15.62% |████▋ | 0% 0%
VideoEnhance/0 0.00% | | 0% 0%

PID NAME RCS BCS VCS VECS

 4084        gem_wsim |█████▌     ||█          ||           ||           |
 4086        gem_wsim |█▌         ||           ||███        ||           |

==========================================================================

Tvrtko Ursulin (1):
intel-gpu-top: Support for client stats

 tools/intel_gpu_top.c | 590 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 584 insertions(+), 6 deletions(-)
Signature · 6 lines
2.19.1

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

RFC 1/1 intel-gpu-top: Support for client stats

From: Tvrtko Ursulin <[email protected]>

Adds support for per-client engine busyness stats i915 exports in sysfs and produces output like the below:

==========================================================================
intel-gpu-top - 935/ 935 MHz; 0% RC6; 14.73 Watts; 1097 irqs/s

IMC reads: 1401 MiB/s
IMC writes: 4 MiB/s

ENGINE BUSY MI_SEMA MI_WAIT
Render/3D/0 63.73% |███████████████████ | 3% 0%
Blitter/0 9.53% |██▊ | 6% 0%
Video/0 39.32% |███████████▊ | 16% 0%
Video/1 15.62% |████▋ | 0% 0%
VideoEnhance/0 0.00% | | 0% 0%

PID NAME RCS BCS VCS VECS

 4084        gem_wsim |█████▌     ||█          ||           ||           |
 4086        gem_wsim |█▌         ||           ||███        ||           |

==========================================================================

Apart from the existing physical engine utilization it now also shows utilization per client and per engine class.

---
 tools/intel_gpu_top.c | 590 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 584 insertions(+), 6 deletions(-)
tools/intel_gpu_top.c +584 -6
index cc8db7c539ed..88e1ad52d17c 100644
@@ -659,8 +659,403 @@ static void pmu_sample(struct engines *engines)
 	}
 }
 
+enum client_status {
+	FREE = 0, /* mbz */
+	ALIVE,
+	PROBE
+};
+
+struct clients;
+
+struct client {
+	struct clients *clients;
+
+	enum client_status status;
+	unsigned int id;
+	unsigned int pid;
+	char name[128];
+	unsigned int samples;
+	unsigned long total;
+	struct engines *engines;
+	unsigned long *val;
+	uint64_t *last;
+};
+
+struct engine_class {
+	unsigned int class;
+	const char *name;
+	unsigned int num_engines;
+};
+
+struct clients {
+	unsigned int num_classes;
+	struct engine_class *class;
+
+	unsigned int num_clients;
+	struct client *client;
+};
+
+#define for_each_client(clients, c, tmp) \
+	for ((tmp) = (clients)->num_clients, c = (clients)->client; \
+	     (tmp > 0); (tmp)--, (c)++)
+
+#define SYSFS_ENABLE "/sys/class/drm/card0/clients/enable_stats"
+
+bool __stats_enabled;
+
+static int __set_stats(bool val)
+{
+	int fd, ret;
+
+	fd = open(SYSFS_ENABLE, O_WRONLY);
+	if (fd < 0)
+		return -errno;
+
+	ret = write(fd, val ? "1" : "0", 2);
+	if (ret < 0)
+		return -errno;
+	else if (ret < 2)
+		return 1;
+
+	close(fd);
+
+	return 0;
+}
+
+static void __restore_stats(void)
+{
+	int ret;
+
+	if (__stats_enabled)
+		return;
+
+	ret = __set_stats(false);
+	if (ret)
+		fprintf(stderr, "Failed to disable per-client stats! (%d)\n",
+			ret);
+}
+
+static void __restore_stats_signal(int sig)
+{
+	exit(0);
+}
+
+static int enable_stats(void)
+{
+	int fd, ret;
+
+	fd = open(SYSFS_ENABLE, O_RDONLY);
+	if (fd < 0)
+		return -errno;
+
+	close(fd);
+
+	__stats_enabled = filename_to_u64(SYSFS_ENABLE, 10);
+	if (__stats_enabled)
+		return 0;
+
+	ret = __set_stats(true);
+	if (!ret) {
+		if (atexit(__restore_stats))
+			fprintf(stderr, "Failed to register exit handler!");
+
+		if (signal(SIGINT, __restore_stats_signal))
+			fprintf(stderr, "Failed to register signal handler!");
+	} else {
+		fprintf(stderr, "Failed to enable per-client stats! (%d)\n",
+			ret);
+	}
+
+	return ret;
+}
+
+static struct clients *init_clients(void)
+{
+	struct clients *clients = malloc(sizeof(*clients));
+
+	if (enable_stats()) {
+		free(clients);
+		return NULL;
+	}
+
+	return memset(clients, 0, sizeof(*clients));
+}
+
+#define SYSFS_CLIENTS "/sys/class/drm/card0/clients"
+
+static uint64_t read_client_busy(unsigned int id, unsigned int class)
+{
+	char buf[256];
+	ssize_t ret;
+
+	ret = snprintf(buf, sizeof(buf),
+		       SYSFS_CLIENTS "/%u/busy/%u",
+		       id, class);
+	assert(ret > 0 && ret < sizeof(buf));
+	if (ret <= 0 || ret == sizeof(buf))
+		return 0;
+
+	return filename_to_u64(buf, 10);
+}
+
+static struct client *
+find_client(struct clients *clients, enum client_status status, unsigned int id)
+{
+	struct client *c;
+	int tmp;
+
+	for_each_client(clients, c, tmp) {
+		if ((status == FREE && c->status == FREE) ||
+		    (status == c->status && c->id == id))
+			return c;
+	}
+
+	return NULL;
+}
+
+static void update_client(struct client *c, unsigned int pid, char *name)
+{
+	uint64_t val[c->clients->num_classes];
+	unsigned int i;
+
+	if (c->pid != pid)
+		c->pid = pid;
+
+	if (strncmp(c->name, name, sizeof(c->name)))
+		strncpy(c->name, name, sizeof(c->name));
+
+	for (i = 0; i < c->clients->num_classes; i++)
+		val[i] = read_client_busy(c->id, c->clients->class[i].class);
+
+	c->total = 0;
+
+	for (i = 0; i < c->clients->num_classes; i++) {
+		assert(val[i] >= c->last[i]);
+		c->val[i] = val[i] - c->last[i];
+		c->total += c->val[i];
+		c->last[i] = val[i];
+	}
+
+	c->samples++;
+	c->status = ALIVE;
+}
+
+static int class_cmp(const void *_a, const void *_b)
+{
+	const struct engine_class *a = _a;
+	const struct engine_class *b = _b;
+
+	return a->class - b->class;
+}
+
+static void scan_classes(struct clients *clients, unsigned int id)
+{
+	struct engine_class *classes;
+	unsigned int num, i;
+	struct dirent *dent;
+	char buf[256];
+	int ret;
+	DIR *d;
+
+	ret = snprintf(buf, sizeof(buf), SYSFS_CLIENTS "/%u/busy", id);
+	assert(ret > 0 && ret < sizeof(buf));
+	if (ret <= 0 || ret == sizeof(buf))
+		return;
+
+	d = opendir(buf);
+	if (!d)
+		return;
+
+restart:
+	rewinddir(d);
+
+	num = 0;
+	while ((dent = readdir(d)) != NULL) {
+		if (dent->d_type != DT_REG)
+			continue;
+
+		num++;
+	}
+
+	rewinddir(d);
+
+	classes = calloc(num, sizeof(*classes));
+	assert(classes);
+
+	i = 0;
+	while ((dent = readdir(d)) != NULL) {
+		if (i > num) {
+			// FIXME: free individual names
+			free(classes);
+			goto restart;
+		}
+
+		if (dent->d_type != DT_REG)
+			continue;
+
+		classes[i].class = atoi(dent->d_name);
+		classes[i].name = class_short_name(classes[i].class);
+		i++;
+	}
+
+	closedir(d);
+
+	qsort(classes, num, sizeof(*classes), class_cmp);
+
+	clients->num_classes = num;
+	clients->class = classes;
+}
+
+static void
+add_client(struct clients *clients, unsigned int id, unsigned int pid,
+	   char *name)
+{
+	struct client *c;
+
+	assert(!find_client(clients, ALIVE, id));
+
+	c = find_client(clients, FREE, 0);
+	if (!c) {
+		unsigned int idx = clients->num_clients;
+
+		clients->num_clients += (clients->num_clients + 2) / 2;
+		clients->client = realloc(clients->client,
+					  clients->num_clients * sizeof(*c));
+		assert(clients->client);
+
+		c = &clients->client[idx];
+		memset(c, 0, (clients->num_clients - idx) * sizeof(*c));
+	}
+
+	if (!clients->num_classes)
+		scan_classes(clients, id);
+
+	c->id = id;
+	c->clients = clients;
+	c->val = calloc(clients->num_classes, sizeof(c->val));
+	c->last = calloc(clients->num_classes, sizeof(c->last));
+	assert(c->val && c->last);
+
+	update_client(c, pid, name);
+}
+
+static void free_client(struct client *c)
+{
+	free(c->val);
+	free(c->last);
+	memset(c, 0, sizeof(*c));
+}
+
+static char *read_client_sysfs(unsigned int id, const char *field)
+{
+	char buf[256];
+	ssize_t ret;
+
+	ret = snprintf(buf, sizeof(buf), SYSFS_CLIENTS "/%u/%s", id, field);
+	assert(ret > 0 && ret < sizeof(buf));
+	if (ret <= 0 || ret == sizeof(buf))
+		return NULL;
+
+	ret = filename_to_buf(buf, buf, sizeof(buf));
+	assert(ret == 0);
+	if (ret)
+		return NULL;
+
+	return strdup(buf);
+}
+
+static void scan_clients(struct clients *clients)
+{
+	struct dirent *dent;
+	struct client *c;
+	char *pid, *name;
+	unsigned int id;
+	int tmp;
+	DIR *d;
+
+	if (!clients)
+		return;
+
+	for_each_client(clients, c, tmp) {
+		if (c->status == ALIVE)
+			c->status = PROBE;
+	}
+
+	d = opendir(SYSFS_CLIENTS);
+	if (!d)
+		return;
+
+	while ((dent = readdir(d)) != NULL) {
+		if (dent->d_type != DT_DIR)
+			continue;
+		if (!isdigit(dent->d_name[0]))
+			continue;
+
+		id = atoi(dent->d_name);
+
+		name = read_client_sysfs(id, "name");
+		assert(name);
+		if (!name)
+			continue;
+
+		pid = read_client_sysfs(id, "pid");
+		assert(pid);
+		if (!pid) {
+			free(name);
+			continue;
+		}
+
+		c = find_client(clients, PROBE, id);
+		if (c) {
+			update_client(c, atoi(pid), name);
+			continue;
+		}
+
+		add_client(clients, id, atoi(pid), name);
+
+		free(name);
+		free(pid);
+	}
+
+	closedir(d);
+
+	for_each_client(clients, c, tmp) {
+		if (c->status == PROBE)
+			free_client(c);
+	}
+}
+
+static int cmp(const void *_a, const void *_b)
+{
+	const struct client *a = _a;
+	const struct client *b = _b;
+	long tot_a = a->total;
+	long tot_b = b->total;
+
+	tot_a *= a->status == ALIVE && a->samples > 1;
+	tot_b *= b->status == ALIVE && b->samples > 1;
+
+	tot_b -= tot_a;
+
+	if (!tot_b)
+		return (int)b->id - a->id;
+
+	while (tot_b > INT_MAX || tot_b < INT_MIN)
+		tot_b /= 2;
+
+	return tot_b;
+}
+
 static const char *bars[] = { " ", "▏", "▎", "▍", "▌", "▋", "▊", "▉", "█" };
 
+static void n_spaces(const unsigned int n)
+{
+	unsigned int i;
+
+	for (i = 0; i < n; i++)
+		putchar(' ');
+}
+
 static void
 print_percentage_bar(double percent, int max_len)
 {
@@ -674,8 +1069,10 @@ print_percentage_bar(double percent, int max_len)
 	if (i)
 		printf("%s", bars[i]);
 
-	for (i = 0; i < (max_len - 2 - (bar_len + 7) / 8); i++)
-		putchar(' ');
+	bar_len = max_len - 2 - (bar_len + 7) / 8;
+	if (bar_len > max_len)
+		bar_len = max_len;
+	n_spaces(bar_len);
 
 	putchar('|');
 }
@@ -775,6 +1172,18 @@ json_close_struct(void)
 		fflush(stdout);
 }
 
+static void
+__json_add_member(const char *key, const char *val)
+{
+	assert(json_indent_level < ARRAY_SIZE(json_indent));
+
+	fprintf(out, "%s%s\"%s\": \"%s\"",
+		json_struct_members ? ",\n" : "",
+		json_indent[json_indent_level], key, val);
+
+	json_struct_members++;
+}
+
 static unsigned int
 json_add_member(const struct cnt_group *parent, struct cnt_item *item,
 		unsigned int headers)
@@ -1075,8 +1484,6 @@ print_header(struct engines *engines, double t,
 		memmove(&groups[0], &groups[1],
 			sizeof(groups) - sizeof(groups[0]));
 
-	pops->open_struct(NULL);
-
 	*consumed = print_groups(groups);
 
 	if (output_mode == INTERACTIVE) {
@@ -1232,7 +1639,6 @@ print_engines_footer(struct engines *engines, double t,
 		     int lines, int con_w, int con_h)
 {
 	pops->close_struct();
-	pops->close_struct();
 
 	if (output_mode == INTERACTIVE) {
 		if (lines++ < con_h)
@@ -1242,6 +1648,136 @@ print_engines_footer(struct engines *engines, double t,
 	return lines;
 }
 
+static int
+print_clients_header(struct clients *clients, int lines,
+		     int con_w, int con_h, unsigned int *class_w)
+{
+	int len;
+
+	if (output_mode == INTERACTIVE) {
+		if (lines++ >= con_h)
+			return lines;
+
+		printf("\033[7m");
+		len = printf("%5s%16s", "PID", "NAME");
+
+		if (lines++ >= con_h)
+			return lines;
+
+		if (clients->num_classes) {
+			unsigned int i;
+
+			*class_w = (con_w - len) / clients->num_classes;
+
+			for (i = 0; i < clients->num_classes; i++) {
+				unsigned int name_len =
+					strlen(clients->class[i].name);
+				unsigned int pad = (*class_w - name_len) / 2;
+
+				n_spaces(pad);
+				printf("%s", clients->class[i].name);
+				n_spaces(*class_w - pad - name_len);
+				len += pad + name_len +
+				       (*class_w - pad - name_len);
+			}
+		}
+
+		n_spaces(con_w - len);
+		printf("\033[0m\n");
+	} else {
+		if (clients->num_classes)
+			pops->open_struct("clients");
+	}
+
+	return lines;
+}
+
+static void count_engines(struct clients *clients, struct engines *engines)
+{
+	unsigned int i;
+
+	for (i = 0; i < engines->num_engines; i++) {
+		struct engine *engine = engine_ptr(engines, i);
+
+		clients->class[engine->class].num_engines++;
+	}
+}
+
+static int
+print_client(struct client *c, struct engines *engines, double t, int lines,
+	     int con_w, int con_h, unsigned int period_us,
+	     unsigned int *class_w)
+{
+	struct clients *clients = c->clients;
+	unsigned int i;
+
+	if (output_mode == INTERACTIVE) {
+		printf("%5u%16s ", c->pid, c->name);
+
+		for (i = 0; i < clients->num_classes; i++) {
+			double pct;
+
+			if (!clients->class[i].num_engines)
+				count_engines(clients, engines);
+
+			pct = (double)c->val[i] / period_us / 1e3 * 100 /
+			      clients->class[i].num_engines;
+
+			print_percentage_bar(pct, *class_w);
+		}
+
+		putchar('\n');
+	} else if (output_mode == JSON) {
+		char buf[64];
+
+		snprintf(buf, sizeof(buf), "%u", c->id);
+		pops->open_struct(buf);
+
+		__json_add_member("name", c->name);
+
+		snprintf(buf, sizeof(buf), "%u", c->pid);
+		__json_add_member("pid", buf);
+
+		pops->open_struct("engine-classes");
+
+		for (i = 0; i < clients->num_classes; i++) {
+			double pct;
+
+			snprintf(buf, sizeof(buf), "%s",
+				 clients->class[i].name);
+			pops->open_struct(buf);
+
+			pct = (double)c->val[i] / period_us / 1e3 * 100;
+			snprintf(buf, sizeof(buf), "%f", pct);
+			__json_add_member("busy", buf);
+
+			__json_add_member("unit", "%");
+
+			pops->close_struct();
+		}
+
+		pops->close_struct();
+		pops->close_struct();
+	}
+
+	return lines;
+}
+
+static int
+print_clients_footer(struct clients *clients, double t,
+		     int lines, int con_w, int con_h)
+{
+	if (output_mode == INTERACTIVE) {
+		if (lines++ < con_h)
+			printf("\n");
+	} else {
+		if (clients->num_classes)
+			pops->close_struct();
+	}
+
+	return lines;
+}
+
 static bool stop_top;
 
 static void sigint_handler(int  sig)
@@ -1252,6 +1788,7 @@ static void sigint_handler(int  sig)
 int main(int argc, char **argv)
 {
 	unsigned int period_us = DEFAULT_PERIOD_MS * 1000;
+	struct clients *clients = NULL;
 	int con_w = -1, con_h = -1;
 	char *output_path = NULL;
 	struct engines *engines;
@@ -1335,12 +1872,17 @@ int main(int argc, char **argv)
 		return 1;
 	}
 
+	clients = init_clients();
+
 	pmu_sample(engines);
+	scan_clients(clients);
 
 	while (!stop_top) {
 		bool consumed = false;
-		int lines = 0;
+		int j, lines = 0;
+		unsigned int class_w;
 		struct winsize ws;
+		struct client *c;
 		double t;
 
 		/* Update terminal size. */
@@ -1354,10 +1896,18 @@ int main(int argc, char **argv)
 		pmu_sample(engines);
 		t = (double)(engines->ts.cur - engines->ts.prev) / 1e9;
 
+		scan_clients(clients);
+		if (clients) {
+			qsort(&clients->client, clients->num_clients,
+			      sizeof(clients->client), cmp);
+		}
+
 		if (stop_top)
 			break;
 
 		while (!consumed) {
+			pops->open_struct(NULL);
+
 			lines = print_header(engines, t, lines, con_w, con_h,
 					     &consumed);
 
@@ -1376,6 +1926,34 @@ int main(int argc, char **argv)
 
 			lines = print_engines_footer(engines, t, lines, con_w,
 						     con_h);
+
+			if (clients) {
+				lines = print_clients_header(clients, lines,
+							     con_w, con_h,
+							     &class_w);
+
+				for_each_client(clients, c, j) {
+					if (lines++ > con_h)
+						break;
+
+					assert(c->status != PROBE);
+					if (c->status != ALIVE)
+						break;
+
+					if (c->samples < 2)
+						continue;
+
+					lines = print_client(c, engines, t,
+							     lines, con_w,
+							     con_h, period_us,
+							     &class_w);
+				}
+
+				lines = print_clients_footer(clients, t, lines,
+							     con_w, con_h);
+			}
+
+			pops->close_struct();
 		}
 
 		if (stop_top)
Signature · 6 lines
2.19.1

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

Re: [igt-dev] [RFC i-g-t 1/1] intel-gpu-top: Support for client stats

Quoting Tvrtko Ursulin (2019-05-10 14:23:12)

Quoted 82 lines

From: Tvrtko Ursulin <[email protected]>

Adds support for per-client engine busyness stats i915 exports in sysfs and produces output like the below:

==========================================================================
intel-gpu-top - 935/ 935 MHz; 0% RC6; 14.73 Watts; 1097 irqs/s

IMC reads: 1401 MiB/s
IMC writes: 4 MiB/s

ENGINE BUSY MI_SEMA MI_WAIT
Render/3D/0 63.73% |███████████████████ | 3% 0%
Blitter/0 9.53% |██▊ | 6% 0%
Video/0 39.32% |███████████▊ | 16% 0%
Video/1 15.62% |████▋ | 0% 0%
VideoEnhance/0 0.00% | | 0% 0%

PID NAME RCS BCS VCS VECS

 4084        gem_wsim |█████▌     ||█          ||           ||           |
 4086        gem_wsim |█▌         ||           ||███        ||           |

==========================================================================

Apart from the existing physical engine utilization it now also shows utilization per client and per engine class.

---
 tools/intel_gpu_top.c | 590 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 584 insertions(+), 6 deletions(-)
tools/intel_gpu_top.c +43 -0
index cc8db7c539ed..88e1ad52d17c 100644
@@ -659,8 +659,403 @@ static void pmu_sample(struct engines *engines)
        }
 }
 
+enum client_status {
+       FREE = 0, /* mbz */
+       ALIVE,
+       PROBE
+};
+
+struct clients;
+
+struct client {
+       struct clients *clients;
+
+       enum client_status status;
+       unsigned int id;
+       unsigned int pid;
+       char name[128];
+       unsigned int samples;
+       unsigned long total;
+       struct engines *engines;
+       unsigned long *val;
+       uint64_t *last;
+};
+
+struct engine_class {
+       unsigned int class;
+       const char *name;
+       unsigned int num_engines;
+};
+
+struct clients {
+       unsigned int num_classes;
+       struct engine_class *class;
+
+       unsigned int num_clients;
+       struct client *client;
+};
+
+#define for_each_client(clients, c, tmp) \
+       for ((tmp) = (clients)->num_clients, c = (clients)->client; \
+            (tmp > 0); (tmp)--, (c)++)
+
+#define SYSFS_ENABLE "/sys/class/drm/card0/clients/enable_stats"
+
+bool __stats_enabled;

tools/intel_gpu_top.c static void pmu_sample(struct engines *engines) · line 714

Quoted 10 lines
tools/intel_gpu_top.c +10 -0
+
+static int __set_stats(bool val)
+{
+       int fd, ret;
+
+       fd = open(SYSFS_ENABLE, O_WRONLY);
+       if (fd < 0)
+               return -errno;
+
+       ret = write(fd, val ? "1" : "0", 2);

close(fd);

Might as well still be tidy on error when it's trivial to do so.

Quoted 39 lines
tools/intel_gpu_top.c +39 -0
+       if (ret < 0)
+               return -errno;
+       else if (ret < 2)
+               return 1;
+
+       close(fd);
+
+       return 0;
+}
+
+static void __restore_stats(void)
+{
+       int ret;
+
+       if (__stats_enabled)
+               return;
+
+       ret = __set_stats(false);
+       if (ret)
+               fprintf(stderr, "Failed to disable per-client stats! (%d)\n",
+                       ret);
+}
+
+static void __restore_stats_signal(int sig)
+{
+       exit(0);
+}
+
+static int enable_stats(void)
+{
+       int fd, ret;
+
+       fd = open(SYSFS_ENABLE, O_RDONLY);
+       if (fd < 0)
+               return -errno;
+
+       close(fd);
+
+       __stats_enabled = filename_to_u64(SYSFS_ENABLE, 10);

tools/intel_gpu_top.c static void pmu_sample(struct engines *engines) · line 763

Quoted 10 lines
tools/intel_gpu_top.c +10 -0
+       if (__stats_enabled)
+               return 0;
+
+       ret = __set_stats(true);
+       if (!ret) {
+               if (atexit(__restore_stats))
+                       fprintf(stderr, "Failed to register exit handler!");
+
+               if (signal(SIGINT, __restore_stats_signal))
+                       fprintf(stderr, "Failed to register signal handler!");

That really suggests an alternative mechanism where the stats are only active for as long as the open(sysfs/stats) is. However, iirc, sysfs doesn't allow us to hook into the open!

In which case we could hook into the write, and keep it enabled for as long as the user write("1") until the fd is closed. Food for thought, I hope you convince me we don't need optional stats in the first place :)

tools/intel_gpu_top.c static void pmu_sample(struct engines *engines) · line 774

Quoted 11 lines
tools/intel_gpu_top.c +11 -0
+       } else {
+               fprintf(stderr, "Failed to enable per-client stats! (%d)\n",
+                       ret);
+       }
+
+       return ret;
+}
+
+static struct clients *init_clients(void)
+{
+       struct clients *clients = malloc(sizeof(*clients));

We purport this to be a user-facing tool, it should generally avoid nasty errors.

tools/intel_gpu_top.c static void pmu_sample(struct engines *engines) · line 784

Quoted 10 lines
tools/intel_gpu_top.c +10 -0
+
+       if (enable_stats()) {
+               free(clients);
+               return NULL;
+       }
+
+       return memset(clients, 0, sizeof(*clients));
+}
+
+#define SYSFS_CLIENTS "/sys/class/drm/card0/clients"

We need to detect which cardN. Which turns into scan all possible dirents.

Quoted 15 lines
tools/intel_gpu_top.c +15 -0
+static uint64_t read_client_busy(unsigned int id, unsigned int class)
+{
+       char buf[256];
+       ssize_t ret;
+
+       ret = snprintf(buf, sizeof(buf),
+                      SYSFS_CLIENTS "/%u/busy/%u",
+                      id, class);
+       assert(ret > 0 && ret < sizeof(buf));
+       if (ret <= 0 || ret == sizeof(buf))
+               return 0;
+
+       return filename_to_u64(buf, 10);
+}
+

tools/intel_gpu_top.c static void pmu_sample(struct engines *engines) · line 810

Quoted 10 lines
tools/intel_gpu_top.c +10 -0
+static struct client *
+find_client(struct clients *clients, enum client_status status, unsigned int id)
+{
+       struct client *c;
+       int tmp;
+
+       for_each_client(clients, c, tmp) {
+               if ((status == FREE && c->status == FREE) ||
+                   (status == c->status && c->id == id))
+                       return c;

if (status != c->status)

	continue;

if (status == FREE || c->id == id)

	return c;
Quoted 16 lines
tools/intel_gpu_top.c +16 -0
+       }
+
+       return NULL;
+}
+
+static void update_client(struct client *c, unsigned int pid, char *name)
+{
+       uint64_t val[c->clients->num_classes];
+       unsigned int i;
+
+       if (c->pid != pid)
+               c->pid = pid;
+
+       if (strncmp(c->name, name, sizeof(c->name)))
+               strncpy(c->name, name, sizeof(c->name));
+

tools/intel_gpu_top.c static void pmu_sample(struct engines *engines) · line 836

Quoted 10 lines
tools/intel_gpu_top.c +10 -0
+       for (i = 0; i < c->clients->num_classes; i++)
+               val[i] = read_client_busy(c->id, c->clients->class[i].class);
+
+       c->total = 0;
+
+       for (i = 0; i < c->clients->num_classes; i++) {
+               assert(val[i] >= c->last[i]);
+               c->val[i] = val[i] - c->last[i];
+               c->total += c->val[i];
+               c->last[i] = val[i];

Where's the normalisation for capacity? Ok, later on, but only for interactive conversion to %%. What about json output, how do they know capacity? Wait.. json is using %% as well without scaling for num_engines.

Should we not say timestamp the sampling and compute the % here? -Chris
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev

#3 lore raw

[igt-dev] ✓ Fi.CI.BAT: success for intel_gpu_top: Per-client engine busyness

In reply to Tvrtko Ursulin
== Series Details ==

== Series Details ==

Series: intel_gpu_top: Per-client engine busyness
URL : https://patchwork.freedesktop.org/series/60507/
State : success

== Summary ==

CI Bug Log - changes from IGT_4980 -> IGTPW_2963
====================================================

Summary
-------

**SUCCESS**

No regressions found.

External URL: https://patchwork.freedesktop.org/api/1.0/series/60507/revisions/1/mbox/

Changes
-------

No changes found

Participating hosts (53 -> 43)
------------------------------

Missing (10): fi-kbl-soraka fi-ilk-m540 fi-hsw-4200u fi-byt-j1900 fi-hsw-peppy fi-byt-squawks fi-bsw-cyan fi-ctg-p8600 fi-byt-clapper fi-bdw-samus

Build changes
-------------

* IGT: IGT_4980 -> IGTPW_2963

CI_DRM_6073: c059ddabfe60a5072ace44a34a9de9b4202df6ec @ git://anongit.freedesktop.org/gfx-ci/linux
IGTPW_2963: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2963/
IGT_4980: 159c69e5318e934b5f1d83939191c8756280b758 @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2963/
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev

#4 lore raw

[igt-dev] ✓ Fi.CI.IGT: success for intel_gpu_top: Per-client engine busyness

In reply to Tvrtko Ursulin
== Series Details ==

== Series Details ==

Series: intel_gpu_top: Per-client engine busyness
URL : https://patchwork.freedesktop.org/series/60507/
State : success

== Summary ==

CI Bug Log - changes from IGT_4980_full -> IGTPW_2963_full
====================================================

Summary
-------

**SUCCESS**

No regressions found.

External URL: https://patchwork.freedesktop.org/api/1.0/series/60507/revisions/1/mbox/

Known issues
------------

Here are the changes found in IGTPW_2963_full that come from known issues:

### IGT changes ###

#### Issues hit ####

* igt@gem_ctx_isolation@bcs0-s3:
- shard-kbl: [PASS][1] -> [INCOMPLETE][2] ([fdo#103665])
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4980/shard-kbl2/igt@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2963/shard-kbl3/igt@[email protected]

* igt@gem_eio@in-flight-suspend:
- shard-apl: [PASS][3] -> [DMESG-WARN][4] ([fdo#108566]) +10 similar issues
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4980/shard-apl4/igt@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2963/shard-apl5/igt@[email protected]

* igt@kms_cursor_legacy@cursor-vs-flip-toggle:
- shard-hsw: [PASS][5] -> [FAIL][6] ([fdo#103355])
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4980/shard-hsw8/igt@[email protected]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2963/shard-hsw6/igt@[email protected]

* igt@kms_frontbuffer_tracking@fbc-1p-primscrn-cur-indfb-draw-blt:
- shard-iclb: [PASS][7] -> [FAIL][8] ([fdo#103167]) +6 similar issues
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4980/shard-iclb4/igt@[email protected]
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2963/shard-iclb2/igt@[email protected]

* igt@kms_plane_lowres@pipe-a-tiling-x:
- shard-iclb: [PASS][9] -> [FAIL][10] ([fdo#103166])
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4980/shard-iclb6/igt@[email protected]
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2963/shard-iclb5/igt@[email protected]

* igt@kms_psr@psr2_sprite_plane_move:
- shard-iclb: [PASS][11] -> [SKIP][12] ([fdo#109441])
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4980/shard-iclb2/igt@kms_psr@psr2_sprite_plane_move.html
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2963/shard-iclb5/igt@kms_psr@psr2_sprite_plane_move.html

#### Possible fixes ####

* igt@drm_import_export@import-close-race-prime:
- shard-hsw: [INCOMPLETE][13] ([fdo#103540]) -> [PASS][14]
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4980/shard-hsw6/igt@[email protected]
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2963/shard-hsw2/igt@[email protected]

* igt@gem_tiled_swapping@non-threaded:
- shard-iclb: [FAIL][15] ([fdo#108686]) -> [PASS][16]
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4980/shard-iclb2/igt@[email protected]
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2963/shard-iclb7/igt@[email protected]

* igt@i915_pm_rc6_residency@rc6-accuracy:
- shard-snb: [SKIP][17] ([fdo#109271]) -> [PASS][18]
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4980/shard-snb5/igt@[email protected]
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2963/shard-snb6/igt@[email protected]

* igt@i915_suspend@fence-restore-untiled:
- shard-apl: [DMESG-WARN][19] ([fdo#108566]) -> [PASS][20] +2 similar issues
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4980/shard-apl6/igt@[email protected]
[20]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2963/shard-apl3/igt@[email protected]

* igt@kms_cursor_legacy@cursora-vs-flipb-legacy:
- shard-hsw: [SKIP][21] ([fdo#109271]) -> [PASS][22]
[21]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4980/shard-hsw1/igt@[email protected]
[22]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2963/shard-hsw7/igt@[email protected]

* igt@kms_frontbuffer_tracking@fbc-1p-primscrn-cur-indfb-draw-mmap-cpu:
- shard-kbl: [FAIL][23] ([fdo#103167]) -> [PASS][24]
[23]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4980/shard-kbl6/igt@kms_frontbuffer_tracking@fbc-1p-primscrn-cur-indfb-draw-mmap-cpu.html
[24]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2963/shard-kbl1/igt@kms_frontbuffer_tracking@fbc-1p-primscrn-cur-indfb-draw-mmap-cpu.html
- shard-apl: [FAIL][25] ([fdo#103167]) -> [PASS][26]
[25]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4980/shard-apl3/igt@kms_frontbuffer_tracking@fbc-1p-primscrn-cur-indfb-draw-mmap-cpu.html
[26]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2963/shard-apl6/igt@kms_frontbuffer_tracking@fbc-1p-primscrn-cur-indfb-draw-mmap-cpu.html

* igt@kms_frontbuffer_tracking@fbcpsr-1p-primscrn-cur-indfb-draw-render:
- shard-iclb: [FAIL][27] ([fdo#103167]) -> [PASS][28] +4 similar issues
[27]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4980/shard-iclb6/igt@kms_frontbuffer_tracking@fbcpsr-1p-primscrn-cur-indfb-draw-render.html
[28]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2963/shard-iclb6/igt@kms_frontbuffer_tracking@fbcpsr-1p-primscrn-cur-indfb-draw-render.html

* igt@kms_plane@plane-position-covered-pipe-c-planes:
- shard-apl: [FAIL][29] ([fdo#110038]) -> [PASS][30]
[29]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4980/shard-apl8/igt@[email protected]
[30]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2963/shard-apl3/igt@[email protected]
- shard-kbl: [FAIL][31] ([fdo#110038]) -> [PASS][32]
[31]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4980/shard-kbl2/igt@[email protected]
[32]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2963/shard-kbl2/igt@[email protected]

* igt@kms_psr@psr2_sprite_render:
- shard-iclb: [SKIP][33] ([fdo#109441]) -> [PASS][34] +2 similar issues
[33]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4980/shard-iclb1/igt@kms_psr@psr2_sprite_render.html
[34]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2963/shard-iclb2/igt@kms_psr@psr2_sprite_render.html

* igt@kms_vblank@pipe-a-ts-continuation-suspend:
- shard-kbl: [INCOMPLETE][35] ([fdo#103665]) -> [PASS][36]
[35]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4980/shard-kbl1/igt@[email protected]
[36]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2963/shard-kbl2/igt@[email protected]

[fdo#103166]: https://bugs.freedesktop.org/show_bug.cgi?id=103166
[fdo#103167]: https://bugs.freedesktop.org/show_bug.cgi?id=103167
[fdo#103355]: https://bugs.freedesktop.org/show_bug.cgi?id=103355
[fdo#103540]: https://bugs.freedesktop.org/show_bug.cgi?id=103540
[fdo#103665]: https://bugs.freedesktop.org/show_bug.cgi?id=103665
[fdo#108566]: https://bugs.freedesktop.org/show_bug.cgi?id=108566
[fdo#108686]: https://bugs.freedesktop.org/show_bug.cgi?id=108686
[fdo#109271]: https://bugs.freedesktop.org/show_bug.cgi?id=109271
[fdo#109441]: https://bugs.freedesktop.org/show_bug.cgi?id=109441
[fdo#110038]: https://bugs.freedesktop.org/show_bug.cgi?id=110038

Participating hosts (7 -> 6)
------------------------------

Missing (1): shard-skl

Build changes
-------------

* IGT: IGT_4980 -> IGTPW_2963

CI_DRM_6073: c059ddabfe60a5072ace44a34a9de9b4202df6ec @ git://anongit.freedesktop.org/gfx-ci/linux
IGTPW_2963: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2963/
IGT_4980: 159c69e5318e934b5f1d83939191c8756280b758 @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2963/
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev