From patchwork Mon Jul 23 11:46:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 10540027 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 31B4A157A for ; Mon, 23 Jul 2018 11:47:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 16FCD2863B for ; Mon, 23 Jul 2018 11:47:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 08AD928669; Mon, 23 Jul 2018 11:47:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8113F2863B for ; Mon, 23 Jul 2018 11:47:06 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BCE2E6E15B; Mon, 23 Jul 2018 11:47:05 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by gabe.freedesktop.org (Postfix) with ESMTPS id 854E56E15B for ; Mon, 23 Jul 2018 11:47:04 +0000 (UTC) Received: by mail-wr1-x442.google.com with SMTP id e7-v6so380571wrs.9 for ; Mon, 23 Jul 2018 04:47:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=cyGHicgZU9Rn1LYXEpzeCvbkPRI7ANCaVD3o1Y4pho8=; b=seE41LWV9URJ9qDfwswzD2e6BA9kKAg4hFcdwinNafD1NQizYz0piWkE2usYruTKlS O9zNPGSXmOqf0FNRpFv0vnXZji6D9iePtV3Otgaw/y2+wMGDYxxLbKbyPis7Wk4MSPLC 7hGIuJqr1fS60XCf+3TpQKKsl9hpO2ey9t/m8INf2IjzoitWf0zEHyzmRCNGU9A9XXI+ lWd/YR9FjTIOfb1FCUBn41h7BpO2ijVaRC1S6ePBm9OtdfbGfIEA7W6ydAqC/gj5m0Vl hnElJXTqkiIGqDdutuh4erF4szXmaB/nRCqjSPN4uPhiLoWT7pG0hIItmiQq0URPxfsc SnMg== X-Gm-Message-State: AOUpUlF0yEi6U37UlKPyL2EUwcftiPtXuIBS7oIRaC6Wj+Lo92GtGzxs NEBmYs9k+uNmSCCKaCeOWKISHeZwBqA= X-Google-Smtp-Source: AAOMgpec3Sro6LQEt+HJxWzwfHPrI1Jij3qpP+tCLJtOK+PUc0RnaUNyqh3P4Yg8zi0MUjQIwcuV9w== X-Received: by 2002:adf:b2f4:: with SMTP id g107-v6mr8613520wrd.53.1532346423159; Mon, 23 Jul 2018 04:47:03 -0700 (PDT) Received: from localhost.localdomain ([95.146.151.144]) by smtp.gmail.com with ESMTPSA id l14-v6sm23658407wrw.65.2018.07.23.04.47.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 04:47:02 -0700 (PDT) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: igt-dev@lists.freedesktop.org Date: Mon, 23 Jul 2018 12:46:55 +0100 Message-Id: <20180723114658.13025-1-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.17.1 Subject: [Intel-gfx] [PATCH i-g-t 1/4] lib/igt_pm: Make exit handlers signal safe X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: intel-gfx@lists.freedesktop.org MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Tvrtko Ursulin IGT logging helpers are not signal safe so avoid calling them from exit handlers. At the same time refactor the code a bit to enable following patches. Signed-off-by: Tvrtko Ursulin --- lib/igt_pm.c | 77 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 24 deletions(-) diff --git a/lib/igt_pm.c b/lib/igt_pm.c index 8ac132269d79..6f3b0a2d897d 100644 --- a/lib/igt_pm.c +++ b/lib/igt_pm.c @@ -66,33 +66,47 @@ enum { static char __igt_pm_audio_runtime_power_save[64]; static char __igt_pm_audio_runtime_control[64]; -static void __igt_pm_audio_runtime_exit_handler(int sig) +static int __igt_pm_audio_restore_runtime_pm(void) { int fd; - igt_debug("Restoring audio power management to '%s' and '%s'\n", - __igt_pm_audio_runtime_power_save, - __igt_pm_audio_runtime_control); + if (!__igt_pm_audio_runtime_power_save[0]) + return 0; fd = open("/sys/module/snd_hda_intel/parameters/power_save", O_WRONLY); if (fd < 0) - return; + return errno; + if (write(fd, __igt_pm_audio_runtime_power_save, strlen(__igt_pm_audio_runtime_power_save)) != - strlen(__igt_pm_audio_runtime_power_save)) - igt_warn("Failed to restore audio power_save to '%s'\n", - __igt_pm_audio_runtime_power_save); + strlen(__igt_pm_audio_runtime_power_save)) { + close(fd); + return errno; + } + close(fd); fd = open("/sys/bus/pci/devices/0000:00:03.0/power/control", O_WRONLY); if (fd < 0) - return; + return errno; + if (write(fd, __igt_pm_audio_runtime_control, strlen(__igt_pm_audio_runtime_control)) != - strlen(__igt_pm_audio_runtime_control)) - igt_warn("Failed to restore audio control to '%s'\n", - __igt_pm_audio_runtime_control); + strlen(__igt_pm_audio_runtime_control)) { + close(fd); + return errno; + } + close(fd); + + __igt_pm_audio_runtime_power_save[0] = 0; + + return 0; +} + +static void __igt_pm_audio_runtime_exit_handler(int sig) +{ + __igt_pm_audio_restore_runtime_pm(); } static void strchomp(char *str) @@ -297,33 +311,48 @@ int pm_status_fd = -1; static char __igt_pm_runtime_autosuspend[64]; static char __igt_pm_runtime_control[64]; -static void __igt_pm_runtime_exit_handler(int sig) +static int __igt_restore_runtime_pm(void) { int fd; - igt_debug("Restoring runtime management to '%s' and '%s'\n", - __igt_pm_runtime_autosuspend, - __igt_pm_runtime_control); + if (pm_status_fd < 0) + return 0; fd = open(POWER_DIR "/autosuspend_delay_ms", O_WRONLY); if (fd < 0) - return; + return errno; + if (write(fd, __igt_pm_runtime_autosuspend, strlen(__igt_pm_runtime_autosuspend)) != - strlen(__igt_pm_runtime_autosuspend)) - igt_warn("Failed to restore runtime pm autosuspend delay to '%s'\n", - __igt_pm_runtime_autosuspend); + strlen(__igt_pm_runtime_autosuspend)) { + close(fd); + return errno; + } + close(fd); fd = open(POWER_DIR "/control", O_WRONLY); if (fd < 0) - return; + return errno; + if (write(fd, __igt_pm_runtime_control, strlen(__igt_pm_runtime_control)) != - strlen(__igt_pm_runtime_control)) - igt_warn("Failed to restore runtime pm control to '%s'\n", - __igt_pm_runtime_control); + strlen(__igt_pm_runtime_control)) { + close(fd); + return errno; + } + close(fd); + + close(pm_status_fd); + pm_status_fd = -1; + + return 0; +} + +static void __igt_pm_runtime_exit_handler(int sig) +{ + __igt_restore_runtime_pm(); } /** From patchwork Mon Jul 23 11:46:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 10540031 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0A96213BB for ; Mon, 23 Jul 2018 11:47:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE8B428640 for ; Mon, 23 Jul 2018 11:47:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E2DDA2866C; Mon, 23 Jul 2018 11:47:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 875E428640 for ; Mon, 23 Jul 2018 11:47:12 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B08C06E298; Mon, 23 Jul 2018 11:47:10 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2C8D66E15B for ; Mon, 23 Jul 2018 11:47:05 +0000 (UTC) Received: by mail-wr1-x442.google.com with SMTP id r16-v6so372614wrt.11 for ; Mon, 23 Jul 2018 04:47:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=tK6h/trZ+BTVHsoymSwpp5+3Py92kDjBl8Q3bApQ7Bs=; b=LhLJXCi4ursATTQf63Cz680LHsMrVQn8yA6HqMgZBWSICCNEvGUgGQfmDXEdV5Oztd c6tZu1ZyFJlErbsFhK4D7PmERlNX/vKJKjjXC6orkGFkAv5Z/Qo2aOKee+9x9qvgXCI9 QLX/YPKydRoo+GLiQjhkYMDLjblJLPVSLz2HdS47eCBdCRoLiP1VXbRDiJqdFbpDK2rl kfEBzMDEue//xxmJyj8xdsPErwhlYSsIUJZI7z/IVQMChgYrZSaf0xxnYDzLopkken4m aQY0fjUbdNs/1qN+2aM9JisHTvsof21sXuHBKJRFic7cYQhopyhJ3AInTGuLr+XoXRMc 1oYw== X-Gm-Message-State: AOUpUlHfagajsaQ7ne1iUjrFp1S0sLjMyKtytBFjQ+EG7JmqzKl1Qs8M Zof5TPJNQW4v+Umgp0P41xiCxQ== X-Google-Smtp-Source: AAOMgpfafueiGU7orT/8P4mUlmno5PDbCT13JOhW3NGdr5qxplIbx5AnsUmNVQR3gReEe3qCEx/+Tw== X-Received: by 2002:adf:8405:: with SMTP id 5-v6mr8628783wrf.167.1532346423853; Mon, 23 Jul 2018 04:47:03 -0700 (PDT) Received: from localhost.localdomain ([95.146.151.144]) by smtp.gmail.com with ESMTPSA id l14-v6sm23658407wrw.65.2018.07.23.04.47.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 04:47:03 -0700 (PDT) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: igt-dev@lists.freedesktop.org Date: Mon, 23 Jul 2018 12:46:56 +0100 Message-Id: <20180723114658.13025-2-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180723114658.13025-1-tvrtko.ursulin@linux.intel.com> References: <20180723114658.13025-1-tvrtko.ursulin@linux.intel.com> Subject: [Intel-gfx] [PATCH i-g-t 2/4] lib/igt_pm: Find HDA device when attempting to enable runtime PM X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: intel-gfx@lists.freedesktop.org MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Tvrtko Ursulin HDA audio device can be present at various PCI paths on different systems which the existing code did not account for. Furthermore the failure to enable runtime PM was silent leaving callers in the dark. Improve it by auto-locating the PCI path and logging a warning when something is not as expected. Signed-off-by: Tvrtko Ursulin --- lib/igt_pm.c | 77 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 60 insertions(+), 17 deletions(-) diff --git a/lib/igt_pm.c b/lib/igt_pm.c index 6f3b0a2d897d..a4c0cf335f6d 100644 --- a/lib/igt_pm.c +++ b/lib/igt_pm.c @@ -33,6 +33,7 @@ #include #include #include +#include #include "drmtest.h" #include "igt_pm.h" @@ -64,6 +65,7 @@ enum { #define MAX_POLICY_STRLEN strlen(MAX_PERFORMANCE_STR) static char __igt_pm_audio_runtime_power_save[64]; +static const char * __igt_pm_audio_runtime_control_path; static char __igt_pm_audio_runtime_control[64]; static int __igt_pm_audio_restore_runtime_pm(void) @@ -86,7 +88,7 @@ static int __igt_pm_audio_restore_runtime_pm(void) close(fd); - fd = open("/sys/bus/pci/devices/0000:00:03.0/power/control", O_WRONLY); + fd = open(__igt_pm_audio_runtime_control_path, O_WRONLY); if (fd < 0) return errno; @@ -130,36 +132,77 @@ static void strchomp(char *str) */ void igt_pm_enable_audio_runtime_pm(void) { + char *path = NULL; + struct dirent *de; + DIR *dir; int fd; /* Check if already enabled. */ if (__igt_pm_audio_runtime_power_save[0]) return; - fd = open("/sys/module/snd_hda_intel/parameters/power_save", O_RDWR); - if (fd >= 0) { - igt_assert(read(fd, __igt_pm_audio_runtime_power_save, - sizeof(__igt_pm_audio_runtime_power_save)) > 0); - strchomp(__igt_pm_audio_runtime_power_save); - igt_install_exit_handler(__igt_pm_audio_runtime_exit_handler); - igt_assert_eq(write(fd, "1\n", 2), 2); - close(fd); - } - fd = open("/sys/bus/pci/devices/0000:00:03.0/power/control", O_RDWR); - if (fd >= 0) { - igt_assert(read(fd, __igt_pm_audio_runtime_control, - sizeof(__igt_pm_audio_runtime_control)) > 0); - strchomp(__igt_pm_audio_runtime_control); - igt_assert_eq(write(fd, "auto\n", 5), 5); - close(fd); + dir = opendir("/sys/bus/pci/drivers/snd_hda_intel"); + if (!dir) + goto err; + + while ((de = readdir(dir))) { + const char *prefix = "/sys/bus/pci/devices/"; + const char *suffix = "/power/control"; + const char *match = "0000:00:"; + + if (strncmp(de->d_name, match, strlen(match))) + continue; + + path = malloc(strlen(prefix) + + strlen(de->d_name) + + strlen(suffix) + + 1); + if (!path) + goto err; + + strcpy(path, prefix); + strcat(path, de->d_name); + strcat(path, suffix); + + igt_debug("Audio device PCI path is %s\n", path); } + if (!path) + goto err; + + fd = open("/sys/module/snd_hda_intel/parameters/power_save", O_RDWR); + if (fd < 0) + goto err; + + igt_assert(read(fd, __igt_pm_audio_runtime_power_save, + sizeof(__igt_pm_audio_runtime_power_save)) > 0); + strchomp(__igt_pm_audio_runtime_power_save); + igt_install_exit_handler(__igt_pm_audio_runtime_exit_handler); + igt_assert_eq(write(fd, "1\n", 2), 2); + close(fd); + + fd = open(path, O_RDWR); + if (fd < 0) + goto err; + + igt_assert(read(fd, __igt_pm_audio_runtime_control, + sizeof(__igt_pm_audio_runtime_control)) > 0); + strchomp(__igt_pm_audio_runtime_control); + igt_assert_eq(write(fd, "auto\n", 5), 5); + close(fd); + __igt_pm_audio_runtime_control_path = path; + igt_debug("Saved audio power management as '%s' and '%s'\n", __igt_pm_audio_runtime_power_save, __igt_pm_audio_runtime_control); /* Give some time for it to react. */ sleep(1); + + return; + +err: + igt_warn("Failed to enable audio runtime PM! (%d)", errno); } /** From patchwork Mon Jul 23 11:46:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 10540029 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6358313BB for ; Mon, 23 Jul 2018 11:47:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 50D6328640 for ; Mon, 23 Jul 2018 11:47:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 44BF22866C; Mon, 23 Jul 2018 11:47:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DCDB028640 for ; Mon, 23 Jul 2018 11:47:10 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4FD676E21C; Mon, 23 Jul 2018 11:47:10 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by gabe.freedesktop.org (Postfix) with ESMTPS id D8FEF6E192 for ; Mon, 23 Jul 2018 11:47:05 +0000 (UTC) Received: by mail-wr1-x42b.google.com with SMTP id j5-v6so380808wrr.8 for ; Mon, 23 Jul 2018 04:47:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=zQzdnYjMWZTU19Shzp+t7xAR5DS37sypQWlgAYM7uXw=; b=oAKYXTrZsj5e3IWJe+g6tY+RIAWMYCty2HHDmQCuMfmx/a3LXCvD54motoV5OfHzVg WWblymxAj+DZpzsSLHhQBg/N8ZCV4lWHSu8RhXBH+9tssyR1czacNZ7qwYq76lEOeftb QisQOZJdQb+oyZfI7k7Km2LUmJCfjQafcQNPiN5chNQpK+mCAzvKsVKedQoL8ytIoZKp qKAzbZJBqZcY6maaO0q8dv4UPbLn56lJB6yZk8SvLyf9Pg9I5arIvQEePQ8DgSdOB4/h dM0yJHyCx5AutmGq84F3Vd2PHo+UFPlai12f0SGh6wH0zbZ4qTx2mRkgPEhJNi/6Qv5N SQ9A== X-Gm-Message-State: AOUpUlEWsOAl4a1hYtZis/LLHO9Tlic/q2GUK0r9tKgrIIUs6ytujiak wVkiYVeAOev0MhY5YsKjJyeCKw== X-Google-Smtp-Source: AAOMgpeuzEny6EsVRsbQ/Udv7awJRtQAAy3v2117EFrC0M7MJLkAe8gnXZSg9omlPxFgTqjz5upW7A== X-Received: by 2002:adf:f60a:: with SMTP id t10-v6mr7538764wrp.170.1532346424581; Mon, 23 Jul 2018 04:47:04 -0700 (PDT) Received: from localhost.localdomain ([95.146.151.144]) by smtp.gmail.com with ESMTPSA id l14-v6sm23658407wrw.65.2018.07.23.04.47.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 04:47:04 -0700 (PDT) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: igt-dev@lists.freedesktop.org Date: Mon, 23 Jul 2018 12:46:57 +0100 Message-Id: <20180723114658.13025-3-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180723114658.13025-1-tvrtko.ursulin@linux.intel.com> References: <20180723114658.13025-1-tvrtko.ursulin@linux.intel.com> Subject: [Intel-gfx] [PATCH i-g-t 3/4] lib/igt_pm: Export function to restore runtime PM status X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: intel-gfx@lists.freedesktop.org MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Tvrtko Ursulin In cases when runtime PM is enabled only from individual subtests and not whole tests it is usable to be able to restore the old runtime PM config and so avoid running subsequent subtests in an unexpected environment. Signed-off-by: Tvrtko Ursulin --- lib/igt_pm.c | 41 +++++++++++++++++++++++++++++++++++++++++ lib/igt_pm.h | 1 + 2 files changed, 42 insertions(+) diff --git a/lib/igt_pm.c b/lib/igt_pm.c index a4c0cf335f6d..a861055d382b 100644 --- a/lib/igt_pm.c +++ b/lib/igt_pm.c @@ -106,6 +106,23 @@ static int __igt_pm_audio_restore_runtime_pm(void) return 0; } +static void igt_pm_audio_restore_runtime_pm(void) +{ + int ret; + + if (!__igt_pm_audio_runtime_power_save[0]) + return; + + igt_debug("Restoring audio power management to '%s' and '%s'\n", + __igt_pm_audio_runtime_power_save, + __igt_pm_audio_runtime_control); + + ret = __igt_pm_audio_restore_runtime_pm(); + if (ret) + igt_warn("Failed to restore runtime audio PM! (errno=%d)\n", + ret); +} + static void __igt_pm_audio_runtime_exit_handler(int sig) { __igt_pm_audio_restore_runtime_pm(); @@ -393,6 +410,30 @@ static int __igt_restore_runtime_pm(void) return 0; } +/** + * igt_restore_runtime_pm: + * + * Restores the runtime PM configuration as it was before the call to + * igt_setup_runtime_pm. + */ +void igt_restore_runtime_pm(void) +{ + int ret; + + if (pm_status_fd < 0) + return; + + igt_debug("Restoring runtime PM management to '%s' and '%s'\n", + __igt_pm_runtime_autosuspend, + __igt_pm_runtime_control); + + ret = __igt_restore_runtime_pm(); + if (ret) + igt_warn("Failed to restore runtime PM! (errno=%d)\n", ret); + + igt_pm_audio_restore_runtime_pm(); +} + static void __igt_pm_runtime_exit_handler(int sig) { __igt_restore_runtime_pm(); diff --git a/lib/igt_pm.h b/lib/igt_pm.h index eced39f8801a..10cc6794e4e7 100644 --- a/lib/igt_pm.h +++ b/lib/igt_pm.h @@ -47,6 +47,7 @@ enum igt_runtime_pm_status { }; bool igt_setup_runtime_pm(void); +void igt_restore_runtime_pm(void); enum igt_runtime_pm_status igt_get_runtime_pm_status(void); bool igt_wait_for_pm_status(enum igt_runtime_pm_status status); From patchwork Mon Jul 23 11:46:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 10540033 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D1FE313BB for ; Mon, 23 Jul 2018 11:47:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C25D12863B for ; Mon, 23 Jul 2018 11:47:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B6AB428669; Mon, 23 Jul 2018 11:47:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 825EE2863B for ; Mon, 23 Jul 2018 11:47:13 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 671D66E30F; Mon, 23 Jul 2018 11:47:11 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by gabe.freedesktop.org (Postfix) with ESMTPS id BED5B6E21C for ; Mon, 23 Jul 2018 11:47:06 +0000 (UTC) Received: by mail-wr1-x442.google.com with SMTP id b15-v6so376638wrv.10 for ; Mon, 23 Jul 2018 04:47:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=G9202F9jb+tGm2buj5MUcBvA/z3lf/jhpS0kAEHhY9M=; b=Mvu5cPtq5vDpI6K2i68HVSYPYFvz+VHPqpByeGudxNuh3nnloBgS320Daeo2TfTcNT SbkYdUwhJ4JaKz/RHItbnjHuUM0uY8dujvd9IZI3wIGlE/JKjEziD+fL4yUxc8sk3mmD 3C6Q32HmNrQX4ebtYAR3x9Icab83AlSCRXY5QKaH3mCON60UpG0j0C4e8u5HaliU2plj sZXlTKLgIMb+PSMZ3A6f5l+vAyFIfz+jZrlixHsNETxnwXa1/2Ie42QAXfOihx/GJ4/z IusQnXMxRD/KYxWGCZEC76zt2lgvOnogUJ3xSA910kaqRklyxcgHTs340zsHhF2XtS9Y RfOg== X-Gm-Message-State: AOUpUlERawfrDC9YP2CG+Jgmuu5Oa7HloeIJXTEjeDc1+AXe5ZsSZTvO znJxDvGDjby96APJdXetqK2R1w== X-Google-Smtp-Source: AAOMgpdUhhSaViQkz1sAdua/v6qOV91f7tZT0Q2sGskyKYbQ2G8fmf80e6LB0B0qsQoGsQ3c+/yI4w== X-Received: by 2002:adf:f9c9:: with SMTP id w9-v6mr8269736wrr.105.1532346425445; Mon, 23 Jul 2018 04:47:05 -0700 (PDT) Received: from localhost.localdomain ([95.146.151.144]) by smtp.gmail.com with ESMTPSA id l14-v6sm23658407wrw.65.2018.07.23.04.47.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 04:47:04 -0700 (PDT) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: igt-dev@lists.freedesktop.org Date: Mon, 23 Jul 2018 12:46:58 +0100 Message-Id: <20180723114658.13025-4-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180723114658.13025-1-tvrtko.ursulin@linux.intel.com> References: <20180723114658.13025-1-tvrtko.ursulin@linux.intel.com> Subject: [Intel-gfx] [PATCH i-g-t 4/4] tests/perf_pmu: Restore runtime PM status at rc6 test exit X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: intel-gfx@lists.freedesktop.org MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Tvrtko Ursulin Avoid running subsequent subtests in non-default setup by restoring the runtime PM config in one particular subtest. Signed-off-by: Tvrtko Ursulin --- tests/perf_pmu.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/perf_pmu.c b/tests/perf_pmu.c index a1d36ac4fa9d..9a20abb6b95c 100644 --- a/tests/perf_pmu.c +++ b/tests/perf_pmu.c @@ -1441,6 +1441,9 @@ test_rc6(int gem_fd, unsigned int flags) close(fw); close(fd); + if (flags & TEST_RUNTIME_PM) + igt_restore_runtime_pm(); + assert_within_epsilon(busy - prev, 0.0, tolerance); }