mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-11-25 00:30:50 +08:00
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: 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)
This commit is contained in:
1 parent
ab86cd9dab
commit
4438ad7913
1 file changed
+1
-2
@@ -4127,8 +4127,7 @@ void MavlinkReceiver::start()
|
||||
param.sched_priority = SCHED_PRIORITY_MAX - 80;
|
||||
(void)pthread_attr_setschedparam(&receiveloop_attr, ¶m);
|
||||
|
||||
pthread_attr_setstacksize(&receiveloop_attr,
|
||||
PX4_STACK_ADJUSTED(sizeof(MavlinkReceiver) + 2840 + MAVLINK_RECEIVER_NET_ADDED_STACK));
|
||||
pthread_attr_setstacksize(&receiveloop_attr, PX4_STACK_ADJUSTED(4000 + MAVLINK_RECEIVER_NET_ADDED_STACK));
|
||||
|
||||
pthread_create(&_thread, &receiveloop_attr, MavlinkReceiver::start_trampoline, (void *)this);
|
||||
|
||||
|
||||
Reference in new issue
Block a user