summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTvrtko Ursulin <tvrtko.ursulin@intel.com>2021-03-31 09:57:13 +0100
committerTvrtko Ursulin <tvrtko.ursulin@intel.com>2021-04-01 15:38:23 +0100
commit198d02e0db3d0940a59802b35b9e108ad618f2a3 (patch)
tree9562c4386406d3eea99974105767af9438cb397b
parent03905dc18a28978d1ca7430ca2c3de96411bdc48 (diff)
intel_gpu_top: Do not print client header if no client stats
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>
-rw-r--r--tools/intel_gpu_top.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c
index e22e3bed..7311038a 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);