diff options
author | Greg Hackmann <ghackmann@google.com> | 2013-12-16 17:04:32 -0800 |
---|---|---|
committer | Greg Hackmann <ghackmann@google.com> | 2013-12-17 14:45:39 -0800 |
commit | 64289760a2df9409d8f4fa5becb4a49f0acb20a5 (patch) | |
tree | b1cf5104c9a1f658bcca05209156702b75b4a888 /libutils | |
parent | a585e662e0141d8b3445749ef83b8d9b138d7905 (diff) | |
download | core-64289760a2df9409d8f4fa5becb4a49f0acb20a5.tar.gz core-64289760a2df9409d8f4fa5becb4a49f0acb20a5.tar.bz2 core-64289760a2df9409d8f4fa5becb4a49f0acb20a5.zip |
SystemClock: use clock_gettime() on devices without /dev/alarm
On devices with an up-to-date kernel, the back-in-time bug affecting
clock_gettime() has been fixed and it can safely be used as an
alternative to the ANDROID_ALARM_GET_TIME ioctl. To ensure consistent
behavior on existing devices, make clock_gettime() a fallback for when
the alarm driver isn't available.
Change-Id: I384af5e7ec9e73e0bad4b6b0f987a8ea4583cba6
Signed-off-by: Greg Hackmann <ghackmann@google.com>
Diffstat (limited to 'libutils')
-rw-r--r-- | libutils/SystemClock.cpp | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/libutils/SystemClock.cpp b/libutils/SystemClock.cpp index ac8da8871..413250f48 100644 --- a/libutils/SystemClock.cpp +++ b/libutils/SystemClock.cpp @@ -119,22 +119,6 @@ int64_t elapsedRealtimeNano() static volatile int prevMethod; #endif -#if 0 - /* - * b/7100774 - * clock_gettime appears to have clock skews and can sometimes return - * backwards values. Disable its use until we find out what's wrong. - */ - result = clock_gettime(CLOCK_BOOTTIME, &ts); - if (result == 0) { - timestamp = seconds_to_nanoseconds(ts.tv_sec) + ts.tv_nsec; - checkTimeStamps(timestamp, &prevTimestamp, &prevMethod, - METHOD_CLOCK_GETTIME); - return timestamp; - } -#endif - - // CLOCK_BOOTTIME doesn't exist, fallback to /dev/alarm static int s_fd = -1; if (s_fd == -1) { @@ -153,6 +137,15 @@ int64_t elapsedRealtimeNano() return timestamp; } + // /dev/alarm doesn't exist, fallback to CLOCK_BOOTTIME + result = clock_gettime(CLOCK_BOOTTIME, &ts); + if (result == 0) { + timestamp = seconds_to_nanoseconds(ts.tv_sec) + ts.tv_nsec; + checkTimeStamps(timestamp, &prevTimestamp, &prevMethod, + METHOD_CLOCK_GETTIME); + return timestamp; + } + // XXX: there was an error, probably because the driver didn't // exist ... this should return // a real error, like an exception! |