From: Daniel Vetter <daniel@ffwll.ch>
To: Paulo Zanoni <przanoni@gmail.com>
Cc: intel-gfx@lists.freedesktop.org, Paulo Zanoni <paulo.r.zanoni@intel.com>
Subject: Re: [PATCH igt 1/4] lib: add igt_wait()
Date: Mon, 8 Dec 2014 17:40:00 +0100 [thread overview]
Message-ID: <20141208164000.GD27182@phenom.ffwll.local> (raw)
In-Reply-To: <1418055164-1536-1-git-send-email-przanoni@gmail.com>
On Mon, Dec 08, 2014 at 02:12:41PM -0200, Paulo Zanoni wrote:
> From: Paulo Zanoni <paulo.r.zanoni@intel.com>
>
> 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 <paulo.r.zanoni@intel.com>
A library unit test in lib/tests would be awesome for igt_wait. You can
run them with $ make check. If you're a bit bored, that is ;-)
-Daniel
> ---
> 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 <intel_bufmgr.h>
> #include <stdbool.h>
> +#include <sys/time.h>
>
> 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)
> --
> 2.1.3
>
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
prev parent reply other threads:[~2014-12-08 16:39 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-08 16:09 [PATCH 00/11] FBC improvements + frontbuffer tracking conversion Paulo Zanoni
2014-12-08 16:09 ` [PATCH 01/11] drm/i915: Move FBC stuff to intel_fbc.c Paulo Zanoni
2014-12-08 16:09 ` [PATCH 02/11] drm/i915: Introduce FBC DocBook Paulo Zanoni
2014-12-08 16:49 ` Daniel Vetter
2014-12-08 14:46 ` [PATCH] " Rodrigo Vivi
2014-12-08 21:48 ` [PATCH 02/11] " Rodrigo Vivi
2014-12-09 9:52 ` Daniel Vetter
2014-12-08 16:09 ` [PATCH 03/11] drm/i915: don't try to find crtcs for FBC if it's disabled Paulo Zanoni
2014-12-13 0:53 ` Rodrigo Vivi
2014-12-15 8:35 ` Daniel Vetter
2014-12-08 16:09 ` [PATCH 04/11] drm/i915: don't keep reassigning FBC_UNSUPPORTED Paulo Zanoni
2014-12-13 0:55 ` Rodrigo Vivi
2014-12-15 8:37 ` Daniel Vetter
2014-12-08 16:09 ` [PATCH 05/11] drm/i915: change dev_priv->fbc.plane to dev_priv->fbc.crtc Paulo Zanoni
2014-12-13 0:58 ` Rodrigo Vivi
2014-12-08 16:09 ` [PATCH 06/11] drm/i915: pass which operation triggered the frontbuffer tracking Paulo Zanoni
2014-12-08 16:53 ` Daniel Vetter
2014-12-13 1:05 ` Rodrigo Vivi
2014-12-15 8:43 ` Daniel Vetter
2014-12-15 13:58 ` Paulo Zanoni
2014-12-08 16:09 ` [PATCH 07/11] drm/i915: also do frontbuffer tracking on pwrites Paulo Zanoni
2014-12-08 16:55 ` Daniel Vetter
2014-12-13 1:10 ` Rodrigo Vivi
2014-12-15 8:39 ` Daniel Vetter
2014-12-08 16:09 ` [PATCH 08/11] drm/i915: add fronbuffer tracking to FBC Paulo Zanoni
2014-12-13 1:12 ` [PATCH 6/9] drm/i915: add frontbuffer " Rodrigo Vivi
2014-12-13 1:16 ` [PATCH 08/11] drm/i915: add fronbuffer " Rodrigo Vivi
2014-12-15 14:00 ` [PATCH 8/11] drm/i915: add frontbuffer " Paulo Zanoni
2014-12-08 16:09 ` [PATCH 09/11] drm/i915: extract intel_fbc_find_crtc() Paulo Zanoni
2014-12-13 1:20 ` Rodrigo Vivi
2014-12-08 16:09 ` [PATCH 10/11] drm/i915: HSW+ FBC is tied to pipe A Paulo Zanoni
2014-12-13 1:23 ` Rodrigo Vivi
2014-12-15 8:41 ` Daniel Vetter
2014-12-08 16:09 ` [PATCH 11/11] drm/i915: gen5+ can have FBC with multiple pipes Paulo Zanoni
2014-12-09 16:08 ` shuang.he
2014-12-13 1:25 ` Rodrigo Vivi
2014-12-08 16:12 ` [PATCH igt 1/4] lib: add igt_wait() Paulo Zanoni
2014-12-08 16:12 ` [PATCH igt 2/4] tests/kms_fb_crc: call gem_sync() instead of gem_bo_busy() Paulo Zanoni
2014-12-08 16:12 ` [PATCH igt 3/4] tests/kms_fbc_crc: add wait_for_fbc_enabled() Paulo Zanoni
2014-12-08 16:12 ` [PATCH igt 4/4] tests/kms_fbc_crc: also gem_sync() on exec_nop() Paulo Zanoni
2014-12-08 16:40 ` Daniel Vetter [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20141208164000.GD27182@phenom.ffwll.local \
--to=daniel@ffwll.ch \
--cc=intel-gfx@lists.freedesktop.org \
--cc=paulo.r.zanoni@intel.com \
--cc=przanoni@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox