summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2019-02-09 19:18:53 +0100
committerSimon Rettberg2019-02-09 19:18:53 +0100
commit3259da07aef6ca7d9ce395503d512c53ea3316d7 (patch)
treec818659093bf8f2ed376d2373d777af977b54f4e
parent[FUSE] Consider RTT of active connection for switch-decisions (diff)
downloaddnbd3-3259da07aef6ca7d9ce395503d512c53ea3316d7.tar.gz
dnbd3-3259da07aef6ca7d9ce395503d512c53ea3316d7.tar.xz
dnbd3-3259da07aef6ca7d9ce395503d512c53ea3316d7.zip
[SHARED] More timing helpers
-rw-r--r--src/shared/timing.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/shared/timing.h b/src/shared/timing.h
index dfff5f8..f3d8802 100644
--- a/src/shared/timing.h
+++ b/src/shared/timing.h
@@ -66,6 +66,12 @@ static inline void timing_gets(ticks* retval, int32_t addSeconds)
retval->tv_sec += addSeconds;
}
+static inline void timing_addSeconds(ticks* retval, ticks* base, int32_t addSeconds)
+{
+ retval->tv_sec = base->tv_sec + addSeconds;
+ retval->tv_nsec = base->tv_nsec;
+}
+
/**
* Check whether given timeout is reached.
* Might trigger up to one second early.
@@ -135,5 +141,22 @@ static inline uint64_t timing_diffMs(const ticks *start, const ticks *end)
return diff;
}
+/**
+ * Get difference between two ticks, rounded down to microseconds.
+ * Same as above; passing arguments in reverse will always return 0.
+ */
+static inline uint64_t timing_diffUs(const ticks *start, const ticks *end)
+{
+ if ( end->tv_sec < start->tv_sec ) return 0;
+ uint64_t diff = (uint64_t)( end->tv_sec - start->tv_sec ) * 1000000;
+ if ( start->tv_nsec >= end->tv_nsec ) {
+ if ( diff == 0 ) return 0;
+ diff -= ( start->tv_nsec - end->tv_nsec ) / 1000;
+ } else {
+ diff += ( end->tv_nsec - start->tv_nsec ) / 1000;
+ }
+ return diff;
+}
+
#endif