diff options
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/expression.c | 4 | ||||
-rw-r--r-- | src/libutil/util.c | 27 | ||||
-rw-r--r-- | src/libutil/util.h | 2 |
3 files changed, 24 insertions, 9 deletions
diff --git a/src/libutil/expression.c b/src/libutil/expression.c index b49935cb4..dae574da5 100644 --- a/src/libutil/expression.c +++ b/src/libutil/expression.c @@ -1007,7 +1007,7 @@ rspamd_ast_process_node (struct rspamd_expression *expr, gint flags, GNode *node */ if ((expr->evals & 0x1F) == (GPOINTER_TO_UINT (node) >> 4 & 0x1F)) { calc_ticks = TRUE; - t1 = rspamd_get_ticks (); + t1 = rspamd_get_ticks (TRUE); } elt->value = expr->subr->process (data, elt->p.atom); @@ -1021,7 +1021,7 @@ rspamd_ast_process_node (struct rspamd_expression *expr, gint flags, GNode *node } if (calc_ticks) { - t2 = rspamd_get_ticks (); + t2 = rspamd_get_ticks (TRUE); elt->p.atom->avg_ticks += ((t2 - t1) - elt->p.atom->avg_ticks) / (expr->evals); } 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; diff --git a/src/libutil/util.h b/src/libutil/util.h index d8a1eae60..ab677210e 100644 --- a/src/libutil/util.h +++ b/src/libutil/util.h @@ -295,7 +295,7 @@ gint rspamd_read_passphrase (gchar *buf, gint size, gint rwflag, gpointer key); * Portably return the current clock ticks as seconds * @return */ -gdouble rspamd_get_ticks (void); +gdouble rspamd_get_ticks (gboolean rdtsc_ok); /** * Portably return the current virtual clock ticks as seconds |