summaryrefslogtreecommitdiff
path: root/core/host/timer.c
diff options
context:
space:
mode:
authorVic Yang <victoryang@chromium.org>2013-05-11 22:45:22 +0800
committerChromeBot <chrome-bot@google.com>2013-05-14 00:31:40 -0700
commit3615ac4c0b6141f9d5a3fb008d09f6792155815c (patch)
tree0de06d0ebfd7b83db158869677a0b878dd1aa261 /core/host/timer.c
parent8ab12847b55b34e07e35eba11b74f1ef1ce25a78 (diff)
downloadchrome-ec-3615ac4c0b6141f9d5a3fb008d09f6792155815c.tar.gz
Scale timer for emulator
The timer is the only source of timing for the emulator. This means we can make it go faster without breaking the tests. This CL sets the default scale to be 3x faster than normal time. BUG=chrome-os-partner:19235 TEST=Pass all tests. Check the tests run faster. BRANCH=None Change-Id: Ib9035884b34f41c4e9aa2206284b5f1ec8fc0d1f Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/50956
Diffstat (limited to 'core/host/timer.c')
-rw-r--r--core/host/timer.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/core/host/timer.c b/core/host/timer.c
index 8de12a7f3c..8d9f3f4be3 100644
--- a/core/host/timer.c
+++ b/core/host/timer.c
@@ -12,6 +12,15 @@
#include "task.h"
#include "timer.h"
+/*
+ * Scale the timer to be 3 times faster for emulator.
+ * This can be adjusted for individual tests in test/build.mk by
+ * specifying <test_name>-scale=<new scale>.
+ */
+#ifndef TEST_TIME_SCALE
+#define TEST_TIME_SCALE 3
+#endif
+
static timestamp_t boot_time;
void usleep(unsigned us)
@@ -24,7 +33,8 @@ timestamp_t _get_time(void)
struct timespec ts;
timestamp_t ret;
clock_gettime(CLOCK_MONOTONIC, &ts);
- ret.val = 1000000 * (uint64_t)ts.tv_sec + ts.tv_nsec / 1000;
+ ret.val = (1000000000 * (uint64_t)ts.tv_sec + ts.tv_nsec) *
+ TEST_TIME_SCALE / 1000;
return ret;
}