On 11/01/2017 10:40 AM, Stefan Berger wrote:
When timer_calc_usec() is used with large timeout falues, such as 60s,
obviously a typo ->values.
The problem occurred with the TPM driver where we are given usec values by the hardware and specs and want to call the timer_calc_usec() function. That function works well for small values but fails once the values become larger.
Stefan
the function lacks precision and produces different results than when using timer_calc(time / 1000) for the same timeout. This patch fixes the precision issue by falling back to timer_calc(time / 1000) for usec values over one second.
Signed-off-by: Stefan Berger stefanb@linux.vnet.ibm.com
src/hw/timer.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/src/hw/timer.c b/src/hw/timer.c index 03d22b2..2f0c864 100644 --- a/src/hw/timer.c +++ b/src/hw/timer.c @@ -213,6 +213,8 @@ timer_calc(u32 msecs) u32 timer_calc_usec(u32 usecs) {
- if (usecs > 1000000)
}return timer_calc(usecs / 1000); return timer_read() + DIV_ROUND_UP(GET_GLOBAL(TimerKHz) * usecs, 1000);