diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-10-27 14:09:40 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-10-27 14:09:40 +0100 |
commit | 48dafdabc1240932db01252279393fdfa18acc14 (patch) | |
tree | 842aa553e32c95efb6211076da699468be9e5624 | |
parent | a8bbbc899c238d06f89a1abe773a967c08051081 (diff) | |
download | rspamd-48dafdabc1240932db01252279393fdfa18acc14.tar.gz rspamd-48dafdabc1240932db01252279393fdfa18acc14.zip |
[Fix] Another fix for rdtcs
Issue: #1885
-rw-r--r-- | CMakeLists.txt | 12 | ||||
-rw-r--r-- | config.h.in | 2 | ||||
-rw-r--r-- | src/libutil/util.c | 13 |
3 files changed, 15 insertions, 12 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 0acfefb75..8256f5f39 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1123,18 +1123,18 @@ ENDIF() CHECK_C_SOURCE_RUNS(" #include <x86intrin.h> int main(int argc, char **argv) { - unsigned l; - if (__builtin_ia32_rdtscp(&l)) { + __builtin_ia32_lfence (); + if (__builtin_ia32_rdtsc()) { return 0; } return -1; } -" HAVE_RDTSCP) +" HAVE_RDTSC) -IF(NOT HAVE_RDTSCP) - MESSAGE(STATUS "rdtscp intrinsic is -NOT- supported") +IF(NOT HAVE_RDTSC) + MESSAGE(STATUS "rdtsc intrinsic is -NOT- supported") ELSE() - MESSAGE(STATUS "rdtscp intrinsic is supported") + MESSAGE(STATUS "rdtsc intrinsic is supported") ENDIF() IF(CMAKE_SYSTEM_NAME STREQUAL "Linux") diff --git a/config.h.in b/config.h.in index 6f8d3c48c..ce3ee9650 100644 --- a/config.h.in +++ b/config.h.in @@ -71,7 +71,7 @@ #cmakedefine HAVE_POSIX_FALLOCATE 1 #cmakedefine HAVE_PTHREAD_PROCESS_SHARED 1 #cmakedefine HAVE_PWD_H 1 -#cmakedefine HAVE_RDTSCP 1 +#cmakedefine HAVE_RDTSC 1 #cmakedefine HAVE_READPASSPHRASE_H 1 #cmakedefine HAVE_SA_SIGINFO 1 #cmakedefine HAVE_SANE_SHMEM 1 diff --git a/src/libutil/util.c b/src/libutil/util.c index 7cb2ff81a..9c2af41e3 100644 --- a/src/libutil/util.c +++ b/src/libutil/util.c @@ -70,9 +70,11 @@ #ifdef HAVE_SYS_RESOURCE_H #include <sys/resource.h> #endif -#ifdef HAVE_RDTSCP +#ifdef HAVE_RDTSC +#ifdef __x86_64__ #include <x86intrin.h> #endif +#endif #include <math.h> /* for pow */ #include "cryptobox.h" @@ -1768,17 +1770,18 @@ rspamd_get_ticks (gboolean rdtsc_ok) { gdouble res; -#ifdef HAVE_RDTSCP - guint tmp; +#ifdef HAVE_RDTSC +# ifdef __x86_64__ guint64 r64; if (rdtsc_ok) { - r64 = __builtin_ia32_rdtscp (&tmp); + __builtin_ia32_lfence (); + r64 = __rdtsc (); /* Preserve lower 52 bits */ res = r64 & ((1ULL << 53) - 1); return res; } - +# endif #endif #ifdef HAVE_CLOCK_GETTIME struct timespec ts; |