]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Use mach_approximate_time() for coarse time where available.
authorNick Mathewson <nickm@torproject.org>
Fri, 8 Dec 2017 14:24:02 +0000 (09:24 -0500)
committerNick Mathewson <nickm@torproject.org>
Fri, 8 Dec 2017 14:24:02 +0000 (09:24 -0500)
This lets us have a coarse-time implementation with reasonable
performance characteristics on OSX and iOS.

Implements 24427.

changes/feature24427 [new file with mode: 0644]
configure.ac
src/common/compat_time.c
src/common/compat_time.h

diff --git a/changes/feature24427 b/changes/feature24427
new file mode 100644 (file)
index 0000000..8650c45
--- /dev/null
@@ -0,0 +1,5 @@
+  o Minor features (OSX, iOS, performance):
+    - Use the mach_approximate_time() function (when available) to
+      implement coarse monotonic time. Having a coarse time function
+      should avoid a large number of system calls, and improve
+      performance slightly, especially under load. Closes ticket 24427.
index 0b3e1dda26cf034247a8ae70c51bb4aee792ef00..84ae9090b811bb77d221b791046e78d0fec4e21b 100644 (file)
@@ -506,6 +506,7 @@ AC_CHECK_FUNCS(
         llround \
         localtime_r \
         lround \
+       mach_approximate_time \
         memmem \
         memset_s \
        pipe \
index 204b8d7d1554868a4f8ae7972411bd0d925adcf4..c0cd73c74d84ad9ac01850f24d8af4479fab4361 100644 (file)
@@ -314,6 +314,21 @@ monotime_get(monotime_t *out)
   out->abstime_ = mach_absolute_time();
 }
 
+#if defined(HAVE_MACH_APPROXIMATE_TIME)
+void
+monotime_coarse_get(monotime_coarse_t *out)
+{
+#ifdef TOR_UNIT_TESTS
+  if (monotime_mocking_enabled) {
+    out->abstime_ = (mock_time_nsec_coarse * mach_time_info.denom)
+      / mach_time_info.numer;
+    return;
+  }
+#endif /* defined(TOR_UNIT_TESTS) */
+  out->abstime_ = mach_approximate_time();
+}
+#endif
+
 /**
  * Return the number of nanoseconds between <b>start</b> and <b>end</b>.
  */
index 462dcecceac94ef52904670bb9efbd136de298d4..bcf469e2707ddcb36f9341f3a37ac54c500b98f9 100644 (file)
@@ -65,6 +65,9 @@ typedef struct monotime_t {
 typedef struct monotime_coarse_t {
   uint64_t tick_count_;
 } monotime_coarse_t;
+#elif defined(__APPLE__) && defined(HAVE_MACH_APPROXIMATE_TIME)
+#define MONOTIME_COARSE_FN_IS_DIFFERENT
+#define monotime_coarse_t monotime_t
 #else
 #define monotime_coarse_t monotime_t
 #endif /* defined(CLOCK_MONOTONIC_COARSE) && ... || ... */