diff --git a/boards/auterion/fmu-v6x/nuttx-config/nsh/defconfig b/boards/auterion/fmu-v6x/nuttx-config/nsh/defconfig index 6070e6696e..be964c8590 100644 --- a/boards/auterion/fmu-v6x/nuttx-config/nsh/defconfig +++ b/boards/auterion/fmu-v6x/nuttx-config/nsh/defconfig @@ -66,6 +66,7 @@ CONFIG_ARCH_STACKDUMP=y CONFIG_ARMV7M_BASEPRI_WAR=y CONFIG_ARMV7M_DCACHE=y CONFIG_ARMV7M_DTCM=y +CONFIG_STM32H7_DTCMEXCLUDE=y CONFIG_ARMV7M_ICACHE=y CONFIG_ARMV7M_MEMCPY=y CONFIG_ARMV7M_USEBASEPRI=y diff --git a/boards/auterion/fmu-v6x/src/init.cpp b/boards/auterion/fmu-v6x/src/init.cpp index 69ef472ba1..938db24c5e 100644 --- a/boards/auterion/fmu-v6x/src/init.cpp +++ b/boards/auterion/fmu-v6x/src/init.cpp @@ -74,6 +74,7 @@ #include #include #include +#include /**************************************************************************** * Pre-Processor Definitions @@ -211,6 +212,10 @@ __EXPORT int board_app_initialize(uintptr_t arg) { #if !defined(BOOTLOADER) +#ifdef HAVE_DTCM_HEAP + dtcm_initialize(); +#endif + /* Power on Interfaces */ VDD_3V3_SD_CARD_EN(true); VDD_5V_PERIPH_EN(true); diff --git a/platforms/common/include/px4_platform_common/FastAllocated.hpp b/platforms/common/include/px4_platform_common/FastAllocated.hpp new file mode 100644 index 0000000000..aa30c23e55 --- /dev/null +++ b/platforms/common/include/px4_platform_common/FastAllocated.hpp @@ -0,0 +1,57 @@ +/**************************************************************************** + * + * Copyright (c) 2026 PX4 Development Team. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + ****************************************************************************/ + +#pragma once + +#include + +/** + * Mixin that routes operator new/delete through px4_fast_malloc so that + * heap-allocated instances of hot modules land in DTCM on boards that + * have it, with transparent fallback to the regular heap everywhere else. + * + * Usage: + * class VehicleIMU : public ModuleParams, + * public FastAllocated { ... }; + * + * Call sites remain unchanged — normal `new`/`delete` syntax works. + */ +class FastAllocated +{ +public: + static void *operator new(size_t size) { return px4_fast_malloc(size); } + static void operator delete(void *ptr) noexcept { px4_fast_free(ptr); } + + /* Prevent array forms — these modules are always single instances */ + static void *operator new[](size_t) = delete; + static void operator delete[](void *) = delete; +}; diff --git a/platforms/common/include/px4_platform_common/px4_fast_alloc.h b/platforms/common/include/px4_platform_common/px4_fast_alloc.h new file mode 100644 index 0000000000..eae04edce9 --- /dev/null +++ b/platforms/common/include/px4_platform_common/px4_fast_alloc.h @@ -0,0 +1,58 @@ +/**************************************************************************** + * + * Copyright (c) 2026 PX4 Development Team. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + ****************************************************************************/ + +#pragma once + +#include + +/** + * Allocate from fast (DTCM) memory where available, falling back to the + * regular heap. On platforms without DTCM this is equivalent to malloc/free. + * + * Allocations are one-shot at module startup — the fallback to malloc on a + * full DTCM heap adds no runtime overhead to the hot path. + */ +__BEGIN_DECLS + +void *px4_fast_malloc(size_t size); +void *px4_fast_memalign(size_t alignment, size_t size); +void px4_fast_free(void *ptr); + +__END_DECLS + +/* Cache-aligned fast alloc: uses DTCM (cache-bypass, alignment irrelevant) when + * available, falls back to memalign() on cached SRAM so cache maintenance stays safe. */ +#if defined(ARMV7M_DCACHE_LINESIZE) +# define px4_fast_cache_aligned_alloc(s) px4_fast_memalign(ARMV7M_DCACHE_LINESIZE, (s)) +#else +# define px4_fast_cache_aligned_alloc(s) px4_fast_malloc(s) +#endif diff --git a/platforms/common/uORB/uORBDeviceNode.cpp b/platforms/common/uORB/uORBDeviceNode.cpp index fd4ef60e63..7b279ae949 100644 --- a/platforms/common/uORB/uORBDeviceNode.cpp +++ b/platforms/common/uORB/uORBDeviceNode.cpp @@ -36,6 +36,8 @@ #include "uORBUtils.hpp" #include "uORBManager.hpp" +#include + #include "SubscriptionCallback.hpp" #ifdef CONFIG_ORB_COMMUNICATOR @@ -57,7 +59,7 @@ uORB::DeviceNode::DeviceNode(const struct orb_metadata *meta, const uint8_t inst uORB::DeviceNode::~DeviceNode() { - free(_data); + px4_fast_free(_data); const char *devname = get_devname(); @@ -160,7 +162,7 @@ uORB::DeviceNode::write(cdev::file_t *filp, const char *buffer, size_t buflen) /* re-check size */ if (nullptr == _data) { const size_t data_size = _meta->o_size * _meta->o_queue; - _data = (uint8_t *) px4_cache_aligned_alloc(data_size); + _data = (uint8_t *) px4_fast_cache_aligned_alloc(data_size); if (_data) { memset(_data, 0, data_size); diff --git a/platforms/common/uORB/uORBDeviceNode.hpp b/platforms/common/uORB/uORBDeviceNode.hpp index 527c5ddf2b..0b3d482f0d 100644 --- a/platforms/common/uORB/uORBDeviceNode.hpp +++ b/platforms/common/uORB/uORBDeviceNode.hpp @@ -41,6 +41,7 @@ #include #include #include +#include #include namespace uORB @@ -59,7 +60,7 @@ class UnitTest; /** * Per-object device instance. */ -class uORB::DeviceNode : public cdev::CDev, public IntrusiveSortedListNode +class uORB::DeviceNode : public cdev::CDev, public IntrusiveSortedListNode, public FastAllocated { public: DeviceNode(const struct orb_metadata *meta, const uint8_t instance, const char *path); diff --git a/platforms/nuttx/src/px4/common/CMakeLists.txt b/platforms/nuttx/src/px4/common/CMakeLists.txt index c74810b03a..e6cbb59872 100644 --- a/platforms/nuttx/src/px4/common/CMakeLists.txt +++ b/platforms/nuttx/src/px4/common/CMakeLists.txt @@ -37,6 +37,7 @@ if(NOT PX4_BOARD MATCHES "io-v2") set(KERNEL_SRCS board_crashdump.c board_dma_alloc.c + px4_fast_alloc.cpp board_fat_dma_alloc.c console_buffer.cpp cpuload.cpp diff --git a/platforms/nuttx/src/px4/common/px4_fast_alloc.cpp b/platforms/nuttx/src/px4/common/px4_fast_alloc.cpp new file mode 100644 index 0000000000..f2ff033d08 --- /dev/null +++ b/platforms/nuttx/src/px4/common/px4_fast_alloc.cpp @@ -0,0 +1,71 @@ +/**************************************************************************** + * + * Copyright (c) 2026 PX4 Development Team. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + ****************************************************************************/ + +#include +#include +#include + +void *px4_fast_malloc(size_t size) +{ +#ifdef HAVE_DTCM_HEAP + if (g_dtcm_heap != nullptr) { + void *p = dtcm_malloc(size); + + if (p != nullptr) { + return p; + } + } + +#endif + return malloc(size); +} + +void *px4_fast_memalign(size_t alignment, size_t size) +{ + void *p = px4_fast_malloc(size); + return p ? p : memalign(alignment, size); +} + +void px4_fast_free(void *ptr) +{ +#ifdef HAVE_DTCM_HEAP + + if (g_dtcm_heap != nullptr + && ptr >= (void *)DTCM_START + && ptr < (void *)DTCM_END) { + dtcm_free(ptr); + return; + } + +#endif + free(ptr); +} diff --git a/platforms/nuttx/src/px4/stm/stm32f1/include/px4_arch/dtcm.h b/platforms/nuttx/src/px4/stm/stm32f1/include/px4_arch/dtcm.h new file mode 100644 index 0000000000..2cc0030b0c --- /dev/null +++ b/platforms/nuttx/src/px4/stm/stm32f1/include/px4_arch/dtcm.h @@ -0,0 +1,35 @@ +/**************************************************************************** + * + * Copyright (c) 2026 PX4 Development Team. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + ****************************************************************************/ + +#pragma once + +/* STM32F4 has no DTCM — HAVE_DTCM_HEAP intentionally not defined */ diff --git a/platforms/nuttx/src/px4/stm/stm32f3/include/px4_arch/dtcm.h b/platforms/nuttx/src/px4/stm/stm32f3/include/px4_arch/dtcm.h new file mode 100644 index 0000000000..2cc0030b0c --- /dev/null +++ b/platforms/nuttx/src/px4/stm/stm32f3/include/px4_arch/dtcm.h @@ -0,0 +1,35 @@ +/**************************************************************************** + * + * Copyright (c) 2026 PX4 Development Team. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + ****************************************************************************/ + +#pragma once + +/* STM32F4 has no DTCM — HAVE_DTCM_HEAP intentionally not defined */ diff --git a/platforms/nuttx/src/px4/stm/stm32f4/include/px4_arch/dtcm.h b/platforms/nuttx/src/px4/stm/stm32f4/include/px4_arch/dtcm.h new file mode 100644 index 0000000000..2cc0030b0c --- /dev/null +++ b/platforms/nuttx/src/px4/stm/stm32f4/include/px4_arch/dtcm.h @@ -0,0 +1,35 @@ +/**************************************************************************** + * + * Copyright (c) 2026 PX4 Development Team. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + ****************************************************************************/ + +#pragma once + +/* STM32F4 has no DTCM — HAVE_DTCM_HEAP intentionally not defined */ diff --git a/platforms/nuttx/src/px4/stm/stm32f7/include/px4_arch/dtcm.h b/platforms/nuttx/src/px4/stm/stm32f7/include/px4_arch/dtcm.h new file mode 100644 index 0000000000..fef640bc00 --- /dev/null +++ b/platforms/nuttx/src/px4/stm/stm32f7/include/px4_arch/dtcm.h @@ -0,0 +1,35 @@ +/**************************************************************************** + * + * Copyright (c) 2026 PX4 Development Team. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + ****************************************************************************/ + +#pragma once + +#include diff --git a/platforms/nuttx/src/px4/stm/stm32h7/include/px4_arch/dtcm.h b/platforms/nuttx/src/px4/stm/stm32h7/include/px4_arch/dtcm.h new file mode 100644 index 0000000000..fef640bc00 --- /dev/null +++ b/platforms/nuttx/src/px4/stm/stm32h7/include/px4_arch/dtcm.h @@ -0,0 +1,35 @@ +/**************************************************************************** + * + * Copyright (c) 2026 PX4 Development Team. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + ****************************************************************************/ + +#pragma once + +#include diff --git a/platforms/posix/src/px4/common/CMakeLists.txt b/platforms/posix/src/px4/common/CMakeLists.txt index e99ac9ca90..1aa41d9799 100644 --- a/platforms/posix/src/px4/common/CMakeLists.txt +++ b/platforms/posix/src/px4/common/CMakeLists.txt @@ -39,6 +39,7 @@ set(EXTRA_DEPENDS) add_library(px4_layer px4_posix_impl.cpp + px4_fast_alloc.cpp tasks.cpp ${PX4_SOURCE_DIR}/platforms/common/module_base.cpp px4_sem.cpp diff --git a/platforms/posix/src/px4/common/px4_fast_alloc.cpp b/platforms/posix/src/px4/common/px4_fast_alloc.cpp new file mode 100644 index 0000000000..26b5163a6b --- /dev/null +++ b/platforms/posix/src/px4/common/px4_fast_alloc.cpp @@ -0,0 +1,38 @@ +/**************************************************************************** + * + * Copyright (c) 2026 PX4 Development Team. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + ****************************************************************************/ + +#include +#include + +void *px4_fast_malloc(size_t size) { return malloc(size); } +void *px4_fast_memalign(size_t, size_t size) { return malloc(size); } +void px4_fast_free(void *ptr) { free(ptr); } diff --git a/src/modules/control_allocator/ControlAllocator.hpp b/src/modules/control_allocator/ControlAllocator.hpp index 99420ee95a..a2233610b6 100644 --- a/src/modules/control_allocator/ControlAllocator.hpp +++ b/src/modules/control_allocator/ControlAllocator.hpp @@ -64,6 +64,7 @@ #include #include #include +#include #include #include #include @@ -80,7 +81,7 @@ #include #include -class ControlAllocator : public ModuleBase, public ModuleParams, public px4::ScheduledWorkItem +class ControlAllocator : public ModuleBase, public ModuleParams, public px4::ScheduledWorkItem, public FastAllocated { public: static Descriptor desc; diff --git a/src/modules/ekf2/EKF2.hpp b/src/modules/ekf2/EKF2.hpp index b350d9c102..07c0665ca9 100644 --- a/src/modules/ekf2/EKF2.hpp +++ b/src/modules/ekf2/EKF2.hpp @@ -57,6 +57,7 @@ #include #include #include +#include #include #include #include @@ -130,7 +131,7 @@ extern pthread_mutex_t ekf2_module_mutex; -class EKF2 final : public ModuleParams, public px4::ScheduledWorkItem +class EKF2 final : public ModuleParams, public px4::ScheduledWorkItem, public FastAllocated { public: EKF2() = delete; diff --git a/src/modules/ekf2/EKF2Selector.hpp b/src/modules/ekf2/EKF2Selector.hpp index 535af97e6d..af011258cf 100644 --- a/src/modules/ekf2/EKF2Selector.hpp +++ b/src/modules/ekf2/EKF2Selector.hpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -64,7 +65,7 @@ using namespace time_literals; -class EKF2Selector : public ModuleParams, public px4::ScheduledWorkItem +class EKF2Selector : public ModuleParams, public px4::ScheduledWorkItem, public FastAllocated { public: EKF2Selector(); diff --git a/src/modules/gyro_fft/GyroFFT.hpp b/src/modules/gyro_fft/GyroFFT.hpp index 1c7d7da8ea..133c3d956a 100644 --- a/src/modules/gyro_fft/GyroFFT.hpp +++ b/src/modules/gyro_fft/GyroFFT.hpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -58,7 +59,7 @@ using namespace time_literals; -class GyroFFT : public ModuleBase, public ModuleParams, public px4::ScheduledWorkItem +class GyroFFT : public ModuleBase, public ModuleParams, public px4::ScheduledWorkItem, public FastAllocated { public: static Descriptor desc; diff --git a/src/modules/mc_att_control/mc_att_control.hpp b/src/modules/mc_att_control/mc_att_control.hpp index 3f5e6e17f8..bcb223f687 100644 --- a/src/modules/mc_att_control/mc_att_control.hpp +++ b/src/modules/mc_att_control/mc_att_control.hpp @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -64,7 +65,7 @@ using namespace time_literals; class MulticopterAttitudeControl : public ModuleBase, public ModuleParams, - public px4::WorkItem + public px4::WorkItem, public FastAllocated { public: static Descriptor desc; diff --git a/src/modules/mc_rate_control/MulticopterRateControl.hpp b/src/modules/mc_rate_control/MulticopterRateControl.hpp index 44c6c13bc4..0def4d7db0 100644 --- a/src/modules/mc_rate_control/MulticopterRateControl.hpp +++ b/src/modules/mc_rate_control/MulticopterRateControl.hpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -63,7 +64,7 @@ using namespace time_literals; -class MulticopterRateControl : public ModuleBase, public ModuleParams, public px4::WorkItem +class MulticopterRateControl : public ModuleBase, public ModuleParams, public px4::WorkItem, public FastAllocated { public: static Descriptor desc; diff --git a/src/modules/sensors/vehicle_acceleration/VehicleAcceleration.hpp b/src/modules/sensors/vehicle_acceleration/VehicleAcceleration.hpp index 68c0652082..9def7112a3 100644 --- a/src/modules/sensors/vehicle_acceleration/VehicleAcceleration.hpp +++ b/src/modules/sensors/vehicle_acceleration/VehicleAcceleration.hpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -56,7 +57,7 @@ using namespace time_literals; namespace sensors { -class VehicleAcceleration : public ModuleParams, public px4::ScheduledWorkItem +class VehicleAcceleration : public ModuleParams, public px4::ScheduledWorkItem, public FastAllocated { public: VehicleAcceleration(); diff --git a/src/modules/sensors/vehicle_air_data/VehicleAirData.hpp b/src/modules/sensors/vehicle_air_data/VehicleAirData.hpp index d7620d48d0..38ed0fd982 100644 --- a/src/modules/sensors/vehicle_air_data/VehicleAirData.hpp +++ b/src/modules/sensors/vehicle_air_data/VehicleAirData.hpp @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -62,7 +63,7 @@ using namespace time_literals; namespace sensors { -class VehicleAirData : public ModuleParams, public px4::ScheduledWorkItem +class VehicleAirData : public ModuleParams, public px4::ScheduledWorkItem, public FastAllocated { public: diff --git a/src/modules/sensors/vehicle_angular_velocity/VehicleAngularVelocity.hpp b/src/modules/sensors/vehicle_angular_velocity/VehicleAngularVelocity.hpp index 8aae8a3c03..1b82362c12 100644 --- a/src/modules/sensors/vehicle_angular_velocity/VehicleAngularVelocity.hpp +++ b/src/modules/sensors/vehicle_angular_velocity/VehicleAngularVelocity.hpp @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -62,7 +63,7 @@ using namespace time_literals; namespace sensors { -class VehicleAngularVelocity : public ModuleParams, public px4::ScheduledWorkItem +class VehicleAngularVelocity : public ModuleParams, public px4::ScheduledWorkItem, public FastAllocated { public: VehicleAngularVelocity(); diff --git a/src/modules/sensors/vehicle_imu/VehicleIMU.hpp b/src/modules/sensors/vehicle_imu/VehicleIMU.hpp index 689d72f614..e701ed9f76 100644 --- a/src/modules/sensors/vehicle_imu/VehicleIMU.hpp +++ b/src/modules/sensors/vehicle_imu/VehicleIMU.hpp @@ -46,6 +46,7 @@ #include #include #include +#include #include #include #include @@ -63,7 +64,7 @@ using namespace time_literals; namespace sensors { -class VehicleIMU : public ModuleParams, public px4::ScheduledWorkItem +class VehicleIMU : public ModuleParams, public px4::ScheduledWorkItem, public FastAllocated { public: VehicleIMU() = delete; diff --git a/src/modules/sensors/vehicle_magnetometer/VehicleMagnetometer.hpp b/src/modules/sensors/vehicle_magnetometer/VehicleMagnetometer.hpp index c90398fe1f..de46b0ceac 100644 --- a/src/modules/sensors/vehicle_magnetometer/VehicleMagnetometer.hpp +++ b/src/modules/sensors/vehicle_magnetometer/VehicleMagnetometer.hpp @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -65,7 +66,7 @@ using namespace time_literals; namespace sensors { -class VehicleMagnetometer : public ModuleParams, public px4::ScheduledWorkItem +class VehicleMagnetometer : public ModuleParams, public px4::ScheduledWorkItem, public FastAllocated { public: