Skip to content

Commit

Permalink
sensord: fix timestamp race condition (commaai#33867)
Browse files Browse the repository at this point in the history
Co-authored-by: Comma Device <[email protected]>
  • Loading branch information
adeebshihadeh and Comma Device authored Oct 24, 2024
1 parent 2f7d09b commit 47aee33
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions system/sensord/sensors_qcom2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down

0 comments on commit 47aee33

Please sign in to comment.