lib/timer: Add current_time_now() function for immediate timestamp

Add a current_time_now() function which gets an immediate monotonic
timestamp instead of using the cached value from the event loop. This is
useful for callers that need precise times, such as the Babel RTT
measurement code.

Signed-off-by: Toke Høiland-Jørgensen <toke@toke.dk>
This commit is contained in:
Toke Høiland-Jørgensen 2022-04-19 00:24:14 +02:00
parent 8f9a091d30
commit 44421ba7d4
2 changed files with 14 additions and 0 deletions

View file

@ -76,6 +76,19 @@ current_time(void)
return timeloop_current()->last_time; return timeloop_current()->last_time;
} }
btime
current_time_now(void)
{
struct timespec ts;
int rv;
rv = clock_gettime(CLOCK_MONOTONIC, &ts);
if (rv < 0)
die("clock_gettime: %m");
return ts.tv_sec S + ts.tv_nsec NS;
}
btime btime
current_real_time(void) current_real_time(void)
{ {

View file

@ -44,6 +44,7 @@ static inline timer *timers_first(struct timeloop *loop)
extern struct timeloop main_timeloop; extern struct timeloop main_timeloop;
btime current_time(void); btime current_time(void);
btime current_time_now(void);
btime current_real_time(void); btime current_real_time(void);
//#define now (current_time() TO_S) //#define now (current_time() TO_S)