From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by gabe.freedesktop.org (Postfix) with ESMTPS id 13EC210E4C2 for ; Thu, 22 Jun 2023 06:02:44 +0000 (UTC) From: Anshuman Gupta To: igt-dev@lists.freedesktop.org Date: Thu, 22 Jun 2023 11:32:28 +0530 Message-Id: <20230622060228.2885144-3-anshuman.gupta@intel.com> In-Reply-To: <20230622060228.2885144-1-anshuman.gupta@intel.com> References: <20230622060228.2885144-1-anshuman.gupta@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [igt-dev] [PATCH i-g-t v3 2/2] lib/igt_aux: Enable PM Suspend dbg messages List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: badal.nilawar@intel.com Errors-To: igt-dev-bounces@lists.freedesktop.org Sender: "igt-dev" List-ID: Enabling PM Suspend dbg messages by turning on /sys/power/pm_debug_messages switch also adding an exit handler provision to restore the pm_debug_messages state. v2: Fixed sysfs_fd leak. [Badal] Signed-off-by: Anshuman Gupta Reviewed-by: Badal Nilawar --- lib/igt_aux.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/igt_aux.c b/lib/igt_aux.c index 25bf720b8e..3bd7132552 100644 --- a/lib/igt_aux.c +++ b/lib/igt_aux.c @@ -703,6 +703,7 @@ void igt_print_activity(void) static int autoresume_delay; bool __console_suspend_saved_state; +bool __pm_debug_messages_state; #define SYSFS_MODULE_PRINTK "/sys/module/printk/parameters/" #define CONSOLE_SUSPEND_DISABLE false @@ -913,7 +914,7 @@ static bool is_mem_sleep_state_supported(int power_dir, enum igt_mem_sleep state static void igt_aux_pm_suspend_dbg_restore_exit_handler(int sig) { - int sysfs_fd; + int sysfs_fd, power_dir; sysfs_fd = open(SYSFS_MODULE_PRINTK, O_RDONLY); @@ -922,9 +923,18 @@ static void igt_aux_pm_suspend_dbg_restore_exit_handler(int sig) igt_sysfs_set_boolean(sysfs_fd, "console_suspend", __console_suspend_saved_state); close(sysfs_fd); + power_dir = open("/sys/power", O_RDONLY); + + if (power_dir < 0) + return; + + if (!faccessat(power_dir, "pm_debug_messages", R_OK | W_OK, 0)) + igt_sysfs_set_boolean(power_dir, "pm_debug_messages", __pm_debug_messages_state); + + close(power_dir); } -static void igt_aux_enable_pm_suspend_dbg(void) +static void igt_aux_enable_pm_suspend_dbg(int power_dir) { int sysfs_fd; @@ -940,6 +950,14 @@ static void igt_aux_enable_pm_suspend_dbg(void) igt_warn("Unable to open printk parameters Err:%d\n", errno); } + /* pm_debug_messages depends on CONFIG_PM_SLEEP_DEBUG */ + if (!faccessat(power_dir, "pm_debug_messages", R_OK | W_OK, 0)) { + __pm_debug_messages_state = igt_sysfs_get_boolean(sysfs_fd, "pm_debug_messages"); + igt_sysfs_set_boolean(power_dir, "pm_debug_messages", true); + } + + igt_install_exit_handler(igt_aux_pm_suspend_dbg_restore_exit_handler); + close(sysfs_fd); } @@ -981,7 +999,7 @@ void igt_system_suspend_autoresume(enum igt_suspend_state state, "Suspend to disk requires swap space.\n"); orig_test = get_suspend_test(power_dir); - igt_aux_enable_pm_suspend_dbg(); + igt_aux_enable_pm_suspend_dbg(power_dir); if (state == SUSPEND_STATE_S3) { orig_mem_sleep = get_mem_sleep(); -- 2.25.1