From aba8380e3936705f7fe5b081bcbe76ab9a794f43 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Mon, 23 Sep 2024 18:40:47 +0200 Subject: [PATCH] iox-#2301 Add cmake flags to build experimental 32-64 bit mix mode --- iceoryx_meta/build_options.cmake | 2 + iceoryx_posh/BUILD.bazel | 4 ++ .../cmake/IceoryxPoshDeployment.cmake | 9 +++ .../cmake/iceoryx_posh_deployment.hpp.in | 57 ++++++++++++------- .../condition_variable_data.hpp | 9 +-- .../popo/building_blocks/locking_policy.hpp | 9 +-- .../condition_variable_data.cpp | 8 ++- .../popo/building_blocks/locking_policy.cpp | 2 +- tools/iceoryx_build_test.sh | 9 +++ 9 files changed, 69 insertions(+), 40 deletions(-) diff --git a/iceoryx_meta/build_options.cmake b/iceoryx_meta/build_options.cmake index 8986a807b0..4a55062ebc 100644 --- a/iceoryx_meta/build_options.cmake +++ b/iceoryx_meta/build_options.cmake @@ -36,6 +36,7 @@ option(THREAD_SANITIZER "Build with thread sanitizer" OFF) option(TEST_WITH_ADDITIONAL_USER "Build Test with additional user accounts for testing access control" OFF) option(TEST_WITH_HUGE_PAYLOAD "Build Tests which use payload bigger than 2GB" OFF) option(TOML_CONFIG "TOML support for RouDi with dynamic configuration" ON) +option(IOX_EXPERIMENTAL_32_64_BIT_MIX_MODE "Enable experimental 32<->64 bit mix mode zero-copy communication" OFF) option(IOX_EXPERIMENTAL_POSH "Export experimental posh features (no guarantees)" OFF) option(IOX_REPRODUCIBLE_BUILD "Create reproducible builds by omit setting the build timestamp in the version header" ON) @@ -95,6 +96,7 @@ function(show_config_options) message(" TEST_WITH_ADDITIONAL_USER ...........: " ${TEST_WITH_ADDITIONAL_USER}) message(" TEST_WITH_HUGE_PAYLOAD ..............: " ${TEST_WITH_HUGE_PAYLOAD}) message(" TOML_CONFIG..........................: " ${TOML_CONFIG}) + message(" IOX_EXPERIMENTAL_32_64_BIT_MIX_MODE..: " ${IOX_EXPERIMENTAL_32_64_BIT_MIX_MODE}) message(" IOX_EXPERIMENTAL_POSH................: " ${IOX_EXPERIMENTAL_POSH}) message(" IOX_REPRODUCIBLE_BUILD...............: " ${IOX_REPRODUCIBLE_BUILD}) endfunction() diff --git a/iceoryx_posh/BUILD.bazel b/iceoryx_posh/BUILD.bazel index b72023af3e..a86d67e738 100644 --- a/iceoryx_posh/BUILD.bazel +++ b/iceoryx_posh/BUILD.bazel @@ -31,6 +31,8 @@ configure_file( "IOX_COMMUNICATION_POLICY": "ManyToManyPolicy", "IOX_DEFAULT_RESOURCE_PREFIX": "iox1", "IOX_EXPERIMENTAL_POSH_FLAG": "false", + "IOX_INTERPROCESS_LOCK": "mutex", + "IOX_INTERPROCESS_SEMAPHORE": "UnnamedSemaphore", "IOX_MAX_CHUNKS_ALLOCATED_PER_PUBLISHER_SIMULTANEOUSLY": "8", "IOX_MAX_CHUNKS_HELD_PER_SUBSCRIBER_SIMULTANEOUSLY": "256", "IOX_MAX_CLIENTS_PER_SERVER": "256", @@ -58,6 +60,8 @@ configure_file( "IOX_COMMUNICATION_POLICY": "ManyToManyPolicy", "IOX_DEFAULT_RESOURCE_PREFIX": "iox1", "IOX_EXPERIMENTAL_POSH_FLAG": "false", + "IOX_INTERPROCESS_LOCK": "mutex", + "IOX_INTERPROCESS_SEMAPHORE": "UnnamedSemaphore", "IOX_MAX_CHUNKS_ALLOCATED_PER_PUBLISHER_SIMULTANEOUSLY": "8", "IOX_MAX_CHUNKS_HELD_PER_SUBSCRIBER_SIMULTANEOUSLY": "256", "IOX_MAX_CLIENTS_PER_SERVER": "256", diff --git a/iceoryx_posh/cmake/IceoryxPoshDeployment.cmake b/iceoryx_posh/cmake/IceoryxPoshDeployment.cmake index 5ed93e67af..864c643fed 100644 --- a/iceoryx_posh/cmake/IceoryxPoshDeployment.cmake +++ b/iceoryx_posh/cmake/IceoryxPoshDeployment.cmake @@ -142,6 +142,15 @@ if(IOX_EXPERIMENTAL_POSH) else() set(IOX_EXPERIMENTAL_POSH_FLAG false) endif() + +if(IOX_EXPERIMENTAL_32_64_BIT_MIX_MODE) + set(IOX_INTERPROCESS_LOCK concurrent::SpinLock) + set(IOX_INTERPROCESS_SEMAPHORE concurrent::SpinSemaphore) +else() + set(IOX_INTERPROCESS_LOCK mutex) + set(IOX_INTERPROCESS_SEMAPHORE UnnamedSemaphore) +endif() + message(STATUS "[i] IOX_EXPERIMENTAL_POSH_FLAG: ${IOX_EXPERIMENTAL_POSH_FLAG}") message(STATUS "[i] <<<<<<<<<<<<<< End iceoryx_posh configuration: >>>>>>>>>>>>>>") diff --git a/iceoryx_posh/cmake/iceoryx_posh_deployment.hpp.in b/iceoryx_posh/cmake/iceoryx_posh_deployment.hpp.in index 71aa6126ca..ee0bd31e2d 100644 --- a/iceoryx_posh/cmake/iceoryx_posh_deployment.hpp.in +++ b/iceoryx_posh/cmake/iceoryx_posh_deployment.hpp.in @@ -21,6 +21,19 @@ namespace iox { +class mutex; +class UnnamedSemaphore; +namespace concurrent +{ +class SpinLock; +class SpinSemaphore; +} +namespace build +{ +using InterProcessLock = @IOX_INTERPROCESS_LOCK@; +using InterProcessSemaphore = @IOX_INTERPROCESS_SEMAPHORE@; +} + namespace popo { class SubscriberPortSingleProducer; @@ -46,28 +59,28 @@ constexpr uint32_t IOX_MAX_CHUNKS_ALLOCATED_PER_PUBLISHER_SIMULTANEOUSLY = constexpr uint64_t IOX_MAX_PUBLISHER_HISTORY = static_cast(@IOX_MAX_PUBLISHER_HISTORY@); constexpr uint32_t IOX_MAX_CHUNKS_HELD_PER_SUBSCRIBER_SIMULTANEOUSLY = static_cast(@IOX_MAX_CHUNKS_HELD_PER_SUBSCRIBER_SIMULTANEOUSLY@); - constexpr uint32_t IOX_MAX_NUMBER_OF_NOTIFIERS = static_cast(@IOX_MAX_NUMBER_OF_NOTIFIERS@); - constexpr uint32_t IOX_MAX_PROCESS_NUMBER = static_cast(@IOX_MAX_PROCESS_NUMBER@); - // NOTE: this is currently only used in the experimental API and corresponds to 'IOX_MAX_PROCESS_NUMBER' - // due to a limitation in the 'PointerRepository' - constexpr uint32_t IOX_MAX_NODE_NUMBER = static_cast(@IOX_MAX_NODE_NUMBER@); - // NOTE: this is currently set to 1 due to the limitation in the 'PointerRepository' - constexpr uint32_t IOX_MAX_NODE_PER_PROCESS = static_cast(@IOX_MAX_NODE_PER_PROCESS@); - constexpr uint32_t IOX_MAX_SHM_SEGMENTS = static_cast(@IOX_MAX_SHM_SEGMENTS@); - constexpr uint32_t IOX_MAX_NUMBER_OF_MEMPOOLS = static_cast(@IOX_MAX_NUMBER_OF_MEMPOOLS@); - constexpr uint32_t IOX_MAX_NUMBER_OF_CONDITION_VARIABLES = - static_cast(@IOX_MAX_NUMBER_OF_CONDITION_VARIABLES@); - constexpr uint32_t IOX_MAX_NODE_NAME_LENGTH = static_cast(@IOX_MAX_NODE_NAME_LENGTH@); - constexpr uint32_t IOX_MAX_ID_STRING_LENGTH = static_cast(@IOX_MAX_ID_STRING_LENGTH@); - constexpr uint32_t IOX_MAX_RUNTIME_NAME_LENGTH = static_cast(@IOX_MAX_RUNTIME_NAME_LENGTH@); - constexpr uint32_t IOX_MAX_RESPONSES_PROCESSED_SIMULTANEOUSLY = - static_cast(@IOX_MAX_RESPONSES_PROCESSED_SIMULTANEOUSLY@); - constexpr uint32_t IOX_MAX_RESPONSE_QUEUE_CAPACITY = static_cast(@IOX_MAX_RESPONSE_QUEUE_CAPACITY@); - constexpr uint32_t IOX_MAX_REQUEST_QUEUE_CAPACITY = static_cast(@IOX_MAX_REQUEST_QUEUE_CAPACITY@); - constexpr uint32_t IOX_MAX_CLIENTS_PER_SERVER = static_cast(@IOX_MAX_CLIENTS_PER_SERVER@); - constexpr uint32_t IOX_MAX_REQUESTS_PROCESSED_SIMULTANEOUSLY = static_cast(@IOX_MAX_REQUESTS_PROCESSED_SIMULTANEOUSLY@); - constexpr const char IOX_DEFAULT_RESOURCE_PREFIX[] = "@IOX_DEFAULT_RESOURCE_PREFIX@"; - constexpr bool IOX_EXPERIMENTAL_POSH_FLAG = @IOX_EXPERIMENTAL_POSH_FLAG@; +constexpr uint32_t IOX_MAX_NUMBER_OF_NOTIFIERS = static_cast(@IOX_MAX_NUMBER_OF_NOTIFIERS@); +constexpr uint32_t IOX_MAX_PROCESS_NUMBER = static_cast(@IOX_MAX_PROCESS_NUMBER@); +// NOTE: this is currently only used in the experimental API and corresponds to 'IOX_MAX_PROCESS_NUMBER' +// due to a limitation in the 'PointerRepository' +constexpr uint32_t IOX_MAX_NODE_NUMBER = static_cast(@IOX_MAX_NODE_NUMBER@); +// NOTE: this is currently set to 1 due to the limitation in the 'PointerRepository' +constexpr uint32_t IOX_MAX_NODE_PER_PROCESS = static_cast(@IOX_MAX_NODE_PER_PROCESS@); +constexpr uint32_t IOX_MAX_SHM_SEGMENTS = static_cast(@IOX_MAX_SHM_SEGMENTS@); +constexpr uint32_t IOX_MAX_NUMBER_OF_MEMPOOLS = static_cast(@IOX_MAX_NUMBER_OF_MEMPOOLS@); +constexpr uint32_t IOX_MAX_NUMBER_OF_CONDITION_VARIABLES = + static_cast(@IOX_MAX_NUMBER_OF_CONDITION_VARIABLES@); +constexpr uint32_t IOX_MAX_NODE_NAME_LENGTH = static_cast(@IOX_MAX_NODE_NAME_LENGTH@); +constexpr uint32_t IOX_MAX_ID_STRING_LENGTH = static_cast(@IOX_MAX_ID_STRING_LENGTH@); +constexpr uint32_t IOX_MAX_RUNTIME_NAME_LENGTH = static_cast(@IOX_MAX_RUNTIME_NAME_LENGTH@); +constexpr uint32_t IOX_MAX_RESPONSES_PROCESSED_SIMULTANEOUSLY = + static_cast(@IOX_MAX_RESPONSES_PROCESSED_SIMULTANEOUSLY@); +constexpr uint32_t IOX_MAX_RESPONSE_QUEUE_CAPACITY = static_cast(@IOX_MAX_RESPONSE_QUEUE_CAPACITY@); +constexpr uint32_t IOX_MAX_REQUEST_QUEUE_CAPACITY = static_cast(@IOX_MAX_REQUEST_QUEUE_CAPACITY@); +constexpr uint32_t IOX_MAX_CLIENTS_PER_SERVER = static_cast(@IOX_MAX_CLIENTS_PER_SERVER@); +constexpr uint32_t IOX_MAX_REQUESTS_PROCESSED_SIMULTANEOUSLY = static_cast(@IOX_MAX_REQUESTS_PROCESSED_SIMULTANEOUSLY@); +constexpr const char IOX_DEFAULT_RESOURCE_PREFIX[] = "@IOX_DEFAULT_RESOURCE_PREFIX@"; +constexpr bool IOX_EXPERIMENTAL_POSH_FLAG = @IOX_EXPERIMENTAL_POSH_FLAG@; // clang-format on } // namespace build } // namespace iox diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/condition_variable_data.hpp b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/condition_variable_data.hpp index 787c9926c2..7406da1583 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/condition_variable_data.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/condition_variable_data.hpp @@ -17,6 +17,7 @@ #ifndef IOX_POSH_POPO_BUILDING_BLOCKS_CONDITION_VARIABLE_DATA_HPP #define IOX_POSH_POPO_BUILDING_BLOCKS_CONDITION_VARIABLE_DATA_HPP +#include "iceoryx_posh/iceoryx_posh_deployment.hpp" #include "iceoryx_posh/iceoryx_posh_types.hpp" #include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iox/atomic.hpp" @@ -27,12 +28,6 @@ namespace iox { namespace popo { -#ifdef IOX_EXPERIMENTAL_32_64_BIT_MIX_MODE -using InterProcessSemaphore = concurrent::SpinSemaphore; -#else -using InterProcessSemaphore = UnnamedSemaphore; -#endif - struct ConditionVariableData { ConditionVariableData() noexcept; @@ -44,7 +39,7 @@ struct ConditionVariableData ConditionVariableData& operator=(ConditionVariableData&& rhs) = delete; ~ConditionVariableData() noexcept = default; - optional m_semaphore; + optional m_semaphore; RuntimeName_t m_runtimeName; concurrent::Atomic m_toBeDestroyed{false}; concurrent::Atomic m_activeNotifications[MAX_NUMBER_OF_NOTIFIERS]; diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/locking_policy.hpp b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/locking_policy.hpp index 7a56be3290..26881f0698 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/locking_policy.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/locking_policy.hpp @@ -16,6 +16,7 @@ #ifndef IOX_POSH_POPO_BUILDING_BLOCKS_LOCKING_POLICY_HPP #define IOX_POSH_POPO_BUILDING_BLOCKS_LOCKING_POLICY_HPP +#include "iceoryx_posh/iceoryx_posh_deployment.hpp" #include "iox/mutex.hpp" #include "iox/spin_lock.hpp" @@ -23,12 +24,6 @@ namespace iox { namespace popo { -#ifdef IOX_EXPERIMENTAL_32_64_BIT_MIX_MODE -using InterProcessLock = concurrent::SpinLock; -#else -using InterProcessLock = mutex; -#endif - class ThreadSafePolicy { public: @@ -40,7 +35,7 @@ class ThreadSafePolicy bool tryLock() const noexcept; private: - mutable optional m_lock; + mutable optional m_lock; }; class SingleThreadedPolicy diff --git a/iceoryx_posh/source/popo/building_blocks/condition_variable_data.cpp b/iceoryx_posh/source/popo/building_blocks/condition_variable_data.cpp index eacdc20597..9755d803ec 100644 --- a/iceoryx_posh/source/popo/building_blocks/condition_variable_data.cpp +++ b/iceoryx_posh/source/popo/building_blocks/condition_variable_data.cpp @@ -30,9 +30,11 @@ ConditionVariableData::ConditionVariableData() noexcept ConditionVariableData::ConditionVariableData(const RuntimeName_t& runtimeName) noexcept : m_runtimeName(runtimeName) { - InterProcessSemaphore::Builder().initialValue(0U).isInterProcessCapable(true).create(m_semaphore).or_else([](auto) { - IOX_REPORT_FATAL(PoshError::POPO__CONDITION_VARIABLE_DATA_FAILED_TO_CREATE_SEMAPHORE); - }); + build::InterProcessSemaphore::Builder() + .initialValue(0U) + .isInterProcessCapable(true) + .create(m_semaphore) + .or_else([](auto) { IOX_REPORT_FATAL(PoshError::POPO__CONDITION_VARIABLE_DATA_FAILED_TO_CREATE_SEMAPHORE); }); for (auto& id : m_activeNotifications) { diff --git a/iceoryx_posh/source/popo/building_blocks/locking_policy.cpp b/iceoryx_posh/source/popo/building_blocks/locking_policy.cpp index 8d990c4ec3..36066c4609 100644 --- a/iceoryx_posh/source/popo/building_blocks/locking_policy.cpp +++ b/iceoryx_posh/source/popo/building_blocks/locking_policy.cpp @@ -25,7 +25,7 @@ namespace popo { ThreadSafePolicy::ThreadSafePolicy() noexcept { - InterProcessLock::Builder() + build::InterProcessLock::Builder() .is_inter_process_capable(true) .lock_behavior(LockBehavior::RECURSIVE) .create(m_lock) diff --git a/tools/iceoryx_build_test.sh b/tools/iceoryx_build_test.sh index b0e4ad278c..dc44fc5680 100755 --- a/tools/iceoryx_build_test.sh +++ b/tools/iceoryx_build_test.sh @@ -51,6 +51,7 @@ TEST_HUGE_PAYLOAD="OFF" OUT_OF_TREE_FLAG="OFF" EXAMPLE_FLAG="OFF" EXPERIMENTAL_FLAG="OFF" +EXPERIMENTAL_32_64_MIX_MODE_FLAG="OFF" BUILD_ALL_FLAG="OFF" BUILD_SHARED="OFF" TOML_FLAG="ON" @@ -170,6 +171,11 @@ while (( "$#" )); do EXPERIMENTAL_FLAG="ON" shift 1 ;; + "experimental-32-64-bit-mix-mode") + echo " [i] Build experimental 32<->64 bit mix mode zero-copy communication" + EXPERIMENTAL_32_64_MIX_MODE_FLAG="ON" + shift 1 + ;; "out-of-tree") echo " [i] Out-of-tree build" OUT_OF_TREE_FLAG="ON" @@ -253,6 +259,8 @@ while (( "$#" )); do echo " doc Build and generate doxygen" echo " help Print this help" echo " examples Build all examples" + echo " experimental Build experimental features" + echo " experimental-32-64-bit-mix-mode Enable experimental 32<->64 bit mix mode zero-copy communication" echo " one-to-many-only Restrict to 1:n communication only" echo " out-of-tree Out-of-tree build for CI" echo " package Create a debian package from clean build in build_package" @@ -331,6 +339,7 @@ if [ "$NO_BUILD" == false ]; then -DROUDI_ENVIRONMENT=$ROUDI_ENV_FLAG \ -DEXAMPLES=$EXAMPLE_FLAG \ -DIOX_EXPERIMENTAL_POSH=$EXPERIMENTAL_FLAG \ + -DIOX_EXPERIMENTAL_32_64_BIT_MIX_MODE=$EXPERIMENTAL_32_64_MIX_MODE_FLAG \ -DTOML_CONFIG=$TOML_FLAG \ -DBUILD_DOC=$BUILD_DOC \ -DBINDING_C=$BINDING_C_FLAG \