From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id 791F710E123 for ; Thu, 2 Mar 2023 11:10:12 +0000 (UTC) From: =?UTF-8?q?Zbigniew=20Kempczy=C5=84ski?= To: igt-dev@lists.freedesktop.org Date: Thu, 2 Mar 2023 12:09:42 +0100 Message-Id: <20230302110947.548610-4-zbigniew.kempczynski@intel.com> In-Reply-To: <20230302110947.548610-1-zbigniew.kempczynski@intel.com> References: <20230302110947.548610-1-zbigniew.kempczynski@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [igt-dev] [PATCH i-g-t v4 3/8] lib/igt_pm: Add a helper to query the runtime_usage. List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: igt-dev-bounces@lists.freedesktop.org Sender: "igt-dev" List-ID: From: Rodrigo Vivi It will be useful so the tests can assert the expected usage counter movement depending on the operation. Signed-off-by: Rodrigo Vivi Signed-off-by: Zbigniew KempczyƄski --- 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