mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-26 09:26:25 +08:00
HRT: Create new separate call for atomic HRT elapsed time calculation
This call rarely needs to be truly atomic and the involved CPU overhead in making it atomic was unnecessary and introduces a lot of IRQ jitter with no value-add. The call has been moved to be non-atomic and the codebase will be inspected and changed in follow-up commits for the few instances where it is truly needed.
This commit is contained in:
@@ -92,6 +92,14 @@ __EXPORT extern hrt_abstime ts_to_abstime(const struct timespec *ts);
|
||||
*/
|
||||
__EXPORT extern void abstime_to_ts(struct timespec *ts, hrt_abstime abstime);
|
||||
|
||||
/**
|
||||
* Compute the delta between a timestamp taken in the past
|
||||
* and now.
|
||||
*
|
||||
* This function is not interrupt save.
|
||||
*/
|
||||
__EXPORT extern hrt_abstime hrt_elapsed_time(const volatile hrt_abstime *then);
|
||||
|
||||
/**
|
||||
* Compute the delta between a timestamp taken in the past
|
||||
* and now.
|
||||
@@ -99,7 +107,7 @@ __EXPORT extern void abstime_to_ts(struct timespec *ts, hrt_abstime abstime);
|
||||
* This function is safe to use even if the timestamp is updated
|
||||
* by an interrupt during execution.
|
||||
*/
|
||||
__EXPORT extern hrt_abstime hrt_elapsed_time(const volatile hrt_abstime *then);
|
||||
__EXPORT extern hrt_abstime hrt_elapsed_time_atomic(const volatile hrt_abstime *then);
|
||||
|
||||
/**
|
||||
* Store the absolute time in an interrupt-safe fashion.
|
||||
|
||||
@@ -720,6 +720,17 @@ abstime_to_ts(struct timespec *ts, hrt_abstime abstime)
|
||||
*/
|
||||
hrt_abstime
|
||||
hrt_elapsed_time(const volatile hrt_abstime *then)
|
||||
{
|
||||
hrt_abstime delta = hrt_absolute_time() - *then;
|
||||
|
||||
return delta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare a time value with the current time as atomic operation
|
||||
*/
|
||||
hrt_abstime
|
||||
hrt_elapsed_time_atomic(const volatile hrt_abstime *then)
|
||||
{
|
||||
irqstate_t flags = px4_enter_critical_section();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user