Skip to content

Commit

Permalink
Bug #30981914: COMPILE WITH FASTER TLS MODEL
Browse files Browse the repository at this point in the history
Change from the default TLS model, global-dynamic (since we are using -fPIC),
to a faster one, initial-exec. global-dynamic calls __tls_get_addr() for each
TLS access (to e.g. current_thd); initial-exec caches the value (per-function),
the first time it reaches the function. In other words, on subsequent function
calls, there will be a predictable branch and then just a read from %fs.

The disadvantage of initial-exec is that one cannot access “extern thread_local”
variables across modules that are dlopen()-ed (and not otherwise linked to each
other). This is not a problem for plugins that want to access current_thd or
*THR_MALLOC, since they are linked against the server, but it would affect
a hypothetical situation where plugin A has “thread_local int x;” and plugin B
has “extern thread_local int x;” (and was not linked to A; presumably, A would
need to be loaded before B). Plugins and components are already supposed not to
do this, and we know of no cases where it happens.

Point select throughput goes up 1.4-2.2%, depending on thread count. This is
on top of the gains we already got earlier, from changing to C++11 thread_local
instead of calling pthread_getspecific().

Change-Id: Ic511636de6e0f3703cc811680596467d064146bf
  • Loading branch information
Steinar H. Gunderson committed Mar 3, 2020
1 parent 31b4cca commit 735bd2a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cmake/build_configurations/compiler_options.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
Expand Down Expand Up @@ -71,6 +71,12 @@ IF(UNIX)
SET(COMMON_CXX_FLAGS "-std=c++14 -fno-omit-frame-pointer")
ENDIF()

# Faster TLS model
IF(MY_COMPILER_IS_GNU_OR_CLANG AND NOT SOLARIS)
STRING_APPEND(COMMON_C_FLAGS " -ftls-model=initial-exec")
STRING_APPEND(COMMON_CXX_FLAGS " -ftls-model=initial-exec")
ENDIF()

# Solaris flags
IF(SOLARIS)
# Link mysqld with mtmalloc on Solaris 10 and later
Expand Down

0 comments on commit 735bd2a

Please sign in to comment.