diff mbox series

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

Message ID 20210331085713.2566057-1-tvrtko.ursulin@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series [i-g-t] intel_gpu_top: Do not print client header if no client stats | expand

Commit Message

Tvrtko Ursulin March 31, 2021, 8:57 a.m. UTC
From: Tvrtko Ursulin <tvrtko.ursulin@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@intel.com>
---
 tools/intel_gpu_top.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

Comments

Matthew Auld April 1, 2021, 1:24 p.m. UTC | #1
On Wed, 31 Mar 2021 at 09:57, Tvrtko Ursulin
<tvrtko.ursulin@linux.intel.com> wrote:
>
> From: Tvrtko Ursulin <tvrtko.ursulin@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@intel.com>
Reviewed-by: Matthew Auld <matthew.auld@intel.com>
diff mbox series

Patch

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);