Skip to content

Commit 735bd2a

Browse files
author
Steinar H. Gunderson
committed
Bug #30981914: COMPILE WITH FASTER TLS MODEL
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
1 parent 31b4cca commit 735bd2a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

cmake/build_configurations/compiler_options.cmake

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License, version 2.0,
@@ -71,6 +71,12 @@ IF(UNIX)
7171
SET(COMMON_CXX_FLAGS "-std=c++14 -fno-omit-frame-pointer")
7272
ENDIF()
7373

74+
# Faster TLS model
75+
IF(MY_COMPILER_IS_GNU_OR_CLANG AND NOT SOLARIS)
76+
STRING_APPEND(COMMON_C_FLAGS " -ftls-model=initial-exec")
77+
STRING_APPEND(COMMON_CXX_FLAGS " -ftls-model=initial-exec")
78+
ENDIF()
79+
7480
# Solaris flags
7581
IF(SOLARIS)
7682
# Link mysqld with mtmalloc on Solaris 10 and later

0 commit comments

Comments
 (0)