mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-03 05:29:29 +00:00
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
72 lines
1.3 KiB
C
72 lines
1.3 KiB
C
/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
/* Timer module */
|
|
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <time.h>
|
|
|
|
#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)
|
|
{
|
|
task_wait_event(us);
|
|
}
|
|
|
|
timestamp_t _get_time(void)
|
|
{
|
|
struct timespec ts;
|
|
timestamp_t ret;
|
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
|
ret.val = (1000000000 * (uint64_t)ts.tv_sec + ts.tv_nsec) *
|
|
TEST_TIME_SCALE / 1000;
|
|
return ret;
|
|
}
|
|
|
|
timestamp_t get_time(void)
|
|
{
|
|
timestamp_t ret = _get_time();
|
|
ret.val -= boot_time.val;
|
|
return ret;
|
|
}
|
|
|
|
void udelay(unsigned us)
|
|
{
|
|
timestamp_t deadline = get_time();
|
|
deadline.val += us;
|
|
while (get_time().val < deadline.val)
|
|
;
|
|
}
|
|
|
|
int timestamp_expired(timestamp_t deadline, const timestamp_t *now)
|
|
{
|
|
timestamp_t now_val;
|
|
|
|
if (!now) {
|
|
now_val = get_time();
|
|
now = &now_val;
|
|
}
|
|
|
|
return ((int64_t)(now->val - deadline.val) >= 0);
|
|
}
|
|
|
|
void timer_init(void)
|
|
{
|
|
boot_time = _get_time();
|
|
}
|