From cd44e0daa191e52d6bd7e0093f0d7d563ce3eb27 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Mon, 25 Sep 2023 15:23:58 +1000 Subject: [PATCH] Move a few task stacks into internal ram for better speed --- src/tasks/tasks.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/tasks/tasks.cpp b/src/tasks/tasks.cpp index 0d9169a5..002d6e56 100644 --- a/src/tasks/tasks.cpp +++ b/src/tasks/tasks.cpp @@ -49,15 +49,15 @@ auto AllocateStack() -> cpp::span; // usually written with embedded use cases in mind. template <> auto AllocateStack() -> cpp::span { - std::size_t size = 64 * 1024; - return {static_cast(heap_caps_malloc(size, MALLOC_CAP_SPIRAM)), - size}; + constexpr std::size_t size = 24 * 1024; + static StackType_t sStack[size]; + return {sStack, size}; } // LVGL requires only a relatively small stack. However, it can be allocated in // PSRAM so we give it a bit of headroom for safety. template <> auto AllocateStack() -> cpp::span { - std::size_t size = 32 * 1024; + constexpr std::size_t size = 24 * 1024; return {static_cast(heap_caps_malloc(size, MALLOC_CAP_SPIRAM)), size}; } @@ -66,9 +66,9 @@ template <> // entirely with PSRAM-allocated buffers, so no real speed gain from allocating // it internally. auto AllocateStack() -> cpp::span { - std::size_t size = 4 * 1024; - return {static_cast(heap_caps_malloc(size, MALLOC_CAP_SPIRAM)), - size}; + constexpr std::size_t size = 4 * 1024; + static StackType_t sStack[size]; + return {sStack, size}; } // Leveldb is designed for non-embedded use cases, where stack space isn't so // much of a concern. It therefore uses an eye-wateringly large amount of stack. @@ -86,10 +86,9 @@ auto AllocateStack() -> cpp::span { } template <> auto AllocateStack() -> cpp::span { - std::size_t size = 4 * 1024; - return {static_cast( - heap_caps_malloc(size, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT)), - size}; + constexpr std::size_t size = 4 * 1024; + static StackType_t sStack[size]; + return {sStack, size}; } // 2 KiB in internal ram