[Intel-gfx] [PATCH i-g-t] intel_gpu_top: Do not print client header if no client stats

Tvrtko Ursulin tvrtko.ursulin at linux.intel.com
Wed Mar 31 08:57:13 UTC 2021


From: Tvrtko Ursulin <tvrtko.ursulin at intel.com>

Add a check if client stats are present to init_clients() so that the
returned clients data can be null from the start. This prevents the client
stats header to be printed on old kernels.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin at intel.com>
---
 tools/intel_gpu_top.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c
index e22e3bedacbe..7311038a39f4 100644
--- a/tools/intel_gpu_top.c
+++ b/tools/intel_gpu_top.c
@@ -671,9 +671,14 @@ struct clients {
 
 static struct clients *init_clients(const char *drm_card)
 {
-	struct clients *clients = malloc(sizeof(*clients));
+	struct clients *clients;
 	const char *slash;
 	ssize_t ret;
+	int dir;
+
+	clients = malloc(sizeof(*clients));
+	if (!clients)
+		return NULL;
 
 	memset(clients, 0, sizeof(*clients));
 
@@ -688,6 +693,14 @@ static struct clients *init_clients(const char *drm_card)
 		       "/sys/class/drm/%s/clients/", slash);
 	assert(ret > 0 && ret < sizeof(clients->sysfs_root));
 
+	dir = open(clients->sysfs_root, O_DIRECTORY | O_RDONLY);
+	if (dir < 0) {
+		free(clients);
+		clients = NULL;
+	} else {
+		close(dir);
+	}
+
 	return clients;
 }
 
@@ -2519,8 +2532,10 @@ int main(int argc, char **argv)
 
 	clients = init_clients(card.pci_slot_name[0] ? card.card : NULL);
 	init_engine_classes(engines);
-	clients->num_classes = engines->num_classes;
-	clients->class = engines->class;
+	if (clients) {
+		clients->num_classes = engines->num_classes;
+		clients->class = engines->class;
+	}
 
 	pmu_sample(engines);
 	scan_clients(clients);
-- 
2.27.0



More information about the Intel-gfx mailing list