From patchwork Wed Jul 27 12:38:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 9249769 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 A3520607D8 for ; Wed, 27 Jul 2016 12:39:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 922471FF0B for ; Wed, 27 Jul 2016 12:39:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 84C9C271FD; Wed, 27 Jul 2016 12:39:32 +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]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D795A26253 for ; Wed, 27 Jul 2016 12:39:31 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 20B616E6BF; Wed, 27 Jul 2016 12:39:07 +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 6F5A56E6B3 for ; Wed, 27 Jul 2016 12:38:35 +0000 (UTC) Received: by mail-wm0-x241.google.com with SMTP id o80so6281893wme.0 for ; Wed, 27 Jul 2016 05:38:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=tiAzJ4pZr4MMZb4sLLqFCif8nrZUnw+PdJa2KzOFpCg=; b=VOb14owFLrQ1Krh/J5TwhYPfpad7Cj5eRUkuI7r/4S3rHievWUTQUrlU+6/PjtvEdb XOIwzyme3pGrjahosaWsydLRf/yjs2GTiyRY2Jmq49cS1XWzDWFVAM228yO0qjpkQPzA x4E48DDu/IVGoRkOdEBFg8HXvApRcawgZu2s8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=tiAzJ4pZr4MMZb4sLLqFCif8nrZUnw+PdJa2KzOFpCg=; b=Nfh/812XMO1Yyd7r/MFgUIzA3RRzjNGAr7umILBhmwwR6oFWHEaF2KaiXfn9ECHKQ9 0Zj1OxCXslDJ+VLhRQEExojnlMPc170Og+GXd3E0i+EKjRToiOLIBh1f1dOD7yemMRwE fWff3m2wpZP8Mfw/clK/dq8+3kE5E0TRT4VweBjT2TjS0iZuiFCpA8S+NN3pzRfZx1d7 KmJ+Gt/+sFPbDLEnHaeb9i8Uh/Orl0x/f/xU2EA4dvV1V5oReeb24cS/tq1BoVF804/R xNcAUQ06vIzuVSbQxHAhzAxJez90yDM4h05fjr67p1x8jE39LUJTgI3ck3GCgbCNvaqr cxCA== X-Gm-Message-State: AEkoouuqVr8Nb8kLOdutlUKwXdKZRX/CA/FWR9KGyAeat2NR+s68Z9pYvzq1skgt9GVEgw== X-Received: by 10.28.194.195 with SMTP id s186mr33889425wmf.48.1469623111026; Wed, 27 Jul 2016 05:38:31 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:56b5:0:ac27:b86c:7764:9429]) by smtp.gmail.com with ESMTPSA id p23sm6979002wme.8.2016.07.27.05.38.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Jul 2016 05:38:30 -0700 (PDT) From: Daniel Vetter To: Intel Graphics Development Date: Wed, 27 Jul 2016 14:38:11 +0200 Message-Id: <1469623097-26044-6-git-send-email-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1469623097-26044-1-git-send-email-daniel.vetter@ffwll.ch> References: <1469623097-26044-1-git-send-email-daniel.vetter@ffwll.ch> Cc: Daniel Vetter , Paulo Zanoni , David Weinehall Subject: [Intel-gfx] [PATCH i-g-t 05/11] lib: update docs for igt_pm X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP - Move all the pm helpers into igt_pm.c. No idea why that wasn't done in the original commit that created igt_pm.c. - Add missing docs where needed. Cc: David Weinehall Cc: Paulo Zanoni Signed-off-by: Daniel Vetter --- lib/igt_aux.c | 106 ----------------------------------------------- lib/igt_aux.h | 11 ----- lib/igt_pm.c | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++++----- lib/igt_pm.h | 22 ++++++++++ 4 files changed, 140 insertions(+), 128 deletions(-) diff --git a/lib/igt_aux.c b/lib/igt_aux.c index 1cb939849dd4..5eaf35ec2fb2 100644 --- a/lib/igt_aux.c +++ b/lib/igt_aux.c @@ -62,7 +62,6 @@ #include "intel_reg.h" #include "ioctl_wrappers.h" #include "igt_kms.h" -#include "igt_pm.h" #include "igt_stats.h" /** @@ -791,111 +790,6 @@ void igt_debug_manual_check(const char *var, const char *expected) igt_assert(key != 'n' && key != 'N'); } -#define POWER_DIR "/sys/devices/pci0000:00/0000:00:02.0/power" -/* We just leak this on exit ... */ -int pm_status_fd = -1; - -/** - * igt_setup_runtime_pm: - * - * Sets up the runtime PM helper functions and enables runtime PM. To speed up - * tests the autosuspend delay is set to 0. - * - * Returns: - * True if runtime pm is available, false otherwise. - */ -bool igt_setup_runtime_pm(void) -{ - int fd; - ssize_t size; - char buf[6]; - - if (pm_status_fd >= 0) - return true; - - igt_pm_enable_audio_runtime_pm(); - - /* 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); - 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. */ - size = write(fd, "0\n", 2); - - close(fd); - - if (size != 2) - return false; - - /* 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"); - - size = write(fd, "auto\n", 5); - igt_assert(size == 5); - - lseek(fd, 0, SEEK_SET); - size = read(fd, buf, ARRAY_SIZE(buf)); - igt_assert(size == 5); - igt_assert(strncmp(buf, "auto\n", 5) == 0); - - close(fd); - - pm_status_fd = open(POWER_DIR "/runtime_status", O_RDONLY); - igt_assert_f(pm_status_fd >= 0, - "Can't open " POWER_DIR "/runtime_status\n"); - - return true; -} - -/** - * igt_get_runtime_pm_status: - * - * Returns: The current runtime PM status. - */ -enum igt_runtime_pm_status igt_get_runtime_pm_status(void) -{ - ssize_t n_read; - char buf[32]; - - lseek(pm_status_fd, 0, SEEK_SET); - n_read = read(pm_status_fd, buf, ARRAY_SIZE(buf)); - igt_assert(n_read >= 0); - buf[n_read] = '\0'; - - if (strncmp(buf, "suspended\n", n_read) == 0) - return IGT_RUNTIME_PM_STATUS_SUSPENDED; - else if (strncmp(buf, "active\n", n_read) == 0) - return IGT_RUNTIME_PM_STATUS_ACTIVE; - else if (strncmp(buf, "suspending\n", n_read) == 0) - return IGT_RUNTIME_PM_STATUS_SUSPENDING; - else if (strncmp(buf, "resuming\n", n_read) == 0) - return IGT_RUNTIME_PM_STATUS_RESUMING; - - igt_assert_f(false, "Unknown status %s\n", buf); - return IGT_RUNTIME_PM_STATUS_UNKNOWN; -} - -/** - * igt_wait_for_pm_status: - * @status: desired runtime PM status - * - * Waits until for the driver to switch to into the desired runtime PM status, - * with a 10 second timeout. - * - * Returns: - * True if the desired runtime PM status was attained, false if the operation - * timed out. - */ -bool igt_wait_for_pm_status(enum igt_runtime_pm_status status) -{ - return igt_wait(igt_get_runtime_pm_status() == status, 10000, 100); -} - /* Functions with prefix kmstest_ independent of cairo library are pulled out * from file igt_kms.c since this file is skipped in lib/Android.mk when flag * ANDROID_HAS_CAIRO is 0. This ensures the usability of these functions even diff --git a/lib/igt_aux.h b/lib/igt_aux.h index be0d2d69144e..5627cb0449c6 100644 --- a/lib/igt_aux.h +++ b/lib/igt_aux.h @@ -111,17 +111,6 @@ void igt_drop_root(void); void igt_debug_wait_for_keypress(const char *var); void igt_debug_manual_check(const char *var, const char *expected); -enum igt_runtime_pm_status { - IGT_RUNTIME_PM_STATUS_ACTIVE, - IGT_RUNTIME_PM_STATUS_SUSPENDED, - IGT_RUNTIME_PM_STATUS_SUSPENDING, - IGT_RUNTIME_PM_STATUS_RESUMING, - IGT_RUNTIME_PM_STATUS_UNKNOWN, -}; -bool igt_setup_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); - /* sysinfo cross-arch wrappers from intel_os.c */ /* These are separate to allow easier testing when porting, see the comment at diff --git a/lib/igt_pm.c b/lib/igt_pm.c index b1b5503c4016..5bf5b2e23cdc 100644 --- a/lib/igt_pm.c +++ b/lib/igt_pm.c @@ -36,6 +36,19 @@ #include "drmtest.h" #include "igt_pm.h" +#include "igt_aux.h" + +/** + * SECTION:igt_pm + * @short_description: Power Management related helpers + * @title: Power Management + * @include: igt.h + * + * This library provides various helpers to enable power management for, + * and in some cases subsequently allow restoring the old behaviour of, + * various external components that by default are set up in a way + * that interferes with the testing of our power management functionality. + */ enum { POLICY_UNKNOWN = -1, @@ -51,17 +64,6 @@ enum { #define MAX_POLICY_STRLEN strlen(MAX_PERFORMANCE_STR) /** - * SECTION:igt_pm - * @short_description: Power Management related helpers - * @title: Power Management - * @include: igt.h - * - * This library provides various helpers to enable power management for, - * and in some cases subsequently allow restoring the old behaviour of, - * various external components that by default are set up in a way - * that interferes with the testing of our power management functionality. - */ -/** * igt_pm_enable_audio_runtime_pm: * * We know that if we don't enable audio runtime PM, snd_hda_intel will never @@ -182,6 +184,7 @@ int8_t *igt_pm_enable_sata_link_power_management(void) * we might restore the settings to the wrong hosts. */ void igt_pm_restore_sata_link_power_management(int8_t *pm_data) + { int fd, i; char *file_name; @@ -231,3 +234,107 @@ void igt_pm_restore_sata_link_power_management(int8_t *pm_data) } free(file_name); } +#define POWER_DIR "/sys/devices/pci0000:00/0000:00:02.0/power" +/* We just leak this on exit ... */ +int pm_status_fd = -1; + +/** + * igt_setup_runtime_pm: + * + * Sets up the runtime PM helper functions and enables runtime PM. To speed up + * tests the autosuspend delay is set to 0. + * + * Returns: + * True if runtime pm is available, false otherwise. + */ +bool igt_setup_runtime_pm(void) +{ + int fd; + ssize_t size; + char buf[6]; + + if (pm_status_fd >= 0) + return true; + + igt_pm_enable_audio_runtime_pm(); + + /* 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); + 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. */ + size = write(fd, "0\n", 2); + + close(fd); + + if (size != 2) + return false; + + /* 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"); + + size = write(fd, "auto\n", 5); + igt_assert(size == 5); + + lseek(fd, 0, SEEK_SET); + size = read(fd, buf, ARRAY_SIZE(buf)); + igt_assert(size == 5); + igt_assert(strncmp(buf, "auto\n", 5) == 0); + + close(fd); + + pm_status_fd = open(POWER_DIR "/runtime_status", O_RDONLY); + igt_assert_f(pm_status_fd >= 0, + "Can't open " POWER_DIR "/runtime_status\n"); + + return true; +} + +/** + * igt_get_runtime_pm_status: + * + * Returns: The current runtime PM status. + */ +enum igt_runtime_pm_status igt_get_runtime_pm_status(void) +{ + ssize_t n_read; + char buf[32]; + + lseek(pm_status_fd, 0, SEEK_SET); + n_read = read(pm_status_fd, buf, ARRAY_SIZE(buf)); + igt_assert(n_read >= 0); + buf[n_read] = '\0'; + + if (strncmp(buf, "suspended\n", n_read) == 0) + return IGT_RUNTIME_PM_STATUS_SUSPENDED; + else if (strncmp(buf, "active\n", n_read) == 0) + return IGT_RUNTIME_PM_STATUS_ACTIVE; + else if (strncmp(buf, "suspending\n", n_read) == 0) + return IGT_RUNTIME_PM_STATUS_SUSPENDING; + else if (strncmp(buf, "resuming\n", n_read) == 0) + return IGT_RUNTIME_PM_STATUS_RESUMING; + + igt_assert_f(false, "Unknown status %s\n", buf); + return IGT_RUNTIME_PM_STATUS_UNKNOWN; +} + +/** + * igt_wait_for_pm_status: + * @status: desired runtime PM status + * + * Waits until for the driver to switch to into the desired runtime PM status, + * with a 10 second timeout. + * + * Returns: + * True if the desired runtime PM status was attained, false if the operation + * timed out. + */ +bool igt_wait_for_pm_status(enum igt_runtime_pm_status status) +{ + return igt_wait(igt_get_runtime_pm_status() == status, 10000, 100); +} diff --git a/lib/igt_pm.h b/lib/igt_pm.h index c14ff1f7a0ef..eced39f8801a 100644 --- a/lib/igt_pm.h +++ b/lib/igt_pm.h @@ -28,4 +28,26 @@ void igt_pm_enable_audio_runtime_pm(void); int8_t *igt_pm_enable_sata_link_power_management(void); void igt_pm_restore_sata_link_power_management(int8_t *pm_data); +/** + * igt_runtime_pm_status: + * @IGT_RUNTIME_PM_STATUS_ACTIVE: device is active + * @IGT_RUNTIME_PM_STATUS_SUSPENDED: device is suspended + * @IGT_RUNTIME_PM_STATUS_SUSPENDING: device is in the process of suspending + * @IGT_RUNTIME_PM_STATUS_RESUMING: device is in the process of resuming + * @IGT_RUNTIME_PM_STATUS_UNKNOWN: unknown runtime PM status + * + * Symbolic values for runtime PM device status. + */ +enum igt_runtime_pm_status { + IGT_RUNTIME_PM_STATUS_ACTIVE, + IGT_RUNTIME_PM_STATUS_SUSPENDED, + IGT_RUNTIME_PM_STATUS_SUSPENDING, + IGT_RUNTIME_PM_STATUS_RESUMING, + IGT_RUNTIME_PM_STATUS_UNKNOWN, +}; + +bool igt_setup_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); + #endif /* IGT_PM_H */