diff options
author | Gabe Black <gabeblack@google.com> | 2013-12-06 23:30:10 -0800 |
---|---|---|
committer | Isaac Christensen <isaac.christensen@se-eng.com> | 2014-09-15 19:01:03 +0200 |
commit | 125a6a22f81b3cf11732ce2a0e77652661fa0764 (patch) | |
tree | 6ecf832074b545afe304ae06ad9ff7b66a04f68f /payloads/libpayload/libc/time.c | |
parent | 5f43184349e75415126937c60b0fbb9dc6bd2a35 (diff) | |
download | coreboot-125a6a22f81b3cf11732ce2a0e77652661fa0764.tar.xz |
libpayload: Add a timer_us() function.
This function returns the number of microseconds scaled from the number of raw
timer ticks. It accepts a base parameter which is subtracted from the current
time, which makes it easy to keep track of relative times.
Change-Id: I55f2f9e90c0e12cda430bbe88b044f12b0b563c8
Signed-off-by: Gabe Black <gabeblack@google.com>
Reviewed-on: https://chromium-review.googlesource.com/179600
Reviewed-by: Ronald Minnich <rminnich@chromium.org>
Commit-Queue: Gabe Black <gabeblack@chromium.org>
Tested-by: Gabe Black <gabeblack@chromium.org>
(cherry picked from commit 4dd549e18d170dbf918c5b4b11bbe1f4e99b6695)
Signed-off-by: Isaac Christensen <isaac.christensen@se-eng.com>
Reviewed-on: http://review.coreboot.org/6897
Tested-by: build bot (Jenkins)
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
Diffstat (limited to 'payloads/libpayload/libc/time.c')
-rw-r--r-- | payloads/libpayload/libc/time.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/payloads/libpayload/libc/time.c b/payloads/libpayload/libc/time.c index ec1c85ce8c..0d8163495b 100644 --- a/payloads/libpayload/libc/time.c +++ b/payloads/libpayload/libc/time.c @@ -189,3 +189,20 @@ void delay(unsigned int s) { _delay((uint64_t)s * timer_hz()); } + +u64 timer_us(u64 base) +{ + static u64 hz; + + // Only check timer_hz once. Assume it doesn't change. + if (hz == 0) { + hz = timer_hz(); + if (hz < 1000000) { + printf("Timer frequency %lld is too low, " + "must be at least 1MHz.\n", hz); + halt(); + } + } + + return timer_raw_value() / (hz / 1000000) - base; +} |