From patchwork Mon Dec 8 16:12:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paulo Zanoni X-Patchwork-Id: 5457461 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 661F4BEEA8 for ; Mon, 8 Dec 2014 16:13:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 691982015A for ; Mon, 8 Dec 2014 16:13:30 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 743F120155 for ; Mon, 8 Dec 2014 16:13:29 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CAAFB6E7BB; Mon, 8 Dec 2014 08:13:28 -0800 (PST) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-qg0-f47.google.com (mail-qg0-f47.google.com [209.85.192.47]) by gabe.freedesktop.org (Postfix) with ESMTP id 75CF46E7BB for ; Mon, 8 Dec 2014 08:13:27 -0800 (PST) Received: by mail-qg0-f47.google.com with SMTP id z60so3700540qgd.34 for ; Mon, 08 Dec 2014 08:13:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=70SwGJRT2U6LhpTNPiPILKzGkGsFDb4Pbsjn4A8dYPM=; b=mmjuC8XXUjjioxQdVLHjzjd0UYfASKi2oAbgVqqH3V9AF4ZrJ11H7kW4weecCfGLHP y2OXSiKsjYTsQtNyNQmIWIsZjxSrI/rDYVjWfbifVopSo8xol12+L+WTn47N7mYlddZ8 QE8D41yzxu9//GC0Q7Dv4fjLmva+1kJvgim2Awe2urX9vjEpxPVsZ1YjhHFw7sKP0cW3 PFJ7mdOXmbx+YwtYLrl9U7NMwJezCocGhod2+oSuiHM77MxTlOxMWphNlyWAtAYXQim9 Xau8ZAUU3dsW/4Fw+Tm9dRvRWloKlSGUobcP0SaYXY19cOXnQrd7buDH5fIsg4KyEjsA 3JWQ== X-Received: by 10.140.22.83 with SMTP id 77mr51657402qgm.19.1418055205069; Mon, 08 Dec 2014 08:13:25 -0800 (PST) Received: from localhost.localdomain ([187.95.104.42]) by mx.google.com with ESMTPSA id l10sm30480245qas.25.2014.12.08.08.13.23 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 08 Dec 2014 08:13:24 -0800 (PST) From: Paulo Zanoni To: intel-gfx@lists.freedesktop.org Date: Mon, 8 Dec 2014 14:12:41 -0200 Message-Id: <1418055164-1536-1-git-send-email-przanoni@gmail.com> X-Mailer: git-send-email 2.1.3 In-Reply-To: <1418054960-1403-1-git-send-email-przanoni@gmail.com> References: <1418054960-1403-1-git-send-email-przanoni@gmail.com> Cc: Paulo Zanoni Subject: [Intel-gfx] [PATCH igt 1/4] lib: add igt_wait() 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-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Paulo Zanoni Just a little helper for code that needs to wait for a certain condition to happen. It has the nice advantage that it can survive the signal helper. Despite the callers added in this patch, there is another that will go in a separate patch, and another in a new IGT test file that I plan to push later. Signed-off-by: Paulo Zanoni --- lib/igt_aux.c | 18 +----------------- lib/igt_aux.h | 40 ++++++++++++++++++++++++++++++++++++++++ tests/pm_rpm.c | 28 +++++----------------------- 3 files changed, 46 insertions(+), 40 deletions(-) diff --git a/lib/igt_aux.c b/lib/igt_aux.c index 3051d84..180141e 100644 --- a/lib/igt_aux.c +++ b/lib/igt_aux.c @@ -518,29 +518,13 @@ enum igt_runtime_pm_status igt_get_runtime_pm_status(void) * Waits until for the driver to switch to into the desired runtime PM status, * with a 10 second timeout. * - * Some subtests call this function while the signal helper is active, so we - * can't assume each usleep() call will sleep for 100ms. - * * 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) { - struct timeval start, end, diff; - - igt_assert(gettimeofday(&start, NULL) == 0); - do { - if (igt_get_runtime_pm_status() == status) - return true; - - usleep(100 * 1000); - - igt_assert(gettimeofday(&end, NULL) == 0); - timersub(&end, &start, &diff); - } while (diff.tv_sec < 10); - - return false; + return igt_wait(igt_get_runtime_pm_status() == status, 10000, 100); } /* Functions with prefix kmstest_ independent of cairo library are pulled out diff --git a/lib/igt_aux.h b/lib/igt_aux.h index 6c83c53..48c495b 100644 --- a/lib/igt_aux.h +++ b/lib/igt_aux.h @@ -30,6 +30,7 @@ #include #include +#include extern drm_intel_bo **trash_bos; extern int num_trash_bos; @@ -90,4 +91,43 @@ void intel_require_memory(uint32_t count, uint32_t size, unsigned mode); #define min(a, b) ((a) < (b) ? (a) : (b)) #define max(a, b) ((a) > (b) ? (a) : (b)) +/** + * igt_wait: + * @COND: condition to wait + * @timeout_ms: timeout in milliseconds + * @interval_ms: amount of time we try to sleep between COND checks + * + * Waits until COND evaluates to true or the timeout passes. + * + * It is safe to call this macro if the signal helper is active. The only + * problem is that the usleep() calls will return early, making us evaluate COND + * too often, possibly eating valuable CPU cycles. + * + * Returns: + * True of COND evaluated to true, false otherwise. + */ +#define igt_wait(COND, timeout_ms, interval_ms) ({ \ + struct timeval start_, end_, diff_; \ + int elapsed_ms_; \ + bool ret_ = false; \ + \ + igt_assert(gettimeofday(&start_, NULL) == 0); \ + do { \ + if (COND) { \ + ret_ = true; \ + break; \ + } \ + \ + usleep(interval_ms * 1000); \ + \ + igt_assert(gettimeofday(&end_, NULL) == 0); \ + timersub(&end_, &start_, &diff_); \ + \ + elapsed_ms_ = diff_.tv_sec * 1000 + \ + diff_.tv_usec / 1000; \ + } while (elapsed_ms_ < timeout_ms); \ + \ + ret_; \ +}) + #endif /* IGT_AUX_H */ diff --git a/tests/pm_rpm.c b/tests/pm_rpm.c index c120d75..b7f9635 100644 --- a/tests/pm_rpm.c +++ b/tests/pm_rpm.c @@ -153,24 +153,16 @@ static uint64_t get_residency(uint32_t type) static bool pc8_plus_residency_changed(unsigned int timeout_sec) { - unsigned int i; uint64_t res_pc8, res_pc9, res_pc10; - int to_sleep = 100 * 1000; res_pc8 = get_residency(MSR_PC8_RES); res_pc9 = get_residency(MSR_PC9_RES); res_pc10 = get_residency(MSR_PC10_RES); - for (i = 0; i < timeout_sec * 1000 * 1000; i += to_sleep) { - if (res_pc8 != get_residency(MSR_PC8_RES) || - res_pc9 != get_residency(MSR_PC9_RES) || - res_pc10 != get_residency(MSR_PC10_RES)) { - return true; - } - usleep(to_sleep); - } - - return false; + return igt_wait(res_pc8 != get_residency(MSR_PC8_RES) || + res_pc9 != get_residency(MSR_PC9_RES) || + res_pc10 != get_residency(MSR_PC10_RES), + timeout_sec * 1000, 100); } static enum pc8_status get_pc8_status(void) @@ -191,17 +183,7 @@ static enum pc8_status get_pc8_status(void) static bool wait_for_pc8_status(enum pc8_status status) { - int i; - int hundred_ms = 100 * 1000, ten_s = 10 * 1000 * 1000; - - for (i = 0; i < ten_s; i += hundred_ms) { - if (get_pc8_status() == status) - return true; - - usleep(hundred_ms); - } - - return false; + return igt_wait(get_pc8_status() == status, 10000, 100); } static bool wait_for_suspended(void)