From b11f9f7e162759cf5ae0f033e125e9158520030d Mon Sep 17 00:00:00 2001 From: Rob Barnes Date: Fri, 24 Jun 2022 10:28:31 -0600 Subject: timer: Switch mono_time to uint64_t A 32-bit long storing microseconds will rollover every ~1.19 hours. This can cause stopwatch to misbehave, causing unexpected failures. If the current field in stopwatch is near 2^31, the expires field may rollover when initialized. If this occurs, stopwatch_expired() will instantly return true. If current and expires fields are near 2^31, the current field could rollover before being checked. In this case, stopwatch_expired() will not return true for over an hour. Also stopwatch_duration_usecs() will return a large negative duration. This issue has only been observed in SMM since it never takes more than 35 minutes to boot. Switching to uint64_t mitigates this issue since it will not rollover for over 500K+ years. The raw TSC would rollover sooner than this, ~200 years, depending on the tick frequency. BUG=b:237082996 BRANCH=All TEST=Boot Nipperkin Change-Id: I4c24894718f093ac7cd1e434410bc64e6436869a Signed-off-by: Rob Barnes Reviewed-on: https://review.coreboot.org/c/coreboot/+/65403 Reviewed-by: Paul Fagerburg Tested-by: build bot (Jenkins) Reviewed-by: Tim Van Patten Reviewed-by: Martin L Roth --- src/include/timer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/include/timer.h b/src/include/timer.h index 9b7a05e5fd..0e7104b70e 100644 --- a/src/include/timer.h +++ b/src/include/timer.h @@ -17,7 +17,7 @@ * outside of the core timer code is not supported. */ struct mono_time { - long microseconds; + uint64_t microseconds; }; /* A timeout_callback structure is used for the book keeping for scheduling -- cgit v1.2.3