refactor(firmware): run git on a dedicated large-stack thread
libgit2's init→push chain is deeply stack-hungry (~67 KB measured for a trivial config write; the push is deeper). Spike 7 sized the shared main task stack at 96 KB for it, which forced the editor build to over-reserve ~80 KB. Move git_publish onto its own std::thread (GIT_STACK = 96 KB via Builder::stack_size) and join it from main. This lets CONFIG_ESP_MAIN_TASK_STACK_SIZE drop back to 12288 — the Spike-6 value proven to run the editor plus a TLS-on-main handshake — so the editor no longer pays for git's stack. Hardware-verified: the push ran off-main (mbedTLS + FATFS) with no panic, no stack overflow, and no ENOMEM on the 96 KB spawn. This retires the earlier "time() only works on the main task" misdiagnosis for good — it was always the default 4 KB pthread stack overflowing, never thread-vs-main.
This commit is contained in:
@@ -1,20 +1,21 @@
|
||||
# Rust often needs a bit of an extra main task stack size compared to C (the default is 3K)
|
||||
# You might have to increase this further if you allocate large stack variables in the main task.
|
||||
# Bumped for the TLS handshake (Spike 6): mbedtls runs on the calling task and
|
||||
# wants several KB of stack on top of the app's own usage.
|
||||
# Bumped hard for Spike 7: libgit2's call chain is stack-hungry. Nearly every
|
||||
# function puts a `char path[GIT_PATH_MAX]` (4 KB) buffer on the stack, and the
|
||||
# repository_init → config-write → FATFS → wear-leveling chain nests ~10 of them
|
||||
# deep — a trivial config write measured ~67 KB of stack on hardware, overflowing
|
||||
# the previous 48 KB and smashing an adjacent newlib lock handle (LoadProhibited
|
||||
# in xQueueGenericSend). The push (smart-HTTP + pack + mbedTLS) is deeper still.
|
||||
# NOTE: this earlier looked like "time() only works on the main task" — but that
|
||||
# iteration ran git on a std::thread with the default 4 KB stack; the same chain
|
||||
# just overflowed sooner. It's stack depth, not thread-vs-main.
|
||||
# CAVEAT: this sdkconfig is shared with the editor build, so the editor also
|
||||
# reserves this stack for nothing. Once the push is proven, git should move to a
|
||||
# dedicated large-stack task and this can drop back to ~16 KB.
|
||||
CONFIG_ESP_MAIN_TASK_STACK_SIZE=98304
|
||||
# wants several KB of stack on top of the app's own usage. 12 KB ran the editor
|
||||
# AND a full TLS-on-main handshake on hardware — the last-known-good value for
|
||||
# this shared stack.
|
||||
#
|
||||
# Spike 7 briefly bumped this to 96 KB because libgit2's push chain is far deeper
|
||||
# (~67 KB measured for a trivial config write: nearly every function puts a 4 KB
|
||||
# `char path[GIT_PATH_MAX]` on the stack and init→config→FATFS→wear-leveling
|
||||
# nests ~10 deep). But this sdkconfig is SHARED with the editor build, so that
|
||||
# forced the editor to over-reserve ~80 KB for nothing. Git now runs on its own
|
||||
# large-stack thread instead (git_push.rs — GIT_STACK via
|
||||
# std::thread::Builder::stack_size), so this drops back to the Spike-6 value.
|
||||
# (The "time() only works on the main task" theory was a misdiagnosis: that
|
||||
# iteration ran git on a std::thread with the DEFAULT 4 KB stack and just
|
||||
# overflowed sooner — it was always stack depth, never thread-vs-main.)
|
||||
CONFIG_ESP_MAIN_TASK_STACK_SIZE=12288
|
||||
|
||||
# Increase a bit these stack sizes as they are also a bit too small by default
|
||||
CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=4096
|
||||
|
||||
Reference in New Issue
Block a user