From 108c98a691953913e5eec6dffdae4f6945155590 Mon Sep 17 00:00:00 2001 From: Peter van der Perk Date: Thu, 24 Feb 2022 18:41:42 +0100 Subject: [PATCH] Added experimental LTO kconfig option --- CMakeLists.txt | 10 +++++++++- Kconfig | 7 +++++++ .../mc_pos_control/MulticopterPositionControl.hpp | 2 +- src/modules/mc_pos_control/Takeoff/Takeoff.cpp | 8 ++++---- src/modules/mc_pos_control/Takeoff/Takeoff.hpp | 6 +++--- src/modules/mc_pos_control/Takeoff/TakeoffTest.cpp | 4 ++-- 6 files changed, 26 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f32f3966d8..c1bc1b494e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,7 +99,7 @@ # #============================================================================= -cmake_minimum_required(VERSION 3.2 FATAL_ERROR) +cmake_minimum_required(VERSION 3.9 FATAL_ERROR) set(PX4_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" CACHE FILEPATH "PX4 source directory" FORCE) set(PX4_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}" CACHE FILEPATH "PX4 binary directory" FORCE) @@ -234,6 +234,14 @@ message(STATUS "cmake build type: ${CMAKE_BUILD_TYPE}") # project(px4 CXX C ASM) +# Check if LTO option and check if toolchain supports it +if(LTO) + include(CheckIPOSupported) + check_ipo_supported() + message(AUTHOR_WARNING "LTO enabled: LTO is highly experimental and should not be used in production") + set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) +endif() + set(package-contact "px4users@googlegroups.com") set(CMAKE_CXX_STANDARD 14) diff --git a/Kconfig b/Kconfig index 425cf9fa82..a6be4d1a8c 100644 --- a/Kconfig +++ b/Kconfig @@ -51,6 +51,13 @@ menu "Toolchain" string "Architecture" default "" + config BOARD_LTO + bool "(EXPERIMENTAL) Link Time Optimization (LTO)" + default n + help + Enables LTO flag in linker + Note: Highly EXPERIMENTAL, furthermore make sure you're using a modern compiler GCC 9 or later + config BOARD_FULL_OPTIMIZATION bool "Full optmization (O3)" default n diff --git a/src/modules/mc_pos_control/MulticopterPositionControl.hpp b/src/modules/mc_pos_control/MulticopterPositionControl.hpp index 93b910cc10..856a4fa517 100644 --- a/src/modules/mc_pos_control/MulticopterPositionControl.hpp +++ b/src/modules/mc_pos_control/MulticopterPositionControl.hpp @@ -88,7 +88,7 @@ public: private: void Run() override; - Takeoff _takeoff; /**< state machine and ramp to bring the vehicle off the ground without jumps */ + TakeoffHandling _takeoff; /**< state machine and ramp to bring the vehicle off the ground without jumps */ orb_advert_t _mavlink_log_pub{nullptr}; diff --git a/src/modules/mc_pos_control/Takeoff/Takeoff.cpp b/src/modules/mc_pos_control/Takeoff/Takeoff.cpp index 1a33377b40..2e4fbc1f40 100644 --- a/src/modules/mc_pos_control/Takeoff/Takeoff.cpp +++ b/src/modules/mc_pos_control/Takeoff/Takeoff.cpp @@ -39,14 +39,14 @@ #include #include -void Takeoff::generateInitialRampValue(float velocity_p_gain) +void TakeoffHandling::generateInitialRampValue(float velocity_p_gain) { velocity_p_gain = math::max(velocity_p_gain, 0.01f); _takeoff_ramp_vz_init = -CONSTANTS_ONE_G / velocity_p_gain; } -void Takeoff::updateTakeoffState(const bool armed, const bool landed, const bool want_takeoff, - const float takeoff_desired_vz, const bool skip_takeoff, const hrt_abstime &now_us) +void TakeoffHandling::updateTakeoffState(const bool armed, const bool landed, const bool want_takeoff, + const float takeoff_desired_vz, const bool skip_takeoff, const hrt_abstime &now_us) { _spoolup_time_hysteresis.set_state_and_update(armed, now_us); @@ -109,7 +109,7 @@ void Takeoff::updateTakeoffState(const bool armed, const bool landed, const bool } } -float Takeoff::updateRamp(const float dt, const float takeoff_desired_vz) +float TakeoffHandling::updateRamp(const float dt, const float takeoff_desired_vz) { float upwards_velocity_limit = takeoff_desired_vz; diff --git a/src/modules/mc_pos_control/Takeoff/Takeoff.hpp b/src/modules/mc_pos_control/Takeoff/Takeoff.hpp index ab2a39ffc9..560b0f6ef8 100644 --- a/src/modules/mc_pos_control/Takeoff/Takeoff.hpp +++ b/src/modules/mc_pos_control/Takeoff/Takeoff.hpp @@ -53,11 +53,11 @@ enum class TakeoffState { flight = takeoff_status_s::TAKEOFF_STATE_FLIGHT }; -class Takeoff +class TakeoffHandling { public: - Takeoff() = default; - ~Takeoff() = default; + TakeoffHandling() = default; + ~TakeoffHandling() = default; // initialize parameters void setSpoolupTime(const float seconds) { _spoolup_time_hysteresis.set_hysteresis_time_from(false, seconds * 1_s); } diff --git a/src/modules/mc_pos_control/Takeoff/TakeoffTest.cpp b/src/modules/mc_pos_control/Takeoff/TakeoffTest.cpp index 865514dc98..edfe9e8eb4 100644 --- a/src/modules/mc_pos_control/Takeoff/TakeoffTest.cpp +++ b/src/modules/mc_pos_control/Takeoff/TakeoffTest.cpp @@ -38,13 +38,13 @@ TEST(TakeoffTest, Initialization) { - Takeoff takeoff; + TakeoffHandling takeoff; EXPECT_EQ(takeoff.getTakeoffState(), TakeoffState::disarmed); } TEST(TakeoffTest, RegularTakeoffRamp) { - Takeoff takeoff; + TakeoffHandling takeoff; takeoff.setSpoolupTime(1.f); takeoff.setTakeoffRampTime(2.0); takeoff.generateInitialRampValue(CONSTANTS_ONE_G / 0.5f);