From patchwork Wed Feb 28 11:08:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 10247269 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5A31860365 for ; Wed, 28 Feb 2018 11:08:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5693328669 for ; Wed, 28 Feb 2018 11:08:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4AE8728C9E; Wed, 28 Feb 2018 11:08:44 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID 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 79F0828669 for ; Wed, 28 Feb 2018 11:08:43 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 12C3489852; Wed, 28 Feb 2018 11:08:42 +0000 (UTC) X-Original-To: Intel-gfx@lists.freedesktop.org Delivered-To: Intel-gfx@lists.freedesktop.org Received: from mail-wm0-x241.google.com (mail-wm0-x241.google.com [IPv6:2a00:1450:400c:c09::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id EF2016E932 for ; Wed, 28 Feb 2018 11:08:39 +0000 (UTC) Received: by mail-wm0-x241.google.com with SMTP id 188so4262332wme.1 for ; Wed, 28 Feb 2018 03:08:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ursulin-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=tlAL6XfcLCDWhnH9XhaAfou+2Sae/ymLXRhzCI4M4r4=; b=bh0nLAJhvX1fQGumX3E91JyhISMabtLpDutVnT13FOeOZ/q7XlMuZN7TGNuFZZKW1k /TWVGDlMOwpeCGaYu1XPLdPX43NPNsLF2nYzaqYq3bvFX8CLQbTAXd3fxPWavma3PS8d ksUq+B1DwDQGVMCKbleQKhgYAYGI5kNHAke0sovEwH3mhamDYBj8f87Lyqmj5X3wV9fz f37885LqIIfIOf+8UUp0WcaR7c7vWo+2hNxFWcyeQb4wZ1XonWeiuQOGQYI4Daxo6wA8 EpdLXX0wDOzHshmBmwecpC2sA5080r/ba4C3WkimWuStI8h27zhDTjTjuzfo3PT1keU0 vuXQ== 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=tlAL6XfcLCDWhnH9XhaAfou+2Sae/ymLXRhzCI4M4r4=; b=iN0ZzyWv6OuDcpt8YwTp/dWl5WYVjf/Qw7TJSZeufx86ZUP9xQTzaD9QlziqhBAz8H /uIXmAiD9Y5qzkubxDMBdHX/kguqYaUdioBzjgG08O1Q6qCODs0obW62DiYc4v3rY3L1 9RihwDls0vXqSLGLzt3zFmVHvXvtlvfA4qpJVDfZLFsec2qZvGJDo4ggkQ3zUtJ6cpHA 24ACs/S3tfiT11uomvFfl81DooMsJBBySulsA1AjFKA3eCBeKtHwcQSBH5jMlCSbve5r MbuLONwxsRJyQq2OMi78Wl7icnyOA9vX1cQRZ1pMGrUJhLJA0B5f6ENOVwG1isRw91sY QJLA== X-Gm-Message-State: APf1xPDvTemiKVot80/SJOvtlHaYh/bv662XazuQngDWjEGNCvMTvAXh 4pOd+8sLjpeky5zK90nKHJkD9umw X-Google-Smtp-Source: AG47ELsaWtwcF202Qd0eQ6mztccUjTfy1rdTcIaoegheBXjVCDwJlLDT6RUO1XqPVpwNt+5+45i8KA== X-Received: by 10.28.218.147 with SMTP id r141mr13059120wmg.55.1519816118312; Wed, 28 Feb 2018 03:08:38 -0800 (PST) Received: from localhost.localdomain ([95.146.144.186]) by smtp.gmail.com with ESMTPSA id u20sm1116444wru.94.2018.02.28.03.08.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Feb 2018 03:08:37 -0800 (PST) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: igt-dev@lists.freedesktop.org Date: Wed, 28 Feb 2018 11:08:29 +0000 Message-Id: <20180228110829.12126-1-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.14.1 Subject: [Intel-gfx] [PATCH i-g-t] lib/igt_pm: Restore runtime pm state on 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 Some tests (the ones which call igt_setup_runtime_pm and igt_pm_enable_audio_runtime_pm) change default system configuration and never restore it. The configured runtime suspend is aggressive and may influence behaviour of subsequent tests, so it is better to restore to previous values on test exit. This way system behaviour, with regards to a random sequence of executed tests, will be more consistent from one run to another. Signed-off-by: Tvrtko Ursulin Cc: Imre Deak Reviewed-by: Chris Wilson --- lib/igt_pm.c | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 104 insertions(+), 3 deletions(-) diff --git a/lib/igt_pm.c b/lib/igt_pm.c index 5bf5b2e23cdc..0c8b5e8e9257 100644 --- a/lib/igt_pm.c +++ b/lib/igt_pm.c @@ -63,6 +63,46 @@ enum { /* Remember to fix this if adding longer strings */ #define MAX_POLICY_STRLEN strlen(MAX_PERFORMANCE_STR) +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) +{ + int fd; + + igt_debug("Restoring audio power management to '%s' and '%s'\n", + __igt_pm_audio_runtime_power_save, + __igt_pm_audio_runtime_control); + + fd = open("/sys/module/snd_hda_intel/parameters/power_save", O_WRONLY); + if (fd < 0) + return; + 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); + close(fd); + + fd = open("/sys/bus/pci/devices/0000:00:03.0/power/control", O_WRONLY); + if (fd < 0) + return; + 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); + close(fd); +} + +static void strchomp(char *str) +{ + int len = strlen(str); + + if (str[len - 1] == '\n') + str[len - 1] = 0; +} + /** * igt_pm_enable_audio_runtime_pm: * @@ -78,16 +118,32 @@ void igt_pm_enable_audio_runtime_pm(void) { int fd; - fd = open("/sys/module/snd_hda_intel/parameters/power_save", O_WRONLY); + /* 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_assert_eq(write(fd, "1\n", 2), 2); + igt_install_exit_handler(__igt_pm_audio_runtime_exit_handler); close(fd); } - fd = open("/sys/bus/pci/devices/0000:00:03.0/power/control", O_WRONLY); + 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); } + + 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); } @@ -238,6 +294,38 @@ void igt_pm_restore_sata_link_power_management(int8_t *pm_data) /* We just leak this on exit ... */ 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) +{ + int fd; + + igt_debug("Restoring runtime management to '%s' and '%s'\n", + __igt_pm_runtime_autosuspend, + __igt_pm_runtime_control); + + fd = open(POWER_DIR "/autosuspend_delay_ms", O_WRONLY); + if (fd < 0) + return; + 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); + close(fd); + + fd = open(POWER_DIR "/control", O_WRONLY); + if (fd < 0) + return; + 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); + close(fd); +} + /** * igt_setup_runtime_pm: * @@ -261,10 +349,16 @@ bool igt_setup_runtime_pm(void) /* Our implementation uses autosuspend. Try to set it to 0ms so the test * suite goes faster and we have a higher probability of triggering race * conditions. */ - fd = open(POWER_DIR "/autosuspend_delay_ms", O_WRONLY); + fd = open(POWER_DIR "/autosuspend_delay_ms", O_RDWR); igt_assert_f(fd >= 0, "Can't open " POWER_DIR "/autosuspend_delay_ms\n"); + /* Save previous values and install exit handler to restore them. */ + igt_assert(read(fd, __igt_pm_runtime_autosuspend, + sizeof(__igt_pm_runtime_autosuspend)) > 0); + strchomp(__igt_pm_runtime_autosuspend); + igt_install_exit_handler(__igt_pm_runtime_exit_handler); + /* If we fail to write to the file, it means this system doesn't support * runtime PM. */ size = write(fd, "0\n", 2); @@ -278,6 +372,13 @@ bool igt_setup_runtime_pm(void) fd = open(POWER_DIR "/control", O_RDWR); igt_assert_f(fd >= 0, "Can't open " POWER_DIR "/control\n"); + igt_assert(read(fd, __igt_pm_runtime_control, + sizeof(__igt_pm_runtime_control)) > 0); + strchomp(__igt_pm_runtime_control); + + igt_debug("Saved runtime power management as '%s' and '%s'\n", + __igt_pm_runtime_autosuspend, __igt_pm_runtime_control); + size = write(fd, "auto\n", 5); igt_assert(size == 5);