* [tarantool-patches] [PATCH v2 1/3] test: prevent guard-breaker optimization with LTO
2018-10-14 23:17 [tarantool-patches] [PATCH v2 0/3] Add LTO support Alexander Turenko
@ 2018-10-14 23:17 ` Alexander Turenko
2018-10-14 23:17 ` [tarantool-patches] [PATCH v2 2/3] Add LTO support Alexander Turenko
` (2 subsequent siblings)
3 siblings, 0 replies; 9+ messages in thread
From: Alexander Turenko @ 2018-10-14 23:17 UTC (permalink / raw)
To: Georgy Kirichenko; +Cc: AKhatskevich, tarantool-patches
From: AKhatskevich <avkhatskevich@tarantool.org>
In case of very aggressive optimizations the compiler can
optimize guard-breaker function away and the `unit/guard`
test would fail.
---
test/unit/guard.cc | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/test/unit/guard.cc b/test/unit/guard.cc
index 231b44c7d..3d42fee31 100644
--- a/test/unit/guard.cc
+++ b/test/unit/guard.cc
@@ -13,7 +13,11 @@ static int __attribute__((noinline))
stack_break_f(char *ptr)
{
char block[2048];
- char sum = 0;
+ /*
+ * Make sum volatile to prevent a compiler from
+ * optimizing away call to this function.
+ */
+ volatile char sum = 0;
memset(block, 0xff, 2048);
sum += block[block[4]];
ptrdiff_t stack_diff = ptr > block ? ptr - block : block - ptr;
--
2.19.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [tarantool-patches] [PATCH v2 2/3] Add LTO support
2018-10-14 23:17 [tarantool-patches] [PATCH v2 0/3] Add LTO support Alexander Turenko
2018-10-14 23:17 ` [tarantool-patches] [PATCH v2 1/3] test: prevent guard-breaker optimization with LTO Alexander Turenko
@ 2018-10-14 23:17 ` Alexander Turenko
2018-10-16 18:09 ` [tarantool-patches] " Konstantin Osipov
2018-10-14 23:17 ` [tarantool-patches] [PATCH v2 3/3] test: add LTO targets into CI Alexander Turenko
2018-10-25 12:18 ` [tarantool-patches] Re: [PATCH v2 0/3] Add LTO support Kirill Yukhin
3 siblings, 1 reply; 9+ messages in thread
From: Alexander Turenko @ 2018-10-14 23:17 UTC (permalink / raw)
To: Georgy Kirichenko; +Cc: AKhatskevich, tarantool-patches
From: AKhatskevich <avkhatskevich@tarantool.org>
Added -DENABLE_LTO=ON/OFF cmake option, OFF by default.
LTO speeds up cpu-intensive workloads by up to 20% (see [1] and [2]).
Requirements for LTO enabling:
- cmake >= 3.9;
- Linux: ld.bfd / ld.gold from binutils >= 2.31 (or later 2.30)
(gold >= 1.15);
- Mac OS: xcode >= 8 (earlier versions are not tested).
The requirement of the recent ld version is due to bug with exporting
symbols from dynamic list when LTO is enabled, see [3].
Note: -Wlto-type-mismatch on GCC (enabled by default with -flto) gives
namy warnings. Filed [4] to investigate it.
Note: LuaJIT will be compiled w/o LTO despite the option set, filed [5].
[1]: https://github.com/tarantool/tarantool/wiki/performance-research
[2]: https://gist.github.com/Khatskevich/31a2da6ab46ce903120e7a03d65966db
[3]: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84901
[4]: https://github.com/tarantool/tarantool/issues/3742
[5]: https://github.com/tarantool/tarantool/issues/3743
Closes #3117
---
CMakeLists.txt | 3 ++
cmake/lto.cmake | 95 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 98 insertions(+)
create mode 100644 cmake/lto.cmake
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 439a2750a..491ccaf0b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -63,6 +63,9 @@ include(cmake/pod2man.cmake)
include(cmake/arch.cmake)
include(cmake/os.cmake)
include(cmake/compiler.cmake)
+# NO_POLICY_SCOPE is to suppress CMP0069 warnings on the unset
+# policy.
+include(cmake/lto.cmake NO_POLICY_SCOPE)
include(cmake/simd.cmake)
include(cmake/atomic.cmake)
include(cmake/profile.cmake)
diff --git a/cmake/lto.cmake b/cmake/lto.cmake
new file mode 100644
index 000000000..44a6f5771
--- /dev/null
+++ b/cmake/lto.cmake
@@ -0,0 +1,95 @@
+#
+# Manage LTO (Link-Time-Optimization) and IPO
+# (Inter-Procedural-Optimization)
+#
+
+# Tarantool uses both dynamic-list and lto link options, which
+# works only since binutils:
+#
+# - 2.30 for linking with ld.gold (gold version is 1.15);
+# - last 2.30 or 2.31 in case of ld.bfd.
+
+# This cmake module exports CMP0069 policy and should be included
+# with NO_POLICY_SCOPE option.
+
+# The file gives an error if LTO is requested, but cannot be
+# enabled for some reason.
+
+if (NOT DEFINED ENABLE_LTO)
+ set(ENABLE_LTO OFF)
+endif()
+
+# Disable LTO if not requested.
+if (NOT ENABLE_LTO)
+ message(STATUS "Enabling LTO: FALSE")
+ return()
+endif()
+
+if(CMAKE_VERSION VERSION_LESS 3.9)
+ message(FATAL_ERROR "cmake >= 3.9 is needed for LTO enabling")
+endif()
+
+# Set 'CMP0069 NEW' behaviour for this project to support
+# compilers other than Intel Compiler and suppress cmake
+# warnings on the unset policy.
+cmake_policy(SET CMP0069 NEW)
+
+# Retain 'CMP0069 NEW' behaviour after
+# 'cmake_minimum_required(VERSION ...) in subprojects to
+# avoid cmake warnings on the unset policy.
+set(CMAKE_POLICY_DEFAULT_CMP0069 NEW)
+
+# Check whether LTO is supported by the compiler / toolchain and
+# give an error otherwise.
+include(CheckIPOSupported)
+check_ipo_supported(RESULT CMAKE_IPO_AVAILABLE)
+if (NOT CMAKE_IPO_AVAILABLE)
+ message(FATAL_ERROR "LTO is not supported by the compiler / toolchain")
+endif()
+
+# Extra checks on Linux whether all needed LTO features are
+# supported. Mac OS seems to work correctly with xcode >= 8.
+if (NOT TARGET_OS_DARWIN)
+ execute_process(
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ COMMAND ld -v OUTPUT_VARIABLE linker_version_str)
+ message(STATUS "ld version string: ${linker_version_str}")
+
+ # GNU ld (Gentoo 2.31.1 p3) 2.31.1
+ # GNU ld (GNU Binutils for Ubuntu) 2.30
+ # GNU ld version 2.27-10.el7
+ string(REGEX MATCH "^GNU ld.* (2\\.[0-9]+)[^ ]*$" matched_bfd
+ ${linker_version_str})
+
+ # GNU gold (Gentoo 2.31.1 p3 2.31.1) 1.16
+ # GNU gold (GNU Binutils for Ubuntu 2.30) 1.15
+ # GNU gold (version 2.27-10.el7) 1.12
+ if (NOT matched_bfd)
+ string(REGEX MATCH "^GNU gold.* (1\\.[0-9]+)[^ ]*$" matched_gold
+ ${linker_version_str})
+ endif()
+
+ if(matched_bfd)
+ set(linker_version ${CMAKE_MATCH_1})
+ message(STATUS "Found ld.bfd version: ${linker_version}")
+
+ if (linker_version VERSION_LESS "2.31")
+ message(FATAL_ERROR "ld.bfd >= 2.31 is needed for LTO")
+ endif()
+ elseif(matched_gold)
+ set(linker_version ${CMAKE_MATCH_1})
+ message(STATUS "Found ld.gold version: ${linker_version}")
+
+ if (linker_version VERSION_LESS "1.15")
+ message(FATAL_ERROR "ld.gold >= 1.15 is needed for LTO")
+ endif()
+ else()
+ message(FATAL_ERROR "Unsupported ld version format")
+ endif()
+endif()
+
+# gh-3742: investigate LTO warnings.
+set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wno-lto-type-mismatch")
+
+set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
+message(STATUS "Enabling LTO: TRUE")
--
2.19.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [tarantool-patches] Re: [PATCH v2 2/3] Add LTO support
2018-10-14 23:17 ` [tarantool-patches] [PATCH v2 2/3] Add LTO support Alexander Turenko
@ 2018-10-16 18:09 ` Konstantin Osipov
2018-10-17 7:13 ` Alexander Turenko
0 siblings, 1 reply; 9+ messages in thread
From: Konstantin Osipov @ 2018-10-16 18:09 UTC (permalink / raw)
To: tarantool-patches; +Cc: Georgy Kirichenko, AKhatskevich
* Alexander Turenko <alexander.turenko@tarantool.org> [18/10/15 10:15]:
> From: AKhatskevich <avkhatskevich@tarantool.org>
>
> Added -DENABLE_LTO=ON/OFF cmake option, OFF by default.
>
> LTO speeds up cpu-intensive workloads by up to 20% (see [1] and [2]).
>
> Requirements for LTO enabling:
to enable LTO, not "for LTO enabling".
The same applies to cmake message:
> +if(CMAKE_VERSION VERSION_LESS 3.9)
> + message(FATAL_ERROR "cmake >= 3.9 is needed for LTO enabling")
> +endif()
> +
> +# Set 'CMP0069 NEW' behaviour for this project to support
> +# compilers other than Intel Compiler and suppress cmake
> +# warnings on the unset policy.
> +cmake_policy(SET CMP0069 NEW)
Please describe what this policy is about, not only just what it
is for.
> +
> +# Retain 'CMP0069 NEW' behaviour after
> +# 'cmake_minimum_required(VERSION ...) in subprojects to
> +# avoid cmake warnings on the unset policy.
> +set(CMAKE_POLICY_DEFAULT_CMP0069 NEW)
--
Konstantin Osipov, Moscow, Russia, +7 903 626 22 32
http://tarantool.io - www.twitter.com/kostja_osipov
^ permalink raw reply [flat|nested] 9+ messages in thread
* [tarantool-patches] Re: [PATCH v2 2/3] Add LTO support
2018-10-16 18:09 ` [tarantool-patches] " Konstantin Osipov
@ 2018-10-17 7:13 ` Alexander Turenko
2018-10-25 11:17 ` Georgy Kirichenko
0 siblings, 1 reply; 9+ messages in thread
From: Alexander Turenko @ 2018-10-17 7:13 UTC (permalink / raw)
To: Konstantin Osipov; +Cc: tarantool-patches, Georgy Kirichenko, AKhatskevich
On Tue, Oct 16, 2018 at 09:09:02PM +0300, Konstantin Osipov wrote:
> * Alexander Turenko <alexander.turenko@tarantool.org> [18/10/15 10:15]:
> > From: AKhatskevich <avkhatskevich@tarantool.org>
> >
> > Added -DENABLE_LTO=ON/OFF cmake option, OFF by default.
> >
> > LTO speeds up cpu-intensive workloads by up to 20% (see [1] and [2]).
> >
> > Requirements for LTO enabling:
>
> to enable LTO, not "for LTO enabling".
>
> The same applies to cmake message:
> > +if(CMAKE_VERSION VERSION_LESS 3.9)
> > + message(FATAL_ERROR "cmake >= 3.9 is needed for LTO enabling")
> > +endif()
>
Fixed.
>
> > +
> > +# Set 'CMP0069 NEW' behaviour for this project to support
> > +# compilers other than Intel Compiler and suppress cmake
> > +# warnings on the unset policy.
> > +cmake_policy(SET CMP0069 NEW)
>
> Please describe what this policy is about, not only just what it
> is for.
>
-# Set 'CMP0069 NEW' behaviour for this project to support
-# compilers other than Intel Compiler and suppress cmake
-# warnings on the unset policy.
+# 'CMP0069 NEW' behaviour enables LTO for compilers other then
+# Intel Compiler when CMAKE_INTERPROCEDURAL_OPTIMIZATION is
+# enabled and provides CheckIPOSupported module. We set the policy
+# to support LTO with GCC / Clang and to suppress cmake warnings
+# on the unset policy.
> > +
> > +# Retain 'CMP0069 NEW' behaviour after
> > +# 'cmake_minimum_required(VERSION ...) in subprojects to
> > +# avoid cmake warnings on the unset policy.
> > +set(CMAKE_POLICY_DEFAULT_CMP0069 NEW)
>
>
> --
> Konstantin Osipov, Moscow, Russia, +7 903 626 22 32
> http://tarantool.io - www.twitter.com/kostja_osipov
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [tarantool-patches] Re: [PATCH v2 2/3] Add LTO support
2018-10-17 7:13 ` Alexander Turenko
@ 2018-10-25 11:17 ` Georgy Kirichenko
0 siblings, 0 replies; 9+ messages in thread
From: Georgy Kirichenko @ 2018-10-25 11:17 UTC (permalink / raw)
To: Alexander Turenko; +Cc: Konstantin Osipov, tarantool-patches, AKhatskevich
[-- Attachment #1: Type: text/plain, Size: 1677 bytes --]
Seems OK
On Wednesday, October 17, 2018 10:13:25 AM MSK Alexander Turenko wrote:
> On Tue, Oct 16, 2018 at 09:09:02PM +0300, Konstantin Osipov wrote:
> > * Alexander Turenko <alexander.turenko@tarantool.org> [18/10/15 10:15]:
> > > From: AKhatskevich <avkhatskevich@tarantool.org>
> > >
> > > Added -DENABLE_LTO=ON/OFF cmake option, OFF by default.
> > >
> > > LTO speeds up cpu-intensive workloads by up to 20% (see [1] and [2]).
> >
> > > Requirements for LTO enabling:
> > to enable LTO, not "for LTO enabling".
> >
> > The same applies to cmake message:
> > > +if(CMAKE_VERSION VERSION_LESS 3.9)
> > > + message(FATAL_ERROR "cmake >= 3.9 is needed for LTO enabling")
> > > +endif()
>
> Fixed.
>
> > > +
> > > +# Set 'CMP0069 NEW' behaviour for this project to support
> > > +# compilers other than Intel Compiler and suppress cmake
> > > +# warnings on the unset policy.
> > > +cmake_policy(SET CMP0069 NEW)
> >
> > Please describe what this policy is about, not only just what it
> > is for.
>
> -# Set 'CMP0069 NEW' behaviour for this project to support
> -# compilers other than Intel Compiler and suppress cmake
> -# warnings on the unset policy.
> +# 'CMP0069 NEW' behaviour enables LTO for compilers other then
> +# Intel Compiler when CMAKE_INTERPROCEDURAL_OPTIMIZATION is
> +# enabled and provides CheckIPOSupported module. We set the policy
> +# to support LTO with GCC / Clang and to suppress cmake warnings
> +# on the unset policy.
>
> > > +
> > > +# Retain 'CMP0069 NEW' behaviour after
> > > +# 'cmake_minimum_required(VERSION ...) in subprojects to
> > > +# avoid cmake warnings on the unset policy.
> > > +set(CMAKE_POLICY_DEFAULT_CMP0069 NEW)
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* [tarantool-patches] [PATCH v2 3/3] test: add LTO targets into CI
2018-10-14 23:17 [tarantool-patches] [PATCH v2 0/3] Add LTO support Alexander Turenko
2018-10-14 23:17 ` [tarantool-patches] [PATCH v2 1/3] test: prevent guard-breaker optimization with LTO Alexander Turenko
2018-10-14 23:17 ` [tarantool-patches] [PATCH v2 2/3] Add LTO support Alexander Turenko
@ 2018-10-14 23:17 ` Alexander Turenko
2018-10-25 11:16 ` [tarantool-patches] " Georgy Kirichenko
2018-10-25 12:18 ` [tarantool-patches] Re: [PATCH v2 0/3] Add LTO support Kirill Yukhin
3 siblings, 1 reply; 9+ messages in thread
From: Alexander Turenko @ 2018-10-14 23:17 UTC (permalink / raw)
To: Georgy Kirichenko; +Cc: AKhatskevich, tarantool-patches
From: AKhatskevich <avkhatskevich@tarantool.org>
---
.travis.mk | 4 ++--
.travis.yml | 8 ++++++++
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/.travis.mk b/.travis.mk
index 88335474c..1b7d05149 100644
--- a/.travis.mk
+++ b/.travis.mk
@@ -40,7 +40,7 @@ deps_ubuntu:
lcov ruby
test_ubuntu: deps_ubuntu
- cmake . -DCMAKE_BUILD_TYPE=RelWithDebInfoWError
+ cmake . -DCMAKE_BUILD_TYPE=RelWithDebInfoWError ${CMAKE_EXTRA_PARAMS}
make -j8
cd test && /usr/bin/python test-run.py -j 1
@@ -49,7 +49,7 @@ deps_osx:
brew install openssl readline curl icu4c --force
test_osx: deps_osx
- cmake . -DCMAKE_BUILD_TYPE=RelWithDebInfoWError
+ cmake . -DCMAKE_BUILD_TYPE=RelWithDebInfoWError ${CMAKE_EXTRA_PARAMS}
# Increase the maximum number of open file descriptors on macOS
sudo sysctl -w kern.maxfiles=20480 || :
sudo sysctl -w kern.maxfilesperproc=20480 || :
diff --git a/.travis.yml b/.travis.yml
index a9d1036da..dbd8c91c0 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -33,6 +33,14 @@ matrix:
os: osx
- name: Debug build + test + coverage (Linux, gcc)
env: TARGET=coverage
+ - name: LTO build + test (Linux, gcc)
+ env: TARGET=test CMAKE_EXTRA_PARAMS=-DENABLE_LTO=ON
+ - name: LTO build + test (Linux, clang)
+ env: TARGET=test CMAKE_EXTRA_PARAMS=-DENABLE_LTO=ON
+ compiler: clang
+ - name: LTO build + test (OS X)
+ os: osx
+ env: TARGET=test CMAKE_EXTRA_PARAMS=-DENABLE_LTO=ON
- name: CentOS 6 build + test + deploy RPM
env: OS=el DIST=6
- name: CentOS 7 build + test + deploy RPM
--
2.19.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [tarantool-patches] Re: [PATCH v2 3/3] test: add LTO targets into CI
2018-10-14 23:17 ` [tarantool-patches] [PATCH v2 3/3] test: add LTO targets into CI Alexander Turenko
@ 2018-10-25 11:16 ` Georgy Kirichenko
0 siblings, 0 replies; 9+ messages in thread
From: Georgy Kirichenko @ 2018-10-25 11:16 UTC (permalink / raw)
To: Alexander Turenko; +Cc: AKhatskevich, tarantool-patches
[-- Attachment #1: Type: text/plain, Size: 1788 bytes --]
Seems Ok
On Monday, October 15, 2018 2:17:39 AM MSK Alexander Turenko wrote:
> From: AKhatskevich <avkhatskevich@tarantool.org>
>
> ---
> .travis.mk | 4 ++--
> .travis.yml | 8 ++++++++
> 2 files changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/.travis.mk b/.travis.mk
> index 88335474c..1b7d05149 100644
> --- a/.travis.mk
> +++ b/.travis.mk
> @@ -40,7 +40,7 @@ deps_ubuntu:
> lcov ruby
>
> test_ubuntu: deps_ubuntu
> - cmake . -DCMAKE_BUILD_TYPE=RelWithDebInfoWError
> + cmake . -DCMAKE_BUILD_TYPE=RelWithDebInfoWError ${CMAKE_EXTRA_PARAMS}
> make -j8
> cd test && /usr/bin/python test-run.py -j 1
>
> @@ -49,7 +49,7 @@ deps_osx:
> brew install openssl readline curl icu4c --force
>
> test_osx: deps_osx
> - cmake . -DCMAKE_BUILD_TYPE=RelWithDebInfoWError
> + cmake . -DCMAKE_BUILD_TYPE=RelWithDebInfoWError ${CMAKE_EXTRA_PARAMS}
> # Increase the maximum number of open file descriptors on macOS
> sudo sysctl -w kern.maxfiles=20480 || :
> sudo sysctl -w kern.maxfilesperproc=20480 || :
> diff --git a/.travis.yml b/.travis.yml
> index a9d1036da..dbd8c91c0 100644
> --- a/.travis.yml
> +++ b/.travis.yml
> @@ -33,6 +33,14 @@ matrix:
> os: osx
> - name: Debug build + test + coverage (Linux, gcc)
> env: TARGET=coverage
> + - name: LTO build + test (Linux, gcc)
> + env: TARGET=test CMAKE_EXTRA_PARAMS=-DENABLE_LTO=ON
> + - name: LTO build + test (Linux, clang)
> + env: TARGET=test CMAKE_EXTRA_PARAMS=-DENABLE_LTO=ON
> + compiler: clang
> + - name: LTO build + test (OS X)
> + os: osx
> + env: TARGET=test CMAKE_EXTRA_PARAMS=-DENABLE_LTO=ON
> - name: CentOS 6 build + test + deploy RPM
> env: OS=el DIST=6
> - name: CentOS 7 build + test + deploy RPM
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* [tarantool-patches] Re: [PATCH v2 0/3] Add LTO support
2018-10-14 23:17 [tarantool-patches] [PATCH v2 0/3] Add LTO support Alexander Turenko
` (2 preceding siblings ...)
2018-10-14 23:17 ` [tarantool-patches] [PATCH v2 3/3] test: add LTO targets into CI Alexander Turenko
@ 2018-10-25 12:18 ` Kirill Yukhin
3 siblings, 0 replies; 9+ messages in thread
From: Kirill Yukhin @ 2018-10-25 12:18 UTC (permalink / raw)
To: tarantool-patches; +Cc: Georgy Kirichenko, Alexander Turenko
Hello,
On 15 Oct 02:17, Alexander Turenko wrote:
> Changes since the last Alex's patch:
>
> * Discarded submodules update in order to use
> `set(CMAKE_POLICY_DEFAULT_CMP0069 NEW)` (deleted the branches).
> * Splitted ld / gold version parsing.
> * Always give an error when LTO is requested, but cannot be enabled for
> some reason.
> * Added more comments to cmake/lto.cmake.
> * Suppressed -Wlto-type-mismatch wargings, filed #3742.
> * Noted that LuaJIT will not be subject for LTO, filed #3743.
> * Rebased on top of fresh 1.10, rewrote CI targets definitions.
>
> https://github.com/tarantool/tarantool/issues/3117
> https://github.com/tarantool/tarantool/tree/kh/gh-3117-lto-3
> https://travis-ci.org/tarantool/tarantool/builds/441418628
I've checked the patchset into 2.1 branch.
--
Regards, Kirill Yukhin
^ permalink raw reply [flat|nested] 9+ messages in thread