clocksync: expose transmit_extra as a tunable [danger_options] knob#2
Open
pdscomp wants to merge 3 commits into
Open
clocksync: expose transmit_extra as a tunable [danger_options] knob#2pdscomp wants to merge 3 commits into
transmit_extra as a tunable [danger_options] knob#2pdscomp wants to merge 3 commits into
Conversation
The TRANSMIT_EXTRA constant in clocksync.py controls how far ahead of
the estimated MCU clock the host pre-schedules commands. When the host
is under CPU or scheduling pressure (e.g. competing processes, high
swap, real-time preemption latency) the gap between when klippy
calculates a clock value and when the MCU actually receives the command
can exceed this window. The MCU then sees the scheduled waketime land
in the past and fires the hard shutdown:
MCU 'hotend' shutdown: Timer too close
This commit:
1. Changes the default TRANSMIT_EXTRA from 0.001 s (1 ms) to
0.002 s (2 ms), giving the serialqueue twice as much headroom
to absorb host scheduling jitter.
2. Exposes the value as `transmit_extra` in [danger_options] so
operators can tune it without patching Python.
Tuning guidance for end users
------------------------------
Add or adjust in your printer.cfg:
[danger_options]
transmit_extra: 0.002 # default; increase if you see 'Timer too close'
Recommended values by scenario:
- Quiet dedicated host (e.g. CB1/CM4 running only Klipper): 0.001
- Default / lightly loaded host: 0.002
- Shared host with other services or high CPU load: 0.003-0.004
- CAN-bus multi-MCU setups with added bus latency: 0.003-0.005
Keeping the value below ~0.010 s is advisable; larger values push
commands further into the future relative to the MCU, which can cause
a small increase in scheduling latency for move commands but has no
impact on step timing accuracy or print quality at normal values.
The MCU-side 'Timer too close' guard in src/sched.c is intentionally
not modified — it is a hard safety check and should not be weakened.
There was a problem hiding this comment.
Pull request overview
Exposes the host-side clock sync forward-scheduling headroom (transmit_extra) as a configurable [danger_options] knob to reduce “Timer too close” MCU shutdowns under host scheduling jitter.
Changes:
- Increase
klippy.clocksync.TRANSMIT_EXTRAdefault and make it instance-tunable viaset_transmit_extra(). - Add
[danger_options] transmit_extraconfig option with bounds and apply it to all MCU clocksync instances atklippy:mcu_identify. - Include
transmit_extrain clocksync debug output to aid diagnostics.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
klippy/clocksync.py |
Makes transmit headroom configurable per ClockSync instance and uses it in clock estimation + debug output. |
klippy/extras/danger_options.py |
Adds config plumbing to set transmit_extra and propagates it to all MCU _clocksync objects during connect. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When the host computer is under CPU or scheduling pressure, the
MCU 'X' shutdown: Timer too closeerror can occur across multiple MCUs simultaneously. This happens becauseTRANSMIT_EXTRAinclocksync.py— the fixed 1 ms forward-scheduling headroom added to the MCU clock estimate passed to the serialqueue — is too small to absorb the host's scheduling jitter. The MCU then receives a command whose scheduled waketime has already passed, triggering the hardtry_shutdown("Timer too close")guard insrc/sched.c.Because the error originates on the klippy/host side (not in MCU firmware), this is safely fixable without reflashing.
Changes
klippy/clocksync.pyTRANSMIT_EXTRAmodule-level default from0.001s →0.002s.self.transmit_extrainstance attribute (initialized from the module default) so eachClockSync/SecondarySyncobject can be overridden independently.set_transmit_extra(value)method sodanger_optionscan push a user-supplied value in at connect time._handle_clock()now usesself.transmit_extrainstead of the bareTRANSMIT_EXTRAconstant.dump_debug()now includestransmit_extrain its output to aid diagnostics.klippy/extras/danger_options.pytransmit_extraconfig option (minval=0.0,maxval=0.010, default sourced fromclocksync.TRANSMIT_EXTRA).klippy:mcu_identifyevent handler that walks all MCU objects and callsset_transmit_extra()on each_clocksync, so a single config line applies to every MCU (primary + secondary/CAN).Tuning Guide for End Users
Add to
printer.cfg:0.0010.0020.003–0.0040.003–0.0050.005–0.010Values above
0.010s are capped bymaxvaland are not recommended — they push commands so far ahead that scheduling latency for reactive events (endstops, probes) could be marginally affected, though step timing accuracy and print quality are not impacted at normal values.Do not increase
transmit_extraas a substitute for fixing the underlying host load issue. If you need values above0.004consistently, investigate CPU usage, swap, disk I/O, or thermal throttling on the host.Safety
The MCU-side
Timer too closeguard insrc/sched.cis not modified. It is a hard safety check that must remain intact. All changes are confined to the host-side Python layer.