Tarantool development patches archive
 help / color / mirror / Atom feed
* [tarantool-patches] [PATCH] Add LTO support
@ 2018-05-15 10:23 AKhatskevich
  2018-05-15 11:11 ` [tarantool-patches] " Alexander Turenko
  0 siblings, 1 reply; 2+ messages in thread
From: AKhatskevich @ 2018-05-15 10:23 UTC (permalink / raw)
  To: tarantool-patches

branch: kh/gh-3117-lto-2
notes:
1. This patch speeds up some workloads speeds down the other.
2. Important, lto build requires cmake >= 3.9 and binutild >= 2.30.
   cmake 3.9 requirement can be removed by implementing lto "by hand",
   however binutils 2.30 is strong requirement. binutils 2.30 was
   released in 2018.01, cmake 3.9 was released in 2017.07. That is
   why I think it do not has sense to write lto "by hand".

----------- commit message ----------

This commit introduces LTO support.

Changes:
  - update submodules (fix lto-related warnings)
  - add `TARANTOOL_LTO` cmake option (by default it is `True` only for
    non-Debug builds)

LTO speeds up cpu-intensive workloads by up to 20%.
Requirements for LTO enabling:
  - cmake >= 3.9
  - linker
    - ld >= 2.31 (or latest 2.30)
    - gold >= 1.15 (binutils 2.30)
This small patch required fixing bug in GNU ld linker.
ld was not exporting symbols from dynamic list when LTO enabled.

Closes #3117
---
 CMakeLists.txt      |  1 +
 cmake/lto.cmake     | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/lib/msgpuck     |  2 +-
 src/lib/small       |  2 +-
 third_party/libyaml |  2 +-
 5 files changed, 60 insertions(+), 3 deletions(-)
 create mode 100644 cmake/lto.cmake

diff --git a/CMakeLists.txt b/CMakeLists.txt
index d0cae0f01..432d2a6fb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -63,6 +63,7 @@ include(cmake/pod2man.cmake)
 include(cmake/arch.cmake)
 include(cmake/os.cmake)
 include(cmake/compiler.cmake)
+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..e6a6d579a
--- /dev/null
+++ b/cmake/lto.cmake
@@ -0,0 +1,56 @@
+##
+## 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 gold (gold version is 1.15)
+#  - last 2.30 or 2.31 in case of ld (dbf)
+#    (ld was fixed expecially for Tarantool,
+#    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84901)
+
+if (NOT DEFINED TARANTOOL_LTO)
+    if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
+        set(TARANTOOL_LTO TRUE)
+    else()
+        set(TARANTOOL_LTO FALSE)
+    endif()
+endif()
+
+if(NOT CMAKE_VERSION VERSION_LESS 3.9)
+    cmake_policy(SET CMP0069 NEW)
+    include(CheckIPOSupported)
+    check_ipo_supported(RESULT CMAKE_IPO_AVAILABLE)
+else()
+    set(CMAKE_IPO_AVAILABLE FALSE)
+endif()
+
+# Ensure that default value is false
+set(CMAKE_INTERPROCEDURAL_OPTIMIZATION FALSE)
+if (TARANTOOL_LTO AND CMAKE_IPO_AVAILABLE)
+    execute_process(COMMAND ld -v OUTPUT_VARIABLE linker_v)
+
+    # e.g. GNU ld (GNU Binutils) 2.29
+    string(REGEX MATCH "^GNU ld [^)]+[)] ([0-9.]+).*$" linker_valid ${linker_v})
+
+    if (NOT linker_valid)
+        message(FATAL_ERROR "Unsuported linker (ld expected)")
+    endif()
+
+    set(linker_version ${CMAKE_MATCH_1})
+    message(STATUS "Found linker ld VERSION ${linker_version}")
+
+    if (NOT linker_version VERSION_LESS "2.31")
+	set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
+    elseif(NOT linker_version VERSION_LESS "2.30")
+      # Use gold if LTO+dynamic-list is available in gold & not in ld
+      find_program(gold_available "ld.gold")
+      if (gold_available)
+	message(WARNING "Use gold linker (to enable LTO)")
+	SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold")
+	set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
+      endif()
+    endif()
+endif()
+
+message(STATUS "LTO enabled ${CMAKE_INTERPROCEDURAL_OPTIMIZATION}")
diff --git a/src/lib/msgpuck b/src/lib/msgpuck
index 3b8f3e59b..1eb56a447 160000
--- a/src/lib/msgpuck
+++ b/src/lib/msgpuck
@@ -1 +1 @@
-Subproject commit 3b8f3e59b62d74f0198e01cbec0beb9c6a3082fb
+Subproject commit 1eb56a447ea35f9c403dbc8aa98a25336303c1cb
diff --git a/src/lib/small b/src/lib/small
index 22d1bad18..0627a7f98 160000
--- a/src/lib/small
+++ b/src/lib/small
@@ -1 +1 @@
-Subproject commit 22d1bad1873edcb9b1383a273e70c4cf881d5349
+Subproject commit 0627a7f986ff91701bd741908818749fef5e2266
diff --git a/third_party/libyaml b/third_party/libyaml
index b7a1bddc7..58bc5c428 160000
--- a/third_party/libyaml
+++ b/third_party/libyaml
@@ -1 +1 @@
-Subproject commit b7a1bddc798fd8ab329785e913dc56534026d3f7
+Subproject commit 58bc5c4284b8276c6ec6711a0652b5cfee129063
-- 
2.14.1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-05-15 11:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-15 10:23 [tarantool-patches] [PATCH] Add LTO support AKhatskevich
2018-05-15 11:11 ` [tarantool-patches] " Alexander Turenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox