Files
PX4-Autopilot/src
gguidone 4438ad7913 fix(mavlink): stop sizing the receive thread stack by sizeof(MavlinkReceiver)
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:

  before 0a0c404a08  heap (new/delete in start_helper), stack 2840
  0a0c404a08         object became a stack local, stack sizeof + 2840
  4498509426         object became a heap-resident member, term left behind

so the pairing has been wrong since 4498509426 (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 commit 61b7efcbc3)
2026-08-08 20:31:58 -07:00
..