Skip to content

task priorities: raise CONNECT and TCPIP_THREAD to osPriorityNormal#5205

Draft
bkerler wants to merge 1 commit intoprusa3d:masterfrom
bkerler:fix_task_prio
Draft

task priorities: raise CONNECT and TCPIP_THREAD to osPriorityNormal#5205
bkerler wants to merge 1 commit intoprusa3d:masterfrom
bkerler:fix_task_prio

Conversation

@bkerler
Copy link
Copy Markdown

@bkerler bkerler commented Mar 25, 2026

During active printing, media_prefetch temporarily raises the async executor thread to TASK_PRIORITY_MEDIA_PREFETCH (osPriorityNormal) for the duration of each fetch_routine call. With TASK_PRIORITY_CONNECT and TASK_PRIORITY_TCPIP_THREAD both at osPriorityBelowNormal, this caused two distinct failures:

  1. "net fail" / Connect drops offline while printing (issue [BUG] CORE One L 6.5.3. beta connect "net fail" drop out #5167). The TCPIP thread could not process incoming TCP segments or send ACKs while prefetch was running. The Connect task was also starved, missing the 4-second WebSocket telemetry window and eventually the 15-second ping-inactivity threshold, causing the server to mark the printer offline.

  2. "G-Code transfer running too slow" when printing from Connect (issue [BUG]Error while printing with Prusa Connect, "G-code transfer running too slow", print stops/fails 6.5.3-RC #5174). When printing via inline WebSocket streaming, the Connect task receives chunks from the server and writes them to the partial download file. Media prefetch reads that same file. With prefetch elevated above Connect, Connect could not write new chunks while prefetch was reading — a priority inversion where prefetch hit RESULT_OUT_OF_RANGE on data that the starved Connect task had not yet delivered.

Fix: raise both tasks to osPriorityNormal so they are peers of the elevated prefetch thread rather than subordinates to it. They now share CPU fairly with media prefetch during I/O, which is the same relationship the old dual-priority scheme (TASK_PRIORITY_MEDIA_PREFETCH _WHILE_FREAD) provided before BFW-5653 removed it.

TASK_PRIORITY_WUI is left at osPriorityBelowNormal (local PrusaLink remains functional and is latency-tolerant). TASK_PRIORITY_ASYNC_JOB_ EXECUTOR remains at osPriorityBelowNormal; the executor only needs elevation during active fetch work, which fetch_routine already handles via osThreadSetPriority.

During active printing, media_prefetch temporarily raises the async
executor thread to TASK_PRIORITY_MEDIA_PREFETCH (osPriorityNormal) for
the duration of each fetch_routine call.  With TASK_PRIORITY_CONNECT
and TASK_PRIORITY_TCPIP_THREAD both at osPriorityBelowNormal, this
caused two distinct failures:

1. "net fail" / Connect drops offline while printing (issue prusa3d#5167).
   The TCPIP thread could not process incoming TCP segments or send
   ACKs while prefetch was running.  The Connect task was also starved,
   missing the 4-second WebSocket telemetry window and eventually the
   15-second ping-inactivity threshold, causing the server to mark the
   printer offline.

2. "G-Code transfer running too slow" when printing from Connect
   (issue prusa3d#5174).  When printing via inline WebSocket streaming, the
   Connect task receives chunks from the server and writes them to the
   partial download file.  Media prefetch reads that same file.  With
   prefetch elevated above Connect, Connect could not write new chunks
   while prefetch was reading — a priority inversion where prefetch
   hit RESULT_OUT_OF_RANGE on data that the starved Connect task had
   not yet delivered.

Fix: raise both tasks to osPriorityNormal so they are peers of the
elevated prefetch thread rather than subordinates to it.  They now
share CPU fairly with media prefetch during I/O, which is the same
relationship the old dual-priority scheme (TASK_PRIORITY_MEDIA_PREFETCH
_WHILE_FREAD) provided before BFW-5653 removed it.

TASK_PRIORITY_WUI is left at osPriorityBelowNormal (local PrusaLink
remains functional and is latency-tolerant).  TASK_PRIORITY_ASYNC_JOB_
EXECUTOR remains at osPriorityBelowNormal; the executor only needs
elevation during active fetch work, which fetch_routine already handles
via osThreadSetPriority.
@bkerler bkerler changed the title priorities: raise CONNECT and TCPIP_THREAD to osPriorityNormal task priorities: raise CONNECT and TCPIP_THREAD to osPriorityNormal Mar 25, 2026
@bkerler bkerler marked this pull request as draft March 26, 2026 07:24
@bkerler
Copy link
Copy Markdown
Author

bkerler commented Mar 26, 2026

Moved to draft as Prusa devs said that raising priorities (race print vs. tcpip) is not an option

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant