mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-11-25 00:11:05 +08:00
The receive thread stack is requested as sizeof(MavlinkReceiver) + 2840, but the object is not on that stack. It is a member of the heap-allocated Mavlink object (mavlink_main.h), and pthread_create is handed only (void *)this, which start_trampoline casts straight back to a pointer. Every MAVLink instance therefore reserves a second copy of the object as stack the thread can never touch. The term is a leftover from a refactor round trip: before0a0c404a08heap (new/delete in start_helper), stack 28400a0c404a08object became a stack local, stack sizeof + 28404498509426object became a heap-resident member, term left behind so the pairing has been wrong since4498509426(Apr 2021). On px4_fmu-v4 sizeof(MavlinkReceiver) is 4592 and sizeof(Mavlink) is 5568, so the receiver is 82% of its heap-allocated parent. PX4_STACK_ADJUSTED is the identity on NuttX and this board has no networking, so the request was 7432 B per instance. Deepest measured high-water over the receive paths is 1908 B, 26% of that. Replaced with a flat 4000 B, 2.1x the deepest measurement, returning 3432 B per MAVLink instance. Measured on px4_fmu-v4 with CONFIG_STACK_COLORATION=y, taking top once between each of: full parameter download and rewrite, 30-item mission upload and readback, MAVFTP listing and 400 kB log download, and COMMAND_LONG handling. MAVFTP was the deepest path. Effect on hardware: with a USB ground station attached the board goes from no MAVLink heartbeat at all in 110 s to a heartbeat in 1 s. (cherry picked from commit61b7efcbc3)