From 1c5cdad09efa7d6bd196ad852dbeb5f740ac66e3 Mon Sep 17 00:00:00 2001 From: Vadim Bendebury Date: Thu, 10 Jul 2014 12:49:46 -0700 Subject: 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 Original-Change-Id: Iffb323db10e74b0ce3b4d59a56983bfee12e6805 Original-Signed-off-by: Vadim Bendebury Original-Reviewed-on: https://chromium-review.googlesource.com/207358 Original-Reviewed-by: David Hendricks (cherry picked from commit e1abf87d438de1a04714482d5b610671e8cc0663) Signed-off-by: Marc Jones Change-Id: Ia892726187ab040dd235f493c92856c15951cc06 Reviewed-on: http://review.coreboot.org/8128 Reviewed-by: Stefan Reinauer Reviewed-by: Paul Menzel Tested-by: build bot (Jenkins) --- payloads/libpayload/libc/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'payloads/libpayload') 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; } -- cgit v1.2.3