Return-Path: Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6160810E82F for ; Fri, 2 Sep 2022 13:10:42 +0000 (UTC) From: Swati Sharma To: igt-dev@lists.freedesktop.org Date: Fri, 2 Sep 2022 18:41:55 +0530 Message-Id: <20220902131156.29798-3-swati2.sharma@intel.com> In-Reply-To: <20220902131156.29798-1-swati2.sharma@intel.com> References: <20220902131156.29798-1-swati2.sharma@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [igt-dev] [v2 2/3] lib/pm: Add helper functions to get runtime suspended time List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: igt-dev-bounces@lists.freedesktop.org Sender: "igt-dev" List-ID: Added helper function to get runtime suspended time. This will be used to extend dc9 validation. v2: -created separate helper igt_pm_get_power_attr_fd_rdonly() (imre) -fixed igt_pm_get_runtime_suspended_time() (imre) Signed-off-by: Swati Sharma --- lib/igt_pm.c | 36 ++++++++++++++++++++++++++++++++++-- lib/igt_pm.h | 1 + 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/lib/igt_pm.c b/lib/igt_pm.c index 99251b40b..65f1fc866 100644 --- a/lib/igt_pm.c +++ b/lib/igt_pm.c @@ -953,13 +953,27 @@ static int igt_pm_get_power_attr_fd(struct pci_device *pci_dev, const char *attr return fd; } -static bool igt_pm_read_power_attr(int fd, char *attr, int len, bool autosuspend_delay) +static int igt_pm_get_power_attr_fd_rdonly(struct pci_device *pci_dev, const char *attr) +{ + char name[PATH_MAX]; + int fd; + + snprintf(name, PATH_MAX, "/sys/bus/pci/devices/%04x:%02x:%02x.%01x/power/%s", + pci_dev->domain, pci_dev->bus, pci_dev->dev, pci_dev->func, attr); + + fd = open(name, O_RDONLY); + igt_assert_f(fd >= 0, "Can't open %s\n", attr); + + return fd; +} + +static bool igt_pm_read_power_attr(int fd, char *attr, int len, bool power_attr) { int size; size = read(fd, attr, len - 1); - if (autosuspend_delay) { + if (power_attr) { if (size < 0 && errno == EIO) return false; } else { @@ -1219,3 +1233,21 @@ bool i915_is_slpc_enabled(int fd) else return strstr(buf, "SLPC state: running"); } + +int igt_pm_get_runtime_suspended_time(struct pci_device *pci_dev) +{ + char time_str[64]; + int time, time_fd; + + time_fd = igt_pm_get_power_attr_fd_rdonly(pci_dev, "runtime_suspended_time"); + if (igt_pm_read_power_attr(time_fd, time_str, 64, false)){ + igt_assert(sscanf(time_str, "%d", &time) > 0); + + igt_info("runtime suspend time for PCI '%04x:%02x:%02x.%01x' = %d\n", + pci_dev->domain, pci_dev->bus, pci_dev->dev, pci_dev->func, time); + + return time; + } + + return -1; +} diff --git a/lib/igt_pm.h b/lib/igt_pm.h index cbbde12b5..a7d621366 100644 --- a/lib/igt_pm.h +++ b/lib/igt_pm.h @@ -80,5 +80,6 @@ void igt_pm_setup_pci_card_runtime_pm(struct pci_device *pci_dev); 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); #endif /* IGT_PM_H */ -- 2.25.1