diff --git a/system/sensord/sensors_qcom2.cc b/system/sensord/sensors_qcom2.cc index 189da78099..55c8d2a448 100644 --- a/system/sensord/sensors_qcom2.cc +++ b/system/sensord/sensors_qcom2.cc @@ -39,6 +39,7 @@ void interrupt_loop(std::vector> sensors) { } } + uint64_t offset = 0; struct pollfd fd_list[1] = {0}; fd_list[0].fd = fd; fd_list[0].events = POLLIN | POLLPRI; @@ -68,9 +69,19 @@ void interrupt_loop(std::vector> sensors) { continue; } + uint64_t cur_offset = nanos_since_epoch() - nanos_since_boot(); + uint64_t diff = cur_offset > offset ? cur_offset - offset : offset - cur_offset; + if (diff > 1*1e6) { // 1ms + LOGW("time jumped: %lu %lu", cur_offset, offset); + offset = cur_offset; + + // we don't have a valid timestamp since the + // time jumped, so throw out this measurement. + continue; + } + int num_events = err / sizeof(*evdata); - uint64_t offset = nanos_since_epoch() - nanos_since_boot(); - uint64_t ts = evdata[num_events - 1].timestamp - offset; + uint64_t ts = evdata[num_events - 1].timestamp - cur_offset; for (auto &[sensor, msg_name] : sensors) { if (!sensor->has_interrupt_enabled()) {