From e1abf87d438de1a04714482d5b610671e8cc0663 Mon Sep 17 00:00:00 2001 From: Vadim Bendebury Date: Thu, 10 Jul 2014 12:49:46 -0700 Subject: [PATCH] libpayload: improve us timer accuracy In cases where timer clock frequency is not an integer number of megahertz, the calculations in timer_us() lack accuracy. This patch modifies calculations to reduce the error. The maximum interval this calculation would support decreases, but it still is in excess of 1844674 seconds for a timer clocked by 10 MHz, which is more than enough. BUG=none TEST=manual . verified timer accuracy using a depthcharge CLI command Change-Id: Iffb323db10e74b0ce3b4d59a56983bfee12e6805 Signed-off-by: Vadim Bendebury Reviewed-on: https://chromium-review.googlesource.com/207358 Reviewed-by: David Hendricks --- payloads/libpayload/libc/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/payloads/libpayload/libc/time.c b/payloads/libpayload/libc/time.c index 0d8163495b..8d07c4f172 100644 --- a/payloads/libpayload/libc/time.c +++ b/payloads/libpayload/libc/time.c @@ -204,5 +204,5 @@ u64 timer_us(u64 base) } } - return timer_raw_value() / (hz / 1000000) - base; + return (1000000 * timer_raw_value()) / hz - base; }