diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-10-26 15:52:11 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-10-26 15:52:42 +0100 |
commit | 22d602b81fe3315007075f7807bb9d944a72cb94 (patch) | |
tree | 1841992bbb7f8457d8c2b07ad2cb6ab57facc523 /src/libutil/util.c | |
parent | b08a65087f4ec74b6076038d26bf084bb485973c (diff) | |
download | rspamd-22d602b81fe3315007075f7807bb9d944a72cb94.tar.gz rspamd-22d602b81fe3315007075f7807bb9d944a72cb94.zip |
[Feature] Use rdtsc where possible
Diffstat (limited to 'src/libutil/util.c')
-rw-r--r-- | src/libutil/util.c | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/src/libutil/util.c b/src/libutil/util.c index f2d9d41b0..f022b4689 100644 --- a/src/libutil/util.c +++ b/src/libutil/util.c @@ -70,6 +70,9 @@ #ifdef HAVE_SYS_RESOURCE_H #include <sys/resource.h> #endif +#ifdef HAVE_RDTSCP +#include <x86intrin.h> +#endif #include <math.h> /* for pow */ #include "cryptobox.h" @@ -1761,24 +1764,36 @@ restart: } gdouble -rspamd_get_ticks (void) +rspamd_get_ticks (gboolean rdtsc_ok) { gdouble res; +#ifdef HAVE_RDTSCP + guint tmp; + guint64 r64; + + if (rdtsc_ok) { + r64 = __builtin_ia32_rdtscp (&tmp); + /* Preserve lower 52 bits */ + res = r64 & ((1ULL << 53) - 1); + return res; + } + +#endif #ifdef HAVE_CLOCK_GETTIME struct timespec ts; gint clk_id = CLOCK_MONOTONIC; -#ifdef CLOCK_MONOTONIC_FAST +# ifdef CLOCK_MONOTONIC_FAST clk_id = CLOCK_MONOTONIC_FAST; -#endif -#ifdef CLOCK_MONOTONIC_COARSE +# endif +# ifdef CLOCK_MONOTONIC_COARSE clk_id = CLOCK_MONOTONIC_COARSE; -#endif +# endif clock_gettime (clk_id, &ts); res = (double)ts.tv_sec + ts.tv_nsec / 1000000000.; -#elif defined(__APPLE__) +# elif defined(__APPLE__) res = mach_absolute_time () / 1000000000.; #else struct timeval tv; |