From patchwork Wed Feb 28 15:35:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 10248063 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 4371E60365 for ; Wed, 28 Feb 2018 15:35:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3016B28D0D for ; Wed, 28 Feb 2018 15:35:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2320128D18; Wed, 28 Feb 2018 15:35:19 +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 9A98728D0D for ; Wed, 28 Feb 2018 15:35:18 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EAD926E99A; Wed, 28 Feb 2018 15:35:17 +0000 (UTC) X-Original-To: Intel-gfx@lists.freedesktop.org Delivered-To: Intel-gfx@lists.freedesktop.org Received: from mail-wr0-x241.google.com (mail-wr0-x241.google.com [IPv6:2a00:1450:400c:c0c::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id 484716E999 for ; Wed, 28 Feb 2018 15:35:16 +0000 (UTC) Received: by mail-wr0-x241.google.com with SMTP id o76so2870116wrb.7 for ; Wed, 28 Feb 2018 07:35:16 -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=e9/EQT1vqwbgOUkPepFHhuSw/zOpWeYSPIyTDTGejfY=; b=g0Wr4gnfwqYjJTUjRF8LYV5PnMZzeo5twWtSWRBDYcevcBaxTvBHUdQnZ38t1Ea+9G OQt+KYPb0UAIuN3OTragYer3gw4Wmd6yPg5AxJJ1+m/r1JywBoXXFcCf5QXss7F3tGaO LekMxBxawdVsjhnvNFI0rH9TILjNBCNxvUMQNsVb5o9Nt5n4nnRjbU6lPqe9E8g0Kze9 r7Hcji96L+hzpT4NzKsch2/wEGqOeMjinJcOhBEf4AQkZ+F+YAbvGXY/uHEHE2CLAhkc ewuMzhaP6fEKzrz+VU72PomAbGWCQiYKKyP5IObdLQGDsWBAlPWuNJy1v1kAlJQmLNGA 69XA== 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=e9/EQT1vqwbgOUkPepFHhuSw/zOpWeYSPIyTDTGejfY=; b=QgdvDjVO3iFs70/h0GsYAYqNMaCboBFPN1ywb/zlpdcJKDkGtngWMDc416lFAd4gAi wHfGvJ0H/jV+fBIjiOlQ3tZlKBPkpWOXTh6RHn9OO6KwiG1qs66mfXwUA0UkGFdSbhvI 2VAs6VxGBnqS5fCaCxpGPokVgzV5nYte/c4QBFweBQ6oz+jAmqGjvA/xI+5FYGUdgrEX C0MlTYIJktldgf8foHphTK8z31O7AU2QQnWi5AmFhqvdpruWh+nvzprnMlABQKlts5SZ ZbQMTpjYoIMSCiCgPC3tmk4MCbOAsBJEO78iwAMrSAKav3aKYhrtZ0Jes67g/LNhla6h CPMw== X-Gm-Message-State: APf1xPB5i1snVmUtkBGFcpO89fRoi4uyjcQjJvi10Us0GYVRx6EexUhe Ui3IeSINTV0Sd9cw2fxkh1fnvRcY X-Google-Smtp-Source: AH8x224Nx5os1DZ3wTUUnz22CZOOSq7LB2C/diSMlVbrTSi0Y4QDEk16wj/ehO5V3WZzaUxyoT2qkg== X-Received: by 10.223.209.68 with SMTP id b4mr16262454wri.161.1519832114817; Wed, 28 Feb 2018 07:35:14 -0800 (PST) Received: from localhost.localdomain ([95.146.144.186]) by smtp.gmail.com with ESMTPSA id x10sm1711608wrc.64.2018.02.28.07.35.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Feb 2018 07:35:14 -0800 (PST) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: igt-dev@lists.freedesktop.org Date: Wed, 28 Feb 2018 15:35:06 +0000 Message-Id: <20180228153506.13035-1-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180228110829.12126-1-tvrtko.ursulin@linux.intel.com> References: <20180228110829.12126-1-tvrtko.ursulin@linux.intel.com> Subject: [Intel-gfx] [PATCH i-g-t v2] 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. Signed-off-by: Tvrtko Ursulin Cc: Imre Deak Reviewed-by: Chris Wilson # v1 Reviewed-by: Chris Wilson Acked-by: Imre Deak Reviewed-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..04e2b89cca95 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_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,12 +349,26 @@ 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; + } + size = write(fd, "0\n", 2); close(fd); @@ -274,10 +376,20 @@ bool igt_setup_runtime_pm(void) if (size != 2) return false; + strchomp(__igt_pm_runtime_autosuspend); + igt_install_exit_handler(__igt_pm_runtime_exit_handler); + /* We know we support runtime PM, let's try to enable it now. */ 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);