Skip to content

Commit

Permalink
drv_hrt posix: improve performance for hrt_absolute_time()
Browse files Browse the repository at this point in the history
Previously hrt_absolute_time() was at around 5% of the total CPU usage, now
it's around 0.35%.
  • Loading branch information
bkueng authored and julianoes committed Jan 14, 2019
1 parent ccefc64 commit ecbe2a3
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions platforms/posix/src/px4_layer/drv_hrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,19 @@ uint64_t hrt_system_time()
*/
hrt_abstime hrt_absolute_time()
{
#if defined(ENABLE_LOCKSTEP_SCHEDULER)
// optimized case (avoid ts_to_abstime) if lockstep scheduler is used
const uint64_t abstime = lockstep_scheduler.get_absolute_time();
return abstime - px4_timestart_monotonic;
#else // defined(ENABLE_LOCKSTEP_SCHEDULER)
struct timespec ts;
px4_clock_gettime(CLOCK_MONOTONIC, &ts);
#ifdef __PX4_QURT
return ts_to_abstime(&ts) + dsp_offset;
#else
return ts_to_abstime(&ts);
#endif
#endif // defined(ENABLE_LOCKSTEP_SCHEDULER)
}

#ifdef __PX4_QURT
Expand Down

0 comments on commit ecbe2a3

Please sign in to comment.