summaryrefslogtreecommitdiff
path: root/tests/pm_rpm.c
diff options
context:
space:
mode:
authorPaulo Zanoni <paulo.r.zanoni@intel.com>2014-12-03 16:12:49 -0200
committerPaulo Zanoni <paulo.r.zanoni@intel.com>2015-05-05 17:27:49 -0300
commit9bb04d3aa6a2b1b86e091967e312a19ce337df4d (patch)
tree4bc4ddc0b7f75b5c8156599f36dc08991b223811 /tests/pm_rpm.c
parenta734ac2058fd0cce842a4290335c0697d89b2d63 (diff)
lib: add igt_wait()
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. v2: Check COND again before returning in case we hit the timeout. Signed-off-by: Paulo Zanoni <paulo.r.zanoni@intel.com>
Diffstat (limited to 'tests/pm_rpm.c')
-rw-r--r--tests/pm_rpm.c28
1 files changed, 5 insertions, 23 deletions
diff --git a/tests/pm_rpm.c b/tests/pm_rpm.c
index 91df93a3..1a93fe8e 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)