From patchwork Fri Mar 2 09:51:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 10254005 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 48D646037D for ; Fri, 2 Mar 2018 09:51:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 358AA28901 for ; Fri, 2 Mar 2018 09:51:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 29F9A28938; Fri, 2 Mar 2018 09:51:55 +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 9945A28924 for ; Fri, 2 Mar 2018 09:51:54 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E25866EE3A; Fri, 2 Mar 2018 09:51:53 +0000 (UTC) X-Original-To: Intel-gfx@lists.freedesktop.org Delivered-To: Intel-gfx@lists.freedesktop.org Received: from mail-wm0-x242.google.com (mail-wm0-x242.google.com [IPv6:2a00:1450:400c:c09::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id 304406EE3A for ; Fri, 2 Mar 2018 09:51:52 +0000 (UTC) Received: by mail-wm0-x242.google.com with SMTP id i3so1921203wmi.4 for ; Fri, 02 Mar 2018 01:51:51 -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:in-reply-to:references; bh=uNN0H4PGeDNUTb7iZEP5ycIR5Nk7KUQghOk84Pb/StU=; b=efQoph3qXbwHUbFM1hyQmM0AxDKiICFptdZk3VJru1yCICQeaS+uREJCXY9Lwo81oz MsC6X17sPz9JPir8VPu9BBhKbvE3H8Rb4gRTagJ+IDVsaIIIgBHTpMmR4ZLWPXsxu+Ho NAbBaydpI/K3dcUHnICLXiRQ3t7WQ4zT7EhnMy3QEPKwXBVcGhBanOcEUMyVUusxmlyR fUS8VyWL1xkKmYwnFIWAGb0xUiATpzd1N3Ddf5XmQfkFm0OVWvMH4u7uKntDORG7ryvt /jC0CHkuzkyiCTWbuwYic35/HBoxXaTUdlqBCfZhVRffStcknjPfseYysFLGFme6N2sl 3lWg== 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=uNN0H4PGeDNUTb7iZEP5ycIR5Nk7KUQghOk84Pb/StU=; b=VKwxuI2/PnHQX/1X8MFMwqspbIgoLLh59zdkM5h+E4RQP06E7Rj7l59rsZyAIiqbuG 1OPOa2LUHSJZih0BPeXcSeO48EKnIHxudL4wd24Z1JV8Tgf8+7nQbCb9WCHUhDauajOu 8i047F0jK9tYdnS589sP/kPKvi+Q45IKZ3vI3eDpU/iUEAwsn4vV/xgOUDIf/Dqap4NX bd2QBP+1ACsaW9Y8BZQe+ub7u/rN0Nm3hnL8rAz7rMX0oU4OpStM3b5yIKnEuZvcOEVc GFF9kBd0iX5nk1HiU/UrPK7hXmcl/ymgn5MxkBMMenR41pHPTlgg3X+Ac20iBN6GnxFp 7mlw== X-Gm-Message-State: AElRT7FeTaJcZf4OVZsOHw3jcvNc2bgp6sYUfbiJEYFIsq1iaYUFh7KX 93zcFMUeSFe6e0q+hxAtY+4hhA== X-Google-Smtp-Source: AG47ELteGvbVI1b2TteE2wfEWEzl6l5g+Vp2fmGAwfrSj4GSvFndCP0QwElssq8B/BIcz/5bcM6fow== X-Received: by 10.28.186.66 with SMTP id k63mr909406wmf.156.1519984310556; Fri, 02 Mar 2018 01:51:50 -0800 (PST) Received: from localhost.localdomain ([95.146.144.186]) by smtp.gmail.com with ESMTPSA id y23sm6618980wra.9.2018.03.02.01.51.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Mar 2018 01:51:50 -0800 (PST) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: igt-dev@lists.freedesktop.org Date: Fri, 2 Mar 2018 09:51:39 +0000 Message-Id: <20180302095139.24140-1-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180302092950.2cybveeu5py5hkzc@ideak-desk.fi.intel.com> References: <20180302092950.2cybveeu5py5hkzc@ideak-desk.fi.intel.com> Subject: [Intel-gfx] [PATCH i-g-t v3] 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. v2: Read failure means no runtime pm support so don't assert on it. v3: Install exit handler before the write to close the Ctrl^C race. (Imre) Signed-off-by: Tvrtko Ursulin Cc: Imre Deak Reviewed-by: Chris Wilson # v2 Acked-by: Imre Deak --- lib/igt_pm.c | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 117 insertions(+), 5 deletions(-) diff --git a/lib/igt_pm.c b/lib/igt_pm.c index 5bf5b2e23cdc..8ac132269d79 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 (len && 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_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_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,12 +349,29 @@ 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"); - /* If we fail to write to the file, it means this system doesn't support - * runtime PM. */ + /* + * Save previous values to be able to install exit handler to restore + * them on test exit. + */ + size = read(fd, __igt_pm_runtime_autosuspend, + sizeof(__igt_pm_runtime_autosuspend)); + + /* + * If we fail to read from the file, it means this system doesn't + * support runtime PM. + */ + if (size <= 0) { + close(fd); + return false; + } + + strchomp(__igt_pm_runtime_autosuspend); + igt_install_exit_handler(__igt_pm_runtime_exit_handler); + size = write(fd, "0\n", 2); close(fd); @@ -278,6 +383,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);