static int active_poll_sensors; /* Number of enabled poll-mode sensors */
-int64_t ts_delta; /* delta between SystemClock.getNanos and our timestamp */
-
static int64_t sys_to_rt_delta; /* delta between system and realtime clocks */
/* We use pthread condition variables to get worker threads out of sleep */
pthread_mutex_lock(&thread_release_mutex[s]);
/* Pinpoint the moment we start sampling */
- timestamp = get_timestamp_monotonic();
+ timestamp = get_timestamp_boot();
/* Check and honor termination requests */
while (sensor_info[s].thread_data_fd[1] != -1) {
- start = get_timestamp();
+ start = get_timestamp_boot();
/* Read values through sysfs */
for (c=0; c<num_fields; c++) {
data.data[c] = acquire_immediate_value(s, c);
if (sensor_info[s].thread_data_fd[1] == -1)
goto exit;
}
- stop = get_timestamp();
+ stop = get_timestamp_boot();
data.timestamp = start/2 + stop/2;
/* If the sample looks good */
/* Prepare the report timestamp field for the first event, see set_report_ts method */
sensor_info[s].report_ts = 0;
- ts_delta = load_timestamp_sys_clock() - get_timestamp_monotonic();
- sys_to_rt_delta = get_timestamp_realtime() - load_timestamp_sys_clock();
+
+ sys_to_rt_delta = get_timestamp_realtime() - get_timestamp_boot();
/* If we want to activate gyro calibrated and gyro uncalibrated is activated
for (s=0; s<MAX_SENSORS; s++)
if (sensor_info[s].dev_num == dev_num &&
sensor_info[s].enabled)
- set_report_ts(s, get_timestamp());
+ set_report_ts(s, get_timestamp_boot());
return 0;
}
for (s=0; s<MAX_SENSORS; s++)
if (sensor_info[s].dev_num == dev_num &&
sensor_info[s].enabled)
- set_report_ts(s, get_timestamp());
+ set_report_ts(s, get_timestamp_boot());
return 0;
}
period = (int64_t) (1000000000.0/ sensor_info[s].sampling_rate);
- current_ts = get_timestamp();
+ current_ts = get_timestamp_boot();
target_ts = sensor_info[s].report_ts + period;
if (target_ts <= current_ts) {
if (target_ts == INT64_MAX)
return -1; /* Infinite wait */
- ms_to_wait = (target_ts - get_timestamp()) / 1000000;
+ ms_to_wait = (target_ts - get_timestamp_boot()) / 1000000;
/* If the target timestamp is already behind us, don't wait */
if (ms_to_wait < 1)
}
-int64_t load_timestamp_monotonic(struct timespec *ts)
-{
- clock_gettime(CLOCK_MONOTONIC, ts);
-
- return (1000000000LL * ts->tv_sec + ts->tv_nsec);
-}
-
-
-int64_t load_timestamp_sys_clock(void)
-{
- static int s_fd = -1;
- int fd, result = 0;
- struct timespec ts;
-
- if (s_fd == -1) {
- fd = open("/dev/alarm", O_RDONLY);
- if (android_atomic_cmpxchg(-1, fd, &s_fd)) {
- close(fd);
- }
- }
-
- result = ioctl(s_fd,
- ANDROID_ALARM_GET_TIME(ANDROID_ALARM_ELAPSED_REALTIME), &ts);
-
- if (result != 0) {
- /** /dev/alarm doesn't exist, fallback to CLOCK_BOOTTIME */
- result = clock_gettime(CLOCK_BOOTTIME, &ts);
- }
-
- return 1000000000LL * ts.tv_sec + ts.tv_nsec;
-}
-
-
int64_t get_timestamp_realtime (void)
{
struct timespec ts = {0};
-
clock_gettime(CLOCK_REALTIME, &ts);
return 1000000000LL * ts.tv_sec + ts.tv_nsec;
}
-int64_t get_timestamp_monotonic(void)
+int64_t get_timestamp_boot (void)
{
struct timespec ts = {0};
+ clock_gettime(CLOCK_BOOTTIME, &ts);
- return load_timestamp_monotonic(&ts);
-}
-
-
-int64_t get_timestamp(void)
-{
- return (get_timestamp_monotonic() + ts_delta);
+ return 1000000000LL * ts.tv_sec + ts.tv_nsec;
}
-void set_timestamp(struct timespec *out, int64_t target_ns)
+void set_timestamp (struct timespec *out, int64_t target_ns)
{
out->tv_sec = target_ns / 1000000000LL;
out->tv_nsec = target_ns % 1000000000LL;
int decode_type_spec(const char type_buf[MAX_TYPE_SPEC_LEN],
struct datum_info_t *type_info);
-int64_t load_timestamp_monotonic (struct timespec *ts);
-int64_t get_timestamp_monotonic (void);
void set_timestamp (struct timespec *out, int64_t target_ns);
-int64_t get_timestamp(void);
-int64_t load_timestamp_sys_clock(void);
-
-int64_t get_timestamp_realtime (void);
+int64_t get_timestamp_boot (void);
+int64_t get_timestamp_realtime (void);
#endif