Currently profiling is enabled for every device by writing '1' into the
appropriate sysfs node. But Panthor uses a bit mask where cycle and
timestamp sampling are enabled by the first and second bits respectively.

By default assume that writing '1' will enable profiling, but then adjust
the value to '3' for the Panthor driver.

Closes: https://gitlab.freedesktop.org/drm/igt-gpu-tools/-/work_items/209
Signed-off-by: Deborah Brouwer <[email protected]>
---
 lib/igt_profiling.c | 23 +++++++++++++++++++++--
 lib/igt_profiling.h |  1 +
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/lib/igt_profiling.c b/lib/igt_profiling.c
index e1526ad98..5c62a3fb1 100644
--- a/lib/igt_profiling.c
+++ b/lib/igt_profiling.c
@@ -50,7 +50,10 @@ struct igt_profiled_device *igt_devices_profiled(void)
 
        while ((entry = readdir(dev_dir)) != NULL) {
                char path[PATH_MAX];
+               char driver_path[PATH_MAX];
+               char driver_link[PATH_MAX];
                char orig_state;
+               ssize_t len;
                int sysfs_fd;
 
                /* All DRM device entries are symlinks to other paths within 
sysfs */
@@ -87,7 +90,23 @@ struct igt_profiled_device *igt_devices_profiled(void)
                }
 
                profiled_devices[i].syspath = strdup(path);
-               profiled_devices[i++].original_state = orig_state;
+               profiled_devices[i].original_state = orig_state;
+               profiled_devices[i].enable_state = '1';
+
+               snprintf(driver_path, sizeof(driver_path), 
"%s/%s/device/driver",
+                        SYSFS_DRM, entry->d_name);
+
+               len = readlink(driver_path, driver_link, sizeof(driver_link) - 
1);
+               if (len >= 0) {
+                       driver_link[len] = '\0';
+
+                       if (strstr(driver_link, "/panthor")) {
+                               /* Enable both cycle and timestamp sampling. */
+                               profiled_devices[i].enable_state = '3';
+                       }
+               }
+
+               i++;
 
                close(sysfs_fd);
        }
@@ -124,7 +143,7 @@ void igt_devices_configure_profiling(struct 
igt_profiled_device *devices, bool e
                if (sysfs_fd < 0)
                        continue;
 
-               write(sysfs_fd, enable ? "1" : &devices[i].original_state, 1);
+               write(sysfs_fd, enable ? &devices[i].enable_state : 
&devices[i].original_state, 1);
                close(sysfs_fd);
        }
 }
diff --git a/lib/igt_profiling.h b/lib/igt_profiling.h
index b063d54e1..d38cc2bb6 100644
--- a/lib/igt_profiling.h
+++ b/lib/igt_profiling.h
@@ -12,6 +12,7 @@
 struct igt_profiled_device {
        char *syspath;
        char original_state;
+       char enable_state;
 };
 
 void igt_devices_configure_profiling(struct igt_profiled_device *devices, bool 
enable);

---
base-commit: 65f84b280be2caf8ce376295d97987a808affdee
change-id: 20260922-b4-gputop_panthor-cbb78c0ffbf8

Best regards,
-- 
Deborah Brouwer <[email protected]>

Reply via email to