From 042fc2959705eba79b2eae6031d5f9ca5c454c01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Thu, 27 Jun 2019 10:53:18 +0300 Subject: MDEV-19845: Adaptive spin loops Starting with the Intel Skylake microarchitecture, the PAUSE instruction latency is about 140 clock cycles instead of earlier 10. On AMD processors, the latency could be 10 or 50 clock cycles, depending on microarchitecture. Because of this big range of latency, let us scale the loops around the PAUSE instruction based on timing results at server startup. my_cpu_relax_multiplier: New variable: How many times to invoke PAUSE in a loop. Only defined for IA-32 and AMD64. my_cpu_init(): Determine with RDTSC the time to run 16 PAUSE instructions in two unrolled loops according, and based on the quicker of the two runs, initialize my_cpu_relax_multiplier. This form of calibration was suggested by Mikhail Sinyavin from Intel. LF_BACKOFF(), ut_delay(): Use my_cpu_relax_multiplier when available. ut_delay(): Define inline in my_cpu.h. UT_COMPILER_BARRIER(): Remove. This does not seem to have any effect, because in our ut_delay() implementation, no computations are being performed inside the loop. The purpose of UT_COMPILER_BARRIER() was to prohibit the compiler from reordering computations. It was not emitting any code. --- configure.cmake | 26 -------------------------- 1 file changed, 26 deletions(-) (limited to 'configure.cmake') diff --git a/configure.cmake b/configure.cmake index 67ed6503e3e..e75810f8150 100644 --- a/configure.cmake +++ b/configure.cmake @@ -758,32 +758,6 @@ IF(NOT C_HAS_inline) ENDIF() ENDIF() -IF(NOT CMAKE_CROSSCOMPILING AND NOT MSVC) - STRING(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} processor) - IF(processor MATCHES "86" OR processor MATCHES "amd64" OR processor MATCHES "x64") - #Check for x86 PAUSE instruction - # We have to actually try running the test program, because of a bug - # in Solaris on x86_64, where it wrongly reports that PAUSE is not - # supported when trying to run an application. See - # http://bugs.opensolaris.org/bugdatabase/printableBug.do?bug_id=6478684 - CHECK_C_SOURCE_RUNS(" - int main() - { - __asm__ __volatile__ (\"pause\"); - return 0; - }" HAVE_PAUSE_INSTRUCTION) - ENDIF() - IF (NOT HAVE_PAUSE_INSTRUCTION) - CHECK_C_SOURCE_COMPILES(" - int main() - { - __asm__ __volatile__ (\"rep; nop\"); - return 0; - } - " HAVE_FAKE_PAUSE_INSTRUCTION) - ENDIF() -ENDIF() - CHECK_SYMBOL_EXISTS(tcgetattr "termios.h" HAVE_TCGETATTR 1) # -- cgit v1.2.1