[igt-dev] [PATCH i-g-t v5 3/7] lib/igt_pm: Add a helper to query the runtime_usage.

Zbigniew Kempczyński zbigniew.kempczynski at intel.com
Tue Mar 7 15:21:26 UTC 2023


From: Rodrigo Vivi <rodrigo.vivi at intel.com>

It will be useful so the tests can assert the expected
usage counter movement depending on the operation.

Signed-off-by: Rodrigo Vivi <rodrigo.vivi at intel.com>
Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>
Acked-by: Mauro Carvalho Chehab <mchehab at kernel.org>
---
 lib/igt_pm.c | 18 ++++++++++++++++++
 lib/igt_pm.h |  1 +
 2 files changed, 19 insertions(+)

diff --git a/lib/igt_pm.c b/lib/igt_pm.c
index 6c84e94f63..704acf7d14 100644
--- a/lib/igt_pm.c
+++ b/lib/igt_pm.c
@@ -1363,3 +1363,21 @@ int igt_pm_get_runtime_suspended_time(struct pci_device *pci_dev)
 
 	return -1;
 }
+
+/**
+ * igt_pm_get_runtime_usage:
+ * @pci_dev: pci device
+ *
+ * Reports the runtime PM usage count of a device.
+ */
+int igt_pm_get_runtime_usage(struct pci_device *pci_dev)
+{
+	char usage_str[64];
+	int usage, fd;
+
+	fd = igt_pm_get_power_attr_fd_rdonly(pci_dev, "runtime_usage");
+	if (igt_pm_read_power_attr(fd, usage_str, 64, true))
+		igt_assert(sscanf(usage_str, "%d", &usage) > 0);
+
+	return usage;
+}
diff --git a/lib/igt_pm.h b/lib/igt_pm.h
index f65b960c38..d0d6d673e8 100644
--- a/lib/igt_pm.h
+++ b/lib/igt_pm.h
@@ -86,5 +86,6 @@ void igt_pm_restore_pci_card_runtime_pm(void);
 void igt_pm_print_pci_card_runtime_status(void);
 bool i915_is_slpc_enabled(int fd);
 int igt_pm_get_runtime_suspended_time(struct pci_device *pci_dev);
+int igt_pm_get_runtime_usage(struct pci_device *pci_dev);
 
 #endif /* IGT_PM_H */
-- 
2.34.1



More information about the igt-dev mailing list