From cc1bf34ba613b05afaf53c5a68634513fcc024f6 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Wed, 7 Feb 2024 16:55:49 -0800 Subject: [PATCH] fastboot: Use clock_gettime(CLOCK_MONOTONIC) in now() If the system time changes during the execution of fastboot we might see some strange output such as: Sending sparse 'super' 4/20 (254972 KB) OKAY [-516.263s] Fix it by changing now() to use clock_gettime(CLOCK_MONOTONIC). I confirmed that all callers of now() are using it for relative time and not time since the epoch. Change-Id: Ic3e9442c2ab21dfb076bfed88915085a183754b0 --- fastboot/util.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fastboot/util.cpp b/fastboot/util.cpp index e03012a05..5966aead6 100644 --- a/fastboot/util.cpp +++ b/fastboot/util.cpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include @@ -43,9 +43,9 @@ using android::base::borrowed_fd; static bool g_verbose = false; double now() { - struct timeval tv; - gettimeofday(&tv, NULL); - return (double)tv.tv_sec + (double)tv.tv_usec / 1000000; + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return (double)ts.tv_sec + (double)ts.tv_nsec / 1000000000; } void die(const char* fmt, ...) {