From c01e94a4319c416c4c231ffbea9e778d52424e30 Mon Sep 17 00:00:00 2001 From: Jim Brunner Date: Fri, 28 Aug 2020 01:54:10 -0700 Subject: Use H/W Monotonic clock and updates to AE (#7644) Update adds a general source for retrieving a monotonic time. In addition, AE has been updated to utilize the new monotonic clock for timer processing. This performance improvement is **not** enabled in a default build due to various H/W compatibility concerns, see README.md for details. It does however change the default use of gettimeofday with clock_gettime and somewhat improves performance. This update provides the following 1. An interface for retrieving a monotonic clock. getMonotonicUs returns a uint64_t (aka monotime) with the number of micro-seconds from an arbitrary point. No more messing with tv_sec/tv_usec. Simple routines are provided for measuring elapsed milli-seconds or elapsed micro-seconds (the most common use case for a monotonic timer). No worries about time moving backwards. 2. High-speed assembler implementation for x86 and ARM. The standard method for retrieving the monotonic clock is POSIX.1b (1993): clock_gettime(CLOCK_MONOTONIC, timespec*). However, most modern processors provide a constant speed instruction clock which can be retrieved in a fraction of the time that it takes to call clock_gettime. For x86, this is provided by the RDTSC instruction. For ARM, this is provided by the CNTVCT_EL0 instruction. As a compile-time option, these high-speed timers can be chosen. (Default is POSIX clock_gettime.) 3. Refactor of event loop timers. The timer processing in ae.c has been refactored to use the new monotonic clock interface. This results in simpler/cleaner logic and improved performance. --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'README.md') diff --git a/README.md b/README.md index d8f8f7880..46b89c392 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,18 @@ To compile against jemalloc on Mac OS X systems, use: % make MALLOC=jemalloc +Monotonic clock +--------------- + +By default, Redis will build using the POSIX clock_gettime function as the +monotonic clock source. On most modern systems, the internal processor clock +can be used to improve performance. Cautions can be found here: + http://oliveryang.net/2015/09/pitfalls-of-TSC-usage/ + +To build with support for the processor's internal instruction clock, use: + + % make CFLAGS="-DUSE_PROCESSOR_CLOCK" + Verbose build ------------- -- cgit v1.2.1