summaryrefslogtreecommitdiffstats
path: root/libutils
diff options
context:
space:
mode:
authorGreg Hackmann <ghackmann@google.com>2016-04-25 10:39:55 -0700
committerGreg Hackmann <ghackmann@google.com>2016-05-02 14:00:02 -0700
commite94c92cd4852698c5ea2cab2e2f5686ec3708f36 (patch)
tree9cfdb364f67f997dd92eb5fadb6ad9f944f15d97 /libutils
parent340079df2621e27bf8e9f999fbe146fd894fdcfd (diff)
downloadcore-e94c92cd4852698c5ea2cab2e2f5686ec3708f36.tar.gz
core-e94c92cd4852698c5ea2cab2e2f5686ec3708f36.tar.bz2
core-e94c92cd4852698c5ea2cab2e2f5686ec3708f36.zip
SystemClock: elapsedRealtimeNano() should use clock_gettime() on Linux
We've removed the Android alarm driver from our supported kernels. clock_gettime(CLOCK_BOOTTIME) has been a viable option since 2.6.39, so there's no need for the legacy code path anymore. We can use this on Linux hosts too, since no one should be building Android on hosts with kernels that old. Bug: 28357356 Change-Id: I0aa164383c95e77c53d2c85883d83f85d4abc7b1 Signed-off-by: Greg Hackmann <ghackmann@google.com>
Diffstat (limited to 'libutils')
-rw-r--r--libutils/SystemClock.cpp37
1 files changed, 9 insertions, 28 deletions
diff --git a/libutils/SystemClock.cpp b/libutils/SystemClock.cpp
index c5ae32778..965e32c0f 100644
--- a/libutils/SystemClock.cpp
+++ b/libutils/SystemClock.cpp
@@ -19,18 +19,13 @@
* System clock functions.
*/
-#if defined(__ANDROID__)
-#include <linux/ioctl.h>
-#include <linux/rtc.h>
-#include <utils/Atomic.h>
-#include <linux/android_alarm.h>
-#endif
-
#include <sys/time.h>
#include <limits.h>
#include <fcntl.h>
#include <string.h>
+#include <errno.h>
+#include <cutils/compiler.h>
#include <utils/SystemClock.h>
#include <utils/Timers.h>
@@ -61,30 +56,16 @@ int64_t elapsedRealtime()
*/
int64_t elapsedRealtimeNano()
{
-#if defined(__ANDROID__)
- static int s_fd = -1;
-
- if (s_fd == -1) {
- int fd = open("/dev/alarm", O_RDONLY);
- if (android_atomic_cmpxchg(-1, fd, &s_fd)) {
- close(fd);
- }
- }
-
+#if defined(__linux__)
struct timespec ts;
- if (ioctl(s_fd, ANDROID_ALARM_GET_TIME(ANDROID_ALARM_ELAPSED_REALTIME), &ts) == 0) {
- return seconds_to_nanoseconds(ts.tv_sec) + ts.tv_nsec;
- }
-
- // /dev/alarm doesn't exist, fallback to CLOCK_BOOTTIME
- if (clock_gettime(CLOCK_BOOTTIME, &ts) == 0) {
- return seconds_to_nanoseconds(ts.tv_sec) + ts.tv_nsec;
+ int err = clock_gettime(CLOCK_BOOTTIME, &ts);
+ if (CC_UNLIKELY(err)) {
+ // This should never happen, but just in case ...
+ ALOGE("clock_gettime(CLOCK_BOOTTIME) failed: %s", strerror(errno));
+ return 0;
}
- // XXX: there was an error, probably because the driver didn't
- // exist ... this should return
- // a real error, like an exception!
- return systemTime(SYSTEM_TIME_MONOTONIC);
+ return seconds_to_nanoseconds(ts.tv_sec) + ts.tv_nsec;
#else
return systemTime(SYSTEM_TIME_MONOTONIC);
#endif