Skip to content

Commit

Permalink
Some POWER specific optimizations
Browse files Browse the repository at this point in the history
Bug#18842925 : SET THREAD PRIORITY IN INNODB MUTEX SPINLOOP
Like "pause" instruction for hyper-threading at Intel CPUs,
POWER has special instructions only for hinting priority of hardware-threads.

Approved by Sunny in rb#6256

Backport of the 5.7 fix - mysql/mysql-server@c92102a
(excluded cache line size patch)

Suggestion by Stewart Smith
  • Loading branch information
Yasufumi Kinoshita authored and grooverdan committed Mar 31, 2016
1 parent 2275640 commit d4ba504
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,16 @@ IF(NOT CMAKE_CROSSCOMPILING AND NOT MSVC)
}
" HAVE_FAKE_PAUSE_INSTRUCTION)
ENDIF()
IF (NOT HAVE_PAUSE_INSTRUCTION)
CHECK_C_SOURCE_COMPILES("
int main()
{
__asm__ __volatile__ (\"or 1,1,1\");
__asm__ __volatile__ (\"or 2,2,2\");
return 0;
}
" HAVE_HMT_PRIORITY_INSTRUCTION)
ENDIF()
ENDIF()

CHECK_SYMBOL_EXISTS(tcgetattr "termios.h" HAVE_TCGETATTR 1)
Expand Down
8 changes: 8 additions & 0 deletions storage/innobase/include/ut0ut.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ struct ut_when_dtor {
# define UT_RELAX_CPU() __asm__ __volatile__ ("":::"memory")
# endif

# if defined(HAVE_HMT_PRIORITY_INSTRUCTION)
# define UT_LOW_PRIORITY_CPU() __asm__ __volatile__ ("or 1,1,1")
# define UT_RESUME_PRIORITY_CPU() __asm__ __volatile__ ("or 2,2,2")
# 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.
Expand Down
4 changes: 4 additions & 0 deletions storage/innobase/ut/ut0ut.cc
Original file line number Diff line number Diff line change
Expand Up @@ -401,13 +401,17 @@ ut_delay(
{
ulint i, j;

UT_LOW_PRIORITY_CPU();

j = 0;

for (i = 0; i < delay * 50; i++) {
j += i;
UT_RELAX_CPU();
}

UT_RESUME_PRIORITY_CPU();

return(j);
}
#endif /* !UNIV_HOTBACKUP */
Expand Down
8 changes: 8 additions & 0 deletions storage/xtradb/include/ut0ut.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ struct ut_when_dtor {
# define UT_RELAX_CPU() __asm__ __volatile__ ("":::"memory")
# endif

# if defined(HAVE_HMT_PRIORITY_INSTRUCTION)
# define UT_LOW_PRIORITY_CPU() __asm__ __volatile__ ("or 1,1,1")
# define UT_RESUME_PRIORITY_CPU() __asm__ __volatile__ ("or 2,2,2")
# 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.
Expand Down
4 changes: 4 additions & 0 deletions storage/xtradb/ut/ut0ut.cc
Original file line number Diff line number Diff line change
Expand Up @@ -402,13 +402,17 @@ ut_delay(
{
ulint i, j;

UT_LOW_PRIORITY_CPU();

j = 0;

for (i = 0; i < delay * 50; i++) {
j += i;
UT_RELAX_CPU();
}

UT_RESUME_PRIORITY_CPU();

return(j);
}
#endif /* !UNIV_HOTBACKUP */
Expand Down

0 comments on commit d4ba504

Please sign in to comment.