summaryrefslogtreecommitdiff
path: root/src/common/compat_time.h
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2017-11-21 12:28:16 -0500
committerNick Mathewson <nickm@torproject.org>2017-11-27 09:43:15 -0500
commitc3c0a05f51eff73e624b18f651339ed08a122e3d (patch)
treef679e50de45db6c6a5218bdb0815da4f5f058172 /src/common/compat_time.h
parentda82e0b5795c449f4442c87e065e9a60da4892a8 (diff)
downloadtor-c3c0a05f51eff73e624b18f651339ed08a122e3d.tar.gz
tor-c3c0a05f51eff73e624b18f651339ed08a122e3d.zip
Add a new notion of "stamps" to be a fast 32-bit monotonic timestamp
The goal here is to replace our use of msec-based timestamps with something less precise, but easier to calculate. We're doing this because calculating lots of msec-based timestamps requires lots of 64/32 division operations, which can be inefficient on 32-bit platforms. We make sure that these stamps can be calculated using only the coarse monotonic timer and 32-bit bitwise operations.
Diffstat (limited to 'src/common/compat_time.h')
-rw-r--r--src/common/compat_time.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/common/compat_time.h b/src/common/compat_time.h
index 5ea4aae42b..462dceccea 100644
--- a/src/common/compat_time.h
+++ b/src/common/compat_time.h
@@ -117,6 +117,23 @@ uint64_t monotime_coarse_absolute_msec(void);
#define monotime_coarse_absolute_msec monotime_absolute_msec
#endif /* defined(MONOTIME_COARSE_FN_IS_DIFFERENT) */
+/**
+ * Return a "timestamp" approximation for a coarse monotonic timer.
+ * This timestamp is meant to be fast to calculate and easy to
+ * compare, and have a unit of something roughly around 1 msec.
+ *
+ * It will wrap over from time to time.
+ *
+ * It has no defined zero point.
+ */
+uint32_t monotime_coarse_to_stamp(const monotime_coarse_t *t);
+/**
+ * Convert a difference, expressed in the units of monotime_coarse_to_stamp,
+ * into an approximate number of milliseconds.
+ */
+uint64_t monotime_coarse_stamp_units_to_approx_msec(uint64_t units);
+uint32_t monotime_coarse_get_stamp(void);
+
#if defined(MONOTIME_COARSE_TYPE_IS_DIFFERENT)
int64_t monotime_coarse_diff_nsec(const monotime_coarse_t *start,
const monotime_coarse_t *end);