Commit 9794cf23 authored by Jan Lindström's avatar Jan Lindström

Merge pull request #168 from grooverdan/10.1-MDEV-8684-UT_RELAX_CPU_isnt_relaxing

MDEV-8684 ut relax cpu isnt relaxing
parents 04737330 26c38de8
......@@ -225,6 +225,7 @@
#cmakedefine HAVE_PREAD 1
#cmakedefine HAVE_PAUSE_INSTRUCTION 1
#cmakedefine HAVE_FAKE_PAUSE_INSTRUCTION 1
#cmakedefine HAVE_HMT_PRIORITY_INSTRUCTION 1
#cmakedefine HAVE_RDTSCLL 1
#cmakedefine HAVE_READ_REAL_TIME 1
#cmakedefine HAVE_PTHREAD_ATTR_CREATE 1
......
......@@ -855,6 +855,17 @@ IF(NOT CMAKE_CROSSCOMPILING AND NOT MSVC)
}
" HAVE_FAKE_PAUSE_INSTRUCTION)
ENDIF()
IF (NOT HAVE_PAUSE_INSTRUCTION)
CHECK_C_SOURCE_COMPILES("
#include <sys/platform/ppc.h>
int main()
{
__ppc_set_ppr_low();
__ppc_set_ppr_med();
return 0;
}
" HAVE_HMT_PRIORITY_INSTRUCTION)
ENDIF()
ENDIF()
CHECK_SYMBOL_EXISTS(tcgetattr "termios.h" HAVE_TCGETATTR 1)
......
......@@ -88,15 +88,26 @@ private:
the YieldProcessor macro defined in WinNT.h. It is a CPU architecture-
independent way by using YieldProcessor. */
# define UT_RELAX_CPU() YieldProcessor()
# elif defined(HAVE_ATOMIC_BUILTINS)
# elif defined(__powerpc__)
#include <sys/platform/ppc.h>
# define UT_RELAX_CPU() do { \
volatile lint volatile_var; \
os_compare_and_swap_lint(&volatile_var, 0, 1); \
volatile lint volatile_var = __ppc_get_timebase(); \
} while (0)
# else
# define UT_RELAX_CPU() ((void)0) /* avoid warning for an empty statement */
# endif
#define UT_COMPILER_BARRIER() __asm__ __volatile__ ("":::"memory")
# if defined(HAVE_HMT_PRIORITY_INSTRUCTION)
#include <sys/platform/ppc.h>
# define UT_LOW_PRIORITY_CPU() __ppc_set_ppr_low()
# define UT_RESUME_PRIORITY_CPU() __ppc_set_ppr_med()
# else
# define UT_LOW_PRIORITY_CPU() ((void)0)
# define UT_RESUME_PRIORITY_CPU() ((void)0)
# endif
/*********************************************************************//**
Delays execution for at most max_wait_us microseconds or returns earlier
if cond becomes true.
......@@ -342,7 +353,7 @@ Runs an idle loop on CPU. The argument gives the desired delay
in microseconds on 100 MHz Pentium + Visual C++.
@return dummy value */
UNIV_INTERN
ulint
void
ut_delay(
/*=====*/
ulint delay); /*!< in: delay in microseconds on 100 MHz Pentium */
......
......@@ -45,9 +45,6 @@ Created 5/11/1994 Heikki Tuuri
# include <string>
#endif /* UNIV_HOTBACKUP */
/** A constant to prevent the compiler from optimizing ut_delay() away. */
UNIV_INTERN ibool ut_always_false = FALSE;
#ifdef __WIN__
/*****************************************************************//**
NOTE: The Windows epoch starts from 1601/01/01 whereas the Unix
......@@ -397,25 +394,21 @@ Runs an idle loop on CPU. The argument gives the desired delay
in microseconds on 100 MHz Pentium + Visual C++.
@return dummy value */
UNIV_INTERN
ulint
void
ut_delay(
/*=====*/
ulint delay) /*!< in: delay in microseconds on 100 MHz Pentium */
{
ulint i, j;
ulint i;
j = 0;
UT_LOW_PRIORITY_CPU();
for (i = 0; i < delay * 50; i++) {
j += i;
UT_RELAX_CPU();
UT_COMPILER_BARRIER();
}
if (ut_always_false) {
ut_always_false = (ibool) j;
}
return(j);
UT_RESUME_PRIORITY_CPU();
}
#endif /* !UNIV_HOTBACKUP */
......
......@@ -80,20 +80,31 @@ private:
# elif defined(HAVE_FAKE_PAUSE_INSTRUCTION)
# define UT_RELAX_CPU() __asm__ __volatile__ ("rep; nop")
# elif defined(HAVE_ATOMIC_BUILTINS)
# define UT_RELAX_CPU() do { \
volatile lint volatile_var; \
os_compare_and_swap_lint(&volatile_var, 0, 1); \
} while (0)
# elif defined(HAVE_WINDOWS_ATOMICS)
/* In the Win32 API, the x86 PAUSE instruction is executed by calling
the YieldProcessor macro defined in WinNT.h. It is a CPU architecture-
independent way by using YieldProcessor. */
# define UT_RELAX_CPU() YieldProcessor()
# elif defined(__powerpc__)
#include <sys/platform/ppc.h>
# define UT_RELAX_CPU() do { \
volatile lint volatile_var = __ppc_get_timebase(); \
} while (0)
# else
# define UT_RELAX_CPU() ((void)0) /* avoid warning for an empty statement */
# endif
#define UT_COMPILER_BARRIER() __asm__ __volatile__ ("":::"memory")
# if defined(HAVE_HMT_PRIORITY_INSTRUCTION)
#include <sys/platform/ppc.h>
# define UT_LOW_PRIORITY_CPU() __ppc_set_ppr_low()
# define UT_RESUME_PRIORITY_CPU() __ppc_set_ppr_med()
# else
# define UT_LOW_PRIORITY_CPU() ((void)0)
# define UT_RESUME_PRIORITY_CPU() ((void)0)
# endif
/*********************************************************************//**
Delays execution for at most max_wait_us microseconds or returns earlier
if cond becomes true.
......@@ -334,7 +345,7 @@ Runs an idle loop on CPU. The argument gives the desired delay
in microseconds on 100 MHz Pentium + Visual C++.
@return dummy value */
UNIV_INTERN
ulint
void
ut_delay(
/*=====*/
ulint delay); /*!< in: delay in microseconds on 100 MHz Pentium */
......
......@@ -46,9 +46,6 @@ Created 5/11/1994 Heikki Tuuri
# include <string>
#endif /* UNIV_HOTBACKUP */
/** A constant to prevent the compiler from optimizing ut_delay() away. */
UNIV_INTERN ibool ut_always_false = FALSE;
#ifdef __WIN__
/*****************************************************************//**
NOTE: The Windows epoch starts from 1601/01/01 whereas the Unix
......@@ -398,25 +395,21 @@ Runs an idle loop on CPU. The argument gives the desired delay
in microseconds on 100 MHz Pentium + Visual C++.
@return dummy value */
UNIV_INTERN
ulint
void
ut_delay(
/*=====*/
ulint delay) /*!< in: delay in microseconds on 100 MHz Pentium */
{
ulint i, j;
ulint i;
j = 0;
UT_LOW_PRIORITY_CPU();
for (i = 0; i < delay * 50; i++) {
j += i;
UT_RELAX_CPU();
UT_COMPILER_BARRIER();
}
if (ut_always_false) {
ut_always_false = (ibool) j;
}
return(j);
UT_RESUME_PRIORITY_CPU();
}
#endif /* !UNIV_HOTBACKUP */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment