sensord: fix timestamp race condition (#33867)

Co-authored-by: Comma Device <device@comma.ai>
pull/33868/head
Adeeb Shihadeh 6 months ago committed by GitHub
parent 2f7d09bb01
commit 47aee33ad2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 15
      system/sensord/sensors_qcom2.cc

@ -39,6 +39,7 @@ void interrupt_loop(std::vector<std::tuple<Sensor *, std::string>> 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<std::tuple<Sensor *, std::string>> 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()) {

Loading…
Cancel
Save